zfsonlinux/zfs-patches/0037-Linux-4.16-compat-use-correct-_dec_and_test.patch
Fabian Grünbichler 7fdf8cc174 revert potentially buggy zap_add change
until investigation of upstream issue[1] is completed.

1: https://github.com/zfsonlinux/zfs/issues/7401
2018-04-09 09:47:38 +02:00

86 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tony Hutter <hutter2@llnl.gov>
Date: Thu, 22 Feb 2018 09:02:06 -0800
Subject: [PATCH] Linux 4.16 compat: use correct *_dec_and_test()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Use refcount_dec_and_test() on 4.16+ kernels, atomic_dec_and_test()
on older kernels. https://lwn.net/Articles/714974/
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes: #7179
Closes: #7211
(cherry picked from commit e5ba614d05bde1e98ba46d5b75cf6b8a0701c2ca)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
include/linux/vfs_compat.h | 6 +++++-
config/kernel-acl-refcount.m4 | 20 ++++++++++++++++++++
config/kernel.m4 | 1 +
3 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 config/kernel-acl-refcount.m4
diff --git a/include/linux/vfs_compat.h b/include/linux/vfs_compat.h
index 7fcf3c055..6347268af 100644
--- a/include/linux/vfs_compat.h
+++ b/include/linux/vfs_compat.h
@@ -288,9 +288,13 @@ zpl_posix_acl_release(struct posix_acl *acl)
{
if ((acl == NULL) || (acl == ACL_NOT_CACHED))
return;
-
+#ifdef HAVE_ACL_REFCOUNT
+ if (refcount_dec_and_test(&acl->a_refcount))
+ zpl_posix_acl_release_impl(acl);
+#else
if (atomic_dec_and_test(&acl->a_refcount))
zpl_posix_acl_release_impl(acl);
+#endif
}
#endif /* HAVE_POSIX_ACL_RELEASE */
diff --git a/config/kernel-acl-refcount.m4 b/config/kernel-acl-refcount.m4
new file mode 100644
index 000000000..43e3c442d
--- /dev/null
+++ b/config/kernel-acl-refcount.m4
@@ -0,0 +1,20 @@
+dnl #
+dnl # 4.16 kernel: check if struct posix_acl acl.a_refcount is a refcount_t.
+dnl # It's an atomic_t on older kernels.
+dnl #
+AC_DEFUN([ZFS_AC_KERNEL_ACL_HAS_REFCOUNT], [
+ AC_MSG_CHECKING([whether posix_acl has refcount_t])
+ ZFS_LINUX_TRY_COMPILE([
+ #include <linux/backing-dev.h>
+ #include <linux/refcount.h>
+ #include <linux/posix_acl.h>
+ ],[
+ struct posix_acl acl;
+ refcount_t *r __attribute__ ((unused)) = &acl.a_refcount;
+ ],[
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_ACL_REFCOUNT, 1, [posix_acl has refcount_t])
+ ],[
+ AC_MSG_RESULT(no)
+ ])
+])
diff --git a/config/kernel.m4 b/config/kernel.m4
index d4a84b2b2..7bb86a96e 100644
--- a/config/kernel.m4
+++ b/config/kernel.m4
@@ -124,6 +124,7 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
ZFS_AC_KERNEL_HAVE_GENERIC_SETXATTR
ZFS_AC_KERNEL_CURRENT_TIME
ZFS_AC_KERNEL_VM_NODE_STAT
+ ZFS_AC_KERNEL_ACL_HAS_REFCOUNT
AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
--
2.14.2