3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 # QP exists since this version. Should be finally set before landing.
43 VERSION_WITH_QP="2.13.53"
45 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
46 skip "Needs MDS version $VERSION_WITH_QP or later."
49 require_dsh_mds || exit 0
50 require_dsh_ost || exit 0
52 # Does e2fsprogs support quota feature?
53 if [ "$mds1_FSTYPE" == ldiskfs ] &&
54 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
55 grep -q 'quota'"; then
56 skip_env "e2fsprogs doesn't support quota"
59 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
61 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
66 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 check_and_setup_lustre
71 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
73 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
74 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
75 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
76 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
77 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
80 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
85 local fail_val=${3:-0}
89 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
90 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
91 ost) NODES="$(comma_list $(osts_nodes))";;
94 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
100 lfs project $* || error "lfs project $* failed"
103 RUNAS="runas -u $TSTID -g $TSTID"
104 RUNAS2="runas -u $TSTID2 -g $TSTID2"
105 DD="dd if=/dev/zero bs=1M"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
112 # resetquota -p projid
115 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
116 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
117 error "resetquota: wrong specifier $1 passed"
119 if [ $1 == "-p" ]; then
120 is_project_quota_supported || return 0
123 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
124 error "clear quota for [type:$1 name:$2] failed"
125 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 log "Files for user ($local_id):"
136 ($LFS find --user $local_id $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
140 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
141 $LFS quota -v -g $local_id $DIR
142 log "Files for group ($local_id):"
143 ($LFS find --group $local_id $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
147 is_project_quota_supported || return 0
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
149 $LFS quota -v -p $TSTPRJID $DIR
150 log "Files for project ($TSTPRJID):"
151 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
168 # get quota for a user or a group
169 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
170 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
177 sync_all_data > /dev/null 2>&1 || true
179 [ "$#" != 4 -a "$#" != 5 ] &&
180 error "getquota: wrong number of arguments: $#"
181 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
182 error "getquota: wrong u/g/p specifier $1 passed"
195 *) error "unknown quota parameter $4";;
198 [ ! -z "$5" ] && pool_arg="--pool $5 "
199 [ "$uuid" = "global" ] && uuid=$DIR
201 $LFS quota -v "$1" "$2" $pool_arg $DIR |
202 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
203 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
208 # usage: set_mdt_qtype ugp|u|g|p|none
212 local mdts=$(get_facets MDS)
214 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
215 qtype=$(tr -d 'p' <<<$qtype)
217 if [[ $PERM_CMD == *"set_param -P"* ]]; then
218 do_facet mgs $PERM_CMD \
219 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
221 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
223 # we have to make sure each MDT received config changes
224 for mdt in ${mdts//,/ }; do
226 cmd="$LCTL get_param -n "
227 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
228 cmd=${cmd}.quota_slave.enabled
230 if $(facet_up $mdt); then
231 wait_update_facet $mdt "$cmd" "$qtype" || return 1
238 # usage: set_ost_qtype ugp|u|g|p|none
242 local osts=$(get_facets OST)
244 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
245 qtype=$(tr -d 'p' <<<$qtype)
247 if [[ $PERM_CMD == *"set_param -P"* ]]; then
248 do_facet mgs $PERM_CMD \
249 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
251 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
253 # we have to make sure each OST received config changes
254 for ost in ${osts//,/ }; do
256 cmd="$LCTL get_param -n "
257 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
258 cmd=${cmd}.quota_slave.enabled
260 if $(facet_up $ost); then
261 wait_update_facet $ost "$cmd" "$qtype" || return 1
267 wait_reintegration() {
271 local result="glb[1],slv[1],reint[0]"
276 if [ $ntype == "mdt" ]; then
277 tgts=$(get_facets MDS)
279 tgts=$(get_facets OST)
282 for tgt in ${tgts//,/ }; do
284 cmd="$LCTL get_param -n "
285 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
286 cmd=${cmd}.quota_slave.info
288 if $(facet_up $tgt); then
289 wait_update_facet $tgt "$cmd |
290 grep "$qtype" | awk '{ print \\\$3 }'" \
291 "$result" $max || return 1
301 if [[ "$qtype" =~ "u" ]]; then
302 wait_reintegration "mdt" "user" $max || return 1
305 if [[ "$qtype" =~ "g" ]]; then
306 wait_reintegration "mdt" "group" $max || return 1
309 if [[ "$qtype" =~ "p" ]]; then
310 ! is_project_quota_supported && return 0
311 wait_reintegration "mdt" "project" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "ost" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "ost" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "ost" "project" $max || return 1
339 local extrasleep=${4:-5}
346 *) error "get_grace_time: Invalid quota type: $qtype"
351 echo "Quota info for $pool:"
352 $LFS quota -$qtype $qarg $parg $DIR
357 time=$(lfs quota -$qtype $qarg $parg $DIR|
358 awk 'NR == 3{ print $5 }'| sed 's/s$//')
361 time=$(lfs quota -$qtype $qarg $DIR|
362 awk 'NR == 3{ print $9 }'| sed 's/s$//')
365 error "Unknown quota type: $flavour"
369 # from lfs.c:__sec2str()
370 # const char spec[] = "smhdw";
371 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
372 [[ $time == *m* ]] && time=${time//m/} && time=$((time*60));
373 [[ $time == *h* ]] && time=${time//h/} && time=$((time*60*60));
374 [[ $time == *d* ]] && time=${time//d/} && time=$((time*24*60*60));
375 [[ $time == *w* ]] && time=${time//w/} && time=$((time*7*24*60*60));
377 echo "Sleep through grace ..."
378 [ "$time" == "-" ] &&
379 error "Grace timeout was not set or quota not exceeded"
380 if [ "$time" == "none" ]; then
381 echo "...Grace timeout already expired"
383 let time+=$extrasleep
384 echo "...sleep $time seconds"
390 wait_delete_completed
391 echo "Creating test directory"
392 mkdir $DIR/$tdir || return 1
393 chmod 0777 $DIR/$tdir || return 2
394 # always clear fail_loc in case of fail_loc isn't cleared
395 # properly when previous test failed
396 lustre_fail mds_ost 0
399 cleanup_quota_test() {
400 echo "Delete files..."
402 echo "Wait for unlink objects finished..."
403 wait_delete_completed
404 sync_all_data || true
414 $LFS quota -v -$ugp $qid $DIR
416 if [ "$bf" == "a" -o "$bf" == "b" ]; then
417 usage=$(getquota -$ugp $qid global curspace)
418 if [ -z $usage ]; then
419 quota_error $ugp $qid \
420 "Query block quota failed ($ugp:$qid)."
422 [ $usage -ne 0 ] && quota_log $ugp $qid \
423 "Block quota isn't 0 ($ugp:$qid:$usage)."
427 if [ "$bf" == "a" -o "$bf" == "f" ]; then
428 usage=$(getquota -$ugp $qid global curinodes)
429 if [ -z $usage ]; then
430 quota_error $ugp $qid \
431 "Query file quota failed ($ugp:$qid)."
433 [ $usage -ne 0 ] && quota_log $ugp $qid \
434 "File quota isn't 0 ($ugp:$qid:$usage)."
439 project_quota_enabled () {
441 local zfeat="feature@project_quota"
443 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
444 local facet_fstype=${facet:0:3}1_FSTYPE
447 if [ "${!facet_fstype}" = "zfs" ]; then
448 devname=$(zpool_name ${facet})
449 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
450 grep -wq active || rc=1
452 [ ${facet:0:3} == "mds" ] &&
453 devname=$(mdsdevname ${facet:3}) ||
454 devname=$(ostdevname ${facet:3})
455 do_facet ${facet} $DEBUGFS -R features $devname |
456 grep -q project || rc=1
459 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
463 project_quota_enabled || enable_project_quota
465 reset_quota_settings() {
466 resetquota -u $TSTUSR
468 resetquota -g $TSTUSR
470 resetquota -u $TSTUSR2
471 resetquota -u $TSTID2
472 resetquota -g $TSTUSR2
473 resetquota -g $TSTID2
474 resetquota -p $TSTPRJID
479 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota+trace"
484 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
485 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
486 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
487 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
489 test_quota_performance() {
490 local TESTFILE="$DIR/$tdir/$tfile-0"
491 local size=$1 # in MB
492 local stime=$(date +%s)
493 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
494 quota_error u $TSTUSR "write failure"
495 local etime=$(date +%s)
496 delta=$((etime - stime))
497 if [ $delta -gt 0 ]; then
498 rate=$((size * 1024 / delta))
499 if [ "$mds1_FSTYPE" = zfs ]; then
500 # LU-2872 - see LU-2887 for fix
502 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
504 [ $rate -gt 1024 ] ||
505 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
511 # test basic quota performance b=21696
514 [ "$SLOW" = "no" ] && MB=10
516 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
517 [ $free_space -le $((MB * 1024)) ] &&
518 skip "not enough space ${free_space} KB, " \
519 "required $((MB * 1024)) KB"
520 setup_quota_test || error "setup quota failed with $?"
521 trap cleanup_quota_test EXIT
523 set_ost_qtype "none" || error "disable ost quota failed"
524 test_quota_performance $MB
526 set_ost_qtype $QTYPE || error "enable ost quota failed"
527 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
528 error "set quota failed"
529 test_quota_performance $MB
533 run_test 0 "Test basic quota performance"
535 # usage: test_1_check_write tfile user|group|project
536 test_1_check_write() {
540 local short_qtype=${qtype:0:1}
543 $RUNAS $DD of=$testfile count=$((limit/2)) ||
544 quota_error $short_qtype $TSTUSR \
545 "$qtype write failure, but expect success"
546 log "Write out of block quota ..."
547 # this time maybe cache write, ignore it's failure
548 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
549 # flush cache, ensure noquota flag is set on client
551 sync; sync_all_data || true
552 # sync means client wrote all it's cache, but id doesn't
553 # garantee that slave got new edquot trough glimpse.
554 # so wait a little to be sure slave got it.
556 $RUNAS $DD of=$testfile count=1 seek=$limit &&
557 quota_error $short_qtype $TSTUSR \
558 "user write success, but expect EDQUOT"
561 check_write_fallocate() {
565 local short_qtype=${qtype:0:1}
568 log "Write ${count}MiB Using Fallocate"
569 $RUNAS fallocate -l${count}MiB $testfile ||
570 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
573 sync; sync_all_data || true
577 log "Write ${count}MiB Using Fallocate"
578 $RUNAS fallocate -l${count}MiB $testfile &&
579 quota_error $short_qtype $TSTUSR \
580 "Write success, expect EDQUOT" || true
583 # test block hardlimit
586 local testfile="$DIR/$tdir/$tfile-0"
588 setup_quota_test || error "setup quota failed with $?"
589 trap cleanup_quota_test EXIT
592 set_ost_qtype $QTYPE || error "enable ost quota failed"
595 log "User quota (block hardlimit:$limit MB)"
596 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
597 error "set user quota failed"
599 # make sure the system is clean
600 local used=$(getquota -u $TSTUSR global curspace)
601 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
603 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
604 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
606 test_1_check_write $testfile "user" $limit
609 wait_delete_completed || error "wait_delete_completed failed"
610 sync_all_data || true
611 used=$(getquota -u $TSTUSR global curspace)
612 [ $used -ne 0 ] && quota_error u $TSTUSR \
613 "user quota isn't released after deletion"
614 resetquota -u $TSTUSR
617 log "--------------------------------------"
618 log "Group quota (block hardlimit:$limit MB)"
619 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
620 error "set group quota failed"
622 testfile="$DIR/$tdir/$tfile-1"
623 # make sure the system is clean
624 used=$(getquota -g $TSTUSR global curspace)
625 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
627 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
628 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
630 test_1_check_write $testfile "group" $limit
632 wait_delete_completed || error "wait_delete_completed failed"
633 sync_all_data || true
634 used=$(getquota -g $TSTUSR global curspace)
635 [ $used -ne 0 ] && quota_error g $TSTUSR \
636 "Group quota isn't released after deletion"
637 resetquota -g $TSTUSR
639 if ! is_project_quota_supported; then
640 echo "Project quota is not supported"
645 testfile="$DIR/$tdir/$tfile-2"
646 # make sure the system is clean
647 used=$(getquota -p $TSTPRJID global curspace)
649 error "used space($used) for project $TSTPRJID isn't 0"
652 log "--------------------------------------"
653 log "Project quota (block hardlimit:$limit mb)"
654 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
655 error "set project quota failed"
657 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
658 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
659 change_project -p $TSTPRJID $testfile
661 test_1_check_write $testfile "project" $limit
666 used=$(getquota -p $TSTPRJID global curspace)
667 [ $used -ne 0 ] && quota_error p $TSTPRJID \
668 "project quota isn't released after deletion"
670 resetquota -p $TSTPRJID
672 run_test 1a "Block hard limit (normal use and out of quota)"
676 local global_limit=20 # 100M
677 local testfile="$DIR/$tdir/$tfile-0"
681 setup_quota_test || error "setup quota failed with $?"
682 stack_trap cleanup_quota_test EXIT
685 set_ost_qtype $QTYPE || error "enable ost quota failed"
688 log "User quota (block hardlimit:$global_limit MB)"
689 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
690 error "set user quota failed"
692 pool_add $qpool || error "pool_add failed"
693 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
694 error "pool_add_targets failed"
696 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
697 error "set user quota failed"
699 # make sure the system is clean
700 local used=$(getquota -u $TSTUSR global curspace)
702 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
704 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
706 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
707 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
709 test_1_check_write $testfile "user" $limit
712 wait_delete_completed || error "wait_delete_completed failed"
713 sync_all_data || true
714 used=$(getquota -u $TSTUSR global curspace $qpool)
715 [ $used -ne 0 ] && quota_error u $TSTUSR \
716 "user quota isn't released after deletion"
717 resetquota -u $TSTUSR
720 log "--------------------------------------"
721 log "Group quota (block hardlimit:$global_limit MB)"
722 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
723 error "set group quota failed"
725 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
726 error "set group quota failed"
728 testfile="$DIR/$tdir/$tfile-1"
729 # make sure the system is clean
730 used=$(getquota -g $TSTUSR global curspace $qpool)
731 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
733 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
734 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
736 test_1_check_write $testfile "group" $limit
739 wait_delete_completed || error "wait_delete_completed failed"
740 sync_all_data || true
741 used=$(getquota -g $TSTUSR global curspace $qpool)
742 [ $used -ne 0 ] && quota_error g $TSTUSR \
743 "Group quota isn't released after deletion"
744 resetquota -g $TSTUSR
746 if ! is_project_quota_supported; then
747 echo "Project quota is not supported"
752 testfile="$DIR/$tdir/$tfile-2"
753 # make sure the system is clean
754 used=$(getquota -p $TSTPRJID global curspace $qpool)
756 error "used space($used) for project $TSTPRJID isn't 0"
759 log "--------------------------------------"
760 log "Project quota (block hardlimit:$global_limit mb)"
761 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
762 error "set project quota failed"
764 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
765 error "set project quota failed"
768 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
769 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
770 change_project -p $TSTPRJID $testfile
772 test_1_check_write $testfile "project" $limit
777 used=$(getquota -p $TSTPRJID global curspace)
778 [ $used -eq 0 ] || quota_error p $TSTPRJID \
779 "project quota isn't released after deletion"
781 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
784 local global_limit=20 # 100M
785 local testfile="$DIR/$tdir/$tfile-0"
786 local qpool1="qpool1"
787 local qpool2="qpool2"
790 setup_quota_test || error "setup quota failed with $?"
791 stack_trap cleanup_quota_test EXIT
794 set_ost_qtype $QTYPE || error "enable ost quota failed"
797 log "User quota (block hardlimit:$global_limit MB)"
798 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
799 error "set user quota failed"
801 pool_add $qpool1 || error "pool_add failed"
802 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
803 error "pool_add_targets failed"
805 pool_add $qpool2 || error "pool_add failed"
806 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
807 error "pool_add_targets failed"
809 # create pools without hard limit
810 # initially such case raised several bugs
811 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
812 error "set user quota failed"
814 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
815 error "set user quota failed"
817 # make sure the system is clean
818 local used=$(getquota -u $TSTUSR global curspace)
820 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
822 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
824 test_1_check_write $testfile "user" $global_limit
826 used=$(getquota -u $TSTUSR global curspace $qpool1)
827 echo "qpool1 used $used"
828 used=$(getquota -u $TSTUSR global curspace $qpool2)
829 echo "qpool2 used $used"
832 wait_delete_completed || error "wait_delete_completed failed"
833 sync_all_data || true
835 used=$(getquota -u $TSTUSR global curspace $qpool1)
836 [ $used -ne 0 ] && quota_error u $TSTUSR \
837 "user quota isn't released after deletion"
838 resetquota -u $TSTUSR
843 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
846 local limit1=10 # 10M
847 local limit2=12 # 12M
848 local global_limit=20 # 100M
849 local testfile="$DIR/$tdir/$tfile-0"
850 local qpool1="qpool1"
851 local qpool2="qpool2"
854 setup_quota_test || error "setup quota failed with $?"
855 stack_trap cleanup_quota_test EXIT
858 set_ost_qtype $QTYPE || error "enable ost quota failed"
861 log "User quota (block hardlimit:$global_limit MB)"
862 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
863 error "set user quota failed"
865 pool_add $qpool1 || error "pool_add failed"
866 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
867 error "pool_add_targets failed"
869 pool_add $qpool2 || error "pool_add failed"
870 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
871 error "pool_add_targets failed"
873 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
874 error "set user quota failed"
876 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
877 error "set user quota failed"
879 # make sure the system is clean
880 local used=$(getquota -u $TSTUSR global curspace)
882 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
884 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
886 test_1_check_write $testfile "user" $limit1
888 used=$(getquota -u $TSTUSR global curspace $qpool1)
889 echo "qpool1 used $used"
890 used=$(getquota -u $TSTUSR global curspace $qpool2)
891 echo "qpool2 used $used"
894 wait_delete_completed || error "wait_delete_completed failed"
895 sync_all_data || true
897 used=$(getquota -u $TSTUSR global curspace $qpool1)
898 [ $used -ne 0 ] && quota_error u $TSTUSR \
899 "user quota isn't released after deletion"
900 resetquota -u $TSTUSR
905 run_test 1d "Quota pools: check block hardlimit on different pools"
908 local limit1=10 # 10M
909 local global_limit=200 # 200M
910 local testfile="$DIR/$tdir/$tfile-0"
911 local testfile2="$DIR/$tdir/$tfile-1"
912 local qpool1="qpool1"
915 setup_quota_test || error "setup quota failed with $?"
916 stack_trap cleanup_quota_test EXIT
919 set_ost_qtype $QTYPE || error "enable ost quota failed"
921 # global_limit is much greater than limit1 to get
922 # different qunit's on osts. Since 1st qunit shrinking
923 # on OST1(that belongs to qpool1), this qunit should
925 log "User quota (block hardlimit:$global_limit MB)"
926 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
927 error "set user quota failed"
929 pool_add $qpool1 || error "pool_add failed"
930 pool_add_targets $qpool1 1 1 ||
931 error "pool_add_targets failed"
933 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
934 error "set user quota failed"
936 # make sure the system is clean
937 local used=$(getquota -u $TSTUSR global curspace)
938 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
940 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
941 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
943 test_1_check_write $testfile "user" $limit1
945 $LFS setstripe $testfile2 -c 1 -i 0 ||
946 error "setstripe $testfile2 failed"
947 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
948 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
950 $RUNAS $DD of=$testfile2 count=20 ||
951 quota_error u $TSTUSR \
952 "$qtype write failure, but expect success"
956 wait_delete_completed || error "wait_delete_completed failed"
957 sync_all_data || true
959 used=$(getquota -u $TSTUSR global curspace $qpool1)
960 [ $used -ne 0 ] && quota_error u $TSTUSR \
961 "user quota isn't released after deletion"
962 resetquota -u $TSTUSR
967 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
970 local global_limit=200 # 200M
971 local limit1=10 # 10M
972 local TESTDIR="$DIR/$tdir/"
973 local testfile="$TESTDIR/$tfile-0"
974 local qpool1="qpool1"
977 setup_quota_test || error "setup quota failed with $?"
978 stack_trap cleanup_quota_test EXIT
981 set_ost_qtype $QTYPE || error "enable ost quota failed"
983 log "User quota (block hardlimit:$global_limit MB)"
984 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
985 error "set user quota failed"
987 pool_add $qpool1 || error "pool_add failed"
988 pool_add_targets $qpool1 0 0 ||
989 error "pool_add_targets failed"
991 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
992 error "set user quota failed"
994 # make sure the system is clean
995 local used=$(getquota -u $TSTUSR global curspace)
996 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
998 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1000 test_1_check_write $testfile "user" $limit1
1002 pool_remove_target $qpool1 0
1004 wait_delete_completed || error "wait_delete_completed failed"
1005 sync_all_data || true
1007 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1008 # qunit for appropriate element in lgd array should be set
1009 # correctly(4096). Earlier it was not changed continuing to be 1024.
1010 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1011 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1012 # as it already was 1024. As flag "need_update" for this qunit was
1013 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1014 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1015 # became > 10M. QMT returned EINPROGRESS in a loop.
1016 # Check that it doesn't hung anymore.
1017 test_1_check_write $testfile "user" $limit1
1022 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1025 local limit=20 # 20M
1026 local global_limit=40 # 40M
1027 local testfile="$DIR/$tdir/$tfile-0"
1028 local qpool="qpool1"
1029 local mdmb_param="osc.*.max_dirty_mb"
1030 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1033 setup_quota_test || error "setup quota failed with $?"
1034 stack_trap cleanup_quota_test EXIT
1035 $LCTL set_param $mdmb_param=1
1036 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1039 set_ost_qtype $QTYPE || error "enable ost quota failed"
1042 log "User quota (block hardlimit:$global_limit MB)"
1043 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1044 error "set user quota failed"
1046 pool_add $qpool || error "pool_add failed"
1047 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1048 error "pool_add_targets failed"
1050 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1051 error "set user quota failed"
1053 # make sure the system is clean
1054 local used=$(getquota -u $TSTUSR global curspace)
1056 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1058 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1059 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1062 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1063 quota_error u $TSTUSR \
1064 "$qtype write failure, but expect success"
1065 log "Write out of block quota ..."
1066 # this time maybe cache write, ignore it's failure
1067 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1068 # flush cache, ensure noquota flag is set on client
1069 cancel_lru_locks osc
1070 sync; sync_all_data || true
1072 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1073 quota_error u $TSTUSR \
1074 "user write success, but expect EDQUOT"
1077 wait_delete_completed || error "wait_delete_completed failed"
1078 sync_all_data || true
1080 used=$(getquota -u $TSTUSR global curspace $qpool)
1081 [ $used -ne 0 ] && quota_error u $TSTUSR \
1082 "user quota isn't released after deletion"
1085 run_test 1g "Quota pools: Block hard limit with wide striping"
1088 local limit=10 # 10M
1089 local testfile="$DIR/$tdir/$tfile-0"
1091 [ "$ost1_FSTYPE" != ldiskfs ] && skip "non-ldiskfs backend"
1092 [ $OST1_VERSION -lt $(version_code 2.13.50) ] &&
1093 skip "Need OST version at least 2.13.53"
1095 setup_quota_test || error "setup quota failed with $?"
1096 trap cleanup_quota_test EXIT
1099 set_ost_qtype $QTYPE || error "enable ost quota failed"
1102 log "User quota (block hardlimit:$limit MB)"
1103 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1104 error "set user quota failed"
1106 # make sure the system is clean
1107 local used=$(getquota -u $TSTUSR global curspace)
1108 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1110 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1111 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1113 check_write_fallocate $testfile "user" $limit
1116 wait_delete_completed || error "wait_delete_completed failed"
1117 sync_all_data || true
1118 used=$(getquota -u $TSTUSR global curspace)
1119 [ $used -ne 0 ] && quota_error u $TSTUSR \
1120 "user quota isn't released after deletion"
1121 resetquota -u $TSTUSR
1123 run_test 1h "Block hard limit test using fallocate"
1125 # test inode hardlimit
1127 local TESTFILE="$DIR/$tdir/$tfile-0"
1128 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1129 qmt.$FSNAME-QMT0000.md-0x0.info |
1130 awk '/least qunit/{ print $3 }')
1131 local L2=$(do_facet mds1 $LCTL get_param -n \
1132 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1134 [ $L2 -le $LIMIT ] || LIMIT=$L2
1136 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1138 local FREE_INODES=$(mdt_free_inodes 0)
1139 echo "$FREE_INODES free inodes on master MDT"
1140 [ $FREE_INODES -lt $LIMIT ] &&
1141 skip "not enough free inodes $FREE_INODES required $LIMIT"
1143 setup_quota_test || error "setup quota failed with $?"
1144 trap cleanup_quota_test EXIT
1147 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1150 log "User quota (inode hardlimit:$LIMIT files)"
1151 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1152 error "set user quota failed"
1154 # make sure the system is clean
1155 local USED=$(getquota -u $TSTUSR global curinodes)
1156 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1158 log "Create $LIMIT files ..."
1159 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1160 quota_error u $TSTUSR "user create failure, but expect success"
1161 log "Create out of file quota ..."
1162 $RUNAS touch ${TESTFILE}_xxx &&
1163 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1166 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1167 rm -f ${TESTFILE}_xxx
1168 wait_delete_completed
1170 USED=$(getquota -u $TSTUSR global curinodes)
1171 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1172 "user quota isn't released after deletion"
1173 resetquota -u $TSTUSR
1176 log "--------------------------------------"
1177 log "Group quota (inode hardlimit:$LIMIT files)"
1178 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1179 error "set group quota failed"
1181 TESTFILE=$DIR/$tdir/$tfile-1
1182 # make sure the system is clean
1183 USED=$(getquota -g $TSTUSR global curinodes)
1184 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1186 log "Create $LIMIT files ..."
1187 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1188 quota_error g $TSTUSR "group create failure, but expect success"
1189 log "Create out of file quota ..."
1190 $RUNAS touch ${TESTFILE}_xxx &&
1191 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1194 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1195 rm -f ${TESTFILE}_xxx
1196 wait_delete_completed
1198 USED=$(getquota -g $TSTUSR global curinodes)
1199 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1200 "user quota isn't released after deletion"
1202 resetquota -g $TSTUSR
1203 ! is_project_quota_supported && cleanup_quota_test &&
1204 echo "Skip project quota is not supported" && return 0
1207 log "--------------------------------------"
1208 log "Project quota (inode hardlimit:$LIMIT files)"
1209 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1210 error "set project quota failed"
1212 TESTFILE=$DIR/$tdir/$tfile-1
1213 # make sure the system is clean
1214 USED=$(getquota -p $TSTPRJID global curinodes)
1216 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1218 change_project -sp $TSTPRJID $DIR/$tdir
1219 log "Create $LIMIT files ..."
1220 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1221 $TSTPRJID "project create fail, but expect success"
1222 log "Create out of file quota ..."
1223 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1224 "project create success, but expect EDQUOT"
1225 change_project -C $DIR/$tdir
1228 USED=$(getquota -p $TSTPRJID global curinodes)
1229 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1230 "project quota isn't released after deletion"
1233 run_test 2 "File hard limit (normal use and out of quota)"
1244 stack_trap cleanup_quota_test EXIT
1246 $LFS setstripe $testfile -c 1 -i 0
1247 chown $TSTUSR.$TSTUSR $testfile
1248 [ "$qtype" == "p" ] && is_project_quota_supported &&
1249 change_project -p $TSTPRJID $testfile
1251 echo "Write up to soft limit"
1252 $RUNAS $DD of=$testfile count=$limit ||
1253 quota_error a $TSTUSR "write failure, but expect success"
1254 OFFSET=$((limit * 1024))
1255 cancel_lru_locks osc
1257 echo "Write to exceed soft limit"
1258 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1259 quota_error a $TSTUSR "write failure, but expect success"
1260 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1261 cancel_lru_locks osc
1263 echo "mmap write when over soft limit"
1264 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1265 quota_error a $TSTUSR "mmap write failure, but expect success"
1266 cancel_lru_locks osc
1271 $SHOW_QUOTA_INFO_USER
1272 $SHOW_QUOTA_INFO_GROUP
1273 $SHOW_QUOTA_INFO_PROJID
1275 echo "Write before timer goes off"
1276 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1277 quota_error a $TSTUSR "write failure, but expect success"
1278 OFFSET=$((OFFSET + 1024))
1279 cancel_lru_locks osc
1281 wait_grace_time $qtype "block" $pool
1286 $SHOW_QUOTA_INFO_USER
1287 $SHOW_QUOTA_INFO_GROUP
1288 $SHOW_QUOTA_INFO_PROJID
1290 log "Write after timer goes off"
1291 # maybe cache write, ignore.
1292 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1293 OFFSET=$((OFFSET + 1024))
1294 cancel_lru_locks osc
1295 log "Write after cancel lru locks"
1296 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1297 quota_error a $TSTUSR "write success, but expect EDQUOT"
1302 $SHOW_QUOTA_INFO_USER
1303 $SHOW_QUOTA_INFO_GROUP
1304 $SHOW_QUOTA_INFO_PROJID
1306 echo "Unlink file to stop timer"
1308 wait_delete_completed
1309 sync_all_data || true
1314 $SHOW_QUOTA_INFO_USER
1315 $SHOW_QUOTA_INFO_GROUP
1316 $SHOW_QUOTA_INFO_PROJID
1318 $LFS setstripe $testfile -c 1 -i 0
1319 chown $TSTUSR.$TSTUSR $testfile
1320 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1323 $RUNAS $DD of=$testfile count=$limit ||
1324 quota_error a $TSTUSR "write failure, but expect success"
1331 local grace=20 # 20s
1332 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1335 local testfile=$DIR/$tdir/$tfile-0
1337 # get minimum soft qunit size
1338 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1339 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1341 set_ost_qtype $QTYPE || error "enable ost quota failed"
1343 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1344 # make sure the system is clean
1345 local used=$(getquota -u $TSTUSR global curspace)
1346 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1348 $LFS setquota -t -u --block-grace $grace --inode-grace \
1349 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1350 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1351 error "set user quota failed"
1353 test_block_soft $testfile $grace $limit "u"
1355 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1356 testfile=$DIR/$tdir/$tfile-1
1357 # make sure the system is clean
1358 used=$(getquota -g $TSTUSR global curspace)
1359 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1361 $LFS setquota -t -g --block-grace $grace --inode-grace \
1362 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1363 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1364 error "set group quota failed"
1366 test_block_soft $testfile $grace $limit "g"
1368 if is_project_quota_supported; then
1369 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1370 testfile=$DIR/$tdir/$tfile-2
1371 # make sure the system is clean
1372 used=$(getquota -p $TSTPRJID global curspace)
1373 [ $used -ne 0 ] && error \
1374 "Used space($used) for project $TSTPRJID isn't 0."
1376 $LFS setquota -t -p --block-grace $grace --inode-grace \
1377 $MAX_IQ_TIME $DIR ||
1378 error "set project grace time failed"
1379 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1380 $DIR || error "set project quota failed"
1382 test_block_soft $testfile $grace $limit "p"
1383 resetquota -p $TSTPRJID
1384 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1385 $MAX_IQ_TIME $DIR ||
1386 error "restore project grace time failed"
1390 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1391 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1392 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1393 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1395 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1398 local grace=20 # 20s
1399 local qpool="qpool1"
1400 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1403 local testfile=$DIR/$tdir/$tfile-0
1406 # get minimum soft qunit size
1407 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1408 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1409 local glbl_limit=$((2*limit))
1410 local glbl_grace=$((2*grace))
1411 echo "limit $limit glbl_limit $glbl_limit"
1412 echo "grace $grace glbl_grace $glbl_grace"
1414 set_ost_qtype $QTYPE || error "enable ost quota failed"
1416 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1417 # make sure the system is clean
1418 local used=$(getquota -u $TSTUSR global curspace)
1419 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1421 pool_add $qpool || error "pool_add failed"
1422 pool_add_targets $qpool 0 1 ||
1423 error "pool_add_targets failed"
1425 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1426 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1427 $LFS setquota -t -u --block-grace $grace \
1428 --pool $qpool $DIR || error "set user grace time failed"
1430 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1431 error "set user quota failed"
1432 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1433 error "set user quota failed"
1435 test_block_soft $testfile $grace $limit "u" $qpool
1437 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1438 testfile=$DIR/$tdir/$tfile-1
1439 # make sure the system is clean
1440 used=$(getquota -g $TSTUSR global curspace)
1441 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1443 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1444 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1445 $LFS setquota -t -g --block-grace $grace \
1446 --pool $qpool $DIR || error "set group grace time failed"
1448 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1449 error "set group quota failed"
1450 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1451 error "set group quota failed"
1453 test_block_soft $testfile $grace $limit "g" $qpool
1455 if is_project_quota_supported; then
1456 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1457 testfile=$DIR/$tdir/$tfile-2
1458 # make sure the system is clean
1459 used=$(getquota -p $TSTPRJID global curspace)
1460 [ $used -ne 0 ] && error \
1461 "Used space($used) for project $TSTPRJID isn't 0."
1463 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1464 $MAX_IQ_TIME $DIR ||
1465 error "set project grace time failed"
1466 $LFS setquota -t -p --block-grace $grace \
1467 --pool $qpool $DIR ||
1468 error "set project grace time failed"
1470 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1471 $DIR || error "set project quota failed"
1472 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1473 --pool $qpool $DIR || error "set project quota failed"
1475 test_block_soft $testfile $grace $limit "p" $qpool
1476 resetquota -p $TSTPRJID
1477 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1478 $MAX_IQ_TIME $DIR ||
1479 error "restore project grace time failed"
1480 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1481 $DIR || error "set project grace time failed"
1485 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1486 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1487 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1488 --pool $qpool $DIR || error "restore user grace time failed"
1489 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1490 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1491 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1492 --pool $qpool $DIR || error "restore group grace time failed"
1494 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1497 local grace=20 # 20s
1498 local qpool="qpool1"
1499 local qpool2="qpool2"
1500 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1503 local testfile=$DIR/$tdir/$tfile-0
1506 # get minimum soft qunit size
1507 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1508 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1509 local limit2=$((limit+4))
1510 local glbl_limit=$((limit+8))
1511 local grace1=$((grace+10))
1513 local glbl_grace=$((grace+20))
1514 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1515 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1517 set_ost_qtype $QTYPE || error "enable ost quota failed"
1519 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1520 # make sure the system is clean
1521 local used=$(getquota -u $TSTUSR global curspace)
1522 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1524 pool_add $qpool || error "pool_add failed"
1525 pool_add_targets $qpool 0 1 ||
1526 error "pool_add_targets failed"
1528 pool_add $qpool2 || error "pool_add failed"
1529 pool_add_targets $qpool2 0 1 ||
1530 error "pool_add_targets failed"
1533 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1534 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1535 $LFS setquota -t -u --block-grace $grace1 \
1536 --pool $qpool $DIR || error "set user grace time failed"
1537 $LFS setquota -t -u --block-grace $grace2 \
1538 --pool $qpool2 $DIR || error "set user grace time failed"
1540 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1541 error "set user quota failed"
1542 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1543 error "set user quota failed"
1544 # qpool has minimum soft limit, but it's grace is grater than
1545 # grace period of qpool2. Thus write shouldn't fail when
1546 # hit qpool soft limit - only when reaches up qpool2 limit
1547 # after grace2 seconds.
1548 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1549 error "set user quota failed"
1551 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1554 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1555 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1556 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1557 --pool $qpool $DIR || error "restore user grace time failed"
1558 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1559 --pool $qpool2 $DIR || error "restore user grace time failed"
1561 run_test 3c "Quota pools: check block soft limit on different pools"
1570 trap cleanup_quota_test EXIT
1571 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1573 echo "Create files to exceed soft limit"
1574 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1575 quota_error a $TSTUSR "create failure, but expect success"
1576 local trigger_time=$(date +%s)
1578 sync_all_data || true
1580 local cur_time=$(date +%s)
1581 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1582 error "Passed grace time $grace, $trigger_time, $cur_time"
1584 echo "Create file before timer goes off"
1585 $RUNAS touch ${TESTFILE}_before ||
1586 quota_error a $TSTUSR "failed create before timer expired," \
1587 "but expect success. $trigger_time, $cur_time"
1588 sync_all_data || true
1590 wait_grace_time $qtype "file"
1595 $SHOW_QUOTA_INFO_USER
1596 $SHOW_QUOTA_INFO_GROUP
1597 $SHOW_QUOTA_INFO_PROJID
1599 echo "Create file after timer goes off"
1600 # There is a window that space is accounted in the quota usage but
1601 # hasn't been decreased from the pending write, if we acquire quota
1602 # in this window, we'll acquire more than we needed.
1603 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
1604 sync_all_data || true
1605 $RUNAS touch ${TESTFILE}_after_3 &&
1606 quota_error a $TSTUSR "create after timer expired," \
1608 sync_all_data || true
1613 $SHOW_QUOTA_INFO_USER
1614 $SHOW_QUOTA_INFO_GROUP
1615 $SHOW_QUOTA_INFO_PROJID
1617 echo "Unlink files to stop timer"
1618 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1619 wait_delete_completed
1622 $RUNAS touch ${TESTFILE}_xxx ||
1623 quota_error a $TSTUSR "touch after timer stop failure," \
1624 "but expect success"
1625 sync_all_data || true
1633 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1634 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1635 local TESTFILE=$DIR/$tdir/$tfile-0
1638 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1640 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1641 # make sure the system is clean
1642 local USED=$(getquota -u $TSTUSR global curinodes)
1643 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1645 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1646 $GRACE $DIR || error "set user grace time failed"
1647 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1648 error "set user quota failed"
1650 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1652 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1654 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1655 # make sure the system is clean
1656 USED=$(getquota -g $TSTUSR global curinodes)
1657 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1659 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1660 $GRACE $DIR || error "set group grace time failed"
1661 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1662 error "set group quota failed"
1663 TESTFILE=$DIR/$tdir/$tfile-1
1665 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1667 if is_project_quota_supported; then
1668 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1669 # make sure the system is clean
1670 USED=$(getquota -p $TSTPRJID global curinodes)
1671 [ $USED -ne 0 ] && error \
1672 "Used space($USED) for project $TSTPRJID isn't 0."
1674 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1675 $GRACE $DIR || error "set project grace time failed"
1676 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1677 error "set project quota failed"
1679 TESTFILE=$DIR/$tdir/$tfile-1
1680 # one less than limit, because of parent directory included.
1681 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1682 resetquota -p $TSTPRJID
1683 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1684 $MAX_IQ_TIME $DIR ||
1685 error "restore project grace time failed"
1689 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1690 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1691 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1692 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1694 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1697 local GR_STR1="1w3d"
1698 local GR_STR2="1000s"
1700 local GR_STR4="1w2d3h4m5s"
1702 local GR_STR6="18446744073709551615"
1705 wait_delete_completed
1707 # test of valid grace strings handling
1708 echo "Valid grace strings test"
1709 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1710 $GR_STR2 $DIR || error "set user grace time failed"
1711 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1712 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1713 $GR_STR4 $DIR || error "set group grace time quota failed"
1714 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1716 # test of invalid grace strings handling
1717 echo " Invalid grace strings test"
1718 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1719 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1720 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1724 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1725 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1726 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1727 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1729 run_test 4b "Grace time strings handling"
1731 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1733 local BLIMIT=10 # 10M
1734 local ILIMIT=10 # 10 inodes
1736 setup_quota_test || error "setup quota failed with $?"
1737 trap cleanup_quota_test EXIT
1739 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1740 set_ost_qtype $QTYPE || error "enable ost quota failed"
1742 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1743 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1744 error "set user quota failed"
1745 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1746 if is_project_quota_supported; then
1747 error "set group quota failed"
1748 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1749 -I $ILIMIT $DIR || error "set project quota failed"
1752 # make sure the system is clean
1753 local USED=$(getquota -u $TSTUSR global curinodes)
1754 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1755 USED=$(getquota -g $TSTUSR global curinodes)
1756 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1757 USED=$(getquota -u $TSTUSR global curspace)
1758 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1759 USED=$(getquota -g $TSTUSR global curspace)
1760 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1761 if is_project_quota_supported; then
1762 USED=$(getquota -p $TSTPRJID global curinodes)
1764 error "Used inode($USED) for project $TSTPRJID isn't 0."
1765 USED=$(getquota -p $TSTPRJID global curspace)
1767 error "Used block($USED) for project $TSTPRJID isn't 0."
1770 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1771 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1772 error "create failure, expect success"
1773 if is_project_quota_supported; then
1774 touch $DIR/$tdir/$tfile-0_1
1775 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1777 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1778 error "write failure, expect success"
1780 echo "Chown files to $TSTUSR.$TSTUSR ..."
1781 for i in $(seq 0 $ILIMIT); do
1782 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1783 quota_error a $TSTUSR "chown failure, expect success"
1787 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1788 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1791 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1793 # test dropping acquire request on master
1797 # Clear dmesg so watchdog is not triggered by previous
1799 do_facet ost1 dmesg -c > /dev/null
1801 setup_quota_test || error "setup quota failed with $?"
1802 trap cleanup_quota_test EXIT
1804 # make sure the system is clean
1805 local USED=$(getquota -u $TSTUSR global curspace)
1806 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1808 # make sure no granted quota on ost
1809 set_ost_qtype $QTYPE || error "enable ost quota failed"
1810 resetquota -u $TSTUSR
1812 # create file for $TSTUSR
1813 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1814 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1815 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1817 # create file for $TSTUSR2
1818 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1819 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1820 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1822 # cache per-ID lock for $TSTUSR on slave
1823 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1824 error "set quota failed"
1825 $RUNAS $DD of=$TESTFILE count=1 ||
1826 error "write $TESTFILE failure, expect success"
1827 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1828 error "write $TESTFILE2 failure, expect success"
1830 if at_is_enabled; then
1831 at_max_saved=$(at_max_get ost1)
1832 at_max_set $TIMEOUT ost1
1834 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1835 # DQACQ is sent, which makes at_max to take effect
1836 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1839 wait_delete_completed
1843 sync_all_data || true
1845 #define QUOTA_DQACQ 601
1846 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1847 lustre_fail mds 0x513 601
1849 do_facet ost1 $LCTL set_param \
1850 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1852 # write to un-enforced ID ($TSTUSR2) should succeed
1853 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1854 error "write failure, expect success"
1856 # write to enforced ID ($TSTUSR) in background, exceeding limit
1857 # to make sure DQACQ is sent
1858 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1861 # watchdog timer uses a factor of 2
1862 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1863 sleep $((TIMEOUT * 2 + 1))
1865 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1867 # write should be blocked and never finished
1868 if ! ps -p $DDPID > /dev/null 2>&1; then
1870 error "write finished incorrectly!"
1875 # no watchdog is triggered
1876 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1877 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1878 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1879 [ -z "$watchdog" ] || error "$watchdog"
1881 rm -f $TMP/lustre-log-${TESTNAME}.log
1883 # write should continue then fail with EDQUOT
1887 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1888 if [ $count -ge 240 ]; then
1889 quota_error u $TSTUSR "dd not finished in $count secs"
1891 count=$((count + 1))
1892 if [ $((count % 30)) -eq 0 ]; then
1893 c_size=$(stat -c %s $TESTFILE)
1894 echo "Waiting $count secs. $c_size"
1902 run_test 6 "Test dropping acquire request on master"
1904 # quota reintegration (global index)
1906 local TESTFILE=$DIR/$tdir/$tfile
1907 local LIMIT=20 # 20M
1909 [ "$SLOW" = "no" ] && LIMIT=5
1911 setup_quota_test || error "setup quota failed with $?"
1912 trap cleanup_quota_test EXIT
1914 # make sure the system is clean
1915 local USED=$(getquota -u $TSTUSR global curspace)
1916 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1918 # make sure no granted quota on ost1
1919 set_ost_qtype $QTYPE || error "enable ost quota failed"
1920 resetquota -u $TSTUSR
1921 set_ost_qtype "none" || error "disable ost quota failed"
1923 local OSTUUID=$(ostuuid_from_index 0)
1924 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1926 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1929 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1930 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1935 echo "Enable quota & set quota limit for $TSTUSR"
1936 set_ost_qtype $QTYPE || error "enable ost quota failed"
1937 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1938 error "set quota failed"
1940 echo "Start ost1..."
1941 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1944 wait_ost_reint $QTYPE || error "reintegration failed"
1946 # hardlimit should have been fetched by slave during global
1947 # reintegration, write will exceed quota
1948 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1949 quota_error u $TSTUSR "write success, but expect EDQUOT"
1952 wait_delete_completed
1953 sync_all_data || true
1959 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1960 error "clear quota failed"
1962 echo "Start ost1..."
1963 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1966 wait_ost_reint $QTYPE || error "reintegration failed"
1968 # hardlimit should be cleared on slave during reintegration
1969 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1970 quota_error u $TSTUSR "write error, but expect success"
1974 run_test 7a "Quota reintegration (global index)"
1976 # quota reintegration (slave index)
1979 local TESTFILE=$DIR/$tdir/$tfile
1981 setup_quota_test || error "setup quota failed with $?"
1982 trap cleanup_quota_test EXIT
1984 # make sure the system is clean
1985 local USED=$(getquota -u $TSTUSR global curspace)
1986 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1988 # make sure no granted quota on ost1
1989 set_ost_qtype $QTYPE || error "enable ost quota failed"
1990 resetquota -u $TSTUSR
1991 set_ost_qtype "none" || error "disable ost quota failed"
1993 local OSTUUID=$(ostuuid_from_index 0)
1994 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1996 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1999 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2000 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2002 # consume some space to make sure the granted space will not
2003 # be released during reconciliation
2004 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2005 error "consume space failure, expect success"
2007 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2008 lustre_fail mds 0xa02
2010 set_ost_qtype $QTYPE || error "enable ost quota failed"
2011 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2012 error "set quota failed"
2014 # ignore the write error
2015 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2017 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2021 echo "Restart ost to trigger reintegration..."
2023 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2026 wait_ost_reint $QTYPE || error "reintegration failed"
2028 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2029 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2034 run_test 7b "Quota reintegration (slave index)"
2036 # quota reintegration (restart mds during reintegration)
2038 local LIMIT=20 # 20M
2039 local TESTFILE=$DIR/$tdir/$tfile
2041 [ "$SLOW" = "no" ] && LIMIT=5
2043 setup_quota_test || error "setup quota failed with $?"
2044 trap cleanup_quota_test EXIT
2046 # make sure the system is clean
2047 local USED=$(getquota -u $TSTUSR global curspace)
2048 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2050 set_ost_qtype "none" || error "disable ost quota failed"
2051 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2052 error "set quota failed"
2054 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2055 lustre_fail ost 0xa03
2058 set_ost_qtype $QTYPE || error "enable ost quota failed"
2059 # trigger reintegration
2060 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2061 procf=${procf}quota_slave.force_reint
2062 do_facet ost1 $LCTL set_param $procf=1 ||
2063 error "force reintegration failed"
2071 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2074 # wait longer than usual to make sure the reintegration
2075 # is triggered by quota wb thread.
2076 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2078 # hardlimit should have been fetched by slave during global
2079 # reintegration, write will exceed quota
2080 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2081 quota_error u $TSTUSR "write success, but expect EDQUOT"
2085 run_test 7c "Quota reintegration (restart mds during reintegration)"
2087 # Quota reintegration (Transfer index in multiple bulks)
2089 local TESTFILE=$DIR/$tdir/$tfile
2090 local TESTFILE1="$DIR/$tdir/$tfile"-1
2093 setup_quota_test || error "setup quota failed with $?"
2094 trap cleanup_quota_test EXIT
2096 set_ost_qtype "none" || error "disable ost quota failed"
2097 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2098 error "set quota for $TSTUSR failed"
2099 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2100 error "set quota for $TSTUSR2 failed"
2102 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2103 lustre_fail mds 0x608 0
2105 # enable quota to tirgger reintegration
2106 set_ost_qtype "u" || error "enable ost quota failed"
2107 wait_ost_reint "u" || error "reintegration failed"
2111 # hardlimit should have been fetched by slave during global
2112 # reintegration, write will exceed quota
2113 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2114 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2116 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2117 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2121 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2123 # quota reintegration (inode limits)
2125 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2127 # LU-2435: skip this quota test if underlying zfs version has not
2128 # supported native dnode accounting
2129 [ "$mds1_FSTYPE" == zfs ] && {
2130 local F="feature@userobj_accounting"
2131 local pool=$(zpool_name mds1)
2132 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2134 [[ "$feature" != *" active "* ]] &&
2135 skip "requires zpool with active userobj_accounting"
2138 local ilimit=$((1024 * 2)) # 2k inodes
2139 local TESTFILE=$DIR/${tdir}-1/$tfile
2141 setup_quota_test || error "setup quota failed with $?"
2142 trap cleanup_quota_test EXIT
2144 # make sure the system is clean
2145 local USED=$(getquota -u $TSTUSR global curinodes)
2146 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2148 # make sure no granted quota on mdt1
2149 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2150 resetquota -u $TSTUSR
2151 set_mdt_qtype "none" || error "disable mdt quota failed"
2153 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2154 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2155 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2158 echo "Stop mds${MDSCOUNT}..."
2161 echo "Enable quota & set quota limit for $TSTUSR"
2162 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2163 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2164 error "set quota failed"
2166 echo "Start mds${MDSCOUNT}..."
2167 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2170 wait_mdt_reint $QTYPE || error "reintegration failed"
2172 echo "create remote dir"
2173 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2174 error "create remote dir failed"
2175 chmod 0777 $DIR/${tdir}-1
2177 # hardlimit should have been fetched by slave during global
2178 # reintegration, create will exceed quota
2179 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2180 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2182 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2183 wait_delete_completed
2184 sync_all_data || true
2186 echo "Stop mds${MDSCOUNT}..."
2189 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2190 error "clear quota failed"
2192 echo "Start mds${MDSCOUNT}..."
2193 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2196 wait_mdt_reint $QTYPE || error "reintegration failed"
2198 # hardlimit should be cleared on slave during reintegration
2199 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2200 quota_error u $TSTUSR "create failed, expect success"
2202 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2203 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2207 run_test 7e "Quota reintegration (inode limits)"
2209 # run dbench with quota enabled
2211 local BLK_LIMIT="100g" #100G
2212 local FILE_LIMIT=1000000
2214 setup_quota_test || error "setup quota failed with $?"
2215 trap cleanup_quota_test EXIT
2217 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2218 set_ost_qtype $QTYPE || error "enable ost quota failed"
2220 echo "Set enough high limit for user: $TSTUSR"
2221 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2222 error "set user quota failed"
2223 echo "Set enough high limit for group: $TSTUSR"
2224 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2225 error "set group quota failed"
2226 if is_project_quota_supported; then
2227 change_project -sp $TSTPRJID $DIR/$tdir
2228 echo "Set enough high limit for project: $TSTPRJID"
2229 $LFS setquota -p $TSTPRJID -b 0 \
2230 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2231 error "set project quota failed"
2235 [ "$SLOW" = "no" ] && duration=" -t 120"
2236 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2237 quota_error a $TSTUSR "dbench failed!"
2239 is_project_quota_supported && change_project -C $DIR/$tdir
2242 run_test 8 "Run dbench with quota enabled"
2244 # this check is just for test_9
2245 OST0_MIN=4900000 #4.67G
2247 check_whether_skip () {
2248 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2249 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2250 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2251 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2258 # run for fixing bug10707, it needs a big room. test for 64bit
2260 local filesize=$((1024 * 9 / 2)) # 4.5G
2262 check_whether_skip && return 0
2264 setup_quota_test || error "setup quota failed with $?"
2265 trap cleanup_quota_test EXIT
2267 set_ost_qtype "ug" || error "enable ost quota failed"
2269 local TESTFILE="$DIR/$tdir/$tfile-0"
2270 local BLK_LIMIT=100G #100G
2271 local FILE_LIMIT=1000000
2273 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2275 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2277 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2278 error "set user quota failed"
2280 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2281 "for group: $TSTUSR"
2282 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2283 error "set group quota failed"
2285 quota_show_check a u $TSTUSR
2286 quota_show_check a g $TSTUSR
2288 echo "Create test file"
2289 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2290 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2292 log "Write the big file of 4.5G ..."
2293 $RUNAS $DD of=$TESTFILE count=$filesize ||
2294 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2304 run_test 9 "Block limit larger than 4GB (b10707)"
2307 local TESTFILE=$DIR/$tdir/$tfile
2309 setup_quota_test || error "setup quota failed with $?"
2310 trap cleanup_quota_test EXIT
2312 # set limit to root user should fail
2313 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2314 error "set limit for root user successfully, expect failure"
2315 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2316 error "set limit for root group successfully, expect failure"
2317 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2318 error "set limit for project 0 successfully, expect failure"
2320 # root user can overrun quota
2321 set_ost_qtype "ug" || error "enable ost quota failed"
2323 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2324 error "set quota failed"
2325 quota_show_check b u $TSTUSR
2327 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2328 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2330 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2331 error "write failure, expect success"
2335 run_test 10 "Test quota for root user"
2338 local TESTFILE=$DIR/$tdir/$tfile
2339 setup_quota_test || error "setup quota failed with $?"
2340 trap cleanup_quota_test EXIT
2342 set_mdt_qtype "ug" || error "enable mdt quota failed"
2343 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2344 error "set quota failed"
2346 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2347 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2349 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2350 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2353 local USED=$(getquota -u $TSTUSR global curinodes)
2354 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2358 run_test 11 "Chown/chgrp ignores quota"
2361 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2363 local blimit=22 # 22M
2364 local blk_cnt=$((blimit - 5))
2365 local TESTFILE0="$DIR/$tdir/$tfile"-0
2366 local TESTFILE1="$DIR/$tdir/$tfile"-1
2368 setup_quota_test || error "setup quota failed with $?"
2369 trap cleanup_quota_test EXIT
2371 set_ost_qtype "u" || error "enable ost quota failed"
2372 quota_show_check b u $TSTUSR
2374 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2375 error "set quota failed"
2377 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2378 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2379 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2380 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2382 echo "Write to ost0..."
2383 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2384 quota_error a $TSTUSR "dd failed"
2386 echo "Write to ost1..."
2387 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2388 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2390 echo "Free space from ost0..."
2392 wait_delete_completed
2393 sync_all_data || true
2395 echo "Write to ost1 after space freed from ost0..."
2396 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2397 quota_error a $TSTUSR "rebalancing failed"
2401 run_test 12a "Block quota rebalancing"
2404 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2406 local ilimit=$((1024 * 2)) # 2k inodes
2407 local TESTFILE0=$DIR/$tdir/$tfile
2408 local TESTFILE1=$DIR/${tdir}-1/$tfile
2410 setup_quota_test || error "setup quota failed with $?"
2411 trap cleanup_quota_test EXIT
2413 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2414 chmod 0777 $DIR/${tdir}-1
2416 set_mdt_qtype "u" || error "enable mdt quota failed"
2417 quota_show_check f u $TSTUSR
2419 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2420 error "set quota failed"
2422 echo "Create $ilimit files on mdt0..."
2423 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2424 quota_error u $TSTUSR "create failed, but expect success"
2426 echo "Create files on mdt1..."
2427 $RUNAS createmany -m $TESTFILE1 1 &&
2428 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2430 echo "Free space from mdt0..."
2431 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2432 wait_delete_completed
2433 sync_all_data || true
2435 echo "Create files on mdt1 after space freed from mdt0..."
2436 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2437 quota_error a $TSTUSR "rebalancing failed"
2439 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2440 error "unlink mdt1 files failed"
2441 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2445 run_test 12b "Inode quota rebalancing"
2448 local TESTFILE=$DIR/$tdir/$tfile
2449 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2450 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2452 setup_quota_test || error "setup quota failed with $?"
2453 trap cleanup_quota_test EXIT
2455 set_ost_qtype "u" || error "enable ost quota failed"
2456 quota_show_check b u $TSTUSR
2458 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2459 error "set quota failed"
2460 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2461 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2463 # clear the locks in cache first
2464 do_facet ost1 $LCTL set_param -n $procf=clear
2465 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2466 [ $nlock -eq 0 ] || error "$nlock cached locks"
2468 # write to acquire the per-ID lock
2469 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2470 quota_error a $TSTUSR "dd failed"
2472 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2473 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2475 # clear quota doesn't trigger per-ID lock cancellation
2476 resetquota -u $TSTUSR
2477 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2478 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2480 # clear the per-ID lock
2481 do_facet ost1 $LCTL set_param -n $procf=clear
2482 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2483 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2485 # spare quota should be released
2486 local OSTUUID=$(ostuuid_from_index 0)
2487 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2488 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2489 [ $limit -le $space ] ||
2490 error "spare quota isn't released, limit:$limit, space:$space"
2494 run_test 13 "Cancel per-ID lock in the LRU list"
2497 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2499 wait_delete_completed
2500 sync_all_data || true
2503 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2504 error "set user quota failed"
2505 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2506 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2507 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2508 resetquota -u $TSTUSR
2511 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2512 error "set group quota failed"
2513 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2514 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2515 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2516 resetquota -g $TSTUSR
2518 run_test 15 "Set over 4T block quota"
2522 local BLKS=1 # 1M less than limit
2523 local TESTFILE=$DIR/$tdir/$tfile
2525 setup_quota_test || error "setup quota failed with $?"
2526 trap cleanup_quota_test EXIT
2528 # make sure the system is clean
2529 local USED=$(getquota -u $TSTUSR global curspace)
2530 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2532 set_ost_qtype "ug" || error "enable ost quota failed"
2533 # make sure no granted quota on ost
2534 resetquota -u $TSTUSR
2535 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2536 error "set quota failed"
2538 quota_show_check b u $TSTUSR
2540 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2541 lustre_fail mds 0xa04 $err_code
2543 # write in background
2544 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2548 # write should be blocked and never finished
2549 if ! ps -p $DDPID > /dev/null 2>&1; then
2551 quota_error u $TSTUSR "write finished incorrectly!"
2559 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2561 if [ $count -gt $timeout ]; then
2562 quota_error u $TSTUSR "dd is not finished!"
2567 sync; sync_all_data || true
2569 USED=$(getquota -u $TSTUSR global curspace)
2570 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2571 "Used space(${USED}K) is less than ${BLKS}M"
2576 # DQACQ return recoverable error
2578 echo "DQACQ return -ENOLCK"
2580 test_17sub 37 || error "Handle -ENOLCK failed"
2582 echo "DQACQ return -EAGAIN"
2584 test_17sub 11 || error "Handle -EAGAIN failed"
2586 echo "DQACQ return -ETIMEDOUT"
2587 #define ETIMEDOUT 110
2588 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2590 echo "DQACQ return -ENOTCONN"
2591 #define ENOTCONN 107
2592 test_17sub 107 || error "Handle -ENOTCONN failed"
2595 run_test 17 "DQACQ return recoverable error"
2599 local blimit="200m" # 200M
2600 local TESTFILE="$DIR/$tdir/$tfile"
2602 setup_quota_test || error "setup quota failed with $?"
2603 trap cleanup_quota_test EXIT
2605 set_ost_qtype "u" || error "enable ost quota failed"
2606 log "User quota (limit: $blimit)"
2607 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2608 error "set quota failed"
2609 quota_show_check b u $TSTUSR
2611 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2612 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2614 local timeout=$(sysctl -n lustre.timeout)
2616 if [ $io_type = "directio" ]; then
2617 log "Write 100M (directio) ..."
2618 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2620 log "Write 100M (buffered) ..."
2621 $RUNAS $DD of=$TESTFILE count=100 &
2625 replay_barrier $SINGLEMDS
2626 log "Fail mds for $((2 * timeout)) seconds"
2627 fail $SINGLEMDS $((2 * timeout))
2630 if at_is_enabled; then
2631 timeout=$(at_max_get mds)
2633 timeout=$(lctl get_param -n timeout)
2637 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2638 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2639 log "it took $count second"
2644 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2646 cancel_lru_locks mdc
2647 cancel_lru_locks osc
2650 local testfile_size=$(stat -c %s $TESTFILE)
2651 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2652 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2653 "got ${testfile_size}. Verifying file failed!"
2658 # test when mds does failover, the ost still could work well
2659 # this test shouldn't trigger watchdog b=14840
2661 # Clear dmesg so watchdog is not triggered by previous
2663 do_facet ost1 dmesg -c > /dev/null
2666 test_18_sub directio
2668 # check if watchdog is triggered
2669 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2670 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2671 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2672 [ -z "$watchdog" ] || error "$watchdog"
2673 rm -f $TMP/lustre-log-${TESTNAME}.log
2675 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2679 local TESTFILE=$DIR/$tdir/$tfile
2681 setup_quota_test || error "setup quota failed with $?"
2682 trap cleanup_quota_test EXIT
2684 set_ost_qtype $QTYPE || error "enable ost quota failed"
2686 # bind file to a single OST
2687 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2688 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2690 echo "Set user quota (limit: ${blimit}M)"
2691 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2692 error "set user quota failed"
2693 quota_show_check b u $TSTUSR
2694 echo "Update quota limits"
2695 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2696 error "set group quota failed"
2697 quota_show_check b u $TSTUSR
2699 # first wirte might be cached
2700 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2701 cancel_lru_locks osc
2703 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2704 quota_error u $TSTUSR "Write success, expect failure"
2709 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2711 test_20() { # b15754
2712 local LSTR=(2g 1t 4k 3m) # limits strings
2714 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2717 resetquota -u $TSTUSR
2719 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2720 $MOUNT || error "could not set quota limits"
2721 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2722 --inode-softlimit ${LSTR[2]} \
2723 --inode-hardlimit ${LSTR[3]} \
2724 $MOUNT || error "could not set quota limits"
2726 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2727 error "bsoftlimit was not set properly"
2728 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2729 error "bhardlimit was not set properly"
2730 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2731 error "isoftlimit was not set properly"
2732 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2733 error "ihardlimit was not set properly"
2735 resetquota -u $TSTUSR
2737 run_test 20 "Test if setquota specifiers work properly (b15754)"
2744 local time=$(($(date +%s) + seconds))
2745 while [ $(date +%s) -lt $time ]; do
2746 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2750 # run for fixing bug16053, setquota shouldn't fail when writing and
2751 # deleting are happening
2753 local TESTFILE="$DIR/$tdir/$tfile"
2754 local BLIMIT=10 # 10G
2755 local ILIMIT=1000000
2757 setup_quota_test || error "setup quota failed with $?"
2758 trap cleanup_quota_test EXIT
2760 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2762 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2763 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2764 error "set user quota failed"
2765 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2766 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2767 error "set group quota failed"
2768 if is_project_quota_supported; then
2769 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2770 "project: $TSTPRJID"
2771 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2772 $MOUNT || error "set project quota failed"
2775 # repeat writing on a 1M file
2776 test_21_sub ${TESTFILE}_1 1 30 &
2778 # repeat writing on a 128M file
2779 test_21_sub ${TESTFILE}_2 128 30 &
2782 local time=$(($(date +%s) + 30))
2784 while [ $(date +%s) -lt $time ]; do
2785 log "Set quota for $i times"
2786 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2787 -I $((ILIMIT + i)) $MOUNT ||
2788 error "Set user quota failed"
2789 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2790 -I $((ILIMIT + i)) $MOUNT ||
2791 error "Set group quota failed"
2792 if is_project_quota_supported; then
2793 $LFS setquota -p $TSTPRJID -b 0 -B \
2794 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2795 error "Set project quota failed"
2803 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2805 if [ $count -gt 60 ]; then
2806 quota_error a $TSTUSR "dd should be finished!"
2810 echo "(dd_pid=$DDPID1, time=$count)successful"
2814 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2816 if [ $count -gt 60 ]; then
2817 quota_error a $TSTUSR "dd should be finished!"
2821 echo "(dd_pid=$DDPID2, time=$count)successful"
2825 run_test 21 "Setquota while writing & deleting (b16053)"
2827 # enable/disable quota enforcement permanently
2829 echo "Set both mdt & ost quota type as ug"
2831 is_project_quota_supported && qtype=$QTYPE
2832 set_mdt_qtype $qtype || error "enable mdt quota failed"
2833 set_ost_qtype $qtype || error "enable ost quota failed"
2836 stopall || error "failed to stopall (1)"
2840 echo "Verify if quota is enabled"
2841 local qtype1=$(mdt_quota_type)
2842 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2843 qtype=$(ost_quota_type)
2844 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2846 echo "Set both mdt & ost quota type as none"
2847 set_mdt_qtype "none" || error "disable mdt quota failed"
2848 set_ost_qtype "none" || error "disable ost quota failed"
2851 stopall || error "failed to stopall (2)"
2856 echo "Verify if quota is disabled"
2857 qtype=$(mdt_quota_type)
2858 [ $qtype != "none" ] && error "mdt quota setting is lost"
2859 qtype=$(ost_quota_type)
2860 [ $qtype != "none" ] && error "ost quota setting is lost"
2864 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2867 local TESTFILE="$DIR/$tdir/$tfile"
2870 setup_quota_test || error "setup quota failed with $?"
2871 trap cleanup_quota_test EXIT
2873 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2876 log "User quota (limit: $LIMIT MB)"
2877 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2878 error "set quota failed"
2879 quota_show_check b u $TSTUSR
2881 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2882 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2884 log "Step1: trigger EDQUOT with O_DIRECT"
2885 log "Write half of file"
2886 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2887 quota_error u $TSTUSR "(1) Write failure, expect success." \
2889 log "Write out of block quota ..."
2890 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2891 oflag=direct conv=notrunc &&
2892 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2896 log "Step2: rewrite should succeed"
2897 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2898 quota_error u $TSTUSR "(3) Write failure, expect success." \
2904 local OST0_UUID=$(ostuuid_from_index 0)
2905 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2906 [ $OST0_QUOTA_USED -ne 0 ] &&
2907 ($SHOW_QUOTA_USER; \
2908 quota_error u $TSTUSR "quota isn't released")
2913 [ "$ost1_FSTYPE" == zfs ] &&
2914 skip "Overwrite in place is not guaranteed to be " \
2915 "space neutral on ZFS"
2917 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2918 check_whether_skip && return 0
2919 log "run for 4MB test file"
2922 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2923 check_whether_skip && return 0
2924 log "run for 40MB test file"
2927 run_test 23 "Quota should be honored with directIO (b16125)"
2931 local TESTFILE="$DIR/$tdir/$tfile"
2933 setup_quota_test || error "setup quota failed with $?"
2934 trap cleanup_quota_test EXIT
2936 set_ost_qtype $QTYPE || error "enable ost quota failed"
2938 # bind file to a single OST
2939 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2940 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2942 echo "Set user quota (limit: ${blimit}M)"
2943 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2944 error "set quota failed"
2946 # overrun quota by root user
2947 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2948 error "write failure, expect success"
2949 cancel_lru_locks osc
2950 sync_all_data || true
2952 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2956 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2958 test_27a() { # b19612
2959 $LFS quota $TSTUSR $DIR &&
2960 error "lfs succeeded with no type, but should have failed"
2961 $LFS setquota $TSTUSR $DIR &&
2962 error "lfs succeeded with no type, but should have failed"
2965 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2967 test_27b() { # b20200
2968 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2969 error "lfs setquota failed with uid argument"
2970 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2971 error "lfs stequota failed with gid argument"
2972 if is_project_quota_supported; then
2973 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2974 1000 $DIR || error \
2975 "lfs stequota failed with projid argument"
2977 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2978 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2979 if is_project_quota_supported; then
2980 $SHOW_QUOTA_PROJID ||
2981 error "lfs quota failed with projid argument"
2983 resetquota -u $TSTID
2984 resetquota -g $TSTID
2985 resetquota -p $TSTPRJID
2988 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2993 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2994 error "lfs setquota failed"
2996 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2997 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2998 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2999 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3001 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3002 error "lfs setquota for $TSTID failed"
3004 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3005 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3006 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3007 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3009 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3010 error "total allocated inode/block limit not printed"
3012 resetquota -u $TSTUSR
3014 run_test 27c "lfs quota should support human-readable output"
3021 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3022 error "set fraction block limit failed"
3023 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3024 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3025 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3026 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3028 resetquota -u $TSTUSR
3030 run_test 27d "lfs setquota should support fraction block limit"
3034 local TESTFILE="$DIR/$tdir/$tfile"
3037 setup_quota_test || error "setup quota failed with $?"
3038 trap cleanup_quota_test EXIT
3040 set_ost_qtype "u" || error "enable ost quota failed"
3042 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3043 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3045 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3046 $MAX_IQ_TIME $DIR || error "set grace time failed"
3047 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3048 error "set quota failed"
3049 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3050 cancel_lru_locks osc
3052 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3053 # over-quota flag has not yet settled since we do not trigger async
3054 # events based on grace time period expiration
3056 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3057 cancel_lru_locks osc
3058 # now over-quota flag should be settled and further writes should fail
3060 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3061 error "grace times were reset"
3064 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3065 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3067 run_test 30 "Hard limit updates should not reset grace times"
3069 # basic usage tracking for user & group
3071 local INODES=10 # 10 files
3072 local BLK_CNT=2 # of 2M each
3073 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3075 setup_quota_test || error "setup quota failed with $?"
3076 trap cleanup_quota_test EXIT
3078 # make sure the system is clean
3079 local USED=$(getquota -u $TSTID global curspace)
3081 error "Used space ($USED) for user $TSTID isn't 0."
3082 USED=$(getquota -g $TSTID global curspace)
3084 error "Used space ($USED) for group $TSTID isn't 0."
3085 if is_project_quota_supported; then
3086 USED=$(getquota -p $TSTPRJID global curspace)
3087 [ $USED -ne 0 ] && error \
3088 "Used space ($USED) for project $TSTPRJID isn't 0."
3091 echo "Write files..."
3092 for i in $(seq 0 $INODES); do
3093 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3094 error "write failed"
3095 is_project_quota_supported &&
3096 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3097 echo "Iteration $i/$INODES completed"
3099 cancel_lru_locks osc
3101 echo "Wait for setattr on objects finished..."
3102 wait_delete_completed
3104 sync; sync_all_data || true
3106 echo "Verify disk usage after write"
3107 USED=$(getquota -u $TSTID global curspace)
3108 [ $USED -lt $TOTAL_BLKS ] &&
3109 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3110 USED=$(getquota -g $TSTID global curspace)
3111 [ $USED -lt $TOTAL_BLKS ] &&
3112 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3113 if is_project_quota_supported; then
3114 USED=$(getquota -p $TSTPRJID global curspace)
3115 [ $USED -lt $TOTAL_BLKS ] && error \
3116 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3119 echo "Verify inode usage after write"
3120 USED=$(getquota -u $TSTID global curinodes)
3121 [ $USED -lt $INODES ] &&
3122 error "Used inode for user $TSTID is $USED, expected $INODES"
3123 USED=$(getquota -g $TSTID global curinodes)
3124 [ $USED -lt $INODES ] &&
3125 error "Used inode for group $TSTID is $USED, expected $INODES"
3126 if is_project_quota_supported; then
3127 USED=$(getquota -p $TSTPRJID global curinodes)
3128 [ $USED -lt $INODES ] && error \
3129 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3134 echo "Verify disk usage after delete"
3135 USED=$(getquota -u $TSTID global curspace)
3136 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3137 USED=$(getquota -u $TSTID global curinodes)
3138 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3139 USED=$(getquota -g $TSTID global curspace)
3140 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3141 USED=$(getquota -g $TSTID global curinodes)
3142 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3143 if is_project_quota_supported; then
3144 USED=$(getquota -p $TSTPRJID global curspace)
3146 error "Used space for project $TSTPRJID isn't 0. $USED"
3147 USED=$(getquota -p $TSTPRJID global curinodes)
3149 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3152 run_test 33 "Basic usage tracking for user & group & project"
3154 # usage transfer test for user & group & project
3156 local BLK_CNT=2 # 2MB
3157 local project_supported="no"
3159 is_project_quota_supported && project_supported="yes"
3160 setup_quota_test || error "setup quota failed with $?"
3161 trap cleanup_quota_test EXIT
3163 # make sure the system is clean
3164 local USED=$(getquota -u $TSTID global curspace)
3165 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3166 USED=$(getquota -g $TSTID global curspace)
3167 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3169 local USED=$(getquota -u $TSTID2 global curspace)
3170 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3171 if [ $project_supported == "yes" ]; then
3172 USED=$(getquota -p $TSTPRJID global curspace)
3173 [ $USED -ne 0 ] && error \
3174 "Used space ($USED) for Project $TSTPRJID isn't 0."
3177 echo "Write file..."
3178 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3179 error "write failed"
3180 cancel_lru_locks osc
3181 sync; sync_all_data || true
3183 echo "chown the file to user $TSTID"
3184 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3186 echo "Wait for setattr on objects finished..."
3187 wait_delete_completed
3189 BLK_CNT=$((BLK_CNT * 1024))
3191 echo "Verify disk usage for user $TSTID"
3192 USED=$(getquota -u $TSTID global curspace)
3193 [ $USED -lt $BLK_CNT ] &&
3194 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3195 USED=$(getquota -u $TSTID global curinodes)
3197 error "Used inodes for user $TSTID is $USED, expected 1"
3199 echo "chgrp the file to group $TSTID"
3200 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3202 echo "Wait for setattr on objects finished..."
3203 wait_delete_completed
3205 echo "Verify disk usage for group $TSTID"
3206 USED=$(getquota -g $TSTID global curspace)
3207 [ $USED -ge $BLK_CNT ] ||
3208 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3209 USED=$(getquota -g $TSTID global curinodes)
3211 error "Used inodes for group $TSTID is $USED, expected 1"
3213 # chown won't change the ost object group. LU-4345 */
3214 echo "chown the file to user $TSTID2"
3215 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3217 echo "Wait for setattr on objects finished..."
3218 wait_delete_completed
3220 echo "change_project project id to $TSTPRJID"
3221 [ $project_supported == "yes" ] &&
3222 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3223 echo "Wait for setattr on objects finished..."
3224 wait_delete_completed
3226 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3227 USED=$(getquota -u $TSTID2 global curspace)
3228 [ $USED -lt $BLK_CNT ] &&
3229 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3230 USED=$(getquota -u $TSTID global curspace)
3232 error "Used space for user $TSTID is $USED, expected 0"
3233 USED=$(getquota -g $TSTID global curspace)
3234 [ $USED -lt $BLK_CNT ] &&
3235 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3236 if [ $project_supported == "yes" ]; then
3237 USED=$(getquota -p $TSTPRJID global curspace)
3238 [ $USED -lt $BLK_CNT ] && error \
3239 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3244 run_test 34 "Usage transfer for user & group & project"
3246 # usage is still accessible across restart
3248 local BLK_CNT=2 # 2 MB
3250 setup_quota_test || error "setup quota failed with $?"
3251 trap cleanup_quota_test EXIT
3253 echo "Write file..."
3254 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3255 error "write failed"
3256 is_project_quota_supported &&
3257 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3258 cancel_lru_locks osc
3260 echo "Wait for setattr on objects finished..."
3261 wait_delete_completed
3263 sync; sync_all_data || true
3265 echo "Save disk usage before restart"
3266 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3267 [ $ORIG_USR_SPACE -eq 0 ] &&
3268 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3269 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3270 [ $ORIG_USR_INODES -eq 0 ] &&
3271 error "Used inodes for user $TSTID is 0, expected 1"
3272 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3273 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3274 [ $ORIG_GRP_SPACE -eq 0 ] &&
3275 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3276 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3277 [ $ORIG_GRP_INODES -eq 0 ] &&
3278 error "Used inodes for group $TSTID is 0, expected 1"
3279 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3281 if is_project_quota_supported; then
3282 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3283 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3284 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3285 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3286 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3287 "Used inodes for project $TSTPRJID is 0, expected 1"
3288 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3296 echo "Verify disk usage after restart"
3297 local USED=$(getquota -u $TSTID global curspace)
3298 [ $USED -eq $ORIG_USR_SPACE ] ||
3299 error "Used space for user $TSTID changed from " \
3300 "$ORIG_USR_SPACE to $USED"
3301 USED=$(getquota -u $TSTID global curinodes)
3302 [ $USED -eq $ORIG_USR_INODES ] ||
3303 error "Used inodes for user $TSTID changed from " \
3304 "$ORIG_USR_INODES to $USED"
3305 USED=$(getquota -g $TSTID global curspace)
3306 [ $USED -eq $ORIG_GRP_SPACE ] ||
3307 error "Used space for group $TSTID changed from " \
3308 "$ORIG_GRP_SPACE to $USED"
3309 USED=$(getquota -g $TSTID global curinodes)
3310 [ $USED -eq $ORIG_GRP_INODES ] ||
3311 error "Used inodes for group $TSTID changed from " \
3312 "$ORIG_GRP_INODES to $USED"
3313 if [ $project_supported == "yes" ]; then
3314 USED=$(getquota -p $TSTPRJID global curinodes)
3315 [ $USED -eq $ORIG_PRJ_INODES ] ||
3316 error "Used inodes for project $TSTPRJID " \
3317 "changed from $ORIG_PRJ_INODES to $USED"
3318 USED=$(getquota -p $TSTPRJID global curspace)
3319 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3320 error "Used space for project $TSTPRJID "\
3321 "changed from $ORIG_PRJ_SPACE to $USED"
3324 # check if the vfs_dq_init() is called before writing
3325 echo "Append to the same file..."
3326 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3327 error "write failed"
3328 cancel_lru_locks osc
3329 sync; sync_all_data || true
3331 echo "Verify space usage is increased"
3332 USED=$(getquota -u $TSTID global curspace)
3333 [ $USED -gt $ORIG_USR_SPACE ] ||
3334 error "Used space for user $TSTID isn't increased" \
3335 "orig:$ORIG_USR_SPACE, now:$USED"
3336 USED=$(getquota -g $TSTID global curspace)
3337 [ $USED -gt $ORIG_GRP_SPACE ] ||
3338 error "Used space for group $TSTID isn't increased" \
3339 "orig:$ORIG_GRP_SPACE, now:$USED"
3340 if [ $project_supported == "yes" ]; then
3341 USED=$(getquota -p $TSTPRJID global curspace)
3342 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3343 error "Used space for project $TSTPRJID isn't " \
3344 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3349 run_test 35 "Usage is still accessible across reboot"
3351 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3354 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3355 skip "Old server doesn't have LU-5006 fix."
3357 setup_quota_test || error "setup quota failed with $?"
3358 trap cleanup_quota_test EXIT
3360 # make sure the system is clean
3361 local USED=$(getquota -u $TSTID global curspace)
3363 error "Used space ($USED) for user $TSTID isn't 0."
3365 # create file with MDS_OPEN_DELAY_CREATE flag
3366 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3367 error "Create file failed"
3369 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3370 oflag=sync || error "Write file failed"
3372 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3374 # wait for setattr on objects finished..."
3375 wait_delete_completed
3377 USED=$(getquota -u $TSTID global curspace)
3378 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3382 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3386 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3387 skip "Old server doesn't have LU-8801 fix."
3389 [ "$UID" != 0 ] && skip_env "must run as root" && return
3391 setup_quota_test || error "setup quota failed with $?"
3392 trap cleanup_quota_test EXIT
3394 # make sure the system is clean
3395 local USED=$(getquota -u $TSTID global curspace)
3397 error "Used space ($USED) for user $TSTID isn't 0."
3398 USED=$(getquota -u $TSTID2 global curspace)
3400 error "Used space ($USED) for user $TSTID2 isn't 0."
3402 local TESTFILE="$DIR/$tdir/$tfile"
3403 local file_cnt=10000
3405 # Generate id entries in accounting file
3406 echo "Create $file_cnt files..."
3407 for i in `seq $file_cnt`; do
3409 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3410 error "failed to chown $TESTFILE-$i"
3412 cancel_lru_locks osc
3413 sync; sync_all_data || true
3415 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3416 procf=${procf}.quota_slave.acct_user
3419 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3420 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3421 echo "Found $acct_cnt id entries"
3423 [ $file_cnt -eq $acct_cnt ] || {
3424 do_facet mds1 $LCTL get_param $procf
3425 error "skipped id entries"
3430 run_test 38 "Quota accounting iterator doesn't skip id entries"
3433 local TESTFILE="$DIR/$tdir/project"
3434 ! is_project_quota_supported &&
3435 skip "Project quota is not supported"
3437 setup_quota_test || error "setup quota failed with $?"
3440 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3441 [ $projectid -ne 0 ] &&
3442 error "Project id should be 0 not $projectid"
3443 change_project -p 1024 $TESTFILE
3444 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3445 [ $projectid -ne 1024 ] &&
3446 error "Project id should be 1024 not $projectid"
3448 stopall || error "failed to stopall (1)"
3451 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3452 [ $projectid -ne 1024 ] &&
3453 error "Project id should be 1024 not $projectid"
3457 run_test 39 "Project ID interface works correctly"
3460 ! is_project_quota_supported &&
3461 skip "Project quota is not supported"
3462 local dir1="$DIR/$tdir/dir1"
3463 local dir2="$DIR/$tdir/dir2"
3465 setup_quota_test || error "setup quota failed with $?"
3467 mkdir -p $dir1 $dir2
3468 change_project -sp 1 $dir1 && touch $dir1/1
3469 change_project -sp 2 $dir2
3471 ln $dir1/1 $dir2/1_link &&
3472 error "Hard link across different project quota should fail"
3477 run_test 40a "Hard link across different project ID"
3480 ! is_project_quota_supported &&
3481 skip "Project quota is not supported"
3482 local dir1="$DIR/$tdir/dir1"
3483 local dir2="$DIR/$tdir/dir2"
3485 setup_quota_test || error "setup quota failed with $?"
3486 mkdir -p $dir1 $dir2
3487 change_project -sp 1 $dir1 && touch $dir1/1
3488 change_project -sp 2 $dir2
3490 mv $dir1/1 $dir2/2 || error "mv failed $?"
3491 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3492 if [ "$projid" != "2" ]; then
3493 error "project id expected 2 not $projid"
3498 run_test 40b "Mv across different project ID"
3501 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3502 ! is_project_quota_supported &&
3503 skip "Project quota is not supported"
3505 setup_quota_test || error "setup quota failed with $?"
3506 local dir="$DIR/$tdir/dir"
3508 mkdir -p $dir && change_project -sp 1 $dir
3509 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3510 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3511 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3512 touch $dir/remote_dir/file
3513 #verify inherit works file for remote dir.
3514 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3515 [ "$projid" != "1" ] &&
3516 error "file under remote dir expected 1 not $projid"
3518 #Agent inode should be ignored for project quota
3519 USED=$(getquota -p 1 global curinodes)
3520 [ "$USED" != "3" ] &&
3521 error "file count expected 3 got $USED"
3527 run_test 40c "Remote child Dir inherit project quota properly"
3530 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3531 is_project_quota_supported || skip "Project quota is not supported"
3533 setup_quota_test || error "setup quota failed with $?"
3534 local dir="$DIR/$tdir/dir"
3537 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3538 change_project -sp $TSTPRJID $dir ||
3539 error "change project on $dir failed"
3540 for i in $(seq 5); do
3541 mkdir -p $dir/d$i/d$i ||
3542 error "mkdir $dir/d$i/d$i failed"
3543 local projid=$($LFS project -d $dir/d$i/d$i |
3545 [ "$projid" == "$TSTPRJID" ] ||
3546 error "projid id expected $TSTPRJID not $projid"
3547 touch $dir/d$i/d$i/file
3548 #verify inherit works file for stripe dir.
3549 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3550 [ "$projid" == "$TSTPRJID" ] ||
3551 error "file under remote dir expected 1 not $projid"
3554 # account should be 1 + (2 + 1) *10 + 1 * 5
3555 USED=$(getquota -p $TSTPRJID global curinodes)
3556 [ "$USED" == "36" ] ||
3557 error "file count expected 36 got $USED"
3562 run_test 40d "Stripe Directory inherit project quota properly"
3565 is_project_quota_supported ||
3566 skip "Project quota is not supported"
3567 setup_quota_test || error "setup quota failed with $?"
3568 trap cleanup_quota_test EXIT
3569 local dir="$DIR/$tdir/dir"
3572 local projid=$((testnum * 1000))
3576 # enable mdt/ost quota
3577 set_mdt_qtype ugp || error "enable mdt quota failed"
3578 set_ost_qtype ugp || error "enable ost quota failed"
3580 test_mkdir -p $dir && change_project -sp $projid $dir
3581 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3582 error "set project quota failed"
3587 # check if df output works as expected
3588 echo "== global statfs: $MOUNT =="
3589 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3591 echo "== project statfs (prjid=$projid): $dir =="
3592 df -kP $dir; df -iP $dir
3593 local bused=$(getquota -p $projid global curspace)
3594 local iused=$(getquota -p $projid global curinodes)
3595 # note trailing space to match double printf from awk
3596 local expected="$blimit $bused $ilimit $iused "
3598 wait_update $HOSTNAME \
3599 "{ df -kP $dir; df -iP $dir; } |
3600 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3602 error "failed to get correct statfs for project quota"
3606 run_test 41 "df should return projid-specific values"
3609 ! is_project_quota_supported &&
3610 skip "Project quota is not supported"
3612 setup_quota_test || error "setup quota failed with $?"
3613 local dir1="$DIR/$tdir/dir1"
3614 local dir2="$DIR/$tdir/dir2"
3616 mkdir -p $dir1 && change_project -sp 1 $dir1
3617 mkdir -p $dir2 && change_project -sp 2 $dir2
3618 for num in $(seq 1 10); do
3619 touch $dir1/file_$num $dir2/file_$num
3620 ln -s $dir1/file_$num $dir1/file_$num"_link"
3621 ln -s $dir2/file_$num $dir2/file_$num"_link"
3624 count=$($LFS find --projid 1 $DIR | wc -l)
3625 [ "$count" != 21 ] && error "expected 21 but got $count"
3627 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3628 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3629 [ "$count" != 22 ] && error "expected 22 but got $count"
3634 run_test 50 "Test if lfs find --projid works"
3637 ! is_project_quota_supported &&
3638 skip "Project quota is not supported"
3639 setup_quota_test || error "setup quota failed with $?"
3640 local dir="$DIR/$tdir/dir"
3642 mkdir $dir && change_project -sp 1 $dir
3643 local used=$(getquota -p 1 global curinodes)
3644 [ $used != "1" ] && error "expected 1 got $used"
3649 used=$(getquota -p 1 global curinodes)
3650 [ $used != "4" ] && error "expected 4 got $used"
3652 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3654 cp $DIR/$tdir/6 $dir/6
3655 used=$(getquota -p 1 global curinodes)
3656 [ $used != "5" ] && error "expected 5 got $used"
3659 mv $DIR/$tdir/6 $dir/7
3660 used=$(getquota -p 1 global curinodes)
3661 [ $used != "6" ] && error "expected 6 got $used"
3666 run_test 51 "Test project accounting with mv/cp"
3669 ! is_project_quota_supported &&
3670 skip "Project quota is not supported"
3671 setup_quota_test || error "setup quota failed with $?"
3672 local dir="$DIR/$tdir/dir"
3673 mkdir $dir && change_project -sp 1 $dir
3675 touch $DIR/$tdir/file
3676 #Try renaming a file into the project. This should fail.
3677 for num in $(seq 1 2000); do
3678 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3679 error "rename should fail"
3684 run_test 52 "Rename across different project ID"
3687 ! is_project_quota_supported &&
3688 skip "Project quota is not supported"
3689 setup_quota_test || error "setup quota failed with $?"
3690 local dir="$DIR/$tdir/dir"
3691 mkdir $dir && change_project -s $dir
3692 lfs project -d $dir | grep P || error "inherit attribute should be set"
3694 change_project -C $dir
3695 lfs project -d $dir | grep P &&
3696 error "inherit attribute should be cleared"
3701 run_test 53 "Project inherit attribute could be cleared"
3704 ! is_project_quota_supported &&
3705 skip "Project quota is not supported"
3706 setup_quota_test || error "setup quota failed with $?"
3707 trap cleanup_quota_test EXIT
3708 local testfile="$DIR/$tdir/$tfile-0"
3710 #set project ID/inherit attribute
3711 change_project -sp $TSTPRJID $DIR/$tdir
3712 $RUNAS createmany -m ${testfile} 100 ||
3713 error "create many files failed"
3715 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3716 # one more count for directory itself */
3720 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3721 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3723 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3724 [ $proj_count1 -eq $proj_count ] ||
3725 error "c2: expected $proj_count got $proj_count1"
3727 #clear project but with kept projid
3728 change_project -rCk $DIR/$tdir
3729 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3730 [ $proj_count1 -eq 1 ] ||
3731 error "c3: expected 1 got $proj_count1"
3733 #verify projid untouched.
3734 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3736 [ $proj_count1 -eq $proj_count ] ||
3737 error "c4: expected $proj_count got $proj_count1"
3740 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3741 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3742 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3744 #this time clear all
3745 change_project -rC $DIR/$tdir
3746 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3747 [ $proj_count1 -eq 0 ] ||
3748 error "c6: expected 0 got $proj_count1"
3750 unlinkmany ${testfile} 100 ||
3751 error "unlink many files failed"
3755 run_test 54 "basic lfs project interface test"
3758 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3759 skip "Not supported before 2.10.58."
3760 setup_quota_test || error "setup quota failed with $?"
3762 set_ost_qtype $QTYPE || error "enable ost quota failed"
3765 #add second group to TSTUSR
3766 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3769 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3770 error "failed to dd"
3772 cancel_lru_locks osc
3773 sync; sync_all_data || true
3775 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3776 error "failed to setquota on group $TSTUSR2"
3778 $LFS quota -v -g $TSTUSR2 $DIR
3780 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3781 error "chgrp should failed with -EDQUOT"
3783 USED=$(getquota -g $TSTUSR2 global curspace)
3786 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3787 error "failed to setquota on group $TSTUSR2"
3789 $LFS quota -v -g $TSTUSR2 $DIR
3791 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3792 error "chgrp should succeed"
3794 $LFS quota -v -g $TSTUSR2 $DIR
3798 run_test 55 "Chgrp should be affected by group quota"
3801 setup_quota_test || error "setup quota failed with $?"
3803 set_ost_qtype $QTYPE || error "enable ost quota failed"
3806 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3807 erro "failed to set grace time for usr quota"
3808 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3809 awk '{print $4 $8}')
3810 if [ "x$grace_time" != "x10s;10s" ]; then
3811 $LFS quota -t -u $DIR
3812 error "expected grace time: 10s;10s, got:$grace_time"
3817 run_test 56 "lfs quota -t should work well"
3820 setup_quota_test || error "setup quota failed with $?"
3822 local dir="$DIR/$tdir/dir"
3825 #try to change pipe file should not hang and return failure
3826 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3827 awk -F ':' '{ print \\\$2 }'" \
3828 " unable to get xattr for fifo '$dir/pipe'" || return 1
3829 #command can process further if it hit some errors
3830 touch $dir/aaa $dir/bbb
3831 mkdir $dir/subdir -p
3832 touch $dir/subdir/aaa $dir/subdir/bbb
3833 #create one invalid link file
3834 ln -s $dir/not_exist_file $dir/ccc
3835 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3836 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3840 run_test 57 "lfs project could tolerate errors"
3843 [ "$mds1_FSTYPE" != ldiskfs ] &&
3844 skip "ldiskfs only test"
3845 disable_project_quota
3846 setup_quota_test || error "setup quota failed with $?"
3849 local testfile="$DIR/$tdir/$tfile-0"
3850 #make sure it did not crash kernel
3851 touch $testfile && lfs project -sp 1 $testfile
3853 enable_project_quota
3856 run_test 59 "lfs project dosen't crash kernel with project disabled"
3859 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3860 skip "Needs MDS version 2.11.53 or later."
3861 setup_quota_test || error "setup quota failed with $?"
3862 trap cleanup_quota_test EXIT
3864 local testfile=$DIR/$tdir/$tfile
3867 set_mdt_qtype "ug" || error "enable mdt quota failed"
3869 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3870 error "set quota failed"
3871 quota_show_check a g $TSTUSR
3873 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3874 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3875 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3876 error "create many files failed"
3878 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3880 # root user can overrun quota
3881 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3882 error "root user should succeed"
3886 run_test 60 "Test quota for root with setgid"
3888 # test default quota
3889 test_default_quota() {
3890 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3891 skip "Not supported before 2.11.51."
3896 local qprjid=$TSTPRJID
3900 local LIMIT=20480 #20M disk space
3901 local TESTFILE="$DIR/$tdir/$tfile-0"
3903 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3904 echo "Project quota is not supported" && return 0
3906 [ $qtype == "-u" ] && qdtype="-U"
3907 [ $qtype == "-g" ] && qdtype="-G"
3908 [ $qtype == "-p" ] && {
3913 [ $qpool == "meta" ] && {
3914 LIMIT=10240 #10K inodes
3919 setup_quota_test || error "setup quota failed with $?"
3920 trap cleanup_quota_test EXIT
3924 # enable mdt/ost quota
3925 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3926 set_ost_qtype $QTYPE || error "enable ost quota failed"
3928 log "set to use default quota"
3929 $LFS setquota $qtype $qid -d $DIR ||
3930 error "set $qid to use default quota failed"
3932 log "set default quota"
3933 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3934 error "set $qid default quota failed"
3936 log "get default quota"
3937 $LFS quota $qdtype $DIR || error "get default quota failed"
3939 if [ $qpool == "data" ]; then
3940 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3942 [ $SLIMIT -eq $LIMIT ] ||
3943 error "the returned default quota is wrong"
3945 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3947 [ $SLIMIT -eq $LIMIT ] ||
3948 error "the returned default quota is wrong"
3951 # make sure the system is clean
3952 local USED=$(getquota $qtype $qid global curspace)
3953 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3955 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3956 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3958 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3960 log "Test not out of quota"
3961 if [ $qpool == "data" ]; then
3962 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3963 quota_error $qtype $qid "write failed, expect succeed"
3965 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3966 quota_error $qtype $qid "create failed, expect succeed"
3968 unlinkmany $TESTFILE $((LIMIT/2))
3971 log "Test out of quota"
3972 # flush cache, ensure noquota flag is set on client
3973 cancel_lru_locks osc
3974 cancel_lru_locks mdc
3975 sync; sync_all_data || true
3976 if [ $qpool == "data" ]; then
3977 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3978 quota_error $qtype $qid "write succeed, expect EDQUOT"
3980 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3981 quota_error $qtype $qid "create succeed, expect EDQUOT"
3983 unlinkmany $TESTFILE $((LIMIT*2))
3986 log "Increase default quota"
3987 # increase default quota
3988 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3989 error "set default quota failed"
3991 cancel_lru_locks osc
3992 cancel_lru_locks mdc
3993 sync; sync_all_data || true
3994 if [ $qpool == "data" ]; then
3995 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3996 quota_error $qtype $qid "write failed, expect succeed"
3998 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3999 quota_error $qtype $qid "create failed, expect succeed"
4001 unlinkmany $TESTFILE $((LIMIT*2))
4004 log "Set quota to override default quota"
4005 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4006 error "set $qid quota failed"
4008 cancel_lru_locks osc
4009 cancel_lru_locks mdc
4010 sync; sync_all_data || true
4011 if [ $qpool == "data" ]; then
4012 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4013 quota_error $qtype $qid "write succeed, expect EQUOT"
4015 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4016 quota_error $qtype $qid "create succeed, expect EQUOT"
4018 unlinkmany $TESTFILE $((LIMIT*2))
4021 log "Set to use default quota again"
4022 $LFS setquota $qtype $qid -d $DIR ||
4023 error "set $qid to use default quota failed"
4025 cancel_lru_locks osc
4026 cancel_lru_locks mdc
4027 sync; sync_all_data || true
4028 if [ $qpool == "data" ]; then
4029 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4030 quota_error $qtype $qid "write failed, expect succeed"
4032 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4033 quota_error $qtype $qid "create failed, expect succeed"
4035 unlinkmany $TESTFILE $((LIMIT*2))
4040 wait_delete_completed || error "wait_delete_completed failed"
4041 sync_all_data || true
4042 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
4043 error "reset default quota failed"
4044 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
4045 error "reset quota failed"
4051 test_default_quota "-u" "data"
4052 test_default_quota "-u" "meta"
4053 test_default_quota "-g" "data"
4054 test_default_quota "-g" "meta"
4055 test_default_quota "-p" "data"
4056 test_default_quota "-p" "meta"
4058 run_test 61 "default quota tests"
4061 ! is_project_quota_supported &&
4062 skip "Project quota is not supported"
4063 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4064 skip "chattr did not support project quota"
4065 setup_quota_test || error "setup quota failed with $?"
4066 local testdir=$DIR/$tdir/
4068 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4069 change_project -s $testdir
4070 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4071 error "inherit attribute should be set"
4072 # chattr used FS_IOC_SETFLAGS ioctl
4073 $RUNAS chattr -P $testdir &&
4074 error "regular user clear inherit should fail"
4075 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4076 error "inherit attribute should still be set"
4077 chattr -P $testdir || error "root failed to clear inherit"
4078 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4079 error "inherit attribute should be cleared"
4082 run_test 62 "Project inherit should be only changed by root"
4085 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4086 skip "Not supported before 2.11.55"
4090 local dd_failed=false
4091 local tdir_dom=${tdir}_dom
4092 local LIMIT=20480 #20M
4094 [ $qtype == "p" ] && ! is_project_quota_supported &&
4095 echo "Project quota is not supported" && return 0
4097 [ $qtype == "p" ] && qid=$TSTPRJID
4099 setup_quota_test || error "setup quota failed with $?"
4100 trap cleanup_quota_test EXIT
4104 # enable mdt/ost quota
4105 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4106 set_ost_qtype $QTYPE || error "enable ost quota failed"
4108 # make sure the system is clean
4109 local USED=$(getquota -$qtype $qid global curspace)
4110 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4112 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4114 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4115 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4116 error "setstripe $tdir_dom failed"
4117 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4119 [ $qtype == "p" ] && {
4120 change_project -sp $TSTPRJID $DIR/$tdir
4121 change_project -sp $TSTPRJID $DIR/$tdir_dom
4124 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4125 error "set $qid quota failed"
4127 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4128 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4132 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4134 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4135 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4139 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4141 rm -f $DIR/$tdir_dom/*
4143 # flush cache, ensure noquota flag is set on client
4144 cancel_lru_locks osc
4145 cancel_lru_locks mdc
4146 sync; sync_all_data || true
4150 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4151 quota_error $qtype $qid "write failed, expect succeed"
4153 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4154 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4158 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4161 rm -f $DIR/$tdir_dom/*
4163 # flush cache, ensure noquota flag is set on client
4164 cancel_lru_locks osc
4165 cancel_lru_locks mdc
4166 sync; sync_all_data || true
4170 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4171 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4175 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4177 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4178 quota_error $qtype $qid "write succeed, expect EDQUOT"
4181 rm -fr $DIR/$tdir_dom
4183 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4184 error "reset usr quota failed"
4194 run_test 63 "quota on DoM tests"
4197 ! is_project_quota_supported &&
4198 skip "Project quota is not supported"
4199 setup_quota_test || error "setup quota failed with $?"
4200 local dir1="$DIR/$tdir/"
4203 ln -s $dir1/file $dir1/file_link
4205 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4206 error "set symlink file's project should fail"
4208 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4209 error "get symlink file's project should fail"
4213 run_test 64 "lfs project on symlink files should fail"
4217 local TESTFILE="$DIR/$tdir/$tfile-0"
4219 setup_quota_test || error "setup quota failed with $?"
4220 set_ost_qtype $QTYPE || error "enable ost quota failed"
4224 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4225 error "failed to write"
4226 # flush cache, ensure noquota flag is set on client
4227 cancel_lru_locks osc
4228 sync; sync_all_data || true
4230 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4231 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4232 local quota_all=$($RUNAS $LFS quota $DIR)
4234 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4235 error "usr quota not match"
4236 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4237 error "grp quota not match"
4243 run_test 65 "Check lfs quota result"
4246 ! is_project_quota_supported &&
4247 skip "Project quota is not supported"
4248 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4249 skip "Not supported before 2.12.4"
4250 setup_quota_test || error "setup quota failed with $?"
4251 stack_trap cleanup_quota_test EXIT
4252 local old=$(do_facet mds1 $LCTL get_param -n \
4253 mdt.*.enable_chprojid_gid | head -1)
4254 local testdir=$DIR/$tdir/foo
4256 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4257 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4260 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4261 chown -R $TSTID:$TSTID $testdir
4262 change_project -sp $TSTPRJID $testdir
4263 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4265 $RUNAS lfs project -p 0 $testdir/foo &&
4266 error "nonroot user should fail to set projid"
4268 $RUNAS lfs project -C $testdir/foo &&
4269 error "nonroot user should fail to clear projid"
4271 change_project -C $testdir/foo || error "failed to clear project"
4273 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4274 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4275 "failed to set projid with normal user when enable_chprojid_gid=-1"
4277 $RUNAS lfs project -rC $testdir/ || error \
4278 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4280 touch $testdir/bar || error "failed touch $testdir/bar"
4281 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4282 "normal user should not be able to set projid on root owned file"
4284 change_project -p $TSTPRJID $testdir/bar || error \
4285 "root should be able to change its own file's projid"
4289 run_test 66 "nonroot user can not change project state in default"
4296 local short_qtype=${qtype:0:1}
4299 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4301 quota_usr) _runas=$RUNAS;;
4302 quota_2usr) _runas=$RUNAS2;;
4303 *) error "unknown quota parameter $4";;
4308 $_runas $DD of=$file count=$size ||
4309 quota_error $short_qtype $TSTUSR \
4310 "$qtype write failure, but expect success"
4312 cancel_lru_locks osc
4314 sync; sync_all_data || true
4323 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4325 do_facet mds1 $LCTL get_param $param |
4326 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4330 local limit=20 # 20M
4331 local testfile="$DIR/$tdir/$tfile-0"
4332 local testfile2="$DIR/$tdir/$tfile-1"
4333 local testfile3="$DIR/$tdir/$tfile-2"
4334 local qpool="qpool1"
4340 [ "$ost1_FSTYPE" == zfs ] &&
4341 skip "ZFS grants some block space together with inode"
4343 setup_quota_test || error "setup quota failed with $?"
4344 trap cleanup_quota_test EXIT
4347 set_ost_qtype $QTYPE || error "enable ost quota failed"
4350 log "User quota (block hardlimit:$limit MB)"
4351 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4352 error "set user quota failed"
4354 # make sure the system is clean
4355 used=$(getquota -u $TSTUSR global curspace)
4356 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4358 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4359 echo "granted 0x0 before write $granted"
4361 # trigger reintegration
4362 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4363 procf=${procf}quota_slave.force_reint
4364 do_facet ost1 $LCTL set_param $procf=1 ||
4365 error "force reintegration failed"
4366 wait_ost_reint "u" || error "reintegration failed"
4367 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4368 [ $granted -ne 0 ] &&
4369 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4371 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4372 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4374 # write 10 MB to testfile
4375 test_67_write "$testfile" "user" 10 "quota_usr"
4377 # create qpool and add OST1
4378 pool_add $qpool || error "pool_add failed"
4379 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4380 # as quota_usr hasn't limits, lqe may absent. But it should be
4381 # created after the 1st direct qmt_get.
4382 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4384 # check granted - should be 0, as testfile is located only on OST0
4385 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4386 echo "global granted $granted"
4387 granted=$(getgranted $qpool "dt" $TSTID "usr")
4388 echo "$qpool granted $granted"
4389 [ $granted -ne 0 ] &&
4390 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4392 # add OST0 to qpool and check granted space
4393 pool_add_targets $qpool 0 1 ||
4394 error "pool_add_targets failed"
4395 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4396 echo "Granted $granted_mb MB"
4397 #should be 10M + qunit for each OST
4398 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4399 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4401 $LFS setstripe $testfile2 -c 1 -i 1 ||
4402 error "setstripe $testfile2 failed"
4403 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4404 # Write from another user and check that qpool1
4405 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4406 test_67_write "$testfile2" "user" 10 "quota_2usr"
4407 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4408 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4409 [ $granted -ne 0 ] &&
4410 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4412 # Granted space for quota_2usr in qpool1 should appear only
4413 # when global lqe for this user becomes enforced.
4414 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4415 error "set user quota failed"
4416 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4417 echo "granted_mb $granted_mb"
4418 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4419 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4421 $LFS setstripe $testfile3 -c 1 -i 0 ||
4422 error "setstripe $testfile3 failed"
4423 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4424 test_67_write "$testfile3" "user" 10 "quota_2usr"
4425 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4426 echo "$testfile3 granted_mb $granted_mb"
4427 [ $granted_mb -eq $limit ] ||
4428 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4430 # remove OST1 from the qpool1 and check granted space
4431 # should be 0 for TSTUSR and 10M for TSTUSR2
4432 pool_remove_target $qpool 0
4433 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4434 [ $granted_mb -eq 0 ] ||
4435 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4436 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4437 [ $granted_mb -eq 10 ] ||
4438 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4441 wait_delete_completed || error "wait_delete_completed failed"
4442 sync_all_data || true
4443 used=$(getquota -u $TSTUSR global curspace)
4444 [ $used -ne 0 ] && quota_error u $TSTUSR \
4445 "user quota isn't released after deletion"
4446 resetquota -u $TSTUSR
4450 run_test 67 "quota pools recalculation"
4457 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4458 awk '/usr/ {getline; print $2}'
4463 local qpool="qpool1"
4466 setup_quota_test || error "setup quota failed with $?"
4467 stack_trap cleanup_quota_test EXIT
4470 set_ost_qtype $QTYPE || error "enable ost quota failed"
4472 # check slave number for glbal pool
4473 local nr=$(get_slave_nr "0x0" "usr")
4474 echo "nr result $nr"
4475 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4476 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4478 # create qpool and add OST1
4479 pool_add $qpool || error "pool_add failed"
4480 nr=$(get_slave_nr $qpool "usr")
4481 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4484 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4485 nr=$(get_slave_nr $qpool "usr")
4486 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4489 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4490 nr=$(get_slave_nr $qpool "usr")
4491 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4494 pool_remove_target $qpool 0
4495 nr=$(get_slave_nr $qpool "usr")
4496 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4499 pool_remove_target $qpool 1
4500 nr=$(get_slave_nr $qpool "usr")
4501 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4503 # Check again that all is fine with global pool
4504 nr=$(get_slave_nr "0x0" "usr")
4505 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4506 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4510 run_test 68 "slave number in quota pool changed after each add/remove OST"
4514 local global_limit=200 # 200M
4515 local limit=10 # 10M
4516 local testfile="$DIR/$tdir/$tfile-0"
4517 local dom0="$DIR/$tdir/dom0"
4518 local qpool="qpool1"
4521 setup_quota_test || error "setup quota failed with $?"
4522 stack_trap cleanup_quota_test EXIT
4525 set_ost_qtype $QTYPE || error "enable ost quota failed"
4526 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4528 # Save DOM only at MDT0
4529 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4530 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4532 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4534 # create qpool and add OST0
4535 pool_add $qpool || error "pool_add failed"
4536 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4538 log "User quota (block hardlimit:$global_limit MB)"
4539 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4540 error "set user quota failed"
4542 log "User quota (block hardlimit:$limit MB)"
4543 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4544 error "set user quota failed"
4546 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4547 quota_error u $TSTUSR "write failed"
4549 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4550 oflag=sync || quota_error u $TSTUSR "write failed"
4552 $RUNAS $DD of=$testfile count=$limit || true
4554 # flush cache, ensure noquota flag is set on client
4555 cancel_lru_locks osc
4556 sync; sync_all_data || true
4558 # MDT0 shouldn't get EDQUOT with glimpse.
4559 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4560 quota_error u $TSTUSR \
4561 "user write success, but expect EDQUOT"
4563 # Now all members of qpool1 should get EDQUOT. Expect success
4564 # when write to DOM on MDT0, as it belongs to global pool.
4565 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4566 oflag=sync || quota_error u $TSTUSR "write failed"
4568 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4569 oflag=sync || quota_error u $TSTUSR "write failed"
4573 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4577 local qpool="qpool1"
4582 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4583 skip "Needs a client >= $VERSION_WITH_QP"
4585 setup_quota_test || error "setup quota failed with $?"
4586 stack_trap cleanup_quota_test EXIT
4588 # MDS returns EFAULT for unsupported quotactl command
4589 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4591 # create qpool and add OST0
4592 pool_add $qpool || error "pool_add failed"
4593 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4595 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4597 [ $rc -eq $err ] || error "setquota res $rc != $err"
4599 # If MDS supports QP, check that limit was set properly.
4600 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4601 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4602 echo "hard limit $bhard limit $limit"
4603 [ $bhard -ne $((limit*1024)) ] &&
4604 error "bhard:$bhard for $qpool!=$((limit*1024))"
4607 $LFS quota -u $TSTUSR --pool $qpool $DIR
4609 [ $rc -eq $err ] || error "quota res $rc != $err"
4613 run_test 70 "check lfs setquota/quota with a pool option"
4617 local limit=10 # 10M
4618 local global_limit=100 # 100M
4619 local testfile="$DIR/$tdir/$tfile-0"
4620 local qpool="qpool1"
4621 local qpool2="qpool2"
4623 [ "$ost1_FSTYPE" == zfs ] &&
4624 skip "ZFS grants some block space together with inode"
4625 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4627 setup_quota_test || error "setup quota failed with $?"
4628 stack_trap cleanup_quota_test EXIT
4631 set_ost_qtype $QTYPE || error "enable ost quota failed"
4634 log "User quota (block hardlimit:$global_limit MB)"
4635 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4636 error "set user quota failed"
4638 pool_add $qpool || error "pool_add failed"
4639 pool_add_targets $qpool 0 1 ||
4640 error "pool_add_targets failed"
4642 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4643 error "set user quota failed"
4645 pool_add $qpool2 || error "pool_add failed"
4646 pool_add_targets $qpool2 1 1 ||
4647 error "pool_add_targets failed"
4649 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4650 error "set user quota failed"
4652 # make sure the system is clean
4653 local used=$(getquota -u $TSTUSR global curspace)
4656 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4658 # create 1st component 1-10M
4659 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4660 #create 2nd component 10-30M
4661 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4662 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4664 # сheck normal use and out of quota with PFL
4665 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4666 test_1_check_write $testfile "user" $((limit*2))
4668 wait_delete_completed || error "wait_delete_completed failed"
4669 sync_all_data || true
4670 used=$(getquota -u $TSTUSR global curspace)
4671 [ $used -ne 0 ] && quota_error u $TSTUSR \
4672 "user quota isn't released after deletion"
4674 # create 1st component 1-10M
4675 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4676 # create 2nd component 10-30M
4677 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4678 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4680 # write to the 2nd component
4681 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4682 quota_error u $TSTUSR \
4683 "write failure, but expect success"
4684 # this time maybe cache write, ignore it's failure
4685 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4686 cancel_lru_locks osc
4687 sync; sync_all_data || true
4688 # write over limit in qpool2(2nd component 10-30M)
4689 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4690 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4691 # write to the 1st component - OST0 is empty
4692 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4693 quota_error u $TSTUSR "write failed"
4697 run_test 71a "Check PFL with quota pools"
4701 local global_limit=1000 # 1G
4702 local limit1=160 # 160M
4703 local limit2=10 # 10M
4704 local testfile="$DIR/$tdir/$tfile-0"
4705 local qpool="qpool1"
4706 local qpool2="qpool2"
4708 [ "$ost1_FSTYPE" == zfs ] &&
4709 skip "ZFS grants some block space together with inode"
4710 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4712 setup_quota_test || error "setup quota failed with $?"
4713 stack_trap cleanup_quota_test EXIT
4716 set_ost_qtype $QTYPE || error "enable ost quota failed"
4719 log "User quota (block hardlimit:$global_limit MB)"
4720 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4721 error "set user quota failed"
4723 pool_add $qpool || error "pool_add failed"
4724 pool_add_targets $qpool 0 1 ||
4725 error "pool_add_targets failed"
4727 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4728 error "set user quota failed"
4730 pool_add $qpool2 || error "pool_add failed"
4731 pool_add_targets $qpool2 1 1 ||
4732 error "pool_add_targets failed"
4734 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4735 error "set user quota failed"
4737 # make sure the system is clean
4738 local used=$(getquota -u $TSTUSR global curspace)
4741 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4743 # First component is on OST0, 2nd on OST1
4744 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4745 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4747 # fill the 1st component on OST0
4748 $RUNAS $DD of=$testfile count=128 ||
4749 quota_error u $TSTUSR "write failed"
4750 # write to the 2nd cmpnt on OST1
4751 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4752 quota_error u $TSTUSR "write failed"
4753 # this time maybe cache write, ignore it's failure
4754 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4756 cancel_lru_locks osc
4757 sync; sync_all_data || true
4758 # write over limit in qpool2
4759 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4760 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4764 run_test 71b "Check SEL with quota pools"
4768 local limit=10 # 10M
4769 local global_limit=50 # 50M
4770 local testfile="$DIR/$tdir/$tfile-0"
4771 local qpool="qpool1"
4774 setup_quota_test || error "setup quota failed with $?"
4775 stack_trap cleanup_quota_test EXIT
4778 set_ost_qtype $QTYPE || error "enable ost quota failed"
4781 log "User quota (block hardlimit:$global_limit MB)"
4782 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4783 error "set user quota failed"
4785 pool_add $qpool || error "pool_add failed"
4786 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4788 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4789 error "set user quota failed"
4791 # make sure the system is clean
4792 local used=$(getquota -u $TSTUSR global curspace)
4794 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4796 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4798 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4799 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4800 test_1_check_write $testfile "user" $limit
4801 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4803 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4804 # check that lfs quota -uv --pool prints only OST that
4805 # was added in a pool
4806 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4807 grep "OST\|MDT" && error "$qpool consists wrong targets"
4811 run_test 72 "lfs quota --pool prints only pool's OSTs"
4815 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4816 if $PQ_CLEANUP; then
4817 disable_project_quota
4820 reset_quota_settings
4825 check_and_cleanup_lustre
4826 export QUOTA_AUTO=$QUOTA_AUTO_OLD