Whamcloud - gitweb
LU-9951 lustre_compat: add wrapper function for posix_acl_update_mode 71/28871/9
authorGu Zheng <gzheng@ddn.com>
Wed, 18 Oct 2017 19:10:53 +0000 (15:10 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 1 Nov 2017 04:57:36 +0000 (04:57 +0000)
posix_acl_update_mode is introduced in kernel 4.9, add the precheck
of it, if not exists, use inline wrapper function instead.

Change-Id: I8a1476d611c387a88efef5d5b8707edf5feacca8
Signed-off-by: Gu Zheng <gzheng@ddn.com>
Reviewed-on: https://review.whamcloud.com/28871
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Jenkins
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_compat.h

index d49a4d2..c2f5038 100644 (file)
@@ -2555,6 +2555,25 @@ vfs_setxattr, [
 ]) # LC_VFS_SETXATTR
 
 #
+# LC_POSIX_ACL_UPDATE_MODE
+#
+# Kernel version 4.9 commit 073931017b49d9458aa351605b43a7e34598caef
+# posix_acl: Clear SGID bit when setting file permissions
+#
+AC_DEFUN([LC_POSIX_ACL_UPDATE_MODE], [
+LB_CHECK_COMPILE([if 'posix_acl_update_mode' exists],
+posix_acl_update_mode, [
+       #include <linux/fs.h>
+       #include <linux/posix_acl.h>
+],[
+       posix_acl_update_mode(NULL, NULL, NULL);
+],[
+       AC_DEFINE(HAVE_POSIX_ACL_UPDATE_MODE, 1,
+               ['posix_acl_update_mode' is available])
+])
+]) # LC_POSIX_ACL_UPDATE_MODE
+
+#
 # LC_IOP_GENERIC_READLINK
 #
 # Kernel version 4.10 commit dfeef68862edd7d4bafe68ef7aeb5f658ef24bb5
@@ -2880,6 +2899,7 @@ AC_DEFUN([LC_PROG_LINUX], [
        # 4.9
        LC_GROUP_INFO_GID
        LC_VFS_SETXATTR
+       LC_POSIX_ACL_UPDATE_MODE
 
        # 4.10
        LC_IOP_GENERIC_READLINK
index ef60f3e..237d7b8 100644 (file)
@@ -480,6 +480,30 @@ __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
 #endif /* HAVE_XATTR_HANDLER_FLAGS */
 #endif /* HAVE_VFS_SETXATTR */
 
+#ifdef HAVE_IOP_SET_ACL
+#ifdef CONFIG_FS_POSIX_ACL
+#ifndef HAVE_POSIX_ACL_UPDATE_MODE
+static inline int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,
+                         struct posix_acl **acl)
+{
+       umode_t mode = inode->i_mode;
+       int error;
+
+       error = posix_acl_equiv_mode(*acl, &mode);
+       if (error < 0)
+               return error;
+       if (error == 0)
+               *acl = NULL;
+       if (!in_group_p(inode->i_gid) &&
+           !capable_wrt_inode_uidgid(inode, CAP_FSETID))
+               mode &= ~S_ISGID;
+       *mode_p = mode;
+       return 0;
+}
+#endif /* HAVE_POSIX_ACL_UPDATE_MODE */
+#endif
+#endif
+
 #ifndef HAVE_IOV_ITER_TRUNCATE
 static inline void iov_iter_truncate(struct iov_iter *i, u64 count)
 {