[PATCH v1 20/21] qemu: Manage /dev entry on RNG hotplug

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

 



When attaching a device to a domain that's using separate mount
namespace we must maintain /dev entries in order for qemu process
to see them.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c  | 72 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/qemu/qemu_domain.h  |  8 ++++++
 src/qemu/qemu_hotplug.c | 10 +++++++
 3 files changed, 88 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cc7ce2d..0b46336 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7372,6 +7372,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
     }   break;
 
     case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_RNG:
         /* No labelling. */
         break;
 
@@ -7390,7 +7391,6 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED,
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_RNG:
     case VIR_DOMAIN_DEVICE_SHMEM:
     case VIR_DOMAIN_DEVICE_TPM:
     case VIR_DOMAIN_DEVICE_PANIC:
@@ -7508,6 +7508,7 @@ qemuDomainDetachDeviceUnlink(virQEMUDriverPtr driver,
     }   break;
 
     case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_RNG:
         /* No labelling. */
         break;
 
@@ -7526,7 +7527,6 @@ qemuDomainDetachDeviceUnlink(virQEMUDriverPtr driver,
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
-    case VIR_DOMAIN_DEVICE_RNG:
     case VIR_DOMAIN_DEVICE_SHMEM:
     case VIR_DOMAIN_DEVICE_TPM:
     case VIR_DOMAIN_DEVICE_PANIC:
@@ -7731,3 +7731,71 @@ qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
  cleanup:
     return ret;
 }
+
+
+int
+qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
+                            virDomainObjPtr vm,
+                            virDomainRNGDefPtr rng)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virDomainDeviceDef dev = {.type = VIR_DOMAIN_DEVICE_RNG, .data.rng = rng};
+    const char *path = NULL;
+    int ret = -1;
+
+    if (!priv->containerized)
+        return 0;
+
+    switch ((virDomainRNGBackend) rng->backend) {
+    case VIR_DOMAIN_RNG_BACKEND_RANDOM:
+        path = rng->source.file;
+        break;
+
+    case VIR_DOMAIN_RNG_BACKEND_EGD:
+    case VIR_DOMAIN_RNG_BACKEND_LAST:
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (qemuDomainAttachDeviceMknod(driver,
+                                    vm,
+                                    &dev,
+                                    path) < 0)
+        goto cleanup;
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+
+int
+qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
+                               virDomainObjPtr vm,
+                               virDomainRNGDefPtr rng)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virDomainDeviceDef dev = {.type = VIR_DOMAIN_DEVICE_RNG, .data.rng = rng};
+    int ret = -1;
+    const char *path = NULL;
+
+    if (!priv->containerized)
+        return 0;
+
+    switch ((virDomainRNGBackend) rng->backend) {
+    case VIR_DOMAIN_RNG_BACKEND_RANDOM:
+        path = rng->source.file;
+        break;
+
+    case VIR_DOMAIN_RNG_BACKEND_EGD:
+    case VIR_DOMAIN_RNG_BACKEND_LAST:
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (qemuDomainDetachDeviceUnlink(driver, vm, &dev, path) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 37b1e41..78d00de 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -819,4 +819,12 @@ int qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver,
 int qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver,
                                        virDomainObjPtr vm,
                                        virDomainChrDefPtr chr);
+
+int qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver,
+                                    virDomainObjPtr vm,
+                                    virDomainRNGDefPtr rng);
+
+int qemuDomainNamespaceTeardownRNG(virQEMUDriverPtr driver,
+                                       virDomainObjPtr vm,
+                                       virDomainRNGDefPtr rng);
 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4f012d0..61f7c5a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1980,6 +1980,7 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
     char *secAlias = NULL;
     bool releaseaddr = false;
     bool teardowncgroup = false;
+    bool teardowndevice = false;
     bool chardevAdded = false;
     bool objAdded = false;
     bool tlsobjAdded = false;
@@ -2025,6 +2026,10 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
             goto cleanup;
     }
 
+    if (qemuDomainNamespaceSetupRNG(driver, vm, rng) < 0)
+        goto cleanup;
+    teardowndevice = true;
+
     if (qemuSetupRNGCgroup(vm, rng) < 0)
         goto cleanup;
     teardowncgroup = true;
@@ -2111,6 +2116,8 @@ qemuDomainAttachRNGDevice(virConnectPtr conn,
             qemuDomainReleaseDeviceAddress(vm, &rng->info, NULL);
         if (teardowncgroup && qemuTeardownRNGCgroup(vm, rng) < 0)
             VIR_WARN("Unable to remove RNG device cgroup ACL on hotplug fail");
+        if (teardowndevice && qemuDomainNamespaceTeardownRNG(driver, vm, rng) < 0)
+            VIR_WARN("Unable to remove chr device from /dev");
     }
 
     VIR_FREE(tlsAlias);
@@ -3975,6 +3982,9 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
     if (qemuTeardownRNGCgroup(vm, rng) < 0)
         VIR_WARN("Failed to remove RNG device cgroup ACL");
 
+    if (qemuDomainNamespaceTeardownRNG(driver, vm, rng) < 0)
+        VIR_WARN("Unable to remove RNG device from /dev");
+
     event = virDomainEventDeviceRemovedNewFromObj(vm, rng->info.alias);
     qemuDomainEventQueue(driver, event);
 
-- 
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]
  Powered by Linux