tree fefd62f9db584a807b87f7c58ed3544a58e886d3
parent af15d96850d18b09aaae85914b719c71fdc314cf
author Daniel McNeil <[EMAIL PROTECTED]> Tue Apr 12 08:26:18 2005
committer Linus Torvalds <[EMAIL PROTECTED]> Tue Apr 12 08:26:18 2005

[PATCH] Direct IO async short read fix

The direct I/O code is mapping the read request to the file system block.  If
the file size was not on a block boundary, the result would show the the read
reading past EOF.  This was only happening for the AIO case.  The non-AIO case
truncates the result to match file size (in direct_io_worker).  This patch
does the same thing for the AIO case, it truncates the result to match the
file size if the read reads past EOF.

When I/O completes the result can be truncated to match the file size
without using i_size_read(), thus the aio result now matches the number of
bytes read to the end of file.

Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 direct-io.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

Index: fs/direct-io.c
===================================================================
--- 7ec30344667b228aa8d81bb096f2dda767ccecf1/fs/direct-io.c  (mode:100644 
sha1:b42c266b95a24e5f298cc7b3a65c051718c16efa)
+++ fefd62f9db584a807b87f7c58ed3544a58e886d3/fs/direct-io.c  (mode:100644 
sha1:2fa0264c43da84cda22d2df94b4c3e01229dce43)
@@ -66,6 +66,7 @@
        struct bio *bio;                /* bio under assembly */
        struct inode *inode;
        int rw;
+       loff_t i_size;                  /* i_size when submitted */
        int lock_type;                  /* doesn't change */
        unsigned blkbits;               /* doesn't change */
        unsigned blkfactor;             /* When we're using an alignment which
@@ -230,17 +231,29 @@
        spin_lock_irqsave(&dio->bio_lock, flags);
        if (dio->bio_count == 1) {
                if (dio->is_async) {
+                       ssize_t transferred;
+                       loff_t offset;
+
                        /*
                         * Last reference to the dio is going away.
                         * Drop spinlock and complete the DIO.
                         */
                        spin_unlock_irqrestore(&dio->bio_lock, flags);
-                       dio_complete(dio, dio->block_in_file << dio->blkbits,
-                                       dio->result);
+
+                       /* Check for short read case */
+                       transferred = dio->result;
+                       offset = dio->iocb->ki_pos;
+
+                       if ((dio->rw == READ) &&
+                           ((offset + transferred) > dio->i_size))
+                               transferred = dio->i_size - offset;
+
+                       dio_complete(dio, offset, transferred);
+
                        /* Complete AIO later if falling back to buffered i/o */
                        if (dio->result == dio->size ||
                                ((dio->rw == READ) && dio->result)) {
-                               aio_complete(dio->iocb, dio->result, 0);
+                               aio_complete(dio->iocb, transferred, 0);
                                kfree(dio);
                                return;
                        } else {
@@ -951,6 +964,7 @@
        dio->page_errors = 0;
        dio->result = 0;
        dio->iocb = iocb;
+       dio->i_size = i_size_read(inode);
 
        /*
         * BIO completion state.
-
To unsubscribe from this list: send the line "unsubscribe bk-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to