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 virHostMemGetFreePages() doesn't have to query it. Querying may fail if libvirt was compiled without numactl support. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/lxc/lxc_driver.c | 12 +++++++++++- src/qemu/qemu_driver.c | 12 +++++++++++- src/util/virhostmem.c | 6 ++---- src/util/virhostmem.h | 1 + src/vbox/vbox_common.c | 12 ++++++++++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 8f2ca19f44..f720cf968d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5013,12 +5013,22 @@ lxcNodeGetFreePages(virConnectPtr conn, unsigned long long *counts, unsigned int flags) { + virLXCDriver *driver = conn->privateData; + g_autoptr(virCaps) caps = NULL; + int lastCell; + virCheckFlags(0, -1); if (virNodeGetFreePagesEnsureACL(conn) < 0) return -1; - return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts); + if (!(caps = virLXCDriverGetCapabilities(driver, false))) + return -1; + + lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa); + + return virHostMemGetFreePages(npages, pages, startCell, cellCount, + lastCell, counts); } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f31e13889e..6a065a9c06 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17428,12 +17428,22 @@ qemuNodeGetFreePages(virConnectPtr conn, unsigned long long *counts, unsigned int flags) { + virQEMUDriver *driver = conn->privateData; + g_autoptr(virCaps) caps = NULL; + int lastCell; + virCheckFlags(0, -1); if (virNodeGetFreePagesEnsureACL(conn) < 0) return -1; - return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts); + if (!(caps = virQEMUDriverGetCapabilities(driver, false))) + return -1; + + lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa); + + return virHostMemGetFreePages(npages, pages, startCell, cellCount, + lastCell, counts); } diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index 8aa675cb4f..43dd775fd3 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -843,14 +843,12 @@ virHostMemGetFreePages(unsigned int npages, unsigned int *pages, int startCell, unsigned int cellCount, + int lastCell, unsigned long long *counts) { - 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 1369829807..ecfdd71618 100644 --- a/src/util/virhostmem.h +++ b/src/util/virhostmem.h @@ -45,6 +45,7 @@ int virHostMemGetFreePages(unsigned int npages, unsigned int *pages, int startCell, unsigned int cellCount, + int lastCell, unsigned long long *counts); int virHostMemAllocPages(unsigned int npages, diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index ecdcdbe88d..89f74b86d6 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7598,7 +7598,7 @@ vboxNodeGetFreeMemory(virConnectPtr conn G_GNUC_UNUSED) } static int -vboxNodeGetFreePages(virConnectPtr conn G_GNUC_UNUSED, +vboxNodeGetFreePages(virConnectPtr conn, unsigned int npages, unsigned int *pages, int startCell, @@ -7606,9 +7606,17 @@ vboxNodeGetFreePages(virConnectPtr conn G_GNUC_UNUSED, unsigned long long *counts, unsigned int flags) { + struct _vboxDriver *driver = conn->privateData; + int lastCell; + virCheckFlags(0, -1); - return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts); + virObjectLock(driver); + lastCell = virCapabilitiesHostNUMAGetMaxNode(driver->caps->host.numa); + virObjectUnlock(driver); + + return virHostMemGetFreePages(npages, pages, startCell, + cellCount, lastCell, counts); } static int -- 2.31.1