]> xenbits.xensource.com Git - libvirt.git/commitdiff
virCapabilitiesHostNUMAAddCell: Take double pointer
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 29 Apr 2021 16:58:40 +0000 (18:58 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 May 2021 13:16:25 +0000 (15:16 +0200)
What this function really does it takes ownership of all pointers
passed (well, except for the first one - caps - to which it
registers new NUMA node). But since all info is passed as a
single pointer it's hard to tell (and use g_auto*). Let's use
double pointers to make the ownership transfer obvious.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/capabilities.c
src/conf/capabilities.h
src/libxl/libxl_capabilities.c
src/test/test_driver.c
tests/testutils.c

index 4d509a6d28348fac6604692d2c500d9042451ec9..ea07afc92077566d94d60489e9ed6cb463be7161 100644 (file)
@@ -330,36 +330,45 @@ virCapabilitiesSetNetPrefix(virCaps *caps,
  * @num: ID number of NUMA cell
  * @mem: Total size of memory in the NUMA node (in KiB)
  * @ncpus: number of CPUs in cell
- * @cpus: array of CPU definition structures, the pointer is stolen
+ * @cpus: array of CPU definition structures
  * @nsiblings: number of sibling NUMA nodes
  * @siblings: info on sibling NUMA nodes
  * @npageinfo: number of pages at node @num
  * @pageinfo: info on each single memory page
  *
- * Registers a new NUMA cell for a host, passing in a
- * array of CPU IDs belonging to the cell
+ * Registers a new NUMA cell for a host, passing in a array of
+ * CPU IDs belonging to the cell, distances to other NUMA nodes
+ * and info on hugepages on the node.
+ *
+ * All pointers are stolen.
  */
 void
 virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps,
                                int num,
                                unsigned long long mem,
                                int ncpus,
-                               virCapsHostNUMACellCPU *cpus,
+                               virCapsHostNUMACellCPU **cpus,
                                int nsiblings,
-                               virCapsHostNUMACellSiblingInfo *siblings,
+                               virCapsHostNUMACellSiblingInfo **siblings,
                                int npageinfo,
-                               virCapsHostNUMACellPageInfo *pageinfo)
+                               virCapsHostNUMACellPageInfo **pageinfo)
 {
     virCapsHostNUMACell *cell = g_new0(virCapsHostNUMACell, 1);
 
     cell->num = num;
     cell->mem = mem;
-    cell->ncpus = ncpus;
-    cell->cpus = cpus;
-    cell->nsiblings = nsiblings;
-    cell->siblings = siblings;
-    cell->npageinfo = npageinfo;
-    cell->pageinfo = pageinfo;
+    if (cpus) {
+        cell->ncpus = ncpus;
+        cell->cpus = g_steal_pointer(cpus);
+    }
+    if (siblings) {
+        cell->nsiblings = nsiblings;
+        cell->siblings = g_steal_pointer(siblings);
+    }
+    if (pageinfo) {
+        cell->npageinfo = npageinfo;
+        cell->pageinfo = g_steal_pointer(pageinfo);
+    }
 
     g_ptr_array_add(caps->cells, cell);
 }
@@ -1568,7 +1577,7 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps)
 
         virCapabilitiesHostNUMAAddCell(caps, 0,
                                        nodeinfo.memory,
-                                       cid, cpus,
+                                       cid, &cpus,
                                        0, NULL,
                                        0, NULL);
     }
@@ -1633,13 +1642,9 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps)
         memory >>= 10;
 
         virCapabilitiesHostNUMAAddCell(caps, n, memory,
-                                       ncpus, cpus,
-                                       nsiblings, siblings,
-                                       npageinfo, pageinfo);
-
-        cpus = NULL;
-        siblings = NULL;
-        pageinfo = NULL;
+                                       ncpus, &cpus,
+                                       nsiblings, &siblings,
+                                       npageinfo, &pageinfo);
         virBitmapFree(cpumap);
         cpumap = NULL;
     }
index 66cae4b9022393409ed0a54c82e905b897a2b9e5..ba863447c07d08510c37e4d9da08a149fc3004c1 100644 (file)
@@ -254,11 +254,11 @@ virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps,
                                int num,
                                unsigned long long mem,
                                int ncpus,
-                               virCapsHostNUMACellCPU *cpus,
+                               virCapsHostNUMACellCPU **cpus,
                                int nsiblings,
-                               virCapsHostNUMACellSiblingInfo *siblings,
+                               virCapsHostNUMACellSiblingInfo **siblings,
                                int npageinfo,
-                               virCapsHostNUMACellPageInfo *pageinfo);
+                               virCapsHostNUMACellPageInfo **pageinfo);
 
 virCapsGuestMachine **
 virCapabilitiesAllocMachines(const char *const *names,
index 6c1199552d5eb1d1996f639046851d96bd9e5860..ea4f370a6d74552531a0778766c15d6720680ddf 100644 (file)
@@ -330,8 +330,8 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps)
 
         virCapabilitiesHostNUMAAddCell(caps->host.numa, i,
                                        numa_info[i].size / 1024,
-                                       nr_cpus_node[i], cpus[i],
-                                       nr_siblings, siblings,
+                                       nr_cpus_node[i], &cpus[i],
+                                       nr_siblings, &siblings,
                                        0, NULL);
 
         /* This is safe, as the CPU list is now stored in the NUMA cell */
index 15e9018803a05539bd44f091aefcf33a36a2fdec..ea5a5005e7d36af8cedd9f91ad4125ac79e8ee87 100644 (file)
@@ -329,8 +329,9 @@ testBuildCapabilities(virConnectPtr conn)
 
         virCapabilitiesHostNUMAAddCell(caps->host.numa,
                                        i, privconn->cells[i].mem,
-                                       privconn->cells[i].numCpus,
-                                       cpu_cells, 0, NULL, nPages, pages);
+                                       privconn->cells[i].numCpus, &cpu_cells,
+                                       0, NULL,
+                                       nPages, &pages);
     }
 
     for (i = 0; i < G_N_ELEMENTS(guest_types); i++) {
index c39797e51d852ddfc2cca5fd5e4ecc713758390a..d6b7c2a5800d76c1a959ea43851c022bf8e1b82a 100644 (file)
@@ -935,9 +935,9 @@ virTestCapsBuildNUMATopology(int seq)
 
         virCapabilitiesHostNUMAAddCell(caps, cell_id + seq,
                                        MAX_MEM_IN_CELL,
-                                       MAX_CPUS_IN_CELL, cell_cpus,
-                                       VIR_ARCH_NONE, NULL,
-                                       VIR_ARCH_NONE, NULL);
+                                       MAX_CPUS_IN_CELL, &cell_cpus,
+                                       0, NULL,
+                                       0, NULL);
 
         cell_cpus = NULL;
     }