]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Refactor qemuDomainHelperGetVcpus by reusing virBitmapToDataBuf
authorPeter Krempa <pkrempa@redhat.com>
Fri, 29 May 2015 12:01:32 +0000 (14:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 3 Jun 2015 07:42:07 +0000 (09:42 +0200)
Get rid of the unnecessary allocation and copying of the bitmap and
clean up some unnecesary temporary variables.

src/qemu/qemu_driver.c

index 3fdc4483cea55defec8d5386208867a9e1807914..f32b87eb27c6f00f3659a55431f36b60a7ff620c 100644 (file)
@@ -1416,7 +1416,7 @@ static int
 qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
                          unsigned char *cpumaps, int maplen)
 {
-    int maxcpu, hostcpus;
+    int hostcpus;
     size_t i, v;
     qemuDomainObjPrivatePtr priv = vm->privateData;
 
@@ -1429,10 +1429,6 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
         return -1;
     }
 
-    maxcpu = maplen * 8;
-    if (maxcpu > hostcpus)
-        maxcpu = hostcpus;
-
     /* Clamp to actual number of vcpus */
     if (maxinfo > priv->nvcpupids)
         maxinfo = priv->nvcpupids;
@@ -1457,25 +1453,15 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
         }
 
         if (cpumaps != NULL) {
-            memset(cpumaps, 0, maplen * maxinfo);
             for (v = 0; v < maxinfo; v++) {
                 unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
                 virBitmapPtr map = NULL;
-                unsigned char *tmpmap = NULL;
-                int tmpmapLen = 0;
 
                 if (virProcessGetAffinity(priv->vcpupids[v],
-                                          &map, maxcpu) < 0)
+                                          &map, hostcpus) < 0)
                     return -1;
-                if (virBitmapToData(map, &tmpmap, &tmpmapLen) < 0) {
-                    virBitmapFree(map);
-                    return -1;
-                }
-                if (tmpmapLen > maplen)
-                    tmpmapLen = maplen;
-                memcpy(cpumap, tmpmap, tmpmapLen);
 
-                VIR_FREE(tmpmap);
+                virBitmapToDataBuf(map, cpumap, maplen);
                 virBitmapFree(map);
             }
         }