render / rpms / libvirt

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