]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (--all) continue although /proc is not mounted
authorKarel Zak <kzak@redhat.com>
Thu, 18 Nov 2021 10:47:08 +0000 (11:47 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 18 Nov 2021 12:07:59 +0000 (13:07 +0100)
Now 'mount --all' ends with error if /proc is not mounted and there is
some other entry before /proc in fstab. This commit improves this
situation and ignores all mount table related errors if the table is
empty.

This is important for situation when there is for example "/" as the
first line in fstab.

Addresses: https://github.com/util-linux/util-linux/issues/1492
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
sys-utils/mount.8.adoc

index de05757eb113bccd6ca9c033ff514d18a346cd50..69fd8bf2314464044e37cf7c68a85c26fea74f94 100644 (file)
@@ -1302,6 +1302,16 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb)
                                        cxt->table_fltrcb_data);
 
                mnt_table_set_cache(cxt->mtab, mnt_context_get_cache(cxt));
+       }
+
+       /* Read the table; it's empty, because this first mnt_context_get_mtab()
+        * call, or because /proc was not accessible in previous calls */
+       if (mnt_table_is_empty(cxt->mtab)) {
+               if (!ns_old) {
+                       ns_old = mnt_context_switch_target_ns(cxt);
+                       if (!ns_old)
+                               return -MNT_ERR_NAMESPACE;
+               }
 
                /*
                 * Note that mtab_path is NULL if mtab is useless or unsupported
@@ -2924,7 +2934,7 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
                              struct libmnt_fs *fs, int *mounted)
 {
        struct libmnt_table *mtab, *orig;
-       int rc;
+       int rc = 0;
        struct libmnt_ns *ns_old;
 
        if (!cxt || !fs || !mounted)
@@ -2943,18 +2953,17 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt,
                        cxt->mtab = NULL;
                }
                *mounted = 0;
-               return 0;       /* /proc not mounted */
-       }
+               rc = 0;                 /* /proc not mounted */
 
-       if (rc)
-               return rc;
-
-       *mounted = __mnt_table_is_fs_mounted(mtab, fs,
+       } else if (rc == 0) {
+               *mounted = __mnt_table_is_fs_mounted(mtab, fs,
                                mnt_context_get_target_prefix(cxt));
 
+       }
+
        if (!mnt_context_switch_ns(cxt, ns_old))
                return -MNT_ERR_NAMESPACE;
-       return 0;
+       return rc;
 }
 
 static int mnt_context_add_child(struct libmnt_context *cxt, pid_t pid)
index 84bc770b3688330552d74460c001e2e6a81e206f..1fc3ff2cce5da44bcd90e7c7d8965c796bf4bdb9 100644 (file)
@@ -1453,8 +1453,15 @@ int mnt_context_next_mount(struct libmnt_context *cxt,
 
        /* ignore already mounted filesystems */
        rc = mnt_context_is_fs_mounted(cxt, *fs, &mounted);
-       if (rc)
+       if (rc) {
+               if (mnt_table_is_empty(cxt->mtab)) {
+                       DBG(CXT, ul_debugobj(cxt, "next-mount: no mount table [rc=%d], ignore", rc));
+                       rc = 0;
+                       if (ignored)
+                               *ignored = 1;
+               }
                return rc;
+       }
        if (mounted) {
                if (ignored)
                        *ignored = 2;
index c3c2e0dcf065f2e3a9b8ebd003992fd203dc7462..3451514e32efe6c1236ec0372236ad39c0490fc9 100644 (file)
@@ -301,7 +301,7 @@ Command-line options available for the *mount* command are:
 *-a*, *--all*::
 Mount all filesystems (of the given types) mentioned in _fstab_ (except for those whose line contains the *noauto* keyword). The filesystems are mounted following their order in _fstab_. The *mount* command compares filesystem source, target (and fs root for bind mount or btrfs) to detect already mounted filesystems. The kernel table with already mounted filesystems is cached during *mount --all*. This means that all duplicated _fstab_ entries will be mounted.
 +
-The correct functionality depends on /proc (to detect already mounted filesystems) and on /sys (to evaluate filesystem tags like UUID= or LABEL=). It's strongly recommended to mount /proc and /sys filesystems before *mount -a* is executed on system boot.
+The correct functionality depends on /proc (to detect already mounted filesystems) and on /sys (to evaluate filesystem tags like UUID= or LABEL=). It's strongly recommended to mount /proc and /sys filesystems before *mount -a* is executed, or keep /proc and /sys at the beginning of fstab.
 +
 The option *--all* is possible to use for remount operation too. In this case all filters (*-t* and *-O*) are applied to the table of already mounted filesystems.
 +