From 12e5cad73349255032c1f4b7e6d484fbf5a23c1d Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 10 Jul 2012 07:34:53 -0400 Subject: [PATCH] Linux 3.5 compatibility: miscellaneous changes torvalds/linux@b0b0382bb4904965a9e9fca77ad87514dfda0d1c changed export_operations->encode_fn() to use struct inode * instead of struct dentry * torvalds/linux@dbd5768f87ff6fb0a4fe09c4d7b6c4a24de99430 renamed end_writeback() to clear_inode() torvalds/linux@17cf28afea2a1112f240a3a2da8af883be024811 removed inode_operations->truncate_range(). The file hole punching functionality is provided by inode_operations->fallocate() Closes zfsonlinux/zfs#784 Signed-off-by: Richard Yao --- config/kernel-clear-inode.m4 | 13 +++++++++++++ config/kernel-encode_fh-inode.m4 | 23 +++++++++++++++++++++++ config/kernel-truncate-range.m4 | 26 ++++++++++++++++++++++++++ config/kernel.m4 | 3 +++ module/zfs/zpl_export.c | 7 ++++++- module/zfs/zpl_inode.c | 4 ++++ module/zfs/zpl_super.c | 5 +++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 config/kernel-clear-inode.m4 create mode 100644 config/kernel-encode_fh-inode.m4 create mode 100644 config/kernel-truncate-range.m4 diff --git a/config/kernel-clear-inode.m4 b/config/kernel-clear-inode.m4 new file mode 100644 index 000000000000..bedfc519b685 --- /dev/null +++ b/config/kernel-clear-inode.m4 @@ -0,0 +1,13 @@ +dnl # +dnl # 3.5.0 API change +dnl # torvalds/linux@90324cc1b11a211e37eabd8cb863e1a1561d6b1d renamed +dnl # end_writeback() to clear_inode(). +dnl # +AC_DEFUN([ZFS_AC_KERNEL_CLEAR_INODE], [ + ZFS_CHECK_SYMBOL_EXPORT( + [clear_inode], + [fs/inode.c], + [AC_DEFINE(HAVE_CLEAR_INODE, 1, + [clear_inode() is available])], + []) +]) diff --git a/config/kernel-encode_fh-inode.m4 b/config/kernel-encode_fh-inode.m4 new file mode 100644 index 000000000000..e4d448d973a1 --- /dev/null +++ b/config/kernel-encode_fh-inode.m4 @@ -0,0 +1,23 @@ +dnl # +dnl # 3.5.0 API change # +dnl # torvalds/linux@b0b0382bb4904965a9e9fca77ad87514dfda0d1c changed the header +dnl # to use struct inode * instead of struct dentry * +dnl # +AC_DEFUN([ZFS_AC_KERNEL_EXPORT_ENCODE_FH_WITH_INODE_PARAMETER], [ + AC_MSG_CHECKING([export_operations->encodefh()]) + ZFS_LINUX_TRY_COMPILE([ + #include + ],[ + int (*encode_fh)(struct inode *, __u32 *fh, int *, struct inode *) = NULL; + struct export_operations export_ops = { + .encode_fh = encode_fh, + }; + export_ops.encode_fh(0, 0, 0, 0); + ],[ + AC_MSG_RESULT(uses struct inode * as first parameter) + AC_DEFINE(HAVE_EXPORT_ENCODE_FH_WITH_INODE_PARAMETER, 1, + [fhfn() uses struct inode *]) + ],[ + AC_MSG_RESULT(does not use struct inode * as first parameter) + ]) +]) diff --git a/config/kernel-truncate-range.m4 b/config/kernel-truncate-range.m4 new file mode 100644 index 000000000000..1f23d6a7aad0 --- /dev/null +++ b/config/kernel-truncate-range.m4 @@ -0,0 +1,26 @@ +dnl # +dnl # 3.5.0 API change # +dnl # torvalds/linux@17cf28afea2a1112f240a3a2da8af883be024811 removed +dnl # truncate_range(). The file hole punching functionality is provided by +dnl # fallocate() +dnl # +AC_DEFUN([ZFS_AC_KERNEL_INODE_TRUNCATE_RANGE], [ + AC_MSG_CHECKING([inode_operations->truncate_range() exists]) + ZFS_LINUX_TRY_COMPILE([ + #include + ],[ + void (*tr)(struct inode *, loff_t, loff_t) = NULL; + struct inode_operations inode_ops = { + .truncate_range = tr, + }; + inode_ops.truncate_range(0, 0, 0); + + + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_INODE_TRUNCATE_RANGE, 1, + [inode_operations->truncate_range() exists]) + ],[ + AC_MSG_RESULT(no) + ]) +]) diff --git a/config/kernel.m4 b/config/kernel.m4 index 7f07c90638c4..752a7dfd3335 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -59,6 +59,9 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ ZFS_AC_KERNEL_BDI ZFS_AC_KERNEL_BDI_SETUP_AND_REGISTER ZFS_AC_KERNEL_SET_NLINK + ZFS_AC_KERNEL_EXPORT_ENCODE_FH_WITH_INODE_PARAMETER + ZFS_AC_KERNEL_INODE_TRUNCATE_RANGE + ZFS_AC_KERNEL_CLEAR_INODE AS_IF([test "$LINUX_OBJ" != "$LINUX"], [ KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ" diff --git a/module/zfs/zpl_export.c b/module/zfs/zpl_export.c index f82ee30887fc..ab6e6d28a6ed 100644 --- a/module/zfs/zpl_export.c +++ b/module/zfs/zpl_export.c @@ -30,10 +30,15 @@ static int +#ifdef HAVE_EXPORT_ENCODE_FH_WITH_INODE_PARAMETER +zpl_encode_fh(struct inode *ip, __u32 *fh, int *max_len, struct inode *parent) +{ +#else zpl_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, int connectable) { - fid_t *fid = (fid_t *)fh; struct inode *ip = dentry->d_inode; +#endif + fid_t *fid = (fid_t *)fh; int len_bytes, rc; len_bytes = *max_len * sizeof (__u32); diff --git a/module/zfs/zpl_inode.c b/module/zfs/zpl_inode.c index 1f6169b755fd..51202e77062f 100644 --- a/module/zfs/zpl_inode.c +++ b/module/zfs/zpl_inode.c @@ -329,6 +329,7 @@ zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) return (error); } +#ifdef HAVE_INODE_TRUNCATE_RANGE static void zpl_truncate_range(struct inode* ip, loff_t start, loff_t end) { @@ -355,6 +356,7 @@ zpl_truncate_range(struct inode* ip, loff_t start, loff_t end) crfree(cr); } +#endif #ifdef HAVE_INODE_FALLOCATE static long @@ -380,7 +382,9 @@ const struct inode_operations zpl_inode_operations = { .getxattr = generic_getxattr, .removexattr = generic_removexattr, .listxattr = zpl_xattr_list, +#ifdef HAVE_INODE_TRUNCATE_RANGE .truncate_range = zpl_truncate_range, +#endif /* HAVE_INODE_TRUNCATE_RANGE */ #ifdef HAVE_INODE_FALLOCATE .fallocate = zpl_fallocate, #endif /* HAVE_INODE_FALLOCATE */ diff --git a/module/zfs/zpl_super.c b/module/zfs/zpl_super.c index 98d0a03127de..c2aac3504cdc 100644 --- a/module/zfs/zpl_super.c +++ b/module/zfs/zpl_super.c @@ -75,7 +75,12 @@ static void zpl_evict_inode(struct inode *ip) { truncate_setsize(ip, 0); +#ifdef HAVE_CLEAR_INODE + clear_inode(ip); +#else end_writeback(ip); + +#endif zfs_inactive(ip); }