[PATCH RFC 28/51] qemu: blockjob: Pass job into qemuBlockJobUpdateDisk and rename it

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

 



Instead of passing in the disk information, pass in the job and name the
function accordingly.

Few callers needed to be modified to have the job pointer handy.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_blockjob.c  | 20 ++++++++++++--------
 src/qemu/qemu_blockjob.h  |  6 +++---
 src/qemu/qemu_driver.c    |  6 +++---
 src/qemu/qemu_migration.c | 40 +++++++++++++++++++++++++++------------
 4 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 49e747ebbb..c1826baa3c 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -333,7 +333,7 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,


 /**
- * qemuBlockJobUpdateDisk:
+ * qemuBlockJobUpdate:
  * @vm: domain
  * @disk: domain disk
  * @error: error (output parameter)
@@ -344,11 +344,10 @@ qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
  * Returns the block job event processed or -1 if there was no pending event.
  */
 int
-qemuBlockJobUpdateDisk(virDomainObjPtr vm,
-                       int asyncJob,
-                       virDomainDiskDefPtr disk)
+qemuBlockJobUpdate(virDomainObjPtr vm,
+                   qemuBlockJobDataPtr job,
+                   int asyncJob)
 {
-    qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
     qemuDomainObjPrivatePtr priv = vm->privateData;

     if (job->newstate == -1)
@@ -370,7 +369,7 @@ qemuBlockJobUpdateDisk(virDomainObjPtr vm,
  *
  * During a synchronous block job, a block job event for @disk
  * will not be processed asynchronously. Instead, it will be
- * processed only when qemuBlockJobUpdateDisk or qemuBlockJobSyncEndDisk
+ * processed only when qemuBlockJobUpdate or qemuBlockJobSyncEndDisk
  * is called.
  */
 void
@@ -402,7 +401,12 @@ qemuBlockJobSyncEndDisk(virDomainObjPtr vm,
                         int asyncJob,
                         virDomainDiskDefPtr disk)
 {
+    qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
+
+    if (!job)
+        return;
+
     VIR_DEBUG("disk=%s", disk->dst);
-    qemuBlockJobUpdateDisk(vm, asyncJob, disk);
-    QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob->synchronous = false;
+    qemuBlockJobUpdate(vm, job, asyncJob);
+    job->synchronous = false;
 }
diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h
index 4527ee2a93..9dad47f732 100644
--- a/src/qemu/qemu_blockjob.h
+++ b/src/qemu/qemu_blockjob.h
@@ -95,9 +95,9 @@ qemuBlockJobIsRunning(qemuBlockJobDataPtr job)
 void
 qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job);

-int qemuBlockJobUpdateDisk(virDomainObjPtr vm,
-                           int asyncJob,
-                           virDomainDiskDefPtr disk);
+int qemuBlockJobUpdate(virDomainObjPtr vm,
+                       qemuBlockJobDataPtr job,
+                       int asyncJob);

 void qemuBlockJobSyncBegin(qemuBlockJobDataPtr job);
 void qemuBlockJobSyncEndDisk(virDomainObjPtr vm,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2e47ec021a..4ffa5b573d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4739,7 +4739,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,

     job->newstate = status;

-    qemuBlockJobUpdateDisk(vm, QEMU_ASYNC_JOB_NONE, disk);
+    qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);

  endjob:
     qemuBlockJobStartupFinalize(job);
@@ -17397,13 +17397,13 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
      * do the waiting while still holding the VM job, to prevent newly
      * scheduled block jobs from confusing us. */
     if (!async) {
-        qemuBlockJobUpdateDisk(vm, QEMU_ASYNC_JOB_NONE, disk);
+        qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
         while (qemuBlockJobIsRunning(job)) {
             if (virDomainObjWait(vm) < 0) {
                 ret = -1;
                 goto endjob;
             }
-            qemuBlockJobUpdateDisk(vm, QEMU_ASYNC_JOB_NONE, disk);
+            qemuBlockJobUpdate(vm, job, QEMU_ASYNC_JOB_NONE);
         }
     }

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ac3c609067..92fcfa6278 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -464,17 +464,16 @@ qemuMigrationDstStopNBDServer(virQEMUDriverPtr driver,


 static void
-qemuMigrationNBDReportMirrorError(virDomainDiskDefPtr disk)
+qemuMigrationNBDReportMirrorError(qemuBlockJobDataPtr job,
+                                  const char *diskdst)
 {
-    qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
-
     if (job->errmsg) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("migration of disk %s failed: %s"),
-                       disk->dst, job->errmsg);
+                       diskdst, job->errmsg);
     } else {
         virReportError(VIR_ERR_OPERATION_FAILED,
-                       _("migration of disk %s failed"), disk->dst);
+                       _("migration of disk %s failed"), diskdst);
     }
 }

