]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Refactor qemuDomainObjSetJobPhase
authorJiri Denemark <jdenemar@redhat.com>
Tue, 10 May 2022 13:20:25 +0000 (15:20 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 7 Jun 2022 15:40:20 +0000 (17:40 +0200)
We will want to update migration phase without affecting job ownership.
Either in the thread that already owns the job or from an event handler
which only changes the phase (of a job no-one owns) without assuming it.

Let's move the ownership change to a new qemuDomainObjStartJobPhase
helper and let qemuDomainObjSetJobPhase set the phase without touching
ownership.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_domainjob.c
src/qemu/qemu_domainjob.h
src/qemu/qemu_migration.c

index e76eb7f2cf52524e58b1e61d5282314c2b62a8ae..1f6d97655887ea8f2fb437c88e39a028e95582d9 100644 (file)
@@ -717,6 +717,10 @@ qemuDomainJobDataToParams(virDomainJobData *jobData,
 }
 
 
+/*
+ * Sets the job phase without changing the job owner. The owner is supposed to
+ * be 0 or the current thread, a warning is issued otherwise.
+ */
 void
 qemuDomainObjSetJobPhase(virDomainObj *obj,
                          int phase)
@@ -731,19 +735,51 @@ qemuDomainObjSetJobPhase(virDomainObj *obj,
               virDomainAsyncJobTypeToString(priv->job.asyncJob),
               qemuDomainAsyncJobPhaseToString(priv->job.asyncJob, phase));
 
+    if (priv->job.asyncOwner != 0 &&
+        priv->job.asyncOwner != me) {
+        VIR_WARN("'%s' async job is owned by thread %llu, API '%s'",
+                 virDomainAsyncJobTypeToString(priv->job.asyncJob),
+                 priv->job.asyncOwner,
+                 NULLSTR(priv->job.asyncOwnerAPI));
+    }
+
+    priv->job.phase = phase;
+    qemuDomainSaveStatus(obj);
+}
+
+
+/*
+ * Changes the job owner and sets the job phase. The current owner is supposed
+ * to be 0 or the current thread, a warning is issued otherwise.
+ */
+void
+qemuDomainObjStartJobPhase(virDomainObj *obj,
+                           int phase)
+{
+    qemuDomainObjPrivate *priv = obj->privateData;
+    unsigned long long me = virThreadSelfID();
+
+    if (!priv->job.asyncJob)
+        return;
+
+    VIR_DEBUG("Starting phase '%s' of '%s' job",
+              qemuDomainAsyncJobPhaseToString(priv->job.asyncJob, phase),
+              virDomainAsyncJobTypeToString(priv->job.asyncJob));
+
     if (priv->job.asyncOwner == 0) {
         priv->job.asyncOwnerAPI = g_strdup(virThreadJobGet());
     } else if (me != priv->job.asyncOwner) {
-        VIR_WARN("'%s' async job is owned by thread %llu",
+        VIR_WARN("'%s' async job is owned by thread %llu, API '%s'",
                  virDomainAsyncJobTypeToString(priv->job.asyncJob),
-                 priv->job.asyncOwner);
+                 priv->job.asyncOwner,
+                 NULLSTR(priv->job.asyncOwnerAPI));
     }
 
-    priv->job.phase = phase;
     priv->job.asyncOwner = me;
-    qemuDomainSaveStatus(obj);
+    qemuDomainObjSetJobPhase(obj, phase);
 }
 
+
 void
 qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
                              unsigned long long allowedJobs)
index 707d4e91eda0485448b315d6d400340a2db08047..e8021a7f04ea0552fc88552a7a0b6e23a96f1f41 100644 (file)
@@ -156,6 +156,9 @@ void qemuDomainObjEndAsyncJob(virDomainObj *obj);
 void qemuDomainObjAbortAsyncJob(virDomainObj *obj);
 void qemuDomainObjSetJobPhase(virDomainObj *obj,
                               int phase);
+void
+qemuDomainObjStartJobPhase(virDomainObj *obj,
+                           int phase);
 void qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
                                   unsigned long long allowedJobs);
 int qemuDomainObjPreserveJob(virDomainObj *obj,
index 9cc2c07c79db928fd3c914f421ff35dc2e3bab22..8940c266bbc549fdbf6809224da5a05b67550995 100644 (file)
@@ -165,7 +165,7 @@ qemuMigrationJobSetPhase(virDomainObj *vm,
     if (qemuMigrationCheckPhase(vm, phase) < 0)
         return -1;
 
-    qemuDomainObjSetJobPhase(vm, phase);
+    qemuDomainObjStartJobPhase(vm, phase);
     return 0;
 }