bcachefs: Incompatible features may now be enabled at runtime
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 15 Apr 2025 14:20:46 +0000 (10:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:16 +0000 (20:14 -0400)
version_upgrade is now a runtime option.

In the future we'll want to add compatible upgrades at runtime, and call
the full check_version_upgrade() when the option changes, but we don't
have compatible optional upgrades just yet.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/recovery.c
fs/bcachefs/super-io.c
fs/bcachefs/super-io.h

index 386482ff8e7bdd58c50bf5c3557724a81f84482d..b1cf88905b816edf424cd5c0d1ab3745b7a87339 100644 (file)
@@ -595,6 +595,15 @@ void bch2_opt_hook_post_set(struct bch_fs *c, struct bch_dev *ca, u64 inum,
                        mutex_unlock(&c->sb_lock);
                }
                break;
+       case Opt_version_upgrade:
+               /*
+                * XXX: in the future we'll likely want to do compatible
+                * upgrades at runtime as well, but right now there's nothing
+                * that does that:
+                */
+               if (new_opts->version_upgrade == BCH_VERSION_UPGRADE_incompatible)
+                       bch2_sb_upgrade_incompat(c);
+               break;
        default:
                break;
        }
index b7952405d502a6973f2677e4a343d0d1d645e086..b8cd0b04e62aee169e01f15424fa5026c363d050 100644 (file)
@@ -450,7 +450,7 @@ enum fsck_err_opts {
          BCH2_NO_SB_OPT,               false,                          \
          NULL,         "Reconstruct alloc btree")                      \
        x(version_upgrade,              u8,                             \
-         OPT_FS|OPT_MOUNT,                                             \
+         OPT_FS|OPT_MOUNT|OPT_RUNTIME,                                 \
          OPT_STR(bch2_version_upgrade_opts),                           \
          BCH_SB_VERSION_UPGRADE,       BCH_VERSION_UPGRADE_compatible, \
          NULL,         "Set superblock to latest version,\n"           \
index d6c4ef819d40ac9fc73db339d62933f3dcc28b46..4c336f20d5ebaaaa2c5b9b99111097646490b2f8 100644 (file)
@@ -667,7 +667,7 @@ static bool check_version_upgrade(struct bch_fs *c)
                                     bch2_recovery_passes_from_stable(le64_to_cpu(passes)));
                }
 
-               bch_info(c, "%s", buf.buf);
+               bch_notice(c, "%s", buf.buf);
                printbuf_exit(&buf);
 
                ret = true;
@@ -683,7 +683,7 @@ static bool check_version_upgrade(struct bch_fs *c)
                bch2_version_to_text(&buf, c->sb.version_incompat_allowed);
                prt_newline(&buf);
 
-               bch_info(c, "%s", buf.buf);
+               bch_notice(c, "%s", buf.buf);
                printbuf_exit(&buf);
 
                ret = true;
index 2435e114cad9148631400719db0893eebecdffb3..8ebc5e3f3ea3bcd54736486ecdee10a759698667 100644 (file)
@@ -1274,6 +1274,31 @@ void bch2_sb_upgrade(struct bch_fs *c, unsigned new_version, bool incompat)
        }
 }
 
+void bch2_sb_upgrade_incompat(struct bch_fs *c)
+{
+       mutex_lock(&c->sb_lock);
+       if (c->sb.version == c->sb.version_incompat_allowed)
+               goto unlock;
+
+       struct printbuf buf = PRINTBUF;
+
+       prt_str(&buf, "Now allowing incompatible features up to ");
+       bch2_version_to_text(&buf, c->sb.version);
+       prt_str(&buf, ", previously allowed up to ");
+       bch2_version_to_text(&buf, c->sb.version_incompat_allowed);
+       prt_newline(&buf);
+
+       bch_notice(c, "%s", buf.buf);
+       printbuf_exit(&buf);
+
+       c->disk_sb.sb->features[0] |= cpu_to_le64(BCH_SB_FEATURES_ALL);
+       SET_BCH_SB_VERSION_INCOMPAT_ALLOWED(c->disk_sb.sb,
+                       max(BCH_SB_VERSION_INCOMPAT_ALLOWED(c->disk_sb.sb), c->sb.version));
+       bch2_write_super(c);
+unlock:
+       mutex_unlock(&c->sb_lock);
+}
+
 static int bch2_sb_ext_validate(struct bch_sb *sb, struct bch_sb_field *f,
                                enum bch_validate_flags flags, struct printbuf *err)
 {
index 78f708a6fbcdfb5bdf8302ae6abf9be9c1613291..a3b7a90f2533db39de93d93a5c1bc00f478015bd 100644 (file)
@@ -107,6 +107,7 @@ static inline void bch2_check_set_feature(struct bch_fs *c, unsigned feat)
 
 bool bch2_check_version_downgrade(struct bch_fs *);
 void bch2_sb_upgrade(struct bch_fs *, unsigned, bool);
+void bch2_sb_upgrade_incompat(struct bch_fs *);
 
 void __bch2_sb_field_to_text(struct printbuf *, struct bch_sb *,
                             struct bch_sb_field *);