summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2016-05-26 19:50:03 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2016-07-26 00:24:51 -0800
commit06d7271178f75ff6ab8fc02294e47dc2e781142e (patch)
treec7e210d982672009b18d37219deeecb2b9893c14
parentb529ca218ea6f34eb4dab6836260fe2ce464b205 (diff)
bcache: btree_node_lock_write() now requires iter
added an underscore version so we can see where it might be null
-rw-r--r--drivers/md/bcache/btree_io.c12
-rw-r--r--drivers/md/bcache/btree_iter.c40
-rw-r--r--drivers/md/bcache/btree_locking.h3
3 files changed, 34 insertions, 21 deletions
diff --git a/drivers/md/bcache/btree_io.c b/drivers/md/bcache/btree_io.c
index 6de528e5f5cf..7753a1c2ce85 100644
--- a/drivers/md/bcache/btree_io.c
+++ b/drivers/md/bcache/btree_io.c
@@ -49,7 +49,7 @@ static void btree_node_sort(struct cache_set *c, struct btree *b,
node_iter, sort, &c->sort);
if (!is_write_locked)
- btree_node_lock_write(b, iter);
+ __btree_node_lock_write(b, iter);
if (!from) {
unsigned u64s = le16_to_cpu(out->keys.u64s);
@@ -77,7 +77,7 @@ static void btree_node_sort(struct cache_set *c, struct btree *b,
bch_bset_build_written_tree(&b->keys);
if (!is_write_locked)
- btree_node_unlock_write(b, iter);
+ __btree_node_unlock_write(b, iter);
if (used_mempool)
mempool_free(virt_to_page(out), &c->sort.pool);
@@ -121,9 +121,9 @@ static bool btree_node_compact(struct cache_set *c, struct btree *b,
}
nosort:
- btree_node_lock_write(b, iter);
+ __btree_node_lock_write(b, iter);
bch_bset_build_written_tree(&b->keys);
- btree_node_unlock_write(b, iter);
+ __btree_node_unlock_write(b, iter);
return false;
sort:
btree_node_sort(c, b, iter, i, NULL, NULL, false);
@@ -153,9 +153,9 @@ void bch_btree_init_next(struct cache_set *c, struct btree *b,
bch_btree_verify(c, b);
if (b->written < btree_blocks(c)) {
- btree_node_lock_write(b, iter);
+ __btree_node_lock_write(b, iter);
bch_bset_init_next(&b->keys, &write_block(c, b)->keys);
- btree_node_unlock_write(b, iter);
+ __btree_node_unlock_write(b, iter);
}
if (iter && did_sort)
diff --git a/drivers/md/bcache/btree_iter.c b/drivers/md/bcache/btree_iter.c
index c4f167e98ed5..435bceafaac7 100644
--- a/drivers/md/bcache/btree_iter.c
+++ b/drivers/md/bcache/btree_iter.c
@@ -22,17 +22,15 @@ static inline bool is_btree_node(struct btree_iter *iter, unsigned l)
*/
void btree_node_unlock_write(struct btree *b, struct btree_iter *iter)
{
- EBUG_ON(iter && iter->nodes[b->level] != b);
- EBUG_ON(iter && iter->lock_seq[b->level] + 1 != b->lock.state.seq);
+ struct btree_iter *linked;
- if (iter) {
- struct btree_iter *linked;
+ EBUG_ON(iter->nodes[b->level] != b);
+ EBUG_ON(iter->lock_seq[b->level] + 1 != b->lock.state.seq);
- for_each_linked_btree_node(iter, b, linked)
- linked->lock_seq[b->level] += 2;
+ for_each_linked_btree_node(iter, b, linked)
+ linked->lock_seq[b->level] += 2;
- iter->lock_seq[b->level] += 2;
- }
+ iter->lock_seq[b->level] += 2;
six_unlock_write(&b->lock);
}
@@ -42,17 +40,12 @@ void btree_node_lock_write(struct btree *b, struct btree_iter *iter)
struct btree_iter *linked;
unsigned readers = 0;
- EBUG_ON(iter && iter->nodes[b->level] != b);
- EBUG_ON(iter && iter->lock_seq[b->level] != b->lock.state.seq);
+ EBUG_ON(iter->nodes[b->level] != b);
+ EBUG_ON(iter->lock_seq[b->level] != b->lock.state.seq);
if (six_trylock_write(&b->lock))
return;
- if (!iter) {
- six_lock_write(&b->lock);
- return;
- }
-
for_each_linked_btree_iter(iter, linked)
if (linked->nodes[b->level] == b &&
btree_node_read_locked(linked, b->level))
@@ -75,6 +68,23 @@ void btree_node_lock_write(struct btree *b, struct btree_iter *iter)
}
}
+/* versions that allow iter to be null: */
+void __btree_node_unlock_write(struct btree *b, struct btree_iter *iter)
+{
+ if (likely(iter))
+ btree_node_unlock_write(b, iter);
+ else
+ six_unlock_write(&b->lock);
+}
+
+void __btree_node_lock_write(struct btree *b, struct btree_iter *iter)
+{
+ if (likely(iter))
+ btree_node_lock_write(b, iter);
+ else
+ six_lock_write(&b->lock);
+}
+
static bool btree_lock_upgrade(struct btree_iter *iter, unsigned level)
{
struct btree *b = iter->nodes[level];
diff --git a/drivers/md/bcache/btree_locking.h b/drivers/md/bcache/btree_locking.h
index 7337248cded5..7db4acbae67a 100644
--- a/drivers/md/bcache/btree_locking.h
+++ b/drivers/md/bcache/btree_locking.h
@@ -148,4 +148,7 @@ bool btree_node_relock(struct btree_iter *, unsigned);
void btree_node_unlock_write(struct btree *, struct btree_iter *);
void btree_node_lock_write(struct btree *, struct btree_iter *);
+void __btree_node_unlock_write(struct btree *, struct btree_iter *);
+void __btree_node_lock_write(struct btree *, struct btree_iter *);
+
#endif /* _BCACHE_BTREE_LOCKING_H */