diff options
Diffstat (limited to 'drivers/md/bcache/btree.c')
-rw-r--r-- | drivers/md/bcache/btree.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index d1734d9d9c7..87299baa8a1 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -884,6 +884,7 @@ out: lock_set_subclass(&b->lock.dep_map, level + 1, _THIS_IP_); b->level = level; + b->parent = (void *) ~0UL; mca_reinit(b); @@ -1898,7 +1899,7 @@ out: static int btree_split(struct btree *b, struct btree_op *op) { - bool split, root = b == b->c->root; + bool split; struct btree *n1, *n2 = NULL, *n3 = NULL; uint64_t start_time = local_clock(); @@ -1920,7 +1921,7 @@ static int btree_split(struct btree *b, struct btree_op *op) if (IS_ERR(n2)) goto err_free1; - if (root) { + if (!b->parent) { n3 = bch_btree_node_alloc(b->c, b->level + 1, &op->cl); if (IS_ERR(n3)) goto err_free2; @@ -1928,7 +1929,8 @@ static int btree_split(struct btree *b, struct btree_op *op) bch_btree_insert_keys(n1, op); - /* Has to be a linear search because we don't have an auxiliary + /* + * Has to be a linear search because we don't have an auxiliary * search tree yet */ @@ -1960,6 +1962,8 @@ static int btree_split(struct btree *b, struct btree_op *op) bch_btree_node_write(n1, &op->cl); if (n3) { + /* Depth increases, make a new root */ + bkey_copy_key(&n3->key, &MAX_KEY); bch_btree_insert_keys(n3, op); bch_btree_node_write(n3, &op->cl); @@ -1967,7 +1971,9 @@ static int btree_split(struct btree *b, struct btree_op *op) closure_sync(&op->cl); bch_btree_set_root(n3); rw_unlock(true, n3); - } else if (root) { + } else if (!b->parent) { + /* Root filled up but didn't need to be split */ + op->keys.top = op->keys.bottom; closure_sync(&op->cl); bch_btree_set_root(n1); |