[PATCH 2/3] qemu: make separate function for setting statsType of privateData

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

 



We only need to set statsType in almost every case of setting
something from private data, so it seems unnecessary to pull
privateData out of current / completed job for just this one
thing every time. I think this patch keeps the code cleaner
without variables used just once.

Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/qemu/qemu_backup.c    |  4 ++--
 src/qemu/qemu_domain.c    |  8 ++++++++
 src/qemu/qemu_domain.h    |  3 +++
 src/qemu/qemu_driver.c    | 14 ++++++--------
 src/qemu/qemu_migration.c |  9 ++++-----
 src/qemu/qemu_process.c   |  5 ++---
 src/qemu/qemu_snapshot.c  |  5 ++---
 7 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index 081c4d023f..23d3f44dd8 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -746,7 +746,6 @@ qemuBackupBegin(virDomainObj *vm,
                 unsigned int flags)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
-    qemuDomainJobDataPrivate *privData = priv->job.current->privateData;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
     g_autoptr(virDomainBackupDef) def = NULL;
     g_autofree char *suffix = NULL;
@@ -800,7 +799,8 @@ qemuBackupBegin(virDomainObj *vm,
     qemuDomainObjSetAsyncJobMask(vm, (QEMU_JOB_DEFAULT_MASK |
                                       JOB_MASK(QEMU_JOB_SUSPEND) |
                                       JOB_MASK(QEMU_JOB_MODIFY)));
-    privData->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP;
+    qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                     QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP);
 
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a8401bac30..62e67b438f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -81,6 +81,14 @@
 VIR_LOG_INIT("qemu.qemu_domain");
 
 
+void
+qemuDomainJobPrivateSetStatsType(qemuDomainJobDataPrivate *privData,
+                                 qemuDomainJobStatsType type)
+{
+    privData->statsType = type;
+}
+
+
 static void *
 qemuJobAllocPrivate(void)
 {
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index e5046367e3..7363ff6444 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -488,6 +488,9 @@ void qemuDomainObjStopWorker(virDomainObj *dom);
 
 virDomainObj *qemuDomainObjFromDomain(virDomainPtr domain);
 
+void qemuDomainJobPrivateSetStatsType(qemuDomainJobDataPrivate *privData,
+                                      qemuDomainJobStatsType type);
+
 qemuDomainSaveCookie *qemuDomainSaveCookieNew(virDomainObj *vm);
 
 void qemuDomainEventFlush(int timer, void *opaque);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 800db34a4b..7f7684f1cc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2630,7 +2630,6 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
     int ret = -1;
     virObjectEvent *event = NULL;
     qemuDomainObjPrivate *priv = vm->privateData;
-    qemuDomainJobDataPrivate *privJobCurrent = priv->job.current->privateData;
     virQEMUSaveData *data = NULL;
     g_autoptr(qemuDomainSaveCookie) cookie = NULL;
 
@@ -2647,7 +2646,8 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
         goto endjob;
     }
 
-    privJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP;
+    qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                     QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP);
 
     /* Pause */
     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
@@ -2988,9 +2988,8 @@ qemuDumpToFd(virQEMUDriver *driver,
         return -1;
 
     if (detach) {
-        qemuDomainJobDataPrivate *privStats = priv->job.current->privateData;
-
-        privStats->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP;
+        qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                         QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP);
     } else {
         g_clear_pointer(&priv->job.current, virDomainJobDataFree);
     }
@@ -3128,7 +3127,6 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
     virQEMUDriver *driver = dom->conn->privateData;
     virDomainObj *vm;
     qemuDomainObjPrivate *priv = NULL;
-    qemuDomainJobDataPrivate *privJobCurrent = NULL;
     bool resume = false, paused = false;
     int ret = -1;
     virObjectEvent *event = NULL;
@@ -3153,8 +3151,8 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
         goto endjob;
 
     priv = vm->privateData;
-    privJobCurrent = priv->job.current->privateData;
-    privJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP;
+    qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                     QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP);
 
     /* Migrate will always stop the VM, so the resume condition is
        independent of whether the stop command is issued.  */
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 7957b79fc2..9e4fd67e2a 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5859,11 +5859,10 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
 
     if (dom) {
         if (jobData) {
-            qemuDomainJobDataPrivate *privJob = jobData->privateData;
-
             priv->job.completed = g_steal_pointer(&jobData);
             priv->job.completed->status = VIR_DOMAIN_JOB_STATUS_COMPLETED;
-            privJob->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION;
+            qemuDomainJobPrivateSetStatsType(jobData->privateData,
+                                             QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION);
         }
 
         if (qemuMigrationCookieFormat(mig, driver, vm,
@@ -6105,7 +6104,6 @@ qemuMigrationJobStart(virQEMUDriver *driver,
                       unsigned long apiFlags)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
-    qemuDomainJobDataPrivate *privJob = priv->job.current->privateData;
     virDomainJobOperation op;
     unsigned long long mask;
 
@@ -6122,7 +6120,8 @@ qemuMigrationJobStart(virQEMUDriver *driver,
     if (qemuDomainObjBeginAsyncJob(driver, vm, job, op, apiFlags) < 0)
         return -1;
 
-    privJob->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION;
+    qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                     QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION);
 
     qemuDomainObjSetAsyncJobMask(vm, mask);
     return 0;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index fb7a04139a..39872e6c12 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3597,7 +3597,6 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
                       unsigned int *stopFlags)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
-    qemuDomainJobDataPrivate *privDataJobCurrent = NULL;
     virDomainState state;
     int reason;
     unsigned long long now;
@@ -3666,10 +3665,10 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
          * active. This is possible because we are able to recover the state
          * of blockjobs and also the backup job allows all sub-job types */
         priv->job.current = virDomainJobDataInit(&qemuJobDataPrivateDataCallbacks);
-        privDataJobCurrent = priv->job.current->privateData;
 
+        qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                         QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP);
         priv->job.current->operation = VIR_DOMAIN_JOB_OPERATION_BACKUP;
-        privDataJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP;
         priv->job.current->status = VIR_DOMAIN_JOB_STATUS_ACTIVE;
         priv->job.current->started = now;
         break;
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 6f9aedace7..359a7a32ea 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -1414,13 +1414,12 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
 
     /* do the memory snapshot if necessary */
     if (memory) {
-        qemuDomainJobDataPrivate *privJobCurrent = priv->job.current->privateData;
-
         /* check if migration is possible */
         if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
             goto cleanup;
 
-        privJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP;
+        qemuDomainJobPrivateSetStatsType(priv->job.current->privateData,
+                                         QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP);
 
         /* allow the migration job to be cancelled or the domain to be paused */
         qemuDomainObjSetAsyncJobMask(vm, (QEMU_JOB_DEFAULT_MASK |
-- 
2.34.1




[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