This is a note to let you know that I've just added the patch titled btrfs: fix failure of RWF_NOWAIT write into prealloc extent beyond eof to the 5.7-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-fix-failure-of-rwf_nowait-write-into-prealloc-extent-beyond-eof.patch and it can be found in the queue-5.7 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 4b1946284dd6641afdb9457101056d9e6ee6204c Mon Sep 17 00:00:00 2001 From: Filipe Manana <fdmanana@xxxxxxxx> Date: Mon, 15 Jun 2020 18:48:58 +0100 Subject: btrfs: fix failure of RWF_NOWAIT write into prealloc extent beyond eof From: Filipe Manana <fdmanana@xxxxxxxx> commit 4b1946284dd6641afdb9457101056d9e6ee6204c upstream. If we attempt to write to prealloc extent located after eof using a RWF_NOWAIT write, we always fail with -EAGAIN. We do actually check if we have an allocated extent for the write at the start of btrfs_file_write_iter() through a call to check_can_nocow(), but later when we go into the actual direct IO write path we simply return -EAGAIN if the write starts at or beyond EOF. Trivial to reproduce: $ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ touch /mnt/foo $ chattr +C /mnt/foo $ xfs_io -d -c "pwrite -S 0xab 0 64K" /mnt/foo wrote 65536/65536 bytes at offset 0 64 KiB, 16 ops; 0.0004 sec (135.575 MiB/sec and 34707.1584 ops/sec) $ xfs_io -c "falloc -k 64K 1M" /mnt/foo $ xfs_io -d -c "pwrite -N -V 1 -S 0xfe -b 64K 64K 64K" /mnt/foo pwrite: Resource temporarily unavailable On xfs and ext4 the write succeeds, as expected. Fix this by removing the wrong check at btrfs_direct_IO(). Fixes: edf064e7c6fec3 ("btrfs: nowait aio support") CC: stable@xxxxxxxxxxxxxxx # 4.14+ Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/inode.c | 3 --- 1 file changed, 3 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8262,9 +8262,6 @@ static ssize_t btrfs_direct_IO(struct ki dio_data.overwrite = 1; inode_unlock(inode); relock = true; - } else if (iocb->ki_flags & IOCB_NOWAIT) { - ret = -EAGAIN; - goto out; } ret = btrfs_delalloc_reserve_space(inode, &data_reserved, offset, count); Patches currently in stable-queue which might be from fdmanana@xxxxxxxx are queue-5.7/btrfs-fix-bytes_may_use-underflow-when-running-balance-and-scrub-in-parallel.patch queue-5.7/btrfs-fix-rwf_nowait-write-not-failling-when-we-need-to-cow.patch queue-5.7/btrfs-fix-hang-on-snapshot-creation-after-rwf_nowait-write.patch queue-5.7/btrfs-fix-failure-of-rwf_nowait-write-into-prealloc-extent-beyond-eof.patch queue-5.7/btrfs-check-if-a-log-root-exists-before-locking-the-log_mutex-on-unlink.patch queue-5.7/btrfs-fix-data-block-group-relocation-failure-due-to-concurrent-scrub.patch queue-5.7/btrfs-fix-a-block-group-ref-counter-leak-after-failu.patch