Skip to content

Commit 8d7b7ac

Browse files
author
Kent Overstreet
committed
bcachefs: Device state is now a runtime option
Other options can normally be set at runtime via sysfs, no reason for this one not to be as well - it just doesn't support the degraded flags argument this way, that requires the ioctl. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 7b84d93 commit 8d7b7ac

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

fs/bcachefs/opts.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,16 @@ void bch2_opts_to_text(struct printbuf *out,
482482

483483
int bch2_opt_check_may_set(struct bch_fs *c, struct bch_dev *ca, int id, u64 v)
484484
{
485+
lockdep_assert_held(&c->state_lock);
486+
485487
int ret = 0;
486488

487489
switch (id) {
490+
case Opt_state:
491+
if (ca)
492+
return __bch2_dev_set_state(c, ca, v, BCH_FORCE_IF_DEGRADED);
493+
break;
494+
488495
case Opt_compression:
489496
case Opt_background_compression:
490497
ret = bch2_check_set_has_compressed_data(c, v);

fs/bcachefs/opts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ enum fsck_err_opts {
495495
NULL, "Skip submit_bio() for data reads and writes, " \
496496
"for performance testing purposes") \
497497
x(state, u64, \
498-
OPT_DEVICE, \
498+
OPT_DEVICE|OPT_RUNTIME, \
499499
OPT_STR(bch2_member_states), \
500500
BCH_MEMBER_STATE, BCH_MEMBER_STATE_rw, \
501501
"state", "rw,ro,failed,spare") \

fs/bcachefs/sysfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,8 @@ static ssize_t sysfs_opt_store(struct bch_fs *c,
631631
if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
632632
return -EROFS;
633633

634+
down_write(&c->state_lock);
635+
634636
char *tmp = kstrdup(buf, GFP_KERNEL);
635637
if (!tmp) {
636638
ret = -ENOMEM;
@@ -664,6 +666,7 @@ static ssize_t sysfs_opt_store(struct bch_fs *c,
664666

665667
ret = size;
666668
err:
669+
up_write(&c->state_lock);
667670
bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
668671
return ret;
669672
}

0 commit comments

Comments
 (0)