[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH RFC 21/51] qemu: blockjob: Record job type when starting the job



We can properly track the job type when starting the job so that we
don't have to infer it later.

This patch also adds an enum of block job types specific to qemu
(qemuBlockjobType) which mirrors the public block job types
(virDomainBlockJobType) but allows for other types to be added later
which will not be public.

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 src/qemu/qemu_blockjob.c  | 10 +++++-----
 src/qemu/qemu_blockjob.h  | 20 ++++++++++++++++++--
 src/qemu/qemu_driver.c    | 11 ++++++-----
 src/qemu/qemu_migration.c |  2 +-
 src/qemu/qemu_process.c   |  8 ++++++--
 5 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 7bbe582722..531de035af 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -96,12 +96,16 @@ qemuBlockJobDataReset(qemuBlockJobDataPtr job)
  * Returns 0 on success and -1 on failure.
  */
 qemuBlockJobDataPtr
-qemuBlockJobDiskNew(virDomainDiskDefPtr disk)
+qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
+                    qemuBlockjobType type)
 {
     qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
     job->disk = disk;

     qemuBlockJobDataReset(job);
+
+    job->type = type;
+
     return virObjectRef(job);
 }

@@ -278,10 +282,6 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
               type,
               status);

-    if (type == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
-        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
-        type = disk->mirrorJob;
-
     qemuBlockJobEmitEvents(driver, vm, disk, type, status);

     /* If we completed a block pull or commit, then update the XML
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index feaee4dee3..6f6d0aa691 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -25,6 +25,21 @@
 # include "internal.h"
 # include "qemu_conf.h"

+/**
+ * This enum has to map all known block job types from enum virDomainBlockJobType
+ * to the same values. All internal blockjobs can be mapped after and don't
+ * need to have stable values.
+ */
+typedef enum {
+    QEMU_BLOCKJOB_TYPE_NONE = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN,
+    QEMU_BLOCKJOB_TYPE_PULL = VIR_DOMAIN_BLOCK_JOB_TYPE_PULL,
+    QEMU_BLOCKJOB_TYPE_COPY = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY,
+    QEMU_BLOCKJOB_TYPE_COMMIT = VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT,
+    QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT,
+    QEMU_BLOCKJOB_TYPE_INTERNAL,
+    QEMU_BLOCKJOB_TYPE_LAST
+} qemuBlockjobType;
+verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL == VIR_DOMAIN_BLOCK_JOB_TYPE_LAST);

 typedef struct _qemuBlockJobData qemuBlockJobData;
 typedef qemuBlockJobData *qemuBlockJobDataPtr;
@@ -35,7 +50,7 @@ struct _qemuBlockJobData {
     virDomainDiskDefPtr disk; /* may be NULL, if blockjob does not corrspond to any disk */

     bool started;
-    int type;
+    int type; /* qemuBlockjobType */
     char *errmsg;
     bool synchronous; /* API call is waiting for this job */

@@ -45,7 +60,8 @@ struct _qemuBlockJobData {
 qemuBlockJobDataPtr qemuBlockJobDataNew(void);

 qemuBlockJobDataPtr
-qemuBlockJobDiskNew(virDomainDiskDefPtr disk)
+qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
+                    qemuBlockjobType type)
     ATTRIBUTE_NONNULL(1);

 qemuBlockJobDataPtr
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9e5171744e..5eace06099 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4732,12 +4732,11 @@ processBlockJobEvent(virQEMUDriverPtr driver,
     }

     if (!(job = qemuBlockJobDiskGetJob(disk))) {
-        if (!(job = qemuBlockJobDiskNew(disk)))
+        if (!(job = qemuBlockJobDiskNew(disk, type)))
             goto endjob;
         qemuBlockJobStarted(job);
     }

-    job->type = type;
     job->newstate = status;

     qemuBlockJobUpdateDisk(vm, QEMU_ASYNC_JOB_NONE, disk, NULL);
@@ -17269,7 +17268,7 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
         speed <<= 20;
     }

-    if (!(job = qemuBlockJobDiskNew(disk)))
+    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_PULL)))
         goto endjob;

     qemuDomainObjEnterMonitor(driver, vm);
@@ -17797,7 +17796,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
         goto endjob;
     }

-    if (!(job = qemuBlockJobDiskNew(disk)))
+    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY)))
         goto endjob;

     /* Actually start the mirroring */
@@ -18048,6 +18047,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
     virStorageSourcePtr mirror = NULL;
     unsigned long long speed = bandwidth;
     qemuBlockJobDataPtr job = NULL;
+    qemuBlockjobType jobtype = QEMU_BLOCKJOB_TYPE_COMMIT;

     /* XXX Add support for COMMIT_DELETE */
     virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW |
@@ -18207,9 +18207,10 @@ qemuDomainBlockCommit(virDomainPtr dom,
         disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
         disk->mirror = mirror;
         disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT;
+        jobtype = QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT;
     }

-    if (!(job = qemuBlockJobDiskNew(disk)))
+    if (!(job = qemuBlockJobDiskNew(disk, jobtype)))
         goto endjob;

     qemuDomainObjEnterMonitor(driver, vm);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index dbf35b0829..837ed39efe 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -908,7 +908,7 @@ qemuMigrationSrcNBDStorageCopyOne(virQEMUDriverPtr driver,
     if (!(diskAlias = qemuAliasDiskDriveFromDisk(disk)))
         goto cleanup;

-    if (!(job = qemuBlockJobDiskNew(disk)))
+    if (!(job = qemuBlockJobDiskNew(disk, QEMU_BLOCKJOB_TYPE_COPY)))
         goto cleanup;

     qemuBlockJobSyncBeginDisk(disk);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b1fdbca15e..91c99a2a11 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -941,7 +941,6 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,

     if (job && job->synchronous) {
         /* We have a SYNC API waiting for this event, dispatch it back */
-        job->type = type;
         job->newstate = status;
         VIR_FREE(job->errmsg);
         ignore_value(VIR_STRDUP_QUIET(job->errmsg, error));
@@ -7766,13 +7765,18 @@ qemuProcessRefreshLegacyBlockjob(void *payload,
     qemuMonitorBlockJobInfoPtr info = payload;
     virDomainDiskDefPtr disk;
     qemuBlockJobDataPtr job;
+    virDomainBlockJobType jobtype = info->type;

     if (!(disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, jobname, jobname))) {
         VIR_DEBUG("could not find disk for block job '%s'", jobname);
         return 0;
     }

-    if (!(job = qemuBlockJobDiskNew(disk)))
+    if (jobtype == VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT &&
+        disk->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
+        jobtype = disk->mirrorJob;
+
+    if (!(job = qemuBlockJobDiskNew(disk, jobtype)))
         return -1;

     qemuBlockJobStarted(job);
-- 
2.19.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]