Skip to content

Commit f269af5

Browse files
author
Kent Overstreet
committed
bcache: Add btree_node_write_sync()
More refactoring - mostly making the interfaces more explicit about what we actually want to do. Signed-off-by: Kent Overstreet <kmo@daterainc.com>
1 parent 0eacac2 commit f269af5

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

‎drivers/md/bcache/btree.c‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,15 @@ void bch_btree_node_write(struct btree *b, struct closure *parent)
474474
bch_bset_init_next(b);
475475
}
476476

477+
static void bch_btree_node_write_sync(struct btree *b)
478+
{
479+
struct closure cl;
480+
481+
closure_init_stack(&cl);
482+
bch_btree_node_write(b, &cl);
483+
closure_sync(&cl);
484+
}
485+
477486
static void btree_node_write_work(struct work_struct *w)
478487
{
479488
struct btree *b = container_of(to_delayed_work(w), struct btree, work);
@@ -655,10 +664,8 @@ static int mca_reap(struct btree *b, unsigned min_order, bool flush)
655664
return -ENOMEM;
656665
}
657666

658-
if (btree_node_dirty(b)) {
659-
bch_btree_node_write(b, &cl);
660-
closure_sync(&cl);
661-
}
667+
if (btree_node_dirty(b))
668+
bch_btree_node_write_sync(b);
662669

663670
/* wait for any in flight btree write */
664671
closure_wait_event(&b->io.wait, &cl,
@@ -1411,9 +1418,6 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op,
14111418
struct btree *n = NULL;
14121419
unsigned keys = 0;
14131420
int ret = 0, stale = btree_gc_mark_node(b, &keys, gc);
1414-
struct closure cl;
1415-
1416-
closure_init_stack(&cl);
14171421

14181422
if (b->level || stale > 10)
14191423
n = btree_node_alloc_replacement(b);
@@ -1424,12 +1428,10 @@ static int bch_btree_gc_root(struct btree *b, struct btree_op *op,
14241428
if (b->level)
14251429
ret = btree_gc_recurse(b, op, writes, gc);
14261430

1427-
if (!b->written || btree_node_dirty(b)) {
1428-
bch_btree_node_write(b, n ? &cl : NULL);
1429-
}
1431+
if (!b->written || btree_node_dirty(b))
1432+
bch_btree_node_write_sync(b);
14301433

14311434
if (!IS_ERR_OR_NULL(n)) {
1432-
closure_sync(&cl);
14331435
bch_btree_set_root(b);
14341436
btree_node_free(n);
14351437
rw_unlock(true, b);
@@ -2104,15 +2106,10 @@ static int bch_btree_insert_node(struct btree *b, struct btree_op *op,
21042106

21052107
if (bch_btree_insert_keys(b, op, insert_keys,
21062108
replace_key)) {
2107-
if (!b->level) {
2109+
if (!b->level)
21082110
bch_btree_leaf_dirty(b, journal_ref);
2109-
} else {
2110-
struct closure cl;
2111-
2112-
closure_init_stack(&cl);
2113-
bch_btree_node_write(b, &cl);
2114-
closure_sync(&cl);
2115-
}
2111+
else
2112+
bch_btree_node_write_sync(b);
21162113
}
21172114
}
21182115
} while (!bch_keylist_empty(&split_keys));

0 commit comments

Comments
 (0)