bcachefs: Centralize btree node lock initialization
This fixes some confusion in the lockdep code due to initializing btree node/key cache locks with the same lockdep key, but different names. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
1306f87de3
commit
3329cf1bb9
@ -119,8 +119,7 @@ static struct btree *__btree_node_mem_alloc(struct bch_fs *c, gfp_t gfp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
bkey_btree_ptr_init(&b->key);
|
bkey_btree_ptr_init(&b->key);
|
||||||
six_lock_init(&b->c.lock);
|
bch2_btree_lock_init(&b->c);
|
||||||
lockdep_set_novalidate_class(&b->c.lock);
|
|
||||||
INIT_LIST_HEAD(&b->list);
|
INIT_LIST_HEAD(&b->list);
|
||||||
INIT_LIST_HEAD(&b->write_blocked);
|
INIT_LIST_HEAD(&b->write_blocked);
|
||||||
b->byte_order = ilog2(btree_bytes(c));
|
b->byte_order = ilog2(btree_bytes(c));
|
||||||
|
@ -33,6 +33,8 @@ void bch2_btree_node_io_unlock(struct btree *b)
|
|||||||
|
|
||||||
void bch2_btree_node_io_lock(struct btree *b)
|
void bch2_btree_node_io_lock(struct btree *b)
|
||||||
{
|
{
|
||||||
|
bch2_assert_btree_nodes_not_locked();
|
||||||
|
|
||||||
wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
|
wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
|
||||||
TASK_UNINTERRUPTIBLE);
|
TASK_UNINTERRUPTIBLE);
|
||||||
}
|
}
|
||||||
@ -51,12 +53,16 @@ void __bch2_btree_node_wait_on_write(struct btree *b)
|
|||||||
|
|
||||||
void bch2_btree_node_wait_on_read(struct btree *b)
|
void bch2_btree_node_wait_on_read(struct btree *b)
|
||||||
{
|
{
|
||||||
|
bch2_assert_btree_nodes_not_locked();
|
||||||
|
|
||||||
wait_on_bit_io(&b->flags, BTREE_NODE_read_in_flight,
|
wait_on_bit_io(&b->flags, BTREE_NODE_read_in_flight,
|
||||||
TASK_UNINTERRUPTIBLE);
|
TASK_UNINTERRUPTIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bch2_btree_node_wait_on_write(struct btree *b)
|
void bch2_btree_node_wait_on_write(struct btree *b)
|
||||||
{
|
{
|
||||||
|
bch2_assert_btree_nodes_not_locked();
|
||||||
|
|
||||||
wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
|
wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
|
||||||
TASK_UNINTERRUPTIBLE);
|
TASK_UNINTERRUPTIBLE);
|
||||||
}
|
}
|
||||||
|
@ -282,8 +282,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path,
|
|||||||
return NULL;
|
return NULL;
|
||||||
init:
|
init:
|
||||||
INIT_LIST_HEAD(&ck->list);
|
INIT_LIST_HEAD(&ck->list);
|
||||||
__six_lock_init(&ck->c.lock, "b->c.lock", &bch2_btree_node_lock_key);
|
bch2_btree_lock_init(&ck->c);
|
||||||
lockdep_set_novalidate_class(&ck->c.lock);
|
|
||||||
if (pcpu_readers)
|
if (pcpu_readers)
|
||||||
six_lock_pcpu_alloc(&ck->c.lock);
|
six_lock_pcpu_alloc(&ck->c.lock);
|
||||||
|
|
||||||
|
@ -4,7 +4,23 @@
|
|||||||
#include "btree_locking.h"
|
#include "btree_locking.h"
|
||||||
#include "btree_types.h"
|
#include "btree_types.h"
|
||||||
|
|
||||||
struct lock_class_key bch2_btree_node_lock_key;
|
static struct lock_class_key bch2_btree_node_lock_key;
|
||||||
|
|
||||||
|
void bch2_btree_lock_init(struct btree_bkey_cached_common *b)
|
||||||
|
{
|
||||||
|
__six_lock_init(&b->lock, "b->c.lock", &bch2_btree_node_lock_key);
|
||||||
|
lockdep_set_novalidate_class(&b->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_LOCKDEP
|
||||||
|
void bch2_assert_btree_nodes_not_locked(void)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
//Re-enable when lock_class_is_held() is merged:
|
||||||
|
BUG_ON(lock_class_is_held(&bch2_btree_node_lock_key));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Btree node locking: */
|
/* Btree node locking: */
|
||||||
|
|
||||||
|
@ -13,7 +13,13 @@
|
|||||||
#include "btree_iter.h"
|
#include "btree_iter.h"
|
||||||
#include "six.h"
|
#include "six.h"
|
||||||
|
|
||||||
extern struct lock_class_key bch2_btree_node_lock_key;
|
void bch2_btree_lock_init(struct btree_bkey_cached_common *);
|
||||||
|
|
||||||
|
#ifdef CONFIG_LOCKDEP
|
||||||
|
void bch2_assert_btree_nodes_not_locked(void);
|
||||||
|
#else
|
||||||
|
static inline void bch2_assert_btree_nodes_not_locked(void) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline bool is_btree_node(struct btree_path *path, unsigned l)
|
static inline bool is_btree_node(struct btree_path *path, unsigned l)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user