[PATCH 05/35] qemu: Use virBitmapToDataBuf in qemuDomainGetVcpuPinInfo

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

 



Reuse the function so that we can get rid of a lot of temporary
allocations.
---
 src/qemu/qemu_driver.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e34cb6c..f6107b7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5291,8 +5291,8 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     virDomainDefPtr targetDef = NULL;
     int ret = -1;
     int hostcpus, vcpu;
-    unsigned char *cpumap;
     virCapsPtr caps = NULL;
+    virBitmapPtr allcpumap = NULL;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -5319,6 +5319,11 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     if ((hostcpus = nodeGetCPUCount()) < 0)
         goto cleanup;

+    if (!(allcpumap = virBitmapNew(hostcpus)))
+        goto cleanup;
+
+    virBitmapSetAll(allcpumap);
+
     /* Clamp to actual number of vcpus */
     if (ncpumaps > targetDef->vcpus)
         ncpumaps = targetDef->vcpus;
@@ -5329,37 +5334,23 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
     for (vcpu = 0; vcpu < ncpumaps; vcpu++) {
         virDomainPinDefPtr pininfo;
         virBitmapPtr bitmap = NULL;
-        unsigned char *tmpmap = NULL;
-        int tmpmaplen;

         pininfo = virDomainPinFind(targetDef->cputune.vcpupin,
                                    targetDef->cputune.nvcpupin,
                                    vcpu);
-        if (!pininfo) {
-            if (!(bitmap = virBitmapNew(hostcpus)))
-                goto cleanup;
-            virBitmapSetAll(bitmap);
-        } else {
+
+        if (pininfo && pininfo->cpumask)
             bitmap = pininfo->cpumask;
-        }
+        else
+            bitmap = allcpumap;

-        if (virBitmapToData(bitmap, &tmpmap, &tmpmaplen) < 0) {
-            if (!pininfo)
-                virBitmapFree(bitmap);
-            goto cleanup;
-        }
-        if (tmpmaplen > maplen)
-            tmpmaplen = maplen;
-        cpumap = VIR_GET_CPUMAP(cpumaps, maplen, vcpu);
-        memcpy(cpumap, tmpmap, tmpmaplen);
-        if (!pininfo)
-            virBitmapFree(bitmap);
-        VIR_FREE(tmpmap);
+        virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, vcpu), maplen);
     }

     ret = ncpumaps;

  cleanup:
+    virBitmapFree(allcpumap);
     virDomainObjEndAPI(&vm);
     virObjectUnref(caps);
     return ret;
-- 
2.4.1

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