[PATCH v2.1 05/21] refactor virDomainVcpuPinAdd()

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

 



---
 src/conf/domain_conf.c   |   81 ++++++++++++++++++----------------------------
 src/conf/domain_conf.h   |    3 +-
 src/libxl/libxl_driver.c |   13 +++++++-
 src/qemu/qemu_driver.c   |   26 +++++++++++++--
 src/xen/xend_internal.c  |   13 +++++++-
 5 files changed, 82 insertions(+), 54 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4e52177..56ee4c9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10921,69 +10921,52 @@ cleanup:
     return bitmap;
 }
 
-int
-virDomainVcpuPinAdd(virDomainDefPtr def,
-                    unsigned char *cpumap,
-                    int maplen,
-                    int vcpu)
+int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr *vcpupin_list,
+                        int *nvcpupin,
+                        unsigned char *cpumap,
+                        int maplen,
+                        int vcpu)
 {
-    virDomainVcpuPinDefPtr *vcpupin_list = NULL;
     virDomainVcpuPinDefPtr vcpupin = NULL;
     char *cpumask = NULL;
 
-    if ((cpumask = bitmapFromBytemap(cpumap, maplen)) == NULL)
-        goto cleanup;
-
-    /* No vcpupin exists yet. */
-    if (!def->cputune.nvcpupin) {
-        if (VIR_ALLOC(vcpupin) < 0) {
-            virReportOOMError();
-            goto cleanup;
-        }
+    if (!vcpupin_list)
+        return -1;
 
-        if (VIR_ALLOC(vcpupin_list) < 0) {
-            virReportOOMError();
-            VIR_FREE(vcpupin);
-            goto cleanup;
-        }
+    if ((cpumask = bitmapFromBytemap(cpumap, maplen)) == NULL)
+        return -1;
 
+    vcpupin = virDomainVcpuPinFindByVcpu(vcpupin_list,
+                                         *nvcpupin,
+                                         vcpu);
+    if (vcpupin) {
         vcpupin->vcpuid = vcpu;
         vcpupin->cpumask = cpumask;
-        vcpupin_list[def->cputune.nvcpupin++] = vcpupin;
 
-        def->cputune.vcpupin = vcpupin_list;
-    } else {
-        if (virDomainVcpuPinIsDuplicate(def->cputune.vcpupin,
-                                        def->cputune.nvcpupin,
-                                        vcpu)) {
-            vcpupin = virDomainVcpuPinFindByVcpu(def->cputune.vcpupin,
-                                                 def->cputune.nvcpupin,
-                                                 vcpu);
-            vcpupin->vcpuid = vcpu;
-            vcpupin->cpumask = cpumask;
-        } else {
-            if (VIR_ALLOC(vcpupin) < 0) {
-                virReportOOMError();
-                goto cleanup;
-            }
+        return 0;
+    }
+
+    /* No existing vcpupin matches vcpu, adding a new one */
+
+    if (VIR_ALLOC(vcpupin) < 0) {
+        virReportOOMError();
+        VIR_FREE(cpumask);
+        return -1;
+    }
+    vcpupin->vcpuid = vcpu;
+    vcpupin->cpumask = cpumask;
 
-            if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin + 1) < 0) {
-                virReportOOMError();
-                VIR_FREE(vcpupin);
-                goto cleanup;
-            }
 
-            vcpupin->vcpuid = vcpu;
-            vcpupin->cpumask = cpumask;
-            def->cputune.vcpupin[def->cputune.nvcpupin++] = vcpupin;
-       }
+    if (VIR_REALLOC_N(vcpupin_list, *nvcpupin + 1) < 0) {
+        virReportOOMError();
+        VIR_FREE(cpumask);
+        VIR_FREE(vcpupin);
+        return -1;
     }
 
-    return 0;
+    vcpupin_list[(*nvcpupin)++] = vcpupin;
 
-cleanup:
-    VIR_FREE(cpumask);
-    return -1;
+    return 0;
 }
 
 int
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 74abe6c..30aef6b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1968,7 +1968,8 @@ int virDomainCpuSetParse(const char *str,
 char *virDomainCpuSetFormat(char *cpuset,
                             int maxcpu);
 
-int virDomainVcpuPinAdd(virDomainDefPtr def,
+int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr *vcpupin_list,
+                        int *nvcpupin,
                         unsigned char *cpumap,
                         int maplen,
                         int vcpu);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 398a9a2..7881cd1 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2454,7 +2454,18 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
         goto cleanup;
     }
 
-    if (virDomainVcpuPinAdd(vm->def, cpumap, maplen, vcpu) < 0) {
+    if (!vm->def->cputune->vcpupin) {
+        if (VIR_ALLOC(vm->def->cputune->vcpupin) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+        vm->def->cputune->nvcpupin = 0;
+    }
+    if (virDomainVcpuPinAdd(vm->def->cputune->vcpupin
+                            &vm->def->cputune->nvcpupin,
+                            cpumap,
+                            maplen,
+                            vcpu) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("failed to update or add vcpupin xml"));
         goto cleanup;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 109d18d..17c66d7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3785,7 +3785,18 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
                 goto cleanup;
             }
         } else {
-            if (virDomainVcpuPinAdd(vm->def, cpumap, maplen, vcpu) < 0) {
+            if (!vm->def->cputune.vcpupin) {
+                if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) {
+                    virReportOOMError();
+                    goto cleanup;
+                }
+                vm->def->cputune.nvcpupin = 0;
+            }
+            if (virDomainVcpuPinAdd(vm->def->cputune.vcpupin,
+                                    &vm->def->cputune.nvcpupin,
+                                    cpumap,
+                                    maplen,
+                                    vcpu) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("failed to update or add vcpupin xml of "
                                  "a running domain"));
@@ -3807,7 +3818,18 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
                 goto cleanup;
             }
         } else {
-            if (virDomainVcpuPinAdd(persistentDef, cpumap, maplen, vcpu) < 0) {
+            if (!persistentDef->cputune.vcpupin) {
+                if (VIR_ALLOC(persistentDef->cputune.vcpupin) < 0) {
+                    virReportOOMError();
+                    goto cleanup;
+                }
+                persistentDef->cputune.nvcpupin = 0;
+            }
+            if (virDomainVcpuPinAdd(persistentDef->cputune.vcpupin,
+                                    &persistentDef->cputune.nvcpupin,
+                                    cpumap,
+                                    maplen,
+                                    vcpu) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                _("failed to update or add vcpupin xml of "
                                  "a persistent domain"));
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index f93b249..f29f533 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2296,7 +2296,18 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
         goto cleanup;
 
     if (ret == 0) {
-        if (virDomainVcpuPinAdd(def, cpumap, maplen, vcpu) < 0) {
+        if (!def->cputune.vcpupin) {
+            if (VIR_ALLOC(def->cputune.vcpupin) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+            def->cputune.nvcpupin = 0;
+        }
+        if (virDomainVcpuPinAdd(def->cputune->vcpupin,
+                                &def->cputune->nvcpupin,
+                                cpumap,
+                                maplen,
+                                vcpu) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("failed to add vcpupin xml entry"));
             return -1;
-- 
1.7.10.2

--
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]