In bch2_sb_set_upgrade_extra, it checks the metadata version for
stripes. If it needs to write super, bch2_write_super will be done.
But this pharse may be incorrect, and the original code didn't keep
the error code. We should check the return code in this case.
Fixes: 7773df19c35f ("bcachefs: metadata version bucket_stripe_sectors")
Signed-off-by: Hongbo Li <[email protected]>
---
fs/bcachefs/recovery.c | 2 ++
fs/bcachefs/sb-downgrade.c | 8 ++++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index be1e7ca4362f..31e33f93055f 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -855,6 +855,8 @@ int bch2_fs_recovery(struct bch_fs *c)
set_bit(BCH_FS_btree_running, &c->flags);
ret = bch2_sb_set_upgrade_extra(c);
+ if (ret)
+ goto err;
ret = bch2_run_recovery_passes(c);
if (ret)
diff --git a/fs/bcachefs/sb-downgrade.c b/fs/bcachefs/sb-downgrade.c
index 6f0493f79959..2acb52d107be 100644
--- a/fs/bcachefs/sb-downgrade.c
+++ b/fs/bcachefs/sb-downgrade.c
@@ -138,7 +138,7 @@ UPGRADE_TABLE()
#undef x
};
-static int have_stripes(struct bch_fs *c)
+static bool have_stripes(struct bch_fs *c)
{
return !btree_node_fake(c->btree_roots_known[BTREE_ID_stripes].b);
}
@@ -155,7 +155,7 @@ int bch2_sb_set_upgrade_extra(struct bch_fs *c)
if (old_version < bcachefs_metadata_version_bucket_stripe_sectors &&
new_version >= bcachefs_metadata_version_bucket_stripe_sectors &&
- (ret = have_stripes(c) > 0)) {
+ have_stripes(c)) {
__set_bit_le64(BCH_RECOVERY_PASS_STABLE_check_allocations,
ext->recovery_passes_required);
__set_bit_le64(BCH_FSCK_ERR_alloc_key_dirty_sectors_wrong,
ext->errors_silent);
__set_bit_le64(BCH_FSCK_ERR_alloc_key_stripe_sectors_wrong,
ext->errors_silent);
@@ -163,10 +163,10 @@ int bch2_sb_set_upgrade_extra(struct bch_fs *c)
}
if (write_sb)
- bch2_write_super(c);
+ ret = bch2_write_super(c);
mutex_unlock(&c->sb_lock);
- return ret < 0 ? ret : 0;
+ return ret;
}
void bch2_sb_set_upgrade(struct bch_fs *c,
--
2.34.1