tree 449f6598e10a1930d113fd7bbe3aa6ca37341d10
parent 1f08ad02379530e1c970d3d104343b9907b4d1b4
author Daniel McNeil <[EMAIL PROTECTED]> Sun, 17 Apr 2005 05:25:50 -0700
committer Linus Torvalds <[EMAIL PROTECTED]> Sun, 17 Apr 2005 05:25:50 -0700

[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
===================================================================
--- 607f1e99cefab35bccb14b5c053c0d63ff74458c/fs/direct-io.c  (mode:100644 
sha1:5a674a0c71461d4b5c5bcf05f42e867f196e4984)
+++ 449f6598e10a1930d113fd7bbe3aa6ca37341d10/fs/direct-io.c  (mode:100644 
sha1:1d55e7e6734247e8464899f308d94f8d0a398f4b)
@@ -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