]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
libxl: implement virDomainPinVcpuFlags
authorDario Faggioli <dario.faggioli@citrix.com>
Tue, 17 Dec 2013 18:11:28 +0000 (19:11 +0100)
committerDario Faggioli <dario.faggioli@citrix.com>
Fri, 20 Dec 2013 14:10:20 +0000 (15:10 +0100)
And use it to implement libxlDomainPinVcpu(), similarly to what
happens in the QEMU driver. This way, it is possible to both
query and change the vcpu affinity of a persistent but not
running domain.

In face, before this patch, we have:
 # virsh list --all
  Id    Name                           State
 ----------------------------------------------------
  5     debian_32                      running
  -     fedora20_64                    shut off
 # virsh vcpupin fedora20_64 0 2-4 --current
 error: this function is not supported by the connection driver: virDomainPinVcpuFlags

After (same situation as above):
 # virsh vcpupin  fedora20_64 0 2-4 --current
 # virsh vcpupin  fedora20_64 0
 VCPU: CPU Affinity
 ----------------------------------
    0: 2-4

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
src/libxl/libxl_driver.c

index 3855509eb64b07c0d9c8942efbc8fff4960a8ad5..8528106dd7e3f029f59f4696e5c3ce90aacfcc81 100644 (file)
@@ -2358,45 +2358,61 @@ cleanup:
 }
 
 static int
-libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
-                   int maplen)
+libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
+                        unsigned char *cpumap, int maplen,
+                        unsigned int flags)
 {
     libxlDriverPrivatePtr driver = dom->conn->privateData;
     libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
-    libxlDomainObjPrivatePtr priv;
+    virDomainDefPtr targetDef = NULL;
     virDomainObjPtr vm;
     int ret = -1;
-    libxl_bitmap map;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
 
     if (!(vm = libxlDomObjFromDomain(dom)))
         goto cleanup;
 
-    if (virDomainPinVcpuEnsureACL(dom->conn, vm->def) < 0)
+    if (virDomainPinVcpuFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
         goto cleanup;
 
-    if (!virDomainObjIsActive(vm)) {
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) && !virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("cannot pin vcpus on an inactive domain"));
+                       _("domain is inactive"));
         goto cleanup;
     }
 
-    priv = vm->privateData;
-
-    map.size = maplen;
-    map.map = cpumap;
-    if (libxl_set_vcpuaffinity(priv->ctx, dom->id, vcpu, &map) != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Failed to pin vcpu '%d' with libxenlight"), vcpu);
+    if (virDomainLiveConfigHelperMethod(cfg->caps, driver->xmlopt, vm,
+                                        &flags, &targetDef) < 0)
         goto cleanup;
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        targetDef = vm->def;
     }
 
-    if (!vm->def->cputune.vcpupin) {
-        if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0)
+    sa_assert(targetDef);
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        libxl_bitmap map = { .size = maplen, .map = cpumap };
+        libxlDomainObjPrivatePtr priv;
+
+        priv = vm->privateData;
+        if (libxl_set_vcpuaffinity(priv->ctx, dom->id, vcpu, &map) != 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Failed to pin vcpu '%d' with libxenlight"),
+                           vcpu);
             goto cleanup;
-        vm->def->cputune.nvcpupin = 0;
+        }
     }
-    if (virDomainVcpuPinAdd(&vm->def->cputune.vcpupin,
-                            &vm->def->cputune.nvcpupin,
+
+    if (!targetDef->cputune.vcpupin) {
+        if (VIR_ALLOC(targetDef->cputune.vcpupin) < 0)
+            goto cleanup;
+        targetDef->cputune.nvcpupin = 0;
+    }
+    if (virDomainVcpuPinAdd(&targetDef->cputune.vcpupin,
+                            &targetDef->cputune.nvcpupin,
                             cpumap,
                             maplen,
                             vcpu) < 0) {
@@ -2405,11 +2421,14 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
         goto cleanup;
     }
 
-    if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
-        goto cleanup;
-
     ret = 0;
 
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm);
+    } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        ret = virDomainSaveConfig(cfg->configDir, targetDef);
+    }
+
 cleanup:
     if (vm)
         virObjectUnlock(vm);
@@ -2417,6 +2436,14 @@ cleanup:
     return ret;
 }
 
+static int
+libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
+                   int maplen)
+{
+    return libxlDomainPinVcpuFlags(dom, vcpu, cpumap, maplen,
+                                   VIR_DOMAIN_AFFECT_LIVE);
+}
+
 static int
 libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
                           unsigned char *cpumaps, int maplen,
@@ -4320,6 +4347,7 @@ static virDriver libxlDriver = {
     .domainSetVcpusFlags = libxlDomainSetVcpusFlags, /* 0.9.0 */
     .domainGetVcpusFlags = libxlDomainGetVcpusFlags, /* 0.9.0 */
     .domainPinVcpu = libxlDomainPinVcpu, /* 0.9.0 */
+    .domainPinVcpuFlags = libxlDomainPinVcpuFlags, /* 1.2.1 */
     .domainGetVcpus = libxlDomainGetVcpus, /* 0.9.0 */
     .domainGetVcpuPinInfo = libxlDomainGetVcpuPinInfo, /* 1.2.1 */
     .domainGetXMLDesc = libxlDomainGetXMLDesc, /* 0.9.0 */