[PATCHv2 4/7] Introduce qemuDomainNamespaceMknodPath

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

 



Use this function in qemuDomainNamespaceSetup* functions which
only require creating one device.
---
 src/qemu/qemu_domain.c | 120 +++++++++++--------------------------------------
 1 file changed, 26 insertions(+), 94 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f1c664248..696f4751e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9963,6 +9963,16 @@ qemuDomainNamespaceMknodPaths(virDomainObjPtr vm,
 }
 
 
+static int
+qemuDomainNamespaceMknodPath(virDomainObjPtr vm,
+                             const char *path)
+{
+    const char *paths[] = { path };
+
+    return qemuDomainNamespaceMknodPaths(vm, paths, 1);
+}
+
+
 int
 qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                              virDomainObjPtr vm,
@@ -10082,35 +10092,17 @@ qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver,
 
 
 int
-qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver,
+qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                                virDomainObjPtr vm,
                                virDomainMemoryDefPtr mem)
 {
-    virQEMUDriverConfigPtr cfg = NULL;
-    char **devMountsPath = NULL;
-    size_t ndevMountsPath = 0;
-    int ret = -1;
-
     if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
         return 0;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
-
-    cfg = virQEMUDriverGetConfig(driver);
-    if (qemuDomainGetPreservedMounts(cfg, vm,
-                                     &devMountsPath, NULL,
-                                     &ndevMountsPath) < 0)
-        goto cleanup;
+    if (qemuDomainNamespaceMknodPath(vm, mem->nvdimmPath) < 0)
+        return -1;
 
-    if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath,
-                                    devMountsPath, ndevMountsPath) < 0)
-        goto cleanup;
-    ret = 0;
- cleanup:
-    virStringListFreeCount(devMountsPath, ndevMountsPath);
-    virObjectUnref(cfg);
-    return ret;
+    return 0;
 }
 
 
@@ -10148,18 +10140,11 @@ qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver,
 
 
 int
-qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
+qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                                 virDomainObjPtr vm,
                                 virDomainChrDefPtr chr)
 {
-    virQEMUDriverConfigPtr cfg = NULL;
-    char **devMountsPath = NULL;
-    size_t ndevMountsPath = 0;
     const char *path;
-    int ret = -1;
-
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
 
     if (!(path = virDomainChrSourceDefGetPath(chr->source)))
         return 0;
@@ -10169,22 +10154,10 @@ qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
         chr->source->data.nix.listen)
         return 0;
 
-    cfg = virQEMUDriverGetConfig(driver);
-    if (qemuDomainGetPreservedMounts(cfg, vm,
-                                     &devMountsPath, NULL,
-                                     &ndevMountsPath) < 0)
-        goto cleanup;
+    if (qemuDomainNamespaceMknodPath(vm, path) < 0)
+        return -1;
 
-    if (qemuDomainAttachDeviceMknod(driver,
-                                    vm,
-                                    path,
-                                    devMountsPath, ndevMountsPath) < 0)
-        goto cleanup;
-    ret = 0;
- cleanup:
-    virStringListFreeCount(devMountsPath, ndevMountsPath);
-    virObjectUnref(cfg);
-    return ret;
+    return 0;
 }
 
 
@@ -10226,18 +10199,11 @@ qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
 
 
 int
-qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
+qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
                             virDomainObjPtr vm,
                             virDomainRNGDefPtr rng)
 {
-    virQEMUDriverConfigPtr cfg = NULL;
-    char **devMountsPath = NULL;
-    size_t ndevMountsPath = 0;
     const char *path = NULL;
-    int ret = -1;
-
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
 
     switch ((virDomainRNGBackend) rng->backend) {
     case VIR_DOMAIN_RNG_BACKEND_RANDOM:
@@ -10246,26 +10212,13 @@ qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
 
     case VIR_DOMAIN_RNG_BACKEND_EGD:
     case VIR_DOMAIN_RNG_BACKEND_LAST:
-        ret = 0;
-        goto cleanup;
+        break;
     }
 
-    cfg = virQEMUDriverGetConfig(driver);
-    if (qemuDomainGetPreservedMounts(cfg, vm,
-                                     &devMountsPath, NULL,
-                                     &ndevMountsPath) < 0)
-        goto cleanup;
+    if (path && qemuDomainNamespaceMknodPath(vm, path) < 0)
+        return -1;
 
-    if (qemuDomainAttachDeviceMknod(driver,
-                                    vm,
-                                    path,
-                                    devMountsPath, ndevMountsPath) < 0)
-        goto cleanup;
-    ret = 0;
- cleanup:
-    virStringListFreeCount(devMountsPath, ndevMountsPath);
-    virObjectUnref(cfg);
-    return ret;
+    return 0;
 }
 
 
@@ -10316,35 +10269,14 @@ int
 qemuDomainNamespaceSetupInput(virDomainObjPtr vm,
                               virDomainInputDefPtr input)
 {
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-    virQEMUDriverPtr driver = priv->driver;
-    virQEMUDriverConfigPtr cfg = NULL;
-    char **devMountsPath = NULL;
-    size_t ndevMountsPath = 0;
     const char *path = NULL;
-    int ret = -1;
 
     if (!(path = virDomainInputDefGetPath(input)))
         return 0;
 
-    if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
-        return 0;
-
-    cfg = virQEMUDriverGetConfig(driver);
-    if (qemuDomainGetPreservedMounts(cfg, vm,
-                                     &devMountsPath, NULL,
-                                     &ndevMountsPath) < 0)
-        goto cleanup;
-
-    if (qemuDomainAttachDeviceMknod(driver, vm, path,
-                                    devMountsPath, ndevMountsPath) < 0)
-        goto cleanup;
-
-    ret = 0;
- cleanup:
-    virStringListFreeCount(devMountsPath, ndevMountsPath);
-    virObjectUnref(cfg);
-    return ret;
+    if (path && qemuDomainNamespaceMknodPath(vm, path) < 0)
+        return -1;
+    return 0;
 }
 
 
-- 
2.13.6

--
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]
  Powered by Linux