bcachefs: Don't add unknown accounting types to eytzinger tree
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 5 Dec 2024 17:35:43 +0000 (12:35 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:22 +0000 (01:36 -0500)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_accounting.c
fs/bcachefs/disk_accounting.h

index a0061bcf915983ab62a8a1e8ae658a165324f00d..b18cbe80936b272999d5bf40bd51b34290023d53 100644 (file)
@@ -729,6 +729,16 @@ int bch2_accounting_read(struct bch_fs *c)
                                BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k, ({
                        struct bkey u;
                        struct bkey_s_c k = bch2_btree_path_peek_slot_exact(btree_iter_path(trans, &iter), &u);
+
+                       if (k.k->type != KEY_TYPE_accounting)
+                               continue;
+
+                       struct disk_accounting_pos acc_k;
+                       bpos_to_disk_accounting_pos(&acc_k, k.k->p);
+
+                       if (!bch2_accounting_is_mem(acc_k))
+                               continue;
+
                        accounting_read_key(trans, k);
                }));
        if (ret)
@@ -740,6 +750,12 @@ int bch2_accounting_read(struct bch_fs *c)
 
        darray_for_each(*keys, i) {
                if (i->k->k.type == KEY_TYPE_accounting) {
+                       struct disk_accounting_pos acc_k;
+                       bpos_to_disk_accounting_pos(&acc_k, i->k->k.p);
+
+                       if (!bch2_accounting_is_mem(acc_k))
+                               continue;
+
                        struct bkey_s_c k = bkey_i_to_s_c(i->k);
                        unsigned idx = eytzinger0_find(acc->k.data, acc->k.nr,
                                                sizeof(acc->k.data[0]),
index 566aa2a8539d563ad8c75d83c04aef01ce5401ef..0eeaca12c5896698a4e7ccbbd3fc87bdcf945c9b 100644 (file)
@@ -114,6 +114,12 @@ enum bch_accounting_mode {
 int bch2_accounting_mem_insert(struct bch_fs *, struct bkey_s_c_accounting, enum bch_accounting_mode);
 void bch2_accounting_mem_gc(struct bch_fs *);
 
+static inline bool bch2_accounting_is_mem(struct disk_accounting_pos acc)
+{
+       return acc.type < BCH_DISK_ACCOUNTING_TYPE_NR &&
+               acc.type != BCH_DISK_ACCOUNTING_inum;
+}
+
 /*
  * Update in memory counters so they match the btree update we're doing; called
  * from transaction commit path
@@ -130,7 +136,7 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans,
 
        EBUG_ON(gc && !acc->gc_running);
 
-       if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
+       if (!bch2_accounting_is_mem(acc_k))
                return 0;
 
        if (mode == BCH_ACCOUNTING_normal) {