@@ -501,16 +500,26 @@ qemuMigrationSrcNBDStorageCopyReady(virDomainObjPtr vm,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+        qemuBlockJobDataPtr job;

         if (!diskPriv->migrating)
             continue;

-        status = qemuBlockJobUpdateDisk(vm, asyncJob, disk);
+        if (!(job = qemuBlockJobDiskGetJob(disk))) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("missing block job data for disk '%s'"), disk->dst);
+            return -1;
+        }
+
+        status = qemuBlockJobUpdate(vm, job, asyncJob);
         if (status == VIR_DOMAIN_BLOCK_JOB_FAILED) {
-            qemuMigrationNBDReportMirrorError(disk);
+            qemuMigrationNBDReportMirrorError(job, disk->dst);
+            virObjectUnref(job);
             return -1;
         }

+        virObjectUnref(job);
+
         if (disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_READY)
             notReady++;
     }
@@ -550,15 +559,19 @@ qemuMigrationSrcNBDCopyCancelled(virDomainObjPtr vm,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+        qemuBlockJobDataPtr job;

         if (!diskPriv->migrating)
             continue;

-        status = qemuBlockJobUpdateDisk(vm, asyncJob, disk);
+        if (!(job = qemuBlockJobDiskGetJob(disk)))
+            continue;
+
+        status = qemuBlockJobUpdate(vm, job, asyncJob);
         switch (status) {
         case VIR_DOMAIN_BLOCK_JOB_FAILED:
             if (check) {
-                qemuMigrationNBDReportMirrorError(disk);
+                qemuMigrationNBDReportMirrorError(job, disk->dst);
                 failed = true;
             }
             ATTRIBUTE_FALLTHROUGH;
@@ -574,6 +587,8 @@ qemuMigrationSrcNBDCopyCancelled(virDomainObjPtr vm,

         if (status == VIR_DOMAIN_BLOCK_JOB_COMPLETED)
             completed++;
+
+        virObjectUnref(job);
     }

     /* Updating completed block job drops the lock thus we have to recheck
@@ -616,6 +631,7 @@ static int
 qemuMigrationSrcNBDCopyCancelOne(virQEMUDriverPtr driver,
                                  virDomainObjPtr vm,
                                  virDomainDiskDefPtr disk,
+                                 qemuBlockJobDataPtr job,
                                  bool failNoJob,
                                  qemuDomainAsyncJob asyncJob)
 {
@@ -625,12 +641,12 @@ qemuMigrationSrcNBDCopyCancelOne(virQEMUDriverPtr driver,
     int status;
     int rv;

-    status = qemuBlockJobUpdateDisk(vm, asyncJob, disk);
+    status = qemuBlockJobUpdate(vm, job, asyncJob);
     switch (status) {
     case VIR_DOMAIN_BLOCK_JOB_FAILED:
     case VIR_DOMAIN_BLOCK_JOB_CANCELED:
         if (failNoJob) {
-            qemuMigrationNBDReportMirrorError(disk);
+            qemuMigrationNBDReportMirrorError(job, disk->dst);
             goto cleanup;
         }
         ATTRIBUTE_FALLTHROUGH;
@@ -698,7 +714,7 @@ qemuMigrationSrcNBDCopyCancel(virQEMUDriverPtr driver,
         if (!diskPriv->migrating)
             continue;

-        rv = qemuMigrationSrcNBDCopyCancelOne(driver, vm, disk,
+        rv = qemuMigrationSrcNBDCopyCancelOne(driver, vm, disk, job,
                                               check, asyncJob);
         if (rv != 0) {
             if (rv < 0) {
-- 
2.19.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux