]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: allow use -o together with --all
authorKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2019 11:10:03 +0000 (12:10 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 31 Oct 2019 11:25:08 +0000 (12:25 +0100)
For example:
# mount --verbose --all -t xfs -o ro

will mount all all XFS filesystems from fstab, but read-only.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context_mount.c
sys-utils/mount.8

index ae72929330deeb39a95bb6383eb9fbe31f2fc4a8..70a843e89b6146ace9722e44bcee2dff0f7bea0b 100644 (file)
@@ -1291,11 +1291,6 @@ int mnt_context_next_mount(struct libmnt_context *cxt,
        if (!cxt || !fs || !itr)
                return -EINVAL;
 
-       mtab = cxt->mtab;
-       cxt->mtab = NULL;               /* do not reset mtab */
-       mnt_reset_context(cxt);
-       cxt->mtab = mtab;
-
        rc = mnt_context_get_fstab(cxt, &fstab);
        if (rc)
                return rc;
@@ -1346,6 +1341,23 @@ int mnt_context_next_mount(struct libmnt_context *cxt,
                return 0;
        }
 
+       /* Save mount options, etc. -- this is effective for the first
+        * mnt_context_next_mount() call only. Make sure that cxt has not set
+        * source, target or fstype.
+        */
+       if (!mnt_context_has_template(cxt)) {
+               mnt_context_set_source(cxt, NULL);
+               mnt_context_set_target(cxt, NULL);
+               mnt_context_set_fstype(cxt, NULL);
+               mnt_context_save_template(cxt);
+       }
+
+       /* reset context, but protect mtab */
+       mtab = cxt->mtab;
+       cxt->mtab = NULL;
+       mnt_reset_context(cxt);
+       cxt->mtab = mtab;
+
        if (mnt_context_is_fork(cxt)) {
                rc = mnt_fork_context(cxt);
                if (rc)
@@ -1356,9 +1368,12 @@ int mnt_context_next_mount(struct libmnt_context *cxt,
                }
        }
 
-       /* child or non-forked */
+       /*
+        * child or non-forked
+        */
 
-       rc = mnt_context_set_fs(cxt, *fs);
+       /* copy stuff from fstab to context */
+       rc = mnt_context_apply_fs(cxt, *fs);
        if (!rc) {
                /*
                 * "-t <pattern>" is used to filter out fstab entries, but for ordinary
@@ -1470,8 +1485,16 @@ int mnt_context_next_remount(struct libmnt_context *cxt,
                return 0;
        }
 
-       if (!mnt_context_has_template(cxt))
+       /* Save mount options, etc. -- this is effective for the first
+        * mnt_context_next_remount() call only. Make sure that cxt has not set
+        * source, target or fstype.
+        */
+       if (!mnt_context_has_template(cxt)) {
+               mnt_context_set_source(cxt, NULL);
+               mnt_context_set_target(cxt, NULL);
+               mnt_context_set_fstype(cxt, NULL);
                mnt_context_save_template(cxt);
+       }
 
        /* restore original, but protect mtab */
        cxt->mtab = NULL;
index 7b3f876617dafdfe1b04cbf9be6c44b9eba12ba8..75d90e4e9be54f63ccc79b38858f08e112a8f5bd 100644 (file)
@@ -583,6 +583,9 @@ The option \fB\-\-all\fR is possible to use for remount operation too. In this
 case all filters (\fB\-t\fR and \fB\-O\fR) are applied to the table of already
 mounted filesystems.
 .sp
+Since version 2.35 is possible to use the command line option \fB\-o\fR to
+alter mount options from fstab (see also \fB\-\-options\-mode\fR).
+.sp
 Note that it is a bad practice to use \fBmount \-a\fR for
 .I fstab
 checking. The recommended solution is \fBfindmnt \-\-verify\fR.