From 993808978803771748b2c4bb3982baf01482ce5e Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 17 Aug 2021 10:16:41 -0400 Subject: [PATCH] LU-9859 mdd: unwind md_capable() The inline function md_capable() is just a wrapper around cap_raised() which adds little benefit. Lets just remove the use of this wrapper. Change-Id: I1a5f4b2e34b4cf358b52b3fc4bdeff17fdab50c9 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/44580 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Aurelien Degremont Reviewed-by: Arshad Hussain Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- lustre/include/md_object.h | 8 -------- lustre/mdd/mdd_dir.c | 4 ++-- lustre/mdd/mdd_object.c | 20 ++++++++++---------- lustre/mdd/mdd_permission.c | 6 +++--- lustre/mdd/mdd_trans.c | 2 +- 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index 1785744..daa62d8 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -729,13 +729,5 @@ int lu_ucred_global_init(void); void lu_ucred_global_fini(void); -/* capable() is copied from linux kernel! */ -static inline int md_capable(struct lu_ucred *uc, int cap) -{ - if (cap_raised(uc->uc_cap, cap)) - return 1; - return 0; -} - /** @} md */ #endif /* _LINUX_MD_OBJECT_H */ diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 07777ee..fcad947 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -515,7 +515,7 @@ static inline int mdd_is_sticky(const struct lu_env *env, if (cattr->la_uid == uc->uc_fsuid) return 0; - return !md_capable(uc, CAP_FOWNER); + return !cap_raised(uc->uc_cap, CAP_FOWNER); } static int mdd_may_delete_entry(const struct lu_env *env, @@ -2114,7 +2114,7 @@ static int mdd_create_sanity_check(const struct lu_env *env, !lustre_in_group_p(uc, (cattr->la_valid & LA_GID) ? cattr->la_gid : pattr->la_gid) && - !md_capable(uc, CAP_FSETID)) { + !cap_raised(uc->uc_cap, CAP_FSETID)) { cattr->la_mode &= ~S_ISGID; cattr->la_valid |= LA_MODE; } diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index e431fdf..e266977 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -684,7 +684,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, RETURN(0); if (is_project_state_change(oattr, la)) { - if (!md_capable(uc, CAP_SYS_RESOURCE) && + if (!cap_raised(uc->uc_cap, CAP_SYS_RESOURCE) && !lustre_in_group_p(uc, ma->ma_enable_chprojid_gid) && !(ma->ma_enable_chprojid_gid == -1 && mdd_permission_internal(env, obj, oattr, MAY_WRITE))) @@ -726,13 +726,13 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL); if ((uc->uc_fsuid != oattr->la_uid) && - !md_capable(uc, CAP_FOWNER)) + !cap_raised(uc->uc_cap, CAP_FOWNER)) RETURN(-EPERM); /* The IMMUTABLE and APPEND_ONLY flags can * only be changed by the relevant capability. */ if ((oldflags ^ newflags) && - !md_capable(uc, CAP_LINUX_IMMUTABLE)) + !cap_raised(uc->uc_cap, CAP_LINUX_IMMUTABLE)) RETURN(-EPERM); if (!S_ISDIR(oattr->la_mode)) { @@ -757,7 +757,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) && !(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) { if ((uc->uc_fsuid != oattr->la_uid) && - !md_capable(uc, CAP_FOWNER)) { + !cap_raised(uc->uc_cap, CAP_FOWNER)) { rc = mdd_permission_internal(env, obj, oattr, MAY_WRITE); if (rc) @@ -790,7 +790,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, if (la->la_valid & LA_MODE) { if (!(flags & MDS_PERM_BYPASS) && (uc->uc_fsuid != oattr->la_uid) && - !md_capable(uc, CAP_FOWNER)) + !cap_raised(uc->uc_cap, CAP_FOWNER)) RETURN(-EPERM); if (la->la_mode == (umode_t) -1) @@ -802,7 +802,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, /* Also check the setgid bit! */ if (!lustre_in_group_p(uc, (la->la_valid & LA_GID) ? la->la_gid : oattr->la_gid) && - !md_capable(uc, CAP_FSETID)) + !cap_raised(uc->uc_cap, CAP_FSETID)) la->la_mode &= ~S_ISGID; } else { la->la_mode = oattr->la_mode; @@ -814,7 +814,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, la->la_uid = oattr->la_uid; if (((uc->uc_fsuid != oattr->la_uid) || (la->la_uid != oattr->la_uid)) && - !md_capable(uc, CAP_CHOWN)) + !cap_raised(uc->uc_cap, CAP_CHOWN)) RETURN(-EPERM); /* If the user or group of a non-directory has been @@ -840,7 +840,7 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, if (((uc->uc_fsuid != oattr->la_uid) || ((la->la_gid != oattr->la_gid) && !lustre_in_group_p(uc, la->la_gid))) && - !md_capable(uc, CAP_CHOWN)) + !cap_raised(uc->uc_cap, CAP_CHOWN)) RETURN(-EPERM); /* Likewise, if the user or group of a non-directory @@ -1396,11 +1396,11 @@ static int mdd_xattr_sanity_check(const struct lu_env *env, * can write attributes. */ if (S_ISDIR(attr->la_mode) && (attr->la_mode & S_ISVTX) && (uc->uc_fsuid != attr->la_uid) && - !md_capable(uc, CAP_FOWNER)) + !cap_raised(uc->uc_cap, CAP_FOWNER)) RETURN(-EPERM); } else if (strcmp(name, XATTR_NAME_SOM) != 0 && (uc->uc_fsuid != attr->la_uid) && - !md_capable(uc, CAP_FOWNER)) { + !cap_raised(uc->uc_cap, CAP_FOWNER)) { RETURN(-EPERM); } diff --git a/lustre/mdd/mdd_permission.c b/lustre/mdd/mdd_permission.c index b7321aa..81f4f1a 100644 --- a/lustre/mdd/mdd_permission.c +++ b/lustre/mdd/mdd_permission.c @@ -304,12 +304,12 @@ int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, check_capabilities: if (!(may_mask & MAY_EXEC) || (la->la_mode & S_IXUGO) || S_ISDIR(la->la_mode)) - if (md_capable(uc, CAP_DAC_OVERRIDE)) + if (cap_raised(uc->uc_cap, CAP_DAC_OVERRIDE)) RETURN(0); if ((may_mask == MAY_READ) || (S_ISDIR(la->la_mode) && !(may_mask & MAY_WRITE))) - if (md_capable(uc, CAP_DAC_READ_SEARCH)) + if (cap_raised(uc->uc_cap, CAP_DAC_READ_SEARCH)) RETURN(0); CDEBUG(D_SEC, "permission denied, mode %x, fsuid %u, uid %u\n", @@ -353,7 +353,7 @@ int mdd_permission(const struct lu_env *env, struct md_object *pobj, uc = lu_ucred_assert(env); if (cattr->la_uid != uc->uc_fsuid && - !md_capable(uc, CAP_FOWNER)) + !cap_raised(uc->uc_cap, CAP_FOWNER)) rc = -EPERM; } diff --git a/lustre/mdd/mdd_trans.c b/lustre/mdd/mdd_trans.c index a6c5971..6d24c3c 100644 --- a/lustre/mdd/mdd_trans.c +++ b/lustre/mdd/mdd_trans.c @@ -61,7 +61,7 @@ struct thandle *mdd_trans_create(const struct lu_env *env, th = mdd_child_ops(mdd)->dt_trans_create(env, mdd->mdd_child); if (!IS_ERR(th) && uc) - th->th_ignore_quota = !!md_capable(uc, CAP_SYS_RESOURCE); + th->th_ignore_quota = !!cap_raised(uc->uc_cap, CAP_SYS_RESOURCE); return th; } -- 1.8.3.1