[PATCH v2 09/11] lxc_domain: Allow lxcDomainObjListAdd to keep job upon return

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

 



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

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/lxc/lxc_domain.c | 17 ++++++++++++++---
 src/lxc/lxc_domain.h |  1 +
 src/lxc/lxc_driver.c | 19 ++++++++-----------
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index 800999cbed..2249d38757 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -54,6 +54,7 @@ VIR_LOG_INIT("lxc.lxc_domain");
  * @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
@@ -63,6 +64,10 @@ VIR_LOG_INIT("lxc.lxc_domain");
  * 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.
  */
@@ -71,9 +76,11 @@ lxcDomainObjListAdd(virLXCDriverPtr 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;
@@ -84,7 +91,9 @@ lxcDomainObjListAdd(virLXCDriverPtr 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
@@ -96,9 +105,11 @@ lxcDomainObjListAdd(virLXCDriverPtr driver,
         return NULL;
     }
 
-    virDomainObjAssignDef(vm, def, live, oldDef);
+    if (!defSet)
+        virDomainObjAssignDef(vm, def, live, oldDef);
 
-    virLXCDomainObjEndJob(driver, vm);
+    if (!keepJob)
+        virLXCDomainObjEndJob(driver, vm);
 
     return vm;
 }
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index 522cf7917d..539914e0a8 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -101,6 +101,7 @@ lxcDomainObjListAdd(virLXCDriverPtr driver,
                     virDomainDefPtr def,
                     virDomainDefPtr *oldDef,
                     bool live,
+                    bool keepJob,
                     unsigned int flags);
 
 int
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 41e6b59927..e77df15772 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -444,7 +444,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
         goto cleanup;
     }
 
-    if (!(vm = lxcDomainObjListAdd(driver, def, &oldDef, false, 0)))
+    if (!(vm = lxcDomainObjListAdd(driver, def, &oldDef, false, true, 0)))
         goto cleanup;
     def = NULL;
 
@@ -453,7 +453,7 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
     if (virDomainSaveConfig(cfg->configDir, driver->caps,
                             vm->newDef ? vm->newDef : vm->def) < 0) {
         virDomainObjListRemove(driver->domains, vm);
-        goto cleanup;
+        goto endjob;
     }
 
     event = virDomainEventLifecycleNewFromObj(vm,
@@ -464,6 +464,9 @@ lxcDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
+ endjob:
+    virLXCDomainObjEndJob(driver, vm);
+
  cleanup:
     virDomainDefFree(def);
     virDomainDefFree(oldDef);
@@ -1189,26 +1192,19 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
     }
 
 
-    if (!(vm = lxcDomainObjListAdd(driver, def, NULL, true,
+    if (!(vm = lxcDomainObjListAdd(driver, def, NULL, true, true,
                                    VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE)))
         goto cleanup;
     def = NULL;
 
-    if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0) {
-        if (!vm->persistent)
-            virDomainObjListRemove(driver->domains, vm);
-        goto cleanup;
-    }
-
     if (virLXCProcessStart(conn, driver, vm,
                            nfiles, files,
                            (flags & VIR_DOMAIN_START_AUTODESTROY),
                            VIR_DOMAIN_RUNNING_BOOTED) < 0) {
         virDomainAuditStart(vm, "booted", false);
-        virLXCDomainObjEndJob(driver, vm);
         if (!vm->persistent)
             virDomainObjListRemove(driver->domains, vm);
-        goto cleanup;
+        goto endjob;
     }
 
     event = virDomainEventLifecycleNewFromObj(vm,
@@ -1218,6 +1214,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
 
     dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
+ endjob:
     virLXCDomainObjEndJob(driver, vm);
 
  cleanup:
-- 
2.21.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