]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Device state is now a runtime option
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 13 Mar 2025 04:55:52 +0000 (00:55 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 24 Mar 2025 13:50:35 +0000 (09:50 -0400)
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>
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/sysfs.c

index de24af773224334090d0064315a8e3f42a789030..d0ce96529dd48bcc0531c586897f35c70833fbbb 100644 (file)
@@ -482,9 +482,16 @@ void bch2_opts_to_text(struct printbuf *out,
 
 int bch2_opt_check_may_set(struct bch_fs *c, struct bch_dev *ca, int id, u64 v)
 {
+       lockdep_assert_held(&c->state_lock);
+
        int ret = 0;
 
        switch (id) {
+       case Opt_state:
+               if (ca)
+                       return __bch2_dev_set_state(c, ca, v, BCH_FORCE_IF_DEGRADED);
+               break;
+
        case Opt_compression:
        case Opt_background_compression:
                ret = bch2_check_set_has_compressed_data(c, v);
index 19fcc0e51c0bd7e585c4c89c6b1e66d67c812df6..0bf39e4b1c8ec358d4f2159896c377dd2d1430d6 100644 (file)
@@ -495,7 +495,7 @@ enum fsck_err_opts {
          NULL,         "Skip submit_bio() for data reads and writes, " \
                        "for performance testing purposes")             \
        x(state,                        u64,                            \
-         OPT_DEVICE,                                                   \
+         OPT_DEVICE|OPT_RUNTIME,                                       \
          OPT_STR(bch2_member_states),                                  \
          BCH_MEMBER_STATE,             BCH_MEMBER_STATE_rw,            \
          "state",      "rw,ro,failed,spare")                           \
index b01b2ae87051451b8f186c12af2590c4dd533974..e8a795578186b2c3f987a964ef6388cb6e432ab0 100644 (file)
@@ -631,6 +631,8 @@ static ssize_t sysfs_opt_store(struct bch_fs *c,
        if (unlikely(!bch2_write_ref_tryget(c, BCH_WRITE_REF_sysfs)))
                return -EROFS;
 
+       down_write(&c->state_lock);
+
        char *tmp = kstrdup(buf, GFP_KERNEL);
        if (!tmp) {
                ret = -ENOMEM;
@@ -664,6 +666,7 @@ static ssize_t sysfs_opt_store(struct bch_fs *c,
 
        ret = size;
 err:
+       up_write(&c->state_lock);
        bch2_write_ref_put(c, BCH_WRITE_REF_sysfs);
        return ret;
 }