3e5111
From 2cc49072ced64daa446a90b802191496b4d28e69 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <2cc49072ced64daa446a90b802191496b4d28e69@dist-git>
3e5111
From: Michal Privoznik <mprivozn@redhat.com>
3e5111
Date: Thu, 11 May 2017 15:38:37 +0200
3e5111
Subject: [PATCH] qemuDomainBuildNamespace: Move /dev/* mountpoints later
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1449510
3e5111
3e5111
When setting up mount namespace for a qemu domain the following
3e5111
steps are executed:
3e5111
3e5111
1) get list of mountpoints under /dev/
3e5111
2) move them to /var/run/libvirt/qemu/$domName.ext
3e5111
3) start constructing new device tree under /var/run/libvirt/qemu/$domName.dev
3e5111
4) move the mountpoint of the new device tree to /dev
3e5111
5) restore original mountpoints from step 2)
3e5111
3e5111
Note the problem with this approach is that if some device in step
3e5111
3) requires access to a mountpoint from step 2) it will fail as
3e5111
the mountpoint is not there anymore. For instance consider the
3e5111
following domain disk configuration:
3e5111
3e5111
    <disk type='file' device='disk'>
3e5111
      <driver name='qemu' type='raw'/>
3e5111
      <source file='/dev/shm/vhostmd0'/>
3e5111
      <target dev='vdb' bus='virtio'/>
3e5111
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
3e5111
    </disk>
3e5111
3e5111
In this case operation fails as we are unable to create vhostmd0
3e5111
in the new device tree because after step 2) there is no /dev/shm
3e5111
anymore. Leave aside fact that we shouldn't try to create devices
3e5111
living in other mountpoints. That's a separate bug that will be
3e5111
addressed later.
3e5111
3e5111
Currently, the order described above is rearranged to:
3e5111
3e5111
1) get list of mountpoints under /dev/
3e5111
2) start constructing new device tree under /var/run/libvirt/qemu/$domName.dev
3e5111
3) move them to /var/run/libvirt/qemu/$domName.ext
3e5111
4) move the mountpoint of the new device tree to /dev
3e5111
5) restore original mountpoints from step 3)
3e5111
3e5111
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3e5111
Reviewed-by: Cedric Bosdonnat <cbosdonnat@suse.com>
3e5111
(cherry picked from commit a7cc039dc796f541793955598377807af48341fb)
3e5111
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_domain.c | 48 ++++++++++++++++++++++++------------------------
3e5111
 1 file changed, 24 insertions(+), 24 deletions(-)
3e5111
3e5111
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
3e5111
index 2790d7e74..fbb65fab4 100644
3e5111
--- a/src/qemu/qemu_domain.c
3e5111
+++ b/src/qemu/qemu_domain.c
3e5111
@@ -8026,6 +8026,30 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
3e5111
     if (qemuDomainSetupDev(cfg, mgr, vm, devPath) < 0)
3e5111
         goto cleanup;
3e5111
 
3e5111
+    if (qemuDomainSetupAllDisks(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllHostdevs(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllMemories(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllChardevs(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupTPM(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllGraphics(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllInputs(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
+    if (qemuDomainSetupAllRNGs(cfg, vm, devPath) < 0)
3e5111
+        goto cleanup;
3e5111
+
3e5111
     /* Save some mount points because we want to share them with the host */
3e5111
     for (i = 0; i < ndevMountsPath; i++) {
3e5111
         struct stat sb;
3e5111
@@ -8053,30 +8077,6 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
3e5111
             goto cleanup;
3e5111
     }
3e5111
 
3e5111
-    if (qemuDomainSetupAllDisks(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllHostdevs(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllMemories(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllChardevs(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupTPM(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllGraphics(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllInputs(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
-    if (qemuDomainSetupAllRNGs(cfg, vm, devPath) < 0)
3e5111
-        goto cleanup;
3e5111
-
3e5111
     if (virFileMoveMount(devPath, "/dev") < 0)
3e5111
         goto cleanup;
3e5111
 
3e5111
-- 
3e5111
2.13.0
3e5111