render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 75f3f4ed1356eba49f472206bb9bb0eeae728ba6 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <75f3f4ed1356eba49f472206bb9bb0eeae728ba6@dist-git>
7a3408
From: Martin Kletzander <mkletzan@redhat.com>
7a3408
Date: Tue, 6 Oct 2015 15:20:33 +0200
7a3408
Subject: [PATCH] qemu: Extract -mem-path building into its own function
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1266856
7a3408
7a3408
That function is called qemuBuildMemPathStr() and will be used in
7a3408
other places in the future.  The change in the test suite is proper due
7a3408
to the fact that -mem-prealloc makes only sense with -mem-path (from
7a3408
qemu documentation -- html/qemu-doc.html).
7a3408
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
(cherry picked from commit ad8ab88c9141afb9b7541c67f3d0966d5a1b31cd)
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_command.c                            | 120 ++++++++++++---------
7a3408
 .../qemuxml2argv-hugepages-pages6.args             |   2 +-
7a3408
 2 files changed, 73 insertions(+), 49 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
7a3408
index 53c9d01..0822ee4 100644
7a3408
--- a/src/qemu/qemu_command.c
7a3408
+++ b/src/qemu/qemu_command.c
7a3408
@@ -7705,6 +7705,71 @@ qemuBuildSmpArgStr(const virDomainDef *def,
7a3408
 }
7a3408
 
7a3408
 static int
7a3408
+qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
7a3408
+                    virDomainDefPtr def,
7a3408
+                    virQEMUCapsPtr qemuCaps,
7a3408
+                    virCommandPtr cmd)
7a3408
+{
7a3408
+    const long system_page_size = virGetSystemPageSizeKB();
7a3408
+    char *mem_path = NULL;
7a3408
+    size_t i = 0;
7a3408
+
7a3408
+    /*
7a3408
+     *  No-op if hugepages were not requested.
7a3408
+     */
7a3408
+    if (!def->mem.nhugepages)
7a3408
+        return 0;
7a3408
+
7a3408
+    /* There is one special case: if user specified "huge"
7a3408
+     * pages of regular system pages size.
7a3408
+     * And there is nothing to do in this case.
7a3408
+     */
7a3408
+    if (def->mem.hugepages[0].size == system_page_size)
7a3408
+        return 0;
7a3408
+
7a3408
+    if (!cfg->nhugetlbfs) {
7a3408
+        virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
+                       "%s", _("hugetlbfs filesystem is not mounted "
7a3408
+                               "or disabled by administrator config"));
7a3408
+        return -1;
7a3408
+    }
7a3408
+
7a3408
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_PATH)) {
7a3408
+        virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
+                       _("hugepage backing not supported by '%s'"),
7a3408
+                       def->emulator);
7a3408
+        return -1;
7a3408
+    }
7a3408
+
7a3408
+    if (!def->mem.hugepages[0].size) {
7a3408
+        if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
7a3408
+                                                cfg->nhugetlbfs)))
7a3408
+            return -1;
7a3408
+    } else {
7a3408
+        for (i = 0; i < cfg->nhugetlbfs; i++) {
7a3408
+            if (cfg->hugetlbfs[i].size == def->mem.hugepages[0].size)
7a3408
+                break;
7a3408
+        }
7a3408
+
7a3408
+        if (i == cfg->nhugetlbfs) {
7a3408
+            virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
+                           _("Unable to find any usable hugetlbfs "
7a3408
+                             "mount for %llu KiB"),
7a3408
+                           def->mem.hugepages[0].size);
7a3408
+            return -1;
7a3408
+        }
7a3408
+
7a3408
+        if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
7a3408
+            return -1;
7a3408
+    }
7a3408
+
7a3408
+    virCommandAddArgList(cmd, "-mem-prealloc", "-mem-path", mem_path, NULL);
7a3408
+    VIR_FREE(mem_path);
7a3408
+
7a3408
+    return 0;
7a3408
+}
7a3408
+
7a3408
+static int
7a3408
 qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
7a3408
                     virDomainDefPtr def,
7a3408
                     virCommandPtr cmd,
7a3408
@@ -9074,54 +9139,13 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
        virCommandAddArgFormat(cmd, "%llu", virDomainDefGetMemoryInitial(def) / 1024);
7a3408
     }
7a3408
 
7a3408
-    if (def->mem.nhugepages && !virDomainNumaGetNodeCount(def->numa)) {
7a3408
-        const long system_page_size = virGetSystemPageSizeKB();
7a3408
-        char *mem_path = NULL;
7a3408
-
7a3408
-        if (def->mem.hugepages[0].size == system_page_size) {
7a3408
-            /* There is one special case: if user specified "huge"
7a3408
-             * pages of regular system pages size. */
7a3408
-        } else {
7a3408
-            if (!cfg->nhugetlbfs) {
7a3408
-                virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
-                               "%s", _("hugetlbfs filesystem is not mounted "
7a3408
-                                       "or disabled by administrator config"));
7a3408
-                goto error;
7a3408
-            }
7a3408
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_PATH)) {
7a3408
-                virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
-                               _("hugepage backing not supported by '%s'"),
7a3408
-                               def->emulator);
7a3408
-                goto error;
7a3408
-            }
7a3408
-
7a3408
-            if (def->mem.hugepages[0].size) {
7a3408
-                for (j = 0; j < cfg->nhugetlbfs; j++) {
7a3408
-                    if (cfg->hugetlbfs[j].size == def->mem.hugepages[0].size)
7a3408
-                        break;
7a3408
-                }
7a3408
-
7a3408
-                if (j == cfg->nhugetlbfs) {
7a3408
-                    virReportError(VIR_ERR_INTERNAL_ERROR,
7a3408
-                                   _("Unable to find any usable hugetlbfs mount for %llu KiB"),
7a3408
-                                   def->mem.hugepages[0].size);
7a3408
-                    goto error;
7a3408
-                }
7a3408
-
7a3408
-                if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[j])))
7a3408
-                    goto error;
7a3408
-            } else {
7a3408
-                if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
7a3408
-                                                        cfg->nhugetlbfs)))
7a3408
-                    goto error;
7a3408
-            }
7a3408
-        }
7a3408
-
7a3408
-        virCommandAddArg(cmd, "-mem-prealloc");
7a3408
-        if (mem_path)
7a3408
-            virCommandAddArgList(cmd, "-mem-path", mem_path, NULL);
7a3408
-        VIR_FREE(mem_path);
7a3408
-    }
7a3408
+    /*
7a3408
+     * Add '-mem-path' (and '-mem-prealloc') parameter here only if
7a3408
+     * there is no numa node specified.
7a3408
+     */
7a3408
+    if (!virDomainNumaGetNodeCount(def->numa) &&
7a3408
+        qemuBuildMemPathStr(cfg, def, qemuCaps, cmd) < 0)
7a3408
+        goto error;
7a3408
 
7a3408
     if (def->mem.locked && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_MLOCK)) {
7a3408
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages6.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages6.args
7a3408
index 4eccb86..a3a4e57 100644
7a3408
--- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages6.args
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages6.args
7a3408
@@ -1,4 +1,4 @@
7a3408
 LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
7a3408
-/usr/bin/qemu -S -M pc -m 1024 -mem-prealloc -smp 2 -nographic \
7a3408
+/usr/bin/qemu -S -M pc -m 1024 -smp 2 -nographic \
7a3408
 -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
7a3408
 -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none
7a3408
-- 
7a3408
2.6.1
7a3408