Commit 0a34c058 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Ensure bch_sb_field_ext always exists

This makes bch_sb_field_ext more consistent with the rest of -o
nochanges - we don't want to be varying other codepaths based on -o
nochanges, since it's used for testing in dry run mode; also fixes some
potential null ptr derefs.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4fe0eeea
...@@ -592,16 +592,9 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -592,16 +592,9 @@ int bch2_fs_recovery(struct bch_fs *c)
if (!c->opts.nochanges) { if (!c->opts.nochanges) {
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
bool write_sb = false; bool write_sb = false;
struct bch_sb_field_ext *ext =
bch2_sb_field_get_minsize(&c->disk_sb, ext, sizeof(*ext) / sizeof(u64));
if (!ext) {
ret = -BCH_ERR_ENOSPC_sb;
mutex_unlock(&c->sb_lock);
goto err;
}
if (BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb)) { if (BCH_SB_HAS_TOPOLOGY_ERRORS(c->disk_sb.sb)) {
ext->recovery_passes_required[0] |= ext->recovery_passes_required[0] |=
cpu_to_le64(bch2_recovery_passes_to_stable(BIT_ULL(BCH_RECOVERY_PASS_check_topology))); cpu_to_le64(bch2_recovery_passes_to_stable(BIT_ULL(BCH_RECOVERY_PASS_check_topology)));
...@@ -832,6 +825,7 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -832,6 +825,7 @@ int bch2_fs_recovery(struct bch_fs *c)
} }
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
bool write_sb = false; bool write_sb = false;
if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) != le16_to_cpu(c->disk_sb.sb->version)) { if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) != le16_to_cpu(c->disk_sb.sb->version)) {
...@@ -845,15 +839,12 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -845,15 +839,12 @@ int bch2_fs_recovery(struct bch_fs *c)
write_sb = true; write_sb = true;
} }
if (!test_bit(BCH_FS_error, &c->flags)) { if (!test_bit(BCH_FS_error, &c->flags) &&
struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext); (!bch2_is_zero(ext->recovery_passes_required, sizeof(ext->recovery_passes_required)) ||
if (ext && !bch2_is_zero(ext->errors_silent, sizeof(ext->errors_silent)))) {
(!bch2_is_zero(ext->recovery_passes_required, sizeof(ext->recovery_passes_required)) || memset(ext->recovery_passes_required, 0, sizeof(ext->recovery_passes_required));
!bch2_is_zero(ext->errors_silent, sizeof(ext->errors_silent)))) { memset(ext->errors_silent, 0, sizeof(ext->errors_silent));
memset(ext->recovery_passes_required, 0, sizeof(ext->recovery_passes_required)); write_sb = true;
memset(ext->errors_silent, 0, sizeof(ext->errors_silent));
write_sb = true;
}
} }
if (c->opts.fsck && if (c->opts.fsck &&
......
...@@ -1015,8 +1015,16 @@ int bch2_fs_start(struct bch_fs *c) ...@@ -1015,8 +1015,16 @@ int bch2_fs_start(struct bch_fs *c)
for_each_online_member(c, ca) for_each_online_member(c, ca)
bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = cpu_to_le64(now); bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx)->last_mount = cpu_to_le64(now);
struct bch_sb_field_ext *ext =
bch2_sb_field_get_minsize(&c->disk_sb, ext, sizeof(*ext) / sizeof(u64));
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
if (!ext) {
bch_err(c, "insufficient space in superblock for sb_field_ext");
ret = -BCH_ERR_ENOSPC_sb;
goto err;
}
for_each_rw_member(c, ca) for_each_rw_member(c, ca)
bch2_dev_allocator_add(c, ca); bch2_dev_allocator_add(c, ca);
bch2_recalc_capacity(c); bch2_recalc_capacity(c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment