[libvirt] [PATCH v2 07/11] qemu_domain: Allow qemuDomainObjListAdd to keep job upon return

Michal Privoznik mprivozn at redhat.com
Wed Jun 5 09:09:15 UTC 2019


In some cases, caller of qemuDomainObjListAdd() tries to acquire
MODIFY job after the call. Let's adjust qemuDomainObjListAdd() so
that it will keep the job set upon return (if requested by
caller).

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_domain.c    | 17 ++++++++++++++---
 src/qemu/qemu_domain.h    |  1 +
 src/qemu/qemu_driver.c    | 24 +++++++++++-------------
 src/qemu/qemu_migration.c |  2 +-
 4 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f6b677c69e..b0b3fa5fd8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7061,6 +7061,7 @@ virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
  * @def: domain definition
  * @oldDef: previous domain definition
  * @live: whether @def is live definition
+ * @keepJob: whether to leave MODIFY job set on returned object
  * @flags: an bitwise-OR of virDomainObjListAdd flags
  *
  * Add a domain onto the list of domain object and sets its
@@ -7070,6 +7071,10 @@ virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
  * In addition to that, if definition of an existing domain is
  * changed a MODIFY job is acquired prior to that.
  *
+ * If @keepJob is true, then the MODIFY job is not ended upon
+ * successful return from this function. This might be handy if
+ * caller would try to acquire the job anyway.
+ *
  * Returns: domain object pointer on success,
  *          NULL otherwise.
  */
@@ -7078,9 +7083,11 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver,
                      virDomainDefPtr def,
                      virDomainDefPtr *oldDef,
                      bool live,
+                     bool keepJob,
                      unsigned int flags)
 {
     virDomainObjPtr vm = NULL;
+    bool defSet = false;
 
     if (!(vm = virDomainObjListAdd(driver->domains, def, driver->xmlopt, flags)))
         return NULL;
@@ -7091,7 +7098,9 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver,
      * just set the definition without acquiring job. */
     if (!vm->def) {
         virDomainObjAssignDef(vm, def, live, oldDef);
-        VIR_RETURN_PTR(vm);
+        defSet = true;
+        if (!keepJob)
+            VIR_RETURN_PTR(vm);
     }
 
     /* Bad luck. Domain was pre-existing and this call is trying
@@ -7102,9 +7111,11 @@ qemuDomainObjListAdd(virQEMUDriverPtr driver,
         return NULL;
     }
 
-    virDomainObjAssignDef(vm, def, live, oldDef);
+    if (!defSet)
+        virDomainObjAssignDef(vm, def, live, oldDef);
 
-    qemuDomainObjEndJob(driver, vm);
+    if (!keepJob)
+        qemuDomainObjEndJob(driver, vm);
 
     return vm;
 }
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f469f8eaca..52b708babb 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -547,6 +547,7 @@ virDomainObjPtr qemuDomainObjListAdd(virQEMUDriverPtr driver,
                                      virDomainDefPtr def,
                                      virDomainDefPtr *oldDef,
                                      bool live,
+                                     bool keepJob,
                                      unsigned int flags);
 
 int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fa93a686b7..34359c9500 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1701,7 +1701,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
     if (virDomainCreateXMLEnsureACL(conn, def) < 0)
         goto cleanup;
 
-    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true,
+    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true, false,
                                     VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE)))
         goto cleanup;
     def = NULL;
@@ -6969,7 +6969,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
         def = tmp;
     }
 
-    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true,
+    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true, false,
                                     VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE)))
         goto cleanup;
     def = NULL;
@@ -7642,7 +7642,7 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
     if (virDomainDefineXMLFlagsEnsureACL(conn, def) < 0)
         goto cleanup;
 
-    if (!(vm = qemuDomainObjListAdd(driver, def, &oldDef, false, 0)))
+    if (!(vm = qemuDomainObjListAdd(driver, def, &oldDef, false, true, 0)))
         goto cleanup;
     def = NULL;
 
@@ -7663,9 +7663,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
             /* Brand new domain. Remove it */
             VIR_INFO("Deleting domain '%s'", vm->def->name);
             vm->persistent = 0;
-            qemuDomainRemoveInactiveJob(driver, vm);
+            qemuDomainRemoveInactive(driver, vm);
         }
-        goto cleanup;
+        goto endjob;
     }
 
     event = virDomainEventLifecycleNewFromObj(vm,
@@ -7677,6 +7677,9 @@ qemuDomainDefineXMLFlags(virConnectPtr conn,
     VIR_INFO("Creating domain '%s'", vm->def->name);
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
+ endjob:
+    qemuDomainObjEndJob(driver, vm);
+
  cleanup:
     virDomainDefFree(oldDef);
     virDomainDefFree(def);
@@ -16876,25 +16879,20 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
     if (qemuAssignDeviceAliases(def, qemuCaps) < 0)
         goto cleanup;
 
-    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true,
+    if (!(vm = qemuDomainObjListAdd(driver, def, NULL, true, true,
                                     VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE)))
         goto cleanup;
     def = NULL;
 
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) {
-        qemuDomainRemoveInactive(driver, vm);
-        goto cleanup;
-    }
-
     if (qemuProcessAttach(conn, driver, vm, pid,
                           pidfile, monConfig, monJSON) < 0) {
         qemuDomainRemoveInactive(driver, vm);
-        qemuDomainObjEndJob(driver, vm);
-        goto cleanup;
+        goto endjob;
     }
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
+ endjob:
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 13f0bc7e45..4e1c57c273 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2403,7 +2403,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
                                        QEMU_MIGRATION_COOKIE_CAPS)))
         goto cleanup;
 
-    if (!(vm = qemuDomainObjListAdd(driver, *def, NULL, true,
+    if (!(vm = qemuDomainObjListAdd(driver, *def, NULL, true, false,
                                    VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE)))
         goto cleanup;
     *def = NULL;
-- 
2.21.0




More information about the libvir-list mailing list