]> www.infradead.org Git - users/hch/misc.git/commitdiff
bcachefs: Don't use designated initializers for disk_accounting_pos
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 30 Mar 2025 00:58:32 +0000 (20:58 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 30 Mar 2025 20:35:13 +0000 (16:35 -0400)
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: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/buckets.c
fs/bcachefs/chardev.c
fs/bcachefs/disk_accounting.c
fs/bcachefs/ec.c
fs/bcachefs/progress.c
fs/bcachefs/rebalance.c
fs/bcachefs/sysfs.c

index 1c6fc45e1449eb7410ecbefe7fc580235550f180..0903311cc71e693834fffc5c5a0c58a7c429f344 100644 (file)
@@ -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 @@ err:
 
                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 };
index 57d55b3ddc716bcc236eb3504e38b75e06bd3119..584f4a3eb670925b8a57eabc49970f7a681e6465 100644 (file)
@@ -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),
index 651e1b2521a6467df8a6af7d9c8acfd3d9ff566c..a59f6c12529b303a7e0b398389a4a0f89d255509 100644 (file)
@@ -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;
                        }
index 0c23d749621af0b08b2ed8a4fefdb5497a3e4fd0..6faeda7ad03df9046742637f95dc6c9a1b56aab2 100644 (file)
@@ -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);
index bafd1c91a802a3c82f3aabd224feca08ba53fd2d..d09898566abea94df5872506dce9255fe12c56dc 100644 (file)
@@ -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);
index a480c3cb6712b78d194b4e72e2cfd2713f5153e9..b9bde04b66c0b01f87c0d523de0ad127ade12739 100644 (file)
@@ -600,7 +600,8 @@ void bch2_rebalance_status_to_text(struct printbuf *out, struct bch_fs *c)
        struct bch_fs_rebalance *r = &c->rebalance;
 
        /* print pending work */
-       struct disk_accounting_pos acc = { .type = BCH_DISK_ACCOUNTING_rebalance_work, };
+       struct disk_accounting_pos acc;
+       disk_accounting_key_init(acc, rebalance_work);
        u64 v;
        bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc), &v, 1);
 
index 74c186d65d1f4b539841b9a2fc2d012f9c4cf13a..e5f003c29369e05dbbb90ba1831fcbeaca9e66b9 100644 (file)
@@ -257,10 +257,8 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
        prt_printf(out, "type\tcompressed\runcompressed\raverage extent size\r\n");
 
        for (unsigned i = 1; i < BCH_COMPRESSION_TYPE_NR; i++) {
-               struct disk_accounting_pos a = {
-                       .type                   = BCH_DISK_ACCOUNTING_compression,
-                       .compression.type       = i,
-               };
+               struct disk_accounting_pos a;
+               disk_accounting_key_init(a, compression, .type = i);
                struct bpos p = disk_accounting_pos_to_bpos(&a);
                u64 v[3];
                bch2_accounting_mem_read(c, p, v, ARRAY_SIZE(v));