diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2013-06-27 06:50:59 -0400 |
---|---|---|
committer | Josef Bacik <jbacik@fusionio.com> | 2013-07-02 11:50:56 -0400 |
commit | 826aa0a82c5b9d2c8016c02b552e8f82f5b1e660 (patch) | |
tree | abab9acde3b519854bcf47becb02df64546bc5dd /fs/btrfs | |
parent | 26b258919006fc2d76a50b8247d7dea73207b583 (diff) |
Btrfs: cleanup the code of copy_nocow_pages_for_inode()
- It make no sense that we continue to do something after the error
happened, just go back with this patch.
- remove some check of copy_nocow_pages_for_inode(), such as page check
after write, inode check in the end of the function, because we are
sure they exist.
- remove the unnecessary goto in the return value check of the write
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/scrub.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index c1647f8c1cd0..186ea82b75f7 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c | |||
@@ -3199,16 +3199,18 @@ out: | |||
3199 | 3199 | ||
3200 | static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) | 3200 | static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) |
3201 | { | 3201 | { |
3202 | unsigned long index; | ||
3203 | struct scrub_copy_nocow_ctx *nocow_ctx = ctx; | 3202 | struct scrub_copy_nocow_ctx *nocow_ctx = ctx; |
3204 | int ret = 0; | 3203 | struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; |
3205 | struct btrfs_key key; | 3204 | struct btrfs_key key; |
3206 | struct inode *inode = NULL; | 3205 | struct inode *inode; |
3206 | struct page *page; | ||
3207 | struct btrfs_root *local_root; | 3207 | struct btrfs_root *local_root; |
3208 | u64 physical_for_dev_replace; | 3208 | u64 physical_for_dev_replace; |
3209 | u64 len; | 3209 | u64 len; |
3210 | struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; | 3210 | unsigned long index; |
3211 | int srcu_index; | 3211 | int srcu_index; |
3212 | int ret; | ||
3213 | int err; | ||
3212 | 3214 | ||
3213 | key.objectid = root; | 3215 | key.objectid = root; |
3214 | key.type = BTRFS_ROOT_ITEM_KEY; | 3216 | key.type = BTRFS_ROOT_ITEM_KEY; |
@@ -3230,19 +3232,17 @@ static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) | |||
3230 | if (IS_ERR(inode)) | 3232 | if (IS_ERR(inode)) |
3231 | return PTR_ERR(inode); | 3233 | return PTR_ERR(inode); |
3232 | 3234 | ||
3235 | ret = 0; | ||
3233 | physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; | 3236 | physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; |
3234 | len = nocow_ctx->len; | 3237 | len = nocow_ctx->len; |
3235 | while (len >= PAGE_CACHE_SIZE) { | 3238 | while (len >= PAGE_CACHE_SIZE) { |
3236 | struct page *page = NULL; | ||
3237 | int ret_sub; | ||
3238 | |||
3239 | index = offset >> PAGE_CACHE_SHIFT; | 3239 | index = offset >> PAGE_CACHE_SHIFT; |
3240 | 3240 | ||
3241 | page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); | 3241 | page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); |
3242 | if (!page) { | 3242 | if (!page) { |
3243 | pr_err("find_or_create_page() failed\n"); | 3243 | pr_err("find_or_create_page() failed\n"); |
3244 | ret = -ENOMEM; | 3244 | ret = -ENOMEM; |
3245 | goto next_page; | 3245 | goto out; |
3246 | } | 3246 | } |
3247 | 3247 | ||
3248 | if (PageUptodate(page)) { | 3248 | if (PageUptodate(page)) { |
@@ -3250,12 +3250,12 @@ static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) | |||
3250 | goto next_page; | 3250 | goto next_page; |
3251 | } else { | 3251 | } else { |
3252 | ClearPageError(page); | 3252 | ClearPageError(page); |
3253 | ret_sub = extent_read_full_page(&BTRFS_I(inode)-> | 3253 | err = extent_read_full_page(&BTRFS_I(inode)-> |
3254 | io_tree, | 3254 | io_tree, |
3255 | page, btrfs_get_extent, | 3255 | page, btrfs_get_extent, |
3256 | nocow_ctx->mirror_num); | 3256 | nocow_ctx->mirror_num); |
3257 | if (ret_sub) { | 3257 | if (err) { |
3258 | ret = ret_sub; | 3258 | ret = err; |
3259 | goto next_page; | 3259 | goto next_page; |
3260 | } | 3260 | } |
3261 | lock_page(page); | 3261 | lock_page(page); |
@@ -3264,25 +3264,23 @@ static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) | |||
3264 | goto next_page; | 3264 | goto next_page; |
3265 | } | 3265 | } |
3266 | } | 3266 | } |
3267 | ret_sub = write_page_nocow(nocow_ctx->sctx, | 3267 | err = write_page_nocow(nocow_ctx->sctx, |
3268 | physical_for_dev_replace, page); | 3268 | physical_for_dev_replace, page); |
3269 | if (ret_sub) { | 3269 | if (err) |
3270 | ret = ret_sub; | 3270 | ret = err; |
3271 | goto next_page; | ||
3272 | } | ||
3273 | |||
3274 | next_page: | 3271 | next_page: |
3275 | if (page) { | 3272 | unlock_page(page); |
3276 | unlock_page(page); | 3273 | page_cache_release(page); |
3277 | put_page(page); | 3274 | |
3278 | } | 3275 | if (ret) |
3276 | break; | ||
3277 | |||
3279 | offset += PAGE_CACHE_SIZE; | 3278 | offset += PAGE_CACHE_SIZE; |
3280 | physical_for_dev_replace += PAGE_CACHE_SIZE; | 3279 | physical_for_dev_replace += PAGE_CACHE_SIZE; |
3281 | len -= PAGE_CACHE_SIZE; | 3280 | len -= PAGE_CACHE_SIZE; |
3282 | } | 3281 | } |
3283 | 3282 | out: | |
3284 | if (inode) | 3283 | iput(inode); |
3285 | iput(inode); | ||
3286 | return ret; | 3284 | return ret; |
3287 | } | 3285 | } |
3288 | 3286 | ||