]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use mount table filter on --no-canonicalize
authorKarel Zak <kzak@redhat.com>
Wed, 7 Jun 2017 09:35:26 +0000 (11:35 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 7 Jun 2017 09:35:26 +0000 (11:35 +0200)
The umount command option --no-canonicalize means that the path is
already canonical. So, we can use mount table filter in this case too.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_umount.c

index 3620f652542a0666ff3b3ee8ff01360e50ba730a..5725ab1ad78ff3150d7003cf951768ef6c8c3828 100644 (file)
@@ -1124,7 +1124,10 @@ int mnt_context_get_mtab_for_target(struct libmnt_context *cxt,
        char *cn_tgt = NULL;
        int rc;
 
-       if (mnt_stat_mountpoint(tgt, &st) == 0 && S_ISDIR(st.st_mode)) {
+       if (mnt_context_is_nocanonicalize(cxt))
+               mnt_context_set_tabfilter(cxt, mtab_filter, (void *) tgt);
+
+       else if (mnt_stat_mountpoint(tgt, &st) == 0 && S_ISDIR(st.st_mode)) {
                cache = mnt_context_get_cache(cxt);
                cn_tgt = mnt_resolve_path(tgt, cache);
                if (cn_tgt)
@@ -1132,12 +1135,10 @@ int mnt_context_get_mtab_for_target(struct libmnt_context *cxt,
        }
 
        rc = mnt_context_get_mtab(cxt, mtab);
+       mnt_context_set_tabfilter(cxt, NULL, NULL);
 
-       if (cn_tgt) {
-               mnt_context_set_tabfilter(cxt, NULL, NULL);
-               if (!cache)
-                       free(cn_tgt);
-       }
+       if (cn_tgt && !cache)
+               free(cn_tgt);
 
        return rc;
 }
index 693891def0e131743ae07cfe21dae7d6912ad834..4a4c5bfe5e788169ffcaa5e94d4925db8b363526 100644 (file)
@@ -67,17 +67,21 @@ int mnt_context_find_umount_fs(struct libmnt_context *cxt,
                return 1; /* empty string is not an error */
 
        /*
-        * The mount table may be huge, and on systems with utab we have to merge
-        * userspace mount options into /proc/self/mountinfo. This all is
-        * expensive. The tab filter allows to filter out entries, then
-        * a mount table and utab are very tiny files.
+        * The mount table may be huge, and on systems with utab we have to
+        * merge userspace mount options into /proc/self/mountinfo. This all is
+        * expensive. The tab filter allows to filter out entries, then a mount
+        * table and utab are very tiny files.
         *
-        * *but*... the filter uses mnt_fs_streq_{target,srcpath} functions
-        * where LABEL, UUID or symlinks are canonicalized. It means that
-        * it's usable only for canonicalized stuff (e.g. kernel mountinfo).
+        * The filter uses mnt_fs_streq_{target,srcpath} function where all
+        * paths should be absolute and canonicalized. This is done within
+        * mnt_context_get_mtab_for_target() where LABEL, UUID or symlinks are
+        * canonicalized. If --no-canonicalize is enabled than the target path
+        * is expected already canonical.
+        *
+        * It also means that we have to read mount table from kernel
+        * (non-writable mtab).
         */
        if (!mnt_context_mtab_writable(cxt) && *tgt == '/' &&
-           !mnt_context_is_nocanonicalize(cxt) &&
            !mnt_context_is_force(cxt) && !mnt_context_is_lazy(cxt))
                rc = mnt_context_get_mtab_for_target(cxt, &mtab, tgt);
        else