bcachefs: fix simulateously upgrading & downgrading
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 00:04:42 +0000 (19:04 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 6 Jan 2024 04:24:21 +0000 (23:24 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super-io.c

index c05983fe681557875e75c57d4202de944ed1e4b7..55926b81eede63596f7a48f6daaa363bede4d504 100644 (file)
@@ -1088,13 +1088,22 @@ bool bch2_check_version_downgrade(struct bch_fs *c)
        /*
         * Downgrade, if superblock is at a higher version than currently
         * supported:
+        *
+        * c->sb will be checked before we write the superblock, so update it as
+        * well:
         */
-       if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) > bcachefs_metadata_version_current)
+       if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) > bcachefs_metadata_version_current) {
                SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, bcachefs_metadata_version_current);
-       if (c->sb.version > bcachefs_metadata_version_current)
+               c->sb.version_upgrade_complete = bcachefs_metadata_version_current;
+       }
+       if (c->sb.version > bcachefs_metadata_version_current) {
                c->disk_sb.sb->version = cpu_to_le16(bcachefs_metadata_version_current);
-       if (c->sb.version_min > bcachefs_metadata_version_current)
+               c->sb.version = bcachefs_metadata_version_current;
+       }
+       if (c->sb.version_min > bcachefs_metadata_version_current) {
                c->disk_sb.sb->version_min = cpu_to_le16(bcachefs_metadata_version_current);
+               c->sb.version_min = bcachefs_metadata_version_current;
+       }
        c->disk_sb.sb->compat[0] &= cpu_to_le64((1ULL << BCH_COMPAT_NR) - 1);
        return ret;
 }