]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: qemuDomainHotplugVcpus - separate out pin adjustment code
authorJohn Ferlan <jferlan@redhat.com>
Wed, 8 Apr 2015 13:25:47 +0000 (09:25 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 10 Apr 2015 20:02:40 +0000 (16:02 -0400)
Future IOThread setting patches would copy the code anyway, so create
and generalize the adding of pindef for the vcpu and the pinning of the
thread into their own APIs.

src/qemu/qemu_driver.c

index 7eb5a7d5d4b4f6f9426adae1de0a043c85cffe90..f37a11e3974ee1690be79e81265605799bab8464 100644 (file)
@@ -4669,6 +4669,64 @@ qemuDomainAddCgroupForThread(virCgroupPtr cgroup,
     return NULL;
 }
 
+static int
+qemuDomainHotplugAddPin(virBitmapPtr cpumask,
+                        int index,
+                        virDomainPinDefPtr **pindef_list,
+                        size_t *npin)
+{
+    int ret = -1;
+    virDomainPinDefPtr pindef = NULL;
+
+    if (VIR_ALLOC(pindef) < 0)
+        goto cleanup;
+
+    if (!(pindef->cpumask = virBitmapNewCopy(cpumask))) {
+        VIR_FREE(pindef);
+        goto cleanup;
+    }
+    pindef->id = index;
+    if (VIR_APPEND_ELEMENT_COPY(*pindef_list, *npin, pindef) < 0) {
+        virBitmapFree(pindef->cpumask);
+        VIR_FREE(pindef);
+        goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
+static int
+qemuDomainHotplugPinThread(virBitmapPtr cpumask,
+                           int index,
+                           pid_t pid,
+                           virCgroupPtr cgroup)
+{
+    int ret = -1;
+
+    if (cgroup) {
+        if (qemuSetupCgroupCpusetCpus(cgroup, cpumask) < 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("failed to set cpuset.cpus in cgroup for id %d"),
+                           index);
+            goto cleanup;
+        }
+    } else {
+        if (virProcessSetAffinity(pid, cpumask) < 0) {
+            virReportError(VIR_ERR_SYSTEM_ERROR,
+                           _("failed to set cpu affinity for id %d"),
+                           index);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
 static int
 qemuDomainDelCgroupForThread(virCgroupPtr cgroup,
                              virCgroupThreadName nameval,
@@ -4791,48 +4849,18 @@ qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
 
             /* Inherit def->cpuset */
             if (vm->def->cpumask) {
-                /* vm->def->cputune.vcpupin can't be NULL if
-                 * vm->def->cpumask is not NULL.
-                 */
-                virDomainPinDefPtr vcpupin = NULL;
-
-                if (VIR_ALLOC(vcpupin) < 0)
-                    goto cleanup;
-
-                if (!(vcpupin->cpumask = virBitmapNewCopy(vm->def->cpumask))) {
-                    VIR_FREE(vcpupin);
+                if (qemuDomainHotplugAddPin(vm->def->cpumask, i,
+                                            &vm->def->cputune.vcpupin,
+                                            &vm->def->cputune.nvcpupin) < 0) {
+                    ret = -1;
                     goto cleanup;
                 }
-                vcpupin->id = i;
-                if (VIR_APPEND_ELEMENT_COPY(vm->def->cputune.vcpupin,
-                                            vm->def->cputune.nvcpupin, vcpupin) < 0) {
-                    virBitmapFree(vcpupin->cpumask);
-                    VIR_FREE(vcpupin);
+                if (qemuDomainHotplugPinThread(vm->def->cpumask, i, cpupids[i],
+                                               cgroup_vcpu) < 0) {
                     ret = -1;
                     goto cleanup;
                 }
-
-                if (cgroup_vcpu) {
-                    if (qemuSetupCgroupCpusetCpus(cgroup_vcpu,
-                                                  vcpupin->cpumask) < 0) {
-                        virReportError(VIR_ERR_OPERATION_INVALID,
-                                       _("failed to set cpuset.cpus in cgroup"
-                                         " for vcpu %zu"), i);
-                        ret = -1;
-                        goto cleanup;
-                    }
-                } else {
-                    if (virProcessSetAffinity(cpupids[i],
-                                              vcpupin->cpumask) < 0) {
-                        virReportError(VIR_ERR_SYSTEM_ERROR,
-                                       _("failed to set cpu affinity for vcpu %zu"),
-                                       i);
-                        ret = -1;
-                        goto cleanup;
-                    }
-                }
             }
-
             virCgroupFree(&cgroup_vcpu);
 
             if (qemuProcessSetSchedParams(i, cpupids[i],