Message ID | 1596613234-174664-1-git-send-email-jiangying8582@126.com |
---|---|
State | Not Applicable |
Headers | show |
Series | [v4] ext4: fix direct I/O read error | expand |
On Wed, Aug 05, 2020 at 03:40:34PM +0800, Jiang Ying wrote: > This patch is used to fix ext4 direct I/O read error when > the read size is not aligned with block size. > > Then, I will use a test to explain the error. > > (1) Make a file that is not aligned with block size: > $dd if=/dev/zero of=./test.jar bs=1000 count=3 > > (2) I wrote a source file named "direct_io_read_file.c" as following: Can you please add your reproducer to xfstests? Thanks!
Ok,I will make time to do it. 发自我的iPhone > 在 2020年8月14日,下午4:04,Christoph Hellwig <hch@infradead.org> 写道: > > On Wed, Aug 05, 2020 at 03:40:34PM +0800, Jiang Ying wrote: >> This patch is used to fix ext4 direct I/O read error when >> the read size is not aligned with block size. >> >> Then, I will use a test to explain the error. >> >> (1) Make a file that is not aligned with block size: >> $dd if=/dev/zero of=./test.jar bs=1000 count=3 >> >> (2) I wrote a source file named "direct_io_read_file.c" as following: > > Can you please add your reproducer to xfstests? > > Thanks!
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 516faa2..a66b0ac 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3821,6 +3821,11 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter) struct inode *inode = mapping->host; size_t count = iov_iter_count(iter); ssize_t ret; + loff_t offset = iocb->ki_pos; + loff_t size = i_size_read(inode); + + if (offset >= size) + return 0; /* * Shared inode_lock is enough for us - it protects against concurrent