From f0ff89fc86873a96a3f60e86e1694775b664663e Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 14 Jul 2010 11:26:54 -0700 Subject: [PATCH] Linux 2.6.35 compat: filp_fsync() dropped 'stuct dentry *' The prototype for filp_fsync() drop the unused argument 'stuct dentry *'. I've fixed this by adding the needed autoconf check and moving all of those filp related functions to file_compat.h. This will simplify handling any further API changes in the future. --- config/spl-build.m4 | 20 ++++++ configure | 130 ++++++++++++++++++++++++++++++++++++ include/linux/file_compat.h | 27 ++++++++ module/spl/spl-debug.c | 33 ++------- module/spl/spl-vnode.c | 2 +- spl_config.h.in | 3 + 6 files changed, 187 insertions(+), 28 deletions(-) diff --git a/config/spl-build.m4 b/config/spl-build.m4 index ae4e1f1625..b908a56d5b 100644 --- a/config/spl-build.m4 +++ b/config/spl-build.m4 @@ -76,6 +76,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ SPL_AC_PUT_TASK_STRUCT SPL_AC_5ARGS_PROC_HANDLER SPL_AC_KVASPRINTF + SPL_AC_3ARGS_FILE_FSYNC ]) AC_DEFUN([SPL_AC_MODULE_SYMVERS], [ @@ -1438,3 +1439,22 @@ AC_DEFUN([SPL_AC_KVASPRINTF], [ [kvasprintf() is available])], []) ]) + +dnl # +dnl # 2.6.35 API change, +dnl # Unused 'struct dentry *' removed from prototype. +dnl # +AC_DEFUN([SPL_AC_3ARGS_FILE_FSYNC], [ + AC_MSG_CHECKING([whether file_fsync() wants 3 args]) + SPL_LINUX_TRY_COMPILE([ + #include + ],[ + file_fsync(NULL, NULL, 0); + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_3ARGS_FILE_FSYNC, 1, + [file_fsync() wants 3 args]) + ],[ + AC_MSG_RESULT(no) + ]) +]) diff --git a/configure b/configure index 04da5953a1..656f0425aa 100755 --- a/configure +++ b/configure @@ -14905,6 +14905,71 @@ _ACEOF fi + + { $as_echo "$as_me:$LINENO: checking whether file_fsync() wants 3 args" >&5 +$as_echo_n "checking whether file_fsync() wants 3 args... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + file_fsync(NULL, NULL, 0); + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_3ARGS_FILE_FSYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + ;; user) if test "x$AWK" != xgawk; then @@ -18350,6 +18415,71 @@ _ACEOF + { $as_echo "$as_me:$LINENO: checking whether file_fsync() wants 3 args" >&5 +$as_echo_n "checking whether file_fsync() wants 3 args... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + file_fsync(NULL, NULL, 0); + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_3ARGS_FILE_FSYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + + if test "x$AWK" != xgawk; then diff --git a/include/linux/file_compat.h b/include/linux/file_compat.h index d30e90356d..b03373ebdc 100644 --- a/include/linux/file_compat.h +++ b/include/linux/file_compat.h @@ -29,5 +29,32 @@ #include #endif +static inline struct file * +spl_filp_open(const char *name, int flags, int mode, int *err) +{ + struct file *filp = NULL; + int rc; + + filp = filp_open(name, flags, mode); + if (IS_ERR(filp)) { + rc = PTR_ERR(filp); + if (err) + *err = rc; + filp = NULL; + } + return filp; +} + +#define spl_filp_close(f) filp_close(f, NULL) +#define spl_filp_poff(f) (&(f)->f_pos) +#define spl_filp_write(fp, b, s, p) (fp)->f_op->write((fp), (b), (s), p) + +#ifdef HAVE_3ARGS_FILE_FSYNC +#define spl_filp_fsync(fp, sync) (fp)->f_op->fsync((fp), \ + (fp)->f_dentry, sync) +#else +#define spl_filp_fsync(fp, sync) (fp)->f_op->fsync((fp), sync) +#endif + #endif /* SPL_FILE_COMPAT_H */ diff --git a/module/spl/spl-debug.c b/module/spl/spl-debug.c index 6a10862412..75778752b0 100644 --- a/module/spl/spl-debug.c +++ b/module/spl/spl-debug.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -902,28 +903,6 @@ put_pages_back(struct page_collection *pc) put_pages_back_on_all_cpus(pc); } -static struct file * -trace_filp_open (const char *name, int flags, int mode, int *err) -{ - struct file *filp = NULL; - int rc; - - filp = filp_open(name, flags, mode); - if (IS_ERR(filp)) { - rc = PTR_ERR(filp); - printk(KERN_ERR "SPL: Can't open %s file: %d\n", name, rc); - if (err) - *err = rc; - filp = NULL; - } - return filp; -} - -#define trace_filp_write(fp, b, s, p) (fp)->f_op->write((fp), (b), (s), p) -#define trace_filp_fsync(fp) (fp)->f_op->fsync((fp),(fp)->f_dentry,1) -#define trace_filp_close(f) filp_close(f, NULL) -#define trace_filp_poff(f) (&(f)->f_pos) - static int spl_debug_dump_all_pages(dumplog_priv_t *dp, char *filename) { @@ -936,7 +915,7 @@ spl_debug_dump_all_pages(dumplog_priv_t *dp, char *filename) down_write(&trace_sem); - filp = trace_filp_open(filename, O_CREAT|O_EXCL|O_WRONLY|O_LARGEFILE, + filp = spl_filp_open(filename, O_CREAT|O_EXCL|O_WRONLY|O_LARGEFILE, 0600, &rc); if (filp == NULL) { if (rc != -EEXIST) @@ -958,8 +937,8 @@ spl_debug_dump_all_pages(dumplog_priv_t *dp, char *filename) list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) { __ASSERT_TAGE_INVARIANT(tage); - rc = trace_filp_write(filp, page_address(tage->page), - tage->used, trace_filp_poff(filp)); + rc = spl_filp_write(filp, page_address(tage->page), + tage->used, spl_filp_poff(filp)); if (rc != (int)tage->used) { printk(KERN_WARNING "SPL: Wanted to write %u " "but wrote %d\n", tage->used, rc); @@ -973,11 +952,11 @@ spl_debug_dump_all_pages(dumplog_priv_t *dp, char *filename) set_fs(oldfs); - rc = trace_filp_fsync(filp); + rc = spl_filp_fsync(filp, 1); if (rc) printk(KERN_ERR "SPL: Unable to sync: %d\n", rc); close: - trace_filp_close(filp); + spl_filp_close(filp); out: up_write(&trace_sem); diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c index b5c34fbcd0..c67fc4c7fc 100644 --- a/module/spl/spl-vnode.c +++ b/module/spl/spl-vnode.c @@ -473,7 +473,7 @@ int vn_fsync(vnode_t *vp, int flags, void *x3, void *x4) if (flags & FDSYNC) datasync = 1; - RETURN(-file_fsync(vp->v_file, vp->v_file->f_dentry, datasync)); + RETURN(-spl_filp_fsync(vp->v_file, datasync)); } /* vn_fsync() */ EXPORT_SYMBOL(vn_fsync); diff --git a/spl_config.h.in b/spl_config.h.in index 5ed1991f99..8d57a63ea2 100644 --- a/spl_config.h.in +++ b/spl_config.h.in @@ -18,6 +18,9 @@ /* vfs_unlink() wants 2 args */ #undef HAVE_2ARGS_VFS_UNLINK +/* file_fsync() wants 3 args */ +#undef HAVE_3ARGS_FILE_FSYNC + /* INIT_WORK wants 3 args */ #undef HAVE_3ARGS_INIT_WORK