summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-06 15:15:41 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2022-03-12 20:14:11 -0500
commit1c74d11fb3f84ce0fb37ef7ff9aeae13c29bab29 (patch)
tree92bd8eb01aa461fc0a7a1d7338101f4ffa9aac9a
parente9b22ea68ad8b8462c1d079ad4798a01cbd5a64b (diff)
bcachefs: Check for rw before setting opts via sysfs
This isn't a correctness issue, it just eliminates errors in the dmesg log when we're RO. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/sysfs.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c
index 49e38859bff8..3d6ece515a88 100644
--- a/fs/bcachefs/sysfs.c
+++ b/fs/bcachefs/sysfs.c
@@ -607,23 +607,32 @@ STORE(bch2_fs_opts_dir)
{
struct bch_fs *c = container_of(kobj, struct bch_fs, opts_dir);
const struct bch_option *opt = container_of(attr, struct bch_option, attr);
- int ret, id = opt - bch2_opt_table;
+ int ret = size, id = opt - bch2_opt_table;
char *tmp;
u64 v;
+ /*
+ * We don't need to take c->writes for correctness, but it eliminates an
+ * unsightly error message in the dmesg log when we're RO:
+ */
+ if (unlikely(!percpu_ref_tryget(&c->writes)))
+ return -EROFS;
+
tmp = kstrdup(buf, GFP_KERNEL);
- if (!tmp)
- return -ENOMEM;
+ if (!tmp) {
+ ret = -ENOMEM;
+ goto err;
+ }
ret = bch2_opt_parse(c, NULL, opt, strim(tmp), &v);
kfree(tmp);
if (ret < 0)
- return ret;
+ goto err;
ret = bch2_opt_check_may_set(c, id, v);
if (ret < 0)
- return ret;
+ goto err;
bch2_opt_set_sb(c, opt, v);
bch2_opt_set_by_id(&c->opts, id, v);
@@ -633,8 +642,9 @@ STORE(bch2_fs_opts_dir)
bch2_rebalance_add_work(c, S64_MAX);
rebalance_wakeup(c);
}
-
- return size;
+err:
+ percpu_ref_put(&c->writes);
+ return ret;
}
SYSFS_OPS(bch2_fs_opts_dir);