aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-18 16:15:28 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-18 16:15:28 -0400
commita429e51371eee3c989160c003ee40bc3947c6a76 (patch)
tree863b55de8823be579264260a51407cd90aac103d /fs/btrfs/ctree.c
parent70b2befd0c8a4064715d8b340270650cc9d15af8 (diff)
Btrfs: working file_write, reorganized key flags
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r--fs/btrfs/ctree.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 5c160c236773..4efcd1bd63e5 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -893,7 +893,11 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
893 } 893 }
894 894
895 left_nritems = btrfs_header_nritems(&left->header); 895 left_nritems = btrfs_header_nritems(&left->header);
896 for (i = left_nritems - 1; i >= 0; i--) { 896 if (left_nritems == 0) {
897 btrfs_block_release(root, right_buf);
898 return 1;
899 }
900 for (i = left_nritems - 1; i >= 1; i--) {
897 item = left->items + i; 901 item = left->items + i;
898 if (path->slots[0] == i) 902 if (path->slots[0] == i)
899 push_space += data_size + sizeof(*item); 903 push_space += data_size + sizeof(*item);
@@ -907,6 +911,8 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
907 btrfs_block_release(root, right_buf); 911 btrfs_block_release(root, right_buf);
908 return 1; 912 return 1;
909 } 913 }
914 if (push_items == left_nritems)
915 WARN_ON(1);
910 right_nritems = btrfs_header_nritems(&right->header); 916 right_nritems = btrfs_header_nritems(&right->header);
911 /* push left to right */ 917 /* push left to right */
912 push_space = btrfs_item_end(left->items + left_nritems - push_items); 918 push_space = btrfs_item_end(left->items + left_nritems - push_items);
@@ -943,6 +949,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root
943 949
944 btrfs_mark_buffer_dirty(left_buf); 950 btrfs_mark_buffer_dirty(left_buf);
945 btrfs_mark_buffer_dirty(right_buf); 951 btrfs_mark_buffer_dirty(right_buf);
952
946 btrfs_memcpy(root, upper_node, &upper_node->ptrs[slot + 1].key, 953 btrfs_memcpy(root, upper_node, &upper_node->ptrs[slot + 1].key,
947 &right->items[0].key, sizeof(struct btrfs_disk_key)); 954 &right->items[0].key, sizeof(struct btrfs_disk_key));
948 btrfs_mark_buffer_dirty(upper); 955 btrfs_mark_buffer_dirty(upper);
@@ -1004,7 +1011,12 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
1004 return 1; 1011 return 1;
1005 } 1012 }
1006 1013
1007 for (i = 0; i < btrfs_header_nritems(&right->header); i++) { 1014 if (btrfs_header_nritems(&right->header) == 0) {
1015 btrfs_block_release(root, t);
1016 return 1;
1017 }
1018
1019 for (i = 0; i < btrfs_header_nritems(&right->header) - 1; i++) {
1008 item = right->items + i; 1020 item = right->items + i;
1009 if (path->slots[0] == i) 1021 if (path->slots[0] == i)
1010 push_space += data_size + sizeof(*item); 1022 push_space += data_size + sizeof(*item);
@@ -1018,6 +1030,8 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
1018 btrfs_block_release(root, t); 1030 btrfs_block_release(root, t);
1019 return 1; 1031 return 1;
1020 } 1032 }
1033 if (push_items == btrfs_header_nritems(&right->header))
1034 WARN_ON(1);
1021 /* push data from right to left */ 1035 /* push data from right to left */
1022 btrfs_memcpy(root, left, left->items + 1036 btrfs_memcpy(root, left, left->items +
1023 btrfs_header_nritems(&left->header), 1037 btrfs_header_nritems(&left->header),
@@ -1064,7 +1078,6 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root
1064 1078
1065 btrfs_mark_buffer_dirty(t); 1079 btrfs_mark_buffer_dirty(t);
1066 btrfs_mark_buffer_dirty(right_buf); 1080 btrfs_mark_buffer_dirty(right_buf);
1067
1068 wret = fixup_low_keys(trans, root, path, &right->items[0].key, 1); 1081 wret = fixup_low_keys(trans, root, path, &right->items[0].key, 1);
1069 if (wret) 1082 if (wret)
1070 ret = wret; 1083 ret = wret;
@@ -1181,6 +1194,12 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
1181 path->nodes[0] = right_buffer; 1194 path->nodes[0] = right_buffer;
1182 path->slots[0] = 0; 1195 path->slots[0] = 0;
1183 path->slots[1] -= 1; 1196 path->slots[1] -= 1;
1197 if (path->slots[1] == 0) {
1198 wret = fixup_low_keys(trans, root,
1199 path, &disk_key, 1);
1200 if (wret)
1201 ret = wret;
1202 }
1184 return ret; 1203 return ret;
1185 } 1204 }
1186 mid = slot; 1205 mid = slot;
@@ -1241,6 +1260,11 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root
1241 path->slots[1], 1); 1260 path->slots[1], 1);
1242 if (wret) 1261 if (wret)
1243 ret = wret; 1262 ret = wret;
1263 if (path->slots[1] == 0) {
1264 wret = fixup_low_keys(trans, root, path, &disk_key, 1);
1265 if (wret)
1266 ret = wret;
1267 }
1244 btrfs_block_release(root, path->nodes[0]); 1268 btrfs_block_release(root, path->nodes[0]);
1245 path->nodes[0] = right_buffer; 1269 path->nodes[0] = right_buffer;
1246 path->slots[0] = 0; 1270 path->slots[0] = 0;