Skip to content

Commit

Permalink
Cleanup vn_rename() and vn_remove()
Browse files Browse the repository at this point in the history
zfsonlinux/spl#bcb15891ab394e11615eee08bba1fd85ac32e158 implemented
Linux 3.6+ support by adding duplicate vn_rename and vn_remove
functions. The new ones were cleaner, but the duplicate functions made
the codebase less maintainable. This adds some compatibility shims that
allow us to retire the older vn_rename and vn_remove in favor of the new
ones on old kernels. The result is a net 143 line reduction in lines of
code and a cleaner codebase.

Signed-off-by: Richard Yao <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes openzfs#370
  • Loading branch information
ryao authored and behlendorf committed Aug 13, 2014
1 parent 2fc44f6 commit ec18fe3
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 305 deletions.
96 changes: 28 additions & 68 deletions config/spl-build.m4
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
SPL_AC_TYPE_UINTPTR_T
SPL_AC_2ARGS_REGISTER_SYSCTL
SPL_AC_SHRINKER_CALLBACK
SPL_AC_PATH_IN_NAMEIDATA
SPL_AC_TASK_CURR
SPL_AC_CTL_UNNUMBERED
SPL_AC_CTL_NAME
Expand Down Expand Up @@ -81,9 +80,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [
SPL_AC_KERNEL_FALLOCATE
SPL_AC_SHRINK_DCACHE_MEMORY
SPL_AC_SHRINK_ICACHE_MEMORY
SPL_AC_KERN_PATH_PARENT_HEADER
SPL_AC_KERN_PATH_PARENT_SYMBOL
SPL_AC_KERN_PATH_LOCKED
SPL_AC_KERN_PATH
SPL_AC_CONFIG_KALLSYMS
SPL_AC_CONFIG_ZLIB_INFLATE
SPL_AC_CONFIG_ZLIB_DEFLATE
Expand Down Expand Up @@ -990,28 +987,6 @@ AC_DEFUN([SPL_AC_SHRINKER_CALLBACK],[
EXTRA_KCFLAGS="$tmp_flags"
])

dnl #
dnl # 2.6.25 API change,
dnl # struct path entry added to struct nameidata
dnl #
AC_DEFUN([SPL_AC_PATH_IN_NAMEIDATA],
[AC_MSG_CHECKING([whether struct path used in struct nameidata])
SPL_LINUX_TRY_COMPILE([
#include <linux/namei.h>
],[
struct nameidata nd __attribute__ ((unused));
nd.path.mnt = NULL;
nd.path.dentry = NULL;
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_PATH_IN_NAMEIDATA, 1,
[struct path used in struct nameidata])
],[
AC_MSG_RESULT(no)
])
])

dnl #
dnl # Custom SPL patch may export this system it is not required
dnl #
Expand Down Expand Up @@ -2279,56 +2254,41 @@ AC_DEFUN([SPL_AC_SHRINK_ICACHE_MEMORY],
])

dnl #
dnl # 2.6.39 API compat,
dnl # The path_lookup() function has been renamed to kern_path_parent()
dnl # and the flags argument has been removed. The only behavior now
dnl # offered is that of LOOKUP_PARENT. The spl already always passed
dnl # this flag so dropping the flag does not impact us.
dnl #
AC_DEFUN([SPL_AC_KERN_PATH_PARENT_HEADER], [
SPL_CHECK_SYMBOL_HEADER(
[kern_path_parent],
[int kern_path_parent(const char \*, struct nameidata \*)],
[include/linux/namei.h],
[AC_DEFINE(HAVE_KERN_PATH_PARENT_HEADER, 1,
[kern_path_parent() is available])],
[])
])

