1 ext4: cleanup pagecache before swap i_data
3 From: yangerkun <yangerkun@huawei.com>
5 While do swap, we should make sure there has no new dirty page since we
6 should swap i_data between two inode:
7 1.We should lock i_mmap_sem with write to avoid new pagecache from mmap
9 2.Change filemap_flush to filemap_write_and_wait and move them to the
10 space protected by inode lock to avoid new pagecache from buffer read/write.
12 Signed-off-by: yangerkun <yangerkun@huawei.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 fs/ext4/ioctl.c | 16 ++++++++++++----
17 1 file changed, 12 insertions(+), 4 deletions(-)
19 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
20 index 597e8b6..ea05e8d 100644
23 @@ -121,9 +121,6 @@ static long swap_inode_boot_loader(struct super_block *sb,
24 return PTR_ERR(inode_bl);
25 ei_bl = EXT4_I(inode_bl);
27 - filemap_flush(inode->i_mapping);
28 - filemap_flush(inode_bl->i_mapping);
30 /* Protect orig inodes against a truncate and make sure,
31 * that only 1 swap_inode_boot_loader is running. */
32 lock_two_nondirectories(inode, inode_bl);
33 @@ -141,6 +138,15 @@ static long swap_inode_boot_loader(struct super_block *sb,
37 + down_write(&EXT4_I(inode)->i_mmap_sem);
38 + err = filemap_write_and_wait(inode->i_mapping);
42 + err = filemap_write_and_wait(inode_bl->i_mapping);
46 /* Wait for all existing dio workers */
47 inode_dio_wait(inode);
48 inode_dio_wait(inode_bl);
49 @@ -151,7 +157,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
50 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
53 - goto journal_err_out;
57 /* Protect extent tree against block allocations via delalloc */
58 @@ -208,6 +214,8 @@ static long swap_inode_boot_loader(struct super_block *sb,
59 ext4_journal_stop(handle);
60 ext4_double_up_write_data_sem(inode, inode_bl);
63 + up_write(&EXT4_I(inode)->i_mmap_sem);
65 unlock_two_nondirectories(inode, inode_bl);