]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: bch_accounting_mode
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 25 Sep 2024 02:53:56 +0000 (22:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 28 Sep 2024 01:46:35 +0000 (21:46 -0400)
Minor refactoring - replace multiple bool arguments with an enum; prep
work for fixing a bug in accounting read.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_trans_commit.c
fs/bcachefs/disk_accounting.c
fs/bcachefs/disk_accounting.h

index 91884da4e30a3ba5a53945551c051c6e1c169022..4a131e3b622513844c561ff21bbbb7f955ba43ec 100644 (file)
@@ -712,7 +712,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
                                a->k.version = journal_pos_to_bversion(&trans->journal_res,
                                                                (u64 *) entry - (u64 *) trans->journal_entries);
                                BUG_ON(bversion_zero(a->k.version));
-                               ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), false, false);
+                               ret = bch2_accounting_mem_mod_locked(trans, accounting_i_to_s_c(a), BCH_ACCOUNTING_normal);
                                if (ret)
                                        goto revert_fs_usage;
                        }
@@ -798,7 +798,7 @@ revert_fs_usage:
                        struct bkey_s_accounting a = bkey_i_to_s_accounting(entry2->start);
 
                        bch2_accounting_neg(a);
-                       bch2_accounting_mem_mod_locked(trans, a.c, false, false);
+                       bch2_accounting_mem_mod_locked(trans, a.c, BCH_ACCOUNTING_normal);
                        bch2_accounting_neg(a);
                }
        percpu_up_read(&c->mark_lock);
index e972e2bca546a9335320948287b1cc1b6c7b9f60..e9a7f1dab4505ec1283bf5533884d2902a2a621b 100644 (file)
@@ -319,7 +319,8 @@ err:
        return -BCH_ERR_ENOMEM_disk_accounting;
 }
 
-int bch2_accounting_mem_insert(struct bch_fs *c, struct bkey_s_c_accounting a, bool gc)
+int bch2_accounting_mem_insert(struct bch_fs *c, struct bkey_s_c_accounting a,
+                              enum bch_accounting_mode mode)
 {
        struct bch_replicas_padded r;
 
@@ -566,7 +567,9 @@ int bch2_gc_accounting_done(struct bch_fs *c)
                                        struct { __BKEY_PADDED(k, BCH_ACCOUNTING_MAX_COUNTERS); } k_i;
 
                                        accounting_key_init(&k_i.k, &acc_k, src_v, nr);
-                                       bch2_accounting_mem_mod_locked(trans, bkey_i_to_s_c_accounting(&k_i.k), false, false);
+                                       bch2_accounting_mem_mod_locked(trans,
+                                                               bkey_i_to_s_c_accounting(&k_i.k),
+                                                               BCH_ACCOUNTING_normal);
 
                                        preempt_disable();
                                        struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage);
@@ -595,7 +598,8 @@ static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k)
                return 0;
 
        percpu_down_read(&c->mark_lock);
-       int ret = bch2_accounting_mem_mod_locked(trans, bkey_s_c_to_accounting(k), false, true);
+       int ret = bch2_accounting_mem_mod_locked(trans, bkey_s_c_to_accounting(k),
+                                                BCH_ACCOUNTING_read);
        percpu_up_read(&c->mark_lock);
 
        if (bch2_accounting_key_is_zero(bkey_s_c_to_accounting(k)) &&
index f29fd0dd9581fb9b70cf4201c553b4bf6d0faa7f..243bfb0975eab8a863af0f33f7b5b79b1665a148 100644 (file)
@@ -103,23 +103,35 @@ static inline int accounting_pos_cmp(const void *_l, const void *_r)
        return bpos_cmp(*l, *r);
 }
 
-int bch2_accounting_mem_insert(struct bch_fs *, struct bkey_s_c_accounting, bool);
+enum bch_accounting_mode {
+       BCH_ACCOUNTING_normal,
+       BCH_ACCOUNTING_gc,
+       BCH_ACCOUNTING_read,
+};
+
+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 *);
 
 /*
  * Update in memory counters so they match the btree update we're doing; called
  * from transaction commit path
  */
-static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc, bool read)
+static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans,
+                                                struct bkey_s_c_accounting a,
+                                                enum bch_accounting_mode mode)
 {
        struct bch_fs *c = trans->c;
+       struct bch_accounting_mem *acc = &c->accounting;
        struct disk_accounting_pos acc_k;
        bpos_to_disk_accounting_pos(&acc_k, a.k->p);
+       bool gc = mode == BCH_ACCOUNTING_gc;
+
+       EBUG_ON(gc && !acc->gc_running);
 
        if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
                return 0;
 
-       if (!gc && !read) {
+       if (mode == BCH_ACCOUNTING_normal) {
                switch (acc_k.type) {
                case BCH_DISK_ACCOUNTING_persistent_reserved:
                        trans->fs_usage_delta.reserved += acc_k.persistent_reserved.nr_replicas * a.v->d[0];
@@ -140,14 +152,11 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
                }
        }
 
-       struct bch_accounting_mem *acc = &c->accounting;
        unsigned idx;
 
-       EBUG_ON(gc && !acc->gc_running);
-
        while ((idx = eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]),
                                      accounting_pos_cmp, &a.k->p)) >= acc->k.nr) {
-               int ret = bch2_accounting_mem_insert(c, a, gc);
+               int ret = bch2_accounting_mem_insert(c, a, mode);
                if (ret)
                        return ret;
        }
@@ -164,7 +173,7 @@ static inline int bch2_accounting_mem_mod_locked(struct btree_trans *trans, stru
 static inline int bch2_accounting_mem_add(struct btree_trans *trans, struct bkey_s_c_accounting a, bool gc)
 {
        percpu_down_read(&trans->c->mark_lock);
-       int ret = bch2_accounting_mem_mod_locked(trans, a, gc, false);
+       int ret = bch2_accounting_mem_mod_locked(trans, a, gc ? BCH_ACCOUNTING_gc : BCH_ACCOUNTING_normal);
        percpu_up_read(&trans->c->mark_lock);
        return ret;
 }