summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-08-31 18:53:42 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-03 23:53:49 -0400
commit7e66c211571632a0abb0f96a46e8382ef1f19eb6 (patch)
tree4751e73aa8330a64aab1762c525c90b0185d6ee7
parent1f060a564f47597615f4028c751643f05b85f97e (diff)
bcachefs: btree_bkey_cached_common->cached
Add a type descriptor to btree_bkey_cached_common - there's no reason not to since we've got padding that was otherwise unused, and this is a nice cleanup (and helpful in later patches). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/btree_iter.c9
-rw-r--r--fs/bcachefs/btree_key_cache.c1
-rw-r--r--fs/bcachefs/btree_locking.c3
-rw-r--r--fs/bcachefs/btree_types.h6
4 files changed, 9 insertions, 10 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index a8db847da9ed..3e2398646f90 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -3010,8 +3010,7 @@ void bch2_trans_exit(struct btree_trans *trans)
static void __maybe_unused
bch2_btree_path_node_to_text(struct printbuf *out,
- struct btree_bkey_cached_common *b,
- bool cached)
+ struct btree_bkey_cached_common *b)
{
struct six_lock_count c = six_lock_counts(&b->lock);
struct task_struct *owner;
@@ -3024,7 +3023,7 @@ bch2_btree_path_node_to_text(struct printbuf *out,
prt_printf(out, " l=%u %s:",
b->level, bch2_btree_ids[b->btree_id]);
- bch2_bpos_to_text(out, btree_node_pos(b, cached));
+ bch2_bpos_to_text(out, btree_node_pos(b));
prt_printf(out, " locks %u:%u:%u held by pid %u",
c.n[0], c.n[1], c.n[2], pid);
@@ -3056,7 +3055,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
!IS_ERR_OR_NULL(b = (void *) READ_ONCE(path->l[l].b))) {
prt_printf(out, " %c l=%u ",
lock_types[btree_node_locked_type(path, l)], l);
- bch2_btree_path_node_to_text(out, b, path->cached);
+ bch2_btree_path_node_to_text(out, b);
prt_printf(out, "\n");
}
}
@@ -3074,7 +3073,7 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
bch2_bpos_to_text(out, trans->locking_pos);
prt_printf(out, " node ");
- bch2_btree_path_node_to_text(out, b, path->cached);
+ bch2_btree_path_node_to_text(out, b);
prt_printf(out, "\n");
}
}
diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
index 8d4eb7970165..c7843c836049 100644
--- a/fs/bcachefs/btree_key_cache.c
+++ b/fs/bcachefs/btree_key_cache.c
@@ -203,6 +203,7 @@ bkey_cached_alloc(struct btree_trans *trans,
if (likely(ck)) {
INIT_LIST_HEAD(&ck->list);
__six_lock_init(&ck->c.lock, "b->c.lock", &bch2_btree_node_lock_key);
+ ck->c.cached = true;
BUG_ON(!six_trylock_intent(&ck->c.lock));
BUG_ON(!six_trylock_write(&ck->c.lock));
return ck;
diff --git a/fs/bcachefs/btree_locking.c b/fs/bcachefs/btree_locking.c
index 2c3d44564d50..c8c90b4fca58 100644
--- a/fs/bcachefs/btree_locking.c
+++ b/fs/bcachefs/btree_locking.c
@@ -144,8 +144,7 @@ int __bch2_btree_node_lock(struct btree_trans *trans,
/* Must lock btree nodes in key order: */
if (btree_node_locked(linked, level) &&
- bpos_cmp(pos, btree_node_pos(&linked->l[level].b->c,
- linked->cached)) <= 0) {
+ bpos_cmp(pos, btree_node_pos(&linked->l[level].b->c)) <= 0) {
reason = 7;
goto deadlock;
}
diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h
index 3113b20a4067..c2f852c28ea5 100644
--- a/fs/bcachefs/btree_types.h
+++ b/fs/bcachefs/btree_types.h
@@ -63,6 +63,7 @@ struct btree_bkey_cached_common {
struct six_lock lock;
u8 level;
u8 btree_id;
+ bool cached;
};
struct btree {
@@ -337,10 +338,9 @@ struct bkey_cached {
struct bkey_i *k;
};
-static inline struct bpos btree_node_pos(struct btree_bkey_cached_common *b,
- bool cached)
+static inline struct bpos btree_node_pos(struct btree_bkey_cached_common *b)
{
- return !cached
+ return !b->cached
? container_of(b, struct btree, c)->key.k.p
: container_of(b, struct bkey_cached, c)->key.pos;
}