]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virhostmem: Let caller pass max NUMA node to virHostMemAllocPages
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 19 Aug 2021 13:55:19 +0000 (15:55 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 23 Aug 2021 12:00:15 +0000 (14:00 +0200)
In all three cases (LXC, QEMU and VBox drivers) the caller has
access to host capabilities and thus know the maximum NUMA node.
This means, that virHostMemAllocPages() doesn't have to query
it. Querying may fail if libvirt was compiled without numactl
support.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/lxc/lxc_driver.c
src/qemu/qemu_driver.c
src/util/virhostmem.c
src/util/virhostmem.h
src/vbox/vbox_common.c

index f720cf968d84fc7c750d1cb4cdabadf6d275e277..e2720a6f893ba3f7aee5fc689d91802159010927 100644 (file)
@@ -5041,6 +5041,9 @@ lxcNodeAllocPages(virConnectPtr conn,
                   unsigned int cellCount,
                   unsigned int flags)
 {
+    virLXCDriver *driver = conn->privateData;
+    g_autoptr(virCaps) caps = NULL;
+    int lastCell;
     bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET);
 
     virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1);
@@ -5048,8 +5051,14 @@ lxcNodeAllocPages(virConnectPtr conn,
     if (virNodeAllocPagesEnsureACL(conn) < 0)
         return -1;
 
+    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
+        return -1;
+
+    lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa);
+
     return virHostMemAllocPages(npages, pageSizes, pageCounts,
-                                startCell, cellCount, add);
+                                startCell, cellCount,
+                                lastCell, add);
 }
 
 
index 6a065a9c0614296c208dfc538a7b692cee01e3fc..444e9e5cbc83be24fda4d5c7dd17576d25d44f33 100644 (file)
@@ -18802,6 +18802,9 @@ qemuNodeAllocPages(virConnectPtr conn,
                    unsigned int cellCount,
                    unsigned int flags)
 {
+    virQEMUDriver *driver = conn->privateData;
+    g_autoptr(virCaps) caps = NULL;
+    int lastCell;
     bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET);
 
     virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1);
@@ -18809,8 +18812,14 @@ qemuNodeAllocPages(virConnectPtr conn,
     if (virNodeAllocPagesEnsureACL(conn) < 0)
         return -1;
 
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        return -1;
+
+    lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa);
+
     return virHostMemAllocPages(npages, pageSizes, pageCounts,
-                                startCell, cellCount, add);
+                                startCell, cellCount,
+                                lastCell, add);
 }
 
 static int
index 43dd775fd3093364ab52ff48aaad3358c57109d7..8734dafb72e9669e19ba834e593fdadb8d2a5d8d 100644 (file)
@@ -885,14 +885,12 @@ virHostMemAllocPages(unsigned int npages,
                      unsigned long long *pageCounts,
                      int startCell,
                      unsigned int cellCount,
+                     int lastCell,
                      bool add)
 {
-    int cell, lastCell;
+    int cell;
     size_t i, ncounts = 0;
 
-    if ((lastCell = virNumaGetMaxNode()) < 0)
-        return 0;
-
     if (startCell > lastCell) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("start cell %d out of range (0-%d)"),
index ecfdd716188c91fd2b9168cb96b59ffaafc9dbab..3265215d84bbdb61254b2299e348f1e00abc052c 100644 (file)
@@ -53,4 +53,5 @@ int virHostMemAllocPages(unsigned int npages,
                          unsigned long long *pageCounts,
                          int startCell,
                          unsigned int cellCount,
+                         int lastCell,
                          bool add);
index 89f74b86d6020d5b7b047c4a825c0620ec5d82c6..7334254a3600f62e4487b6d51de91904c0b0b293 100644 (file)
@@ -7628,12 +7628,18 @@ vboxNodeAllocPages(virConnectPtr conn G_GNUC_UNUSED,
                    unsigned int cellCount,
                    unsigned int flags)
 {
+    struct _vboxDriver *driver = conn->privateData;
+    int lastCell;
     bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET);
 
     virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1);
 
+    virObjectLock(driver);
+    lastCell = virCapabilitiesHostNUMAGetMaxNode(driver->caps->host.numa);
+    virObjectUnlock(driver);
+
     return virHostMemAllocPages(npages, pageSizes, pageCounts,
-                                startCell, cellCount, add);
+                                startCell, cellCount, lastCell, add);
 }
 
 static int