Now that block job data is stored in the status XML portion we need to
make sure that everything which changes the state also saves the status
XML. The job registering function is used while parsing the status XML
so in that case we need to skip the XML saving.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_blockjob.c | 15 ++++++++++++---
src/qemu/qemu_blockjob.h | 8 +++++---
src/qemu/qemu_domain.c | 2 +-
src/qemu/qemu_driver.c | 8 ++++----
src/qemu/qemu_migration.c | 2 +-
src/qemu/qemu_process.c | 4 ++--
6 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 78d4938684..3211230811 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -104,7 +104,8 @@ qemuBlockJobDataNew(qemuBlockJobType type,
int
qemuBlockJobRegister(qemuBlockJobDataPtr job,
virDomainObjPtr vm,
- virDomainDiskDefPtr disk)
+ virDomainDiskDefPtr disk,
+ bool savestatus)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -118,6 +119,9 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
}
+ if (savestatus)
+ qemuDomainSaveStatus(vm);
+
return 0;
}
@@ -142,6 +146,8 @@ qemuBlockJobUnregister(qemuBlockJobDataPtr job,
/* this may remove the last reference of 'job' */
virHashRemoveEntry(priv->blockjobs, job->name);
+
+ qemuDomainSaveStatus(vm);
}
@@ -164,7 +170,7 @@ qemuBlockJobDiskNew(virDomainObjPtr vm,
if (!(job = qemuBlockJobDataNew(type, jobname)))
return NULL;
- if (qemuBlockJobRegister(job, vm, disk) < 0)
+ if (qemuBlockJobRegister(job, vm, disk, true) < 0)
return NULL;
VIR_RETURN_PTR(job);
@@ -196,10 +202,13 @@ qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
* Mark @job as started in qemu.
*/
void
-qemuBlockJobStarted(qemuBlockJobDataPtr job)
+qemuBlockJobStarted(qemuBlockJobDataPtr job,
+ virDomainObjPtr vm)
{
if (job->state == QEMU_BLOCKJOB_STATE_NEW)
job->state = QEMU_BLOCKJOB_STATE_RUNNING;
+
+ qemuDomainSaveStatus(vm);
}
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index 5b3af69d89..c5fd636340 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -87,7 +87,8 @@ struct _qemuBlockJobData {
int
qemuBlockJobRegister(qemuBlockJobDataPtr job,
virDomainObjPtr vm,
- virDomainDiskDefPtr disk)
+ virDomainDiskDefPtr disk,
+ bool savestatus)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
qemuBlockJobDataPtr
@@ -107,8 +108,9 @@ qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
ATTRIBUTE_NONNULL(1);
void
-qemuBlockJobStarted(qemuBlockJobDataPtr job)
- ATTRIBUTE_NONNULL(1);
+qemuBlockJobStarted(qemuBlockJobDataPtr job,
+ virDomainObjPtr vm)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bool
qemuBlockJobIsRunning(qemuBlockJobDataPtr job)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 59225c3ca9..7162fca71b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2755,7 +2755,7 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm,
job->errmsg = virXPathString("string(./errmsg)", ctxt);
job->invalidData = invalidData;
- if (qemuBlockJobRegister(job, vm, disk) < 0)
+ if (qemuBlockJobRegister(job, vm, disk, false) < 0)
return -1;
return 0;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 879a78858b..a0c246a416 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4704,7 +4704,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
if (!(job = qemuBlockJobDiskGetJob(disk))) {
if (!(job = qemuBlockJobDiskNew(vm, disk, type, diskAlias)))
goto endjob;
- qemuBlockJobStarted(job);
+ job->state = QEMU_BLOCKJOB_STATE_RUNNING;
}
job->newstate = status;
@@ -17100,7 +17100,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
if (ret < 0)
goto endjob;
- qemuBlockJobStarted(job);
+ qemuBlockJobStarted(job, vm);
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps)
< 0)
VIR_WARN("Unable to save status on vm %s after state change",
@@ -17676,11 +17676,11 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
}
/* Update vm in place to match changes. */
- qemuBlockJobStarted(job);
need_unlink = false;
virStorageFileDeinit(mirror);
VIR_STEAL_PTR(disk->mirror, mirror);
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
+ qemuBlockJobStarted(job, vm);
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps)
< 0)
VIR_WARN("Unable to save status on vm %s after state change",
@@ -18066,11 +18066,11 @@ qemuDomainBlockCommit(virDomainPtr dom,
goto endjob;
}
- qemuBlockJobStarted(job);
if (mirror) {
VIR_STEAL_PTR(disk->mirror, mirror);
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT;
}
+ qemuBlockJobStarted(job, vm);
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps)
< 0)
VIR_WARN("Unable to save status on vm %s after block job",
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index e72553befc..cbacb886f8 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -944,7 +944,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
goto cleanup;
diskPriv->migrating = true;
- qemuBlockJobStarted(job);
+ qemuBlockJobStarted(job, vm);
ret = 0;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 29124ae184..f39143d499 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7819,8 +7819,6 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
if (!(job = qemuBlockJobDiskNew(vm, disk, jobtype, jobname)))
return -1;
- qemuBlockJobStarted(job);
-
if (disk->mirror) {
if (info->ready == 1 ||
(info->ready == -1 && info->end == info->cur)) {
@@ -7849,6 +7847,8 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
}
}
+ qemuBlockJobStarted(job, vm);
+
cleanup:
qemuBlockJobStartupFinalize(vm, job);
--
2.21.0