]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_namespace: Make qemuDomainGetPreservedMounts() more robust wrt running VMs
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 31 Oct 2022 15:26:17 +0000 (16:26 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 1 Nov 2022 13:51:48 +0000 (14:51 +0100)
The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And if given domain is also running it looks into its
mount table rather than at the host one. But if it did look at
the domain's private mount table, it find /dev mounted twice: the
first time by udev, the second time the tmpfs mounted by us.

Now, later in the function there's a "sorting" algorithm that
tries to reduce number of mount points needing preservation, by
identifying nested mount points. And if we keep the second
occurrence of /dev on the list, well, after the "sorting" we are
left with nothing but "/dev" because all other mount points are
nested.

Fixes: 46b03819ae8d833b11c2aaccb2c2a0361727f51b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_namespace.c

index 9fed6871e844d235f9be2eb989a1652e300a9eeb..8189cc37ba85c65151a0c2c9d943089c4736e207 100644 (file)
@@ -154,6 +154,17 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfig *cfg,
     for (i = 1; i < nmounts; i++) {
         size_t j = i + 1;
 
+        /* If we looked into mount table of already running VM,
+         * we might have found /dev twice. Remove the other
+         * occurrence as it would jeopardize the rest of the prune
+         * algorithm.
+         */
+        if (STREQ(mounts[i], "/dev")) {
+            VIR_FREE(mounts[i]);
+            VIR_DELETE_ELEMENT_INPLACE(mounts, i, nmounts);
+            continue;
+        }
+
         while (j < nmounts) {
             char *c = STRSKIP(mounts[j], mounts[i]);