[PATCH 62/68] qemu: Store API flags for async jobs in qemuDomainJobObj

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

 



When an async job is running, we sometimes need to know how it was
started to distinguish between several types of the job, e.g., post-copy
vs. normal migration. So far we added a specific bool item to
qemuDomainJobObj for such cases, which doesn't scale very well and
storing such bools in status XML would be painful so we didn't do it.

A better approach is to store the flags passed to the API which started
the async job, which can be easily stored in status XML.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c    | 10 ++++++++--
 src/qemu/qemu_domain.h    |  4 +++-
 src/qemu/qemu_driver.c    | 31 +++++++++++++++++++------------
 src/qemu/qemu_migration.c | 20 +++++++++++++-------
 src/qemu/qemu_process.c   |  5 +++--
 src/qemu/qemu_process.h   |  3 ++-
 6 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cef08343ea..3f3a49f064 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -339,6 +339,7 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
     VIR_FREE(job->current);
     qemuMigrationParamsFree(job->migParams);
     job->migParams = NULL;
+    job->apiFlags = 0;
 }
 
 void
@@ -354,6 +355,7 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj,
     job->asyncOwner = priv->job.asyncOwner;
     job->phase = priv->job.phase;
     VIR_STEAL_PTR(job->migParams, priv->job.migParams);
+    job->apiFlags = priv->job.apiFlags;
 
     qemuDomainObjResetJob(priv);
     qemuDomainObjResetAsyncJob(priv);
@@ -5788,7 +5790,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
         asyncDuration = now - priv->job.asyncStarted;
 
     VIR_WARN("Cannot start job (%s, %s) for domain %s; "
-             "current job is (%s, %s) owned by (%llu %s, %llu %s) "
+             "current job is (%s, %s) "
+             "owned by (%llu %s, %llu %s (flags=0x%lx)) "
              "for (%llus, %llus)",
              qemuDomainJobTypeToString(job),
              qemuDomainAsyncJobTypeToString(asyncJob),
@@ -5797,6 +5800,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
              qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
              priv->job.owner, NULLSTR(priv->job.ownerAPI),
              priv->job.asyncOwner, NULLSTR(priv->job.asyncOwnerAPI),
+             priv->job.apiFlags,
              duration / 1000, asyncDuration / 1000);
 
     if (nested || qemuDomainNestedJobAllowed(priv, job))
@@ -5860,7 +5864,8 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
 int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob,
-                               virDomainJobOperation operation)
+                               virDomainJobOperation operation,
+                               unsigned long apiFlags)
 {
     qemuDomainObjPrivatePtr priv;
 
@@ -5870,6 +5875,7 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
 
     priv = obj->privateData;
     priv->job.current->operation = operation;
+    priv->job.apiFlags = apiFlags;
     return 0;
 }
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2bb3e0a788..2146ff00a9 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -182,6 +182,7 @@ struct _qemuDomainJobObj {
     bool dumpCompleted;                 /* dump completed */
 
     qemuMigrationParamsPtr migParams;
+    unsigned long apiFlags; /* flags passed to the API which started the async job */
 };
 
 typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
@@ -493,7 +494,8 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
 int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
                                virDomainObjPtr obj,
                                qemuDomainAsyncJob asyncJob,
-                               virDomainJobOperation operation)
+                               virDomainJobOperation operation,
+                               unsigned long apiFlags)
     ATTRIBUTE_RETURN_CHECK;
 int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
                                 virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 93dec7c2ce..e15eb49a5c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -267,7 +267,7 @@ qemuAutostartDomain(virDomainObjPtr vm,
     if (vm->autostart &&
         !virDomainObjIsActive(vm)) {
         if (qemuProcessBeginJob(driver, vm,
-                                VIR_DOMAIN_JOB_OPERATION_START) < 0) {
+                                VIR_DOMAIN_JOB_OPERATION_START, flags) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to start job on VM '%s': %s"),
                            vm->def->name, virGetLastErrorMessage());
@@ -1779,7 +1779,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
     virObjectRef(vm);
     def = NULL;
 
-    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START) < 0) {
+    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START,
+                            flags) < 0) {
         qemuDomainRemoveInactiveJob(driver, vm);
         goto cleanup;
     }
@@ -3345,7 +3346,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver,
         goto cleanup;
 
     if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SAVE,
