diff options
author | Dmitry Monakhov <dmonakhov@openvz.org> | 2011-10-29 09:03:00 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-10-29 09:03:00 -0400 |
commit | fba90ffee813e2425feb9a57c532b3d297af18c3 (patch) | |
tree | d208361cfec8a3a5a1bbebb90d7f50f6707d99ec /fs/ext4 | |
parent | 6cdbb0effc2f511ced23e46f2117e4b31d3d4a50 (diff) |
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>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/migrate.c | 101 |
1 files changed, 35 insertions, 66 deletions
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 6f07a06f2437..8a9a0912fdae 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c | |||
@@ -20,13 +20,13 @@ | |||
20 | * The contiguous blocks details which can be | 20 | * The contiguous blocks details which can be |
21 | * represented by a single extent | 21 | * represented by a single extent |
22 | */ | 22 | */ |
23 | struct list_blocks_struct { | 23 | struct migrate_struct { |
24 | ext4_lblk_t first_block, last_block; | 24 | ext4_lblk_t first_block, last_block, curr_block; |
25 | ext4_fsblk_t first_pblock, last_pblock; | 25 | ext4_fsblk_t first_pblock, last_pblock; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | static int finish_range(handle_t *handle, struct inode *inode, | 28 | static int finish_range(handle_t *handle, struct inode *inode, |
29 | struct list_blocks_struct *lb) | 29 | struct migrate_struct *lb) |
30 | 30 | ||
31 | { | 31 | { |
32 | int retval = 0, needed; | 32 | int retval = 0, needed; |
@@ -86,8 +86,7 @@ err_out: | |||
86 | } | 86 | } |
87 | 87 | ||
88 | static int update_extent_range(handle_t *handle, struct inode *inode, | 88 | static int update_extent_range(handle_t *handle, struct inode *inode, |
89 | ext4_fsblk_t pblock, ext4_lblk_t blk_num, | 89 | ext4_fsblk_t pblock, struct migrate_struct *lb) |
90 | struct list_blocks_struct *lb) | ||
91 | { | 90 | { |
92 | int retval; | 91 | int retval; |
93 | /* | 92 | /* |
@@ -95,9 +94,10 @@ static int update_extent_range(handle_t *handle, struct inode *inode, | |||
95 | */ | 94 | */ |
96 | if (lb->first_pblock && | 95 | if (lb->first_pblock && |
97 | (lb->last_pblock+1 == pblock) && | 96 | (lb->last_pblock+1 == pblock) && |
98 | (lb->last_block+1 == blk_num)) { | 97 | (lb->last_block+1 == lb->curr_block)) { |
99 | lb->last_pblock = pblock; | 98 | lb->last_pblock = pblock; |
100 | lb->last_block = blk_num; | 99 | lb->last_block = lb->curr_block; |
100 | lb->curr_block++; | ||
101 | return 0; | 101 | return 0; |
102 | } | 102 | } |
103 | /* | 103 | /* |
@@ -105,64 +105,49 @@ static int update_extent_range(handle_t *handle, struct inode *inode, | |||
105 | */ | 105 | */ |
106 | retval = finish_range(handle, inode, lb); | 106 | retval = finish_range(handle, inode, lb); |
107 | lb->first_pblock = lb->last_pblock = pblock; | 107 | lb->first_pblock = lb->last_pblock = pblock; |
108 | lb->first_block = lb->last_block = blk_num; | 108 | lb->first_block = lb->last_block = lb->curr_block; |
109 | 109 | lb->curr_block++; | |
110 | return retval; | 110 | return retval; |
111 | } | 111 | } |
112 | 112 | ||
113 | static int update_ind_extent_range(handle_t *handle, struct inode *inode, | 113 | static int update_ind_extent_range(handle_t *handle, struct inode *inode, |
114 | ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, | 114 | ext4_fsblk_t pblock, |
115 | struct list_blocks_struct *lb) | 115 | struct migrate_struct *lb) |
116 | { | 116 | { |
117 | struct buffer_head *bh; | 117 | struct buffer_head *bh; |
118 | __le32 *i_data; | 118 | __le32 *i_data; |
119 | int i, retval = 0; | 119 | int i, retval = 0; |
120 | ext4_lblk_t blk_count = *blk_nump; | ||
121 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; | 120 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; |
122 | 121 | ||
123 | if (!pblock) { | ||
124 | /* Only update the file block number */ | ||
125 | *blk_nump += max_entries; | ||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | bh = sb_bread(inode->i_sb, pblock); | 122 | bh = sb_bread(inode->i_sb, pblock); |
130 | if (!bh) | 123 | if (!bh) |
131 | return -EIO; | 124 | return -EIO; |
132 | 125 | ||
133 | i_data = (__le32 *)bh->b_data; | 126 | i_data = (__le32 *)bh->b_data; |
134 | for (i = 0; i < max_entries; i++, blk_count++) { | 127 | for (i = 0; i < max_entries; i++) { |
135 | if (i_data[i]) { | 128 | if (i_data[i]) { |
136 | retval = update_extent_range(handle, inode, | 129 | retval = update_extent_range(handle, inode, |
137 | le32_to_cpu(i_data[i]), | 130 | le32_to_cpu(i_data[i]), lb); |
138 | blk_count, lb); | ||
139 | if (retval) | 131 | if (retval) |
140 | break; | 132 | break; |
133 | } else { | ||
134 | lb->curr_block++; | ||
141 | } | 135 | } |
142 | } | 136 | } |
143 | |||
144 | /* Update the file block number */ | ||
145 | *blk_nump = blk_count; | ||
146 | put_bh(bh); | 137 | put_bh(bh); |
147 | return retval; | 138 | return retval; |
148 | 139 | ||
149 | } | 140 | } |
150 | 141 | ||
151 | static int update_dind_extent_range(handle_t *handle, struct inode *inode, | 142 | static int update_dind_extent_range(handle_t *handle, struct inode *inode, |
152 | ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, | 143 | ext4_fsblk_t pblock, |
153 | struct list_blocks_struct *lb) | 144 | struct migrate_struct *lb) |
154 | { | 145 | { |
155 | struct buffer_head *bh; | 146 | struct buffer_head *bh; |
156 | __le32 *i_data; | 147 | __le32 *i_data; |
157 | int i, retval = 0; | 148 | int i, retval = 0; |
158 | ext4_lblk_t blk_count = *blk_nump; | ||
159 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; | 149 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; |
160 | 150 | ||
161 | if (!pblock) { | ||
162 | /* Only update the file block number */ | ||
163 | *blk_nump += max_entries * max_entries; | ||
164 | return 0; | ||
165 | } | ||
166 | bh = sb_bread(inode->i_sb, pblock); | 151 | bh = sb_bread(inode->i_sb, pblock); |
167 | if (!bh) | 152 | if (!bh) |
168 | return -EIO; | 153 | return -EIO; |
@@ -171,38 +156,28 @@ static int update_dind_extent_range(handle_t *handle, struct inode *inode, | |||
171 | for (i = 0; i < max_entries; i++) { | 156 | for (i = 0; i < max_entries; i++) { |
172 | if (i_data[i]) { | 157 | if (i_data[i]) { |
173 | retval = update_ind_extent_range(handle, inode, | 158 | retval = update_ind_extent_range(handle, inode, |
174 | le32_to_cpu(i_data[i]), | 159 | le32_to_cpu(i_data[i]), lb); |
175 | &blk_count, lb); | ||
176 | if (retval) | 160 | if (retval) |
177 | break; | 161 | break; |
178 | } else { | 162 | } else { |
179 | /* Only update the file block number */ | 163 | /* Only update the file block number */ |
180 | blk_count += max_entries; | 164 | lb->curr_block += max_entries; |
181 | } | 165 | } |
182 | } | 166 | } |
183 | |||
184 | /* Update the file block number */ | ||
185 | *blk_nump = blk_count; | ||
186 | put_bh(bh); | 167 | put_bh(bh); |
187 | return retval; | 168 | return retval; |
188 | 169 | ||
189 | } | 170 | } |
190 | 171 | ||
191 | static int update_tind_extent_range(handle_t *handle, struct inode *inode, | 172 | static int update_tind_extent_range(handle_t *handle, struct inode *inode, |
192 | ext4_fsblk_t pblock, ext4_lblk_t *blk_nump, | 173 | ext4_fsblk_t pblock, |
193 | struct list_blocks_struct *lb) | 174 | struct migrate_struct *lb) |
194 | { | 175 | { |
195 | struct buffer_head *bh; | 176 | struct buffer_head *bh; |
196 | __le32 *i_data; | 177 | __le32 *i_data; |
197 | int i, retval = 0; | 178 | int i, retval = 0; |
198 | ext4_lblk_t blk_count = *blk_nump; | ||
199 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; | 179 | unsigned long max_entries = inode->i_sb->s_blocksize >> 2; |
200 | 180 | ||
201 | if (!pblock) { | ||
202 | /* Only update the file block number */ | ||
203 | *blk_nump += max_entries * max_entries * max_entries; | ||
204 | return 0; | ||
205 | } | ||
206 | bh = sb_bread(inode->i_sb, pblock); | 181 | bh = sb_bread(inode->i_sb, pblock); |
207 | if (!bh) | 182 | if (!bh) |
208 | return -EIO; | 183 | return -EIO; |
@@ -211,16 +186,14 @@ static int update_tind_extent_range(handle_t *handle, struct inode *inode, | |||
211 | for (i = 0; i < max_entries; i++) { | 186 | for (i = 0; i < max_entries; i++) { |
212 | if (i_data[i]) { | 187 | if (i_data[i]) { |
213 | retval = update_dind_extent_range(handle, inode, | 188 | retval = update_dind_extent_range(handle, inode, |
214 | le32_to_cpu(i_data[i]), | 189 | le32_to_cpu(i_data[i]), lb); |
215 | &blk_count, lb); | ||
216 | if (retval) | 190 | if (retval) |
217 | break; | 191 | break; |
218 | } else | 192 | } else { |
219 | /* Only update the file block number */ | 193 | /* Only update the file block number */ |
220 | blk_count += max_entries * max_entries; | 194 | lb->curr_block += max_entries * max_entries; |
195 | } | ||
221 | } | 196 | } |
222 | /* Update the file block number */ | ||
223 | *blk_nump = blk_count; | ||
224 | put_bh(bh); | 197 | put_bh(bh); |
225 | return retval; | 198 | return retval; |
226 | 199 | ||
@@ -461,10 +434,9 @@ int ext4_ext_migrate(struct inode *inode) | |||
461 | handle_t *handle; | 434 | handle_t *handle; |
462 | int retval = 0, i; | 435 | int retval = 0, i; |
463 | __le32 *i_data; | 436 | __le32 *i_data; |
464 | ext4_lblk_t blk_count = 0; | ||
465 | struct ext4_inode_info *ei; | 437 | struct ext4_inode_info *ei; |
466 | struct inode *tmp_inode = NULL; | 438 | struct inode *tmp_inode = NULL; |
467 | struct list_blocks_struct lb; | 439 | struct migrate_struct lb; |
468 | unsigned long max_entries; | 440 | unsigned long max_entries; |
469 | __u32 goal; | 441 | __u32 goal; |
470 | 442 | ||
@@ -550,35 +522,32 @@ int ext4_ext_migrate(struct inode *inode) | |||
550 | 522 | ||
551 | /* 32 bit block address 4 bytes */ | 523 | /* 32 bit block address 4 bytes */ |
552 | max_entries = inode->i_sb->s_blocksize >> 2; | 524 | 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++) { |
554 | if (i_data[i]) { | 526 | if (i_data[i]) { |
555 | retval = update_extent_range(handle, tmp_inode, | 527 | retval = update_extent_range(handle, tmp_inode, |
556 | le32_to_cpu(i_data[i]), | 528 | le32_to_cpu(i_data[i]), &lb); |
557 | blk_count, &lb); | ||
558 | if (retval) | 529 | if (retval) |
559 | goto err_out; | 530 | goto err_out; |
560 | } | 531 | } else |
532 | lb.curr_block++; | ||
561 | } | 533 | } |
562 | if (i_data[EXT4_IND_BLOCK]) { | 534 | if (i_data[EXT4_IND_BLOCK]) { |
563 | retval = update_ind_extent_range(handle, tmp_inode, | 535 | retval = update_ind_extent_range(handle, tmp_inode, |
564 | le32_to_cpu(i_data[EXT4_IND_BLOCK]), | 536 | le32_to_cpu(i_data[EXT4_IND_BLOCK]), &lb); |
565 | &blk_count, &lb); | ||
566 | if (retval) | 537 | if (retval) |
567 | goto err_out; | 538 | goto err_out; |
568 | } else | 539 | } else |
569 | blk_count += max_entries; | 540 | lb.curr_block += max_entries; |
570 | if (i_data[EXT4_DIND_BLOCK]) { | 541 | if (i_data[EXT4_DIND_BLOCK]) { |
571 | retval = update_dind_extent_range(handle, tmp_inode, | 542 | retval = update_dind_extent_range(handle, tmp_inode, |
572 | le32_to_cpu(i_data[EXT4_DIND_BLOCK]), | 543 | le32_to_cpu(i_data[EXT4_DIND_BLOCK]), &lb); |
573 | &blk_count, &lb); | ||
574 | if (retval) | 544 | if (retval) |
575 | goto err_out; | 545 | goto err_out; |
576 | } else | 546 | } else |
577 | blk_count += max_entries * max_entries; | 547 | lb.curr_block += max_entries * max_entries; |
578 | if (i_data[EXT4_TIND_BLOCK]) { | 548 | if (i_data[EXT4_TIND_BLOCK]) { |
579 | retval = update_tind_extent_range(handle, tmp_inode, | 549 | retval = update_tind_extent_range(handle, tmp_inode, |
580 | le32_to_cpu(i_data[EXT4_TIND_BLOCK]), | 550 | le32_to_cpu(i_data[EXT4_TIND_BLOCK]), &lb); |
581 | &blk_count, &lb); | ||
582 | if (retval) | 551 | if (retval) |
583 | goto err_out; | 552 | goto err_out; |
584 | } | 553 | } |