diff mbox

[v2] iomap: fsync swap files before iterating mappings

Message ID 20180605163304.GH9437@magnolia (mailing list archive)
State New, archived
Headers show

Commit Message

Darrick J. Wong June 5, 2018, 4:33 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
v2: fdatasync semantics, per hch feedback
---
 fs/iomap.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Christoph Hellwig June 5, 2018, 4:45 p.m. UTC | #1
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
Jan Kara June 6, 2018, 12:43 p.m. UTC | #2
On Tue 05-06-18 09:33:04, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> 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>

Makes sense and the patch looks good to me. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> v2: fdatasync semantics, per hch feedback
> ---
>  fs/iomap.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/iomap.c b/fs/iomap.c
> index 206539d369a8..2bd04f0451f2 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -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;
>
diff mbox

Patch

diff --git a/fs/iomap.c b/fs/iomap.c
index 206539d369a8..2bd04f0451f2 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -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;