Skip to content

Commit f39490b

Browse files
Dmitry Monakhovtytso
authored andcommitted
ext4: fix error handling in migrate
Set i_nlink to zero for temporary inode from very beginning. otherwise we may fail to start new journal handle and this inode will be unreferenced but with i_nlink == 1 Since we hold inode reference it can not be pruned. Also add missed journal_start retval check. Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 437ca0f commit f39490b

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

‎fs/ext4/migrate.c‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,10 @@ int ext4_ext_migrate(struct inode *inode)
503503
}
504504
i_size_write(tmp_inode, i_size_read(inode));
505505
/*
506-
* We don't want the inode to be reclaimed
507-
* if we got interrupted in between. We have
508-
* this tmp inode carrying reference to the
509-
* data blocks of the original file. We set
510-
* the i_nlink to zero at the last stage after
511-
* switching the original file to extent format
506+
* Set the i_nlink to zero so it will be deleted later
507+
* when we drop inode reference.
512508
*/
513-
tmp_inode->i_nlink = 1;
509+
tmp_inode->i_nlink = 0;
514510

515511
ext4_ext_tree_init(handle, tmp_inode);
516512
ext4_orphan_add(handle, tmp_inode);
@@ -537,6 +533,16 @@ int ext4_ext_migrate(struct inode *inode)
537533
up_read((&EXT4_I(inode)->i_data_sem));
538534

539535
handle = ext4_journal_start(inode, 1);
536+
if (IS_ERR(handle)) {
537+
/*
538+
* It is impossible to update on-disk structures without
539+
* a handle, so just rollback in-core changes and live other
540+
* work to orphan_list_cleanup()
541+
*/
542+
ext4_orphan_del(NULL, tmp_inode);
543+
retval = PTR_ERR(handle);
544+
goto out;
545+
}
540546

541547
ei = EXT4_I(inode);
542548
i_data = ei->i_data;
@@ -618,15 +624,8 @@ int ext4_ext_migrate(struct inode *inode)
618624

619625
/* Reset the extent details */
620626
ext4_ext_tree_init(handle, tmp_inode);
621-
622-
/*
623-
* Set the i_nlink to zero so that
624-
* generic_drop_inode really deletes the
625-
* inode
626-
*/
627-
tmp_inode->i_nlink = 0;
628-
629627
ext4_journal_stop(handle);
628+
out:
630629
unlock_new_inode(tmp_inode);
631630
iput(tmp_inode);
632631

0 commit comments

Comments
 (0)