Commit 782182e53a6cdb3e3d04cc40516e173046942a32
Committed by
Linus Torvalds
1 parent
4fb5ef089b
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
mm: move readahead syscall to mm/readahead.c
It is better to define readahead(2) in mm/readahead.c than in mm/filemap.c. Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 2 changed files with 40 additions and 39 deletions Side-by-side Diff
mm/filemap.c
... | ... | @@ -29,7 +29,6 @@ |
29 | 29 | #include <linux/pagevec.h> |
30 | 30 | #include <linux/blkdev.h> |
31 | 31 | #include <linux/security.h> |
32 | -#include <linux/syscalls.h> | |
33 | 32 | #include <linux/cpuset.h> |
34 | 33 | #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */ |
35 | 34 | #include <linux/memcontrol.h> |
... | ... | @@ -1477,44 +1476,6 @@ |
1477 | 1476 | return retval; |
1478 | 1477 | } |
1479 | 1478 | EXPORT_SYMBOL(generic_file_aio_read); |
1480 | - | |
1481 | -static ssize_t | |
1482 | -do_readahead(struct address_space *mapping, struct file *filp, | |
1483 | - pgoff_t index, unsigned long nr) | |
1484 | -{ | |
1485 | - if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage) | |
1486 | - return -EINVAL; | |
1487 | - | |
1488 | - force_page_cache_readahead(mapping, filp, index, nr); | |
1489 | - return 0; | |
1490 | -} | |
1491 | - | |
1492 | -SYSCALL_DEFINE(readahead)(int fd, loff_t offset, size_t count) | |
1493 | -{ | |
1494 | - ssize_t ret; | |
1495 | - struct file *file; | |
1496 | - | |
1497 | - ret = -EBADF; | |
1498 | - file = fget(fd); | |
1499 | - if (file) { | |
1500 | - if (file->f_mode & FMODE_READ) { | |
1501 | - struct address_space *mapping = file->f_mapping; | |
1502 | - pgoff_t start = offset >> PAGE_CACHE_SHIFT; | |
1503 | - pgoff_t end = (offset + count - 1) >> PAGE_CACHE_SHIFT; | |
1504 | - unsigned long len = end - start + 1; | |
1505 | - ret = do_readahead(mapping, file, start, len); | |
1506 | - } | |
1507 | - fput(file); | |
1508 | - } | |
1509 | - return ret; | |
1510 | -} | |
1511 | -#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS | |
1512 | -asmlinkage long SyS_readahead(long fd, loff_t offset, long count) | |
1513 | -{ | |
1514 | - return SYSC_readahead((int) fd, offset, (size_t) count); | |
1515 | -} | |
1516 | -SYSCALL_ALIAS(sys_readahead, SyS_readahead); | |
1517 | -#endif | |
1518 | 1479 | |
1519 | 1480 | #ifdef CONFIG_MMU |
1520 | 1481 | /** |
mm/readahead.c
... | ... | @@ -17,6 +17,8 @@ |
17 | 17 | #include <linux/task_io_accounting_ops.h> |
18 | 18 | #include <linux/pagevec.h> |
19 | 19 | #include <linux/pagemap.h> |
20 | +#include <linux/syscalls.h> | |
21 | +#include <linux/file.h> | |
20 | 22 | |
21 | 23 | /* |
22 | 24 | * Initialise a struct file's readahead state. Assumes that the caller has |
... | ... | @@ -562,4 +564,42 @@ |
562 | 564 | ondemand_readahead(mapping, ra, filp, true, offset, req_size); |
563 | 565 | } |
564 | 566 | EXPORT_SYMBOL_GPL(page_cache_async_readahead); |
567 | + | |
568 | +static ssize_t | |
569 | +do_readahead(struct address_space *mapping, struct file *filp, | |
570 | + pgoff_t index, unsigned long nr) | |
571 | +{ | |
572 | + if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage) | |
573 | + return -EINVAL; | |
574 | + | |
575 | + force_page_cache_readahead(mapping, filp, index, nr); | |
576 | + return 0; | |
577 | +} | |
578 | + | |
579 | +SYSCALL_DEFINE(readahead)(int fd, loff_t offset, size_t count) | |
580 | +{ | |
581 | + ssize_t ret; | |
582 | + struct file *file; | |
583 | + | |
584 | + ret = -EBADF; | |
585 | + file = fget(fd); | |
586 | + if (file) { | |
587 | + if (file->f_mode & FMODE_READ) { | |
588 | + struct address_space *mapping = file->f_mapping; | |
589 | + pgoff_t start = offset >> PAGE_CACHE_SHIFT; | |
590 | + pgoff_t end = (offset + count - 1) >> PAGE_CACHE_SHIFT; | |
591 | + unsigned long len = end - start + 1; | |
592 | + ret = do_readahead(mapping, file, start, len); | |
593 | + } | |
594 | + fput(file); | |
595 | + } | |
596 | + return ret; | |
597 | +} | |
598 | +#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS | |
599 | +asmlinkage long SyS_readahead(long fd, loff_t offset, long count) | |
600 | +{ | |
601 | + return SYSC_readahead((int) fd, offset, (size_t) count); | |
602 | +} | |
603 | +SYSCALL_ALIAS(sys_readahead, SyS_readahead); | |
604 | +#endif |