From d91b78a44e2a9ab41868d685fab53973d32bbf76 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Mon, 24 Oct 2016 16:37:04 +0800 Subject: [PATCH] LU-8749 osd-ldiskfs: inherit S_ISGID correctly For remote directory S_ISGID is inherited on agent, not where file resides, and also the group inherited from parent. Update sanity 6g to test this. Signed-off-by: Lai Siyao Change-Id: I159b2687ad00fdc7c35f60a18668a015240a1953 Reviewed-on: http://review.whamcloud.com/23329 Tested-by: Jenkins Reviewed-by: Niu Yawei Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_handler.c | 27 +++++++++++++++------------ lustre/tests/sanity.sh | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index b6a8710..ee0284b 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2735,22 +2735,22 @@ enum { }; static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj, - struct lu_attr *attr, - struct dt_allocation_hint *hint, - struct dt_object_format *dof, - struct thandle *th) + struct lu_attr *attr, + struct dt_allocation_hint *hint, + struct dt_object_format *dof, + struct thandle *th) { - int result; - struct osd_thandle *oth; - __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX)); + int result; + struct osd_thandle *oth; + __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX | S_ISGID)); - LASSERT(S_ISDIR(attr->la_mode)); + LASSERT(S_ISDIR(attr->la_mode)); - oth = container_of(th, struct osd_thandle, ot_super); - LASSERT(oth->ot_handle->h_transaction != NULL); - result = osd_mkfile(info, obj, mode, hint, th); + oth = container_of(th, struct osd_thandle, ot_super); + LASSERT(oth->ot_handle->h_transaction != NULL); + result = osd_mkfile(info, obj, mode, hint, th); - return result; + return result; } static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj, @@ -3375,6 +3375,9 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, RETURN(local); } + /* restore i_gid in case S_ISGID is set, we will inherit S_ISGID and set + * correct gid on remote file, not agent here */ + local->i_gid = current_fsgid(); ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NOSCRUB); unlock_new_inode(local); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 3ff73da..f8590ee 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -264,6 +264,21 @@ test_6g() { test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed" $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir || error "$tdir/d/subdir should be GID $RUNAS_GID" + if [[ $MDSCOUNT -gt 1 ]]; then + # check remote dir sgid inherite + $LFS mkdir -i 0 $DIR/$tdir.local || + error "mkdir $tdir.local failed" + chmod g+s $DIR/$tdir.local || + error "chmod $tdir.local failed" + chgrp $RUNAS_GID $DIR/$tdir.local || + error "chgrp $tdir.local failed" + $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote || + error "mkdir $tdir.remote failed" + $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote || + error "$tdir.remote should be owned by $UID.$RUNAS_ID" + $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote || + error "$tdir.remote should be mode 02755" + fi } run_test 6g "Is new dir in sgid dir inheriting group?" -- 1.8.3.1