-                                   VIR_DOMAIN_JOB_OPERATION_SAVE) < 0)
+                                   VIR_DOMAIN_JOB_OPERATION_SAVE, flags) < 0)
         goto cleanup;
 
     if (!virDomainObjIsActive(vm)) {
@@ -3953,7 +3954,8 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
 
     if (qemuDomainObjBeginAsyncJob(driver, vm,
                                    QEMU_ASYNC_JOB_DUMP,
-                                   VIR_DOMAIN_JOB_OPERATION_DUMP) < 0)
+                                   VIR_DOMAIN_JOB_OPERATION_DUMP,
+                                   flags) < 0)
         goto cleanup;
 
     if (!virDomainObjIsActive(vm)) {
@@ -4178,7 +4180,8 @@ processWatchdogEvent(virQEMUDriverPtr driver,
     case VIR_DOMAIN_WATCHDOG_ACTION_DUMP:
         if (qemuDomainObjBeginAsyncJob(driver, vm,
                                        QEMU_ASYNC_JOB_DUMP,
-                                       VIR_DOMAIN_JOB_OPERATION_DUMP) < 0) {
+                                       VIR_DOMAIN_JOB_OPERATION_DUMP,
+                                       flags) < 0) {
             goto cleanup;
         }
 
@@ -4264,9 +4267,10 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
     virObjectEventPtr event = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     bool removeInactive = false;
+    unsigned long flags = VIR_DUMP_MEMORY_ONLY;
 
     if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_DUMP,
-                                   VIR_DOMAIN_JOB_OPERATION_DUMP) < 0)
+                                   VIR_DOMAIN_JOB_OPERATION_DUMP, flags) < 0)
         goto cleanup;
 
     if (!virDomainObjIsActive(vm)) {
@@ -4297,7 +4301,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
 
     switch (action) {
     case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY:
-        if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0)
+        if (doCoreDumpToAutoDumpPath(driver, vm, flags) < 0)
             goto endjob;
         ATTRIBUTE_FALLTHROUGH;
 
@@ -4314,7 +4318,7 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
         break;
 
     case VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART:
-        if (doCoreDumpToAutoDumpPath(driver, vm, VIR_DUMP_MEMORY_ONLY) < 0)
+        if (doCoreDumpToAutoDumpPath(driver, vm, flags) < 0)
             goto endjob;
         ATTRIBUTE_FALLTHROUGH;
 
@@ -6769,7 +6773,8 @@ qemuDomainRestoreFlags(virConnectPtr conn,
         priv->hookRun = true;
     }
 
-    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_RESTORE) < 0)
+    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_RESTORE,
+                            flags) < 0)
         goto cleanup;
 
     ret = qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path,
@@ -7357,7 +7362,8 @@ qemuDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
     if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START) < 0)
+    if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_START,
+                            flags) < 0)
         goto cleanup;
 
     if (virDomainObjIsActive(vm)) {
@@ -15208,7 +15214,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
      * 'savevm' blocks the monitor. External snapshot will then modify the
      * job mask appropriately. */
     if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SNAPSHOT,
-                                   VIR_DOMAIN_JOB_OPERATION_SNAPSHOT) < 0)
+                                   VIR_DOMAIN_JOB_OPERATION_SNAPSHOT, flags) < 0)
         goto cleanup;
 
     qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
@@ -15807,7 +15813,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
     }
 
     if (qemuProcessBeginJob(driver, vm,
-                            VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT) < 0)
+                            VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT,
+                            flags) < 0)
         goto cleanup;
 
     if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 2a0431ea6f..3ce180dd39 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -80,7 +80,8 @@ VIR_ENUM_IMPL(qemuMigrationJobPhase, QEMU_MIGRATION_PHASE_LAST,
 static int
 qemuMigrationJobStart(virQEMUDriverPtr driver,
                       virDomainObjPtr vm,
-                      qemuDomainAsyncJob job)
+                      qemuDomainAsyncJob job,
+                      unsigned long apiFlags)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
 static void
@@ -1984,7 +1985,8 @@ qemuMigrationSrcBegin(virConnectPtr conn,
     qemuDomainAsyncJob asyncJob;
 
     if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
-        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+                                  flags) < 0)
             goto cleanup;
         asyncJob = QEMU_ASYNC_JOB_MIGRATION_OUT;
     } else {
@@ -2317,7 +2319,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
                                          !!(flags & VIR_MIGRATE_NON_SHARED_INC)) < 0)
         goto cleanup;
 
-    if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+    if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+                              flags) < 0)
         goto cleanup;
     qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PREPARE);
 
@@ -4433,7 +4436,8 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
-    if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+    if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+                              flags) < 0)
         goto cleanup;
 
     if (!virDomainObjIsActive(vm) && !(flags & VIR_MIGRATE_OFFLINE)) {
@@ -4545,7 +4549,8 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
 
     /* If we didn't start the job in the begin phase, start it now. */
     if (!(flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
-        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+                                  flags) < 0)
             goto cleanup;
     } else if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_OUT)) {
         goto cleanup;
@@ -5282,7 +5287,8 @@ qemuMigrationSrcCancel(virQEMUDriverPtr driver,
 static int
 qemuMigrationJobStart(virQEMUDriverPtr driver,
                       virDomainObjPtr vm,
-                      qemuDomainAsyncJob job)
+                      qemuDomainAsyncJob job,
+                      unsigned long apiFlags)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainJobOperation op;
@@ -5298,7 +5304,7 @@ qemuMigrationJobStart(virQEMUDriverPtr driver,
                JOB_MASK(QEMU_JOB_MIGRATION_OP);
     }
 
-    if (qemuDomainObjBeginAsyncJob(driver, vm, job, op) < 0)
+    if (qemuDomainObjBeginAsyncJob(driver, vm, job, op, apiFlags) < 0)
         return -1;
 
     priv->job.current->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MIGRATION;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c4d3f67d19..89669c9765 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4185,10 +4185,11 @@ qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps,
 int
 qemuProcessBeginJob(virQEMUDriverPtr driver,
                     virDomainObjPtr vm,
-                    virDomainJobOperation operation)
+                    virDomainJobOperation operation,
+                    unsigned long apiFlags)
 {
     if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_START,
-                                   operation) < 0)
+                                   operation, apiFlags) < 0)
         return -1;
 
     qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 2741115673..9dd5c97642 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -68,7 +68,8 @@ void qemuProcessIncomingDefFree(qemuProcessIncomingDefPtr inc);
 
 int qemuProcessBeginJob(virQEMUDriverPtr driver,
                         virDomainObjPtr vm,
-                        virDomainJobOperation operation);
+                        virDomainJobOperation operation,
+                        unsigned long apiFlags);
 void qemuProcessEndJob(virQEMUDriverPtr driver,
                        virDomainObjPtr vm);
 
-- 
2.17.0

--
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