From b5a6ec93ce565b092034a858214bf7596ddc4414 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Thu, 13 Jun 2019 13:48:10 -0500 Subject: [PATCH] LU-12438 llite: vfs_read/write removed, use kernel_read/write As of Linux 4.14 the vfs_read() is no longer available to kernel modules. The kernel_read() function calls vfs_read() and will continue to be available. Adding a configure test to use kernel_read() as the function signature changed in 4.14 to match the other file I/O helpers. Also remove vfs_write() in favor of kernel_write() wrapper cfs_kernel_write(). Fixes: f172b1168857 ("LU-10092 llite: Add persistent cache on client") Signed-off-by: Shaun Tancheff Signed-off-by: Qian Yingjin Change-Id: I5e5fce0e6644ba750169f3bf11ac5c98525da0a7 Reviewed-on: https://review.whamcloud.com/35223 Tested-by: Jenkins Reviewed-by: Wang Shilong Reviewed-by: Li Xi Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Petros Koutoupis --- libcfs/autoconf/lustre-libcfs.m4 | 24 ++++++++++++++++++++++++ libcfs/include/libcfs/linux/linux-misc.h | 2 ++ libcfs/libcfs/linux/linux-prim.c | 14 ++++++++++++++ lustre/llite/pcc.c | 14 +++++--------- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 543b989..c1cb43b 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -1004,6 +1004,29 @@ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_NEW_KERNEL_WRITE # +# LIBCFS_NEW_KERNEL_WRITE +# +# 4.14 commit bdd1d2d3d251c65b74ac4493e08db18971c09240 changed +# the signature of kernel_read to match other read/write helpers +# and place offset last. +# +AC_DEFUN([LIBCFS_NEW_KERNEL_READ], [ +tmp_flags="$EXTRA_KCFLAGS" +EXTRA_KCFLAGS="-Werror" +LB_CHECK_COMPILE([if 'kernel_read()' has loff_t *pos as last parameter], +kernel_read, [ + #include + ],[ + loff_t pos = 0; + kernel_read(NULL, NULL, 0, &pos); +],[ + AC_DEFINE(HAVE_KERNEL_READ_LAST_POSP, 1, + [kernel_read() signature ends with loff_t *pos]) +]) +EXTRA_KCFLAGS="$tmp_flags" +]) # LIBCFS_NEW_KERNEL_READ + +# # LIBCFS_DEFINE_TIMER # # Kernel version 4.14 commit 1d27e3e2252ba9d949ca82fbdb73cde102cb2067 @@ -1196,6 +1219,7 @@ LIBCFS_WAIT_QUEUE_ENTRY # 4.14 LIBCFS_DEFINE_TIMER LIBCFS_NEW_KERNEL_WRITE +LIBCFS_NEW_KERNEL_READ LIBCFS_EXPORT_SAVE_STACK_TRACE_TSK # 4.15 LIBCFS_TIMER_SETUP diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index 230d8d4..524bf40 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -115,6 +115,8 @@ int cfs_get_environ(const char *key, char *value, int *val_len); int cfs_kernel_write(struct file *filp, const void *buf, size_t count, loff_t *pos); +ssize_t cfs_kernel_read(struct file *file, void *buf, size_t count, + loff_t *pos); /* * For RHEL6 struct kernel_parm_ops doesn't exist. Also diff --git a/libcfs/libcfs/linux/linux-prim.c b/libcfs/libcfs/linux/linux-prim.c index 4f07340..f263e9e 100644 --- a/libcfs/libcfs/linux/linux-prim.c +++ b/libcfs/libcfs/linux/linux-prim.c @@ -120,6 +120,20 @@ int cfs_kernel_write(struct file *filp, const void *buf, size_t count, } EXPORT_SYMBOL(cfs_kernel_write); +ssize_t cfs_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) +{ +#ifdef HAVE_KERNEL_READ_LAST_POSP + return kernel_read(file, buf, count, pos); +#else + ssize_t size = kernel_read(file, *pos, buf, count); + + if (size > 0) + *pos += size; + return size; +#endif +} +EXPORT_SYMBOL(cfs_kernel_read); + #ifndef HAVE_KSET_FIND_OBJ struct kobject *kset_find_obj(struct kset *kset, const char *name) { diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index fcebed4..c779c72 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -2168,7 +2168,7 @@ static int pcc_filp_write(struct file *filp, const void *buf, ssize_t count, while (count > 0) { ssize_t size; - size = vfs_write(filp, (const void __user *)buf, count, offset); + size = cfs_kernel_write(filp, buf, count, offset); if (size < 0) return size; count -= size; @@ -2181,7 +2181,6 @@ static int pcc_copy_data(struct file *src, struct file *dst) { int rc = 0; ssize_t rc2; - mm_segment_t oldfs; loff_t pos, offset = 0; size_t buf_len = 1048576; void *buf; @@ -2192,25 +2191,22 @@ static int pcc_copy_data(struct file *src, struct file *dst) if (buf == NULL) RETURN(-ENOMEM); - oldfs = get_fs(); - set_fs(KERNEL_DS); while (1) { pos = offset; - rc2 = vfs_read(src, (void __user *)buf, buf_len, &pos); + rc2 = cfs_kernel_read(src, buf, buf_len, &pos); if (rc2 < 0) - GOTO(out_fs, rc = rc2); + GOTO(out_free, rc = rc2); else if (rc2 == 0) break; pos = offset; rc = pcc_filp_write(dst, buf, rc2, &pos); if (rc < 0) - GOTO(out_fs, rc); + GOTO(out_free, rc); offset += rc2; } -out_fs: - set_fs(oldfs); +out_free: OBD_FREE_LARGE(buf, buf_len); RETURN(rc); } -- 1.8.3.1