diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-09-11 03:48:51 +0200 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 06:56:06 +0100 |
commit | 48dad8baf92fe8967d9e1358af1cfdda1d2d3298 (patch) | |
tree | c773b028b0123acb07b55690a3cfb1f3ea230587 /drivers/md/bcache/writeback.c | |
parent | bcache: Convert writeback to a kthread (diff) | |
download | linux-48dad8baf92fe8967d9e1358af1cfdda1d2d3298.tar.xz linux-48dad8baf92fe8967d9e1358af1cfdda1d2d3298.zip |
bcache: Add btree_map() functions
Lots of stuff has been open coding its own btree traversal - which is
generally pretty simple code, but there are a few subtleties.
This adds new new functions, bch_btree_map_nodes() and
bch_btree_map_keys(), which do the traversal for you. Everything that's
open coding btree traversal now (with the exception of garbage
collection) is slowly going to be converted to these two functions;
being able to write other code at a higher level of abstraction is a
big improvement w.r.t. overall code quality.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache/writeback.c')
-rw-r--r-- | drivers/md/bcache/writeback.c | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 4392f3f38d62..c68de9f12618 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -433,31 +433,17 @@ static int bch_writeback_thread(void *arg) /* Init */ -static int bch_btree_sectors_dirty_init(struct btree *b, struct btree_op *op, - struct cached_dev *dc) +static int sectors_dirty_init_fn(struct btree_op *op, struct btree *b, + struct bkey *k) { - struct bkey *k; - struct btree_iter iter; - - bch_btree_iter_init(b, &iter, &KEY(dc->disk.id, 0, 0)); - while ((k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad))) - if (!b->level) { - if (KEY_INODE(k) > dc->disk.id) - break; - - if (KEY_DIRTY(k)) - bcache_dev_sectors_dirty_add(b->c, dc->disk.id, - KEY_START(k), - KEY_SIZE(k)); - } else { - btree(sectors_dirty_init, k, b, op, dc); - if (KEY_INODE(k) > dc->disk.id) - break; - - cond_resched(); - } + if (KEY_INODE(k) > op->inode) + return MAP_DONE; - return 0; + if (KEY_DIRTY(k)) + bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k), + KEY_START(k), KEY_SIZE(k)); + + return MAP_CONTINUE; } void bch_sectors_dirty_init(struct cached_dev *dc) @@ -465,7 +451,10 @@ void bch_sectors_dirty_init(struct cached_dev *dc) struct btree_op op; bch_btree_op_init_stack(&op); - btree_root(sectors_dirty_init, dc->disk.c, &op, dc); + op.inode = dc->disk.id; + + bch_btree_map_keys(&op, dc->disk.c, &KEY(op.inode, 0, 0), + sectors_dirty_init_fn, 0); } int bch_cached_dev_writeback_init(struct cached_dev *dc) |