diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-23 10:01:08 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-23 10:01:08 -0400 |
commit | d571976292839cec05a2820b08f7629b145ed157 (patch) | |
tree | 6a3f2f5a9b9c70f61d00ac10edaaaa60d5043474 /fs/btrfs/ctree.c | |
parent | 79154b1b5bcf87903db7ff16a30b360b78d6fe4f (diff) |
btrfs_create, btrfs_write_super, btrfs_sync_fs
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index e690e2bb47d2..052434a328ec 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -39,7 +39,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root | |||
39 | struct buffer_head *cow; | 39 | struct buffer_head *cow; |
40 | struct btrfs_node *cow_node; | 40 | struct btrfs_node *cow_node; |
41 | 41 | ||
42 | if (!buffer_dirty(buf)) { | 42 | if (buffer_dirty(buf)) { |
43 | *cow_ret = buf; | 43 | *cow_ret = buf; |
44 | return 0; | 44 | return 0; |
45 | } | 45 | } |
@@ -48,6 +48,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root | |||
48 | memcpy(cow_node, btrfs_buffer_node(buf), root->blocksize); | 48 | memcpy(cow_node, btrfs_buffer_node(buf), root->blocksize); |
49 | btrfs_set_header_blocknr(&cow_node->header, cow->b_blocknr); | 49 | btrfs_set_header_blocknr(&cow_node->header, cow->b_blocknr); |
50 | *cow_ret = cow; | 50 | *cow_ret = cow; |
51 | mark_buffer_dirty(cow); | ||
51 | btrfs_inc_ref(trans, root, buf); | 52 | btrfs_inc_ref(trans, root, buf); |
52 | if (buf == root->node) { | 53 | if (buf == root->node) { |
53 | root->node = cow; | 54 | root->node = cow; |
@@ -58,7 +59,7 @@ static int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root | |||
58 | } else { | 59 | } else { |
59 | btrfs_set_node_blockptr(btrfs_buffer_node(parent), parent_slot, | 60 | btrfs_set_node_blockptr(btrfs_buffer_node(parent), parent_slot, |
60 | cow->b_blocknr); | 61 | cow->b_blocknr); |
61 | BUG_ON(!buffer_dirty(parent)); | 62 | mark_buffer_dirty(parent); |
62 | btrfs_free_extent(trans, root, buf->b_blocknr, 1, 1); | 63 | btrfs_free_extent(trans, root, buf->b_blocknr, 1, 1); |
63 | } | 64 | } |
64 | btrfs_block_release(root, buf); | 65 | btrfs_block_release(root, buf); |
@@ -362,7 +363,7 @@ static int balance_level(struct btrfs_trans_handle *trans, struct btrfs_root | |||
362 | memcpy(&parent->ptrs[pslot + 1].key, | 363 | memcpy(&parent->ptrs[pslot + 1].key, |
363 | &right->ptrs[0].key, | 364 | &right->ptrs[0].key, |
364 | sizeof(struct btrfs_disk_key)); | 365 | sizeof(struct btrfs_disk_key)); |
365 | BUG_ON(!buffer_dirty(parent_buf)); | 366 | mark_buffer_dirty(parent_buf); |
366 | } | 367 | } |
367 | } | 368 | } |
368 | if (btrfs_header_nritems(&mid->header) == 1) { | 369 | if (btrfs_header_nritems(&mid->header) == 1) { |
@@ -398,7 +399,7 @@ static int balance_level(struct btrfs_trans_handle *trans, struct btrfs_root | |||
398 | /* update the parent key to reflect our changes */ | 399 | /* update the parent key to reflect our changes */ |
399 | memcpy(&parent->ptrs[pslot].key, &mid->ptrs[0].key, | 400 | memcpy(&parent->ptrs[pslot].key, &mid->ptrs[0].key, |
400 | sizeof(struct btrfs_disk_key)); | 401 | sizeof(struct btrfs_disk_key)); |
401 | BUG_ON(!buffer_dirty(parent_buf)); | 402 | mark_buffer_dirty(parent_buf); |
402 | } | 403 | } |
403 | 404 | ||
404 | /* update the path */ | 405 | /* update the path */ |
@@ -539,7 +540,7 @@ static int fixup_low_keys(struct btrfs_trans_handle *trans, struct btrfs_root | |||
539 | break; | 540 | break; |
540 | t = btrfs_buffer_node(path->nodes[i]); | 541 | t = btrfs_buffer_node(path->nodes[i]); |
541 | memcpy(&t->ptrs[tslot].key, key, sizeof(*key)); | 542 | memcpy(&t->ptrs[tslot].key, key, sizeof(*key)); |
542 | BUG_ON(!buffer_dirty(path->nodes[i])); | 543 | mark_buffer_dirty(path->nodes[i]); |
543 | if (tslot != 0) | 544 | if (tslot != 0) |
544 | break; | 545 | break; |
545 | } | 546 | } |
@@ -583,8 +584,8 @@ static int push_node_left(struct btrfs_trans_handle *trans, struct btrfs_root | |||
583 | } | 584 | } |
584 | btrfs_set_header_nritems(&src->header, src_nritems - push_items); | 585 | btrfs_set_header_nritems(&src->header, src_nritems - push_items); |
585 | btrfs_set_header_nritems(&dst->header, dst_nritems + push_items); | 586 | btrfs_set_header_nritems(&dst->header, dst_nritems + push_items); |
586 | BUG_ON(!buffer_dirty(src_buf)); | 587 | mark_buffer_dirty(src_buf); |
587 | BUG_ON(!buffer_dirty(dst_buf)); | 588 | mark_buffer_dirty(dst_buf); |
588 | return ret; | 589 | return ret; |
589 | } | 590 | } |
590 | 591 | ||
@@ -631,8 +632,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans, struct | |||
631 | btrfs_set_header_nritems(&src->header, src_nritems - push_items); | 632 | btrfs_set_header_nritems(&src->header, src_nritems - push_items); |
632 | btrfs_set_header_nritems(&dst->header, dst_nritems + push_items); | 633 | btrfs_set_header_nritems(&dst->header, dst_nritems + push_items); |
633 | 634 | ||
634 | BUG_ON(!buffer_dirty(src_buf)); | 635 | mark_buffer_dirty(src_buf); |
635 | BUG_ON(!buffer_dirty(dst_buf)); | 636 | mark_buffer_dirty(dst_buf); |
636 | return ret; | 637 | return ret; |
637 | } | 638 | } |
638 | 639 | ||
@@ -669,6 +670,9 @@ static int insert_new_root(struct btrfs_trans_handle *trans, struct btrfs_root | |||
669 | lower_key = &lower->ptrs[0].key; | 670 | lower_key = &lower->ptrs[0].key; |
670 | memcpy(&c->ptrs[0].key, lower_key, sizeof(struct btrfs_disk_key)); | 671 | memcpy(&c->ptrs[0].key, lower_key, sizeof(struct btrfs_disk_key)); |
671 | btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->b_blocknr); | 672 | btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->b_blocknr); |
673 | |||
674 | mark_buffer_dirty(t); | ||
675 | |||
672 | /* the super has an extra ref to root->node */ | 676 | /* the super has an extra ref to root->node */ |
673 | btrfs_block_release(root, root->node); | 677 | btrfs_block_release(root, root->node); |
674 | root->node = t; | 678 | root->node = t; |
@@ -708,7 +712,7 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root | |||
708 | memcpy(&lower->ptrs[slot].key, key, sizeof(struct btrfs_disk_key)); | 712 | memcpy(&lower->ptrs[slot].key, key, sizeof(struct btrfs_disk_key)); |
709 | btrfs_set_node_blockptr(lower, slot, blocknr); | 713 | btrfs_set_node_blockptr(lower, slot, blocknr); |
710 | btrfs_set_header_nritems(&lower->header, nritems + 1); | 714 | btrfs_set_header_nritems(&lower->header, nritems + 1); |
711 | BUG_ON(!buffer_dirty(path->nodes[level])); | 715 | mark_buffer_dirty(path->nodes[level]); |
712 | return 0; | 716 | return 0; |
713 | } | 717 | } |
714 | 718 | ||
@@ -755,7 +759,8 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root | |||
755 | btrfs_set_header_nritems(&c->header, mid); | 759 | btrfs_set_header_nritems(&c->header, mid); |
756 | ret = 0; | 760 | ret = 0; |
757 | 761 | ||
758 | BUG_ON(!buffer_dirty(t)); | 762 | mark_buffer_dirty(t); |
763 | mark_buffer_dirty(split_buffer); | ||
759 | wret = insert_ptr(trans, root, path, &split->ptrs[0].key, | 764 | wret = insert_ptr(trans, root, path, &split->ptrs[0].key, |
760 | split_buffer->b_blocknr, path->slots[level + 1] + 1, | 765 | split_buffer->b_blocknr, path->slots[level + 1] + 1, |
761 | level + 1); | 766 | level + 1); |
@@ -886,11 +891,11 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root | |||
886 | left_nritems -= push_items; | 891 | left_nritems -= push_items; |
887 | btrfs_set_header_nritems(&left->header, left_nritems); | 892 | btrfs_set_header_nritems(&left->header, left_nritems); |
888 | 893 | ||
889 | BUG_ON(!buffer_dirty(left_buf)); | 894 | mark_buffer_dirty(left_buf); |
890 | BUG_ON(!buffer_dirty(right_buf)); | 895 | mark_buffer_dirty(right_buf); |
891 | memcpy(&upper_node->ptrs[slot + 1].key, | 896 | memcpy(&upper_node->ptrs[slot + 1].key, |
892 | &right->items[0].key, sizeof(struct btrfs_disk_key)); | 897 | &right->items[0].key, sizeof(struct btrfs_disk_key)); |
893 | BUG_ON(!buffer_dirty(upper)); | 898 | mark_buffer_dirty(upper); |
894 | 899 | ||
895 | /* then fixup the leaf pointer in the path */ | 900 | /* then fixup the leaf pointer in the path */ |
896 | if (path->slots[0] >= left_nritems) { | 901 | if (path->slots[0] >= left_nritems) { |
@@ -1004,8 +1009,8 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1004 | push_space = btrfs_item_offset(right->items + i); | 1009 | push_space = btrfs_item_offset(right->items + i); |
1005 | } | 1010 | } |
1006 | 1011 | ||
1007 | BUG_ON(!buffer_dirty(t)); | 1012 | mark_buffer_dirty(t); |
1008 | BUG_ON(!buffer_dirty(right_buf)); | 1013 | mark_buffer_dirty(right_buf); |
1009 | 1014 | ||
1010 | wret = fixup_low_keys(trans, root, path, &right->items[0].key, 1); | 1015 | wret = fixup_low_keys(trans, root, path, &right->items[0].key, 1); |
1011 | if (wret) | 1016 | if (wret) |
@@ -1115,8 +1120,8 @@ static int split_leaf(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1115 | right_buffer->b_blocknr, path->slots[1] + 1, 1); | 1120 | right_buffer->b_blocknr, path->slots[1] + 1, 1); |
1116 | if (wret) | 1121 | if (wret) |
1117 | ret = wret; | 1122 | ret = wret; |
1118 | BUG_ON(!buffer_dirty(right_buffer)); | 1123 | mark_buffer_dirty(right_buffer); |
1119 | BUG_ON(!buffer_dirty(l_buf)); | 1124 | mark_buffer_dirty(l_buf); |
1120 | BUG_ON(path->slots[0] != slot); | 1125 | BUG_ON(path->slots[0] != slot); |
1121 | if (mid <= slot) { | 1126 | if (mid <= slot) { |
1122 | btrfs_block_release(root, path->nodes[0]); | 1127 | btrfs_block_release(root, path->nodes[0]); |
@@ -1202,12 +1207,12 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1202 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); | 1207 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); |
1203 | btrfs_set_item_size(leaf->items + slot, data_size); | 1208 | btrfs_set_item_size(leaf->items + slot, data_size); |
1204 | btrfs_set_header_nritems(&leaf->header, nritems + 1); | 1209 | btrfs_set_header_nritems(&leaf->header, nritems + 1); |
1210 | mark_buffer_dirty(leaf_buf); | ||
1205 | 1211 | ||
1206 | ret = 0; | 1212 | ret = 0; |
1207 | if (slot == 0) | 1213 | if (slot == 0) |
1208 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); | 1214 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); |
1209 | 1215 | ||
1210 | BUG_ON(!buffer_dirty(leaf_buf)); | ||
1211 | if (btrfs_leaf_free_space(root, leaf) < 0) | 1216 | if (btrfs_leaf_free_space(root, leaf) < 0) |
1212 | BUG(); | 1217 | BUG(); |
1213 | check_leaf(root, path, 0); | 1218 | check_leaf(root, path, 0); |
@@ -1233,6 +1238,7 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |||
1233 | ptr = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), | 1238 | ptr = btrfs_item_ptr(btrfs_buffer_leaf(path.nodes[0]), |
1234 | path.slots[0], u8); | 1239 | path.slots[0], u8); |
1235 | memcpy(ptr, data, data_size); | 1240 | memcpy(ptr, data, data_size); |
1241 | mark_buffer_dirty(path.nodes[0]); | ||
1236 | } | 1242 | } |
1237 | btrfs_release_path(root, &path); | 1243 | btrfs_release_path(root, &path); |
1238 | return ret; | 1244 | return ret; |
@@ -1273,7 +1279,7 @@ static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
1273 | if (wret) | 1279 | if (wret) |
1274 | ret = wret; | 1280 | ret = wret; |
1275 | } | 1281 | } |
1276 | BUG_ON(!buffer_dirty(parent)); | 1282 | mark_buffer_dirty(parent); |
1277 | return ret; | 1283 | return ret; |
1278 | } | 1284 | } |
1279 | 1285 | ||
@@ -1368,8 +1374,11 @@ int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
1368 | if (wret) | 1374 | if (wret) |
1369 | ret = wret; | 1375 | ret = wret; |
1370 | } else { | 1376 | } else { |
1377 | mark_buffer_dirty(leaf_buf); | ||
1371 | btrfs_block_release(root, leaf_buf); | 1378 | btrfs_block_release(root, leaf_buf); |
1372 | } | 1379 | } |
1380 | } else { | ||
1381 | mark_buffer_dirty(leaf_buf); | ||
1373 | } | 1382 | } |
1374 | } | 1383 | } |
1375 | return ret; | 1384 | return ret; |