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 }')
361 time=$(lfs quota -$qtype $qarg $DIR|
362 awk 'NR == 3{ print $9 }')
365 error "Unknown quota type: $flavour"
369 local sleep_seconds=0
370 local orig_time=$time
372 echo "Grace time is $time"
373 # from lfs.c:__sec2str()
374 # const char spec[] = "smhdw";
375 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
376 [[ $time == *w* ]] && w_time=${time%w*} &&
377 let sleep_seconds+=$((w_time*7*24*60*60));
379 [[ $time == *d* ]] && d_time=${time%d*} &&
380 let sleep_seconds+=$((d_time*24*60*60));
382 [[ $time == *h* ]] && h_time=${time%h*} &&
383 let sleep_seconds+=$((h_time*60*60));
385 [[ $time == *m* ]] && m_time=${time%m*} &&
386 let sleep_seconds+=$((m_time*60));
388 [[ $time == *s* ]] && s_time=${time%s*} &&
389 let sleep_seconds+=$s_time
391 echo "Sleep through grace ..."
392 [ "$orig_time" == "-" ] &&
393 error "Grace timeout was not set or quota not exceeded"
394 if [ "$orig_time" == "none" ]; then
395 echo "...Grace timeout already expired"
397 let sleep_seconds+=$extrasleep
398 echo "...sleep $sleep_seconds seconds"
405 wait_delete_completed
406 echo "Creating test directory"
407 $LFS mkdir -i $mdt -c 1 $DIR/$tdir || return 1
408 chmod 0777 $DIR/$tdir || return 2
409 # always clear fail_loc in case of fail_loc isn't cleared
410 # properly when previous test failed
411 lustre_fail mds_ost 0
414 cleanup_quota_test() {
415 echo "Delete files..."
417 echo "Wait for unlink objects finished..."
418 wait_delete_completed
419 sync_all_data || true
429 $LFS quota -v -$ugp $qid $DIR
431 if [ "$bf" == "a" -o "$bf" == "b" ]; then
432 usage=$(getquota -$ugp $qid global curspace)
433 if [ -z $usage ]; then
434 quota_error $ugp $qid \
435 "Query block quota failed ($ugp:$qid)."
437 [ $usage -ne 0 ] && quota_log $ugp $qid \
438 "Block quota isn't 0 ($ugp:$qid:$usage)."
442 if [ "$bf" == "a" -o "$bf" == "f" ]; then
443 usage=$(getquota -$ugp $qid global curinodes)
444 if [ -z $usage ]; then
445 quota_error $ugp $qid \
446 "Query file quota failed ($ugp:$qid)."
448 [ $usage -ne 0 ] && quota_log $ugp $qid \
449 "File quota isn't 0 ($ugp:$qid:$usage)."
454 project_quota_enabled () {
456 local zfeat="feature@project_quota"
458 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
459 local facet_fstype=${facet:0:3}1_FSTYPE
462 if [ "${!facet_fstype}" = "zfs" ]; then
463 devname=$(zpool_name ${facet})
464 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
465 grep -wq active || rc=1
467 [ ${facet:0:3} == "mds" ] &&
468 devname=$(mdsdevname ${facet:3}) ||
469 devname=$(ostdevname ${facet:3})
470 do_facet ${facet} $DEBUGFS -R features $devname |
471 grep -q project || rc=1
474 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
478 project_quota_enabled || enable_project_quota
480 reset_quota_settings() {
481 resetquota -u $TSTUSR
483 resetquota -g $TSTUSR
485 resetquota -u $TSTUSR2
486 resetquota -u $TSTID2
487 resetquota -g $TSTUSR2
488 resetquota -g $TSTID2
489 resetquota -p $TSTPRJID
494 do_nodes $(comma_list $(nodes_list)) \
495 "$LCTL set_param -n debug=+quota,trace"
500 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
501 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
502 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
503 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
505 test_quota_performance() {
506 local TESTFILE="$DIR/$tdir/$tfile-0"
507 local size=$1 # in MB
508 local stime=$(date +%s)
509 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
510 quota_error u $TSTUSR "write failure"
511 local etime=$(date +%s)
512 delta=$((etime - stime))
513 if [ $delta -gt 0 ]; then
514 rate=$((size * 1024 / delta))
515 if [ "$mds1_FSTYPE" = zfs ]; then
516 # LU-2872 - see LU-2887 for fix
518 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
520 [ $rate -gt 1024 ] ||
521 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
527 # test basic quota performance b=21696
530 [ "$SLOW" = "no" ] && MB=10
532 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
533 [ $free_space -le $((MB * 1024)) ] &&
534 skip "not enough space ${free_space} KB, " \
535 "required $((MB * 1024)) KB"
536 setup_quota_test || error "setup quota failed with $?"
537 trap cleanup_quota_test EXIT
539 set_ost_qtype "none" || error "disable ost quota failed"
540 test_quota_performance $MB
542 set_ost_qtype $QTYPE || error "enable ost quota failed"
543 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
544 error "set quota failed"
545 test_quota_performance $MB
549 run_test 0 "Test basic quota performance"
551 # usage: test_1_check_write tfile user|group|project
552 test_1_check_write() {
556 local short_qtype=${qtype:0:1}
559 $RUNAS $DD of=$testfile count=$((limit/2)) ||
560 quota_error $short_qtype $TSTUSR \
561 "$qtype write failure, but expect success"
562 log "Write out of block quota ..."
563 # this time maybe cache write, ignore it's failure
564 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
565 # flush cache, ensure noquota flag is set on client
567 sync; sync_all_data || true
568 # sync means client wrote all it's cache, but id doesn't
569 # garantee that slave got new edquot trough glimpse.
570 # so wait a little to be sure slave got it.
572 $RUNAS $DD of=$testfile count=1 seek=$limit &&
573 quota_error $short_qtype $TSTUSR \
574 "user write success, but expect EDQUOT"
577 check_write_fallocate() {
581 local short_qtype=${qtype:0:1}
584 log "Write ${count}MiB Using Fallocate"
585 $RUNAS fallocate -l${count}MiB $testfile ||
586 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
589 sync; sync_all_data || true
593 log "Write ${count}MiB Using Fallocate"
594 $RUNAS fallocate -l${count}MiB $testfile &&
595 quota_error $short_qtype $TSTUSR \
596 "Write success, expect EDQUOT" || true
599 # test block hardlimit
602 local testfile="$DIR/$tdir/$tfile-0"
604 setup_quota_test || error "setup quota failed with $?"
605 trap cleanup_quota_test EXIT
608 set_ost_qtype $QTYPE || error "enable ost quota failed"
611 log "User quota (block hardlimit:$limit MB)"
612 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
613 error "set user quota failed"
615 # make sure the system is clean
616 local used=$(getquota -u $TSTUSR global curspace)
617 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
619 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
620 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
622 test_1_check_write $testfile "user" $limit
625 wait_delete_completed || error "wait_delete_completed failed"
626 sync_all_data || true
627 used=$(getquota -u $TSTUSR global curspace)
628 [ $used -ne 0 ] && quota_error u $TSTUSR \
629 "user quota isn't released after deletion"
630 resetquota -u $TSTUSR
633 log "--------------------------------------"
634 log "Group quota (block hardlimit:$limit MB)"
635 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
636 error "set group quota failed"
638 testfile="$DIR/$tdir/$tfile-1"
639 # make sure the system is clean
640 used=$(getquota -g $TSTUSR global curspace)
641 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
643 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
644 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
646 test_1_check_write $testfile "group" $limit
648 wait_delete_completed || error "wait_delete_completed failed"
649 sync_all_data || true
650 used=$(getquota -g $TSTUSR global curspace)
651 [ $used -ne 0 ] && quota_error g $TSTUSR \
652 "Group quota isn't released after deletion"
653 resetquota -g $TSTUSR
655 if ! is_project_quota_supported; then
656 echo "Project quota is not supported"
661 testfile="$DIR/$tdir/$tfile-2"
662 # make sure the system is clean
663 used=$(getquota -p $TSTPRJID global curspace)
665 error "used space($used) for project $TSTPRJID isn't 0"
668 log "--------------------------------------"
669 log "Project quota (block hardlimit:$limit mb)"
670 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
671 error "set project quota failed"
673 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
674 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
675 change_project -p $TSTPRJID $testfile
677 test_1_check_write $testfile "project" $limit
682 used=$(getquota -p $TSTPRJID global curspace)
683 [ $used -ne 0 ] && quota_error p $TSTPRJID \
684 "project quota isn't released after deletion"
686 resetquota -p $TSTPRJID
688 run_test 1a "Block hard limit (normal use and out of quota)"
692 local global_limit=20 # MB
693 local testfile="$DIR/$tdir/$tfile-0"
697 setup_quota_test || error "setup quota failed with $?"
698 stack_trap cleanup_quota_test EXIT
701 set_ost_qtype $QTYPE || error "enable ost quota failed"
704 log "User quota (block hardlimit:$global_limit MB)"
705 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
706 error "set user quota failed"
708 pool_add $qpool || error "pool_add failed"
709 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
710 error "pool_add_targets failed"
712 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
713 error "set user quota failed"
715 # make sure the system is clean
716 local used=$(getquota -u $TSTUSR global curspace)
718 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
720 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
722 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
723 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
725 test_1_check_write $testfile "user" $limit
728 wait_delete_completed || error "wait_delete_completed failed"
729 sync_all_data || true
730 used=$(getquota -u $TSTUSR global curspace $qpool)
731 [ $used -ne 0 ] && quota_error u $TSTUSR \
732 "user quota isn't released after deletion"
733 resetquota -u $TSTUSR
736 log "--------------------------------------"
737 log "Group quota (block hardlimit:$global_limit MB)"
738 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
739 error "set group quota failed"
741 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
742 error "set group quota failed"
744 testfile="$DIR/$tdir/$tfile-1"
745 # make sure the system is clean
746 used=$(getquota -g $TSTUSR global curspace $qpool)
747 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
749 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
750 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
752 test_1_check_write $testfile "group" $limit
755 wait_delete_completed || error "wait_delete_completed failed"
756 sync_all_data || true
757 used=$(getquota -g $TSTUSR global curspace $qpool)
758 [ $used -ne 0 ] && quota_error g $TSTUSR \
759 "Group quota isn't released after deletion"
760 resetquota -g $TSTUSR
762 if ! is_project_quota_supported; then
763 echo "Project quota is not supported"
768 testfile="$DIR/$tdir/$tfile-2"
769 # make sure the system is clean
770 used=$(getquota -p $TSTPRJID global curspace $qpool)
772 error "used space($used) for project $TSTPRJID isn't 0"
775 log "--------------------------------------"
776 log "Project quota (block hardlimit:$global_limit mb)"
777 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
778 error "set project quota failed"
780 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
781 error "set project quota failed"
784 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
785 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
786 change_project -p $TSTPRJID $testfile
788 test_1_check_write $testfile "project" $limit
793 used=$(getquota -p $TSTPRJID global curspace)
794 [ $used -eq 0 ] || quota_error p $TSTPRJID \
795 "project quota isn't released after deletion"
797 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
800 local global_limit=20 # MB
801 local testfile="$DIR/$tdir/$tfile-0"
802 local qpool1="qpool1"
803 local qpool2="qpool2"
806 setup_quota_test || error "setup quota failed with $?"
807 stack_trap cleanup_quota_test EXIT
810 set_ost_qtype $QTYPE || error "enable ost quota failed"
813 log "User quota (block hardlimit:$global_limit MB)"
814 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
815 error "set user quota failed"
817 pool_add $qpool1 || error "pool_add failed"
818 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
819 error "pool_add_targets failed"
821 pool_add $qpool2 || error "pool_add failed"
822 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
823 error "pool_add_targets failed"
825 # create pools without hard limit
826 # initially such case raised several bugs
827 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
828 error "set user quota failed"
830 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
831 error "set user quota failed"
833 # make sure the system is clean
834 local used=$(getquota -u $TSTUSR global curspace)
836 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
838 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
840 test_1_check_write $testfile "user" $global_limit
842 used=$(getquota -u $TSTUSR global curspace $qpool1)
843 echo "qpool1 used $used"
844 used=$(getquota -u $TSTUSR global curspace $qpool2)
845 echo "qpool2 used $used"
848 wait_delete_completed || error "wait_delete_completed failed"
849 sync_all_data || true
851 used=$(getquota -u $TSTUSR global curspace $qpool1)
852 [ $used -ne 0 ] && quota_error u $TSTUSR \
853 "user quota isn't released after deletion"
854 resetquota -u $TSTUSR
859 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
864 local global_limit=20 # MB
865 local testfile="$DIR/$tdir/$tfile-0"
866 local qpool1="qpool1"
867 local qpool2="qpool2"
870 setup_quota_test || error "setup quota failed with $?"
871 stack_trap cleanup_quota_test EXIT
874 set_ost_qtype $QTYPE || error "enable ost quota failed"
877 log "User quota (block hardlimit:$global_limit MB)"
878 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
879 error "set user quota failed"
881 pool_add $qpool1 || error "pool_add failed"
882 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
883 error "pool_add_targets failed"
885 pool_add $qpool2 || error "pool_add failed"
886 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
887 error "pool_add_targets failed"
889 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
890 error "set user quota failed"
892 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
893 error "set user quota failed"
895 # make sure the system is clean
896 local used=$(getquota -u $TSTUSR global curspace)
898 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
900 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
902 test_1_check_write $testfile "user" $limit1
904 used=$(getquota -u $TSTUSR global curspace $qpool1)
905 echo "qpool1 used $used"
906 used=$(getquota -u $TSTUSR global curspace $qpool2)
907 echo "qpool2 used $used"
910 wait_delete_completed || error "wait_delete_completed failed"
911 sync_all_data || true
913 used=$(getquota -u $TSTUSR global curspace $qpool1)
914 [ $used -ne 0 ] && quota_error u $TSTUSR \
915 "user quota isn't released after deletion"
916 resetquota -u $TSTUSR
921 run_test 1d "Quota pools: check block hardlimit on different pools"
925 local global_limit=53000000 # MB
926 local testfile="$DIR/$tdir/$tfile-0"
927 local testfile2="$DIR/$tdir/$tfile-1"
928 local qpool1="qpool1"
931 setup_quota_test || error "setup quota failed with $?"
932 stack_trap cleanup_quota_test EXIT
935 set_ost_qtype $QTYPE || error "enable ost quota failed"
937 # global_limit is much greater than limit1 to get
938 # different qunit's on osts. Since 1st qunit shrinking
939 # on OST1(that belongs to qpool1), this qunit should
941 log "User quota (block hardlimit:$global_limit MB)"
942 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
943 error "set user quota failed"
945 pool_add $qpool1 || error "pool_add failed"
946 pool_add_targets $qpool1 1 1 ||
947 error "pool_add_targets failed"
949 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
950 error "set user quota failed"
952 # make sure the system is clean
953 local used=$(getquota -u $TSTUSR global curspace)
954 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
956 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
957 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
959 test_1_check_write $testfile "user" $limit1
961 $LFS setstripe $testfile2 -c 1 -i 0 ||
962 error "setstripe $testfile2 failed"
963 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
964 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
966 $RUNAS $DD of=$testfile2 count=20 ||
967 quota_error u $TSTUSR \
968 "$qtype write failure, but expect success"
972 wait_delete_completed || error "wait_delete_completed failed"
973 sync_all_data || true
975 used=$(getquota -u $TSTUSR global curspace $qpool1)
976 [ $used -ne 0 ] && quota_error u $TSTUSR \
977 "user quota isn't released after deletion"
978 resetquota -u $TSTUSR
983 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
986 local global_limit=200 # MB
988 local TESTDIR="$DIR/$tdir/"
989 local testfile="$TESTDIR/$tfile-0"
990 local qpool1="qpool1"
993 setup_quota_test || error "setup quota failed with $?"
994 stack_trap cleanup_quota_test EXIT
997 set_ost_qtype $QTYPE || error "enable ost quota failed"
999 log "User quota (block hardlimit:$global_limit MB)"
1000 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1001 error "set user quota failed"
1003 pool_add $qpool1 || error "pool_add failed"
1004 pool_add_targets $qpool1 0 0 ||
1005 error "pool_add_targets failed"
1007 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1008 error "set user quota failed"
1010 # make sure the system is clean
1011 local used=$(getquota -u $TSTUSR global curspace)
1012 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1014 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1016 test_1_check_write $testfile "user" $limit1
1018 pool_remove_target $qpool1 0
1020 wait_delete_completed || error "wait_delete_completed failed"
1021 sync_all_data || true
1023 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1024 # qunit for appropriate element in lgd array should be set
1025 # correctly(4096). Earlier it was not changed continuing to be 1024.
1026 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1027 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1028 # as it already was 1024. As flag "need_update" for this qunit was
1029 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1030 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1031 # became > 10M. QMT returned EINPROGRESS in a loop.
1032 # Check that it doesn't hung anymore.
1033 test_1_check_write $testfile "user" $limit1
1038 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1042 local global_limit=40 # MB
1043 local testfile="$DIR/$tdir/$tfile-0"
1044 local qpool="qpool1"
1045 local mdmb_param="osc.*.max_dirty_mb"
1046 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1049 setup_quota_test || error "setup quota failed with $?"
1050 stack_trap cleanup_quota_test EXIT
1051 $LCTL set_param $mdmb_param=1
1052 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1055 set_ost_qtype $QTYPE || error "enable ost quota failed"
1058 log "User quota (block hardlimit:$global_limit MB)"
1059 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1060 error "set user quota failed"
1062 pool_add $qpool || error "pool_add failed"
1063 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1064 error "pool_add_targets failed"
1066 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1067 error "set user quota failed"
1069 # make sure the system is clean
1070 local used=$(getquota -u $TSTUSR global curspace)
1072 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1074 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1075 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1078 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1079 quota_error u $TSTUSR \
1080 "$qtype write failure, but expect success"
1081 log "Write out of block quota ..."
1082 # this time maybe cache write, ignore it's failure
1083 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1084 # flush cache, ensure noquota flag is set on client
1085 cancel_lru_locks osc
1086 sync; sync_all_data || true
1088 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1089 quota_error u $TSTUSR \
1090 "user write success, but expect EDQUOT"
1093 wait_delete_completed || error "wait_delete_completed failed"
1094 sync_all_data || true
1096 used=$(getquota -u $TSTUSR global curspace $qpool)
1097 [ $used -ne 0 ] && quota_error u $TSTUSR \
1098 "user quota isn't released after deletion"
1101 run_test 1g "Quota pools: Block hard limit with wide striping"
1105 local testfile="$DIR/$tdir/$tfile-0"
1107 check_set_fallocate_or_skip
1109 setup_quota_test || error "setup quota failed with $?"
1110 trap cleanup_quota_test EXIT
1113 set_ost_qtype $QTYPE || error "enable ost quota failed"
1116 log "User quota (block hardlimit:$limit MB)"
1117 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1118 error "set user quota failed"
1120 # make sure the system is clean
1121 local used=$(getquota -u $TSTUSR global curspace)
1122 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1124 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1125 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1127 check_write_fallocate $testfile "user" $limit
1130 wait_delete_completed || error "wait_delete_completed failed"
1131 sync_all_data || true
1132 used=$(getquota -u $TSTUSR global curspace)
1133 [ $used -ne 0 ] && quota_error u $TSTUSR \
1134 "user quota isn't released after deletion"
1135 resetquota -u $TSTUSR
1137 run_test 1h "Block hard limit test using fallocate"
1139 # test inode hardlimit
1141 local TESTFILE="$DIR/$tdir/$tfile-0"
1142 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1143 qmt.$FSNAME-QMT0000.md-0x0.info |
1144 awk '/least qunit/{ print $3 }')
1145 local L2=$(do_facet mds1 $LCTL get_param -n \
1146 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1148 [ $L2 -le $LIMIT ] || LIMIT=$L2
1150 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1152 local FREE_INODES=$(mdt_free_inodes 0)
1153 echo "$FREE_INODES free inodes on master MDT"
1154 [ $FREE_INODES -lt $LIMIT ] &&
1155 skip "not enough free inodes $FREE_INODES required $LIMIT"
1157 setup_quota_test || error "setup quota failed with $?"
1158 trap cleanup_quota_test EXIT
1161 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1164 log "User quota (inode hardlimit:$LIMIT files)"
1165 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1166 error "set user quota failed"
1168 # make sure the system is clean
1169 local USED=$(getquota -u $TSTUSR global curinodes)
1170 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1172 log "Create $LIMIT files ..."
1173 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1174 quota_error u $TSTUSR "user create failure, but expect success"
1175 log "Create out of file quota ..."
1176 $RUNAS touch ${TESTFILE}_xxx &&
1177 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1180 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1181 rm -f ${TESTFILE}_xxx
1182 wait_delete_completed
1184 USED=$(getquota -u $TSTUSR global curinodes)
1185 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1186 "user quota isn't released after deletion"
1187 resetquota -u $TSTUSR
1190 log "--------------------------------------"
1191 log "Group quota (inode hardlimit:$LIMIT files)"
1192 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1193 error "set group quota failed"
1195 TESTFILE=$DIR/$tdir/$tfile-1
1196 # make sure the system is clean
1197 USED=$(getquota -g $TSTUSR global curinodes)
1198 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1200 log "Create $LIMIT files ..."
1201 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1202 quota_error g $TSTUSR "group create failure, but expect success"
1203 log "Create out of file quota ..."
1204 $RUNAS touch ${TESTFILE}_xxx &&
1205 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1208 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1209 rm -f ${TESTFILE}_xxx
1210 wait_delete_completed
1212 USED=$(getquota -g $TSTUSR global curinodes)
1213 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1214 "user quota isn't released after deletion"
1216 resetquota -g $TSTUSR
1217 ! is_project_quota_supported && cleanup_quota_test &&
1218 echo "Skip project quota is not supported" && return 0
1221 log "--------------------------------------"
1222 log "Project quota (inode hardlimit:$LIMIT files)"
1223 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1224 error "set project quota failed"
1226 TESTFILE=$DIR/$tdir/$tfile-1
1227 # make sure the system is clean
1228 USED=$(getquota -p $TSTPRJID global curinodes)
1230 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1232 change_project -sp $TSTPRJID $DIR/$tdir
1233 log "Create $LIMIT files ..."
1234 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1235 $TSTPRJID "project create fail, but expect success"
1236 log "Create out of file quota ..."
1237 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1238 "project create success, but expect EDQUOT"
1239 change_project -C $DIR/$tdir
1242 USED=$(getquota -p $TSTPRJID global curinodes)
1243 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1244 "project quota isn't released after deletion"
1247 run_test 2 "File hard limit (normal use and out of quota)"
1256 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1257 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1260 stack_trap cleanup_quota_test EXIT
1262 $LFS setstripe $testfile -c 1 -i 0
1263 chown $TSTUSR.$TSTUSR $testfile
1264 [ "$qtype" == "p" ] && is_project_quota_supported &&
1265 change_project -p $TSTPRJID $testfile
1267 echo "Write up to soft limit"
1268 $RUNAS $DD of=$testfile count=$limit ||
1269 quota_error a $TSTUSR "write failure, but expect success"
1270 OFFSET=$((limit * 1024))
1271 cancel_lru_locks osc
1273 echo "Write to exceed soft limit"
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)) # make sure we don't write to same block
1277 cancel_lru_locks osc
1279 echo "mmap write when over soft limit"
1280 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1281 quota_error a $TSTUSR "mmap write failure, but expect success"
1282 cancel_lru_locks osc
1287 $SHOW_QUOTA_INFO_USER
1288 $SHOW_QUOTA_INFO_GROUP
1289 $SHOW_QUOTA_INFO_PROJID
1291 echo "Write before timer goes off"
1292 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1293 quota_error a $TSTUSR "write failure, but expect success"
1294 OFFSET=$((OFFSET + 1024))
1295 cancel_lru_locks osc
1297 wait_grace_time $qtype "block" $pool
1302 $SHOW_QUOTA_INFO_USER
1303 $SHOW_QUOTA_INFO_GROUP
1304 $SHOW_QUOTA_INFO_PROJID
1306 log "Write after timer goes off"
1307 # maybe cache write, ignore.
1308 # write up to soft least quint to consume all
1309 # possible slave granted space.
1310 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1311 count=$soft_limit seek=$OFFSET || true
1312 OFFSET=$((OFFSET + soft_limit))
1313 cancel_lru_locks osc
1314 log "Write after cancel lru locks"
1315 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1316 quota_error a $TSTUSR "write success, but expect EDQUOT"
1321 $SHOW_QUOTA_INFO_USER
1322 $SHOW_QUOTA_INFO_GROUP
1323 $SHOW_QUOTA_INFO_PROJID
1325 echo "Unlink file to stop timer"
1327 wait_delete_completed
1328 sync_all_data || true
1333 $SHOW_QUOTA_INFO_USER
1334 $SHOW_QUOTA_INFO_GROUP
1335 $SHOW_QUOTA_INFO_PROJID
1337 $LFS setstripe $testfile -c 1 -i 0
1338 chown $TSTUSR.$TSTUSR $testfile
1339 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1342 $RUNAS $DD of=$testfile count=$limit ||
1343 quota_error a $TSTUSR "write failure, but expect success"
1350 local grace=20 # seconds
1351 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1354 local testfile=$DIR/$tdir/$tfile-0
1356 # get minimum soft qunit size
1357 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1358 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1360 set_ost_qtype $QTYPE || error "enable ost quota failed"
1362 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1363 # make sure the system is clean
1364 local used=$(getquota -u $TSTUSR global curspace)
1365 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1367 $LFS setquota -t -u --block-grace $grace --inode-grace \
1368 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1369 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1370 error "set user quota failed"
1372 test_block_soft $testfile $grace $limit "u"
1374 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1375 testfile=$DIR/$tdir/$tfile-1
1376 # make sure the system is clean
1377 used=$(getquota -g $TSTUSR global curspace)
1378 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1380 $LFS setquota -t -g --block-grace $grace --inode-grace \
1381 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1382 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1383 error "set group quota failed"
1385 test_block_soft $testfile $grace $limit "g"
1387 if is_project_quota_supported; then
1388 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1389 testfile=$DIR/$tdir/$tfile-2
1390 # make sure the system is clean
1391 used=$(getquota -p $TSTPRJID global curspace)
1392 [ $used -ne 0 ] && error \
1393 "Used space($used) for project $TSTPRJID isn't 0."
1395 $LFS setquota -t -p --block-grace $grace --inode-grace \
1396 $MAX_IQ_TIME $DIR ||
1397 error "set project grace time failed"
1398 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1399 $DIR || error "set project quota failed"
1401 test_block_soft $testfile $grace $limit "p"
1402 resetquota -p $TSTPRJID
1403 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1404 $MAX_IQ_TIME $DIR ||
1405 error "restore project grace time failed"
1409 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1410 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1411 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1412 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1414 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1417 local grace=20 # seconds
1418 local qpool="qpool1"
1419 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1422 local testfile=$DIR/$tdir/$tfile-0
1425 # get minimum soft qunit size
1426 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1427 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1428 local glbl_limit=$((2*limit))
1429 local glbl_grace=$((2*grace))
1430 echo "limit $limit glbl_limit $glbl_limit"
1431 echo "grace $grace glbl_grace $glbl_grace"
1433 set_ost_qtype $QTYPE || error "enable ost quota failed"
1435 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1436 # make sure the system is clean
1437 local used=$(getquota -u $TSTUSR global curspace)
1438 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1440 pool_add $qpool || error "pool_add failed"
1441 pool_add_targets $qpool 0 1 ||
1442 error "pool_add_targets failed"
1444 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1445 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1446 $LFS setquota -t -u --block-grace $grace \
1447 --pool $qpool $DIR || error "set user grace time failed"
1449 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1450 error "set user quota failed"
1451 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1452 error "set user quota failed"
1454 test_block_soft $testfile $grace $limit "u" $qpool
1456 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1457 testfile=$DIR/$tdir/$tfile-1
1458 # make sure the system is clean
1459 used=$(getquota -g $TSTUSR global curspace)
1460 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1462 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1463 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1464 $LFS setquota -t -g --block-grace $grace \
1465 --pool $qpool $DIR || error "set group grace time failed"
1467 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1468 error "set group quota failed"
1469 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1470 error "set group quota failed"
1472 test_block_soft $testfile $grace $limit "g" $qpool
1474 if is_project_quota_supported; then
1475 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1476 testfile=$DIR/$tdir/$tfile-2
1477 # make sure the system is clean
1478 used=$(getquota -p $TSTPRJID global curspace)
1479 [ $used -ne 0 ] && error \
1480 "Used space($used) for project $TSTPRJID isn't 0."
1482 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1483 $MAX_IQ_TIME $DIR ||
1484 error "set project grace time failed"
1485 $LFS setquota -t -p --block-grace $grace \
1486 --pool $qpool $DIR ||
1487 error "set project grace time failed"
1489 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1490 $DIR || error "set project quota failed"
1491 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1492 --pool $qpool $DIR || error "set project quota failed"
1494 test_block_soft $testfile $grace $limit "p" $qpool
1495 resetquota -p $TSTPRJID
1496 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1497 $MAX_IQ_TIME $DIR ||
1498 error "restore project grace time failed"
1499 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1500 $DIR || error "set project grace time failed"
1504 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1505 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1506 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1507 --pool $qpool $DIR || error "restore user grace time failed"
1508 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1509 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1510 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1511 --pool $qpool $DIR || error "restore group grace time failed"
1513 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1516 local grace=20 # seconds
1517 local qpool="qpool1"
1518 local qpool2="qpool2"
1519 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1522 local testfile=$DIR/$tdir/$tfile-0
1525 # get minimum soft qunit size
1526 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1527 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1528 local limit2=$((limit+4))
1529 local glbl_limit=$((limit+8))
1530 local grace1=$((grace+10))
1532 local glbl_grace=$((grace+20))
1533 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1534 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1536 set_ost_qtype $QTYPE || error "enable ost quota failed"
1538 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1539 # make sure the system is clean
1540 local used=$(getquota -u $TSTUSR global curspace)
1541 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1543 pool_add $qpool || error "pool_add failed"
1544 pool_add_targets $qpool 0 1 ||
1545 error "pool_add_targets failed"
1547 pool_add $qpool2 || error "pool_add failed"
1548 pool_add_targets $qpool2 0 1 ||
1549 error "pool_add_targets failed"
1552 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1553 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1554 $LFS setquota -t -u --block-grace $grace1 \
1555 --pool $qpool $DIR || error "set user grace time failed"
1556 $LFS setquota -t -u --block-grace $grace2 \
1557 --pool $qpool2 $DIR || error "set user grace time failed"
1559 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1560 error "set user quota failed"
1561 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1562 error "set user quota failed"
1563 # qpool has minimum soft limit, but it's grace is grater than
1564 # grace period of qpool2. Thus write shouldn't fail when
1565 # hit qpool soft limit - only when reaches up qpool2 limit
1566 # after grace2 seconds.
1567 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1568 error "set user quota failed"
1570 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1573 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1574 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1575 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1576 --pool $qpool $DIR || error "restore user grace time failed"
1577 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1578 --pool $qpool2 $DIR || error "restore user grace time failed"
1580 run_test 3c "Quota pools: check block soft limit on different pools"
1587 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1588 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1591 trap cleanup_quota_test EXIT
1592 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1594 echo "Create files to exceed soft limit"
1595 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1596 quota_error a $TSTUSR "create failure, but expect success"
1597 local trigger_time=$(date +%s)
1599 sync_all_data || true
1601 local cur_time=$(date +%s)
1602 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1603 error "Passed grace time $grace, $trigger_time, $cur_time"
1605 echo "Create file before timer goes off"
1606 $RUNAS touch ${TESTFILE}_before ||
1607 quota_error a $TSTUSR "failed create before timer expired," \
1608 "but expect success. $trigger_time, $cur_time"
1609 sync_all_data || true
1611 wait_grace_time $qtype "file"
1616 $SHOW_QUOTA_INFO_USER
1617 $SHOW_QUOTA_INFO_GROUP
1618 $SHOW_QUOTA_INFO_PROJID
1620 echo "Create file after timer goes off"
1621 # exceed least soft limit is possible
1622 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1623 quota_error a $TSTUSR "create after timer expired," \
1625 sync_all_data || true
1630 $SHOW_QUOTA_INFO_USER
1631 $SHOW_QUOTA_INFO_GROUP
1632 $SHOW_QUOTA_INFO_PROJID
1634 echo "Unlink files to stop timer"
1635 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1636 wait_delete_completed
1639 $RUNAS touch ${TESTFILE}_xxx ||
1640 quota_error a $TSTUSR "touch after timer stop failure," \
1641 "but expect success"
1642 sync_all_data || true
1650 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1651 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1652 local TESTFILE=$DIR/$tdir/$tfile-0
1655 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1657 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1658 # make sure the system is clean
1659 local USED=$(getquota -u $TSTUSR global curinodes)
1660 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1662 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1663 $GRACE $DIR || error "set user grace time failed"
1664 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1665 error "set user quota failed"
1667 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1669 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1671 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1672 # make sure the system is clean
1673 USED=$(getquota -g $TSTUSR global curinodes)
1674 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1676 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1677 $GRACE $DIR || error "set group grace time failed"
1678 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1679 error "set group quota failed"
1680 TESTFILE=$DIR/$tdir/$tfile-1
1682 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1684 if is_project_quota_supported; then
1685 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1686 # make sure the system is clean
1687 USED=$(getquota -p $TSTPRJID global curinodes)
1688 [ $USED -ne 0 ] && error \
1689 "Used space($USED) for project $TSTPRJID isn't 0."
1691 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1692 $GRACE $DIR || error "set project grace time failed"
1693 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1694 error "set project quota failed"
1696 TESTFILE=$DIR/$tdir/$tfile-1
1697 # one less than limit, because of parent directory included.
1698 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1699 resetquota -p $TSTPRJID
1700 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1701 $MAX_IQ_TIME $DIR ||
1702 error "restore project grace time failed"
1706 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1707 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1708 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1709 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1711 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1714 local GR_STR1="1w3d"
1715 local GR_STR2="1000s"
1717 local GR_STR4="1w2d3h4m5s"
1719 local GR_STR6="18446744073709551615"
1722 wait_delete_completed
1724 # test of valid grace strings handling
1725 echo "Valid grace strings test"
1726 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1727 $GR_STR2 $DIR || error "set user grace time failed"
1728 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1729 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1730 $GR_STR4 $DIR || error "set group grace time quota failed"
1731 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1733 # test of invalid grace strings handling
1734 echo " Invalid grace strings test"
1735 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1736 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1737 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1741 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1742 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1743 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1744 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1746 run_test 4b "Grace time strings handling"
1748 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1750 local BLIMIT=10 # MB
1751 local ILIMIT=10 # inodes
1753 setup_quota_test || error "setup quota failed with $?"
1754 trap cleanup_quota_test EXIT
1756 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1757 set_ost_qtype $QTYPE || error "enable ost quota failed"
1759 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1760 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1761 error "set user quota failed"
1762 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1763 if is_project_quota_supported; then
1764 error "set group quota failed"
1765 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1766 -I $ILIMIT $DIR || error "set project quota failed"
1769 # make sure the system is clean
1770 local USED=$(getquota -u $TSTUSR global curinodes)
1771 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1772 USED=$(getquota -g $TSTUSR global curinodes)
1773 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1774 USED=$(getquota -u $TSTUSR global curspace)
1775 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1776 USED=$(getquota -g $TSTUSR global curspace)
1777 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1778 if is_project_quota_supported; then
1779 USED=$(getquota -p $TSTPRJID global curinodes)
1781 error "Used inode($USED) for project $TSTPRJID isn't 0."
1782 USED=$(getquota -p $TSTPRJID global curspace)
1784 error "Used block($USED) for project $TSTPRJID isn't 0."
1787 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1788 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1789 error "create failure, expect success"
1790 if is_project_quota_supported; then
1791 touch $DIR/$tdir/$tfile-0_1
1792 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1794 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1795 error "write failure, expect success"
1797 echo "Chown files to $TSTUSR.$TSTUSR ..."
1798 for i in $(seq 0 $ILIMIT); do
1799 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1800 quota_error a $TSTUSR "chown failure, expect success"
1804 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1805 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1808 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1810 # test dropping acquire request on master
1814 # Clear dmesg so watchdog is not triggered by previous
1816 do_facet ost1 dmesg -c > /dev/null
1818 setup_quota_test || error "setup quota failed with $?"
1819 trap cleanup_quota_test EXIT
1821 # make sure the system is clean
1822 local USED=$(getquota -u $TSTUSR global curspace)
1823 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1825 # make sure no granted quota on ost
1826 set_ost_qtype $QTYPE || error "enable ost quota failed"
1827 resetquota -u $TSTUSR
1829 # create file for $TSTUSR
1830 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1831 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1832 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1834 # create file for $TSTUSR2
1835 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1836 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1837 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1839 # cache per-ID lock for $TSTUSR on slave
1840 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1841 error "set quota failed"
1842 $RUNAS $DD of=$TESTFILE count=1 ||
1843 error "write $TESTFILE failure, expect success"
1844 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1845 error "write $TESTFILE2 failure, expect success"
1847 if at_is_enabled; then
1848 at_max_saved=$(at_max_get ost1)
1849 at_max_set $TIMEOUT ost1
1851 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1852 # DQACQ is sent, which makes at_max to take effect
1853 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1856 wait_delete_completed
1860 sync_all_data || true
1862 #define QUOTA_DQACQ 601
1863 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1864 lustre_fail mds 0x513 601
1866 do_facet ost1 $LCTL set_param \
1867 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1869 # write to un-enforced ID ($TSTUSR2) should succeed
1870 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1871 error "write failure, expect success"
1873 # write to enforced ID ($TSTUSR) in background, exceeding limit
1874 # to make sure DQACQ is sent
1875 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1878 # watchdog timer uses a factor of 2
1879 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1880 sleep $((TIMEOUT * 2 + 1))
1882 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1884 # write should be blocked and never finished
1885 if ! ps -p $DDPID > /dev/null 2>&1; then
1887 error "write finished incorrectly!"
1892 # no watchdog is triggered
1893 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1894 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1895 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1896 [ -z "$watchdog" ] || error "$watchdog"
1898 rm -f $TMP/lustre-log-${TESTNAME}.log
1900 # write should continue then fail with EDQUOT
1904 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1905 if [ $count -ge 240 ]; then
1906 quota_error u $TSTUSR "dd not finished in $count secs"
1908 count=$((count + 1))
1909 if [ $((count % 30)) -eq 0 ]; then
1910 c_size=$(stat -c %s $TESTFILE)
1911 echo "Waiting $count secs. $c_size"
1919 run_test 6 "Test dropping acquire request on master"
1921 # quota reintegration (global index)
1923 local TESTFILE=$DIR/$tdir/$tfile
1926 [ "$SLOW" = "no" ] && LIMIT=5
1928 setup_quota_test || error "setup quota failed with $?"
1929 trap cleanup_quota_test EXIT
1931 # make sure the system is clean
1932 local USED=$(getquota -u $TSTUSR global curspace)
1933 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1935 # make sure no granted quota on ost1
1936 set_ost_qtype $QTYPE || error "enable ost quota failed"
1937 resetquota -u $TSTUSR
1938 set_ost_qtype "none" || error "disable ost quota failed"
1940 local OSTUUID=$(ostuuid_from_index 0)
1941 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1943 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1946 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1947 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1952 echo "Enable quota & set quota limit for $TSTUSR"
1953 set_ost_qtype $QTYPE || error "enable ost quota failed"
1954 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1955 error "set quota failed"
1957 echo "Start ost1..."
1958 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1961 wait_ost_reint $QTYPE || error "reintegration failed"
1963 # hardlimit should have been fetched by slave during global
1964 # reintegration, write will exceed quota
1965 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1966 quota_error u $TSTUSR "write success, but expect EDQUOT"
1969 wait_delete_completed
1970 sync_all_data || true
1976 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1977 error "clear quota failed"
1979 echo "Start ost1..."
1980 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1983 wait_ost_reint $QTYPE || error "reintegration failed"
1985 # hardlimit should be cleared on slave during reintegration
1986 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1987 quota_error u $TSTUSR "write error, but expect success"
1991 run_test 7a "Quota reintegration (global index)"
1993 # quota reintegration (slave index)
1995 local limit=100000 # MB
1996 local TESTFILE=$DIR/$tdir/$tfile
1998 setup_quota_test || error "setup quota failed with $?"
1999 trap cleanup_quota_test EXIT
2001 # make sure the system is clean
2002 local USED=$(getquota -u $TSTUSR global curspace)
2003 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2005 # make sure no granted quota on ost1
2006 set_ost_qtype $QTYPE || error "enable ost quota failed"
2007 resetquota -u $TSTUSR
2008 set_ost_qtype "none" || error "disable ost quota failed"
2010 local OSTUUID=$(ostuuid_from_index 0)
2011 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2013 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2016 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2017 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2019 # consume some space to make sure the granted space will not
2020 # be released during reconciliation
2021 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2022 error "consume space failure, expect success"
2024 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2025 lustre_fail mds 0xa02
2027 set_ost_qtype $QTYPE || error "enable ost quota failed"
2028 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2029 error "set quota failed"
2031 # ignore the write error
2032 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2034 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2038 echo "Restart ost to trigger reintegration..."
2040 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2043 wait_ost_reint $QTYPE || error "reintegration failed"
2045 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2046 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2051 run_test 7b "Quota reintegration (slave index)"
2053 # quota reintegration (restart mds during reintegration)
2056 local TESTFILE=$DIR/$tdir/$tfile
2058 [ "$SLOW" = "no" ] && LIMIT=5
2060 setup_quota_test || error "setup quota failed with $?"
2061 trap cleanup_quota_test EXIT
2063 # make sure the system is clean
2064 local USED=$(getquota -u $TSTUSR global curspace)
2065 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2067 set_ost_qtype "none" || error "disable ost quota failed"
2068 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2069 error "set quota failed"
2071 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2072 lustre_fail ost 0xa03
2075 set_ost_qtype $QTYPE || error "enable ost quota failed"
2076 # trigger reintegration
2077 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2078 procf=${procf}quota_slave.force_reint
2079 do_facet ost1 $LCTL set_param $procf=1 ||
2080 error "force reintegration failed"
2088 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2091 # wait longer than usual to make sure the reintegration
2092 # is triggered by quota wb thread.
2093 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2095 # hardlimit should have been fetched by slave during global
2096 # reintegration, write will exceed quota
2097 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2098 quota_error u $TSTUSR "write success, but expect EDQUOT"
2102 run_test 7c "Quota reintegration (restart mds during reintegration)"
2104 # Quota reintegration (Transfer index in multiple bulks)
2106 local TESTFILE=$DIR/$tdir/$tfile
2107 local TESTFILE1="$DIR/$tdir/$tfile"-1
2110 setup_quota_test || error "setup quota failed with $?"
2111 trap cleanup_quota_test EXIT
2113 set_ost_qtype "none" || error "disable ost quota failed"
2114 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2115 error "set quota for $TSTUSR failed"
2116 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2117 error "set quota for $TSTUSR2 failed"
2119 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2120 lustre_fail mds 0x608 0
2122 # enable quota to tirgger reintegration
2123 set_ost_qtype "u" || error "enable ost quota failed"
2124 wait_ost_reint "u" || error "reintegration failed"
2128 # hardlimit should have been fetched by slave during global
2129 # reintegration, write will exceed quota
2130 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2131 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2133 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2134 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2138 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2140 # quota reintegration (inode limits)
2142 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2144 # LU-2435: skip this quota test if underlying zfs version has not
2145 # supported native dnode accounting
2146 [ "$mds1_FSTYPE" == zfs ] && {
2147 local F="feature@userobj_accounting"
2148 local pool=$(zpool_name mds1)
2149 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2151 [[ "$feature" != *" active "* ]] &&
2152 skip "requires zpool with active userobj_accounting"
2155 local ilimit=$((1024 * 2)) # inodes
2156 local TESTFILE=$DIR/${tdir}-1/$tfile
2158 setup_quota_test || error "setup quota failed with $?"
2159 trap cleanup_quota_test EXIT
2161 # make sure the system is clean
2162 local USED=$(getquota -u $TSTUSR global curinodes)
2163 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2165 # make sure no granted quota on mdt1
2166 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2167 resetquota -u $TSTUSR
2168 set_mdt_qtype "none" || error "disable mdt quota failed"
2170 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2171 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2172 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2175 echo "Stop mds${MDSCOUNT}..."
2178 echo "Enable quota & set quota limit for $TSTUSR"
2179 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2180 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2181 error "set quota failed"
2183 echo "Start mds${MDSCOUNT}..."
2184 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2187 wait_mdt_reint $QTYPE || error "reintegration failed"
2189 echo "create remote dir"
2190 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2191 error "create remote dir failed"
2192 chmod 0777 $DIR/${tdir}-1
2194 # hardlimit should have been fetched by slave during global
2195 # reintegration, create will exceed quota
2196 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2197 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2199 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2200 wait_delete_completed
2201 sync_all_data || true
2203 echo "Stop mds${MDSCOUNT}..."
2206 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2207 error "clear quota failed"
2209 echo "Start mds${MDSCOUNT}..."
2210 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2213 wait_mdt_reint $QTYPE || error "reintegration failed"
2215 # hardlimit should be cleared on slave during reintegration
2216 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2217 quota_error u $TSTUSR "create failed, expect success"
2219 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2220 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2224 run_test 7e "Quota reintegration (inode limits)"
2226 # run dbench with quota enabled
2228 local BLK_LIMIT="100g" #100G
2229 local FILE_LIMIT=1000000
2231 setup_quota_test || error "setup quota failed with $?"
2232 trap cleanup_quota_test EXIT
2234 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2235 set_ost_qtype $QTYPE || error "enable ost quota failed"
2237 echo "Set enough high limit for user: $TSTUSR"
2238 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2239 error "set user quota failed"
2240 echo "Set enough high limit for group: $TSTUSR"
2241 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2242 error "set group quota failed"
2243 if is_project_quota_supported; then
2244 change_project -sp $TSTPRJID $DIR/$tdir
2245 echo "Set enough high limit for project: $TSTPRJID"
2246 $LFS setquota -p $TSTPRJID -b 0 \
2247 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2248 error "set project quota failed"
2252 [ "$SLOW" = "no" ] && duration=" -t 120"
2253 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2254 quota_error a $TSTUSR "dbench failed!"
2256 is_project_quota_supported && change_project -C $DIR/$tdir
2259 run_test 8 "Run dbench with quota enabled"
2261 # this check is just for test_9
2262 OST0_MIN=4900000 #4.67G
2264 check_whether_skip () {
2265 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2266 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2267 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2268 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2275 # run for fixing bug10707, it needs a big room. test for 64bit
2277 local filesize=$((1024 * 9 / 2)) # 4.5G
2279 check_whether_skip && return 0
2281 setup_quota_test || error "setup quota failed with $?"
2282 trap cleanup_quota_test EXIT
2284 set_ost_qtype "ug" || error "enable ost quota failed"
2286 local TESTFILE="$DIR/$tdir/$tfile-0"
2287 local BLK_LIMIT=100G #100G
2288 local FILE_LIMIT=1000000
2290 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2292 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2294 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2295 error "set user quota failed"
2297 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2298 "for group: $TSTUSR"
2299 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2300 error "set group quota failed"
2302 quota_show_check a u $TSTUSR
2303 quota_show_check a g $TSTUSR
2305 echo "Create test file"
2306 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2307 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2309 log "Write the big file of 4.5G ..."
2310 $RUNAS $DD of=$TESTFILE count=$filesize ||
2311 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2321 run_test 9 "Block limit larger than 4GB (b10707)"
2324 local TESTFILE=$DIR/$tdir/$tfile
2326 setup_quota_test || error "setup quota failed with $?"
2327 trap cleanup_quota_test EXIT
2329 # set limit to root user should fail
2330 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2331 error "set limit for root user successfully, expect failure"
2332 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2333 error "set limit for root group successfully, expect failure"
2334 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2335 error "set limit for project 0 successfully, expect failure"
2337 # root user can overrun quota
2338 set_ost_qtype "ug" || error "enable ost quota failed"
2340 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2341 error "set quota failed"
2342 quota_show_check b u $TSTUSR
2344 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2345 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2347 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2348 error "write failure, expect success"
2352 run_test 10 "Test quota for root user"
2355 local TESTFILE=$DIR/$tdir/$tfile
2356 setup_quota_test || error "setup quota failed with $?"
2357 trap cleanup_quota_test EXIT
2359 set_mdt_qtype "ug" || error "enable mdt quota failed"
2360 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2361 error "set quota failed"
2363 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2364 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2366 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2367 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2370 local USED=$(getquota -u $TSTUSR global curinodes)
2371 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2375 run_test 11 "Chown/chgrp ignores quota"
2378 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2380 local blimit=22 # MB
2381 local blk_cnt=$((blimit - 5))
2382 local TESTFILE0="$DIR/$tdir/$tfile"-0
2383 local TESTFILE1="$DIR/$tdir/$tfile"-1
2385 setup_quota_test || error "setup quota failed with $?"
2386 trap cleanup_quota_test EXIT
2388 set_ost_qtype "u" || error "enable ost quota failed"
2389 quota_show_check b u $TSTUSR
2391 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2392 error "set quota failed"
2394 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2395 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2396 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2397 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2399 echo "Write to ost0..."
2400 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2401 quota_error a $TSTUSR "dd failed"
2403 echo "Write to ost1..."
2404 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2405 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2407 echo "Free space from ost0..."
2409 wait_delete_completed
2410 sync_all_data || true
2412 echo "Write to ost1 after space freed from ost0..."
2413 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2414 quota_error a $TSTUSR "rebalancing failed"
2418 run_test 12a "Block quota rebalancing"
2421 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2423 local ilimit=$((1024 * 2)) # inodes
2424 local TESTFILE0=$DIR/$tdir/$tfile
2425 local TESTFILE1=$DIR/${tdir}-1/$tfile
2427 setup_quota_test || error "setup quota failed with $?"
2428 trap cleanup_quota_test EXIT
2430 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2431 chmod 0777 $DIR/${tdir}-1
2433 set_mdt_qtype "u" || error "enable mdt quota failed"
2434 quota_show_check f u $TSTUSR
2436 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2437 error "set quota failed"
2439 echo "Create $ilimit files on mdt0..."
2440 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2441 quota_error u $TSTUSR "create failed, but expect success"
2443 echo "Create files on mdt1..."
2444 $RUNAS createmany -m $TESTFILE1 1 &&
2445 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2447 echo "Free space from mdt0..."
2448 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2449 wait_delete_completed
2450 sync_all_data || true
2452 echo "Create files on mdt1 after space freed from mdt0..."
2453 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2454 quota_error a $TSTUSR "rebalancing failed"
2456 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2457 error "unlink mdt1 files failed"
2458 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2462 run_test 12b "Inode quota rebalancing"
2465 local TESTFILE=$DIR/$tdir/$tfile
2466 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2467 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2469 setup_quota_test || error "setup quota failed with $?"
2470 trap cleanup_quota_test EXIT
2472 set_ost_qtype "u" || error "enable ost quota failed"
2473 quota_show_check b u $TSTUSR
2475 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2476 error "set quota failed"
2477 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2478 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2480 # clear the locks in cache first
2481 do_facet ost1 $LCTL set_param -n $procf=clear
2482 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2483 [ $nlock -eq 0 ] || error "$nlock cached locks"
2485 # write to acquire the per-ID lock
2486 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2487 quota_error a $TSTUSR "dd failed"
2489 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2490 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2492 # clear quota doesn't trigger per-ID lock cancellation
2493 resetquota -u $TSTUSR
2494 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2495 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2497 # clear the per-ID lock
2498 do_facet ost1 $LCTL set_param -n $procf=clear
2499 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2500 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2502 # spare quota should be released
2503 local OSTUUID=$(ostuuid_from_index 0)
2504 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2505 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2506 [ $limit -le $space ] ||
2507 error "spare quota isn't released, limit:$limit, space:$space"
2511 run_test 13 "Cancel per-ID lock in the LRU list"
2514 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2516 wait_delete_completed
2517 sync_all_data || true
2520 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2521 error "set user quota failed"
2522 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2523 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2524 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2525 resetquota -u $TSTUSR
2528 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2529 error "set group quota failed"
2530 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2531 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2532 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2533 resetquota -g $TSTUSR
2535 run_test 15 "Set over 4T block quota"
2539 local BLKS=1 # 1M less than limit
2540 local TESTFILE=$DIR/$tdir/$tfile
2542 setup_quota_test || error "setup quota failed with $?"
2543 trap cleanup_quota_test EXIT
2545 # make sure the system is clean
2546 local USED=$(getquota -u $TSTUSR global curspace)
2547 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2549 set_ost_qtype "ug" || error "enable ost quota failed"
2550 # make sure no granted quota on ost
2551 resetquota -u $TSTUSR
2552 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2553 error "set quota failed"
2555 quota_show_check b u $TSTUSR
2557 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2558 lustre_fail mds 0xa04 $err_code
2560 # write in background
2561 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2565 # write should be blocked and never finished
2566 if ! ps -p $DDPID > /dev/null 2>&1; then
2568 quota_error u $TSTUSR "write finished incorrectly!"
2576 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2578 if [ $count -gt $timeout ]; then
2579 quota_error u $TSTUSR "dd is not finished!"
2584 sync; sync_all_data || true
2586 USED=$(getquota -u $TSTUSR global curspace)
2587 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2588 "Used space(${USED}K) is less than ${BLKS}M"
2593 # DQACQ return recoverable error
2595 echo "DQACQ return -ENOLCK"
2597 test_17sub 37 || error "Handle -ENOLCK failed"
2599 echo "DQACQ return -EAGAIN"
2601 test_17sub 11 || error "Handle -EAGAIN failed"
2603 echo "DQACQ return -ETIMEDOUT"
2604 #define ETIMEDOUT 110
2605 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2607 echo "DQACQ return -ENOTCONN"
2608 #define ENOTCONN 107
2609 test_17sub 107 || error "Handle -ENOTCONN failed"
2612 run_test 17 "DQACQ return recoverable error"
2616 local blimit=200 # MB
2617 local TESTFILE="$DIR/$tdir/$tfile"
2619 setup_quota_test || error "setup quota failed with $?"
2620 trap cleanup_quota_test EXIT
2622 set_ost_qtype "u" || error "enable ost quota failed"
2623 log "User quota (limit: $blimit)"
2624 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2625 error "set quota failed"
2626 quota_show_check b u $TSTUSR
2628 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2629 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2631 local timeout=$(sysctl -n lustre.timeout)
2633 if [ $io_type = "directio" ]; then
2634 log "Write 100M (directio) ..."
2635 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2637 log "Write 100M (buffered) ..."
2638 $RUNAS $DD of=$TESTFILE count=100 &
2642 replay_barrier $SINGLEMDS
2643 log "Fail mds for $((2 * timeout)) seconds"
2644 fail $SINGLEMDS $((2 * timeout))
2647 if at_is_enabled; then
2648 timeout=$(at_max_get mds)
2650 timeout=$(lctl get_param -n timeout)
2654 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2655 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2656 log "it took $count second"
2661 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2663 cancel_lru_locks mdc
2664 cancel_lru_locks osc
2667 local testfile_size=$(stat -c %s $TESTFILE)
2668 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2669 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2670 "got ${testfile_size}. Verifying file failed!"
2675 # test when mds does failover, the ost still could work well
2676 # this test shouldn't trigger watchdog b=14840
2678 # Clear dmesg so watchdog is not triggered by previous
2680 do_facet ost1 dmesg -c > /dev/null
2683 test_18_sub directio
2685 # check if watchdog is triggered
2686 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2687 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2688 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2689 [ -z "$watchdog" ] || error "$watchdog"
2690 rm -f $TMP/lustre-log-${TESTNAME}.log
2692 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2696 local TESTFILE=$DIR/$tdir/$tfile
2698 setup_quota_test || error "setup quota failed with $?"
2699 trap cleanup_quota_test EXIT
2701 set_ost_qtype $QTYPE || error "enable ost quota failed"
2703 # bind file to a single OST
2704 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2705 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2707 echo "Set user quota (limit: ${blimit}M)"
2708 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2709 error "set user quota failed"
2710 quota_show_check b u $TSTUSR
2711 echo "Update quota limits"
2712 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2713 error "set group quota failed"
2714 quota_show_check b u $TSTUSR
2716 # first wirte might be cached
2717 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2718 cancel_lru_locks osc
2720 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2721 quota_error u $TSTUSR "Write success, expect failure"
2726 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2728 test_20() { # b15754
2729 local LSTR=(2g 1t 4k 3m) # limits strings
2731 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2734 resetquota -u $TSTUSR
2736 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2737 $MOUNT || error "could not set quota limits"
2738 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2739 --inode-softlimit ${LSTR[2]} \
2740 --inode-hardlimit ${LSTR[3]} \
2741 $MOUNT || error "could not set quota limits"
2743 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2744 error "bsoftlimit was not set properly"
2745 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2746 error "bhardlimit was not set properly"
2747 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2748 error "isoftlimit was not set properly"
2749 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2750 error "ihardlimit was not set properly"
2752 resetquota -u $TSTUSR
2754 run_test 20 "Test if setquota specifiers work properly (b15754)"
2761 local time=$(($(date +%s) + seconds))
2762 while [ $(date +%s) -lt $time ]; do
2763 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2767 # run for fixing bug16053, setquota shouldn't fail when writing and
2768 # deleting are happening
2770 local TESTFILE="$DIR/$tdir/$tfile"
2771 local BLIMIT=10 # 10G
2772 local ILIMIT=1000000
2774 setup_quota_test || error "setup quota failed with $?"
2775 trap cleanup_quota_test EXIT
2777 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2779 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2780 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2781 error "set user quota failed"
2782 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2783 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2784 error "set group quota failed"
2785 if is_project_quota_supported; then
2786 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2787 "project: $TSTPRJID"
2788 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2789 $MOUNT || error "set project quota failed"
2792 # repeat writing on a 1M file
2793 test_21_sub ${TESTFILE}_1 1 30 &
2795 # repeat writing on a 128M file
2796 test_21_sub ${TESTFILE}_2 128 30 &
2799 local time=$(($(date +%s) + 30))
2801 while [ $(date +%s) -lt $time ]; do
2802 log "Set quota for $i times"
2803 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2804 -I $((ILIMIT + i)) $MOUNT ||
2805 error "Set user quota failed"
2806 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2807 -I $((ILIMIT + i)) $MOUNT ||
2808 error "Set group quota failed"
2809 if is_project_quota_supported; then
2810 $LFS setquota -p $TSTPRJID -b 0 -B \
2811 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2812 error "Set project quota failed"
2820 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2822 if [ $count -gt 60 ]; then
2823 quota_error a $TSTUSR "dd should be finished!"
2827 echo "(dd_pid=$DDPID1, time=$count)successful"
2831 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2833 if [ $count -gt 60 ]; then
2834 quota_error a $TSTUSR "dd should be finished!"
2838 echo "(dd_pid=$DDPID2, time=$count)successful"
2842 run_test 21 "Setquota while writing & deleting (b16053)"
2844 # enable/disable quota enforcement permanently
2846 echo "Set both mdt & ost quota type as ug"
2848 is_project_quota_supported && qtype=$QTYPE
2849 set_mdt_qtype $qtype || error "enable mdt quota failed"
2850 set_ost_qtype $qtype || error "enable ost quota failed"
2853 stopall || error "failed to stopall (1)"
2857 echo "Verify if quota is enabled"
2858 local qtype1=$(mdt_quota_type)
2859 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2860 qtype=$(ost_quota_type)
2861 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2863 echo "Set both mdt & ost quota type as none"
2864 set_mdt_qtype "none" || error "disable mdt quota failed"
2865 set_ost_qtype "none" || error "disable ost quota failed"
2868 stopall || error "failed to stopall (2)"
2873 echo "Verify if quota is disabled"
2874 qtype=$(mdt_quota_type)
2875 [ $qtype != "none" ] && error "mdt quota setting is lost"
2876 qtype=$(ost_quota_type)
2877 [ $qtype != "none" ] && error "ost quota setting is lost"
2881 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2884 local TESTFILE="$DIR/$tdir/$tfile"
2887 setup_quota_test || error "setup quota failed with $?"
2888 trap cleanup_quota_test EXIT
2890 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2893 log "User quota (limit: $LIMIT MB)"
2894 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2895 error "set quota failed"
2896 quota_show_check b u $TSTUSR
2898 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2899 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2901 log "Step1: trigger EDQUOT with O_DIRECT"
2902 log "Write half of file"
2903 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2904 quota_error u $TSTUSR "(1) Write failure, expect success." \
2906 log "Write out of block quota ..."
2907 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2908 oflag=direct conv=notrunc &&
2909 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2913 log "Step2: rewrite should succeed"
2914 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2915 quota_error u $TSTUSR "(3) Write failure, expect success." \
2921 local OST0_UUID=$(ostuuid_from_index 0)
2922 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2923 [ $OST0_QUOTA_USED -ne 0 ] &&
2924 ($SHOW_QUOTA_USER; \
2925 quota_error u $TSTUSR "quota isn't released")
2930 [ "$ost1_FSTYPE" == zfs ] &&
2931 skip "Overwrite in place is not guaranteed to be " \
2932 "space neutral on ZFS"
2934 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2935 check_whether_skip && return 0
2936 log "run for 4MB test file"
2939 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2940 check_whether_skip && return 0
2941 log "run for 40MB test file"
2944 run_test 23 "Quota should be honored with directIO (b16125)"
2948 local TESTFILE="$DIR/$tdir/$tfile"
2950 setup_quota_test || error "setup quota failed with $?"
2951 trap cleanup_quota_test EXIT
2953 set_ost_qtype $QTYPE || error "enable ost quota failed"
2955 # bind file to a single OST
2956 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2957 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2959 echo "Set user quota (limit: ${blimit}M)"
2960 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2961 error "set quota failed"
2963 # overrun quota by root user
2964 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2965 error "write failure, expect success"
2966 cancel_lru_locks osc
2967 sync_all_data || true
2969 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2973 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2975 test_27a() { # b19612
2976 $LFS quota $TSTUSR $DIR &&
2977 error "lfs succeeded with no type, but should have failed"
2978 $LFS setquota $TSTUSR $DIR &&
2979 error "lfs succeeded with no type, but should have failed"
2982 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2984 test_27b() { # b20200
2985 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2986 error "lfs setquota failed with uid argument"
2987 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2988 error "lfs stequota failed with gid argument"
2989 if is_project_quota_supported; then
2990 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2991 1000 $DIR || error \
2992 "lfs stequota failed with projid argument"
2994 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2995 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2996 if is_project_quota_supported; then
2997 $SHOW_QUOTA_PROJID ||
2998 error "lfs quota failed with projid argument"
3000 resetquota -u $TSTID
3001 resetquota -g $TSTID
3002 resetquota -p $TSTPRJID
3005 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3010 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3011 error "lfs setquota failed"
3013 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3014 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3015 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3016 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3018 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3019 error "lfs setquota for $TSTID failed"
3021 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3022 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3023 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3024 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3026 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3027 error "total allocated inode/block limit not printed"
3029 resetquota -u $TSTUSR
3031 run_test 27c "lfs quota should support human-readable output"
3038 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3039 error "set fraction block limit failed"
3040 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3041 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3042 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3043 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3045 resetquota -u $TSTUSR
3047 run_test 27d "lfs setquota should support fraction block limit"
3051 local TESTFILE="$DIR/$tdir/$tfile"
3054 setup_quota_test || error "setup quota failed with $?"
3055 trap cleanup_quota_test EXIT
3057 set_ost_qtype "u" || error "enable ost quota failed"
3059 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3060 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3062 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3063 $MAX_IQ_TIME $DIR || error "set grace time failed"
3064 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3065 error "set quota failed"
3066 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3067 cancel_lru_locks osc
3069 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3070 # over-quota flag has not yet settled since we do not trigger async
3071 # events based on grace time period expiration
3073 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3074 cancel_lru_locks osc
3075 # now over-quota flag should be settled and further writes should fail
3077 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3078 error "grace times were reset"
3081 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3082 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3084 run_test 30 "Hard limit updates should not reset grace times"
3086 # basic usage tracking for user & group
3088 local INODES=10 # files
3089 local BLK_CNT=2 # MB each
3090 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3092 setup_quota_test || error "setup quota failed with $?"
3093 trap cleanup_quota_test EXIT
3095 # make sure the system is clean
3096 local USED=$(getquota -u $TSTID global curspace)
3098 error "Used space ($USED) for user $TSTID isn't 0."
3099 USED=$(getquota -g $TSTID global curspace)
3101 error "Used space ($USED) for group $TSTID isn't 0."
3102 if is_project_quota_supported; then
3103 USED=$(getquota -p $TSTPRJID global curspace)
3104 [ $USED -ne 0 ] && error \
3105 "Used space ($USED) for project $TSTPRJID isn't 0."
3108 echo "Write files..."
3109 for i in $(seq 0 $INODES); do
3110 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3111 error "write failed"
3112 is_project_quota_supported &&
3113 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3114 echo "Iteration $i/$INODES completed"
3116 cancel_lru_locks osc
3118 echo "Wait for setattr on objects finished..."
3119 wait_delete_completed
3121 sync; sync_all_data || true
3123 echo "Verify disk usage after write"
3124 USED=$(getquota -u $TSTID global curspace)
3125 [ $USED -lt $TOTAL_BLKS ] &&
3126 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3127 USED=$(getquota -g $TSTID global curspace)
3128 [ $USED -lt $TOTAL_BLKS ] &&
3129 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3130 if is_project_quota_supported; then
3131 USED=$(getquota -p $TSTPRJID global curspace)
3132 [ $USED -lt $TOTAL_BLKS ] && error \
3133 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3136 echo "Verify inode usage after write"
3137 USED=$(getquota -u $TSTID global curinodes)
3138 [ $USED -lt $INODES ] &&
3139 error "Used inode for user $TSTID is $USED, expected $INODES"
3140 USED=$(getquota -g $TSTID global curinodes)
3141 [ $USED -lt $INODES ] &&
3142 error "Used inode for group $TSTID is $USED, expected $INODES"
3143 if is_project_quota_supported; then
3144 USED=$(getquota -p $TSTPRJID global curinodes)
3145 [ $USED -lt $INODES ] && error \
3146 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3151 echo "Verify disk usage after delete"
3152 USED=$(getquota -u $TSTID global curspace)
3153 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3154 USED=$(getquota -u $TSTID global curinodes)
3155 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3156 USED=$(getquota -g $TSTID global curspace)
3157 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3158 USED=$(getquota -g $TSTID global curinodes)
3159 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3160 if is_project_quota_supported; then
3161 USED=$(getquota -p $TSTPRJID global curspace)
3163 error "Used space for project $TSTPRJID isn't 0. $USED"
3164 USED=$(getquota -p $TSTPRJID global curinodes)
3166 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3169 run_test 33 "Basic usage tracking for user & group & project"
3171 # usage transfer test for user & group & project
3173 local BLK_CNT=2 # MB
3174 local project_supported="no"
3176 is_project_quota_supported && project_supported="yes"
3177 setup_quota_test || error "setup quota failed with $?"
3178 trap cleanup_quota_test EXIT
3180 # make sure the system is clean
3181 local USED=$(getquota -u $TSTID global curspace)
3182 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3183 USED=$(getquota -g $TSTID global curspace)
3184 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3186 local USED=$(getquota -u $TSTID2 global curspace)
3187 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3188 if [ $project_supported == "yes" ]; then
3189 USED=$(getquota -p $TSTPRJID global curspace)
3190 [ $USED -ne 0 ] && error \
3191 "Used space ($USED) for Project $TSTPRJID isn't 0."
3194 echo "Write file..."
3195 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3196 error "write failed"
3197 cancel_lru_locks osc
3198 sync; sync_all_data || true
3200 echo "chown the file to user $TSTID"
3201 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3203 echo "Wait for setattr on objects finished..."
3204 wait_delete_completed
3206 BLK_CNT=$((BLK_CNT * 1024))
3208 echo "Verify disk usage for user $TSTID"
3209 USED=$(getquota -u $TSTID global curspace)
3210 [ $USED -lt $BLK_CNT ] &&
3211 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3212 USED=$(getquota -u $TSTID global curinodes)
3214 error "Used inodes for user $TSTID is $USED, expected 1"
3216 echo "chgrp the file to group $TSTID"
3217 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3219 echo "Wait for setattr on objects finished..."
3220 wait_delete_completed
3222 echo "Verify disk usage for group $TSTID"
3223 USED=$(getquota -g $TSTID global curspace)
3224 [ $USED -ge $BLK_CNT ] ||
3225 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3226 USED=$(getquota -g $TSTID global curinodes)
3228 error "Used inodes for group $TSTID is $USED, expected 1"
3230 # chown won't change the ost object group. LU-4345 */
3231 echo "chown the file to user $TSTID2"
3232 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3234 echo "Wait for setattr on objects finished..."
3235 wait_delete_completed
3237 echo "change_project project id to $TSTPRJID"
3238 [ $project_supported == "yes" ] &&
3239 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3240 echo "Wait for setattr on objects finished..."
3241 wait_delete_completed
3243 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3244 USED=$(getquota -u $TSTID2 global curspace)
3245 [ $USED -lt $BLK_CNT ] &&
3246 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3247 USED=$(getquota -u $TSTID global curspace)
3249 error "Used space for user $TSTID is $USED, expected 0"
3250 USED=$(getquota -g $TSTID global curspace)
3251 [ $USED -lt $BLK_CNT ] &&
3252 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3253 if [ $project_supported == "yes" ]; then
3254 USED=$(getquota -p $TSTPRJID global curspace)
3255 [ $USED -lt $BLK_CNT ] && error \
3256 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3261 run_test 34 "Usage transfer for user & group & project"
3263 # usage is still accessible across restart
3265 local BLK_CNT=2 # MB
3267 setup_quota_test || error "setup quota failed with $?"
3268 trap cleanup_quota_test EXIT
3270 echo "Write file..."
3271 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3272 error "write failed"
3273 is_project_quota_supported &&
3274 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3275 cancel_lru_locks osc
3277 echo "Wait for setattr on objects finished..."
3278 wait_delete_completed
3280 sync; sync_all_data || true
3282 echo "Save disk usage before restart"
3283 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3284 [ $ORIG_USR_SPACE -eq 0 ] &&
3285 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3286 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3287 [ $ORIG_USR_INODES -eq 0 ] &&
3288 error "Used inodes for user $TSTID is 0, expected 1"
3289 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3290 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3291 [ $ORIG_GRP_SPACE -eq 0 ] &&
3292 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3293 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3294 [ $ORIG_GRP_INODES -eq 0 ] &&
3295 error "Used inodes for group $TSTID is 0, expected 1"
3296 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3298 if is_project_quota_supported; then
3299 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3300 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3301 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3302 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3303 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3304 "Used inodes for project $TSTPRJID is 0, expected 1"
3305 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3313 echo "Verify disk usage after restart"
3314 local USED=$(getquota -u $TSTID global curspace)
3315 [ $USED -eq $ORIG_USR_SPACE ] ||
3316 error "Used space for user $TSTID changed from " \
3317 "$ORIG_USR_SPACE to $USED"
3318 USED=$(getquota -u $TSTID global curinodes)
3319 [ $USED -eq $ORIG_USR_INODES ] ||
3320 error "Used inodes for user $TSTID changed from " \
3321 "$ORIG_USR_INODES to $USED"
3322 USED=$(getquota -g $TSTID global curspace)
3323 [ $USED -eq $ORIG_GRP_SPACE ] ||
3324 error "Used space for group $TSTID changed from " \
3325 "$ORIG_GRP_SPACE to $USED"
3326 USED=$(getquota -g $TSTID global curinodes)
3327 [ $USED -eq $ORIG_GRP_INODES ] ||
3328 error "Used inodes for group $TSTID changed from " \
3329 "$ORIG_GRP_INODES to $USED"
3330 if [ $project_supported == "yes" ]; then
3331 USED=$(getquota -p $TSTPRJID global curinodes)
3332 [ $USED -eq $ORIG_PRJ_INODES ] ||
3333 error "Used inodes for project $TSTPRJID " \
3334 "changed from $ORIG_PRJ_INODES to $USED"
3335 USED=$(getquota -p $TSTPRJID global curspace)
3336 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3337 error "Used space for project $TSTPRJID "\
3338 "changed from $ORIG_PRJ_SPACE to $USED"
3341 # check if the vfs_dq_init() is called before writing
3342 echo "Append to the same file..."
3343 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3344 error "write failed"
3345 cancel_lru_locks osc
3346 sync; sync_all_data || true
3348 echo "Verify space usage is increased"
3349 USED=$(getquota -u $TSTID global curspace)
3350 [ $USED -gt $ORIG_USR_SPACE ] ||
3351 error "Used space for user $TSTID isn't increased" \
3352 "orig:$ORIG_USR_SPACE, now:$USED"
3353 USED=$(getquota -g $TSTID global curspace)
3354 [ $USED -gt $ORIG_GRP_SPACE ] ||
3355 error "Used space for group $TSTID isn't increased" \
3356 "orig:$ORIG_GRP_SPACE, now:$USED"
3357 if [ $project_supported == "yes" ]; then
3358 USED=$(getquota -p $TSTPRJID global curspace)
3359 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3360 error "Used space for project $TSTPRJID isn't " \
3361 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3366 run_test 35 "Usage is still accessible across reboot"
3368 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3371 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3372 skip "Old server doesn't have LU-5006 fix."
3374 setup_quota_test || error "setup quota failed with $?"
3375 trap cleanup_quota_test EXIT
3377 # make sure the system is clean
3378 local USED=$(getquota -u $TSTID global curspace)
3380 error "Used space ($USED) for user $TSTID isn't 0."
3382 # create file with MDS_OPEN_DELAY_CREATE flag
3383 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3384 error "Create file failed"
3386 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3387 oflag=sync || error "Write file failed"
3389 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3391 # wait for setattr on objects finished..."
3392 wait_delete_completed
3394 USED=$(getquota -u $TSTID global curspace)
3395 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3399 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3403 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3404 skip "Old server doesn't have LU-8801 fix."
3406 [ "$UID" != 0 ] && skip_env "must run as root" && return
3408 setup_quota_test 0 || error "setup quota failed with $?"
3409 trap cleanup_quota_test EXIT
3411 # make sure the system is clean
3412 local USED=$(getquota -u $TSTID global curspace)
3414 error "Used space ($USED) for user $TSTID isn't 0."
3415 USED=$(getquota -u $TSTID2 global curspace)
3417 error "Used space ($USED) for user $TSTID2 isn't 0."
3419 local TESTFILE="$DIR/$tdir/$tfile"
3420 local file_cnt=10000
3422 # Generate id entries in accounting file
3423 echo "Create $file_cnt files..."
3424 for i in `seq $file_cnt`; do
3426 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3427 error "failed to chown $TESTFILE-$i"
3429 cancel_lru_locks osc
3430 sync; sync_all_data || true
3432 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3433 procf=${procf}.quota_slave.acct_user
3436 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3437 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3438 echo "Found $acct_cnt id entries"
3440 [ $file_cnt -eq $acct_cnt ] || {
3441 do_facet mds1 $LCTL get_param $procf
3442 error "skipped id entries"
3447 run_test 38 "Quota accounting iterator doesn't skip id entries"
3450 local TESTFILE="$DIR/$tdir/project"
3451 ! is_project_quota_supported &&
3452 skip "Project quota is not supported"
3454 setup_quota_test || error "setup quota failed with $?"
3457 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3458 [ $projectid -ne 0 ] &&
3459 error "Project id should be 0 not $projectid"
3460 change_project -p 1024 $TESTFILE
3461 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3462 [ $projectid -ne 1024 ] &&
3463 error "Project id should be 1024 not $projectid"
3465 stopall || error "failed to stopall (1)"
3468 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3469 [ $projectid -ne 1024 ] &&
3470 error "Project id should be 1024 not $projectid"
3474 run_test 39 "Project ID interface works correctly"
3477 ! is_project_quota_supported &&
3478 skip "Project quota is not supported"
3479 local dir1="$DIR/$tdir/dir1"
3480 local dir2="$DIR/$tdir/dir2"
3482 setup_quota_test || error "setup quota failed with $?"
3484 mkdir -p $dir1 $dir2
3485 change_project -sp 1 $dir1 && touch $dir1/1
3486 change_project -sp 2 $dir2
3488 ln $dir1/1 $dir2/1_link &&
3489 error "Hard link across different project quota should fail"
3494 run_test 40a "Hard link across different project ID"
3497 ! is_project_quota_supported &&
3498 skip "Project quota is not supported"
3499 local dir1="$DIR/$tdir/dir1"
3500 local dir2="$DIR/$tdir/dir2"
3502 setup_quota_test || error "setup quota failed with $?"
3503 mkdir -p $dir1 $dir2
3504 change_project -sp 1 $dir1 && touch $dir1/1
3505 change_project -sp 2 $dir2
3507 mv $dir1/1 $dir2/2 || error "mv failed $?"
3508 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3509 if [ "$projid" != "2" ]; then
3510 error "project id expected 2 not $projid"
3515 run_test 40b "Mv across different project ID"
3518 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3519 ! is_project_quota_supported &&
3520 skip "Project quota is not supported"
3522 setup_quota_test || error "setup quota failed with $?"
3523 local dir="$DIR/$tdir/dir"
3525 mkdir -p $dir && change_project -sp 1 $dir
3526 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3527 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3528 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3529 touch $dir/remote_dir/file
3530 #verify inherit works file for remote dir.
3531 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3532 [ "$projid" != "1" ] &&
3533 error "file under remote dir expected 1 not $projid"
3535 #Agent inode should be ignored for project quota
3536 USED=$(getquota -p 1 global curinodes)
3537 [ "$USED" != "3" ] &&
3538 error "file count expected 3 got $USED"
3544 run_test 40c "Remote child Dir inherit project quota properly"
3547 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3548 is_project_quota_supported || skip "Project quota is not supported"
3550 setup_quota_test || error "setup quota failed with $?"
3551 local dir="$DIR/$tdir/dir"
3554 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3555 change_project -sp $TSTPRJID $dir ||
3556 error "change project on $dir failed"
3557 for i in $(seq 5); do
3558 mkdir -p $dir/d$i/d$i ||
3559 error "mkdir $dir/d$i/d$i failed"
3560 local projid=$($LFS project -d $dir/d$i/d$i |
3562 [ "$projid" == "$TSTPRJID" ] ||
3563 error "projid id expected $TSTPRJID not $projid"
3564 touch $dir/d$i/d$i/file
3565 #verify inherit works file for stripe dir.
3566 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3567 [ "$projid" == "$TSTPRJID" ] ||
3568 error "file under remote dir expected 1 not $projid"
3571 # account should be 1 + (2 + 1) *10 + 1 * 5
3572 USED=$(getquota -p $TSTPRJID global curinodes)
3573 [ "$USED" == "36" ] ||
3574 error "file count expected 36 got $USED"
3579 run_test 40d "Stripe Directory inherit project quota properly"
3582 is_project_quota_supported ||
3583 skip "Project quota is not supported"
3584 setup_quota_test || error "setup quota failed with $?"
3585 trap cleanup_quota_test EXIT
3586 local dir="$DIR/$tdir/dir"
3589 local projid=$((testnum * 1000))
3593 # enable mdt/ost quota
3594 set_mdt_qtype ugp || error "enable mdt quota failed"
3595 set_ost_qtype ugp || error "enable ost quota failed"
3597 test_mkdir -p $dir && change_project -sp $projid $dir
3598 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3599 error "set project quota failed"
3604 # check if df output works as expected
3605 echo "== global statfs: $MOUNT =="
3606 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3608 echo "== project statfs (prjid=$projid): $dir =="
3609 df -kP $dir; df -iP $dir
3610 local bused=$(getquota -p $projid global curspace)
3611 local iused=$(getquota -p $projid global curinodes)
3612 # note trailing space to match double printf from awk
3613 local expected="$blimit $bused $ilimit $iused "
3615 wait_update $HOSTNAME \
3616 "{ df -kP $dir; df -iP $dir; } |
3617 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3619 error "failed to get correct statfs for project quota"
3623 run_test 41 "df should return projid-specific values"
3626 ! is_project_quota_supported &&
3627 skip "Project quota is not supported"
3629 setup_quota_test || error "setup quota failed with $?"
3630 local dir1="$DIR/$tdir/dir1"
3631 local dir2="$DIR/$tdir/dir2"
3633 mkdir -p $dir1 && change_project -sp 1 $dir1
3634 mkdir -p $dir2 && change_project -sp 2 $dir2
3635 for num in $(seq 1 10); do
3636 touch $dir1/file_$num $dir2/file_$num
3637 ln -s $dir1/file_$num $dir1/file_$num"_link"
3638 ln -s $dir2/file_$num $dir2/file_$num"_link"
3641 count=$($LFS find --projid 1 $DIR | wc -l)
3642 [ "$count" != 21 ] && error "expected 21 but got $count"
3644 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3645 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3646 [ "$count" != 22 ] && error "expected 22 but got $count"
3651 run_test 50 "Test if lfs find --projid works"
3654 ! is_project_quota_supported &&
3655 skip "Project quota is not supported"
3656 setup_quota_test || error "setup quota failed with $?"
3657 local dir="$DIR/$tdir/dir"
3659 mkdir $dir && change_project -sp 1 $dir
3660 local used=$(getquota -p 1 global curinodes)
3661 [ $used != "1" ] && error "expected 1 got $used"
3666 used=$(getquota -p 1 global curinodes)
3667 [ $used != "4" ] && error "expected 4 got $used"
3669 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3671 cp $DIR/$tdir/6 $dir/6
3672 used=$(getquota -p 1 global curinodes)
3673 [ $used != "5" ] && error "expected 5 got $used"
3676 mv $DIR/$tdir/6 $dir/7
3677 used=$(getquota -p 1 global curinodes)
3678 [ $used != "6" ] && error "expected 6 got $used"
3683 run_test 51 "Test project accounting with mv/cp"
3686 ! is_project_quota_supported &&
3687 skip "Project quota is not supported"
3688 setup_quota_test || error "setup quota failed with $?"
3689 local dir="$DIR/$tdir/dir"
3690 mkdir $dir && change_project -sp 1 $dir
3692 touch $DIR/$tdir/file
3693 #Try renaming a file into the project. This should fail.
3694 for num in $(seq 1 2000); do
3695 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3696 error "rename should fail"
3701 run_test 52 "Rename across different project ID"
3704 ! is_project_quota_supported &&
3705 skip "Project quota is not supported"
3706 setup_quota_test || error "setup quota failed with $?"
3707 local dir="$DIR/$tdir/dir"
3708 mkdir $dir && change_project -s $dir
3709 lfs project -d $dir | grep P || error "inherit attribute should be set"
3711 change_project -C $dir
3712 lfs project -d $dir | grep P &&
3713 error "inherit attribute should be cleared"
3718 run_test 53 "Project inherit attribute could be cleared"
3721 ! is_project_quota_supported &&
3722 skip "Project quota is not supported"
3723 setup_quota_test || error "setup quota failed with $?"
3724 trap cleanup_quota_test EXIT
3725 local testfile="$DIR/$tdir/$tfile-0"
3727 #set project ID/inherit attribute
3728 change_project -sp $TSTPRJID $DIR/$tdir
3729 $RUNAS createmany -m ${testfile} 100 ||
3730 error "create many files failed"
3732 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3733 # one more count for directory itself */
3737 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3738 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3740 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3741 [ $proj_count1 -eq $proj_count ] ||
3742 error "c2: expected $proj_count got $proj_count1"
3744 #clear project but with kept projid
3745 change_project -rCk $DIR/$tdir
3746 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3747 [ $proj_count1 -eq 1 ] ||
3748 error "c3: expected 1 got $proj_count1"
3750 #verify projid untouched.
3751 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3753 [ $proj_count1 -eq $proj_count ] ||
3754 error "c4: expected $proj_count got $proj_count1"
3757 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3758 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3759 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3761 #this time clear all
3762 change_project -rC $DIR/$tdir
3763 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3764 [ $proj_count1 -eq 0 ] ||
3765 error "c6: expected 0 got $proj_count1"
3767 unlinkmany ${testfile} 100 ||
3768 error "unlink many files failed"
3772 run_test 54 "basic lfs project interface test"
3775 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3776 skip "Not supported before 2.10.58."
3777 setup_quota_test || error "setup quota failed with $?"
3779 set_ost_qtype $QTYPE || error "enable ost quota failed"
3782 #add second group to TSTUSR
3783 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3786 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3787 error "failed to dd"
3789 cancel_lru_locks osc
3790 sync; sync_all_data || true
3792 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3793 error "failed to setquota on group $TSTUSR2"
3795 $LFS quota -v -g $TSTUSR2 $DIR
3797 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3798 error "chgrp should failed with -EDQUOT"
3800 USED=$(getquota -g $TSTUSR2 global curspace)
3803 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3804 error "failed to setquota on group $TSTUSR2"
3806 $LFS quota -v -g $TSTUSR2 $DIR
3808 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3809 error "chgrp should succeed"
3811 $LFS quota -v -g $TSTUSR2 $DIR
3815 run_test 55 "Chgrp should be affected by group quota"
3818 setup_quota_test || error "setup quota failed with $?"
3820 set_ost_qtype $QTYPE || error "enable ost quota failed"
3823 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3824 erro "failed to set grace time for usr quota"
3825 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3826 awk '{print $4 $8}')
3827 if [ "x$grace_time" != "x10s;10s" ]; then
3828 $LFS quota -t -u $DIR
3829 error "expected grace time: 10s;10s, got:$grace_time"
3834 run_test 56 "lfs quota -t should work well"
3837 setup_quota_test || error "setup quota failed with $?"
3839 local dir="$DIR/$tdir/dir"
3842 #command can process further if it hit some errors
3843 $LFS project -sp 1 $dir/pipe
3844 touch $dir/aaa $dir/bbb
3845 mkdir $dir/subdir -p
3846 touch $dir/subdir/aaa $dir/subdir/bbb
3847 #create one invalid link file
3848 ln -s $dir/not_exist_file $dir/ccc
3849 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3850 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3854 run_test 57 "lfs project could tolerate errors"
3857 [ "$mds1_FSTYPE" != ldiskfs ] &&
3858 skip "ldiskfs only test"
3859 disable_project_quota
3860 setup_quota_test || error "setup quota failed with $?"
3863 local testfile="$DIR/$tdir/$tfile-0"
3864 #make sure it did not crash kernel
3865 touch $testfile && lfs project -sp 1 $testfile
3867 enable_project_quota
3870 run_test 59 "lfs project dosen't crash kernel with project disabled"
3873 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3874 skip "Needs MDS version 2.11.53 or later."
3875 setup_quota_test || error "setup quota failed with $?"
3876 trap cleanup_quota_test EXIT
3878 local testfile=$DIR/$tdir/$tfile
3881 set_mdt_qtype "ug" || error "enable mdt quota failed"
3883 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3884 error "set quota failed"
3885 quota_show_check a g $TSTUSR
3887 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3888 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3889 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3890 error "create many files failed"
3892 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3894 # root user can overrun quota
3895 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3896 error "root user should succeed"
3900 run_test 60 "Test quota for root with setgid"
3902 # test default quota
3903 test_default_quota() {
3904 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3905 skip "Not supported before 2.11.51."
3910 local qprjid=$TSTPRJID
3914 local LIMIT=20480 #20M disk space
3915 local TESTFILE="$DIR/$tdir/$tfile-0"
3918 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3919 echo "Project quota is not supported" && return 0
3921 [ $qtype == "-u" ] && qdtype="-U"
3922 [ $qtype == "-g" ] && qdtype="-G"
3923 [ $qtype == "-p" ] && {
3928 [ $qres_type == "meta" ] && {
3929 LIMIT=10240 #10K inodes
3934 qpool_cmd="--pool $3"
3935 # pool quotas don't work properly without global limit
3936 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3937 error "set global limit failed"
3940 setup_quota_test || error "setup quota failed with $?"
3941 stack_trap cleanup_quota_test EXIT
3945 # enable mdt/ost quota
3946 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3947 set_ost_qtype $QTYPE || error "enable ost quota failed"
3949 log "set to use default quota"
3950 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3951 error "set $qid to use default quota failed"
3953 log "set default quota"
3954 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3955 error "set $qid default quota failed"
3957 log "get default quota"
3958 $LFS quota $qdtype $DIR || error "get default quota failed"
3960 if [ $qres_type == "data" ]; then
3961 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
3962 grep "$MOUNT" | awk '{print $2}')
3963 [ $SLIMIT -eq $LIMIT ] ||
3964 error "the returned default quota is wrong"
3966 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3968 [ $SLIMIT -eq $LIMIT ] ||
3969 error "the returned default quota is wrong"
3972 # make sure the system is clean
3973 local USED=$(getquota $qtype $qid global curspace)
3974 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3976 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3977 error "setstripe $TESTFILE failed"
3978 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3980 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3982 log "Test not out of quota"
3983 if [ $qres_type == "data" ]; then
3984 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3985 quota_error $qtype $qid "write failed, expect succeed"
3987 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3988 quota_error $qtype $qid "create failed, expect succeed"
3990 unlinkmany $TESTFILE $((LIMIT/2))
3993 log "Test out of quota"
3994 # flush cache, ensure noquota flag is set on client
3995 cancel_lru_locks osc
3996 cancel_lru_locks mdc
3997 sync; sync_all_data || true
3998 if [ $qres_type == "data" ]; then
3999 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4000 quota_error $qtype $qid "write succeed, expect EDQUOT"
4002 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4003 quota_error $qtype $qid "create succeed, expect EDQUOT"
4005 unlinkmany $TESTFILE $((LIMIT*2))
4009 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4010 error "setstripe $TESTFILE failed"
4011 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4013 log "Increase default quota"
4015 # LU-4505: sleep 5 seconds to enable quota acquire
4018 # increase default quota
4019 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4020 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4022 cancel_lru_locks osc
4023 cancel_lru_locks mdc
4024 sync; sync_all_data || true
4025 if [ $qres_type == "data" ]; then
4026 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4027 quota_error $qtype $qid "write failed, expect succeed"
4029 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4030 quota_error $qtype $qid "create failed, expect succeed"
4032 unlinkmany $TESTFILE $((LIMIT*2))
4035 log "Set quota to override default quota"
4036 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4037 error "set $qid quota failed"
4039 cancel_lru_locks osc
4040 cancel_lru_locks mdc
4041 sync; sync_all_data || true
4042 if [ $qres_type == "data" ]; then
4043 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4044 quota_error $qtype $qid "write succeed, expect EQUOT"
4046 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4047 quota_error $qtype $qid "create succeed, expect EQUOT"
4049 unlinkmany $TESTFILE $((LIMIT*2))
4052 log "Set to use default quota again"
4054 # LU-4505: sleep 5 seconds to enable quota acquire
4057 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4058 error "set $qid to use default quota failed"
4060 cancel_lru_locks osc
4061 cancel_lru_locks mdc
4062 sync; sync_all_data || true
4063 if [ $qres_type == "data" ]; then
4064 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4065 quota_error $qtype $qid "write failed, expect succeed"
4067 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4068 quota_error $qtype $qid "create failed, expect succeed"
4070 unlinkmany $TESTFILE $((LIMIT*2))
4075 wait_delete_completed || error "wait_delete_completed failed"
4076 sync_all_data || true
4078 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4079 error "reset default quota failed"
4080 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4081 error "reset quota failed"
4087 test_default_quota "-u" "data"
4088 test_default_quota "-u" "meta"
4089 test_default_quota "-g" "data"
4090 test_default_quota "-g" "meta"
4091 test_default_quota "-p" "data"
4092 test_default_quota "-p" "meta"
4094 run_test 61 "default quota tests"
4097 ! is_project_quota_supported &&
4098 skip "Project quota is not supported"
4099 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4100 skip "chattr did not support project quota"
4101 setup_quota_test || error "setup quota failed with $?"
4102 local testdir=$DIR/$tdir/
4104 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4105 change_project -s $testdir
4106 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4107 error "inherit attribute should be set"
4108 # chattr used FS_IOC_SETFLAGS ioctl
4109 $RUNAS chattr -P $testdir &&
4110 error "regular user clear inherit should fail"
4111 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4112 error "inherit attribute should still be set"
4113 chattr -P $testdir || error "root failed to clear inherit"
4114 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4115 error "inherit attribute should be cleared"
4118 run_test 62 "Project inherit should be only changed by root"
4121 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4122 skip "Not supported before 2.11.55"
4126 local dd_failed=false
4127 local tdir_dom=${tdir}_dom
4128 local LIMIT=20480 #20M
4130 [ $qtype == "p" ] && ! is_project_quota_supported &&
4131 echo "Project quota is not supported" && return 0
4133 [ $qtype == "p" ] && qid=$TSTPRJID
4135 setup_quota_test || error "setup quota failed with $?"
4136 trap cleanup_quota_test EXIT
4140 # enable mdt/ost quota
4141 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4142 set_ost_qtype $QTYPE || error "enable ost quota failed"
4144 # make sure the system is clean
4145 local USED=$(getquota -$qtype $qid global curspace)
4146 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4148 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4150 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4151 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4152 error "setstripe $tdir_dom failed"
4153 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4155 [ $qtype == "p" ] && {
4156 change_project -sp $TSTPRJID $DIR/$tdir
4157 change_project -sp $TSTPRJID $DIR/$tdir_dom
4160 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4161 error "set $qid quota failed"
4163 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4164 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4168 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4170 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4171 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4175 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4177 rm -f $DIR/$tdir_dom/*
4179 # flush cache, ensure noquota flag is set on client
4180 cancel_lru_locks osc
4181 cancel_lru_locks mdc
4182 sync; sync_all_data || true
4186 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4187 quota_error $qtype $qid "write failed, expect succeed"
4189 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4190 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4194 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4197 rm -f $DIR/$tdir_dom/*
4199 # flush cache, ensure noquota flag is set on client
4200 cancel_lru_locks osc
4201 cancel_lru_locks mdc
4202 sync; sync_all_data || true
4206 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4207 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4211 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4213 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4214 quota_error $qtype $qid "write succeed, expect EDQUOT"
4217 rm -fr $DIR/$tdir_dom
4219 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4220 error "reset usr quota failed"
4230 run_test 63 "quota on DoM tests"
4233 ! is_project_quota_supported &&
4234 skip "Project quota is not supported"
4235 setup_quota_test || error "setup quota failed with $?"
4236 local dir1="$DIR/$tdir/"
4239 ln -s $dir1/file $dir1/file_link
4242 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4243 error "set project should succeed"
4245 used=$(getquota -p $TSTPRJID global curinodes)
4246 [ $used -eq 4 ] || error "expected 4 got $used"
4247 $LFS project -rC $dir1 >&/dev/null ||
4248 error "clear project should succeed"
4250 used=$(getquota -p $TSTPRJID global curinodes)
4251 [ $used -eq 0 ] || error "expected 0 got $used"
4255 run_test 64 "lfs project on non dir/files should succeed"
4259 local TESTFILE="$DIR/$tdir/$tfile-0"
4261 setup_quota_test || error "setup quota failed with $?"
4262 set_ost_qtype $QTYPE || error "enable ost quota failed"
4266 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4267 error "failed to write"
4268 # flush cache, ensure noquota flag is set on client
4269 cancel_lru_locks osc
4270 sync; sync_all_data || true
4272 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4273 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4274 local quota_all=$($RUNAS $LFS quota $DIR)
4276 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4277 error "usr quota not match"
4278 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4279 error "grp quota not match"
4285 run_test 65 "Check lfs quota result"
4288 ! is_project_quota_supported &&
4289 skip "Project quota is not supported"
4290 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4291 skip "Not supported before 2.12.4"
4292 setup_quota_test || error "setup quota failed with $?"
4293 stack_trap cleanup_quota_test EXIT
4294 local old=$(do_facet mds1 $LCTL get_param -n \
4295 mdt.*.enable_chprojid_gid | head -1)
4296 local testdir=$DIR/$tdir/foo
4298 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4299 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4302 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4303 chown -R $TSTID:$TSTID $testdir
4304 change_project -sp $TSTPRJID $testdir
4305 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4307 $RUNAS lfs project -p 0 $testdir/foo &&
4308 error "nonroot user should fail to set projid"
4310 $RUNAS lfs project -C $testdir/foo &&
4311 error "nonroot user should fail to clear projid"
4313 change_project -C $testdir/foo || error "failed to clear project"
4315 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4316 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4317 "failed to set projid with normal user when enable_chprojid_gid=-1"
4319 $RUNAS lfs project -rC $testdir/ || error \
4320 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4322 touch $testdir/bar || error "failed touch $testdir/bar"
4323 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4324 "normal user should not be able to set projid on root owned file"
4326 change_project -p $TSTPRJID $testdir/bar || error \
4327 "root should be able to change its own file's projid"
4331 run_test 66 "nonroot user can not change project state in default"
4338 local short_qtype=${qtype:0:1}
4341 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4343 quota_usr) _runas=$RUNAS;;
4344 quota_2usr) _runas=$RUNAS2;;
4345 *) error "unknown quota parameter $4";;
4350 $_runas $DD of=$file count=$size ||
4351 quota_error $short_qtype $TSTUSR \
4352 "$qtype write failure, but expect success"
4354 cancel_lru_locks osc
4356 sync; sync_all_data || true
4365 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4367 do_facet mds1 $LCTL get_param $param |
4368 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4373 local testfile="$DIR/$tdir/$tfile-0"
4374 local testfile2="$DIR/$tdir/$tfile-1"
4375 local testfile3="$DIR/$tdir/$tfile-2"
4376 local qpool="qpool1"
4382 [ "$ost1_FSTYPE" == zfs ] &&
4383 skip "ZFS grants some block space together with inode"
4385 setup_quota_test || error "setup quota failed with $?"
4386 trap cleanup_quota_test EXIT
4389 set_ost_qtype $QTYPE || error "enable ost quota failed"
4392 log "User quota (block hardlimit:$limit MB)"
4393 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4394 error "set user quota failed"
4396 # make sure the system is clean
4397 used=$(getquota -u $TSTUSR global curspace)
4398 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4400 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4401 echo "granted 0x0 before write $granted"
4403 # trigger reintegration
4404 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4405 procf=${procf}quota_slave.force_reint
4406 do_facet ost1 $LCTL set_param $procf=1 ||
4407 error "force reintegration failed"
4408 wait_ost_reint "u" || error "reintegration failed"
4409 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4410 [ $granted -ne 0 ] &&
4411 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4413 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4414 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4416 # write 10 MB to testfile
4417 test_67_write "$testfile" "user" 10 "quota_usr"
4419 # create qpool and add OST1
4420 pool_add $qpool || error "pool_add failed"
4421 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4422 # as quota_usr hasn't limits, lqe may absent. But it should be
4423 # created after the 1st direct qmt_get.
4424 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4426 # check granted - should be 0, as testfile is located only on OST0
4427 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4428 echo "global granted $granted"
4429 granted=$(getgranted $qpool "dt" $TSTID "usr")
4430 echo "$qpool granted $granted"
4431 [ $granted -ne 0 ] &&
4432 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4434 # add OST0 to qpool and check granted space
4435 pool_add_targets $qpool 0 1 ||
4436 error "pool_add_targets failed"
4437 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4438 echo "Granted $granted_mb MB"
4439 #should be 10M + qunit for each OST
4440 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4441 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4443 $LFS setstripe $testfile2 -c 1 -i 1 ||
4444 error "setstripe $testfile2 failed"
4445 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4446 # Write from another user and check that qpool1
4447 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4448 test_67_write "$testfile2" "user" 10 "quota_2usr"
4449 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4450 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4451 [ $granted -ne 0 ] &&
4452 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4454 # Granted space for quota_2usr in qpool1 should appear only
4455 # when global lqe for this user becomes enforced.
4456 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4457 error "set user quota failed"
4458 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4459 echo "granted_mb $granted_mb"
4460 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4461 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4463 $LFS setstripe $testfile3 -c 1 -i 0 ||
4464 error "setstripe $testfile3 failed"
4465 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4466 test_67_write "$testfile3" "user" 10 "quota_2usr"
4467 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4468 echo "$testfile3 granted_mb $granted_mb"
4469 [ $granted_mb -eq $limit ] ||
4470 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4472 # remove OST1 from the qpool1 and check granted space
4473 # should be 0 for TSTUSR and 10M for TSTUSR2
4474 pool_remove_target $qpool 0
4475 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4476 [ $granted_mb -eq 0 ] ||
4477 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4478 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4479 [ $granted_mb -eq 10 ] ||
4480 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4483 wait_delete_completed || error "wait_delete_completed failed"
4484 sync_all_data || true
4485 used=$(getquota -u $TSTUSR global curspace)
4486 [ $used -ne 0 ] && quota_error u $TSTUSR \
4487 "user quota isn't released after deletion"
4488 resetquota -u $TSTUSR
4492 run_test 67 "quota pools recalculation"
4499 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4500 awk '/usr/ {getline; print $2}'
4505 local qpool="qpool1"
4508 setup_quota_test || error "setup quota failed with $?"
4509 stack_trap cleanup_quota_test EXIT
4512 set_ost_qtype $QTYPE || error "enable ost quota failed"
4514 # check slave number for glbal pool
4515 local nr=$(get_slave_nr "0x0" "usr")
4516 echo "nr result $nr"
4517 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4518 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4520 # create qpool and add OST1
4521 pool_add $qpool || error "pool_add failed"
4522 nr=$(get_slave_nr $qpool "usr")
4523 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4526 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4527 nr=$(get_slave_nr $qpool "usr")
4528 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4531 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4532 nr=$(get_slave_nr $qpool "usr")
4533 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4536 pool_remove_target $qpool 0
4537 nr=$(get_slave_nr $qpool "usr")
4538 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4541 pool_remove_target $qpool 1
4542 nr=$(get_slave_nr $qpool "usr")
4543 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4545 # Check again that all is fine with global pool
4546 nr=$(get_slave_nr "0x0" "usr")
4547 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4548 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4552 run_test 68 "slave number in quota pool changed after each add/remove OST"
4556 local global_limit=200 # MB
4558 local testfile="$DIR/$tdir/$tfile-0"
4559 local dom0="$DIR/$tdir/dom0"
4560 local qpool="qpool1"
4563 setup_quota_test || error "setup quota failed with $?"
4564 stack_trap cleanup_quota_test EXIT
4567 set_ost_qtype $QTYPE || error "enable ost quota failed"
4568 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4570 # Save DOM only at MDT0
4571 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4572 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4574 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4576 # create qpool and add OST0
4577 pool_add $qpool || error "pool_add failed"
4578 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4580 log "User quota (block hardlimit:$global_limit MB)"
4581 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4582 error "set user quota failed"
4584 log "User quota (block hardlimit:$limit MB)"
4585 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4586 error "set user quota failed"
4588 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4589 quota_error u $TSTUSR "write failed"
4591 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4592 oflag=sync || quota_error u $TSTUSR "write failed"
4594 $RUNAS $DD of=$testfile count=$limit || true
4596 # flush cache, ensure noquota flag is set on client
4597 cancel_lru_locks osc
4598 sync; sync_all_data || true
4600 # MDT0 shouldn't get EDQUOT with glimpse.
4601 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4602 quota_error u $TSTUSR \
4603 "user write success, but expect EDQUOT"
4605 # Now all members of qpool1 should get EDQUOT. Expect success
4606 # when write to DOM on MDT0, as it belongs to global pool.
4607 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4608 oflag=sync || quota_error u $TSTUSR "write failed"
4610 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4611 oflag=sync || quota_error u $TSTUSR "write failed"
4615 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4619 local qpool="qpool1"
4624 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4625 skip "Needs a client >= $VERSION_WITH_QP"
4627 setup_quota_test || error "setup quota failed with $?"
4628 stack_trap cleanup_quota_test EXIT
4630 # MDS returns EFAULT for unsupported quotactl command
4631 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4633 # create qpool and add OST0
4634 pool_add $qpool || error "pool_add failed"
4635 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4637 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4639 [ $rc -eq $err ] || error "setquota res $rc != $err"
4641 # If MDS supports QP, check that limit was set properly.
4642 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4643 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4644 echo "hard limit $bhard limit $limit"
4645 [ $bhard -ne $((limit*1024)) ] &&
4646 error "bhard:$bhard for $qpool!=$((limit*1024))"
4649 $LFS quota -u $TSTUSR --pool $qpool $DIR
4651 [ $rc -eq $err ] || error "quota res $rc != $err"
4655 run_test 70 "check lfs setquota/quota with a pool option"
4660 local global_limit=100 # MB
4661 local testfile="$DIR/$tdir/$tfile-0"
4662 local qpool="qpool1"
4663 local qpool2="qpool2"
4665 [ "$ost1_FSTYPE" == zfs ] &&
4666 skip "ZFS grants some block space together with inode"
4667 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4669 setup_quota_test || error "setup quota failed with $?"
4670 stack_trap cleanup_quota_test EXIT
4673 set_ost_qtype $QTYPE || error "enable ost quota failed"
4676 log "User quota (block hardlimit:$global_limit MB)"
4677 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4678 error "set user quota failed"
4680 pool_add $qpool || error "pool_add failed"
4681 pool_add_targets $qpool 0 1 ||
4682 error "pool_add_targets failed"
4684 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4685 error "set user quota failed"
4687 pool_add $qpool2 || error "pool_add failed"
4688 pool_add_targets $qpool2 1 1 ||
4689 error "pool_add_targets failed"
4691 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4692 error "set user quota failed"
4694 # make sure the system is clean
4695 local used=$(getquota -u $TSTUSR global curspace)
4698 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4700 # create 1st component 1-10M
4701 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4702 #create 2nd component 10-30M
4703 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4704 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4706 # сheck normal use and out of quota with PFL
4707 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4708 test_1_check_write $testfile "user" $((limit*2))
4710 wait_delete_completed || error "wait_delete_completed failed"
4711 sync_all_data || true
4712 used=$(getquota -u $TSTUSR global curspace)
4713 [ $used -ne 0 ] && quota_error u $TSTUSR \
4714 "user quota isn't released after deletion"
4716 # create 1st component 1-10M
4717 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4718 # create 2nd component 10-30M
4719 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4720 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4722 # write to the 2nd component
4723 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4724 quota_error u $TSTUSR \
4725 "write failure, but expect success"
4726 # this time maybe cache write, ignore it's failure
4727 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4728 cancel_lru_locks osc
4729 sync; sync_all_data || true
4730 # write over limit in qpool2(2nd component 10-30M)
4731 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4732 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4733 # write to the 1st component - OST0 is empty
4734 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4735 quota_error u $TSTUSR "write failed"
4739 run_test 71a "Check PFL with quota pools"
4743 local global_limit=1000 # MB
4744 local limit1=160 # MB
4745 local limit2=10 # MB
4746 local testfile="$DIR/$tdir/$tfile-0"
4747 local qpool="qpool1"
4748 local qpool2="qpool2"
4750 [ "$ost1_FSTYPE" == zfs ] &&
4751 skip "ZFS grants some block space together with inode"
4752 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4754 setup_quota_test || error "setup quota failed with $?"
4755 stack_trap cleanup_quota_test EXIT
4758 set_ost_qtype $QTYPE || error "enable ost quota failed"
4761 log "User quota (block hardlimit:$global_limit MB)"
4762 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4763 error "set user quota failed"
4765 pool_add $qpool || error "pool_add failed"
4766 pool_add_targets $qpool 0 1 ||
4767 error "pool_add_targets failed"
4769 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4770 error "set user quota failed"
4772 pool_add $qpool2 || error "pool_add failed"
4773 pool_add_targets $qpool2 1 1 ||
4774 error "pool_add_targets failed"
4776 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4777 error "set user quota failed"
4779 # make sure the system is clean
4780 local used=$(getquota -u $TSTUSR global curspace)
4783 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4785 # First component is on OST0, 2nd on OST1
4786 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4787 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4789 # fill the 1st component on OST0
4790 $RUNAS $DD of=$testfile count=128 ||
4791 quota_error u $TSTUSR "write failed"
4792 # write to the 2nd cmpnt on OST1
4793 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4794 quota_error u $TSTUSR "write failed"
4795 # this time maybe cache write, ignore it's failure
4796 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4798 cancel_lru_locks osc
4799 sync; sync_all_data || true
4800 # write over limit in qpool2
4801 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4802 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4806 run_test 71b "Check SEL with quota pools"
4811 local global_limit=50 # MB
4812 local testfile="$DIR/$tdir/$tfile-0"
4813 local qpool="qpool1"
4816 setup_quota_test || error "setup quota failed with $?"
4817 stack_trap cleanup_quota_test EXIT
4820 set_ost_qtype $QTYPE || error "enable ost quota failed"
4823 log "User quota (block hardlimit:$global_limit MB)"
4824 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4825 error "set user quota failed"
4827 pool_add $qpool || error "pool_add failed"
4828 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4830 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4831 error "set user quota failed"
4833 # make sure the system is clean
4834 local used=$(getquota -u $TSTUSR global curspace)
4836 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4838 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4840 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4841 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4842 test_1_check_write $testfile "user" $limit
4843 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4845 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4846 # check that lfs quota -uv --pool prints only OST that
4847 # was added in a pool
4848 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4849 grep "OST\|MDT" && error "$qpool consists wrong targets"
4853 run_test 72 "lfs quota --pool prints only pool's OSTs"
4857 local qpool="qpool1"
4861 pool_add $qpool || error "pool_add failed"
4862 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4863 error "pool_add_targets failed"
4865 test_default_quota "-u" "data" "qpool1"
4867 run_test 73 "default limits at OST Pool Quotas"
4871 local global_limit=200 # 200M
4872 local limit=10 # 10M
4873 local limit2=50 # 50M
4874 local qpool="qpool1"
4875 local qpool2="qpool2"
4879 setup_quota_test || error "setup quota failed with $?"
4880 stack_trap cleanup_quota_test EXIT
4883 set_ost_qtype $QTYPE || error "enable ost quota failed"
4885 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4886 error "set user quota failed"
4888 pool_add $qpool || error "pool_add failed"
4889 pool_add_targets $qpool 0 1 ||
4890 error "pool_add_targets failed"
4892 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4893 error "set user quota failed"
4895 pool_add $qpool2 || error "pool_add failed"
4896 pool_add_targets $qpool2 1 1 ||
4897 error "pool_add_targets failed"
4899 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4900 error "set user quota failed"
4902 tmp=$(getquota -u $TSTUSR global bhardlimit)
4903 [ $tmp -eq $((global_limit * 1024)) ] ||
4904 error "wrong global limit $global_limit"
4906 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4907 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4909 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
4910 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
4912 # check limits in pools
4913 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4914 grep -A4 $qpool | awk 'NR == 4{print $4}')
4915 echo "pool limit for $qpool $tmp"
4916 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
4917 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4918 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
4919 echo "pool limit for $qpool2 $tmp"
4920 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
4922 run_test 74 "check quota pools per user"
4926 do_nodes $(comma_list $(nodes_list)) \
4927 "lctl set_param -n debug=-quota,trace"
4928 if $PQ_CLEANUP; then
4929 disable_project_quota
4932 reset_quota_settings
4937 check_and_cleanup_lustre
4938 export QUOTA_AUTO=$QUOTA_AUTO_OLD