Skip to content

Commit fba90ff

Browse files
Dmitry Monakhovtytso
authored andcommitted
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: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 6cdbb0e commit fba90ff

1 file changed

Lines changed: 35 additions & 66 deletions

File tree

‎fs/ext4/migrate.c‎

Lines changed: 35 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
* The contiguous blocks details which can be
2121
* represented by a single extent
2222
*/
23-
struct list_blocks_struct {
24-
ext4_lblk_t first_block, last_block;
23+
struct migrate_struct {
24+
ext4_lblk_t first_block, last_block, curr_block;
2525
ext4_fsblk_t first_pblock, last_pblock;
2626
};
2727

2828
static int finish_range(handle_t *handle, struct inode *inode,
29-
struct list_blocks_struct *lb)
29+
struct migrate_struct *lb)
3030

3131
{
3232
int retval = 0, needed;
@@ -86,83 +86,68 @@ static int finish_range(handle_t *handle, struct inode *inode,
8686
}
8787

8888
static int update_extent_range(handle_t *handle, struct inode *inode,
89-
ext4_fsblk_t pblock, ext4_lblk_t blk_num,
90-
struct list_blocks_struct *lb)
89+
ext4_fsblk_t pblock, struct migrate_struct *lb)
9190
{
9291
int retval;
9392
/*
9493
* See if we can add on to the existing range (if it exists)
9594
*/
9695
if (lb->first_pblock &&
9796
(lb->last_pblock+1 == pblock) &&
98-
(lb->last_block+1 == blk_num)) {
97+
(lb->last_block+1 == lb->curr_block)) {
9998
lb->last_pblock = pblock;
100-
lb->last_block = blk_num;
99+
lb->last_block = lb->curr_block;
100+
lb->curr_block++;
101101
return 0;
102102
}
103103
/*
104104
* Start a new range.
105105
*/
106106
retval = finish_range(handle, inode, lb);
107107
lb->first_pblock = lb->last_pblock = pblock;
108-
lb->first_block = lb->last_block = blk_num;
109-
108+
lb->first_block = lb->last_block = lb->curr_block;
109+
lb->curr_block++;
110110
return retval;
111111
}
112112

113113
static int update_ind_extent_range(handle_t *handle, struct inode *inode,
114-
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump,
115-
struct list_blocks_struct *lb)
114+
ext4_fsblk_t pblock,
115+
struct migrate_struct *lb)
116116
{
117117
struct buffer_head *bh;
118118
__le32 *i_data;
119119
int i, retval = 0;
120-
ext4_lblk_t blk_count = *blk_nump;
121120
unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
122121

123-
if (!pblock) {
124-
/* Only update the file block number */
125-
*blk_nump += max_entries;
126-
return 0;
127-
}
128-
129122
bh = sb_bread(inode->i_sb, pblock);
130123
if (!bh)
131124
return -EIO;
132125

133126
i_data = (__le32 *)bh->b_data;
134-
for (i = 0; i < max_entries; i++, blk_count++) {
127+
for (i = 0; i < max_entries; i++) {
135128
if (i_data[i]) {
136129
retval = update_extent_range(handle, inode,
137-
le32_to_cpu(i_data[i]),
138-
blk_count, lb);
130+
le32_to_cpu(i_data[i]), lb);
139131
if (retval)
140132
break;
133+
} else {
134+
lb->curr_block++;
141135
}
142136
}
143-
144-
/* Update the file block number */
145-
*blk_nump = blk_count;
146137
put_bh(bh);
147138
return retval;
148139

149140
}
150141

151142
static int update_dind_extent_range(handle_t *handle, struct inode *inode,
152-
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump,
153-
struct list_blocks_struct *lb)
143+
ext4_fsblk_t pblock,
144+
struct migrate_struct *lb)
154145
{
155146
struct buffer_head *bh;
156147
__le32 *i_data;
157148
int i, retval = 0;
158-
ext4_lblk_t blk_count = *blk_nump;
159149
unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
160150

161-
if (!pblock) {
162-
/* Only update the file block number */
163-
*blk_nump += max_entries * max_entries;
164-
return 0;
165-
}
166151
bh = sb_bread(inode->i_sb, pblock);
167152
if (!bh)
168153
return -EIO;
@@ -171,38 +156,28 @@ static int update_dind_extent_range(handle_t *handle, struct inode *inode,
171156
for (i = 0; i < max_entries; i++) {
172157
if (i_data[i]) {
173158
retval = update_ind_extent_range(handle, inode,
174-
le32_to_cpu(i_data[i]),
175-
&blk_count, lb);
159+
le32_to_cpu(i_data[i]), lb);
176160
if (retval)
177161
break;
178162
} else {
179163
/* Only update the file block number */
180-
blk_count += max_entries;
164+
lb->curr_block += max_entries;
181165
}
182166
}
183-
184-
/* Update the file block number */
185-
*blk_nump = blk_count;
186167
put_bh(bh);
187168
return retval;
188169

189170
}
190171

