]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: CLASS(btree_trans)
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 25 May 2025 05:41:17 +0000 (01:41 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 1 Jun 2025 04:03:12 +0000 (00:03 -0400)
Allow btree_trans to be used with CLASS().

Automatic cleanup, instead of manually calling bch2_trans_put().

We don't use DEFINE_CLASS because using a static inline for the
constructor breaks bch2_trans_get()'s use of __func__, so we have to
open code it.

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

index 2cabb5f0f484c616cd5e46eece4574c7e40e2d51..09dd3e52622e48e39ba57c853df4dfbebfdad637 100644 (file)
@@ -963,16 +963,6 @@ struct bkey_s_c bch2_btree_iter_peek_and_restart_outlined(struct btree_trans *,
        _p;                                                             \
 })
 
-#define bch2_trans_run(_c, _do)                                                \
-({                                                                     \
-       struct btree_trans *trans = bch2_trans_get(_c);                 \
-       int _ret = (_do);                                               \
-       bch2_trans_put(trans);                                          \
-       _ret;                                                           \
-})
-
-#define bch2_trans_do(_c, _do) bch2_trans_run(_c, lockrestart_do(trans, _do))
-
 struct btree_trans *__bch2_trans_get(struct bch_fs *, unsigned);
 void bch2_trans_put(struct btree_trans *);
 
@@ -990,6 +980,27 @@ unsigned bch2_trans_get_fn_idx(const char *);
        __bch2_trans_get(_c, trans_fn_idx);                             \
 })
 
+/*
+ * We don't use DEFINE_CLASS() because using a function for the constructor
+ * breaks bch2_trans_get()'s use of __func__
+ */
+typedef struct btree_trans * class_btree_trans_t;
+static inline void class_btree_trans_destructor(struct btree_trans **p)
+{
+       struct btree_trans *trans = *p;
+       bch2_trans_put(trans);
+}
+
+#define class_btree_trans_constructor(_c)      bch2_trans_get(_c)
+
+#define bch2_trans_run(_c, _do)                                                \
+({                                                                     \
+       CLASS(btree_trans, trans)(_c);                                  \
+       (_do);                                                          \
+})
+
+#define bch2_trans_do(_c, _do) bch2_trans_run(_c, lockrestart_do(trans, _do))
+
 void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);
 
 void bch2_fs_btree_iter_exit(struct bch_fs *);