dnl #
dnl # 3.1 API compat,
dnl # The kern_path_parent() symbol is no longer exported by the kernel.
dnl # However, it remains the prefered interface and since we still have
dnl # access to the prototype we dynamically lookup the required address.
dnl # 2.6.28 API change
dnl # The kern_path() function has been introduced. We adopt it as the new way
dnl # of looking up paths. When it is not available, we emulate it using the
dnl # older interfaces.
dnl #
AC_DEFUN([SPL_AC_KERN_PATH_PARENT_SYMBOL],
[AC_MSG_CHECKING([whether kern_path_parent() is available])
AC_DEFUN([SPL_AC_KERN_PATH],
[AC_MSG_CHECKING([whether kern_path() is available])
SPL_LINUX_TRY_COMPILE_SYMBOL([
#include <linux/namei.h>
], [
kern_path_parent(NULL, NULL);
], [kern_path_parent], [fs/namei.c], [
int r = kern_path(NULL, 0, NULL);
], [kern_path], [fs/namei.c], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_KERN_PATH_PARENT_SYMBOL, 1,
[kern_path_parent() is available])
AC_DEFINE(HAVE_KERN_PATH, 1,
[kern_path() is available])
], [
AC_MSG_RESULT(no)
])
])
AC_MSG_CHECKING([whether path_lookup() is available])
SPL_LINUX_TRY_COMPILE_SYMBOL([
#include <linux/namei.h>
], [
int r = path_lookup(NULL, 0, NULL);
], [path_lookup], [fs/namei.c], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_KERN_PATH, 1,
[kern_path() is available])
], [
AC_MSG_RESULT(no)
AC_MSG_ERROR([
*** Neither kern_path() nor path_lookup() is available.
*** Please file an issue:
*** https://github.com/zfsonlinux/spl/issues/new])
dnl #
dnl # 3.6 API compat,
dnl # The kern_path_parent() function was replaced by the kern_path_locked()
dnl # function to eliminate all struct nameidata usage outside fs/namei.c.
dnl #
AC_DEFUN([SPL_AC_KERN_PATH_LOCKED], [
SPL_CHECK_SYMBOL_HEADER(
[kern_path_locked],
[struct dentry \*kern_path_locked(const char \*, struct path \*)],
[include/linux/namei.h],
[AC_DEFINE(HAVE_KERN_PATH_LOCKED, 1,
[kern_path_locked() is available])],
[])
])
])
])

dnl #
Expand Down
18 changes: 0 additions & 18 deletions include/linux/file_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,5 @@ spl_filp_fallocate(struct file *fp, int mode, loff_t offset, loff_t len)
#define spl_inode_unlock(ip) (up(&(ip)->i_sem))
#endif /* HAVE_INODE_I_MUTEX */

#ifdef HAVE_KERN_PATH_PARENT_HEADER
# ifndef HAVE_KERN_PATH_PARENT_SYMBOL
typedef int (*kern_path_parent_t)(const char *, struct nameidata *);
extern kern_path_parent_t kern_path_parent_fn;
# define spl_kern_path_parent(path, nd) kern_path_parent_fn(path, nd)
# else
# define spl_kern_path_parent(path, nd) kern_path_parent(path, nd)
# endif /* HAVE_KERN_PATH_PARENT_SYMBOL */
#else
# define spl_kern_path_parent(path, nd) path_lookup(path, LOOKUP_PARENT, nd)
#endif /* HAVE_KERN_PATH_PARENT_HEADER */

#ifdef HAVE_KERN_PATH_LOCKED
typedef struct dentry * (*kern_path_locked_t)(const char *, struct path *);
extern kern_path_locked_t kern_path_locked_fn;
# define spl_kern_path_locked(name, path) kern_path_locked_fn(name, path)
#endif /* HAVE_KERN_PATH_LOCKED */

#endif /* SPL_FILE_COMPAT_H */

9 changes: 0 additions & 9 deletions include/sys/vnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@
#define CREATE_XATTR_DIR 0x04
#define ATTR_NOACLCHECK 0x20

#ifdef HAVE_PATH_IN_NAMEIDATA
# define nd_dentry path.dentry
# define nd_mnt path.mnt
#else
# define nd_dentry dentry
# define nd_mnt mnt
#endif

typedef enum vtype {
VNON = 0,
VREG = 1,
Expand Down Expand Up @@ -194,7 +186,6 @@ extern file_t *vn_getf(int fd);
extern void vn_releasef(int fd);
extern int vn_set_pwd(const char *filename);

int spl_vn_init_kallsyms_lookup(void);
int spl_vn_init(void);
void spl_vn_fini(void);

Expand Down
3 changes: 0 additions & 3 deletions module/spl/spl-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,6 @@ __init spl_init(void)
if ((rc = spl_kmem_init_kallsyms_lookup()))
SGOTO(out10, rc);

if ((rc = spl_vn_init_kallsyms_lookup()))
SGOTO(out10, rc);

printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s\n", SPL_META_VERSION,
SPL_META_RELEASE, SPL_DEBUG_STR);
SRETURN(rc);
Expand Down
Loading

0 comments on commit ec18fe3

Please sign in to comment.