]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: Use virDomainLiveConfigHelperMethod for libxlDomainSetMemoryFlags
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Wed, 24 Feb 2016 08:38:37 +0000 (11:38 +0300)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 4 Mar 2016 12:39:01 +0000 (07:39 -0500)
Flag expansion is the same as in virDomainObjUpdateModificationImpact
which virDomainLiveConfigHelperMethod calls internally. The difference
is merely in implementation. Note that VIR_DOMAIN_MEM_CONFIG is the
same as VIR_DOMAIN_AFFECT_CONFIG.  Additionally, the called functions
will properly use flag OR and thus handle the VIR_DOMAIN_MEM_MAXIMUM case.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
src/libxl/libxl_driver.c

index 6b316db42ab220bfc4db942a0c2c8f4ef5504b1b..890c0c3e4ead0d9ac0397e308c2cb022e04e84eb 100644 (file)
@@ -1445,7 +1445,6 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
     virDomainObjPtr vm;
     virDomainDefPtr persistentDef = NULL;
-    bool isActive;
     int ret = -1;
 
     virCheckFlags(VIR_DOMAIN_MEM_LIVE |
@@ -1461,38 +1460,9 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
     if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
         goto cleanup;
 
-    isActive = virDomainObjIsActive(vm);
-
-    if (flags == VIR_DOMAIN_MEM_CURRENT) {
-        if (isActive)
-            flags = VIR_DOMAIN_MEM_LIVE;
-        else
-            flags = VIR_DOMAIN_MEM_CONFIG;
-    }
-    if (flags == VIR_DOMAIN_MEM_MAXIMUM) {
-        if (isActive)
-            flags = VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_MAXIMUM;
-        else
-            flags = VIR_DOMAIN_MEM_CONFIG | VIR_DOMAIN_MEM_MAXIMUM;
-    }
-
-    if (!isActive && (flags & VIR_DOMAIN_MEM_LIVE)) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("cannot set memory on an inactive domain"));
+    if (virDomainLiveConfigHelperMethod(cfg->caps, driver->xmlopt, vm, &flags,
+                                        &persistentDef) < 0)
         goto endjob;
-    }
-
-    if (flags & VIR_DOMAIN_MEM_CONFIG) {
-        if (!vm->persistent) {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("cannot change persistent config of a transient domain"));
-            goto endjob;
-        }
-        if (!(persistentDef = virDomainObjGetPersistentDef(cfg->caps,
-                                                           driver->xmlopt,
-                                                           vm)))
-            goto endjob;
-    }
 
     if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
         /* resize the maximum memory */