On Thu, Apr 10, 2025 at 09:34:39AM +0200, Christoph Hellwig wrote: > On Wed, Apr 09, 2025 at 09:44:41PM +0800, Ming Lei wrote: > > On Wed, Apr 09, 2025 at 03:09:40PM +0200, Christoph Hellwig wrote: > > > vfs_iter_{read,write} always perform direct I/O when the file has the > > > O_DIRECT flag set, which breaks disabling direct I/O using the > > > LOOP_SET_STATUS / LOOP_SET_STATUS64 ioctls. > > > > So dio is disabled automatically because lo_offset is changed in > > LOOP_SET_STATUS, but backing file is still opened with O_DIRECT, > > then dio fails? > > > > But Darrick reports it is caused by changing sector size, instead of > > LOOP_SET_STATUS. > > LOOP_SET_STATUS changes the direct I/O flag. It isn't true in the following test case. > > This is the minimal reproducer, dev needs to be a 4k lba size device: > > dev=/dev/nvme0n1 > > mkfs.xfs -f $dev > mount $dev /mnt > > truncate -s 30g /mnt/a > losetup --direct-io=on -f --show /mnt/a > losetup --direct-io=off /dev/loop0 direct I/O flag is changed by LOOP_SET_DIRECT_IO instead of LOOP_SET_STATUS. losetup forgets the backfile is opened as O_DIRECT, and util-linux need fix too, such as call F_GETFL/F_SETFL to clear O_DIRECT. I guess it is hard to figure out one simple kernel fix to clear IOCB_DIRECT of file->f_iocb_flags for backporting. Thanks, Ming