[libvirt] [PATCH 3/4] nodeinfo: Implement nodeAllocPages

Michal Privoznik mprivozn at redhat.com
Thu Sep 18 08:24:21 UTC 2014


And add stubs to other drivers like: lxc, qemu, uml and vbox.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/lxc/lxc_driver.c     | 22 ++++++++++++++++++++++
 src/nodeinfo.c           | 29 +++++++++++++++++++++++++++++
 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, 122 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index aabc11f..c75da80 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -891,6 +891,7 @@ virLockManagerRelease;
 
 
 # nodeinfo.h
+nodeAllocPages;
 nodeCapsInitNUMA;
 nodeGetCellsFreeMemory;
 nodeGetCPUBitmap;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index c3cd62c..38763de 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 af23b8b..4c92626 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -2053,3 +2053,32 @@ 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;
+    size_t i, ncounts = 0;
+
+    for (cell = startCell; cell < (int) (startCell + cellCount); 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 0896c6c..a993c63 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 5fd89a3..a8f3dca 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17953,6 +17953,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,
@@ -18152,6 +18173,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 12b0ba7..c255c07 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 7ff0761..e831255 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)
-- 
1.8.5.5




More information about the libvir-list mailing list