3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 # QP exists since this version. Should be finally set before landing.
43 VERSION_WITH_QP="2.13.53"
45 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
46 skip "Needs MDS version $VERSION_WITH_QP or later."
49 require_dsh_mds || exit 0
50 require_dsh_ost || exit 0
52 # Does e2fsprogs support quota feature?
53 if [ "$mds1_FSTYPE" == ldiskfs ] &&
54 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
55 grep -q 'quota'"; then
56 skip_env "e2fsprogs doesn't support quota"
59 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
61 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
66 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 check_and_setup_lustre
71 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
73 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
74 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
75 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
76 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
77 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
80 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
85 local fail_val=${3:-0}
89 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
90 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
91 ost) NODES="$(comma_list $(osts_nodes))";;
94 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
100 lfs project $* || error "lfs project $* failed"
103 RUNAS="runas -u $TSTID -g $TSTID"
104 RUNAS2="runas -u $TSTID2 -g $TSTID2"
105 DD="dd if=/dev/zero bs=1M"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
112 # resetquota -p projid
115 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
116 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
117 error "resetquota: wrong specifier $1 passed"
119 if [ $1 == "-p" ]; then
120 is_project_quota_supported || return 0
123 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
124 error "clear quota for [type:$1 name:$2] failed"
125 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 log "Files for user ($local_id):"
136 ($LFS find --user $local_id $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
140 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
141 $LFS quota -v -g $local_id $DIR
142 log "Files for group ($local_id):"
143 ($LFS find --group $local_id $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
147 is_project_quota_supported || return 0
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
149 $LFS quota -v -p $TSTPRJID $DIR
150 log "Files for project ($TSTPRJID):"
151 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
168 # get quota for a user or a group
169 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
170 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
177 sync_all_data > /dev/null 2>&1 || true
179 [ "$#" != 4 -a "$#" != 5 ] &&
180 error "getquota: wrong number of arguments: $#"
181 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
182 error "getquota: wrong u/g/p specifier $1 passed"
195 *) error "unknown quota parameter $4";;
198 [ ! -z "$5" ] && pool_arg="--pool $5 "
199 [ "$uuid" = "global" ] && uuid=$DIR
201 $LFS quota -v "$1" "$2" $pool_arg $DIR |
202 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
203 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
208 # usage: set_mdt_qtype ugp|u|g|p|none
212 local mdts=$(get_facets MDS)
214 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
215 qtype=$(tr -d 'p' <<<$qtype)
217 if [[ $PERM_CMD == *"set_param -P"* ]]; then
218 do_facet mgs $PERM_CMD \
219 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
221 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
223 # we have to make sure each MDT received config changes
224 for mdt in ${mdts//,/ }; do
226 cmd="$LCTL get_param -n "
227 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
228 cmd=${cmd}.quota_slave.enabled
230 if $(facet_up $mdt); then
231 wait_update_facet $mdt "$cmd" "$qtype" || return 1
238 # usage: set_ost_qtype ugp|u|g|p|none
242 local osts=$(get_facets OST)
244 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
245 qtype=$(tr -d 'p' <<<$qtype)
247 if [[ $PERM_CMD == *"set_param -P"* ]]; then
248 do_facet mgs $PERM_CMD \
249 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
251 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
253 # we have to make sure each OST received config changes
254 for ost in ${osts//,/ }; do
256 cmd="$LCTL get_param -n "
257 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
258 cmd=${cmd}.quota_slave.enabled
260 if $(facet_up $ost); then
261 wait_update_facet $ost "$cmd" "$qtype" || return 1
267 wait_reintegration() {
271 local result="glb[1],slv[1],reint[0]"
276 if [ $ntype == "mdt" ]; then
277 tgts=$(get_facets MDS)
279 tgts=$(get_facets OST)
282 for tgt in ${tgts//,/ }; do
284 cmd="$LCTL get_param -n "
285 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
286 cmd=${cmd}.quota_slave.info
288 if $(facet_up $tgt); then
289 wait_update_facet $tgt "$cmd |
290 grep "$qtype" | awk '{ print \\\$3 }'" \
291 "$result" $max || return 1
301 if [[ "$qtype" =~ "u" ]]; then
302 wait_reintegration "mdt" "user" $max || return 1
305 if [[ "$qtype" =~ "g" ]]; then
306 wait_reintegration "mdt" "group" $max || return 1
309 if [[ "$qtype" =~ "p" ]]; then
310 ! is_project_quota_supported && return 0
311 wait_reintegration "mdt" "project" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "ost" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "ost" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "ost" "project" $max || return 1
339 local extrasleep=${4:-5}
346 *) error "get_grace_time: Invalid quota type: $qtype"
351 echo "Quota info for $pool:"
352 $LFS quota -$qtype $qarg $parg $DIR
357 time=$(lfs quota -$qtype $qarg $parg $DIR|
358 awk 'NR == 3{ print $5 }')
361 time=$(lfs quota -$qtype $qarg $DIR|
362 awk 'NR == 3{ print $9 }')
365 error "Unknown quota type: $flavour"
369 local sleep_seconds=0
370 local orig_time=$time
372 echo "Grace time is $time"
373 # from lfs.c:__sec2str()
374 # const char spec[] = "smhdw";
375 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
376 [[ $time == *w* ]] && w_time=${time%w*} &&
377 let sleep_seconds+=$((w_time*7*24*60*60));
379 [[ $time == *d* ]] && d_time=${time%d*} &&
380 let sleep_seconds+=$((d_time*24*60*60));
382 [[ $time == *h* ]] && h_time=${time%h*} &&
383 let sleep_seconds+=$((h_time*60*60));
385 [[ $time == *m* ]] && m_time=${time%m*} &&
386 let sleep_seconds+=$((m_time*60));
388 [[ $time == *s* ]] && s_time=${time%s*} &&
389 let sleep_seconds+=$s_time
391 echo "Sleep through grace ..."
392 [ "$orig_time" == "-" ] &&
393 error "Grace timeout was not set or quota not exceeded"
394 if [ "$orig_time" == "none" ]; then
395 echo "...Grace timeout already expired"
397 let sleep_seconds+=$extrasleep
398 echo "...sleep $sleep_seconds seconds"
404 wait_delete_completed
405 echo "Creating test directory"
406 mkdir $DIR/$tdir || return 1
407 chmod 0777 $DIR/$tdir || return 2
408 # always clear fail_loc in case of fail_loc isn't cleared
409 # properly when previous test failed
410 lustre_fail mds_ost 0
413 cleanup_quota_test() {
414 echo "Delete files..."
416 echo "Wait for unlink objects finished..."
417 wait_delete_completed
418 sync_all_data || true
428 $LFS quota -v -$ugp $qid $DIR
430 if [ "$bf" == "a" -o "$bf" == "b" ]; then
431 usage=$(getquota -$ugp $qid global curspace)
432 if [ -z $usage ]; then
433 quota_error $ugp $qid \
434 "Query block quota failed ($ugp:$qid)."
436 [ $usage -ne 0 ] && quota_log $ugp $qid \
437 "Block quota isn't 0 ($ugp:$qid:$usage)."
441 if [ "$bf" == "a" -o "$bf" == "f" ]; then
442 usage=$(getquota -$ugp $qid global curinodes)
443 if [ -z $usage ]; then
444 quota_error $ugp $qid \
445 "Query file quota failed ($ugp:$qid)."
447 [ $usage -ne 0 ] && quota_log $ugp $qid \
448 "File quota isn't 0 ($ugp:$qid:$usage)."
453 project_quota_enabled () {
455 local zfeat="feature@project_quota"
457 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
458 local facet_fstype=${facet:0:3}1_FSTYPE
461 if [ "${!facet_fstype}" = "zfs" ]; then
462 devname=$(zpool_name ${facet})
463 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
464 grep -wq active || rc=1
466 [ ${facet:0:3} == "mds" ] &&
467 devname=$(mdsdevname ${facet:3}) ||
468 devname=$(ostdevname ${facet:3})
469 do_facet ${facet} $DEBUGFS -R features $devname |
470 grep -q project || rc=1
473 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
477 project_quota_enabled || enable_project_quota
479 reset_quota_settings() {
480 resetquota -u $TSTUSR
482 resetquota -g $TSTUSR
484 resetquota -u $TSTUSR2
485 resetquota -u $TSTID2
486 resetquota -g $TSTUSR2
487 resetquota -g $TSTID2
488 resetquota -p $TSTPRJID
493 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota+trace"
498 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
499 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
500 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
501 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
503 test_quota_performance() {
504 local TESTFILE="$DIR/$tdir/$tfile-0"
505 local size=$1 # in MB
506 local stime=$(date +%s)
507 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
508 quota_error u $TSTUSR "write failure"
509 local etime=$(date +%s)
510 delta=$((etime - stime))
511 if [ $delta -gt 0 ]; then
512 rate=$((size * 1024 / delta))
513 if [ "$mds1_FSTYPE" = zfs ]; then
514 # LU-2872 - see LU-2887 for fix
516 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
518 [ $rate -gt 1024 ] ||
519 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
525 # test basic quota performance b=21696
528 [ "$SLOW" = "no" ] && MB=10
530 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
531 [ $free_space -le $((MB * 1024)) ] &&
532 skip "not enough space ${free_space} KB, " \
533 "required $((MB * 1024)) KB"
534 setup_quota_test || error "setup quota failed with $?"
535 trap cleanup_quota_test EXIT
537 set_ost_qtype "none" || error "disable ost quota failed"
538 test_quota_performance $MB
540 set_ost_qtype $QTYPE || error "enable ost quota failed"
541 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
542 error "set quota failed"
543 test_quota_performance $MB
547 run_test 0 "Test basic quota performance"
549 # usage: test_1_check_write tfile user|group|project
550 test_1_check_write() {
554 local short_qtype=${qtype:0:1}
557 $RUNAS $DD of=$testfile count=$((limit/2)) ||
558 quota_error $short_qtype $TSTUSR \
559 "$qtype write failure, but expect success"
560 log "Write out of block quota ..."
561 # this time maybe cache write, ignore it's failure
562 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
563 # flush cache, ensure noquota flag is set on client
565 sync; sync_all_data || true
566 # sync means client wrote all it's cache, but id doesn't
567 # garantee that slave got new edquot trough glimpse.
568 # so wait a little to be sure slave got it.
570 $RUNAS $DD of=$testfile count=1 seek=$limit &&
571 quota_error $short_qtype $TSTUSR \
572 "user write success, but expect EDQUOT"
575 check_write_fallocate() {
579 local short_qtype=${qtype:0:1}
582 log "Write ${count}MiB Using Fallocate"
583 $RUNAS fallocate -l${count}MiB $testfile ||
584 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
587 sync; sync_all_data || true
591 log "Write ${count}MiB Using Fallocate"
592 $RUNAS fallocate -l${count}MiB $testfile &&
593 quota_error $short_qtype $TSTUSR \
594 "Write success, expect EDQUOT" || true
597 # test block hardlimit
600 local testfile="$DIR/$tdir/$tfile-0"
602 setup_quota_test || error "setup quota failed with $?"
603 trap cleanup_quota_test EXIT
606 set_ost_qtype $QTYPE || error "enable ost quota failed"
609 log "User quota (block hardlimit:$limit MB)"
610 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
611 error "set user quota failed"
613 # make sure the system is clean
614 local used=$(getquota -u $TSTUSR global curspace)
615 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
617 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
618 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
620 test_1_check_write $testfile "user" $limit
623 wait_delete_completed || error "wait_delete_completed failed"
624 sync_all_data || true
625 used=$(getquota -u $TSTUSR global curspace)
626 [ $used -ne 0 ] && quota_error u $TSTUSR \
627 "user quota isn't released after deletion"
628 resetquota -u $TSTUSR
631 log "--------------------------------------"
632 log "Group quota (block hardlimit:$limit MB)"
633 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
634 error "set group quota failed"
636 testfile="$DIR/$tdir/$tfile-1"
637 # make sure the system is clean
638 used=$(getquota -g $TSTUSR global curspace)
639 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
641 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
642 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
644 test_1_check_write $testfile "group" $limit
646 wait_delete_completed || error "wait_delete_completed failed"
647 sync_all_data || true
648 used=$(getquota -g $TSTUSR global curspace)
649 [ $used -ne 0 ] && quota_error g $TSTUSR \
650 "Group quota isn't released after deletion"
651 resetquota -g $TSTUSR
653 if ! is_project_quota_supported; then
654 echo "Project quota is not supported"
659 testfile="$DIR/$tdir/$tfile-2"
660 # make sure the system is clean
661 used=$(getquota -p $TSTPRJID global curspace)
663 error "used space($used) for project $TSTPRJID isn't 0"
666 log "--------------------------------------"
667 log "Project quota (block hardlimit:$limit mb)"
668 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
669 error "set project quota failed"
671 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
672 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
673 change_project -p $TSTPRJID $testfile
675 test_1_check_write $testfile "project" $limit
680 used=$(getquota -p $TSTPRJID global curspace)
681 [ $used -ne 0 ] && quota_error p $TSTPRJID \
682 "project quota isn't released after deletion"
684 resetquota -p $TSTPRJID
686 run_test 1a "Block hard limit (normal use and out of quota)"
690 local global_limit=20 # 100M
691 local testfile="$DIR/$tdir/$tfile-0"
695 setup_quota_test || error "setup quota failed with $?"
696 stack_trap cleanup_quota_test EXIT
699 set_ost_qtype $QTYPE || error "enable ost quota failed"
702 log "User quota (block hardlimit:$global_limit MB)"
703 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
704 error "set user quota failed"
706 pool_add $qpool || error "pool_add failed"
707 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
708 error "pool_add_targets failed"
710 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
711 error "set user quota failed"
713 # make sure the system is clean
714 local used=$(getquota -u $TSTUSR global curspace)
716 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
718 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
720 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
721 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
723 test_1_check_write $testfile "user" $limit
726 wait_delete_completed || error "wait_delete_completed failed"
727 sync_all_data || true
728 used=$(getquota -u $TSTUSR global curspace $qpool)
729 [ $used -ne 0 ] && quota_error u $TSTUSR \
730 "user quota isn't released after deletion"
731 resetquota -u $TSTUSR
734 log "--------------------------------------"
735 log "Group quota (block hardlimit:$global_limit MB)"
736 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
737 error "set group quota failed"
739 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
740 error "set group quota failed"
742 testfile="$DIR/$tdir/$tfile-1"
743 # make sure the system is clean
744 used=$(getquota -g $TSTUSR global curspace $qpool)
745 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
747 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
748 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
750 test_1_check_write $testfile "group" $limit
753 wait_delete_completed || error "wait_delete_completed failed"
754 sync_all_data || true
755 used=$(getquota -g $TSTUSR global curspace $qpool)
756 [ $used -ne 0 ] && quota_error g $TSTUSR \
757 "Group quota isn't released after deletion"
758 resetquota -g $TSTUSR
760 if ! is_project_quota_supported; then
761 echo "Project quota is not supported"
766 testfile="$DIR/$tdir/$tfile-2"
767 # make sure the system is clean
768 used=$(getquota -p $TSTPRJID global curspace $qpool)
770 error "used space($used) for project $TSTPRJID isn't 0"
773 log "--------------------------------------"
774 log "Project quota (block hardlimit:$global_limit mb)"
775 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
776 error "set project quota failed"
778 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
779 error "set project quota failed"
782 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
783 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
784 change_project -p $TSTPRJID $testfile
786 test_1_check_write $testfile "project" $limit
791 used=$(getquota -p $TSTPRJID global curspace)
792 [ $used -eq 0 ] || quota_error p $TSTPRJID \
793 "project quota isn't released after deletion"
795 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
798 local global_limit=20 # 100M
799 local testfile="$DIR/$tdir/$tfile-0"
800 local qpool1="qpool1"
801 local qpool2="qpool2"
804 setup_quota_test || error "setup quota failed with $?"
805 stack_trap cleanup_quota_test EXIT
808 set_ost_qtype $QTYPE || error "enable ost quota failed"
811 log "User quota (block hardlimit:$global_limit MB)"
812 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
813 error "set user quota failed"
815 pool_add $qpool1 || error "pool_add failed"
816 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
817 error "pool_add_targets failed"
819 pool_add $qpool2 || error "pool_add failed"
820 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
821 error "pool_add_targets failed"
823 # create pools without hard limit
824 # initially such case raised several bugs
825 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
826 error "set user quota failed"
828 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
829 error "set user quota failed"
831 # make sure the system is clean
832 local used=$(getquota -u $TSTUSR global curspace)
834 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
836 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
838 test_1_check_write $testfile "user" $global_limit
840 used=$(getquota -u $TSTUSR global curspace $qpool1)
841 echo "qpool1 used $used"
842 used=$(getquota -u $TSTUSR global curspace $qpool2)
843 echo "qpool2 used $used"
846 wait_delete_completed || error "wait_delete_completed failed"
847 sync_all_data || true
849 used=$(getquota -u $TSTUSR global curspace $qpool1)
850 [ $used -ne 0 ] && quota_error u $TSTUSR \
851 "user quota isn't released after deletion"
852 resetquota -u $TSTUSR
857 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
860 local limit1=10 # 10M
861 local limit2=12 # 12M
862 local global_limit=20 # 100M
863 local testfile="$DIR/$tdir/$tfile-0"
864 local qpool1="qpool1"
865 local qpool2="qpool2"
868 setup_quota_test || error "setup quota failed with $?"
869 stack_trap cleanup_quota_test EXIT
872 set_ost_qtype $QTYPE || error "enable ost quota failed"
875 log "User quota (block hardlimit:$global_limit MB)"
876 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
877 error "set user quota failed"
879 pool_add $qpool1 || error "pool_add failed"
880 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
881 error "pool_add_targets failed"
883 pool_add $qpool2 || error "pool_add failed"
884 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
885 error "pool_add_targets failed"
887 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
888 error "set user quota failed"
890 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
891 error "set user quota failed"
893 # make sure the system is clean
894 local used=$(getquota -u $TSTUSR global curspace)
896 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
898 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
900 test_1_check_write $testfile "user" $limit1
902 used=$(getquota -u $TSTUSR global curspace $qpool1)
903 echo "qpool1 used $used"
904 used=$(getquota -u $TSTUSR global curspace $qpool2)
905 echo "qpool2 used $used"
908 wait_delete_completed || error "wait_delete_completed failed"
909 sync_all_data || true
911 used=$(getquota -u $TSTUSR global curspace $qpool1)
912 [ $used -ne 0 ] && quota_error u $TSTUSR \
913 "user quota isn't released after deletion"
914 resetquota -u $TSTUSR
919 run_test 1d "Quota pools: check block hardlimit on different pools"
922 local limit1=10 # 10M
923 local global_limit=200 # 200M
924 local testfile="$DIR/$tdir/$tfile-0"
925 local testfile2="$DIR/$tdir/$tfile-1"
926 local qpool1="qpool1"
929 setup_quota_test || error "setup quota failed with $?"
930 stack_trap cleanup_quota_test EXIT
933 set_ost_qtype $QTYPE || error "enable ost quota failed"
935 # global_limit is much greater than limit1 to get
936 # different qunit's on osts. Since 1st qunit shrinking
937 # on OST1(that belongs to qpool1), this qunit should
939 log "User quota (block hardlimit:$global_limit MB)"
940 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
941 error "set user quota failed"
943 pool_add $qpool1 || error "pool_add failed"
944 pool_add_targets $qpool1 1 1 ||
945 error "pool_add_targets failed"
947 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
948 error "set user quota failed"
950 # make sure the system is clean
951 local used=$(getquota -u $TSTUSR global curspace)
952 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
954 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
955 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
957 test_1_check_write $testfile "user" $limit1
959 $LFS setstripe $testfile2 -c 1 -i 0 ||
960 error "setstripe $testfile2 failed"
961 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
962 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
964 $RUNAS $DD of=$testfile2 count=20 ||
965 quota_error u $TSTUSR \
966 "$qtype write failure, but expect success"
970 wait_delete_completed || error "wait_delete_completed failed"
971 sync_all_data || true
973 used=$(getquota -u $TSTUSR global curspace $qpool1)
974 [ $used -ne 0 ] && quota_error u $TSTUSR \
975 "user quota isn't released after deletion"
976 resetquota -u $TSTUSR
981 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
984 local global_limit=200 # 200M
985 local limit1=10 # 10M
986 local TESTDIR="$DIR/$tdir/"
987 local testfile="$TESTDIR/$tfile-0"
988 local qpool1="qpool1"
991 setup_quota_test || error "setup quota failed with $?"
992 stack_trap cleanup_quota_test EXIT
995 set_ost_qtype $QTYPE || error "enable ost quota failed"
997 log "User quota (block hardlimit:$global_limit MB)"
998 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
999 error "set user quota failed"
1001 pool_add $qpool1 || error "pool_add failed"
1002 pool_add_targets $qpool1 0 0 ||
1003 error "pool_add_targets failed"
1005 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1006 error "set user quota failed"
1008 # make sure the system is clean
1009 local used=$(getquota -u $TSTUSR global curspace)
1010 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1012 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1014 test_1_check_write $testfile "user" $limit1
1016 pool_remove_target $qpool1 0
1018 wait_delete_completed || error "wait_delete_completed failed"
1019 sync_all_data || true
1021 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1022 # qunit for appropriate element in lgd array should be set
1023 # correctly(4096). Earlier it was not changed continuing to be 1024.
1024 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1025 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1026 # as it already was 1024. As flag "need_update" for this qunit was
1027 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1028 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1029 # became > 10M. QMT returned EINPROGRESS in a loop.
1030 # Check that it doesn't hung anymore.
1031 test_1_check_write $testfile "user" $limit1
1036 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1039 local limit=20 # 20M
1040 local global_limit=40 # 40M
1041 local testfile="$DIR/$tdir/$tfile-0"
1042 local qpool="qpool1"
1043 local mdmb_param="osc.*.max_dirty_mb"
1044 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1047 setup_quota_test || error "setup quota failed with $?"
1048 stack_trap cleanup_quota_test EXIT
1049 $LCTL set_param $mdmb_param=1
1050 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1053 set_ost_qtype $QTYPE || error "enable ost quota failed"
1056 log "User quota (block hardlimit:$global_limit MB)"
1057 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1058 error "set user quota failed"
1060 pool_add $qpool || error "pool_add failed"
1061 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1062 error "pool_add_targets failed"
1064 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1065 error "set user quota failed"
1067 # make sure the system is clean
1068 local used=$(getquota -u $TSTUSR global curspace)
1070 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1072 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1073 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1076 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1077 quota_error u $TSTUSR \
1078 "$qtype write failure, but expect success"
1079 log "Write out of block quota ..."
1080 # this time maybe cache write, ignore it's failure
1081 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1082 # flush cache, ensure noquota flag is set on client
1083 cancel_lru_locks osc
1084 sync; sync_all_data || true
1086 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1087 quota_error u $TSTUSR \
1088 "user write success, but expect EDQUOT"
1091 wait_delete_completed || error "wait_delete_completed failed"
1092 sync_all_data || true
1094 used=$(getquota -u $TSTUSR global curspace $qpool)
1095 [ $used -ne 0 ] && quota_error u $TSTUSR \
1096 "user quota isn't released after deletion"
1099 run_test 1g "Quota pools: Block hard limit with wide striping"
1102 local limit=10 # 10M
1103 local testfile="$DIR/$tdir/$tfile-0"
1105 check_set_fallocate_or_skip
1107 setup_quota_test || error "setup quota failed with $?"
1108 trap cleanup_quota_test EXIT
1111 set_ost_qtype $QTYPE || error "enable ost quota failed"
1114 log "User quota (block hardlimit:$limit MB)"
1115 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1116 error "set user quota failed"
1118 # make sure the system is clean
1119 local used=$(getquota -u $TSTUSR global curspace)
1120 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1122 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1123 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1125 check_write_fallocate $testfile "user" $limit
1128 wait_delete_completed || error "wait_delete_completed failed"
1129 sync_all_data || true
1130 used=$(getquota -u $TSTUSR global curspace)
1131 [ $used -ne 0 ] && quota_error u $TSTUSR \
1132 "user quota isn't released after deletion"
1133 resetquota -u $TSTUSR
1135 run_test 1h "Block hard limit test using fallocate"
1137 # test inode hardlimit
1139 local TESTFILE="$DIR/$tdir/$tfile-0"
1140 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1141 qmt.$FSNAME-QMT0000.md-0x0.info |
1142 awk '/least qunit/{ print $3 }')
1143 local L2=$(do_facet mds1 $LCTL get_param -n \
1144 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1146 [ $L2 -le $LIMIT ] || LIMIT=$L2
1148 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1150 local FREE_INODES=$(mdt_free_inodes 0)
1151 echo "$FREE_INODES free inodes on master MDT"
1152 [ $FREE_INODES -lt $LIMIT ] &&
1153 skip "not enough free inodes $FREE_INODES required $LIMIT"
1155 setup_quota_test || error "setup quota failed with $?"
1156 trap cleanup_quota_test EXIT
1159 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1162 log "User quota (inode hardlimit:$LIMIT files)"
1163 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1164 error "set user quota failed"
1166 # make sure the system is clean
1167 local USED=$(getquota -u $TSTUSR global curinodes)
1168 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1170 log "Create $LIMIT files ..."
1171 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1172 quota_error u $TSTUSR "user create failure, but expect success"
1173 log "Create out of file quota ..."
1174 $RUNAS touch ${TESTFILE}_xxx &&
1175 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1178 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1179 rm -f ${TESTFILE}_xxx
1180 wait_delete_completed
1182 USED=$(getquota -u $TSTUSR global curinodes)
1183 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1184 "user quota isn't released after deletion"
1185 resetquota -u $TSTUSR
1188 log "--------------------------------------"
1189 log "Group quota (inode hardlimit:$LIMIT files)"
1190 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1191 error "set group quota failed"
1193 TESTFILE=$DIR/$tdir/$tfile-1
1194 # make sure the system is clean
1195 USED=$(getquota -g $TSTUSR global curinodes)
1196 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1198 log "Create $LIMIT files ..."
1199 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1200 quota_error g $TSTUSR "group create failure, but expect success"
1201 log "Create out of file quota ..."
1202 $RUNAS touch ${TESTFILE}_xxx &&
1203 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1206 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1207 rm -f ${TESTFILE}_xxx
1208 wait_delete_completed
1210 USED=$(getquota -g $TSTUSR global curinodes)
1211 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1212 "user quota isn't released after deletion"
1214 resetquota -g $TSTUSR
1215 ! is_project_quota_supported && cleanup_quota_test &&
1216 echo "Skip project quota is not supported" && return 0
1219 log "--------------------------------------"
1220 log "Project quota (inode hardlimit:$LIMIT files)"
1221 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1222 error "set project quota failed"
1224 TESTFILE=$DIR/$tdir/$tfile-1
1225 # make sure the system is clean
1226 USED=$(getquota -p $TSTPRJID global curinodes)
1228 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1230 change_project -sp $TSTPRJID $DIR/$tdir
1231 log "Create $LIMIT files ..."
1232 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1233 $TSTPRJID "project create fail, but expect success"
1234 log "Create out of file quota ..."
1235 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1236 "project create success, but expect EDQUOT"
1237 change_project -C $DIR/$tdir
1240 USED=$(getquota -p $TSTPRJID global curinodes)
1241 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1242 "project quota isn't released after deletion"
1245 run_test 2 "File hard limit (normal use and out of quota)"
1254 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1255 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1258 stack_trap cleanup_quota_test EXIT
1260 $LFS setstripe $testfile -c 1 -i 0
1261 chown $TSTUSR.$TSTUSR $testfile
1262 [ "$qtype" == "p" ] && is_project_quota_supported &&
1263 change_project -p $TSTPRJID $testfile
1265 echo "Write up to soft limit"
1266 $RUNAS $DD of=$testfile count=$limit ||
1267 quota_error a $TSTUSR "write failure, but expect success"
1268 OFFSET=$((limit * 1024))
1269 cancel_lru_locks osc
1271 echo "Write to exceed soft limit"
1272 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1273 quota_error a $TSTUSR "write failure, but expect success"
1274 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1275 cancel_lru_locks osc
1277 echo "mmap write when over soft limit"
1278 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1279 quota_error a $TSTUSR "mmap write failure, but expect success"
1280 cancel_lru_locks osc
1285 $SHOW_QUOTA_INFO_USER
1286 $SHOW_QUOTA_INFO_GROUP
1287 $SHOW_QUOTA_INFO_PROJID
1289 echo "Write before timer goes off"
1290 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1291 quota_error a $TSTUSR "write failure, but expect success"
1292 OFFSET=$((OFFSET + 1024))
1293 cancel_lru_locks osc
1295 wait_grace_time $qtype "block" $pool
1300 $SHOW_QUOTA_INFO_USER
1301 $SHOW_QUOTA_INFO_GROUP
1302 $SHOW_QUOTA_INFO_PROJID
1304 log "Write after timer goes off"
1305 # maybe cache write, ignore.
1306 # write up to soft least quint to consume all
1307 # possible slave granted space.
1308 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1309 count=$soft_limit seek=$OFFSET || true
1310 OFFSET=$((OFFSET + soft_limit))
1311 cancel_lru_locks osc
1312 log "Write after cancel lru locks"
1313 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1314 quota_error a $TSTUSR "write success, but expect EDQUOT"
1319 $SHOW_QUOTA_INFO_USER
1320 $SHOW_QUOTA_INFO_GROUP
1321 $SHOW_QUOTA_INFO_PROJID
1323 echo "Unlink file to stop timer"
1325 wait_delete_completed
1326 sync_all_data || true
1331 $SHOW_QUOTA_INFO_USER
1332 $SHOW_QUOTA_INFO_GROUP
1333 $SHOW_QUOTA_INFO_PROJID
1335 $LFS setstripe $testfile -c 1 -i 0
1336 chown $TSTUSR.$TSTUSR $testfile
1337 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1340 $RUNAS $DD of=$testfile count=$limit ||
1341 quota_error a $TSTUSR "write failure, but expect success"
1348 local grace=20 # 20s
1349 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1352 local testfile=$DIR/$tdir/$tfile-0
1354 # get minimum soft qunit size
1355 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1356 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1358 set_ost_qtype $QTYPE || error "enable ost quota failed"
1360 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1361 # make sure the system is clean
1362 local used=$(getquota -u $TSTUSR global curspace)
1363 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1365 $LFS setquota -t -u --block-grace $grace --inode-grace \
1366 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1367 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1368 error "set user quota failed"
1370 test_block_soft $testfile $grace $limit "u"
1372 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1373 testfile=$DIR/$tdir/$tfile-1
1374 # make sure the system is clean
1375 used=$(getquota -g $TSTUSR global curspace)
1376 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1378 $LFS setquota -t -g --block-grace $grace --inode-grace \
1379 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1380 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1381 error "set group quota failed"
1383 test_block_soft $testfile $grace $limit "g"
1385 if is_project_quota_supported; then
1386 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1387 testfile=$DIR/$tdir/$tfile-2
1388 # make sure the system is clean
1389 used=$(getquota -p $TSTPRJID global curspace)
1390 [ $used -ne 0 ] && error \
1391 "Used space($used) for project $TSTPRJID isn't 0."
1393 $LFS setquota -t -p --block-grace $grace --inode-grace \
1394 $MAX_IQ_TIME $DIR ||
1395 error "set project grace time failed"
1396 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1397 $DIR || error "set project quota failed"
1399 test_block_soft $testfile $grace $limit "p"
1400 resetquota -p $TSTPRJID
1401 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1402 $MAX_IQ_TIME $DIR ||
1403 error "restore project grace time failed"
1407 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1408 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1409 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1410 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1412 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1415 local grace=20 # 20s
1416 local qpool="qpool1"
1417 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1420 local testfile=$DIR/$tdir/$tfile-0
1423 # get minimum soft qunit size
1424 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1425 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1426 local glbl_limit=$((2*limit))
1427 local glbl_grace=$((2*grace))
1428 echo "limit $limit glbl_limit $glbl_limit"
1429 echo "grace $grace glbl_grace $glbl_grace"
1431 set_ost_qtype $QTYPE || error "enable ost quota failed"
1433 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1434 # make sure the system is clean
1435 local used=$(getquota -u $TSTUSR global curspace)
1436 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1438 pool_add $qpool || error "pool_add failed"
1439 pool_add_targets $qpool 0 1 ||
1440 error "pool_add_targets failed"
1442 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1443 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1444 $LFS setquota -t -u --block-grace $grace \
1445 --pool $qpool $DIR || error "set user grace time failed"
1447 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1448 error "set user quota failed"
1449 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1450 error "set user quota failed"
1452 test_block_soft $testfile $grace $limit "u" $qpool
1454 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1455 testfile=$DIR/$tdir/$tfile-1
1456 # make sure the system is clean
1457 used=$(getquota -g $TSTUSR global curspace)
1458 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1460 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1461 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1462 $LFS setquota -t -g --block-grace $grace \
1463 --pool $qpool $DIR || error "set group grace time failed"
1465 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1466 error "set group quota failed"
1467 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1468 error "set group quota failed"
1470 test_block_soft $testfile $grace $limit "g" $qpool
1472 if is_project_quota_supported; then
1473 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1474 testfile=$DIR/$tdir/$tfile-2
1475 # make sure the system is clean
1476 used=$(getquota -p $TSTPRJID global curspace)
1477 [ $used -ne 0 ] && error \
1478 "Used space($used) for project $TSTPRJID isn't 0."
1480 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1481 $MAX_IQ_TIME $DIR ||
1482 error "set project grace time failed"
1483 $LFS setquota -t -p --block-grace $grace \
1484 --pool $qpool $DIR ||
1485 error "set project grace time failed"
1487 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1488 $DIR || error "set project quota failed"
1489 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1490 --pool $qpool $DIR || error "set project quota failed"
1492 test_block_soft $testfile $grace $limit "p" $qpool
1493 resetquota -p $TSTPRJID
1494 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1495 $MAX_IQ_TIME $DIR ||
1496 error "restore project grace time failed"
1497 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1498 $DIR || error "set project grace time failed"
1502 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1503 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1504 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1505 --pool $qpool $DIR || error "restore user grace time failed"
1506 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1507 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1508 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1509 --pool $qpool $DIR || error "restore group grace time failed"
1511 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1514 local grace=20 # 20s
1515 local qpool="qpool1"
1516 local qpool2="qpool2"
1517 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1520 local testfile=$DIR/$tdir/$tfile-0
1523 # get minimum soft qunit size
1524 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1525 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1526 local limit2=$((limit+4))
1527 local glbl_limit=$((limit+8))
1528 local grace1=$((grace+10))
1530 local glbl_grace=$((grace+20))
1531 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1532 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1534 set_ost_qtype $QTYPE || error "enable ost quota failed"
1536 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1537 # make sure the system is clean
1538 local used=$(getquota -u $TSTUSR global curspace)
1539 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1541 pool_add $qpool || error "pool_add failed"
1542 pool_add_targets $qpool 0 1 ||
1543 error "pool_add_targets failed"
1545 pool_add $qpool2 || error "pool_add failed"
1546 pool_add_targets $qpool2 0 1 ||
1547 error "pool_add_targets failed"
1550 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1551 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1552 $LFS setquota -t -u --block-grace $grace1 \
1553 --pool $qpool $DIR || error "set user grace time failed"
1554 $LFS setquota -t -u --block-grace $grace2 \
1555 --pool $qpool2 $DIR || error "set user grace time failed"
1557 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1558 error "set user quota failed"
1559 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1560 error "set user quota failed"
1561 # qpool has minimum soft limit, but it's grace is grater than
1562 # grace period of qpool2. Thus write shouldn't fail when
1563 # hit qpool soft limit - only when reaches up qpool2 limit
1564 # after grace2 seconds.
1565 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1566 error "set user quota failed"
1568 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1571 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1572 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1573 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1574 --pool $qpool $DIR || error "restore user grace time failed"
1575 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1576 --pool $qpool2 $DIR || error "restore user grace time failed"
1578 run_test 3c "Quota pools: check block soft limit on different pools"
1585 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1586 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1589 trap cleanup_quota_test EXIT
1590 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1592 echo "Create files to exceed soft limit"
1593 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1594 quota_error a $TSTUSR "create failure, but expect success"
1595 local trigger_time=$(date +%s)
1597 sync_all_data || true
1599 local cur_time=$(date +%s)
1600 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1601 error "Passed grace time $grace, $trigger_time, $cur_time"
1603 echo "Create file before timer goes off"
1604 $RUNAS touch ${TESTFILE}_before ||
1605 quota_error a $TSTUSR "failed create before timer expired," \
1606 "but expect success. $trigger_time, $cur_time"
1607 sync_all_data || true
1609 wait_grace_time $qtype "file"
1614 $SHOW_QUOTA_INFO_USER
1615 $SHOW_QUOTA_INFO_GROUP
1616 $SHOW_QUOTA_INFO_PROJID
1618 echo "Create file after timer goes off"
1619 # exceed least soft limit is possible
1620 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1621 quota_error a $TSTUSR "create after timer expired," \
1623 sync_all_data || true
1628 $SHOW_QUOTA_INFO_USER
1629 $SHOW_QUOTA_INFO_GROUP
1630 $SHOW_QUOTA_INFO_PROJID
1632 echo "Unlink files to stop timer"
1633 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1634 wait_delete_completed
1637 $RUNAS touch ${TESTFILE}_xxx ||
1638 quota_error a $TSTUSR "touch after timer stop failure," \
1639 "but expect success"
1640 sync_all_data || true
1648 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1649 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1650 local TESTFILE=$DIR/$tdir/$tfile-0
1653 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1655 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1656 # make sure the system is clean
1657 local USED=$(getquota -u $TSTUSR global curinodes)
1658 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1660 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1661 $GRACE $DIR || error "set user grace time failed"
1662 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1663 error "set user quota failed"
1665 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1667 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1669 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1670 # make sure the system is clean
1671 USED=$(getquota -g $TSTUSR global curinodes)
1672 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1674 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1675 $GRACE $DIR || error "set group grace time failed"
1676 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1677 error "set group quota failed"
1678 TESTFILE=$DIR/$tdir/$tfile-1
1680 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1682 if is_project_quota_supported; then
1683 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1684 # make sure the system is clean
1685 USED=$(getquota -p $TSTPRJID global curinodes)
1686 [ $USED -ne 0 ] && error \
1687 "Used space($USED) for project $TSTPRJID isn't 0."
1689 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1690 $GRACE $DIR || error "set project grace time failed"
1691 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1692 error "set project quota failed"
1694 TESTFILE=$DIR/$tdir/$tfile-1
1695 # one less than limit, because of parent directory included.
1696 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1697 resetquota -p $TSTPRJID
1698 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1699 $MAX_IQ_TIME $DIR ||
1700 error "restore project grace time failed"
1704 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1705 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1706 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1707 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1709 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1712 local GR_STR1="1w3d"
1713 local GR_STR2="1000s"
1715 local GR_STR4="1w2d3h4m5s"
1717 local GR_STR6="18446744073709551615"
1720 wait_delete_completed
1722 # test of valid grace strings handling
1723 echo "Valid grace strings test"
1724 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1725 $GR_STR2 $DIR || error "set user grace time failed"
1726 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1727 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1728 $GR_STR4 $DIR || error "set group grace time quota failed"
1729 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1731 # test of invalid grace strings handling
1732 echo " Invalid grace strings test"
1733 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1734 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1735 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1739 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1740 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1741 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1742 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1744 run_test 4b "Grace time strings handling"
1746 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1748 local BLIMIT=10 # 10M
1749 local ILIMIT=10 # 10 inodes
1751 setup_quota_test || error "setup quota failed with $?"
1752 trap cleanup_quota_test EXIT
1754 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1755 set_ost_qtype $QTYPE || error "enable ost quota failed"
1757 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1758 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1759 error "set user quota failed"
1760 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1761 if is_project_quota_supported; then
1762 error "set group quota failed"
1763 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1764 -I $ILIMIT $DIR || error "set project quota failed"
1767 # make sure the system is clean
1768 local USED=$(getquota -u $TSTUSR global curinodes)
1769 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1770 USED=$(getquota -g $TSTUSR global curinodes)
1771 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1772 USED=$(getquota -u $TSTUSR global curspace)
1773 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1774 USED=$(getquota -g $TSTUSR global curspace)
1775 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1776 if is_project_quota_supported; then
1777 USED=$(getquota -p $TSTPRJID global curinodes)
1779 error "Used inode($USED) for project $TSTPRJID isn't 0."
1780 USED=$(getquota -p $TSTPRJID global curspace)
1782 error "Used block($USED) for project $TSTPRJID isn't 0."
1785 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1786 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1787 error "create failure, expect success"
1788 if is_project_quota_supported; then
1789 touch $DIR/$tdir/$tfile-0_1
1790 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1792 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1793 error "write failure, expect success"
1795 echo "Chown files to $TSTUSR.$TSTUSR ..."
1796 for i in $(seq 0 $ILIMIT); do
1797 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1798 quota_error a $TSTUSR "chown failure, expect success"
1802 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1803 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1806 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1808 # test dropping acquire request on master
1812 # Clear dmesg so watchdog is not triggered by previous
1814 do_facet ost1 dmesg -c > /dev/null
1816 setup_quota_test || error "setup quota failed with $?"
1817 trap cleanup_quota_test EXIT
1819 # make sure the system is clean
1820 local USED=$(getquota -u $TSTUSR global curspace)
1821 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1823 # make sure no granted quota on ost
1824 set_ost_qtype $QTYPE || error "enable ost quota failed"
1825 resetquota -u $TSTUSR
1827 # create file for $TSTUSR
1828 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1829 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1830 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1832 # create file for $TSTUSR2
1833 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1834 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1835 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1837 # cache per-ID lock for $TSTUSR on slave
1838 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1839 error "set quota failed"
1840 $RUNAS $DD of=$TESTFILE count=1 ||
1841 error "write $TESTFILE failure, expect success"
1842 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1843 error "write $TESTFILE2 failure, expect success"
1845 if at_is_enabled; then
1846 at_max_saved=$(at_max_get ost1)
1847 at_max_set $TIMEOUT ost1
1849 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1850 # DQACQ is sent, which makes at_max to take effect
1851 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1854 wait_delete_completed
1858 sync_all_data || true
1860 #define QUOTA_DQACQ 601
1861 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1862 lustre_fail mds 0x513 601
1864 do_facet ost1 $LCTL set_param \
1865 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1867 # write to un-enforced ID ($TSTUSR2) should succeed
1868 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1869 error "write failure, expect success"
1871 # write to enforced ID ($TSTUSR) in background, exceeding limit
1872 # to make sure DQACQ is sent
1873 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1876 # watchdog timer uses a factor of 2
1877 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1878 sleep $((TIMEOUT * 2 + 1))
1880 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1882 # write should be blocked and never finished
1883 if ! ps -p $DDPID > /dev/null 2>&1; then
1885 error "write finished incorrectly!"
1890 # no watchdog is triggered
1891 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1892 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1893 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1894 [ -z "$watchdog" ] || error "$watchdog"
1896 rm -f $TMP/lustre-log-${TESTNAME}.log
1898 # write should continue then fail with EDQUOT
1902 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1903 if [ $count -ge 240 ]; then
1904 quota_error u $TSTUSR "dd not finished in $count secs"
1906 count=$((count + 1))
1907 if [ $((count % 30)) -eq 0 ]; then
1908 c_size=$(stat -c %s $TESTFILE)
1909 echo "Waiting $count secs. $c_size"
1917 run_test 6 "Test dropping acquire request on master"
1919 # quota reintegration (global index)
1921 local TESTFILE=$DIR/$tdir/$tfile
1922 local LIMIT=20 # 20M
1924 [ "$SLOW" = "no" ] && LIMIT=5
1926 setup_quota_test || error "setup quota failed with $?"
1927 trap cleanup_quota_test EXIT
1929 # make sure the system is clean
1930 local USED=$(getquota -u $TSTUSR global curspace)
1931 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1933 # make sure no granted quota on ost1
1934 set_ost_qtype $QTYPE || error "enable ost quota failed"
1935 resetquota -u $TSTUSR
1936 set_ost_qtype "none" || error "disable ost quota failed"
1938 local OSTUUID=$(ostuuid_from_index 0)
1939 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1941 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1944 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1945 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1950 echo "Enable quota & set quota limit for $TSTUSR"
1951 set_ost_qtype $QTYPE || error "enable ost quota failed"
1952 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1953 error "set quota failed"
1955 echo "Start ost1..."
1956 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1959 wait_ost_reint $QTYPE || error "reintegration failed"
1961 # hardlimit should have been fetched by slave during global
1962 # reintegration, write will exceed quota
1963 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1964 quota_error u $TSTUSR "write success, but expect EDQUOT"
1967 wait_delete_completed
1968 sync_all_data || true
1974 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1975 error "clear quota failed"
1977 echo "Start ost1..."
1978 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1981 wait_ost_reint $QTYPE || error "reintegration failed"
1983 # hardlimit should be cleared on slave during reintegration
1984 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1985 quota_error u $TSTUSR "write error, but expect success"
1989 run_test 7a "Quota reintegration (global index)"
1991 # quota reintegration (slave index)
1994 local TESTFILE=$DIR/$tdir/$tfile
1996 setup_quota_test || error "setup quota failed with $?"
1997 trap cleanup_quota_test EXIT
1999 # make sure the system is clean
2000 local USED=$(getquota -u $TSTUSR global curspace)
2001 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2003 # make sure no granted quota on ost1
2004 set_ost_qtype $QTYPE || error "enable ost quota failed"
2005 resetquota -u $TSTUSR
2006 set_ost_qtype "none" || error "disable ost quota failed"
2008 local OSTUUID=$(ostuuid_from_index 0)
2009 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2011 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2014 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2015 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2017 # consume some space to make sure the granted space will not
2018 # be released during reconciliation
2019 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2020 error "consume space failure, expect success"
2022 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2023 lustre_fail mds 0xa02
2025 set_ost_qtype $QTYPE || error "enable ost quota failed"
2026 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2027 error "set quota failed"
2029 # ignore the write error
2030 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2032 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2036 echo "Restart ost to trigger reintegration..."
2038 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2041 wait_ost_reint $QTYPE || error "reintegration failed"
2043 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2044 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2049 run_test 7b "Quota reintegration (slave index)"
2051 # quota reintegration (restart mds during reintegration)
2053 local LIMIT=20 # 20M
2054 local TESTFILE=$DIR/$tdir/$tfile
2056 [ "$SLOW" = "no" ] && LIMIT=5
2058 setup_quota_test || error "setup quota failed with $?"
2059 trap cleanup_quota_test EXIT
2061 # make sure the system is clean
2062 local USED=$(getquota -u $TSTUSR global curspace)
2063 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2065 set_ost_qtype "none" || error "disable ost quota failed"
2066 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2067 error "set quota failed"
2069 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2070 lustre_fail ost 0xa03
2073 set_ost_qtype $QTYPE || error "enable ost quota failed"
2074 # trigger reintegration
2075 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2076 procf=${procf}quota_slave.force_reint
2077 do_facet ost1 $LCTL set_param $procf=1 ||
2078 error "force reintegration failed"
2086 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2089 # wait longer than usual to make sure the reintegration
2090 # is triggered by quota wb thread.
2091 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2093 # hardlimit should have been fetched by slave during global
2094 # reintegration, write will exceed quota
2095 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2096 quota_error u $TSTUSR "write success, but expect EDQUOT"
2100 run_test 7c "Quota reintegration (restart mds during reintegration)"
2102 # Quota reintegration (Transfer index in multiple bulks)
2104 local TESTFILE=$DIR/$tdir/$tfile
2105 local TESTFILE1="$DIR/$tdir/$tfile"-1
2108 setup_quota_test || error "setup quota failed with $?"
2109 trap cleanup_quota_test EXIT
2111 set_ost_qtype "none" || error "disable ost quota failed"
2112 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2113 error "set quota for $TSTUSR failed"
2114 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2115 error "set quota for $TSTUSR2 failed"
2117 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2118 lustre_fail mds 0x608 0
2120 # enable quota to tirgger reintegration
2121 set_ost_qtype "u" || error "enable ost quota failed"
2122 wait_ost_reint "u" || error "reintegration failed"
2126 # hardlimit should have been fetched by slave during global
2127 # reintegration, write will exceed quota
2128 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2129 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2131 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2132 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2136 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2138 # quota reintegration (inode limits)
2140 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2142 # LU-2435: skip this quota test if underlying zfs version has not
2143 # supported native dnode accounting
2144 [ "$mds1_FSTYPE" == zfs ] && {
2145 local F="feature@userobj_accounting"
2146 local pool=$(zpool_name mds1)
2147 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2149 [[ "$feature" != *" active "* ]] &&
2150 skip "requires zpool with active userobj_accounting"
2153 local ilimit=$((1024 * 2)) # 2k inodes
2154 local TESTFILE=$DIR/${tdir}-1/$tfile
2156 setup_quota_test || error "setup quota failed with $?"
2157 trap cleanup_quota_test EXIT
2159 # make sure the system is clean
2160 local USED=$(getquota -u $TSTUSR global curinodes)
2161 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2163 # make sure no granted quota on mdt1
2164 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2165 resetquota -u $TSTUSR
2166 set_mdt_qtype "none" || error "disable mdt quota failed"
2168 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2169 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2170 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2173 echo "Stop mds${MDSCOUNT}..."
2176 echo "Enable quota & set quota limit for $TSTUSR"
2177 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2178 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2179 error "set quota failed"
2181 echo "Start mds${MDSCOUNT}..."
2182 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2185 wait_mdt_reint $QTYPE || error "reintegration failed"
2187 echo "create remote dir"
2188 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2189 error "create remote dir failed"
2190 chmod 0777 $DIR/${tdir}-1
2192 # hardlimit should have been fetched by slave during global
2193 # reintegration, create will exceed quota
2194 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2195 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2197 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2198 wait_delete_completed
2199 sync_all_data || true
2201 echo "Stop mds${MDSCOUNT}..."
2204 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2205 error "clear quota failed"
2207 echo "Start mds${MDSCOUNT}..."
2208 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2211 wait_mdt_reint $QTYPE || error "reintegration failed"
2213 # hardlimit should be cleared on slave during reintegration
2214 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2215 quota_error u $TSTUSR "create failed, expect success"
2217 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2218 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2222 run_test 7e "Quota reintegration (inode limits)"
2224 # run dbench with quota enabled
2226 local BLK_LIMIT="100g" #100G
2227 local FILE_LIMIT=1000000
2229 setup_quota_test || error "setup quota failed with $?"
2230 trap cleanup_quota_test EXIT
2232 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2233 set_ost_qtype $QTYPE || error "enable ost quota failed"
2235 echo "Set enough high limit for user: $TSTUSR"
2236 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2237 error "set user quota failed"
2238 echo "Set enough high limit for group: $TSTUSR"
2239 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2240 error "set group quota failed"
2241 if is_project_quota_supported; then
2242 change_project -sp $TSTPRJID $DIR/$tdir
2243 echo "Set enough high limit for project: $TSTPRJID"
2244 $LFS setquota -p $TSTPRJID -b 0 \
2245 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2246 error "set project quota failed"
2250 [ "$SLOW" = "no" ] && duration=" -t 120"
2251 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2252 quota_error a $TSTUSR "dbench failed!"
2254 is_project_quota_supported && change_project -C $DIR/$tdir
2257 run_test 8 "Run dbench with quota enabled"
2259 # this check is just for test_9
2260 OST0_MIN=4900000 #4.67G
2262 check_whether_skip () {
2263 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2264 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2265 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2266 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2273 # run for fixing bug10707, it needs a big room. test for 64bit
2275 local filesize=$((1024 * 9 / 2)) # 4.5G
2277 check_whether_skip && return 0
2279 setup_quota_test || error "setup quota failed with $?"
2280 trap cleanup_quota_test EXIT
2282 set_ost_qtype "ug" || error "enable ost quota failed"
2284 local TESTFILE="$DIR/$tdir/$tfile-0"
2285 local BLK_LIMIT=100G #100G
2286 local FILE_LIMIT=1000000
2288 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2290 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2292 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2293 error "set user quota failed"
2295 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2296 "for group: $TSTUSR"
2297 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2298 error "set group quota failed"
2300 quota_show_check a u $TSTUSR
2301 quota_show_check a g $TSTUSR
2303 echo "Create test file"
2304 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2305 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2307 log "Write the big file of 4.5G ..."
2308 $RUNAS $DD of=$TESTFILE count=$filesize ||
2309 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2319 run_test 9 "Block limit larger than 4GB (b10707)"
2322 local TESTFILE=$DIR/$tdir/$tfile
2324 setup_quota_test || error "setup quota failed with $?"
2325 trap cleanup_quota_test EXIT
2327 # set limit to root user should fail
2328 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2329 error "set limit for root user successfully, expect failure"
2330 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2331 error "set limit for root group successfully, expect failure"
2332 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2333 error "set limit for project 0 successfully, expect failure"
2335 # root user can overrun quota
2336 set_ost_qtype "ug" || error "enable ost quota failed"
2338 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2339 error "set quota failed"
2340 quota_show_check b u $TSTUSR
2342 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2343 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2345 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2346 error "write failure, expect success"
2350 run_test 10 "Test quota for root user"
2353 local TESTFILE=$DIR/$tdir/$tfile
2354 setup_quota_test || error "setup quota failed with $?"
2355 trap cleanup_quota_test EXIT
2357 set_mdt_qtype "ug" || error "enable mdt quota failed"
2358 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2359 error "set quota failed"
2361 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2362 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2364 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2365 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2368 local USED=$(getquota -u $TSTUSR global curinodes)
2369 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2373 run_test 11 "Chown/chgrp ignores quota"
2376 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2378 local blimit=22 # 22M
2379 local blk_cnt=$((blimit - 5))
2380 local TESTFILE0="$DIR/$tdir/$tfile"-0
2381 local TESTFILE1="$DIR/$tdir/$tfile"-1
2383 setup_quota_test || error "setup quota failed with $?"
2384 trap cleanup_quota_test EXIT
2386 set_ost_qtype "u" || error "enable ost quota failed"
2387 quota_show_check b u $TSTUSR
2389 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2390 error "set quota failed"
2392 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2393 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2394 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2395 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2397 echo "Write to ost0..."
2398 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2399 quota_error a $TSTUSR "dd failed"
2401 echo "Write to ost1..."
2402 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2403 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2405 echo "Free space from ost0..."
2407 wait_delete_completed
2408 sync_all_data || true
2410 echo "Write to ost1 after space freed from ost0..."
2411 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2412 quota_error a $TSTUSR "rebalancing failed"
2416 run_test 12a "Block quota rebalancing"
2419 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2421 local ilimit=$((1024 * 2)) # 2k inodes
2422 local TESTFILE0=$DIR/$tdir/$tfile
2423 local TESTFILE1=$DIR/${tdir}-1/$tfile
2425 setup_quota_test || error "setup quota failed with $?"
2426 trap cleanup_quota_test EXIT
2428 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2429 chmod 0777 $DIR/${tdir}-1
2431 set_mdt_qtype "u" || error "enable mdt quota failed"
2432 quota_show_check f u $TSTUSR
2434 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2435 error "set quota failed"
2437 echo "Create $ilimit files on mdt0..."
2438 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2439 quota_error u $TSTUSR "create failed, but expect success"
2441 echo "Create files on mdt1..."
2442 $RUNAS createmany -m $TESTFILE1 1 &&
2443 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2445 echo "Free space from mdt0..."
2446 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2447 wait_delete_completed
2448 sync_all_data || true
2450 echo "Create files on mdt1 after space freed from mdt0..."
2451 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2452 quota_error a $TSTUSR "rebalancing failed"
2454 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2455 error "unlink mdt1 files failed"
2456 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2460 run_test 12b "Inode quota rebalancing"
2463 local TESTFILE=$DIR/$tdir/$tfile
2464 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2465 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2467 setup_quota_test || error "setup quota failed with $?"
2468 trap cleanup_quota_test EXIT
2470 set_ost_qtype "u" || error "enable ost quota failed"
2471 quota_show_check b u $TSTUSR
2473 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2474 error "set quota failed"
2475 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2476 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2478 # clear the locks in cache first
2479 do_facet ost1 $LCTL set_param -n $procf=clear
2480 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2481 [ $nlock -eq 0 ] || error "$nlock cached locks"
2483 # write to acquire the per-ID lock
2484 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2485 quota_error a $TSTUSR "dd failed"
2487 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2488 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2490 # clear quota doesn't trigger per-ID lock cancellation
2491 resetquota -u $TSTUSR
2492 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2493 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2495 # clear the per-ID lock
2496 do_facet ost1 $LCTL set_param -n $procf=clear
2497 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2498 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2500 # spare quota should be released
2501 local OSTUUID=$(ostuuid_from_index 0)
2502 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2503 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2504 [ $limit -le $space ] ||
2505 error "spare quota isn't released, limit:$limit, space:$space"
2509 run_test 13 "Cancel per-ID lock in the LRU list"
2512 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2514 wait_delete_completed
2515 sync_all_data || true
2518 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2519 error "set user quota failed"
2520 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2521 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2522 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2523 resetquota -u $TSTUSR
2526 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2527 error "set group quota failed"
2528 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2529 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2530 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2531 resetquota -g $TSTUSR
2533 run_test 15 "Set over 4T block quota"
2537 local BLKS=1 # 1M less than limit
2538 local TESTFILE=$DIR/$tdir/$tfile
2540 setup_quota_test || error "setup quota failed with $?"
2541 trap cleanup_quota_test EXIT
2543 # make sure the system is clean
2544 local USED=$(getquota -u $TSTUSR global curspace)
2545 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2547 set_ost_qtype "ug" || error "enable ost quota failed"
2548 # make sure no granted quota on ost
2549 resetquota -u $TSTUSR
2550 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2551 error "set quota failed"
2553 quota_show_check b u $TSTUSR
2555 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2556 lustre_fail mds 0xa04 $err_code
2558 # write in background
2559 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2563 # write should be blocked and never finished
2564 if ! ps -p $DDPID > /dev/null 2>&1; then
2566 quota_error u $TSTUSR "write finished incorrectly!"
2574 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2576 if [ $count -gt $timeout ]; then
2577 quota_error u $TSTUSR "dd is not finished!"
2582 sync; sync_all_data || true
2584 USED=$(getquota -u $TSTUSR global curspace)
2585 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2586 "Used space(${USED}K) is less than ${BLKS}M"
2591 # DQACQ return recoverable error
2593 echo "DQACQ return -ENOLCK"
2595 test_17sub 37 || error "Handle -ENOLCK failed"
2597 echo "DQACQ return -EAGAIN"
2599 test_17sub 11 || error "Handle -EAGAIN failed"
2601 echo "DQACQ return -ETIMEDOUT"
2602 #define ETIMEDOUT 110
2603 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2605 echo "DQACQ return -ENOTCONN"
2606 #define ENOTCONN 107
2607 test_17sub 107 || error "Handle -ENOTCONN failed"
2610 run_test 17 "DQACQ return recoverable error"
2614 local blimit="200m" # 200M
2615 local TESTFILE="$DIR/$tdir/$tfile"
2617 setup_quota_test || error "setup quota failed with $?"
2618 trap cleanup_quota_test EXIT
2620 set_ost_qtype "u" || error "enable ost quota failed"
2621 log "User quota (limit: $blimit)"
2622 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2623 error "set quota failed"
2624 quota_show_check b u $TSTUSR
2626 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2627 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2629 local timeout=$(sysctl -n lustre.timeout)
2631 if [ $io_type = "directio" ]; then
2632 log "Write 100M (directio) ..."
2633 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2635 log "Write 100M (buffered) ..."
2636 $RUNAS $DD of=$TESTFILE count=100 &
2640 replay_barrier $SINGLEMDS
2641 log "Fail mds for $((2 * timeout)) seconds"
2642 fail $SINGLEMDS $((2 * timeout))
2645 if at_is_enabled; then
2646 timeout=$(at_max_get mds)
2648 timeout=$(lctl get_param -n timeout)
2652 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2653 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2654 log "it took $count second"
2659 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2661 cancel_lru_locks mdc
2662 cancel_lru_locks osc
2665 local testfile_size=$(stat -c %s $TESTFILE)
2666 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2667 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2668 "got ${testfile_size}. Verifying file failed!"
2673 # test when mds does failover, the ost still could work well
2674 # this test shouldn't trigger watchdog b=14840
2676 # Clear dmesg so watchdog is not triggered by previous
2678 do_facet ost1 dmesg -c > /dev/null
2681 test_18_sub directio
2683 # check if watchdog is triggered
2684 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2685 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2686 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2687 [ -z "$watchdog" ] || error "$watchdog"
2688 rm -f $TMP/lustre-log-${TESTNAME}.log
2690 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2694 local TESTFILE=$DIR/$tdir/$tfile
2696 setup_quota_test || error "setup quota failed with $?"
2697 trap cleanup_quota_test EXIT
2699 set_ost_qtype $QTYPE || error "enable ost quota failed"
2701 # bind file to a single OST
2702 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2703 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2705 echo "Set user quota (limit: ${blimit}M)"
2706 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2707 error "set user quota failed"
2708 quota_show_check b u $TSTUSR
2709 echo "Update quota limits"
2710 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2711 error "set group quota failed"
2712 quota_show_check b u $TSTUSR
2714 # first wirte might be cached
2715 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2716 cancel_lru_locks osc
2718 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2719 quota_error u $TSTUSR "Write success, expect failure"
2724 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2726 test_20() { # b15754
2727 local LSTR=(2g 1t 4k 3m) # limits strings
2729 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2732 resetquota -u $TSTUSR
2734 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2735 $MOUNT || error "could not set quota limits"
2736 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2737 --inode-softlimit ${LSTR[2]} \
2738 --inode-hardlimit ${LSTR[3]} \
2739 $MOUNT || error "could not set quota limits"
2741 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2742 error "bsoftlimit was not set properly"
2743 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2744 error "bhardlimit was not set properly"
2745 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2746 error "isoftlimit was not set properly"
2747 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2748 error "ihardlimit was not set properly"
2750 resetquota -u $TSTUSR
2752 run_test 20 "Test if setquota specifiers work properly (b15754)"
2759 local time=$(($(date +%s) + seconds))
2760 while [ $(date +%s) -lt $time ]; do
2761 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2765 # run for fixing bug16053, setquota shouldn't fail when writing and
2766 # deleting are happening
2768 local TESTFILE="$DIR/$tdir/$tfile"
2769 local BLIMIT=10 # 10G
2770 local ILIMIT=1000000
2772 setup_quota_test || error "setup quota failed with $?"
2773 trap cleanup_quota_test EXIT
2775 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2777 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2778 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2779 error "set user quota failed"
2780 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2781 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2782 error "set group quota failed"
2783 if is_project_quota_supported; then
2784 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2785 "project: $TSTPRJID"
2786 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2787 $MOUNT || error "set project quota failed"
2790 # repeat writing on a 1M file
2791 test_21_sub ${TESTFILE}_1 1 30 &
2793 # repeat writing on a 128M file
2794 test_21_sub ${TESTFILE}_2 128 30 &
2797 local time=$(($(date +%s) + 30))
2799 while [ $(date +%s) -lt $time ]; do
2800 log "Set quota for $i times"
2801 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2802 -I $((ILIMIT + i)) $MOUNT ||
2803 error "Set user quota failed"
2804 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2805 -I $((ILIMIT + i)) $MOUNT ||
2806 error "Set group quota failed"
2807 if is_project_quota_supported; then
2808 $LFS setquota -p $TSTPRJID -b 0 -B \
2809 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2810 error "Set project quota failed"
2818 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2820 if [ $count -gt 60 ]; then
2821 quota_error a $TSTUSR "dd should be finished!"
2825 echo "(dd_pid=$DDPID1, time=$count)successful"
2829 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2831 if [ $count -gt 60 ]; then
2832 quota_error a $TSTUSR "dd should be finished!"
2836 echo "(dd_pid=$DDPID2, time=$count)successful"
2840 run_test 21 "Setquota while writing & deleting (b16053)"
2842 # enable/disable quota enforcement permanently
2844 echo "Set both mdt & ost quota type as ug"
2846 is_project_quota_supported && qtype=$QTYPE
2847 set_mdt_qtype $qtype || error "enable mdt quota failed"
2848 set_ost_qtype $qtype || error "enable ost quota failed"
2851 stopall || error "failed to stopall (1)"
2855 echo "Verify if quota is enabled"
2856 local qtype1=$(mdt_quota_type)
2857 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2858 qtype=$(ost_quota_type)
2859 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2861 echo "Set both mdt & ost quota type as none"
2862 set_mdt_qtype "none" || error "disable mdt quota failed"
2863 set_ost_qtype "none" || error "disable ost quota failed"
2866 stopall || error "failed to stopall (2)"
2871 echo "Verify if quota is disabled"
2872 qtype=$(mdt_quota_type)
2873 [ $qtype != "none" ] && error "mdt quota setting is lost"
2874 qtype=$(ost_quota_type)
2875 [ $qtype != "none" ] && error "ost quota setting is lost"
2879 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2882 local TESTFILE="$DIR/$tdir/$tfile"
2885 setup_quota_test || error "setup quota failed with $?"
2886 trap cleanup_quota_test EXIT
2888 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2891 log "User quota (limit: $LIMIT MB)"
2892 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2893 error "set quota failed"
2894 quota_show_check b u $TSTUSR
2896 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2897 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2899 log "Step1: trigger EDQUOT with O_DIRECT"
2900 log "Write half of file"
2901 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2902 quota_error u $TSTUSR "(1) Write failure, expect success." \
2904 log "Write out of block quota ..."
2905 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2906 oflag=direct conv=notrunc &&
2907 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2911 log "Step2: rewrite should succeed"
2912 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2913 quota_error u $TSTUSR "(3) Write failure, expect success." \
2919 local OST0_UUID=$(ostuuid_from_index 0)
2920 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2921 [ $OST0_QUOTA_USED -ne 0 ] &&
2922 ($SHOW_QUOTA_USER; \
2923 quota_error u $TSTUSR "quota isn't released")
2928 [ "$ost1_FSTYPE" == zfs ] &&
2929 skip "Overwrite in place is not guaranteed to be " \
2930 "space neutral on ZFS"
2932 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2933 check_whether_skip && return 0
2934 log "run for 4MB test file"
2937 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2938 check_whether_skip && return 0
2939 log "run for 40MB test file"
2942 run_test 23 "Quota should be honored with directIO (b16125)"
2946 local TESTFILE="$DIR/$tdir/$tfile"
2948 setup_quota_test || error "setup quota failed with $?"
2949 trap cleanup_quota_test EXIT
2951 set_ost_qtype $QTYPE || error "enable ost quota failed"
2953 # bind file to a single OST
2954 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2955 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2957 echo "Set user quota (limit: ${blimit}M)"
2958 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2959 error "set quota failed"
2961 # overrun quota by root user
2962 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2963 error "write failure, expect success"
2964 cancel_lru_locks osc
2965 sync_all_data || true
2967 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2971 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2973 test_27a() { # b19612
2974 $LFS quota $TSTUSR $DIR &&
2975 error "lfs succeeded with no type, but should have failed"
2976 $LFS setquota $TSTUSR $DIR &&
2977 error "lfs succeeded with no type, but should have failed"
2980 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2982 test_27b() { # b20200
2983 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2984 error "lfs setquota failed with uid argument"
2985 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2986 error "lfs stequota failed with gid argument"
2987 if is_project_quota_supported; then
2988 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2989 1000 $DIR || error \
2990 "lfs stequota failed with projid argument"
2992 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2993 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2994 if is_project_quota_supported; then
2995 $SHOW_QUOTA_PROJID ||
2996 error "lfs quota failed with projid argument"
2998 resetquota -u $TSTID
2999 resetquota -g $TSTID
3000 resetquota -p $TSTPRJID
3003 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3008 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3009 error "lfs setquota failed"
3011 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3012 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3013 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3014 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3016 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3017 error "lfs setquota for $TSTID failed"
3019 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3020 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3021 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3022 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3024 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3025 error "total allocated inode/block limit not printed"
3027 resetquota -u $TSTUSR
3029 run_test 27c "lfs quota should support human-readable output"
3036 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3037 error "set fraction block limit failed"
3038 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3039 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3040 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3041 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3043 resetquota -u $TSTUSR
3045 run_test 27d "lfs setquota should support fraction block limit"
3049 local TESTFILE="$DIR/$tdir/$tfile"
3052 setup_quota_test || error "setup quota failed with $?"
3053 trap cleanup_quota_test EXIT
3055 set_ost_qtype "u" || error "enable ost quota failed"
3057 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3058 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3060 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3061 $MAX_IQ_TIME $DIR || error "set grace time failed"
3062 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3063 error "set quota failed"
3064 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3065 cancel_lru_locks osc
3067 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3068 # over-quota flag has not yet settled since we do not trigger async
3069 # events based on grace time period expiration
3071 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3072 cancel_lru_locks osc
3073 # now over-quota flag should be settled and further writes should fail
3075 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3076 error "grace times were reset"
3079 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3080 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3082 run_test 30 "Hard limit updates should not reset grace times"
3084 # basic usage tracking for user & group
3086 local INODES=10 # 10 files
3087 local BLK_CNT=2 # of 2M each
3088 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3090 setup_quota_test || error "setup quota failed with $?"
3091 trap cleanup_quota_test EXIT
3093 # make sure the system is clean
3094 local USED=$(getquota -u $TSTID global curspace)
3096 error "Used space ($USED) for user $TSTID isn't 0."
3097 USED=$(getquota -g $TSTID global curspace)
3099 error "Used space ($USED) for group $TSTID isn't 0."
3100 if is_project_quota_supported; then
3101 USED=$(getquota -p $TSTPRJID global curspace)
3102 [ $USED -ne 0 ] && error \
3103 "Used space ($USED) for project $TSTPRJID isn't 0."
3106 echo "Write files..."
3107 for i in $(seq 0 $INODES); do
3108 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3109 error "write failed"
3110 is_project_quota_supported &&
3111 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3112 echo "Iteration $i/$INODES completed"
3114 cancel_lru_locks osc
3116 echo "Wait for setattr on objects finished..."
3117 wait_delete_completed
3119 sync; sync_all_data || true
3121 echo "Verify disk usage after write"
3122 USED=$(getquota -u $TSTID global curspace)
3123 [ $USED -lt $TOTAL_BLKS ] &&
3124 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3125 USED=$(getquota -g $TSTID global curspace)
3126 [ $USED -lt $TOTAL_BLKS ] &&
3127 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3128 if is_project_quota_supported; then
3129 USED=$(getquota -p $TSTPRJID global curspace)
3130 [ $USED -lt $TOTAL_BLKS ] && error \
3131 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3134 echo "Verify inode usage after write"
3135 USED=$(getquota -u $TSTID global curinodes)
3136 [ $USED -lt $INODES ] &&
3137 error "Used inode for user $TSTID is $USED, expected $INODES"
3138 USED=$(getquota -g $TSTID global curinodes)
3139 [ $USED -lt $INODES ] &&
3140 error "Used inode for group $TSTID is $USED, expected $INODES"
3141 if is_project_quota_supported; then
3142 USED=$(getquota -p $TSTPRJID global curinodes)
3143 [ $USED -lt $INODES ] && error \
3144 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3149 echo "Verify disk usage after delete"
3150 USED=$(getquota -u $TSTID global curspace)
3151 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3152 USED=$(getquota -u $TSTID global curinodes)
3153 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3154 USED=$(getquota -g $TSTID global curspace)
3155 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3156 USED=$(getquota -g $TSTID global curinodes)
3157 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3158 if is_project_quota_supported; then
3159 USED=$(getquota -p $TSTPRJID global curspace)
3161 error "Used space for project $TSTPRJID isn't 0. $USED"
3162 USED=$(getquota -p $TSTPRJID global curinodes)
3164 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3167 run_test 33 "Basic usage tracking for user & group & project"
3169 # usage transfer test for user & group & project
3171 local BLK_CNT=2 # 2MB
3172 local project_supported="no"
3174 is_project_quota_supported && project_supported="yes"
3175 setup_quota_test || error "setup quota failed with $?"
3176 trap cleanup_quota_test EXIT
3178 # make sure the system is clean
3179 local USED=$(getquota -u $TSTID global curspace)
3180 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3181 USED=$(getquota -g $TSTID global curspace)
3182 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3184 local USED=$(getquota -u $TSTID2 global curspace)
3185 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3186 if [ $project_supported == "yes" ]; then
3187 USED=$(getquota -p $TSTPRJID global curspace)
3188 [ $USED -ne 0 ] && error \
3189 "Used space ($USED) for Project $TSTPRJID isn't 0."
3192 echo "Write file..."
3193 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3194 error "write failed"
3195 cancel_lru_locks osc
3196 sync; sync_all_data || true
3198 echo "chown the file to user $TSTID"
3199 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3201 echo "Wait for setattr on objects finished..."
3202 wait_delete_completed
3204 BLK_CNT=$((BLK_CNT * 1024))
3206 echo "Verify disk usage for user $TSTID"
3207 USED=$(getquota -u $TSTID global curspace)
3208 [ $USED -lt $BLK_CNT ] &&
3209 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3210 USED=$(getquota -u $TSTID global curinodes)
3212 error "Used inodes for user $TSTID is $USED, expected 1"
3214 echo "chgrp the file to group $TSTID"
3215 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3217 echo "Wait for setattr on objects finished..."
3218 wait_delete_completed
3220 echo "Verify disk usage for group $TSTID"
3221 USED=$(getquota -g $TSTID global curspace)
3222 [ $USED -ge $BLK_CNT ] ||
3223 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3224 USED=$(getquota -g $TSTID global curinodes)
3226 error "Used inodes for group $TSTID is $USED, expected 1"
3228 # chown won't change the ost object group. LU-4345 */
3229 echo "chown the file to user $TSTID2"
3230 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3232 echo "Wait for setattr on objects finished..."
3233 wait_delete_completed
3235 echo "change_project project id to $TSTPRJID"
3236 [ $project_supported == "yes" ] &&
3237 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3238 echo "Wait for setattr on objects finished..."
3239 wait_delete_completed
3241 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3242 USED=$(getquota -u $TSTID2 global curspace)
3243 [ $USED -lt $BLK_CNT ] &&
3244 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3245 USED=$(getquota -u $TSTID global curspace)
3247 error "Used space for user $TSTID is $USED, expected 0"
3248 USED=$(getquota -g $TSTID global curspace)
3249 [ $USED -lt $BLK_CNT ] &&
3250 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3251 if [ $project_supported == "yes" ]; then
3252 USED=$(getquota -p $TSTPRJID global curspace)
3253 [ $USED -lt $BLK_CNT ] && error \
3254 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3259 run_test 34 "Usage transfer for user & group & project"
3261 # usage is still accessible across restart
3263 local BLK_CNT=2 # 2 MB
3265 setup_quota_test || error "setup quota failed with $?"
3266 trap cleanup_quota_test EXIT
3268 echo "Write file..."
3269 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3270 error "write failed"
3271 is_project_quota_supported &&
3272 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3273 cancel_lru_locks osc
3275 echo "Wait for setattr on objects finished..."
3276 wait_delete_completed
3278 sync; sync_all_data || true
3280 echo "Save disk usage before restart"
3281 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3282 [ $ORIG_USR_SPACE -eq 0 ] &&
3283 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3284 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3285 [ $ORIG_USR_INODES -eq 0 ] &&
3286 error "Used inodes for user $TSTID is 0, expected 1"
3287 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3288 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3289 [ $ORIG_GRP_SPACE -eq 0 ] &&
3290 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3291 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3292 [ $ORIG_GRP_INODES -eq 0 ] &&
3293 error "Used inodes for group $TSTID is 0, expected 1"
3294 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3296 if is_project_quota_supported; then
3297 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3298 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3299 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3300 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3301 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3302 "Used inodes for project $TSTPRJID is 0, expected 1"
3303 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3311 echo "Verify disk usage after restart"
3312 local USED=$(getquota -u $TSTID global curspace)
3313 [ $USED -eq $ORIG_USR_SPACE ] ||
3314 error "Used space for user $TSTID changed from " \
3315 "$ORIG_USR_SPACE to $USED"
3316 USED=$(getquota -u $TSTID global curinodes)
3317 [ $USED -eq $ORIG_USR_INODES ] ||
3318 error "Used inodes for user $TSTID changed from " \
3319 "$ORIG_USR_INODES to $USED"
3320 USED=$(getquota -g $TSTID global curspace)
3321 [ $USED -eq $ORIG_GRP_SPACE ] ||
3322 error "Used space for group $TSTID changed from " \
3323 "$ORIG_GRP_SPACE to $USED"
3324 USED=$(getquota -g $TSTID global curinodes)
3325 [ $USED -eq $ORIG_GRP_INODES ] ||
3326 error "Used inodes for group $TSTID changed from " \
3327 "$ORIG_GRP_INODES to $USED"
3328 if [ $project_supported == "yes" ]; then
3329 USED=$(getquota -p $TSTPRJID global curinodes)
3330 [ $USED -eq $ORIG_PRJ_INODES ] ||
3331 error "Used inodes for project $TSTPRJID " \
3332 "changed from $ORIG_PRJ_INODES to $USED"
3333 USED=$(getquota -p $TSTPRJID global curspace)
3334 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3335 error "Used space for project $TSTPRJID "\
3336 "changed from $ORIG_PRJ_SPACE to $USED"
3339 # check if the vfs_dq_init() is called before writing
3340 echo "Append to the same file..."
3341 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3342 error "write failed"
3343 cancel_lru_locks osc
3344 sync; sync_all_data || true
3346 echo "Verify space usage is increased"
3347 USED=$(getquota -u $TSTID global curspace)
3348 [ $USED -gt $ORIG_USR_SPACE ] ||
3349 error "Used space for user $TSTID isn't increased" \
3350 "orig:$ORIG_USR_SPACE, now:$USED"
3351 USED=$(getquota -g $TSTID global curspace)
3352 [ $USED -gt $ORIG_GRP_SPACE ] ||
3353 error "Used space for group $TSTID isn't increased" \
3354 "orig:$ORIG_GRP_SPACE, now:$USED"
3355 if [ $project_supported == "yes" ]; then
3356 USED=$(getquota -p $TSTPRJID global curspace)
3357 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3358 error "Used space for project $TSTPRJID isn't " \
3359 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3364 run_test 35 "Usage is still accessible across reboot"
3366 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3369 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3370 skip "Old server doesn't have LU-5006 fix."
3372 setup_quota_test || error "setup quota failed with $?"
3373 trap cleanup_quota_test EXIT
3375 # make sure the system is clean
3376 local USED=$(getquota -u $TSTID global curspace)
3378 error "Used space ($USED) for user $TSTID isn't 0."
3380 # create file with MDS_OPEN_DELAY_CREATE flag
3381 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3382 error "Create file failed"
3384 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3385 oflag=sync || error "Write file failed"
3387 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3389 # wait for setattr on objects finished..."
3390 wait_delete_completed
3392 USED=$(getquota -u $TSTID global curspace)
3393 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3397 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3401 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3402 skip "Old server doesn't have LU-8801 fix."
3404 [ "$UID" != 0 ] && skip_env "must run as root" && return
3406 setup_quota_test || error "setup quota failed with $?"
3407 trap cleanup_quota_test EXIT
3409 # make sure the system is clean
3410 local USED=$(getquota -u $TSTID global curspace)
3412 error "Used space ($USED) for user $TSTID isn't 0."
3413 USED=$(getquota -u $TSTID2 global curspace)
3415 error "Used space ($USED) for user $TSTID2 isn't 0."
3417 local TESTFILE="$DIR/$tdir/$tfile"
3418 local file_cnt=10000
3420 # Generate id entries in accounting file
3421 echo "Create $file_cnt files..."
3422 for i in `seq $file_cnt`; do
3424 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3425 error "failed to chown $TESTFILE-$i"
3427 cancel_lru_locks osc
3428 sync; sync_all_data || true
3430 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3431 procf=${procf}.quota_slave.acct_user
3434 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3435 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3436 echo "Found $acct_cnt id entries"
3438 [ $file_cnt -eq $acct_cnt ] || {
3439 do_facet mds1 $LCTL get_param $procf
3440 error "skipped id entries"
3445 run_test 38 "Quota accounting iterator doesn't skip id entries"
3448 local TESTFILE="$DIR/$tdir/project"
3449 ! is_project_quota_supported &&
3450 skip "Project quota is not supported"
3452 setup_quota_test || error "setup quota failed with $?"
3455 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3456 [ $projectid -ne 0 ] &&
3457 error "Project id should be 0 not $projectid"
3458 change_project -p 1024 $TESTFILE
3459 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3460 [ $projectid -ne 1024 ] &&
3461 error "Project id should be 1024 not $projectid"
3463 stopall || error "failed to stopall (1)"
3466 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3467 [ $projectid -ne 1024 ] &&
3468 error "Project id should be 1024 not $projectid"
3472 run_test 39 "Project ID interface works correctly"
3475 ! is_project_quota_supported &&
3476 skip "Project quota is not supported"
3477 local dir1="$DIR/$tdir/dir1"
3478 local dir2="$DIR/$tdir/dir2"
3480 setup_quota_test || error "setup quota failed with $?"
3482 mkdir -p $dir1 $dir2
3483 change_project -sp 1 $dir1 && touch $dir1/1
3484 change_project -sp 2 $dir2
3486 ln $dir1/1 $dir2/1_link &&
3487 error "Hard link across different project quota should fail"
3492 run_test 40a "Hard link across different project ID"
3495 ! is_project_quota_supported &&
3496 skip "Project quota is not supported"
3497 local dir1="$DIR/$tdir/dir1"
3498 local dir2="$DIR/$tdir/dir2"
3500 setup_quota_test || error "setup quota failed with $?"
3501 mkdir -p $dir1 $dir2
3502 change_project -sp 1 $dir1 && touch $dir1/1
3503 change_project -sp 2 $dir2
3505 mv $dir1/1 $dir2/2 || error "mv failed $?"
3506 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3507 if [ "$projid" != "2" ]; then
3508 error "project id expected 2 not $projid"
3513 run_test 40b "Mv across different project ID"
3516 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3517 ! is_project_quota_supported &&
3518 skip "Project quota is not supported"
3520 setup_quota_test || error "setup quota failed with $?"
3521 local dir="$DIR/$tdir/dir"
3523 mkdir -p $dir && change_project -sp 1 $dir
3524 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3525 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3526 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3527 touch $dir/remote_dir/file
3528 #verify inherit works file for remote dir.
3529 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3530 [ "$projid" != "1" ] &&
3531 error "file under remote dir expected 1 not $projid"
3533 #Agent inode should be ignored for project quota
3534 USED=$(getquota -p 1 global curinodes)
3535 [ "$USED" != "3" ] &&
3536 error "file count expected 3 got $USED"
3542 run_test 40c "Remote child Dir inherit project quota properly"
3545 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3546 is_project_quota_supported || skip "Project quota is not supported"
3548 setup_quota_test || error "setup quota failed with $?"
3549 local dir="$DIR/$tdir/dir"
3552 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3553 change_project -sp $TSTPRJID $dir ||
3554 error "change project on $dir failed"
3555 for i in $(seq 5); do
3556 mkdir -p $dir/d$i/d$i ||
3557 error "mkdir $dir/d$i/d$i failed"
3558 local projid=$($LFS project -d $dir/d$i/d$i |
3560 [ "$projid" == "$TSTPRJID" ] ||
3561 error "projid id expected $TSTPRJID not $projid"
3562 touch $dir/d$i/d$i/file
3563 #verify inherit works file for stripe dir.
3564 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3565 [ "$projid" == "$TSTPRJID" ] ||
3566 error "file under remote dir expected 1 not $projid"
3569 # account should be 1 + (2 + 1) *10 + 1 * 5
3570 USED=$(getquota -p $TSTPRJID global curinodes)
3571 [ "$USED" == "36" ] ||
3572 error "file count expected 36 got $USED"
3577 run_test 40d "Stripe Directory inherit project quota properly"
3580 is_project_quota_supported ||
3581 skip "Project quota is not supported"
3582 setup_quota_test || error "setup quota failed with $?"
3583 trap cleanup_quota_test EXIT
3584 local dir="$DIR/$tdir/dir"
3587 local projid=$((testnum * 1000))
3591 # enable mdt/ost quota
3592 set_mdt_qtype ugp || error "enable mdt quota failed"
3593 set_ost_qtype ugp || error "enable ost quota failed"
3595 test_mkdir -p $dir && change_project -sp $projid $dir
3596 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3597 error "set project quota failed"
3602 # check if df output works as expected
3603 echo "== global statfs: $MOUNT =="
3604 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3606 echo "== project statfs (prjid=$projid): $dir =="
3607 df -kP $dir; df -iP $dir
3608 local bused=$(getquota -p $projid global curspace)
3609 local iused=$(getquota -p $projid global curinodes)
3610 # note trailing space to match double printf from awk
3611 local expected="$blimit $bused $ilimit $iused "
3613 wait_update $HOSTNAME \
3614 "{ df -kP $dir; df -iP $dir; } |
3615 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3617 error "failed to get correct statfs for project quota"
3621 run_test 41 "df should return projid-specific values"
3624 ! is_project_quota_supported &&
3625 skip "Project quota is not supported"
3627 setup_quota_test || error "setup quota failed with $?"
3628 local dir1="$DIR/$tdir/dir1"
3629 local dir2="$DIR/$tdir/dir2"
3631 mkdir -p $dir1 && change_project -sp 1 $dir1
3632 mkdir -p $dir2 && change_project -sp 2 $dir2
3633 for num in $(seq 1 10); do
3634 touch $dir1/file_$num $dir2/file_$num
3635 ln -s $dir1/file_$num $dir1/file_$num"_link"
3636 ln -s $dir2/file_$num $dir2/file_$num"_link"
3639 count=$($LFS find --projid 1 $DIR | wc -l)
3640 [ "$count" != 21 ] && error "expected 21 but got $count"
3642 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3643 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3644 [ "$count" != 22 ] && error "expected 22 but got $count"
3649 run_test 50 "Test if lfs find --projid works"
3652 ! is_project_quota_supported &&
3653 skip "Project quota is not supported"
3654 setup_quota_test || error "setup quota failed with $?"
3655 local dir="$DIR/$tdir/dir"
3657 mkdir $dir && change_project -sp 1 $dir
3658 local used=$(getquota -p 1 global curinodes)
3659 [ $used != "1" ] && error "expected 1 got $used"
3664 used=$(getquota -p 1 global curinodes)
3665 [ $used != "4" ] && error "expected 4 got $used"
3667 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3669 cp $DIR/$tdir/6 $dir/6
3670 used=$(getquota -p 1 global curinodes)
3671 [ $used != "5" ] && error "expected 5 got $used"
3674 mv $DIR/$tdir/6 $dir/7
3675 used=$(getquota -p 1 global curinodes)
3676 [ $used != "6" ] && error "expected 6 got $used"
3681 run_test 51 "Test project accounting with mv/cp"
3684 ! is_project_quota_supported &&
3685 skip "Project quota is not supported"
3686 setup_quota_test || error "setup quota failed with $?"
3687 local dir="$DIR/$tdir/dir"
3688 mkdir $dir && change_project -sp 1 $dir
3690 touch $DIR/$tdir/file
3691 #Try renaming a file into the project. This should fail.
3692 for num in $(seq 1 2000); do
3693 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3694 error "rename should fail"
3699 run_test 52 "Rename across different project ID"
3702 ! is_project_quota_supported &&
3703 skip "Project quota is not supported"
3704 setup_quota_test || error "setup quota failed with $?"
3705 local dir="$DIR/$tdir/dir"
3706 mkdir $dir && change_project -s $dir
3707 lfs project -d $dir | grep P || error "inherit attribute should be set"
3709 change_project -C $dir
3710 lfs project -d $dir | grep P &&
3711 error "inherit attribute should be cleared"
3716 run_test 53 "Project inherit attribute could be cleared"
3719 ! is_project_quota_supported &&
3720 skip "Project quota is not supported"
3721 setup_quota_test || error "setup quota failed with $?"
3722 trap cleanup_quota_test EXIT
3723 local testfile="$DIR/$tdir/$tfile-0"
3725 #set project ID/inherit attribute
3726 change_project -sp $TSTPRJID $DIR/$tdir
3727 $RUNAS createmany -m ${testfile} 100 ||
3728 error "create many files failed"
3730 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3731 # one more count for directory itself */
3735 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3736 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3738 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3739 [ $proj_count1 -eq $proj_count ] ||
3740 error "c2: expected $proj_count got $proj_count1"
3742 #clear project but with kept projid
3743 change_project -rCk $DIR/$tdir
3744 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3745 [ $proj_count1 -eq 1 ] ||
3746 error "c3: expected 1 got $proj_count1"
3748 #verify projid untouched.
3749 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3751 [ $proj_count1 -eq $proj_count ] ||
3752 error "c4: expected $proj_count got $proj_count1"
3755 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3756 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3757 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3759 #this time clear all
3760 change_project -rC $DIR/$tdir
3761 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3762 [ $proj_count1 -eq 0 ] ||
3763 error "c6: expected 0 got $proj_count1"
3765 unlinkmany ${testfile} 100 ||
3766 error "unlink many files failed"
3770 run_test 54 "basic lfs project interface test"
3773 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3774 skip "Not supported before 2.10.58."
3775 setup_quota_test || error "setup quota failed with $?"
3777 set_ost_qtype $QTYPE || error "enable ost quota failed"
3780 #add second group to TSTUSR
3781 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3784 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3785 error "failed to dd"
3787 cancel_lru_locks osc
3788 sync; sync_all_data || true
3790 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3791 error "failed to setquota on group $TSTUSR2"
3793 $LFS quota -v -g $TSTUSR2 $DIR
3795 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3796 error "chgrp should failed with -EDQUOT"
3798 USED=$(getquota -g $TSTUSR2 global curspace)
3801 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3802 error "failed to setquota on group $TSTUSR2"
3804 $LFS quota -v -g $TSTUSR2 $DIR
3806 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3807 error "chgrp should succeed"
3809 $LFS quota -v -g $TSTUSR2 $DIR
3813 run_test 55 "Chgrp should be affected by group quota"
3816 setup_quota_test || error "setup quota failed with $?"
3818 set_ost_qtype $QTYPE || error "enable ost quota failed"
3821 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3822 erro "failed to set grace time for usr quota"
3823 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3824 awk '{print $4 $8}')
3825 if [ "x$grace_time" != "x10s;10s" ]; then
3826 $LFS quota -t -u $DIR
3827 error "expected grace time: 10s;10s, got:$grace_time"
3832 run_test 56 "lfs quota -t should work well"
3835 setup_quota_test || error "setup quota failed with $?"
3837 local dir="$DIR/$tdir/dir"
3840 #try to change pipe file should not hang and return failure
3841 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3842 awk -F ':' '{ print \\\$2 }'" \
3843 " unable to get xattr for fifo '$dir/pipe'" || return 1
3844 #command can process further if it hit some errors
3845 touch $dir/aaa $dir/bbb
3846 mkdir $dir/subdir -p
3847 touch $dir/subdir/aaa $dir/subdir/bbb
3848 #create one invalid link file
3849 ln -s $dir/not_exist_file $dir/ccc
3850 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3851 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3855 run_test 57 "lfs project could tolerate errors"
3858 [ "$mds1_FSTYPE" != ldiskfs ] &&
3859 skip "ldiskfs only test"
3860 disable_project_quota
3861 setup_quota_test || error "setup quota failed with $?"
3864 local testfile="$DIR/$tdir/$tfile-0"
3865 #make sure it did not crash kernel
3866 touch $testfile && lfs project -sp 1 $testfile
3868 enable_project_quota
3871 run_test 59 "lfs project dosen't crash kernel with project disabled"
3874 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3875 skip "Needs MDS version 2.11.53 or later."
3876 setup_quota_test || error "setup quota failed with $?"
3877 trap cleanup_quota_test EXIT
3879 local testfile=$DIR/$tdir/$tfile
3882 set_mdt_qtype "ug" || error "enable mdt quota failed"
3884 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3885 error "set quota failed"
3886 quota_show_check a g $TSTUSR
3888 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3889 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3890 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3891 error "create many files failed"
3893 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3895 # root user can overrun quota
3896 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3897 error "root user should succeed"
3901 run_test 60 "Test quota for root with setgid"
3903 # test default quota
3904 test_default_quota() {
3905 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3906 skip "Not supported before 2.11.51."
3911 local qprjid=$TSTPRJID
3915 local LIMIT=20480 #20M disk space
3916 local TESTFILE="$DIR/$tdir/$tfile-0"
3918 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3919 echo "Project quota is not supported" && return 0
3921 [ $qtype == "-u" ] && qdtype="-U"
3922 [ $qtype == "-g" ] && qdtype="-G"
3923 [ $qtype == "-p" ] && {
3928 [ $qpool == "meta" ] && {
3929 LIMIT=10240 #10K inodes
3934 setup_quota_test || error "setup quota failed with $?"
3935 trap cleanup_quota_test EXIT
3939 # enable mdt/ost quota
3940 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3941 set_ost_qtype $QTYPE || error "enable ost quota failed"
3943 log "set to use default quota"
3944 $LFS setquota $qtype $qid -d $DIR ||
3945 error "set $qid to use default quota failed"
3947 log "set default quota"
3948 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3949 error "set $qid default quota failed"
3951 log "get default quota"
3952 $LFS quota $qdtype $DIR || error "get default quota failed"
3954 if [ $qpool == "data" ]; then
3955 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3957 [ $SLIMIT -eq $LIMIT ] ||
3958 error "the returned default quota is wrong"
3960 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3962 [ $SLIMIT -eq $LIMIT ] ||
3963 error "the returned default quota is wrong"
3966 # make sure the system is clean
3967 local USED=$(getquota $qtype $qid global curspace)
3968 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3970 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3971 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3973 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3975 log "Test not out of quota"
3976 if [ $qpool == "data" ]; then
3977 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3978 quota_error $qtype $qid "write failed, expect succeed"
3980 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3981 quota_error $qtype $qid "create failed, expect succeed"
3983 unlinkmany $TESTFILE $((LIMIT/2))
3986 log "Test out of quota"
3987 # flush cache, ensure noquota flag is set on client
3988 cancel_lru_locks osc
3989 cancel_lru_locks mdc
3990 sync; sync_all_data || true
3991 if [ $qpool == "data" ]; then
3992 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3993 quota_error $qtype $qid "write succeed, expect EDQUOT"
3995 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3996 quota_error $qtype $qid "create succeed, expect EDQUOT"
3998 unlinkmany $TESTFILE $((LIMIT*2))
4001 log "Increase default quota"
4003 # LU-4505: sleep 5 seconds to enable quota acquire
4006 # increase default quota
4007 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
4008 error "set default quota failed"
4010 cancel_lru_locks osc
4011 cancel_lru_locks mdc
4012 sync; sync_all_data || true
4013 if [ $qpool == "data" ]; then
4014 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4015 quota_error $qtype $qid "write failed, expect succeed"
4017 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4018 quota_error $qtype $qid "create failed, expect succeed"
4020 unlinkmany $TESTFILE $((LIMIT*2))
4023 log "Set quota to override default quota"
4024 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4025 error "set $qid quota failed"
4027 cancel_lru_locks osc
4028 cancel_lru_locks mdc
4029 sync; sync_all_data || true
4030 if [ $qpool == "data" ]; then
4031 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4032 quota_error $qtype $qid "write succeed, expect EQUOT"
4034 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4035 quota_error $qtype $qid "create succeed, expect EQUOT"
4037 unlinkmany $TESTFILE $((LIMIT*2))
4040 log "Set to use default quota again"
4042 # LU-4505: sleep 5 seconds to enable quota acquire
4045 $LFS setquota $qtype $qid -d $DIR ||
4046 error "set $qid to use default quota failed"
4048 cancel_lru_locks osc
4049 cancel_lru_locks mdc
4050 sync; sync_all_data || true
4051 if [ $qpool == "data" ]; then
4052 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4053 quota_error $qtype $qid "write failed, expect succeed"
4055 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4056 quota_error $qtype $qid "create failed, expect succeed"
4058 unlinkmany $TESTFILE $((LIMIT*2))
4063 wait_delete_completed || error "wait_delete_completed failed"
4064 sync_all_data || true
4065 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
4066 error "reset default quota failed"
4067 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
4068 error "reset quota failed"
4074 test_default_quota "-u" "data"
4075 test_default_quota "-u" "meta"
4076 test_default_quota "-g" "data"
4077 test_default_quota "-g" "meta"
4078 test_default_quota "-p" "data"
4079 test_default_quota "-p" "meta"
4081 run_test 61 "default quota tests"
4084 ! is_project_quota_supported &&
4085 skip "Project quota is not supported"
4086 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4087 skip "chattr did not support project quota"
4088 setup_quota_test || error "setup quota failed with $?"
4089 local testdir=$DIR/$tdir/
4091 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4092 change_project -s $testdir
4093 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4094 error "inherit attribute should be set"
4095 # chattr used FS_IOC_SETFLAGS ioctl
4096 $RUNAS chattr -P $testdir &&
4097 error "regular user clear inherit should fail"
4098 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4099 error "inherit attribute should still be set"
4100 chattr -P $testdir || error "root failed to clear inherit"
4101 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4102 error "inherit attribute should be cleared"
4105 run_test 62 "Project inherit should be only changed by root"
4108 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4109 skip "Not supported before 2.11.55"
4113 local dd_failed=false
4114 local tdir_dom=${tdir}_dom
4115 local LIMIT=20480 #20M
4117 [ $qtype == "p" ] && ! is_project_quota_supported &&
4118 echo "Project quota is not supported" && return 0
4120 [ $qtype == "p" ] && qid=$TSTPRJID
4122 setup_quota_test || error "setup quota failed with $?"
4123 trap cleanup_quota_test EXIT
4127 # enable mdt/ost quota
4128 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4129 set_ost_qtype $QTYPE || error "enable ost quota failed"
4131 # make sure the system is clean
4132 local USED=$(getquota -$qtype $qid global curspace)
4133 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4135 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4137 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4138 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4139 error "setstripe $tdir_dom failed"
4140 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4142 [ $qtype == "p" ] && {
4143 change_project -sp $TSTPRJID $DIR/$tdir
4144 change_project -sp $TSTPRJID $DIR/$tdir_dom
4147 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4148 error "set $qid quota failed"
4150 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4151 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4155 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4157 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4158 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4162 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4164 rm -f $DIR/$tdir_dom/*
4166 # flush cache, ensure noquota flag is set on client
4167 cancel_lru_locks osc
4168 cancel_lru_locks mdc
4169 sync; sync_all_data || true
4173 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4174 quota_error $qtype $qid "write failed, expect succeed"
4176 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4177 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4181 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4184 rm -f $DIR/$tdir_dom/*
4186 # flush cache, ensure noquota flag is set on client
4187 cancel_lru_locks osc
4188 cancel_lru_locks mdc
4189 sync; sync_all_data || true
4193 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4194 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4198 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4200 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4201 quota_error $qtype $qid "write succeed, expect EDQUOT"
4204 rm -fr $DIR/$tdir_dom
4206 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4207 error "reset usr quota failed"
4217 run_test 63 "quota on DoM tests"
4220 ! is_project_quota_supported &&
4221 skip "Project quota is not supported"
4222 setup_quota_test || error "setup quota failed with $?"
4223 local dir1="$DIR/$tdir/"
4226 ln -s $dir1/file $dir1/file_link
4228 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4229 error "set symlink file's project should fail"
4231 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4232 error "get symlink file's project should fail"
4236 run_test 64 "lfs project on symlink files should fail"
4240 local TESTFILE="$DIR/$tdir/$tfile-0"
4242 setup_quota_test || error "setup quota failed with $?"
4243 set_ost_qtype $QTYPE || error "enable ost quota failed"
4247 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4248 error "failed to write"
4249 # flush cache, ensure noquota flag is set on client
4250 cancel_lru_locks osc
4251 sync; sync_all_data || true
4253 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4254 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4255 local quota_all=$($RUNAS $LFS quota $DIR)
4257 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4258 error "usr quota not match"
4259 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4260 error "grp quota not match"
4266 run_test 65 "Check lfs quota result"
4269 ! is_project_quota_supported &&
4270 skip "Project quota is not supported"
4271 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4272 skip "Not supported before 2.12.4"
4273 setup_quota_test || error "setup quota failed with $?"
4274 stack_trap cleanup_quota_test EXIT
4275 local old=$(do_facet mds1 $LCTL get_param -n \
4276 mdt.*.enable_chprojid_gid | head -1)
4277 local testdir=$DIR/$tdir/foo
4279 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4280 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4283 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4284 chown -R $TSTID:$TSTID $testdir
4285 change_project -sp $TSTPRJID $testdir
4286 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4288 $RUNAS lfs project -p 0 $testdir/foo &&
4289 error "nonroot user should fail to set projid"
4291 $RUNAS lfs project -C $testdir/foo &&
4292 error "nonroot user should fail to clear projid"
4294 change_project -C $testdir/foo || error "failed to clear project"
4296 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4297 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4298 "failed to set projid with normal user when enable_chprojid_gid=-1"
4300 $RUNAS lfs project -rC $testdir/ || error \
4301 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4303 touch $testdir/bar || error "failed touch $testdir/bar"
4304 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4305 "normal user should not be able to set projid on root owned file"
4307 change_project -p $TSTPRJID $testdir/bar || error \
4308 "root should be able to change its own file's projid"
4312 run_test 66 "nonroot user can not change project state in default"
4319 local short_qtype=${qtype:0:1}
4322 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4324 quota_usr) _runas=$RUNAS;;
4325 quota_2usr) _runas=$RUNAS2;;
4326 *) error "unknown quota parameter $4";;
4331 $_runas $DD of=$file count=$size ||
4332 quota_error $short_qtype $TSTUSR \
4333 "$qtype write failure, but expect success"
4335 cancel_lru_locks osc
4337 sync; sync_all_data || true
4346 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4348 do_facet mds1 $LCTL get_param $param |
4349 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4353 local limit=20 # 20M
4354 local testfile="$DIR/$tdir/$tfile-0"
4355 local testfile2="$DIR/$tdir/$tfile-1"
4356 local testfile3="$DIR/$tdir/$tfile-2"
4357 local qpool="qpool1"
4363 [ "$ost1_FSTYPE" == zfs ] &&
4364 skip "ZFS grants some block space together with inode"
4366 setup_quota_test || error "setup quota failed with $?"
4367 trap cleanup_quota_test EXIT
4370 set_ost_qtype $QTYPE || error "enable ost quota failed"
4373 log "User quota (block hardlimit:$limit MB)"
4374 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4375 error "set user quota failed"
4377 # make sure the system is clean
4378 used=$(getquota -u $TSTUSR global curspace)
4379 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4381 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4382 echo "granted 0x0 before write $granted"
4384 # trigger reintegration
4385 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4386 procf=${procf}quota_slave.force_reint
4387 do_facet ost1 $LCTL set_param $procf=1 ||
4388 error "force reintegration failed"
4389 wait_ost_reint "u" || error "reintegration failed"
4390 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4391 [ $granted -ne 0 ] &&
4392 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4394 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4395 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4397 # write 10 MB to testfile
4398 test_67_write "$testfile" "user" 10 "quota_usr"
4400 # create qpool and add OST1
4401 pool_add $qpool || error "pool_add failed"
4402 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4403 # as quota_usr hasn't limits, lqe may absent. But it should be
4404 # created after the 1st direct qmt_get.
4405 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4407 # check granted - should be 0, as testfile is located only on OST0
4408 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4409 echo "global granted $granted"
4410 granted=$(getgranted $qpool "dt" $TSTID "usr")
4411 echo "$qpool granted $granted"
4412 [ $granted -ne 0 ] &&
4413 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4415 # add OST0 to qpool and check granted space
4416 pool_add_targets $qpool 0 1 ||
4417 error "pool_add_targets failed"
4418 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4419 echo "Granted $granted_mb MB"
4420 #should be 10M + qunit for each OST
4421 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4422 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4424 $LFS setstripe $testfile2 -c 1 -i 1 ||
4425 error "setstripe $testfile2 failed"
4426 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4427 # Write from another user and check that qpool1
4428 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4429 test_67_write "$testfile2" "user" 10 "quota_2usr"
4430 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4431 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4432 [ $granted -ne 0 ] &&
4433 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4435 # Granted space for quota_2usr in qpool1 should appear only
4436 # when global lqe for this user becomes enforced.
4437 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4438 error "set user quota failed"
4439 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4440 echo "granted_mb $granted_mb"
4441 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4442 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4444 $LFS setstripe $testfile3 -c 1 -i 0 ||
4445 error "setstripe $testfile3 failed"
4446 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4447 test_67_write "$testfile3" "user" 10 "quota_2usr"
4448 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4449 echo "$testfile3 granted_mb $granted_mb"
4450 [ $granted_mb -eq $limit ] ||
4451 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4453 # remove OST1 from the qpool1 and check granted space
4454 # should be 0 for TSTUSR and 10M for TSTUSR2
4455 pool_remove_target $qpool 0
4456 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4457 [ $granted_mb -eq 0 ] ||
4458 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4459 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4460 [ $granted_mb -eq 10 ] ||
4461 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4464 wait_delete_completed || error "wait_delete_completed failed"
4465 sync_all_data || true
4466 used=$(getquota -u $TSTUSR global curspace)
4467 [ $used -ne 0 ] && quota_error u $TSTUSR \
4468 "user quota isn't released after deletion"
4469 resetquota -u $TSTUSR
4473 run_test 67 "quota pools recalculation"
4480 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4481 awk '/usr/ {getline; print $2}'
4486 local qpool="qpool1"
4489 setup_quota_test || error "setup quota failed with $?"
4490 stack_trap cleanup_quota_test EXIT
4493 set_ost_qtype $QTYPE || error "enable ost quota failed"
4495 # check slave number for glbal pool
4496 local nr=$(get_slave_nr "0x0" "usr")
4497 echo "nr result $nr"
4498 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4499 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4501 # create qpool and add OST1
4502 pool_add $qpool || error "pool_add failed"
4503 nr=$(get_slave_nr $qpool "usr")
4504 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4507 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4508 nr=$(get_slave_nr $qpool "usr")
4509 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4512 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4513 nr=$(get_slave_nr $qpool "usr")
4514 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4517 pool_remove_target $qpool 0
4518 nr=$(get_slave_nr $qpool "usr")
4519 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4522 pool_remove_target $qpool 1
4523 nr=$(get_slave_nr $qpool "usr")
4524 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4526 # Check again that all is fine with global pool
4527 nr=$(get_slave_nr "0x0" "usr")
4528 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4529 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4533 run_test 68 "slave number in quota pool changed after each add/remove OST"
4537 local global_limit=200 # 200M
4538 local limit=10 # 10M
4539 local testfile="$DIR/$tdir/$tfile-0"
4540 local dom0="$DIR/$tdir/dom0"
4541 local qpool="qpool1"
4544 setup_quota_test || error "setup quota failed with $?"
4545 stack_trap cleanup_quota_test EXIT
4548 set_ost_qtype $QTYPE || error "enable ost quota failed"
4549 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4551 # Save DOM only at MDT0
4552 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4553 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4555 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4557 # create qpool and add OST0
4558 pool_add $qpool || error "pool_add failed"
4559 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4561 log "User quota (block hardlimit:$global_limit MB)"
4562 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4563 error "set user quota failed"
4565 log "User quota (block hardlimit:$limit MB)"
4566 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4567 error "set user quota failed"
4569 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4570 quota_error u $TSTUSR "write failed"
4572 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4573 oflag=sync || quota_error u $TSTUSR "write failed"
4575 $RUNAS $DD of=$testfile count=$limit || true
4577 # flush cache, ensure noquota flag is set on client
4578 cancel_lru_locks osc
4579 sync; sync_all_data || true
4581 # MDT0 shouldn't get EDQUOT with glimpse.
4582 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4583 quota_error u $TSTUSR \
4584 "user write success, but expect EDQUOT"
4586 # Now all members of qpool1 should get EDQUOT. Expect success
4587 # when write to DOM on MDT0, as it belongs to global pool.
4588 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4589 oflag=sync || quota_error u $TSTUSR "write failed"
4591 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4592 oflag=sync || quota_error u $TSTUSR "write failed"
4596 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4600 local qpool="qpool1"
4605 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4606 skip "Needs a client >= $VERSION_WITH_QP"
4608 setup_quota_test || error "setup quota failed with $?"
4609 stack_trap cleanup_quota_test EXIT
4611 # MDS returns EFAULT for unsupported quotactl command
4612 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4614 # create qpool and add OST0
4615 pool_add $qpool || error "pool_add failed"
4616 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4618 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4620 [ $rc -eq $err ] || error "setquota res $rc != $err"
4622 # If MDS supports QP, check that limit was set properly.
4623 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4624 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4625 echo "hard limit $bhard limit $limit"
4626 [ $bhard -ne $((limit*1024)) ] &&
4627 error "bhard:$bhard for $qpool!=$((limit*1024))"
4630 $LFS quota -u $TSTUSR --pool $qpool $DIR
4632 [ $rc -eq $err ] || error "quota res $rc != $err"
4636 run_test 70 "check lfs setquota/quota with a pool option"
4640 local limit=10 # 10M
4641 local global_limit=100 # 100M
4642 local testfile="$DIR/$tdir/$tfile-0"
4643 local qpool="qpool1"
4644 local qpool2="qpool2"
4646 [ "$ost1_FSTYPE" == zfs ] &&
4647 skip "ZFS grants some block space together with inode"
4648 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4650 setup_quota_test || error "setup quota failed with $?"
4651 stack_trap cleanup_quota_test EXIT
4654 set_ost_qtype $QTYPE || error "enable ost quota failed"
4657 log "User quota (block hardlimit:$global_limit MB)"
4658 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4659 error "set user quota failed"
4661 pool_add $qpool || error "pool_add failed"
4662 pool_add_targets $qpool 0 1 ||
4663 error "pool_add_targets failed"
4665 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4666 error "set user quota failed"
4668 pool_add $qpool2 || error "pool_add failed"
4669 pool_add_targets $qpool2 1 1 ||
4670 error "pool_add_targets failed"
4672 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4673 error "set user quota failed"
4675 # make sure the system is clean
4676 local used=$(getquota -u $TSTUSR global curspace)
4679 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4681 # create 1st component 1-10M
4682 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4683 #create 2nd component 10-30M
4684 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4685 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4687 # сheck normal use and out of quota with PFL
4688 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4689 test_1_check_write $testfile "user" $((limit*2))
4691 wait_delete_completed || error "wait_delete_completed failed"
4692 sync_all_data || true
4693 used=$(getquota -u $TSTUSR global curspace)
4694 [ $used -ne 0 ] && quota_error u $TSTUSR \
4695 "user quota isn't released after deletion"
4697 # create 1st component 1-10M
4698 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4699 # create 2nd component 10-30M
4700 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4701 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4703 # write to the 2nd component
4704 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4705 quota_error u $TSTUSR \
4706 "write failure, but expect success"
4707 # this time maybe cache write, ignore it's failure
4708 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4709 cancel_lru_locks osc
4710 sync; sync_all_data || true
4711 # write over limit in qpool2(2nd component 10-30M)
4712 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4713 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4714 # write to the 1st component - OST0 is empty
4715 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4716 quota_error u $TSTUSR "write failed"
4720 run_test 71a "Check PFL with quota pools"
4724 local global_limit=1000 # 1G
4725 local limit1=160 # 160M
4726 local limit2=10 # 10M
4727 local testfile="$DIR/$tdir/$tfile-0"
4728 local qpool="qpool1"
4729 local qpool2="qpool2"
4731 [ "$ost1_FSTYPE" == zfs ] &&
4732 skip "ZFS grants some block space together with inode"
4733 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4735 setup_quota_test || error "setup quota failed with $?"
4736 stack_trap cleanup_quota_test EXIT
4739 set_ost_qtype $QTYPE || error "enable ost quota failed"
4742 log "User quota (block hardlimit:$global_limit MB)"
4743 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4744 error "set user quota failed"
4746 pool_add $qpool || error "pool_add failed"
4747 pool_add_targets $qpool 0 1 ||
4748 error "pool_add_targets failed"
4750 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4751 error "set user quota failed"
4753 pool_add $qpool2 || error "pool_add failed"
4754 pool_add_targets $qpool2 1 1 ||
4755 error "pool_add_targets failed"
4757 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4758 error "set user quota failed"
4760 # make sure the system is clean
4761 local used=$(getquota -u $TSTUSR global curspace)
4764 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4766 # First component is on OST0, 2nd on OST1
4767 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4768 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4770 # fill the 1st component on OST0
4771 $RUNAS $DD of=$testfile count=128 ||
4772 quota_error u $TSTUSR "write failed"
4773 # write to the 2nd cmpnt on OST1
4774 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4775 quota_error u $TSTUSR "write failed"
4776 # this time maybe cache write, ignore it's failure
4777 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4779 cancel_lru_locks osc
4780 sync; sync_all_data || true
4781 # write over limit in qpool2
4782 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4783 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4787 run_test 71b "Check SEL with quota pools"
4791 local limit=10 # 10M
4792 local global_limit=50 # 50M
4793 local testfile="$DIR/$tdir/$tfile-0"
4794 local qpool="qpool1"
4797 setup_quota_test || error "setup quota failed with $?"
4798 stack_trap cleanup_quota_test EXIT
4801 set_ost_qtype $QTYPE || error "enable ost quota failed"
4804 log "User quota (block hardlimit:$global_limit MB)"
4805 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4806 error "set user quota failed"
4808 pool_add $qpool || error "pool_add failed"
4809 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4811 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4812 error "set user quota failed"
4814 # make sure the system is clean
4815 local used=$(getquota -u $TSTUSR global curspace)
4817 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4819 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4821 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4822 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4823 test_1_check_write $testfile "user" $limit
4824 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4826 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4827 # check that lfs quota -uv --pool prints only OST that
4828 # was added in a pool
4829 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4830 grep "OST\|MDT" && error "$qpool consists wrong targets"
4834 run_test 72 "lfs quota --pool prints only pool's OSTs"
4838 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4839 if $PQ_CLEANUP; then
4840 disable_project_quota
4843 reset_quota_settings
4848 check_and_cleanup_lustre
4849 export QUOTA_AUTO=$QUOTA_AUTO_OLD