Jeff Moyer 35dc8161d0 [PATCH] fix O_DIRECT read of last block in a sparse file
Currently, if you open a file O_DIRECT, truncate it to a size that is not a
multiple of the disk block size, and then try to read the last block in the
file, the read will return 0.  The problem is in do_direct_IO, here:

        /* Handle holes */
        if (!buffer_mapped(map_bh)) {
                char *kaddr;

		...

                if (dio->block_in_file >=
                        i_size_read(dio->inode)>>blkbits) {
                        /* We hit eof */
                        page_cache_release(page);
                        goto out;
                }

We shift off any remaining bytes in the final block of the I/O, resulting
in a 0-sized read.  I've attached a patch that fixes this.  I'm not happy
about how ugly the math is getting, so suggestions are more than welcome.

I've tested this with a simple program that performs the steps outlined for
reproducing the problem above.  Without the patch, we get a 0-sized result
from read.  With the patch, we get the correct return value from the short
read.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Cc: Badari Pulavarty <pbadari@us.ibm.com>
Cc: Suparna Bhattacharya <suparna@in.ibm.com>
Cc: Mingming Cao <cmm@us.ibm.com>
Cc: Joel Becker <Joel.Becker@oracle.com>
Cc: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-02-03 08:32:07 -08:00
..
2006-01-11 18:42:13 -08:00
2006-01-14 18:25:19 -08:00
2005-11-08 16:54:53 +01:00
2005-10-04 13:22:01 -07:00
2006-01-27 18:36:11 -08:00
2006-01-11 18:42:13 -08:00
2006-01-18 19:20:23 -08:00
2006-01-18 19:20:16 -08:00
2006-01-11 18:42:13 -08:00
2005-05-05 16:36:47 -07:00
2006-01-11 18:42:13 -08:00
2005-11-07 07:54:06 -08:00
2006-02-01 08:53:09 -08:00
2006-01-11 18:42:13 -08:00
2006-01-11 18:42:13 -08:00
2006-02-03 08:32:04 -08:00
2006-01-08 20:13:48 -08:00
2006-01-11 18:42:13 -08:00
2005-05-05 16:36:47 -07:00
2006-01-10 08:01:25 -08:00
2005-04-16 15:20:36 -07:00
2005-04-16 15:20:36 -07:00
2006-01-31 15:24:34 +01:00
2006-01-11 18:42:13 -08:00
2005-04-16 15:20:36 -07:00
2006-01-11 18:42:13 -08:00
2006-01-08 20:12:40 -08:00
2006-01-18 19:20:29 -08:00
2005-10-30 17:37:32 -08:00
2006-01-11 18:42:13 -08:00
2006-01-11 18:42:13 -08:00
2006-01-16 23:15:29 -08:00
2006-01-18 19:20:30 -08:00
2006-01-18 19:20:29 -08:00
2006-01-08 20:13:56 -08:00
2005-11-07 18:18:11 -08:00
2005-04-16 15:20:36 -07:00
2006-01-11 18:42:13 -08:00
2006-01-18 19:20:29 -08:00
2005-04-16 15:20:36 -07:00