[PATCH 5/7] qemu: qemuDomainHotplugVcpus - separate out pin adjustment code

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

 



Impending IOThread setting patches would copy the code anyway, so create
and generalize the adding of pindef for the vcpu into its own API

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 104 +++++++++++++++++++++++++++++--------------------
 1 file changed, 62 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 673b95e..1fca43c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4669,6 +4669,63 @@ qemuDomainHotplugAddCgroup(virCgroupPtr cgroup,
     return NULL;
 }
 
+typedef int cgroupSetupFunc(virCgroupPtr cgroup,
+                            virDomainPinDefPtr *pindef,
+                            int npin,
+                            int id);
+
+static int
+qemuDomainHotplugAddPin(virBitmapPtr cpumask,
+                        int index,
+                        pid_t pid,
+                        virDomainPinDefPtr **pindef_list,
+                        size_t *npin,
+                        cgroupSetupFunc func,
+                        virCgroupPtr cgroup)
+{
+    int ret = -1;
+    virDomainPinDefPtr pindef = NULL;
+
+    /* vm->def->cputune.* arrays can't be NULL if
+     * vm->def->cpumask is not NULL.
+     */
+    if (VIR_ALLOC(pindef) < 0)
+        goto cleanup;
+
+    if (!(pindef->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN))) {
+        VIR_FREE(pindef);
+        goto cleanup;
+    }
+    virBitmapCopy(pindef->cpumask, cpumask);
+    pindef->id = index;
+    if (VIR_APPEND_ELEMENT_COPY(*pindef_list, *npin, pindef) < 0) {
+        virBitmapFree(pindef->cpumask);
+        VIR_FREE(pindef);
+        goto cleanup;
+    }
+
+    if (cgroup) {
+        if (func(cgroup, *pindef_list, *npin, index) < 0) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("failed to set cpuset.cpus in cgroup for id %d"),
+                           index);
+            goto cleanup;
+        }
+    } else {
+        if (virProcessSetAffinity(pid, pindef->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
 qemuDomainHotplugDelCgroupPin(virCgroupPtr cgroup,
                               cgroupNewFunc func,
@@ -4795,51 +4852,14 @@ 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 =
-                      virBitmapNew(VIR_DOMAIN_CPUMASK_LEN))) {
-                    VIR_FREE(vcpupin);
-                    goto cleanup;
-                }
-                virBitmapCopy(vcpupin->cpumask, vm->def->cpumask);
-                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 (qemuDomainHotplugAddPin(vm->def->cpumask, i, cpupids[i],
+                                            &vm->def->cputune.vcpupin,
+                                            &vm->def->cputune.nvcpupin,
+                                            qemuSetupCgroupVcpuPin,
+                                            cgroup_vcpu) < 0)
                     ret = -1;
                     goto cleanup;
-                }
-
-                if (cgroup_vcpu) {
-                    if (qemuSetupCgroupVcpuPin(cgroup_vcpu,
-                                               vm->def->cputune.vcpupin,
-                                               vm->def->cputune.nvcpupin, i) < 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],
-- 
2.1.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]