aboutsummaryrefslogtreecommitdiffstats
path: root/mm/readahead.c
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2014-01-29 17:05:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-29 19:22:40 -0500
commit58d5640ebdb273cc817b0d0cda7bcf2efbbc2ff7 (patch)
tree9f4c83901b87b3c7d90d93c4b054c04ef4ef9700 /mm/readahead.c
parenta0132ac0f275434db32111b8cf7372d991899da3 (diff)
mm/readahead.c: fix do_readahead() for no readpage(s)
Commit 63d0f0a3c7e1 ("mm/readahead.c:do_readhead(): don't check for ->readpage") unintentionally made do_readahead return 0 for all valid files regardless of whether readahead was supported, rather than the expected -EINVAL. This gets forwarded on to userspace, and results in sys_readahead appearing to succeed in cases that don't make sense (e.g. when called on pipes or sockets). This issue is detected by the LTP readahead01 testcase. As the exact return value of force_page_cache_readahead is currently never used, we can simplify it to return only 0 or -EINVAL (when readpage or readpages is missing). With that in place we can simply forward on the return value of force_page_cache_readahead in do_readahead. This patch performs said change, restoring the expected semantics. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/readahead.c')
-rw-r--r--mm/readahead.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/mm/readahead.c b/mm/readahead.c
index 7cdbb44aa90b..0de2360d65f3 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -211,8 +211,6 @@ out:
211int force_page_cache_readahead(struct address_space *mapping, struct file *filp, 211int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
212 pgoff_t offset, unsigned long nr_to_read) 212 pgoff_t offset, unsigned long nr_to_read)
213{ 213{
214 int ret = 0;
215
216 if (unlikely(!mapping->a_ops->readpage && !mapping->a_ops->readpages)) 214 if (unlikely(!mapping->a_ops->readpage && !mapping->a_ops->readpages))
217 return -EINVAL; 215 return -EINVAL;
218 216
@@ -226,15 +224,13 @@ int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
226 this_chunk = nr_to_read; 224 this_chunk = nr_to_read;
227 err = __do_page_cache_readahead(mapping, filp, 225 err = __do_page_cache_readahead(mapping, filp,
228 offset, this_chunk, 0); 226 offset, this_chunk, 0);
229 if (err < 0) { 227 if (err < 0)
230 ret = err; 228 return err;
231 break; 229
232 }
233 ret += err;
234 offset += this_chunk; 230 offset += this_chunk;
235 nr_to_read -= this_chunk; 231 nr_to_read -= this_chunk;
236 } 232 }
237 return ret; 233 return 0;
238} 234}
239 235
240/* 236/*
@@ -576,8 +572,7 @@ do_readahead(struct address_space *mapping, struct file *filp,
576 if (!mapping || !mapping->a_ops) 572 if (!mapping || !mapping->a_ops)
577 return -EINVAL; 573 return -EINVAL;
578 574
579 force_page_cache_readahead(mapping, filp, index, nr); 575 return force_page_cache_readahead(mapping, filp, index, nr);
580 return 0;
581} 576}
582 577
583SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count) 578SYSCALL_DEFINE3(readahead, int, fd, loff_t, offset, size_t, count)