rework csum and extent item ordering
[platform/upstream/btrfs-progs.git] / ctree.c
diff --git a/ctree.c b/ctree.c
index 17a3ff2..01baa0b 100644 (file)
--- a/ctree.c
+++ b/ctree.c
@@ -294,6 +294,10 @@ static int balance_level(struct btrfs_trans_handle *trans, struct btrfs_root
                parent_buf = path->nodes[level + 1];
        pslot = path->slots[level + 1];
 
+       /*
+        * deal with the case where there is only one pointer in the root
+        * by promoting the node below to a root
+        */
        if (!parent_buf) {
                struct btrfs_buffer *child;
                u64 blocknr = mid_buf->blocknr;
@@ -657,8 +661,6 @@ static int insert_new_root(struct btrfs_trans_handle *trans, struct btrfs_root
        btrfs_set_header_nritems(&c->header, 1);
        btrfs_set_header_level(&c->header, level);
        btrfs_set_header_blocknr(&c->header, t->blocknr);
-       btrfs_set_header_parentid(&c->header,
-                              btrfs_header_parentid(&root->node->node.header));
        lower = &path->nodes[level-1]->node;
        if (btrfs_is_leaf(lower))
                lower_key = &((struct btrfs_leaf *)lower)->items[0].key;
@@ -742,9 +744,8 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
        split_buffer = btrfs_alloc_free_block(trans, root);
        split = &split_buffer->node;
        btrfs_set_header_flags(&split->header, btrfs_header_flags(&c->header));
+       btrfs_set_header_level(&split->header, btrfs_header_level(&c->header));
        btrfs_set_header_blocknr(&split->header, split_buffer->blocknr);
-       btrfs_set_header_parentid(&split->header,
-                              btrfs_header_parentid(&root->node->node.header));
        mid = (c_nritems + 1) / 2;
        memcpy(split->ptrs, c->ptrs + mid,
                (c_nritems - mid) * sizeof(struct btrfs_key_ptr));
@@ -1043,6 +1044,7 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
        int ret;
        int wret;
 
+       /* first try to make some room by pushing left and right */
        wret = push_leaf_left(trans, root, path, data_size);
        if (wret < 0)
                return wret;
@@ -1086,8 +1088,6 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
        btrfs_set_header_nritems(&right->header, nritems - mid);
        btrfs_set_header_blocknr(&right->header, right_buffer->blocknr);
        btrfs_set_header_level(&right->header, 0);
-       btrfs_set_header_parentid(&right->header,
-                              btrfs_header_parentid(&root->node->node.header));
        data_copy_size = btrfs_item_end(l->items + mid) -
                         leaf_data_end(root, l);
        memcpy(right->items, l->items + mid,