summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bertschinger <tahbertschinger@gmail.com>2024-05-26 13:08:19 -0600
committerKent Overstreet <kent.overstreet@linux.dev>2024-06-23 12:57:13 -0400
commit87c521d09c085b66e9a45f60bd60c3bab380a46e (patch)
treedd4fb77e4f10c4485e4c06f410b9f123e0851ea8
parent15d1ac22282952e765722c158481c24ccef61525 (diff)
bcachefs: make offline fsck set read_only fs flag
A subsequent change will remove "read_only" as a mount option in favor of the standard option "ro", meaning the userspace fsck command cannot pass it to the fsck ioctl. Instead, in offline fsck, set "read_only" kernel-side without trying to parse it as a mount option. For compatibility with versions of the "bcachefs fsck" command that try to pass the "read_only" mount opt, remove it from the mount options string prior to parsing when it is present. Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/chardev.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index 6d82e1165adc..8c5b13cd3205 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -213,6 +213,18 @@ static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_a
if (arg.opts) {
char *optstr = strndup_user((char __user *)(unsigned long) arg.opts, 1 << 16);
+ char *ro, *rest;
+
+ /*
+ * If passed a "read_only" mount option, remove it because it is
+ * no longer a valid mount option, and the filesystem will be
+ * set "read_only" regardless.
+ */
+ ro = strstr(optstr, "read_only");
+ if (ro) {
+ rest = ro + strlen("read_only");
+ memmove(ro, rest, strlen(rest) + 1);
+ }
ret = PTR_ERR_OR_ZERO(optstr) ?:
bch2_parse_mount_opts(NULL, &thr->opts, optstr);
@@ -224,6 +236,7 @@ static long bch2_ioctl_fsck_offline(struct bch_ioctl_fsck_offline __user *user_a
}
opt_set(thr->opts, stdio, (u64)(unsigned long)&thr->thr.stdio);
+ opt_set(thr->opts, read_only, 1);
/* We need request_key() to be called before we punt to kthread: */
opt_set(thr->opts, nostart, true);