ext4: fix off-by-one error when writing back pages before dio read
authorEric Biggers <ebiggers@google.com>
Wed, 24 May 2017 22:05:29 +0000 (18:05 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 24 May 2017 22:05:29 +0000 (18:05 -0400)
The 'lend' argument of filemap_write_and_wait_range() is inclusive, so
we need to subtract 1 from pos + count.

Note that 'count' is guaranteed to be nonzero since
ext4_file_read_iter() returns early when given a 0 count.

Fixes: 16c54688592c ("ext4: Allow parallel DIO reads")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
fs/ext4/inode.c

index 7cd99de8c4bace1d7ac072d50889eb0f17159cfe..90b2649287424a0902f7db083de6d28c5e5fc278 100644 (file)
@@ -3713,7 +3713,7 @@ static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter)
         */
        inode_lock_shared(inode);
        ret = filemap_write_and_wait_range(mapping, iocb->ki_pos,
-                                          iocb->ki_pos + count);
+                                          iocb->ki_pos + count - 1);
        if (ret)
                goto out_unlock;
        ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,