Skip to content

Commit

Permalink
teach iomap_dio_rw() to suppress dsync
Browse files Browse the repository at this point in the history
New flag, equivalent to removal of IOCB_DSYNC from iocb flags.
This mimics what btrfs is doing (and that's what btrfs will
switch to).  However, I'm not at all sure that we want to
suppress REQ_FUA for those - all btrfs hack really cares about
is suppression of generic_write_sync().  For now let's keep
the existing behaviour, but I really want to hear more detailed
arguments pro or contra.

[folded brain fix from willy]

Suggested-by: Christoph Hellwig <[email protected]>
Reviewed-by: Christian Brauner (Microsoft) <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Jun 10, 2022
1 parent 0e3c3b9 commit 36518b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 11 additions & 9 deletions fs/iomap/direct-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,17 +548,19 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
}

/* for data sync or sync, we need sync completion processing */
if (iocb->ki_flags & IOCB_DSYNC)
if (iocb->ki_flags & IOCB_DSYNC &&
!(dio_flags & IOMAP_DIO_NOSYNC)) {
dio->flags |= IOMAP_DIO_NEED_SYNC;

/*
* For datasync only writes, we optimistically try using FUA for
* this IO. Any non-FUA write that occurs will clear this flag,
* hence we know before completion whether a cache flush is
* necessary.
*/
if ((iocb->ki_flags & (IOCB_DSYNC | IOCB_SYNC)) == IOCB_DSYNC)
dio->flags |= IOMAP_DIO_WRITE_FUA;
/*
* For datasync only writes, we optimistically try
* using FUA for this IO. Any non-FUA write that
* occurs will clear this flag, hence we know before
* completion whether a cache flush is necessary.
*/
if (!(iocb->ki_flags & IOCB_SYNC))
dio->flags |= IOMAP_DIO_WRITE_FUA;
}
}

if (dio_flags & IOMAP_DIO_OVERWRITE_ONLY) {
Expand Down
6 changes: 6 additions & 0 deletions include/linux/iomap.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ struct iomap_dio_ops {
*/
#define IOMAP_DIO_PARTIAL (1 << 2)

/*
* The caller will sync the write if needed; do not sync it within
* iomap_dio_rw. Overrides IOMAP_DIO_FORCE_WAIT.
*/
#define IOMAP_DIO_NOSYNC (1 << 3)

ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
unsigned int dio_flags, void *private, size_t done_before);
Expand Down

0 comments on commit 36518b6

Please sign in to comment.