191172
static int update_tind_extent_range(handle_t *handle, struct inode *inode,
192-
ext4_fsblk_t pblock, ext4_lblk_t *blk_nump,
193-
struct list_blocks_struct *lb)
173+
ext4_fsblk_t pblock,
174+
struct migrate_struct *lb)
194175
{
195176
struct buffer_head *bh;
196177
__le32 *i_data;
197178
int i, retval = 0;
198-
ext4_lblk_t blk_count = *blk_nump;
199179
unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
200180

201-
if (!pblock) {
202-
/* Only update the file block number */
203-
*blk_nump += max_entries * max_entries * max_entries;
204-
return 0;
205-
}
206181
bh = sb_bread(inode->i_sb, pblock);
207182
if (!bh)
208183
return -EIO;
@@ -211,16 +186,14 @@ static int update_tind_extent_range(handle_t *handle, struct inode *inode,
211186
for (i = 0; i < max_entries; i++) {
212187
if (i_data[i]) {
213188
retval = update_dind_extent_range(handle, inode,
214-
le32_to_cpu(i_data[i]),
215-
&blk_count, lb);
189+
le32_to_cpu(i_data[i]), lb);
216190
if (retval)
217191
break;
218-
} else
192+
} else {
219193
/* Only update the file block number */
220-
blk_count += max_entries * max_entries;
194+
lb->curr_block += max_entries * max_entries;
195+
}
221196
}
222-
/* Update the file block number */
223-
*blk_nump = blk_count;
224197
put_bh(bh);
225198
return retval;
226199

@@ -461,10 +434,9 @@ int ext4_ext_migrate(struct inode *inode)
461434
handle_t *handle;
462435
int retval = 0, i;
463436
__le32 *i_data;
464-
ext4_lblk_t blk_count = 0;
465437
struct ext4_inode_info *ei;
466438
struct inode *tmp_inode = NULL;
467-
struct list_blocks_struct lb;
439+
struct migrate_struct lb;
468440
unsigned long max_entries;
469441
__u32 goal;
470442

@@ -550,35 +522,32 @@ int ext4_ext_migrate(struct inode *inode)
550522

551523
/* 32 bit block address 4 bytes */
552524
max_entries = inode->i_sb->s_blocksize >> 2;
553-
for (i = 0; i < EXT4_NDIR_BLOCKS; i++, blk_count++) {
525+
for (i = 0; i < EXT4_NDIR_BLOCKS; i++) {
554526
if (i_data[i]) {
555527
retval = update_extent_range(handle, tmp_inode,
556-
le32_to_cpu(i_data[i]),
557-
blk_count, &lb);
528+
le32_to_cpu(i_data[i]), &lb);
558529
if (retval)
559530
goto err_out;
560-
}
531+
} else
532+
lb.curr_block++;
561533
}
562534
if (i_data[EXT4_IND_BLOCK]) {
563535
retval = update_ind_extent_range(handle, tmp_inode,
564-
le32_to_cpu(i_data[EXT4_IND_BLOCK]),
565-
&blk_count, &lb);
536+
le32_to_cpu(i_data[EXT4_IND_BLOCK]), &lb);
566537
if (retval)
567538
goto err_out;
568539
} else
569-
blk_count += max_entries;
540+
lb.curr_block += max_entries;
570541
if (i_data[EXT4_DIND_BLOCK]) {
571542
retval = update_dind_extent_range(handle, tmp_inode,
572-
le32_to_cpu(i_data[EXT4_DIND_BLOCK]),
573-
&blk_count, &lb);
543+
le32_to_cpu(i_data[EXT4_DIND_BLOCK]), &lb);
574544
if (retval)
575545
goto err_out;
576546
} else
577-
blk_count += max_entries * max_entries;
547+
lb.curr_block += max_entries * max_entries;
578548
if (i_data[EXT4_TIND_BLOCK]) {
579549
retval = update_tind_extent_range(handle, tmp_inode,
580-
le32_to_cpu(i_data[EXT4_TIND_BLOCK]),
581-
&blk_count, &lb);
550+
le32_to_cpu(i_data[EXT4_TIND_BLOCK]), &lb);
582551
if (retval)
583552
goto err_out;
584553
}

0 commit comments

Comments
 (0)