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:
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 VERSION_WITH_QP="2.13.53"
44 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
45 skip "Needs MDS version $VERSION_WITH_QP or later."
48 require_dsh_mds || exit 0
49 require_dsh_ost || exit 0
51 # Does e2fsprogs support quota feature?
52 if [ "$mds1_FSTYPE" == ldiskfs ] &&
53 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
54 grep -q 'quota'"; then
55 skip_env "e2fsprogs doesn't support quota"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 QUOTA_AUTO_OLD=$QUOTA_AUTO
68 check_and_setup_lustre
70 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
77 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
78 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
79 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
99 lfs project $* || error "lfs project $* failed"
102 RUNAS="runas -u $TSTID -g $TSTID"
103 RUNAS2="runas -u $TSTID2 -g $TSTID2"
104 DD="dd if=/dev/zero bs=1M"
108 # clear quota limits for a user or a group
109 # usage: resetquota -u username
110 # resetquota -g groupname
111 # resetquota -p projid
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 if [ $1 == "-p" ]; then
119 is_project_quota_supported || return 0
122 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
123 error "clear quota for [type:$1 name:$2] failed"
124 # give a chance to slave to release space
132 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
133 $LFS quota -v -u $local_id $DIR
134 log "Files for user ($local_id):"
135 ($LFS find --user $local_id $DIR | head -n 4 |
136 xargs stat 2>/dev/null)
139 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
140 $LFS quota -v -g $local_id $DIR
141 log "Files for group ($local_id):"
142 ($LFS find --group $local_id $DIR | head -n 4 |
143 xargs stat 2>/dev/null)
146 is_project_quota_supported || return 0
147 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
148 $LFS quota -v -p $TSTPRJID $DIR
149 log "Files for project ($TSTPRJID):"
150 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
151 xargs stat 2>/dev/null)
167 # get quota for a user or a group
168 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
169 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
176 sync_all_data > /dev/null 2>&1 || true
178 [ "$#" != 4 -a "$#" != 5 ] &&
179 error "getquota: wrong number of arguments: $#"
180 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
181 error "getquota: wrong u/g/p specifier $1 passed"
194 *) error "unknown quota parameter $4";;
197 [ ! -z "$5" ] && pool_arg="--pool $5 "
198 [ "$uuid" = "global" ] && uuid=$DIR
200 $LFS quota -v "$1" "$2" $pool_arg $DIR |
201 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
202 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
207 # usage: set_mdt_qtype ugp|u|g|p|none
211 local mdts=$(get_facets MDS)
213 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
214 qtype=$(tr -d 'p' <<<$qtype)
216 if [[ $PERM_CMD == *"set_param -P"* ]]; then
217 do_facet mgs $PERM_CMD \
218 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
220 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
222 # we have to make sure each MDT received config changes
223 for mdt in ${mdts//,/ }; do
225 cmd="$LCTL get_param -n "
226 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
227 cmd=${cmd}.quota_slave.enabled
229 if $(facet_up $mdt); then
230 wait_update_facet $mdt "$cmd" "$qtype" || return 1
237 # usage: set_ost_qtype ugp|u|g|p|none
241 local osts=$(get_facets OST)
243 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
244 qtype=$(tr -d 'p' <<<$qtype)
246 if [[ $PERM_CMD == *"set_param -P"* ]]; then
247 do_facet mgs $PERM_CMD \
248 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
250 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
252 # we have to make sure each OST received config changes
253 for ost in ${osts//,/ }; do
255 cmd="$LCTL get_param -n "
256 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
257 cmd=${cmd}.quota_slave.enabled
259 if $(facet_up $ost); then
260 wait_update_facet $ost "$cmd" "$qtype" || return 1
266 wait_reintegration() {
270 local result="glb[1],slv[1],reint[0]"
275 if [ $ntype == "mdt" ]; then
276 tgts=$(get_facets MDS)
278 tgts=$(get_facets OST)
281 for tgt in ${tgts//,/ }; do
283 cmd="$LCTL get_param -n "
284 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
285 cmd=${cmd}.quota_slave.info
287 if $(facet_up $tgt); then
288 wait_update_facet $tgt "$cmd |
289 grep "$qtype" | awk '{ print \\\$3 }'" \
290 "$result" $max || return 1
300 if [[ "$qtype" =~ "u" ]]; then
301 wait_reintegration "mdt" "user" $max || return 1
304 if [[ "$qtype" =~ "g" ]]; then
305 wait_reintegration "mdt" "group" $max || return 1
308 if [[ "$qtype" =~ "p" ]]; then
309 ! is_project_quota_supported && return 0
310 wait_reintegration "mdt" "project" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "ost" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "ost" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "ost" "project" $max || return 1
338 local extrasleep=${4:-5}
345 *) error "get_grace_time: Invalid quota type: $qtype"
350 echo "Quota info for $pool:"
351 $LFS quota -$qtype $qarg $parg $DIR
356 time=$(lfs quota -$qtype $qarg $parg $DIR|
357 awk 'NR == 3{ print $5 }')
360 time=$(lfs quota -$qtype $qarg $DIR|
361 awk 'NR == 3{ print $9 }')
364 error "Unknown quota type: $flavour"
368 local sleep_seconds=0
369 local orig_time=$time
371 echo "Grace time is $time"
372 # from lfs.c:__sec2str()
373 # const char spec[] = "smhdw";
374 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
375 [[ $time == *w* ]] && w_time=${time%w*} &&
376 let sleep_seconds+=$((w_time*7*24*60*60));
378 [[ $time == *d* ]] && d_time=${time%d*} &&
379 let sleep_seconds+=$((d_time*24*60*60));
381 [[ $time == *h* ]] && h_time=${time%h*} &&
382 let sleep_seconds+=$((h_time*60*60));
384 [[ $time == *m* ]] && m_time=${time%m*} &&
385 let sleep_seconds+=$((m_time*60));
387 [[ $time == *s* ]] && s_time=${time%s*} &&
388 let sleep_seconds+=$s_time
390 echo "Sleep through grace ..."
391 [ "$orig_time" == "-" ] &&
392 error "Grace timeout was not set or quota not exceeded"
393 if [ "$orig_time" == "none" ]; then
394 echo "...Grace timeout already expired"
396 let sleep_seconds+=$extrasleep
397 echo "...sleep $sleep_seconds seconds"
403 wait_delete_completed
404 echo "Creating test directory"
405 mkdir_on_mdt0 $DIR/$tdir || return 1
406 chmod 0777 $DIR/$tdir || return 2
407 # always clear fail_loc in case of fail_loc isn't cleared
408 # properly when previous test failed
409 lustre_fail mds_ost 0
410 stack_trap cleanup_quota_test EXIT
413 cleanup_quota_test() {
414 echo "Delete files..."
416 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
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 $?"
538 set_ost_qtype "none" || error "disable ost quota failed"
539 test_quota_performance $MB
541 set_ost_qtype $QTYPE || error "enable ost quota failed"
542 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
543 error "set quota failed"
544 test_quota_performance $MB
546 run_test 0 "Test basic quota performance"
548 # usage: test_1_check_write tfile user|group|project
549 test_1_check_write() {
553 local short_qtype=${qtype:0:1}
556 $RUNAS $DD of=$testfile count=$((limit/2)) ||
557 quota_error $short_qtype $TSTUSR \
558 "$qtype write failure, but expect success"
559 log "Write out of block quota ..."
560 # this time maybe cache write, ignore it's failure
561 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
562 # flush cache, ensure noquota flag is set on client
564 sync; sync_all_data || true
565 # sync means client wrote all it's cache, but id doesn't
566 # guarantee that slave received new edquot through glimpse.
567 # so wait a little to be sure slave got it.
569 $RUNAS $DD of=$testfile count=1 seek=$limit &&
570 quota_error $short_qtype $TSTUSR \
571 "user write success, but expect EDQUOT"
575 check_write_fallocate() {
579 local short_qtype=${qtype:0:1}
582 log "Write ${count}MiB Using Fallocate"
583 $RUNAS fallocate -l${count}MiB $testfile ||
584 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
587 sync; sync_all_data || true
591 log "Write ${count}MiB Using Fallocate"
592 $RUNAS fallocate -l${count}MiB $testfile &&
593 quota_error $short_qtype $TSTUSR \
594 "Write success, expect EDQUOT" || true
597 # test block hardlimit
600 local testfile="$DIR/$tdir/$tfile-0"
602 setup_quota_test || error "setup quota failed with $?"
605 set_ost_qtype $QTYPE || error "enable ost quota failed"
608 log "User quota (block hardlimit:$limit MB)"
609 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
610 error "set user quota failed"
612 # make sure the system is clean
613 local used=$(getquota -u $TSTUSR global curspace)
614 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
616 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
617 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
619 test_1_check_write $testfile "user" $limit
622 wait_delete_completed || error "wait_delete_completed failed"
623 sync_all_data || true
624 used=$(getquota -u $TSTUSR global curspace)
625 [ $used -ne 0 ] && quota_error u $TSTUSR \
626 "user quota isn't released after deletion"
627 resetquota -u $TSTUSR
630 log "--------------------------------------"
631 log "Group quota (block hardlimit:$limit MB)"
632 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
633 error "set group quota failed"
635 testfile="$DIR/$tdir/$tfile-1"
636 # make sure the system is clean
637 used=$(getquota -g $TSTUSR global curspace)
638 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
640 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
641 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
643 test_1_check_write $testfile "group" $limit
645 wait_delete_completed || error "wait_delete_completed failed"
646 sync_all_data || true
647 used=$(getquota -g $TSTUSR global curspace)
648 [ $used -ne 0 ] && quota_error g $TSTUSR \
649 "Group quota isn't released after deletion"
650 resetquota -g $TSTUSR
652 if ! is_project_quota_supported; then
653 echo "Project quota is not supported"
657 testfile="$DIR/$tdir/$tfile-2"
658 # make sure the system is clean
659 used=$(getquota -p $TSTPRJID global curspace)
661 error "used space($used) for project $TSTPRJID isn't 0"
664 log "--------------------------------------"
665 log "Project quota (block hardlimit:$limit mb)"
666 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
667 error "set project quota failed"
669 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
670 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
671 change_project -p $TSTPRJID $testfile
673 test_1_check_write $testfile "project" $limit
678 used=$(getquota -p $TSTPRJID global curspace)
679 [ $used -ne 0 ] && quota_error p $TSTPRJID \
680 "project quota isn't released after deletion"
682 resetquota -p $TSTPRJID
684 run_test 1a "Block hard limit (normal use and out of quota)"
688 local global_limit=20 # MB
689 local testfile="$DIR/$tdir/$tfile-0"
693 setup_quota_test || error "setup quota failed with $?"
696 set_ost_qtype $QTYPE || error "enable ost quota failed"
699 log "User quota (block hardlimit:$global_limit MB)"
700 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
701 error "set user quota failed"
703 pool_add $qpool || error "pool_add failed"
704 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
705 error "pool_add_targets failed"
707 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
708 error "set user quota failed"
710 # make sure the system is clean
711 local used=$(getquota -u $TSTUSR global curspace)
713 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
715 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
717 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
718 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
720 test_1_check_write $testfile "user" $limit
723 wait_delete_completed || error "wait_delete_completed failed"
724 sync_all_data || true
725 used=$(getquota -u $TSTUSR global curspace $qpool)
726 [ $used -ne 0 ] && quota_error u $TSTUSR \
727 "user quota isn't released after deletion"
728 resetquota -u $TSTUSR
731 log "--------------------------------------"
732 log "Group quota (block hardlimit:$global_limit MB)"
733 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
734 error "set group quota failed"
736 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
737 error "set group quota failed"
739 testfile="$DIR/$tdir/$tfile-1"
740 # make sure the system is clean
741 used=$(getquota -g $TSTUSR global curspace $qpool)
742 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
744 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
745 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
747 test_1_check_write $testfile "group" $limit
750 wait_delete_completed || error "wait_delete_completed failed"
751 sync_all_data || true
752 used=$(getquota -g $TSTUSR global curspace $qpool)
753 [ $used -ne 0 ] && quota_error g $TSTUSR \
754 "Group quota isn't released after deletion"
755 resetquota -g $TSTUSR
757 if ! is_project_quota_supported; then
758 echo "Project quota is not supported"
762 testfile="$DIR/$tdir/$tfile-2"
763 # make sure the system is clean
764 used=$(getquota -p $TSTPRJID global curspace $qpool)
766 error "used space($used) for project $TSTPRJID isn't 0"
769 log "--------------------------------------"
770 log "Project quota (block hardlimit:$global_limit mb)"
771 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
772 error "set project quota failed"
774 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
775 error "set project quota failed"
778 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
779 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
780 change_project -p $TSTPRJID $testfile
782 test_1_check_write $testfile "project" $limit
787 used=$(getquota -p $TSTPRJID global curspace)
788 [ $used -eq 0 ] || quota_error p $TSTPRJID \
789 "project quota isn't released after deletion"
791 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
794 local global_limit=20 # MB
795 local testfile="$DIR/$tdir/$tfile-0"
796 local qpool1="qpool1"
797 local qpool2="qpool2"
800 setup_quota_test || error "setup quota failed with $?"
803 set_ost_qtype $QTYPE || error "enable ost quota failed"
806 log "User quota (block hardlimit:$global_limit MB)"
807 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
808 error "set user quota failed"
810 pool_add $qpool1 || error "pool_add failed"
811 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
812 error "pool_add_targets failed"
814 pool_add $qpool2 || error "pool_add failed"
815 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
816 error "pool_add_targets failed"
818 # create pools without hard limit
819 # initially such case raised several bugs
820 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
821 error "set user quota failed"
823 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
824 error "set user quota failed"
826 # make sure the system is clean
827 local used=$(getquota -u $TSTUSR global curspace)
829 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
831 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
833 test_1_check_write $testfile "user" $global_limit
835 used=$(getquota -u $TSTUSR global curspace $qpool1)
836 echo "qpool1 used $used"
837 used=$(getquota -u $TSTUSR global curspace $qpool2)
838 echo "qpool2 used $used"
841 wait_delete_completed || error "wait_delete_completed failed"
842 sync_all_data || true
844 used=$(getquota -u $TSTUSR global curspace $qpool1)
845 [ $used -eq 0 ] || quota_error u $TSTUSR \
846 "user quota isn't released after deletion"
848 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
853 local global_limit=20 # MB
854 local testfile="$DIR/$tdir/$tfile-0"
855 local qpool1="qpool1"
856 local qpool2="qpool2"
859 setup_quota_test || error "setup quota failed with $?"
862 set_ost_qtype $QTYPE || error "enable ost quota failed"
865 log "User quota (block hardlimit:$global_limit MB)"
866 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
867 error "set user quota failed"
869 pool_add $qpool1 || error "pool_add failed"
870 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
871 error "pool_add_targets failed"
873 pool_add $qpool2 || error "pool_add failed"
874 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
875 error "pool_add_targets failed"
877 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
878 error "set user quota failed"
880 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
881 error "set user quota failed"
883 # make sure the system is clean
884 local used=$(getquota -u $TSTUSR global curspace)
886 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
888 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
890 test_1_check_write $testfile "user" $limit1
892 used=$(getquota -u $TSTUSR global curspace $qpool1)
893 echo "qpool1 used $used"
894 used=$(getquota -u $TSTUSR global curspace $qpool2)
895 echo "qpool2 used $used"
898 wait_delete_completed || error "wait_delete_completed failed"
899 sync_all_data || true
901 used=$(getquota -u $TSTUSR global curspace $qpool1)
902 [ $used -eq 0 ] || quota_error u $TSTUSR \
903 "user quota isn't released after deletion"
905 run_test 1d "Quota pools: check block hardlimit on different pools"
909 local global_limit=53000000 # MB
910 local testfile="$DIR/$tdir/$tfile-0"
911 local testfile2="$DIR/$tdir/$tfile-1"
912 local qpool1="qpool1"
915 setup_quota_test || error "setup quota failed with $?"
918 set_ost_qtype $QTYPE || error "enable ost quota failed"
920 # global_limit is much greater than limit1 to get
921 # different qunit's on osts. Since 1st qunit shrinking
922 # on OST1(that belongs to qpool1), this qunit should
924 log "User quota (block hardlimit:$global_limit MB)"
925 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
926 error "set user quota failed"
928 pool_add $qpool1 || error "pool_add failed"
929 pool_add_targets $qpool1 1 1 ||
930 error "pool_add_targets failed"
932 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
933 error "set user quota failed"
935 # make sure the system is clean
936 local used=$(getquota -u $TSTUSR global curspace)
937 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
939 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
940 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
942 test_1_check_write $testfile "user" $limit1
944 $LFS setstripe $testfile2 -c 1 -i 0 ||
945 error "setstripe $testfile2 failed"
946 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
947 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
949 $RUNAS $DD of=$testfile2 count=20 ||
950 quota_error u $TSTUSR \
951 "$qtype write failure, but expect success"
955 wait_delete_completed || error "wait_delete_completed failed"
956 sync_all_data || true
958 used=$(getquota -u $TSTUSR global curspace $qpool1)
959 [ $used -eq 0 ] || quota_error u $TSTUSR \
960 "user quota isn't released after deletion"
962 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
965 local global_limit=200 # MB
967 local TESTDIR="$DIR/$tdir/"
968 local testfile="$TESTDIR/$tfile-0"
969 local qpool1="qpool1"
972 setup_quota_test || error "setup quota failed with $?"
975 set_ost_qtype $QTYPE || error "enable ost quota failed"
977 log "User quota (block hardlimit:$global_limit MB)"
978 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
979 error "set user quota failed"
981 pool_add $qpool1 || error "pool_add failed"
982 pool_add_targets $qpool1 0 0 ||
983 error "pool_add_targets failed"
985 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
986 error "set user quota failed"
988 # make sure the system is clean
989 local used=$(getquota -u $TSTUSR global curspace)
990 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
992 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
994 test_1_check_write $testfile "user" $limit1
996 pool_remove_target $qpool1 0
998 wait_delete_completed || error "wait_delete_completed failed"
999 sync_all_data || true
1001 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1002 # qunit for appropriate element in lgd array should be set
1003 # correctly(4096). Earlier it was not changed continuing to be 1024.
1004 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1005 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1006 # as it already was 1024. As flag "need_update" for this qunit was
1007 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1008 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1009 # became > 10M. QMT returned EINPROGRESS in a loop.
1010 # Check that it doesn't hung anymore.
1011 test_1_check_write $testfile "user" $limit1
1013 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1017 local global_limit=40 # MB
1018 local testfile="$DIR/$tdir/$tfile-0"
1019 local qpool="qpool1"
1020 local mdmb_param="osc.*.max_dirty_mb"
1021 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1024 setup_quota_test || error "setup quota failed with $?"
1025 $LCTL set_param $mdmb_param=1
1026 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1029 set_ost_qtype $QTYPE || error "enable ost quota failed"
1032 log "User quota (block hardlimit:$global_limit MB)"
1033 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1034 error "set user quota failed"
1036 pool_add $qpool || error "pool_add failed"
1037 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1038 error "pool_add_targets failed"
1040 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1041 error "set user quota failed"
1043 # make sure the system is clean
1044 local used=$(getquota -u $TSTUSR global curspace)
1046 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1048 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1049 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1052 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1053 quota_error u $TSTUSR \
1054 "$qtype write failure, but expect success"
1055 log "Write out of block quota ..."
1056 # this time maybe cache write, ignore it's failure
1057 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1058 # flush cache, ensure noquota flag is set on client
1059 cancel_lru_locks osc
1060 sync; sync_all_data || true
1062 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1063 quota_error u $TSTUSR \
1064 "user write success, but expect EDQUOT"
1067 wait_delete_completed || error "wait_delete_completed failed"
1068 sync_all_data || true
1070 used=$(getquota -u $TSTUSR global curspace $qpool)
1071 [ $used -ne 0 ] && quota_error u $TSTUSR \
1072 "user quota isn't released after deletion"
1075 run_test 1g "Quota pools: Block hard limit with wide striping"
1079 local testfile="$DIR/$tdir/$tfile-0"
1081 check_set_fallocate_or_skip
1083 setup_quota_test || error "setup quota failed with $?"
1086 set_ost_qtype $QTYPE || error "enable ost quota failed"
1089 log "User quota (block hardlimit:$limit MB)"
1090 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1091 error "set user quota failed"
1093 # make sure the system is clean
1094 local used=$(getquota -u $TSTUSR global curspace)
1095 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1097 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1098 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1100 check_write_fallocate $testfile "user" $limit
1103 wait_delete_completed || error "wait_delete_completed failed"
1104 sync_all_data || true
1105 used=$(getquota -u $TSTUSR global curspace)
1106 [ $used -eq 0 ] || quota_error u $TSTUSR \
1107 "user quota isn't released after deletion"
1109 run_test 1h "Block hard limit test using fallocate"
1112 local global_limit=200 # 200M
1113 local limit1=10 # 10M
1114 local TESTDIR="$DIR/$tdir/"
1115 local testfile="$TESTDIR/$tfile-0"
1116 local testfile1="$TESTDIR/$tfile-1"
1117 local testfile2="$TESTDIR/$tfile-2"
1118 local qpool1="qpool1"
1121 setup_quota_test || error "setup quota failed with $?"
1122 stack_trap cleanup_quota_test EXIT
1125 set_ost_qtype $QTYPE || error "enable ost quota failed"
1127 log "User quota (block hardlimit:$global_limit MB)"
1128 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1129 error "set user quota failed"
1131 pool_add $qpool1 || error "pool_add failed"
1132 pool_add_targets $qpool1 0 0 ||
1133 error "pool_add_targets failed"
1135 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1136 error "set user quota failed"
1138 # make sure the system is clean
1139 local used=$(getquota -u $TSTUSR global curspace)
1140 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1142 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1145 test_1_check_write $testfile "user" $limit1
1146 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1147 error "set user quota failed"
1149 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1150 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1151 quota_error u $TSTUSR "write failure, but expect success"
1155 wait_delete_completed || error "wait_delete_completed failed"
1156 sync_all_data || true
1158 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1159 error "set user quota failed"
1160 test_1_check_write $testfile "user" $limit1
1161 local tmp_limit=$(($limit1*2))
1162 # increase pool limit
1163 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1164 error "set user quota failed"
1165 # now write shouldn't fail
1166 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1167 quota_error u $TSTUSR "write failure, but expect success"
1168 # decrease pool limit
1169 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1170 error "set user quota failed"
1171 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1172 # flush cache, ensure noquota flag is set on client
1173 cancel_lru_locks osc
1174 sync; sync_all_data || true
1175 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1176 quota_error u $TSTUSR "write success, but expect failure"
1179 run_test 1i "Quota pools: different limit and usage relations"
1181 # test inode hardlimit
1183 local TESTFILE="$DIR/$tdir/$tfile-0"
1184 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1185 qmt.$FSNAME-QMT0000.md-0x0.info |
1186 awk '/least qunit/{ print $3 }')
1187 local L2=$(do_facet mds1 $LCTL get_param -n \
1188 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1190 [ $L2 -le $LIMIT ] || LIMIT=$L2
1192 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1194 local FREE_INODES=$(mdt_free_inodes 0)
1195 echo "$FREE_INODES free inodes on master MDT"
1196 [ $FREE_INODES -lt $LIMIT ] &&
1197 skip "not enough free inodes $FREE_INODES required $LIMIT"
1199 setup_quota_test || error "setup quota failed with $?"
1202 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1205 log "User quota (inode hardlimit:$LIMIT files)"
1206 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1207 error "set user quota failed"
1209 # make sure the system is clean
1210 local USED=$(getquota -u $TSTUSR global curinodes)
1211 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1213 log "Create $LIMIT files ..."
1214 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1215 quota_error u $TSTUSR "user create failure, but expect success"
1216 log "Create out of file quota ..."
1217 $RUNAS touch ${TESTFILE}_xxx &&
1218 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1221 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1222 rm -f ${TESTFILE}_xxx
1223 wait_delete_completed
1225 USED=$(getquota -u $TSTUSR global curinodes)
1226 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1227 "user quota isn't released after deletion"
1228 resetquota -u $TSTUSR
1231 log "--------------------------------------"
1232 log "Group quota (inode hardlimit:$LIMIT files)"
1233 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1234 error "set group quota failed"
1236 TESTFILE=$DIR/$tdir/$tfile-1
1237 # make sure the system is clean
1238 USED=$(getquota -g $TSTUSR global curinodes)
1239 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1241 log "Create $LIMIT files ..."
1242 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1243 quota_error g $TSTUSR "group create failure, but expect success"
1244 log "Create out of file quota ..."
1245 $RUNAS touch ${TESTFILE}_xxx &&
1246 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1249 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1250 rm -f ${TESTFILE}_xxx
1251 wait_delete_completed
1253 USED=$(getquota -g $TSTUSR global curinodes)
1254 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1255 "user quota isn't released after deletion"
1257 resetquota -g $TSTUSR
1258 ! is_project_quota_supported &&
1259 echo "Skip project quota is not supported" && return 0
1262 log "--------------------------------------"
1263 log "Project quota (inode hardlimit:$LIMIT files)"
1264 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1265 error "set project quota failed"
1267 TESTFILE=$DIR/$tdir/$tfile-1
1268 # make sure the system is clean
1269 USED=$(getquota -p $TSTPRJID global curinodes)
1271 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1273 change_project -sp $TSTPRJID $DIR/$tdir
1274 log "Create $LIMIT files ..."
1275 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1276 $TSTPRJID "project create fail, but expect success"
1277 log "Create out of file quota ..."
1278 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1279 "project create success, but expect EDQUOT"
1280 change_project -C $DIR/$tdir
1283 USED=$(getquota -p $TSTPRJID global curinodes)
1284 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1285 "project quota isn't released after deletion"
1288 run_test 2 "File hard limit (normal use and out of quota)"
1297 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1298 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1302 $LFS setstripe $testfile -c 1 -i 0
1303 chown $TSTUSR.$TSTUSR $testfile
1304 [ "$qtype" == "p" ] && is_project_quota_supported &&
1305 change_project -p $TSTPRJID $testfile
1307 echo "Write up to soft limit"
1308 $RUNAS $DD of=$testfile count=$limit ||
1309 quota_error a $TSTUSR "write failure, but expect success"
1310 OFFSET=$((limit * 1024))
1311 cancel_lru_locks osc
1313 echo "Write to exceed soft limit"
1314 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1315 quota_error a $TSTUSR "write failure, but expect success"
1316 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1317 cancel_lru_locks osc
1319 echo "mmap write when over soft limit"
1320 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1321 quota_error a $TSTUSR "mmap write failure, but expect success"
1322 cancel_lru_locks osc
1327 $SHOW_QUOTA_INFO_USER
1328 $SHOW_QUOTA_INFO_GROUP
1329 $SHOW_QUOTA_INFO_PROJID
1331 echo "Write before timer goes off"
1332 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1333 quota_error a $TSTUSR "write failure, but expect success"
1334 OFFSET=$((OFFSET + 1024))
1335 cancel_lru_locks osc
1337 wait_grace_time $qtype "block" $pool
1342 $SHOW_QUOTA_INFO_USER
1343 $SHOW_QUOTA_INFO_GROUP
1344 $SHOW_QUOTA_INFO_PROJID
1346 log "Write after timer goes off"
1347 # maybe cache write, ignore.
1348 # write up to soft least quint to consume all
1349 # possible slave granted space.
1350 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1351 count=$soft_limit seek=$OFFSET || true
1352 OFFSET=$((OFFSET + soft_limit))
1353 cancel_lru_locks osc
1354 log "Write after cancel lru locks"
1355 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1356 quota_error a $TSTUSR "write success, but expect EDQUOT"
1361 $SHOW_QUOTA_INFO_USER
1362 $SHOW_QUOTA_INFO_GROUP
1363 $SHOW_QUOTA_INFO_PROJID
1365 echo "Unlink file to stop timer"
1367 wait_delete_completed
1368 sync_all_data || true
1373 $SHOW_QUOTA_INFO_USER
1374 $SHOW_QUOTA_INFO_GROUP
1375 $SHOW_QUOTA_INFO_PROJID
1377 $LFS setstripe $testfile -c 1 -i 0
1378 chown $TSTUSR.$TSTUSR $testfile
1379 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1382 $RUNAS $DD of=$testfile count=$limit ||
1383 quota_error a $TSTUSR "write failure, but expect success"
1390 local grace=20 # seconds
1391 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1394 local testfile=$DIR/$tdir/$tfile-0
1396 # get minimum soft qunit size
1397 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1398 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1400 set_ost_qtype $QTYPE || error "enable ost quota failed"
1402 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1403 # make sure the system is clean
1404 local used=$(getquota -u $TSTUSR global curspace)
1405 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1407 $LFS setquota -t -u --block-grace $grace --inode-grace \
1408 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1409 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1410 error "set user quota failed"
1412 test_block_soft $testfile $grace $limit "u"
1414 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1415 testfile=$DIR/$tdir/$tfile-1
1416 # make sure the system is clean
1417 used=$(getquota -g $TSTUSR global curspace)
1418 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1420 $LFS setquota -t -g --block-grace $grace --inode-grace \
1421 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1422 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1423 error "set group quota failed"
1425 test_block_soft $testfile $grace $limit "g"
1427 if is_project_quota_supported; then
1428 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1429 testfile=$DIR/$tdir/$tfile-2
1430 # make sure the system is clean
1431 used=$(getquota -p $TSTPRJID global curspace)
1432 [ $used -ne 0 ] && error \
1433 "Used space($used) for project $TSTPRJID isn't 0."
1435 $LFS setquota -t -p --block-grace $grace --inode-grace \
1436 $MAX_IQ_TIME $DIR ||
1437 error "set project grace time failed"
1438 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1439 $DIR || error "set project quota failed"
1441 test_block_soft $testfile $grace $limit "p"
1442 resetquota -p $TSTPRJID
1443 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1444 $MAX_IQ_TIME $DIR ||
1445 error "restore project grace time failed"
1449 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1450 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1451 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1452 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1454 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1457 local grace=20 # seconds
1458 local qpool="qpool1"
1459 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1462 local testfile=$DIR/$tdir/$tfile-0
1465 # get minimum soft qunit size
1466 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1467 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1468 local glbl_limit=$((2*limit))
1469 local glbl_grace=$((2*grace))
1470 echo "limit $limit glbl_limit $glbl_limit"
1471 echo "grace $grace glbl_grace $glbl_grace"
1473 set_ost_qtype $QTYPE || error "enable ost quota failed"
1475 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1476 # make sure the system is clean
1477 local used=$(getquota -u $TSTUSR global curspace)
1478 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1480 pool_add $qpool || error "pool_add failed"
1481 pool_add_targets $qpool 0 1 ||
1482 error "pool_add_targets failed"
1484 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1485 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1486 $LFS setquota -t -u --block-grace $grace \
1487 --pool $qpool $DIR || error "set user grace time failed"
1489 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1490 error "set user quota failed"
1491 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1492 error "set user quota failed"
1494 test_block_soft $testfile $grace $limit "u" $qpool
1496 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1497 testfile=$DIR/$tdir/$tfile-1
1498 # make sure the system is clean
1499 used=$(getquota -g $TSTUSR global curspace)
1500 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1502 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1503 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1504 $LFS setquota -t -g --block-grace $grace \
1505 --pool $qpool $DIR || error "set group grace time failed"
1507 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1508 error "set group quota failed"
1509 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1510 error "set group quota failed"
1512 test_block_soft $testfile $grace $limit "g" $qpool
1514 if is_project_quota_supported; then
1515 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1516 testfile=$DIR/$tdir/$tfile-2
1517 # make sure the system is clean
1518 used=$(getquota -p $TSTPRJID global curspace)
1519 [ $used -ne 0 ] && error \
1520 "Used space($used) for project $TSTPRJID isn't 0."
1522 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1523 $MAX_IQ_TIME $DIR ||
1524 error "set project grace time failed"
1525 $LFS setquota -t -p --block-grace $grace \
1526 --pool $qpool $DIR ||
1527 error "set project grace time failed"
1529 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1530 $DIR || error "set project quota failed"
1531 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1532 --pool $qpool $DIR || error "set project quota failed"
1534 test_block_soft $testfile $grace $limit "p" $qpool
1535 resetquota -p $TSTPRJID
1536 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1537 $MAX_IQ_TIME $DIR ||
1538 error "restore project grace time failed"
1539 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1540 $DIR || error "set project grace time failed"
1544 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1545 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1546 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1547 --pool $qpool $DIR || error "restore user grace time failed"
1548 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1549 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1550 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1551 --pool $qpool $DIR || error "restore group grace time failed"
1553 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1556 local grace=20 # seconds
1557 local qpool="qpool1"
1558 local qpool2="qpool2"
1559 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1562 local testfile=$DIR/$tdir/$tfile-0
1565 # get minimum soft qunit size
1566 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1567 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1568 local limit2=$((limit+4))
1569 local glbl_limit=$((limit+8))
1570 local grace1=$((grace+10))
1572 local glbl_grace=$((grace+20))
1573 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1574 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1576 set_ost_qtype $QTYPE || error "enable ost quota failed"
1578 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1579 # make sure the system is clean
1580 local used=$(getquota -u $TSTUSR global curspace)
1581 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1583 pool_add $qpool || error "pool_add failed"
1584 pool_add_targets $qpool 0 1 ||
1585 error "pool_add_targets failed"
1587 pool_add $qpool2 || error "pool_add failed"
1588 pool_add_targets $qpool2 0 1 ||
1589 error "pool_add_targets failed"
1592 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1593 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1594 $LFS setquota -t -u --block-grace $grace1 \
1595 --pool $qpool $DIR || error "set user grace time failed"
1596 $LFS setquota -t -u --block-grace $grace2 \
1597 --pool $qpool2 $DIR || error "set user grace time failed"
1599 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1600 error "set user quota failed"
1601 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1602 error "set user quota failed"
1603 # qpool has minimum soft limit, but its grace is greater than
1604 # the grace period of qpool2. Thus write shouldn't fail when
1605 # hit qpool soft limit - only when reaches up qpool2 limit
1606 # after grace2 seconds.
1607 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1608 error "set user quota failed"
1610 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1613 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1614 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1615 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1616 --pool $qpool $DIR || error "restore user grace time failed"
1617 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1618 --pool $qpool2 $DIR || error "restore user grace time failed"
1620 run_test 3c "Quota pools: check block soft limit on different pools"
1627 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1628 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1631 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1633 echo "Create files to exceed soft limit"
1634 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1635 quota_error a $TSTUSR "create failure, but expect success"
1636 local trigger_time=$(date +%s)
1638 sync_all_data || true
1640 local cur_time=$(date +%s)
1641 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1642 error "Passed grace time $grace, $trigger_time, $cur_time"
1644 echo "Create file before timer goes off"
1645 $RUNAS touch ${TESTFILE}_before ||
1646 quota_error a $TSTUSR "failed create before timer expired," \
1647 "but expect success. $trigger_time, $cur_time"
1648 sync_all_data || true
1650 wait_grace_time $qtype "file"
1655 $SHOW_QUOTA_INFO_USER
1656 $SHOW_QUOTA_INFO_GROUP
1657 $SHOW_QUOTA_INFO_PROJID
1659 echo "Create file after timer goes off"
1660 # exceed least soft limit is possible
1661 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1662 quota_error a $TSTUSR "create after timer expired," \
1664 sync_all_data || true
1669 $SHOW_QUOTA_INFO_USER
1670 $SHOW_QUOTA_INFO_GROUP
1671 $SHOW_QUOTA_INFO_PROJID
1673 echo "Unlink files to stop timer"
1674 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1675 wait_delete_completed
1678 $RUNAS touch ${TESTFILE}_xxx ||
1679 quota_error a $TSTUSR "touch after timer stop failure," \
1680 "but expect success"
1681 sync_all_data || true
1689 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1690 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1691 local TESTFILE=$DIR/$tdir/$tfile-0
1694 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1696 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1697 # make sure the system is clean
1698 local USED=$(getquota -u $TSTUSR global curinodes)
1699 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1701 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1702 $GRACE $DIR || error "set user grace time failed"
1703 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1704 error "set user quota failed"
1706 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1708 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1710 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1711 # make sure the system is clean
1712 USED=$(getquota -g $TSTUSR global curinodes)
1713 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1715 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1716 $GRACE $DIR || error "set group grace time failed"
1717 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1718 error "set group quota failed"
1719 TESTFILE=$DIR/$tdir/$tfile-1
1721 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1723 if is_project_quota_supported; then
1724 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1725 # make sure the system is clean
1726 USED=$(getquota -p $TSTPRJID global curinodes)
1727 [ $USED -ne 0 ] && error \
1728 "Used space($USED) for project $TSTPRJID isn't 0."
1730 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1731 $GRACE $DIR || error "set project grace time failed"
1732 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1733 error "set project quota failed"
1735 TESTFILE=$DIR/$tdir/$tfile-1
1736 # one less than limit, because of parent directory included.
1737 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1738 resetquota -p $TSTPRJID
1739 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1740 $MAX_IQ_TIME $DIR ||
1741 error "restore project grace time failed"
1745 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1746 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1747 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1748 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1750 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1753 local GR_STR1="1w3d"
1754 local GR_STR2="1000s"
1756 local GR_STR4="1w2d3h4m5s"
1758 local GR_STR6="18446744073709551615"
1761 wait_delete_completed
1763 # test of valid grace strings handling
1764 echo "Valid grace strings test"
1765 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1766 $GR_STR2 $DIR || error "set user grace time failed"
1767 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1768 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1769 $GR_STR4 $DIR || error "set group grace time quota failed"
1770 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1772 # test of invalid grace strings handling
1773 echo " Invalid grace strings test"
1774 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1775 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1776 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1780 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1781 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1782 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1783 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1785 run_test 4b "Grace time strings handling"
1787 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1789 local BLIMIT=10 # MB
1790 local ILIMIT=10 # inodes
1792 setup_quota_test || error "setup quota failed with $?"
1794 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1795 set_ost_qtype $QTYPE || error "enable ost quota failed"
1797 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1798 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1799 error "set user quota failed"
1800 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1801 if is_project_quota_supported; then
1802 error "set group quota failed"
1803 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1804 -I $ILIMIT $DIR || error "set project quota failed"
1807 # make sure the system is clean
1808 local USED=$(getquota -u $TSTUSR global curinodes)
1809 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1810 USED=$(getquota -g $TSTUSR global curinodes)
1811 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1812 USED=$(getquota -u $TSTUSR global curspace)
1813 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1814 USED=$(getquota -g $TSTUSR global curspace)
1815 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1816 if is_project_quota_supported; then
1817 USED=$(getquota -p $TSTPRJID global curinodes)
1819 error "Used inode($USED) for project $TSTPRJID isn't 0."
1820 USED=$(getquota -p $TSTPRJID global curspace)
1822 error "Used block($USED) for project $TSTPRJID isn't 0."
1825 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1826 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1827 error "create failure, expect success"
1828 if is_project_quota_supported; then
1829 touch $DIR/$tdir/$tfile-0_1
1830 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1832 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1833 error "write failure, expect success"
1835 echo "Chown files to $TSTUSR.$TSTUSR ..."
1836 for i in $(seq 0 $ILIMIT); do
1837 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1838 quota_error a $TSTUSR "chown failure, expect success"
1842 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1843 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1845 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1847 # test dropping acquire request on master
1851 # Clear dmesg so watchdog is not triggered by previous
1853 do_facet ost1 dmesg -c > /dev/null
1855 setup_quota_test || error "setup quota failed with $?"
1857 # make sure the system is clean
1858 local USED=$(getquota -u $TSTUSR global curspace)
1859 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1861 # make sure no granted quota on ost
1862 set_ost_qtype $QTYPE || error "enable ost quota failed"
1863 resetquota -u $TSTUSR
1865 # create file for $TSTUSR
1866 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1867 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1868 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1870 # create file for $TSTUSR2
1871 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1872 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1873 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1875 # cache per-ID lock for $TSTUSR on slave
1876 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1877 error "set quota failed"
1878 $RUNAS $DD of=$TESTFILE count=1 ||
1879 error "write $TESTFILE failure, expect success"
1880 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1881 error "write $TESTFILE2 failure, expect success"
1883 if at_is_enabled; then
1884 at_max_saved=$(at_max_get ost1)
1885 at_max_set $TIMEOUT ost1
1887 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1888 # DQACQ is sent, which makes at_max to take effect
1889 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1892 wait_delete_completed
1896 sync_all_data || true
1898 #define QUOTA_DQACQ 601
1899 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1900 lustre_fail mds 0x513 601
1902 do_facet ost1 $LCTL set_param \
1903 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1905 # write to un-enforced ID ($TSTUSR2) should succeed
1906 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1907 error "write failure, expect success"
1909 # write to enforced ID ($TSTUSR) in background, exceeding limit
1910 # to make sure DQACQ is sent
1911 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1914 # watchdog timer uses a factor of 2
1915 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1916 sleep $((TIMEOUT * 2 + 1))
1918 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1920 # write should be blocked and never finished
1921 if ! ps -p $DDPID > /dev/null 2>&1; then
1923 error "write finished incorrectly!"
1928 # no watchdog is triggered
1929 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1930 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1931 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1932 [ -z "$watchdog" ] || error "$watchdog"
1934 rm -f $TMP/lustre-log-${TESTNAME}.log
1936 # write should continue then fail with EDQUOT
1940 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1941 if [ $count -ge 240 ]; then
1942 quota_error u $TSTUSR "dd not finished in $count secs"
1944 count=$((count + 1))
1945 if [ $((count % 30)) -eq 0 ]; then
1946 c_size=$(stat -c %s $TESTFILE)
1947 echo "Waiting $count secs. $c_size"
1953 run_test 6 "Test dropping acquire request on master"
1955 # quota reintegration (global index)
1957 local TESTFILE=$DIR/$tdir/$tfile
1960 [ "$SLOW" = "no" ] && LIMIT=5
1962 setup_quota_test || error "setup quota failed with $?"
1964 # make sure the system is clean
1965 local USED=$(getquota -u $TSTUSR global curspace)
1966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1968 # make sure no granted quota on ost1
1969 set_ost_qtype $QTYPE || error "enable ost quota failed"
1970 resetquota -u $TSTUSR
1971 set_ost_qtype "none" || error "disable ost quota failed"
1973 local OSTUUID=$(ostuuid_from_index 0)
1974 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1976 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1979 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1980 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1985 echo "Enable quota & set quota limit for $TSTUSR"
1986 set_ost_qtype $QTYPE || error "enable ost quota failed"
1987 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1988 error "set quota failed"
1990 echo "Start ost1..."
1991 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1994 wait_ost_reint $QTYPE || error "reintegration failed"
1996 # hardlimit should have been fetched by slave during global
1997 # reintegration, write will exceed quota
1998 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1999 quota_error u $TSTUSR "write success, but expect EDQUOT"
2002 wait_delete_completed
2003 sync_all_data || true
2009 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2010 error "clear quota failed"
2012 echo "Start ost1..."
2013 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2016 wait_ost_reint $QTYPE || error "reintegration failed"
2018 # hardlimit should be cleared on slave during reintegration
2019 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2020 quota_error u $TSTUSR "write error, but expect success"
2022 run_test 7a "Quota reintegration (global index)"
2024 # quota reintegration (slave index)
2026 local limit=100000 # MB
2027 local TESTFILE=$DIR/$tdir/$tfile
2029 setup_quota_test || error "setup quota failed with $?"
2031 # make sure the system is clean
2032 local USED=$(getquota -u $TSTUSR global curspace)
2033 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2035 # make sure no granted quota on ost1
2036 set_ost_qtype $QTYPE || error "enable ost quota failed"
2037 resetquota -u $TSTUSR
2038 set_ost_qtype "none" || error "disable ost quota failed"
2040 local OSTUUID=$(ostuuid_from_index 0)
2041 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2043 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2046 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2047 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2049 # consume some space to make sure the granted space will not
2050 # be released during reconciliation
2051 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2052 error "consume space failure, expect success"
2054 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2055 lustre_fail mds 0xa02
2057 set_ost_qtype $QTYPE || error "enable ost quota failed"
2058 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2059 error "set quota failed"
2061 # ignore the write error
2062 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2064 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2068 echo "Restart ost to trigger reintegration..."
2070 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2073 wait_ost_reint $QTYPE || error "reintegration failed"
2075 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2076 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2081 run_test 7b "Quota reintegration (slave index)"
2083 # quota reintegration (restart mds during reintegration)
2086 local TESTFILE=$DIR/$tdir/$tfile
2088 [ "$SLOW" = "no" ] && LIMIT=5
2090 setup_quota_test || error "setup quota failed with $?"
2092 # make sure the system is clean
2093 local USED=$(getquota -u $TSTUSR global curspace)
2094 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2096 set_ost_qtype "none" || error "disable ost quota failed"
2097 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2098 error "set quota failed"
2100 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2101 lustre_fail ost 0xa03
2104 set_ost_qtype $QTYPE || error "enable ost quota failed"
2105 # trigger reintegration
2106 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2107 procf=${procf}quota_slave.force_reint
2108 do_facet ost1 $LCTL set_param $procf=1 ||
2109 error "force reintegration failed"
2117 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2120 # wait longer than usual to make sure the reintegration
2121 # is triggered by quota wb thread.
2122 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2124 # hardlimit should have been fetched by slave during global
2125 # reintegration, write will exceed quota
2126 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2127 quota_error u $TSTUSR "write success, but expect EDQUOT"
2130 run_test 7c "Quota reintegration (restart mds during reintegration)"
2132 # Quota reintegration (Transfer index in multiple bulks)
2134 local TESTFILE=$DIR/$tdir/$tfile
2135 local TESTFILE1="$DIR/$tdir/$tfile"-1
2138 setup_quota_test || error "setup quota failed with $?"
2140 set_ost_qtype "none" || error "disable ost quota failed"
2141 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2142 error "set quota for $TSTUSR failed"
2143 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2144 error "set quota for $TSTUSR2 failed"
2146 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2147 lustre_fail mds 0x608 0
2149 # enable quota to tirgger reintegration
2150 set_ost_qtype "u" || error "enable ost quota failed"
2151 wait_ost_reint "u" || error "reintegration failed"
2155 # hardlimit should have been fetched by slave during global
2156 # reintegration, write will exceed quota
2157 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2158 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2160 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2161 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2164 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2166 # quota reintegration (inode limits)
2168 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2170 # LU-2435: skip this quota test if underlying zfs version has not
2171 # supported native dnode accounting
2172 [ "$mds1_FSTYPE" == zfs ] && {
2173 local F="feature@userobj_accounting"
2174 local pool=$(zpool_name mds1)
2175 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2177 [[ "$feature" != *" active "* ]] &&
2178 skip "requires zpool with active userobj_accounting"
2181 local ilimit=$((1024 * 2)) # inodes
2182 local TESTFILE=$DIR/${tdir}-1/$tfile
2184 setup_quota_test || error "setup quota failed with $?"
2186 # make sure the system is clean
2187 local USED=$(getquota -u $TSTUSR global curinodes)
2188 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2190 # make sure no granted quota on mdt1
2191 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2192 resetquota -u $TSTUSR
2193 set_mdt_qtype "none" || error "disable mdt quota failed"
2195 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2196 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2197 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2200 echo "Stop mds${MDSCOUNT}..."
2203 echo "Enable quota & set quota limit for $TSTUSR"
2204 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2205 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2206 error "set quota failed"
2208 echo "Start mds${MDSCOUNT}..."
2209 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2212 wait_mdt_reint $QTYPE || error "reintegration failed"
2214 echo "create remote dir"
2215 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2216 error "create remote dir failed"
2217 chmod 0777 $DIR/${tdir}-1
2219 # hardlimit should have been fetched by slave during global
2220 # reintegration, create will exceed quota
2221 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2222 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2224 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2225 wait_delete_completed
2226 sync_all_data || true
2228 echo "Stop mds${MDSCOUNT}..."
2231 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2232 error "clear quota failed"
2234 echo "Start mds${MDSCOUNT}..."
2235 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2238 wait_mdt_reint $QTYPE || error "reintegration failed"
2240 # hardlimit should be cleared on slave during reintegration
2241 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2242 quota_error u $TSTUSR "create failed, expect success"
2244 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2245 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2247 run_test 7e "Quota reintegration (inode limits)"
2249 # run dbench with quota enabled
2251 local BLK_LIMIT="100g" #100G
2252 local FILE_LIMIT=1000000
2254 setup_quota_test || error "setup quota failed with $?"
2256 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2257 set_ost_qtype $QTYPE || error "enable ost quota failed"
2259 echo "Set enough high limit for user: $TSTUSR"
2260 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2261 error "set user quota failed"
2262 echo "Set enough high limit for group: $TSTUSR"
2263 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2264 error "set group quota failed"
2265 if is_project_quota_supported; then
2266 change_project -sp $TSTPRJID $DIR/$tdir
2267 echo "Set enough high limit for project: $TSTPRJID"
2268 $LFS setquota -p $TSTPRJID -b 0 \
2269 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2270 error "set project quota failed"
2274 [ "$SLOW" = "no" ] && duration=" -t 120"
2275 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2276 quota_error a $TSTUSR "dbench failed!"
2278 is_project_quota_supported && change_project -C $DIR/$tdir
2280 run_test 8 "Run dbench with quota enabled"
2282 # this check is just for test_9
2283 OST0_MIN=4900000 #4.67G
2285 check_whether_skip () {
2286 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2287 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2288 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2289 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2296 # run for fixing bug10707, it needs a big room. test for 64bit
2298 local filesize=$((1024 * 9 / 2)) # 4.5G
2300 check_whether_skip && return 0
2302 setup_quota_test || error "setup quota failed with $?"
2304 set_ost_qtype "ug" || error "enable ost quota failed"
2306 local TESTFILE="$DIR/$tdir/$tfile-0"
2307 local BLK_LIMIT=100G #100G
2308 local FILE_LIMIT=1000000
2310 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2312 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2314 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2315 error "set user quota failed"
2317 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2318 "for group: $TSTUSR"
2319 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2320 error "set group quota failed"
2322 quota_show_check a u $TSTUSR
2323 quota_show_check a g $TSTUSR
2325 echo "Create test file"
2326 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2327 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2329 log "Write the big file of 4.5G ..."
2330 $RUNAS $DD of=$TESTFILE count=$filesize ||
2331 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2341 run_test 9 "Block limit larger than 4GB (b10707)"
2344 local TESTFILE=$DIR/$tdir/$tfile
2346 setup_quota_test || error "setup quota failed with $?"
2348 # set limit to root user should fail
2349 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2350 error "set limit for root user successfully, expect failure"
2351 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2352 error "set limit for root group successfully, expect failure"
2353 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2354 error "set limit for project 0 successfully, expect failure"
2356 # root user can overrun quota
2357 set_ost_qtype "ug" || error "enable ost quota failed"
2359 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2360 error "set quota failed"
2361 quota_show_check b u $TSTUSR
2363 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2364 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2366 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2367 error "write failure, expect success"
2369 run_test 10 "Test quota for root user"
2372 local TESTFILE=$DIR/$tdir/$tfile
2373 setup_quota_test || error "setup quota failed with $?"
2375 set_mdt_qtype "ug" || error "enable mdt quota failed"
2376 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2377 error "set quota failed"
2379 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2380 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2382 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2383 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2386 local USED=$(getquota -u $TSTUSR global curinodes)
2387 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2389 run_test 11 "Chown/chgrp ignores quota"
2392 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2394 local blimit=22 # MB
2395 local blk_cnt=$((blimit - 5))
2396 local TESTFILE0="$DIR/$tdir/$tfile"-0
2397 local TESTFILE1="$DIR/$tdir/$tfile"-1
2399 setup_quota_test || error "setup quota failed with $?"
2401 set_ost_qtype "u" || error "enable ost quota failed"
2402 quota_show_check b u $TSTUSR
2404 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2405 error "set quota failed"
2407 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2408 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2409 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2410 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2412 echo "Write to ost0..."
2413 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2414 quota_error a $TSTUSR "dd failed"
2416 echo "Write to ost1..."
2417 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2418 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2420 echo "Free space from ost0..."
2422 wait_delete_completed
2423 sync_all_data || true
2425 echo "Write to ost1 after space freed from ost0..."
2426 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2427 quota_error a $TSTUSR "rebalancing failed"
2429 run_test 12a "Block quota rebalancing"
2432 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2434 local ilimit=$((1024 * 2)) # inodes
2435 local TESTFILE0=$DIR/$tdir/$tfile
2436 local TESTFILE1=$DIR/${tdir}-1/$tfile
2438 setup_quota_test || error "setup quota failed with $?"
2440 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2441 chmod 0777 $DIR/${tdir}-1
2443 set_mdt_qtype "u" || error "enable mdt quota failed"
2444 quota_show_check f u $TSTUSR
2446 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2447 error "set quota failed"
2449 echo "Create $ilimit files on mdt0..."
2450 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2451 quota_error u $TSTUSR "create failed, but expect success"
2453 echo "Create files on mdt1..."
2454 $RUNAS createmany -m $TESTFILE1 1 &&
2455 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2457 echo "Free space from mdt0..."
2458 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2459 wait_delete_completed
2460 sync_all_data || true
2462 echo "Create files on mdt1 after space freed from mdt0..."
2463 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2464 quota_error a $TSTUSR "rebalancing failed"
2466 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2467 error "unlink mdt1 files failed"
2468 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2470 run_test 12b "Inode quota rebalancing"
2473 local TESTFILE=$DIR/$tdir/$tfile
2474 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2475 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2477 setup_quota_test || error "setup quota failed with $?"
2479 set_ost_qtype "u" || error "enable ost quota failed"
2480 quota_show_check b u $TSTUSR
2482 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2483 error "set quota failed"
2484 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2485 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2487 # clear the locks in cache first
2488 do_facet ost1 $LCTL set_param -n $procf=clear
2489 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2490 [ $nlock -eq 0 ] || error "$nlock cached locks"
2492 # write to acquire the per-ID lock
2493 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2494 quota_error a $TSTUSR "dd failed"
2496 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2497 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2499 # clear quota doesn't trigger per-ID lock cancellation
2500 resetquota -u $TSTUSR
2501 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2502 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2504 # clear the per-ID lock
2505 do_facet ost1 $LCTL set_param -n $procf=clear
2506 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2507 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2509 # spare quota should be released
2510 local OSTUUID=$(ostuuid_from_index 0)
2511 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2512 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2513 [ $limit -le $space ] ||
2514 error "spare quota isn't released, limit:$limit, space:$space"
2516 run_test 13 "Cancel per-ID lock in the LRU list"
2519 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2521 wait_delete_completed
2522 sync_all_data || true
2525 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2526 error "set user quota failed"
2527 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2528 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2529 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2530 resetquota -u $TSTUSR
2533 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2534 error "set group quota failed"
2535 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2536 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2537 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2538 resetquota -g $TSTUSR
2540 run_test 15 "Set over 4T block quota"
2544 local BLKS=1 # 1M less than limit
2545 local TESTFILE=$DIR/$tdir/$tfile
2547 setup_quota_test || error "setup quota failed with $?"
2549 # make sure the system is clean
2550 local USED=$(getquota -u $TSTUSR global curspace)
2551 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2553 set_ost_qtype "ug" || error "enable ost quota failed"
2554 # make sure no granted quota on ost
2555 resetquota -u $TSTUSR
2556 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2557 error "set quota failed"
2559 quota_show_check b u $TSTUSR
2561 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2562 lustre_fail mds 0xa04 $err_code
2564 # write in background
2565 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2569 # write should be blocked and never finished
2570 if ! ps -p $DDPID > /dev/null 2>&1; then
2572 quota_error u $TSTUSR "write finished incorrectly!"
2580 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2582 if [ $count -gt $timeout ]; then
2583 quota_error u $TSTUSR "dd is not finished!"
2588 sync; sync_all_data || true
2590 USED=$(getquota -u $TSTUSR global curspace)
2591 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2592 "Used space(${USED}K) is less than ${BLKS}M"
2597 # DQACQ return recoverable error
2599 echo "DQACQ return -ENOLCK"
2601 test_17sub 37 || error "Handle -ENOLCK failed"
2603 echo "DQACQ return -EAGAIN"
2605 test_17sub 11 || error "Handle -EAGAIN failed"
2607 echo "DQACQ return -ETIMEDOUT"
2608 #define ETIMEDOUT 110
2609 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2611 echo "DQACQ return -ENOTCONN"
2612 #define ENOTCONN 107
2613 test_17sub 107 || error "Handle -ENOTCONN failed"
2616 run_test 17 "DQACQ return recoverable error"
2620 local blimit=200 # MB
2621 local TESTFILE="$DIR/$tdir/$tfile"
2623 setup_quota_test || error "setup quota failed with $?"
2625 set_ost_qtype "u" || error "enable ost quota failed"
2626 log "User quota (limit: $blimit)"
2627 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2628 error "set quota failed"
2629 quota_show_check b u $TSTUSR
2631 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2632 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2634 local timeout=$(sysctl -n lustre.timeout)
2636 if [ $io_type = "directio" ]; then
2637 log "Write 100M (directio) ..."
2638 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2640 log "Write 100M (buffered) ..."
2641 $RUNAS $DD of=$TESTFILE count=100 &
2645 replay_barrier $SINGLEMDS
2646 log "Fail mds for $((2 * timeout)) seconds"
2647 fail $SINGLEMDS $((2 * timeout))
2650 if at_is_enabled; then
2651 timeout=$(at_max_get mds)
2653 timeout=$(lctl get_param -n timeout)
2657 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2658 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2659 log "it took $count second"
2664 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2666 cancel_lru_locks mdc
2667 cancel_lru_locks osc
2670 local testfile_size=$(stat -c %s $TESTFILE)
2671 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2672 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2673 "got ${testfile_size}. Verifying file failed!"
2678 # test when mds does failover, the ost still could work well
2679 # this test shouldn't trigger watchdog b=14840
2681 # Clear dmesg so watchdog is not triggered by previous
2683 do_facet ost1 dmesg -c > /dev/null
2686 test_18_sub directio
2688 # check if watchdog is triggered
2689 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2690 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2691 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2692 [ -z "$watchdog" ] || error "$watchdog"
2693 rm -f $TMP/lustre-log-${TESTNAME}.log
2695 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2699 local TESTFILE=$DIR/$tdir/$tfile
2701 setup_quota_test || error "setup quota failed with $?"
2703 set_ost_qtype $QTYPE || error "enable ost quota failed"
2705 # bind file to a single OST
2706 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2707 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2709 echo "Set user quota (limit: ${blimit}M)"
2710 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2711 error "set user quota failed"
2712 quota_show_check b u $TSTUSR
2713 echo "Update quota limits"
2714 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2715 error "set group quota failed"
2716 quota_show_check b u $TSTUSR
2718 # first wirte might be cached
2719 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2720 cancel_lru_locks osc
2722 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2723 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 $?"
2776 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2778 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2779 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2780 error "set user quota failed"
2781 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2782 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2783 error "set group quota failed"
2784 if is_project_quota_supported; then
2785 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2786 "project: $TSTPRJID"
2787 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2788 $MOUNT || error "set project quota failed"
2791 # repeat writing on a 1M file
2792 test_21_sub ${TESTFILE}_1 1 30 &
2794 # repeat writing on a 128M file
2795 test_21_sub ${TESTFILE}_2 128 30 &
2798 local time=$(($(date +%s) + 30))
2800 while [ $(date +%s) -lt $time ]; do
2801 log "Set quota for $i times"
2802 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2803 -I $((ILIMIT + i)) $MOUNT ||
2804 error "Set user quota failed"
2805 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2806 -I $((ILIMIT + i)) $MOUNT ||
2807 error "Set group quota failed"
2808 if is_project_quota_supported; then
2809 $LFS setquota -p $TSTPRJID -b 0 -B \
2810 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2811 error "Set project quota failed"
2819 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2821 if [ $count -gt 60 ]; then
2822 quota_error a $TSTUSR "dd should be finished!"
2826 echo "(dd_pid=$DDPID1, time=$count)successful"
2830 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2832 if [ $count -gt 60 ]; then
2833 quota_error a $TSTUSR "dd should be finished!"
2837 echo "(dd_pid=$DDPID2, time=$count)successful"
2839 run_test 21 "Setquota while writing & deleting (b16053)"
2841 # enable/disable quota enforcement permanently
2843 echo "Set both mdt & ost quota type as ug"
2845 is_project_quota_supported && qtype=$QTYPE
2846 set_mdt_qtype $qtype || error "enable mdt quota failed"
2847 set_ost_qtype $qtype || error "enable ost quota failed"
2850 stopall || error "failed to stopall (1)"
2854 echo "Verify if quota is enabled"
2855 local qtype1=$(mdt_quota_type)
2856 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2857 qtype=$(ost_quota_type)
2858 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2860 echo "Set both mdt & ost quota type as none"
2861 set_mdt_qtype "none" || error "disable mdt quota failed"
2862 set_ost_qtype "none" || error "disable ost quota failed"
2865 stopall || error "failed to stopall (2)"
2870 echo "Verify if quota is disabled"
2871 qtype=$(mdt_quota_type)
2872 [ $qtype != "none" ] && error "mdt quota setting is lost"
2873 qtype=$(ost_quota_type)
2874 [ $qtype != "none" ] && error "ost quota setting is lost"
2878 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2881 local TESTFILE="$DIR/$tdir/$tfile"
2884 setup_quota_test || error "setup quota failed with $?"
2886 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2889 log "User quota (limit: $LIMIT MB)"
2890 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2891 error "set quota failed"
2892 quota_show_check b u $TSTUSR
2894 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2895 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2897 log "Step1: trigger EDQUOT with O_DIRECT"
2898 log "Write half of file"
2899 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2900 quota_error u $TSTUSR "(1) Write failure, expect success." \
2902 log "Write out of block quota ..."
2903 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2904 oflag=direct conv=notrunc &&
2905 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2909 log "Step2: rewrite should succeed"
2910 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2911 quota_error u $TSTUSR "(3) Write failure, expect success." \
2917 local OST0_UUID=$(ostuuid_from_index 0)
2918 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2919 [ $OST0_QUOTA_USED -ne 0 ] &&
2920 ($SHOW_QUOTA_USER; \
2921 quota_error u $TSTUSR "quota isn't released")
2926 [ "$ost1_FSTYPE" == zfs ] &&
2927 skip "Overwrite in place is not guaranteed to be " \
2928 "space neutral on ZFS"
2930 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2931 check_whether_skip && return 0
2932 log "run for 4MB test file"
2935 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2936 check_whether_skip && return 0
2937 log "run for 40MB test file"
2940 run_test 23 "Quota should be honored with directIO (b16125)"
2944 local TESTFILE="$DIR/$tdir/$tfile"
2946 setup_quota_test || error "setup quota failed with $?"
2948 set_ost_qtype $QTYPE || error "enable ost quota failed"
2950 # bind file to a single OST
2951 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2952 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2954 echo "Set user quota (limit: ${blimit}M)"
2955 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2956 error "set quota failed"
2958 # overrun quota by root user
2959 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2960 error "write failure, expect success"
2961 cancel_lru_locks osc
2962 sync_all_data || true
2964 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2966 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2968 test_27a() { # b19612
2969 $LFS quota $TSTUSR $DIR &&
2970 error "lfs succeeded with no type, but should have failed"
2971 $LFS setquota $TSTUSR $DIR &&
2972 error "lfs succeeded with no type, but should have failed"
2975 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2977 test_27b() { # b20200
2978 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2979 error "lfs setquota failed with uid argument"
2980 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2981 error "lfs stequota failed with gid argument"
2982 if is_project_quota_supported; then
2983 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2984 1000 $DIR || error \
2985 "lfs stequota failed with projid argument"
2987 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2988 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2989 if is_project_quota_supported; then
2990 $SHOW_QUOTA_PROJID ||
2991 error "lfs quota failed with projid argument"
2993 resetquota -u $TSTID
2994 resetquota -g $TSTID
2995 resetquota -p $TSTPRJID
2998 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3003 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3004 error "lfs setquota failed"
3006 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3007 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3008 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3009 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3011 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3012 error "lfs setquota for $TSTID failed"
3014 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3015 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3016 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3017 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3019 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3020 error "total allocated inode/block limit not printed"
3022 resetquota -u $TSTUSR
3024 run_test 27c "lfs quota should support human-readable output"
3031 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3032 error "set fraction block limit failed"
3033 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3034 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3035 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3036 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3038 resetquota -u $TSTUSR
3040 run_test 27d "lfs setquota should support fraction block limit"
3044 local TESTFILE="$DIR/$tdir/$tfile"
3047 setup_quota_test || error "setup quota failed with $?"
3049 set_ost_qtype "u" || error "enable ost quota failed"
3051 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3052 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3054 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3055 $MAX_IQ_TIME $DIR || error "set grace time failed"
3056 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3057 error "set quota failed"
3058 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3059 cancel_lru_locks osc
3061 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3062 # over-quota flag has not yet settled since we do not trigger async
3063 # events based on grace time period expiration
3065 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3066 cancel_lru_locks osc
3067 # now over-quota flag should be settled and further writes should fail
3069 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3070 error "grace times were reset"
3071 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3072 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3074 run_test 30 "Hard limit updates should not reset grace times"
3076 # basic usage tracking for user & group
3078 local INODES=10 # files
3079 local BLK_CNT=2 # MB each
3080 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3082 setup_quota_test || error "setup quota failed with $?"
3084 # make sure the system is clean
3085 local USED=$(getquota -u $TSTID global curspace)
3087 error "Used space ($USED) for user $TSTID isn't 0."
3088 USED=$(getquota -g $TSTID global curspace)
3090 error "Used space ($USED) for group $TSTID isn't 0."
3091 if is_project_quota_supported; then
3092 USED=$(getquota -p $TSTPRJID global curspace)
3093 [ $USED -ne 0 ] && error \
3094 "Used space ($USED) for project $TSTPRJID isn't 0."
3097 echo "Write files..."
3098 for i in $(seq 0 $INODES); do
3099 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3100 error "write failed"
3101 is_project_quota_supported &&
3102 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3103 echo "Iteration $i/$INODES completed"
3105 cancel_lru_locks osc
3107 echo "Wait for setattr on objects finished..."
3108 wait_delete_completed
3110 sync; sync_all_data || true
3112 echo "Verify disk usage after write"
3113 USED=$(getquota -u $TSTID global curspace)
3114 [ $USED -lt $TOTAL_BLKS ] &&
3115 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3116 USED=$(getquota -g $TSTID global curspace)
3117 [ $USED -lt $TOTAL_BLKS ] &&
3118 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3119 if is_project_quota_supported; then
3120 USED=$(getquota -p $TSTPRJID global curspace)
3121 [ $USED -lt $TOTAL_BLKS ] && error \
3122 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3125 echo "Verify inode usage after write"
3126 USED=$(getquota -u $TSTID global curinodes)
3127 [ $USED -lt $INODES ] &&
3128 error "Used inode for user $TSTID is $USED, expected $INODES"
3129 USED=$(getquota -g $TSTID global curinodes)
3130 [ $USED -lt $INODES ] &&
3131 error "Used inode for group $TSTID is $USED, expected $INODES"
3132 if is_project_quota_supported; then
3133 USED=$(getquota -p $TSTPRJID global curinodes)
3134 [ $USED -lt $INODES ] && error \
3135 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3140 echo "Verify disk usage after delete"
3141 USED=$(getquota -u $TSTID global curspace)
3142 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3143 USED=$(getquota -u $TSTID global curinodes)
3144 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3145 USED=$(getquota -g $TSTID global curspace)
3146 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3147 USED=$(getquota -g $TSTID global curinodes)
3148 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3149 if is_project_quota_supported; then
3150 USED=$(getquota -p $TSTPRJID global curspace)
3152 error "Used space for project $TSTPRJID isn't 0. $USED"
3153 USED=$(getquota -p $TSTPRJID global curinodes)
3155 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3158 run_test 33 "Basic usage tracking for user & group & project"
3160 # usage transfer test for user & group & project
3162 local BLK_CNT=2 # MB
3163 local project_supported="no"
3165 is_project_quota_supported && project_supported="yes"
3166 setup_quota_test || error "setup quota failed with $?"
3168 # make sure the system is clean
3169 local USED=$(getquota -u $TSTID global curspace)
3170 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3171 USED=$(getquota -g $TSTID global curspace)
3172 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3174 local USED=$(getquota -u $TSTID2 global curspace)
3175 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3176 if [ $project_supported == "yes" ]; then
3177 USED=$(getquota -p $TSTPRJID global curspace)
3178 [ $USED -ne 0 ] && error \
3179 "Used space ($USED) for Project $TSTPRJID isn't 0."
3182 echo "Write file..."
3183 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3184 error "write failed"
3185 cancel_lru_locks osc
3186 sync; sync_all_data || true
3188 echo "chown the file to user $TSTID"
3189 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3191 echo "Wait for setattr on objects finished..."
3192 wait_delete_completed
3194 BLK_CNT=$((BLK_CNT * 1024))
3196 echo "Verify disk usage for user $TSTID"
3197 USED=$(getquota -u $TSTID global curspace)
3198 [ $USED -lt $BLK_CNT ] &&
3199 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3200 USED=$(getquota -u $TSTID global curinodes)
3202 error "Used inodes for user $TSTID is $USED, expected 1"
3204 echo "chgrp the file to group $TSTID"
3205 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3207 echo "Wait for setattr on objects finished..."
3208 wait_delete_completed
3210 echo "Verify disk usage for group $TSTID"
3211 USED=$(getquota -g $TSTID global curspace)
3212 [ $USED -ge $BLK_CNT ] ||
3213 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3214 USED=$(getquota -g $TSTID global curinodes)
3216 error "Used inodes for group $TSTID is $USED, expected 1"
3218 # chown won't change the ost object group. LU-4345 */
3219 echo "chown the file to user $TSTID2"
3220 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3222 echo "Wait for setattr on objects finished..."
3223 wait_delete_completed
3225 echo "change_project project id to $TSTPRJID"
3226 [ $project_supported == "yes" ] &&
3227 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3228 echo "Wait for setattr on objects finished..."
3229 wait_delete_completed
3231 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3232 USED=$(getquota -u $TSTID2 global curspace)
3233 [ $USED -lt $BLK_CNT ] &&
3234 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3235 USED=$(getquota -u $TSTID global curspace)
3237 error "Used space for user $TSTID is $USED, expected 0"
3238 USED=$(getquota -g $TSTID global curspace)
3239 [ $USED -lt $BLK_CNT ] &&
3240 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3241 if [ $project_supported == "yes" ]; then
3242 USED=$(getquota -p $TSTPRJID global curspace)
3243 [ $USED -lt $BLK_CNT ] && error \
3244 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3248 run_test 34 "Usage transfer for user & group & project"
3250 # usage is still accessible across restart
3252 local BLK_CNT=2 # MB
3254 setup_quota_test || error "setup quota failed with $?"
3256 echo "Write file..."
3257 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3258 error "write failed"
3259 is_project_quota_supported &&
3260 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3261 cancel_lru_locks osc
3263 echo "Wait for setattr on objects finished..."
3264 wait_delete_completed
3266 sync; sync_all_data || true
3268 echo "Save disk usage before restart"
3269 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3270 [ $ORIG_USR_SPACE -eq 0 ] &&
3271 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3272 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3273 [ $ORIG_USR_INODES -eq 0 ] &&
3274 error "Used inodes for user $TSTID is 0, expected 1"
3275 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3276 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3277 [ $ORIG_GRP_SPACE -eq 0 ] &&
3278 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3279 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3280 [ $ORIG_GRP_INODES -eq 0 ] &&
3281 error "Used inodes for group $TSTID is 0, expected 1"
3282 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3284 if is_project_quota_supported; then
3285 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3286 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3287 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3288 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3289 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3290 "Used inodes for project $TSTPRJID is 0, expected 1"
3291 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3299 echo "Verify disk usage after restart"
3300 local USED=$(getquota -u $TSTID global curspace)
3301 [ $USED -eq $ORIG_USR_SPACE ] ||
3302 error "Used space for user $TSTID changed from " \
3303 "$ORIG_USR_SPACE to $USED"
3304 USED=$(getquota -u $TSTID global curinodes)
3305 [ $USED -eq $ORIG_USR_INODES ] ||
3306 error "Used inodes for user $TSTID changed from " \
3307 "$ORIG_USR_INODES to $USED"
3308 USED=$(getquota -g $TSTID global curspace)
3309 [ $USED -eq $ORIG_GRP_SPACE ] ||
3310 error "Used space for group $TSTID changed from " \
3311 "$ORIG_GRP_SPACE to $USED"
3312 USED=$(getquota -g $TSTID global curinodes)
3313 [ $USED -eq $ORIG_GRP_INODES ] ||
3314 error "Used inodes for group $TSTID changed from " \
3315 "$ORIG_GRP_INODES to $USED"
3316 if [ $project_supported == "yes" ]; then
3317 USED=$(getquota -p $TSTPRJID global curinodes)
3318 [ $USED -eq $ORIG_PRJ_INODES ] ||
3319 error "Used inodes for project $TSTPRJID " \
3320 "changed from $ORIG_PRJ_INODES to $USED"
3321 USED=$(getquota -p $TSTPRJID global curspace)
3322 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3323 error "Used space for project $TSTPRJID "\
3324 "changed from $ORIG_PRJ_SPACE to $USED"
3327 # check if the vfs_dq_init() is called before writing
3328 echo "Append to the same file..."
3329 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3330 error "write failed"
3331 cancel_lru_locks osc
3332 sync; sync_all_data || true
3334 echo "Verify space usage is increased"
3335 USED=$(getquota -u $TSTID global curspace)
3336 [ $USED -gt $ORIG_USR_SPACE ] ||
3337 error "Used space for user $TSTID isn't increased" \
3338 "orig:$ORIG_USR_SPACE, now:$USED"
3339 USED=$(getquota -g $TSTID global curspace)
3340 [ $USED -gt $ORIG_GRP_SPACE ] ||
3341 error "Used space for group $TSTID isn't increased" \
3342 "orig:$ORIG_GRP_SPACE, now:$USED"
3343 if [ $project_supported == "yes" ]; then
3344 USED=$(getquota -p $TSTPRJID global curspace)
3345 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3346 error "Used space for project $TSTPRJID isn't " \
3347 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3350 run_test 35 "Usage is still accessible across reboot"
3352 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3355 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3356 skip "Old server doesn't have LU-5006 fix."
3358 setup_quota_test || error "setup quota failed with $?"
3360 # make sure the system is clean
3361 local USED=$(getquota -u $TSTID global curspace)
3363 error "Used space ($USED) for user $TSTID isn't 0."
3365 # create file with MDS_OPEN_DELAY_CREATE flag
3366 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3367 error "Create file failed"
3369 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3370 oflag=sync || error "Write file failed"
3372 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3374 # wait for setattr on objects finished..."
3375 wait_delete_completed
3377 USED=$(getquota -u $TSTID global curspace)
3378 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3380 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3384 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3385 skip "Old server doesn't have LU-8801 fix."
3387 [ "$UID" != 0 ] && skip_env "must run as root" && return
3389 setup_quota_test || error "setup quota failed with $?"
3391 # make sure the system is clean
3392 local USED=$(getquota -u $TSTID global curspace)
3394 error "Used space ($USED) for user $TSTID isn't 0."
3395 USED=$(getquota -u $TSTID2 global curspace)
3397 error "Used space ($USED) for user $TSTID2 isn't 0."
3399 local TESTFILE="$DIR/$tdir/$tfile"
3400 local file_cnt=10000
3402 # Generate id entries in accounting file
3403 echo "Create $file_cnt files..."
3404 for i in `seq $file_cnt`; do
3406 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3407 error "failed to chown $TESTFILE-$i"
3409 cancel_lru_locks osc
3410 sync; sync_all_data || true
3412 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3413 procf=${procf}.quota_slave.acct_user
3416 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3417 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3418 echo "Found $acct_cnt id entries"
3420 [ $file_cnt -eq $acct_cnt ] || {
3421 do_facet mds1 $LCTL get_param $procf
3422 error "skipped id entries"
3425 run_test 38 "Quota accounting iterator doesn't skip id entries"
3428 local TESTFILE="$DIR/$tdir/project"
3429 ! is_project_quota_supported &&
3430 skip "Project quota is not supported"
3432 setup_quota_test || error "setup quota failed with $?"
3435 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3436 [ $projectid -ne 0 ] &&
3437 error "Project id should be 0 not $projectid"
3438 change_project -p 1024 $TESTFILE
3439 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3440 [ $projectid -ne 1024 ] &&
3441 error "Project id should be 1024 not $projectid"
3443 stopall || error "failed to stopall (1)"
3446 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3447 [ $projectid -eq 1024 ] ||
3448 error "Project id should be 1024 not $projectid"
3450 run_test 39 "Project ID interface works correctly"
3453 ! is_project_quota_supported &&
3454 skip "Project quota is not supported"
3455 local dir1="$DIR/$tdir/dir1"
3456 local dir2="$DIR/$tdir/dir2"
3458 setup_quota_test || error "setup quota failed with $?"
3460 mkdir -p $dir1 $dir2
3461 change_project -sp 1 $dir1 && touch $dir1/1
3462 change_project -sp 2 $dir2
3464 ln $dir1/1 $dir2/1_link &&
3465 error "Hard link across different project quota should fail"
3468 run_test 40a "Hard link across different project ID"
3471 ! is_project_quota_supported &&
3472 skip "Project quota is not supported"
3473 local dir1="$DIR/$tdir/dir1"
3474 local dir2="$DIR/$tdir/dir2"
3476 setup_quota_test || error "setup quota failed with $?"
3477 mkdir -p $dir1 $dir2
3478 change_project -sp 1 $dir1 && touch $dir1/1
3479 change_project -sp 2 $dir2
3481 mv $dir1/1 $dir2/2 || error "mv failed $?"
3482 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3483 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3485 run_test 40b "Mv across different project ID"
3488 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3489 ! is_project_quota_supported &&
3490 skip "Project quota is not supported"
3492 setup_quota_test || error "setup quota failed with $?"
3493 local dir="$DIR/$tdir/dir"
3495 mkdir -p $dir && change_project -sp 1 $dir
3496 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3497 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3498 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3499 touch $dir/remote_dir/file
3500 #verify inherit works file for remote dir.
3501 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3502 [ "$projid" != "1" ] &&
3503 error "file under remote dir expected 1 not $projid"
3505 #Agent inode should be ignored for project quota
3506 local used=$(getquota -p 1 global curinodes)
3508 error "file count expected 3 got $used"
3510 run_test 40c "Remote child Dir inherit project quota properly"
3513 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3514 is_project_quota_supported || skip "Project quota is not supported"
3516 setup_quota_test || error "setup quota failed with $?"
3517 local dir="$DIR/$tdir/dir"
3520 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3521 change_project -sp $TSTPRJID $dir ||
3522 error "change project on $dir failed"
3523 for i in $(seq 5); do
3524 mkdir -p $dir/d$i/d$i ||
3525 error "mkdir $dir/d$i/d$i failed"
3526 local projid=$($LFS project -d $dir/d$i/d$i |
3528 [ "$projid" == "$TSTPRJID" ] ||
3529 error "projid id expected $TSTPRJID not $projid"
3530 touch $dir/d$i/d$i/file
3531 #verify inherit works file for stripe dir.
3532 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3533 [ "$projid" == "$TSTPRJID" ] ||
3534 error "file under remote dir expected 1 not $projid"
3537 # account should be 1 + (2 + 1) *10 + 1 * 5
3538 local used=$(getquota -p $TSTPRJID global curinodes)
3540 error "file count expected 36 got $used"
3542 run_test 40d "Stripe Directory inherit project quota properly"
3545 is_project_quota_supported ||
3546 skip "Project quota is not supported"
3547 setup_quota_test || error "setup quota failed with $?"
3548 local dir="$DIR/$tdir/dir"
3551 local projid=$((testnum * 1000))
3555 # enable mdt/ost quota
3556 set_mdt_qtype ugp || error "enable mdt quota failed"
3557 set_ost_qtype ugp || error "enable ost quota failed"
3559 test_mkdir -p $dir && change_project -sp $projid $dir
3560 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3561 error "set project quota failed"
3566 # check if df output works as expected
3567 echo "== global statfs: $MOUNT =="
3568 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3570 echo "== project statfs (prjid=$projid): $dir =="
3571 df -kP $dir; df -iP $dir
3572 local bused=$(getquota -p $projid global curspace)
3573 local iused=$(getquota -p $projid global curinodes)
3574 # note trailing space to match double printf from awk
3575 local expected="$blimit $bused $ilimit $iused "
3577 wait_update $HOSTNAME \
3578 "{ df -kP $dir; df -iP $dir; } |
3579 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3581 error "failed to get correct statfs for project quota"
3583 run_test 41 "df should return projid-specific values"
3586 ! is_project_quota_supported &&
3587 skip "Project quota is not supported"
3589 setup_quota_test || error "setup quota failed with $?"
3590 local dir1="$DIR/$tdir/dir1"
3591 local dir2="$DIR/$tdir/dir2"
3593 mkdir -p $dir1 && change_project -sp 1 $dir1
3594 mkdir -p $dir2 && change_project -sp 2 $dir2
3595 for num in $(seq 1 10); do
3596 touch $dir1/file_$num $dir2/file_$num
3597 ln -s $dir1/file_$num $dir1/file_$num"_link"
3598 ln -s $dir2/file_$num $dir2/file_$num"_link"
3601 count=$($LFS find --projid 1 $DIR | wc -l)
3602 [ "$count" != 21 ] && error "expected 21 but got $count"
3604 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3605 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3606 [ $count -eq 22 ] || error "expected 22 but got $count"
3608 run_test 50 "Test if lfs find --projid works"
3611 ! is_project_quota_supported &&
3612 skip "Project quota is not supported"
3613 setup_quota_test || error "setup quota failed with $?"
3614 local dir="$DIR/$tdir/dir"
3616 mkdir $dir && change_project -sp 1 $dir
3617 local used=$(getquota -p 1 global curinodes)
3618 [ $used != "1" ] && error "expected 1 got $used"
3623 used=$(getquota -p 1 global curinodes)
3624 [ $used != "4" ] && error "expected 4 got $used"
3626 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3628 cp $DIR/$tdir/6 $dir/6
3629 used=$(getquota -p 1 global curinodes)
3630 [ $used != "5" ] && error "expected 5 got $used"
3633 mv $DIR/$tdir/6 $dir/7
3634 used=$(getquota -p 1 global curinodes)
3635 [ $used -eq 6 ] || error "expected 6 got $used"
3637 run_test 51 "Test project accounting with mv/cp"
3640 ! is_project_quota_supported &&
3641 skip "Project quota is not supported"
3642 setup_quota_test || error "setup quota failed with $?"
3643 local dir="$DIR/$tdir/dir"
3644 mkdir $dir && change_project -sp 1 $dir
3646 touch $DIR/$tdir/file
3647 #Try renaming a file into the project. This should fail.
3648 for num in $(seq 1 2000); do
3649 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3650 error "rename should fail"
3654 run_test 52 "Rename across different project ID"
3657 ! is_project_quota_supported &&
3658 skip "Project quota is not supported"
3659 setup_quota_test || error "setup quota failed with $?"
3660 local dir="$DIR/$tdir/dir"
3661 mkdir $dir && change_project -s $dir
3662 [[ $($LFS project -d $dir) =~ " P " ]] ||
3663 error "inherit attribute should be set"
3665 change_project -C $dir
3666 [[ $($LFS project -d $dir) =~ " - " ]] ||
3667 error "inherit attribute should be cleared"
3669 run_test 53 "Project inherit attribute could be cleared"
3672 ! is_project_quota_supported &&
3673 skip "Project quota is not supported"
3674 setup_quota_test || error "setup quota failed with $?"
3675 local testfile="$DIR/$tdir/$tfile-0"
3677 #set project ID/inherit attribute
3678 change_project -sp $TSTPRJID $DIR/$tdir
3679 $RUNAS createmany -m ${testfile} 100 ||
3680 error "create many files failed"
3682 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3683 # one more count for directory itself */
3687 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3688 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3690 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3691 [ $proj_count1 -eq $proj_count ] ||
3692 error "c2: expected $proj_count got $proj_count1"
3694 #clear project but with kept projid
3695 change_project -rCk $DIR/$tdir
3696 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3697 [ $proj_count1 -eq 1 ] ||
3698 error "c3: expected 1 got $proj_count1"
3700 #verify projid untouched.
3701 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3703 [ $proj_count1 -eq $proj_count ] ||
3704 error "c4: expected $proj_count got $proj_count1"
3707 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3708 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3709 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3711 #this time clear all
3712 change_project -rC $DIR/$tdir
3713 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3714 [ $proj_count1 -eq 0 ] ||
3715 error "c6: expected 0 got $proj_count1"
3717 unlinkmany ${testfile} 100 ||
3718 error "unlink many files failed"
3720 run_test 54 "basic lfs project interface test"
3723 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3724 skip "Not supported before 2.10.58."
3725 setup_quota_test || error "setup quota failed with $?"
3727 set_ost_qtype $QTYPE || error "enable ost quota failed"
3730 #add second group to TSTUSR
3731 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3734 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3735 error "failed to dd"
3737 cancel_lru_locks osc
3738 sync; sync_all_data || true
3740 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3741 error "failed to setquota on group $TSTUSR2"
3743 $LFS quota -v -g $TSTUSR2 $DIR
3745 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3746 error "chgrp should failed with -EDQUOT"
3748 USED=$(getquota -g $TSTUSR2 global curspace)
3751 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3752 error "failed to setquota on group $TSTUSR2"
3754 $LFS quota -v -g $TSTUSR2 $DIR
3756 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3757 error "chgrp should succeed"
3759 $LFS quota -v -g $TSTUSR2 $DIR
3761 run_test 55 "Chgrp should be affected by group quota"
3764 setup_quota_test || error "setup quota failed with $?"
3766 set_ost_qtype $QTYPE || error "enable ost quota failed"
3769 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3770 erro "failed to set grace time for usr quota"
3771 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3772 awk '{print $4 $8}')
3773 if [ "x$grace_time" != "x10s;10s" ]; then
3774 $LFS quota -t -u $DIR
3775 error "expected grace time: 10s;10s, got:$grace_time"
3778 run_test 56 "lfs quota -t should work well"
3781 setup_quota_test || error "setup quota failed with $?"
3783 local dir="$DIR/$tdir/dir"
3786 #command can process further if it hit some errors
3787 $LFS project -sp 1 $dir/pipe
3788 touch $dir/aaa $dir/bbb
3789 mkdir $dir/subdir -p
3790 touch $dir/subdir/aaa $dir/subdir/bbb
3791 #create one invalid link file
3792 ln -s $dir/not_exist_file $dir/ccc
3793 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3794 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3796 run_test 57 "lfs project could tolerate errors"
3799 [ "$mds1_FSTYPE" != ldiskfs ] &&
3800 skip "ldiskfs only test"
3801 disable_project_quota
3802 setup_quota_test || error "setup quota failed with $?"
3805 local testfile="$DIR/$tdir/$tfile-0"
3806 #make sure it did not crash kernel
3807 touch $testfile && lfs project -sp 1 $testfile
3809 enable_project_quota
3811 run_test 59 "lfs project dosen't crash kernel with project disabled"
3814 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3815 skip "Needs MDS version 2.11.53 or later."
3816 setup_quota_test || error "setup quota failed with $?"
3818 local testfile=$DIR/$tdir/$tfile
3821 set_mdt_qtype "ug" || error "enable mdt quota failed"
3823 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3824 error "set quota failed"
3825 quota_show_check a g $TSTUSR
3827 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3828 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3829 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3830 error "create many files failed"
3832 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3834 # root user can overrun quota
3835 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3836 error "root user should succeed"
3838 run_test 60 "Test quota for root with setgid"
3840 # test default quota
3841 test_default_quota() {
3842 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3843 skip "Not supported before 2.11.51."
3848 local qprjid=$TSTPRJID
3852 local LIMIT=20480 #20M disk space
3853 local TESTFILE="$DIR/$tdir/$tfile-0"
3856 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3857 echo "Project quota is not supported" && return 0
3859 [ $qtype == "-u" ] && qdtype="-U"
3860 [ $qtype == "-g" ] && qdtype="-G"
3861 [ $qtype == "-p" ] && {
3866 [ $qres_type == "meta" ] && {
3867 LIMIT=10240 #10K inodes
3872 qpool_cmd="--pool $3"
3873 # pool quotas don't work properly without global limit
3874 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3875 error "set global limit failed"
3878 setup_quota_test || error "setup quota failed with $?"
3882 # enable mdt/ost quota
3883 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3884 set_ost_qtype $QTYPE || error "enable ost quota failed"
3886 log "set to use default quota"
3887 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3888 error "set $qid to use default quota failed"
3890 log "set default quota"
3891 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3892 error "set $qid default quota failed"
3894 log "get default quota"
3895 $LFS quota $qdtype $DIR || error "get default quota failed"
3897 if [ $qres_type == "data" ]; then
3898 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
3899 grep "$MOUNT" | awk '{print $2}')
3900 [ $SLIMIT -eq $LIMIT ] ||
3901 error "the returned default quota is wrong"
3903 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3905 [ $SLIMIT -eq $LIMIT ] ||
3906 error "the returned default quota is wrong"
3909 # make sure the system is clean
3910 local USED=$(getquota $qtype $qid global curspace)
3911 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3913 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3914 error "setstripe $TESTFILE failed"
3915 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3917 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3919 log "Test not out of quota"
3920 if [ $qres_type == "data" ]; then
3921 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3922 quota_error $qtype $qid "write failed, expect succeed"
3924 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3925 quota_error $qtype $qid "create failed, expect succeed"
3927 unlinkmany $TESTFILE $((LIMIT/2))
3930 log "Test out of quota"
3931 # flush cache, ensure noquota flag is set on client
3932 cancel_lru_locks osc
3933 cancel_lru_locks mdc
3934 sync; sync_all_data || true
3935 if [ $qres_type == "data" ]; then
3936 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3937 quota_error $qtype $qid "write succeed, expect EDQUOT"
3939 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3940 quota_error $qtype $qid "create succeed, expect EDQUOT"
3942 unlinkmany $TESTFILE $((LIMIT*2))
3946 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3947 error "setstripe $TESTFILE failed"
3948 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3950 log "Increase default quota"
3952 # LU-4505: sleep 5 seconds to enable quota acquire
3955 # increase default quota
3956 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
3957 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
3959 cancel_lru_locks osc
3960 cancel_lru_locks mdc
3961 sync; sync_all_data || true
3962 if [ $qres_type == "data" ]; then
3963 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3964 quota_error $qtype $qid "write failed, expect succeed"
3966 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3967 quota_error $qtype $qid "create failed, expect succeed"
3969 unlinkmany $TESTFILE $((LIMIT*2))
3972 log "Set quota to override default quota"
3973 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3974 error "set $qid quota failed"
3976 cancel_lru_locks osc
3977 cancel_lru_locks mdc
3978 sync; sync_all_data || true
3979 if [ $qres_type == "data" ]; then
3980 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3981 quota_error $qtype $qid "write succeed, expect EQUOT"
3983 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3984 quota_error $qtype $qid "create succeed, expect EQUOT"
3986 unlinkmany $TESTFILE $((LIMIT*2))
3989 log "Set to use default quota again"
3991 # LU-4505: sleep 5 seconds to enable quota acquire
3994 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3995 error "set $qid to use default quota failed"
3997 cancel_lru_locks osc
3998 cancel_lru_locks mdc
3999 sync; sync_all_data || true
4000 if [ $qres_type == "data" ]; then
4001 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4002 quota_error $qtype $qid "write failed, expect succeed"
4004 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4005 quota_error $qtype $qid "create failed, expect succeed"
4007 unlinkmany $TESTFILE $((LIMIT*2))
4012 wait_delete_completed || error "wait_delete_completed failed"
4013 sync_all_data || true
4015 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4016 error "reset default quota failed"
4017 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4018 error "reset quota failed"
4023 test_default_quota "-u" "data"
4024 test_default_quota "-u" "meta"
4025 test_default_quota "-g" "data"
4026 test_default_quota "-g" "meta"
4027 test_default_quota "-p" "data"
4028 test_default_quota "-p" "meta"
4030 run_test 61 "default quota tests"
4033 ! is_project_quota_supported &&
4034 skip "Project quota is not supported"
4035 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4036 skip "chattr did not support project quota"
4037 setup_quota_test || error "setup quota failed with $?"
4038 local testdir=$DIR/$tdir/
4040 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4041 change_project -s $testdir
4042 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4043 error "inherit attribute should be set"
4044 # chattr used FS_IOC_SETFLAGS ioctl
4045 $RUNAS chattr -P $testdir &&
4046 error "regular user clear inherit should fail"
4047 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4048 error "inherit attribute should still be set"
4049 chattr -P $testdir || error "root failed to clear inherit"
4050 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4051 error "inherit attribute should be cleared"
4054 run_test 62 "Project inherit should be only changed by root"
4057 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4058 skip "Not supported before 2.11.55"
4062 local dd_failed=false
4063 local tdir_dom=${tdir}_dom
4064 local LIMIT=20480 #20M
4066 [ $qtype == "p" ] && ! is_project_quota_supported &&
4067 echo "Project quota is not supported" && return 0
4069 [ $qtype == "p" ] && qid=$TSTPRJID
4071 setup_quota_test || error "setup quota failed with $?"
4075 # enable mdt/ost quota
4076 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4077 set_ost_qtype $QTYPE || error "enable ost quota failed"
4079 # make sure the system is clean
4080 local USED=$(getquota -$qtype $qid global curspace)
4081 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4083 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4085 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4086 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4087 error "setstripe $tdir_dom failed"
4088 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4090 [ $qtype == "p" ] && {
4091 change_project -sp $TSTPRJID $DIR/$tdir
4092 change_project -sp $TSTPRJID $DIR/$tdir_dom
4095 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4096 error "set $qid quota failed"
4098 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4099 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4103 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4105 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4106 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4110 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4112 rm -f $DIR/$tdir_dom/*
4114 # flush cache, ensure noquota flag is set on client
4115 cancel_lru_locks osc
4116 cancel_lru_locks mdc
4117 sync; sync_all_data || true
4121 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4122 quota_error $qtype $qid "write failed, expect succeed"
4124 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4125 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4129 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4132 rm -f $DIR/$tdir_dom/*
4134 # flush cache, ensure noquota flag is set on client
4135 cancel_lru_locks osc
4136 cancel_lru_locks mdc
4137 sync; sync_all_data || true
4141 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4142 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4146 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4148 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4149 quota_error $qtype $qid "write succeed, expect EDQUOT"
4152 rm -fr $DIR/$tdir_dom
4154 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4155 error "reset usr quota failed"
4163 run_test 63 "quota on DoM tests"
4166 ! is_project_quota_supported &&
4167 skip "Project quota is not supported"
4168 setup_quota_test || error "setup quota failed with $?"
4169 local dir1="$DIR/$tdir/"
4172 ln -s $dir1/file $dir1/file_link
4175 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4176 error "set project should succeed"
4178 used=$(getquota -p $TSTPRJID global curinodes)
4179 [ $used -eq 4 ] || error "expected 4 got $used"
4180 $LFS project -rC $dir1 >&/dev/null ||
4181 error "clear project should succeed"
4183 used=$(getquota -p $TSTPRJID global curinodes)
4184 [ $used -eq 0 ] || error "expected 0 got $used"
4186 run_test 64 "lfs project on non dir/files should succeed"
4190 local TESTFILE="$DIR/$tdir/$tfile-0"
4192 setup_quota_test || error "setup quota failed with $?"
4193 set_ost_qtype $QTYPE || error "enable ost quota failed"
4197 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4198 error "failed to write"
4199 # flush cache, ensure noquota flag is set on client
4200 cancel_lru_locks osc
4201 sync; sync_all_data || true
4203 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4204 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4205 local quota_all=$($RUNAS $LFS quota $DIR)
4207 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4208 error "usr quota not match"
4209 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4210 error "grp quota not match"
4212 run_test 65 "Check lfs quota result"
4215 ! is_project_quota_supported &&
4216 skip "Project quota is not supported"
4217 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4218 skip "Not supported before 2.12.4"
4219 setup_quota_test || error "setup quota failed with $?"
4220 local old=$(do_facet mds1 $LCTL get_param -n \
4221 mdt.*.enable_chprojid_gid | head -1)
4222 local testdir=$DIR/$tdir/foo
4224 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4225 stack_trap "do_facet mds1 $LCTL \
4226 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4228 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4229 chown -R $TSTID:$TSTID $testdir
4230 change_project -sp $TSTPRJID $testdir
4231 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4233 $RUNAS lfs project -p 0 $testdir/foo &&
4234 error "nonroot user should fail to set projid"
4236 $RUNAS lfs project -C $testdir/foo &&
4237 error "nonroot user should fail to clear projid"
4239 change_project -C $testdir/foo || error "failed to clear project"
4241 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4242 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4243 "failed to set projid with normal user when enable_chprojid_gid=-1"
4245 $RUNAS lfs project -rC $testdir/ || error \
4246 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4248 touch $testdir/bar || error "failed touch $testdir/bar"
4249 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4250 "normal user should not be able to set projid on root owned file"
4252 change_project -p $TSTPRJID $testdir/bar || error \
4253 "root should be able to change its own file's projid"
4255 run_test 66 "nonroot user can not change project state in default"
4262 local short_qtype=${qtype:0:1}
4265 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4267 quota_usr) _runas=$RUNAS;;
4268 quota_2usr) _runas=$RUNAS2;;
4269 *) error "unknown quota parameter $4";;
4274 $_runas $DD of=$file count=$size ||
4275 quota_error $short_qtype $TSTUSR \
4276 "$qtype write failure, but expect success"
4278 cancel_lru_locks osc
4280 sync; sync_all_data || true
4289 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4291 do_facet mds1 $LCTL get_param $param |
4292 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4297 local testfile="$DIR/$tdir/$tfile-0"
4298 local testfile2="$DIR/$tdir/$tfile-1"
4299 local testfile3="$DIR/$tdir/$tfile-2"
4300 local qpool="qpool1"
4306 [ "$ost1_FSTYPE" == zfs ] &&
4307 skip "ZFS grants some block space together with inode"
4309 setup_quota_test || error "setup quota failed with $?"
4312 set_ost_qtype $QTYPE || error "enable ost quota failed"
4315 log "User quota (block hardlimit:$limit MB)"
4316 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4317 error "set user quota failed"
4319 # make sure the system is clean
4320 used=$(getquota -u $TSTUSR global curspace)
4321 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4323 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4324 echo "granted 0x0 before write $granted"
4326 # trigger reintegration
4327 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4328 procf=${procf}quota_slave.force_reint
4329 do_facet ost1 $LCTL set_param $procf=1 ||
4330 error "force reintegration failed"
4331 wait_ost_reint "u" || error "reintegration failed"
4332 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4333 [ $granted -ne 0 ] &&
4334 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4336 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4337 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4339 # write 10 MB to testfile
4340 test_67_write "$testfile" "user" 10 "quota_usr"
4342 # create qpool and add OST1
4343 pool_add $qpool || error "pool_add failed"
4344 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4345 # as quota_usr hasn't limits, lqe may absent. But it should be
4346 # created after the 1st direct qmt_get.
4347 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4349 # check granted - should be 0, as testfile is located only on OST0
4350 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4351 echo "global granted $granted"
4352 granted=$(getgranted $qpool "dt" $TSTID "usr")
4353 echo "$qpool granted $granted"
4354 [ $granted -ne 0 ] &&
4355 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4357 # add OST0 to qpool and check granted space
4358 pool_add_targets $qpool 0 1 ||
4359 error "pool_add_targets failed"
4360 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4361 echo "Granted $granted_mb MB"
4362 #should be 10M + qunit for each OST
4363 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4364 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4366 $LFS setstripe $testfile2 -c 1 -i 1 ||
4367 error "setstripe $testfile2 failed"
4368 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4369 # Write from another user and check that qpool1
4370 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4371 test_67_write "$testfile2" "user" 10 "quota_2usr"
4372 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4373 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4374 [ $granted -ne 0 ] &&
4375 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4377 # Granted space for quota_2usr in qpool1 should appear only
4378 # when global lqe for this user becomes enforced.
4379 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4380 error "set user quota failed"
4381 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4382 echo "granted_mb $granted_mb"
4383 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4384 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4386 $LFS setstripe $testfile3 -c 1 -i 0 ||
4387 error "setstripe $testfile3 failed"
4388 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4389 test_67_write "$testfile3" "user" 10 "quota_2usr"
4390 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4391 echo "$testfile3 granted_mb $granted_mb"
4392 [ $granted_mb -eq $limit ] ||
4393 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4395 # remove OST1 from the qpool1 and check granted space
4396 # should be 0 for TSTUSR and 10M for TSTUSR2
4397 pool_remove_target $qpool 0
4398 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4399 [ $granted_mb -eq 0 ] ||
4400 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4401 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4402 [ $granted_mb -eq 10 ] ||
4403 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4406 wait_delete_completed || error "wait_delete_completed failed"
4407 sync_all_data || true
4408 used=$(getquota -u $TSTUSR global curspace)
4409 [ $used -eq 0 ] || quota_error u $TSTUSR \
4410 "user quota isn't released after deletion"
4412 run_test 67 "quota pools recalculation"
4419 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4420 awk '/usr/ {getline; print $2}'
4425 local qpool="qpool1"
4428 setup_quota_test || error "setup quota failed with $?"
4431 set_ost_qtype $QTYPE || error "enable ost quota failed"
4433 # check slave number for glbal pool
4434 local nr=$(get_slave_nr "0x0" "usr")
4435 echo "nr result $nr"
4436 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4437 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4439 # create qpool and add OST1
4440 pool_add $qpool || error "pool_add failed"
4441 nr=$(get_slave_nr $qpool "usr")
4442 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4445 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4446 nr=$(get_slave_nr $qpool "usr")
4447 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4450 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4451 nr=$(get_slave_nr $qpool "usr")
4452 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4455 pool_remove_target $qpool 0
4456 nr=$(get_slave_nr $qpool "usr")
4457 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4460 pool_remove_target $qpool 1
4461 nr=$(get_slave_nr $qpool "usr")
4462 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4464 # Check again that all is fine with global pool
4465 nr=$(get_slave_nr "0x0" "usr")
4466 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4467 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4469 run_test 68 "slave number in quota pool changed after each add/remove OST"
4473 local global_limit=200 # MB
4475 local testfile="$DIR/$tdir/$tfile-0"
4476 local dom0="$DIR/$tdir/dom0"
4477 local qpool="qpool1"
4480 setup_quota_test || error "setup quota failed with $?"
4483 set_ost_qtype $QTYPE || error "enable ost quota failed"
4484 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4486 # Save DOM only at MDT0
4487 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4488 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4490 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4492 # create qpool and add OST0
4493 pool_add $qpool || error "pool_add failed"
4494 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4496 log "User quota (block hardlimit:$global_limit MB)"
4497 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4498 error "set user quota failed"
4500 log "User quota (block hardlimit:$limit MB)"
4501 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4502 error "set user quota failed"
4504 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4505 quota_error u $TSTUSR "write failed"
4507 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4508 oflag=sync || quota_error u $TSTUSR "write failed"
4510 $RUNAS $DD of=$testfile count=$limit || true
4512 # flush cache, ensure noquota flag is set on client
4513 cancel_lru_locks osc
4514 sync; sync_all_data || true
4516 # MDT0 shouldn't get EDQUOT with glimpse.
4517 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4518 quota_error u $TSTUSR \
4519 "user write success, but expect EDQUOT"
4521 # Now all members of qpool1 should get EDQUOT. Expect success
4522 # when write to DOM on MDT0, as it belongs to global pool.
4523 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4524 oflag=sync || quota_error u $TSTUSR "write failed"
4526 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4527 oflag=sync || quota_error u $TSTUSR "write failed"
4529 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4533 local qpool="qpool1"
4538 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4539 skip "Needs a client >= $VERSION_WITH_QP"
4541 setup_quota_test || error "setup quota failed with $?"
4543 # MDS returns EFAULT for unsupported quotactl command
4544 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4546 # create qpool and add OST0
4547 pool_add $qpool || error "pool_add failed"
4548 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4550 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4552 [ $rc -eq $err ] || error "setquota res $rc != $err"
4554 # If MDS supports QP, check that limit was set properly.
4555 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4556 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4557 echo "hard limit $bhard limit $limit"
4558 [ $bhard -ne $((limit*1024)) ] &&
4559 error "bhard:$bhard for $qpool!=$((limit*1024))"
4562 $LFS quota -u $TSTUSR --pool $qpool $DIR
4564 [ $rc -eq $err ] || error "quota res $rc != $err"
4566 run_test 70 "check lfs setquota/quota with a pool option"
4571 local global_limit=100 # MB
4572 local testfile="$DIR/$tdir/$tfile-0"
4573 local qpool="qpool1"
4574 local qpool2="qpool2"
4576 [ "$ost1_FSTYPE" == zfs ] &&
4577 skip "ZFS grants some block space together with inode"
4578 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4580 setup_quota_test || error "setup quota failed with $?"
4583 set_ost_qtype $QTYPE || error "enable ost quota failed"
4586 log "User quota (block hardlimit:$global_limit MB)"
4587 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4588 error "set user quota failed"
4590 pool_add $qpool || error "pool_add failed"
4591 pool_add_targets $qpool 0 1 ||
4592 error "pool_add_targets failed"
4594 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4595 error "set user quota failed"
4597 pool_add $qpool2 || error "pool_add failed"
4598 pool_add_targets $qpool2 1 1 ||
4599 error "pool_add_targets failed"
4601 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4602 error "set user quota failed"
4604 # make sure the system is clean
4605 local used=$(getquota -u $TSTUSR global curspace)
4608 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4610 # create 1st component 1-10M
4611 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4612 #create 2nd component 10-30M
4613 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4614 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4616 # сheck normal use and out of quota with PFL
4617 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4618 test_1_check_write $testfile "user" $((limit*2))
4620 wait_delete_completed || error "wait_delete_completed failed"
4621 sync_all_data || true
4622 used=$(getquota -u $TSTUSR global curspace)
4623 [ $used -ne 0 ] && quota_error u $TSTUSR \
4624 "user quota isn't released after deletion"
4626 # create 1st component 1-10M
4627 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4628 # create 2nd component 10-30M
4629 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4630 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4632 # write to the 2nd component
4633 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4634 quota_error u $TSTUSR \
4635 "write failure, but expect success"
4636 # this time maybe cache write, ignore it's failure
4637 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4638 cancel_lru_locks osc
4639 sync; sync_all_data || true
4640 # write over limit in qpool2(2nd component 10-30M)
4641 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4642 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4643 # write to the 1st component - OST0 is empty
4644 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4645 quota_error u $TSTUSR "write failed"
4647 run_test 71a "Check PFL with quota pools"
4651 local global_limit=1000 # MB
4652 local limit1=160 # MB
4653 local limit2=10 # MB
4654 local testfile="$DIR/$tdir/$tfile-0"
4655 local qpool="qpool1"
4656 local qpool2="qpool2"
4658 [ "$ost1_FSTYPE" == zfs ] &&
4659 skip "ZFS grants some block space together with inode"
4660 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4662 setup_quota_test || error "setup quota failed with $?"
4665 set_ost_qtype $QTYPE || error "enable ost quota failed"
4668 log "User quota (block hardlimit:$global_limit MB)"
4669 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4670 error "set user quota failed"
4672 pool_add $qpool || error "pool_add failed"
4673 pool_add_targets $qpool 0 1 ||
4674 error "pool_add_targets failed"
4676 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4677 error "set user quota failed"
4679 pool_add $qpool2 || error "pool_add failed"
4680 pool_add_targets $qpool2 1 1 ||
4681 error "pool_add_targets failed"
4683 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4684 error "set user quota failed"
4686 # make sure the system is clean
4687 local used=$(getquota -u $TSTUSR global curspace)
4690 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4692 # First component is on OST0, 2nd on OST1
4693 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4694 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4696 # fill the 1st component on OST0
4697 $RUNAS $DD of=$testfile count=128 ||
4698 quota_error u $TSTUSR "write failed"
4699 # write to the 2nd cmpnt on OST1
4700 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4701 quota_error u $TSTUSR "write failed"
4702 # this time maybe cache write, ignore it's failure
4703 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4705 cancel_lru_locks osc
4706 sync; sync_all_data || true
4707 # write over limit in qpool2
4708 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4709 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4712 run_test 71b "Check SEL with quota pools"
4717 local global_limit=50 # MB
4718 local testfile="$DIR/$tdir/$tfile-0"
4719 local qpool="qpool1"
4722 setup_quota_test || error "setup quota failed with $?"
4725 set_ost_qtype $QTYPE || error "enable ost quota failed"
4728 log "User quota (block hardlimit:$global_limit MB)"
4729 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4730 error "set user quota failed"
4732 pool_add $qpool || error "pool_add failed"
4733 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4735 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4736 error "set user quota failed"
4738 # make sure the system is clean
4739 local used=$(getquota -u $TSTUSR global curspace)
4741 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4743 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4745 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4746 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4747 test_1_check_write $testfile "user" $limit
4748 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4750 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4751 # check that lfs quota -uv --pool prints only OST that
4752 # was added in a pool
4753 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4754 grep "OST\|MDT" && error "$qpool consists wrong targets"
4757 run_test 72 "lfs quota --pool prints only pool's OSTs"
4761 local qpool="qpool1"
4765 pool_add $qpool || error "pool_add failed"
4766 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4767 error "pool_add_targets failed"
4769 test_default_quota "-u" "data" "qpool1"
4771 run_test 73a "default limits at OST Pool Quotas"
4775 local TESTFILE1="$DIR/$tdir/$tfile-1"
4777 local qpool="qpool1"
4781 setup_quota_test || error "setup quota failed with $?"
4783 set_ost_qtype $QTYPE || error "enable ost quota failed"
4785 # pool quotas don't work properly without global limit
4786 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4787 error "set global limit failed"
4789 pool_add $qpool || error "pool_add failed"
4790 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4791 error "pool_add_targets failed"
4793 log "set default quota for $qpool"
4794 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
4795 error "set default quota failed"
4797 log "Write from user that hasn't lqe"
4798 # Check that it doesn't cause a panic or a deadlock
4799 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
4800 # Have to use RUNAS_ID as resetquota creates lqes in
4801 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
4802 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
4804 cancel_lru_locks osc
4805 sync; sync_all_data || true
4807 run_test 73b "default OST Pool Quotas limit for new user"
4811 local global_limit=200 # 200M
4812 local limit=10 # 10M
4813 local limit2=50 # 50M
4814 local qpool="qpool1"
4815 local qpool2="qpool2"
4819 setup_quota_test || error "setup quota failed with $?"
4822 set_ost_qtype $QTYPE || error "enable ost quota failed"
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 0 1 ||
4829 error "pool_add_targets failed"
4831 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4832 error "set user quota failed"
4834 pool_add $qpool2 || error "pool_add failed"
4835 pool_add_targets $qpool2 1 1 ||
4836 error "pool_add_targets failed"
4838 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4839 error "set user quota failed"
4841 tmp=$(getquota -u $TSTUSR global bhardlimit)
4842 [ $tmp -eq $((global_limit * 1024)) ] ||
4843 error "wrong global limit $global_limit"
4845 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4846 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4848 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
4849 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
4851 # check limits in pools
4852 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4853 grep -A4 $qpool | awk 'NR == 4{print $4}')
4854 echo "pool limit for $qpool $tmp"
4855 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
4856 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4857 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
4858 echo "pool limit for $qpool2 $tmp"
4859 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
4861 run_test 74 "check quota pools per user"
4863 function cleanup_quota_test_75()
4865 do_facet mgs $LCTL nodemap_modify --name default \
4866 --property admin --value 1
4867 do_facet mgs $LCTL nodemap_modify --name default \
4868 --property trusted --value 1
4869 do_facet mgs $LCTL nodemap_modify --name default \
4870 --property squash_uid --value 99
4871 do_facet mgs $LCTL nodemap_modify --name default \
4872 --property squash_gid --value 99
4874 wait_nm_sync default admin_nodemap
4875 wait_nm_sync default trusted_nodemap
4877 do_facet mgs $LCTL nodemap_activate 0
4880 resetquota -u $TSTUSR
4884 local dd_failed=false
4885 local LIMIT=20480 #20M
4888 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4889 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4890 oflag=sync || dd_failed=true
4893 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
4895 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
4896 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4897 oflag=sync || dd_failed=true
4900 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
4902 rm -f $DIR/$tdir_dom/*
4904 # flush cache, ensure noquota flag is set on client
4906 sync; sync_all_data || true
4910 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
4911 quota_error u $qid "write failed, expect succeed (2)"
4913 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4914 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4915 oflag=sync || dd_failed=true
4918 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
4921 rm -f $DIR/$tdir_dom/*
4923 # flush cache, ensure noquota flag is set on client
4925 sync; sync_all_data || true
4929 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4930 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4931 oflag=sync || dd_failed=true
4934 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
4936 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4937 quota_error u $qid "write succeed, expect EDQUOT (3)"
4943 local soft_limit=10 # MB
4944 local hard_limit=20 # MB
4945 local limit=$soft_limit
4946 local testfile="$DIR/$tdir/$tfile-0"
4947 local grace=20 # seconds
4948 local tdir_dom=${tdir}_dom
4950 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
4954 setup_quota_test || error "setup quota failed with $?"
4955 stack_trap cleanup_quota_test_75 EXIT
4958 set_ost_qtype $QTYPE || error "enable ost quota failed"
4959 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4961 local used=$(getquota -u $TSTID global curspace)
4962 $LFS setquota -t -u --block-grace $grace --inode-grace \
4963 $MAX_IQ_TIME $DIR || error "set user grace time failed"
4964 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
4965 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
4966 error "set user quota failed"
4968 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
4969 mkdir $DIR/$tdir_dom
4970 chmod 777 $DIR/$tdir_dom
4971 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4972 error "setstripe $tdir_dom failed"
4974 do_facet mgs $LCTL nodemap_activate 1
4976 do_facet mgs $LCTL nodemap_modify --name default \
4977 --property admin --value 0
4978 do_facet mgs $LCTL nodemap_modify --name default \
4979 --property trusted --value 0
4980 do_facet mgs $LCTL nodemap_modify --name default \
4981 --property deny_unknown --value 0
4982 do_facet mgs $LCTL nodemap_modify --name default \
4983 --property squash_uid --value $TSTID
4984 do_facet mgs $LCTL nodemap_modify --name default \
4985 --property squash_gid --value $TSTID
4986 cancel_lru_locks mdc
4987 wait_nm_sync default admin_nodemap
4988 wait_nm_sync default trusted_nodemap
4989 wait_nm_sync default squash_uid
4991 # mmap write when over soft limit
4993 $DD of=$testfile count=${limit} ||
4994 quota_error a "root write failure, but expect success (1)"
4995 OFFSET=$((limit * 1024))
4996 cancel_lru_locks osc
4998 echo "Write to exceed soft limit"
4999 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5000 quota_error a $TSTUSR "root write failure, but expect success (2)"
5001 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5002 cancel_lru_locks osc
5004 echo "mmap write when over soft limit"
5005 $MULTIOP $testfile.mmap OT40960SMW ||
5006 quota_error a $TSTUSR "mmap write failure, but expect success"
5007 cancel_lru_locks osc
5009 wait_delete_completed || error "wait_delete_completed failed (1)"
5010 sync_all_data || true
5012 # test for user hard limit
5015 $DD of=$testfile bs=1M count=$((limit/2)) ||
5016 quota_error u $TSTID \
5017 "root write failure, but expect success (3)"
5019 log "Write out of block quota ..."
5020 # possibly a cache write, ignore failure
5021 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5022 # flush cache, ensure noquota flag is set on client
5023 cancel_lru_locks osc
5024 sync; sync_all_data || true
5025 # sync forced cache flush, but did not guarantee that slave
5026 # got new edquot through glimpse, so wait to make sure
5028 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5029 quota_error u $TSTID \
5030 "user write success, but expect EDQUOT"
5032 wait_delete_completed || error "wait_delete_completed failed (2)"
5033 sync_all_data || true
5034 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5035 quota_error u $TSTID "user quota not released after deletion"
5039 run_test 75 "nodemap squashed root respects quota enforcement"
5042 ! is_project_quota_supported &&
5043 skip "skip project quota unsupported"
5045 setup_quota_test || error "setup quota failed with $?"
5048 local testfile="$DIR/$tdir/$tfile-0"
5051 $LFS project -p 4294967295 $testfile &&
5052 error "set project ID should fail"
5055 run_test 76 "project ID 4294967295 should be not allowed"
5059 mount_client $MOUNT2 "ro"
5060 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5061 error "lfs setquota should fail in read-only Lustre mount"
5064 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5068 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5069 skip "need OST at least 2.14.55"
5070 check_set_fallocate_or_skip
5072 setup_quota_test || error "setup quota failed with $?"
5075 set_ost_qtype $QTYPE || error "enable ost quota failed"
5077 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5078 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5081 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5082 error "lfs setquota failed"
5085 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5087 kbytes=$(lfs quota -u $TSTUSR $DIR |
5088 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5089 echo "kbytes returned:$kbytes"
5091 # For file size of 204800. We should be having roughly 200 kbytes
5092 # returned. Anything alarmingly low (50 taken as arbitrary value)
5093 # would bail out this TC. Also this also avoids $kbytes of 0
5094 # to be used in calculation below.
5095 (( $kbytes > 50 )) ||
5096 error "fallocate did not use quota. kbytes returned:$kbytes"
5098 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5099 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5101 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5102 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5103 error "fallocate did not use quota correctly"
5105 run_test 78 "Check fallocate increase quota usage"
5109 local qpool="qpool1"
5110 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5111 local stopf=$TMP/$tfile
5113 do_facet mds1 "touch $stopf"
5114 stack_trap "do_facet mds1 'rm -f $stopf'"
5115 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5117 pool_add $qpool || error "pool_add failed"
5118 do_facet mds1 "rm $stopf"
5121 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5125 local dir1="$DIR/$tdir/dir1"
5126 local dir2="$DIR/$tdir/dir2"
5127 local TESTFILE0="$dir1/$tfile-0"
5128 local TESTFILE1="$dir1/$tfile-1"
5129 local TESTFILE2="$dir1/$tfile-2"
5130 local TESTFILE3="$dir2/$tfile-0"
5131 local global_limit=100 # 100M
5132 local limit=10 # 10M
5133 local qpool="qpool1"
5135 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5137 [ "$ost1_FSTYPE" == zfs ] &&
5138 skip "ZFS grants some block space together with inode"
5139 setup_quota_test || error "setup quota failed with $?"
5140 set_ost_qtype $QTYPE || error "enable ost quota failed"
5142 # make sure the system is clean
5143 local used=$(getquota -u $TSTUSR global curspace)
5144 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5146 pool_add $qpool || error "pool_add failed"
5147 pool_add_targets $qpool 0 1 ||
5148 error "pool_add_targets failed"
5150 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5151 error "set user quota failed"
5153 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5154 error "set user quota failed"
5155 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5156 error "set user quota failed"
5158 mkdir -p $dir1 || error "failed to mkdir"
5159 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5160 mkdir -p $dir2 || error "failed to mkdir"
5161 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5163 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5164 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5169 $LFS quota -uv $TSTUSR $DIR
5170 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5171 do_facet mds1 $LCTL set_param fail_loc=0xa06
5172 $RUNAS $DD of=$TESTFILE3 count=3 ||
5173 quota_error u $TSTUSR "write failed"
5174 $RUNAS $DD of=$TESTFILE2 count=7 ||
5175 quota_error u $TSTUSR "write failed"
5176 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5177 quota_error u $TSTUSR "write failed"
5180 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5184 do_facet mds1 $LCTL set_param fail_loc=0
5185 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5186 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5187 # OST0 needs some time to update quota usage after removing TESTFILE2
5189 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5190 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5191 quota_error u $TSTUSR "write failure, but expect success"
5193 run_test 80 "check for EDQUOT after OST failover"
5196 local global_limit=20 # 100M
5197 local testfile="$DIR/$tdir/$tfile-0"
5198 local qpool="qpool1"
5201 setup_quota_test || error "setup quota failed with $?"
5204 set_ost_qtype $QTYPE || error "enable ost quota failed"
5207 log "User quota (block hardlimit:$global_limit MB)"
5208 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5210 pool_add $qpool || error "pool_add failed"
5211 #define OBD_FAIL_QUOTA_RECALC 0xA07
5212 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5213 # added OST casues to start pool recalculation
5214 pool_add_targets $qpool 0 0 1
5215 stop mds1 -f || error "MDS umount failed"
5217 #start mds1 back to destroy created pool
5218 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5221 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5225 do_nodes $(comma_list $(nodes_list)) \
5226 "lctl set_param -n debug=-quota,trace"
5227 if $PQ_CLEANUP; then
5228 disable_project_quota
5231 reset_quota_settings
5236 check_and_cleanup_lustre
5237 export QUOTA_AUTO=$QUOTA_AUTO_OLD