diff options
Diffstat (limited to 'fs/btrfs/inode.c')
| -rw-r--r-- | fs/btrfs/inode.c | 297 |
1 files changed, 34 insertions, 263 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6cef48572e9e..8ae72c3eedb1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | #include <linux/posix_acl.h> | 37 | #include <linux/posix_acl.h> |
| 38 | #include <linux/falloc.h> | 38 | #include <linux/falloc.h> |
| 39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
| 40 | #include <linux/ratelimit.h> | ||
| 40 | #include "compat.h" | 41 | #include "compat.h" |
| 41 | #include "ctree.h" | 42 | #include "ctree.h" |
| 42 | #include "disk-io.h" | 43 | #include "disk-io.h" |
| @@ -650,7 +651,7 @@ retry: | |||
| 650 | async_extent->start + | 651 | async_extent->start + |
| 651 | async_extent->ram_size - 1, 0); | 652 | async_extent->ram_size - 1, 0); |
| 652 | 653 | ||
| 653 | em = alloc_extent_map(GFP_NOFS); | 654 | em = alloc_extent_map(); |
| 654 | BUG_ON(!em); | 655 | BUG_ON(!em); |
| 655 | em->start = async_extent->start; | 656 | em->start = async_extent->start; |
| 656 | em->len = async_extent->ram_size; | 657 | em->len = async_extent->ram_size; |
| @@ -836,7 +837,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
| 836 | (u64)-1, &ins, 1); | 837 | (u64)-1, &ins, 1); |
| 837 | BUG_ON(ret); | 838 | BUG_ON(ret); |
| 838 | 839 | ||
| 839 | em = alloc_extent_map(GFP_NOFS); | 840 | em = alloc_extent_map(); |
| 840 | BUG_ON(!em); | 841 | BUG_ON(!em); |
| 841 | em->start = start; | 842 | em->start = start; |
| 842 | em->orig_start = em->start; | 843 | em->orig_start = em->start; |
| @@ -1176,7 +1177,7 @@ out_check: | |||
| 1176 | goto next_slot; | 1177 | goto next_slot; |
| 1177 | } | 1178 | } |
| 1178 | 1179 | ||
| 1179 | btrfs_release_path(root, path); | 1180 | btrfs_release_path(path); |
| 1180 | if (cow_start != (u64)-1) { | 1181 | if (cow_start != (u64)-1) { |
| 1181 | ret = cow_file_range(inode, locked_page, cow_start, | 1182 | ret = cow_file_range(inode, locked_page, cow_start, |
| 1182 | found_key.offset - 1, page_started, | 1183 | found_key.offset - 1, page_started, |
| @@ -1189,7 +1190,7 @@ out_check: | |||
| 1189 | struct extent_map *em; | 1190 | struct extent_map *em; |
| 1190 | struct extent_map_tree *em_tree; | 1191 | struct extent_map_tree *em_tree; |
| 1191 | em_tree = &BTRFS_I(inode)->extent_tree; | 1192 | em_tree = &BTRFS_I(inode)->extent_tree; |
| 1192 | em = alloc_extent_map(GFP_NOFS); | 1193 | em = alloc_extent_map(); |
| 1193 | BUG_ON(!em); | 1194 | BUG_ON(!em); |
| 1194 | em->start = cur_offset; | 1195 | em->start = cur_offset; |
| 1195 | em->orig_start = em->start; | 1196 | em->orig_start = em->start; |
| @@ -1234,7 +1235,7 @@ out_check: | |||
| 1234 | if (cur_offset > end) | 1235 | if (cur_offset > end) |
| 1235 | break; | 1236 | break; |
| 1236 | } | 1237 | } |
| 1237 | btrfs_release_path(root, path); | 1238 | btrfs_release_path(path); |
| 1238 | 1239 | ||
| 1239 | if (cur_offset <= end && cow_start == (u64)-1) | 1240 | if (cur_offset <= end && cow_start == (u64)-1) |
| 1240 | cow_start = cur_offset; | 1241 | cow_start = cur_offset; |
| @@ -1865,7 +1866,7 @@ static int btrfs_io_failed_hook(struct bio *failed_bio, | |||
| 1865 | } | 1866 | } |
| 1866 | read_unlock(&em_tree->lock); | 1867 | read_unlock(&em_tree->lock); |
| 1867 | 1868 | ||
| 1868 | if (!em || IS_ERR(em)) { | 1869 | if (IS_ERR_OR_NULL(em)) { |
| 1869 | kfree(failrec); | 1870 | kfree(failrec); |
| 1870 | return -EIO; | 1871 | return -EIO; |
| 1871 | } | 1872 | } |
| @@ -2014,13 +2015,11 @@ good: | |||
| 2014 | return 0; | 2015 | return 0; |
| 2015 | 2016 | ||
| 2016 | zeroit: | 2017 | zeroit: |
| 2017 | if (printk_ratelimit()) { | 2018 | printk_ratelimited(KERN_INFO "btrfs csum failed ino %llu off %llu csum %u " |
| 2018 | printk(KERN_INFO "btrfs csum failed ino %llu off %llu csum %u " | ||
| 2019 | "private %llu\n", | 2019 | "private %llu\n", |
| 2020 | (unsigned long long)btrfs_ino(page->mapping->host), | 2020 | (unsigned long long)btrfs_ino(page->mapping->host), |
| 2021 | (unsigned long long)start, csum, | 2021 | (unsigned long long)start, csum, |
| 2022 | (unsigned long long)private); | 2022 | (unsigned long long)private); |
| 2023 | } | ||
| 2024 | memset(kaddr + offset, 1, end - start + 1); | 2023 | memset(kaddr + offset, 1, end - start + 1); |
| 2025 | flush_dcache_page(page); | 2024 | flush_dcache_page(page); |
| 2026 | kunmap_atomic(kaddr, KM_USER0); | 2025 | kunmap_atomic(kaddr, KM_USER0); |
| @@ -2357,7 +2356,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) | |||
| 2357 | break; | 2356 | break; |
| 2358 | 2357 | ||
| 2359 | /* release the path since we're done with it */ | 2358 | /* release the path since we're done with it */ |
| 2360 | btrfs_release_path(root, path); | 2359 | btrfs_release_path(path); |
| 2361 | 2360 | ||
| 2362 | /* | 2361 | /* |
| 2363 | * this is where we are basically btrfs_lookup, without the | 2362 | * this is where we are basically btrfs_lookup, without the |
| @@ -2740,7 +2739,7 @@ static int __btrfs_unlink_inode(struct btrfs_trans_handle *trans, | |||
| 2740 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 2739 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
| 2741 | if (ret) | 2740 | if (ret) |
| 2742 | goto err; | 2741 | goto err; |
| 2743 | btrfs_release_path(root, path); | 2742 | btrfs_release_path(path); |
| 2744 | 2743 | ||
| 2745 | ret = btrfs_del_inode_ref(trans, root, name, name_len, ino, | 2744 | ret = btrfs_del_inode_ref(trans, root, name, name_len, ino, |
| 2746 | dir_ino, &index); | 2745 | dir_ino, &index); |
| @@ -2882,7 +2881,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
| 2882 | } else { | 2881 | } else { |
| 2883 | check_link = 0; | 2882 | check_link = 0; |
| 2884 | } | 2883 | } |
| 2885 | btrfs_release_path(root, path); | 2884 | btrfs_release_path(path); |
| 2886 | 2885 | ||
| 2887 | ret = btrfs_lookup_inode(trans, root, path, | 2886 | ret = btrfs_lookup_inode(trans, root, path, |
| 2888 | &BTRFS_I(inode)->location, 0); | 2887 | &BTRFS_I(inode)->location, 0); |
| @@ -2896,7 +2895,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
| 2896 | } else { | 2895 | } else { |
| 2897 | check_link = 0; | 2896 | check_link = 0; |
| 2898 | } | 2897 | } |
| 2899 | btrfs_release_path(root, path); | 2898 | btrfs_release_path(path); |
| 2900 | 2899 | ||
| 2901 | if (ret == 0 && S_ISREG(inode->i_mode)) { | 2900 | if (ret == 0 && S_ISREG(inode->i_mode)) { |
| 2902 | ret = btrfs_lookup_file_extent(trans, root, path, | 2901 | ret = btrfs_lookup_file_extent(trans, root, path, |
| @@ -2908,7 +2907,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
| 2908 | BUG_ON(ret == 0); | 2907 | BUG_ON(ret == 0); |
| 2909 | if (check_path_shared(root, path)) | 2908 | if (check_path_shared(root, path)) |
| 2910 | goto out; | 2909 | goto out; |
| 2911 | btrfs_release_path(root, path); | 2910 | btrfs_release_path(path); |
| 2912 | } | 2911 | } |
| 2913 | 2912 | ||
| 2914 | if (!check_link) { | 2913 | if (!check_link) { |
| @@ -2929,7 +2928,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
| 2929 | err = 0; | 2928 | err = 0; |
| 2930 | goto out; | 2929 | goto out; |
| 2931 | } | 2930 | } |
| 2932 | btrfs_release_path(root, path); | 2931 | btrfs_release_path(path); |
| 2933 | 2932 | ||
| 2934 | ref = btrfs_lookup_inode_ref(trans, root, path, | 2933 | ref = btrfs_lookup_inode_ref(trans, root, path, |
| 2935 | dentry->d_name.name, dentry->d_name.len, | 2934 | dentry->d_name.name, dentry->d_name.len, |
| @@ -2942,7 +2941,7 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir, | |||
| 2942 | if (check_path_shared(root, path)) | 2941 | if (check_path_shared(root, path)) |
| 2943 | goto out; | 2942 | goto out; |
| 2944 | index = btrfs_inode_ref_index(path->nodes[0], ref); | 2943 | index = btrfs_inode_ref_index(path->nodes[0], ref); |
| 2945 | btrfs_release_path(root, path); | 2944 | btrfs_release_path(path); |
| 2946 | 2945 | ||
| 2947 | /* | 2946 | /* |
| 2948 | * This is a commit root search, if we can lookup inode item and other | 2947 | * This is a commit root search, if we can lookup inode item and other |
| @@ -3035,14 +3034,14 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
| 3035 | 3034 | ||
| 3036 | di = btrfs_lookup_dir_item(trans, root, path, dir_ino, | 3035 | di = btrfs_lookup_dir_item(trans, root, path, dir_ino, |
| 3037 | name, name_len, -1); | 3036 | name, name_len, -1); |
| 3038 | BUG_ON(!di || IS_ERR(di)); | 3037 | BUG_ON(IS_ERR_OR_NULL(di)); |
| 3039 | 3038 | ||
| 3040 | leaf = path->nodes[0]; | 3039 | leaf = path->nodes[0]; |
| 3041 | btrfs_dir_item_key_to_cpu(leaf, di, &key); | 3040 | btrfs_dir_item_key_to_cpu(leaf, di, &key); |
| 3042 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); | 3041 | WARN_ON(key.type != BTRFS_ROOT_ITEM_KEY || key.objectid != objectid); |
| 3043 | ret = btrfs_delete_one_dir_name(trans, root, path, di); | 3042 | ret = btrfs_delete_one_dir_name(trans, root, path, di); |
| 3044 | BUG_ON(ret); | 3043 | BUG_ON(ret); |
| 3045 | btrfs_release_path(root, path); | 3044 | btrfs_release_path(path); |
| 3046 | 3045 | ||
| 3047 | ret = btrfs_del_root_ref(trans, root->fs_info->tree_root, | 3046 | ret = btrfs_del_root_ref(trans, root->fs_info->tree_root, |
| 3048 | objectid, root->root_key.objectid, | 3047 | objectid, root->root_key.objectid, |
| @@ -3051,14 +3050,14 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, | |||
| 3051 | BUG_ON(ret != -ENOENT); | 3050 | BUG_ON(ret != -ENOENT); |
| 3052 | di = btrfs_search_dir_index_item(root, path, dir_ino, | 3051 | di = btrfs_search_dir_index_item(root, path, dir_ino, |
| 3053 | name, name_len); | 3052 | name, name_len); |
| 3054 | BUG_ON(!di || IS_ERR(di)); | 3053 | BUG_ON(IS_ERR_OR_NULL(di)); |
| 3055 | 3054 | ||
| 3056 | leaf = path->nodes[0]; | 3055 | leaf = path->nodes[0]; |
| 3057 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); | 3056 | btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); |
| 3058 | btrfs_release_path(root, path); | 3057 | btrfs_release_path(path); |
| 3059 | index = key.offset; | 3058 | index = key.offset; |
| 3060 | } | 3059 | } |
| 3061 | btrfs_release_path(root, path); | 3060 | btrfs_release_path(path); |
| 3062 | 3061 | ||
| 3063 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); | 3062 | ret = btrfs_delete_delayed_dir_index(trans, root, dir, index); |
| 3064 | BUG_ON(ret); | 3063 | BUG_ON(ret); |
| @@ -3114,178 +3113,6 @@ out: | |||
| 3114 | return err; | 3113 | return err; |
| 3115 | } | 3114 | } |
| 3116 | 3115 | ||
| 3117 | #if 0 | ||
| 3118 | /* | ||
| 3119 | * when truncating bytes in a file, it is possible to avoid reading | ||
| 3120 | * the leaves that contain only checksum items. This can be the | ||
| 3121 | * majority of the IO required to delete a large file, but it must | ||
| 3122 | * be done carefully. | ||
| 3123 | * | ||
| 3124 | * The keys in the level just above the leaves are checked to make sure | ||
| 3125 | * the lowest key in a given leaf is a csum key, and starts at an offset | ||
| 3126 | * after the new size. | ||
| 3127 | * | ||
| 3128 | * Then the key for the next leaf is checked to make sure it also has | ||
| 3129 | * a checksum item for the same file. If it does, we know our target leaf | ||
| 3130 | * contains only checksum items, and it can be safely freed without reading | ||
| 3131 | * it. | ||
| 3132 | * | ||
| 3133 | * This is just an optimization targeted at large files. It may do | ||
| 3134 | * nothing. It will return 0 unless things went badly. | ||
| 3135 | */ | ||
| 3136 | static noinline int drop_csum_leaves(struct btrfs_trans_handle *trans, | ||
| 3137 | struct btrfs_root *root, | ||
| 3138 | struct btrfs_path *path, | ||
| 3139 | struct inode *inode, u64 new_size) | ||
| 3140 | { | ||
| 3141 | struct btrfs_key key; | ||
| 3142 | int ret; | ||
| 3143 | int nritems; | ||
| 3144 | struct btrfs_key found_key; | ||
| 3145 | struct btrfs_key other_key; | ||
| 3146 | struct btrfs_leaf_ref *ref; | ||
| 3147 | u64 leaf_gen; | ||
| 3148 | u64 leaf_start; | ||
| 3149 | |||
| 3150 | path->lowest_level = 1; | ||
| 3151 | key.objectid = inode->i_ino; | ||
| 3152 | key.type = BTRFS_CSUM_ITEM_KEY; | ||
| 3153 | key.offset = new_size; | ||
| 3154 | again: | ||
| 3155 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | ||
| 3156 | if (ret < 0) | ||
| 3157 | goto out; | ||
| 3158 | |||
| 3159 | if (path->nodes[1] == NULL) { | ||
| 3160 | ret = 0; | ||
| 3161 | goto out; | ||
| 3162 | } | ||
| 3163 | ret = 0; | ||
| 3164 | btrfs_node_key_to_cpu(path->nodes[1], &found_key, path->slots[1]); | ||
| 3165 | nritems = btrfs_header_nritems(path->nodes[1]); | ||
| 3166 | |||
| 3167 | if (!nritems) | ||
| 3168 | goto out; | ||
| 3169 | |||
| 3170 | if (path->slots[1] >= nritems) | ||
| 3171 | goto next_node; | ||
| 3172 | |||
| 3173 | /* did we find a key greater than anything we want to delete? */ | ||
| 3174 | if (found_key.objectid > inode->i_ino || | ||
| 3175 | (found_key.objectid == inode->i_ino && found_key.type > key.type)) | ||
| 3176 | goto out; | ||
| 3177 | |||
| 3178 | /* we check the next key in the node to make sure the leave contains | ||
| 3179 | * only checksum items. This comparison doesn't work if our | ||
| 3180 | * leaf is the last one in the node | ||
| 3181 | */ | ||
| 3182 | if (path->slots[1] + 1 >= nritems) { | ||
| 3183 | next_node: | ||
| 3184 | /* search forward from the last key in the node, this | ||
| 3185 | * will bring us into the next node in the tree | ||
| 3186 | */ | ||
| 3187 | btrfs_node_key_to_cpu(path->nodes[1], &found_key, nritems - 1); | ||
| 3188 | |||
| 3189 | /* unlikely, but we inc below, so check to be safe */ | ||
| 3190 | if (found_key.offset == (u64)-1) | ||
| 3191 | goto out; | ||
| 3192 | |||
| 3193 | /* search_forward needs a path with locks held, do the | ||
| 3194 | * search again for the original key. It is possible | ||
| 3195 | * this will race with a balance and return a path that | ||
| 3196 | * we could modify, but this drop is just an optimization | ||
| 3197 | * and is allowed to miss some leaves. | ||
| 3198 | */ | ||
| 3199 | btrfs_release_path(root, path); | ||
| 3200 | found_key.offset++; | ||
| 3201 | |||
| 3202 | /* setup a max key for search_forward */ | ||
| 3203 | other_key.offset = (u64)-1; | ||
| 3204 | other_key.type = key.type; | ||
| 3205 | other_key.objectid = key.objectid; | ||
| 3206 | |||
| 3207 | path->keep_locks = 1; | ||
| 3208 | ret = btrfs_search_forward(root, &found_key, &other_key, | ||
| 3209 | path, 0, 0); | ||
| 3210 | path->keep_locks = 0; | ||
| 3211 | if (ret || found_key.objectid != key.objectid || | ||
| 3212 | found_key.type != key.type) { | ||
| 3213 | ret = 0; | ||
| 3214 | goto out; | ||
| 3215 | } | ||
| 3216 | |||
| 3217 | key.offset = found_key.offset; | ||
| 3218 | btrfs_release_path(root, path); | ||
| 3219 | cond_resched(); | ||
| 3220 | goto again; | ||
| 3221 | } | ||
| 3222 | |||
| 3223 | /* we know there's one more slot after us in the tree, | ||
| 3224 | * read that key so we can verify it is also a checksum item | ||
| 3225 | */ | ||
| 3226 | btrfs_node_key_to_cpu(path->nodes[1], &other_key, path->slots[1] + 1); | ||
| 3227 | |||
| 3228 | if (found_key.objectid < inode->i_ino) | ||
| 3229 | goto next_key; | ||
| 3230 | |||
| 3231 | if (found_key.type != key.type || found_key.offset < new_size) | ||
| 3232 | goto next_key; | ||
| 3233 | |||
| 3234 | /* | ||
| 3235 | * if the key for the next leaf isn't a csum key from this objectid, | ||
| 3236 | * we can't be sure there aren't good items inside this leaf. | ||
| 3237 | * Bail out | ||
| 3238 | */ | ||
| 3239 | if (other_key.objectid != inode->i_ino || other_key.type != key.type) | ||
| 3240 | goto out; | ||
| 3241 | |||
| 3242 | leaf_start = btrfs_node_blockptr(path->nodes[1], path->slots[1]); | ||
| 3243 | leaf_gen = btrfs_node_ptr_generation(path->nodes[1], path->slots[1]); | ||
| 3244 | /* | ||
| 3245 | * it is safe to delete this leaf, it contains only | ||
| 3246 | * csum items from this inode at an offset >= new_size | ||
| 3247 | */ | ||
| 3248 | ret = btrfs_del_leaf(trans, root, path, leaf_start); | ||
| 3249 | BUG_ON(ret); | ||
| 3250 | |||
| 3251 | if (root->ref_cows && leaf_gen < trans->transid) { | ||
| 3252 | ref = btrfs_alloc_leaf_ref(root, 0); | ||
| 3253 | if (ref) { | ||
| 3254 | ref->root_gen = root->root_key.offset; | ||
| 3255 | ref->bytenr = leaf_start; | ||
| 3256 | ref->owner = 0; | ||
| 3257 | ref->generation = leaf_gen; | ||
| 3258 | ref->nritems = 0; | ||
| 3259 | |||
| 3260 | btrfs_sort_leaf_ref(ref); | ||
| 3261 | |||
| 3262 | ret = btrfs_add_leaf_ref(root, ref, 0); | ||
| 3263 | WARN_ON(ret); | ||
| 3264 | btrfs_free_leaf_ref(root, ref); | ||
| 3265 | } else { | ||
| 3266 | WARN_ON(1); | ||
| 3267 | } | ||
| 3268 | } | ||
| 3269 | next_key: | ||
| 3270 | btrfs_release_path(root, path); | ||
| 3271 | |||
| 3272 | if (other_key.objectid == inode->i_ino && | ||
| 3273 | other_key.type == key.type && other_key.offset > key.offset) { | ||
| 3274 | key.offset = other_key.offset; | ||
| 3275 | cond_resched(); | ||
| 3276 | goto again; | ||
| 3277 | } | ||
| 3278 | ret = 0; | ||
| 3279 | out: | ||
| 3280 | /* fixup any changes we've made to the path */ | ||
| 3281 | path->lowest_level = 0; | ||
| 3282 | path->keep_locks = 0; | ||
| 3283 | btrfs_release_path(root, path); | ||
| 3284 | return ret; | ||
| 3285 | } | ||
| 3286 | |||
| 3287 | #endif | ||
| 3288 | |||
| 3289 | /* | 3116 | /* |
| 3290 | * this can truncate away extent items, csum items and directory items. | 3117 | * this can truncate away extent items, csum items and directory items. |
| 3291 | * It starts at a high offset and removes keys until it can't find | 3118 | * It starts at a high offset and removes keys until it can't find |
| @@ -3510,7 +3337,7 @@ delete: | |||
| 3510 | BUG_ON(ret); | 3337 | BUG_ON(ret); |
| 3511 | pending_del_nr = 0; | 3338 | pending_del_nr = 0; |
| 3512 | } | 3339 | } |
| 3513 | btrfs_release_path(root, path); | 3340 | btrfs_release_path(path); |
| 3514 | goto search_again; | 3341 | goto search_again; |
| 3515 | } else { | 3342 | } else { |
| 3516 | path->slots[0]--; | 3343 | path->slots[0]--; |
| @@ -3668,7 +3495,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) | |||
| 3668 | while (1) { | 3495 | while (1) { |
| 3669 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, | 3496 | em = btrfs_get_extent(inode, NULL, 0, cur_offset, |
| 3670 | block_end - cur_offset, 0); | 3497 | block_end - cur_offset, 0); |
| 3671 | BUG_ON(IS_ERR(em) || !em); | 3498 | BUG_ON(IS_ERR_OR_NULL(em)); |
| 3672 | last_byte = min(extent_map_end(em), block_end); | 3499 | last_byte = min(extent_map_end(em), block_end); |
| 3673 | last_byte = (last_byte + mask) & ~mask; | 3500 | last_byte = (last_byte + mask) & ~mask; |
| 3674 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { | 3501 | if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { |
| @@ -3878,7 +3705,7 @@ static int btrfs_inode_by_name(struct inode *dir, struct dentry *dentry, | |||
| 3878 | if (IS_ERR(di)) | 3705 | if (IS_ERR(di)) |
| 3879 | ret = PTR_ERR(di); | 3706 | ret = PTR_ERR(di); |
| 3880 | 3707 | ||
| 3881 | if (!di || IS_ERR(di)) | 3708 | if (IS_ERR_OR_NULL(di)) |
| 3882 | goto out_err; | 3709 | goto out_err; |
| 3883 | 3710 | ||
| 3884 | btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); | 3711 | btrfs_dir_item_key_to_cpu(path->nodes[0], di, location); |
| @@ -3936,7 +3763,7 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
| 3936 | if (ret) | 3763 | if (ret) |
| 3937 | goto out; | 3764 | goto out; |
| 3938 | 3765 | ||
| 3939 | btrfs_release_path(root->fs_info->tree_root, path); | 3766 | btrfs_release_path(path); |
| 3940 | 3767 | ||
| 3941 | new_root = btrfs_read_fs_root_no_name(root->fs_info, location); | 3768 | new_root = btrfs_read_fs_root_no_name(root->fs_info, location); |
| 3942 | if (IS_ERR(new_root)) { | 3769 | if (IS_ERR(new_root)) { |
| @@ -4479,24 +4306,20 @@ void btrfs_dirty_inode(struct inode *inode) | |||
| 4479 | btrfs_end_transaction(trans, root); | 4306 | btrfs_end_transaction(trans, root); |
| 4480 | trans = btrfs_start_transaction(root, 1); | 4307 | trans = btrfs_start_transaction(root, 1); |
| 4481 | if (IS_ERR(trans)) { | 4308 | if (IS_ERR(trans)) { |
| 4482 | if (printk_ratelimit()) { | 4309 | printk_ratelimited(KERN_ERR "btrfs: fail to " |
| 4483 | printk(KERN_ERR "btrfs: fail to " | ||
| 4484 | "dirty inode %llu error %ld\n", | 4310 | "dirty inode %llu error %ld\n", |
| 4485 | (unsigned long long)btrfs_ino(inode), | 4311 | (unsigned long long)btrfs_ino(inode), |
| 4486 | PTR_ERR(trans)); | 4312 | PTR_ERR(trans)); |
| 4487 | } | ||
| 4488 | return; | 4313 | return; |
| 4489 | } | 4314 | } |
| 4490 | btrfs_set_trans_block_group(trans, inode); | 4315 | btrfs_set_trans_block_group(trans, inode); |
| 4491 | 4316 | ||
| 4492 | ret = btrfs_update_inode(trans, root, inode); | 4317 | ret = btrfs_update_inode(trans, root, inode); |
| 4493 | if (ret) { | 4318 | if (ret) { |
| 4494 | if (printk_ratelimit()) { | 4319 | printk_ratelimited(KERN_ERR "btrfs: fail to " |
| 4495 | printk(KERN_ERR "btrfs: fail to " | ||
| 4496 | "dirty inode %llu error %d\n", | 4320 | "dirty inode %llu error %d\n", |
| 4497 | (unsigned long long)btrfs_ino(inode), | 4321 | (unsigned long long)btrfs_ino(inode), |
| 4498 | ret); | 4322 | ret); |
| 4499 | } | ||
| 4500 | } | 4323 | } |
| 4501 | } | 4324 | } |
| 4502 | btrfs_end_transaction(trans, root); | 4325 | btrfs_end_transaction(trans, root); |
| @@ -5146,7 +4969,7 @@ again: | |||
| 5146 | else | 4969 | else |
| 5147 | goto out; | 4970 | goto out; |
| 5148 | } | 4971 | } |
| 5149 | em = alloc_extent_map(GFP_NOFS); | 4972 | em = alloc_extent_map(); |
| 5150 | if (!em) { | 4973 | if (!em) { |
| 5151 | err = -ENOMEM; | 4974 | err = -ENOMEM; |
| 5152 | goto out; | 4975 | goto out; |
| @@ -5300,7 +5123,7 @@ again: | |||
| 5300 | kunmap(page); | 5123 | kunmap(page); |
| 5301 | free_extent_map(em); | 5124 | free_extent_map(em); |
| 5302 | em = NULL; | 5125 | em = NULL; |
| 5303 | btrfs_release_path(root, path); | 5126 | btrfs_release_path(path); |
| 5304 | trans = btrfs_join_transaction(root, 1); | 5127 | trans = btrfs_join_transaction(root, 1); |
| 5305 | if (IS_ERR(trans)) | 5128 | if (IS_ERR(trans)) |
| 5306 | return ERR_CAST(trans); | 5129 | return ERR_CAST(trans); |
| @@ -5326,7 +5149,7 @@ not_found_em: | |||
| 5326 | em->block_start = EXTENT_MAP_HOLE; | 5149 | em->block_start = EXTENT_MAP_HOLE; |
| 5327 | set_bit(EXTENT_FLAG_VACANCY, &em->flags); | 5150 | set_bit(EXTENT_FLAG_VACANCY, &em->flags); |
| 5328 | insert: | 5151 | insert: |
| 5329 | btrfs_release_path(root, path); | 5152 | btrfs_release_path(path); |
| 5330 | if (em->start > start || extent_map_end(em) <= start) { | 5153 | if (em->start > start || extent_map_end(em) <= start) { |
| 5331 | printk(KERN_ERR "Btrfs: bad extent! em: [%llu %llu] passed " | 5154 | printk(KERN_ERR "Btrfs: bad extent! em: [%llu %llu] passed " |
| 5332 | "[%llu %llu]\n", (unsigned long long)em->start, | 5155 | "[%llu %llu]\n", (unsigned long long)em->start, |
| @@ -5459,7 +5282,7 @@ struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *pag | |||
| 5459 | u64 hole_start = start; | 5282 | u64 hole_start = start; |
| 5460 | u64 hole_len = len; | 5283 | u64 hole_len = len; |
| 5461 | 5284 | ||
| 5462 | em = alloc_extent_map(GFP_NOFS); | 5285 | em = alloc_extent_map(); |
| 5463 | if (!em) { | 5286 | if (!em) { |
| 5464 | err = -ENOMEM; | 5287 | err = -ENOMEM; |
| 5465 | goto out; | 5288 | goto out; |
| @@ -5560,7 +5383,7 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode, | |||
| 5560 | } | 5383 | } |
| 5561 | 5384 | ||
| 5562 | if (!em) { | 5385 | if (!em) { |
| 5563 | em = alloc_extent_map(GFP_NOFS); | 5386 | em = alloc_extent_map(); |
| 5564 | if (!em) { | 5387 | if (!em) { |
| 5565 | em = ERR_PTR(-ENOMEM); | 5388 | em = ERR_PTR(-ENOMEM); |
| 5566 | goto out; | 5389 | goto out; |
| @@ -6865,9 +6688,9 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
| 6865 | ei->delayed_node = NULL; | 6688 | ei->delayed_node = NULL; |
| 6866 | 6689 | ||
| 6867 | inode = &ei->vfs_inode; | 6690 | inode = &ei->vfs_inode; |
| 6868 | extent_map_tree_init(&ei->extent_tree, GFP_NOFS); | 6691 | extent_map_tree_init(&ei->extent_tree); |
| 6869 | extent_io_tree_init(&ei->io_tree, &inode->i_data, GFP_NOFS); | 6692 | extent_io_tree_init(&ei->io_tree, &inode->i_data); |
| 6870 | extent_io_tree_init(&ei->io_failure_tree, &inode->i_data, GFP_NOFS); | 6693 | extent_io_tree_init(&ei->io_failure_tree, &inode->i_data); |
| 6871 | mutex_init(&ei->log_mutex); | 6694 | mutex_init(&ei->log_mutex); |
| 6872 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); | 6695 | btrfs_ordered_inode_tree_init(&ei->ordered_tree); |
| 6873 | INIT_LIST_HEAD(&ei->i_orphan); | 6696 | INIT_LIST_HEAD(&ei->i_orphan); |
| @@ -7265,58 +7088,6 @@ int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput) | |||
| 7265 | return 0; | 7088 | return 0; |
| 7266 | } | 7089 | } |
| 7267 | 7090 | ||
| 7268 | int btrfs_start_one_delalloc_inode(struct btrfs_root *root, int delay_iput, | ||
| 7269 | int sync) | ||
| 7270 | { | ||
| 7271 | struct btrfs_inode *binode; | ||
| 7272 | struct inode *inode = NULL; | ||
| 7273 | |||
| 7274 | spin_lock(&root->fs_info->delalloc_lock); | ||
| 7275 | while (!list_empty(&root->fs_info->delalloc_inodes)) { | ||
| 7276 | binode = list_entry(root->fs_info->delalloc_inodes.next, | ||
| 7277 | struct btrfs_inode, delalloc_inodes); | ||
| 7278 | inode = igrab(&binode->vfs_inode); | ||
| 7279 | if (inode) { | ||
| 7280 | list_move_tail(&binode->delalloc_inodes, | ||
| 7281 | &root->fs_info->delalloc_inodes); | ||
| 7282 | break; | ||
| 7283 | } | ||
| 7284 | |||
| 7285 | list_del_init(&binode->delalloc_inodes); | ||
| 7286 | cond_resched_lock(&root->fs_info->delalloc_lock); | ||
| 7287 | } | ||
| 7288 | spin_unlock(&root->fs_info->delalloc_lock); | ||
| 7289 | |||
| 7290 | if (inode) { | ||
| 7291 | if (sync) { | ||
| 7292 | filemap_write_and_wait(inode->i_mapping); | ||
| 7293 | /* | ||
| 7294 | * We have to do this because compression doesn't | ||
| 7295 | * actually set PG_writeback until it submits the pages | ||
| 7296 | * for IO, which happens in an async thread, so we could | ||
| 7297 | * race and not actually wait for any writeback pages | ||
| 7298 | * because they've not been submitted yet. Technically | ||
| 7299 | * this could still be the case for the ordered stuff | ||
| 7300 | * since the async thread may not have started to do its | ||
| 7301 | * work yet. If this becomes the case then we need to | ||
| 7302 | * figure out a way to make sure that in writepage we | ||
| 7303 | * wait for any async pages to be submitted before | ||
| 7304 | * returning so that fdatawait does what its supposed to | ||
| 7305 | * do. | ||
| 7306 | */ | ||
| 7307 | btrfs_wait_ordered_range(inode, 0, (u64)-1); | ||
| 7308 | } else { | ||
| 7309 | filemap_flush(inode->i_mapping); | ||
| 7310 | } | ||
| 7311 | if (delay_iput) | ||
| 7312 | btrfs_add_delayed_iput(inode); | ||
| 7313 | else | ||
| 7314 | iput(inode); | ||
| 7315 | return 1; | ||
| 7316 | } | ||
| 7317 | return 0; | ||
| 7318 | } | ||
| 7319 | |||
| 7320 | static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | 7091 | static int btrfs_symlink(struct inode *dir, struct dentry *dentry, |
| 7321 | const char *symname) | 7092 | const char *symname) |
| 7322 | { | 7093 | { |
