Whamcloud - gitweb
LU-18626 mdd: allow chgrp with read-only permissions 17/57717/4
authorMax Wang <wamax@amazon.com>
Fri, 10 Jan 2025 23:39:09 +0000 (23:39 +0000)
committerOleg Drokin <green@whamcloud.com>
Sun, 2 Feb 2025 06:30:23 +0000 (06:30 +0000)
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 <wamax@amazon.com>
Change-Id: I6c4b73d1d48cb2ffc4866ab2e03a86a6c723e960
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57717
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mdd/mdd_object.c
lustre/tests/sanity.sh

index 8ddeec4..cdd1245 100644 (file)
@@ -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);
                }
index 266a27d..8b8ec22 100755 (executable)
@@ -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