1

bcachefs: Use x-macros for btree node flags

This is for adding an array of strings for btree node flag names.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-02-26 11:10:20 -05:00 committed by Kent Overstreet
parent 55334d7897
commit de517c9551
6 changed files with 41 additions and 43 deletions

View File

@ -13,6 +13,13 @@
#include <linux/prefetch.h>
#include <linux/sched/mm.h>
const char * const bch2_btree_node_flags[] = {
#define x(f) #f,
BTREE_FLAGS()
#undef x
NULL
};
void bch2_recalc_btree_reserve(struct bch_fs *c)
{
unsigned i, reserve = 16;
@ -413,7 +420,7 @@ void bch2_fs_btree_cache_exit(struct bch_fs *c)
if (btree_node_dirty(b))
bch2_btree_complete_write(c, b, btree_current_write(b));
clear_btree_node_dirty(c, b);
clear_btree_node_dirty_acct(c, b);
btree_node_data_free(c, b);
}

View File

@ -5,6 +5,8 @@
#include "bcachefs.h"
#include "btree_types.h"
extern const char * const bch2_btree_node_flags[];
struct btree_iter;
void bch2_recalc_btree_reserve(struct bch_fs *);

View File

@ -15,18 +15,13 @@ struct btree;
struct btree_iter;
struct btree_node_read_all;
static inline bool btree_node_dirty(struct btree *b)
{
return test_bit(BTREE_NODE_dirty, &b->flags);
}
static inline void set_btree_node_dirty(struct bch_fs *c, struct btree *b)
static inline void set_btree_node_dirty_acct(struct bch_fs *c, struct btree *b)
{
if (!test_and_set_bit(BTREE_NODE_dirty, &b->flags))
atomic_inc(&c->btree_cache.dirty);
}
static inline void clear_btree_node_dirty(struct bch_fs *c, struct btree *b)
static inline void clear_btree_node_dirty_acct(struct bch_fs *c, struct btree *b)
{
if (test_and_clear_bit(BTREE_NODE_dirty, &b->flags))
atomic_dec(&c->btree_cache.dirty);

View File

@ -429,7 +429,29 @@ struct btree_trans {
struct replicas_delta_list *fs_usage_deltas;
};
#define BTREE_FLAG(flag) \
#define BTREE_FLAGS() \
x(read_in_flight) \
x(read_error) \
x(dirty) \
x(need_write) \
x(noevict) \
x(write_idx) \
x(accessed) \
x(write_in_flight) \
x(write_in_flight_inner) \
x(just_written) \
x(dying) \
x(fake) \
x(need_rewrite) \
x(never_write)
enum btree_flags {
#define x(flag) BTREE_NODE_##flag,
BTREE_FLAGS()
#undef x
};
#define x(flag) \
static inline bool btree_node_ ## flag(struct btree *b) \
{ return test_bit(BTREE_NODE_ ## flag, &b->flags); } \
\
@ -439,36 +461,8 @@ static inline void set_btree_node_ ## flag(struct btree *b) \
static inline void clear_btree_node_ ## flag(struct btree *b) \
{ clear_bit(BTREE_NODE_ ## flag, &b->flags); }
enum btree_flags {
BTREE_NODE_read_in_flight,
BTREE_NODE_read_error,
BTREE_NODE_dirty,
BTREE_NODE_need_write,
BTREE_NODE_noevict,
BTREE_NODE_write_idx,
BTREE_NODE_accessed,
BTREE_NODE_write_in_flight,
BTREE_NODE_write_in_flight_inner,
BTREE_NODE_just_written,
BTREE_NODE_dying,
BTREE_NODE_fake,
BTREE_NODE_need_rewrite,
BTREE_NODE_never_write,
};
BTREE_FLAG(read_in_flight);
BTREE_FLAG(read_error);
BTREE_FLAG(need_write);
BTREE_FLAG(noevict);
BTREE_FLAG(write_idx);
BTREE_FLAG(accessed);
BTREE_FLAG(write_in_flight);
BTREE_FLAG(write_in_flight_inner);
BTREE_FLAG(just_written);
BTREE_FLAG(dying);
BTREE_FLAG(fake);
BTREE_FLAG(need_rewrite);
BTREE_FLAG(never_write);
BTREE_FLAGS()
#undef x
static inline struct btree_write *btree_current_write(struct btree *b)
{

View File

@ -271,7 +271,7 @@ static struct btree *bch2_btree_node_alloc(struct btree_update *as, unsigned lev
six_lock_write(&b->c.lock, NULL, NULL);
set_btree_node_accessed(b);
set_btree_node_dirty(c, b);
set_btree_node_dirty_acct(c, b);
set_btree_node_need_write(b);
bch2_bset_init_first(b, &b->data->keys);
@ -868,7 +868,7 @@ static void bch2_btree_interior_update_will_free_node(struct btree_update *as,
closure_wake_up(&c->btree_interior_update_wait);
}
clear_btree_node_dirty(c, b);
clear_btree_node_dirty_acct(c, b);
clear_btree_node_need_write(b);
/*
@ -1172,7 +1172,7 @@ static void bch2_insert_fixup_btree_ptr(struct btree_update *as,
bch2_btree_node_iter_advance(node_iter, b);
bch2_btree_bset_insert_key(trans, path, b, node_iter, insert);
set_btree_node_dirty(c, b);
set_btree_node_dirty_acct(c, b);
set_btree_node_need_write(b);
}

View File

@ -221,7 +221,7 @@ static bool btree_insert_key_leaf(struct btree_trans *trans,
bch2_btree_add_journal_pin(c, b, trans->journal_res.seq);
if (unlikely(!btree_node_dirty(b)))
set_btree_node_dirty(c, b);
set_btree_node_dirty_acct(c, b);
live_u64s_added = (int) b->nr.live_u64s - old_live_u64s;
u64s_added = (int) bset_u64s(t) - old_u64s;