[libvirt] [PATCH] qemu-ns: Detect /dev/* mount point duplicates better

Michal Privoznik posted 1 patch 6 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/cab9efcf2d2fae7939b6be251b110c4a43face97.1508420074.git.mprivozn@redhat.com
src/qemu/qemu_domain.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt] [PATCH] qemu-ns: Detect /dev/* mount point duplicates better
Posted by Michal Privoznik 6 years, 5 months ago
https://bugzilla.redhat.com/show_bug.cgi?id=1495511

When creating new /dev for domain ran in namespace we try to
preserve all sub-mounts of /dev. Well, not quite all. For
instance if /dev/foo/bar and /dev/foo are both mount points, only
/dev/foo needs preserving. /dev/foo/bar is preserved with it too.
Now, to identify such cases like this one STRPREFIX() is used.
That is not good enough. While it works for [/dev/foo/bar;
/dev/foo] case, it fails for [/dev/prefix; /dev/prefix2] where
the strings share the same prefix but are in fact two different
paths. The solution is to use STRSKIP().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 05e8b96aa..8aa66c69c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8182,7 +8182,9 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg,
     for (i = 1; i < nmounts; i++) {
         j = i + 1;
         while (j < nmounts) {
-            if (STRPREFIX(mounts[j], mounts[i])) {
+            char *c = STRSKIP(mounts[j], mounts[i]);
+
+            if (c && *c == '/') {
                 VIR_DEBUG("Dropping path %s because of %s", mounts[j], mounts[i]);
                 VIR_DELETE_ELEMENT(mounts, j, nmounts);
             } else {
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu-ns: Detect /dev/* mount point duplicates better
Posted by Erik Skultety 6 years, 5 months ago
On Thu, Oct 19, 2017 at 03:34:34PM +0200, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1495511
>
> When creating new /dev for domain ran in namespace we try to
> preserve all sub-mounts of /dev. Well, not quite all. For
> instance if /dev/foo/bar and /dev/foo are both mount points, only
> /dev/foo needs preserving. /dev/foo/bar is preserved with it too.
> Now, to identify such cases like this one STRPREFIX() is used.
> That is not good enough. While it works for [/dev/foo/bar;
> /dev/foo] case, it fails for [/dev/prefix; /dev/prefix2] where
> the strings share the same prefix but are in fact two different
> paths. The solution is to use STRSKIP().
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Reviewed-by: Erik Skultety <eskultet@redhat.com>

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list