diff options
author | Jeff Mahoney <jeffm@suse.com> | 2012-03-01 08:56:26 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2012-03-21 20:45:34 -0400 |
commit | 143bede527b054a271053f41bfaca2b57baa9408 (patch) | |
tree | 95c71d3705c73bf98e7a1547da35e70a44703c1e /fs/btrfs/ctree.c | |
parent | ffd7b33944f4573a063af7a55f8a5199c8185665 (diff) |
btrfs: return void in functions without error conditions
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 200 |
1 files changed, 67 insertions, 133 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 0639a555e16e..9d472c2a8de8 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -36,7 +36,7 @@ static int balance_node_right(struct btrfs_trans_handle *trans, | |||
36 | struct btrfs_root *root, | 36 | struct btrfs_root *root, |
37 | struct extent_buffer *dst_buf, | 37 | struct extent_buffer *dst_buf, |
38 | struct extent_buffer *src_buf); | 38 | struct extent_buffer *src_buf); |
39 | static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 39 | static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
40 | struct btrfs_path *path, int level, int slot); | 40 | struct btrfs_path *path, int level, int slot); |
41 | 41 | ||
42 | struct btrfs_path *btrfs_alloc_path(void) | 42 | struct btrfs_path *btrfs_alloc_path(void) |
@@ -1010,10 +1010,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1010 | if (btrfs_header_nritems(right) == 0) { | 1010 | if (btrfs_header_nritems(right) == 0) { |
1011 | clean_tree_block(trans, root, right); | 1011 | clean_tree_block(trans, root, right); |
1012 | btrfs_tree_unlock(right); | 1012 | btrfs_tree_unlock(right); |
1013 | wret = del_ptr(trans, root, path, level + 1, pslot + | 1013 | del_ptr(trans, root, path, level + 1, pslot + 1); |
1014 | 1); | ||
1015 | if (wret) | ||
1016 | ret = wret; | ||
1017 | root_sub_used(root, right->len); | 1014 | root_sub_used(root, right->len); |
1018 | btrfs_free_tree_block(trans, root, right, 0, 1, 0); | 1015 | btrfs_free_tree_block(trans, root, right, 0, 1, 0); |
1019 | free_extent_buffer(right); | 1016 | free_extent_buffer(right); |
@@ -1051,9 +1048,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, | |||
1051 | if (btrfs_header_nritems(mid) == 0) { | 1048 | if (btrfs_header_nritems(mid) == 0) { |
1052 | clean_tree_block(trans, root, mid); | 1049 | clean_tree_block(trans, root, mid); |
1053 | btrfs_tree_unlock(mid); | 1050 | btrfs_tree_unlock(mid); |
1054 | wret = del_ptr(trans, root, path, level + 1, pslot); | 1051 | del_ptr(trans, root, path, level + 1, pslot); |
1055 | if (wret) | ||
1056 | ret = wret; | ||
1057 | root_sub_used(root, mid->len); | 1052 | root_sub_used(root, mid->len); |
1058 | btrfs_free_tree_block(trans, root, mid, 0, 1, 0); | 1053 | btrfs_free_tree_block(trans, root, mid, 0, 1, 0); |
1059 | free_extent_buffer(mid); | 1054 | free_extent_buffer(mid); |
@@ -1881,15 +1876,12 @@ done: | |||
1881 | * fixing up pointers when a given leaf/node is not in slot 0 of the | 1876 | * fixing up pointers when a given leaf/node is not in slot 0 of the |
1882 | * higher levels | 1877 | * higher levels |
1883 | * | 1878 | * |
1884 | * If this fails to write a tree block, it returns -1, but continues | ||
1885 | * fixing up the blocks in ram so the tree is consistent. | ||
1886 | */ | 1879 | */ |
1887 | static int fixup_low_keys(struct btrfs_trans_handle *trans, | 1880 | static void fixup_low_keys(struct btrfs_trans_handle *trans, |
1888 | struct btrfs_root *root, struct btrfs_path *path, | 1881 | struct btrfs_root *root, struct btrfs_path *path, |
1889 | struct btrfs_disk_key *key, int level) | 1882 | struct btrfs_disk_key *key, int level) |
1890 | { | 1883 | { |
1891 | int i; | 1884 | int i; |
1892 | int ret = 0; | ||
1893 | struct extent_buffer *t; | 1885 | struct extent_buffer *t; |
1894 | 1886 | ||
1895 | for (i = level; i < BTRFS_MAX_LEVEL; i++) { | 1887 | for (i = level; i < BTRFS_MAX_LEVEL; i++) { |
@@ -1902,7 +1894,6 @@ static int fixup_low_keys(struct btrfs_trans_handle *trans, | |||
1902 | if (tslot != 0) | 1894 | if (tslot != 0) |
1903 | break; | 1895 | break; |
1904 | } | 1896 | } |
1905 | return ret; | ||
1906 | } | 1897 | } |
1907 | 1898 | ||
1908 | /* | 1899 | /* |
@@ -1911,9 +1902,9 @@ static int fixup_low_keys(struct btrfs_trans_handle *trans, | |||
1911 | * This function isn't completely safe. It's the caller's responsibility | 1902 | * This function isn't completely safe. It's the caller's responsibility |
1912 | * that the new key won't break the order | 1903 | * that the new key won't break the order |
1913 | */ | 1904 | */ |
1914 | int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, | 1905 | void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, |
1915 | struct btrfs_root *root, struct btrfs_path *path, | 1906 | struct btrfs_root *root, struct btrfs_path *path, |
1916 | struct btrfs_key *new_key) | 1907 | struct btrfs_key *new_key) |
1917 | { | 1908 | { |
1918 | struct btrfs_disk_key disk_key; | 1909 | struct btrfs_disk_key disk_key; |
1919 | struct extent_buffer *eb; | 1910 | struct extent_buffer *eb; |
@@ -1923,13 +1914,11 @@ int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, | |||
1923 | slot = path->slots[0]; | 1914 | slot = path->slots[0]; |
1924 | if (slot > 0) { | 1915 | if (slot > 0) { |
1925 | btrfs_item_key(eb, &disk_key, slot - 1); | 1916 | btrfs_item_key(eb, &disk_key, slot - 1); |
1926 | if (comp_keys(&disk_key, new_key) >= 0) | 1917 | BUG_ON(comp_keys(&disk_key, new_key) >= 0); |
1927 | return -1; | ||
1928 | } | 1918 | } |
1929 | if (slot < btrfs_header_nritems(eb) - 1) { | 1919 | if (slot < btrfs_header_nritems(eb) - 1) { |
1930 | btrfs_item_key(eb, &disk_key, slot + 1); | 1920 | btrfs_item_key(eb, &disk_key, slot + 1); |
1931 | if (comp_keys(&disk_key, new_key) <= 0) | 1921 | BUG_ON(comp_keys(&disk_key, new_key) <= 0); |
1932 | return -1; | ||
1933 | } | 1922 | } |
1934 | 1923 | ||
1935 | btrfs_cpu_key_to_disk(&disk_key, new_key); | 1924 | btrfs_cpu_key_to_disk(&disk_key, new_key); |
@@ -1937,7 +1926,6 @@ int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, | |||
1937 | btrfs_mark_buffer_dirty(eb); | 1926 | btrfs_mark_buffer_dirty(eb); |
1938 | if (slot == 0) | 1927 | if (slot == 0) |
1939 | fixup_low_keys(trans, root, path, &disk_key, 1); | 1928 | fixup_low_keys(trans, root, path, &disk_key, 1); |
1940 | return 0; | ||
1941 | } | 1929 | } |
1942 | 1930 | ||
1943 | /* | 1931 | /* |
@@ -2140,12 +2128,11 @@ static noinline int insert_new_root(struct btrfs_trans_handle *trans, | |||
2140 | * | 2128 | * |
2141 | * slot and level indicate where you want the key to go, and | 2129 | * slot and level indicate where you want the key to go, and |
2142 | * blocknr is the block the key points to. | 2130 | * blocknr is the block the key points to. |
2143 | * | ||
2144 | * returns zero on success and < 0 on any error | ||
2145 | */ | 2131 | */ |
2146 | static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root | 2132 | static void insert_ptr(struct btrfs_trans_handle *trans, |
2147 | *root, struct btrfs_path *path, struct btrfs_disk_key | 2133 | struct btrfs_root *root, struct btrfs_path *path, |
2148 | *key, u64 bytenr, int slot, int level) | 2134 | struct btrfs_disk_key *key, u64 bytenr, |
2135 | int slot, int level) | ||
2149 | { | 2136 | { |
2150 | struct extent_buffer *lower; | 2137 | struct extent_buffer *lower; |
2151 | int nritems; | 2138 | int nritems; |
@@ -2155,8 +2142,7 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root | |||
2155 | lower = path->nodes[level]; | 2142 | lower = path->nodes[level]; |
2156 | nritems = btrfs_header_nritems(lower); | 2143 | nritems = btrfs_header_nritems(lower); |
2157 | BUG_ON(slot > nritems); | 2144 | BUG_ON(slot > nritems); |
2158 | if (nritems == BTRFS_NODEPTRS_PER_BLOCK(root)) | 2145 | BUG_ON(nritems == BTRFS_NODEPTRS_PER_BLOCK(root)); |
2159 | BUG(); | ||
2160 | if (slot != nritems) { | 2146 | if (slot != nritems) { |
2161 | memmove_extent_buffer(lower, | 2147 | memmove_extent_buffer(lower, |
2162 | btrfs_node_key_ptr_offset(slot + 1), | 2148 | btrfs_node_key_ptr_offset(slot + 1), |
@@ -2169,7 +2155,6 @@ static int insert_ptr(struct btrfs_trans_handle *trans, struct btrfs_root | |||
2169 | btrfs_set_node_ptr_generation(lower, slot, trans->transid); | 2155 | btrfs_set_node_ptr_generation(lower, slot, trans->transid); |
2170 | btrfs_set_header_nritems(lower, nritems + 1); | 2156 | btrfs_set_header_nritems(lower, nritems + 1); |
2171 | btrfs_mark_buffer_dirty(lower); | 2157 | btrfs_mark_buffer_dirty(lower); |
2172 | return 0; | ||
2173 | } | 2158 | } |
2174 | 2159 | ||
2175 | /* | 2160 | /* |
@@ -2190,7 +2175,6 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
2190 | struct btrfs_disk_key disk_key; | 2175 | struct btrfs_disk_key disk_key; |
2191 | int mid; | 2176 | int mid; |
2192 | int ret; | 2177 | int ret; |
2193 | int wret; | ||
2194 | u32 c_nritems; | 2178 | u32 c_nritems; |
2195 | 2179 | ||
2196 | c = path->nodes[level]; | 2180 | c = path->nodes[level]; |
@@ -2247,11 +2231,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans, | |||
2247 | btrfs_mark_buffer_dirty(c); | 2231 | btrfs_mark_buffer_dirty(c); |
2248 | btrfs_mark_buffer_dirty(split); | 2232 | btrfs_mark_buffer_dirty(split); |
2249 | 2233 | ||
2250 | wret = insert_ptr(trans, root, path, &disk_key, split->start, | 2234 | insert_ptr(trans, root, path, &disk_key, split->start, |
2251 | path->slots[level + 1] + 1, | 2235 | path->slots[level + 1] + 1, level + 1); |
2252 | level + 1); | ||
2253 | if (wret) | ||
2254 | ret = wret; | ||
2255 | 2236 | ||
2256 | if (path->slots[level] >= mid) { | 2237 | if (path->slots[level] >= mid) { |
2257 | path->slots[level] -= mid; | 2238 | path->slots[level] -= mid; |
@@ -2537,7 +2518,6 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, | |||
2537 | u32 old_left_nritems; | 2518 | u32 old_left_nritems; |
2538 | u32 nr; | 2519 | u32 nr; |
2539 | int ret = 0; | 2520 | int ret = 0; |
2540 | int wret; | ||
2541 | u32 this_item_size; | 2521 | u32 this_item_size; |
2542 | u32 old_left_item_size; | 2522 | u32 old_left_item_size; |
2543 | 2523 | ||
@@ -2643,9 +2623,7 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans, | |||
2643 | clean_tree_block(trans, root, right); | 2623 | clean_tree_block(trans, root, right); |
2644 | 2624 | ||
2645 | btrfs_item_key(right, &disk_key, 0); | 2625 | btrfs_item_key(right, &disk_key, 0); |
2646 | wret = fixup_low_keys(trans, root, path, &disk_key, 1); | 2626 | fixup_low_keys(trans, root, path, &disk_key, 1); |
2647 | if (wret) | ||
2648 | ret = wret; | ||
2649 | 2627 | ||
2650 | /* then fixup the leaf pointer in the path */ | 2628 | /* then fixup the leaf pointer in the path */ |
2651 | if (path->slots[0] < push_items) { | 2629 | if (path->slots[0] < push_items) { |
@@ -2738,21 +2716,17 @@ out: | |||
2738 | /* | 2716 | /* |
2739 | * split the path's leaf in two, making sure there is at least data_size | 2717 | * split the path's leaf in two, making sure there is at least data_size |
2740 | * available for the resulting leaf level of the path. | 2718 | * available for the resulting leaf level of the path. |
2741 | * | ||
2742 | * returns 0 if all went well and < 0 on failure. | ||
2743 | */ | 2719 | */ |
2744 | static noinline int copy_for_split(struct btrfs_trans_handle *trans, | 2720 | static noinline void copy_for_split(struct btrfs_trans_handle *trans, |
2745 | struct btrfs_root *root, | 2721 | struct btrfs_root *root, |
2746 | struct btrfs_path *path, | 2722 | struct btrfs_path *path, |
2747 | struct extent_buffer *l, | 2723 | struct extent_buffer *l, |
2748 | struct extent_buffer *right, | 2724 | struct extent_buffer *right, |
2749 | int slot, int mid, int nritems) | 2725 | int slot, int mid, int nritems) |
2750 | { | 2726 | { |
2751 | int data_copy_size; | 2727 | int data_copy_size; |
2752 | int rt_data_off; | 2728 | int rt_data_off; |
2753 | int i; | 2729 | int i; |
2754 | int ret = 0; | ||
2755 | int wret; | ||
2756 | struct btrfs_disk_key disk_key; | 2730 | struct btrfs_disk_key disk_key; |
2757 | 2731 | ||
2758 | nritems = nritems - mid; | 2732 | nritems = nritems - mid; |
@@ -2780,12 +2754,9 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, | |||
2780 | } | 2754 | } |
2781 | 2755 | ||
2782 | btrfs_set_header_nritems(l, mid); | 2756 | btrfs_set_header_nritems(l, mid); |
2783 | ret = 0; | ||
2784 | btrfs_item_key(right, &disk_key, 0); | 2757 | btrfs_item_key(right, &disk_key, 0); |
2785 | wret = insert_ptr(trans, root, path, &disk_key, right->start, | 2758 | insert_ptr(trans, root, path, &disk_key, right->start, |
2786 | path->slots[1] + 1, 1); | 2759 | path->slots[1] + 1, 1); |
2787 | if (wret) | ||
2788 | ret = wret; | ||
2789 | 2760 | ||
2790 | btrfs_mark_buffer_dirty(right); | 2761 | btrfs_mark_buffer_dirty(right); |
2791 | btrfs_mark_buffer_dirty(l); | 2762 | btrfs_mark_buffer_dirty(l); |
@@ -2803,8 +2774,6 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, | |||
2803 | } | 2774 | } |
2804 | 2775 | ||
2805 | BUG_ON(path->slots[0] < 0); | 2776 | BUG_ON(path->slots[0] < 0); |
2806 | |||
2807 | return ret; | ||
2808 | } | 2777 | } |
2809 | 2778 | ||
2810 | /* | 2779 | /* |
@@ -2993,12 +2962,8 @@ again: | |||
2993 | if (split == 0) { | 2962 | if (split == 0) { |
2994 | if (mid <= slot) { | 2963 | if (mid <= slot) { |
2995 | btrfs_set_header_nritems(right, 0); | 2964 | btrfs_set_header_nritems(right, 0); |
2996 | wret = insert_ptr(trans, root, path, | 2965 | insert_ptr(trans, root, path, &disk_key, right->start, |
2997 | &disk_key, right->start, | 2966 | path->slots[1] + 1, 1); |
2998 | path->slots[1] + 1, 1); | ||
2999 | if (wret) | ||
3000 | ret = wret; | ||
3001 | |||
3002 | btrfs_tree_unlock(path->nodes[0]); | 2967 | btrfs_tree_unlock(path->nodes[0]); |
3003 | free_extent_buffer(path->nodes[0]); | 2968 | free_extent_buffer(path->nodes[0]); |
3004 | path->nodes[0] = right; | 2969 | path->nodes[0] = right; |
@@ -3006,29 +2971,21 @@ again: | |||
3006 | path->slots[1] += 1; | 2971 | path->slots[1] += 1; |
3007 | } else { | 2972 | } else { |
3008 | btrfs_set_header_nritems(right, 0); | 2973 | btrfs_set_header_nritems(right, 0); |
3009 | wret = insert_ptr(trans, root, path, | 2974 | insert_ptr(trans, root, path, &disk_key, right->start, |
3010 | &disk_key, | ||
3011 | right->start, | ||
3012 | path->slots[1], 1); | 2975 | path->slots[1], 1); |
3013 | if (wret) | ||
3014 | ret = wret; | ||
3015 | btrfs_tree_unlock(path->nodes[0]); | 2976 | btrfs_tree_unlock(path->nodes[0]); |
3016 | free_extent_buffer(path->nodes[0]); | 2977 | free_extent_buffer(path->nodes[0]); |
3017 | path->nodes[0] = right; | 2978 | path->nodes[0] = right; |
3018 | path->slots[0] = 0; | 2979 | path->slots[0] = 0; |
3019 | if (path->slots[1] == 0) { | 2980 | if (path->slots[1] == 0) |
3020 | wret = fixup_low_keys(trans, root, | 2981 | fixup_low_keys(trans, root, path, |
3021 | path, &disk_key, 1); | 2982 | &disk_key, 1); |
3022 | if (wret) | ||
3023 | ret = wret; | ||
3024 | } | ||
3025 | } | 2983 | } |
3026 | btrfs_mark_buffer_dirty(right); | 2984 | btrfs_mark_buffer_dirty(right); |
3027 | return ret; | 2985 | return ret; |
3028 | } | 2986 | } |
3029 | 2987 | ||
3030 | ret = copy_for_split(trans, root, path, l, right, slot, mid, nritems); | 2988 | copy_for_split(trans, root, path, l, right, slot, mid, nritems); |
3031 | BUG_ON(ret); | ||
3032 | 2989 | ||
3033 | if (split == 2) { | 2990 | if (split == 2) { |
3034 | BUG_ON(num_doubles != 0); | 2991 | BUG_ON(num_doubles != 0); |
@@ -3036,7 +2993,7 @@ again: | |||
3036 | goto again; | 2993 | goto again; |
3037 | } | 2994 | } |
3038 | 2995 | ||
3039 | return ret; | 2996 | return 0; |
3040 | 2997 | ||
3041 | push_for_double: | 2998 | push_for_double: |
3042 | push_for_double_split(trans, root, path, data_size); | 2999 | push_for_double_split(trans, root, path, data_size); |
@@ -3238,11 +3195,9 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans, | |||
3238 | return ret; | 3195 | return ret; |
3239 | 3196 | ||
3240 | path->slots[0]++; | 3197 | path->slots[0]++; |
3241 | ret = setup_items_for_insert(trans, root, path, new_key, &item_size, | 3198 | setup_items_for_insert(trans, root, path, new_key, &item_size, |
3242 | item_size, item_size + | 3199 | item_size, item_size + |
3243 | sizeof(struct btrfs_item), 1); | 3200 | sizeof(struct btrfs_item), 1); |
3244 | BUG_ON(ret); | ||
3245 | |||
3246 | leaf = path->nodes[0]; | 3201 | leaf = path->nodes[0]; |
3247 | memcpy_extent_buffer(leaf, | 3202 | memcpy_extent_buffer(leaf, |
3248 | btrfs_item_ptr_offset(leaf, path->slots[0]), | 3203 | btrfs_item_ptr_offset(leaf, path->slots[0]), |
@@ -3257,10 +3212,10 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans, | |||
3257 | * off the end of the item or if we shift the item to chop bytes off | 3212 | * off the end of the item or if we shift the item to chop bytes off |
3258 | * the front. | 3213 | * the front. |
3259 | */ | 3214 | */ |
3260 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, | 3215 | void btrfs_truncate_item(struct btrfs_trans_handle *trans, |
3261 | struct btrfs_root *root, | 3216 | struct btrfs_root *root, |
3262 | struct btrfs_path *path, | 3217 | struct btrfs_path *path, |
3263 | u32 new_size, int from_end) | 3218 | u32 new_size, int from_end) |
3264 | { | 3219 | { |
3265 | int slot; | 3220 | int slot; |
3266 | struct extent_buffer *leaf; | 3221 | struct extent_buffer *leaf; |
@@ -3277,7 +3232,7 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans, | |||
3277 | 3232 | ||
3278 | old_size = btrfs_item_size_nr(leaf, slot); | 3233 | old_size = btrfs_item_size_nr(leaf, slot); |
3279 | if (old_size == new_size) | 3234 | if (old_size == new_size) |
3280 | return 0; | 3235 | return; |
3281 | 3236 | ||
3282 | nritems = btrfs_header_nritems(leaf); | 3237 | nritems = btrfs_header_nritems(leaf); |
3283 | data_end = leaf_data_end(root, leaf); | 3238 | data_end = leaf_data_end(root, leaf); |
@@ -3350,15 +3305,14 @@ int btrfs_truncate_item(struct btrfs_trans_handle *trans, | |||
3350 | btrfs_print_leaf(root, leaf); | 3305 | btrfs_print_leaf(root, leaf); |
3351 | BUG(); | 3306 | BUG(); |
3352 | } | 3307 | } |
3353 | return 0; | ||
3354 | } | 3308 | } |
3355 | 3309 | ||
3356 | /* | 3310 | /* |
3357 | * make the item pointed to by the path bigger, data_size is the new size. | 3311 | * make the item pointed to by the path bigger, data_size is the new size. |
3358 | */ | 3312 | */ |
3359 | int btrfs_extend_item(struct btrfs_trans_handle *trans, | 3313 | void btrfs_extend_item(struct btrfs_trans_handle *trans, |
3360 | struct btrfs_root *root, struct btrfs_path *path, | 3314 | struct btrfs_root *root, struct btrfs_path *path, |
3361 | u32 data_size) | 3315 | u32 data_size) |
3362 | { | 3316 | { |
3363 | int slot; | 3317 | int slot; |
3364 | struct extent_buffer *leaf; | 3318 | struct extent_buffer *leaf; |
@@ -3416,7 +3370,6 @@ int btrfs_extend_item(struct btrfs_trans_handle *trans, | |||
3416 | btrfs_print_leaf(root, leaf); | 3370 | btrfs_print_leaf(root, leaf); |
3417 | BUG(); | 3371 | BUG(); |
3418 | } | 3372 | } |
3419 | return 0; | ||
3420 | } | 3373 | } |
3421 | 3374 | ||
3422 | /* | 3375 | /* |
@@ -3544,7 +3497,7 @@ int btrfs_insert_some_items(struct btrfs_trans_handle *trans, | |||
3544 | ret = 0; | 3497 | ret = 0; |
3545 | if (slot == 0) { | 3498 | if (slot == 0) { |
3546 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); | 3499 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); |
3547 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); | 3500 | fixup_low_keys(trans, root, path, &disk_key, 1); |
3548 | } | 3501 | } |
3549 | 3502 | ||
3550 | if (btrfs_leaf_free_space(root, leaf) < 0) { | 3503 | if (btrfs_leaf_free_space(root, leaf) < 0) { |
@@ -3562,17 +3515,16 @@ out: | |||
3562 | * to save stack depth by doing the bulk of the work in a function | 3515 | * to save stack depth by doing the bulk of the work in a function |
3563 | * that doesn't call btrfs_search_slot | 3516 | * that doesn't call btrfs_search_slot |
3564 | */ | 3517 | */ |
3565 | int setup_items_for_insert(struct btrfs_trans_handle *trans, | 3518 | void setup_items_for_insert(struct btrfs_trans_handle *trans, |
3566 | struct btrfs_root *root, struct btrfs_path *path, | 3519 | struct btrfs_root *root, struct btrfs_path *path, |
3567 | struct btrfs_key *cpu_key, u32 *data_size, | 3520 | struct btrfs_key *cpu_key, u32 *data_size, |
3568 | u32 total_data, u32 total_size, int nr) | 3521 | u32 total_data, u32 total_size, int nr) |
3569 | { | 3522 | { |
3570 | struct btrfs_item *item; | 3523 | struct btrfs_item *item; |
3571 | int i; | 3524 | int i; |
3572 | u32 nritems; | 3525 | u32 nritems; |
3573 | unsigned int data_end; | 3526 | unsigned int data_end; |
3574 | struct btrfs_disk_key disk_key; | 3527 | struct btrfs_disk_key disk_key; |
3575 | int ret; | ||
3576 | struct extent_buffer *leaf; | 3528 | struct extent_buffer *leaf; |
3577 | int slot; | 3529 | int slot; |
3578 | 3530 | ||
@@ -3633,10 +3585,9 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans, | |||
3633 | 3585 | ||
3634 | btrfs_set_header_nritems(leaf, nritems + nr); | 3586 | btrfs_set_header_nritems(leaf, nritems + nr); |
3635 | 3587 | ||
3636 | ret = 0; | ||
3637 | if (slot == 0) { | 3588 | if (slot == 0) { |
3638 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); | 3589 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); |
3639 | ret = fixup_low_keys(trans, root, path, &disk_key, 1); | 3590 | fixup_low_keys(trans, root, path, &disk_key, 1); |
3640 | } | 3591 | } |
3641 | btrfs_unlock_up_safe(path, 1); | 3592 | btrfs_unlock_up_safe(path, 1); |
3642 | btrfs_mark_buffer_dirty(leaf); | 3593 | btrfs_mark_buffer_dirty(leaf); |
@@ -3645,7 +3596,6 @@ int setup_items_for_insert(struct btrfs_trans_handle *trans, | |||
3645 | btrfs_print_leaf(root, leaf); | 3596 | btrfs_print_leaf(root, leaf); |
3646 | BUG(); | 3597 | BUG(); |
3647 | } | 3598 | } |
3648 | return ret; | ||
3649 | } | 3599 | } |
3650 | 3600 | ||
3651 | /* | 3601 | /* |
@@ -3672,16 +3622,14 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, | |||
3672 | if (ret == 0) | 3622 | if (ret == 0) |
3673 | return -EEXIST; | 3623 | return -EEXIST; |
3674 | if (ret < 0) | 3624 | if (ret < 0) |
3675 | goto out; | 3625 | return ret; |
3676 | 3626 | ||
3677 | slot = path->slots[0]; | 3627 | slot = path->slots[0]; |
3678 | BUG_ON(slot < 0); | 3628 | BUG_ON(slot < 0); |
3679 | 3629 | ||
3680 | ret = setup_items_for_insert(trans, root, path, cpu_key, data_size, | 3630 | setup_items_for_insert(trans, root, path, cpu_key, data_size, |
3681 | total_data, total_size, nr); | 3631 | total_data, total_size, nr); |
3682 | 3632 | return 0; | |
3683 | out: | ||
3684 | return ret; | ||
3685 | } | 3633 | } |
3686 | 3634 | ||
3687 | /* | 3635 | /* |
@@ -3717,13 +3665,11 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |||
3717 | * the tree should have been previously balanced so the deletion does not | 3665 | * the tree should have been previously balanced so the deletion does not |
3718 | * empty a node. | 3666 | * empty a node. |
3719 | */ | 3667 | */ |
3720 | static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | 3668 | static void del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
3721 | struct btrfs_path *path, int level, int slot) | 3669 | struct btrfs_path *path, int level, int slot) |
3722 | { | 3670 | { |
3723 | struct extent_buffer *parent = path->nodes[level]; | 3671 | struct extent_buffer *parent = path->nodes[level]; |
3724 | u32 nritems; | 3672 | u32 nritems; |
3725 | int ret = 0; | ||
3726 | int wret; | ||
3727 | 3673 | ||
3728 | nritems = btrfs_header_nritems(parent); | 3674 | nritems = btrfs_header_nritems(parent); |
3729 | if (slot != nritems - 1) { | 3675 | if (slot != nritems - 1) { |
@@ -3743,12 +3689,9 @@ static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
3743 | struct btrfs_disk_key disk_key; | 3689 | struct btrfs_disk_key disk_key; |
3744 | 3690 | ||
3745 | btrfs_node_key(parent, &disk_key, 0); | 3691 | btrfs_node_key(parent, &disk_key, 0); |
3746 | wret = fixup_low_keys(trans, root, path, &disk_key, level + 1); | 3692 | fixup_low_keys(trans, root, path, &disk_key, level + 1); |
3747 | if (wret) | ||
3748 | ret = wret; | ||
3749 | } | 3693 | } |
3750 | btrfs_mark_buffer_dirty(parent); | 3694 | btrfs_mark_buffer_dirty(parent); |
3751 | return ret; | ||
3752 | } | 3695 | } |
3753 | 3696 | ||
3754 | /* | 3697 | /* |
@@ -3761,17 +3704,13 @@ static int del_ptr(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
3761 | * The path must have already been setup for deleting the leaf, including | 3704 | * The path must have already been setup for deleting the leaf, including |
3762 | * all the proper balancing. path->nodes[1] must be locked. | 3705 | * all the proper balancing. path->nodes[1] must be locked. |
3763 | */ | 3706 | */ |
3764 | static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans, | 3707 | static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans, |
3765 | struct btrfs_root *root, | 3708 | struct btrfs_root *root, |
3766 | struct btrfs_path *path, | 3709 | struct btrfs_path *path, |
3767 | struct extent_buffer *leaf) | 3710 | struct extent_buffer *leaf) |
3768 | { | 3711 | { |
3769 | int ret; | ||
3770 | |||
3771 | WARN_ON(btrfs_header_generation(leaf) != trans->transid); | 3712 | WARN_ON(btrfs_header_generation(leaf) != trans->transid); |
3772 | ret = del_ptr(trans, root, path, 1, path->slots[1]); | 3713 | del_ptr(trans, root, path, 1, path->slots[1]); |
3773 | if (ret) | ||
3774 | return ret; | ||
3775 | 3714 | ||
3776 | /* | 3715 | /* |
3777 | * btrfs_free_extent is expensive, we want to make sure we | 3716 | * btrfs_free_extent is expensive, we want to make sure we |
@@ -3782,7 +3721,6 @@ static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans, | |||
3782 | root_sub_used(root, leaf->len); | 3721 | root_sub_used(root, leaf->len); |
3783 | 3722 | ||
3784 | btrfs_free_tree_block(trans, root, leaf, 0, 1, 0); | 3723 | btrfs_free_tree_block(trans, root, leaf, 0, 1, 0); |
3785 | return 0; | ||
3786 | } | 3724 | } |
3787 | /* | 3725 | /* |
3788 | * delete the item at the leaf level in path. If that empties | 3726 | * delete the item at the leaf level in path. If that empties |
@@ -3839,8 +3777,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
3839 | } else { | 3777 | } else { |
3840 | btrfs_set_path_blocking(path); | 3778 | btrfs_set_path_blocking(path); |
3841 | clean_tree_block(trans, root, leaf); | 3779 | clean_tree_block(trans, root, leaf); |
3842 | ret = btrfs_del_leaf(trans, root, path, leaf); | 3780 | btrfs_del_leaf(trans, root, path, leaf); |
3843 | BUG_ON(ret); | ||
3844 | } | 3781 | } |
3845 | } else { | 3782 | } else { |
3846 | int used = leaf_space_used(leaf, 0, nritems); | 3783 | int used = leaf_space_used(leaf, 0, nritems); |
@@ -3848,10 +3785,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
3848 | struct btrfs_disk_key disk_key; | 3785 | struct btrfs_disk_key disk_key; |
3849 | 3786 | ||
3850 | btrfs_item_key(leaf, &disk_key, 0); | 3787 | btrfs_item_key(leaf, &disk_key, 0); |
3851 | wret = fixup_low_keys(trans, root, path, | 3788 | fixup_low_keys(trans, root, path, &disk_key, 1); |
3852 | &disk_key, 1); | ||
3853 | if (wret) | ||
3854 | ret = wret; | ||
3855 | } | 3789 | } |
3856 | 3790 | ||
3857 | /* delete the leaf if it is mostly empty */ | 3791 | /* delete the leaf if it is mostly empty */ |
@@ -3879,9 +3813,9 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |||
3879 | 3813 | ||
3880 | if (btrfs_header_nritems(leaf) == 0) { | 3814 | if (btrfs_header_nritems(leaf) == 0) { |
3881 | path->slots[1] = slot; | 3815 | path->slots[1] = slot; |
3882 | ret = btrfs_del_leaf(trans, root, path, leaf); | 3816 | btrfs_del_leaf(trans, root, path, leaf); |
3883 | BUG_ON(ret); | ||
3884 | free_extent_buffer(leaf); | 3817 | free_extent_buffer(leaf); |
3818 | ret = 0; | ||
3885 | } else { | 3819 | } else { |
3886 | /* if we're still in the path, make sure | 3820 | /* if we're still in the path, make sure |
3887 | * we're dirty. Otherwise, one of the | 3821 | * we're dirty. Otherwise, one of the |