FAILED: patch "[PATCH] direct-io: Fix negative return from dio read beyond eof" failed to apply to 3.14-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 3.14-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
Quoted 1 line
From
74cedf9b6c603f2278a05bc91b140b32b434d0b5Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Mon, 30 Nov 2015 10:15:42 -0700
Subject: [PATCH] direct-io: Fix negative return from dio read beyond eof
Assume a filesystem with 4KB blocks. When a file has size 1000 bytes and we issue direct IO read at offset 1024, blockdev_direct_IO() reads the tail of the last block and the logic for handling short DIO reads in dio_complete() results in a return value -24 (1000 - 1024) which obviously confuses userspace.
Fix the problem by bailing out early once we sample i_size and can reliably check that direct IO read starts beyond i_size.
fs/direct-io.c +9 -1
@@ -1169,6 +1169,15 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, } } +/* Once we sampled i_size check for reads beyond EOF */ + dio->i_size =i_size_read (inode); +if (iov_iter_rw (iter) ==READ && offset >= dio->i_size) { +if (dio->flags &DIO_LOCKING ) +mutex_unlock (&inode->i_mutex); +kmem_cache_free (dio_cache, dio); + goto out; + } +/* * For file extending writes updating i_size before data writeouts * complete can expose uninitialized blocks in dumb filesystems.
@@ -1222,7 +1231,6 @@ do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, sdio.next_block_for_io =-1 ; dio->iocb = iocb; - dio->i_size =i_size_read (inode);spin_lock_init (&dio->bio_lock); dio->refcount =1 ;