Skip to content

Commit 6eeaf88

Browse files
committed
ext4: don't use the orphan list when migrating an inode
We probably want to remove the indirect block to extents migration feature after a deprecation window, but until then, let's fix a potential data loss problem caused by the fact that we put the tmp_inode on the orphan list. In the unlikely case where we crash and do a journal recovery, the data blocks belonging to the inode being migrated are also represented in the tmp_inode on the orphan list --- and so its data blocks will get marked unallocated, and available for reuse. Instead, stop putting the tmp_inode on the oprhan list. So in the case where we crash while migrating the inode, we'll leak an inode, which is not a disaster. It will be easily fixed the next time we run fsck, and it's better than potentially having blocks getting claimed by two different files, and losing data as a result. Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Lukas Czerner <lczerner@redhat.com> Cc: stable@kernel.org
1 parent a2e3965 commit 6eeaf88

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

fs/ext4/migrate.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@ int ext4_ext_migrate(struct inode *inode)
437437
percpu_down_write(&sbi->s_writepages_rwsem);
438438

439439
/*
440-
* Worst case we can touch the allocation bitmaps, a bgd
441-
* block, and a block to link in the orphan list. We do need
442-
* need to worry about credits for modifying the quota inode.
440+
* Worst case we can touch the allocation bitmaps and a block
441+
* group descriptor block. We do need need to worry about
442+
* credits for modifying the quota inode.
443443
*/
444444
handle = ext4_journal_start(inode, EXT4_HT_MIGRATE,
445-
4 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb));
445+
3 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb));
446446

447447
if (IS_ERR(handle)) {
448448
retval = PTR_ERR(handle);
@@ -463,10 +463,6 @@ int ext4_ext_migrate(struct inode *inode)
463463
* Use the correct seed for checksum (i.e. the seed from 'inode'). This
464464
* is so that the metadata blocks will have the correct checksum after
465465
* the migration.
466-
*
467-
* Note however that, if a crash occurs during the migration process,
468-
* the recovery process is broken because the tmp_inode checksums will
469-
* be wrong and the orphans cleanup will fail.
470466
*/
471467
ei = EXT4_I(inode);
472468
EXT4_I(tmp_inode)->i_csum_seed = ei->i_csum_seed;
@@ -478,7 +474,6 @@ int ext4_ext_migrate(struct inode *inode)
478474
clear_nlink(tmp_inode);
479475

480476
ext4_ext_tree_init(handle, tmp_inode);
481-
ext4_orphan_add(handle, tmp_inode);
482477
ext4_journal_stop(handle);
483478

484479
/*
@@ -503,12 +498,6 @@ int ext4_ext_migrate(struct inode *inode)
503498

504499
handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1);
505500
if (IS_ERR(handle)) {
506-
/*
507-
* It is impossible to update on-disk structures without
508-
* a handle, so just rollback in-core changes and live other
509-
* work to orphan_list_cleanup()
510-
*/
511-
ext4_orphan_del(NULL, tmp_inode);
512501
retval = PTR_ERR(handle);
513502
goto out_tmp_inode;
514503
}

0 commit comments

Comments
 (0)