Commit 393a05a7 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Don't use designated initializers for disk_accounting_pos

Not all compilers fully initialize these - they're not guaranteed to
because of the union shenanigans.

Fixes: https://github.com/koverstreet/bcachefs/issues/844


Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f548db4d
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -666,9 +666,9 @@ static int bch2_trigger_stripe_ptr(struct btree_trans *trans,
			stripe_blockcount_get(&s->v, p.ec.block) +
			sectors);

		struct disk_accounting_pos acc = {
			.type = BCH_DISK_ACCOUNTING_replicas,
		};
		struct disk_accounting_pos acc;
		memset(&acc, 0, sizeof(acc));
		acc.type = BCH_DISK_ACCOUNTING_replicas;
		bch2_bkey_to_replicas(&acc.replicas, bkey_i_to_s_c(&s->k_i));
		acc.replicas.data_type = data_type;
		ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, false);
@@ -704,9 +704,9 @@ static int bch2_trigger_stripe_ptr(struct btree_trans *trans,

		m->block_sectors[p.ec.block] += sectors;

		struct disk_accounting_pos acc = {
			.type = BCH_DISK_ACCOUNTING_replicas,
		};
		struct disk_accounting_pos acc;
		memset(&acc, 0, sizeof(acc));
		acc.type = BCH_DISK_ACCOUNTING_replicas;
		memcpy(&acc.replicas, &m->r.e, replicas_entry_bytes(&m->r.e));
		gc_stripe_unlock(m);

@@ -734,12 +734,12 @@ static int __trigger_extent(struct btree_trans *trans,
		: BCH_DATA_user;
	int ret = 0;

	struct disk_accounting_pos acc_replicas_key = {
		.type			= BCH_DISK_ACCOUNTING_replicas,
		.replicas.data_type	= data_type,
		.replicas.nr_devs	= 0,
		.replicas.nr_required	= 1,
	};
	struct disk_accounting_pos acc_replicas_key;
	memset(&acc_replicas_key, 0, sizeof(acc_replicas_key));
	acc_replicas_key.type = BCH_DISK_ACCOUNTING_replicas;
	acc_replicas_key.replicas.data_type	= data_type;
	acc_replicas_key.replicas.nr_devs	= 0;
	acc_replicas_key.replicas.nr_required	= 1;

	unsigned cur_compression_type = 0;
	u64 compression_acct[3] = { 1, 0, 0 };
+2 −4
Original line number Diff line number Diff line
@@ -426,10 +426,8 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
	arg.replica_entries_bytes = replicas.nr;

	for (unsigned i = 0; i < BCH_REPLICAS_MAX; i++) {
		struct disk_accounting_pos k = {
			.type = BCH_DISK_ACCOUNTING_persistent_reserved,
			.persistent_reserved.nr_replicas = i,
		};
		struct disk_accounting_pos k;
		disk_accounting_key_init(k, persistent_reserved, .nr_replicas = i);

		bch2_accounting_mem_read(c,
					 disk_accounting_pos_to_bpos(&k),
+13 −12
Original line number Diff line number Diff line
@@ -114,10 +114,9 @@ int bch2_mod_dev_cached_sectors(struct btree_trans *trans,
				unsigned dev, s64 sectors,
				bool gc)
{
	struct disk_accounting_pos acc = {
		.type = BCH_DISK_ACCOUNTING_replicas,
	};

	struct disk_accounting_pos acc;
	memset(&acc, 0, sizeof(acc));
	acc.type = BCH_DISK_ACCOUNTING_replicas;
	bch2_replicas_entry_cached(&acc.replicas, dev);

	return bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc);
@@ -737,7 +736,9 @@ int bch2_accounting_read(struct bch_fs *c)
				break;

			if (!bch2_accounting_is_mem(acc_k)) {
				struct disk_accounting_pos next = { .type = acc_k.type + 1 };
				struct disk_accounting_pos next;
				memset(&next, 0, sizeof(next));
				next.type = acc_k.type + 1;
				bch2_btree_iter_set_pos(&iter, disk_accounting_pos_to_bpos(&next));
				continue;
			}
@@ -893,15 +894,13 @@ int bch2_dev_usage_remove(struct bch_fs *c, unsigned dev)
int bch2_dev_usage_init(struct bch_dev *ca, bool gc)
{
	struct bch_fs *c = ca->fs;
	struct disk_accounting_pos acc = {
		.type = BCH_DISK_ACCOUNTING_dev_data_type,
		.dev_data_type.dev = ca->dev_idx,
		.dev_data_type.data_type = BCH_DATA_free,
	};
	u64 v[3] = { ca->mi.nbuckets - ca->mi.first_bucket, 0, 0 };

	int ret = bch2_trans_do(c, ({
		bch2_disk_accounting_mod(trans, &acc, v, ARRAY_SIZE(v), gc) ?:
		bch2_disk_accounting_mod2(trans, gc,
					  v, dev_data_type,
					  .dev = ca->dev_idx,
					  .data_type = BCH_DATA_free) ?:
		(!gc ? bch2_trans_commit(trans, NULL, NULL, 0) : 0);
	}));
	bch_err_fn(c, ret);
@@ -928,7 +927,9 @@ void bch2_verify_accounting_clean(struct bch_fs *c)
				break;

			if (!bch2_accounting_is_mem(acc_k)) {
				struct disk_accounting_pos next = { .type = acc_k.type + 1 };
				struct disk_accounting_pos next;
				memset(&next, 0, sizeof(next));
				next.type = acc_k.type + 1;
				bch2_btree_iter_set_pos(&iter, disk_accounting_pos_to_bpos(&next));
				continue;
			}
+11 −9
Original line number Diff line number Diff line
@@ -453,9 +453,9 @@ int bch2_trigger_stripe(struct btree_trans *trans,
		if (new_s) {
			s64 sectors = (u64) le16_to_cpu(new_s->sectors) * new_s->nr_redundant;

			struct disk_accounting_pos acc = {
				.type = BCH_DISK_ACCOUNTING_replicas,
			};
			struct disk_accounting_pos acc;
			memset(&acc, 0, sizeof(acc));
			acc.type = BCH_DISK_ACCOUNTING_replicas;
			bch2_bkey_to_replicas(&acc.replicas, new);
			int ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc);
			if (ret)
@@ -468,9 +468,9 @@ int bch2_trigger_stripe(struct btree_trans *trans,
		if (old_s) {
			s64 sectors = -((s64) le16_to_cpu(old_s->sectors)) * old_s->nr_redundant;

			struct disk_accounting_pos acc = {
				.type = BCH_DISK_ACCOUNTING_replicas,
			};
			struct disk_accounting_pos acc;
			memset(&acc, 0, sizeof(acc));
			acc.type = BCH_DISK_ACCOUNTING_replicas;
			bch2_bkey_to_replicas(&acc.replicas, old);
			int ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc);
			if (ret)
@@ -2110,14 +2110,14 @@ static int bch2_invalidate_stripe_to_dev(struct btree_trans *trans, struct bkey_
	if (ret)
		return ret;

	struct disk_accounting_pos acc = {
		.type = BCH_DISK_ACCOUNTING_replicas,
	};
	struct disk_accounting_pos acc;

	s64 sectors = 0;
	for (unsigned i = 0; i < s->v.nr_blocks; i++)
		sectors -= stripe_blockcount_get(&s->v, i);

	memset(&acc, 0, sizeof(acc));
	acc.type = BCH_DISK_ACCOUNTING_replicas;
	bch2_bkey_to_replicas(&acc.replicas, bkey_i_to_s_c(&s->k_i));
	acc.replicas.data_type = BCH_DATA_user;
	ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, false);
@@ -2131,6 +2131,8 @@ static int bch2_invalidate_stripe_to_dev(struct btree_trans *trans, struct bkey_

	sectors = -sectors;

	memset(&acc, 0, sizeof(acc));
	acc.type = BCH_DISK_ACCOUNTING_replicas;
	bch2_bkey_to_replicas(&acc.replicas, bkey_i_to_s_c(&s->k_i));
	acc.replicas.data_type = BCH_DATA_user;
	ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, false);
+2 −4
Original line number Diff line number Diff line
@@ -16,10 +16,8 @@ void bch2_progress_init(struct progress_indicator_state *s,
		if (!(btree_id_mask & BIT_ULL(i)))
			continue;

		struct disk_accounting_pos acc = {
			.type		= BCH_DISK_ACCOUNTING_btree,
			.btree.id	= i,
		};
		struct disk_accounting_pos acc;
		disk_accounting_key_init(acc, btree, .id = i);

		u64 v;
		bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc), &v, 1);
Loading