render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
2cf05b
From 215adedb16aa082d052f84705338de0d77721fe0 Mon Sep 17 00:00:00 2001
2cf05b
Message-Id: <215adedb16aa082d052f84705338de0d77721fe0@dist-git>
2cf05b
From: Michal Privoznik <mprivozn@redhat.com>
2cf05b
Date: Tue, 6 Sep 2022 13:43:22 +0200
2cf05b
Subject: [PATCH] qemu_namespace: Fix a corner case in
2cf05b
 qemuDomainGetPreservedMounts()
2cf05b
2cf05b
When setting up namespace for QEMU we look at mount points under
2cf05b
/dev (like /dev/pts, /dev/mqueue/, etc.) because we want to
2cf05b
preserve those (which is done by moving them to a temp location,
2cf05b
unshare(), and then moving them back). We have a convenience
2cf05b
helper - qemuDomainGetPreservedMounts() - that processes the
2cf05b
mount table and (optionally) moves the other filesystems too.
2cf05b
This helper is also used when attempting to create a path in NS,
2cf05b
because the path, while starting with "/dev/" prefix, may
2cf05b
actually lead to one of those filesystems that we preserved.
2cf05b
2cf05b
And here comes the corner case: while we require the parent mount
2cf05b
table to be in shared mode (equivalent of `mount --make-rshared /'),
2cf05b
these mount events propagate iff the target path exist inside the
2cf05b
slave mount table (= QEMU's private namespace). And since we
2cf05b
create only a subset of /dev nodes, well, that assumption is not
2cf05b
always the case.
2cf05b
2cf05b
For instance, assume that a domain is already running, no
2cf05b
hugepages were configured for it nor any hugetlbfs is mounted.
2cf05b
Now, when a hugetlbfs is mounted into '/dev/hugepages', this is
2cf05b
propagated into the QEMU's namespace, but since the target dir
2cf05b
does not exist in the private /dev, the FS is not mounted in the
2cf05b
namespace.
2cf05b
2cf05b
Fortunately, this difference between namespaces is visible when
2cf05b
comparing /proc/mounts and /proc/$PID/mounts (where PID is the
2cf05b
QEMU's PID). Therefore, if possible we should look at the latter.
2cf05b
2cf05b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2cf05b
(cherry picked from commit 46b03819ae8d833b11c2aaccb2c2a0361727f51b)
2cf05b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2123196
2cf05b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2cf05b
---
2cf05b
 src/qemu/qemu_namespace.c | 10 +++++++++-
2cf05b
 1 file changed, 9 insertions(+), 1 deletion(-)
2cf05b
2cf05b
diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
2cf05b
index 4bff325a2c..fc286ab0be 100644
2cf05b
--- a/src/qemu/qemu_namespace.c
2cf05b
+++ b/src/qemu/qemu_namespace.c
2cf05b
@@ -110,6 +110,8 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfig *cfg,
2cf05b
  * b) generate backup path for all the entries in a)
2cf05b
  *
2cf05b
  * Any of the return pointers can be NULL. Both arrays are NULL-terminated.
2cf05b
+ * Get the mount table either from @vm's PID (if running), or from the
2cf05b
+ * namespace we're in (if @vm's not running).
2cf05b
  *
2cf05b
  * Returns 0 on success, -1 otherwise (with error reported)
2cf05b
  */
2cf05b
@@ -124,12 +126,18 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg,
2cf05b
     size_t nmounts = 0;
2cf05b
     g_auto(GStrv) paths = NULL;
2cf05b
     g_auto(GStrv) savePaths = NULL;
2cf05b
+    g_autofree char *mountsPath = NULL;
2cf05b
     size_t i;
2cf05b
 
2cf05b
     if (ndevPath)
2cf05b
         *ndevPath = 0;
2cf05b
 
2cf05b
-    if (virFileGetMountSubtree(QEMU_PROC_MOUNTS, "/dev", &mounts, &nmounts) < 0)
2cf05b
+    if (vm->pid > 0)
2cf05b
+        mountsPath = g_strdup_printf("/proc/%lld/mounts", (long long) vm->pid);
2cf05b
+    else
2cf05b
+        mountsPath = g_strdup(QEMU_PROC_MOUNTS);
2cf05b
+
2cf05b
+    if (virFileGetMountSubtree(mountsPath, "/dev", &mounts, &nmounts) < 0)
2cf05b
         return -1;
2cf05b
 
2cf05b
     if (nmounts == 0)
2cf05b
-- 
2cf05b
2.38.0
2cf05b