Commit 0929d858 authored by Dave Chinner's avatar Dave Chinner Committed by Darrick J. Wong

iomap: FUA is wrong for DIO O_DSYNC writes into unwritten extents

When we write into an unwritten extent via direct IO, we dirty
metadata on IO completion to convert the unwritten extent to
written. However, when we do the FUA optimisation checks, the inode
may be clean and so we issue a FUA write into the unwritten extent.
This means we then bypass the generic_write_sync() call after
unwritten extent conversion has ben done and we don't force the
modified metadata to stable storage.

This violates O_DSYNC semantics. The window of exposure is a single
IO, as the next DIO write will see the inode has dirty metadata and
hence will not use the FUA optimisation. Calling
generic_write_sync() after completion of the second IO will also
sync the first write and it's metadata.

Fix this by avoiding the FUA optimisation when writing to unwritten
extents.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 9230a0b6
...@@ -1596,12 +1596,13 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, ...@@ -1596,12 +1596,13 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
if (iomap->flags & IOMAP_F_NEW) { if (iomap->flags & IOMAP_F_NEW) {
need_zeroout = true; need_zeroout = true;
} else { } else if (iomap->type == IOMAP_MAPPED) {
/* /*
* Use a FUA write if we need datasync semantics, this * Use a FUA write if we need datasync semantics, this is a pure
* is a pure data IO that doesn't require any metadata * data IO that doesn't require any metadata updates (including
* updates and the underlying device supports FUA. This * after IO completion such as unwritten extent conversion) and
* allows us to avoid cache flushes on IO completion. * the underlying device supports FUA. This allows us to avoid
* cache flushes on IO completion.
*/ */
if (!(iomap->flags & (IOMAP_F_SHARED|IOMAP_F_DIRTY)) && if (!(iomap->flags & (IOMAP_F_SHARED|IOMAP_F_DIRTY)) &&
(dio->flags & IOMAP_DIO_WRITE_FUA) && (dio->flags & IOMAP_DIO_WRITE_FUA) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment