From cab9e82ffb3a5e2fc4e0ed75a4737d51cee8da3f Mon Sep 17 00:00:00 2001 From: jhb Date: Thu, 29 Dec 2011 15:34:59 +0000 Subject: Implement linux_fadvise64() and linux_fadvise64_64() using kern_posix_fadvise(). Reviewed by: silence on emulation@ MFC after: 2 weeks --- sys/amd64/linux32/linux.h | 10 +++++++++ sys/amd64/linux32/linux32_dummy.c | 2 -- sys/amd64/linux32/syscalls.master | 7 ++++-- sys/compat/linux/linux_file.c | 45 +++++++++++++++++++++++++++++++++++++++ sys/i386/linux/linux.h | 10 +++++++++ sys/i386/linux/linux_dummy.c | 2 -- sys/i386/linux/syscalls.master | 7 ++++-- 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/sys/amd64/linux32/linux.h b/sys/amd64/linux32/linux.h index 4a5ec01..d91c694 100644 --- a/sys/amd64/linux32/linux.h +++ b/sys/amd64/linux32/linux.h @@ -597,6 +597,16 @@ int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h); #define LINUX_F_UNLCK 2 /* + * posix_fadvise advice + */ +#define LINUX_POSIX_FADV_NORMAL 0 +#define LINUX_POSIX_FADV_RANDOM 1 +#define LINUX_POSIX_FADV_SEQUENTIAL 2 +#define LINUX_POSIX_FADV_WILLNEED 3 +#define LINUX_POSIX_FADV_DONTNEED 4 +#define LINUX_POSIX_FADV_NOREUSE 5 + +/* * mount flags */ #define LINUX_MS_RDONLY 0x0001 diff --git a/sys/amd64/linux32/linux32_dummy.c b/sys/amd64/linux32/linux32_dummy.c index a147b91..893fcd4 100644 --- a/sys/amd64/linux32/linux32_dummy.c +++ b/sys/amd64/linux32/linux32_dummy.c @@ -59,7 +59,6 @@ DUMMY(setfsuid); DUMMY(setfsgid); DUMMY(pivot_root); DUMMY(mincore); -DUMMY(fadvise64); DUMMY(ptrace); DUMMY(lookup_dcookie); DUMMY(epoll_create); @@ -72,7 +71,6 @@ DUMMY(timer_gettime); DUMMY(timer_getoverrun); DUMMY(timer_delete); DUMMY(fstatfs64); -DUMMY(fadvise64_64); DUMMY(mbind); DUMMY(get_mempolicy); DUMMY(set_mempolicy); diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master index 1c09084..0554a60 100644 --- a/sys/amd64/linux32/syscalls.master +++ b/sys/amd64/linux32/syscalls.master @@ -419,7 +419,8 @@ 247 AUE_NULL UNIMPL linux_io_getevents 248 AUE_NULL UNIMPL linux_io_submit 249 AUE_NULL UNIMPL linux_io_cancel -250 AUE_NULL STD { int linux_fadvise64(void); } +250 AUE_NULL STD { int linux_fadvise64(int fd, l_loff_t offset, \ + l_size_t len, int advice); } 251 AUE_NULL UNIMPL 252 AUE_EXIT STD { int linux_exit_group(int error_code); } 253 AUE_NULL STD { int linux_lookup_dcookie(void); } @@ -443,7 +444,9 @@ 270 AUE_NULL STD { int linux_tgkill(int tgid, int pid, int sig); } 271 AUE_UTIMES STD { int linux_utimes(char *fname, \ struct l_timeval *tptr); } -272 AUE_NULL STD { int linux_fadvise64_64(void); } +272 AUE_NULL STD { int linux_fadvise64_64(int fd, \ + l_loff_t offset, l_loff_t len, \ + int advice); } 273 AUE_NULL UNIMPL 274 AUE_NULL STD { int linux_mbind(void); } 275 AUE_NULL STD { int linux_get_mempolicy(void); } diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index ffa2282..c04156c 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -1530,3 +1530,48 @@ linux_lchown(struct thread *td, struct linux_lchown_args *args) LFREEPATH(path); return (error); } + +static int +convert_fadvice(int advice) +{ + switch (advice) { + case LINUX_POSIX_FADV_NORMAL: + return (POSIX_FADV_NORMAL); + case LINUX_POSIX_FADV_RANDOM: + return (POSIX_FADV_RANDOM); + case LINUX_POSIX_FADV_SEQUENTIAL: + return (POSIX_FADV_SEQUENTIAL); + case LINUX_POSIX_FADV_WILLNEED: + return (POSIX_FADV_WILLNEED); + case LINUX_POSIX_FADV_DONTNEED: + return (POSIX_FADV_DONTNEED); + case LINUX_POSIX_FADV_NOREUSE: + return (POSIX_FADV_NOREUSE); + default: + return (-1); + } +} + +int +linux_fadvise64(struct thread *td, struct linux_fadvise64_args *args) +{ + int advice; + + advice = convert_fadvice(args->advice); + if (advice == -1) + return (EINVAL); + return (kern_posix_fadvise(td, args->fd, args->offset, args->len, + advice)); +} + +int +linux_fadvise64_64(struct thread *td, struct linux_fadvise64_64_args *args) +{ + int advice; + + advice = convert_fadvice(args->advice); + if (advice == -1) + return (EINVAL); + return (kern_posix_fadvise(td, args->fd, args->offset, args->len, + advice)); +} diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h index d02614b..a57be83 100644 --- a/sys/i386/linux/linux.h +++ b/sys/i386/linux/linux.h @@ -573,6 +573,16 @@ int linux_ioctl_unregister_handler(struct linux_ioctl_handler *h); #define LINUX_F_UNLCK 2 /* + * posix_fadvise advice + */ +#define LINUX_POSIX_FADV_NORMAL 0 +#define LINUX_POSIX_FADV_RANDOM 1 +#define LINUX_POSIX_FADV_SEQUENTIAL 2 +#define LINUX_POSIX_FADV_WILLNEED 3 +#define LINUX_POSIX_FADV_DONTNEED 4 +#define LINUX_POSIX_FADV_NOREUSE 5 + +/* * mount flags */ #define LINUX_MS_RDONLY 0x0001 diff --git a/sys/i386/linux/linux_dummy.c b/sys/i386/linux/linux_dummy.c index bc300b1..ca38649 100644 --- a/sys/i386/linux/linux_dummy.c +++ b/sys/i386/linux/linux_dummy.c @@ -62,14 +62,12 @@ DUMMY(setfsuid); DUMMY(setfsgid); DUMMY(pivot_root); DUMMY(mincore); -DUMMY(fadvise64); DUMMY(lookup_dcookie); DUMMY(epoll_create); DUMMY(epoll_ctl); DUMMY(epoll_wait); DUMMY(remap_file_pages); DUMMY(fstatfs64); -DUMMY(fadvise64_64); DUMMY(mbind); DUMMY(get_mempolicy); DUMMY(set_mempolicy); diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master index 7e7965f..618d0ad 100644 --- a/sys/i386/linux/syscalls.master +++ b/sys/i386/linux/syscalls.master @@ -421,7 +421,8 @@ 247 AUE_NULL UNIMPL linux_io_getevents 248 AUE_NULL UNIMPL linux_io_submit 249 AUE_NULL UNIMPL linux_io_cancel -250 AUE_NULL STD { int linux_fadvise64(void); } +250 AUE_NULL STD { int linux_fadvise64(int fd, l_loff_t offset, \ + l_size_t len, int advice); } 251 AUE_NULL UNIMPL 252 AUE_EXIT STD { int linux_exit_group(int error_code); } 253 AUE_NULL STD { int linux_lookup_dcookie(void); } @@ -447,7 +448,9 @@ 270 AUE_NULL STD { int linux_tgkill(int tgid, int pid, int sig); } 271 AUE_UTIMES STD { int linux_utimes(char *fname, \ struct l_timeval *tptr); } -272 AUE_NULL STD { int linux_fadvise64_64(void); } +272 AUE_NULL STD { int linux_fadvise64_64(int fd, \ + l_loff_t offset, l_loff_t len, \ + int advice); } 273 AUE_NULL UNIMPL 274 AUE_NULL STD { int linux_mbind(void); } 275 AUE_NULL STD { int linux_get_mempolicy(void); } -- cgit v1.1