Skip to contentSkip to conversation

iomap: fsync swap files before iterating mappings

PATCH Superseded Darrick J. Wong 2 participants 2 messages Jun 5, 2018 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: fsync swap files before iterating mappings

From: Darrick J. Wong <[email protected]>

Swap files require that all the file mapping metadata be stable on disk. It is insufficient to flush dirty pages in the page cache because that won't necessarily result in filesystems pushing all their metadata out to disk. Therefore, call fsync from iomap_swapfile_activate.

---
 fs/iomap.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/iomap.c +5 -1
index 206539d369a8..48622bbbd751 100644
@@ -1387,7 +1387,11 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
 	loff_t len = ALIGN_DOWN(i_size_read(inode), PAGE_SIZE);
 	loff_t ret;
 
-	ret = filemap_write_and_wait(inode->i_mapping);
+	/*
+	 * Persist all file mapping metadata so that we won't have any
+	 * IOMAP_F_DIRTY iomaps.
+	 */
+	ret = vfs_fsync(swap_file, 0);
 	if (ret)
 		return ret;
 
#1 lore raw
Quoted 17 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Swap files require that all the file mapping metadata be stable on disk. It is insufficient to flush dirty pages in the page cache because that won't necessarily result in filesystems pushing all their metadata out to disk. Therefore, call fsync from iomap_swapfile_activate.

---
 fs/iomap.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/iomap.c +0 -0
index 206539d369a8..48622bbbd751 100644

fs/iomap.c int iomap_swapfile_activate(struct swap_info_struct *sis, · line 1394

Quoted 9 lines
fs/iomap.c +5 -1
@@ -1387,7 +1387,11 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
 	loff_t len = ALIGN_DOWN(i_size_read(inode), PAGE_SIZE);
 	loff_t ret;
 
-	ret = filemap_write_and_wait(inode->i_mapping);
+	/*
+	 * Persist all file mapping metadata so that we won't have any
+	 * IOMAP_F_DIRTY iomaps.
+	 */
+	ret = vfs_fsync(swap_file, 0);

datasync semantics should be more than enough, so you can pass 1 here..