[PATCH v2 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_domainjob.c | 10 ++++++++++
 src/qemu/qemu_domainjob.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, 29 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index b0c81261de..2471242e60 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -745,7 +745,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;
@@ -799,7 +798,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;
+    qemuDomainJobSetStatsType(priv->job.current,
+                              QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP);
 
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index baa52dd986..3e73eba4ed 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -95,6 +95,16 @@ virDomainJobDataPrivateDataCallbacks qemuJobDataPrivateDataCallbacks = {
 };
 
 
+void
+qemuDomainJobSetStatsType(virDomainJobData *jobData,
+                          qemuDomainJobStatsType type)
+{
+    qemuDomainJobDataPrivate *privData = jobData->privateData;
+
+    privData->statsType = type;
+}
+
+
 const char *
 qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
                                 int phase G_GNUC_UNUSED)
diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h
index 36acf401dd..a078e62a1f 100644
--- a/src/qemu/qemu_domainjob.h
+++ b/src/qemu/qemu_domainjob.h
@@ -174,6 +174,9 @@ struct _qemuDomainJobObj {
     qemuDomainObjPrivateJobCallbacks *cb;
 };
 
+void qemuDomainJobSetStatsType(virDomainJobData *jobData,
+                               qemuDomainJobStatsType type);
+
 const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
                                             int phase);
 int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52a8931656..4f3d4bab3e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2637,7 +2637,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;
 
@@ -2654,7 +2653,8 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
         goto endjob;
     }
 
-    privJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP;
+    qemuDomainJobSetStatsType(priv->job.current,
+                              QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP);
 
     /* Pause */
     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
@@ -2995,9 +2995,8 @@ qemuDumpToFd(virQEMUDriver *driver,
         return -1;
 
     if (detach) {
-        qemuDomainJobDataPrivate *privStats = priv->job.current->privateData;
-
-        privStats->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP;
+        qemuDomainJobSetStatsType(priv->job.current,
+                                  QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP);
     } else {
         g_clear_pointer(&priv->job.current, virDomainJobDataFree);
     }
@@ -3135,7 +3134,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;
@@ -3160,8 +3158,8 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
         goto endjob;
 
     priv = vm->privateData;
-    privJobCurrent = priv->job.current->privateData;
-    privJobCurrent->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_SAVEDUMP;
+    qemuDomainJobSetStatsType(priv->job.current,
+                              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 a48350be74..fea5e71f4d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5853,11 +5853,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;
+            qemuDomainJobSetStatsType(jobData,
+                                      QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION);
         }
 
         if (qemuMigrationCookieFormat(mig, driver, vm,
@@ -6099,7 +6098,6 @@ qemuMigrationJobStart(virQEMUDriver *driver,
                       unsigned long apiFlags)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
-    qemuDomainJobDataPrivate *privJob = priv->job.current->privateData;
     virDomainJobOperation op;
     unsigned long long mask;
 
@@ -6116,7 +6114,8 @@ qemuMigrationJobStart(virQEMUDriver *driver,
     if (qemuDomainObjBeginAsyncJob(driver, vm, job, op, apiFlags) < 0)
         return -1;
 
-    privJob->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION;
+    qemuDomainJobSetStatsType(priv->job.current,
+                              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 4b921c1e35..a1d4299347 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;
 
+        qemuDomainJobSetStatsType(priv->job.current,
+                                  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 98080ac5f8..cb2a7eb739 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;
+        qemuDomainJobSetStatsType(priv->job.current,
+                                  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