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"
1111 # test inode hardlimit
1113 local TESTFILE="$DIR/$tdir/$tfile-0"
1114 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1115 qmt.$FSNAME-QMT0000.md-0x0.info |
1116 awk '/least qunit/{ print $3 }')
1117 local L2=$(do_facet mds1 $LCTL get_param -n \
1118 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1120 [ $L2 -le $LIMIT ] || LIMIT=$L2
1122 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1124 local FREE_INODES=$(mdt_free_inodes 0)
1125 echo "$FREE_INODES free inodes on master MDT"
1126 [ $FREE_INODES -lt $LIMIT ] &&
1127 skip "not enough free inodes $FREE_INODES required $LIMIT"
1129 setup_quota_test || error "setup quota failed with $?"
1132 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1135 log "User quota (inode hardlimit:$LIMIT files)"
1136 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1137 error "set user quota failed"
1139 # make sure the system is clean
1140 local USED=$(getquota -u $TSTUSR global curinodes)
1141 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1143 log "Create $LIMIT files ..."
1144 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1145 quota_error u $TSTUSR "user create failure, but expect success"
1146 log "Create out of file quota ..."
1147 $RUNAS touch ${TESTFILE}_xxx &&
1148 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1151 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1152 rm -f ${TESTFILE}_xxx
1153 wait_delete_completed
1155 USED=$(getquota -u $TSTUSR global curinodes)
1156 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1157 "user quota isn't released after deletion"
1158 resetquota -u $TSTUSR
1161 log "--------------------------------------"
1162 log "Group quota (inode hardlimit:$LIMIT files)"
1163 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1164 error "set group quota failed"
1166 TESTFILE=$DIR/$tdir/$tfile-1
1167 # make sure the system is clean
1168 USED=$(getquota -g $TSTUSR global curinodes)
1169 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1171 log "Create $LIMIT files ..."
1172 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1173 quota_error g $TSTUSR "group create failure, but expect success"
1174 log "Create out of file quota ..."
1175 $RUNAS touch ${TESTFILE}_xxx &&
1176 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1179 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1180 rm -f ${TESTFILE}_xxx
1181 wait_delete_completed
1183 USED=$(getquota -g $TSTUSR global curinodes)
1184 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1185 "user quota isn't released after deletion"
1187 resetquota -g $TSTUSR
1188 ! is_project_quota_supported &&
1189 echo "Skip project quota is not supported" && return 0
1192 log "--------------------------------------"
1193 log "Project quota (inode hardlimit:$LIMIT files)"
1194 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1195 error "set project quota failed"
1197 TESTFILE=$DIR/$tdir/$tfile-1
1198 # make sure the system is clean
1199 USED=$(getquota -p $TSTPRJID global curinodes)
1201 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1203 change_project -sp $TSTPRJID $DIR/$tdir
1204 log "Create $LIMIT files ..."
1205 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1206 $TSTPRJID "project create fail, but expect success"
1207 log "Create out of file quota ..."
1208 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1209 "project create success, but expect EDQUOT"
1210 change_project -C $DIR/$tdir
1213 USED=$(getquota -p $TSTPRJID global curinodes)
1214 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1215 "project quota isn't released after deletion"
1218 run_test 2 "File hard limit (normal use and out of quota)"
1227 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1228 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1232 $LFS setstripe $testfile -c 1 -i 0
1233 chown $TSTUSR.$TSTUSR $testfile
1234 [ "$qtype" == "p" ] && is_project_quota_supported &&
1235 change_project -p $TSTPRJID $testfile
1237 echo "Write up to soft limit"
1238 $RUNAS $DD of=$testfile count=$limit ||
1239 quota_error a $TSTUSR "write failure, but expect success"
1240 OFFSET=$((limit * 1024))
1241 cancel_lru_locks osc
1243 echo "Write to exceed soft limit"
1244 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1245 quota_error a $TSTUSR "write failure, but expect success"
1246 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1247 cancel_lru_locks osc
1249 echo "mmap write when over soft limit"
1250 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1251 quota_error a $TSTUSR "mmap write failure, but expect success"
1252 cancel_lru_locks osc
1257 $SHOW_QUOTA_INFO_USER
1258 $SHOW_QUOTA_INFO_GROUP
1259 $SHOW_QUOTA_INFO_PROJID
1261 echo "Write before timer goes off"
1262 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1263 quota_error a $TSTUSR "write failure, but expect success"
1264 OFFSET=$((OFFSET + 1024))
1265 cancel_lru_locks osc
1267 wait_grace_time $qtype "block" $pool
1272 $SHOW_QUOTA_INFO_USER
1273 $SHOW_QUOTA_INFO_GROUP
1274 $SHOW_QUOTA_INFO_PROJID
1276 log "Write after timer goes off"
1277 # maybe cache write, ignore.
1278 # write up to soft least quint to consume all
1279 # possible slave granted space.
1280 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1281 count=$soft_limit seek=$OFFSET || true
1282 OFFSET=$((OFFSET + soft_limit))
1283 cancel_lru_locks osc
1284 log "Write after cancel lru locks"
1285 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1286 quota_error a $TSTUSR "write success, but expect EDQUOT"
1291 $SHOW_QUOTA_INFO_USER
1292 $SHOW_QUOTA_INFO_GROUP
1293 $SHOW_QUOTA_INFO_PROJID
1295 echo "Unlink file to stop timer"
1297 wait_delete_completed
1298 sync_all_data || true
1303 $SHOW_QUOTA_INFO_USER
1304 $SHOW_QUOTA_INFO_GROUP
1305 $SHOW_QUOTA_INFO_PROJID
1307 $LFS setstripe $testfile -c 1 -i 0
1308 chown $TSTUSR.$TSTUSR $testfile
1309 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1312 $RUNAS $DD of=$testfile count=$limit ||
1313 quota_error a $TSTUSR "write failure, but expect success"
1320 local grace=20 # seconds
1321 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1324 local testfile=$DIR/$tdir/$tfile-0
1326 # get minimum soft qunit size
1327 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1328 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1330 set_ost_qtype $QTYPE || error "enable ost quota failed"
1332 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1333 # make sure the system is clean
1334 local used=$(getquota -u $TSTUSR global curspace)
1335 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1337 $LFS setquota -t -u --block-grace $grace --inode-grace \
1338 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1339 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1340 error "set user quota failed"
1342 test_block_soft $testfile $grace $limit "u"
1344 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1345 testfile=$DIR/$tdir/$tfile-1
1346 # make sure the system is clean
1347 used=$(getquota -g $TSTUSR global curspace)
1348 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1350 $LFS setquota -t -g --block-grace $grace --inode-grace \
1351 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1352 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1353 error "set group quota failed"
1355 test_block_soft $testfile $grace $limit "g"
1357 if is_project_quota_supported; then
1358 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1359 testfile=$DIR/$tdir/$tfile-2
1360 # make sure the system is clean
1361 used=$(getquota -p $TSTPRJID global curspace)
1362 [ $used -ne 0 ] && error \
1363 "Used space($used) for project $TSTPRJID isn't 0."
1365 $LFS setquota -t -p --block-grace $grace --inode-grace \
1366 $MAX_IQ_TIME $DIR ||
1367 error "set project grace time failed"
1368 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1369 $DIR || error "set project quota failed"
1371 test_block_soft $testfile $grace $limit "p"
1372 resetquota -p $TSTPRJID
1373 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1374 $MAX_IQ_TIME $DIR ||
1375 error "restore project grace time failed"
1379 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1380 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1381 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1382 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1384 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1387 local grace=20 # seconds
1388 local qpool="qpool1"
1389 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1392 local testfile=$DIR/$tdir/$tfile-0
1395 # get minimum soft qunit size
1396 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1397 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1398 local glbl_limit=$((2*limit))
1399 local glbl_grace=$((2*grace))
1400 echo "limit $limit glbl_limit $glbl_limit"
1401 echo "grace $grace glbl_grace $glbl_grace"
1403 set_ost_qtype $QTYPE || error "enable ost quota failed"
1405 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1406 # make sure the system is clean
1407 local used=$(getquota -u $TSTUSR global curspace)
1408 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1410 pool_add $qpool || error "pool_add failed"
1411 pool_add_targets $qpool 0 1 ||
1412 error "pool_add_targets failed"
1414 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1415 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1416 $LFS setquota -t -u --block-grace $grace \
1417 --pool $qpool $DIR || error "set user grace time failed"
1419 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1420 error "set user quota failed"
1421 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1422 error "set user quota failed"
1424 test_block_soft $testfile $grace $limit "u" $qpool
1426 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1427 testfile=$DIR/$tdir/$tfile-1
1428 # make sure the system is clean
1429 used=$(getquota -g $TSTUSR global curspace)
1430 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1432 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1433 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1434 $LFS setquota -t -g --block-grace $grace \
1435 --pool $qpool $DIR || error "set group grace time failed"
1437 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1438 error "set group quota failed"
1439 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1440 error "set group quota failed"
1442 test_block_soft $testfile $grace $limit "g" $qpool
1444 if is_project_quota_supported; then
1445 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1446 testfile=$DIR/$tdir/$tfile-2
1447 # make sure the system is clean
1448 used=$(getquota -p $TSTPRJID global curspace)
1449 [ $used -ne 0 ] && error \
1450 "Used space($used) for project $TSTPRJID isn't 0."
1452 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1453 $MAX_IQ_TIME $DIR ||
1454 error "set project grace time failed"
1455 $LFS setquota -t -p --block-grace $grace \
1456 --pool $qpool $DIR ||
1457 error "set project grace time failed"
1459 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1460 $DIR || error "set project quota failed"
1461 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1462 --pool $qpool $DIR || error "set project quota failed"
1464 test_block_soft $testfile $grace $limit "p" $qpool
1465 resetquota -p $TSTPRJID
1466 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1467 $MAX_IQ_TIME $DIR ||
1468 error "restore project grace time failed"
1469 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1470 $DIR || error "set project grace time failed"
1474 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1475 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1476 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1477 --pool $qpool $DIR || error "restore user grace time failed"
1478 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1479 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1480 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1481 --pool $qpool $DIR || error "restore group grace time failed"
1483 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1486 local grace=20 # seconds
1487 local qpool="qpool1"
1488 local qpool2="qpool2"
1489 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1492 local testfile=$DIR/$tdir/$tfile-0
1495 # get minimum soft qunit size
1496 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1497 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1498 local limit2=$((limit+4))
1499 local glbl_limit=$((limit+8))
1500 local grace1=$((grace+10))
1502 local glbl_grace=$((grace+20))
1503 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1504 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1506 set_ost_qtype $QTYPE || error "enable ost quota failed"
1508 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1509 # make sure the system is clean
1510 local used=$(getquota -u $TSTUSR global curspace)
1511 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1513 pool_add $qpool || error "pool_add failed"
1514 pool_add_targets $qpool 0 1 ||
1515 error "pool_add_targets failed"
1517 pool_add $qpool2 || error "pool_add failed"
1518 pool_add_targets $qpool2 0 1 ||
1519 error "pool_add_targets failed"
1522 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1523 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1524 $LFS setquota -t -u --block-grace $grace1 \
1525 --pool $qpool $DIR || error "set user grace time failed"
1526 $LFS setquota -t -u --block-grace $grace2 \
1527 --pool $qpool2 $DIR || error "set user grace time failed"
1529 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1530 error "set user quota failed"
1531 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1532 error "set user quota failed"
1533 # qpool has minimum soft limit, but its grace is greater than
1534 # the grace period of qpool2. Thus write shouldn't fail when
1535 # hit qpool soft limit - only when reaches up qpool2 limit
1536 # after grace2 seconds.
1537 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1538 error "set user quota failed"
1540 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1543 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1544 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1545 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1546 --pool $qpool $DIR || error "restore user grace time failed"
1547 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1548 --pool $qpool2 $DIR || error "restore user grace time failed"
1550 run_test 3c "Quota pools: check block soft limit on different pools"
1557 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1558 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1561 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1563 echo "Create files to exceed soft limit"
1564 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1565 quota_error a $TSTUSR "create failure, but expect success"
1566 local trigger_time=$(date +%s)
1568 sync_all_data || true
1570 local cur_time=$(date +%s)
1571 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1572 error "Passed grace time $grace, $trigger_time, $cur_time"
1574 echo "Create file before timer goes off"
1575 $RUNAS touch ${TESTFILE}_before ||
1576 quota_error a $TSTUSR "failed create before timer expired," \
1577 "but expect success. $trigger_time, $cur_time"
1578 sync_all_data || true
1580 wait_grace_time $qtype "file"
1585 $SHOW_QUOTA_INFO_USER
1586 $SHOW_QUOTA_INFO_GROUP
1587 $SHOW_QUOTA_INFO_PROJID
1589 echo "Create file after timer goes off"
1590 # exceed least soft limit is possible
1591 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1592 quota_error a $TSTUSR "create after timer expired," \
1594 sync_all_data || true
1599 $SHOW_QUOTA_INFO_USER
1600 $SHOW_QUOTA_INFO_GROUP
1601 $SHOW_QUOTA_INFO_PROJID
1603 echo "Unlink files to stop timer"
1604 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1605 wait_delete_completed
1608 $RUNAS touch ${TESTFILE}_xxx ||
1609 quota_error a $TSTUSR "touch after timer stop failure," \
1610 "but expect success"
1611 sync_all_data || true
1619 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1620 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1621 local TESTFILE=$DIR/$tdir/$tfile-0
1624 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1626 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1627 # make sure the system is clean
1628 local USED=$(getquota -u $TSTUSR global curinodes)
1629 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1631 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1632 $GRACE $DIR || error "set user grace time failed"
1633 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1634 error "set user quota failed"
1636 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1638 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1640 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1641 # make sure the system is clean
1642 USED=$(getquota -g $TSTUSR global curinodes)
1643 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1645 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1646 $GRACE $DIR || error "set group grace time failed"
1647 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1648 error "set group quota failed"
1649 TESTFILE=$DIR/$tdir/$tfile-1
1651 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1653 if is_project_quota_supported; then
1654 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1655 # make sure the system is clean
1656 USED=$(getquota -p $TSTPRJID global curinodes)
1657 [ $USED -ne 0 ] && error \
1658 "Used space($USED) for project $TSTPRJID isn't 0."
1660 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1661 $GRACE $DIR || error "set project grace time failed"
1662 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1663 error "set project quota failed"
1665 TESTFILE=$DIR/$tdir/$tfile-1
1666 # one less than limit, because of parent directory included.
1667 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1668 resetquota -p $TSTPRJID
1669 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1670 $MAX_IQ_TIME $DIR ||
1671 error "restore project grace time failed"
1675 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1676 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1677 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1678 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1680 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1683 local GR_STR1="1w3d"
1684 local GR_STR2="1000s"
1686 local GR_STR4="1w2d3h4m5s"
1688 local GR_STR6="18446744073709551615"
1691 wait_delete_completed
1693 # test of valid grace strings handling
1694 echo "Valid grace strings test"
1695 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1696 $GR_STR2 $DIR || error "set user grace time failed"
1697 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1698 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1699 $GR_STR4 $DIR || error "set group grace time quota failed"
1700 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1702 # test of invalid grace strings handling
1703 echo " Invalid grace strings test"
1704 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1705 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1706 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1710 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1711 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1712 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1713 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1715 run_test 4b "Grace time strings handling"
1717 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1719 local BLIMIT=10 # MB
1720 local ILIMIT=10 # inodes
1722 setup_quota_test || error "setup quota failed with $?"
1724 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1725 set_ost_qtype $QTYPE || error "enable ost quota failed"
1727 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1728 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1729 error "set user quota failed"
1730 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1731 if is_project_quota_supported; then
1732 error "set group quota failed"
1733 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1734 -I $ILIMIT $DIR || error "set project quota failed"
1737 # make sure the system is clean
1738 local USED=$(getquota -u $TSTUSR global curinodes)
1739 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1740 USED=$(getquota -g $TSTUSR global curinodes)
1741 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1742 USED=$(getquota -u $TSTUSR global curspace)
1743 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1744 USED=$(getquota -g $TSTUSR global curspace)
1745 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1746 if is_project_quota_supported; then
1747 USED=$(getquota -p $TSTPRJID global curinodes)
1749 error "Used inode($USED) for project $TSTPRJID isn't 0."
1750 USED=$(getquota -p $TSTPRJID global curspace)
1752 error "Used block($USED) for project $TSTPRJID isn't 0."
1755 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1756 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1757 error "create failure, expect success"
1758 if is_project_quota_supported; then
1759 touch $DIR/$tdir/$tfile-0_1
1760 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1762 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1763 error "write failure, expect success"
1765 echo "Chown files to $TSTUSR.$TSTUSR ..."
1766 for i in $(seq 0 $ILIMIT); do
1767 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1768 quota_error a $TSTUSR "chown failure, expect success"
1772 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1773 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1775 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1777 # test dropping acquire request on master
1781 # Clear dmesg so watchdog is not triggered by previous
1783 do_facet ost1 dmesg -c > /dev/null
1785 setup_quota_test || error "setup quota failed with $?"
1787 # make sure the system is clean
1788 local USED=$(getquota -u $TSTUSR global curspace)
1789 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1791 # make sure no granted quota on ost
1792 set_ost_qtype $QTYPE || error "enable ost quota failed"
1793 resetquota -u $TSTUSR
1795 # create file for $TSTUSR
1796 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1797 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1798 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1800 # create file for $TSTUSR2
1801 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1802 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1803 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1805 # cache per-ID lock for $TSTUSR on slave
1806 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1807 error "set quota failed"
1808 $RUNAS $DD of=$TESTFILE count=1 ||
1809 error "write $TESTFILE failure, expect success"
1810 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1811 error "write $TESTFILE2 failure, expect success"
1813 if at_is_enabled; then
1814 at_max_saved=$(at_max_get ost1)
1815 at_max_set $TIMEOUT ost1
1817 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1818 # DQACQ is sent, which makes at_max to take effect
1819 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1822 wait_delete_completed
1826 sync_all_data || true
1828 #define QUOTA_DQACQ 601
1829 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1830 lustre_fail mds 0x513 601
1832 do_facet ost1 $LCTL set_param \
1833 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1835 # write to un-enforced ID ($TSTUSR2) should succeed
1836 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1837 error "write failure, expect success"
1839 # write to enforced ID ($TSTUSR) in background, exceeding limit
1840 # to make sure DQACQ is sent
1841 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1844 # watchdog timer uses a factor of 2
1845 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1846 sleep $((TIMEOUT * 2 + 1))
1848 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1850 # write should be blocked and never finished
1851 if ! ps -p $DDPID > /dev/null 2>&1; then
1853 error "write finished incorrectly!"
1858 # no watchdog is triggered
1859 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1860 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1861 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1862 [ -z "$watchdog" ] || error "$watchdog"
1864 rm -f $TMP/lustre-log-${TESTNAME}.log
1866 # write should continue then fail with EDQUOT
1870 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1871 if [ $count -ge 240 ]; then
1872 quota_error u $TSTUSR "dd not finished in $count secs"
1874 count=$((count + 1))
1875 if [ $((count % 30)) -eq 0 ]; then
1876 c_size=$(stat -c %s $TESTFILE)
1877 echo "Waiting $count secs. $c_size"
1883 run_test 6 "Test dropping acquire request on master"
1885 # quota reintegration (global index)
1887 local TESTFILE=$DIR/$tdir/$tfile
1890 [ "$SLOW" = "no" ] && LIMIT=5
1892 setup_quota_test || error "setup quota failed with $?"
1894 # make sure the system is clean
1895 local USED=$(getquota -u $TSTUSR global curspace)
1896 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1898 # make sure no granted quota on ost1
1899 set_ost_qtype $QTYPE || error "enable ost quota failed"
1900 resetquota -u $TSTUSR
1901 set_ost_qtype "none" || error "disable ost quota failed"
1903 local OSTUUID=$(ostuuid_from_index 0)
1904 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1906 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1909 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1910 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1915 echo "Enable quota & set quota limit for $TSTUSR"
1916 set_ost_qtype $QTYPE || error "enable ost quota failed"
1917 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1918 error "set quota failed"
1920 echo "Start ost1..."
1921 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1924 wait_ost_reint $QTYPE || error "reintegration failed"
1926 # hardlimit should have been fetched by slave during global
1927 # reintegration, write will exceed quota
1928 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1929 quota_error u $TSTUSR "write success, but expect EDQUOT"
1932 wait_delete_completed
1933 sync_all_data || true
1939 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1940 error "clear quota failed"
1942 echo "Start ost1..."
1943 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1946 wait_ost_reint $QTYPE || error "reintegration failed"
1948 # hardlimit should be cleared on slave during reintegration
1949 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1950 quota_error u $TSTUSR "write error, but expect success"
1952 run_test 7a "Quota reintegration (global index)"
1954 # quota reintegration (slave index)
1956 local limit=100000 # MB
1957 local TESTFILE=$DIR/$tdir/$tfile
1959 setup_quota_test || error "setup quota failed with $?"
1961 # make sure the system is clean
1962 local USED=$(getquota -u $TSTUSR global curspace)
1963 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1965 # make sure no granted quota on ost1
1966 set_ost_qtype $QTYPE || error "enable ost quota failed"
1967 resetquota -u $TSTUSR
1968 set_ost_qtype "none" || error "disable ost quota failed"
1970 local OSTUUID=$(ostuuid_from_index 0)
1971 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1973 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1976 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1977 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1979 # consume some space to make sure the granted space will not
1980 # be released during reconciliation
1981 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1982 error "consume space failure, expect success"
1984 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1985 lustre_fail mds 0xa02
1987 set_ost_qtype $QTYPE || error "enable ost quota failed"
1988 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1989 error "set quota failed"
1991 # ignore the write error
1992 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1994 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1998 echo "Restart ost to trigger reintegration..."
2000 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2003 wait_ost_reint $QTYPE || error "reintegration failed"
2005 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2006 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2011 run_test 7b "Quota reintegration (slave index)"
2013 # quota reintegration (restart mds during reintegration)
2016 local TESTFILE=$DIR/$tdir/$tfile
2018 [ "$SLOW" = "no" ] && LIMIT=5
2020 setup_quota_test || error "setup quota failed with $?"
2022 # make sure the system is clean
2023 local USED=$(getquota -u $TSTUSR global curspace)
2024 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2026 set_ost_qtype "none" || error "disable ost quota failed"
2027 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2028 error "set quota failed"
2030 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2031 lustre_fail ost 0xa03
2034 set_ost_qtype $QTYPE || error "enable ost quota failed"
2035 # trigger reintegration
2036 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2037 procf=${procf}quota_slave.force_reint
2038 do_facet ost1 $LCTL set_param $procf=1 ||
2039 error "force reintegration failed"
2047 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2050 # wait longer than usual to make sure the reintegration
2051 # is triggered by quota wb thread.
2052 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2054 # hardlimit should have been fetched by slave during global
2055 # reintegration, write will exceed quota
2056 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2057 quota_error u $TSTUSR "write success, but expect EDQUOT"
2060 run_test 7c "Quota reintegration (restart mds during reintegration)"
2062 # Quota reintegration (Transfer index in multiple bulks)
2064 local TESTFILE=$DIR/$tdir/$tfile
2065 local TESTFILE1="$DIR/$tdir/$tfile"-1
2068 setup_quota_test || error "setup quota failed with $?"
2070 set_ost_qtype "none" || error "disable ost quota failed"
2071 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2072 error "set quota for $TSTUSR failed"
2073 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2074 error "set quota for $TSTUSR2 failed"
2076 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2077 lustre_fail mds 0x608 0
2079 # enable quota to tirgger reintegration
2080 set_ost_qtype "u" || error "enable ost quota failed"
2081 wait_ost_reint "u" || error "reintegration failed"
2085 # hardlimit should have been fetched by slave during global
2086 # reintegration, write will exceed quota
2087 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2088 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2090 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2091 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2094 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2096 # quota reintegration (inode limits)
2098 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2100 # LU-2435: skip this quota test if underlying zfs version has not
2101 # supported native dnode accounting
2102 [ "$mds1_FSTYPE" == zfs ] && {
2103 local F="feature@userobj_accounting"
2104 local pool=$(zpool_name mds1)
2105 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2107 [[ "$feature" != *" active "* ]] &&
2108 skip "requires zpool with active userobj_accounting"
2111 local ilimit=$((1024 * 2)) # inodes
2112 local TESTFILE=$DIR/${tdir}-1/$tfile
2114 setup_quota_test || error "setup quota failed with $?"
2116 # make sure the system is clean
2117 local USED=$(getquota -u $TSTUSR global curinodes)
2118 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2120 # make sure no granted quota on mdt1
2121 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2122 resetquota -u $TSTUSR
2123 set_mdt_qtype "none" || error "disable mdt quota failed"
2125 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2126 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2127 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2130 echo "Stop mds${MDSCOUNT}..."
2133 echo "Enable quota & set quota limit for $TSTUSR"
2134 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2135 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2136 error "set quota failed"
2138 echo "Start mds${MDSCOUNT}..."
2139 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2142 wait_mdt_reint $QTYPE || error "reintegration failed"
2144 echo "create remote dir"
2145 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2146 error "create remote dir failed"
2147 chmod 0777 $DIR/${tdir}-1
2149 # hardlimit should have been fetched by slave during global
2150 # reintegration, create will exceed quota
2151 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2152 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2154 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2155 wait_delete_completed
2156 sync_all_data || true
2158 echo "Stop mds${MDSCOUNT}..."
2161 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2162 error "clear quota failed"
2164 echo "Start mds${MDSCOUNT}..."
2165 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2168 wait_mdt_reint $QTYPE || error "reintegration failed"
2170 # hardlimit should be cleared on slave during reintegration
2171 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2172 quota_error u $TSTUSR "create failed, expect success"
2174 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2175 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2177 run_test 7e "Quota reintegration (inode limits)"
2179 # run dbench with quota enabled
2181 local BLK_LIMIT="100g" #100G
2182 local FILE_LIMIT=1000000
2184 setup_quota_test || error "setup quota failed with $?"
2186 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2187 set_ost_qtype $QTYPE || error "enable ost quota failed"
2189 echo "Set enough high limit for user: $TSTUSR"
2190 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2191 error "set user quota failed"
2192 echo "Set enough high limit for group: $TSTUSR"
2193 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2194 error "set group quota failed"
2195 if is_project_quota_supported; then
2196 change_project -sp $TSTPRJID $DIR/$tdir
2197 echo "Set enough high limit for project: $TSTPRJID"
2198 $LFS setquota -p $TSTPRJID -b 0 \
2199 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2200 error "set project quota failed"
2204 [ "$SLOW" = "no" ] && duration=" -t 120"
2205 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2206 quota_error a $TSTUSR "dbench failed!"
2208 is_project_quota_supported && change_project -C $DIR/$tdir
2210 run_test 8 "Run dbench with quota enabled"
2212 # this check is just for test_9
2213 OST0_MIN=4900000 #4.67G
2215 check_whether_skip () {
2216 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2217 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2218 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2219 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2226 # run for fixing bug10707, it needs a big room. test for 64bit
2228 local filesize=$((1024 * 9 / 2)) # 4.5G
2230 check_whether_skip && return 0
2232 setup_quota_test || error "setup quota failed with $?"
2234 set_ost_qtype "ug" || error "enable ost quota failed"
2236 local TESTFILE="$DIR/$tdir/$tfile-0"
2237 local BLK_LIMIT=100G #100G
2238 local FILE_LIMIT=1000000
2240 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2242 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2244 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2245 error "set user quota failed"
2247 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2248 "for group: $TSTUSR"
2249 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2250 error "set group quota failed"
2252 quota_show_check a u $TSTUSR
2253 quota_show_check a g $TSTUSR
2255 echo "Create test file"
2256 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2257 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2259 log "Write the big file of 4.5G ..."
2260 $RUNAS $DD of=$TESTFILE count=$filesize ||
2261 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2271 run_test 9 "Block limit larger than 4GB (b10707)"
2274 local TESTFILE=$DIR/$tdir/$tfile
2276 setup_quota_test || error "setup quota failed with $?"
2278 # set limit to root user should fail
2279 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2280 error "set limit for root user successfully, expect failure"
2281 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2282 error "set limit for root group successfully, expect failure"
2283 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2284 error "set limit for project 0 successfully, expect failure"
2286 # root user can overrun quota
2287 set_ost_qtype "ug" || error "enable ost quota failed"
2289 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2290 error "set quota failed"
2291 quota_show_check b u $TSTUSR
2293 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2294 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2296 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2297 error "write failure, expect success"
2299 run_test 10 "Test quota for root user"
2302 local TESTFILE=$DIR/$tdir/$tfile
2303 setup_quota_test || error "setup quota failed with $?"
2305 set_mdt_qtype "ug" || error "enable mdt quota failed"
2306 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2307 error "set quota failed"
2309 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2310 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2312 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2313 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2316 local USED=$(getquota -u $TSTUSR global curinodes)
2317 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2319 run_test 11 "Chown/chgrp ignores quota"
2322 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2324 local blimit=22 # MB
2325 local blk_cnt=$((blimit - 5))
2326 local TESTFILE0="$DIR/$tdir/$tfile"-0
2327 local TESTFILE1="$DIR/$tdir/$tfile"-1
2329 setup_quota_test || error "setup quota failed with $?"
2331 set_ost_qtype "u" || error "enable ost quota failed"
2332 quota_show_check b u $TSTUSR
2334 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2335 error "set quota failed"
2337 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2338 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2339 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2340 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2342 echo "Write to ost0..."
2343 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2344 quota_error a $TSTUSR "dd failed"
2346 echo "Write to ost1..."
2347 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2348 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2350 echo "Free space from ost0..."
2352 wait_delete_completed
2353 sync_all_data || true
2355 echo "Write to ost1 after space freed from ost0..."
2356 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2357 quota_error a $TSTUSR "rebalancing failed"
2359 run_test 12a "Block quota rebalancing"
2362 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2364 local ilimit=$((1024 * 2)) # inodes
2365 local TESTFILE0=$DIR/$tdir/$tfile
2366 local TESTFILE1=$DIR/${tdir}-1/$tfile
2368 setup_quota_test || error "setup quota failed with $?"
2370 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2371 chmod 0777 $DIR/${tdir}-1
2373 set_mdt_qtype "u" || error "enable mdt quota failed"
2374 quota_show_check f u $TSTUSR
2376 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2377 error "set quota failed"
2379 echo "Create $ilimit files on mdt0..."
2380 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2381 quota_error u $TSTUSR "create failed, but expect success"
2383 echo "Create files on mdt1..."
2384 $RUNAS createmany -m $TESTFILE1 1 &&
2385 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2387 echo "Free space from mdt0..."
2388 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2389 wait_delete_completed
2390 sync_all_data || true
2392 echo "Create files on mdt1 after space freed from mdt0..."
2393 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2394 quota_error a $TSTUSR "rebalancing failed"
2396 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2397 error "unlink mdt1 files failed"
2398 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2400 run_test 12b "Inode quota rebalancing"
2403 local TESTFILE=$DIR/$tdir/$tfile
2404 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2405 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2407 setup_quota_test || error "setup quota failed with $?"
2409 set_ost_qtype "u" || error "enable ost quota failed"
2410 quota_show_check b u $TSTUSR
2412 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2413 error "set quota failed"
2414 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2415 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2417 # clear the locks in cache first
2418 do_facet ost1 $LCTL set_param -n $procf=clear
2419 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2420 [ $nlock -eq 0 ] || error "$nlock cached locks"
2422 # write to acquire the per-ID lock
2423 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2424 quota_error a $TSTUSR "dd failed"
2426 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2427 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2429 # clear quota doesn't trigger per-ID lock cancellation
2430 resetquota -u $TSTUSR
2431 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2432 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2434 # clear the per-ID lock
2435 do_facet ost1 $LCTL set_param -n $procf=clear
2436 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2437 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2439 # spare quota should be released
2440 local OSTUUID=$(ostuuid_from_index 0)
2441 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2442 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2443 [ $limit -le $space ] ||
2444 error "spare quota isn't released, limit:$limit, space:$space"
2446 run_test 13 "Cancel per-ID lock in the LRU list"
2449 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2451 wait_delete_completed
2452 sync_all_data || true
2455 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2456 error "set user quota failed"
2457 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2458 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2459 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2460 resetquota -u $TSTUSR
2463 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2464 error "set group quota failed"
2465 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2466 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2467 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2468 resetquota -g $TSTUSR
2470 run_test 15 "Set over 4T block quota"
2474 local BLKS=1 # 1M less than limit
2475 local TESTFILE=$DIR/$tdir/$tfile
2477 setup_quota_test || error "setup quota failed with $?"
2479 # make sure the system is clean
2480 local USED=$(getquota -u $TSTUSR global curspace)
2481 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2483 set_ost_qtype "ug" || error "enable ost quota failed"
2484 # make sure no granted quota on ost
2485 resetquota -u $TSTUSR
2486 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2487 error "set quota failed"
2489 quota_show_check b u $TSTUSR
2491 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2492 lustre_fail mds 0xa04 $err_code
2494 # write in background
2495 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2499 # write should be blocked and never finished
2500 if ! ps -p $DDPID > /dev/null 2>&1; then
2502 quota_error u $TSTUSR "write finished incorrectly!"
2510 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2512 if [ $count -gt $timeout ]; then
2513 quota_error u $TSTUSR "dd is not finished!"
2518 sync; sync_all_data || true
2520 USED=$(getquota -u $TSTUSR global curspace)
2521 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2522 "Used space(${USED}K) is less than ${BLKS}M"
2527 # DQACQ return recoverable error
2529 echo "DQACQ return -ENOLCK"
2531 test_17sub 37 || error "Handle -ENOLCK failed"
2533 echo "DQACQ return -EAGAIN"
2535 test_17sub 11 || error "Handle -EAGAIN failed"
2537 echo "DQACQ return -ETIMEDOUT"
2538 #define ETIMEDOUT 110
2539 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2541 echo "DQACQ return -ENOTCONN"
2542 #define ENOTCONN 107
2543 test_17sub 107 || error "Handle -ENOTCONN failed"
2546 run_test 17 "DQACQ return recoverable error"
2550 local blimit=200 # MB
2551 local TESTFILE="$DIR/$tdir/$tfile"
2553 setup_quota_test || error "setup quota failed with $?"
2555 set_ost_qtype "u" || error "enable ost quota failed"
2556 log "User quota (limit: $blimit)"
2557 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2558 error "set quota failed"
2559 quota_show_check b u $TSTUSR
2561 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2562 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2564 local timeout=$(sysctl -n lustre.timeout)
2566 if [ $io_type = "directio" ]; then
2567 log "Write 100M (directio) ..."
2568 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2570 log "Write 100M (buffered) ..."
2571 $RUNAS $DD of=$TESTFILE count=100 &
2575 replay_barrier $SINGLEMDS
2576 log "Fail mds for $((2 * timeout)) seconds"
2577 fail $SINGLEMDS $((2 * timeout))
2580 if at_is_enabled; then
2581 timeout=$(at_max_get mds)
2583 timeout=$(lctl get_param -n timeout)
2587 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2588 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2589 log "it took $count second"
2594 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2596 cancel_lru_locks mdc
2597 cancel_lru_locks osc
2600 local testfile_size=$(stat -c %s $TESTFILE)
2601 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2602 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2603 "got ${testfile_size}. Verifying file failed!"
2608 # test when mds does failover, the ost still could work well
2609 # this test shouldn't trigger watchdog b=14840
2611 # Clear dmesg so watchdog is not triggered by previous
2613 do_facet ost1 dmesg -c > /dev/null
2616 test_18_sub directio
2618 # check if watchdog is triggered
2619 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2620 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2621 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2622 [ -z "$watchdog" ] || error "$watchdog"
2623 rm -f $TMP/lustre-log-${TESTNAME}.log
2625 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2629 local TESTFILE=$DIR/$tdir/$tfile
2631 setup_quota_test || error "setup quota failed with $?"
2633 set_ost_qtype $QTYPE || error "enable ost quota failed"
2635 # bind file to a single OST
2636 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2637 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2639 echo "Set user quota (limit: ${blimit}M)"
2640 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2641 error "set user quota failed"
2642 quota_show_check b u $TSTUSR
2643 echo "Update quota limits"
2644 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2645 error "set group quota failed"
2646 quota_show_check b u $TSTUSR
2648 # first wirte might be cached
2649 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2650 cancel_lru_locks osc
2652 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2653 quota_error u $TSTUSR "Write success, expect failure"
2656 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2658 test_20() { # b15754
2659 local LSTR=(2g 1t 4k 3m) # limits strings
2661 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2664 resetquota -u $TSTUSR
2666 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2667 $MOUNT || error "could not set quota limits"
2668 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2669 --inode-softlimit ${LSTR[2]} \
2670 --inode-hardlimit ${LSTR[3]} \
2671 $MOUNT || error "could not set quota limits"
2673 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2674 error "bsoftlimit was not set properly"
2675 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2676 error "bhardlimit was not set properly"
2677 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2678 error "isoftlimit was not set properly"
2679 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2680 error "ihardlimit was not set properly"
2682 resetquota -u $TSTUSR
2684 run_test 20 "Test if setquota specifiers work properly (b15754)"
2691 local time=$(($(date +%s) + seconds))
2692 while [ $(date +%s) -lt $time ]; do
2693 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2697 # run for fixing bug16053, setquota shouldn't fail when writing and
2698 # deleting are happening
2700 local TESTFILE="$DIR/$tdir/$tfile"
2701 local BLIMIT=10 # 10G
2702 local ILIMIT=1000000
2704 setup_quota_test || error "setup quota failed with $?"
2706 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2708 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2709 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2710 error "set user quota failed"
2711 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2712 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2713 error "set group quota failed"
2714 if is_project_quota_supported; then
2715 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2716 "project: $TSTPRJID"
2717 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2718 $MOUNT || error "set project quota failed"
2721 # repeat writing on a 1M file
2722 test_21_sub ${TESTFILE}_1 1 30 &
2724 # repeat writing on a 128M file
2725 test_21_sub ${TESTFILE}_2 128 30 &
2728 local time=$(($(date +%s) + 30))
2730 while [ $(date +%s) -lt $time ]; do
2731 log "Set quota for $i times"
2732 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2733 -I $((ILIMIT + i)) $MOUNT ||
2734 error "Set user quota failed"
2735 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2736 -I $((ILIMIT + i)) $MOUNT ||
2737 error "Set group quota failed"
2738 if is_project_quota_supported; then
2739 $LFS setquota -p $TSTPRJID -b 0 -B \
2740 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2741 error "Set project quota failed"
2749 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2751 if [ $count -gt 60 ]; then
2752 quota_error a $TSTUSR "dd should be finished!"
2756 echo "(dd_pid=$DDPID1, time=$count)successful"
2760 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2762 if [ $count -gt 60 ]; then
2763 quota_error a $TSTUSR "dd should be finished!"
2767 echo "(dd_pid=$DDPID2, time=$count)successful"
2769 run_test 21 "Setquota while writing & deleting (b16053)"
2771 # enable/disable quota enforcement permanently
2773 echo "Set both mdt & ost quota type as ug"
2775 is_project_quota_supported && qtype=$QTYPE
2776 set_mdt_qtype $qtype || error "enable mdt quota failed"
2777 set_ost_qtype $qtype || error "enable ost quota failed"
2780 stopall || error "failed to stopall (1)"
2784 echo "Verify if quota is enabled"
2785 local qtype1=$(mdt_quota_type)
2786 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2787 qtype=$(ost_quota_type)
2788 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2790 echo "Set both mdt & ost quota type as none"
2791 set_mdt_qtype "none" || error "disable mdt quota failed"
2792 set_ost_qtype "none" || error "disable ost quota failed"
2795 stopall || error "failed to stopall (2)"
2800 echo "Verify if quota is disabled"
2801 qtype=$(mdt_quota_type)
2802 [ $qtype != "none" ] && error "mdt quota setting is lost"
2803 qtype=$(ost_quota_type)
2804 [ $qtype != "none" ] && error "ost quota setting is lost"
2808 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2811 local TESTFILE="$DIR/$tdir/$tfile"
2814 setup_quota_test || error "setup quota failed with $?"
2816 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2819 log "User quota (limit: $LIMIT MB)"
2820 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2821 error "set quota failed"
2822 quota_show_check b u $TSTUSR
2824 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2825 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2827 log "Step1: trigger EDQUOT with O_DIRECT"
2828 log "Write half of file"
2829 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2830 quota_error u $TSTUSR "(1) Write failure, expect success." \
2832 log "Write out of block quota ..."
2833 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2834 oflag=direct conv=notrunc &&
2835 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2839 log "Step2: rewrite should succeed"
2840 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2841 quota_error u $TSTUSR "(3) Write failure, expect success." \
2847 local OST0_UUID=$(ostuuid_from_index 0)
2848 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2849 [ $OST0_QUOTA_USED -ne 0 ] &&
2850 ($SHOW_QUOTA_USER; \
2851 quota_error u $TSTUSR "quota isn't released")
2856 [ "$ost1_FSTYPE" == zfs ] &&
2857 skip "Overwrite in place is not guaranteed to be " \
2858 "space neutral on ZFS"
2860 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2861 check_whether_skip && return 0
2862 log "run for 4MB test file"
2865 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2866 check_whether_skip && return 0
2867 log "run for 40MB test file"
2870 run_test 23 "Quota should be honored with directIO (b16125)"
2874 local TESTFILE="$DIR/$tdir/$tfile"
2876 setup_quota_test || error "setup quota failed with $?"
2878 set_ost_qtype $QTYPE || error "enable ost quota failed"
2880 # bind file to a single OST
2881 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2882 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2884 echo "Set user quota (limit: ${blimit}M)"
2885 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2886 error "set quota failed"
2888 # overrun quota by root user
2889 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2890 error "write failure, expect success"
2891 cancel_lru_locks osc
2892 sync_all_data || true
2894 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2896 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2898 test_27a() { # b19612
2899 $LFS quota $TSTUSR $DIR &&
2900 error "lfs succeeded with no type, but should have failed"
2901 $LFS setquota $TSTUSR $DIR &&
2902 error "lfs succeeded with no type, but should have failed"
2905 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2907 test_27b() { # b20200
2908 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2909 error "lfs setquota failed with uid argument"
2910 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2911 error "lfs stequota failed with gid argument"
2912 if is_project_quota_supported; then
2913 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2914 1000 $DIR || error \
2915 "lfs stequota failed with projid argument"
2917 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2918 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2919 if is_project_quota_supported; then
2920 $SHOW_QUOTA_PROJID ||
2921 error "lfs quota failed with projid argument"
2923 resetquota -u $TSTID
2924 resetquota -g $TSTID
2925 resetquota -p $TSTPRJID
2928 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2933 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2934 error "lfs setquota failed"
2936 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2937 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2938 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2939 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2941 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2942 error "lfs setquota for $TSTID failed"
2944 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2945 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2946 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2947 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2949 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2950 error "total allocated inode/block limit not printed"
2952 resetquota -u $TSTUSR
2954 run_test 27c "lfs quota should support human-readable output"
2961 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2962 error "set fraction block limit failed"
2963 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2964 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2965 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2966 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2968 resetquota -u $TSTUSR
2970 run_test 27d "lfs setquota should support fraction block limit"
2974 local TESTFILE="$DIR/$tdir/$tfile"
2977 setup_quota_test || error "setup quota failed with $?"
2979 set_ost_qtype "u" || error "enable ost quota failed"
2981 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2982 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2984 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2985 $MAX_IQ_TIME $DIR || error "set grace time failed"
2986 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2987 error "set quota failed"
2988 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2989 cancel_lru_locks osc
2991 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2992 # over-quota flag has not yet settled since we do not trigger async
2993 # events based on grace time period expiration
2995 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2996 cancel_lru_locks osc
2997 # now over-quota flag should be settled and further writes should fail
2999 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3000 error "grace times were reset"
3001 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3002 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3004 run_test 30 "Hard limit updates should not reset grace times"
3006 # basic usage tracking for user & group
3008 local INODES=10 # files
3009 local BLK_CNT=2 # MB each
3010 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3012 setup_quota_test || error "setup quota failed with $?"
3014 # make sure the system is clean
3015 local USED=$(getquota -u $TSTID global curspace)
3017 error "Used space ($USED) for user $TSTID isn't 0."
3018 USED=$(getquota -g $TSTID global curspace)
3020 error "Used space ($USED) for group $TSTID isn't 0."
3021 if is_project_quota_supported; then
3022 USED=$(getquota -p $TSTPRJID global curspace)
3023 [ $USED -ne 0 ] && error \
3024 "Used space ($USED) for project $TSTPRJID isn't 0."
3027 echo "Write files..."
3028 for i in $(seq 0 $INODES); do
3029 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3030 error "write failed"
3031 is_project_quota_supported &&
3032 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3033 echo "Iteration $i/$INODES completed"
3035 cancel_lru_locks osc
3037 echo "Wait for setattr on objects finished..."
3038 wait_delete_completed
3040 sync; sync_all_data || true
3042 echo "Verify disk usage after write"
3043 USED=$(getquota -u $TSTID global curspace)
3044 [ $USED -lt $TOTAL_BLKS ] &&
3045 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3046 USED=$(getquota -g $TSTID global curspace)
3047 [ $USED -lt $TOTAL_BLKS ] &&
3048 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3049 if is_project_quota_supported; then
3050 USED=$(getquota -p $TSTPRJID global curspace)
3051 [ $USED -lt $TOTAL_BLKS ] && error \
3052 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3055 echo "Verify inode usage after write"
3056 USED=$(getquota -u $TSTID global curinodes)
3057 [ $USED -lt $INODES ] &&
3058 error "Used inode for user $TSTID is $USED, expected $INODES"
3059 USED=$(getquota -g $TSTID global curinodes)
3060 [ $USED -lt $INODES ] &&
3061 error "Used inode for group $TSTID is $USED, expected $INODES"
3062 if is_project_quota_supported; then
3063 USED=$(getquota -p $TSTPRJID global curinodes)
3064 [ $USED -lt $INODES ] && error \
3065 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3070 echo "Verify disk usage after delete"
3071 USED=$(getquota -u $TSTID global curspace)
3072 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3073 USED=$(getquota -u $TSTID global curinodes)
3074 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3075 USED=$(getquota -g $TSTID global curspace)
3076 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3077 USED=$(getquota -g $TSTID global curinodes)
3078 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3079 if is_project_quota_supported; then
3080 USED=$(getquota -p $TSTPRJID global curspace)
3082 error "Used space for project $TSTPRJID isn't 0. $USED"
3083 USED=$(getquota -p $TSTPRJID global curinodes)
3085 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3088 run_test 33 "Basic usage tracking for user & group & project"
3090 # usage transfer test for user & group & project
3092 local BLK_CNT=2 # MB
3093 local project_supported="no"
3095 is_project_quota_supported && project_supported="yes"
3096 setup_quota_test || error "setup quota failed with $?"
3098 # make sure the system is clean
3099 local USED=$(getquota -u $TSTID global curspace)
3100 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3101 USED=$(getquota -g $TSTID global curspace)
3102 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3104 local USED=$(getquota -u $TSTID2 global curspace)
3105 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3106 if [ $project_supported == "yes" ]; then
3107 USED=$(getquota -p $TSTPRJID global curspace)
3108 [ $USED -ne 0 ] && error \
3109 "Used space ($USED) for Project $TSTPRJID isn't 0."
3112 echo "Write file..."
3113 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3114 error "write failed"
3115 cancel_lru_locks osc
3116 sync; sync_all_data || true
3118 echo "chown the file to user $TSTID"
3119 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3121 echo "Wait for setattr on objects finished..."
3122 wait_delete_completed
3124 BLK_CNT=$((BLK_CNT * 1024))
3126 echo "Verify disk usage for user $TSTID"
3127 USED=$(getquota -u $TSTID global curspace)
3128 [ $USED -lt $BLK_CNT ] &&
3129 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3130 USED=$(getquota -u $TSTID global curinodes)
3132 error "Used inodes for user $TSTID is $USED, expected 1"
3134 echo "chgrp the file to group $TSTID"
3135 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3137 echo "Wait for setattr on objects finished..."
3138 wait_delete_completed
3140 echo "Verify disk usage for group $TSTID"
3141 USED=$(getquota -g $TSTID global curspace)
3142 [ $USED -ge $BLK_CNT ] ||
3143 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3144 USED=$(getquota -g $TSTID global curinodes)
3146 error "Used inodes for group $TSTID is $USED, expected 1"
3148 # chown won't change the ost object group. LU-4345 */
3149 echo "chown the file to user $TSTID2"
3150 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3152 echo "Wait for setattr on objects finished..."
3153 wait_delete_completed
3155 echo "change_project project id to $TSTPRJID"
3156 [ $project_supported == "yes" ] &&
3157 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3158 echo "Wait for setattr on objects finished..."
3159 wait_delete_completed
3161 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3162 USED=$(getquota -u $TSTID2 global curspace)
3163 [ $USED -lt $BLK_CNT ] &&
3164 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3165 USED=$(getquota -u $TSTID global curspace)
3167 error "Used space for user $TSTID is $USED, expected 0"
3168 USED=$(getquota -g $TSTID global curspace)
3169 [ $USED -lt $BLK_CNT ] &&
3170 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3171 if [ $project_supported == "yes" ]; then
3172 USED=$(getquota -p $TSTPRJID global curspace)
3173 [ $USED -lt $BLK_CNT ] && error \
3174 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3178 run_test 34 "Usage transfer for user & group & project"
3180 # usage is still accessible across restart
3182 local BLK_CNT=2 # MB
3184 setup_quota_test || error "setup quota failed with $?"
3186 echo "Write file..."
3187 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3188 error "write failed"
3189 is_project_quota_supported &&
3190 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3191 cancel_lru_locks osc
3193 echo "Wait for setattr on objects finished..."
3194 wait_delete_completed
3196 sync; sync_all_data || true
3198 echo "Save disk usage before restart"
3199 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3200 [ $ORIG_USR_SPACE -eq 0 ] &&
3201 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3202 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3203 [ $ORIG_USR_INODES -eq 0 ] &&
3204 error "Used inodes for user $TSTID is 0, expected 1"
3205 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3206 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3207 [ $ORIG_GRP_SPACE -eq 0 ] &&
3208 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3209 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3210 [ $ORIG_GRP_INODES -eq 0 ] &&
3211 error "Used inodes for group $TSTID is 0, expected 1"
3212 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3214 if is_project_quota_supported; then
3215 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3216 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3217 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3218 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3219 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3220 "Used inodes for project $TSTPRJID is 0, expected 1"
3221 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3229 echo "Verify disk usage after restart"
3230 local USED=$(getquota -u $TSTID global curspace)
3231 [ $USED -eq $ORIG_USR_SPACE ] ||
3232 error "Used space for user $TSTID changed from " \
3233 "$ORIG_USR_SPACE to $USED"
3234 USED=$(getquota -u $TSTID global curinodes)
3235 [ $USED -eq $ORIG_USR_INODES ] ||
3236 error "Used inodes for user $TSTID changed from " \
3237 "$ORIG_USR_INODES to $USED"
3238 USED=$(getquota -g $TSTID global curspace)
3239 [ $USED -eq $ORIG_GRP_SPACE ] ||
3240 error "Used space for group $TSTID changed from " \
3241 "$ORIG_GRP_SPACE to $USED"
3242 USED=$(getquota -g $TSTID global curinodes)
3243 [ $USED -eq $ORIG_GRP_INODES ] ||
3244 error "Used inodes for group $TSTID changed from " \
3245 "$ORIG_GRP_INODES to $USED"
3246 if [ $project_supported == "yes" ]; then
3247 USED=$(getquota -p $TSTPRJID global curinodes)
3248 [ $USED -eq $ORIG_PRJ_INODES ] ||
3249 error "Used inodes for project $TSTPRJID " \
3250 "changed from $ORIG_PRJ_INODES to $USED"
3251 USED=$(getquota -p $TSTPRJID global curspace)
3252 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3253 error "Used space for project $TSTPRJID "\
3254 "changed from $ORIG_PRJ_SPACE to $USED"
3257 # check if the vfs_dq_init() is called before writing
3258 echo "Append to the same file..."
3259 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3260 error "write failed"
3261 cancel_lru_locks osc
3262 sync; sync_all_data || true
3264 echo "Verify space usage is increased"
3265 USED=$(getquota -u $TSTID global curspace)
3266 [ $USED -gt $ORIG_USR_SPACE ] ||
3267 error "Used space for user $TSTID isn't increased" \
3268 "orig:$ORIG_USR_SPACE, now:$USED"
3269 USED=$(getquota -g $TSTID global curspace)
3270 [ $USED -gt $ORIG_GRP_SPACE ] ||
3271 error "Used space for group $TSTID isn't increased" \
3272 "orig:$ORIG_GRP_SPACE, now:$USED"
3273 if [ $project_supported == "yes" ]; then
3274 USED=$(getquota -p $TSTPRJID global curspace)
3275 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3276 error "Used space for project $TSTPRJID isn't " \
3277 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3280 run_test 35 "Usage is still accessible across reboot"
3282 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3285 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3286 skip "Old server doesn't have LU-5006 fix."
3288 setup_quota_test || error "setup quota failed with $?"
3290 # make sure the system is clean
3291 local USED=$(getquota -u $TSTID global curspace)
3293 error "Used space ($USED) for user $TSTID isn't 0."
3295 # create file with MDS_OPEN_DELAY_CREATE flag
3296 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3297 error "Create file failed"
3299 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3300 oflag=sync || error "Write file failed"
3302 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3304 # wait for setattr on objects finished..."
3305 wait_delete_completed
3307 USED=$(getquota -u $TSTID global curspace)
3308 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3310 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3314 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3315 skip "Old server doesn't have LU-8801 fix."
3317 [ "$UID" != 0 ] && skip_env "must run as root" && return
3319 setup_quota_test || error "setup quota failed with $?"
3321 # make sure the system is clean
3322 local USED=$(getquota -u $TSTID global curspace)
3324 error "Used space ($USED) for user $TSTID isn't 0."
3325 USED=$(getquota -u $TSTID2 global curspace)
3327 error "Used space ($USED) for user $TSTID2 isn't 0."
3329 local TESTFILE="$DIR/$tdir/$tfile"
3330 local file_cnt=10000
3332 # Generate id entries in accounting file
3333 echo "Create $file_cnt files..."
3334 for i in `seq $file_cnt`; do
3336 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3337 error "failed to chown $TESTFILE-$i"
3339 cancel_lru_locks osc
3340 sync; sync_all_data || true
3342 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3343 procf=${procf}.quota_slave.acct_user
3346 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3347 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3348 echo "Found $acct_cnt id entries"
3350 [ $file_cnt -eq $acct_cnt ] || {
3351 do_facet mds1 $LCTL get_param $procf
3352 error "skipped id entries"
3355 run_test 38 "Quota accounting iterator doesn't skip id entries"
3358 local TESTFILE="$DIR/$tdir/project"
3359 ! is_project_quota_supported &&
3360 skip "Project quota is not supported"
3362 setup_quota_test || error "setup quota failed with $?"
3365 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3366 [ $projectid -ne 0 ] &&
3367 error "Project id should be 0 not $projectid"
3368 change_project -p 1024 $TESTFILE
3369 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3370 [ $projectid -ne 1024 ] &&
3371 error "Project id should be 1024 not $projectid"
3373 stopall || error "failed to stopall (1)"
3376 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3377 [ $projectid -eq 1024 ] ||
3378 error "Project id should be 1024 not $projectid"
3380 run_test 39 "Project ID interface works correctly"
3383 ! is_project_quota_supported &&
3384 skip "Project quota is not supported"
3385 local dir1="$DIR/$tdir/dir1"
3386 local dir2="$DIR/$tdir/dir2"
3388 setup_quota_test || error "setup quota failed with $?"
3390 mkdir -p $dir1 $dir2
3391 change_project -sp 1 $dir1 && touch $dir1/1
3392 change_project -sp 2 $dir2
3394 ln $dir1/1 $dir2/1_link &&
3395 error "Hard link across different project quota should fail"
3398 run_test 40a "Hard link across different project ID"
3401 ! is_project_quota_supported &&
3402 skip "Project quota is not supported"
3403 local dir1="$DIR/$tdir/dir1"
3404 local dir2="$DIR/$tdir/dir2"
3406 setup_quota_test || error "setup quota failed with $?"
3407 mkdir -p $dir1 $dir2
3408 change_project -sp 1 $dir1 && touch $dir1/1
3409 change_project -sp 2 $dir2
3411 mv $dir1/1 $dir2/2 || error "mv failed $?"
3412 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3413 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3415 run_test 40b "Mv across different project ID"
3418 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3419 ! is_project_quota_supported &&
3420 skip "Project quota is not supported"
3422 setup_quota_test || error "setup quota failed with $?"
3423 local dir="$DIR/$tdir/dir"
3425 mkdir -p $dir && change_project -sp 1 $dir
3426 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3427 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3428 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3429 touch $dir/remote_dir/file
3430 #verify inherit works file for remote dir.
3431 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3432 [ "$projid" != "1" ] &&
3433 error "file under remote dir expected 1 not $projid"
3435 #Agent inode should be ignored for project quota
3436 local used=$(getquota -p 1 global curinodes)
3438 error "file count expected 3 got $used"
3440 run_test 40c "Remote child Dir inherit project quota properly"
3443 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3444 is_project_quota_supported || skip "Project quota is not supported"
3446 setup_quota_test || error "setup quota failed with $?"
3447 local dir="$DIR/$tdir/dir"
3450 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3451 change_project -sp $TSTPRJID $dir ||
3452 error "change project on $dir failed"
3453 for i in $(seq 5); do
3454 mkdir -p $dir/d$i/d$i ||
3455 error "mkdir $dir/d$i/d$i failed"
3456 local projid=$($LFS project -d $dir/d$i/d$i |
3458 [ "$projid" == "$TSTPRJID" ] ||
3459 error "projid id expected $TSTPRJID not $projid"
3460 touch $dir/d$i/d$i/file
3461 #verify inherit works file for stripe dir.
3462 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3463 [ "$projid" == "$TSTPRJID" ] ||
3464 error "file under remote dir expected 1 not $projid"
3467 # account should be 1 + (2 + 1) *10 + 1 * 5
3468 local used=$(getquota -p $TSTPRJID global curinodes)
3470 error "file count expected 36 got $used"
3472 run_test 40d "Stripe Directory inherit project quota properly"
3475 is_project_quota_supported ||
3476 skip "Project quota is not supported"
3477 setup_quota_test || error "setup quota failed with $?"
3478 local dir="$DIR/$tdir/dir"
3481 local projid=$((testnum * 1000))
3485 # enable mdt/ost quota
3486 set_mdt_qtype ugp || error "enable mdt quota failed"
3487 set_ost_qtype ugp || error "enable ost quota failed"
3489 test_mkdir -p $dir && change_project -sp $projid $dir
3490 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3491 error "set project quota failed"
3496 # check if df output works as expected
3497 echo "== global statfs: $MOUNT =="
3498 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3500 echo "== project statfs (prjid=$projid): $dir =="
3501 df -kP $dir; df -iP $dir
3502 local bused=$(getquota -p $projid global curspace)
3503 local iused=$(getquota -p $projid global curinodes)
3504 # note trailing space to match double printf from awk
3505 local expected="$blimit $bused $ilimit $iused "
3507 wait_update $HOSTNAME \
3508 "{ df -kP $dir; df -iP $dir; } |
3509 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3511 error "failed to get correct statfs for project quota"
3513 run_test 41 "df should return projid-specific values"
3516 ! is_project_quota_supported &&
3517 skip "Project quota is not supported"
3519 setup_quota_test || error "setup quota failed with $?"
3520 local dir1="$DIR/$tdir/dir1"
3521 local dir2="$DIR/$tdir/dir2"
3523 mkdir -p $dir1 && change_project -sp 1 $dir1
3524 mkdir -p $dir2 && change_project -sp 2 $dir2
3525 for num in $(seq 1 10); do
3526 touch $dir1/file_$num $dir2/file_$num
3527 ln -s $dir1/file_$num $dir1/file_$num"_link"
3528 ln -s $dir2/file_$num $dir2/file_$num"_link"
3531 count=$($LFS find --projid 1 $DIR | wc -l)
3532 [ "$count" != 21 ] && error "expected 21 but got $count"
3534 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3535 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3536 [ $count -eq 22 ] || error "expected 22 but got $count"
3538 run_test 50 "Test if lfs find --projid works"
3541 ! is_project_quota_supported &&
3542 skip "Project quota is not supported"
3543 setup_quota_test || error "setup quota failed with $?"
3544 local dir="$DIR/$tdir/dir"
3546 mkdir $dir && change_project -sp 1 $dir
3547 local used=$(getquota -p 1 global curinodes)
3548 [ $used != "1" ] && error "expected 1 got $used"
3553 used=$(getquota -p 1 global curinodes)
3554 [ $used != "4" ] && error "expected 4 got $used"
3556 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3558 cp $DIR/$tdir/6 $dir/6
3559 used=$(getquota -p 1 global curinodes)
3560 [ $used != "5" ] && error "expected 5 got $used"
3563 mv $DIR/$tdir/6 $dir/7
3564 used=$(getquota -p 1 global curinodes)
3565 [ $used -eq 6 ] || error "expected 6 got $used"
3567 run_test 51 "Test project accounting with mv/cp"
3570 ! is_project_quota_supported &&
3571 skip "Project quota is not supported"
3572 setup_quota_test || error "setup quota failed with $?"
3573 local dir="$DIR/$tdir/dir"
3574 mkdir $dir && change_project -sp 1 $dir
3576 touch $DIR/$tdir/file
3577 #Try renaming a file into the project. This should fail.
3578 for num in $(seq 1 2000); do
3579 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3580 error "rename should fail"
3584 run_test 52 "Rename across different project ID"
3587 ! is_project_quota_supported &&
3588 skip "Project quota is not supported"
3589 setup_quota_test || error "setup quota failed with $?"
3590 local dir="$DIR/$tdir/dir"
3591 mkdir $dir && change_project -s $dir
3592 [[ $($LFS project -d $dir) =~ " P " ]] ||
3593 error "inherit attribute should be set"
3595 change_project -C $dir
3596 [[ $($LFS project -d $dir) =~ " - " ]] ||
3597 error "inherit attribute should be cleared"
3599 run_test 53 "Project inherit attribute could be cleared"
3602 ! is_project_quota_supported &&
3603 skip "Project quota is not supported"
3604 setup_quota_test || error "setup quota failed with $?"
3605 local testfile="$DIR/$tdir/$tfile-0"
3607 #set project ID/inherit attribute
3608 change_project -sp $TSTPRJID $DIR/$tdir
3609 $RUNAS createmany -m ${testfile} 100 ||
3610 error "create many files failed"
3612 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3613 # one more count for directory itself */
3617 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3618 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3620 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3621 [ $proj_count1 -eq $proj_count ] ||
3622 error "c2: expected $proj_count got $proj_count1"
3624 #clear project but with kept projid
3625 change_project -rCk $DIR/$tdir
3626 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3627 [ $proj_count1 -eq 1 ] ||
3628 error "c3: expected 1 got $proj_count1"
3630 #verify projid untouched.
3631 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3633 [ $proj_count1 -eq $proj_count ] ||
3634 error "c4: expected $proj_count got $proj_count1"
3637 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3638 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3639 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3641 #this time clear all
3642 change_project -rC $DIR/$tdir
3643 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3644 [ $proj_count1 -eq 0 ] ||
3645 error "c6: expected 0 got $proj_count1"
3647 unlinkmany ${testfile} 100 ||
3648 error "unlink many files failed"
3650 run_test 54 "basic lfs project interface test"
3653 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3654 skip "Not supported before 2.10.58."
3655 setup_quota_test || error "setup quota failed with $?"
3657 set_ost_qtype $QTYPE || error "enable ost quota failed"
3660 #add second group to TSTUSR
3661 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3664 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3665 error "failed to dd"
3667 cancel_lru_locks osc
3668 sync; sync_all_data || true
3670 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3671 error "failed to setquota on group $TSTUSR2"
3673 $LFS quota -v -g $TSTUSR2 $DIR
3675 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3676 error "chgrp should failed with -EDQUOT"
3678 USED=$(getquota -g $TSTUSR2 global curspace)
3681 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3682 error "failed to setquota on group $TSTUSR2"
3684 $LFS quota -v -g $TSTUSR2 $DIR
3686 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3687 error "chgrp should succeed"
3689 $LFS quota -v -g $TSTUSR2 $DIR
3691 run_test 55 "Chgrp should be affected by group quota"
3694 setup_quota_test || error "setup quota failed with $?"
3696 set_ost_qtype $QTYPE || error "enable ost quota failed"
3699 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3700 erro "failed to set grace time for usr quota"
3701 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3702 awk '{print $4 $8}')
3703 if [ "x$grace_time" != "x10s;10s" ]; then
3704 $LFS quota -t -u $DIR
3705 error "expected grace time: 10s;10s, got:$grace_time"
3708 run_test 56 "lfs quota -t should work well"
3711 setup_quota_test || error "setup quota failed with $?"
3713 local dir="$DIR/$tdir/dir"
3716 #command can process further if it hit some errors
3717 $LFS project -sp 1 $dir/pipe
3718 touch $dir/aaa $dir/bbb
3719 mkdir $dir/subdir -p
3720 touch $dir/subdir/aaa $dir/subdir/bbb
3721 #create one invalid link file
3722 ln -s $dir/not_exist_file $dir/ccc
3723 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3724 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3726 run_test 57 "lfs project could tolerate errors"
3729 [ "$mds1_FSTYPE" != ldiskfs ] &&
3730 skip "ldiskfs only test"
3731 disable_project_quota
3732 setup_quota_test || error "setup quota failed with $?"
3735 local testfile="$DIR/$tdir/$tfile-0"
3736 #make sure it did not crash kernel
3737 touch $testfile && lfs project -sp 1 $testfile
3739 enable_project_quota
3741 run_test 59 "lfs project dosen't crash kernel with project disabled"
3744 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3745 skip "Needs MDS version 2.11.53 or later."
3746 setup_quota_test || error "setup quota failed with $?"
3748 local testfile=$DIR/$tdir/$tfile
3751 set_mdt_qtype "ug" || error "enable mdt quota failed"
3753 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3754 error "set quota failed"
3755 quota_show_check a g $TSTUSR
3757 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3758 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3759 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3760 error "create many files failed"
3762 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3764 # root user can overrun quota
3765 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3766 error "root user should succeed"
3768 run_test 60 "Test quota for root with setgid"
3770 # test default quota
3771 test_default_quota() {
3772 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3773 skip "Not supported before 2.11.51."
3778 local qprjid=$TSTPRJID
3782 local LIMIT=20480 #20M disk space
3783 local TESTFILE="$DIR/$tdir/$tfile-0"
3786 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3787 echo "Project quota is not supported" && return 0
3789 [ $qtype == "-u" ] && qdtype="-U"
3790 [ $qtype == "-g" ] && qdtype="-G"
3791 [ $qtype == "-p" ] && {
3796 [ $qres_type == "meta" ] && {
3797 LIMIT=10240 #10K inodes
3802 qpool_cmd="--pool $3"
3803 # pool quotas don't work properly without global limit
3804 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3805 error "set global limit failed"
3808 setup_quota_test || error "setup quota failed with $?"
3812 # enable mdt/ost quota
3813 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3814 set_ost_qtype $QTYPE || error "enable ost quota failed"
3816 log "set to use default quota"
3817 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3818 error "set $qid to use default quota failed"
3820 log "set default quota"
3821 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3822 error "set $qid default quota failed"
3824 log "get default quota"
3825 $LFS quota $qdtype $DIR || error "get default quota failed"
3827 if [ $qres_type == "data" ]; then
3828 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
3829 grep "$MOUNT" | awk '{print $2}')
3830 [ $SLIMIT -eq $LIMIT ] ||
3831 error "the returned default quota is wrong"
3833 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3835 [ $SLIMIT -eq $LIMIT ] ||
3836 error "the returned default quota is wrong"
3839 # make sure the system is clean
3840 local USED=$(getquota $qtype $qid global curspace)
3841 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3843 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3844 error "setstripe $TESTFILE failed"
3845 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3847 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3849 log "Test not out of quota"
3850 if [ $qres_type == "data" ]; then
3851 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3852 quota_error $qtype $qid "write failed, expect succeed"
3854 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3855 quota_error $qtype $qid "create failed, expect succeed"
3857 unlinkmany $TESTFILE $((LIMIT/2))
3860 log "Test out of quota"
3861 # flush cache, ensure noquota flag is set on client
3862 cancel_lru_locks osc
3863 cancel_lru_locks mdc
3864 sync; sync_all_data || true
3865 if [ $qres_type == "data" ]; then
3866 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3867 quota_error $qtype $qid "write succeed, expect EDQUOT"
3869 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3870 quota_error $qtype $qid "create succeed, expect EDQUOT"
3872 unlinkmany $TESTFILE $((LIMIT*2))
3876 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3877 error "setstripe $TESTFILE failed"
3878 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3880 log "Increase default quota"
3882 # LU-4505: sleep 5 seconds to enable quota acquire
3885 # increase default quota
3886 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
3887 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
3889 cancel_lru_locks osc
3890 cancel_lru_locks mdc
3891 sync; sync_all_data || true
3892 if [ $qres_type == "data" ]; then
3893 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3894 quota_error $qtype $qid "write failed, expect succeed"
3896 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3897 quota_error $qtype $qid "create failed, expect succeed"
3899 unlinkmany $TESTFILE $((LIMIT*2))
3902 log "Set quota to override default quota"
3903 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3904 error "set $qid quota failed"
3906 cancel_lru_locks osc
3907 cancel_lru_locks mdc
3908 sync; sync_all_data || true
3909 if [ $qres_type == "data" ]; then
3910 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3911 quota_error $qtype $qid "write succeed, expect EQUOT"
3913 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3914 quota_error $qtype $qid "create succeed, expect EQUOT"
3916 unlinkmany $TESTFILE $((LIMIT*2))
3919 log "Set to use default quota again"
3921 # LU-4505: sleep 5 seconds to enable quota acquire
3924 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3925 error "set $qid to use default quota failed"
3927 cancel_lru_locks osc
3928 cancel_lru_locks mdc
3929 sync; sync_all_data || true
3930 if [ $qres_type == "data" ]; then
3931 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3932 quota_error $qtype $qid "write failed, expect succeed"
3934 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3935 quota_error $qtype $qid "create failed, expect succeed"
3937 unlinkmany $TESTFILE $((LIMIT*2))
3942 wait_delete_completed || error "wait_delete_completed failed"
3943 sync_all_data || true
3945 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
3946 error "reset default quota failed"
3947 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
3948 error "reset quota failed"
3953 test_default_quota "-u" "data"
3954 test_default_quota "-u" "meta"
3955 test_default_quota "-g" "data"
3956 test_default_quota "-g" "meta"
3957 test_default_quota "-p" "data"
3958 test_default_quota "-p" "meta"
3960 run_test 61 "default quota tests"
3963 ! is_project_quota_supported &&
3964 skip "Project quota is not supported"
3965 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3966 skip "chattr did not support project quota"
3967 setup_quota_test || error "setup quota failed with $?"
3968 local testdir=$DIR/$tdir/
3970 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3971 change_project -s $testdir
3972 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3973 error "inherit attribute should be set"
3974 # chattr used FS_IOC_SETFLAGS ioctl
3975 $RUNAS chattr -P $testdir &&
3976 error "regular user clear inherit should fail"
3977 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3978 error "inherit attribute should still be set"
3979 chattr -P $testdir || error "root failed to clear inherit"
3980 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3981 error "inherit attribute should be cleared"
3984 run_test 62 "Project inherit should be only changed by root"
3987 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3988 skip "Not supported before 2.11.55"
3992 local dd_failed=false
3993 local tdir_dom=${tdir}_dom
3994 local LIMIT=20480 #20M
3996 [ $qtype == "p" ] && ! is_project_quota_supported &&
3997 echo "Project quota is not supported" && return 0
3999 [ $qtype == "p" ] && qid=$TSTPRJID
4001 setup_quota_test || error "setup quota failed with $?"
4005 # enable mdt/ost quota
4006 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4007 set_ost_qtype $QTYPE || error "enable ost quota failed"
4009 # make sure the system is clean
4010 local USED=$(getquota -$qtype $qid global curspace)
4011 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4013 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4015 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4016 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4017 error "setstripe $tdir_dom failed"
4018 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4020 [ $qtype == "p" ] && {
4021 change_project -sp $TSTPRJID $DIR/$tdir
4022 change_project -sp $TSTPRJID $DIR/$tdir_dom
4025 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4026 error "set $qid quota failed"
4028 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4029 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4033 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4035 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4036 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4040 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4042 rm -f $DIR/$tdir_dom/*
4044 # flush cache, ensure noquota flag is set on client
4045 cancel_lru_locks osc
4046 cancel_lru_locks mdc
4047 sync; sync_all_data || true
4051 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4052 quota_error $qtype $qid "write failed, expect succeed"
4054 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4055 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4059 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4062 rm -f $DIR/$tdir_dom/*
4064 # flush cache, ensure noquota flag is set on client
4065 cancel_lru_locks osc
4066 cancel_lru_locks mdc
4067 sync; sync_all_data || true
4071 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4072 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4076 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4078 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4079 quota_error $qtype $qid "write succeed, expect EDQUOT"
4082 rm -fr $DIR/$tdir_dom
4084 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4085 error "reset usr quota failed"
4093 run_test 63 "quota on DoM tests"
4096 ! is_project_quota_supported &&
4097 skip "Project quota is not supported"
4098 setup_quota_test || error "setup quota failed with $?"
4099 local dir1="$DIR/$tdir/"
4102 ln -s $dir1/file $dir1/file_link
4105 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4106 error "set project should succeed"
4108 used=$(getquota -p $TSTPRJID global curinodes)
4109 [ $used -eq 4 ] || error "expected 4 got $used"
4110 $LFS project -rC $dir1 >&/dev/null ||
4111 error "clear project should succeed"
4113 used=$(getquota -p $TSTPRJID global curinodes)
4114 [ $used -eq 0 ] || error "expected 0 got $used"
4116 run_test 64 "lfs project on non dir/files should succeed"
4120 local TESTFILE="$DIR/$tdir/$tfile-0"
4122 setup_quota_test || error "setup quota failed with $?"
4123 set_ost_qtype $QTYPE || error "enable ost quota failed"
4127 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4128 error "failed to write"
4129 # flush cache, ensure noquota flag is set on client
4130 cancel_lru_locks osc
4131 sync; sync_all_data || true
4133 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4134 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4135 local quota_all=$($RUNAS $LFS quota $DIR)
4137 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4138 error "usr quota not match"
4139 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4140 error "grp quota not match"
4142 run_test 65 "Check lfs quota result"
4145 ! is_project_quota_supported &&
4146 skip "Project quota is not supported"
4147 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4148 skip "Not supported before 2.12.4"
4149 setup_quota_test || error "setup quota failed with $?"
4150 local old=$(do_facet mds1 $LCTL get_param -n \
4151 mdt.*.enable_chprojid_gid | head -1)
4152 local testdir=$DIR/$tdir/foo
4154 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4155 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4158 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4159 chown -R $TSTID:$TSTID $testdir
4160 change_project -sp $TSTPRJID $testdir
4161 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4163 $RUNAS lfs project -p 0 $testdir/foo &&
4164 error "nonroot user should fail to set projid"
4166 $RUNAS lfs project -C $testdir/foo &&
4167 error "nonroot user should fail to clear projid"
4169 change_project -C $testdir/foo || error "failed to clear project"
4171 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4172 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4173 "failed to set projid with normal user when enable_chprojid_gid=-1"
4175 $RUNAS lfs project -rC $testdir/ || error \
4176 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4178 touch $testdir/bar || error "failed touch $testdir/bar"
4179 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4180 "normal user should not be able to set projid on root owned file"
4182 change_project -p $TSTPRJID $testdir/bar || error \
4183 "root should be able to change its own file's projid"
4185 run_test 66 "nonroot user can not change project state in default"
4192 local short_qtype=${qtype:0:1}
4195 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4197 quota_usr) _runas=$RUNAS;;
4198 quota_2usr) _runas=$RUNAS2;;
4199 *) error "unknown quota parameter $4";;
4204 $_runas $DD of=$file count=$size ||
4205 quota_error $short_qtype $TSTUSR \
4206 "$qtype write failure, but expect success"
4208 cancel_lru_locks osc
4210 sync; sync_all_data || true
4219 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4221 do_facet mds1 $LCTL get_param $param |
4222 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4227 local testfile="$DIR/$tdir/$tfile-0"
4228 local testfile2="$DIR/$tdir/$tfile-1"
4229 local testfile3="$DIR/$tdir/$tfile-2"
4230 local qpool="qpool1"
4236 [ "$ost1_FSTYPE" == zfs ] &&
4237 skip "ZFS grants some block space together with inode"
4239 setup_quota_test || error "setup quota failed with $?"
4242 set_ost_qtype $QTYPE || error "enable ost quota failed"
4245 log "User quota (block hardlimit:$limit MB)"
4246 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4247 error "set user quota failed"
4249 # make sure the system is clean
4250 used=$(getquota -u $TSTUSR global curspace)
4251 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4253 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4254 echo "granted 0x0 before write $granted"
4256 # trigger reintegration
4257 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4258 procf=${procf}quota_slave.force_reint
4259 do_facet ost1 $LCTL set_param $procf=1 ||
4260 error "force reintegration failed"
4261 wait_ost_reint "u" || error "reintegration failed"
4262 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4263 [ $granted -ne 0 ] &&
4264 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4266 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4267 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4269 # write 10 MB to testfile
4270 test_67_write "$testfile" "user" 10 "quota_usr"
4272 # create qpool and add OST1
4273 pool_add $qpool || error "pool_add failed"
4274 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4275 # as quota_usr hasn't limits, lqe may absent. But it should be
4276 # created after the 1st direct qmt_get.
4277 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4279 # check granted - should be 0, as testfile is located only on OST0
4280 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4281 echo "global granted $granted"
4282 granted=$(getgranted $qpool "dt" $TSTID "usr")
4283 echo "$qpool granted $granted"
4284 [ $granted -ne 0 ] &&
4285 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4287 # add OST0 to qpool and check granted space
4288 pool_add_targets $qpool 0 1 ||
4289 error "pool_add_targets failed"
4290 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4291 echo "Granted $granted_mb MB"
4292 #should be 10M + qunit for each OST
4293 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4294 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4296 $LFS setstripe $testfile2 -c 1 -i 1 ||
4297 error "setstripe $testfile2 failed"
4298 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4299 # Write from another user and check that qpool1
4300 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4301 test_67_write "$testfile2" "user" 10 "quota_2usr"
4302 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4303 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4304 [ $granted -ne 0 ] &&
4305 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4307 # Granted space for quota_2usr in qpool1 should appear only
4308 # when global lqe for this user becomes enforced.
4309 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4310 error "set user quota failed"
4311 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4312 echo "granted_mb $granted_mb"
4313 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4314 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4316 $LFS setstripe $testfile3 -c 1 -i 0 ||
4317 error "setstripe $testfile3 failed"
4318 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4319 test_67_write "$testfile3" "user" 10 "quota_2usr"
4320 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4321 echo "$testfile3 granted_mb $granted_mb"
4322 [ $granted_mb -eq $limit ] ||
4323 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4325 # remove OST1 from the qpool1 and check granted space
4326 # should be 0 for TSTUSR and 10M for TSTUSR2
4327 pool_remove_target $qpool 0
4328 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4329 [ $granted_mb -eq 0 ] ||
4330 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4331 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4332 [ $granted_mb -eq 10 ] ||
4333 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4336 wait_delete_completed || error "wait_delete_completed failed"
4337 sync_all_data || true
4338 used=$(getquota -u $TSTUSR global curspace)
4339 [ $used -eq 0 ] || quota_error u $TSTUSR \
4340 "user quota isn't released after deletion"
4342 run_test 67 "quota pools recalculation"
4349 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4350 awk '/usr/ {getline; print $2}'
4355 local qpool="qpool1"
4358 setup_quota_test || error "setup quota failed with $?"
4361 set_ost_qtype $QTYPE || error "enable ost quota failed"
4363 # check slave number for glbal pool
4364 local nr=$(get_slave_nr "0x0" "usr")
4365 echo "nr result $nr"
4366 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4367 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4369 # create qpool and add OST1
4370 pool_add $qpool || error "pool_add failed"
4371 nr=$(get_slave_nr $qpool "usr")
4372 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4375 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4376 nr=$(get_slave_nr $qpool "usr")
4377 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4380 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4381 nr=$(get_slave_nr $qpool "usr")
4382 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4385 pool_remove_target $qpool 0
4386 nr=$(get_slave_nr $qpool "usr")
4387 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4390 pool_remove_target $qpool 1
4391 nr=$(get_slave_nr $qpool "usr")
4392 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4394 # Check again that all is fine with global pool
4395 nr=$(get_slave_nr "0x0" "usr")
4396 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4397 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4399 run_test 68 "slave number in quota pool changed after each add/remove OST"
4403 local global_limit=200 # MB
4405 local testfile="$DIR/$tdir/$tfile-0"
4406 local dom0="$DIR/$tdir/dom0"
4407 local qpool="qpool1"
4410 setup_quota_test || error "setup quota failed with $?"
4413 set_ost_qtype $QTYPE || error "enable ost quota failed"
4414 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4416 # Save DOM only at MDT0
4417 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4418 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4420 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4422 # create qpool and add OST0
4423 pool_add $qpool || error "pool_add failed"
4424 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4426 log "User quota (block hardlimit:$global_limit MB)"
4427 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4428 error "set user quota failed"
4430 log "User quota (block hardlimit:$limit MB)"
4431 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4432 error "set user quota failed"
4434 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4435 quota_error u $TSTUSR "write failed"
4437 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4438 oflag=sync || quota_error u $TSTUSR "write failed"
4440 $RUNAS $DD of=$testfile count=$limit || true
4442 # flush cache, ensure noquota flag is set on client
4443 cancel_lru_locks osc
4444 sync; sync_all_data || true
4446 # MDT0 shouldn't get EDQUOT with glimpse.
4447 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4448 quota_error u $TSTUSR \
4449 "user write success, but expect EDQUOT"
4451 # Now all members of qpool1 should get EDQUOT. Expect success
4452 # when write to DOM on MDT0, as it belongs to global pool.
4453 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4454 oflag=sync || quota_error u $TSTUSR "write failed"
4456 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4457 oflag=sync || quota_error u $TSTUSR "write failed"
4459 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4463 local qpool="qpool1"
4468 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4469 skip "Needs a client >= $VERSION_WITH_QP"
4471 setup_quota_test || error "setup quota failed with $?"
4473 # MDS returns EFAULT for unsupported quotactl command
4474 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4476 # create qpool and add OST0
4477 pool_add $qpool || error "pool_add failed"
4478 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4480 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4482 [ $rc -eq $err ] || error "setquota res $rc != $err"
4484 # If MDS supports QP, check that limit was set properly.
4485 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4486 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4487 echo "hard limit $bhard limit $limit"
4488 [ $bhard -ne $((limit*1024)) ] &&
4489 error "bhard:$bhard for $qpool!=$((limit*1024))"
4492 $LFS quota -u $TSTUSR --pool $qpool $DIR
4494 [ $rc -eq $err ] || error "quota res $rc != $err"
4496 run_test 70 "check lfs setquota/quota with a pool option"
4501 local global_limit=100 # MB
4502 local testfile="$DIR/$tdir/$tfile-0"
4503 local qpool="qpool1"
4504 local qpool2="qpool2"
4506 [ "$ost1_FSTYPE" == zfs ] &&
4507 skip "ZFS grants some block space together with inode"
4508 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4510 setup_quota_test || error "setup quota failed with $?"
4513 set_ost_qtype $QTYPE || error "enable ost quota failed"
4516 log "User quota (block hardlimit:$global_limit MB)"
4517 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4518 error "set user quota failed"
4520 pool_add $qpool || error "pool_add failed"
4521 pool_add_targets $qpool 0 1 ||
4522 error "pool_add_targets failed"
4524 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4525 error "set user quota failed"
4527 pool_add $qpool2 || error "pool_add failed"
4528 pool_add_targets $qpool2 1 1 ||
4529 error "pool_add_targets failed"
4531 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4532 error "set user quota failed"
4534 # make sure the system is clean
4535 local used=$(getquota -u $TSTUSR global curspace)
4538 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4540 # create 1st component 1-10M
4541 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4542 #create 2nd component 10-30M
4543 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4544 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4546 # сheck normal use and out of quota with PFL
4547 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4548 test_1_check_write $testfile "user" $((limit*2))
4550 wait_delete_completed || error "wait_delete_completed failed"
4551 sync_all_data || true
4552 used=$(getquota -u $TSTUSR global curspace)
4553 [ $used -ne 0 ] && quota_error u $TSTUSR \
4554 "user quota isn't released after deletion"
4556 # create 1st component 1-10M
4557 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4558 # create 2nd component 10-30M
4559 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4560 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4562 # write to the 2nd component
4563 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4564 quota_error u $TSTUSR \
4565 "write failure, but expect success"
4566 # this time maybe cache write, ignore it's failure
4567 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4568 cancel_lru_locks osc
4569 sync; sync_all_data || true
4570 # write over limit in qpool2(2nd component 10-30M)
4571 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4572 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4573 # write to the 1st component - OST0 is empty
4574 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4575 quota_error u $TSTUSR "write failed"
4577 run_test 71a "Check PFL with quota pools"
4581 local global_limit=1000 # MB
4582 local limit1=160 # MB
4583 local limit2=10 # MB
4584 local testfile="$DIR/$tdir/$tfile-0"
4585 local qpool="qpool1"
4586 local qpool2="qpool2"
4588 [ "$ost1_FSTYPE" == zfs ] &&
4589 skip "ZFS grants some block space together with inode"
4590 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4592 setup_quota_test || error "setup quota failed with $?"
4595 set_ost_qtype $QTYPE || error "enable ost quota failed"
4598 log "User quota (block hardlimit:$global_limit MB)"
4599 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4600 error "set user quota failed"
4602 pool_add $qpool || error "pool_add failed"
4603 pool_add_targets $qpool 0 1 ||
4604 error "pool_add_targets failed"
4606 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4607 error "set user quota failed"
4609 pool_add $qpool2 || error "pool_add failed"
4610 pool_add_targets $qpool2 1 1 ||
4611 error "pool_add_targets failed"
4613 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4614 error "set user quota failed"
4616 # make sure the system is clean
4617 local used=$(getquota -u $TSTUSR global curspace)
4620 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4622 # First component is on OST0, 2nd on OST1
4623 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4624 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4626 # fill the 1st component on OST0
4627 $RUNAS $DD of=$testfile count=128 ||
4628 quota_error u $TSTUSR "write failed"
4629 # write to the 2nd cmpnt on OST1
4630 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4631 quota_error u $TSTUSR "write failed"
4632 # this time maybe cache write, ignore it's failure
4633 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4635 cancel_lru_locks osc
4636 sync; sync_all_data || true
4637 # write over limit in qpool2
4638 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4639 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4642 run_test 71b "Check SEL with quota pools"
4647 local global_limit=50 # MB
4648 local testfile="$DIR/$tdir/$tfile-0"
4649 local qpool="qpool1"
4652 setup_quota_test || error "setup quota failed with $?"
4655 set_ost_qtype $QTYPE || error "enable ost quota failed"
4658 log "User quota (block hardlimit:$global_limit MB)"
4659 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4660 error "set user quota failed"
4662 pool_add $qpool || error "pool_add failed"
4663 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4665 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4666 error "set user quota failed"
4668 # make sure the system is clean
4669 local used=$(getquota -u $TSTUSR global curspace)
4671 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4673 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4675 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4676 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4677 test_1_check_write $testfile "user" $limit
4678 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4680 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4681 # check that lfs quota -uv --pool prints only OST that
4682 # was added in a pool
4683 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4684 grep "OST\|MDT" && error "$qpool consists wrong targets"
4687 run_test 72 "lfs quota --pool prints only pool's OSTs"
4691 local qpool="qpool1"
4695 pool_add $qpool || error "pool_add failed"
4696 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4697 error "pool_add_targets failed"
4699 test_default_quota "-u" "data" "qpool1"
4701 run_test 73a "default limits at OST Pool Quotas"
4705 local TESTFILE1="$DIR/$tdir/$tfile-1"
4707 local qpool="qpool1"
4711 setup_quota_test || error "setup quota failed with $?"
4713 set_ost_qtype $QTYPE || error "enable ost quota failed"
4715 # pool quotas don't work properly without global limit
4716 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4717 error "set global limit failed"
4719 pool_add $qpool || error "pool_add failed"
4720 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4721 error "pool_add_targets failed"
4723 log "set default quota for $qpool"
4724 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
4725 error "set default quota failed"
4727 log "Write from user that hasn't lqe"
4728 # Check that it doesn't cause a panic or a deadlock
4729 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
4730 # Have to use RUNAS_ID as resetquota creates lqes in
4731 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
4732 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
4734 cancel_lru_locks osc
4735 sync; sync_all_data || true
4737 run_test 73b "default OST Pool Quotas limit for new user"
4741 local global_limit=200 # 200M
4742 local limit=10 # 10M
4743 local limit2=50 # 50M
4744 local qpool="qpool1"
4745 local qpool2="qpool2"
4749 setup_quota_test || error "setup quota failed with $?"
4752 set_ost_qtype $QTYPE || error "enable ost quota failed"
4754 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4755 error "set user quota failed"
4757 pool_add $qpool || error "pool_add failed"
4758 pool_add_targets $qpool 0 1 ||
4759 error "pool_add_targets failed"
4761 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4762 error "set user quota failed"
4764 pool_add $qpool2 || error "pool_add failed"
4765 pool_add_targets $qpool2 1 1 ||
4766 error "pool_add_targets failed"
4768 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4769 error "set user quota failed"
4771 tmp=$(getquota -u $TSTUSR global bhardlimit)
4772 [ $tmp -eq $((global_limit * 1024)) ] ||
4773 error "wrong global limit $global_limit"
4775 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4776 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4778 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
4779 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
4781 # check limits in pools
4782 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4783 grep -A4 $qpool | awk 'NR == 4{print $4}')
4784 echo "pool limit for $qpool $tmp"
4785 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
4786 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4787 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
4788 echo "pool limit for $qpool2 $tmp"
4789 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
4791 run_test 74 "check quota pools per user"
4793 function cleanup_quota_test_75()
4795 do_facet mgs $LCTL nodemap_modify --name default \
4796 --property admin --value 1
4797 do_facet mgs $LCTL nodemap_modify --name default \
4798 --property trusted --value 1
4799 do_facet mgs $LCTL nodemap_modify --name default \
4800 --property squash_uid --value 99
4801 do_facet mgs $LCTL nodemap_modify --name default \
4802 --property squash_gid --value 99
4804 wait_nm_sync default admin_nodemap
4805 wait_nm_sync default trusted_nodemap
4807 do_facet mgs $LCTL nodemap_activate 0
4810 resetquota -u $TSTUSR
4814 local dd_failed=false
4815 local LIMIT=20480 #20M
4818 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4819 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4820 oflag=sync || dd_failed=true
4823 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
4825 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
4826 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4827 oflag=sync || dd_failed=true
4830 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
4832 rm -f $DIR/$tdir_dom/*
4834 # flush cache, ensure noquota flag is set on client
4836 sync; sync_all_data || true
4840 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
4841 quota_error u $qid "write failed, expect succeed (2)"
4843 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4844 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4845 oflag=sync || dd_failed=true
4848 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
4851 rm -f $DIR/$tdir_dom/*
4853 # flush cache, ensure noquota flag is set on client
4855 sync; sync_all_data || true
4859 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4860 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4861 oflag=sync || dd_failed=true
4864 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
4866 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4867 quota_error u $qid "write succeed, expect EDQUOT (3)"
4873 local soft_limit=10 # MB
4874 local hard_limit=20 # MB
4875 local limit=$soft_limit
4876 local testfile="$DIR/$tdir/$tfile-0"
4877 local grace=20 # seconds
4878 local tdir_dom=${tdir}_dom
4880 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
4884 setup_quota_test || error "setup quota failed with $?"
4885 stack_trap cleanup_quota_test_75 EXIT
4888 set_ost_qtype $QTYPE || error "enable ost quota failed"
4889 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4891 local used=$(getquota -u $TSTID global curspace)
4892 $LFS setquota -t -u --block-grace $grace --inode-grace \
4893 $MAX_IQ_TIME $DIR || error "set user grace time failed"
4894 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
4895 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
4896 error "set user quota failed"
4898 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
4899 mkdir $DIR/$tdir_dom
4900 chmod 777 $DIR/$tdir_dom
4901 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4902 error "setstripe $tdir_dom failed"
4904 do_facet mgs $LCTL nodemap_activate 1
4906 do_facet mgs $LCTL nodemap_modify --name default \
4907 --property admin --value 0
4908 do_facet mgs $LCTL nodemap_modify --name default \
4909 --property trusted --value 0
4910 do_facet mgs $LCTL nodemap_modify --name default \
4911 --property deny_unknown --value 0
4912 do_facet mgs $LCTL nodemap_modify --name default \
4913 --property squash_uid --value $TSTID
4914 do_facet mgs $LCTL nodemap_modify --name default \
4915 --property squash_gid --value $TSTID
4916 cancel_lru_locks mdc
4917 wait_nm_sync default admin_nodemap
4918 wait_nm_sync default trusted_nodemap
4919 wait_nm_sync default squash_uid
4921 # mmap write when over soft limit
4923 $DD of=$testfile count=${limit} ||
4924 quota_error a "root write failure, but expect success (1)"
4925 OFFSET=$((limit * 1024))
4926 cancel_lru_locks osc
4928 echo "Write to exceed soft limit"
4929 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
4930 quota_error a $TSTUSR "root write failure, but expect success (2)"
4931 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
4932 cancel_lru_locks osc
4934 echo "mmap write when over soft limit"
4935 $MULTIOP $testfile.mmap OT40960SMW ||
4936 quota_error a $TSTUSR "mmap write failure, but expect success"
4937 cancel_lru_locks osc
4939 wait_delete_completed || error "wait_delete_completed failed (1)"
4940 sync_all_data || true
4942 # test for user hard limit
4945 $DD of=$testfile bs=1M count=$((limit/2)) ||
4946 quota_error u $TSTID \
4947 "root write failure, but expect success (3)"
4949 log "Write out of block quota ..."
4950 # possibly a cache write, ignore failure
4951 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
4952 # flush cache, ensure noquota flag is set on client
4953 cancel_lru_locks osc
4954 sync; sync_all_data || true
4955 # sync forced cache flush, but did not guarantee that slave
4956 # got new edquot through glimpse, so wait to make sure
4958 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
4959 quota_error u $TSTID \
4960 "user write success, but expect EDQUOT"
4962 wait_delete_completed || error "wait_delete_completed failed (2)"
4963 sync_all_data || true
4964 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
4965 quota_error u $TSTID "user quota not released after deletion"
4969 run_test 75 "nodemap squashed root respects quota enforcement"
4972 ! is_project_quota_supported &&
4973 skip "skip project quota unsupported"
4975 setup_quota_test || error "setup quota failed with $?"
4978 local testfile="$DIR/$tdir/$tfile-0"
4981 $LFS project -p 4294967295 $testfile &&
4982 error "set project ID should fail"
4985 run_test 76 "project ID 4294967295 should be not allowed"
4989 mount_client $MOUNT2 "ro"
4990 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
4991 error "lfs setquota should fail in read-only Lustre mount"
4994 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
4998 do_nodes $(comma_list $(nodes_list)) \
4999 "lctl set_param -n debug=-quota,trace"
5000 if $PQ_CLEANUP; then
5001 disable_project_quota
5004 reset_quota_settings
5009 check_and_cleanup_lustre
5010 export QUOTA_AUTO=$QUOTA_AUTO_OLD