]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: Rearrange order in lxcDomainUpdateDeviceFlags
authorJohn Ferlan <jferlan@redhat.com>
Tue, 26 Jun 2018 14:14:20 +0000 (10:14 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 2 Jul 2018 21:06:14 +0000 (17:06 -0400)
Although commit e3497f3f noted that the LIVE option doesn't
matter and removed the call to virDomainDefCompatibleDevice,
it didn't go quite far enough and change the order of the checks
and rework the code to just handle the config change causing
a failure after virDomainObjUpdateModificationImpact updates
the @flags. Since we only support config a lot of previously
conditional code is now just inlined.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Prívozník <mprivozn@redhat.com>
src/lxc/lxc_driver.c

index aea48e5e3d0578f7845800507eceaf79e95af125..1fc6c6a7bf844da7e11709d78243eacac9f36363 100644 (file)
@@ -4827,7 +4827,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
     virCapsPtr caps = NULL;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr vmdef = NULL;
-    virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
+    virDomainDeviceDefPtr dev = NULL;
     int ret = -1;
     virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
 
@@ -4846,61 +4846,40 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
     if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
         goto endjob;
 
-    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("Unable to modify live devices"));
         goto endjob;
+    }
 
-    dev = dev_copy = virDomainDeviceDefParse(xml, vm->def,
-                                             caps, driver->xmlopt,
-                                             VIR_DOMAIN_DEF_PARSE_INACTIVE);
-    if (dev == NULL)
+    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
         goto endjob;
 
-    if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
-        flags & VIR_DOMAIN_AFFECT_LIVE) {
-        /* If we are affecting both CONFIG and LIVE
-         * create a deep copy of device as adding
-         * to CONFIG takes one instance.
-         */
-        dev_copy = virDomainDeviceDefCopy(dev, vm->def,
-                                          caps, driver->xmlopt);
-        if (!dev_copy)
-            goto endjob;
-    }
-
-    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        /* Make a copy for updated domain. */
-        vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt);
-        if (!vmdef)
-            goto endjob;
+    if (!(dev = virDomainDeviceDefParse(xml, vm->def, caps, driver->xmlopt,
+                                        VIR_DOMAIN_DEF_PARSE_INACTIVE)))
+        goto endjob;
 
-        /* virDomainDefCompatibleDevice call is delayed until we know the
-         * device we're going to update. */
-        if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0)
-            goto endjob;
-    }
+    /* Make a copy for updated domain. */
+    if (!(vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt)))
+        goto endjob;
 
-    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("Unable to modify live devices"));
+    /* virDomainDefCompatibleDevice call is delayed until we know the
+     * device we're going to update. */
+    if (lxcDomainUpdateDeviceConfig(vmdef, dev) < 0)
+        goto endjob;
 
+    if (virDomainSaveConfig(cfg->configDir, driver->caps, vmdef) < 0)
         goto endjob;
-    }
 
-    /* Finally, if no error until here, we can save config. */
-    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        ret = virDomainSaveConfig(cfg->configDir, driver->caps, vmdef);
-        if (!ret) {
-            virDomainObjAssignDef(vm, vmdef, false, NULL);
-            vmdef = NULL;
-        }
-    }
+    virDomainObjAssignDef(vm, vmdef, false, NULL);
+    vmdef = NULL;
+    ret = 0;
+
  endjob:
     virLXCDomainObjEndJob(driver, vm);
 
  cleanup:
     virDomainDefFree(vmdef);
-    if (dev != dev_copy)
-        virDomainDeviceDefFree(dev_copy);
     virDomainDeviceDefFree(dev);
     virDomainObjEndAPI(&vm);
     virObjectUnref(caps);