linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Moyer <jmoyer@redhat.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, Badari Pulavarty <pbadari@us.ibm.com>
Subject: Re: [patch] fix O_DIRECT read of last block in a sparse file
Date: Tue, 24 Jan 2006 07:09:08 -0500	[thread overview]
Message-ID: <17366.6372.383039.125496@segfault.boston.redhat.com> (raw)
In-Reply-To: <20060123155401.62f7b756.akpm@osdl.org>

==> Regarding Re: [patch] fix O_DIRECT read of last block in a sparse file; Andrew Morton <akpm@osdl.org> adds:

akpm> Jeff Moyer <jmoyer@redhat.com> wrote:
>> 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.

akpm> OK.  We do have some helper functions to make the math a little
akpm> clearer. How does this look?

That's much cleaner, thanks!

-Jeff

      reply	other threads:[~2006-01-24 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-23 19:16 [patch] fix O_DIRECT read of last block in a sparse file Jeff Moyer
2006-01-23 23:54 ` Andrew Morton
2006-01-24 12:09   ` Jeff Moyer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17366.6372.383039.125496@segfault.boston.redhat.com \
    --to=jmoyer@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbadari@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).