From ec6bdd55bb2128dcf9779017ef9623461afe05f8 Mon Sep 17 00:00:00 2001 From: Gu Zheng Date: Wed, 18 Oct 2017 15:10:53 -0400 Subject: [PATCH] LU-9951 lustre_compat: add wrapper function for posix_acl_update_mode 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 Reviewed-on: https://review.whamcloud.com/28871 Reviewed-by: Wang Shilong Reviewed-by: James Simmons Tested-by: Jenkins Reviewed-by: Dmitry Eremin Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 20 ++++++++++++++++++++ lustre/include/lustre_compat.h | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index d49a4d2..c2f5038 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -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 + #include +],[ + 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 diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index ef60f3e..237d7b8 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -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) { -- 1.8.3.1