On Mon, May 23, 2022 at 12:42:33AM +0000, Al Viro wrote: > At the moment it's carved up into 6 commits: > btrfs_direct_write(): cleaner way to handle generic_write_sync() suppression I happpen to need something similar for JFS, so I tried it out. There's a mistake where dio->flags should have been dio_flags. I also added a comment on the definition of DIO_NOSYNC. (the btrfs patch didn't apply cleanly, so I just dropped it since I wasn't going to be touching btrfs anyway) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 370c3241618a..6a361131080f 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -548,7 +548,8 @@ __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; /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index e552097c67e0..c8622d8f064e 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -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);