summaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorKarel Zak2019-01-16 15:00:07 +0100
committerKarel Zak2019-01-16 15:00:07 +0100
commit189a1bf3b314a8fc48c29ea1e0287d5cc71021a0 (patch)
tree684d7415e61e2769f2053cc35801f0c8256d8396 /sys-utils
parentfsck.cramfs: fix utimes() usage (diff)
downloadkernel-qcow2-util-linux-189a1bf3b314a8fc48c29ea1e0287d5cc71021a0.tar.gz
kernel-qcow2-util-linux-189a1bf3b314a8fc48c29ea1e0287d5cc71021a0.tar.xz
kernel-qcow2-util-linux-189a1bf3b314a8fc48c29ea1e0287d5cc71021a0.zip
libmount: add support for MS_REMOUNT on --all
This patch add to support for remount-all operation to libmount and mount(8). For example: mount --all -o remount,ro -t vfat to remount read-only all VFAT filesystems. Addresses: https://github.com/karelzak/util-linux/issues/589 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/mount.84
-rw-r--r--sys-utils/mount.c56
2 files changed, 59 insertions, 1 deletions
diff --git a/sys-utils/mount.8 b/sys-utils/mount.8
index da0ac5b8b..6ef589050 100644
--- a/sys-utils/mount.8
+++ b/sys-utils/mount.8
@@ -580,6 +580,10 @@ mount or btrfs) to detect already mounted filesystems. The kernel table with
already mounted filesystems is cached during \fBmount \-\-all\fR. It means
that all duplicated fstab entries will be mounted.
.sp
+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
Note that it is a bad practice to use \fBmount \-a\fR for
.I fstab
checking. The recommended solution is \fBfindmnt \-\-verify\fR.
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index 5e139e896..f4a387b8a 100644
--- a/sys-utils/mount.c
+++ b/sys-utils/mount.c
@@ -231,6 +231,57 @@ static int mount_all(struct libmnt_context *cxt)
return rc;
}
+
+/*
+ * mount -a -o remount
+ */
+static int remount_all(struct libmnt_context *cxt)
+{
+ struct libmnt_iter *itr;
+ struct libmnt_fs *fs;
+ int mntrc, ignored, rc = MNT_EX_SUCCESS;
+
+ int nsucc = 0, nerrs = 0;
+
+ itr = mnt_new_iter(MNT_ITER_FORWARD);
+ if (!itr) {
+ warn(_("failed to initialize libmount iterator"));
+ return MNT_EX_SYSERR;
+ }
+
+ while (mnt_context_next_remount(cxt, itr, &fs, &mntrc, &ignored) == 0) {
+
+ const char *tgt = mnt_fs_get_target(fs);
+
+ if (ignored) {
+ if (mnt_context_is_verbose(cxt))
+ printf(_("%-25s: ignored\n"), tgt);
+ } else {
+ if (mk_exit_code(cxt, mntrc) == MNT_EX_SUCCESS) {
+ nsucc++;
+
+ /* Note that MNT_EX_SUCCESS return code does
+ * not mean that FS has been really mounted
+ * (e.g. nofail option) */
+ if (mnt_context_get_status(cxt)
+ && mnt_context_is_verbose(cxt))
+ printf("%-25s: successfully remounted\n", tgt);
+ } else
+ nerrs++;
+ }
+ }
+
+ if (nerrs == 0)
+ rc = MNT_EX_SUCCESS; /* all success */
+ else if (nsucc == 0)
+ rc = MNT_EX_FAIL; /* all failed */
+ else
+ rc = MNT_EX_SOMEOK; /* some success, some failed */
+
+ mnt_free_iter(itr);
+ return rc;
+}
+
static void success_message(struct libmnt_context *cxt)
{
unsigned long mflags = 0;
@@ -836,7 +887,10 @@ int main(int argc, char **argv)
/*
* A) Mount all
*/
- rc = mount_all(cxt);
+ if (has_remount_flag(cxt))
+ rc = remount_all(cxt);
+ else
+ rc = mount_all(cxt);
goto done;
} else if (argc == 0 && (mnt_context_get_source(cxt) ||