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>
This commit is contained in:
Miao Xie 2013-06-27 18:50:59 +08:00 committed by Josef Bacik
parent 26b2589190
commit 826aa0a82c
1 changed files with 23 additions and 25 deletions

View File

@ -3199,16 +3199,18 @@ out:
static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx) static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx)
{ {
unsigned long index;
struct scrub_copy_nocow_ctx *nocow_ctx = ctx; struct scrub_copy_nocow_ctx *nocow_ctx = ctx;
int ret = 0; struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info;
struct btrfs_key key; struct btrfs_key key;
struct inode *inode = NULL; struct inode *inode;
struct page *page;
struct btrfs_root *local_root; struct btrfs_root *local_root;
u64 physical_for_dev_replace; u64 physical_for_dev_replace;
u64 len; u64 len;
struct btrfs_fs_info *fs_info = nocow_ctx->sctx->dev_root->fs_info; unsigned long index;
int srcu_index; int srcu_index;
int ret;
int err;
key.objectid = root; key.objectid = root;
key.type = BTRFS_ROOT_ITEM_KEY; 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)
if (IS_ERR(inode)) if (IS_ERR(inode))
return PTR_ERR(inode); return PTR_ERR(inode);
ret = 0;
physical_for_dev_replace = nocow_ctx->physical_for_dev_replace; physical_for_dev_replace = nocow_ctx->physical_for_dev_replace;
len = nocow_ctx->len; len = nocow_ctx->len;
while (len >= PAGE_CACHE_SIZE) { while (len >= PAGE_CACHE_SIZE) {
struct page *page = NULL;
int ret_sub;
index = offset >> PAGE_CACHE_SHIFT; index = offset >> PAGE_CACHE_SHIFT;
page = find_or_create_page(inode->i_mapping, index, GFP_NOFS); page = find_or_create_page(inode->i_mapping, index, GFP_NOFS);
if (!page) { if (!page) {
pr_err("find_or_create_page() failed\n"); pr_err("find_or_create_page() failed\n");
ret = -ENOMEM; ret = -ENOMEM;
goto next_page; goto out;
} }
if (PageUptodate(page)) { if (PageUptodate(page)) {
@ -3250,12 +3250,12 @@ static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx)
goto next_page; goto next_page;
} else { } else {
ClearPageError(page); ClearPageError(page);
ret_sub = extent_read_full_page(&BTRFS_I(inode)-> err = extent_read_full_page(&BTRFS_I(inode)->
io_tree, io_tree,
page, btrfs_get_extent, page, btrfs_get_extent,
nocow_ctx->mirror_num); nocow_ctx->mirror_num);
if (ret_sub) { if (err) {
ret = ret_sub; ret = err;
goto next_page; goto next_page;
} }
lock_page(page); lock_page(page);
@ -3264,25 +3264,23 @@ static int copy_nocow_pages_for_inode(u64 inum, u64 offset, u64 root, void *ctx)
goto next_page; goto next_page;
} }
} }
ret_sub = write_page_nocow(nocow_ctx->sctx, err = write_page_nocow(nocow_ctx->sctx,
physical_for_dev_replace, page); physical_for_dev_replace, page);
if (ret_sub) { if (err)
ret = ret_sub; ret = err;
goto next_page;
}
next_page: next_page:
if (page) { unlock_page(page);
unlock_page(page); page_cache_release(page);
put_page(page);
} if (ret)
break;
offset += PAGE_CACHE_SIZE; offset += PAGE_CACHE_SIZE;
physical_for_dev_replace += PAGE_CACHE_SIZE; physical_for_dev_replace += PAGE_CACHE_SIZE;
len -= PAGE_CACHE_SIZE; len -= PAGE_CACHE_SIZE;
} }
out:
if (inode) iput(inode);
iput(inode);
return ret; return ret;
} }