From ee47ed2491e08ab293dfa2675d7d015bdb9b1031 Mon Sep 17 00:00:00 2001 From: Max Wang Date: Fri, 10 Jan 2025 23:39:09 +0000 Subject: [PATCH] LU-18626 mdd: allow chgrp with read-only permissions In patch LU-11303, chgrp was modified to be asynchronous and updates the quotas. However, this resulted in chgrp calls failing for file owners with read-only permissions. This commit relaxes the permission requirements for quota updates for chgrp calls to allow read-only permissions. Fixes: 83f5544d8518 ("LU-11303 quota: enforce block quota for chgrp") Test-Parameters: testlist=pjdfstest Signed-off-by: Max Wang Change-Id: I6c4b73d1d48cb2ffc4866ab2e03a86a6c723e960 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57717 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_object.c | 10 +++++++++- lustre/tests/sanity.sh | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 8ddeec4..cdd1245 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -889,8 +889,16 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, if (!((flags & MDS_OWNEROVERRIDE) && (uc->uc_fsuid == oattr->la_uid)) && !(flags & MDS_PERM_BYPASS)) { + int mask = MAY_WRITE; + + /* for chgrp, allow the update with + * read-only permissions + */ + if (S_ISREG(oattr->la_mode) && la->la_valid & LA_GID && + la->la_gid != oattr->la_gid) + mask = MAY_READ; rc = mdd_permission_internal(env, obj, oattr, - MAY_WRITE); + mask); if (rc != 0) RETURN(rc); } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 266a27d..8b8ec22 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -376,6 +376,21 @@ test_6h() { # bug 7331 } run_test 6h "$RUNAS chown RUNAS_ID.0 .../$tfile (should return error)" +test_6i() { + (( MDS1_VERSION >= $(version_code 2.16.51) )) || + skip "Need MDS version at least 2.16.51" + (( $RUNAS_ID != $UID )) || skip_env "RUNAS_ID = UID = $UID" + + touch $DIR/$tfile + chmod 444 $DIR/$tfile + chown $RUNAS_ID $DIR/$tfile || error "initial chown failed" + $RUNAS -u $RUNAS_ID -g $RUNAS_ID chgrp $RUNAS_ID $DIR/$tfile || + error "chgrp $RUNAS_ID $file failed" + $CHECKSTAT -t file -u \#$RUNAS_ID -g \#$RUNAS_ID $DIR/$tfile || + error "$tfile should be owned by GID $RUNAS_ID" +} +run_test 6i "touch+chmod+chgrp $tfile; chgrp read-only file should succeed" + test_7a() { test_mkdir $DIR/$tdir $MCREATE $DIR/$tdir/$tfile -- 1.8.3.1