[PATCH 3/5] virhostmem: Let caller pass max NUMA node to virHostMemAllocPages

Michal Privoznik mprivozn at redhat.com
Thu Aug 19 14:27:03 UTC 2021


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 at redhat.com>
---
 src/lxc/lxc_driver.c   | 11 ++++++++++-
 src/qemu/qemu_driver.c | 11 ++++++++++-
 src/util/virhostmem.c  |  6 ++----
 src/util/virhostmem.h  |  1 +
 src/vbox/vbox_common.c |  8 +++++++-
 5 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index f720cf968d..e2720a6f89 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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);
 }
 
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6a065a9c06..444e9e5cbc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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
diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c
index 43dd775fd3..8734dafb72 100644
--- a/src/util/virhostmem.c
+++ b/src/util/virhostmem.c
@@ -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)"),
diff --git a/src/util/virhostmem.h b/src/util/virhostmem.h
index ecfdd71618..3265215d84 100644
--- a/src/util/virhostmem.h
+++ b/src/util/virhostmem.h
@@ -53,4 +53,5 @@ int virHostMemAllocPages(unsigned int npages,
                          unsigned long long *pageCounts,
                          int startCell,
                          unsigned int cellCount,
+                         int lastCell,
                          bool add);
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 89f74b86d6..7334254a36 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -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
-- 
2.31.1




More information about the libvir-list mailing list