]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuDomainGetPreservedMounts: Prune nested mount points
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 12 Jun 2017 14:28:03 +0000 (16:28 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 16 Jun 2017 12:38:23 +0000 (14:38 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1431112

There can be nested mount points. For instance /dev/shm/blah can
be a mount point and /dev/shm too. It doesn't make much sense to
return the former path because callers preserve the latter (and
with that the former too). Therefore prune nested mount points.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/qemu/qemu_domain.c

index 570da2cf546785eb8e7107909a8fd0f41f69587a..81e4b02f38f63db6e4a25ee5789012acf2c516b3 100644 (file)
@@ -7585,7 +7585,7 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
                              size_t *ndevPath)
 {
     char **paths = NULL, **mounts = NULL;
-    size_t i, nmounts;
+    size_t i, j, nmounts;
 
     if (virFileGetMountSubtree(PROC_MOUNTS, "/dev",
                                &mounts, &nmounts) < 0)
@@ -7597,6 +7597,27 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
         return 0;
     }
 
+    /* There can be nested mount points. For instance
+     * /dev/shm/blah can be a mount point and /dev/shm too. It
+     * doesn't make much sense to return the former path because
+     * caller preserves the latter (and with that the former
+     * too). Therefore prune nested mount points.
+     * NB mounts[0] is "/dev". Should we start the outer loop
+     * from the beginning of the array all we'd be left with is
+     * just the first element. Think about it.
+     */
+    for (i = 1; i < nmounts; i++) {
+        j = i + 1;
+        while (j < nmounts) {
+            if (STRPREFIX(mounts[j], mounts[i])) {
+                VIR_DEBUG("Dropping path %s because of %s", mounts[j], mounts[i]);
+                VIR_DELETE_ELEMENT(mounts, j, nmounts);
+            } else {
+                j++;
+            }
+        }
+    }
+
     if (VIR_ALLOC_N(paths, nmounts) < 0)
         goto error;