[libvirt PATCH v2 46/81] qemu: Refactor qemuDomainObjSetJobPhase

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

 



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@xxxxxxxxxx>
Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
Reviewed-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---

Notes:
    Version 2:
    - no change

 src/qemu/qemu_domainjob.c | 44 +++++++++++++++++++++++++++++++++++----
 src/qemu/qemu_domainjob.h |  3 +++
 src/qemu/qemu_migration.c |  2 +-
 3 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index e76eb7f2cf..1f6d976558 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -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)
diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h
index 707d4e91ed..e8021a7f04 100644
--- a/src/qemu/qemu_domainjob.h
+++ b/src/qemu/qemu_domainjob.h
@@ -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,
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 4c09caeace..1c015c0bcb 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -165,7 +165,7 @@ qemuMigrationJobSetPhase(virDomainObj *vm,
     if (qemuMigrationCheckPhase(vm, phase) < 0)
         return -1;
 
-    qemuDomainObjSetJobPhase(vm, phase);
+    qemuDomainObjStartJobPhase(vm, phase);
     return 0;
 }
 
-- 
2.35.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