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 check_set_fallocate_or_skip
1093 setup_quota_test || error "setup quota failed with $?"
1094 trap cleanup_quota_test EXIT
1097 set_ost_qtype $QTYPE || error "enable ost quota failed"
1100 log "User quota (block hardlimit:$limit MB)"
1101 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1102 error "set user quota failed"
1104 # make sure the system is clean
1105 local used=$(getquota -u $TSTUSR global curspace)
1106 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1108 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1109 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1111 check_write_fallocate $testfile "user" $limit
1114 wait_delete_completed || error "wait_delete_completed failed"
1115 sync_all_data || true
1116 used=$(getquota -u $TSTUSR global curspace)
1117 [ $used -ne 0 ] && quota_error u $TSTUSR \
1118 "user quota isn't released after deletion"
1119 resetquota -u $TSTUSR
1121 run_test 1h "Block hard limit test using fallocate"
1123 # test inode hardlimit
1125 local TESTFILE="$DIR/$tdir/$tfile-0"
1126 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1127 qmt.$FSNAME-QMT0000.md-0x0.info |
1128 awk '/least qunit/{ print $3 }')
1129 local L2=$(do_facet mds1 $LCTL get_param -n \
1130 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1132 [ $L2 -le $LIMIT ] || LIMIT=$L2
1134 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1136 local FREE_INODES=$(mdt_free_inodes 0)
1137 echo "$FREE_INODES free inodes on master MDT"
1138 [ $FREE_INODES -lt $LIMIT ] &&
1139 skip "not enough free inodes $FREE_INODES required $LIMIT"
1141 setup_quota_test || error "setup quota failed with $?"
1142 trap cleanup_quota_test EXIT
1145 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1148 log "User quota (inode hardlimit:$LIMIT files)"
1149 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1150 error "set user quota failed"
1152 # make sure the system is clean
1153 local USED=$(getquota -u $TSTUSR global curinodes)
1154 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1156 log "Create $LIMIT files ..."
1157 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1158 quota_error u $TSTUSR "user create failure, but expect success"
1159 log "Create out of file quota ..."
1160 $RUNAS touch ${TESTFILE}_xxx &&
1161 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1164 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1165 rm -f ${TESTFILE}_xxx
1166 wait_delete_completed
1168 USED=$(getquota -u $TSTUSR global curinodes)
1169 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1170 "user quota isn't released after deletion"
1171 resetquota -u $TSTUSR
1174 log "--------------------------------------"
1175 log "Group quota (inode hardlimit:$LIMIT files)"
1176 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1177 error "set group quota failed"
1179 TESTFILE=$DIR/$tdir/$tfile-1
1180 # make sure the system is clean
1181 USED=$(getquota -g $TSTUSR global curinodes)
1182 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1184 log "Create $LIMIT files ..."
1185 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1186 quota_error g $TSTUSR "group create failure, but expect success"
1187 log "Create out of file quota ..."
1188 $RUNAS touch ${TESTFILE}_xxx &&
1189 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1192 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1193 rm -f ${TESTFILE}_xxx
1194 wait_delete_completed
1196 USED=$(getquota -g $TSTUSR global curinodes)
1197 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1198 "user quota isn't released after deletion"
1200 resetquota -g $TSTUSR
1201 ! is_project_quota_supported && cleanup_quota_test &&
1202 echo "Skip project quota is not supported" && return 0
1205 log "--------------------------------------"
1206 log "Project quota (inode hardlimit:$LIMIT files)"
1207 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1208 error "set project quota failed"
1210 TESTFILE=$DIR/$tdir/$tfile-1
1211 # make sure the system is clean
1212 USED=$(getquota -p $TSTPRJID global curinodes)
1214 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1216 change_project -sp $TSTPRJID $DIR/$tdir
1217 log "Create $LIMIT files ..."
1218 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1219 $TSTPRJID "project create fail, but expect success"
1220 log "Create out of file quota ..."
1221 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1222 "project create success, but expect EDQUOT"
1223 change_project -C $DIR/$tdir
1226 USED=$(getquota -p $TSTPRJID global curinodes)
1227 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1228 "project quota isn't released after deletion"
1231 run_test 2 "File hard limit (normal use and out of quota)"
1242 stack_trap cleanup_quota_test EXIT
1244 $LFS setstripe $testfile -c 1 -i 0
1245 chown $TSTUSR.$TSTUSR $testfile
1246 [ "$qtype" == "p" ] && is_project_quota_supported &&
1247 change_project -p $TSTPRJID $testfile
1249 echo "Write up to soft limit"
1250 $RUNAS $DD of=$testfile count=$limit ||
1251 quota_error a $TSTUSR "write failure, but expect success"
1252 OFFSET=$((limit * 1024))
1253 cancel_lru_locks osc
1255 echo "Write to exceed soft limit"
1256 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1257 quota_error a $TSTUSR "write failure, but expect success"
1258 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1259 cancel_lru_locks osc
1261 echo "mmap write when over soft limit"
1262 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1263 quota_error a $TSTUSR "mmap write failure, but expect success"
1264 cancel_lru_locks osc
1269 $SHOW_QUOTA_INFO_USER
1270 $SHOW_QUOTA_INFO_GROUP
1271 $SHOW_QUOTA_INFO_PROJID
1273 echo "Write before timer goes off"
1274 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1275 quota_error a $TSTUSR "write failure, but expect success"
1276 OFFSET=$((OFFSET + 1024))
1277 cancel_lru_locks osc
1279 wait_grace_time $qtype "block" $pool
1284 $SHOW_QUOTA_INFO_USER
1285 $SHOW_QUOTA_INFO_GROUP
1286 $SHOW_QUOTA_INFO_PROJID
1288 log "Write after timer goes off"
1289 # maybe cache write, ignore.
1290 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1291 OFFSET=$((OFFSET + 1024))
1292 cancel_lru_locks osc
1293 log "Write after cancel lru locks"
1294 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1295 quota_error a $TSTUSR "write success, but expect EDQUOT"
1300 $SHOW_QUOTA_INFO_USER
1301 $SHOW_QUOTA_INFO_GROUP
1302 $SHOW_QUOTA_INFO_PROJID
1304 echo "Unlink file to stop timer"
1306 wait_delete_completed
1307 sync_all_data || true
1312 $SHOW_QUOTA_INFO_USER
1313 $SHOW_QUOTA_INFO_GROUP
1314 $SHOW_QUOTA_INFO_PROJID
1316 $LFS setstripe $testfile -c 1 -i 0
1317 chown $TSTUSR.$TSTUSR $testfile
1318 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1321 $RUNAS $DD of=$testfile count=$limit ||
1322 quota_error a $TSTUSR "write failure, but expect success"
1329 local grace=20 # 20s
1330 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1333 local testfile=$DIR/$tdir/$tfile-0
1335 # get minimum soft qunit size
1336 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1337 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1339 set_ost_qtype $QTYPE || error "enable ost quota failed"
1341 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1342 # make sure the system is clean
1343 local used=$(getquota -u $TSTUSR global curspace)
1344 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1346 $LFS setquota -t -u --block-grace $grace --inode-grace \
1347 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1348 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1349 error "set user quota failed"
1351 test_block_soft $testfile $grace $limit "u"
1353 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1354 testfile=$DIR/$tdir/$tfile-1
1355 # make sure the system is clean
1356 used=$(getquota -g $TSTUSR global curspace)
1357 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1359 $LFS setquota -t -g --block-grace $grace --inode-grace \
1360 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1361 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1362 error "set group quota failed"
1364 test_block_soft $testfile $grace $limit "g"
1366 if is_project_quota_supported; then
1367 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1368 testfile=$DIR/$tdir/$tfile-2
1369 # make sure the system is clean
1370 used=$(getquota -p $TSTPRJID global curspace)
1371 [ $used -ne 0 ] && error \
1372 "Used space($used) for project $TSTPRJID isn't 0."
1374 $LFS setquota -t -p --block-grace $grace --inode-grace \
1375 $MAX_IQ_TIME $DIR ||
1376 error "set project grace time failed"
1377 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1378 $DIR || error "set project quota failed"
1380 test_block_soft $testfile $grace $limit "p"
1381 resetquota -p $TSTPRJID
1382 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1383 $MAX_IQ_TIME $DIR ||
1384 error "restore project grace time failed"
1388 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1389 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1390 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1391 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1393 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1396 local grace=20 # 20s
1397 local qpool="qpool1"
1398 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1401 local testfile=$DIR/$tdir/$tfile-0
1404 # get minimum soft qunit size
1405 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1406 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1407 local glbl_limit=$((2*limit))
1408 local glbl_grace=$((2*grace))
1409 echo "limit $limit glbl_limit $glbl_limit"
1410 echo "grace $grace glbl_grace $glbl_grace"
1412 set_ost_qtype $QTYPE || error "enable ost quota failed"
1414 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1415 # make sure the system is clean
1416 local used=$(getquota -u $TSTUSR global curspace)
1417 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1419 pool_add $qpool || error "pool_add failed"
1420 pool_add_targets $qpool 0 1 ||
1421 error "pool_add_targets failed"
1423 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1424 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1425 $LFS setquota -t -u --block-grace $grace \
1426 --pool $qpool $DIR || error "set user grace time failed"
1428 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1429 error "set user quota failed"
1430 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1431 error "set user quota failed"
1433 test_block_soft $testfile $grace $limit "u" $qpool
1435 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1436 testfile=$DIR/$tdir/$tfile-1
1437 # make sure the system is clean
1438 used=$(getquota -g $TSTUSR global curspace)
1439 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1441 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1442 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1443 $LFS setquota -t -g --block-grace $grace \
1444 --pool $qpool $DIR || error "set group grace time failed"
1446 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1447 error "set group quota failed"
1448 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1449 error "set group quota failed"
1451 test_block_soft $testfile $grace $limit "g" $qpool
1453 if is_project_quota_supported; then
1454 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1455 testfile=$DIR/$tdir/$tfile-2
1456 # make sure the system is clean
1457 used=$(getquota -p $TSTPRJID global curspace)
1458 [ $used -ne 0 ] && error \
1459 "Used space($used) for project $TSTPRJID isn't 0."
1461 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1462 $MAX_IQ_TIME $DIR ||
1463 error "set project grace time failed"
1464 $LFS setquota -t -p --block-grace $grace \
1465 --pool $qpool $DIR ||
1466 error "set project grace time failed"
1468 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1469 $DIR || error "set project quota failed"
1470 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1471 --pool $qpool $DIR || error "set project quota failed"
1473 test_block_soft $testfile $grace $limit "p" $qpool
1474 resetquota -p $TSTPRJID
1475 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1476 $MAX_IQ_TIME $DIR ||
1477 error "restore project grace time failed"
1478 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1479 $DIR || error "set project grace time failed"
1483 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1484 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1485 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1486 --pool $qpool $DIR || error "restore user grace time failed"
1487 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1488 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1489 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1490 --pool $qpool $DIR || error "restore group grace time failed"
1492 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1495 local grace=20 # 20s
1496 local qpool="qpool1"
1497 local qpool2="qpool2"
1498 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1501 local testfile=$DIR/$tdir/$tfile-0
1504 # get minimum soft qunit size
1505 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1506 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1507 local limit2=$((limit+4))
1508 local glbl_limit=$((limit+8))
1509 local grace1=$((grace+10))
1511 local glbl_grace=$((grace+20))
1512 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1513 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1515 set_ost_qtype $QTYPE || error "enable ost quota failed"
1517 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1518 # make sure the system is clean
1519 local used=$(getquota -u $TSTUSR global curspace)
1520 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1522 pool_add $qpool || error "pool_add failed"
1523 pool_add_targets $qpool 0 1 ||
1524 error "pool_add_targets failed"
1526 pool_add $qpool2 || error "pool_add failed"
1527 pool_add_targets $qpool2 0 1 ||
1528 error "pool_add_targets failed"
1531 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1532 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1533 $LFS setquota -t -u --block-grace $grace1 \
1534 --pool $qpool $DIR || error "set user grace time failed"
1535 $LFS setquota -t -u --block-grace $grace2 \
1536 --pool $qpool2 $DIR || error "set user grace time failed"
1538 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1539 error "set user quota failed"
1540 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1541 error "set user quota failed"
1542 # qpool has minimum soft limit, but it's grace is grater than
1543 # grace period of qpool2. Thus write shouldn't fail when
1544 # hit qpool soft limit - only when reaches up qpool2 limit
1545 # after grace2 seconds.
1546 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1547 error "set user quota failed"
1549 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1552 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1553 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1554 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1555 --pool $qpool $DIR || error "restore user grace time failed"
1556 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1557 --pool $qpool2 $DIR || error "restore user grace time failed"
1559 run_test 3c "Quota pools: check block soft limit on different pools"
1566 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1567 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1570 trap cleanup_quota_test EXIT
1571 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1573 echo "Create files to exceed soft limit"
1574 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1575 quota_error a $TSTUSR "create failure, but expect success"
1576 local trigger_time=$(date +%s)
1578 sync_all_data || true
1580 local cur_time=$(date +%s)
1581 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1582 error "Passed grace time $grace, $trigger_time, $cur_time"
1584 echo "Create file before timer goes off"
1585 $RUNAS touch ${TESTFILE}_before ||
1586 quota_error a $TSTUSR "failed create before timer expired," \
1587 "but expect success. $trigger_time, $cur_time"
1588 sync_all_data || true
1590 wait_grace_time $qtype "file"
1595 $SHOW_QUOTA_INFO_USER
1596 $SHOW_QUOTA_INFO_GROUP
1597 $SHOW_QUOTA_INFO_PROJID
1599 echo "Create file after timer goes off"
1600 # exceed least soft limit is possible
1601 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1602 quota_error a $TSTUSR "create after timer expired," \
1604 sync_all_data || true
1609 $SHOW_QUOTA_INFO_USER
1610 $SHOW_QUOTA_INFO_GROUP
1611 $SHOW_QUOTA_INFO_PROJID
1613 echo "Unlink files to stop timer"
1614 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1615 wait_delete_completed
1618 $RUNAS touch ${TESTFILE}_xxx ||
1619 quota_error a $TSTUSR "touch after timer stop failure," \
1620 "but expect success"
1621 sync_all_data || true
1629 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1630 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1631 local TESTFILE=$DIR/$tdir/$tfile-0
1634 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1636 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1637 # make sure the system is clean
1638 local USED=$(getquota -u $TSTUSR global curinodes)
1639 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1641 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1642 $GRACE $DIR || error "set user grace time failed"
1643 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1644 error "set user quota failed"
1646 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1648 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1650 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1651 # make sure the system is clean
1652 USED=$(getquota -g $TSTUSR global curinodes)
1653 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1655 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1656 $GRACE $DIR || error "set group grace time failed"
1657 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1658 error "set group quota failed"
1659 TESTFILE=$DIR/$tdir/$tfile-1
1661 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1663 if is_project_quota_supported; then
1664 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1665 # make sure the system is clean
1666 USED=$(getquota -p $TSTPRJID global curinodes)
1667 [ $USED -ne 0 ] && error \
1668 "Used space($USED) for project $TSTPRJID isn't 0."
1670 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1671 $GRACE $DIR || error "set project grace time failed"
1672 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1673 error "set project quota failed"
1675 TESTFILE=$DIR/$tdir/$tfile-1
1676 # one less than limit, because of parent directory included.
1677 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1678 resetquota -p $TSTPRJID
1679 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1680 $MAX_IQ_TIME $DIR ||
1681 error "restore project grace time failed"
1685 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1686 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1687 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1688 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1690 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1693 local GR_STR1="1w3d"
1694 local GR_STR2="1000s"
1696 local GR_STR4="1w2d3h4m5s"
1698 local GR_STR6="18446744073709551615"
1701 wait_delete_completed
1703 # test of valid grace strings handling
1704 echo "Valid grace strings test"
1705 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1706 $GR_STR2 $DIR || error "set user grace time failed"
1707 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1708 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1709 $GR_STR4 $DIR || error "set group grace time quota failed"
1710 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1712 # test of invalid grace strings handling
1713 echo " Invalid grace strings test"
1714 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1715 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1716 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1720 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1721 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1722 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1723 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1725 run_test 4b "Grace time strings handling"
1727 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1729 local BLIMIT=10 # 10M
1730 local ILIMIT=10 # 10 inodes
1732 setup_quota_test || error "setup quota failed with $?"
1733 trap cleanup_quota_test EXIT
1735 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1736 set_ost_qtype $QTYPE || error "enable ost quota failed"
1738 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1739 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1740 error "set user quota failed"
1741 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1742 if is_project_quota_supported; then
1743 error "set group quota failed"
1744 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1745 -I $ILIMIT $DIR || error "set project quota failed"
1748 # make sure the system is clean
1749 local USED=$(getquota -u $TSTUSR global curinodes)
1750 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1751 USED=$(getquota -g $TSTUSR global curinodes)
1752 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1753 USED=$(getquota -u $TSTUSR global curspace)
1754 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1755 USED=$(getquota -g $TSTUSR global curspace)
1756 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1757 if is_project_quota_supported; then
1758 USED=$(getquota -p $TSTPRJID global curinodes)
1760 error "Used inode($USED) for project $TSTPRJID isn't 0."
1761 USED=$(getquota -p $TSTPRJID global curspace)
1763 error "Used block($USED) for project $TSTPRJID isn't 0."
1766 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1767 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1768 error "create failure, expect success"
1769 if is_project_quota_supported; then
1770 touch $DIR/$tdir/$tfile-0_1
1771 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1773 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1774 error "write failure, expect success"
1776 echo "Chown files to $TSTUSR.$TSTUSR ..."
1777 for i in $(seq 0 $ILIMIT); do
1778 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1779 quota_error a $TSTUSR "chown failure, expect success"
1783 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1784 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1787 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1789 # test dropping acquire request on master
1793 # Clear dmesg so watchdog is not triggered by previous
1795 do_facet ost1 dmesg -c > /dev/null
1797 setup_quota_test || error "setup quota failed with $?"
1798 trap cleanup_quota_test EXIT
1800 # make sure the system is clean
1801 local USED=$(getquota -u $TSTUSR global curspace)
1802 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1804 # make sure no granted quota on ost
1805 set_ost_qtype $QTYPE || error "enable ost quota failed"
1806 resetquota -u $TSTUSR
1808 # create file for $TSTUSR
1809 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1810 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1811 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1813 # create file for $TSTUSR2
1814 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1815 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1816 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1818 # cache per-ID lock for $TSTUSR on slave
1819 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1820 error "set quota failed"
1821 $RUNAS $DD of=$TESTFILE count=1 ||
1822 error "write $TESTFILE failure, expect success"
1823 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1824 error "write $TESTFILE2 failure, expect success"
1826 if at_is_enabled; then
1827 at_max_saved=$(at_max_get ost1)
1828 at_max_set $TIMEOUT ost1
1830 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1831 # DQACQ is sent, which makes at_max to take effect
1832 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1835 wait_delete_completed
1839 sync_all_data || true
1841 #define QUOTA_DQACQ 601
1842 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1843 lustre_fail mds 0x513 601
1845 do_facet ost1 $LCTL set_param \
1846 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1848 # write to un-enforced ID ($TSTUSR2) should succeed
1849 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1850 error "write failure, expect success"
1852 # write to enforced ID ($TSTUSR) in background, exceeding limit
1853 # to make sure DQACQ is sent
1854 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1857 # watchdog timer uses a factor of 2
1858 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1859 sleep $((TIMEOUT * 2 + 1))
1861 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1863 # write should be blocked and never finished
1864 if ! ps -p $DDPID > /dev/null 2>&1; then
1866 error "write finished incorrectly!"
1871 # no watchdog is triggered
1872 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1873 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1874 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1875 [ -z "$watchdog" ] || error "$watchdog"
1877 rm -f $TMP/lustre-log-${TESTNAME}.log
1879 # write should continue then fail with EDQUOT
1883 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1884 if [ $count -ge 240 ]; then
1885 quota_error u $TSTUSR "dd not finished in $count secs"
1887 count=$((count + 1))
1888 if [ $((count % 30)) -eq 0 ]; then
1889 c_size=$(stat -c %s $TESTFILE)
1890 echo "Waiting $count secs. $c_size"
1898 run_test 6 "Test dropping acquire request on master"
1900 # quota reintegration (global index)
1902 local TESTFILE=$DIR/$tdir/$tfile
1903 local LIMIT=20 # 20M
1905 [ "$SLOW" = "no" ] && LIMIT=5
1907 setup_quota_test || error "setup quota failed with $?"
1908 trap cleanup_quota_test EXIT
1910 # make sure the system is clean
1911 local USED=$(getquota -u $TSTUSR global curspace)
1912 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1914 # make sure no granted quota on ost1
1915 set_ost_qtype $QTYPE || error "enable ost quota failed"
1916 resetquota -u $TSTUSR
1917 set_ost_qtype "none" || error "disable ost quota failed"
1919 local OSTUUID=$(ostuuid_from_index 0)
1920 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1922 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1925 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1926 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1931 echo "Enable quota & set quota limit for $TSTUSR"
1932 set_ost_qtype $QTYPE || error "enable ost quota failed"
1933 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1934 error "set quota failed"
1936 echo "Start ost1..."
1937 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1940 wait_ost_reint $QTYPE || error "reintegration failed"
1942 # hardlimit should have been fetched by slave during global
1943 # reintegration, write will exceed quota
1944 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1945 quota_error u $TSTUSR "write success, but expect EDQUOT"
1948 wait_delete_completed
1949 sync_all_data || true
1955 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1956 error "clear quota failed"
1958 echo "Start ost1..."
1959 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1962 wait_ost_reint $QTYPE || error "reintegration failed"
1964 # hardlimit should be cleared on slave during reintegration
1965 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1966 quota_error u $TSTUSR "write error, but expect success"
1970 run_test 7a "Quota reintegration (global index)"
1972 # quota reintegration (slave index)
1975 local TESTFILE=$DIR/$tdir/$tfile
1977 setup_quota_test || error "setup quota failed with $?"
1978 trap cleanup_quota_test EXIT
1980 # make sure the system is clean
1981 local USED=$(getquota -u $TSTUSR global curspace)
1982 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1984 # make sure no granted quota on ost1
1985 set_ost_qtype $QTYPE || error "enable ost quota failed"
1986 resetquota -u $TSTUSR
1987 set_ost_qtype "none" || error "disable ost quota failed"
1989 local OSTUUID=$(ostuuid_from_index 0)
1990 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1992 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1995 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1996 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1998 # consume some space to make sure the granted space will not
1999 # be released during reconciliation
2000 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2001 error "consume space failure, expect success"
2003 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2004 lustre_fail mds 0xa02
2006 set_ost_qtype $QTYPE || error "enable ost quota failed"
2007 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2008 error "set quota failed"
2010 # ignore the write error
2011 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2013 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2017 echo "Restart ost to trigger reintegration..."
2019 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2022 wait_ost_reint $QTYPE || error "reintegration failed"
2024 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2025 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2030 run_test 7b "Quota reintegration (slave index)"
2032 # quota reintegration (restart mds during reintegration)
2034 local LIMIT=20 # 20M
2035 local TESTFILE=$DIR/$tdir/$tfile
2037 [ "$SLOW" = "no" ] && LIMIT=5
2039 setup_quota_test || error "setup quota failed with $?"
2040 trap cleanup_quota_test EXIT
2042 # make sure the system is clean
2043 local USED=$(getquota -u $TSTUSR global curspace)
2044 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2046 set_ost_qtype "none" || error "disable ost quota failed"
2047 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2048 error "set quota failed"
2050 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2051 lustre_fail ost 0xa03
2054 set_ost_qtype $QTYPE || error "enable ost quota failed"
2055 # trigger reintegration
2056 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2057 procf=${procf}quota_slave.force_reint
2058 do_facet ost1 $LCTL set_param $procf=1 ||
2059 error "force reintegration failed"
2067 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2070 # wait longer than usual to make sure the reintegration
2071 # is triggered by quota wb thread.
2072 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2074 # hardlimit should have been fetched by slave during global
2075 # reintegration, write will exceed quota
2076 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2077 quota_error u $TSTUSR "write success, but expect EDQUOT"
2081 run_test 7c "Quota reintegration (restart mds during reintegration)"
2083 # Quota reintegration (Transfer index in multiple bulks)
2085 local TESTFILE=$DIR/$tdir/$tfile
2086 local TESTFILE1="$DIR/$tdir/$tfile"-1
2089 setup_quota_test || error "setup quota failed with $?"
2090 trap cleanup_quota_test EXIT
2092 set_ost_qtype "none" || error "disable ost quota failed"
2093 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2094 error "set quota for $TSTUSR failed"
2095 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2096 error "set quota for $TSTUSR2 failed"
2098 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2099 lustre_fail mds 0x608 0
2101 # enable quota to tirgger reintegration
2102 set_ost_qtype "u" || error "enable ost quota failed"
2103 wait_ost_reint "u" || error "reintegration failed"
2107 # hardlimit should have been fetched by slave during global
2108 # reintegration, write will exceed quota
2109 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2110 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2112 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2113 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2117 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2119 # quota reintegration (inode limits)
2121 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2123 # LU-2435: skip this quota test if underlying zfs version has not
2124 # supported native dnode accounting
2125 [ "$mds1_FSTYPE" == zfs ] && {
2126 local F="feature@userobj_accounting"
2127 local pool=$(zpool_name mds1)
2128 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2130 [[ "$feature" != *" active "* ]] &&
2131 skip "requires zpool with active userobj_accounting"
2134 local ilimit=$((1024 * 2)) # 2k inodes
2135 local TESTFILE=$DIR/${tdir}-1/$tfile
2137 setup_quota_test || error "setup quota failed with $?"
2138 trap cleanup_quota_test EXIT
2140 # make sure the system is clean
2141 local USED=$(getquota -u $TSTUSR global curinodes)
2142 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2144 # make sure no granted quota on mdt1
2145 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2146 resetquota -u $TSTUSR
2147 set_mdt_qtype "none" || error "disable mdt quota failed"
2149 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2150 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2151 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2154 echo "Stop mds${MDSCOUNT}..."
2157 echo "Enable quota & set quota limit for $TSTUSR"
2158 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2159 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2160 error "set quota failed"
2162 echo "Start mds${MDSCOUNT}..."
2163 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2166 wait_mdt_reint $QTYPE || error "reintegration failed"
2168 echo "create remote dir"
2169 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2170 error "create remote dir failed"
2171 chmod 0777 $DIR/${tdir}-1
2173 # hardlimit should have been fetched by slave during global
2174 # reintegration, create will exceed quota
2175 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2176 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2178 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2179 wait_delete_completed
2180 sync_all_data || true
2182 echo "Stop mds${MDSCOUNT}..."
2185 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2186 error "clear quota failed"
2188 echo "Start mds${MDSCOUNT}..."
2189 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2192 wait_mdt_reint $QTYPE || error "reintegration failed"
2194 # hardlimit should be cleared on slave during reintegration
2195 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2196 quota_error u $TSTUSR "create failed, expect success"
2198 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2199 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2203 run_test 7e "Quota reintegration (inode limits)"
2205 # run dbench with quota enabled
2207 local BLK_LIMIT="100g" #100G
2208 local FILE_LIMIT=1000000
2210 setup_quota_test || error "setup quota failed with $?"
2211 trap cleanup_quota_test EXIT
2213 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2214 set_ost_qtype $QTYPE || error "enable ost quota failed"
2216 echo "Set enough high limit for user: $TSTUSR"
2217 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2218 error "set user quota failed"
2219 echo "Set enough high limit for group: $TSTUSR"
2220 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2221 error "set group quota failed"
2222 if is_project_quota_supported; then
2223 change_project -sp $TSTPRJID $DIR/$tdir
2224 echo "Set enough high limit for project: $TSTPRJID"
2225 $LFS setquota -p $TSTPRJID -b 0 \
2226 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2227 error "set project quota failed"
2231 [ "$SLOW" = "no" ] && duration=" -t 120"
2232 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2233 quota_error a $TSTUSR "dbench failed!"
2235 is_project_quota_supported && change_project -C $DIR/$tdir
2238 run_test 8 "Run dbench with quota enabled"
2240 # this check is just for test_9
2241 OST0_MIN=4900000 #4.67G
2243 check_whether_skip () {
2244 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2245 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2246 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2247 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2254 # run for fixing bug10707, it needs a big room. test for 64bit
2256 local filesize=$((1024 * 9 / 2)) # 4.5G
2258 check_whether_skip && return 0
2260 setup_quota_test || error "setup quota failed with $?"
2261 trap cleanup_quota_test EXIT
2263 set_ost_qtype "ug" || error "enable ost quota failed"
2265 local TESTFILE="$DIR/$tdir/$tfile-0"
2266 local BLK_LIMIT=100G #100G
2267 local FILE_LIMIT=1000000
2269 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2271 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2273 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2274 error "set user quota failed"
2276 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2277 "for group: $TSTUSR"
2278 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2279 error "set group quota failed"
2281 quota_show_check a u $TSTUSR
2282 quota_show_check a g $TSTUSR
2284 echo "Create test file"
2285 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2286 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2288 log "Write the big file of 4.5G ..."
2289 $RUNAS $DD of=$TESTFILE count=$filesize ||
2290 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2300 run_test 9 "Block limit larger than 4GB (b10707)"
2303 local TESTFILE=$DIR/$tdir/$tfile
2305 setup_quota_test || error "setup quota failed with $?"
2306 trap cleanup_quota_test EXIT
2308 # set limit to root user should fail
2309 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2310 error "set limit for root user successfully, expect failure"
2311 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2312 error "set limit for root group successfully, expect failure"
2313 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2314 error "set limit for project 0 successfully, expect failure"
2316 # root user can overrun quota
2317 set_ost_qtype "ug" || error "enable ost quota failed"
2319 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2320 error "set quota failed"
2321 quota_show_check b u $TSTUSR
2323 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2324 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2326 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2327 error "write failure, expect success"
2331 run_test 10 "Test quota for root user"
2334 local TESTFILE=$DIR/$tdir/$tfile
2335 setup_quota_test || error "setup quota failed with $?"
2336 trap cleanup_quota_test EXIT
2338 set_mdt_qtype "ug" || error "enable mdt quota failed"
2339 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2340 error "set quota failed"
2342 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2343 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2345 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2346 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2349 local USED=$(getquota -u $TSTUSR global curinodes)
2350 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2354 run_test 11 "Chown/chgrp ignores quota"
2357 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2359 local blimit=22 # 22M
2360 local blk_cnt=$((blimit - 5))
2361 local TESTFILE0="$DIR/$tdir/$tfile"-0
2362 local TESTFILE1="$DIR/$tdir/$tfile"-1
2364 setup_quota_test || error "setup quota failed with $?"
2365 trap cleanup_quota_test EXIT
2367 set_ost_qtype "u" || error "enable ost quota failed"
2368 quota_show_check b u $TSTUSR
2370 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2371 error "set quota failed"
2373 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2374 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2375 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2376 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2378 echo "Write to ost0..."
2379 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2380 quota_error a $TSTUSR "dd failed"
2382 echo "Write to ost1..."
2383 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2384 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2386 echo "Free space from ost0..."
2388 wait_delete_completed
2389 sync_all_data || true
2391 echo "Write to ost1 after space freed from ost0..."
2392 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2393 quota_error a $TSTUSR "rebalancing failed"
2397 run_test 12a "Block quota rebalancing"
2400 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2402 local ilimit=$((1024 * 2)) # 2k inodes
2403 local TESTFILE0=$DIR/$tdir/$tfile
2404 local TESTFILE1=$DIR/${tdir}-1/$tfile
2406 setup_quota_test || error "setup quota failed with $?"
2407 trap cleanup_quota_test EXIT
2409 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2410 chmod 0777 $DIR/${tdir}-1
2412 set_mdt_qtype "u" || error "enable mdt quota failed"
2413 quota_show_check f u $TSTUSR
2415 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2416 error "set quota failed"
2418 echo "Create $ilimit files on mdt0..."
2419 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2420 quota_error u $TSTUSR "create failed, but expect success"
2422 echo "Create files on mdt1..."
2423 $RUNAS createmany -m $TESTFILE1 1 &&
2424 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2426 echo "Free space from mdt0..."
2427 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2428 wait_delete_completed
2429 sync_all_data || true
2431 echo "Create files on mdt1 after space freed from mdt0..."
2432 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2433 quota_error a $TSTUSR "rebalancing failed"
2435 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2436 error "unlink mdt1 files failed"
2437 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2441 run_test 12b "Inode quota rebalancing"
2444 local TESTFILE=$DIR/$tdir/$tfile
2445 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2446 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2448 setup_quota_test || error "setup quota failed with $?"
2449 trap cleanup_quota_test EXIT
2451 set_ost_qtype "u" || error "enable ost quota failed"
2452 quota_show_check b u $TSTUSR
2454 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2455 error "set quota failed"
2456 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2457 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2459 # clear the locks in cache first
2460 do_facet ost1 $LCTL set_param -n $procf=clear
2461 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2462 [ $nlock -eq 0 ] || error "$nlock cached locks"
2464 # write to acquire the per-ID lock
2465 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2466 quota_error a $TSTUSR "dd failed"
2468 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2469 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2471 # clear quota doesn't trigger per-ID lock cancellation
2472 resetquota -u $TSTUSR
2473 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2474 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2476 # clear the per-ID lock
2477 do_facet ost1 $LCTL set_param -n $procf=clear
2478 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2479 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2481 # spare quota should be released
2482 local OSTUUID=$(ostuuid_from_index 0)
2483 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2484 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2485 [ $limit -le $space ] ||
2486 error "spare quota isn't released, limit:$limit, space:$space"
2490 run_test 13 "Cancel per-ID lock in the LRU list"
2493 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2495 wait_delete_completed
2496 sync_all_data || true
2499 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2500 error "set user quota failed"
2501 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2502 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2503 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2504 resetquota -u $TSTUSR
2507 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2508 error "set group quota failed"
2509 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2510 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2511 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2512 resetquota -g $TSTUSR
2514 run_test 15 "Set over 4T block quota"
2518 local BLKS=1 # 1M less than limit
2519 local TESTFILE=$DIR/$tdir/$tfile
2521 setup_quota_test || error "setup quota failed with $?"
2522 trap cleanup_quota_test EXIT
2524 # make sure the system is clean
2525 local USED=$(getquota -u $TSTUSR global curspace)
2526 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2528 set_ost_qtype "ug" || error "enable ost quota failed"
2529 # make sure no granted quota on ost
2530 resetquota -u $TSTUSR
2531 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2532 error "set quota failed"
2534 quota_show_check b u $TSTUSR
2536 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2537 lustre_fail mds 0xa04 $err_code
2539 # write in background
2540 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2544 # write should be blocked and never finished
2545 if ! ps -p $DDPID > /dev/null 2>&1; then
2547 quota_error u $TSTUSR "write finished incorrectly!"
2555 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2557 if [ $count -gt $timeout ]; then
2558 quota_error u $TSTUSR "dd is not finished!"
2563 sync; sync_all_data || true
2565 USED=$(getquota -u $TSTUSR global curspace)
2566 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2567 "Used space(${USED}K) is less than ${BLKS}M"
2572 # DQACQ return recoverable error
2574 echo "DQACQ return -ENOLCK"
2576 test_17sub 37 || error "Handle -ENOLCK failed"
2578 echo "DQACQ return -EAGAIN"
2580 test_17sub 11 || error "Handle -EAGAIN failed"
2582 echo "DQACQ return -ETIMEDOUT"
2583 #define ETIMEDOUT 110
2584 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2586 echo "DQACQ return -ENOTCONN"
2587 #define ENOTCONN 107
2588 test_17sub 107 || error "Handle -ENOTCONN failed"
2591 run_test 17 "DQACQ return recoverable error"
2595 local blimit="200m" # 200M
2596 local TESTFILE="$DIR/$tdir/$tfile"
2598 setup_quota_test || error "setup quota failed with $?"
2599 trap cleanup_quota_test EXIT
2601 set_ost_qtype "u" || error "enable ost quota failed"
2602 log "User quota (limit: $blimit)"
2603 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2604 error "set quota failed"
2605 quota_show_check b u $TSTUSR
2607 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2608 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2610 local timeout=$(sysctl -n lustre.timeout)
2612 if [ $io_type = "directio" ]; then
2613 log "Write 100M (directio) ..."
2614 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2616 log "Write 100M (buffered) ..."
2617 $RUNAS $DD of=$TESTFILE count=100 &
2621 replay_barrier $SINGLEMDS
2622 log "Fail mds for $((2 * timeout)) seconds"
2623 fail $SINGLEMDS $((2 * timeout))
2626 if at_is_enabled; then
2627 timeout=$(at_max_get mds)
2629 timeout=$(lctl get_param -n timeout)
2633 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2634 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2635 log "it took $count second"
2640 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2642 cancel_lru_locks mdc
2643 cancel_lru_locks osc
2646 local testfile_size=$(stat -c %s $TESTFILE)
2647 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2648 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2649 "got ${testfile_size}. Verifying file failed!"
2654 # test when mds does failover, the ost still could work well
2655 # this test shouldn't trigger watchdog b=14840
2657 # Clear dmesg so watchdog is not triggered by previous
2659 do_facet ost1 dmesg -c > /dev/null
2662 test_18_sub directio
2664 # check if watchdog is triggered
2665 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2666 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2667 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2668 [ -z "$watchdog" ] || error "$watchdog"
2669 rm -f $TMP/lustre-log-${TESTNAME}.log
2671 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2675 local TESTFILE=$DIR/$tdir/$tfile
2677 setup_quota_test || error "setup quota failed with $?"
2678 trap cleanup_quota_test EXIT
2680 set_ost_qtype $QTYPE || error "enable ost quota failed"
2682 # bind file to a single OST
2683 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2684 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2686 echo "Set user quota (limit: ${blimit}M)"
2687 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2688 error "set user quota failed"
2689 quota_show_check b u $TSTUSR
2690 echo "Update quota limits"
2691 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2692 error "set group quota failed"
2693 quota_show_check b u $TSTUSR
2695 # first wirte might be cached
2696 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2697 cancel_lru_locks osc
2699 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2700 quota_error u $TSTUSR "Write success, expect failure"
2705 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2707 test_20() { # b15754
2708 local LSTR=(2g 1t 4k 3m) # limits strings
2710 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2713 resetquota -u $TSTUSR
2715 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2716 $MOUNT || error "could not set quota limits"
2717 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2718 --inode-softlimit ${LSTR[2]} \
2719 --inode-hardlimit ${LSTR[3]} \
2720 $MOUNT || error "could not set quota limits"
2722 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2723 error "bsoftlimit was not set properly"
2724 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2725 error "bhardlimit was not set properly"
2726 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2727 error "isoftlimit was not set properly"
2728 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2729 error "ihardlimit was not set properly"
2731 resetquota -u $TSTUSR
2733 run_test 20 "Test if setquota specifiers work properly (b15754)"
2740 local time=$(($(date +%s) + seconds))
2741 while [ $(date +%s) -lt $time ]; do
2742 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2746 # run for fixing bug16053, setquota shouldn't fail when writing and
2747 # deleting are happening
2749 local TESTFILE="$DIR/$tdir/$tfile"
2750 local BLIMIT=10 # 10G
2751 local ILIMIT=1000000
2753 setup_quota_test || error "setup quota failed with $?"
2754 trap cleanup_quota_test EXIT
2756 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2758 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2759 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2760 error "set user quota failed"
2761 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2762 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2763 error "set group quota failed"
2764 if is_project_quota_supported; then
2765 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2766 "project: $TSTPRJID"
2767 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2768 $MOUNT || error "set project quota failed"
2771 # repeat writing on a 1M file
2772 test_21_sub ${TESTFILE}_1 1 30 &
2774 # repeat writing on a 128M file
2775 test_21_sub ${TESTFILE}_2 128 30 &
2778 local time=$(($(date +%s) + 30))
2780 while [ $(date +%s) -lt $time ]; do
2781 log "Set quota for $i times"
2782 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2783 -I $((ILIMIT + i)) $MOUNT ||
2784 error "Set user quota failed"
2785 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2786 -I $((ILIMIT + i)) $MOUNT ||
2787 error "Set group quota failed"
2788 if is_project_quota_supported; then
2789 $LFS setquota -p $TSTPRJID -b 0 -B \
2790 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2791 error "Set project quota failed"
2799 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2801 if [ $count -gt 60 ]; then
2802 quota_error a $TSTUSR "dd should be finished!"
2806 echo "(dd_pid=$DDPID1, time=$count)successful"
2810 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2812 if [ $count -gt 60 ]; then
2813 quota_error a $TSTUSR "dd should be finished!"
2817 echo "(dd_pid=$DDPID2, time=$count)successful"
2821 run_test 21 "Setquota while writing & deleting (b16053)"
2823 # enable/disable quota enforcement permanently
2825 echo "Set both mdt & ost quota type as ug"
2827 is_project_quota_supported && qtype=$QTYPE
2828 set_mdt_qtype $qtype || error "enable mdt quota failed"
2829 set_ost_qtype $qtype || error "enable ost quota failed"
2832 stopall || error "failed to stopall (1)"
2836 echo "Verify if quota is enabled"
2837 local qtype1=$(mdt_quota_type)
2838 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2839 qtype=$(ost_quota_type)
2840 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2842 echo "Set both mdt & ost quota type as none"
2843 set_mdt_qtype "none" || error "disable mdt quota failed"
2844 set_ost_qtype "none" || error "disable ost quota failed"
2847 stopall || error "failed to stopall (2)"
2852 echo "Verify if quota is disabled"
2853 qtype=$(mdt_quota_type)
2854 [ $qtype != "none" ] && error "mdt quota setting is lost"
2855 qtype=$(ost_quota_type)
2856 [ $qtype != "none" ] && error "ost quota setting is lost"
2860 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2863 local TESTFILE="$DIR/$tdir/$tfile"
2866 setup_quota_test || error "setup quota failed with $?"
2867 trap cleanup_quota_test EXIT
2869 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2872 log "User quota (limit: $LIMIT MB)"
2873 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2874 error "set quota failed"
2875 quota_show_check b u $TSTUSR
2877 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2878 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2880 log "Step1: trigger EDQUOT with O_DIRECT"
2881 log "Write half of file"
2882 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2883 quota_error u $TSTUSR "(1) Write failure, expect success." \
2885 log "Write out of block quota ..."
2886 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2887 oflag=direct conv=notrunc &&
2888 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2892 log "Step2: rewrite should succeed"
2893 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2894 quota_error u $TSTUSR "(3) Write failure, expect success." \
2900 local OST0_UUID=$(ostuuid_from_index 0)
2901 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2902 [ $OST0_QUOTA_USED -ne 0 ] &&
2903 ($SHOW_QUOTA_USER; \
2904 quota_error u $TSTUSR "quota isn't released")
2909 [ "$ost1_FSTYPE" == zfs ] &&
2910 skip "Overwrite in place is not guaranteed to be " \
2911 "space neutral on ZFS"
2913 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2914 check_whether_skip && return 0
2915 log "run for 4MB test file"
2918 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2919 check_whether_skip && return 0
2920 log "run for 40MB test file"
2923 run_test 23 "Quota should be honored with directIO (b16125)"
2927 local TESTFILE="$DIR/$tdir/$tfile"
2929 setup_quota_test || error "setup quota failed with $?"
2930 trap cleanup_quota_test EXIT
2932 set_ost_qtype $QTYPE || error "enable ost quota failed"
2934 # bind file to a single OST
2935 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2936 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2938 echo "Set user quota (limit: ${blimit}M)"
2939 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2940 error "set quota failed"
2942 # overrun quota by root user
2943 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2944 error "write failure, expect success"
2945 cancel_lru_locks osc
2946 sync_all_data || true
2948 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2952 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2954 test_27a() { # b19612
2955 $LFS quota $TSTUSR $DIR &&
2956 error "lfs succeeded with no type, but should have failed"
2957 $LFS setquota $TSTUSR $DIR &&
2958 error "lfs succeeded with no type, but should have failed"
2961 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2963 test_27b() { # b20200
2964 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2965 error "lfs setquota failed with uid argument"
2966 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2967 error "lfs stequota failed with gid argument"
2968 if is_project_quota_supported; then
2969 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2970 1000 $DIR || error \
2971 "lfs stequota failed with projid argument"
2973 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2974 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2975 if is_project_quota_supported; then
2976 $SHOW_QUOTA_PROJID ||
2977 error "lfs quota failed with projid argument"
2979 resetquota -u $TSTID
2980 resetquota -g $TSTID
2981 resetquota -p $TSTPRJID
2984 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2989 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2990 error "lfs setquota failed"
2992 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2993 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2994 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2995 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2997 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2998 error "lfs setquota for $TSTID failed"
3000 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3001 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3002 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3003 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3005 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3006 error "total allocated inode/block limit not printed"
3008 resetquota -u $TSTUSR
3010 run_test 27c "lfs quota should support human-readable output"
3017 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3018 error "set fraction block limit failed"
3019 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3020 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3021 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3022 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3024 resetquota -u $TSTUSR
3026 run_test 27d "lfs setquota should support fraction block limit"
3030 local TESTFILE="$DIR/$tdir/$tfile"
3033 setup_quota_test || error "setup quota failed with $?"
3034 trap cleanup_quota_test EXIT
3036 set_ost_qtype "u" || error "enable ost quota failed"
3038 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3039 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3041 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3042 $MAX_IQ_TIME $DIR || error "set grace time failed"
3043 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3044 error "set quota failed"
3045 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3046 cancel_lru_locks osc
3048 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3049 # over-quota flag has not yet settled since we do not trigger async
3050 # events based on grace time period expiration
3052 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3053 cancel_lru_locks osc
3054 # now over-quota flag should be settled and further writes should fail
3056 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3057 error "grace times were reset"
3060 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3061 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3063 run_test 30 "Hard limit updates should not reset grace times"
3065 # basic usage tracking for user & group
3067 local INODES=10 # 10 files
3068 local BLK_CNT=2 # of 2M each
3069 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3071 setup_quota_test || error "setup quota failed with $?"
3072 trap cleanup_quota_test EXIT
3074 # make sure the system is clean
3075 local USED=$(getquota -u $TSTID global curspace)
3077 error "Used space ($USED) for user $TSTID isn't 0."
3078 USED=$(getquota -g $TSTID global curspace)
3080 error "Used space ($USED) for group $TSTID isn't 0."
3081 if is_project_quota_supported; then
3082 USED=$(getquota -p $TSTPRJID global curspace)
3083 [ $USED -ne 0 ] && error \
3084 "Used space ($USED) for project $TSTPRJID isn't 0."
3087 echo "Write files..."
3088 for i in $(seq 0 $INODES); do
3089 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3090 error "write failed"
3091 is_project_quota_supported &&
3092 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3093 echo "Iteration $i/$INODES completed"
3095 cancel_lru_locks osc
3097 echo "Wait for setattr on objects finished..."
3098 wait_delete_completed
3100 sync; sync_all_data || true
3102 echo "Verify disk usage after write"
3103 USED=$(getquota -u $TSTID global curspace)
3104 [ $USED -lt $TOTAL_BLKS ] &&
3105 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3106 USED=$(getquota -g $TSTID global curspace)
3107 [ $USED -lt $TOTAL_BLKS ] &&
3108 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3109 if is_project_quota_supported; then
3110 USED=$(getquota -p $TSTPRJID global curspace)
3111 [ $USED -lt $TOTAL_BLKS ] && error \
3112 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3115 echo "Verify inode usage after write"
3116 USED=$(getquota -u $TSTID global curinodes)
3117 [ $USED -lt $INODES ] &&
3118 error "Used inode for user $TSTID is $USED, expected $INODES"
3119 USED=$(getquota -g $TSTID global curinodes)
3120 [ $USED -lt $INODES ] &&
3121 error "Used inode for group $TSTID is $USED, expected $INODES"
3122 if is_project_quota_supported; then
3123 USED=$(getquota -p $TSTPRJID global curinodes)
3124 [ $USED -lt $INODES ] && error \
3125 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3130 echo "Verify disk usage after delete"
3131 USED=$(getquota -u $TSTID global curspace)
3132 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3133 USED=$(getquota -u $TSTID global curinodes)
3134 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3135 USED=$(getquota -g $TSTID global curspace)
3136 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3137 USED=$(getquota -g $TSTID global curinodes)
3138 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3139 if is_project_quota_supported; then
3140 USED=$(getquota -p $TSTPRJID global curspace)
3142 error "Used space for project $TSTPRJID isn't 0. $USED"
3143 USED=$(getquota -p $TSTPRJID global curinodes)
3145 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3148 run_test 33 "Basic usage tracking for user & group & project"
3150 # usage transfer test for user & group & project
3152 local BLK_CNT=2 # 2MB
3153 local project_supported="no"
3155 is_project_quota_supported && project_supported="yes"
3156 setup_quota_test || error "setup quota failed with $?"
3157 trap cleanup_quota_test EXIT
3159 # make sure the system is clean
3160 local USED=$(getquota -u $TSTID global curspace)
3161 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3162 USED=$(getquota -g $TSTID global curspace)
3163 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3165 local USED=$(getquota -u $TSTID2 global curspace)
3166 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3167 if [ $project_supported == "yes" ]; then
3168 USED=$(getquota -p $TSTPRJID global curspace)
3169 [ $USED -ne 0 ] && error \
3170 "Used space ($USED) for Project $TSTPRJID isn't 0."
3173 echo "Write file..."
3174 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3175 error "write failed"
3176 cancel_lru_locks osc
3177 sync; sync_all_data || true
3179 echo "chown the file to user $TSTID"
3180 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3182 echo "Wait for setattr on objects finished..."
3183 wait_delete_completed
3185 BLK_CNT=$((BLK_CNT * 1024))
3187 echo "Verify disk usage for user $TSTID"
3188 USED=$(getquota -u $TSTID global curspace)
3189 [ $USED -lt $BLK_CNT ] &&
3190 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3191 USED=$(getquota -u $TSTID global curinodes)
3193 error "Used inodes for user $TSTID is $USED, expected 1"
3195 echo "chgrp the file to group $TSTID"
3196 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3198 echo "Wait for setattr on objects finished..."
3199 wait_delete_completed
3201 echo "Verify disk usage for group $TSTID"
3202 USED=$(getquota -g $TSTID global curspace)
3203 [ $USED -ge $BLK_CNT ] ||
3204 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3205 USED=$(getquota -g $TSTID global curinodes)
3207 error "Used inodes for group $TSTID is $USED, expected 1"
3209 # chown won't change the ost object group. LU-4345 */
3210 echo "chown the file to user $TSTID2"
3211 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3213 echo "Wait for setattr on objects finished..."
3214 wait_delete_completed
3216 echo "change_project project id to $TSTPRJID"
3217 [ $project_supported == "yes" ] &&
3218 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3219 echo "Wait for setattr on objects finished..."
3220 wait_delete_completed
3222 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3223 USED=$(getquota -u $TSTID2 global curspace)
3224 [ $USED -lt $BLK_CNT ] &&
3225 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3226 USED=$(getquota -u $TSTID global curspace)
3228 error "Used space for user $TSTID is $USED, expected 0"
3229 USED=$(getquota -g $TSTID global curspace)
3230 [ $USED -lt $BLK_CNT ] &&
3231 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3232 if [ $project_supported == "yes" ]; then
3233 USED=$(getquota -p $TSTPRJID global curspace)
3234 [ $USED -lt $BLK_CNT ] && error \
3235 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3240 run_test 34 "Usage transfer for user & group & project"
3242 # usage is still accessible across restart
3244 local BLK_CNT=2 # 2 MB
3246 setup_quota_test || error "setup quota failed with $?"
3247 trap cleanup_quota_test EXIT
3249 echo "Write file..."
3250 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3251 error "write failed"
3252 is_project_quota_supported &&
3253 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3254 cancel_lru_locks osc
3256 echo "Wait for setattr on objects finished..."
3257 wait_delete_completed
3259 sync; sync_all_data || true
3261 echo "Save disk usage before restart"
3262 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3263 [ $ORIG_USR_SPACE -eq 0 ] &&
3264 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3265 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3266 [ $ORIG_USR_INODES -eq 0 ] &&
3267 error "Used inodes for user $TSTID is 0, expected 1"
3268 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3269 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3270 [ $ORIG_GRP_SPACE -eq 0 ] &&
3271 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3272 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3273 [ $ORIG_GRP_INODES -eq 0 ] &&
3274 error "Used inodes for group $TSTID is 0, expected 1"
3275 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3277 if is_project_quota_supported; then
3278 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3279 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3280 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3281 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3282 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3283 "Used inodes for project $TSTPRJID is 0, expected 1"
3284 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3292 echo "Verify disk usage after restart"
3293 local USED=$(getquota -u $TSTID global curspace)
3294 [ $USED -eq $ORIG_USR_SPACE ] ||
3295 error "Used space for user $TSTID changed from " \
3296 "$ORIG_USR_SPACE to $USED"
3297 USED=$(getquota -u $TSTID global curinodes)
3298 [ $USED -eq $ORIG_USR_INODES ] ||
3299 error "Used inodes for user $TSTID changed from " \
3300 "$ORIG_USR_INODES to $USED"
3301 USED=$(getquota -g $TSTID global curspace)
3302 [ $USED -eq $ORIG_GRP_SPACE ] ||
3303 error "Used space for group $TSTID changed from " \
3304 "$ORIG_GRP_SPACE to $USED"
3305 USED=$(getquota -g $TSTID global curinodes)
3306 [ $USED -eq $ORIG_GRP_INODES ] ||
3307 error "Used inodes for group $TSTID changed from " \
3308 "$ORIG_GRP_INODES to $USED"
3309 if [ $project_supported == "yes" ]; then
3310 USED=$(getquota -p $TSTPRJID global curinodes)
3311 [ $USED -eq $ORIG_PRJ_INODES ] ||
3312 error "Used inodes for project $TSTPRJID " \
3313 "changed from $ORIG_PRJ_INODES to $USED"
3314 USED=$(getquota -p $TSTPRJID global curspace)
3315 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3316 error "Used space for project $TSTPRJID "\
3317 "changed from $ORIG_PRJ_SPACE to $USED"
3320 # check if the vfs_dq_init() is called before writing
3321 echo "Append to the same file..."
3322 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3323 error "write failed"
3324 cancel_lru_locks osc
3325 sync; sync_all_data || true
3327 echo "Verify space usage is increased"
3328 USED=$(getquota -u $TSTID global curspace)
3329 [ $USED -gt $ORIG_USR_SPACE ] ||
3330 error "Used space for user $TSTID isn't increased" \
3331 "orig:$ORIG_USR_SPACE, now:$USED"
3332 USED=$(getquota -g $TSTID global curspace)
3333 [ $USED -gt $ORIG_GRP_SPACE ] ||
3334 error "Used space for group $TSTID isn't increased" \
3335 "orig:$ORIG_GRP_SPACE, now:$USED"
3336 if [ $project_supported == "yes" ]; then
3337 USED=$(getquota -p $TSTPRJID global curspace)
3338 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3339 error "Used space for project $TSTPRJID isn't " \
3340 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3345 run_test 35 "Usage is still accessible across reboot"
3347 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3350 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3351 skip "Old server doesn't have LU-5006 fix."
3353 setup_quota_test || error "setup quota failed with $?"
3354 trap cleanup_quota_test EXIT
3356 # make sure the system is clean
3357 local USED=$(getquota -u $TSTID global curspace)
3359 error "Used space ($USED) for user $TSTID isn't 0."
3361 # create file with MDS_OPEN_DELAY_CREATE flag
3362 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3363 error "Create file failed"
3365 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3366 oflag=sync || error "Write file failed"
3368 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3370 # wait for setattr on objects finished..."
3371 wait_delete_completed
3373 USED=$(getquota -u $TSTID global curspace)
3374 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3378 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3382 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3383 skip "Old server doesn't have LU-8801 fix."
3385 [ "$UID" != 0 ] && skip_env "must run as root" && return
3387 setup_quota_test || error "setup quota failed with $?"
3388 trap cleanup_quota_test EXIT
3390 # make sure the system is clean
3391 local USED=$(getquota -u $TSTID global curspace)
3393 error "Used space ($USED) for user $TSTID isn't 0."
3394 USED=$(getquota -u $TSTID2 global curspace)
3396 error "Used space ($USED) for user $TSTID2 isn't 0."
3398 local TESTFILE="$DIR/$tdir/$tfile"
3399 local file_cnt=10000
3401 # Generate id entries in accounting file
3402 echo "Create $file_cnt files..."
3403 for i in `seq $file_cnt`; do
3405 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3406 error "failed to chown $TESTFILE-$i"
3408 cancel_lru_locks osc
3409 sync; sync_all_data || true
3411 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3412 procf=${procf}.quota_slave.acct_user
3415 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3416 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3417 echo "Found $acct_cnt id entries"
3419 [ $file_cnt -eq $acct_cnt ] || {
3420 do_facet mds1 $LCTL get_param $procf
3421 error "skipped id entries"
3426 run_test 38 "Quota accounting iterator doesn't skip id entries"
3429 local TESTFILE="$DIR/$tdir/project"
3430 ! is_project_quota_supported &&
3431 skip "Project quota is not supported"
3433 setup_quota_test || error "setup quota failed with $?"
3436 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3437 [ $projectid -ne 0 ] &&
3438 error "Project id should be 0 not $projectid"
3439 change_project -p 1024 $TESTFILE
3440 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3441 [ $projectid -ne 1024 ] &&
3442 error "Project id should be 1024 not $projectid"
3444 stopall || error "failed to stopall (1)"
3447 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3448 [ $projectid -ne 1024 ] &&
3449 error "Project id should be 1024 not $projectid"
3453 run_test 39 "Project ID interface works correctly"
3456 ! is_project_quota_supported &&
3457 skip "Project quota is not supported"
3458 local dir1="$DIR/$tdir/dir1"
3459 local dir2="$DIR/$tdir/dir2"
3461 setup_quota_test || error "setup quota failed with $?"
3463 mkdir -p $dir1 $dir2
3464 change_project -sp 1 $dir1 && touch $dir1/1
3465 change_project -sp 2 $dir2
3467 ln $dir1/1 $dir2/1_link &&
3468 error "Hard link across different project quota should fail"
3473 run_test 40a "Hard link across different project ID"
3476 ! is_project_quota_supported &&
3477 skip "Project quota is not supported"
3478 local dir1="$DIR/$tdir/dir1"
3479 local dir2="$DIR/$tdir/dir2"
3481 setup_quota_test || error "setup quota failed with $?"
3482 mkdir -p $dir1 $dir2
3483 change_project -sp 1 $dir1 && touch $dir1/1
3484 change_project -sp 2 $dir2
3486 mv $dir1/1 $dir2/2 || error "mv failed $?"
3487 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3488 if [ "$projid" != "2" ]; then
3489 error "project id expected 2 not $projid"
3494 run_test 40b "Mv across different project ID"
3497 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3498 ! is_project_quota_supported &&
3499 skip "Project quota is not supported"
3501 setup_quota_test || error "setup quota failed with $?"
3502 local dir="$DIR/$tdir/dir"
3504 mkdir -p $dir && change_project -sp 1 $dir
3505 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3506 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3507 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3508 touch $dir/remote_dir/file
3509 #verify inherit works file for remote dir.
3510 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3511 [ "$projid" != "1" ] &&
3512 error "file under remote dir expected 1 not $projid"
3514 #Agent inode should be ignored for project quota
3515 USED=$(getquota -p 1 global curinodes)
3516 [ "$USED" != "3" ] &&
3517 error "file count expected 3 got $USED"
3523 run_test 40c "Remote child Dir inherit project quota properly"
3526 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3527 is_project_quota_supported || skip "Project quota is not supported"
3529 setup_quota_test || error "setup quota failed with $?"
3530 local dir="$DIR/$tdir/dir"
3533 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3534 change_project -sp $TSTPRJID $dir ||
3535 error "change project on $dir failed"
3536 for i in $(seq 5); do
3537 mkdir -p $dir/d$i/d$i ||
3538 error "mkdir $dir/d$i/d$i failed"
3539 local projid=$($LFS project -d $dir/d$i/d$i |
3541 [ "$projid" == "$TSTPRJID" ] ||
3542 error "projid id expected $TSTPRJID not $projid"
3543 touch $dir/d$i/d$i/file
3544 #verify inherit works file for stripe dir.
3545 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3546 [ "$projid" == "$TSTPRJID" ] ||
3547 error "file under remote dir expected 1 not $projid"
3550 # account should be 1 + (2 + 1) *10 + 1 * 5
3551 USED=$(getquota -p $TSTPRJID global curinodes)
3552 [ "$USED" == "36" ] ||
3553 error "file count expected 36 got $USED"
3558 run_test 40d "Stripe Directory inherit project quota properly"
3561 is_project_quota_supported ||
3562 skip "Project quota is not supported"
3563 setup_quota_test || error "setup quota failed with $?"
3564 trap cleanup_quota_test EXIT
3565 local dir="$DIR/$tdir/dir"
3568 local projid=$((testnum * 1000))
3572 # enable mdt/ost quota
3573 set_mdt_qtype ugp || error "enable mdt quota failed"
3574 set_ost_qtype ugp || error "enable ost quota failed"
3576 test_mkdir -p $dir && change_project -sp $projid $dir
3577 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3578 error "set project quota failed"
3583 # check if df output works as expected
3584 echo "== global statfs: $MOUNT =="
3585 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3587 echo "== project statfs (prjid=$projid): $dir =="
3588 df -kP $dir; df -iP $dir
3589 local bused=$(getquota -p $projid global curspace)
3590 local iused=$(getquota -p $projid global curinodes)
3591 # note trailing space to match double printf from awk
3592 local expected="$blimit $bused $ilimit $iused "
3594 wait_update $HOSTNAME \
3595 "{ df -kP $dir; df -iP $dir; } |
3596 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3598 error "failed to get correct statfs for project quota"
3602 run_test 41 "df should return projid-specific values"
3605 ! is_project_quota_supported &&
3606 skip "Project quota is not supported"
3608 setup_quota_test || error "setup quota failed with $?"
3609 local dir1="$DIR/$tdir/dir1"
3610 local dir2="$DIR/$tdir/dir2"
3612 mkdir -p $dir1 && change_project -sp 1 $dir1
3613 mkdir -p $dir2 && change_project -sp 2 $dir2
3614 for num in $(seq 1 10); do
3615 touch $dir1/file_$num $dir2/file_$num
3616 ln -s $dir1/file_$num $dir1/file_$num"_link"
3617 ln -s $dir2/file_$num $dir2/file_$num"_link"
3620 count=$($LFS find --projid 1 $DIR | wc -l)
3621 [ "$count" != 21 ] && error "expected 21 but got $count"
3623 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3624 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3625 [ "$count" != 22 ] && error "expected 22 but got $count"
3630 run_test 50 "Test if lfs find --projid works"
3633 ! is_project_quota_supported &&
3634 skip "Project quota is not supported"
3635 setup_quota_test || error "setup quota failed with $?"
3636 local dir="$DIR/$tdir/dir"
3638 mkdir $dir && change_project -sp 1 $dir
3639 local used=$(getquota -p 1 global curinodes)
3640 [ $used != "1" ] && error "expected 1 got $used"
3645 used=$(getquota -p 1 global curinodes)
3646 [ $used != "4" ] && error "expected 4 got $used"
3648 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3650 cp $DIR/$tdir/6 $dir/6
3651 used=$(getquota -p 1 global curinodes)
3652 [ $used != "5" ] && error "expected 5 got $used"
3655 mv $DIR/$tdir/6 $dir/7
3656 used=$(getquota -p 1 global curinodes)
3657 [ $used != "6" ] && error "expected 6 got $used"
3662 run_test 51 "Test project accounting with mv/cp"
3665 ! is_project_quota_supported &&
3666 skip "Project quota is not supported"
3667 setup_quota_test || error "setup quota failed with $?"
3668 local dir="$DIR/$tdir/dir"
3669 mkdir $dir && change_project -sp 1 $dir
3671 touch $DIR/$tdir/file
3672 #Try renaming a file into the project. This should fail.
3673 for num in $(seq 1 2000); do
3674 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3675 error "rename should fail"
3680 run_test 52 "Rename across different project ID"
3683 ! is_project_quota_supported &&
3684 skip "Project quota is not supported"
3685 setup_quota_test || error "setup quota failed with $?"
3686 local dir="$DIR/$tdir/dir"
3687 mkdir $dir && change_project -s $dir
3688 lfs project -d $dir | grep P || error "inherit attribute should be set"
3690 change_project -C $dir
3691 lfs project -d $dir | grep P &&
3692 error "inherit attribute should be cleared"
3697 run_test 53 "Project inherit attribute could be cleared"
3700 ! is_project_quota_supported &&
3701 skip "Project quota is not supported"
3702 setup_quota_test || error "setup quota failed with $?"
3703 trap cleanup_quota_test EXIT
3704 local testfile="$DIR/$tdir/$tfile-0"
3706 #set project ID/inherit attribute
3707 change_project -sp $TSTPRJID $DIR/$tdir
3708 $RUNAS createmany -m ${testfile} 100 ||
3709 error "create many files failed"
3711 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3712 # one more count for directory itself */
3716 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3717 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3719 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3720 [ $proj_count1 -eq $proj_count ] ||
3721 error "c2: expected $proj_count got $proj_count1"
3723 #clear project but with kept projid
3724 change_project -rCk $DIR/$tdir
3725 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3726 [ $proj_count1 -eq 1 ] ||
3727 error "c3: expected 1 got $proj_count1"
3729 #verify projid untouched.
3730 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3732 [ $proj_count1 -eq $proj_count ] ||
3733 error "c4: expected $proj_count got $proj_count1"
3736 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3737 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3738 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3740 #this time clear all
3741 change_project -rC $DIR/$tdir
3742 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3743 [ $proj_count1 -eq 0 ] ||
3744 error "c6: expected 0 got $proj_count1"
3746 unlinkmany ${testfile} 100 ||
3747 error "unlink many files failed"
3751 run_test 54 "basic lfs project interface test"
3754 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3755 skip "Not supported before 2.10.58."
3756 setup_quota_test || error "setup quota failed with $?"
3758 set_ost_qtype $QTYPE || error "enable ost quota failed"
3761 #add second group to TSTUSR
3762 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3765 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3766 error "failed to dd"
3768 cancel_lru_locks osc
3769 sync; sync_all_data || true
3771 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3772 error "failed to setquota on group $TSTUSR2"
3774 $LFS quota -v -g $TSTUSR2 $DIR
3776 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3777 error "chgrp should failed with -EDQUOT"
3779 USED=$(getquota -g $TSTUSR2 global curspace)
3782 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3783 error "failed to setquota on group $TSTUSR2"
3785 $LFS quota -v -g $TSTUSR2 $DIR
3787 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3788 error "chgrp should succeed"
3790 $LFS quota -v -g $TSTUSR2 $DIR
3794 run_test 55 "Chgrp should be affected by group quota"
3797 setup_quota_test || error "setup quota failed with $?"
3799 set_ost_qtype $QTYPE || error "enable ost quota failed"
3802 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3803 erro "failed to set grace time for usr quota"
3804 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3805 awk '{print $4 $8}')
3806 if [ "x$grace_time" != "x10s;10s" ]; then
3807 $LFS quota -t -u $DIR
3808 error "expected grace time: 10s;10s, got:$grace_time"
3813 run_test 56 "lfs quota -t should work well"
3816 setup_quota_test || error "setup quota failed with $?"
3818 local dir="$DIR/$tdir/dir"
3821 #try to change pipe file should not hang and return failure
3822 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3823 awk -F ':' '{ print \\\$2 }'" \
3824 " unable to get xattr for fifo '$dir/pipe'" || return 1
3825 #command can process further if it hit some errors
3826 touch $dir/aaa $dir/bbb
3827 mkdir $dir/subdir -p
3828 touch $dir/subdir/aaa $dir/subdir/bbb
3829 #create one invalid link file
3830 ln -s $dir/not_exist_file $dir/ccc
3831 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3832 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3836 run_test 57 "lfs project could tolerate errors"
3839 [ "$mds1_FSTYPE" != ldiskfs ] &&
3840 skip "ldiskfs only test"
3841 disable_project_quota
3842 setup_quota_test || error "setup quota failed with $?"
3845 local testfile="$DIR/$tdir/$tfile-0"
3846 #make sure it did not crash kernel
3847 touch $testfile && lfs project -sp 1 $testfile
3849 enable_project_quota
3852 run_test 59 "lfs project dosen't crash kernel with project disabled"
3855 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3856 skip "Needs MDS version 2.11.53 or later."
3857 setup_quota_test || error "setup quota failed with $?"
3858 trap cleanup_quota_test EXIT
3860 local testfile=$DIR/$tdir/$tfile
3863 set_mdt_qtype "ug" || error "enable mdt quota failed"
3865 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3866 error "set quota failed"
3867 quota_show_check a g $TSTUSR
3869 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3870 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3871 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3872 error "create many files failed"
3874 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3876 # root user can overrun quota
3877 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3878 error "root user should succeed"
3882 run_test 60 "Test quota for root with setgid"
3884 # test default quota
3885 test_default_quota() {
3886 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3887 skip "Not supported before 2.11.51."
3892 local qprjid=$TSTPRJID
3896 local LIMIT=20480 #20M disk space
3897 local TESTFILE="$DIR/$tdir/$tfile-0"
3899 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3900 echo "Project quota is not supported" && return 0
3902 [ $qtype == "-u" ] && qdtype="-U"
3903 [ $qtype == "-g" ] && qdtype="-G"
3904 [ $qtype == "-p" ] && {
3909 [ $qpool == "meta" ] && {
3910 LIMIT=10240 #10K inodes
3915 setup_quota_test || error "setup quota failed with $?"
3916 trap cleanup_quota_test EXIT
3920 # enable mdt/ost quota
3921 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3922 set_ost_qtype $QTYPE || error "enable ost quota failed"
3924 log "set to use default quota"
3925 $LFS setquota $qtype $qid -d $DIR ||
3926 error "set $qid to use default quota failed"
3928 log "set default quota"
3929 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3930 error "set $qid default quota failed"
3932 log "get default quota"
3933 $LFS quota $qdtype $DIR || error "get default quota failed"
3935 if [ $qpool == "data" ]; then
3936 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3938 [ $SLIMIT -eq $LIMIT ] ||
3939 error "the returned default quota is wrong"
3941 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3943 [ $SLIMIT -eq $LIMIT ] ||
3944 error "the returned default quota is wrong"
3947 # make sure the system is clean
3948 local USED=$(getquota $qtype $qid global curspace)
3949 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3951 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3952 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3954 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3956 log "Test not out of quota"
3957 if [ $qpool == "data" ]; then
3958 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3959 quota_error $qtype $qid "write failed, expect succeed"
3961 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3962 quota_error $qtype $qid "create failed, expect succeed"
3964 unlinkmany $TESTFILE $((LIMIT/2))
3967 log "Test out of quota"
3968 # flush cache, ensure noquota flag is set on client
3969 cancel_lru_locks osc
3970 cancel_lru_locks mdc
3971 sync; sync_all_data || true
3972 if [ $qpool == "data" ]; then
3973 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3974 quota_error $qtype $qid "write succeed, expect EDQUOT"
3976 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3977 quota_error $qtype $qid "create succeed, expect EDQUOT"
3979 unlinkmany $TESTFILE $((LIMIT*2))
3982 log "Increase default quota"
3983 # increase default quota
3984 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3985 error "set default quota failed"
3987 cancel_lru_locks osc
3988 cancel_lru_locks mdc
3989 sync; sync_all_data || true
3990 if [ $qpool == "data" ]; then
3991 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3992 quota_error $qtype $qid "write failed, expect succeed"
3994 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3995 quota_error $qtype $qid "create failed, expect succeed"
3997 unlinkmany $TESTFILE $((LIMIT*2))
4000 log "Set quota to override default quota"
4001 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4002 error "set $qid quota failed"
4004 cancel_lru_locks osc
4005 cancel_lru_locks mdc
4006 sync; sync_all_data || true
4007 if [ $qpool == "data" ]; then
4008 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4009 quota_error $qtype $qid "write succeed, expect EQUOT"
4011 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4012 quota_error $qtype $qid "create succeed, expect EQUOT"
4014 unlinkmany $TESTFILE $((LIMIT*2))
4017 log "Set to use default quota again"
4018 $LFS setquota $qtype $qid -d $DIR ||
4019 error "set $qid to use default quota failed"
4021 cancel_lru_locks osc
4022 cancel_lru_locks mdc
4023 sync; sync_all_data || true
4024 if [ $qpool == "data" ]; then
4025 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4026 quota_error $qtype $qid "write failed, expect succeed"
4028 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4029 quota_error $qtype $qid "create failed, expect succeed"
4031 unlinkmany $TESTFILE $((LIMIT*2))
4036 wait_delete_completed || error "wait_delete_completed failed"
4037 sync_all_data || true
4038 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
4039 error "reset default quota failed"
4040 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
4041 error "reset quota failed"
4047 test_default_quota "-u" "data"
4048 test_default_quota "-u" "meta"
4049 test_default_quota "-g" "data"
4050 test_default_quota "-g" "meta"
4051 test_default_quota "-p" "data"
4052 test_default_quota "-p" "meta"
4054 run_test 61 "default quota tests"
4057 ! is_project_quota_supported &&
4058 skip "Project quota is not supported"
4059 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4060 skip "chattr did not support project quota"
4061 setup_quota_test || error "setup quota failed with $?"
4062 local testdir=$DIR/$tdir/
4064 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4065 change_project -s $testdir
4066 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4067 error "inherit attribute should be set"
4068 # chattr used FS_IOC_SETFLAGS ioctl
4069 $RUNAS chattr -P $testdir &&
4070 error "regular user clear inherit should fail"
4071 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4072 error "inherit attribute should still be set"
4073 chattr -P $testdir || error "root failed to clear inherit"
4074 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4075 error "inherit attribute should be cleared"
4078 run_test 62 "Project inherit should be only changed by root"
4081 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4082 skip "Not supported before 2.11.55"
4086 local dd_failed=false
4087 local tdir_dom=${tdir}_dom
4088 local LIMIT=20480 #20M
4090 [ $qtype == "p" ] && ! is_project_quota_supported &&
4091 echo "Project quota is not supported" && return 0
4093 [ $qtype == "p" ] && qid=$TSTPRJID
4095 setup_quota_test || error "setup quota failed with $?"
4096 trap cleanup_quota_test EXIT
4100 # enable mdt/ost quota
4101 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4102 set_ost_qtype $QTYPE || error "enable ost quota failed"
4104 # make sure the system is clean
4105 local USED=$(getquota -$qtype $qid global curspace)
4106 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4108 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4110 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4111 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4112 error "setstripe $tdir_dom failed"
4113 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4115 [ $qtype == "p" ] && {
4116 change_project -sp $TSTPRJID $DIR/$tdir
4117 change_project -sp $TSTPRJID $DIR/$tdir_dom
4120 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4121 error "set $qid quota failed"
4123 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4124 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4128 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4130 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4131 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4135 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4137 rm -f $DIR/$tdir_dom/*
4139 # flush cache, ensure noquota flag is set on client
4140 cancel_lru_locks osc
4141 cancel_lru_locks mdc
4142 sync; sync_all_data || true
4146 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4147 quota_error $qtype $qid "write failed, expect succeed"
4149 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4150 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4154 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4157 rm -f $DIR/$tdir_dom/*
4159 # flush cache, ensure noquota flag is set on client
4160 cancel_lru_locks osc
4161 cancel_lru_locks mdc
4162 sync; sync_all_data || true
4166 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4167 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4171 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4173 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4174 quota_error $qtype $qid "write succeed, expect EDQUOT"
4177 rm -fr $DIR/$tdir_dom
4179 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4180 error "reset usr quota failed"
4190 run_test 63 "quota on DoM tests"
4193 ! is_project_quota_supported &&
4194 skip "Project quota is not supported"
4195 setup_quota_test || error "setup quota failed with $?"
4196 local dir1="$DIR/$tdir/"
4199 ln -s $dir1/file $dir1/file_link
4201 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4202 error "set symlink file's project should fail"
4204 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4205 error "get symlink file's project should fail"
4209 run_test 64 "lfs project on symlink files should fail"
4213 local TESTFILE="$DIR/$tdir/$tfile-0"
4215 setup_quota_test || error "setup quota failed with $?"
4216 set_ost_qtype $QTYPE || error "enable ost quota failed"
4220 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4221 error "failed to write"
4222 # flush cache, ensure noquota flag is set on client
4223 cancel_lru_locks osc
4224 sync; sync_all_data || true
4226 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4227 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4228 local quota_all=$($RUNAS $LFS quota $DIR)
4230 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4231 error "usr quota not match"
4232 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4233 error "grp quota not match"
4239 run_test 65 "Check lfs quota result"
4242 ! is_project_quota_supported &&
4243 skip "Project quota is not supported"
4244 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4245 skip "Not supported before 2.12.4"
4246 setup_quota_test || error "setup quota failed with $?"
4247 stack_trap cleanup_quota_test EXIT
4248 local old=$(do_facet mds1 $LCTL get_param -n \
4249 mdt.*.enable_chprojid_gid | head -1)
4250 local testdir=$DIR/$tdir/foo
4252 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4253 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4256 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4257 chown -R $TSTID:$TSTID $testdir
4258 change_project -sp $TSTPRJID $testdir
4259 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4261 $RUNAS lfs project -p 0 $testdir/foo &&
4262 error "nonroot user should fail to set projid"
4264 $RUNAS lfs project -C $testdir/foo &&
4265 error "nonroot user should fail to clear projid"
4267 change_project -C $testdir/foo || error "failed to clear project"
4269 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4270 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4271 "failed to set projid with normal user when enable_chprojid_gid=-1"
4273 $RUNAS lfs project -rC $testdir/ || error \
4274 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4276 touch $testdir/bar || error "failed touch $testdir/bar"
4277 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4278 "normal user should not be able to set projid on root owned file"
4280 change_project -p $TSTPRJID $testdir/bar || error \
4281 "root should be able to change its own file's projid"
4285 run_test 66 "nonroot user can not change project state in default"
4292 local short_qtype=${qtype:0:1}
4295 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4297 quota_usr) _runas=$RUNAS;;
4298 quota_2usr) _runas=$RUNAS2;;
4299 *) error "unknown quota parameter $4";;
4304 $_runas $DD of=$file count=$size ||
4305 quota_error $short_qtype $TSTUSR \
4306 "$qtype write failure, but expect success"
4308 cancel_lru_locks osc
4310 sync; sync_all_data || true
4319 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4321 do_facet mds1 $LCTL get_param $param |
4322 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4326 local limit=20 # 20M
4327 local testfile="$DIR/$tdir/$tfile-0"
4328 local testfile2="$DIR/$tdir/$tfile-1"
4329 local testfile3="$DIR/$tdir/$tfile-2"
4330 local qpool="qpool1"
4336 [ "$ost1_FSTYPE" == zfs ] &&
4337 skip "ZFS grants some block space together with inode"
4339 setup_quota_test || error "setup quota failed with $?"
4340 trap cleanup_quota_test EXIT
4343 set_ost_qtype $QTYPE || error "enable ost quota failed"
4346 log "User quota (block hardlimit:$limit MB)"
4347 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4348 error "set user quota failed"
4350 # make sure the system is clean
4351 used=$(getquota -u $TSTUSR global curspace)
4352 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4354 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4355 echo "granted 0x0 before write $granted"
4357 # trigger reintegration
4358 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4359 procf=${procf}quota_slave.force_reint
4360 do_facet ost1 $LCTL set_param $procf=1 ||
4361 error "force reintegration failed"
4362 wait_ost_reint "u" || error "reintegration failed"
4363 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4364 [ $granted -ne 0 ] &&
4365 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4367 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4368 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4370 # write 10 MB to testfile
4371 test_67_write "$testfile" "user" 10 "quota_usr"
4373 # create qpool and add OST1
4374 pool_add $qpool || error "pool_add failed"
4375 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4376 # as quota_usr hasn't limits, lqe may absent. But it should be
4377 # created after the 1st direct qmt_get.
4378 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4380 # check granted - should be 0, as testfile is located only on OST0
4381 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4382 echo "global granted $granted"
4383 granted=$(getgranted $qpool "dt" $TSTID "usr")
4384 echo "$qpool granted $granted"
4385 [ $granted -ne 0 ] &&
4386 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4388 # add OST0 to qpool and check granted space
4389 pool_add_targets $qpool 0 1 ||
4390 error "pool_add_targets failed"
4391 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4392 echo "Granted $granted_mb MB"
4393 #should be 10M + qunit for each OST
4394 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4395 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4397 $LFS setstripe $testfile2 -c 1 -i 1 ||
4398 error "setstripe $testfile2 failed"
4399 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4400 # Write from another user and check that qpool1
4401 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4402 test_67_write "$testfile2" "user" 10 "quota_2usr"
4403 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4404 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4405 [ $granted -ne 0 ] &&
4406 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4408 # Granted space for quota_2usr in qpool1 should appear only
4409 # when global lqe for this user becomes enforced.
4410 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4411 error "set user quota failed"
4412 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4413 echo "granted_mb $granted_mb"
4414 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4415 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4417 $LFS setstripe $testfile3 -c 1 -i 0 ||
4418 error "setstripe $testfile3 failed"
4419 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4420 test_67_write "$testfile3" "user" 10 "quota_2usr"
4421 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4422 echo "$testfile3 granted_mb $granted_mb"
4423 [ $granted_mb -eq $limit ] ||
4424 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4426 # remove OST1 from the qpool1 and check granted space
4427 # should be 0 for TSTUSR and 10M for TSTUSR2
4428 pool_remove_target $qpool 0
4429 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4430 [ $granted_mb -eq 0 ] ||
4431 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4432 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4433 [ $granted_mb -eq 10 ] ||
4434 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4437 wait_delete_completed || error "wait_delete_completed failed"
4438 sync_all_data || true
4439 used=$(getquota -u $TSTUSR global curspace)
4440 [ $used -ne 0 ] && quota_error u $TSTUSR \
4441 "user quota isn't released after deletion"
4442 resetquota -u $TSTUSR
4446 run_test 67 "quota pools recalculation"
4453 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4454 awk '/usr/ {getline; print $2}'
4459 local qpool="qpool1"
4462 setup_quota_test || error "setup quota failed with $?"
4463 stack_trap cleanup_quota_test EXIT
4466 set_ost_qtype $QTYPE || error "enable ost quota failed"
4468 # check slave number for glbal pool
4469 local nr=$(get_slave_nr "0x0" "usr")
4470 echo "nr result $nr"
4471 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4472 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4474 # create qpool and add OST1
4475 pool_add $qpool || error "pool_add failed"
4476 nr=$(get_slave_nr $qpool "usr")
4477 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4480 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4481 nr=$(get_slave_nr $qpool "usr")
4482 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4485 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4486 nr=$(get_slave_nr $qpool "usr")
4487 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4490 pool_remove_target $qpool 0
4491 nr=$(get_slave_nr $qpool "usr")
4492 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4495 pool_remove_target $qpool 1
4496 nr=$(get_slave_nr $qpool "usr")
4497 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4499 # Check again that all is fine with global pool
4500 nr=$(get_slave_nr "0x0" "usr")
4501 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4502 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4506 run_test 68 "slave number in quota pool changed after each add/remove OST"
4510 local global_limit=200 # 200M
4511 local limit=10 # 10M
4512 local testfile="$DIR/$tdir/$tfile-0"
4513 local dom0="$DIR/$tdir/dom0"
4514 local qpool="qpool1"
4517 setup_quota_test || error "setup quota failed with $?"
4518 stack_trap cleanup_quota_test EXIT
4521 set_ost_qtype $QTYPE || error "enable ost quota failed"
4522 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4524 # Save DOM only at MDT0
4525 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4526 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4528 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4530 # create qpool and add OST0
4531 pool_add $qpool || error "pool_add failed"
4532 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4534 log "User quota (block hardlimit:$global_limit MB)"
4535 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4536 error "set user quota failed"
4538 log "User quota (block hardlimit:$limit MB)"
4539 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4540 error "set user quota failed"
4542 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4543 quota_error u $TSTUSR "write failed"
4545 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4546 oflag=sync || quota_error u $TSTUSR "write failed"
4548 $RUNAS $DD of=$testfile count=$limit || true
4550 # flush cache, ensure noquota flag is set on client
4551 cancel_lru_locks osc
4552 sync; sync_all_data || true
4554 # MDT0 shouldn't get EDQUOT with glimpse.
4555 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4556 quota_error u $TSTUSR \
4557 "user write success, but expect EDQUOT"
4559 # Now all members of qpool1 should get EDQUOT. Expect success
4560 # when write to DOM on MDT0, as it belongs to global pool.
4561 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4562 oflag=sync || quota_error u $TSTUSR "write failed"
4564 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4565 oflag=sync || quota_error u $TSTUSR "write failed"
4569 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4573 local qpool="qpool1"
4578 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4579 skip "Needs a client >= $VERSION_WITH_QP"
4581 setup_quota_test || error "setup quota failed with $?"
4582 stack_trap cleanup_quota_test EXIT
4584 # MDS returns EFAULT for unsupported quotactl command
4585 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4587 # create qpool and add OST0
4588 pool_add $qpool || error "pool_add failed"
4589 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4591 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4593 [ $rc -eq $err ] || error "setquota res $rc != $err"
4595 # If MDS supports QP, check that limit was set properly.
4596 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4597 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4598 echo "hard limit $bhard limit $limit"
4599 [ $bhard -ne $((limit*1024)) ] &&
4600 error "bhard:$bhard for $qpool!=$((limit*1024))"
4603 $LFS quota -u $TSTUSR --pool $qpool $DIR
4605 [ $rc -eq $err ] || error "quota res $rc != $err"
4609 run_test 70 "check lfs setquota/quota with a pool option"
4613 local limit=10 # 10M
4614 local global_limit=100 # 100M
4615 local testfile="$DIR/$tdir/$tfile-0"
4616 local qpool="qpool1"
4617 local qpool2="qpool2"
4619 [ "$ost1_FSTYPE" == zfs ] &&
4620 skip "ZFS grants some block space together with inode"
4621 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4623 setup_quota_test || error "setup quota failed with $?"
4624 stack_trap cleanup_quota_test EXIT
4627 set_ost_qtype $QTYPE || error "enable ost quota failed"
4630 log "User quota (block hardlimit:$global_limit MB)"
4631 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4632 error "set user quota failed"
4634 pool_add $qpool || error "pool_add failed"
4635 pool_add_targets $qpool 0 1 ||
4636 error "pool_add_targets failed"
4638 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4639 error "set user quota failed"
4641 pool_add $qpool2 || error "pool_add failed"
4642 pool_add_targets $qpool2 1 1 ||
4643 error "pool_add_targets failed"
4645 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4646 error "set user quota failed"
4648 # make sure the system is clean
4649 local used=$(getquota -u $TSTUSR global curspace)
4652 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4654 # create 1st component 1-10M
4655 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4656 #create 2nd component 10-30M
4657 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4658 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4660 # сheck normal use and out of quota with PFL
4661 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4662 test_1_check_write $testfile "user" $((limit*2))
4664 wait_delete_completed || error "wait_delete_completed failed"
4665 sync_all_data || true
4666 used=$(getquota -u $TSTUSR global curspace)
4667 [ $used -ne 0 ] && quota_error u $TSTUSR \
4668 "user quota isn't released after deletion"
4670 # create 1st component 1-10M
4671 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4672 # create 2nd component 10-30M
4673 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4674 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4676 # write to the 2nd component
4677 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4678 quota_error u $TSTUSR \
4679 "write failure, but expect success"
4680 # this time maybe cache write, ignore it's failure
4681 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4682 cancel_lru_locks osc
4683 sync; sync_all_data || true
4684 # write over limit in qpool2(2nd component 10-30M)
4685 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4686 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4687 # write to the 1st component - OST0 is empty
4688 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4689 quota_error u $TSTUSR "write failed"
4693 run_test 71a "Check PFL with quota pools"
4697 local global_limit=1000 # 1G
4698 local limit1=160 # 160M
4699 local limit2=10 # 10M
4700 local testfile="$DIR/$tdir/$tfile-0"
4701 local qpool="qpool1"
4702 local qpool2="qpool2"
4704 [ "$ost1_FSTYPE" == zfs ] &&
4705 skip "ZFS grants some block space together with inode"
4706 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4708 setup_quota_test || error "setup quota failed with $?"
4709 stack_trap cleanup_quota_test EXIT
4712 set_ost_qtype $QTYPE || error "enable ost quota failed"
4715 log "User quota (block hardlimit:$global_limit MB)"
4716 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4717 error "set user quota failed"
4719 pool_add $qpool || error "pool_add failed"
4720 pool_add_targets $qpool 0 1 ||
4721 error "pool_add_targets failed"
4723 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4724 error "set user quota failed"
4726 pool_add $qpool2 || error "pool_add failed"
4727 pool_add_targets $qpool2 1 1 ||
4728 error "pool_add_targets failed"
4730 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4731 error "set user quota failed"
4733 # make sure the system is clean
4734 local used=$(getquota -u $TSTUSR global curspace)
4737 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4739 # First component is on OST0, 2nd on OST1
4740 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4741 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4743 # fill the 1st component on OST0
4744 $RUNAS $DD of=$testfile count=128 ||
4745 quota_error u $TSTUSR "write failed"
4746 # write to the 2nd cmpnt on OST1
4747 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4748 quota_error u $TSTUSR "write failed"
4749 # this time maybe cache write, ignore it's failure
4750 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4752 cancel_lru_locks osc
4753 sync; sync_all_data || true
4754 # write over limit in qpool2
4755 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4756 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4760 run_test 71b "Check SEL with quota pools"
4764 local limit=10 # 10M
4765 local global_limit=50 # 50M
4766 local testfile="$DIR/$tdir/$tfile-0"
4767 local qpool="qpool1"
4770 setup_quota_test || error "setup quota failed with $?"
4771 stack_trap cleanup_quota_test EXIT
4774 set_ost_qtype $QTYPE || error "enable ost quota failed"
4777 log "User quota (block hardlimit:$global_limit MB)"
4778 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4779 error "set user quota failed"
4781 pool_add $qpool || error "pool_add failed"
4782 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4784 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4785 error "set user quota failed"
4787 # make sure the system is clean
4788 local used=$(getquota -u $TSTUSR global curspace)
4790 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4792 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4794 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4795 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4796 test_1_check_write $testfile "user" $limit
4797 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4799 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4800 # check that lfs quota -uv --pool prints only OST that
4801 # was added in a pool
4802 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4803 grep "OST\|MDT" && error "$qpool consists wrong targets"
4807 run_test 72 "lfs quota --pool prints only pool's OSTs"
4811 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4812 if $PQ_CLEANUP; then
4813 disable_project_quota
4816 reset_quota_settings
4821 check_and_cleanup_lustre
4822 export QUOTA_AUTO=$QUOTA_AUTO_OLD