c1c534
From aa138f5b99f7a05efee017401116d9513cb34b5e Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <aa138f5b99f7a05efee017401116d9513cb34b5e@dist-git>
c1c534
From: Michal Privoznik <mprivozn@redhat.com>
c1c534
Date: Thu, 9 Nov 2017 16:06:45 +0100
c1c534
Subject: [PATCH] qemu: Rename qemuProcessBuildDestroyHugepagesPath
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1461214
c1c534
c1c534
At the same time, move its internals into a separate function so
c1c534
that they can be reused.
c1c534
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
Reviewed-by: John Ferlan <jferlan@redhat.com>
c1c534
(cherry picked from commit eff2b2edb147572b6d8f701f4b4f4a69580e17c8)
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_hotplug.c |  2 +-
c1c534
 src/qemu/qemu_process.c | 76 +++++++++++++++++++++++++++++--------------------
c1c534
 src/qemu/qemu_process.h |  8 +++---
c1c534
 3 files changed, 50 insertions(+), 36 deletions(-)
c1c534
c1c534
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
c1c534
index 91f7f9ed62..5701c033be 100644
c1c534
--- a/src/qemu/qemu_hotplug.c
c1c534
+++ b/src/qemu/qemu_hotplug.c
c1c534
@@ -2077,7 +2077,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
c1c534
                                   priv->qemuCaps, vm->def, mem, NULL, true) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-    if (qemuProcessBuildDestroyHugepagesPath(driver, vm, mem, true) < 0)
c1c534
+    if (qemuProcessBuildDestroyMemoryPaths(driver, vm, mem, true) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
     if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0)
c1c534
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
c1c534
index fdc868912c..605f280d0c 100644
c1c534
--- a/src/qemu/qemu_process.c
c1c534
+++ b/src/qemu/qemu_process.c
c1c534
@@ -3324,11 +3324,45 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def,
c1c534
 }
c1c534
 
c1c534
 
c1c534
+static int
c1c534
+qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver,
c1c534
+                                       virDomainDefPtr def,
c1c534
+                                       const char *path,
c1c534
+                                       bool build)
c1c534
+{
c1c534
+    if (build) {
c1c534
+        if (virFileExists(path))
c1c534
+            return 0;
c1c534
+
c1c534
+        if (virFileMakePathWithMode(path, 0700) < 0) {
c1c534
+            virReportSystemError(errno,
c1c534
+                                 _("Unable to create %s"),
c1c534
+                                 path);
c1c534
+            return -1;
c1c534
+        }
c1c534
+
c1c534
+        if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c1c534
+                                           def, path) < 0) {
c1c534
+            virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
+                            _("Unable to label %s"), path);
c1c534
+            return -1;
c1c534
+        }
c1c534
+    } else {
c1c534
+        if (rmdir(path) < 0 &&
c1c534
+            errno != ENOENT)
c1c534
+            VIR_WARN("Unable to remove hugepage path: %s (errno=%d)",
c1c534
+                     path, errno);
c1c534
+    }
c1c534
+
c1c534
+    return 0;
c1c534
+}
c1c534
+
c1c534
+
c1c534
 int
c1c534
-qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
c1c534
-                                     virDomainObjPtr vm,
c1c534
-                                     virDomainMemoryDefPtr mem,
c1c534
-                                     bool build)
c1c534
+qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c1c534
+                                   virDomainObjPtr vm,
c1c534
+                                   virDomainMemoryDefPtr mem,
c1c534
+                                   bool build)
c1c534
 {
c1c534
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
c1c534
     char *hugepagePath = NULL;
c1c534
@@ -3347,31 +3381,11 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
c1c534
             if (!hugepagePath)
c1c534
                 goto cleanup;
c1c534
 
c1c534
-            if (build) {
c1c534
-                if (virFileExists(hugepagePath)) {
c1c534
-                    ret = 0;
c1c534
-                    goto cleanup;
c1c534
-                }
c1c534
+            if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def,
c1c534
+                                                       hugepagePath, build) < 0)
c1c534
+                goto cleanup;
c1c534
 
c1c534
-                if (virFileMakePathWithMode(hugepagePath, 0700) < 0) {
c1c534
-                    virReportSystemError(errno,
c1c534
-                                         _("Unable to create %s"),
c1c534
-                                         hugepagePath);
c1c534
-                    goto cleanup;
c1c534
-                }
c1c534
-
c1c534
-                if (qemuSecurityDomainSetPathLabel(driver->securityManager,
c1c534
-                                                   vm->def, hugepagePath) < 0) {
c1c534
-                    virReportError(VIR_ERR_INTERNAL_ERROR,
c1c534
-                                   "%s", _("Unable to set huge path in security driver"));
c1c534
-                    goto cleanup;
c1c534
-                }
c1c534
-            } else {
c1c534
-                if (rmdir(hugepagePath) < 0 &&
c1c534
-                    errno != ENOENT)
c1c534
-                    VIR_WARN("Unable to remove hugepage path: %s (errno=%d)",
c1c534
-                             hugepagePath, errno);
c1c534
-            }
c1c534
+            VIR_FREE(hugepagePath);
c1c534
         }
c1c534
     }
c1c534
 
c1c534
@@ -5550,7 +5564,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
c1c534
                                NULL) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
-    if (qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, true) < 0)
c1c534
+    if (qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, true) < 0)
c1c534
         goto cleanup;
c1c534
 
c1c534
     /* Ensure no historical cgroup for this VM is lying around bogus
c1c534
@@ -6254,7 +6268,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
c1c534
         goto endjob;
c1c534
     }
c1c534
 
c1c534
-    qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, false);
c1c534
+    qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, false);
c1c534
 
c1c534
     vm->def->id = -1;
c1c534
 
c1c534
@@ -7112,7 +7126,7 @@ qemuProcessReconnect(void *opaque)
c1c534
         goto cleanup;
c1c534
     }
c1c534
 
c1c534
-    if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0)
c1c534
+    if (qemuProcessBuildDestroyMemoryPaths(driver, obj, NULL, true) < 0)
c1c534
         goto error;
c1c534
 
c1c534
     if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps,
c1c534
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
c1c534
index 814b86d8a7..cd9a720313 100644
c1c534
--- a/src/qemu/qemu_process.h
c1c534
+++ b/src/qemu/qemu_process.h
c1c534
@@ -38,10 +38,10 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver,
c1c534
                         virDomainPausedReason reason,
c1c534
                         qemuDomainAsyncJob asyncJob);
c1c534
 
c1c534
-int qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
c1c534
-                                         virDomainObjPtr vm,
c1c534
-                                         virDomainMemoryDefPtr mem,
c1c534
-                                         bool build);
c1c534
+int qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
c1c534
+                                       virDomainObjPtr vm,
c1c534
+                                       virDomainMemoryDefPtr mem,
c1c534
+                                       bool build);
c1c534
 
c1c534
 void qemuProcessAutostartAll(virQEMUDriverPtr driver);
c1c534
 void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
c1c534
-- 
c1c534
2.15.0
c1c534