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

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
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -592,16 +592,9 @@ int bch2_fs_recovery(struct bch_fs *c)

	if (!c->opts.nochanges) {
		mutex_lock(&c->sb_lock);
		struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
		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)) {
			ext->recovery_passes_required[0] |=
				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)
	}

	mutex_lock(&c->sb_lock);
	struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
	bool write_sb = false;

	if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) != le16_to_cpu(c->disk_sb.sb->version)) {
@@ -845,16 +839,13 @@ int bch2_fs_recovery(struct bch_fs *c)
		write_sb = true;
	}

	if (!test_bit(BCH_FS_error, &c->flags)) {
		struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
		if (ext &&
	if (!test_bit(BCH_FS_error, &c->flags) &&
	    (!bch2_is_zero(ext->recovery_passes_required, sizeof(ext->recovery_passes_required)) ||
	     !bch2_is_zero(ext->errors_silent, sizeof(ext->errors_silent)))) {
		memset(ext->recovery_passes_required, 0, sizeof(ext->recovery_passes_required));
		memset(ext->errors_silent, 0, sizeof(ext->errors_silent));
		write_sb = true;
	}
	}

	if (c->opts.fsck &&
	    !test_bit(BCH_FS_error, &c->flags) &&
+8 −0
Original line number Diff line number Diff line
@@ -1015,8 +1015,16 @@ int bch2_fs_start(struct bch_fs *c)
	for_each_online_member(c, ca)
		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);

	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)
		bch2_dev_allocator_add(c, ca);
	bch2_recalc_capacity(c);