Skip to content

Commit 9cb49fb

Browse files
author
Kent Overstreet
committed
bcachefs: CLASS(btree_trans)
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 <[email protected]>
1 parent 42359f1 commit 9cb49fb

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

fs/bcachefs/btree_iter.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -963,16 +963,6 @@ struct bkey_s_c bch2_btree_iter_peek_and_restart_outlined(struct btree_trans *,
963963
_p; \
964964
})
965965

966-
#define bch2_trans_run(_c, _do) \
967-
({ \
968-
struct btree_trans *trans = bch2_trans_get(_c); \
969-
int _ret = (_do); \
970-
bch2_trans_put(trans); \
971-
_ret; \
972-
})
973-
974-
#define bch2_trans_do(_c, _do) bch2_trans_run(_c, lockrestart_do(trans, _do))
975-
976966
struct btree_trans *__bch2_trans_get(struct bch_fs *, unsigned);
977967
void bch2_trans_put(struct btree_trans *);
978968

@@ -990,6 +980,27 @@ unsigned bch2_trans_get_fn_idx(const char *);
990980
__bch2_trans_get(_c, trans_fn_idx); \
991981
})
992982

983+
/*
984+
* We don't use DEFINE_CLASS() because using a function for the constructor
985+
* breaks bch2_trans_get()'s use of __func__
986+
*/
987+
typedef struct btree_trans * class_btree_trans_t;
988+
static inline void class_btree_trans_destructor(struct btree_trans **p)
989+
{
990+
struct btree_trans *trans = *p;
991+
bch2_trans_put(trans);
992+
}
993+
994+
#define class_btree_trans_constructor(_c) bch2_trans_get(_c)
995+
996+
#define bch2_trans_run(_c, _do) \
997+
({ \
998+
CLASS(btree_trans, trans)(_c); \
999+
(_do); \
1000+
})
1001+
1002+
#define bch2_trans_do(_c, _do) bch2_trans_run(_c, lockrestart_do(trans, _do))
1003+
9931004
void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);
9941005

9951006
void bch2_fs_btree_iter_exit(struct bch_fs *);

0 commit comments

Comments
 (0)