diff options
Diffstat (limited to 'fs/ext4/migrate.c')
-rw-r--r-- | fs/ext4/migrate.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index a93d5b80f3e2..34dcfc52ef44 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c | |||
@@ -13,6 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/slab.h> | ||
16 | #include "ext4_jbd2.h" | 17 | #include "ext4_jbd2.h" |
17 | #include "ext4_extents.h" | 18 | #include "ext4_extents.h" |
18 | 19 | ||
@@ -238,7 +239,7 @@ static int extend_credit_for_blkdel(handle_t *handle, struct inode *inode) | |||
238 | * So allocate a credit of 3. We may update | 239 | * So allocate a credit of 3. We may update |
239 | * quota (user and group). | 240 | * quota (user and group). |
240 | */ | 241 | */ |
241 | needed = 3 + 2*EXT4_QUOTA_TRANS_BLOCKS(inode->i_sb); | 242 | needed = 3 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); |
242 | 243 | ||
243 | if (ext4_journal_extend(handle, needed) != 0) | 244 | if (ext4_journal_extend(handle, needed) != 0) |
244 | retval = ext4_journal_restart(handle, needed); | 245 | retval = ext4_journal_restart(handle, needed); |
@@ -262,13 +263,17 @@ static int free_dind_blocks(handle_t *handle, | |||
262 | for (i = 0; i < max_entries; i++) { | 263 | for (i = 0; i < max_entries; i++) { |
263 | if (tmp_idata[i]) { | 264 | if (tmp_idata[i]) { |
264 | extend_credit_for_blkdel(handle, inode); | 265 | extend_credit_for_blkdel(handle, inode); |
265 | ext4_free_blocks(handle, inode, | 266 | ext4_free_blocks(handle, inode, 0, |
266 | le32_to_cpu(tmp_idata[i]), 1, 1); | 267 | le32_to_cpu(tmp_idata[i]), 1, |
268 | EXT4_FREE_BLOCKS_METADATA | | ||
269 | EXT4_FREE_BLOCKS_FORGET); | ||
267 | } | 270 | } |
268 | } | 271 | } |
269 | put_bh(bh); | 272 | put_bh(bh); |
270 | extend_credit_for_blkdel(handle, inode); | 273 | extend_credit_for_blkdel(handle, inode); |
271 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); | 274 | ext4_free_blocks(handle, inode, 0, le32_to_cpu(i_data), 1, |
275 | EXT4_FREE_BLOCKS_METADATA | | ||
276 | EXT4_FREE_BLOCKS_FORGET); | ||
272 | return 0; | 277 | return 0; |
273 | } | 278 | } |
274 | 279 | ||
@@ -297,7 +302,9 @@ static int free_tind_blocks(handle_t *handle, | |||
297 | } | 302 | } |
298 | put_bh(bh); | 303 | put_bh(bh); |
299 | extend_credit_for_blkdel(handle, inode); | 304 | extend_credit_for_blkdel(handle, inode); |
300 | ext4_free_blocks(handle, inode, le32_to_cpu(i_data), 1, 1); | 305 | ext4_free_blocks(handle, inode, 0, le32_to_cpu(i_data), 1, |
306 | EXT4_FREE_BLOCKS_METADATA | | ||
307 | EXT4_FREE_BLOCKS_FORGET); | ||
301 | return 0; | 308 | return 0; |
302 | } | 309 | } |
303 | 310 | ||
@@ -308,8 +315,10 @@ static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data) | |||
308 | /* ei->i_data[EXT4_IND_BLOCK] */ | 315 | /* ei->i_data[EXT4_IND_BLOCK] */ |
309 | if (i_data[0]) { | 316 | if (i_data[0]) { |
310 | extend_credit_for_blkdel(handle, inode); | 317 | extend_credit_for_blkdel(handle, inode); |
311 | ext4_free_blocks(handle, inode, | 318 | ext4_free_blocks(handle, inode, 0, |
312 | le32_to_cpu(i_data[0]), 1, 1); | 319 | le32_to_cpu(i_data[0]), 1, |
320 | EXT4_FREE_BLOCKS_METADATA | | ||
321 | EXT4_FREE_BLOCKS_FORGET); | ||
313 | } | 322 | } |
314 | 323 | ||
315 | /* ei->i_data[EXT4_DIND_BLOCK] */ | 324 | /* ei->i_data[EXT4_DIND_BLOCK] */ |
@@ -357,12 +366,12 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, | |||
357 | * happened after we started the migrate. We need to | 366 | * happened after we started the migrate. We need to |
358 | * fail the migrate | 367 | * fail the migrate |
359 | */ | 368 | */ |
360 | if (!(EXT4_I(inode)->i_state & EXT4_STATE_EXT_MIGRATE)) { | 369 | if (!ext4_test_inode_state(inode, EXT4_STATE_EXT_MIGRATE)) { |
361 | retval = -EAGAIN; | 370 | retval = -EAGAIN; |
362 | up_write(&EXT4_I(inode)->i_data_sem); | 371 | up_write(&EXT4_I(inode)->i_data_sem); |
363 | goto err_out; | 372 | goto err_out; |
364 | } else | 373 | } else |
365 | EXT4_I(inode)->i_state &= ~EXT4_STATE_EXT_MIGRATE; | 374 | ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE); |
366 | /* | 375 | /* |
367 | * We have the extent map build with the tmp inode. | 376 | * We have the extent map build with the tmp inode. |
368 | * Now copy the i_data across | 377 | * Now copy the i_data across |
@@ -419,7 +428,8 @@ static int free_ext_idx(handle_t *handle, struct inode *inode, | |||
419 | } | 428 | } |
420 | put_bh(bh); | 429 | put_bh(bh); |
421 | extend_credit_for_blkdel(handle, inode); | 430 | extend_credit_for_blkdel(handle, inode); |
422 | ext4_free_blocks(handle, inode, block, 1, 1); | 431 | ext4_free_blocks(handle, inode, 0, block, 1, |
432 | EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET); | ||
423 | return retval; | 433 | return retval; |
424 | } | 434 | } |
425 | 435 | ||
@@ -477,7 +487,7 @@ int ext4_ext_migrate(struct inode *inode) | |||
477 | handle = ext4_journal_start(inode, | 487 | handle = ext4_journal_start(inode, |
478 | EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + | 488 | EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + |
479 | EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + | 489 | EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 + |
480 | 2 * EXT4_QUOTA_INIT_BLOCKS(inode->i_sb) | 490 | EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) |
481 | + 1); | 491 | + 1); |
482 | if (IS_ERR(handle)) { | 492 | if (IS_ERR(handle)) { |
483 | retval = PTR_ERR(handle); | 493 | retval = PTR_ERR(handle); |
@@ -494,14 +504,10 @@ int ext4_ext_migrate(struct inode *inode) | |||
494 | } | 504 | } |
495 | i_size_write(tmp_inode, i_size_read(inode)); | 505 | i_size_write(tmp_inode, i_size_read(inode)); |
496 | /* | 506 | /* |
497 | * We don't want the inode to be reclaimed | 507 | * Set the i_nlink to zero so it will be deleted later |
498 | * if we got interrupted in between. We have | 508 | * when we drop inode reference. |
499 | * this tmp inode carrying reference to the | ||
500 | * data blocks of the original file. We set | ||
501 | * the i_nlink to zero at the last stage after | ||
502 | * switching the original file to extent format | ||
503 | */ | 509 | */ |
504 | tmp_inode->i_nlink = 1; | 510 | tmp_inode->i_nlink = 0; |
505 | 511 | ||
506 | ext4_ext_tree_init(handle, tmp_inode); | 512 | ext4_ext_tree_init(handle, tmp_inode); |
507 | ext4_orphan_add(handle, tmp_inode); | 513 | ext4_orphan_add(handle, tmp_inode); |
@@ -524,10 +530,20 @@ int ext4_ext_migrate(struct inode *inode) | |||
524 | * allocation. | 530 | * allocation. |
525 | */ | 531 | */ |
526 | down_read((&EXT4_I(inode)->i_data_sem)); | 532 | down_read((&EXT4_I(inode)->i_data_sem)); |
527 | EXT4_I(inode)->i_state |= EXT4_STATE_EXT_MIGRATE; | 533 | ext4_set_inode_state(inode, EXT4_STATE_EXT_MIGRATE); |
528 | up_read((&EXT4_I(inode)->i_data_sem)); | 534 | up_read((&EXT4_I(inode)->i_data_sem)); |
529 | 535 | ||
530 | handle = ext4_journal_start(inode, 1); | 536 | handle = ext4_journal_start(inode, 1); |
537 | if (IS_ERR(handle)) { | ||
538 | /* | ||
539 | * It is impossible to update on-disk structures without | ||
540 | * a handle, so just rollback in-core changes and live other | ||
541 | * work to orphan_list_cleanup() | ||
542 | */ | ||
543 | ext4_orphan_del(NULL, tmp_inode); | ||
544 | retval = PTR_ERR(handle); | ||
545 | goto out; | ||
546 | } | ||
531 | 547 | ||
532 | ei = EXT4_I(inode); | 548 | ei = EXT4_I(inode); |
533 | i_data = ei->i_data; | 549 | i_data = ei->i_data; |
@@ -609,15 +625,8 @@ err_out: | |||
609 | 625 | ||
610 | /* Reset the extent details */ | 626 | /* Reset the extent details */ |
611 | ext4_ext_tree_init(handle, tmp_inode); | 627 | ext4_ext_tree_init(handle, tmp_inode); |
612 | |||
613 | /* | ||
614 | * Set the i_nlink to zero so that | ||
615 | * generic_drop_inode really deletes the | ||
616 | * inode | ||
617 | */ | ||
618 | tmp_inode->i_nlink = 0; | ||
619 | |||
620 | ext4_journal_stop(handle); | 628 | ext4_journal_stop(handle); |
629 | out: | ||
621 | unlock_new_inode(tmp_inode); | 630 | unlock_new_inode(tmp_inode); |
622 | iput(tmp_inode); | 631 | iput(tmp_inode); |
623 | 632 | ||