3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 # QP exists since this version. Should be finally set before landing.
43 VERSION_WITH_QP="2.13.53"
45 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
46 skip "Needs MDS version $VERSION_WITH_QP or later."
49 require_dsh_mds || exit 0
50 require_dsh_ost || exit 0
52 # Does e2fsprogs support quota feature?
53 if [ "$mds1_FSTYPE" == ldiskfs ] &&
54 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
55 grep -q 'quota'"; then
56 skip_env "e2fsprogs doesn't support quota"
59 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
61 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
66 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 check_and_setup_lustre
71 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
73 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
74 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
75 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
76 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
77 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
80 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
85 local fail_val=${3:-0}
89 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
90 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
91 ost) NODES="$(comma_list $(osts_nodes))";;
94 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
100 lfs project $* || error "lfs project $* failed"
103 RUNAS="runas -u $TSTID -g $TSTID"
104 RUNAS2="runas -u $TSTID2 -g $TSTID2"
105 DD="dd if=/dev/zero bs=1M"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
112 # resetquota -p projid
115 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
116 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
117 error "resetquota: wrong specifier $1 passed"
119 if [ $1 == "-p" ]; then
120 is_project_quota_supported || return 0
123 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
124 error "clear quota for [type:$1 name:$2] failed"
125 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 log "Files for user ($local_id):"
136 ($LFS find --user $local_id $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
140 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
141 $LFS quota -v -g $local_id $DIR
142 log "Files for group ($local_id):"
143 ($LFS find --group $local_id $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
147 is_project_quota_supported || return 0
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
149 $LFS quota -v -p $TSTPRJID $DIR
150 log "Files for project ($TSTPRJID):"
151 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
168 # get quota for a user or a group
169 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
170 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
177 sync_all_data > /dev/null 2>&1 || true
179 [ "$#" != 4 -a "$#" != 5 ] &&
180 error "getquota: wrong number of arguments: $#"
181 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
182 error "getquota: wrong u/g/p specifier $1 passed"
195 *) error "unknown quota parameter $4";;
198 [ ! -z "$5" ] && pool_arg="--pool $5 "
199 [ "$uuid" = "global" ] && uuid=$DIR
201 $LFS quota -v "$1" "$2" $pool_arg $DIR |
202 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
203 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
208 # usage: set_mdt_qtype ugp|u|g|p|none
212 local mdts=$(get_facets MDS)
214 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
215 qtype=$(tr -d 'p' <<<$qtype)
217 if [[ $PERM_CMD == *"set_param -P"* ]]; then
218 do_facet mgs $PERM_CMD \
219 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
221 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
223 # we have to make sure each MDT received config changes
224 for mdt in ${mdts//,/ }; do
226 cmd="$LCTL get_param -n "
227 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
228 cmd=${cmd}.quota_slave.enabled
230 if $(facet_up $mdt); then
231 wait_update_facet $mdt "$cmd" "$qtype" || return 1
238 # usage: set_ost_qtype ugp|u|g|p|none
242 local osts=$(get_facets OST)
244 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
245 qtype=$(tr -d 'p' <<<$qtype)
247 if [[ $PERM_CMD == *"set_param -P"* ]]; then
248 do_facet mgs $PERM_CMD \
249 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
251 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
253 # we have to make sure each OST received config changes
254 for ost in ${osts//,/ }; do
256 cmd="$LCTL get_param -n "
257 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
258 cmd=${cmd}.quota_slave.enabled
260 if $(facet_up $ost); then
261 wait_update_facet $ost "$cmd" "$qtype" || return 1
267 wait_reintegration() {
271 local result="glb[1],slv[1],reint[0]"
276 if [ $ntype == "mdt" ]; then
277 tgts=$(get_facets MDS)
279 tgts=$(get_facets OST)
282 for tgt in ${tgts//,/ }; do
284 cmd="$LCTL get_param -n "
285 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
286 cmd=${cmd}.quota_slave.info
288 if $(facet_up $tgt); then
289 wait_update_facet $tgt "$cmd |
290 grep "$qtype" | awk '{ print \\\$3 }'" \
291 "$result" $max || return 1
301 if [[ "$qtype" =~ "u" ]]; then
302 wait_reintegration "mdt" "user" $max || return 1
305 if [[ "$qtype" =~ "g" ]]; then
306 wait_reintegration "mdt" "group" $max || return 1
309 if [[ "$qtype" =~ "p" ]]; then
310 ! is_project_quota_supported && return 0
311 wait_reintegration "mdt" "project" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "ost" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "ost" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "ost" "project" $max || return 1
339 local extrasleep=${4:-5}
346 *) error "get_grace_time: Invalid quota type: $qtype"
351 echo "Quota info for $pool:"
352 $LFS quota -$qtype $qarg $parg $DIR
357 time=$(lfs quota -$qtype $qarg $parg $DIR|
358 awk 'NR == 3{ print $5 }'| sed 's/s$//')
361 time=$(lfs quota -$qtype $qarg $DIR|
362 awk 'NR == 3{ print $9 }'| sed 's/s$//')
365 error "Unknown quota type: $flavour"
369 # from lfs.c:__sec2str()
370 # const char spec[] = "smhdw";
371 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
372 [[ $time == *m* ]] && time=${time//m/} && time=$((time*60));
373 [[ $time == *h* ]] && time=${time//h/} && time=$((time*60*60));
374 [[ $time == *d* ]] && time=${time//d/} && time=$((time*24*60*60));
375 [[ $time == *w* ]] && time=${time//w/} && time=$((time*7*24*60*60));
377 echo "Sleep through grace ..."
378 [ "$time" == "-" ] &&
379 error "Grace timeout was not set or quota not exceeded"
380 if [ "$time" == "none" ]; then
381 echo "...Grace timeout already expired"
383 let time+=$extrasleep
384 echo "...sleep $time seconds"
390 wait_delete_completed
391 echo "Creating test directory"
392 mkdir $DIR/$tdir || return 1
393 chmod 0777 $DIR/$tdir || return 2
394 # always clear fail_loc in case of fail_loc isn't cleared
395 # properly when previous test failed
396 lustre_fail mds_ost 0
399 cleanup_quota_test() {
400 echo "Delete files..."
402 echo "Wait for unlink objects finished..."
403 wait_delete_completed
404 sync_all_data || true
414 $LFS quota -v -$ugp $qid $DIR
416 if [ "$bf" == "a" -o "$bf" == "b" ]; then
417 usage=$(getquota -$ugp $qid global curspace)
418 if [ -z $usage ]; then
419 quota_error $ugp $qid \
420 "Query block quota failed ($ugp:$qid)."
422 [ $usage -ne 0 ] && quota_log $ugp $qid \
423 "Block quota isn't 0 ($ugp:$qid:$usage)."
427 if [ "$bf" == "a" -o "$bf" == "f" ]; then
428 usage=$(getquota -$ugp $qid global curinodes)
429 if [ -z $usage ]; then
430 quota_error $ugp $qid \
431 "Query file quota failed ($ugp:$qid)."
433 [ $usage -ne 0 ] && quota_log $ugp $qid \
434 "File quota isn't 0 ($ugp:$qid:$usage)."
439 project_quota_enabled () {
441 local zfeat="feature@project_quota"
443 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
444 local facet_fstype=${facet:0:3}1_FSTYPE
447 if [ "${!facet_fstype}" = "zfs" ]; then
448 devname=$(zpool_name ${facet})
449 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
450 grep -wq active || rc=1
452 [ ${facet:0:3} == "mds" ] &&
453 devname=$(mdsdevname ${facet:3}) ||
454 devname=$(ostdevname ${facet:3})
455 do_facet ${facet} $DEBUGFS -R features $devname |
456 grep -q project || rc=1
459 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
463 project_quota_enabled || enable_project_quota
465 reset_quota_settings() {
466 resetquota -u $TSTUSR
468 resetquota -g $TSTUSR
470 resetquota -u $TSTUSR2
471 resetquota -u $TSTID2
472 resetquota -g $TSTUSR2
473 resetquota -g $TSTID2
474 resetquota -p $TSTPRJID
479 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota+trace"
484 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
485 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
486 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
487 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
489 test_quota_performance() {
490 local TESTFILE="$DIR/$tdir/$tfile-0"
491 local size=$1 # in MB
492 local stime=$(date +%s)
493 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
494 quota_error u $TSTUSR "write failure"
495 local etime=$(date +%s)
496 delta=$((etime - stime))
497 if [ $delta -gt 0 ]; then
498 rate=$((size * 1024 / delta))
499 if [ "$mds1_FSTYPE" = zfs ]; then
500 # LU-2872 - see LU-2887 for fix
502 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
504 [ $rate -gt 1024 ] ||
505 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
511 # test basic quota performance b=21696
514 [ "$SLOW" = "no" ] && MB=10
516 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
517 [ $free_space -le $((MB * 1024)) ] &&
518 skip "not enough space ${free_space} KB, " \
519 "required $((MB * 1024)) KB"
520 setup_quota_test || error "setup quota failed with $?"
521 trap cleanup_quota_test EXIT
523 set_ost_qtype "none" || error "disable ost quota failed"
524 test_quota_performance $MB
526 set_ost_qtype $QTYPE || error "enable ost quota failed"
527 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
528 error "set quota failed"
529 test_quota_performance $MB
533 run_test 0 "Test basic quota performance"
535 # usage: test_1_check_write tfile user|group|project
536 test_1_check_write() {
540 local short_qtype=${qtype:0:1}
543 $RUNAS $DD of=$testfile count=$((limit/2)) ||
544 quota_error $short_qtype $TSTUSR \
545 "$qtype write failure, but expect success"
546 log "Write out of block quota ..."
547 # this time maybe cache write, ignore it's failure
548 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
549 # flush cache, ensure noquota flag is set on client
551 sync; sync_all_data || true
552 # sync means client wrote all it's cache, but id doesn't
553 # garantee that slave got new edquot trough glimpse.
554 # so wait a little to be sure slave got it.
556 $RUNAS $DD of=$testfile count=1 seek=$limit &&
557 quota_error $short_qtype $TSTUSR \
558 "user write success, but expect EDQUOT"
561 check_write_fallocate() {
565 local short_qtype=${qtype:0:1}
568 log "Write ${count}MiB Using Fallocate"
569 $RUNAS fallocate -l${count}MiB $testfile ||
570 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
573 sync; sync_all_data || true
577 log "Write ${count}MiB Using Fallocate"
578 $RUNAS fallocate -l${count}MiB $testfile &&
579 quota_error $short_qtype $TSTUSR \
580 "Write success, expect EDQUOT" || true
583 # test block hardlimit
586 local testfile="$DIR/$tdir/$tfile-0"
588 setup_quota_test || error "setup quota failed with $?"
589 trap cleanup_quota_test EXIT
592 set_ost_qtype $QTYPE || error "enable ost quota failed"
595 log "User quota (block hardlimit:$limit MB)"
596 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
597 error "set user quota failed"
599 # make sure the system is clean
600 local used=$(getquota -u $TSTUSR global curspace)
601 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
603 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
604 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
606 test_1_check_write $testfile "user" $limit
609 wait_delete_completed || error "wait_delete_completed failed"
610 sync_all_data || true
611 used=$(getquota -u $TSTUSR global curspace)
612 [ $used -ne 0 ] && quota_error u $TSTUSR \
613 "user quota isn't released after deletion"
614 resetquota -u $TSTUSR
617 log "--------------------------------------"
618 log "Group quota (block hardlimit:$limit MB)"
619 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
620 error "set group quota failed"
622 testfile="$DIR/$tdir/$tfile-1"
623 # make sure the system is clean
624 used=$(getquota -g $TSTUSR global curspace)
625 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
627 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
628 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
630 test_1_check_write $testfile "group" $limit
632 wait_delete_completed || error "wait_delete_completed failed"
633 sync_all_data || true
634 used=$(getquota -g $TSTUSR global curspace)
635 [ $used -ne 0 ] && quota_error g $TSTUSR \
636 "Group quota isn't released after deletion"
637 resetquota -g $TSTUSR
639 if ! is_project_quota_supported; then
640 echo "Project quota is not supported"
645 testfile="$DIR/$tdir/$tfile-2"
646 # make sure the system is clean
647 used=$(getquota -p $TSTPRJID global curspace)
649 error "used space($used) for project $TSTPRJID isn't 0"
652 log "--------------------------------------"
653 log "Project quota (block hardlimit:$limit mb)"
654 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
655 error "set project quota failed"
657 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
658 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
659 change_project -p $TSTPRJID $testfile
661 test_1_check_write $testfile "project" $limit
666 used=$(getquota -p $TSTPRJID global curspace)
667 [ $used -ne 0 ] && quota_error p $TSTPRJID \
668 "project quota isn't released after deletion"
670 resetquota -p $TSTPRJID
672 run_test 1a "Block hard limit (normal use and out of quota)"
676 local global_limit=20 # 100M
677 local testfile="$DIR/$tdir/$tfile-0"
681 setup_quota_test || error "setup quota failed with $?"
682 stack_trap cleanup_quota_test EXIT
685 set_ost_qtype $QTYPE || error "enable ost quota failed"
688 log "User quota (block hardlimit:$global_limit MB)"
689 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
690 error "set user quota failed"
692 pool_add $qpool || error "pool_add failed"
693 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
694 error "pool_add_targets failed"
696 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
697 error "set user quota failed"
699 # make sure the system is clean
700 local used=$(getquota -u $TSTUSR global curspace)
702 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
704 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
706 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
707 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
709 test_1_check_write $testfile "user" $limit
712 wait_delete_completed || error "wait_delete_completed failed"
713 sync_all_data || true
714 used=$(getquota -u $TSTUSR global curspace $qpool)
715 [ $used -ne 0 ] && quota_error u $TSTUSR \
716 "user quota isn't released after deletion"
717 resetquota -u $TSTUSR
720 log "--------------------------------------"
721 log "Group quota (block hardlimit:$global_limit MB)"
722 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
723 error "set group quota failed"
725 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
726 error "set group quota failed"
728 testfile="$DIR/$tdir/$tfile-1"
729 # make sure the system is clean
730 used=$(getquota -g $TSTUSR global curspace $qpool)
731 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
733 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
734 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
736 test_1_check_write $testfile "group" $limit
739 wait_delete_completed || error "wait_delete_completed failed"
740 sync_all_data || true
741 used=$(getquota -g $TSTUSR global curspace $qpool)
742 [ $used -ne 0 ] && quota_error g $TSTUSR \
743 "Group quota isn't released after deletion"
744 resetquota -g $TSTUSR
746 if ! is_project_quota_supported; then
747 echo "Project quota is not supported"
752 testfile="$DIR/$tdir/$tfile-2"
753 # make sure the system is clean
754 used=$(getquota -p $TSTPRJID global curspace $qpool)
756 error "used space($used) for project $TSTPRJID isn't 0"
759 log "--------------------------------------"
760 log "Project quota (block hardlimit:$global_limit mb)"
761 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
762 error "set project quota failed"
764 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
765 error "set project quota failed"
768 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
769 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
770 change_project -p $TSTPRJID $testfile
772 test_1_check_write $testfile "project" $limit
777 used=$(getquota -p $TSTPRJID global curspace)
778 [ $used -eq 0 ] || quota_error p $TSTPRJID \
779 "project quota isn't released after deletion"
781 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
784 local global_limit=20 # 100M
785 local testfile="$DIR/$tdir/$tfile-0"
786 local qpool1="qpool1"
787 local qpool2="qpool2"
790 setup_quota_test || error "setup quota failed with $?"
791 stack_trap cleanup_quota_test EXIT
794 set_ost_qtype $QTYPE || error "enable ost quota failed"
797 log "User quota (block hardlimit:$global_limit MB)"
798 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
799 error "set user quota failed"
801 pool_add $qpool1 || error "pool_add failed"
802 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
803 error "pool_add_targets failed"
805 pool_add $qpool2 || error "pool_add failed"
806 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
807 error "pool_add_targets failed"
809 # create pools without hard limit
810 # initially such case raised several bugs
811 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
812 error "set user quota failed"
814 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
815 error "set user quota failed"
817 # make sure the system is clean
818 local used=$(getquota -u $TSTUSR global curspace)
820 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
822 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
824 test_1_check_write $testfile "user" $global_limit
826 used=$(getquota -u $TSTUSR global curspace $qpool1)
827 echo "qpool1 used $used"
828 used=$(getquota -u $TSTUSR global curspace $qpool2)
829 echo "qpool2 used $used"
832 wait_delete_completed || error "wait_delete_completed failed"
833 sync_all_data || true
835 used=$(getquota -u $TSTUSR global curspace $qpool1)
836 [ $used -ne 0 ] && quota_error u $TSTUSR \
837 "user quota isn't released after deletion"
838 resetquota -u $TSTUSR
843 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
846 local limit1=10 # 10M
847 local limit2=12 # 12M
848 local global_limit=20 # 100M
849 local testfile="$DIR/$tdir/$tfile-0"
850 local qpool1="qpool1"
851 local qpool2="qpool2"
854 setup_quota_test || error "setup quota failed with $?"
855 stack_trap cleanup_quota_test EXIT
858 set_ost_qtype $QTYPE || error "enable ost quota failed"
861 log "User quota (block hardlimit:$global_limit MB)"
862 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
863 error "set user quota failed"
865 pool_add $qpool1 || error "pool_add failed"
866 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
867 error "pool_add_targets failed"
869 pool_add $qpool2 || error "pool_add failed"
870 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
871 error "pool_add_targets failed"
873 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
874 error "set user quota failed"
876 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
877 error "set user quota failed"
879 # make sure the system is clean
880 local used=$(getquota -u $TSTUSR global curspace)
882 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
884 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
886 test_1_check_write $testfile "user" $limit1
888 used=$(getquota -u $TSTUSR global curspace $qpool1)
889 echo "qpool1 used $used"
890 used=$(getquota -u $TSTUSR global curspace $qpool2)
891 echo "qpool2 used $used"
894 wait_delete_completed || error "wait_delete_completed failed"
895 sync_all_data || true
897 used=$(getquota -u $TSTUSR global curspace $qpool1)
898 [ $used -ne 0 ] && quota_error u $TSTUSR \
899 "user quota isn't released after deletion"
900 resetquota -u $TSTUSR
905 run_test 1d "Quota pools: check block hardlimit on different pools"
908 local limit1=10 # 10M
909 local global_limit=200 # 200M
910 local testfile="$DIR/$tdir/$tfile-0"
911 local testfile2="$DIR/$tdir/$tfile-1"
912 local qpool1="qpool1"
915 setup_quota_test || error "setup quota failed with $?"
916 stack_trap cleanup_quota_test EXIT
919 set_ost_qtype $QTYPE || error "enable ost quota failed"
921 # global_limit is much greater than limit1 to get
922 # different qunit's on osts. Since 1st qunit shrinking
923 # on OST1(that belongs to qpool1), this qunit should
925 log "User quota (block hardlimit:$global_limit MB)"
926 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
927 error "set user quota failed"
929 pool_add $qpool1 || error "pool_add failed"
930 pool_add_targets $qpool1 1 1 ||
931 error "pool_add_targets failed"
933 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
934 error "set user quota failed"
936 # make sure the system is clean
937 local used=$(getquota -u $TSTUSR global curspace)
938 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
940 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
941 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
943 test_1_check_write $testfile "user" $limit1
945 $LFS setstripe $testfile2 -c 1 -i 0 ||
946 error "setstripe $testfile2 failed"
947 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
948 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
950 $RUNAS $DD of=$testfile2 count=20 ||
951 quota_error u $TSTUSR \
952 "$qtype write failure, but expect success"
956 wait_delete_completed || error "wait_delete_completed failed"
957 sync_all_data || true
959 used=$(getquota -u $TSTUSR global curspace $qpool1)
960 [ $used -ne 0 ] && quota_error u $TSTUSR \
961 "user quota isn't released after deletion"
962 resetquota -u $TSTUSR
967 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
970 local global_limit=200 # 200M
971 local limit1=10 # 10M
972 local TESTDIR="$DIR/$tdir/"
973 local testfile="$TESTDIR/$tfile-0"
974 local qpool1="qpool1"
977 setup_quota_test || error "setup quota failed with $?"
978 stack_trap cleanup_quota_test EXIT
981 set_ost_qtype $QTYPE || error "enable ost quota failed"
983 log "User quota (block hardlimit:$global_limit MB)"
984 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
985 error "set user quota failed"
987 pool_add $qpool1 || error "pool_add failed"
988 pool_add_targets $qpool1 0 0 ||
989 error "pool_add_targets failed"
991 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
992 error "set user quota failed"
994 # make sure the system is clean
995 local used=$(getquota -u $TSTUSR global curspace)
996 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
998 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1000 test_1_check_write $testfile "user" $limit1
1002 pool_remove_target $qpool1 0
1004 wait_delete_completed || error "wait_delete_completed failed"
1005 sync_all_data || true
1007 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1008 # qunit for appropriate element in lgd array should be set
1009 # correctly(4096). Earlier it was not changed continuing to be 1024.
1010 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1011 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1012 # as it already was 1024. As flag "need_update" for this qunit was
1013 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1014 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1015 # became > 10M. QMT returned EINPROGRESS in a loop.
1016 # Check that it doesn't hung anymore.
1017 test_1_check_write $testfile "user" $limit1
1022 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1025 local limit=20 # 20M
1026 local global_limit=40 # 40M
1027 local testfile="$DIR/$tdir/$tfile-0"
1028 local qpool="qpool1"
1029 local mdmb_param="osc.*.max_dirty_mb"
1030 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1033 setup_quota_test || error "setup quota failed with $?"
1034 stack_trap cleanup_quota_test EXIT
1035 $LCTL set_param $mdmb_param=1
1036 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1039 set_ost_qtype $QTYPE || error "enable ost quota failed"
1042 log "User quota (block hardlimit:$global_limit MB)"
1043 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1044 error "set user quota failed"
1046 pool_add $qpool || error "pool_add failed"
1047 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1048 error "pool_add_targets failed"
1050 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1051 error "set user quota failed"
1053 # make sure the system is clean
1054 local used=$(getquota -u $TSTUSR global curspace)
1056 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1058 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1059 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1062 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1063 quota_error u $TSTUSR \
1064 "$qtype write failure, but expect success"
1065 log "Write out of block quota ..."
1066 # this time maybe cache write, ignore it's failure
1067 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1068 # flush cache, ensure noquota flag is set on client
1069 cancel_lru_locks osc
1070 sync; sync_all_data || true
1072 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1073 quota_error u $TSTUSR \
1074 "user write success, but expect EDQUOT"
1077 wait_delete_completed || error "wait_delete_completed failed"
1078 sync_all_data || true
1080 used=$(getquota -u $TSTUSR global curspace $qpool)
1081 [ $used -ne 0 ] && quota_error u $TSTUSR \
1082 "user quota isn't released after deletion"
1085 run_test 1g "Quota pools: Block hard limit with wide striping"
1088 local limit=10 # 10M
1089 local testfile="$DIR/$tdir/$tfile-0"
1091 [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
1092 [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
1093 skip "Need OST version at least 2.13.53"
1095 setup_quota_test || error "setup quota failed with $?"
1096 trap cleanup_quota_test EXIT
1099 set_ost_qtype $QTYPE || error "enable ost quota failed"
1102 log "User quota (block hardlimit:$limit MB)"
1103 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1104 error "set user quota failed"
1106 # make sure the system is clean
1107 local used=$(getquota -u $TSTUSR global curspace)
1108 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1110 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1111 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1113 check_write_fallocate $testfile "user" $limit
1116 wait_delete_completed || error "wait_delete_completed failed"
1117 sync_all_data || true
1118 used=$(getquota -u $TSTUSR global curspace)
1119 [ $used -ne 0 ] && quota_error u $TSTUSR \
1120 "user quota isn't released after deletion"
1121 resetquota -u $TSTUSR
1123 run_test 1h "Block hard limit test using fallocate"
1125 # test inode hardlimit
1127 local TESTFILE="$DIR/$tdir/$tfile-0"
1128 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1129 qmt.$FSNAME-QMT0000.md-0x0.info |
1130 awk '/least qunit/{ print $3 }')
1131 local L2=$(do_facet mds1 $LCTL get_param -n \
1132 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1134 [ $L2 -le $LIMIT ] || LIMIT=$L2
1136 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1138 local FREE_INODES=$(mdt_free_inodes 0)
1139 echo "$FREE_INODES free inodes on master MDT"
1140 [ $FREE_INODES -lt $LIMIT ] &&
1141 skip "not enough free inodes $FREE_INODES required $LIMIT"
1143 setup_quota_test || error "setup quota failed with $?"
1144 trap cleanup_quota_test EXIT
1147 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1150 log "User quota (inode hardlimit:$LIMIT files)"
1151 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1152 error "set user quota failed"
1154 # make sure the system is clean
1155 local USED=$(getquota -u $TSTUSR global curinodes)
1156 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1158 log "Create $LIMIT files ..."
1159 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1160 quota_error u $TSTUSR "user create failure, but expect success"
1161 log "Create out of file quota ..."
1162 $RUNAS touch ${TESTFILE}_xxx &&
1163 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1166 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1167 rm -f ${TESTFILE}_xxx
1168 wait_delete_completed
1170 USED=$(getquota -u $TSTUSR global curinodes)
1171 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1172 "user quota isn't released after deletion"
1173 resetquota -u $TSTUSR
1176 log "--------------------------------------"
1177 log "Group quota (inode hardlimit:$LIMIT files)"
1178 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1179 error "set group quota failed"
1181 TESTFILE=$DIR/$tdir/$tfile-1
1182 # make sure the system is clean
1183 USED=$(getquota -g $TSTUSR global curinodes)
1184 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1186 log "Create $LIMIT files ..."
1187 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1188 quota_error g $TSTUSR "group create failure, but expect success"
1189 log "Create out of file quota ..."
1190 $RUNAS touch ${TESTFILE}_xxx &&
1191 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1194 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1195 rm -f ${TESTFILE}_xxx
1196 wait_delete_completed
1198 USED=$(getquota -g $TSTUSR global curinodes)
1199 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1200 "user quota isn't released after deletion"
1202 resetquota -g $TSTUSR
1203 ! is_project_quota_supported && cleanup_quota_test &&
1204 echo "Skip project quota is not supported" && return 0
1207 log "--------------------------------------"
1208 log "Project quota (inode hardlimit:$LIMIT files)"
1209 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1210 error "set project quota failed"
1212 TESTFILE=$DIR/$tdir/$tfile-1
1213 # make sure the system is clean
1214 USED=$(getquota -p $TSTPRJID global curinodes)
1216 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1218 change_project -sp $TSTPRJID $DIR/$tdir
1219 log "Create $LIMIT files ..."
1220 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1221 $TSTPRJID "project create fail, but expect success"
1222 log "Create out of file quota ..."
1223 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1224 "project create success, but expect EDQUOT"
1225 change_project -C $DIR/$tdir
1228 USED=$(getquota -p $TSTPRJID global curinodes)
1229 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1230 "project quota isn't released after deletion"
1233 run_test 2 "File hard limit (normal use and out of quota)"
1244 stack_trap cleanup_quota_test EXIT
1246 $LFS setstripe $testfile -c 1 -i 0
1247 chown $TSTUSR.$TSTUSR $testfile
1248 [ "$qtype" == "p" ] && is_project_quota_supported &&
1249 change_project -p $TSTPRJID $testfile
1251 echo "Write up to soft limit"
1252 $RUNAS $DD of=$testfile count=$limit ||
1253 quota_error a $TSTUSR "write failure, but expect success"
1254 OFFSET=$((limit * 1024))
1255 cancel_lru_locks osc
1257 echo "Write to exceed soft limit"
1258 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1259 quota_error a $TSTUSR "write failure, but expect success"
1260 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1261 cancel_lru_locks osc
1263 echo "mmap write when over soft limit"
1264 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1265 quota_error a $TSTUSR "mmap write failure, but expect success"
1266 cancel_lru_locks osc
1271 $SHOW_QUOTA_INFO_USER
1272 $SHOW_QUOTA_INFO_GROUP
1273 $SHOW_QUOTA_INFO_PROJID
1275 echo "Write before timer goes off"
1276 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1277 quota_error a $TSTUSR "write failure, but expect success"
1278 OFFSET=$((OFFSET + 1024))
1279 cancel_lru_locks osc
1281 wait_grace_time $qtype "block" $pool
1286 $SHOW_QUOTA_INFO_USER
1287 $SHOW_QUOTA_INFO_GROUP
1288 $SHOW_QUOTA_INFO_PROJID
1290 log "Write after timer goes off"
1291 # maybe cache write, ignore.
1292 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1293 OFFSET=$((OFFSET + 1024))
1294 cancel_lru_locks osc
1295 log "Write after cancel lru locks"
1296 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1297 quota_error a $TSTUSR "write success, but expect EDQUOT"
1302 $SHOW_QUOTA_INFO_USER
1303 $SHOW_QUOTA_INFO_GROUP
1304 $SHOW_QUOTA_INFO_PROJID
1306 echo "Unlink file to stop timer"
1308 wait_delete_completed
1309 sync_all_data || true
1314 $SHOW_QUOTA_INFO_USER
1315 $SHOW_QUOTA_INFO_GROUP
1316 $SHOW_QUOTA_INFO_PROJID
1318 $LFS setstripe $testfile -c 1 -i 0
1319 chown $TSTUSR.$TSTUSR $testfile
1320 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1323 $RUNAS $DD of=$testfile count=$limit ||
1324 quota_error a $TSTUSR "write failure, but expect success"
1331 local grace=20 # 20s
1332 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1335 local testfile=$DIR/$tdir/$tfile-0
1337 # get minimum soft qunit size
1338 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1339 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1341 set_ost_qtype $QTYPE || error "enable ost quota failed"
1343 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1344 # make sure the system is clean
1345 local used=$(getquota -u $TSTUSR global curspace)
1346 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1348 $LFS setquota -t -u --block-grace $grace --inode-grace \
1349 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1350 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1351 error "set user quota failed"
1353 test_block_soft $testfile $grace $limit "u"
1355 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1356 testfile=$DIR/$tdir/$tfile-1
1357 # make sure the system is clean
1358 used=$(getquota -g $TSTUSR global curspace)
1359 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1361 $LFS setquota -t -g --block-grace $grace --inode-grace \
1362 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1363 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1364 error "set group quota failed"
1366 test_block_soft $testfile $grace $limit "g"
1368 if is_project_quota_supported; then
1369 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1370 testfile=$DIR/$tdir/$tfile-2
1371 # make sure the system is clean
1372 used=$(getquota -p $TSTPRJID global curspace)
1373 [ $used -ne 0 ] && error \
1374 "Used space($used) for project $TSTPRJID isn't 0."
1376 $LFS setquota -t -p --block-grace $grace --inode-grace \
1377 $MAX_IQ_TIME $DIR ||
1378 error "set project grace time failed"
1379 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1380 $DIR || error "set project quota failed"
1382 test_block_soft $testfile $grace $limit "p"
1383 resetquota -p $TSTPRJID
1384 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1385 $MAX_IQ_TIME $DIR ||
1386 error "restore project grace time failed"
1390 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1391 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1392 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1393 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1395 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1398 local grace=20 # 20s
1399 local qpool="qpool1"
1400 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1403 local testfile=$DIR/$tdir/$tfile-0
1406 # get minimum soft qunit size
1407 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1408 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1409 local glbl_limit=$((2*limit))
1410 local glbl_grace=$((2*grace))
1411 echo "limit $limit glbl_limit $glbl_limit"
1412 echo "grace $grace glbl_grace $glbl_grace"
1414 set_ost_qtype $QTYPE || error "enable ost quota failed"
1416 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1417 # make sure the system is clean
1418 local used=$(getquota -u $TSTUSR global curspace)
1419 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1421 pool_add $qpool || error "pool_add failed"
1422 pool_add_targets $qpool 0 1 ||
1423 error "pool_add_targets failed"
1425 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1426 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1427 $LFS setquota -t -u --block-grace $grace \
1428 --pool $qpool $DIR || error "set user grace time failed"
1430 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1431 error "set user quota failed"
1432 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1433 error "set user quota failed"
1435 test_block_soft $testfile $grace $limit "u" $qpool
1437 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1438 testfile=$DIR/$tdir/$tfile-1
1439 # make sure the system is clean
1440 used=$(getquota -g $TSTUSR global curspace)
1441 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1443 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1444 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1445 $LFS setquota -t -g --block-grace $grace \
1446 --pool $qpool $DIR || error "set group grace time failed"
1448 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1449 error "set group quota failed"
1450 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1451 error "set group quota failed"
1453 test_block_soft $testfile $grace $limit "g" $qpool
1455 if is_project_quota_supported; then
1456 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1457 testfile=$DIR/$tdir/$tfile-2
1458 # make sure the system is clean
1459 used=$(getquota -p $TSTPRJID global curspace)
1460 [ $used -ne 0 ] && error \
1461 "Used space($used) for project $TSTPRJID isn't 0."
1463 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1464 $MAX_IQ_TIME $DIR ||
1465 error "set project grace time failed"
1466 $LFS setquota -t -p --block-grace $grace \
1467 --pool $qpool $DIR ||
1468 error "set project grace time failed"
1470 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1471 $DIR || error "set project quota failed"
1472 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1473 --pool $qpool $DIR || error "set project quota failed"
1475 test_block_soft $testfile $grace $limit "p" $qpool
1476 resetquota -p $TSTPRJID
1477 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1478 $MAX_IQ_TIME $DIR ||
1479 error "restore project grace time failed"
1480 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1481 $DIR || error "set project grace time failed"
1485 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1486 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1487 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1488 --pool $qpool $DIR || error "restore user grace time failed"
1489 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1490 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1491 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1492 --pool $qpool $DIR || error "restore group grace time failed"
1494 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1497 local grace=20 # 20s
1498 local qpool="qpool1"
1499 local qpool2="qpool2"
1500 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1503 local testfile=$DIR/$tdir/$tfile-0
1506 # get minimum soft qunit size
1507 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1508 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1509 local limit2=$((limit+4))
1510 local glbl_limit=$((limit+8))
1511 local grace1=$((grace+10))
1513 local glbl_grace=$((grace+20))
1514 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1515 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1517 set_ost_qtype $QTYPE || error "enable ost quota failed"
1519 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1520 # make sure the system is clean
1521 local used=$(getquota -u $TSTUSR global curspace)
1522 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1524 pool_add $qpool || error "pool_add failed"
1525 pool_add_targets $qpool 0 1 ||
1526 error "pool_add_targets failed"
1528 pool_add $qpool2 || error "pool_add failed"
1529 pool_add_targets $qpool2 0 1 ||
1530 error "pool_add_targets failed"
1533 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1534 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1535 $LFS setquota -t -u --block-grace $grace1 \
1536 --pool $qpool $DIR || error "set user grace time failed"
1537 $LFS setquota -t -u --block-grace $grace2 \
1538 --pool $qpool2 $DIR || error "set user grace time failed"
1540 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1541 error "set user quota failed"
1542 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1543 error "set user quota failed"
1544 # qpool has minimum soft limit, but it's grace is grater than
1545 # grace period of qpool2. Thus write shouldn't fail when
1546 # hit qpool soft limit - only when reaches up qpool2 limit
1547 # after grace2 seconds.
1548 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1549 error "set user quota failed"
1551 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1554 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1555 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1556 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1557 --pool $qpool $DIR || error "restore user grace time failed"
1558 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1559 --pool $qpool2 $DIR || error "restore user grace time failed"
1561 run_test 3c "Quota pools: check block soft limit on different pools"
1568 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1569 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1572 trap cleanup_quota_test EXIT
1573 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1575 echo "Create files to exceed soft limit"
1576 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1577 quota_error a $TSTUSR "create failure, but expect success"
1578 local trigger_time=$(date +%s)
1580 sync_all_data || true
1582 local cur_time=$(date +%s)
1583 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1584 error "Passed grace time $grace, $trigger_time, $cur_time"
1586 echo "Create file before timer goes off"
1587 $RUNAS touch ${TESTFILE}_before ||
1588 quota_error a $TSTUSR "failed create before timer expired," \
1589 "but expect success. $trigger_time, $cur_time"
1590 sync_all_data || true
1592 wait_grace_time $qtype "file"
1597 $SHOW_QUOTA_INFO_USER
1598 $SHOW_QUOTA_INFO_GROUP
1599 $SHOW_QUOTA_INFO_PROJID
1601 echo "Create file after timer goes off"
1602 # exceed least soft limit is possible
1603 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1604 quota_error a $TSTUSR "create after timer expired," \
1606 sync_all_data || true
1611 $SHOW_QUOTA_INFO_USER
1612 $SHOW_QUOTA_INFO_GROUP
1613 $SHOW_QUOTA_INFO_PROJID
1615 echo "Unlink files to stop timer"
1616 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1617 wait_delete_completed
1620 $RUNAS touch ${TESTFILE}_xxx ||
1621 quota_error a $TSTUSR "touch after timer stop failure," \
1622 "but expect success"
1623 sync_all_data || true
1631 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1632 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1633 local TESTFILE=$DIR/$tdir/$tfile-0
1636 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1638 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1639 # make sure the system is clean
1640 local USED=$(getquota -u $TSTUSR global curinodes)
1641 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1643 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1644 $GRACE $DIR || error "set user grace time failed"
1645 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1646 error "set user quota failed"
1648 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1650 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1652 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1653 # make sure the system is clean
1654 USED=$(getquota -g $TSTUSR global curinodes)
1655 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1657 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1658 $GRACE $DIR || error "set group grace time failed"
1659 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1660 error "set group quota failed"
1661 TESTFILE=$DIR/$tdir/$tfile-1
1663 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1665 if is_project_quota_supported; then
1666 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1667 # make sure the system is clean
1668 USED=$(getquota -p $TSTPRJID global curinodes)
1669 [ $USED -ne 0 ] && error \
1670 "Used space($USED) for project $TSTPRJID isn't 0."
1672 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1673 $GRACE $DIR || error "set project grace time failed"
1674 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1675 error "set project quota failed"
1677 TESTFILE=$DIR/$tdir/$tfile-1
1678 # one less than limit, because of parent directory included.
1679 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1680 resetquota -p $TSTPRJID
1681 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1682 $MAX_IQ_TIME $DIR ||
1683 error "restore project grace time failed"
1687 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1688 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1689 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1690 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1692 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1695 local GR_STR1="1w3d"
1696 local GR_STR2="1000s"
1698 local GR_STR4="1w2d3h4m5s"
1700 local GR_STR6="18446744073709551615"
1703 wait_delete_completed
1705 # test of valid grace strings handling
1706 echo "Valid grace strings test"
1707 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1708 $GR_STR2 $DIR || error "set user grace time failed"
1709 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1710 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1711 $GR_STR4 $DIR || error "set group grace time quota failed"
1712 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1714 # test of invalid grace strings handling
1715 echo " Invalid grace strings test"
1716 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1717 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1718 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1722 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1723 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1724 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1725 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1727 run_test 4b "Grace time strings handling"
1729 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1731 local BLIMIT=10 # 10M
1732 local ILIMIT=10 # 10 inodes
1734 setup_quota_test || error "setup quota failed with $?"
1735 trap cleanup_quota_test EXIT
1737 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1738 set_ost_qtype $QTYPE || error "enable ost quota failed"
1740 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1741 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1742 error "set user quota failed"
1743 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1744 if is_project_quota_supported; then
1745 error "set group quota failed"
1746 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1747 -I $ILIMIT $DIR || error "set project quota failed"
1750 # make sure the system is clean
1751 local USED=$(getquota -u $TSTUSR global curinodes)
1752 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1753 USED=$(getquota -g $TSTUSR global curinodes)
1754 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1755 USED=$(getquota -u $TSTUSR global curspace)
1756 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1757 USED=$(getquota -g $TSTUSR global curspace)
1758 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1759 if is_project_quota_supported; then
1760 USED=$(getquota -p $TSTPRJID global curinodes)
1762 error "Used inode($USED) for project $TSTPRJID isn't 0."
1763 USED=$(getquota -p $TSTPRJID global curspace)
1765 error "Used block($USED) for project $TSTPRJID isn't 0."
1768 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1769 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1770 error "create failure, expect success"
1771 if is_project_quota_supported; then
1772 touch $DIR/$tdir/$tfile-0_1
1773 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1775 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1776 error "write failure, expect success"
1778 echo "Chown files to $TSTUSR.$TSTUSR ..."
1779 for i in $(seq 0 $ILIMIT); do
1780 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1781 quota_error a $TSTUSR "chown failure, expect success"
1785 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1786 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1789 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1791 # test dropping acquire request on master
1795 # Clear dmesg so watchdog is not triggered by previous
1797 do_facet ost1 dmesg -c > /dev/null
1799 setup_quota_test || error "setup quota failed with $?"
1800 trap cleanup_quota_test EXIT
1802 # make sure the system is clean
1803 local USED=$(getquota -u $TSTUSR global curspace)
1804 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1806 # make sure no granted quota on ost
1807 set_ost_qtype $QTYPE || error "enable ost quota failed"
1808 resetquota -u $TSTUSR
1810 # create file for $TSTUSR
1811 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1812 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1813 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1815 # create file for $TSTUSR2
1816 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1817 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1818 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1820 # cache per-ID lock for $TSTUSR on slave
1821 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1822 error "set quota failed"
1823 $RUNAS $DD of=$TESTFILE count=1 ||
1824 error "write $TESTFILE failure, expect success"
1825 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1826 error "write $TESTFILE2 failure, expect success"
1828 if at_is_enabled; then
1829 at_max_saved=$(at_max_get ost1)
1830 at_max_set $TIMEOUT ost1
1832 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1833 # DQACQ is sent, which makes at_max to take effect
1834 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1837 wait_delete_completed
1841 sync_all_data || true
1843 #define QUOTA_DQACQ 601
1844 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1845 lustre_fail mds 0x513 601
1847 do_facet ost1 $LCTL set_param \
1848 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1850 # write to un-enforced ID ($TSTUSR2) should succeed
1851 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1852 error "write failure, expect success"
1854 # write to enforced ID ($TSTUSR) in background, exceeding limit
1855 # to make sure DQACQ is sent
1856 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1859 # watchdog timer uses a factor of 2
1860 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1861 sleep $((TIMEOUT * 2 + 1))
1863 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1865 # write should be blocked and never finished
1866 if ! ps -p $DDPID > /dev/null 2>&1; then
1868 error "write finished incorrectly!"
1873 # no watchdog is triggered
1874 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1875 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1876 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1877 [ -z "$watchdog" ] || error "$watchdog"
1879 rm -f $TMP/lustre-log-${TESTNAME}.log
1881 # write should continue then fail with EDQUOT
1885 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1886 if [ $count -ge 240 ]; then
1887 quota_error u $TSTUSR "dd not finished in $count secs"
1889 count=$((count + 1))
1890 if [ $((count % 30)) -eq 0 ]; then
1891 c_size=$(stat -c %s $TESTFILE)
1892 echo "Waiting $count secs. $c_size"
1900 run_test 6 "Test dropping acquire request on master"
1902 # quota reintegration (global index)
1904 local TESTFILE=$DIR/$tdir/$tfile
1905 local LIMIT=20 # 20M
1907 [ "$SLOW" = "no" ] && LIMIT=5
1909 setup_quota_test || error "setup quota failed with $?"
1910 trap cleanup_quota_test EXIT
1912 # make sure the system is clean
1913 local USED=$(getquota -u $TSTUSR global curspace)
1914 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1916 # make sure no granted quota on ost1
1917 set_ost_qtype $QTYPE || error "enable ost quota failed"
1918 resetquota -u $TSTUSR
1919 set_ost_qtype "none" || error "disable ost quota failed"
1921 local OSTUUID=$(ostuuid_from_index 0)
1922 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1924 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1927 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1928 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1933 echo "Enable quota & set quota limit for $TSTUSR"
1934 set_ost_qtype $QTYPE || error "enable ost quota failed"
1935 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1936 error "set quota failed"
1938 echo "Start ost1..."
1939 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1942 wait_ost_reint $QTYPE || error "reintegration failed"
1944 # hardlimit should have been fetched by slave during global
1945 # reintegration, write will exceed quota
1946 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1947 quota_error u $TSTUSR "write success, but expect EDQUOT"
1950 wait_delete_completed
1951 sync_all_data || true
1957 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1958 error "clear quota failed"
1960 echo "Start ost1..."
1961 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1964 wait_ost_reint $QTYPE || error "reintegration failed"
1966 # hardlimit should be cleared on slave during reintegration
1967 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1968 quota_error u $TSTUSR "write error, but expect success"
1972 run_test 7a "Quota reintegration (global index)"
1974 # quota reintegration (slave index)
1977 local TESTFILE=$DIR/$tdir/$tfile
1979 setup_quota_test || error "setup quota failed with $?"
1980 trap cleanup_quota_test EXIT
1982 # make sure the system is clean
1983 local USED=$(getquota -u $TSTUSR global curspace)
1984 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1986 # make sure no granted quota on ost1
1987 set_ost_qtype $QTYPE || error "enable ost quota failed"
1988 resetquota -u $TSTUSR
1989 set_ost_qtype "none" || error "disable ost quota failed"
1991 local OSTUUID=$(ostuuid_from_index 0)
1992 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1994 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1997 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1998 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2000 # consume some space to make sure the granted space will not
2001 # be released during reconciliation
2002 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2003 error "consume space failure, expect success"
2005 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2006 lustre_fail mds 0xa02
2008 set_ost_qtype $QTYPE || error "enable ost quota failed"
2009 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2010 error "set quota failed"
2012 # ignore the write error
2013 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2015 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2019 echo "Restart ost to trigger reintegration..."
2021 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2024 wait_ost_reint $QTYPE || error "reintegration failed"
2026 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2027 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2032 run_test 7b "Quota reintegration (slave index)"
2034 # quota reintegration (restart mds during reintegration)
2036 local LIMIT=20 # 20M
2037 local TESTFILE=$DIR/$tdir/$tfile
2039 [ "$SLOW" = "no" ] && LIMIT=5
2041 setup_quota_test || error "setup quota failed with $?"
2042 trap cleanup_quota_test EXIT
2044 # make sure the system is clean
2045 local USED=$(getquota -u $TSTUSR global curspace)
2046 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2048 set_ost_qtype "none" || error "disable ost quota failed"
2049 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2050 error "set quota failed"
2052 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2053 lustre_fail ost 0xa03
2056 set_ost_qtype $QTYPE || error "enable ost quota failed"
2057 # trigger reintegration
2058 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2059 procf=${procf}quota_slave.force_reint
2060 do_facet ost1 $LCTL set_param $procf=1 ||
2061 error "force reintegration failed"
2069 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2072 # wait longer than usual to make sure the reintegration
2073 # is triggered by quota wb thread.
2074 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2076 # hardlimit should have been fetched by slave during global
2077 # reintegration, write will exceed quota
2078 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2079 quota_error u $TSTUSR "write success, but expect EDQUOT"
2083 run_test 7c "Quota reintegration (restart mds during reintegration)"
2085 # Quota reintegration (Transfer index in multiple bulks)
2087 local TESTFILE=$DIR/$tdir/$tfile
2088 local TESTFILE1="$DIR/$tdir/$tfile"-1
2091 setup_quota_test || error "setup quota failed with $?"
2092 trap cleanup_quota_test EXIT
2094 set_ost_qtype "none" || error "disable ost quota failed"
2095 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2096 error "set quota for $TSTUSR failed"
2097 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2098 error "set quota for $TSTUSR2 failed"
2100 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2101 lustre_fail mds 0x608 0
2103 # enable quota to tirgger reintegration
2104 set_ost_qtype "u" || error "enable ost quota failed"
2105 wait_ost_reint "u" || error "reintegration failed"
2109 # hardlimit should have been fetched by slave during global
2110 # reintegration, write will exceed quota
2111 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2112 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2114 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2115 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2119 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2121 # quota reintegration (inode limits)
2123 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2125 # LU-2435: skip this quota test if underlying zfs version has not
2126 # supported native dnode accounting
2127 [ "$mds1_FSTYPE" == zfs ] && {
2128 local F="feature@userobj_accounting"
2129 local pool=$(zpool_name mds1)
2130 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2132 [[ "$feature" != *" active "* ]] &&
2133 skip "requires zpool with active userobj_accounting"
2136 local ilimit=$((1024 * 2)) # 2k inodes
2137 local TESTFILE=$DIR/${tdir}-1/$tfile
2139 setup_quota_test || error "setup quota failed with $?"
2140 trap cleanup_quota_test EXIT
2142 # make sure the system is clean
2143 local USED=$(getquota -u $TSTUSR global curinodes)
2144 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2146 # make sure no granted quota on mdt1
2147 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2148 resetquota -u $TSTUSR
2149 set_mdt_qtype "none" || error "disable mdt quota failed"
2151 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2152 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2153 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2156 echo "Stop mds${MDSCOUNT}..."
2159 echo "Enable quota & set quota limit for $TSTUSR"
2160 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2161 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2162 error "set quota failed"
2164 echo "Start mds${MDSCOUNT}..."
2165 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2168 wait_mdt_reint $QTYPE || error "reintegration failed"
2170 echo "create remote dir"
2171 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2172 error "create remote dir failed"
2173 chmod 0777 $DIR/${tdir}-1
2175 # hardlimit should have been fetched by slave during global
2176 # reintegration, create will exceed quota
2177 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2178 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2180 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2181 wait_delete_completed
2182 sync_all_data || true
2184 echo "Stop mds${MDSCOUNT}..."
2187 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2188 error "clear quota failed"
2190 echo "Start mds${MDSCOUNT}..."
2191 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2194 wait_mdt_reint $QTYPE || error "reintegration failed"
2196 # hardlimit should be cleared on slave during reintegration
2197 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2198 quota_error u $TSTUSR "create failed, expect success"
2200 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2201 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2205 run_test 7e "Quota reintegration (inode limits)"
2207 # run dbench with quota enabled
2209 local BLK_LIMIT="100g" #100G
2210 local FILE_LIMIT=1000000
2212 setup_quota_test || error "setup quota failed with $?"
2213 trap cleanup_quota_test EXIT
2215 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2216 set_ost_qtype $QTYPE || error "enable ost quota failed"
2218 echo "Set enough high limit for user: $TSTUSR"
2219 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2220 error "set user quota failed"
2221 echo "Set enough high limit for group: $TSTUSR"
2222 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2223 error "set group quota failed"
2224 if is_project_quota_supported; then
2225 change_project -sp $TSTPRJID $DIR/$tdir
2226 echo "Set enough high limit for project: $TSTPRJID"
2227 $LFS setquota -p $TSTPRJID -b 0 \
2228 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2229 error "set project quota failed"
2233 [ "$SLOW" = "no" ] && duration=" -t 120"
2234 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2235 quota_error a $TSTUSR "dbench failed!"
2237 is_project_quota_supported && change_project -C $DIR/$tdir
2240 run_test 8 "Run dbench with quota enabled"
2242 # this check is just for test_9
2243 OST0_MIN=4900000 #4.67G
2245 check_whether_skip () {
2246 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2247 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2248 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2249 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2256 # run for fixing bug10707, it needs a big room. test for 64bit
2258 local filesize=$((1024 * 9 / 2)) # 4.5G
2260 check_whether_skip && return 0
2262 setup_quota_test || error "setup quota failed with $?"
2263 trap cleanup_quota_test EXIT
2265 set_ost_qtype "ug" || error "enable ost quota failed"
2267 local TESTFILE="$DIR/$tdir/$tfile-0"
2268 local BLK_LIMIT=100G #100G
2269 local FILE_LIMIT=1000000
2271 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2273 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2275 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2276 error "set user quota failed"
2278 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2279 "for group: $TSTUSR"
2280 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2281 error "set group quota failed"
2283 quota_show_check a u $TSTUSR
2284 quota_show_check a g $TSTUSR
2286 echo "Create test file"
2287 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2288 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2290 log "Write the big file of 4.5G ..."
2291 $RUNAS $DD of=$TESTFILE count=$filesize ||
2292 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2302 run_test 9 "Block limit larger than 4GB (b10707)"
2305 local TESTFILE=$DIR/$tdir/$tfile
2307 setup_quota_test || error "setup quota failed with $?"
2308 trap cleanup_quota_test EXIT
2310 # set limit to root user should fail
2311 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2312 error "set limit for root user successfully, expect failure"
2313 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2314 error "set limit for root group successfully, expect failure"
2315 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2316 error "set limit for project 0 successfully, expect failure"
2318 # root user can overrun quota
2319 set_ost_qtype "ug" || error "enable ost quota failed"
2321 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2322 error "set quota failed"
2323 quota_show_check b u $TSTUSR
2325 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2326 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2328 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2329 error "write failure, expect success"
2333 run_test 10 "Test quota for root user"
2336 local TESTFILE=$DIR/$tdir/$tfile
2337 setup_quota_test || error "setup quota failed with $?"
2338 trap cleanup_quota_test EXIT
2340 set_mdt_qtype "ug" || error "enable mdt quota failed"
2341 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2342 error "set quota failed"
2344 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2345 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2347 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2348 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2351 local USED=$(getquota -u $TSTUSR global curinodes)
2352 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2356 run_test 11 "Chown/chgrp ignores quota"
2359 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2361 local blimit=22 # 22M
2362 local blk_cnt=$((blimit - 5))
2363 local TESTFILE0="$DIR/$tdir/$tfile"-0
2364 local TESTFILE1="$DIR/$tdir/$tfile"-1
2366 setup_quota_test || error "setup quota failed with $?"
2367 trap cleanup_quota_test EXIT
2369 set_ost_qtype "u" || error "enable ost quota failed"
2370 quota_show_check b u $TSTUSR
2372 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2373 error "set quota failed"
2375 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2376 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2377 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2378 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2380 echo "Write to ost0..."
2381 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2382 quota_error a $TSTUSR "dd failed"
2384 echo "Write to ost1..."
2385 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2386 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2388 echo "Free space from ost0..."
2390 wait_delete_completed
2391 sync_all_data || true
2393 echo "Write to ost1 after space freed from ost0..."
2394 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2395 quota_error a $TSTUSR "rebalancing failed"
2399 run_test 12a "Block quota rebalancing"
2402 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2404 local ilimit=$((1024 * 2)) # 2k inodes
2405 local TESTFILE0=$DIR/$tdir/$tfile
2406 local TESTFILE1=$DIR/${tdir}-1/$tfile
2408 setup_quota_test || error "setup quota failed with $?"
2409 trap cleanup_quota_test EXIT
2411 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2412 chmod 0777 $DIR/${tdir}-1
2414 set_mdt_qtype "u" || error "enable mdt quota failed"
2415 quota_show_check f u $TSTUSR
2417 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2418 error "set quota failed"
2420 echo "Create $ilimit files on mdt0..."
2421 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2422 quota_error u $TSTUSR "create failed, but expect success"
2424 echo "Create files on mdt1..."
2425 $RUNAS createmany -m $TESTFILE1 1 &&
2426 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2428 echo "Free space from mdt0..."
2429 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2430 wait_delete_completed
2431 sync_all_data || true
2433 echo "Create files on mdt1 after space freed from mdt0..."
2434 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2435 quota_error a $TSTUSR "rebalancing failed"
2437 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2438 error "unlink mdt1 files failed"
2439 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2443 run_test 12b "Inode quota rebalancing"
2446 local TESTFILE=$DIR/$tdir/$tfile
2447 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2448 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2450 setup_quota_test || error "setup quota failed with $?"
2451 trap cleanup_quota_test EXIT
2453 set_ost_qtype "u" || error "enable ost quota failed"
2454 quota_show_check b u $TSTUSR
2456 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2457 error "set quota failed"
2458 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2459 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2461 # clear the locks in cache first
2462 do_facet ost1 $LCTL set_param -n $procf=clear
2463 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2464 [ $nlock -eq 0 ] || error "$nlock cached locks"
2466 # write to acquire the per-ID lock
2467 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2468 quota_error a $TSTUSR "dd failed"
2470 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2471 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2473 # clear quota doesn't trigger per-ID lock cancellation
2474 resetquota -u $TSTUSR
2475 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2476 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2478 # clear the per-ID lock
2479 do_facet ost1 $LCTL set_param -n $procf=clear
2480 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2481 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2483 # spare quota should be released
2484 local OSTUUID=$(ostuuid_from_index 0)
2485 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2486 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2487 [ $limit -le $space ] ||
2488 error "spare quota isn't released, limit:$limit, space:$space"
2492 run_test 13 "Cancel per-ID lock in the LRU list"
2495 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2497 wait_delete_completed
2498 sync_all_data || true
2501 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2502 error "set user quota failed"
2503 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2504 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2505 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2506 resetquota -u $TSTUSR
2509 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2510 error "set group quota failed"
2511 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2512 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2513 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2514 resetquota -g $TSTUSR
2516 run_test 15 "Set over 4T block quota"
2520 local BLKS=1 # 1M less than limit
2521 local TESTFILE=$DIR/$tdir/$tfile
2523 setup_quota_test || error "setup quota failed with $?"
2524 trap cleanup_quota_test EXIT
2526 # make sure the system is clean
2527 local USED=$(getquota -u $TSTUSR global curspace)
2528 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2530 set_ost_qtype "ug" || error "enable ost quota failed"
2531 # make sure no granted quota on ost
2532 resetquota -u $TSTUSR
2533 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2534 error "set quota failed"
2536 quota_show_check b u $TSTUSR
2538 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2539 lustre_fail mds 0xa04 $err_code
2541 # write in background
2542 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2546 # write should be blocked and never finished
2547 if ! ps -p $DDPID > /dev/null 2>&1; then
2549 quota_error u $TSTUSR "write finished incorrectly!"
2557 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2559 if [ $count -gt $timeout ]; then
2560 quota_error u $TSTUSR "dd is not finished!"
2565 sync; sync_all_data || true
2567 USED=$(getquota -u $TSTUSR global curspace)
2568 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2569 "Used space(${USED}K) is less than ${BLKS}M"
2574 # DQACQ return recoverable error
2576 echo "DQACQ return -ENOLCK"
2578 test_17sub 37 || error "Handle -ENOLCK failed"
2580 echo "DQACQ return -EAGAIN"
2582 test_17sub 11 || error "Handle -EAGAIN failed"
2584 echo "DQACQ return -ETIMEDOUT"
2585 #define ETIMEDOUT 110
2586 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2588 echo "DQACQ return -ENOTCONN"
2589 #define ENOTCONN 107
2590 test_17sub 107 || error "Handle -ENOTCONN failed"
2593 run_test 17 "DQACQ return recoverable error"
2597 local blimit="200m" # 200M
2598 local TESTFILE="$DIR/$tdir/$tfile"
2600 setup_quota_test || error "setup quota failed with $?"
2601 trap cleanup_quota_test EXIT
2603 set_ost_qtype "u" || error "enable ost quota failed"
2604 log "User quota (limit: $blimit)"
2605 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2606 error "set quota failed"
2607 quota_show_check b u $TSTUSR
2609 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2610 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2612 local timeout=$(sysctl -n lustre.timeout)
2614 if [ $io_type = "directio" ]; then
2615 log "Write 100M (directio) ..."
2616 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2618 log "Write 100M (buffered) ..."
2619 $RUNAS $DD of=$TESTFILE count=100 &
2623 replay_barrier $SINGLEMDS
2624 log "Fail mds for $((2 * timeout)) seconds"
2625 fail $SINGLEMDS $((2 * timeout))
2628 if at_is_enabled; then
2629 timeout=$(at_max_get mds)
2631 timeout=$(lctl get_param -n timeout)
2635 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2636 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2637 log "it took $count second"
2642 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2644 cancel_lru_locks mdc
2645 cancel_lru_locks osc
2648 local testfile_size=$(stat -c %s $TESTFILE)
2649 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2650 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2651 "got ${testfile_size}. Verifying file failed!"
2656 # test when mds does failover, the ost still could work well
2657 # this test shouldn't trigger watchdog b=14840
2659 # Clear dmesg so watchdog is not triggered by previous
2661 do_facet ost1 dmesg -c > /dev/null
2664 test_18_sub directio
2666 # check if watchdog is triggered
2667 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2668 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2669 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2670 [ -z "$watchdog" ] || error "$watchdog"
2671 rm -f $TMP/lustre-log-${TESTNAME}.log
2673 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2677 local TESTFILE=$DIR/$tdir/$tfile
2679 setup_quota_test || error "setup quota failed with $?"
2680 trap cleanup_quota_test EXIT
2682 set_ost_qtype $QTYPE || error "enable ost quota failed"
2684 # bind file to a single OST
2685 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2686 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2688 echo "Set user quota (limit: ${blimit}M)"
2689 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2690 error "set user quota failed"
2691 quota_show_check b u $TSTUSR
2692 echo "Update quota limits"
2693 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2694 error "set group quota failed"
2695 quota_show_check b u $TSTUSR
2697 # first wirte might be cached
2698 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2699 cancel_lru_locks osc
2701 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2702 quota_error u $TSTUSR "Write success, expect failure"
2707 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2709 test_20() { # b15754
2710 local LSTR=(2g 1t 4k 3m) # limits strings
2712 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2715 resetquota -u $TSTUSR
2717 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2718 $MOUNT || error "could not set quota limits"
2719 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2720 --inode-softlimit ${LSTR[2]} \
2721 --inode-hardlimit ${LSTR[3]} \
2722 $MOUNT || error "could not set quota limits"
2724 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2725 error "bsoftlimit was not set properly"
2726 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2727 error "bhardlimit was not set properly"
2728 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2729 error "isoftlimit was not set properly"
2730 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2731 error "ihardlimit was not set properly"
2733 resetquota -u $TSTUSR
2735 run_test 20 "Test if setquota specifiers work properly (b15754)"
2742 local time=$(($(date +%s) + seconds))
2743 while [ $(date +%s) -lt $time ]; do
2744 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2748 # run for fixing bug16053, setquota shouldn't fail when writing and
2749 # deleting are happening
2751 local TESTFILE="$DIR/$tdir/$tfile"
2752 local BLIMIT=10 # 10G
2753 local ILIMIT=1000000
2755 setup_quota_test || error "setup quota failed with $?"
2756 trap cleanup_quota_test EXIT
2758 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2760 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2761 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2762 error "set user quota failed"
2763 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2764 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2765 error "set group quota failed"
2766 if is_project_quota_supported; then
2767 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2768 "project: $TSTPRJID"
2769 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2770 $MOUNT || error "set project quota failed"
2773 # repeat writing on a 1M file
2774 test_21_sub ${TESTFILE}_1 1 30 &
2776 # repeat writing on a 128M file
2777 test_21_sub ${TESTFILE}_2 128 30 &
2780 local time=$(($(date +%s) + 30))
2782 while [ $(date +%s) -lt $time ]; do
2783 log "Set quota for $i times"
2784 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2785 -I $((ILIMIT + i)) $MOUNT ||
2786 error "Set user quota failed"
2787 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2788 -I $((ILIMIT + i)) $MOUNT ||
2789 error "Set group quota failed"
2790 if is_project_quota_supported; then
2791 $LFS setquota -p $TSTPRJID -b 0 -B \
2792 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2793 error "Set project quota failed"
2801 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2803 if [ $count -gt 60 ]; then
2804 quota_error a $TSTUSR "dd should be finished!"
2808 echo "(dd_pid=$DDPID1, time=$count)successful"
2812 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2814 if [ $count -gt 60 ]; then
2815 quota_error a $TSTUSR "dd should be finished!"
2819 echo "(dd_pid=$DDPID2, time=$count)successful"
2823 run_test 21 "Setquota while writing & deleting (b16053)"
2825 # enable/disable quota enforcement permanently
2827 echo "Set both mdt & ost quota type as ug"
2829 is_project_quota_supported && qtype=$QTYPE
2830 set_mdt_qtype $qtype || error "enable mdt quota failed"
2831 set_ost_qtype $qtype || error "enable ost quota failed"
2834 stopall || error "failed to stopall (1)"
2838 echo "Verify if quota is enabled"
2839 local qtype1=$(mdt_quota_type)
2840 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2841 qtype=$(ost_quota_type)
2842 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2844 echo "Set both mdt & ost quota type as none"
2845 set_mdt_qtype "none" || error "disable mdt quota failed"
2846 set_ost_qtype "none" || error "disable ost quota failed"
2849 stopall || error "failed to stopall (2)"
2854 echo "Verify if quota is disabled"
2855 qtype=$(mdt_quota_type)
2856 [ $qtype != "none" ] && error "mdt quota setting is lost"
2857 qtype=$(ost_quota_type)
2858 [ $qtype != "none" ] && error "ost quota setting is lost"
2862 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2865 local TESTFILE="$DIR/$tdir/$tfile"
2868 setup_quota_test || error "setup quota failed with $?"
2869 trap cleanup_quota_test EXIT
2871 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2874 log "User quota (limit: $LIMIT MB)"
2875 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2876 error "set quota failed"
2877 quota_show_check b u $TSTUSR
2879 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2880 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2882 log "Step1: trigger EDQUOT with O_DIRECT"
2883 log "Write half of file"
2884 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2885 quota_error u $TSTUSR "(1) Write failure, expect success." \
2887 log "Write out of block quota ..."
2888 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2889 oflag=direct conv=notrunc &&
2890 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2894 log "Step2: rewrite should succeed"
2895 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2896 quota_error u $TSTUSR "(3) Write failure, expect success." \
2902 local OST0_UUID=$(ostuuid_from_index 0)
2903 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2904 [ $OST0_QUOTA_USED -ne 0 ] &&
2905 ($SHOW_QUOTA_USER; \
2906 quota_error u $TSTUSR "quota isn't released")
2911 [ "$ost1_FSTYPE" == zfs ] &&
2912 skip "Overwrite in place is not guaranteed to be " \
2913 "space neutral on ZFS"
2915 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2916 check_whether_skip && return 0
2917 log "run for 4MB test file"
2920 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2921 check_whether_skip && return 0
2922 log "run for 40MB test file"
2925 run_test 23 "Quota should be honored with directIO (b16125)"
2929 local TESTFILE="$DIR/$tdir/$tfile"
2931 setup_quota_test || error "setup quota failed with $?"
2932 trap cleanup_quota_test EXIT
2934 set_ost_qtype $QTYPE || error "enable ost quota failed"
2936 # bind file to a single OST
2937 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2938 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2940 echo "Set user quota (limit: ${blimit}M)"
2941 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2942 error "set quota failed"
2944 # overrun quota by root user
2945 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2946 error "write failure, expect success"
2947 cancel_lru_locks osc
2948 sync_all_data || true
2950 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2954 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2956 test_27a() { # b19612
2957 $LFS quota $TSTUSR $DIR &&
2958 error "lfs succeeded with no type, but should have failed"
2959 $LFS setquota $TSTUSR $DIR &&
2960 error "lfs succeeded with no type, but should have failed"
2963 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2965 test_27b() { # b20200
2966 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2967 error "lfs setquota failed with uid argument"
2968 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2969 error "lfs stequota failed with gid argument"
2970 if is_project_quota_supported; then
2971 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2972 1000 $DIR || error \
2973 "lfs stequota failed with projid argument"
2975 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2976 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2977 if is_project_quota_supported; then
2978 $SHOW_QUOTA_PROJID ||
2979 error "lfs quota failed with projid argument"
2981 resetquota -u $TSTID
2982 resetquota -g $TSTID
2983 resetquota -p $TSTPRJID
2986 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2991 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2992 error "lfs setquota failed"
2994 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2995 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2996 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2997 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2999 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3000 error "lfs setquota for $TSTID failed"
3002 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3003 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3004 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3005 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3007 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3008 error "total allocated inode/block limit not printed"
3010 resetquota -u $TSTUSR
3012 run_test 27c "lfs quota should support human-readable output"
3019 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3020 error "set fraction block limit failed"
3021 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3022 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3023 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3024 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3026 resetquota -u $TSTUSR
3028 run_test 27d "lfs setquota should support fraction block limit"
3032 local TESTFILE="$DIR/$tdir/$tfile"
3035 setup_quota_test || error "setup quota failed with $?"
3036 trap cleanup_quota_test EXIT
3038 set_ost_qtype "u" || error "enable ost quota failed"
3040 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3041 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3043 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3044 $MAX_IQ_TIME $DIR || error "set grace time failed"
3045 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3046 error "set quota failed"
3047 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3048 cancel_lru_locks osc
3050 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3051 # over-quota flag has not yet settled since we do not trigger async
3052 # events based on grace time period expiration
3054 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3055 cancel_lru_locks osc
3056 # now over-quota flag should be settled and further writes should fail
3058 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3059 error "grace times were reset"
3062 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3063 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3065 run_test 30 "Hard limit updates should not reset grace times"
3067 # basic usage tracking for user & group
3069 local INODES=10 # 10 files
3070 local BLK_CNT=2 # of 2M each
3071 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3073 setup_quota_test || error "setup quota failed with $?"
3074 trap cleanup_quota_test EXIT
3076 # make sure the system is clean
3077 local USED=$(getquota -u $TSTID global curspace)
3079 error "Used space ($USED) for user $TSTID isn't 0."
3080 USED=$(getquota -g $TSTID global curspace)
3082 error "Used space ($USED) for group $TSTID isn't 0."
3083 if is_project_quota_supported; then
3084 USED=$(getquota -p $TSTPRJID global curspace)
3085 [ $USED -ne 0 ] && error \
3086 "Used space ($USED) for project $TSTPRJID isn't 0."
3089 echo "Write files..."
3090 for i in $(seq 0 $INODES); do
3091 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3092 error "write failed"
3093 is_project_quota_supported &&
3094 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3095 echo "Iteration $i/$INODES completed"
3097 cancel_lru_locks osc
3099 echo "Wait for setattr on objects finished..."
3100 wait_delete_completed
3102 sync; sync_all_data || true
3104 echo "Verify disk usage after write"
3105 USED=$(getquota -u $TSTID global curspace)
3106 [ $USED -lt $TOTAL_BLKS ] &&
3107 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3108 USED=$(getquota -g $TSTID global curspace)
3109 [ $USED -lt $TOTAL_BLKS ] &&
3110 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3111 if is_project_quota_supported; then
3112 USED=$(getquota -p $TSTPRJID global curspace)
3113 [ $USED -lt $TOTAL_BLKS ] && error \
3114 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3117 echo "Verify inode usage after write"
3118 USED=$(getquota -u $TSTID global curinodes)
3119 [ $USED -lt $INODES ] &&
3120 error "Used inode for user $TSTID is $USED, expected $INODES"
3121 USED=$(getquota -g $TSTID global curinodes)
3122 [ $USED -lt $INODES ] &&
3123 error "Used inode for group $TSTID is $USED, expected $INODES"
3124 if is_project_quota_supported; then
3125 USED=$(getquota -p $TSTPRJID global curinodes)
3126 [ $USED -lt $INODES ] && error \
3127 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3132 echo "Verify disk usage after delete"
3133 USED=$(getquota -u $TSTID global curspace)
3134 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3135 USED=$(getquota -u $TSTID global curinodes)
3136 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3137 USED=$(getquota -g $TSTID global curspace)
3138 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3139 USED=$(getquota -g $TSTID global curinodes)
3140 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3141 if is_project_quota_supported; then
3142 USED=$(getquota -p $TSTPRJID global curspace)
3144 error "Used space for project $TSTPRJID isn't 0. $USED"
3145 USED=$(getquota -p $TSTPRJID global curinodes)
3147 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3150 run_test 33 "Basic usage tracking for user & group & project"
3152 # usage transfer test for user & group & project
3154 local BLK_CNT=2 # 2MB
3155 local project_supported="no"
3157 is_project_quota_supported && project_supported="yes"
3158 setup_quota_test || error "setup quota failed with $?"
3159 trap cleanup_quota_test EXIT
3161 # make sure the system is clean
3162 local USED=$(getquota -u $TSTID global curspace)
3163 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3164 USED=$(getquota -g $TSTID global curspace)
3165 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3167 local USED=$(getquota -u $TSTID2 global curspace)
3168 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3169 if [ $project_supported == "yes" ]; then
3170 USED=$(getquota -p $TSTPRJID global curspace)
3171 [ $USED -ne 0 ] && error \
3172 "Used space ($USED) for Project $TSTPRJID isn't 0."
3175 echo "Write file..."
3176 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3177 error "write failed"
3178 cancel_lru_locks osc
3179 sync; sync_all_data || true
3181 echo "chown the file to user $TSTID"
3182 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3184 echo "Wait for setattr on objects finished..."
3185 wait_delete_completed
3187 BLK_CNT=$((BLK_CNT * 1024))
3189 echo "Verify disk usage for user $TSTID"
3190 USED=$(getquota -u $TSTID global curspace)
3191 [ $USED -lt $BLK_CNT ] &&
3192 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3193 USED=$(getquota -u $TSTID global curinodes)
3195 error "Used inodes for user $TSTID is $USED, expected 1"
3197 echo "chgrp the file to group $TSTID"
3198 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3200 echo "Wait for setattr on objects finished..."
3201 wait_delete_completed
3203 echo "Verify disk usage for group $TSTID"
3204 USED=$(getquota -g $TSTID global curspace)
3205 [ $USED -ge $BLK_CNT ] ||
3206 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3207 USED=$(getquota -g $TSTID global curinodes)
3209 error "Used inodes for group $TSTID is $USED, expected 1"
3211 # chown won't change the ost object group. LU-4345 */
3212 echo "chown the file to user $TSTID2"
3213 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3215 echo "Wait for setattr on objects finished..."
3216 wait_delete_completed
3218 echo "change_project project id to $TSTPRJID"
3219 [ $project_supported == "yes" ] &&
3220 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3221 echo "Wait for setattr on objects finished..."
3222 wait_delete_completed
3224 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3225 USED=$(getquota -u $TSTID2 global curspace)
3226 [ $USED -lt $BLK_CNT ] &&
3227 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3228 USED=$(getquota -u $TSTID global curspace)
3230 error "Used space for user $TSTID is $USED, expected 0"
3231 USED=$(getquota -g $TSTID global curspace)
3232 [ $USED -lt $BLK_CNT ] &&
3233 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3234 if [ $project_supported == "yes" ]; then
3235 USED=$(getquota -p $TSTPRJID global curspace)
3236 [ $USED -lt $BLK_CNT ] && error \
3237 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3242 run_test 34 "Usage transfer for user & group & project"
3244 # usage is still accessible across restart
3246 local BLK_CNT=2 # 2 MB
3248 setup_quota_test || error "setup quota failed with $?"
3249 trap cleanup_quota_test EXIT
3251 echo "Write file..."
3252 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3253 error "write failed"
3254 is_project_quota_supported &&
3255 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3256 cancel_lru_locks osc
3258 echo "Wait for setattr on objects finished..."
3259 wait_delete_completed
3261 sync; sync_all_data || true
3263 echo "Save disk usage before restart"
3264 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3265 [ $ORIG_USR_SPACE -eq 0 ] &&
3266 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3267 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3268 [ $ORIG_USR_INODES -eq 0 ] &&
3269 error "Used inodes for user $TSTID is 0, expected 1"
3270 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3271 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3272 [ $ORIG_GRP_SPACE -eq 0 ] &&
3273 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3274 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3275 [ $ORIG_GRP_INODES -eq 0 ] &&
3276 error "Used inodes for group $TSTID is 0, expected 1"
3277 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3279 if is_project_quota_supported; then
3280 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3281 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3282 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3283 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3284 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3285 "Used inodes for project $TSTPRJID is 0, expected 1"
3286 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3294 echo "Verify disk usage after restart"
3295 local USED=$(getquota -u $TSTID global curspace)
3296 [ $USED -eq $ORIG_USR_SPACE ] ||
3297 error "Used space for user $TSTID changed from " \
3298 "$ORIG_USR_SPACE to $USED"
3299 USED=$(getquota -u $TSTID global curinodes)
3300 [ $USED -eq $ORIG_USR_INODES ] ||
3301 error "Used inodes for user $TSTID changed from " \
3302 "$ORIG_USR_INODES to $USED"
3303 USED=$(getquota -g $TSTID global curspace)
3304 [ $USED -eq $ORIG_GRP_SPACE ] ||
3305 error "Used space for group $TSTID changed from " \
3306 "$ORIG_GRP_SPACE to $USED"
3307 USED=$(getquota -g $TSTID global curinodes)
3308 [ $USED -eq $ORIG_GRP_INODES ] ||
3309 error "Used inodes for group $TSTID changed from " \
3310 "$ORIG_GRP_INODES to $USED"
3311 if [ $project_supported == "yes" ]; then
3312 USED=$(getquota -p $TSTPRJID global curinodes)
3313 [ $USED -eq $ORIG_PRJ_INODES ] ||
3314 error "Used inodes for project $TSTPRJID " \
3315 "changed from $ORIG_PRJ_INODES to $USED"
3316 USED=$(getquota -p $TSTPRJID global curspace)
3317 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3318 error "Used space for project $TSTPRJID "\
3319 "changed from $ORIG_PRJ_SPACE to $USED"
3322 # check if the vfs_dq_init() is called before writing
3323 echo "Append to the same file..."
3324 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3325 error "write failed"
3326 cancel_lru_locks osc
3327 sync; sync_all_data || true
3329 echo "Verify space usage is increased"
3330 USED=$(getquota -u $TSTID global curspace)
3331 [ $USED -gt $ORIG_USR_SPACE ] ||
3332 error "Used space for user $TSTID isn't increased" \
3333 "orig:$ORIG_USR_SPACE, now:$USED"
3334 USED=$(getquota -g $TSTID global curspace)
3335 [ $USED -gt $ORIG_GRP_SPACE ] ||
3336 error "Used space for group $TSTID isn't increased" \
3337 "orig:$ORIG_GRP_SPACE, now:$USED"
3338 if [ $project_supported == "yes" ]; then
3339 USED=$(getquota -p $TSTPRJID global curspace)
3340 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3341 error "Used space for project $TSTPRJID isn't " \
3342 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3347 run_test 35 "Usage is still accessible across reboot"
3349 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3352 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3353 skip "Old server doesn't have LU-5006 fix."
3355 setup_quota_test || error "setup quota failed with $?"
3356 trap cleanup_quota_test EXIT
3358 # make sure the system is clean
3359 local USED=$(getquota -u $TSTID global curspace)
3361 error "Used space ($USED) for user $TSTID isn't 0."
3363 # create file with MDS_OPEN_DELAY_CREATE flag
3364 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3365 error "Create file failed"
3367 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3368 oflag=sync || error "Write file failed"
3370 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3372 # wait for setattr on objects finished..."
3373 wait_delete_completed
3375 USED=$(getquota -u $TSTID global curspace)
3376 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3380 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3384 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3385 skip "Old server doesn't have LU-8801 fix."
3387 [ "$UID" != 0 ] && skip_env "must run as root" && return
3389 setup_quota_test || error "setup quota failed with $?"
3390 trap cleanup_quota_test EXIT
3392 # make sure the system is clean
3393 local USED=$(getquota -u $TSTID global curspace)
3395 error "Used space ($USED) for user $TSTID isn't 0."
3396 USED=$(getquota -u $TSTID2 global curspace)
3398 error "Used space ($USED) for user $TSTID2 isn't 0."
3400 local TESTFILE="$DIR/$tdir/$tfile"
3401 local file_cnt=10000
3403 # Generate id entries in accounting file
3404 echo "Create $file_cnt files..."
3405 for i in `seq $file_cnt`; do
3407 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3408 error "failed to chown $TESTFILE-$i"
3410 cancel_lru_locks osc
3411 sync; sync_all_data || true
3413 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3414 procf=${procf}.quota_slave.acct_user
3417 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3418 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3419 echo "Found $acct_cnt id entries"
3421 [ $file_cnt -eq $acct_cnt ] || {
3422 do_facet mds1 $LCTL get_param $procf
3423 error "skipped id entries"
3428 run_test 38 "Quota accounting iterator doesn't skip id entries"
3431 local TESTFILE="$DIR/$tdir/project"
3432 ! is_project_quota_supported &&
3433 skip "Project quota is not supported"
3435 setup_quota_test || error "setup quota failed with $?"
3438 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3439 [ $projectid -ne 0 ] &&
3440 error "Project id should be 0 not $projectid"
3441 change_project -p 1024 $TESTFILE
3442 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3443 [ $projectid -ne 1024 ] &&
3444 error "Project id should be 1024 not $projectid"
3446 stopall || error "failed to stopall (1)"
3449 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3450 [ $projectid -ne 1024 ] &&
3451 error "Project id should be 1024 not $projectid"
3455 run_test 39 "Project ID interface works correctly"
3458 ! is_project_quota_supported &&
3459 skip "Project quota is not supported"
3460 local dir1="$DIR/$tdir/dir1"
3461 local dir2="$DIR/$tdir/dir2"
3463 setup_quota_test || error "setup quota failed with $?"
3465 mkdir -p $dir1 $dir2
3466 change_project -sp 1 $dir1 && touch $dir1/1
3467 change_project -sp 2 $dir2
3469 ln $dir1/1 $dir2/1_link &&
3470 error "Hard link across different project quota should fail"
3475 run_test 40a "Hard link across different project ID"
3478 ! is_project_quota_supported &&
3479 skip "Project quota is not supported"
3480 local dir1="$DIR/$tdir/dir1"
3481 local dir2="$DIR/$tdir/dir2"
3483 setup_quota_test || error "setup quota failed with $?"
3484 mkdir -p $dir1 $dir2
3485 change_project -sp 1 $dir1 && touch $dir1/1
3486 change_project -sp 2 $dir2
3488 mv $dir1/1 $dir2/2 || error "mv failed $?"
3489 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3490 if [ "$projid" != "2" ]; then
3491 error "project id expected 2 not $projid"
3496 run_test 40b "Mv across different project ID"
3499 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3500 ! is_project_quota_supported &&
3501 skip "Project quota is not supported"
3503 setup_quota_test || error "setup quota failed with $?"
3504 local dir="$DIR/$tdir/dir"
3506 mkdir -p $dir && change_project -sp 1 $dir
3507 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3508 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3509 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3510 touch $dir/remote_dir/file
3511 #verify inherit works file for remote dir.
3512 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3513 [ "$projid" != "1" ] &&
3514 error "file under remote dir expected 1 not $projid"
3516 #Agent inode should be ignored for project quota
3517 USED=$(getquota -p 1 global curinodes)
3518 [ "$USED" != "3" ] &&
3519 error "file count expected 3 got $USED"
3525 run_test 40c "Remote child Dir inherit project quota properly"
3528 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3529 is_project_quota_supported || skip "Project quota is not supported"
3531 setup_quota_test || error "setup quota failed with $?"
3532 local dir="$DIR/$tdir/dir"
3535 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3536 change_project -sp $TSTPRJID $dir ||
3537 error "change project on $dir failed"
3538 for i in $(seq 5); do
3539 mkdir -p $dir/d$i/d$i ||
3540 error "mkdir $dir/d$i/d$i failed"
3541 local projid=$($LFS project -d $dir/d$i/d$i |
3543 [ "$projid" == "$TSTPRJID" ] ||
3544 error "projid id expected $TSTPRJID not $projid"
3545 touch $dir/d$i/d$i/file
3546 #verify inherit works file for stripe dir.
3547 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3548 [ "$projid" == "$TSTPRJID" ] ||
3549 error "file under remote dir expected 1 not $projid"
3552 # account should be 1 + (2 + 1) *10 + 1 * 5
3553 USED=$(getquota -p $TSTPRJID global curinodes)
3554 [ "$USED" == "36" ] ||
3555 error "file count expected 36 got $USED"
3560 run_test 40d "Stripe Directory inherit project quota properly"
3563 is_project_quota_supported ||
3564 skip "Project quota is not supported"
3565 setup_quota_test || error "setup quota failed with $?"
3566 trap cleanup_quota_test EXIT
3567 local dir="$DIR/$tdir/dir"
3570 local projid=$((testnum * 1000))
3574 # enable mdt/ost quota
3575 set_mdt_qtype ugp || error "enable mdt quota failed"
3576 set_ost_qtype ugp || error "enable ost quota failed"
3578 test_mkdir -p $dir && change_project -sp $projid $dir
3579 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3580 error "set project quota failed"
3585 # check if df output works as expected
3586 echo "== global statfs: $MOUNT =="
3587 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3589 echo "== project statfs (prjid=$projid): $dir =="
3590 df -kP $dir; df -iP $dir
3591 local bused=$(getquota -p $projid global curspace)
3592 local iused=$(getquota -p $projid global curinodes)
3593 # note trailing space to match double printf from awk
3594 local expected="$blimit $bused $ilimit $iused "
3596 wait_update $HOSTNAME \
3597 "{ df -kP $dir; df -iP $dir; } |
3598 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3600 error "failed to get correct statfs for project quota"
3604 run_test 41 "df should return projid-specific values"
3607 ! is_project_quota_supported &&
3608 skip "Project quota is not supported"
3610 setup_quota_test || error "setup quota failed with $?"
3611 local dir1="$DIR/$tdir/dir1"
3612 local dir2="$DIR/$tdir/dir2"
3614 mkdir -p $dir1 && change_project -sp 1 $dir1
3615 mkdir -p $dir2 && change_project -sp 2 $dir2
3616 for num in $(seq 1 10); do
3617 touch $dir1/file_$num $dir2/file_$num
3618 ln -s $dir1/file_$num $dir1/file_$num"_link"
3619 ln -s $dir2/file_$num $dir2/file_$num"_link"
3622 count=$($LFS find --projid 1 $DIR | wc -l)
3623 [ "$count" != 21 ] && error "expected 21 but got $count"
3625 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3626 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3627 [ "$count" != 22 ] && error "expected 22 but got $count"
3632 run_test 50 "Test if lfs find --projid works"
3635 ! is_project_quota_supported &&
3636 skip "Project quota is not supported"
3637 setup_quota_test || error "setup quota failed with $?"
3638 local dir="$DIR/$tdir/dir"
3640 mkdir $dir && change_project -sp 1 $dir
3641 local used=$(getquota -p 1 global curinodes)
3642 [ $used != "1" ] && error "expected 1 got $used"
3647 used=$(getquota -p 1 global curinodes)
3648 [ $used != "4" ] && error "expected 4 got $used"
3650 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3652 cp $DIR/$tdir/6 $dir/6
3653 used=$(getquota -p 1 global curinodes)
3654 [ $used != "5" ] && error "expected 5 got $used"
3657 mv $DIR/$tdir/6 $dir/7
3658 used=$(getquota -p 1 global curinodes)
3659 [ $used != "6" ] && error "expected 6 got $used"
3664 run_test 51 "Test project accounting with mv/cp"
3667 ! is_project_quota_supported &&
3668 skip "Project quota is not supported"
3669 setup_quota_test || error "setup quota failed with $?"
3670 local dir="$DIR/$tdir/dir"
3671 mkdir $dir && change_project -sp 1 $dir
3673 touch $DIR/$tdir/file
3674 #Try renaming a file into the project. This should fail.
3675 for num in $(seq 1 2000); do
3676 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3677 error "rename should fail"
3682 run_test 52 "Rename across different project ID"
3685 ! is_project_quota_supported &&
3686 skip "Project quota is not supported"
3687 setup_quota_test || error "setup quota failed with $?"
3688 local dir="$DIR/$tdir/dir"
3689 mkdir $dir && change_project -s $dir
3690 lfs project -d $dir | grep P || error "inherit attribute should be set"
3692 change_project -C $dir
3693 lfs project -d $dir | grep P &&
3694 error "inherit attribute should be cleared"
3699 run_test 53 "Project inherit attribute could be cleared"
3702 ! is_project_quota_supported &&
3703 skip "Project quota is not supported"
3704 setup_quota_test || error "setup quota failed with $?"
3705 trap cleanup_quota_test EXIT
3706 local testfile="$DIR/$tdir/$tfile-0"
3708 #set project ID/inherit attribute
3709 change_project -sp $TSTPRJID $DIR/$tdir
3710 $RUNAS createmany -m ${testfile} 100 ||
3711 error "create many files failed"
3713 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3714 # one more count for directory itself */
3718 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3719 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3721 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3722 [ $proj_count1 -eq $proj_count ] ||
3723 error "c2: expected $proj_count got $proj_count1"
3725 #clear project but with kept projid
3726 change_project -rCk $DIR/$tdir
3727 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3728 [ $proj_count1 -eq 1 ] ||
3729 error "c3: expected 1 got $proj_count1"
3731 #verify projid untouched.
3732 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3734 [ $proj_count1 -eq $proj_count ] ||
3735 error "c4: expected $proj_count got $proj_count1"
3738 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3739 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3740 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3742 #this time clear all
3743 change_project -rC $DIR/$tdir
3744 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3745 [ $proj_count1 -eq 0 ] ||
3746 error "c6: expected 0 got $proj_count1"
3748 unlinkmany ${testfile} 100 ||
3749 error "unlink many files failed"
3753 run_test 54 "basic lfs project interface test"
3756 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3757 skip "Not supported before 2.10.58."
3758 setup_quota_test || error "setup quota failed with $?"
3760 set_ost_qtype $QTYPE || error "enable ost quota failed"
3763 #add second group to TSTUSR
3764 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3767 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3768 error "failed to dd"
3770 cancel_lru_locks osc
3771 sync; sync_all_data || true
3773 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3774 error "failed to setquota on group $TSTUSR2"
3776 $LFS quota -v -g $TSTUSR2 $DIR
3778 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3779 error "chgrp should failed with -EDQUOT"
3781 USED=$(getquota -g $TSTUSR2 global curspace)
3784 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3785 error "failed to setquota on group $TSTUSR2"
3787 $LFS quota -v -g $TSTUSR2 $DIR
3789 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3790 error "chgrp should succeed"
3792 $LFS quota -v -g $TSTUSR2 $DIR
3796 run_test 55 "Chgrp should be affected by group quota"
3799 setup_quota_test || error "setup quota failed with $?"
3801 set_ost_qtype $QTYPE || error "enable ost quota failed"
3804 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3805 erro "failed to set grace time for usr quota"
3806 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3807 awk '{print $4 $8}')
3808 if [ "x$grace_time" != "x10s;10s" ]; then
3809 $LFS quota -t -u $DIR
3810 error "expected grace time: 10s;10s, got:$grace_time"
3815 run_test 56 "lfs quota -t should work well"
3818 setup_quota_test || error "setup quota failed with $?"
3820 local dir="$DIR/$tdir/dir"
3823 #try to change pipe file should not hang and return failure
3824 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3825 awk -F ':' '{ print \\\$2 }'" \
3826 " unable to get xattr for fifo '$dir/pipe'" || return 1
3827 #command can process further if it hit some errors
3828 touch $dir/aaa $dir/bbb
3829 mkdir $dir/subdir -p
3830 touch $dir/subdir/aaa $dir/subdir/bbb
3831 #create one invalid link file
3832 ln -s $dir/not_exist_file $dir/ccc
3833 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3834 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3838 run_test 57 "lfs project could tolerate errors"
3841 [ "$mds1_FSTYPE" != ldiskfs ] &&
3842 skip "ldiskfs only test"
3843 disable_project_quota
3844 setup_quota_test || error "setup quota failed with $?"
3847 local testfile="$DIR/$tdir/$tfile-0"
3848 #make sure it did not crash kernel
3849 touch $testfile && lfs project -sp 1 $testfile
3851 enable_project_quota
3854 run_test 59 "lfs project dosen't crash kernel with project disabled"
3857 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3858 skip "Needs MDS version 2.11.53 or later."
3859 setup_quota_test || error "setup quota failed with $?"
3860 trap cleanup_quota_test EXIT
3862 local testfile=$DIR/$tdir/$tfile
3865 set_mdt_qtype "ug" || error "enable mdt quota failed"
3867 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3868 error "set quota failed"
3869 quota_show_check a g $TSTUSR
3871 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3872 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3873 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3874 error "create many files failed"
3876 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3878 # root user can overrun quota
3879 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3880 error "root user should succeed"
3884 run_test 60 "Test quota for root with setgid"
3886 # test default quota
3887 test_default_quota() {
3888 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3889 skip "Not supported before 2.11.51."
3894 local qprjid=$TSTPRJID
3898 local LIMIT=20480 #20M disk space
3899 local TESTFILE="$DIR/$tdir/$tfile-0"
3901 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3902 echo "Project quota is not supported" && return 0
3904 [ $qtype == "-u" ] && qdtype="-U"
3905 [ $qtype == "-g" ] && qdtype="-G"
3906 [ $qtype == "-p" ] && {
3911 [ $qpool == "meta" ] && {
3912 LIMIT=10240 #10K inodes
3917 setup_quota_test || error "setup quota failed with $?"
3918 trap cleanup_quota_test EXIT
3922 # enable mdt/ost quota
3923 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3924 set_ost_qtype $QTYPE || error "enable ost quota failed"
3926 log "set to use default quota"
3927 $LFS setquota $qtype $qid -d $DIR ||
3928 error "set $qid to use default quota failed"
3930 log "set default quota"
3931 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3932 error "set $qid default quota failed"
3934 log "get default quota"
3935 $LFS quota $qdtype $DIR || error "get default quota failed"
3937 if [ $qpool == "data" ]; then
3938 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3940 [ $SLIMIT -eq $LIMIT ] ||
3941 error "the returned default quota is wrong"
3943 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3945 [ $SLIMIT -eq $LIMIT ] ||
3946 error "the returned default quota is wrong"
3949 # make sure the system is clean
3950 local USED=$(getquota $qtype $qid global curspace)
3951 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3953 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3954 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3956 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3958 log "Test not out of quota"
3959 if [ $qpool == "data" ]; then
3960 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3961 quota_error $qtype $qid "write failed, expect succeed"
3963 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3964 quota_error $qtype $qid "create failed, expect succeed"
3966 unlinkmany $TESTFILE $((LIMIT/2))
3969 log "Test out of quota"
3970 # flush cache, ensure noquota flag is set on client
3971 cancel_lru_locks osc
3972 cancel_lru_locks mdc
3973 sync; sync_all_data || true
3974 if [ $qpool == "data" ]; then
3975 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3976 quota_error $qtype $qid "write succeed, expect EDQUOT"
3978 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3979 quota_error $qtype $qid "create succeed, expect EDQUOT"
3981 unlinkmany $TESTFILE $((LIMIT*2))
3984 log "Increase default quota"
3985 # increase default quota
3986 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3987 error "set default quota failed"
3989 cancel_lru_locks osc
3990 cancel_lru_locks mdc
3991 sync; sync_all_data || true
3992 if [ $qpool == "data" ]; then
3993 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3994 quota_error $qtype $qid "write failed, expect succeed"
3996 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3997 quota_error $qtype $qid "create failed, expect succeed"
3999 unlinkmany $TESTFILE $((LIMIT*2))
4002 log "Set quota to override default quota"
4003 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4004 error "set $qid quota failed"
4006 cancel_lru_locks osc
4007 cancel_lru_locks mdc
4008 sync; sync_all_data || true
4009 if [ $qpool == "data" ]; then
4010 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4011 quota_error $qtype $qid "write succeed, expect EQUOT"
4013 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4014 quota_error $qtype $qid "create succeed, expect EQUOT"
4016 unlinkmany $TESTFILE $((LIMIT*2))
4019 log "Set to use default quota again"
4020 $LFS setquota $qtype $qid -d $DIR ||
4021 error "set $qid to use default quota failed"
4023 cancel_lru_locks osc
4024 cancel_lru_locks mdc
4025 sync; sync_all_data || true
4026 if [ $qpool == "data" ]; then
4027 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4028 quota_error $qtype $qid "write failed, expect succeed"
4030 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4031 quota_error $qtype $qid "create failed, expect succeed"
4033 unlinkmany $TESTFILE $((LIMIT*2))
4038 wait_delete_completed || error "wait_delete_completed failed"
4039 sync_all_data || true
4040 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
4041 error "reset default quota failed"
4042 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
4043 error "reset quota failed"
4049 test_default_quota "-u" "data"
4050 test_default_quota "-u" "meta"
4051 test_default_quota "-g" "data"
4052 test_default_quota "-g" "meta"
4053 test_default_quota "-p" "data"
4054 test_default_quota "-p" "meta"
4056 run_test 61 "default quota tests"
4059 ! is_project_quota_supported &&
4060 skip "Project quota is not supported"
4061 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4062 skip "chattr did not support project quota"
4063 setup_quota_test || error "setup quota failed with $?"
4064 local testdir=$DIR/$tdir/
4066 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4067 change_project -s $testdir
4068 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4069 error "inherit attribute should be set"
4070 # chattr used FS_IOC_SETFLAGS ioctl
4071 $RUNAS chattr -P $testdir &&
4072 error "regular user clear inherit should fail"
4073 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4074 error "inherit attribute should still be set"
4075 chattr -P $testdir || error "root failed to clear inherit"
4076 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4077 error "inherit attribute should be cleared"
4080 run_test 62 "Project inherit should be only changed by root"
4083 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4084 skip "Not supported before 2.11.55"
4088 local dd_failed=false
4089 local tdir_dom=${tdir}_dom
4090 local LIMIT=20480 #20M
4092 [ $qtype == "p" ] && ! is_project_quota_supported &&
4093 echo "Project quota is not supported" && return 0
4095 [ $qtype == "p" ] && qid=$TSTPRJID
4097 setup_quota_test || error "setup quota failed with $?"
4098 trap cleanup_quota_test EXIT
4102 # enable mdt/ost quota
4103 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4104 set_ost_qtype $QTYPE || error "enable ost quota failed"
4106 # make sure the system is clean
4107 local USED=$(getquota -$qtype $qid global curspace)
4108 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4110 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4112 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4113 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4114 error "setstripe $tdir_dom failed"
4115 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4117 [ $qtype == "p" ] && {
4118 change_project -sp $TSTPRJID $DIR/$tdir
4119 change_project -sp $TSTPRJID $DIR/$tdir_dom
4122 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4123 error "set $qid quota failed"
4125 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4126 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4130 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4132 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4133 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4137 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4139 rm -f $DIR/$tdir_dom/*
4141 # flush cache, ensure noquota flag is set on client
4142 cancel_lru_locks osc
4143 cancel_lru_locks mdc
4144 sync; sync_all_data || true
4148 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4149 quota_error $qtype $qid "write failed, expect succeed"
4151 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4152 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4156 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4159 rm -f $DIR/$tdir_dom/*
4161 # flush cache, ensure noquota flag is set on client
4162 cancel_lru_locks osc
4163 cancel_lru_locks mdc
4164 sync; sync_all_data || true
4168 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4169 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4173 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4175 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4176 quota_error $qtype $qid "write succeed, expect EDQUOT"
4179 rm -fr $DIR/$tdir_dom
4181 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4182 error "reset usr quota failed"
4192 run_test 63 "quota on DoM tests"
4195 ! is_project_quota_supported &&
4196 skip "Project quota is not supported"
4197 setup_quota_test || error "setup quota failed with $?"
4198 local dir1="$DIR/$tdir/"
4201 ln -s $dir1/file $dir1/file_link
4203 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4204 error "set symlink file's project should fail"
4206 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4207 error "get symlink file's project should fail"
4211 run_test 64 "lfs project on symlink files should fail"
4215 local TESTFILE="$DIR/$tdir/$tfile-0"
4217 setup_quota_test || error "setup quota failed with $?"
4218 set_ost_qtype $QTYPE || error "enable ost quota failed"
4222 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4223 error "failed to write"
4224 # flush cache, ensure noquota flag is set on client
4225 cancel_lru_locks osc
4226 sync; sync_all_data || true
4228 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4229 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4230 local quota_all=$($RUNAS $LFS quota $DIR)
4232 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4233 error "usr quota not match"
4234 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4235 error "grp quota not match"
4241 run_test 65 "Check lfs quota result"
4244 ! is_project_quota_supported &&
4245 skip "Project quota is not supported"
4246 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4247 skip "Not supported before 2.12.4"
4248 setup_quota_test || error "setup quota failed with $?"
4249 stack_trap cleanup_quota_test EXIT
4250 local old=$(do_facet mds1 $LCTL get_param -n \
4251 mdt.*.enable_chprojid_gid | head -1)
4252 local testdir=$DIR/$tdir/foo
4254 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4255 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4258 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4259 chown -R $TSTID:$TSTID $testdir
4260 change_project -sp $TSTPRJID $testdir
4261 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4263 $RUNAS lfs project -p 0 $testdir/foo &&
4264 error "nonroot user should fail to set projid"
4266 $RUNAS lfs project -C $testdir/foo &&
4267 error "nonroot user should fail to clear projid"
4269 change_project -C $testdir/foo || error "failed to clear project"
4271 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4272 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4273 "failed to set projid with normal user when enable_chprojid_gid=-1"
4275 $RUNAS lfs project -rC $testdir/ || error \
4276 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4278 touch $testdir/bar || error "failed touch $testdir/bar"
4279 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4280 "normal user should not be able to set projid on root owned file"
4282 change_project -p $TSTPRJID $testdir/bar || error \
4283 "root should be able to change its own file's projid"
4287 run_test 66 "nonroot user can not change project state in default"
4294 local short_qtype=${qtype:0:1}
4297 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4299 quota_usr) _runas=$RUNAS;;
4300 quota_2usr) _runas=$RUNAS2;;
4301 *) error "unknown quota parameter $4";;
4306 $_runas $DD of=$file count=$size ||
4307 quota_error $short_qtype $TSTUSR \
4308 "$qtype write failure, but expect success"
4310 cancel_lru_locks osc
4312 sync; sync_all_data || true
4321 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4323 do_facet mds1 $LCTL get_param $param |
4324 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4328 local limit=20 # 20M
4329 local testfile="$DIR/$tdir/$tfile-0"
4330 local testfile2="$DIR/$tdir/$tfile-1"
4331 local testfile3="$DIR/$tdir/$tfile-2"
4332 local qpool="qpool1"
4338 [ "$ost1_FSTYPE" == zfs ] &&
4339 skip "ZFS grants some block space together with inode"
4341 setup_quota_test || error "setup quota failed with $?"
4342 trap cleanup_quota_test EXIT
4345 set_ost_qtype $QTYPE || error "enable ost quota failed"
4348 log "User quota (block hardlimit:$limit MB)"
4349 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4350 error "set user quota failed"
4352 # make sure the system is clean
4353 used=$(getquota -u $TSTUSR global curspace)
4354 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4356 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4357 echo "granted 0x0 before write $granted"
4359 # trigger reintegration
4360 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4361 procf=${procf}quota_slave.force_reint
4362 do_facet ost1 $LCTL set_param $procf=1 ||
4363 error "force reintegration failed"
4364 wait_ost_reint "u" || error "reintegration failed"
4365 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4366 [ $granted -ne 0 ] &&
4367 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4369 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4370 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4372 # write 10 MB to testfile
4373 test_67_write "$testfile" "user" 10 "quota_usr"
4375 # create qpool and add OST1
4376 pool_add $qpool || error "pool_add failed"
4377 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4378 # as quota_usr hasn't limits, lqe may absent. But it should be
4379 # created after the 1st direct qmt_get.
4380 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4382 # check granted - should be 0, as testfile is located only on OST0
4383 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4384 echo "global granted $granted"
4385 granted=$(getgranted $qpool "dt" $TSTID "usr")
4386 echo "$qpool granted $granted"
4387 [ $granted -ne 0 ] &&
4388 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4390 # add OST0 to qpool and check granted space
4391 pool_add_targets $qpool 0 1 ||
4392 error "pool_add_targets failed"
4393 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4394 echo "Granted $granted_mb MB"
4395 #should be 10M + qunit for each OST
4396 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4397 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4399 $LFS setstripe $testfile2 -c 1 -i 1 ||
4400 error "setstripe $testfile2 failed"
4401 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4402 # Write from another user and check that qpool1
4403 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4404 test_67_write "$testfile2" "user" 10 "quota_2usr"
4405 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4406 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4407 [ $granted -ne 0 ] &&
4408 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4410 # Granted space for quota_2usr in qpool1 should appear only
4411 # when global lqe for this user becomes enforced.
4412 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4413 error "set user quota failed"
4414 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4415 echo "granted_mb $granted_mb"
4416 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4417 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4419 $LFS setstripe $testfile3 -c 1 -i 0 ||
4420 error "setstripe $testfile3 failed"
4421 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4422 test_67_write "$testfile3" "user" 10 "quota_2usr"
4423 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4424 echo "$testfile3 granted_mb $granted_mb"
4425 [ $granted_mb -eq $limit ] ||
4426 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4428 # remove OST1 from the qpool1 and check granted space
4429 # should be 0 for TSTUSR and 10M for TSTUSR2
4430 pool_remove_target $qpool 0
4431 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4432 [ $granted_mb -eq 0 ] ||
4433 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4434 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4435 [ $granted_mb -eq 10 ] ||
4436 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4439 wait_delete_completed || error "wait_delete_completed failed"
4440 sync_all_data || true
4441 used=$(getquota -u $TSTUSR global curspace)
4442 [ $used -ne 0 ] && quota_error u $TSTUSR \
4443 "user quota isn't released after deletion"
4444 resetquota -u $TSTUSR
4448 run_test 67 "quota pools recalculation"
4455 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4456 awk '/usr/ {getline; print $2}'
4461 local qpool="qpool1"
4464 setup_quota_test || error "setup quota failed with $?"
4465 stack_trap cleanup_quota_test EXIT
4468 set_ost_qtype $QTYPE || error "enable ost quota failed"
4470 # check slave number for glbal pool
4471 local nr=$(get_slave_nr "0x0" "usr")
4472 echo "nr result $nr"
4473 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4474 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4476 # create qpool and add OST1
4477 pool_add $qpool || error "pool_add failed"
4478 nr=$(get_slave_nr $qpool "usr")
4479 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4482 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4483 nr=$(get_slave_nr $qpool "usr")
4484 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4487 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4488 nr=$(get_slave_nr $qpool "usr")
4489 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4492 pool_remove_target $qpool 0
4493 nr=$(get_slave_nr $qpool "usr")
4494 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4497 pool_remove_target $qpool 1
4498 nr=$(get_slave_nr $qpool "usr")
4499 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4501 # Check again that all is fine with global pool
4502 nr=$(get_slave_nr "0x0" "usr")
4503 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4504 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4508 run_test 68 "slave number in quota pool changed after each add/remove OST"
4512 local global_limit=200 # 200M
4513 local limit=10 # 10M
4514 local testfile="$DIR/$tdir/$tfile-0"
4515 local dom0="$DIR/$tdir/dom0"
4516 local qpool="qpool1"
4519 setup_quota_test || error "setup quota failed with $?"
4520 stack_trap cleanup_quota_test EXIT
4523 set_ost_qtype $QTYPE || error "enable ost quota failed"
4524 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4526 # Save DOM only at MDT0
4527 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4528 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4530 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4532 # create qpool and add OST0
4533 pool_add $qpool || error "pool_add failed"
4534 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4536 log "User quota (block hardlimit:$global_limit MB)"
4537 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4538 error "set user quota failed"
4540 log "User quota (block hardlimit:$limit MB)"
4541 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4542 error "set user quota failed"
4544 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4545 quota_error u $TSTUSR "write failed"
4547 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4548 oflag=sync || quota_error u $TSTUSR "write failed"
4550 $RUNAS $DD of=$testfile count=$limit || true
4552 # flush cache, ensure noquota flag is set on client
4553 cancel_lru_locks osc
4554 sync; sync_all_data || true
4556 # MDT0 shouldn't get EDQUOT with glimpse.
4557 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4558 quota_error u $TSTUSR \
4559 "user write success, but expect EDQUOT"
4561 # Now all members of qpool1 should get EDQUOT. Expect success
4562 # when write to DOM on MDT0, as it belongs to global pool.
4563 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4564 oflag=sync || quota_error u $TSTUSR "write failed"
4566 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4567 oflag=sync || quota_error u $TSTUSR "write failed"
4571 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4575 local qpool="qpool1"
4580 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4581 skip "Needs a client >= $VERSION_WITH_QP"
4583 setup_quota_test || error "setup quota failed with $?"
4584 stack_trap cleanup_quota_test EXIT
4586 # MDS returns EFAULT for unsupported quotactl command
4587 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4589 # create qpool and add OST0
4590 pool_add $qpool || error "pool_add failed"
4591 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4593 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4595 [ $rc -eq $err ] || error "setquota res $rc != $err"
4597 # If MDS supports QP, check that limit was set properly.
4598 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4599 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4600 echo "hard limit $bhard limit $limit"
4601 [ $bhard -ne $((limit*1024)) ] &&
4602 error "bhard:$bhard for $qpool!=$((limit*1024))"
4605 $LFS quota -u $TSTUSR --pool $qpool $DIR
4607 [ $rc -eq $err ] || error "quota res $rc != $err"
4611 run_test 70 "check lfs setquota/quota with a pool option"
4615 local limit=10 # 10M
4616 local global_limit=100 # 100M
4617 local testfile="$DIR/$tdir/$tfile-0"
4618 local qpool="qpool1"
4619 local qpool2="qpool2"
4621 [ "$ost1_FSTYPE" == zfs ] &&
4622 skip "ZFS grants some block space together with inode"
4623 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4625 setup_quota_test || error "setup quota failed with $?"
4626 stack_trap cleanup_quota_test EXIT
4629 set_ost_qtype $QTYPE || error "enable ost quota failed"
4632 log "User quota (block hardlimit:$global_limit MB)"
4633 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4634 error "set user quota failed"
4636 pool_add $qpool || error "pool_add failed"
4637 pool_add_targets $qpool 0 1 ||
4638 error "pool_add_targets failed"
4640 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4641 error "set user quota failed"
4643 pool_add $qpool2 || error "pool_add failed"
4644 pool_add_targets $qpool2 1 1 ||
4645 error "pool_add_targets failed"
4647 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4648 error "set user quota failed"
4650 # make sure the system is clean
4651 local used=$(getquota -u $TSTUSR global curspace)
4654 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4656 # create 1st component 1-10M
4657 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4658 #create 2nd component 10-30M
4659 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4660 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4662 # сheck normal use and out of quota with PFL
4663 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4664 test_1_check_write $testfile "user" $((limit*2))
4666 wait_delete_completed || error "wait_delete_completed failed"
4667 sync_all_data || true
4668 used=$(getquota -u $TSTUSR global curspace)
4669 [ $used -ne 0 ] && quota_error u $TSTUSR \
4670 "user quota isn't released after deletion"
4672 # create 1st component 1-10M
4673 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4674 # create 2nd component 10-30M
4675 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4676 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4678 # write to the 2nd component
4679 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4680 quota_error u $TSTUSR \
4681 "write failure, but expect success"
4682 # this time maybe cache write, ignore it's failure
4683 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4684 cancel_lru_locks osc
4685 sync; sync_all_data || true
4686 # write over limit in qpool2(2nd component 10-30M)
4687 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4688 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4689 # write to the 1st component - OST0 is empty
4690 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4691 quota_error u $TSTUSR "write failed"
4695 run_test 71a "Check PFL with quota pools"
4699 local global_limit=1000 # 1G
4700 local limit1=160 # 160M
4701 local limit2=10 # 10M
4702 local testfile="$DIR/$tdir/$tfile-0"
4703 local qpool="qpool1"
4704 local qpool2="qpool2"
4706 [ "$ost1_FSTYPE" == zfs ] &&
4707 skip "ZFS grants some block space together with inode"
4708 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4710 setup_quota_test || error "setup quota failed with $?"
4711 stack_trap cleanup_quota_test EXIT
4714 set_ost_qtype $QTYPE || error "enable ost quota failed"
4717 log "User quota (block hardlimit:$global_limit MB)"
4718 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4719 error "set user quota failed"
4721 pool_add $qpool || error "pool_add failed"
4722 pool_add_targets $qpool 0 1 ||
4723 error "pool_add_targets failed"
4725 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4726 error "set user quota failed"
4728 pool_add $qpool2 || error "pool_add failed"
4729 pool_add_targets $qpool2 1 1 ||
4730 error "pool_add_targets failed"
4732 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4733 error "set user quota failed"
4735 # make sure the system is clean
4736 local used=$(getquota -u $TSTUSR global curspace)
4739 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4741 # First component is on OST0, 2nd on OST1
4742 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4743 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4745 # fill the 1st component on OST0
4746 $RUNAS $DD of=$testfile count=128 ||
4747 quota_error u $TSTUSR "write failed"
4748 # write to the 2nd cmpnt on OST1
4749 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4750 quota_error u $TSTUSR "write failed"
4751 # this time maybe cache write, ignore it's failure
4752 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4754 cancel_lru_locks osc
4755 sync; sync_all_data || true
4756 # write over limit in qpool2
4757 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4758 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4762 run_test 71b "Check SEL with quota pools"
4766 local limit=10 # 10M
4767 local global_limit=50 # 50M
4768 local testfile="$DIR/$tdir/$tfile-0"
4769 local qpool="qpool1"
4772 setup_quota_test || error "setup quota failed with $?"
4773 stack_trap cleanup_quota_test EXIT
4776 set_ost_qtype $QTYPE || error "enable ost quota failed"
4779 log "User quota (block hardlimit:$global_limit MB)"
4780 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4781 error "set user quota failed"
4783 pool_add $qpool || error "pool_add failed"
4784 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4786 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4787 error "set user quota failed"
4789 # make sure the system is clean
4790 local used=$(getquota -u $TSTUSR global curspace)
4792 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4794 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4796 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4797 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4798 test_1_check_write $testfile "user" $limit
4799 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4801 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4802 # check that lfs quota -uv --pool prints only OST that
4803 # was added in a pool
4804 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4805 grep "OST\|MDT" && error "$qpool consists wrong targets"
4809 run_test 72 "lfs quota --pool prints only pool's OSTs"
4813 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4814 if $PQ_CLEANUP; then
4815 disable_project_quota
4818 reset_quota_settings
4823 check_and_cleanup_lustre
4824 export QUOTA_AUTO=$QUOTA_AUTO_OLD