Skip to content

Commit 7a34997

Browse files
yangerkungregkh
yangerkun
authored andcommitted
ext4: cleanup pagecache before swap i_data
commit a46c68a upstream. While do swap, we should make sure there has no new dirty page since we should swap i_data between two inode: 1.We should lock i_mmap_sem with write to avoid new pagecache from mmap read/write; 2.Change filemap_flush to filemap_write_and_wait and move them to the space protected by inode lock to avoid new pagecache from buffer read/write. Signed-off-by: yangerkun <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a0f6f65 commit 7a34997

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

fs/ext4/ioctl.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ static long swap_inode_boot_loader(struct super_block *sb,
121121
return PTR_ERR(inode_bl);
122122
ei_bl = EXT4_I(inode_bl);
123123

124-
filemap_flush(inode->i_mapping);
125-
filemap_flush(inode_bl->i_mapping);
126-
127124
/* Protect orig inodes against a truncate and make sure,
128125
* that only 1 swap_inode_boot_loader is running. */
129126
lock_two_nondirectories(inode, inode_bl);
@@ -141,6 +138,15 @@ static long swap_inode_boot_loader(struct super_block *sb,
141138
goto journal_err_out;
142139
}
143140

141+
down_write(&EXT4_I(inode)->i_mmap_sem);
142+
err = filemap_write_and_wait(inode->i_mapping);
143+
if (err)
144+
goto err_out;
145+
146+
err = filemap_write_and_wait(inode_bl->i_mapping);
147+
if (err)
148+
goto err_out;
149+
144150
/* Wait for all existing dio workers */
145151
inode_dio_wait(inode);
146152
inode_dio_wait(inode_bl);
@@ -151,7 +157,7 @@ static long swap_inode_boot_loader(struct super_block *sb,
151157
handle = ext4_journal_start(inode_bl, EXT4_HT_MOVE_EXTENTS, 2);
152158
if (IS_ERR(handle)) {
153159
err = -EINVAL;
154-
goto journal_err_out;
160+
goto err_out;
155161
}
156162

157163
/* Protect extent tree against block allocations via delalloc */
@@ -208,6 +214,8 @@ static long swap_inode_boot_loader(struct super_block *sb,
208214
ext4_journal_stop(handle);
209215
ext4_double_up_write_data_sem(inode, inode_bl);
210216

217+
err_out:
218+
up_write(&EXT4_I(inode)->i_mmap_sem);
211219
journal_err_out:
212220
unlock_two_nondirectories(inode, inode_bl);
213221
iput(inode_bl);

0 commit comments

Comments
 (0)