diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-03-06 15:15:41 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:27 -0400 |
commit | f0cc5d2931378b7a2a7e797c726a2ab760d4a84d (patch) | |
tree | 08720eb30a2f43acfce6715a0ae20810d85fe72c /fs/bcachefs/sysfs.c | |
parent | 07b8121f07056480c54fca99046870d84a657d13 (diff) | |
download | linux-f0cc5d2931378b7a2a7e797c726a2ab760d4a84d.tar.gz linux-f0cc5d2931378b7a2a7e797c726a2ab760d4a84d.tar.bz2 linux-f0cc5d2931378b7a2a7e797c726a2ab760d4a84d.zip |
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>
Diffstat (limited to 'fs/bcachefs/sysfs.c')
-rw-r--r-- | fs/bcachefs/sysfs.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index 49e38859bff8..afcb5ad1aa62 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -611,19 +611,28 @@ STORE(bch2_fs_opts_dir) 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); @@ -634,7 +643,10 @@ STORE(bch2_fs_opts_dir) rebalance_wakeup(c); } - return size; + ret = size; +err: + percpu_ref_put(&c->writes); + return ret; } SYSFS_OPS(bch2_fs_opts_dir); |