提交 fba90ffe 编写于 作者: D Dmitry Monakhov 提交者: Theodore Ts'o

ext4: migrate cleanup

This patch cleanup code a bit, actual logic not changed
- Move current block pointer to migrate_structure, let's all
  walk info will be in one structure.
- Get rid of usless null ind-block ptr checks, caller already
  does that check.
Signed-off-by: NDmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 6cdbb0ef
...@@ -20,13 +20,13 @@ ...@@ -20,13 +20,13 @@
* The contiguous blocks details which can be * The contiguous blocks details which can be
* represented by a single extent * represented by a single extent
*/ */
struct list_blocks_struct { struct migrate_struct {
ext4_lblk_t first_block, last_block; ext4_lblk_t first_block, last_block, curr_block;
ext4_fsblk_t first_pblock, last_pblock; ext4_fsblk_t first_pblock, last_pblock;
}; };
static int finish_range(handle_t *handle, struct inode *inode, static int finish_range(handle_t *handle, struct inode *inode,
struct list_blocks_struct *lb) struct migrate_struct *lb)
{ {
int retval = 0, needed; int retval = 0, needed;
...@@ -86,8 +86,7 @@ static int finish_range(handle_t *handle, struct inode *inode, ...@@ -86,8 +86,7 @@ static int finish_range(handle_t *handle, struct inode *inode,
} }
static int update_extent_range(handle_t *handle, struct inode *inode, static int update_extent_range(handle_t *handle, struct inode *inode,
ext4_fsblk_t pblock, ext4_lblk_t blk_num, ext4_fsblk_t pblock, struct migrate_struct *lb)
struct list_blocks_struct *lb)
{ {
int retval; int retval;
/* /*
...@@ -95,9 +94,10 @@ static int update_extent_range(handle_t *handle, struct inode *inode, ...@@ -95,9 +94,10 @@ static int update_extent_range(handle_t *handle, struct inode *inode,
*/ */
if (lb->first_pblock && if (lb->first_pblock &&
(lb->last_pblock+1 == pblock) && (lb->last_pblock+1 == pblock) &&
(lb->last_block+1 == blk_num)) { (lb->last_block+1 == lb->curr_block)) {
lb->last_pblock = pblock; lb->last_pblock = pblock;
lb->last_block = blk_num; lb->last_block = lb->curr_block;
lb->curr_block++;
return 0; return 0;
} }
/* /*
...@@ -105,64 +105,49 @@ static int update_extent_range(handle_t *handle, struct inode *inode, ...@@ -105,64 +105,49 @@ static int update_extent_range(handle_t *handle, struct inode *inode,
*/ */
retval = finish_range(handle, inode, lb); retval = finish_range(handle, inode, lb);
lb->first_pblock = lb->last_pblock = pblock; lb->first_pblock = lb->last_pblock = pblock;
lb->first_block = lb->last_block = blk_num; lb->first_block = lb->last_block = lb->curr_block;
lb->curr_block++;
return retval; return retval;
} }
static int update_ind_extent_range(handle_t *handle, struct inode *inode, static int update_ind_extent_range(handle_t *handle, struct inode *inode,
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, ext4_fsblk_t pblock,
struct list_blocks_struct *lb) struct migrate_struct *lb)
{ {
struct buffer_head *bh; struct buffer_head *bh;
__le32 *i_data; __le32 *i_data;
int i, retval = 0; int i, retval = 0;
ext4_lblk_t blk_count = *blk_nump;
unsigned long max_entries = inode->i_sb->s_blocksize >> 2; unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
if (!pblock) {
/* Only update the file block number */
*blk_nump += max_entries;
return 0;
}
bh = sb_bread(inode->i_sb, pblock); bh = sb_bread(inode->i_sb, pblock);
if (!bh) if (!bh)
return -EIO; return -EIO;
i_data = (__le32 *)bh->b_data; i_data = (__le32 *)bh->b_data;
for (i = 0; i < max_entries; i++, blk_count++) { for (i = 0; i < max_entries; i++) {
if (i_data[i]) { if (i_data[i]) {
retval = update_extent_range(handle, inode, retval = update_extent_range(handle, inode,
le32_to_cpu(i_data[i]), le32_to_cpu(i_data[i]), lb);
blk_count, lb);
if (retval) if (retval)
break; break;
} else {
lb->curr_block++;
} }
} }
/* Update the file block number */
*blk_nump = blk_count;
put_bh(bh); put_bh(bh);
return retval; return retval;
} }
static int update_dind_extent_range(handle_t *handle, struct inode *inode, static int update_dind_extent_range(handle_t *handle, struct inode *inode,
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, ext4_fsblk_t pblock,
struct list_blocks_struct *lb) struct migrate_struct *lb)
{ {
struct buffer_head *bh; struct buffer_head *bh;
__le32 *i_data; __le32 *i_data;
int i, retval = 0; int i, retval = 0;
ext4_lblk_t blk_count = *blk_nump;
unsigned long max_entries = inode->i_sb->s_blocksize >> 2; unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
if (!pblock) {
/* Only update the file block number */
*blk_nump += max_entries * max_entries;
return 0;
}
bh = sb_bread(inode->i_sb, pblock); bh = sb_bread(inode->i_sb, pblock);
if (!bh) if (!bh)
return -EIO; return -EIO;
...@@ -171,38 +156,28 @@ static int update_dind_extent_range(handle_t *handle, struct inode *inode, ...@@ -171,38 +156,28 @@ static int update_dind_extent_range(handle_t *handle, struct inode *inode,
for (i = 0; i < max_entries; i++) { for (i = 0; i < max_entries; i++) {
if (i_data[i]) { if (i_data[i]) {
retval = update_ind_extent_range(handle, inode, retval = update_ind_extent_range(handle, inode,
le32_to_cpu(i_data[i]), le32_to_cpu(i_data[i]), lb);
&blk_count, lb);
if (retval) if (retval)
break; break;
} else { } else {
/* Only update the file block number */ /* Only update the file block number */
blk_count += max_entries; lb->curr_block += max_entries;
} }
} }
/* Update the file block number */
*blk_nump = blk_count;
put_bh(bh); put_bh(bh);
return retval; return retval;
} }
static int update_tind_extent_range(handle_t *handle, struct inode *inode, static int update_tind_extent_range(handle_t *handle, struct inode *inode,
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, ext4_fsblk_t pblock,
struct list_blocks_struct *lb) struct migrate_struct *lb)
{ {
struct buffer_head *bh; struct buffer_head *bh;
__le32 *i_data; __le32 *i_data;
int i, retval = 0; int i, retval = 0;
ext4_lblk_t blk_count = *blk_nump;
unsigned long max_entries = inode->i_sb->s_blocksize >> 2; unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
if (!pblock) {
/* Only update the file block number */
*blk_nump += max_entries * max_entries * max_entries;
return 0;
}
bh = sb_bread(inode->i_sb, pblock); bh = sb_bread(inode->i_sb, pblock);
if (!bh) if (!bh)
return -EIO; return -EIO;
...@@ -211,16 +186,14 @@ static int update_tind_extent_range(handle_t *handle, struct inode *inode, ...@@ -211,16 +186,14 @@ static int update_tind_extent_range(handle_t *handle, struct inode *inode,
for (i = 0; i < max_entries; i++) { for (i = 0; i < max_entries; i++) {
if (i_data[i]) { if (i_data[i]) {
retval = update_dind_extent_range(handle, inode, retval = update_dind_extent_range(handle, inode,
le32_to_cpu(i_data[i]), le32_to_cpu(i_data[i]), lb);
&blk_count, lb);
if (retval) if (retval)
break; break;
} else } else {
/* Only update the file block number */ /* Only update the file block number */
blk_count += max_entries * max_entries; lb->curr_block += max_entries * max_entries;
}
} }
/* Update the file block number */
*blk_nump = blk_count;
put_bh(bh); put_bh(bh);
return retval; return retval;
...@@ -461,10 +434,9 @@ int ext4_ext_migrate(struct inode *inode) ...@@ -461,10 +434,9 @@ int ext4_ext_migrate(struct inode *inode)
handle_t *handle; handle_t *handle;
int retval = 0, i; int retval = 0, i;
__le32 *i_data; __le32 *i_data;
ext4_lblk_t blk_count = 0;
struct ext4_inode_info *ei; struct ext4_inode_info *ei;
struct inode *tmp_inode = NULL; struct inode *tmp_inode = NULL;
struct list_blocks_struct lb; struct migrate_struct lb;
unsigned long max_entries; unsigned long max_entries;
__u32 goal; __u32 goal;
...@@ -550,35 +522,32 @@ int ext4_ext_migrate(struct inode *inode) ...@@ -550,35 +522,32 @@ int ext4_ext_migrate(struct inode *inode)
/* 32 bit block address 4 bytes */ /* 32 bit block address 4 bytes */
max_entries = inode->i_sb->s_blocksize >> 2; max_entries = inode->i_sb->s_blocksize >> 2;
for (i = 0; i < EXT4_NDIR_BLOCKS; i++, blk_count++) { for (i = 0; i < EXT4_NDIR_BLOCKS; i++) {
if (i_data[i]) { if (i_data[i]) {
retval = update_extent_range(handle, tmp_inode, retval = update_extent_range(handle, tmp_inode,
le32_to_cpu(i_data[i]), le32_to_cpu(i_data[i]), &lb);
blk_count, &lb);
if (retval) if (retval)
goto err_out; goto err_out;
} } else
lb.curr_block++;
} }
if (i_data[EXT4_IND_BLOCK]) { if (i_data[EXT4_IND_BLOCK]) {
retval = update_ind_extent_range(handle, tmp_inode, retval = update_ind_extent_range(handle, tmp_inode,
le32_to_cpu(i_data[EXT4_IND_BLOCK]), le32_to_cpu(i_data[EXT4_IND_BLOCK]), &lb);
&blk_count, &lb);
if (retval) if (retval)
goto err_out; goto err_out;
} else } else
blk_count += max_entries; lb.curr_block += max_entries;
if (i_data[EXT4_DIND_BLOCK]) { if (i_data[EXT4_DIND_BLOCK]) {
retval = update_dind_extent_range(handle, tmp_inode, retval = update_dind_extent_range(handle, tmp_inode,
le32_to_cpu(i_data[EXT4_DIND_BLOCK]), le32_to_cpu(i_data[EXT4_DIND_BLOCK]), &lb);
&blk_count, &lb);
if (retval) if (retval)
goto err_out; goto err_out;
} else } else
blk_count += max_entries * max_entries; lb.curr_block += max_entries * max_entries;
if (i_data[EXT4_TIND_BLOCK]) { if (i_data[EXT4_TIND_BLOCK]) {
retval = update_tind_extent_range(handle, tmp_inode, retval = update_tind_extent_range(handle, tmp_inode,
le32_to_cpu(i_data[EXT4_TIND_BLOCK]), le32_to_cpu(i_data[EXT4_TIND_BLOCK]), &lb);
&blk_count, &lb);
if (retval) if (retval)
goto err_out; goto err_out;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册