render / rpms / libvirt

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