From 0228fa11c0425e68f32172f4c985176474bed122 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Thu, 18 Sep 2014 09:47:07 +0200 Subject: [PATCH] nodeinfo: Implement nodeAllocPages And add stubs to other drivers like: lxc, qemu, uml and vbox. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/lxc/lxc_driver.c | 22 +++++++++++++++++++++ src/nodeinfo.c | 41 ++++++++++++++++++++++++++++++++++++++++ src/nodeinfo.h | 7 +++++++ src/qemu/qemu_driver.c | 22 +++++++++++++++++++++ src/uml/uml_driver.c | 22 +++++++++++++++++++++ src/vbox/vbox_common.c | 19 +++++++++++++++++++ 7 files changed, 134 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6657d3d42e..2019ef52d0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -893,6 +893,7 @@ virLockManagerRelease; # nodeinfo.h +nodeAllocPages; nodeCapsInitNUMA; nodeGetCellsFreeMemory; nodeGetCPUBitmap; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c3cd62c048..38763de1c4 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5685,6 +5685,27 @@ lxcNodeGetFreePages(virConnectPtr conn, } +static int +lxcNodeAllocPages(virConnectPtr conn, + unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + unsigned int flags) +{ + bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET); + + virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1); + + if (virNodeAllocPagesEnsureACL(conn) < 0) + return -1; + + return nodeAllocPages(npages, pageSizes, pageCounts, + startCell, cellCount, add); +} + + /* Function Tables */ static virDriver lxcDriver = { .no = VIR_DRV_LXC, @@ -5776,6 +5797,7 @@ static virDriver lxcDriver = { .domainReboot = lxcDomainReboot, /* 1.0.1 */ .domainLxcOpenNamespace = lxcDomainLxcOpenNamespace, /* 1.0.2 */ .nodeGetFreePages = lxcNodeGetFreePages, /* 1.2.6 */ + .nodeAllocPages = lxcNodeAllocPages, /* 1.2.8 */ }; static virStateDriver lxcStateDriver = { diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 3bc0c3cc47..2e2fffac11 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -2065,3 +2065,44 @@ nodeGetFreePages(unsigned int npages, cleanup: return ret; } + +int +nodeAllocPages(unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + bool add) +{ + int ret = -1; + int cell, lastCell; + 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)"), + startCell, lastCell); + goto cleanup; + } + + lastCell = MIN(lastCell, startCell + (int) cellCount - 1); + + for (cell = startCell; cell <= lastCell; cell++) { + for (i = 0; i < npages; i++) { + unsigned int page_size = pageSizes[i]; + unsigned long long page_count = pageCounts[i]; + + if (virNumaSetPagePoolSize(cell, page_size, page_count, add) < 0) + goto cleanup; + + ncounts++; + } + } + + ret = ncounts; + cleanup: + return ret; +} diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 0896c6c767..a993c6367d 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -63,4 +63,11 @@ int nodeGetFreePages(unsigned int npages, int startCell, unsigned int cellCount, unsigned long long *counts); + +int nodeAllocPages(unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + bool add); #endif /* __VIR_NODEINFO_H__*/ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 543de79e0f..4afd066205 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18142,6 +18142,27 @@ qemuConnectGetAllDomainStats(virConnectPtr conn, } +static int +qemuNodeAllocPages(virConnectPtr conn, + unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + unsigned int flags) +{ + bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET); + + virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1); + + if (virNodeAllocPagesEnsureACL(conn) < 0) + return -1; + + return nodeAllocPages(npages, pageSizes, pageCounts, + startCell, cellCount, add); +} + + static virDriver qemuDriver = { .no = VIR_DRV_QEMU, .name = QEMU_DRIVER_NAME, @@ -18341,6 +18362,7 @@ static virDriver qemuDriver = { .nodeGetFreePages = qemuNodeGetFreePages, /* 1.2.6 */ .connectGetDomainCapabilities = qemuConnectGetDomainCapabilities, /* 1.2.7 */ .connectGetAllDomainStats = qemuConnectGetAllDomainStats, /* 1.2.8 */ + .nodeAllocPages = qemuNodeAllocPages, /* 1.2.8 */ }; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 12b0ba72da..c255c07c16 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -2897,6 +2897,27 @@ umlNodeGetFreePages(virConnectPtr conn, } +static int +umlNodeAllocPages(virConnectPtr conn, + unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + unsigned int flags) +{ + bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET); + + virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1); + + if (virNodeAllocPagesEnsureACL(conn) < 0) + return -1; + + return nodeAllocPages(npages, pageSizes, pageCounts, + startCell, cellCount, add); +} + + static virDriver umlDriver = { .no = VIR_DRV_UML, .name = "UML", @@ -2959,6 +2980,7 @@ static virDriver umlDriver = { .nodeGetMemoryParameters = umlNodeGetMemoryParameters, /* 0.10.2 */ .nodeSetMemoryParameters = umlNodeSetMemoryParameters, /* 0.10.2 */ .nodeGetFreePages = umlNodeGetFreePages, /* 1.2.6 */ + .nodeAllocPages = umlNodeAllocPages, /* 1.2.8 */ }; static virStateDriver umlStateDriver = { diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 7ff0761f5e..e831255b03 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -7462,6 +7462,24 @@ vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED, return nodeGetFreePages(npages, pages, startCell, cellCount, counts); } +static int +vboxNodeAllocPages(virConnectPtr conn ATTRIBUTE_UNUSED, + unsigned int npages, + unsigned int *pageSizes, + unsigned long long *pageCounts, + int startCell, + unsigned int cellCount, + unsigned int flags) +{ + bool add = !(flags & VIR_NODE_ALLOC_PAGES_SET); + + virCheckFlags(VIR_NODE_ALLOC_PAGES_SET, -1); + + return nodeAllocPages(npages, pageSizes, pageCounts, + startCell, cellCount, add); +} + + /** * Function Tables */ @@ -7533,6 +7551,7 @@ virDriver vboxCommonDriver = { .domainSnapshotDelete = vboxDomainSnapshotDelete, /* 0.8.0 */ .connectIsAlive = vboxConnectIsAlive, /* 0.9.8 */ .nodeGetFreePages = vboxNodeGetFreePages, /* 1.2.6 */ + .nodeAllocPages = vboxNodeAllocPages, /* 1.2.8 */ }; static void updateDriver(void) -- GitLab