Whamcloud - gitweb
LU-12787 tests: skip project quota if it is disabled
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
index c057769..4689018 100755 (executable)
@@ -20,7 +20,7 @@ ALWAYS_EXCEPT+="                55"
 # Test duration:                   30 min
 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
 
-if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
+if [ "$mds1_FSTYPE" = zfs ]; then
        # bug number:                        LU-2887
        # Test duration:                     21      9 min"
        [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a     9"
@@ -44,10 +44,10 @@ require_dsh_mds || exit 0
 require_dsh_ost || exit 0
 
 # Does e2fsprogs support quota feature?
-if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
+if [ "$mds1_FSTYPE" == ldiskfs ] &&
        do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
                grep -q 'quota'"; then
-       skip_env "e2fsprogs doesn't support quota" && exit 0
+       skip_env "e2fsprogs doesn't support quota"
 fi
 
 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
@@ -138,6 +138,7 @@ quota_scan() {
                        xargs stat 2>/dev/null)
        fi
 
+       is_project_quota_supported || return 0
        if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
                $LFS quota -v -p $TSTPRJID $DIR
                log "Files for project ($TSTPRJID):"
@@ -412,13 +413,23 @@ quota_show_check() {
 
 project_quota_enabled () {
        local rc=0
-       for num in $(seq $MDSCOUNT); do
-               do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
-                       grep -q project || rc=1
-       done
-       for num in $(seq $OSTCOUNT); do
-               do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
-                       grep -q project || rc=1
+       local zfeat="feature@project_quota"
+
+       for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
+               local facet_fstype=${facet:0:3}1_FSTYPE
+               local devname
+
+               if [ "${!facet_fstype}" = "zfs" ]; then
+                       devname=$(zpool_name ${facet})
+                       do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
+                               grep -wq active || rc=1
+               else
+                       [ ${facet:0:3} == "mds" ] &&
+                               devname=$(mdsdevname ${facet:3}) ||
+                               devname=$(ostdevname ${facet:3})
+                       do_facet ${facet} $DEBUGFS -R features $devname |
+                               grep -q project || rc=1
+               fi
        done
        [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
        return $rc
@@ -428,9 +439,13 @@ 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
 }
 
@@ -455,15 +470,15 @@ test_quota_performance() {
        local etime=$(date +%s)
        delta=$((etime - stime))
        if [ $delta -gt 0 ]; then
-           rate=$((size * 1024 / delta))
-           if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
-               # LU-2872 - see LU-2887 for fix
-               [ $rate -gt 64 ] ||
-                       error "SLOW IO for $TSTUSR (user): $rate KB/sec"
-           else
-               [ $rate -gt 1024 ] ||
-                       error "SLOW IO for $TSTUSR (user): $rate KB/sec"
-           fi
+               rate=$((size * 1024 / delta))
+               if [ "$mds1_FSTYPE" = zfs ]; then
+                       # LU-2872 - see LU-2887 for fix
+                       [ $rate -gt 64 ] ||
+                               error "SLOW IO for $TSTUSR (user): $rate KB/sec"
+               else
+                       [ $rate -gt 1024 ] ||
+                               error "SLOW IO for $TSTUSR (user): $rate KB/sec"
+               fi
        fi
        rm -f $TESTFILE
 }
@@ -955,7 +970,7 @@ test_4a() {
        $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
                error "set user quota failed"
 
-       [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
+       [ "$mds1_FSTYPE" = zfs ] && GRACE=20
 
        test_file_soft $TESTFILE $LIMIT $GRACE "u"
 
@@ -1134,6 +1149,19 @@ test_6() {
                error "write $TESTFILE failure, expect success"
        $RUNAS2 $DD of=$TESTFILE2 count=1 ||
                error "write $TESTFILE2 failure, expect success"
+
+       if at_is_enabled; then
+               at_max_saved=$(at_max_get ost1)
+               at_max_set $TIMEOUT ost1
+
+               # write to enforced ID ($TSTUSR) to exceed limit to make sure
+               # DQACQ is sent, which makes at_max to take effect
+               $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
+                                                               conv=notrunc
+               rm -f $TESTFILE
+               wait_delete_completed
+       fi
+
        sync; sync
        sync_all_data || true
 
@@ -1141,11 +1169,6 @@ test_6() {
        #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
        lustre_fail mds 0x513 601
 
-       if at_is_enabled; then
-               at_max_saved=$(at_max_get ost1)
-               at_max_set $TIMEOUT ost1
-       fi
-
        do_facet ost1 $LCTL set_param \
                        osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
 
@@ -1174,7 +1197,7 @@ test_6() {
 
        # no watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+       watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
                        { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
 
@@ -1357,7 +1380,7 @@ test_7c() {
        # enable ost quota
        set_ost_qtype $QTYPE || error "enable ost quota failed"
        # trigger reintegration
-       local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
+       local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
        procf=${procf}quota_slave.force_reint
        do_facet ost1 $LCTL set_param $procf=1 ||
                error "force reintegration failed"
@@ -1426,7 +1449,7 @@ test_7e() {
 
        # LU-2435: skip this quota test if underlying zfs version has not
        # supported native dnode accounting
-       [ "$(facet_fstype mds1)" == "zfs" ] && {
+       [ "$mds1_FSTYPE" == zfs ] && {
                local F="feature@userobj_accounting"
                local pool=$(zpool_name mds1)
                local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
@@ -1967,7 +1990,7 @@ test_18() {
 
        # check if watchdog is triggered
        do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
-       local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
+       local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
                        { print; }' $TMP/lustre-log-${TESTNAME}.log)
        [ -z "$watchdog" ] || error "$watchdog"
        rm -f $TMP/lustre-log-${TESTNAME}.log
@@ -2210,7 +2233,7 @@ test_23_sub() {
 }
 
 test_23() {
-       [ $(facet_fstype ost1) == "zfs" ] &&
+       [ "$ost1_FSTYPE" == zfs ] &&
                skip "Overwrite in place is not guaranteed to be " \
                "space neutral on ZFS"
 
@@ -2280,8 +2303,8 @@ test_27b() { # b20200
                $SHOW_QUOTA_PROJID ||
                        error "lfs quota failed with projid argument"
        fi
-       resetquota -u $TSTUSR
-       resetquota -g $TSTUSR
+       resetquota -u $TSTID
+       resetquota -g $TSTID
        resetquota -p $TSTPRJID
        return 0
 }
@@ -2651,7 +2674,7 @@ run_test 35 "Usage is still accessible across reboot"
 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
 # LU-5006
 test_37() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
                skip "Old server doesn't have LU-5006 fix."
 
        setup_quota_test || error "setup quota failed with $?"
@@ -2683,7 +2706,7 @@ run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
 
 # LU-8801
 test_38() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
                skip "Old server doesn't have LU-8801 fix."
 
        [ "$UID" != 0 ] && skip_env "must run as root" && return
@@ -2712,7 +2735,7 @@ test_38() {
        cancel_lru_locks osc
        sync; sync_all_data || true
 
-       local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
+       local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
        procf=${procf}.quota_slave.acct_user
        local accnt_cnt
 
@@ -2976,7 +2999,7 @@ test_54() {
 run_test 54 "basic lfs project interface test"
 
 test_55() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
                skip "Not supported before 2.10.58."
        setup_quota_test || error "setup quota failed with $?"
 
@@ -3061,7 +3084,7 @@ test_57() {
 run_test 57 "lfs project could tolerate errors"
 
 test_59() {
-       [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
+       [ "$mds1_FSTYPE" != ldiskfs ] &&
                skip "ldiskfs only test"
        disable_project_quota
        setup_quota_test || error "setup quota failed with $?"
@@ -3108,7 +3131,7 @@ run_test 60 "Test quota for root with setgid"
 
 # test default quota
 test_default_quota() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
                skip "Not supported before 2.11.51."
 
        local qtype=$1
@@ -3303,8 +3326,8 @@ test_62() {
 run_test 62 "Project inherit should be only changed by root"
 
 test_dom() {
-       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
-               skip "Not supported before 2.11.55" && return
+       [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
+               skip "Not supported before 2.11.55"
 
        local qtype=$1
        local qid=$TSTUSR
@@ -3433,6 +3456,80 @@ test_64() {
 }
 run_test 64 "lfs project on symlink files should fail"
 
+test_65() {
+       local SIZE=10 #10M
+       local TESTFILE="$DIR/$tdir/$tfile-0"
+
+       setup_quota_test || error "setup quota failed with $?"
+       set_ost_qtype $QTYPE || error "enable ost quota failed"
+       quota_init
+
+       echo "Write..."
+       $RUNAS $DD of=$TESTFILE count=$SIZE ||
+               error "failed to write"
+       # flush cache, ensure noquota flag is set on client
+       cancel_lru_locks osc
+       sync; sync_all_data || true
+
+       local quota_u=$($LFS quota -u $TSTUSR $DIR)
+       local quota_g=$($LFS quota -g $TSTUSR $DIR)
+       local quota_all=$($RUNAS $LFS quota $DIR)
+
+       [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
+               error "usr quota not match"
+       [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
+               error "grp quota not match"
+
+       rm -f $TESTFILE
+       # cleanup
+       cleanup_quota_test
+}
+run_test 65 "Check lfs quota result"
+
+test_66() {
+       ! is_project_quota_supported &&
+               skip "Project quota is not supported"
+       setup_quota_test || error "setup quota failed with $?"
+       stack_trap cleanup_quota_test EXIT
+       local old=$(do_facet mds1 $LCTL get_param -n \
+                   mdt.*.enable_chprojid_gid | head -1)
+       local testdir=$DIR/$tdir/foo
+
+       do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
+       stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
+               EXIT
+
+       test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
+       chown -R $TSTID:$TSTID $testdir
+       change_project -sp $TSTPRJID $testdir
+       $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
+
+       $RUNAS lfs project -p 0 $testdir/foo &&
+               error "nonroot user should fail to set projid"
+
+       $RUNAS lfs project -C $testdir/foo &&
+               error "nonroot user should fail to clear projid"
+
+       change_project -C $testdir/foo || error "failed to clear project"
+
+       do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
+       $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
+       "failed to set projid with normal user when enable_chprojid_gid=-1"
+
+       $RUNAS lfs project -rC $testdir/ || error \
+"failed to clear project state with normal user when enable_chprojid_gid=-1"
+
+       touch $testdir/bar || error "failed touch $testdir/bar"
+       $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
+       "normal user should not be able to set projid on root owned file"
+
+       change_project -p $TSTPRJID $testdir/bar || error \
+               "root should be able to change its own file's projid"
+
+       cleanup_quota_test
+}
+run_test 66 "nonroot user can not change project state in default"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"