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