iomap: fsync swap files before iterating mappings
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 5 Jun 2018 16:53:05 +0000 (09:53 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Tue, 5 Jun 2018 16:53:05 +0000 (09:53 -0700)
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.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
fs/iomap.c

index 206539d..2bd04f0 100644 (file)
@@ -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, 1);
        if (ret)
                return ret;