Skip to content

Commit 393a05a

Browse files
author
Kent Overstreet
committed
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: koverstreet/bcachefs#844 Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent f548db4 commit 393a05a

File tree

7 files changed

+44
-46
lines changed

7 files changed

+44
-46
lines changed

fs/bcachefs/buckets.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ static int bch2_trigger_stripe_ptr(struct btree_trans *trans,
666666
stripe_blockcount_get(&s->v, p.ec.block) +
667667
sectors);
668668

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

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

707-
struct disk_accounting_pos acc = {
708-
.type = BCH_DISK_ACCOUNTING_replicas,
709-
};
707+
struct disk_accounting_pos acc;
708+
memset(&acc, 0, sizeof(acc));
709+
acc.type = BCH_DISK_ACCOUNTING_replicas;
710710
memcpy(&acc.replicas, &m->r.e, replicas_entry_bytes(&m->r.e));
711711
gc_stripe_unlock(m);
712712

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

737-
struct disk_accounting_pos acc_replicas_key = {
738-
.type = BCH_DISK_ACCOUNTING_replicas,
739-
.replicas.data_type = data_type,
740-
.replicas.nr_devs = 0,
741-
.replicas.nr_required = 1,
742-
};
737+
struct disk_accounting_pos acc_replicas_key;
738+
memset(&acc_replicas_key, 0, sizeof(acc_replicas_key));
739+
acc_replicas_key.type = BCH_DISK_ACCOUNTING_replicas;
740+
acc_replicas_key.replicas.data_type = data_type;
741+
acc_replicas_key.replicas.nr_devs = 0;
742+
acc_replicas_key.replicas.nr_required = 1;
743743

744744
unsigned cur_compression_type = 0;
745745
u64 compression_acct[3] = { 1, 0, 0 };

fs/bcachefs/chardev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,8 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c,
426426
arg.replica_entries_bytes = replicas.nr;
427427

428428
for (unsigned i = 0; i < BCH_REPLICAS_MAX; i++) {
429-
struct disk_accounting_pos k = {
430-
.type = BCH_DISK_ACCOUNTING_persistent_reserved,
431-
.persistent_reserved.nr_replicas = i,
432-
};
429+
struct disk_accounting_pos k;
430+
disk_accounting_key_init(k, persistent_reserved, .nr_replicas = i);
433431

434432
bch2_accounting_mem_read(c,
435433
disk_accounting_pos_to_bpos(&k),

fs/bcachefs/disk_accounting.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ int bch2_mod_dev_cached_sectors(struct btree_trans *trans,
114114
unsigned dev, s64 sectors,
115115
bool gc)
116116
{
117-
struct disk_accounting_pos acc = {
118-
.type = BCH_DISK_ACCOUNTING_replicas,
119-
};
120-
117+
struct disk_accounting_pos acc;
118+
memset(&acc, 0, sizeof(acc));
119+
acc.type = BCH_DISK_ACCOUNTING_replicas;
121120
bch2_replicas_entry_cached(&acc.replicas, dev);
122121

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

739738
if (!bch2_accounting_is_mem(acc_k)) {
740-
struct disk_accounting_pos next = { .type = acc_k.type + 1 };
739+
struct disk_accounting_pos next;
740+
memset(&next, 0, sizeof(next));
741+
next.type = acc_k.type + 1;
741742
bch2_btree_iter_set_pos(&iter, disk_accounting_pos_to_bpos(&next));
742743
continue;
743744
}
@@ -893,15 +894,13 @@ int bch2_dev_usage_remove(struct bch_fs *c, unsigned dev)
893894
int bch2_dev_usage_init(struct bch_dev *ca, bool gc)
894895
{
895896
struct bch_fs *c = ca->fs;
896-
struct disk_accounting_pos acc = {
897-
.type = BCH_DISK_ACCOUNTING_dev_data_type,
898-
.dev_data_type.dev = ca->dev_idx,
899-
.dev_data_type.data_type = BCH_DATA_free,
900-
};
901897
u64 v[3] = { ca->mi.nbuckets - ca->mi.first_bucket, 0, 0 };
902898

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

930929
if (!bch2_accounting_is_mem(acc_k)) {
931-
struct disk_accounting_pos next = { .type = acc_k.type + 1 };
930+
struct disk_accounting_pos next;
931+
memset(&next, 0, sizeof(next));
932+
next.type = acc_k.type + 1;
932933
bch2_btree_iter_set_pos(&iter, disk_accounting_pos_to_bpos(&next));
933934
continue;
934935
}

fs/bcachefs/ec.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ int bch2_trigger_stripe(struct btree_trans *trans,
453453
if (new_s) {
454454
s64 sectors = (u64) le16_to_cpu(new_s->sectors) * new_s->nr_redundant;
455455

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

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

2113-
struct disk_accounting_pos acc = {
2114-
.type = BCH_DISK_ACCOUNTING_replicas,
2115-
};
2113+
struct disk_accounting_pos acc;
21162114

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

2119+
memset(&acc, 0, sizeof(acc));
2120+
acc.type = BCH_DISK_ACCOUNTING_replicas;
21212121
bch2_bkey_to_replicas(&acc.replicas, bkey_i_to_s_c(&s->k_i));
21222122
acc.replicas.data_type = BCH_DATA_user;
21232123
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_
21312131

21322132
sectors = -sectors;
21332133

2134+
memset(&acc, 0, sizeof(acc));
2135+
acc.type = BCH_DISK_ACCOUNTING_replicas;
21342136
bch2_bkey_to_replicas(&acc.replicas, bkey_i_to_s_c(&s->k_i));
21352137
acc.replicas.data_type = BCH_DATA_user;
21362138
ret = bch2_disk_accounting_mod(trans, &acc, &sectors, 1, false);

fs/bcachefs/progress.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ void bch2_progress_init(struct progress_indicator_state *s,
1616
if (!(btree_id_mask & BIT_ULL(i)))
1717
continue;
1818

19-
struct disk_accounting_pos acc = {
20-
.type = BCH_DISK_ACCOUNTING_btree,
21-
.btree.id = i,
22-
};
19+
struct disk_accounting_pos acc;
20+
disk_accounting_key_init(acc, btree, .id = i);
2321

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

fs/bcachefs/rebalance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ void bch2_rebalance_status_to_text(struct printbuf *out, struct bch_fs *c)
600600
struct bch_fs_rebalance *r = &c->rebalance;
601601

602602
/* print pending work */
603-
struct disk_accounting_pos acc = { .type = BCH_DISK_ACCOUNTING_rebalance_work, };
603+
struct disk_accounting_pos acc;
604+
disk_accounting_key_init(acc, rebalance_work);
604605
u64 v;
605606
bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc), &v, 1);
606607

fs/bcachefs/sysfs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,8 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
257257
prt_printf(out, "type\tcompressed\runcompressed\raverage extent size\r\n");
258258

259259
for (unsigned i = 1; i < BCH_COMPRESSION_TYPE_NR; i++) {
260-
struct disk_accounting_pos a = {
261-
.type = BCH_DISK_ACCOUNTING_compression,
262-
.compression.type = i,
263-
};
260+
struct disk_accounting_pos a;
261+
disk_accounting_key_init(a, compression, .type = i);
264262
struct bpos p = disk_accounting_pos_to_bpos(&a);
265263
u64 v[3];
266264
bch2_accounting_mem_read(c, p, v, ARRAY_SIZE(v));

0 commit comments

Comments
 (0)