[PATCH 2/2] qemu: Introduce qemuGetHupageMemPath

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that we have two same implementations for getting path for
huge pages backed guest memory, lets merge them into one function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 63 ++++---------------------------------------------
 src/qemu/qemu_conf.c    | 50 +++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_conf.h    |  4 ++++
 3 files changed, 59 insertions(+), 58 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 0bafc3f..051a0bc 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3275,35 +3275,9 @@ qemuBuildMemoryBackendStr(unsigned long long size,
     if (!(props = virJSONValueNewObject()))
         return -1;
 
-    if (pagesize || hugepage) {
-        if (pagesize) {
-            /* Now lets see, if the huge page we want to use is even mounted
-             * and ready to use */
-            for (i = 0; i < cfg->nhugetlbfs; i++) {
-                if (cfg->hugetlbfs[i].size == pagesize)
-                    break;
-            }
-
-            if (i == cfg->nhugetlbfs) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("Unable to find any usable hugetlbfs mount for %llu KiB"),
-                               pagesize);
-                goto cleanup;
-            }
-
-            if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
-                goto cleanup;
-        } else {
-            if (!cfg->nhugetlbfs) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               "%s", _("hugetlbfs filesystem is not mounted "
-                                       "or disabled by administrator config"));
-                goto cleanup;
-            }
-            if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
-                                                    cfg->nhugetlbfs)))
-                goto cleanup;
-        }
+    if (pagesize) {
+        if (qemuGetHupageMemPath(cfg, pagesize, &mem_path) < 0)
+            goto cleanup;
 
         *backendType = "memory-backend-file";
 
@@ -7272,7 +7246,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
 {
     const long system_page_size = virGetSystemPageSizeKB();
     char *mem_path = NULL;
-    size_t i = 0;
 
     /*
      *  No-op if hugepages were not requested.
@@ -7287,13 +7260,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
     if (def->mem.hugepages[0].size == system_page_size)
         return 0;
 
-    if (!cfg->nhugetlbfs) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("hugetlbfs filesystem is not mounted "
-                               "or disabled by administrator config"));
-        return -1;
-    }
-
     if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_MEM_PATH)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("hugepage backing not supported by '%s'"),
@@ -7301,27 +7267,8 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
         return -1;
     }
 
-    if (!def->mem.hugepages[0].size) {
-        if (!(mem_path = qemuGetDefaultHugepath(cfg->hugetlbfs,
-                                                cfg->nhugetlbfs)))
-            return -1;
-    } else {
-        for (i = 0; i < cfg->nhugetlbfs; i++) {
-            if (cfg->hugetlbfs[i].size == def->mem.hugepages[0].size)
-                break;
-        }
-
-        if (i == cfg->nhugetlbfs) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Unable to find any usable hugetlbfs "
-                             "mount for %llu KiB"),
-                           def->mem.hugepages[0].size);
-            return -1;
-        }
-
-        if (!(mem_path = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
-            return -1;
-    }
+    if (qemuGetHupageMemPath(cfg, def->mem.hugepages[0].size, &mem_path) < 0)
+        return -1;
 
     virCommandAddArgList(cmd, "-mem-prealloc", "-mem-path", mem_path, NULL);
     VIR_FREE(mem_path);
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index dad8334..5a97e96 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1465,3 +1465,53 @@ qemuGetDefaultHugepath(virHugeTLBFSPtr hugetlbfs,
 
     return qemuGetHugepagePath(&hugetlbfs[i]);
 }
+
+
+/**
+ * qemuGetHupageMemPath: Construct HP enabled memory backend path
+ *
+ * If no specific hugepage size is requested (@pagesize is zero)
+ * the default hugepage size is used).
+ * The resulting path is stored at @memPath.
+ *
+ * Returns 0 on success,
+ *        -1 otherwise.
+ */
+int
+qemuGetHupageMemPath(virQEMUDriverConfigPtr cfg,
+                     unsigned long long pagesize,
+                     char **memPath)
+{
+    size_t i = 0;
+
+    if (!cfg->nhugetlbfs) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("hugetlbfs filesystem is not mounted "
+                               "or disabled by administrator config"));
+        return -1;
+    }
+
+    if (!pagesize) {
+        if (!(*memPath = qemuGetDefaultHugepath(cfg->hugetlbfs,
+                                                cfg->nhugetlbfs)))
+            return -1;
+    } else {
+        for (i = 0; i < cfg->nhugetlbfs; i++) {
+            if (cfg->hugetlbfs[i].size == pagesize)
+                break;
+        }
+
+        if (i == cfg->nhugetlbfs) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unable to find any usable hugetlbfs "
+                             "mount for %llu KiB"),
+                           pagesize);
+            return -1;
+        }
+
+        if (!(*memPath = qemuGetHugepagePath(&cfg->hugetlbfs[i])))
+            return -1;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index d8232cc..d32689a 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -335,4 +335,8 @@ int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn,
 char * qemuGetHugepagePath(virHugeTLBFSPtr hugepage);
 char * qemuGetDefaultHugepath(virHugeTLBFSPtr hugetlbfs,
                               size_t nhugetlbfs);
+
+int qemuGetHupageMemPath(virQEMUDriverConfigPtr cfg,
+                         unsigned long long pagesize,
+                         char **memPath);
 #endif /* __QEMUD_CONF_H */
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]