[libvirt] [PATCH 03/10] qemu: command: Make qemuBuildMemoryBackendStr usable without NUMA

Peter Krempa pkrempa at redhat.com
Fri Oct 16 12:11:40 UTC 2015


Make the function usable so that -1 can be passed to it as cell ID so
that we can later enable memory hotplug on non-NUMA guests for certain
architectures.

I've inspected all functions that take guestNode as an argument to
verify that they are eiter safe to be called or are not called at all.
---
 src/qemu/qemu_command.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f727d0b..a37a4fa 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5011,7 +5011,8 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
  * qemuBuildMemoryBackendStr:
  * @size: size of the memory device in kibibytes
  * @pagesize: size of the requested memory page in KiB, 0 for default
- * @guestNode: NUMA node in the guest that the memory object will be attached to
+ * @guestNode: NUMA node in the guest that the memory object will be attached
+ *             to, or -1 if NUMA is not used in the guest
  * @hostNodes: map of host nodes to alloc the memory in, NULL for default
  * @autoNodeset: fallback nodeset in case of automatic numa placement
  * @def: domain definition object
@@ -5058,7 +5059,8 @@ qemuBuildMemoryBackendStr(unsigned long long size,
     *backendType = NULL;

     /* memory devices could provide a invalid guest node */
-    if (guestNode >= virDomainNumaGetNodeCount(def->numa)) {
+    if (guestNode >= 0 &&
+        guestNode >= virDomainNumaGetNodeCount(def->numa)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("can't add memory backend for guest node '%d' as "
                          "the guest has only '%zu' NUMA nodes configured"),
@@ -5069,7 +5071,9 @@ qemuBuildMemoryBackendStr(unsigned long long size,
     if (!(props = virJSONValueNewObject()))
         return -1;

-    memAccess = virDomainNumaGetNodeMemoryAccessMode(def->numa, guestNode);
+    if (guestNode >= 0)
+        memAccess = virDomainNumaGetNodeMemoryAccessMode(def->numa, guestNode);
+
     if (virDomainNumatuneGetMode(def->numa, guestNode, &mode) < 0 &&
         virDomainNumatuneGetMode(def->numa, -1, &mode) < 0)
         mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
@@ -5086,6 +5090,10 @@ qemuBuildMemoryBackendStr(unsigned long long size,
                 continue;
             }

+            /* just find the master hugepage in case we don't use NUMA */
+            if (guestNode < 0)
+                continue;
+
             if (virBitmapGetBit(hugepage->nodemask, guestNode,
                                 &thisHugepage) < 0) {
                 /* Ignore this error. It's not an error after all. Well,
-- 
2.4.5




More information about the libvir-list mailing list