Re: [PATCH v7 0/5] vfs: Non-blockling buffered fs read (page cache only)

Andrew Morton
2015-03-27T16:38:32Z

On Fri, 27 Mar 2015 09:30:46 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:

> I expect that this situation (first part in cache, latter part not in
> cache) is rare - for reasonably small requests the common cases will be
> "all cached" and "nothing cached". So perhaps the best approach here
> is for samba to add special handling for the short read, to work out
> the reason for its occurrence.
>
> Alternatively we could add another flag to pread2() to select this
> "throw away my data and return -EAGAIN" behaviour. Presumably
> implemented with an i_size check, but it's gonna be racy.

Here's a better way:

nr_read = pread2(buf, len);
if (nr_read < len)
nr_read += pread(buf + nr_read, len - nr_read);
if (nr_read < len)
we_hit_eof();