bcachefs: bch2_trans_run()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 14 Jul 2022 06:08:58 +0000 (02:08 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:36 +0000 (17:09 -0400)
This adds a new helper, bch2_trans_run(), that runs a function with a
btree_transaction context but without handling transaction restarts.
We're adding checks for nested transaction restart handling: when an
inner transaction handles a transaction restart it will still have to
return it to the outer transaction, or else assertions will be popped in
the outer transaction.

But some places don't need restart handling at the outer scope, so this
helper does what they need.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_update.h
fs/bcachefs/buckets.c
fs/bcachefs/journal.c

index e9127dbf7e241ab62491af2e800dd15c8aa56d4b..1c3dd012cae890dce9a3d38e61c4e5b1f119a029 100644 (file)
@@ -134,6 +134,18 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
        _ret;                                                           \
 })
 
+#define bch2_trans_run(_c, _do)                                                \
+({                                                                     \
+       struct btree_trans trans;                                       \
+       int _ret;                                                       \
+                                                                       \
+       bch2_trans_init(&trans, (_c), 0, 0);                            \
+       _ret = (_do);                                                   \
+       bch2_trans_exit(&trans);                                        \
+                                                                       \
+       _ret;                                                           \
+})
+
 #define trans_for_each_update(_trans, _i)                              \
        for ((_i) = (_trans)->updates;                                  \
             (_i) < (_trans)->updates + (_trans)->nr_updates;           \
index 71618f5bfcd5b0c3e984e25d10cb059566dd6dfc..136e116981d703935d86f42760650a60ceb7cadb 100644 (file)
@@ -1931,8 +1931,7 @@ static int __bch2_trans_mark_dev_sb(struct btree_trans *trans,
 
 int bch2_trans_mark_dev_sb(struct bch_fs *c, struct bch_dev *ca)
 {
-       return bch2_trans_do(c, NULL, NULL, BTREE_INSERT_LAZY_RW,
-                       __bch2_trans_mark_dev_sb(&trans, ca));
+       return bch2_trans_run(c, __bch2_trans_mark_dev_sb(&trans, ca));
 }
 
 /* Disk reservations: */
index a71bd1bb4066428d236dde7e1f9a52c17608a256..26f60db751cae081b73cb6a8d92dd4ca99fbe497 100644 (file)
@@ -882,7 +882,7 @@ static int __bch2_set_nr_journal_buckets(struct bch_dev *ca, unsigned nr,
 
        if (!new_fs) {
                for (i = 0; i < nr_got; i++) {
-                       ret = bch2_trans_do(c, NULL, NULL, BTREE_INSERT_NOFAIL,
+                       ret = bch2_trans_run(c,
                                bch2_trans_mark_metadata_bucket(&trans, ca,
                                                bu[i], BCH_DATA_journal,
                                                ca->mi.bucket_size));