On Sat, May 21, 2022 at 05:48:42PM +0000, Al Viro wrote: > There's a problem with that variant. Take a look at btrfs_direct_write(): > const bool is_sync_write = (iocb->ki_flags & IOCB_DSYNC); > ... > /* > * We remove IOCB_DSYNC so that we don't deadlock when iomap_dio_rw() > * calls generic_write_sync() (through iomap_dio_complete()), because > * that results in calling fsync (btrfs_sync_file()) which will try to > * lock the inode in exclusive/write mode. > */ > if (is_sync_write) > iocb->ki_flags &= ~IOCB_DSYNC; > ... > > /* > * Add back IOCB_DSYNC. Our caller, btrfs_file_write_iter(), will do > * the fsync (call generic_write_sync()). > */ > if (is_sync_write) > iocb->ki_flags |= IOCB_DSYNC; > > will run into trouble. How about this (completely untested): Which is pretty gross. We can just add a IOMAP_DIO_NOSYNC flag to do what btrfs wants is a much less gross way. > Precalculate iocb_flags() > > Store the value in file->f_i_flags; calculate at open time (do_dentry_open() > for opens, alloc_file() for pipe(2)/socket(2)/etc.), update at FCNTL_SETFL > time. Eww. I don't think we should grow struct file for tht.