diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 20:35:24 -0500 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2014-01-08 16:05:13 -0500 |
commit | c052dd9a26f60bcf70c0c3fcc08e07abb60295cd (patch) | |
tree | 9b6f0f270c546ef974bd0b091679a81e1ea295fc /drivers/md | |
parent | f67342dd342d5917d94a7c0ffbde5f78e0d7a57a (diff) |
bcache: Convert btree_iter to struct btree_keys
More work to disentangle bset.c from struct btree
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/bset.c | 22 | ||||
-rw-r--r-- | drivers/md/bcache/bset.h | 19 | ||||
-rw-r--r-- | drivers/md/bcache/btree.c | 22 | ||||
-rw-r--r-- | drivers/md/bcache/btree.h | 8 | ||||
-rw-r--r-- | drivers/md/bcache/debug.c | 6 | ||||
-rw-r--r-- | drivers/md/bcache/sysfs.c | 2 |
6 files changed, 41 insertions, 38 deletions
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c index a3ffc3711b75..097bd8d2acba 100644 --- a/drivers/md/bcache/bset.c +++ b/drivers/md/bcache/bset.c | |||
@@ -764,7 +764,7 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t, | |||
764 | return (struct bset_search_iter) {l, r}; | 764 | return (struct bset_search_iter) {l, r}; |
765 | } | 765 | } |
766 | 766 | ||
767 | struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t, | 767 | struct bkey *__bch_bset_search(struct btree_keys *b, struct bset_tree *t, |
768 | const struct bkey *search) | 768 | const struct bkey *search) |
769 | { | 769 | { |
770 | struct bset_search_iter i; | 770 | struct bset_search_iter i; |
@@ -787,7 +787,7 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t, | |||
787 | if (unlikely(!t->size)) { | 787 | if (unlikely(!t->size)) { |
788 | i.l = t->data->start; | 788 | i.l = t->data->start; |
789 | i.r = bset_bkey_last(t->data); | 789 | i.r = bset_bkey_last(t->data); |
790 | } else if (bset_written(&b->keys, t)) { | 790 | } else if (bset_written(b, t)) { |
791 | /* | 791 | /* |
792 | * Each node in the auxiliary search tree covers a certain range | 792 | * Each node in the auxiliary search tree covers a certain range |
793 | * of bits, and keys above and below the set it covers might | 793 | * of bits, and keys above and below the set it covers might |
@@ -803,14 +803,14 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t, | |||
803 | 803 | ||
804 | i = bset_search_tree(t, search); | 804 | i = bset_search_tree(t, search); |
805 | } else { | 805 | } else { |
806 | BUG_ON(!b->keys.nsets && | 806 | BUG_ON(!b->nsets && |
807 | t->size < bkey_to_cacheline(t, bset_bkey_last(t->data))); | 807 | t->size < bkey_to_cacheline(t, bset_bkey_last(t->data))); |
808 | 808 | ||
809 | i = bset_search_write_set(t, search); | 809 | i = bset_search_write_set(t, search); |
810 | } | 810 | } |
811 | 811 | ||
812 | if (expensive_debug_checks(b->c)) { | 812 | if (btree_keys_expensive_checks(b)) { |
813 | BUG_ON(bset_written(&b->keys, t) && | 813 | BUG_ON(bset_written(b, t) && |
814 | i.l != t->data->start && | 814 | i.l != t->data->start && |
815 | bkey_cmp(tree_to_prev_bkey(t, | 815 | bkey_cmp(tree_to_prev_bkey(t, |
816 | inorder_to_tree(bkey_to_cacheline(t, i.l), t)), | 816 | inorder_to_tree(bkey_to_cacheline(t, i.l), t)), |
@@ -853,7 +853,7 @@ void bch_btree_iter_push(struct btree_iter *iter, struct bkey *k, | |||
853 | btree_iter_cmp)); | 853 | btree_iter_cmp)); |
854 | } | 854 | } |
855 | 855 | ||
856 | static struct bkey *__bch_btree_iter_init(struct btree *b, | 856 | static struct bkey *__bch_btree_iter_init(struct btree_keys *b, |
857 | struct btree_iter *iter, | 857 | struct btree_iter *iter, |
858 | struct bkey *search, | 858 | struct bkey *search, |
859 | struct bset_tree *start) | 859 | struct bset_tree *start) |
@@ -866,7 +866,7 @@ static struct bkey *__bch_btree_iter_init(struct btree *b, | |||
866 | iter->b = b; | 866 | iter->b = b; |
867 | #endif | 867 | #endif |
868 | 868 | ||
869 | for (; start <= bset_tree_last(&b->keys); start++) { | 869 | for (; start <= bset_tree_last(b); start++) { |
870 | ret = bch_bset_search(b, start, search); | 870 | ret = bch_bset_search(b, start, search); |
871 | bch_btree_iter_push(iter, ret, bset_bkey_last(start->data)); | 871 | bch_btree_iter_push(iter, ret, bset_bkey_last(start->data)); |
872 | } | 872 | } |
@@ -874,11 +874,11 @@ static struct bkey *__bch_btree_iter_init(struct btree *b, | |||
874 | return ret; | 874 | return ret; |
875 | } | 875 | } |
876 | 876 | ||
877 | struct bkey *bch_btree_iter_init(struct btree *b, | 877 | struct bkey *bch_btree_iter_init(struct btree_keys *b, |
878 | struct btree_iter *iter, | 878 | struct btree_iter *iter, |
879 | struct bkey *search) | 879 | struct bkey *search) |
880 | { | 880 | { |
881 | return __bch_btree_iter_init(b, iter, search, b->keys.set); | 881 | return __bch_btree_iter_init(b, iter, search, b->set); |
882 | } | 882 | } |
883 | EXPORT_SYMBOL(bch_btree_iter_init); | 883 | EXPORT_SYMBOL(bch_btree_iter_init); |
884 | 884 | ||
@@ -1047,7 +1047,7 @@ void bch_btree_sort_partial(struct btree *b, unsigned start, | |||
1047 | struct btree_iter iter; | 1047 | struct btree_iter iter; |
1048 | int oldsize = bch_count_data(b); | 1048 | int oldsize = bch_count_data(b); |
1049 | 1049 | ||
1050 | __bch_btree_iter_init(b, &iter, NULL, &b->keys.set[start]); | 1050 | __bch_btree_iter_init(&b->keys, &iter, NULL, &b->keys.set[start]); |
1051 | 1051 | ||
1052 | if (start) { | 1052 | if (start) { |
1053 | unsigned i; | 1053 | unsigned i; |
@@ -1080,7 +1080,7 @@ void bch_btree_sort_into(struct btree *b, struct btree *new, | |||
1080 | uint64_t start_time = local_clock(); | 1080 | uint64_t start_time = local_clock(); |
1081 | 1081 | ||
1082 | struct btree_iter iter; | 1082 | struct btree_iter iter; |
1083 | bch_btree_iter_init(b, &iter, NULL); | 1083 | bch_btree_iter_init(&b->keys, &iter, NULL); |
1084 | 1084 | ||
1085 | btree_mergesort(&b->keys, new->keys.set->data, &iter, false, true); | 1085 | btree_mergesort(&b->keys, new->keys.set->data, &iter, false, true); |
1086 | 1086 | ||
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h index 49135695342e..563130c28142 100644 --- a/drivers/md/bcache/bset.h +++ b/drivers/md/bcache/bset.h | |||
@@ -309,7 +309,7 @@ static inline bool bch_bkey_try_merge(struct btree_keys *b, | |||
309 | struct btree_iter { | 309 | struct btree_iter { |
310 | size_t size, used; | 310 | size_t size, used; |
311 | #ifdef CONFIG_BCACHE_DEBUG | 311 | #ifdef CONFIG_BCACHE_DEBUG |
312 | struct btree *b; | 312 | struct btree_keys *b; |
313 | #endif | 313 | #endif |
314 | struct btree_iter_set { | 314 | struct btree_iter_set { |
315 | struct bkey *k, *end; | 315 | struct bkey *k, *end; |
@@ -323,21 +323,30 @@ struct bkey *bch_btree_iter_next_filter(struct btree_iter *, | |||
323 | struct btree_keys *, ptr_filter_fn); | 323 | struct btree_keys *, ptr_filter_fn); |
324 | 324 | ||
325 | void bch_btree_iter_push(struct btree_iter *, struct bkey *, struct bkey *); | 325 | void bch_btree_iter_push(struct btree_iter *, struct bkey *, struct bkey *); |
326 | struct bkey *bch_btree_iter_init(struct btree *, struct btree_iter *, | 326 | struct bkey *bch_btree_iter_init(struct btree_keys *, struct btree_iter *, |
327 | struct bkey *); | 327 | struct bkey *); |
328 | 328 | ||
329 | struct bkey *__bch_bset_search(struct btree *, struct bset_tree *, | 329 | struct bkey *__bch_bset_search(struct btree_keys *, struct bset_tree *, |
330 | const struct bkey *); | 330 | const struct bkey *); |
331 | 331 | ||
332 | /* | 332 | /* |
333 | * Returns the first key that is strictly greater than search | 333 | * Returns the first key that is strictly greater than search |
334 | */ | 334 | */ |
335 | static inline struct bkey *bch_bset_search(struct btree *b, struct bset_tree *t, | 335 | static inline struct bkey *bch_bset_search(struct btree_keys *b, |
336 | struct bset_tree *t, | ||
336 | const struct bkey *search) | 337 | const struct bkey *search) |
337 | { | 338 | { |
338 | return search ? __bch_bset_search(b, t, search) : t->data->start; | 339 | return search ? __bch_bset_search(b, t, search) : t->data->start; |
339 | } | 340 | } |
340 | 341 | ||
342 | #define for_each_key_filter(b, k, iter, filter) \ | ||
343 | for (bch_btree_iter_init((b), (iter), NULL); \ | ||
344 | ((k) = bch_btree_iter_next_filter((iter), (b), filter));) | ||
345 | |||
346 | #define for_each_key(b, k, iter) \ | ||
347 | for (bch_btree_iter_init((b), (iter), NULL); \ | ||
348 | ((k) = bch_btree_iter_next(iter));) | ||
349 | |||
341 | /* Sorting */ | 350 | /* Sorting */ |
342 | 351 | ||
343 | struct bset_sort_state { | 352 | struct bset_sort_state { |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 2c90003ff4ce..9424c8a15e37 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -212,7 +212,7 @@ void bch_btree_node_read_done(struct btree *b) | |||
212 | iter->used = 0; | 212 | iter->used = 0; |
213 | 213 | ||
214 | #ifdef CONFIG_BCACHE_DEBUG | 214 | #ifdef CONFIG_BCACHE_DEBUG |
215 | iter->b = b; | 215 | iter->b = &b->keys; |
216 | #endif | 216 | #endif |
217 | 217 | ||
218 | if (!i->seq) | 218 | if (!i->seq) |
@@ -1195,7 +1195,7 @@ static bool btree_gc_mark_node(struct btree *b, struct gc_stat *gc) | |||
1195 | 1195 | ||
1196 | gc->nodes++; | 1196 | gc->nodes++; |
1197 | 1197 | ||
1198 | for_each_key_filter(b, k, &iter, bch_ptr_invalid) { | 1198 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) { |
1199 | stale = max(stale, btree_mark_key(b, k)); | 1199 | stale = max(stale, btree_mark_key(b, k)); |
1200 | keys++; | 1200 | keys++; |
1201 | 1201 | ||
@@ -1386,7 +1386,7 @@ static unsigned btree_gc_count_keys(struct btree *b) | |||
1386 | struct btree_iter iter; | 1386 | struct btree_iter iter; |
1387 | unsigned ret = 0; | 1387 | unsigned ret = 0; |
1388 | 1388 | ||
1389 | for_each_key_filter(b, k, &iter, bch_ptr_bad) | 1389 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad) |
1390 | ret += bkey_u64s(k); | 1390 | ret += bkey_u64s(k); |
1391 | 1391 | ||
1392 | return ret; | 1392 | return ret; |
@@ -1406,7 +1406,7 @@ static int btree_gc_recurse(struct btree *b, struct btree_op *op, | |||
1406 | struct gc_merge_info *last = r + GC_MERGE_NODES - 1; | 1406 | struct gc_merge_info *last = r + GC_MERGE_NODES - 1; |
1407 | 1407 | ||
1408 | bch_keylist_init(&keys); | 1408 | bch_keylist_init(&keys); |
1409 | bch_btree_iter_init(b, &iter, &b->c->gc_done); | 1409 | bch_btree_iter_init(&b->keys, &iter, &b->c->gc_done); |
1410 | 1410 | ||
1411 | for (i = 0; i < GC_MERGE_NODES; i++) | 1411 | for (i = 0; i < GC_MERGE_NODES; i++) |
1412 | r[i].b = ERR_PTR(-EINTR); | 1412 | r[i].b = ERR_PTR(-EINTR); |
@@ -1722,7 +1722,7 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op, | |||
1722 | struct bucket *g; | 1722 | struct bucket *g; |
1723 | struct btree_iter iter; | 1723 | struct btree_iter iter; |
1724 | 1724 | ||
1725 | for_each_key_filter(b, k, &iter, bch_ptr_invalid) { | 1725 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_invalid) { |
1726 | for (i = 0; i < KEY_PTRS(k); i++) { | 1726 | for (i = 0; i < KEY_PTRS(k); i++) { |
1727 | if (!ptr_available(b->c, k, i)) | 1727 | if (!ptr_available(b->c, k, i)) |
1728 | continue; | 1728 | continue; |
@@ -1745,7 +1745,7 @@ static int bch_btree_check_recurse(struct btree *b, struct btree_op *op, | |||
1745 | } | 1745 | } |
1746 | 1746 | ||
1747 | if (b->level) { | 1747 | if (b->level) { |
1748 | bch_btree_iter_init(b, &iter, NULL); | 1748 | bch_btree_iter_init(&b->keys, &iter, NULL); |
1749 | 1749 | ||
1750 | do { | 1750 | do { |
1751 | k = bch_btree_iter_next_filter(&iter, &b->keys, | 1751 | k = bch_btree_iter_next_filter(&iter, &b->keys, |
@@ -1892,7 +1892,7 @@ static bool fix_overlapping_extents(struct btree *b, struct bkey *insert, | |||
1892 | * depends on us inserting a new key for the top | 1892 | * depends on us inserting a new key for the top |
1893 | * here. | 1893 | * here. |
1894 | */ | 1894 | */ |
1895 | top = bch_bset_search(b, | 1895 | top = bch_bset_search(&b->keys, |
1896 | bset_tree_last(&b->keys), | 1896 | bset_tree_last(&b->keys), |
1897 | insert); | 1897 | insert); |
1898 | bch_bset_insert(&b->keys, top, k); | 1898 | bch_bset_insert(&b->keys, top, k); |
@@ -1965,7 +1965,7 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, | |||
1965 | * the previous key. | 1965 | * the previous key. |
1966 | */ | 1966 | */ |
1967 | prev = NULL; | 1967 | prev = NULL; |
1968 | m = bch_btree_iter_init(b, &iter, | 1968 | m = bch_btree_iter_init(&b->keys, &iter, |
1969 | PRECEDING_KEY(&START_KEY(k))); | 1969 | PRECEDING_KEY(&START_KEY(k))); |
1970 | 1970 | ||
1971 | if (fix_overlapping_extents(b, k, &iter, replace_key)) { | 1971 | if (fix_overlapping_extents(b, k, &iter, replace_key)) { |
@@ -2001,7 +2001,7 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, | |||
2001 | goto copy; | 2001 | goto copy; |
2002 | } else { | 2002 | } else { |
2003 | BUG_ON(replace_key); | 2003 | BUG_ON(replace_key); |
2004 | m = bch_bset_search(b, bset_tree_last(&b->keys), k); | 2004 | m = bch_bset_search(&b->keys, bset_tree_last(&b->keys), k); |
2005 | } | 2005 | } |
2006 | 2006 | ||
2007 | insert: bch_bset_insert(&b->keys, m, k); | 2007 | insert: bch_bset_insert(&b->keys, m, k); |
@@ -2357,7 +2357,7 @@ static int bch_btree_map_nodes_recurse(struct btree *b, struct btree_op *op, | |||
2357 | struct bkey *k; | 2357 | struct bkey *k; |
2358 | struct btree_iter iter; | 2358 | struct btree_iter iter; |
2359 | 2359 | ||
2360 | bch_btree_iter_init(b, &iter, from); | 2360 | bch_btree_iter_init(&b->keys, &iter, from); |
2361 | 2361 | ||
2362 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, | 2362 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, |
2363 | bch_ptr_bad))) { | 2363 | bch_ptr_bad))) { |
@@ -2390,7 +2390,7 @@ static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op, | |||
2390 | struct bkey *k; | 2390 | struct bkey *k; |
2391 | struct btree_iter iter; | 2391 | struct btree_iter iter; |
2392 | 2392 | ||
2393 | bch_btree_iter_init(b, &iter, from); | 2393 | bch_btree_iter_init(&b->keys, &iter, from); |
2394 | 2394 | ||
2395 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) { | 2395 | while ((k = bch_btree_iter_next_filter(&iter, &b->keys, bch_ptr_bad))) { |
2396 | ret = !b->level | 2396 | ret = !b->level |
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h index 04e81f8ab89a..af065e97e55c 100644 --- a/drivers/md/bcache/btree.h +++ b/drivers/md/bcache/btree.h | |||
@@ -201,14 +201,6 @@ void bkey_put(struct cache_set *c, struct bkey *k); | |||
201 | iter++) \ | 201 | iter++) \ |
202 | hlist_for_each_entry_rcu((b), (c)->bucket_hash + iter, hash) | 202 | hlist_for_each_entry_rcu((b), (c)->bucket_hash + iter, hash) |
203 | 203 | ||
204 | #define for_each_key_filter(b, k, iter, filter) \ | ||
205 | for (bch_btree_iter_init((b), (iter), NULL); \ | ||
206 | ((k) = bch_btree_iter_next_filter((iter), &(b)->keys, filter));) | ||
207 | |||
208 | #define for_each_key(b, k, iter) \ | ||
209 | for (bch_btree_iter_init((b), (iter), NULL); \ | ||
210 | ((k) = bch_btree_iter_next(iter));) | ||
211 | |||
212 | /* Recursing down the btree */ | 204 | /* Recursing down the btree */ |
213 | 205 | ||
214 | struct btree_op { | 206 | struct btree_op { |
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c index 8acc18af07c1..3de27e2a4e07 100644 --- a/drivers/md/bcache/debug.c +++ b/drivers/md/bcache/debug.c | |||
@@ -246,7 +246,7 @@ int __bch_count_data(struct btree *b) | |||
246 | struct bkey *k; | 246 | struct bkey *k; |
247 | 247 | ||
248 | if (!b->level) | 248 | if (!b->level) |
249 | for_each_key(b, k, &iter) | 249 | for_each_key(&b->keys, k, &iter) |
250 | ret += KEY_SIZE(k); | 250 | ret += KEY_SIZE(k); |
251 | return ret; | 251 | return ret; |
252 | } | 252 | } |
@@ -258,7 +258,7 @@ void __bch_check_keys(struct btree *b, const char *fmt, ...) | |||
258 | struct btree_iter iter; | 258 | struct btree_iter iter; |
259 | const char *err; | 259 | const char *err; |
260 | 260 | ||
261 | for_each_key(b, k, &iter) { | 261 | for_each_key(&b->keys, k, &iter) { |
262 | if (!b->level) { | 262 | if (!b->level) { |
263 | err = "Keys out of order"; | 263 | err = "Keys out of order"; |
264 | if (p && bkey_cmp(&START_KEY(p), &START_KEY(k)) > 0) | 264 | if (p && bkey_cmp(&START_KEY(p), &START_KEY(k)) > 0) |
@@ -298,6 +298,7 @@ bug: | |||
298 | 298 | ||
299 | void bch_btree_iter_next_check(struct btree_iter *iter) | 299 | void bch_btree_iter_next_check(struct btree_iter *iter) |
300 | { | 300 | { |
301 | #if 0 | ||
301 | struct bkey *k = iter->data->k, *next = bkey_next(k); | 302 | struct bkey *k = iter->data->k, *next = bkey_next(k); |
302 | 303 | ||
303 | if (next < iter->data->end && | 304 | if (next < iter->data->end && |
@@ -305,6 +306,7 @@ void bch_btree_iter_next_check(struct btree_iter *iter) | |||
305 | bch_dump_bucket(iter->b); | 306 | bch_dump_bucket(iter->b); |
306 | panic("Key skipped backwards\n"); | 307 | panic("Key skipped backwards\n"); |
307 | } | 308 | } |
309 | #endif | ||
308 | } | 310 | } |
309 | 311 | ||
310 | #endif | 312 | #endif |
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index db2111b88e20..c6ab69333a6d 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c | |||
@@ -460,7 +460,7 @@ lock_root: | |||
460 | rw_lock(false, b, b->level); | 460 | rw_lock(false, b, b->level); |
461 | } while (b != c->root); | 461 | } while (b != c->root); |
462 | 462 | ||
463 | for_each_key_filter(b, k, &iter, bch_ptr_bad) | 463 | for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad) |
464 | bytes += bkey_bytes(k); | 464 | bytes += bkey_bytes(k); |
465 | 465 | ||
466 | rw_unlock(false, b); | 466 | rw_unlock(false, b); |