aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYongqiang Yang <xiaoqiangnk@gmail.com>2011-07-26 22:24:41 -0400
committerTheodore Ts'o <tytso@mit.edu>2011-07-26 22:24:41 -0400
commit6d40bc5a7e8fc71795d131e835f38f161ed7e1b1 (patch)
treed66d509a10509bc09d8dc0ecdc4641b585c1bfa0
parentc3e94d1df9bdd9e2c4ba7e8f534f7925f1756f97 (diff)
ext4: simplify journal handling in setup_new_group_blocks()
This patch simplifies journal handling in setup_new_group_blocks(). In previous code, block bitmap is modified everywhere in setup_new_group_blocks(), ext4_get_write_access() in extend_or_restart_transaction() is used to guarantee that the block bitmap stays in the new handle, this makes things complicated. The previous commit changed things so that the modifications on the block bitmap are batched and done by ext4_set_bits() at the end of the for loop. This allows us to simplify things. Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--fs/ext4/resize.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 178fb2f11c3f..5b423f89efda 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -161,8 +161,7 @@ static struct buffer_head *bclean(handle_t *handle, struct super_block *sb,
161 * If that fails, restart the transaction & regain write access for the 161 * If that fails, restart the transaction & regain write access for the
162 * buffer head which is used for block_bitmap modifications. 162 * buffer head which is used for block_bitmap modifications.
163 */ 163 */
164static int extend_or_restart_transaction(handle_t *handle, int thresh, 164static int extend_or_restart_transaction(handle_t *handle, int thresh)
165 struct buffer_head *bh)
166{ 165{
167 int err; 166 int err;
168 167
@@ -173,9 +172,8 @@ static int extend_or_restart_transaction(handle_t *handle, int thresh,
173 if (err < 0) 172 if (err < 0)
174 return err; 173 return err;
175 if (err) { 174 if (err) {
176 if ((err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA))) 175 err = ext4_journal_restart(handle, EXT4_MAX_TRANS_DATA);
177 return err; 176 if (err)
178 if ((err = ext4_journal_get_write_access(handle, bh)))
179 return err; 177 return err;
180 } 178 }
181 179
@@ -212,29 +210,24 @@ static int setup_new_group_blocks(struct super_block *sb,
212 210
213 BUG_ON(input->group != sbi->s_groups_count); 211 BUG_ON(input->group != sbi->s_groups_count);
214 212
215 if (IS_ERR(bh = bclean(handle, sb, input->block_bitmap))) {
216 err = PTR_ERR(bh);
217 goto exit_journal;
218 }
219
220 /* Copy all of the GDT blocks into the backup in this group */ 213 /* Copy all of the GDT blocks into the backup in this group */
221 for (i = 0, bit = 1, block = start + 1; 214 for (i = 0, bit = 1, block = start + 1;
222 i < gdblocks; i++, block++, bit++) { 215 i < gdblocks; i++, block++, bit++) {
223 struct buffer_head *gdb; 216 struct buffer_head *gdb;
224 217
225 ext4_debug("update backup group %#04llx (+%d)\n", block, bit); 218 ext4_debug("update backup group %#04llx (+%d)\n", block, bit);
226 219 err = extend_or_restart_transaction(handle, 1);
227 if ((err = extend_or_restart_transaction(handle, 1, bh))) 220 if (err)
228 goto exit_bh; 221 goto exit_journal;
229 222
230 gdb = sb_getblk(sb, block); 223 gdb = sb_getblk(sb, block);
231 if (!gdb) { 224 if (!gdb) {
232 err = -EIO; 225 err = -EIO;
233 goto exit_bh; 226 goto exit_journal;
234 } 227 }
235 if ((err = ext4_journal_get_write_access(handle, gdb))) { 228 if ((err = ext4_journal_get_write_access(handle, gdb))) {
236 brelse(gdb); 229 brelse(gdb);
237 goto exit_bh; 230 goto exit_journal;
238 } 231 }
239 lock_buffer(gdb); 232 lock_buffer(gdb);
240 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size); 233 memcpy(gdb->b_data, sbi->s_group_desc[i]->b_data, gdb->b_size);
@@ -243,7 +236,7 @@ static int setup_new_group_blocks(struct super_block *sb,
243 err = ext4_handle_dirty_metadata(handle, NULL, gdb); 236 err = ext4_handle_dirty_metadata(handle, NULL, gdb);
244 if (unlikely(err)) { 237 if (unlikely(err)) {
245 brelse(gdb); 238 brelse(gdb);
246 goto exit_bh; 239 goto exit_journal;
247 } 240 }
248 brelse(gdb); 241 brelse(gdb);
249 } 242 }
@@ -254,7 +247,17 @@ static int setup_new_group_blocks(struct super_block *sb,
254 err = sb_issue_zeroout(sb, gdblocks + start + 1, reserved_gdb, 247 err = sb_issue_zeroout(sb, gdblocks + start + 1, reserved_gdb,
255 GFP_NOFS); 248 GFP_NOFS);
256 if (err) 249 if (err)
257 goto exit_bh; 250 goto exit_journal;
251
252 err = extend_or_restart_transaction(handle, 2);
253 if (err)
254 goto exit_journal;
255
256 bh = bclean(handle, sb, input->block_bitmap);
257 if (IS_ERR(bh)) {
258 err = PTR_ERR(bh);
259 goto exit_journal;
260 }
258 261
259 if (ext4_bg_has_super(sb, input->group)) { 262 if (ext4_bg_has_super(sb, input->group)) {
260 ext4_debug("mark backup group tables %#04llx (+0)\n", start); 263 ext4_debug("mark backup group tables %#04llx (+0)\n", start);
@@ -278,8 +281,6 @@ static int setup_new_group_blocks(struct super_block *sb,
278 ext4_set_bits(bh->b_data, input->inode_table - start, 281 ext4_set_bits(bh->b_data, input->inode_table - start,
279 sbi->s_itb_per_group); 282 sbi->s_itb_per_group);
280 283
281 if ((err = extend_or_restart_transaction(handle, 2, bh)))
282 goto exit_bh;
283 284
284 ext4_mark_bitmap_end(input->blocks_count, sb->s_blocksize * 8, 285 ext4_mark_bitmap_end(input->blocks_count, sb->s_blocksize * 8,
285 bh->b_data); 286 bh->b_data);