1 From a46c68a318b08f819047843abf349aeee5d10ac2 Mon Sep 17 00:00:00 2001
2 From: yangerkun <yangerkun@huawei.com>
3 Date: Mon, 11 Feb 2019 00:05:24 -0500
4 Subject: ext4: cleanup pagecache before swap i_data
6 From: yangerkun <yangerkun@huawei.com>
8 commit a46c68a318b08f819047843abf349aeee5d10ac2 upstream.
10 While do swap, we should make sure there has no new dirty page since we
11 should swap i_data between two inode:
12 1.We should lock i_mmap_sem with write to avoid new pagecache from mmap
14 2.Change filemap_flush to filemap_write_and_wait and move them to the
15 space protected by inode lock to avoid new pagecache from buffer read/write.
17 Signed-off-by: yangerkun <yangerkun@huawei.com>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 fs/ext4/ioctl.c | 16 ++++++++++++----
24 1 file changed, 12 insertions(+), 4 deletions(-)
28 @@ -121,9 +121,6 @@ static long swap_inode_boot_loader(struc
29 return PTR_ERR(inode_bl);
30 ei_bl = EXT4_I(inode_bl);
32 - filemap_flush(inode->i_mapping);
33 - filemap_flush(inode_bl->i_mapping);
35 /* Protect orig inodes against a truncate and make sure,
36 * that only 1 swap_inode_boot_loader is running. */
37 lock_two_nondirectories(inode, inode_bl);
38 @@ -141,6 +138,15 @@ static long swap_inode_boot_loader(struc
42 + down_write(&EXT4_I(inode)->i_mmap_sem);
43 + err = filemap_write_and_wait(inode->i_mapping);
47 + err = filemap_write_and_wait(inode_bl->i_mapping);
51 /* Wait for all existing dio workers */
52 inode_dio_wait(inode);
53 inode_dio_wait(inode_bl);
54 @@ -151,7 +157,7 @@ static long swap_inode_boot_loader(struc
55 handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
58 - goto journal_err_out;
62 /* Protect extent tree against block allocations via delalloc */
63 @@ -208,6 +214,8 @@ static long swap_inode_boot_loader(struc
64 ext4_journal_stop(handle);
65 ext4_double_up_write_data_sem(inode, inode_bl);
68 + up_write(&EXT4_I(inode)->i_mmap_sem);
70 unlock_two_nondirectories(inode, inode_bl);