]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/ext4-cleanup-pagecache-before-swap-i_data.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / queue-4.19 / ext4-cleanup-pagecache-before-swap-i_data.patch
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
5
6 From: yangerkun <yangerkun@huawei.com>
7
8 commit a46c68a318b08f819047843abf349aeee5d10ac2 upstream.
9
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
13 read/write;
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.
16
17 Signed-off-by: yangerkun <yangerkun@huawei.com>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 Cc: stable@kernel.org
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21
22 ---
23 fs/ext4/ioctl.c | 16 ++++++++++++----
24 1 file changed, 12 insertions(+), 4 deletions(-)
25
26 --- a/fs/ext4/ioctl.c
27 +++ b/fs/ext4/ioctl.c
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);
31
32 - filemap_flush(inode->i_mapping);
33 - filemap_flush(inode_bl->i_mapping);
34 -
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
39 goto journal_err_out;
40 }
41
42 + down_write(&EXT4_I(inode)->i_mmap_sem);
43 + err = filemap_write_and_wait(inode->i_mapping);
44 + if (err)
45 + goto err_out;
46 +
47 + err = filemap_write_and_wait(inode_bl->i_mapping);
48 + if (err)
49 + goto err_out;
50 +
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);
56 if (IS_ERR(handle)) {
57 err = -EINVAL;
58 - goto journal_err_out;
59 + goto err_out;
60 }
61
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);
66
67 +err_out:
68 + up_write(&EXT4_I(inode)->i_mmap_sem);
69 journal_err_out:
70 unlock_two_nondirectories(inode, inode_bl);
71 iput(inode_bl);