Whamcloud - gitweb
LU-16428 tests: cache is_project_quota_supported result 99/49499/3
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 23 Dec 2022 00:28:14 +0000 (17:28 -0700)
committerOleg Drokin <green@whamcloud.com>
Tue, 14 Feb 2023 06:04:36 +0000 (06:04 +0000)
Rather than is_project_quota_supported() repeatedly checking if the
MDS supports project quota, check the MDS once after mount and then
cache it for the rest of the test run.

In resetquota() there is no need to check is_project_quota_supported()
each time, since this is only called with "-p" when project quota was
previously checked and is enabled.  Also, there is no need to wait 1s
after every quota limit is reset, but rather only once at the end.

Test-Parameters: trivial testlist=sanity-quota mdtcount=4 mdscount=2
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: Id98240e2fcd2e862bb4305961a2946227e3ebbe5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49499
Reviewed-by: Sergey Cheremencev <scherementsev@ddn.com>
Reviewed-by: Alex Deiter <alex.deiter@gmail.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/sanity-quota.sh
lustre/tests/test-framework.sh

index c2fc789..2a422df 100755 (executable)
@@ -66,6 +66,7 @@ export QUOTA_AUTO=0
 check_and_setup_lustre
 
 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
+is_project_quota_supported || echo "project quota not supported/enabled"
 
 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
@@ -108,17 +109,18 @@ FAIL_ON_ERROR=false
 #        resetquota -g groupname
 #       resetquota -p projid
 
+resetquota_one() {
+       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
+               error "clear quota for [type:$1 name:$2] failed"
+}
+
 resetquota() {
-       [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
-       [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
-               error "resetquota: wrong specifier $1 passed"
+       (( "$#" == 2 )) || error "resetquota: wrong number of arguments: '$*'"
+       [[ "$1" == "-u" || "$1" == "-g" || "$1" == "-p" ]] ||
+               error "resetquota: wrong quota type '$1' passed"
 
-       if [ $1 == "-p" ]; then
-               is_project_quota_supported || return 0
-       fi
+       resetquota_one "$1" "$2"
 
-       $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
-               error "clear quota for [type:$1 name:$2] failed"
        # give a chance to slave to release space
        sleep 1
 }
@@ -480,15 +482,17 @@ project_quota_enabled () {
 project_quota_enabled || enable_project_quota
 
 reset_quota_settings() {
-       resetquota -u $TSTUSR
-       resetquota -u $TSTID
-       resetquota -g $TSTUSR
-       resetquota -g $TSTID
-       resetquota -u $TSTUSR2
-       resetquota -u $TSTID2
-       resetquota -g $TSTUSR2
-       resetquota -g $TSTID2
-       resetquota -p $TSTPRJID
+       resetquota_one -u $TSTUSR
+       [[ $(id -u $TSTUSR) == $TSTID ]] || resetquota_one -u $TSTID
+       resetquota_one -g $TSTUSR
+       [[ $(id -g $TSTUSR) == $TSTID ]] || resetquota_one -g $TSTID
+       resetquota_one -u $TSTUSR2
+       [[ $(id -u $TSTUSR2) == $TSTID2 ]] || resetquota_one -u $TSTID2
+       resetquota_one -g $TSTUSR2
+       [[ $(id -g $TSTUSR2) == $TSTID2 ]] || resetquota_one -g $TSTID2
+       is_project_quota_supported && resetquota_one -p $TSTPRJID
+
+       sleep 1
 }
 
 # enable quota debug
@@ -3155,10 +3159,10 @@ test_27b() { # b20200
        if is_project_quota_supported; then
                $SHOW_QUOTA_PROJID ||
                        error "lfs quota failed with projid argument"
+               resetquota_one -p $TSTPRJID
        fi
        resetquota -u $TSTID
        resetquota -g $TSTID
-       resetquota -p $TSTPRJID
        return 0
 }
 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
index 6132d80..39b9c7c 100755 (executable)
@@ -10248,17 +10248,24 @@ verify_yaml_layout() {
 
 is_project_quota_supported() {
        $ENABLE_PROJECT_QUOTAS || return 1
+       [[ -z "$SAVE_PROJECT_SUPPORTED" ]] || return $SAVE_PROJECT_SUPPORTED
+       local save_project_supported=1
 
        [[ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" &&
           $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ]] &&
                do_facet mds1 lfs --list-commands |& grep -q project &&
-                       return 0
+                       save_project_supported=0
 
        [[ "$(facet_fstype $SINGLEMDS)" == "zfs" &&
           $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.10.53) ]] &&
-               do_facet mds1 $ZPOOL get all | grep -q project_quota && return 0
+               do_facet mds1 $ZPOOL get all | grep -q project_quota &&
+                       save_project_supported=0
 
-       return 1
+       # cache state of project quotas once instead of re-checking each time
+       export SAVE_PROJECT_SUPPORTED=$save_project_supported
+       echo "using SAVE_PROJECT_SUPPORTED=$SAVE_PROJECT_SUPPORTED"
+
+       return $save_project_supported
 }
 
 # ZFS project quota enable/disable: