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)"
1256 stack_trap cleanup_quota_test EXIT
1258 $LFS setstripe $testfile -c 1 -i 0
1259 chown $TSTUSR.$TSTUSR $testfile
1260 [ "$qtype" == "p" ] && is_project_quota_supported &&
1261 change_project -p $TSTPRJID $testfile
1263 echo "Write up to soft limit"
1264 $RUNAS $DD of=$testfile count=$limit ||
1265 quota_error a $TSTUSR "write failure, but expect success"
1266 OFFSET=$((limit * 1024))
1267 cancel_lru_locks osc
1269 echo "Write to exceed soft limit"
1270 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1271 quota_error a $TSTUSR "write failure, but expect success"
1272 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1273 cancel_lru_locks osc
1275 echo "mmap write when over soft limit"
1276 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1277 quota_error a $TSTUSR "mmap write failure, but expect success"
1278 cancel_lru_locks osc
1283 $SHOW_QUOTA_INFO_USER
1284 $SHOW_QUOTA_INFO_GROUP
1285 $SHOW_QUOTA_INFO_PROJID
1287 echo "Write before timer goes off"
1288 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1289 quota_error a $TSTUSR "write failure, but expect success"
1290 OFFSET=$((OFFSET + 1024))
1291 cancel_lru_locks osc
1293 wait_grace_time $qtype "block" $pool
1298 $SHOW_QUOTA_INFO_USER
1299 $SHOW_QUOTA_INFO_GROUP
1300 $SHOW_QUOTA_INFO_PROJID
1302 log "Write after timer goes off"
1303 # maybe cache write, ignore.
1304 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1305 OFFSET=$((OFFSET + 1024))
1306 cancel_lru_locks osc
1307 log "Write after cancel lru locks"
1308 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1309 quota_error a $TSTUSR "write success, but expect EDQUOT"
1314 $SHOW_QUOTA_INFO_USER
1315 $SHOW_QUOTA_INFO_GROUP
1316 $SHOW_QUOTA_INFO_PROJID
1318 echo "Unlink file to stop timer"
1320 wait_delete_completed
1321 sync_all_data || true
1326 $SHOW_QUOTA_INFO_USER
1327 $SHOW_QUOTA_INFO_GROUP
1328 $SHOW_QUOTA_INFO_PROJID
1330 $LFS setstripe $testfile -c 1 -i 0
1331 chown $TSTUSR.$TSTUSR $testfile
1332 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1335 $RUNAS $DD of=$testfile count=$limit ||
1336 quota_error a $TSTUSR "write failure, but expect success"
1343 local grace=20 # 20s
1344 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1347 local testfile=$DIR/$tdir/$tfile-0
1349 # get minimum soft qunit size
1350 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1351 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1353 set_ost_qtype $QTYPE || error "enable ost quota failed"
1355 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1356 # make sure the system is clean
1357 local used=$(getquota -u $TSTUSR global curspace)
1358 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1360 $LFS setquota -t -u --block-grace $grace --inode-grace \
1361 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1362 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1363 error "set user quota failed"
1365 test_block_soft $testfile $grace $limit "u"
1367 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1368 testfile=$DIR/$tdir/$tfile-1
1369 # make sure the system is clean
1370 used=$(getquota -g $TSTUSR global curspace)
1371 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1373 $LFS setquota -t -g --block-grace $grace --inode-grace \
1374 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1375 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1376 error "set group quota failed"
1378 test_block_soft $testfile $grace $limit "g"
1380 if is_project_quota_supported; then
1381 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1382 testfile=$DIR/$tdir/$tfile-2
1383 # make sure the system is clean
1384 used=$(getquota -p $TSTPRJID global curspace)
1385 [ $used -ne 0 ] && error \
1386 "Used space($used) for project $TSTPRJID isn't 0."
1388 $LFS setquota -t -p --block-grace $grace --inode-grace \
1389 $MAX_IQ_TIME $DIR ||
1390 error "set project grace time failed"
1391 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1392 $DIR || error "set project quota failed"
1394 test_block_soft $testfile $grace $limit "p"
1395 resetquota -p $TSTPRJID
1396 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1397 $MAX_IQ_TIME $DIR ||
1398 error "restore project grace time failed"
1402 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1403 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1404 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1405 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1407 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1410 local grace=20 # 20s
1411 local qpool="qpool1"
1412 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1415 local testfile=$DIR/$tdir/$tfile-0
1418 # get minimum soft qunit size
1419 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1420 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1421 local glbl_limit=$((2*limit))
1422 local glbl_grace=$((2*grace))
1423 echo "limit $limit glbl_limit $glbl_limit"
1424 echo "grace $grace glbl_grace $glbl_grace"
1426 set_ost_qtype $QTYPE || error "enable ost quota failed"
1428 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1429 # make sure the system is clean
1430 local used=$(getquota -u $TSTUSR global curspace)
1431 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1433 pool_add $qpool || error "pool_add failed"
1434 pool_add_targets $qpool 0 1 ||
1435 error "pool_add_targets failed"
1437 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1438 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1439 $LFS setquota -t -u --block-grace $grace \
1440 --pool $qpool $DIR || error "set user grace time failed"
1442 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1443 error "set user quota failed"
1444 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1445 error "set user quota failed"
1447 test_block_soft $testfile $grace $limit "u" $qpool
1449 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1450 testfile=$DIR/$tdir/$tfile-1
1451 # make sure the system is clean
1452 used=$(getquota -g $TSTUSR global curspace)
1453 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1455 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1456 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1457 $LFS setquota -t -g --block-grace $grace \
1458 --pool $qpool $DIR || error "set group grace time failed"
1460 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1461 error "set group quota failed"
1462 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1463 error "set group quota failed"
1465 test_block_soft $testfile $grace $limit "g" $qpool
1467 if is_project_quota_supported; then
1468 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1469 testfile=$DIR/$tdir/$tfile-2
1470 # make sure the system is clean
1471 used=$(getquota -p $TSTPRJID global curspace)
1472 [ $used -ne 0 ] && error \
1473 "Used space($used) for project $TSTPRJID isn't 0."
1475 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1476 $MAX_IQ_TIME $DIR ||
1477 error "set project grace time failed"
1478 $LFS setquota -t -p --block-grace $grace \
1479 --pool $qpool $DIR ||
1480 error "set project grace time failed"
1482 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1483 $DIR || error "set project quota failed"
1484 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1485 --pool $qpool $DIR || error "set project quota failed"
1487 test_block_soft $testfile $grace $limit "p" $qpool
1488 resetquota -p $TSTPRJID
1489 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1490 $MAX_IQ_TIME $DIR ||
1491 error "restore project grace time failed"
1492 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1493 $DIR || error "set project grace time failed"
1497 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1498 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1499 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1500 --pool $qpool $DIR || error "restore user grace time failed"
1501 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1502 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1503 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1504 --pool $qpool $DIR || error "restore group grace time failed"
1506 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1509 local grace=20 # 20s
1510 local qpool="qpool1"
1511 local qpool2="qpool2"
1512 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1515 local testfile=$DIR/$tdir/$tfile-0
1518 # get minimum soft qunit size
1519 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1520 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1521 local limit2=$((limit+4))
1522 local glbl_limit=$((limit+8))
1523 local grace1=$((grace+10))
1525 local glbl_grace=$((grace+20))
1526 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1527 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1529 set_ost_qtype $QTYPE || error "enable ost quota failed"
1531 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1532 # make sure the system is clean
1533 local used=$(getquota -u $TSTUSR global curspace)
1534 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1536 pool_add $qpool || error "pool_add failed"
1537 pool_add_targets $qpool 0 1 ||
1538 error "pool_add_targets failed"
1540 pool_add $qpool2 || error "pool_add failed"
1541 pool_add_targets $qpool2 0 1 ||
1542 error "pool_add_targets failed"
1545 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1546 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1547 $LFS setquota -t -u --block-grace $grace1 \
1548 --pool $qpool $DIR || error "set user grace time failed"
1549 $LFS setquota -t -u --block-grace $grace2 \
1550 --pool $qpool2 $DIR || error "set user grace time failed"
1552 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1553 error "set user quota failed"
1554 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1555 error "set user quota failed"
1556 # qpool has minimum soft limit, but it's grace is grater than
1557 # grace period of qpool2. Thus write shouldn't fail when
1558 # hit qpool soft limit - only when reaches up qpool2 limit
1559 # after grace2 seconds.
1560 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1561 error "set user quota failed"
1563 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1566 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1567 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1568 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1569 --pool $qpool $DIR || error "restore user grace time failed"
1570 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1571 --pool $qpool2 $DIR || error "restore user grace time failed"
1573 run_test 3c "Quota pools: check block soft limit on different pools"
1580 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1581 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1584 trap cleanup_quota_test EXIT
1585 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1587 echo "Create files to exceed soft limit"
1588 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1589 quota_error a $TSTUSR "create failure, but expect success"
1590 local trigger_time=$(date +%s)
1592 sync_all_data || true
1594 local cur_time=$(date +%s)
1595 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1596 error "Passed grace time $grace, $trigger_time, $cur_time"
1598 echo "Create file before timer goes off"
1599 $RUNAS touch ${TESTFILE}_before ||
1600 quota_error a $TSTUSR "failed create before timer expired," \
1601 "but expect success. $trigger_time, $cur_time"
1602 sync_all_data || true
1604 wait_grace_time $qtype "file"
1609 $SHOW_QUOTA_INFO_USER
1610 $SHOW_QUOTA_INFO_GROUP
1611 $SHOW_QUOTA_INFO_PROJID
1613 echo "Create file after timer goes off"
1614 # exceed least soft limit is possible
1615 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1616 quota_error a $TSTUSR "create after timer expired," \
1618 sync_all_data || true
1623 $SHOW_QUOTA_INFO_USER
1624 $SHOW_QUOTA_INFO_GROUP
1625 $SHOW_QUOTA_INFO_PROJID
1627 echo "Unlink files to stop timer"
1628 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1629 wait_delete_completed
1632 $RUNAS touch ${TESTFILE}_xxx ||
1633 quota_error a $TSTUSR "touch after timer stop failure," \
1634 "but expect success"
1635 sync_all_data || true
1643 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1644 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1645 local TESTFILE=$DIR/$tdir/$tfile-0
1648 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1650 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1651 # make sure the system is clean
1652 local USED=$(getquota -u $TSTUSR global curinodes)
1653 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1655 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1656 $GRACE $DIR || error "set user grace time failed"
1657 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1658 error "set user quota failed"
1660 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1662 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1664 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1665 # make sure the system is clean
1666 USED=$(getquota -g $TSTUSR global curinodes)
1667 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1669 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1670 $GRACE $DIR || error "set group grace time failed"
1671 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1672 error "set group quota failed"
1673 TESTFILE=$DIR/$tdir/$tfile-1
1675 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1677 if is_project_quota_supported; then
1678 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1679 # make sure the system is clean
1680 USED=$(getquota -p $TSTPRJID global curinodes)
1681 [ $USED -ne 0 ] && error \
1682 "Used space($USED) for project $TSTPRJID isn't 0."
1684 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1685 $GRACE $DIR || error "set project grace time failed"
1686 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1687 error "set project quota failed"
1689 TESTFILE=$DIR/$tdir/$tfile-1
1690 # one less than limit, because of parent directory included.
1691 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1692 resetquota -p $TSTPRJID
1693 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1694 $MAX_IQ_TIME $DIR ||
1695 error "restore project grace time failed"
1699 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1700 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1701 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1702 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1704 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1707 local GR_STR1="1w3d"
1708 local GR_STR2="1000s"
1710 local GR_STR4="1w2d3h4m5s"
1712 local GR_STR6="18446744073709551615"
1715 wait_delete_completed
1717 # test of valid grace strings handling
1718 echo "Valid grace strings test"
1719 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1720 $GR_STR2 $DIR || error "set user grace time failed"
1721 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1722 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1723 $GR_STR4 $DIR || error "set group grace time quota failed"
1724 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1726 # test of invalid grace strings handling
1727 echo " Invalid grace strings test"
1728 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1729 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1730 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1734 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1735 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1736 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1737 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1739 run_test 4b "Grace time strings handling"
1741 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1743 local BLIMIT=10 # 10M
1744 local ILIMIT=10 # 10 inodes
1746 setup_quota_test || error "setup quota failed with $?"
1747 trap cleanup_quota_test EXIT
1749 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1750 set_ost_qtype $QTYPE || error "enable ost quota failed"
1752 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1753 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1754 error "set user quota failed"
1755 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1756 if is_project_quota_supported; then
1757 error "set group quota failed"
1758 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1759 -I $ILIMIT $DIR || error "set project quota failed"
1762 # make sure the system is clean
1763 local USED=$(getquota -u $TSTUSR global curinodes)
1764 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1765 USED=$(getquota -g $TSTUSR global curinodes)
1766 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1767 USED=$(getquota -u $TSTUSR global curspace)
1768 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1769 USED=$(getquota -g $TSTUSR global curspace)
1770 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1771 if is_project_quota_supported; then
1772 USED=$(getquota -p $TSTPRJID global curinodes)
1774 error "Used inode($USED) for project $TSTPRJID isn't 0."
1775 USED=$(getquota -p $TSTPRJID global curspace)
1777 error "Used block($USED) for project $TSTPRJID isn't 0."
1780 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1781 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1782 error "create failure, expect success"
1783 if is_project_quota_supported; then
1784 touch $DIR/$tdir/$tfile-0_1
1785 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1787 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1788 error "write failure, expect success"
1790 echo "Chown files to $TSTUSR.$TSTUSR ..."
1791 for i in $(seq 0 $ILIMIT); do
1792 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1793 quota_error a $TSTUSR "chown failure, expect success"
1797 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1798 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1801 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1803 # test dropping acquire request on master
1807 # Clear dmesg so watchdog is not triggered by previous
1809 do_facet ost1 dmesg -c > /dev/null
1811 setup_quota_test || error "setup quota failed with $?"
1812 trap cleanup_quota_test EXIT
1814 # make sure the system is clean
1815 local USED=$(getquota -u $TSTUSR global curspace)
1816 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1818 # make sure no granted quota on ost
1819 set_ost_qtype $QTYPE || error "enable ost quota failed"
1820 resetquota -u $TSTUSR
1822 # create file for $TSTUSR
1823 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1824 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1825 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1827 # create file for $TSTUSR2
1828 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1829 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1830 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1832 # cache per-ID lock for $TSTUSR on slave
1833 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1834 error "set quota failed"
1835 $RUNAS $DD of=$TESTFILE count=1 ||
1836 error "write $TESTFILE failure, expect success"
1837 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1838 error "write $TESTFILE2 failure, expect success"
1840 if at_is_enabled; then
1841 at_max_saved=$(at_max_get ost1)
1842 at_max_set $TIMEOUT ost1
1844 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1845 # DQACQ is sent, which makes at_max to take effect
1846 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1849 wait_delete_completed
1853 sync_all_data || true
1855 #define QUOTA_DQACQ 601
1856 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1857 lustre_fail mds 0x513 601
1859 do_facet ost1 $LCTL set_param \
1860 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1862 # write to un-enforced ID ($TSTUSR2) should succeed
1863 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1864 error "write failure, expect success"
1866 # write to enforced ID ($TSTUSR) in background, exceeding limit
1867 # to make sure DQACQ is sent
1868 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1871 # watchdog timer uses a factor of 2
1872 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1873 sleep $((TIMEOUT * 2 + 1))
1875 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1877 # write should be blocked and never finished
1878 if ! ps -p $DDPID > /dev/null 2>&1; then
1880 error "write finished incorrectly!"
1885 # no watchdog is triggered
1886 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1887 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1888 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1889 [ -z "$watchdog" ] || error "$watchdog"
1891 rm -f $TMP/lustre-log-${TESTNAME}.log
1893 # write should continue then fail with EDQUOT
1897 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1898 if [ $count -ge 240 ]; then
1899 quota_error u $TSTUSR "dd not finished in $count secs"
1901 count=$((count + 1))
1902 if [ $((count % 30)) -eq 0 ]; then
1903 c_size=$(stat -c %s $TESTFILE)
1904 echo "Waiting $count secs. $c_size"
1912 run_test 6 "Test dropping acquire request on master"
1914 # quota reintegration (global index)
1916 local TESTFILE=$DIR/$tdir/$tfile
1917 local LIMIT=20 # 20M
1919 [ "$SLOW" = "no" ] && LIMIT=5
1921 setup_quota_test || error "setup quota failed with $?"
1922 trap cleanup_quota_test EXIT
1924 # make sure the system is clean
1925 local USED=$(getquota -u $TSTUSR global curspace)
1926 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1928 # make sure no granted quota on ost1
1929 set_ost_qtype $QTYPE || error "enable ost quota failed"
1930 resetquota -u $TSTUSR
1931 set_ost_qtype "none" || error "disable ost quota failed"
1933 local OSTUUID=$(ostuuid_from_index 0)
1934 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1936 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1939 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1940 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1945 echo "Enable quota & set quota limit for $TSTUSR"
1946 set_ost_qtype $QTYPE || error "enable ost quota failed"
1947 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1948 error "set quota failed"
1950 echo "Start ost1..."
1951 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1954 wait_ost_reint $QTYPE || error "reintegration failed"
1956 # hardlimit should have been fetched by slave during global
1957 # reintegration, write will exceed quota
1958 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1959 quota_error u $TSTUSR "write success, but expect EDQUOT"
1962 wait_delete_completed
1963 sync_all_data || true
1969 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1970 error "clear quota failed"
1972 echo "Start ost1..."
1973 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1976 wait_ost_reint $QTYPE || error "reintegration failed"
1978 # hardlimit should be cleared on slave during reintegration
1979 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1980 quota_error u $TSTUSR "write error, but expect success"
1984 run_test 7a "Quota reintegration (global index)"
1986 # quota reintegration (slave index)
1989 local TESTFILE=$DIR/$tdir/$tfile
1991 setup_quota_test || error "setup quota failed with $?"
1992 trap cleanup_quota_test EXIT
1994 # make sure the system is clean
1995 local USED=$(getquota -u $TSTUSR global curspace)
1996 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1998 # make sure no granted quota on ost1
1999 set_ost_qtype $QTYPE || error "enable ost quota failed"
2000 resetquota -u $TSTUSR
2001 set_ost_qtype "none" || error "disable ost quota failed"
2003 local OSTUUID=$(ostuuid_from_index 0)
2004 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2006 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2009 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2010 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2012 # consume some space to make sure the granted space will not
2013 # be released during reconciliation
2014 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2015 error "consume space failure, expect success"
2017 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2018 lustre_fail mds 0xa02
2020 set_ost_qtype $QTYPE || error "enable ost quota failed"
2021 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2022 error "set quota failed"
2024 # ignore the write error
2025 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2027 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2031 echo "Restart ost to trigger reintegration..."
2033 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2036 wait_ost_reint $QTYPE || error "reintegration failed"
2038 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2039 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2044 run_test 7b "Quota reintegration (slave index)"
2046 # quota reintegration (restart mds during reintegration)
2048 local LIMIT=20 # 20M
2049 local TESTFILE=$DIR/$tdir/$tfile
2051 [ "$SLOW" = "no" ] && LIMIT=5
2053 setup_quota_test || error "setup quota failed with $?"
2054 trap cleanup_quota_test EXIT
2056 # make sure the system is clean
2057 local USED=$(getquota -u $TSTUSR global curspace)
2058 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2060 set_ost_qtype "none" || error "disable ost quota failed"
2061 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2062 error "set quota failed"
2064 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2065 lustre_fail ost 0xa03
2068 set_ost_qtype $QTYPE || error "enable ost quota failed"
2069 # trigger reintegration
2070 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2071 procf=${procf}quota_slave.force_reint
2072 do_facet ost1 $LCTL set_param $procf=1 ||
2073 error "force reintegration failed"
2081 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2084 # wait longer than usual to make sure the reintegration
2085 # is triggered by quota wb thread.
2086 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2088 # hardlimit should have been fetched by slave during global
2089 # reintegration, write will exceed quota
2090 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2091 quota_error u $TSTUSR "write success, but expect EDQUOT"
2095 run_test 7c "Quota reintegration (restart mds during reintegration)"
2097 # Quota reintegration (Transfer index in multiple bulks)
2099 local TESTFILE=$DIR/$tdir/$tfile
2100 local TESTFILE1="$DIR/$tdir/$tfile"-1
2103 setup_quota_test || error "setup quota failed with $?"
2104 trap cleanup_quota_test EXIT
2106 set_ost_qtype "none" || error "disable ost quota failed"
2107 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2108 error "set quota for $TSTUSR failed"
2109 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2110 error "set quota for $TSTUSR2 failed"
2112 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2113 lustre_fail mds 0x608 0
2115 # enable quota to tirgger reintegration
2116 set_ost_qtype "u" || error "enable ost quota failed"
2117 wait_ost_reint "u" || error "reintegration failed"
2121 # hardlimit should have been fetched by slave during global
2122 # reintegration, write will exceed quota
2123 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2124 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2126 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2127 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2131 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2133 # quota reintegration (inode limits)
2135 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2137 # LU-2435: skip this quota test if underlying zfs version has not
2138 # supported native dnode accounting
2139 [ "$mds1_FSTYPE" == zfs ] && {
2140 local F="feature@userobj_accounting"
2141 local pool=$(zpool_name mds1)
2142 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2144 [[ "$feature" != *" active "* ]] &&
2145 skip "requires zpool with active userobj_accounting"
2148 local ilimit=$((1024 * 2)) # 2k inodes
2149 local TESTFILE=$DIR/${tdir}-1/$tfile
2151 setup_quota_test || error "setup quota failed with $?"
2152 trap cleanup_quota_test EXIT
2154 # make sure the system is clean
2155 local USED=$(getquota -u $TSTUSR global curinodes)
2156 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2158 # make sure no granted quota on mdt1
2159 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2160 resetquota -u $TSTUSR
2161 set_mdt_qtype "none" || error "disable mdt quota failed"
2163 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2164 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2165 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2168 echo "Stop mds${MDSCOUNT}..."
2171 echo "Enable quota & set quota limit for $TSTUSR"
2172 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2173 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2174 error "set quota failed"
2176 echo "Start mds${MDSCOUNT}..."
2177 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2180 wait_mdt_reint $QTYPE || error "reintegration failed"
2182 echo "create remote dir"
2183 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2184 error "create remote dir failed"
2185 chmod 0777 $DIR/${tdir}-1
2187 # hardlimit should have been fetched by slave during global
2188 # reintegration, create will exceed quota
2189 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2190 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2192 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2193 wait_delete_completed
2194 sync_all_data || true
2196 echo "Stop mds${MDSCOUNT}..."
2199 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2200 error "clear quota failed"
2202 echo "Start mds${MDSCOUNT}..."
2203 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2206 wait_mdt_reint $QTYPE || error "reintegration failed"
2208 # hardlimit should be cleared on slave during reintegration
2209 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2210 quota_error u $TSTUSR "create failed, expect success"
2212 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2213 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2217 run_test 7e "Quota reintegration (inode limits)"
2219 # run dbench with quota enabled
2221 local BLK_LIMIT="100g" #100G
2222 local FILE_LIMIT=1000000
2224 setup_quota_test || error "setup quota failed with $?"
2225 trap cleanup_quota_test EXIT
2227 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2228 set_ost_qtype $QTYPE || error "enable ost quota failed"
2230 echo "Set enough high limit for user: $TSTUSR"
2231 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2232 error "set user quota failed"
2233 echo "Set enough high limit for group: $TSTUSR"
2234 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2235 error "set group quota failed"
2236 if is_project_quota_supported; then
2237 change_project -sp $TSTPRJID $DIR/$tdir
2238 echo "Set enough high limit for project: $TSTPRJID"
2239 $LFS setquota -p $TSTPRJID -b 0 \
2240 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2241 error "set project quota failed"
2245 [ "$SLOW" = "no" ] && duration=" -t 120"
2246 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2247 quota_error a $TSTUSR "dbench failed!"
2249 is_project_quota_supported && change_project -C $DIR/$tdir
2252 run_test 8 "Run dbench with quota enabled"
2254 # this check is just for test_9
2255 OST0_MIN=4900000 #4.67G
2257 check_whether_skip () {
2258 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2259 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2260 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2261 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2268 # run for fixing bug10707, it needs a big room. test for 64bit
2270 local filesize=$((1024 * 9 / 2)) # 4.5G
2272 check_whether_skip && return 0
2274 setup_quota_test || error "setup quota failed with $?"
2275 trap cleanup_quota_test EXIT
2277 set_ost_qtype "ug" || error "enable ost quota failed"
2279 local TESTFILE="$DIR/$tdir/$tfile-0"
2280 local BLK_LIMIT=100G #100G
2281 local FILE_LIMIT=1000000
2283 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2285 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2287 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2288 error "set user quota failed"
2290 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2291 "for group: $TSTUSR"
2292 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2293 error "set group quota failed"
2295 quota_show_check a u $TSTUSR
2296 quota_show_check a g $TSTUSR
2298 echo "Create test file"
2299 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2300 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2302 log "Write the big file of 4.5G ..."
2303 $RUNAS $DD of=$TESTFILE count=$filesize ||
2304 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2314 run_test 9 "Block limit larger than 4GB (b10707)"
2317 local TESTFILE=$DIR/$tdir/$tfile
2319 setup_quota_test || error "setup quota failed with $?"
2320 trap cleanup_quota_test EXIT
2322 # set limit to root user should fail
2323 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2324 error "set limit for root user successfully, expect failure"
2325 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2326 error "set limit for root group successfully, expect failure"
2327 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2328 error "set limit for project 0 successfully, expect failure"
2330 # root user can overrun quota
2331 set_ost_qtype "ug" || error "enable ost quota failed"
2333 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2334 error "set quota failed"
2335 quota_show_check b u $TSTUSR
2337 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2338 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2340 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2341 error "write failure, expect success"
2345 run_test 10 "Test quota for root user"
2348 local TESTFILE=$DIR/$tdir/$tfile
2349 setup_quota_test || error "setup quota failed with $?"
2350 trap cleanup_quota_test EXIT
2352 set_mdt_qtype "ug" || error "enable mdt quota failed"
2353 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2354 error "set quota failed"
2356 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2357 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2359 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2360 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2363 local USED=$(getquota -u $TSTUSR global curinodes)
2364 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2368 run_test 11 "Chown/chgrp ignores quota"
2371 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2373 local blimit=22 # 22M
2374 local blk_cnt=$((blimit - 5))
2375 local TESTFILE0="$DIR/$tdir/$tfile"-0
2376 local TESTFILE1="$DIR/$tdir/$tfile"-1
2378 setup_quota_test || error "setup quota failed with $?"
2379 trap cleanup_quota_test EXIT
2381 set_ost_qtype "u" || error "enable ost quota failed"
2382 quota_show_check b u $TSTUSR
2384 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2385 error "set quota failed"
2387 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2388 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2389 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2390 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2392 echo "Write to ost0..."
2393 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2394 quota_error a $TSTUSR "dd failed"
2396 echo "Write to ost1..."
2397 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2398 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2400 echo "Free space from ost0..."
2402 wait_delete_completed
2403 sync_all_data || true
2405 echo "Write to ost1 after space freed from ost0..."
2406 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2407 quota_error a $TSTUSR "rebalancing failed"
2411 run_test 12a "Block quota rebalancing"
2414 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2416 local ilimit=$((1024 * 2)) # 2k inodes
2417 local TESTFILE0=$DIR/$tdir/$tfile
2418 local TESTFILE1=$DIR/${tdir}-1/$tfile
2420 setup_quota_test || error "setup quota failed with $?"
2421 trap cleanup_quota_test EXIT
2423 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2424 chmod 0777 $DIR/${tdir}-1
2426 set_mdt_qtype "u" || error "enable mdt quota failed"
2427 quota_show_check f u $TSTUSR
2429 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2430 error "set quota failed"
2432 echo "Create $ilimit files on mdt0..."
2433 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2434 quota_error u $TSTUSR "create failed, but expect success"
2436 echo "Create files on mdt1..."
2437 $RUNAS createmany -m $TESTFILE1 1 &&
2438 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2440 echo "Free space from mdt0..."
2441 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2442 wait_delete_completed
2443 sync_all_data || true
2445 echo "Create files on mdt1 after space freed from mdt0..."
2446 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2447 quota_error a $TSTUSR "rebalancing failed"
2449 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2450 error "unlink mdt1 files failed"
2451 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2455 run_test 12b "Inode quota rebalancing"
2458 local TESTFILE=$DIR/$tdir/$tfile
2459 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2460 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2462 setup_quota_test || error "setup quota failed with $?"
2463 trap cleanup_quota_test EXIT
2465 set_ost_qtype "u" || error "enable ost quota failed"
2466 quota_show_check b u $TSTUSR
2468 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2469 error "set quota failed"
2470 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2471 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2473 # clear the locks in cache first
2474 do_facet ost1 $LCTL set_param -n $procf=clear
2475 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2476 [ $nlock -eq 0 ] || error "$nlock cached locks"
2478 # write to acquire the per-ID lock
2479 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2480 quota_error a $TSTUSR "dd failed"
2482 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2483 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2485 # clear quota doesn't trigger per-ID lock cancellation
2486 resetquota -u $TSTUSR
2487 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2488 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2490 # clear the per-ID lock
2491 do_facet ost1 $LCTL set_param -n $procf=clear
2492 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2493 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2495 # spare quota should be released
2496 local OSTUUID=$(ostuuid_from_index 0)
2497 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2498 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2499 [ $limit -le $space ] ||
2500 error "spare quota isn't released, limit:$limit, space:$space"
2504 run_test 13 "Cancel per-ID lock in the LRU list"
2507 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2509 wait_delete_completed
2510 sync_all_data || true
2513 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2514 error "set user quota failed"
2515 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2516 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2517 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2518 resetquota -u $TSTUSR
2521 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2522 error "set group quota failed"
2523 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2524 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2525 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2526 resetquota -g $TSTUSR
2528 run_test 15 "Set over 4T block quota"
2532 local BLKS=1 # 1M less than limit
2533 local TESTFILE=$DIR/$tdir/$tfile
2535 setup_quota_test || error "setup quota failed with $?"
2536 trap cleanup_quota_test EXIT
2538 # make sure the system is clean
2539 local USED=$(getquota -u $TSTUSR global curspace)
2540 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2542 set_ost_qtype "ug" || error "enable ost quota failed"
2543 # make sure no granted quota on ost
2544 resetquota -u $TSTUSR
2545 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2546 error "set quota failed"
2548 quota_show_check b u $TSTUSR
2550 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2551 lustre_fail mds 0xa04 $err_code
2553 # write in background
2554 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2558 # write should be blocked and never finished
2559 if ! ps -p $DDPID > /dev/null 2>&1; then
2561 quota_error u $TSTUSR "write finished incorrectly!"
2569 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2571 if [ $count -gt $timeout ]; then
2572 quota_error u $TSTUSR "dd is not finished!"
2577 sync; sync_all_data || true
2579 USED=$(getquota -u $TSTUSR global curspace)
2580 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2581 "Used space(${USED}K) is less than ${BLKS}M"
2586 # DQACQ return recoverable error
2588 echo "DQACQ return -ENOLCK"
2590 test_17sub 37 || error "Handle -ENOLCK failed"
2592 echo "DQACQ return -EAGAIN"
2594 test_17sub 11 || error "Handle -EAGAIN failed"
2596 echo "DQACQ return -ETIMEDOUT"
2597 #define ETIMEDOUT 110
2598 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2600 echo "DQACQ return -ENOTCONN"
2601 #define ENOTCONN 107
2602 test_17sub 107 || error "Handle -ENOTCONN failed"
2605 run_test 17 "DQACQ return recoverable error"
2609 local blimit="200m" # 200M
2610 local TESTFILE="$DIR/$tdir/$tfile"
2612 setup_quota_test || error "setup quota failed with $?"
2613 trap cleanup_quota_test EXIT
2615 set_ost_qtype "u" || error "enable ost quota failed"
2616 log "User quota (limit: $blimit)"
2617 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2618 error "set quota failed"
2619 quota_show_check b u $TSTUSR
2621 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2622 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2624 local timeout=$(sysctl -n lustre.timeout)
2626 if [ $io_type = "directio" ]; then
2627 log "Write 100M (directio) ..."
2628 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2630 log "Write 100M (buffered) ..."
2631 $RUNAS $DD of=$TESTFILE count=100 &
2635 replay_barrier $SINGLEMDS
2636 log "Fail mds for $((2 * timeout)) seconds"
2637 fail $SINGLEMDS $((2 * timeout))
2640 if at_is_enabled; then
2641 timeout=$(at_max_get mds)
2643 timeout=$(lctl get_param -n timeout)
2647 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2648 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2649 log "it took $count second"
2654 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2656 cancel_lru_locks mdc
2657 cancel_lru_locks osc
2660 local testfile_size=$(stat -c %s $TESTFILE)
2661 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2662 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2663 "got ${testfile_size}. Verifying file failed!"
2668 # test when mds does failover, the ost still could work well
2669 # this test shouldn't trigger watchdog b=14840
2671 # Clear dmesg so watchdog is not triggered by previous
2673 do_facet ost1 dmesg -c > /dev/null
2676 test_18_sub directio
2678 # check if watchdog is triggered
2679 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2680 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2681 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2682 [ -z "$watchdog" ] || error "$watchdog"
2683 rm -f $TMP/lustre-log-${TESTNAME}.log
2685 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2689 local TESTFILE=$DIR/$tdir/$tfile
2691 setup_quota_test || error "setup quota failed with $?"
2692 trap cleanup_quota_test EXIT
2694 set_ost_qtype $QTYPE || error "enable ost quota failed"
2696 # bind file to a single OST
2697 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2698 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2700 echo "Set user quota (limit: ${blimit}M)"
2701 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2702 error "set user quota failed"
2703 quota_show_check b u $TSTUSR
2704 echo "Update quota limits"
2705 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2706 error "set group quota failed"
2707 quota_show_check b u $TSTUSR
2709 # first wirte might be cached
2710 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2711 cancel_lru_locks osc
2713 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2714 quota_error u $TSTUSR "Write success, expect failure"
2719 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2721 test_20() { # b15754
2722 local LSTR=(2g 1t 4k 3m) # limits strings
2724 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2727 resetquota -u $TSTUSR
2729 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2730 $MOUNT || error "could not set quota limits"
2731 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2732 --inode-softlimit ${LSTR[2]} \
2733 --inode-hardlimit ${LSTR[3]} \
2734 $MOUNT || error "could not set quota limits"
2736 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2737 error "bsoftlimit was not set properly"
2738 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2739 error "bhardlimit was not set properly"
2740 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2741 error "isoftlimit was not set properly"
2742 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2743 error "ihardlimit was not set properly"
2745 resetquota -u $TSTUSR
2747 run_test 20 "Test if setquota specifiers work properly (b15754)"
2754 local time=$(($(date +%s) + seconds))
2755 while [ $(date +%s) -lt $time ]; do
2756 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2760 # run for fixing bug16053, setquota shouldn't fail when writing and
2761 # deleting are happening
2763 local TESTFILE="$DIR/$tdir/$tfile"
2764 local BLIMIT=10 # 10G
2765 local ILIMIT=1000000
2767 setup_quota_test || error "setup quota failed with $?"
2768 trap cleanup_quota_test EXIT
2770 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2772 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2773 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2774 error "set user quota failed"
2775 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2776 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2777 error "set group quota failed"
2778 if is_project_quota_supported; then
2779 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2780 "project: $TSTPRJID"
2781 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2782 $MOUNT || error "set project quota failed"
2785 # repeat writing on a 1M file
2786 test_21_sub ${TESTFILE}_1 1 30 &
2788 # repeat writing on a 128M file
2789 test_21_sub ${TESTFILE}_2 128 30 &
2792 local time=$(($(date +%s) + 30))
2794 while [ $(date +%s) -lt $time ]; do
2795 log "Set quota for $i times"
2796 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2797 -I $((ILIMIT + i)) $MOUNT ||
2798 error "Set user quota failed"
2799 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2800 -I $((ILIMIT + i)) $MOUNT ||
2801 error "Set group quota failed"
2802 if is_project_quota_supported; then
2803 $LFS setquota -p $TSTPRJID -b 0 -B \
2804 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2805 error "Set project quota failed"
2813 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2815 if [ $count -gt 60 ]; then
2816 quota_error a $TSTUSR "dd should be finished!"
2820 echo "(dd_pid=$DDPID1, time=$count)successful"
2824 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2826 if [ $count -gt 60 ]; then
2827 quota_error a $TSTUSR "dd should be finished!"
2831 echo "(dd_pid=$DDPID2, time=$count)successful"
2835 run_test 21 "Setquota while writing & deleting (b16053)"
2837 # enable/disable quota enforcement permanently
2839 echo "Set both mdt & ost quota type as ug"
2841 is_project_quota_supported && qtype=$QTYPE
2842 set_mdt_qtype $qtype || error "enable mdt quota failed"
2843 set_ost_qtype $qtype || error "enable ost quota failed"
2846 stopall || error "failed to stopall (1)"
2850 echo "Verify if quota is enabled"
2851 local qtype1=$(mdt_quota_type)
2852 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2853 qtype=$(ost_quota_type)
2854 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2856 echo "Set both mdt & ost quota type as none"
2857 set_mdt_qtype "none" || error "disable mdt quota failed"
2858 set_ost_qtype "none" || error "disable ost quota failed"
2861 stopall || error "failed to stopall (2)"
2866 echo "Verify if quota is disabled"
2867 qtype=$(mdt_quota_type)
2868 [ $qtype != "none" ] && error "mdt quota setting is lost"
2869 qtype=$(ost_quota_type)
2870 [ $qtype != "none" ] && error "ost quota setting is lost"
2874 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2877 local TESTFILE="$DIR/$tdir/$tfile"
2880 setup_quota_test || error "setup quota failed with $?"
2881 trap cleanup_quota_test EXIT
2883 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2886 log "User quota (limit: $LIMIT MB)"
2887 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2888 error "set quota failed"
2889 quota_show_check b u $TSTUSR
2891 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2892 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2894 log "Step1: trigger EDQUOT with O_DIRECT"
2895 log "Write half of file"
2896 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2897 quota_error u $TSTUSR "(1) Write failure, expect success." \
2899 log "Write out of block quota ..."
2900 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2901 oflag=direct conv=notrunc &&
2902 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2906 log "Step2: rewrite should succeed"
2907 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2908 quota_error u $TSTUSR "(3) Write failure, expect success." \
2914 local OST0_UUID=$(ostuuid_from_index 0)
2915 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2916 [ $OST0_QUOTA_USED -ne 0 ] &&
2917 ($SHOW_QUOTA_USER; \
2918 quota_error u $TSTUSR "quota isn't released")
2923 [ "$ost1_FSTYPE" == zfs ] &&
2924 skip "Overwrite in place is not guaranteed to be " \
2925 "space neutral on ZFS"
2927 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2928 check_whether_skip && return 0
2929 log "run for 4MB test file"
2932 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2933 check_whether_skip && return 0
2934 log "run for 40MB test file"
2937 run_test 23 "Quota should be honored with directIO (b16125)"
2941 local TESTFILE="$DIR/$tdir/$tfile"
2943 setup_quota_test || error "setup quota failed with $?"
2944 trap cleanup_quota_test EXIT
2946 set_ost_qtype $QTYPE || error "enable ost quota failed"
2948 # bind file to a single OST
2949 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2950 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2952 echo "Set user quota (limit: ${blimit}M)"
2953 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2954 error "set quota failed"
2956 # overrun quota by root user
2957 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2958 error "write failure, expect success"
2959 cancel_lru_locks osc
2960 sync_all_data || true
2962 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2966 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2968 test_27a() { # b19612
2969 $LFS quota $TSTUSR $DIR &&
2970 error "lfs succeeded with no type, but should have failed"
2971 $LFS setquota $TSTUSR $DIR &&
2972 error "lfs succeeded with no type, but should have failed"
2975 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2977 test_27b() { # b20200
2978 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2979 error "lfs setquota failed with uid argument"
2980 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2981 error "lfs stequota failed with gid argument"
2982 if is_project_quota_supported; then
2983 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2984 1000 $DIR || error \
2985 "lfs stequota failed with projid argument"
2987 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2988 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2989 if is_project_quota_supported; then
2990 $SHOW_QUOTA_PROJID ||
2991 error "lfs quota failed with projid argument"
2993 resetquota -u $TSTID
2994 resetquota -g $TSTID
2995 resetquota -p $TSTPRJID
2998 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3003 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3004 error "lfs setquota failed"
3006 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3007 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3008 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3009 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3011 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3012 error "lfs setquota for $TSTID failed"
3014 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3015 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3016 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3017 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3019 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3020 error "total allocated inode/block limit not printed"
3022 resetquota -u $TSTUSR
3024 run_test 27c "lfs quota should support human-readable output"
3031 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3032 error "set fraction block limit failed"
3033 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3034 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3035 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3036 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3038 resetquota -u $TSTUSR
3040 run_test 27d "lfs setquota should support fraction block limit"
3044 local TESTFILE="$DIR/$tdir/$tfile"
3047 setup_quota_test || error "setup quota failed with $?"
3048 trap cleanup_quota_test EXIT
3050 set_ost_qtype "u" || error "enable ost quota failed"
3052 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3053 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3055 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3056 $MAX_IQ_TIME $DIR || error "set grace time failed"
3057 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3058 error "set quota failed"
3059 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3060 cancel_lru_locks osc
3062 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3063 # over-quota flag has not yet settled since we do not trigger async
3064 # events based on grace time period expiration
3066 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3067 cancel_lru_locks osc
3068 # now over-quota flag should be settled and further writes should fail
3070 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3071 error "grace times were reset"
3074 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3075 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3077 run_test 30 "Hard limit updates should not reset grace times"
3079 # basic usage tracking for user & group
3081 local INODES=10 # 10 files
3082 local BLK_CNT=2 # of 2M each
3083 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3085 setup_quota_test || error "setup quota failed with $?"
3086 trap cleanup_quota_test EXIT
3088 # make sure the system is clean
3089 local USED=$(getquota -u $TSTID global curspace)
3091 error "Used space ($USED) for user $TSTID isn't 0."
3092 USED=$(getquota -g $TSTID global curspace)
3094 error "Used space ($USED) for group $TSTID isn't 0."
3095 if is_project_quota_supported; then
3096 USED=$(getquota -p $TSTPRJID global curspace)
3097 [ $USED -ne 0 ] && error \
3098 "Used space ($USED) for project $TSTPRJID isn't 0."
3101 echo "Write files..."
3102 for i in $(seq 0 $INODES); do
3103 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3104 error "write failed"
3105 is_project_quota_supported &&
3106 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3107 echo "Iteration $i/$INODES completed"
3109 cancel_lru_locks osc
3111 echo "Wait for setattr on objects finished..."
3112 wait_delete_completed
3114 sync; sync_all_data || true
3116 echo "Verify disk usage after write"
3117 USED=$(getquota -u $TSTID global curspace)
3118 [ $USED -lt $TOTAL_BLKS ] &&
3119 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3120 USED=$(getquota -g $TSTID global curspace)
3121 [ $USED -lt $TOTAL_BLKS ] &&
3122 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3123 if is_project_quota_supported; then
3124 USED=$(getquota -p $TSTPRJID global curspace)
3125 [ $USED -lt $TOTAL_BLKS ] && error \
3126 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3129 echo "Verify inode usage after write"
3130 USED=$(getquota -u $TSTID global curinodes)
3131 [ $USED -lt $INODES ] &&
3132 error "Used inode for user $TSTID is $USED, expected $INODES"
3133 USED=$(getquota -g $TSTID global curinodes)
3134 [ $USED -lt $INODES ] &&
3135 error "Used inode for group $TSTID is $USED, expected $INODES"
3136 if is_project_quota_supported; then
3137 USED=$(getquota -p $TSTPRJID global curinodes)
3138 [ $USED -lt $INODES ] && error \
3139 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3144 echo "Verify disk usage after delete"
3145 USED=$(getquota -u $TSTID global curspace)
3146 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3147 USED=$(getquota -u $TSTID global curinodes)
3148 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3149 USED=$(getquota -g $TSTID global curspace)
3150 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3151 USED=$(getquota -g $TSTID global curinodes)
3152 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3153 if is_project_quota_supported; then
3154 USED=$(getquota -p $TSTPRJID global curspace)
3156 error "Used space for project $TSTPRJID isn't 0. $USED"
3157 USED=$(getquota -p $TSTPRJID global curinodes)
3159 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3162 run_test 33 "Basic usage tracking for user & group & project"
3164 # usage transfer test for user & group & project
3166 local BLK_CNT=2 # 2MB
3167 local project_supported="no"
3169 is_project_quota_supported && project_supported="yes"
3170 setup_quota_test || error "setup quota failed with $?"
3171 trap cleanup_quota_test EXIT
3173 # make sure the system is clean
3174 local USED=$(getquota -u $TSTID global curspace)
3175 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3176 USED=$(getquota -g $TSTID global curspace)
3177 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3179 local USED=$(getquota -u $TSTID2 global curspace)
3180 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3181 if [ $project_supported == "yes" ]; then
3182 USED=$(getquota -p $TSTPRJID global curspace)
3183 [ $USED -ne 0 ] && error \
3184 "Used space ($USED) for Project $TSTPRJID isn't 0."
3187 echo "Write file..."
3188 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3189 error "write failed"
3190 cancel_lru_locks osc
3191 sync; sync_all_data || true
3193 echo "chown the file to user $TSTID"
3194 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3196 echo "Wait for setattr on objects finished..."
3197 wait_delete_completed
3199 BLK_CNT=$((BLK_CNT * 1024))
3201 echo "Verify disk usage for user $TSTID"
3202 USED=$(getquota -u $TSTID global curspace)
3203 [ $USED -lt $BLK_CNT ] &&
3204 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3205 USED=$(getquota -u $TSTID global curinodes)
3207 error "Used inodes for user $TSTID is $USED, expected 1"
3209 echo "chgrp the file to group $TSTID"
3210 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3212 echo "Wait for setattr on objects finished..."
3213 wait_delete_completed
3215 echo "Verify disk usage for group $TSTID"
3216 USED=$(getquota -g $TSTID global curspace)
3217 [ $USED -ge $BLK_CNT ] ||
3218 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3219 USED=$(getquota -g $TSTID global curinodes)
3221 error "Used inodes for group $TSTID is $USED, expected 1"
3223 # chown won't change the ost object group. LU-4345 */
3224 echo "chown the file to user $TSTID2"
3225 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3227 echo "Wait for setattr on objects finished..."
3228 wait_delete_completed
3230 echo "change_project project id to $TSTPRJID"
3231 [ $project_supported == "yes" ] &&
3232 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3233 echo "Wait for setattr on objects finished..."
3234 wait_delete_completed
3236 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3237 USED=$(getquota -u $TSTID2 global curspace)
3238 [ $USED -lt $BLK_CNT ] &&
3239 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3240 USED=$(getquota -u $TSTID global curspace)
3242 error "Used space for user $TSTID is $USED, expected 0"
3243 USED=$(getquota -g $TSTID global curspace)
3244 [ $USED -lt $BLK_CNT ] &&
3245 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3246 if [ $project_supported == "yes" ]; then
3247 USED=$(getquota -p $TSTPRJID global curspace)
3248 [ $USED -lt $BLK_CNT ] && error \
3249 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3254 run_test 34 "Usage transfer for user & group & project"
3256 # usage is still accessible across restart
3258 local BLK_CNT=2 # 2 MB
3260 setup_quota_test || error "setup quota failed with $?"
3261 trap cleanup_quota_test EXIT
3263 echo "Write file..."
3264 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3265 error "write failed"
3266 is_project_quota_supported &&
3267 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3268 cancel_lru_locks osc
3270 echo "Wait for setattr on objects finished..."
3271 wait_delete_completed
3273 sync; sync_all_data || true
3275 echo "Save disk usage before restart"
3276 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3277 [ $ORIG_USR_SPACE -eq 0 ] &&
3278 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3279 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3280 [ $ORIG_USR_INODES -eq 0 ] &&
3281 error "Used inodes for user $TSTID is 0, expected 1"
3282 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3283 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3284 [ $ORIG_GRP_SPACE -eq 0 ] &&
3285 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3286 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3287 [ $ORIG_GRP_INODES -eq 0 ] &&
3288 error "Used inodes for group $TSTID is 0, expected 1"
3289 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3291 if is_project_quota_supported; then
3292 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3293 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3294 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3295 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3296 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3297 "Used inodes for project $TSTPRJID is 0, expected 1"
3298 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3306 echo "Verify disk usage after restart"
3307 local USED=$(getquota -u $TSTID global curspace)
3308 [ $USED -eq $ORIG_USR_SPACE ] ||
3309 error "Used space for user $TSTID changed from " \
3310 "$ORIG_USR_SPACE to $USED"
3311 USED=$(getquota -u $TSTID global curinodes)
3312 [ $USED -eq $ORIG_USR_INODES ] ||
3313 error "Used inodes for user $TSTID changed from " \
3314 "$ORIG_USR_INODES to $USED"
3315 USED=$(getquota -g $TSTID global curspace)
3316 [ $USED -eq $ORIG_GRP_SPACE ] ||
3317 error "Used space for group $TSTID changed from " \
3318 "$ORIG_GRP_SPACE to $USED"
3319 USED=$(getquota -g $TSTID global curinodes)
3320 [ $USED -eq $ORIG_GRP_INODES ] ||
3321 error "Used inodes for group $TSTID changed from " \
3322 "$ORIG_GRP_INODES to $USED"
3323 if [ $project_supported == "yes" ]; then
3324 USED=$(getquota -p $TSTPRJID global curinodes)
3325 [ $USED -eq $ORIG_PRJ_INODES ] ||
3326 error "Used inodes for project $TSTPRJID " \
3327 "changed from $ORIG_PRJ_INODES to $USED"
3328 USED=$(getquota -p $TSTPRJID global curspace)
3329 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3330 error "Used space for project $TSTPRJID "\
3331 "changed from $ORIG_PRJ_SPACE to $USED"
3334 # check if the vfs_dq_init() is called before writing
3335 echo "Append to the same file..."
3336 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3337 error "write failed"
3338 cancel_lru_locks osc
3339 sync; sync_all_data || true
3341 echo "Verify space usage is increased"
3342 USED=$(getquota -u $TSTID global curspace)
3343 [ $USED -gt $ORIG_USR_SPACE ] ||
3344 error "Used space for user $TSTID isn't increased" \
3345 "orig:$ORIG_USR_SPACE, now:$USED"
3346 USED=$(getquota -g $TSTID global curspace)
3347 [ $USED -gt $ORIG_GRP_SPACE ] ||
3348 error "Used space for group $TSTID isn't increased" \
3349 "orig:$ORIG_GRP_SPACE, now:$USED"
3350 if [ $project_supported == "yes" ]; then
3351 USED=$(getquota -p $TSTPRJID global curspace)
3352 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3353 error "Used space for project $TSTPRJID isn't " \
3354 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3359 run_test 35 "Usage is still accessible across reboot"
3361 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3364 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3365 skip "Old server doesn't have LU-5006 fix."
3367 setup_quota_test || error "setup quota failed with $?"
3368 trap cleanup_quota_test EXIT
3370 # make sure the system is clean
3371 local USED=$(getquota -u $TSTID global curspace)
3373 error "Used space ($USED) for user $TSTID isn't 0."
3375 # create file with MDS_OPEN_DELAY_CREATE flag
3376 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3377 error "Create file failed"
3379 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3380 oflag=sync || error "Write file failed"
3382 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3384 # wait for setattr on objects finished..."
3385 wait_delete_completed
3387 USED=$(getquota -u $TSTID global curspace)
3388 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3392 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3396 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3397 skip "Old server doesn't have LU-8801 fix."
3399 [ "$UID" != 0 ] && skip_env "must run as root" && return
3401 setup_quota_test || error "setup quota failed with $?"
3402 trap cleanup_quota_test EXIT
3404 # make sure the system is clean
3405 local USED=$(getquota -u $TSTID global curspace)
3407 error "Used space ($USED) for user $TSTID isn't 0."
3408 USED=$(getquota -u $TSTID2 global curspace)
3410 error "Used space ($USED) for user $TSTID2 isn't 0."
3412 local TESTFILE="$DIR/$tdir/$tfile"
3413 local file_cnt=10000
3415 # Generate id entries in accounting file
3416 echo "Create $file_cnt files..."
3417 for i in `seq $file_cnt`; do
3419 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3420 error "failed to chown $TESTFILE-$i"
3422 cancel_lru_locks osc
3423 sync; sync_all_data || true
3425 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3426 procf=${procf}.quota_slave.acct_user
3429 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3430 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3431 echo "Found $acct_cnt id entries"
3433 [ $file_cnt -eq $acct_cnt ] || {
3434 do_facet mds1 $LCTL get_param $procf
3435 error "skipped id entries"
3440 run_test 38 "Quota accounting iterator doesn't skip id entries"
3443 local TESTFILE="$DIR/$tdir/project"
3444 ! is_project_quota_supported &&
3445 skip "Project quota is not supported"
3447 setup_quota_test || error "setup quota failed with $?"
3450 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3451 [ $projectid -ne 0 ] &&
3452 error "Project id should be 0 not $projectid"
3453 change_project -p 1024 $TESTFILE
3454 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3455 [ $projectid -ne 1024 ] &&
3456 error "Project id should be 1024 not $projectid"
3458 stopall || error "failed to stopall (1)"
3461 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3462 [ $projectid -ne 1024 ] &&
3463 error "Project id should be 1024 not $projectid"
3467 run_test 39 "Project ID interface works correctly"
3470 ! is_project_quota_supported &&
3471 skip "Project quota is not supported"
3472 local dir1="$DIR/$tdir/dir1"
3473 local dir2="$DIR/$tdir/dir2"
3475 setup_quota_test || error "setup quota failed with $?"
3477 mkdir -p $dir1 $dir2
3478 change_project -sp 1 $dir1 && touch $dir1/1
3479 change_project -sp 2 $dir2
3481 ln $dir1/1 $dir2/1_link &&
3482 error "Hard link across different project quota should fail"
3487 run_test 40a "Hard link across different project ID"
3490 ! is_project_quota_supported &&
3491 skip "Project quota is not supported"
3492 local dir1="$DIR/$tdir/dir1"
3493 local dir2="$DIR/$tdir/dir2"
3495 setup_quota_test || error "setup quota failed with $?"
3496 mkdir -p $dir1 $dir2
3497 change_project -sp 1 $dir1 && touch $dir1/1
3498 change_project -sp 2 $dir2
3500 mv $dir1/1 $dir2/2 || error "mv failed $?"
3501 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3502 if [ "$projid" != "2" ]; then
3503 error "project id expected 2 not $projid"
3508 run_test 40b "Mv across different project ID"
3511 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3512 ! is_project_quota_supported &&
3513 skip "Project quota is not supported"
3515 setup_quota_test || error "setup quota failed with $?"
3516 local dir="$DIR/$tdir/dir"
3518 mkdir -p $dir && change_project -sp 1 $dir
3519 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3520 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3521 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3522 touch $dir/remote_dir/file
3523 #verify inherit works file for remote dir.
3524 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3525 [ "$projid" != "1" ] &&
3526 error "file under remote dir expected 1 not $projid"
3528 #Agent inode should be ignored for project quota
3529 USED=$(getquota -p 1 global curinodes)
3530 [ "$USED" != "3" ] &&
3531 error "file count expected 3 got $USED"
3537 run_test 40c "Remote child Dir inherit project quota properly"
3540 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3541 is_project_quota_supported || skip "Project quota is not supported"
3543 setup_quota_test || error "setup quota failed with $?"
3544 local dir="$DIR/$tdir/dir"
3547 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3548 change_project -sp $TSTPRJID $dir ||
3549 error "change project on $dir failed"
3550 for i in $(seq 5); do
3551 mkdir -p $dir/d$i/d$i ||
3552 error "mkdir $dir/d$i/d$i failed"
3553 local projid=$($LFS project -d $dir/d$i/d$i |
3555 [ "$projid" == "$TSTPRJID" ] ||
3556 error "projid id expected $TSTPRJID not $projid"
3557 touch $dir/d$i/d$i/file
3558 #verify inherit works file for stripe dir.
3559 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3560 [ "$projid" == "$TSTPRJID" ] ||
3561 error "file under remote dir expected 1 not $projid"
3564 # account should be 1 + (2 + 1) *10 + 1 * 5
3565 USED=$(getquota -p $TSTPRJID global curinodes)
3566 [ "$USED" == "36" ] ||
3567 error "file count expected 36 got $USED"
3572 run_test 40d "Stripe Directory inherit project quota properly"
3575 is_project_quota_supported ||
3576 skip "Project quota is not supported"
3577 setup_quota_test || error "setup quota failed with $?"
3578 trap cleanup_quota_test EXIT
3579 local dir="$DIR/$tdir/dir"
3582 local projid=$((testnum * 1000))
3586 # enable mdt/ost quota
3587 set_mdt_qtype ugp || error "enable mdt quota failed"
3588 set_ost_qtype ugp || error "enable ost quota failed"
3590 test_mkdir -p $dir && change_project -sp $projid $dir
3591 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3592 error "set project quota failed"
3597 # check if df output works as expected
3598 echo "== global statfs: $MOUNT =="
3599 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3601 echo "== project statfs (prjid=$projid): $dir =="
3602 df -kP $dir; df -iP $dir
3603 local bused=$(getquota -p $projid global curspace)
3604 local iused=$(getquota -p $projid global curinodes)
3605 # note trailing space to match double printf from awk
3606 local expected="$blimit $bused $ilimit $iused "
3608 wait_update $HOSTNAME \
3609 "{ df -kP $dir; df -iP $dir; } |
3610 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3612 error "failed to get correct statfs for project quota"
3616 run_test 41 "df should return projid-specific values"
3619 ! is_project_quota_supported &&
3620 skip "Project quota is not supported"
3622 setup_quota_test || error "setup quota failed with $?"
3623 local dir1="$DIR/$tdir/dir1"
3624 local dir2="$DIR/$tdir/dir2"
3626 mkdir -p $dir1 && change_project -sp 1 $dir1
3627 mkdir -p $dir2 && change_project -sp 2 $dir2
3628 for num in $(seq 1 10); do
3629 touch $dir1/file_$num $dir2/file_$num
3630 ln -s $dir1/file_$num $dir1/file_$num"_link"
3631 ln -s $dir2/file_$num $dir2/file_$num"_link"
3634 count=$($LFS find --projid 1 $DIR | wc -l)
3635 [ "$count" != 21 ] && error "expected 21 but got $count"
3637 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3638 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3639 [ "$count" != 22 ] && error "expected 22 but got $count"
3644 run_test 50 "Test if lfs find --projid works"
3647 ! is_project_quota_supported &&
3648 skip "Project quota is not supported"
3649 setup_quota_test || error "setup quota failed with $?"
3650 local dir="$DIR/$tdir/dir"
3652 mkdir $dir && change_project -sp 1 $dir
3653 local used=$(getquota -p 1 global curinodes)
3654 [ $used != "1" ] && error "expected 1 got $used"
3659 used=$(getquota -p 1 global curinodes)
3660 [ $used != "4" ] && error "expected 4 got $used"
3662 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3664 cp $DIR/$tdir/6 $dir/6
3665 used=$(getquota -p 1 global curinodes)
3666 [ $used != "5" ] && error "expected 5 got $used"
3669 mv $DIR/$tdir/6 $dir/7
3670 used=$(getquota -p 1 global curinodes)
3671 [ $used != "6" ] && error "expected 6 got $used"
3676 run_test 51 "Test project accounting with mv/cp"
3679 ! is_project_quota_supported &&
3680 skip "Project quota is not supported"
3681 setup_quota_test || error "setup quota failed with $?"
3682 local dir="$DIR/$tdir/dir"
3683 mkdir $dir && change_project -sp 1 $dir
3685 touch $DIR/$tdir/file
3686 #Try renaming a file into the project. This should fail.
3687 for num in $(seq 1 2000); do
3688 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3689 error "rename should fail"
3694 run_test 52 "Rename across different project ID"
3697 ! is_project_quota_supported &&
3698 skip "Project quota is not supported"
3699 setup_quota_test || error "setup quota failed with $?"
3700 local dir="$DIR/$tdir/dir"
3701 mkdir $dir && change_project -s $dir
3702 lfs project -d $dir | grep P || error "inherit attribute should be set"
3704 change_project -C $dir
3705 lfs project -d $dir | grep P &&
3706 error "inherit attribute should be cleared"
3711 run_test 53 "Project inherit attribute could be cleared"
3714 ! is_project_quota_supported &&
3715 skip "Project quota is not supported"
3716 setup_quota_test || error "setup quota failed with $?"
3717 trap cleanup_quota_test EXIT
3718 local testfile="$DIR/$tdir/$tfile-0"
3720 #set project ID/inherit attribute
3721 change_project -sp $TSTPRJID $DIR/$tdir
3722 $RUNAS createmany -m ${testfile} 100 ||
3723 error "create many files failed"
3725 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3726 # one more count for directory itself */
3730 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3731 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3733 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3734 [ $proj_count1 -eq $proj_count ] ||
3735 error "c2: expected $proj_count got $proj_count1"
3737 #clear project but with kept projid
3738 change_project -rCk $DIR/$tdir
3739 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3740 [ $proj_count1 -eq 1 ] ||
3741 error "c3: expected 1 got $proj_count1"
3743 #verify projid untouched.
3744 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3746 [ $proj_count1 -eq $proj_count ] ||
3747 error "c4: expected $proj_count got $proj_count1"
3750 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3751 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3752 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3754 #this time clear all
3755 change_project -rC $DIR/$tdir
3756 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3757 [ $proj_count1 -eq 0 ] ||
3758 error "c6: expected 0 got $proj_count1"
3760 unlinkmany ${testfile} 100 ||
3761 error "unlink many files failed"
3765 run_test 54 "basic lfs project interface test"
3768 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3769 skip "Not supported before 2.10.58."
3770 setup_quota_test || error "setup quota failed with $?"
3772 set_ost_qtype $QTYPE || error "enable ost quota failed"
3775 #add second group to TSTUSR
3776 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3779 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3780 error "failed to dd"
3782 cancel_lru_locks osc
3783 sync; sync_all_data || true
3785 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3786 error "failed to setquota on group $TSTUSR2"
3788 $LFS quota -v -g $TSTUSR2 $DIR
3790 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3791 error "chgrp should failed with -EDQUOT"
3793 USED=$(getquota -g $TSTUSR2 global curspace)
3796 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3797 error "failed to setquota on group $TSTUSR2"
3799 $LFS quota -v -g $TSTUSR2 $DIR
3801 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3802 error "chgrp should succeed"
3804 $LFS quota -v -g $TSTUSR2 $DIR
3808 run_test 55 "Chgrp should be affected by group quota"
3811 setup_quota_test || error "setup quota failed with $?"
3813 set_ost_qtype $QTYPE || error "enable ost quota failed"
3816 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3817 erro "failed to set grace time for usr quota"
3818 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3819 awk '{print $4 $8}')
3820 if [ "x$grace_time" != "x10s;10s" ]; then
3821 $LFS quota -t -u $DIR
3822 error "expected grace time: 10s;10s, got:$grace_time"
3827 run_test 56 "lfs quota -t should work well"
3830 setup_quota_test || error "setup quota failed with $?"
3832 local dir="$DIR/$tdir/dir"
3835 #try to change pipe file should not hang and return failure
3836 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3837 awk -F ':' '{ print \\\$2 }'" \
3838 " unable to get xattr for fifo '$dir/pipe'" || return 1
3839 #command can process further if it hit some errors
3840 touch $dir/aaa $dir/bbb
3841 mkdir $dir/subdir -p
3842 touch $dir/subdir/aaa $dir/subdir/bbb
3843 #create one invalid link file
3844 ln -s $dir/not_exist_file $dir/ccc
3845 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3846 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3850 run_test 57 "lfs project could tolerate errors"
3853 [ "$mds1_FSTYPE" != ldiskfs ] &&
3854 skip "ldiskfs only test"
3855 disable_project_quota
3856 setup_quota_test || error "setup quota failed with $?"
3859 local testfile="$DIR/$tdir/$tfile-0"
3860 #make sure it did not crash kernel
3861 touch $testfile && lfs project -sp 1 $testfile
3863 enable_project_quota
3866 run_test 59 "lfs project dosen't crash kernel with project disabled"
3869 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3870 skip "Needs MDS version 2.11.53 or later."
3871 setup_quota_test || error "setup quota failed with $?"
3872 trap cleanup_quota_test EXIT
3874 local testfile=$DIR/$tdir/$tfile
3877 set_mdt_qtype "ug" || error "enable mdt quota failed"
3879 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3880 error "set quota failed"
3881 quota_show_check a g $TSTUSR
3883 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3884 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3885 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3886 error "create many files failed"
3888 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3890 # root user can overrun quota
3891 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3892 error "root user should succeed"
3896 run_test 60 "Test quota for root with setgid"
3898 # test default quota
3899 test_default_quota() {
3900 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3901 skip "Not supported before 2.11.51."
3906 local qprjid=$TSTPRJID
3910 local LIMIT=20480 #20M disk space
3911 local TESTFILE="$DIR/$tdir/$tfile-0"
3913 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3914 echo "Project quota is not supported" && return 0
3916 [ $qtype == "-u" ] && qdtype="-U"
3917 [ $qtype == "-g" ] && qdtype="-G"
3918 [ $qtype == "-p" ] && {
3923 [ $qpool == "meta" ] && {
3924 LIMIT=10240 #10K inodes
3929 setup_quota_test || error "setup quota failed with $?"
3930 trap cleanup_quota_test EXIT
3934 # enable mdt/ost quota
3935 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3936 set_ost_qtype $QTYPE || error "enable ost quota failed"
3938 log "set to use default quota"
3939 $LFS setquota $qtype $qid -d $DIR ||
3940 error "set $qid to use default quota failed"
3942 log "set default quota"
3943 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3944 error "set $qid default quota failed"
3946 log "get default quota"
3947 $LFS quota $qdtype $DIR || error "get default quota failed"
3949 if [ $qpool == "data" ]; then
3950 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3952 [ $SLIMIT -eq $LIMIT ] ||
3953 error "the returned default quota is wrong"
3955 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3957 [ $SLIMIT -eq $LIMIT ] ||
3958 error "the returned default quota is wrong"
3961 # make sure the system is clean
3962 local USED=$(getquota $qtype $qid global curspace)
3963 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3965 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3966 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3968 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3970 log "Test not out of quota"
3971 if [ $qpool == "data" ]; then
3972 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3973 quota_error $qtype $qid "write failed, expect succeed"
3975 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3976 quota_error $qtype $qid "create failed, expect succeed"
3978 unlinkmany $TESTFILE $((LIMIT/2))
3981 log "Test out of quota"
3982 # flush cache, ensure noquota flag is set on client
3983 cancel_lru_locks osc
3984 cancel_lru_locks mdc
3985 sync; sync_all_data || true
3986 if [ $qpool == "data" ]; then
3987 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3988 quota_error $qtype $qid "write succeed, expect EDQUOT"
3990 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3991 quota_error $qtype $qid "create succeed, expect EDQUOT"
3993 unlinkmany $TESTFILE $((LIMIT*2))
3996 log "Increase default quota"
3998 # LU-4505: sleep 5 seconds to enable quota acquire
4001 # increase default quota
4002 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
4003 error "set default quota failed"
4005 cancel_lru_locks osc
4006 cancel_lru_locks mdc
4007 sync; sync_all_data || true
4008 if [ $qpool == "data" ]; then
4009 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4010 quota_error $qtype $qid "write failed, expect succeed"
4012 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4013 quota_error $qtype $qid "create failed, expect succeed"
4015 unlinkmany $TESTFILE $((LIMIT*2))
4018 log "Set quota to override default quota"
4019 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4020 error "set $qid quota failed"
4022 cancel_lru_locks osc
4023 cancel_lru_locks mdc
4024 sync; sync_all_data || true
4025 if [ $qpool == "data" ]; then
4026 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4027 quota_error $qtype $qid "write succeed, expect EQUOT"
4029 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4030 quota_error $qtype $qid "create succeed, expect EQUOT"
4032 unlinkmany $TESTFILE $((LIMIT*2))
4035 log "Set to use default quota again"
4037 # LU-4505: sleep 5 seconds to enable quota acquire
4040 $LFS setquota $qtype $qid -d $DIR ||
4041 error "set $qid to use default quota failed"
4043 cancel_lru_locks osc
4044 cancel_lru_locks mdc
4045 sync; sync_all_data || true
4046 if [ $qpool == "data" ]; then
4047 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4048 quota_error $qtype $qid "write failed, expect succeed"
4050 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4051 quota_error $qtype $qid "create failed, expect succeed"
4053 unlinkmany $TESTFILE $((LIMIT*2))
4058 wait_delete_completed || error "wait_delete_completed failed"
4059 sync_all_data || true
4060 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
4061 error "reset default quota failed"
4062 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
4063 error "reset quota failed"
4069 test_default_quota "-u" "data"
4070 test_default_quota "-u" "meta"
4071 test_default_quota "-g" "data"
4072 test_default_quota "-g" "meta"
4073 test_default_quota "-p" "data"
4074 test_default_quota "-p" "meta"
4076 run_test 61 "default quota tests"
4079 ! is_project_quota_supported &&
4080 skip "Project quota is not supported"
4081 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
4082 skip "chattr did not support project quota"
4083 setup_quota_test || error "setup quota failed with $?"
4084 local testdir=$DIR/$tdir/
4086 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4087 change_project -s $testdir
4088 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4089 error "inherit attribute should be set"
4090 # chattr used FS_IOC_SETFLAGS ioctl
4091 $RUNAS chattr -P $testdir &&
4092 error "regular user clear inherit should fail"
4093 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4094 error "inherit attribute should still be set"
4095 chattr -P $testdir || error "root failed to clear inherit"
4096 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4097 error "inherit attribute should be cleared"
4100 run_test 62 "Project inherit should be only changed by root"
4103 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4104 skip "Not supported before 2.11.55"
4108 local dd_failed=false
4109 local tdir_dom=${tdir}_dom
4110 local LIMIT=20480 #20M
4112 [ $qtype == "p" ] && ! is_project_quota_supported &&
4113 echo "Project quota is not supported" && return 0
4115 [ $qtype == "p" ] && qid=$TSTPRJID
4117 setup_quota_test || error "setup quota failed with $?"
4118 trap cleanup_quota_test EXIT
4122 # enable mdt/ost quota
4123 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4124 set_ost_qtype $QTYPE || error "enable ost quota failed"
4126 # make sure the system is clean
4127 local USED=$(getquota -$qtype $qid global curspace)
4128 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4130 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4132 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4133 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4134 error "setstripe $tdir_dom failed"
4135 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4137 [ $qtype == "p" ] && {
4138 change_project -sp $TSTPRJID $DIR/$tdir
4139 change_project -sp $TSTPRJID $DIR/$tdir_dom
4142 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4143 error "set $qid quota failed"
4145 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4146 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4150 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4152 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4153 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4157 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4159 rm -f $DIR/$tdir_dom/*
4161 # flush cache, ensure noquota flag is set on client
4162 cancel_lru_locks osc
4163 cancel_lru_locks mdc
4164 sync; sync_all_data || true
4168 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4169 quota_error $qtype $qid "write failed, expect succeed"
4171 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4172 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4176 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4179 rm -f $DIR/$tdir_dom/*
4181 # flush cache, ensure noquota flag is set on client
4182 cancel_lru_locks osc
4183 cancel_lru_locks mdc
4184 sync; sync_all_data || true
4188 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4189 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4193 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4195 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4196 quota_error $qtype $qid "write succeed, expect EDQUOT"
4199 rm -fr $DIR/$tdir_dom
4201 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4202 error "reset usr quota failed"
4212 run_test 63 "quota on DoM tests"
4215 ! is_project_quota_supported &&
4216 skip "Project quota is not supported"
4217 setup_quota_test || error "setup quota failed with $?"
4218 local dir1="$DIR/$tdir/"
4221 ln -s $dir1/file $dir1/file_link
4223 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4224 error "set symlink file's project should fail"
4226 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4227 error "get symlink file's project should fail"
4231 run_test 64 "lfs project on symlink files should fail"
4235 local TESTFILE="$DIR/$tdir/$tfile-0"
4237 setup_quota_test || error "setup quota failed with $?"
4238 set_ost_qtype $QTYPE || error "enable ost quota failed"
4242 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4243 error "failed to write"
4244 # flush cache, ensure noquota flag is set on client
4245 cancel_lru_locks osc
4246 sync; sync_all_data || true
4248 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4249 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4250 local quota_all=$($RUNAS $LFS quota $DIR)
4252 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4253 error "usr quota not match"
4254 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4255 error "grp quota not match"
4261 run_test 65 "Check lfs quota result"
4264 ! is_project_quota_supported &&
4265 skip "Project quota is not supported"
4266 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4267 skip "Not supported before 2.12.4"
4268 setup_quota_test || error "setup quota failed with $?"
4269 stack_trap cleanup_quota_test EXIT
4270 local old=$(do_facet mds1 $LCTL get_param -n \
4271 mdt.*.enable_chprojid_gid | head -1)
4272 local testdir=$DIR/$tdir/foo
4274 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4275 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4278 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4279 chown -R $TSTID:$TSTID $testdir
4280 change_project -sp $TSTPRJID $testdir
4281 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4283 $RUNAS lfs project -p 0 $testdir/foo &&
4284 error "nonroot user should fail to set projid"
4286 $RUNAS lfs project -C $testdir/foo &&
4287 error "nonroot user should fail to clear projid"
4289 change_project -C $testdir/foo || error "failed to clear project"
4291 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4292 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4293 "failed to set projid with normal user when enable_chprojid_gid=-1"
4295 $RUNAS lfs project -rC $testdir/ || error \
4296 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4298 touch $testdir/bar || error "failed touch $testdir/bar"
4299 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4300 "normal user should not be able to set projid on root owned file"
4302 change_project -p $TSTPRJID $testdir/bar || error \
4303 "root should be able to change its own file's projid"
4307 run_test 66 "nonroot user can not change project state in default"
4314 local short_qtype=${qtype:0:1}
4317 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4319 quota_usr) _runas=$RUNAS;;
4320 quota_2usr) _runas=$RUNAS2;;
4321 *) error "unknown quota parameter $4";;
4326 $_runas $DD of=$file count=$size ||
4327 quota_error $short_qtype $TSTUSR \
4328 "$qtype write failure, but expect success"
4330 cancel_lru_locks osc
4332 sync; sync_all_data || true
4341 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4343 do_facet mds1 $LCTL get_param $param |
4344 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4348 local limit=20 # 20M
4349 local testfile="$DIR/$tdir/$tfile-0"
4350 local testfile2="$DIR/$tdir/$tfile-1"
4351 local testfile3="$DIR/$tdir/$tfile-2"
4352 local qpool="qpool1"
4358 [ "$ost1_FSTYPE" == zfs ] &&
4359 skip "ZFS grants some block space together with inode"
4361 setup_quota_test || error "setup quota failed with $?"
4362 trap cleanup_quota_test EXIT
4365 set_ost_qtype $QTYPE || error "enable ost quota failed"
4368 log "User quota (block hardlimit:$limit MB)"
4369 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4370 error "set user quota failed"
4372 # make sure the system is clean
4373 used=$(getquota -u $TSTUSR global curspace)
4374 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4376 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4377 echo "granted 0x0 before write $granted"
4379 # trigger reintegration
4380 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4381 procf=${procf}quota_slave.force_reint
4382 do_facet ost1 $LCTL set_param $procf=1 ||
4383 error "force reintegration failed"
4384 wait_ost_reint "u" || error "reintegration failed"
4385 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4386 [ $granted -ne 0 ] &&
4387 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4389 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4390 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4392 # write 10 MB to testfile
4393 test_67_write "$testfile" "user" 10 "quota_usr"
4395 # create qpool and add OST1
4396 pool_add $qpool || error "pool_add failed"
4397 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4398 # as quota_usr hasn't limits, lqe may absent. But it should be
4399 # created after the 1st direct qmt_get.
4400 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4402 # check granted - should be 0, as testfile is located only on OST0
4403 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4404 echo "global granted $granted"
4405 granted=$(getgranted $qpool "dt" $TSTID "usr")
4406 echo "$qpool granted $granted"
4407 [ $granted -ne 0 ] &&
4408 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4410 # add OST0 to qpool and check granted space
4411 pool_add_targets $qpool 0 1 ||
4412 error "pool_add_targets failed"
4413 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4414 echo "Granted $granted_mb MB"
4415 #should be 10M + qunit for each OST
4416 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4417 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4419 $LFS setstripe $testfile2 -c 1 -i 1 ||
4420 error "setstripe $testfile2 failed"
4421 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4422 # Write from another user and check that qpool1
4423 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4424 test_67_write "$testfile2" "user" 10 "quota_2usr"
4425 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4426 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4427 [ $granted -ne 0 ] &&
4428 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4430 # Granted space for quota_2usr in qpool1 should appear only
4431 # when global lqe for this user becomes enforced.
4432 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4433 error "set user quota failed"
4434 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4435 echo "granted_mb $granted_mb"
4436 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4437 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4439 $LFS setstripe $testfile3 -c 1 -i 0 ||
4440 error "setstripe $testfile3 failed"
4441 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4442 test_67_write "$testfile3" "user" 10 "quota_2usr"
4443 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4444 echo "$testfile3 granted_mb $granted_mb"
4445 [ $granted_mb -eq $limit ] ||
4446 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4448 # remove OST1 from the qpool1 and check granted space
4449 # should be 0 for TSTUSR and 10M for TSTUSR2
4450 pool_remove_target $qpool 0
4451 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4452 [ $granted_mb -eq 0 ] ||
4453 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4454 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4455 [ $granted_mb -eq 10 ] ||
4456 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4459 wait_delete_completed || error "wait_delete_completed failed"
4460 sync_all_data || true
4461 used=$(getquota -u $TSTUSR global curspace)
4462 [ $used -ne 0 ] && quota_error u $TSTUSR \
4463 "user quota isn't released after deletion"
4464 resetquota -u $TSTUSR
4468 run_test 67 "quota pools recalculation"
4475 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4476 awk '/usr/ {getline; print $2}'
4481 local qpool="qpool1"
4484 setup_quota_test || error "setup quota failed with $?"
4485 stack_trap cleanup_quota_test EXIT
4488 set_ost_qtype $QTYPE || error "enable ost quota failed"
4490 # check slave number for glbal pool
4491 local nr=$(get_slave_nr "0x0" "usr")
4492 echo "nr result $nr"
4493 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4494 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4496 # create qpool and add OST1
4497 pool_add $qpool || error "pool_add failed"
4498 nr=$(get_slave_nr $qpool "usr")
4499 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4502 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4503 nr=$(get_slave_nr $qpool "usr")
4504 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4507 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4508 nr=$(get_slave_nr $qpool "usr")
4509 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4512 pool_remove_target $qpool 0
4513 nr=$(get_slave_nr $qpool "usr")
4514 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4517 pool_remove_target $qpool 1
4518 nr=$(get_slave_nr $qpool "usr")
4519 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4521 # Check again that all is fine with global pool
4522 nr=$(get_slave_nr "0x0" "usr")
4523 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4524 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4528 run_test 68 "slave number in quota pool changed after each add/remove OST"
4532 local global_limit=200 # 200M
4533 local limit=10 # 10M
4534 local testfile="$DIR/$tdir/$tfile-0"
4535 local dom0="$DIR/$tdir/dom0"
4536 local qpool="qpool1"
4539 setup_quota_test || error "setup quota failed with $?"
4540 stack_trap cleanup_quota_test EXIT
4543 set_ost_qtype $QTYPE || error "enable ost quota failed"
4544 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4546 # Save DOM only at MDT0
4547 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4548 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4550 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4552 # create qpool and add OST0
4553 pool_add $qpool || error "pool_add failed"
4554 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4556 log "User quota (block hardlimit:$global_limit MB)"
4557 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4558 error "set user quota failed"
4560 log "User quota (block hardlimit:$limit MB)"
4561 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4562 error "set user quota failed"
4564 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4565 quota_error u $TSTUSR "write failed"
4567 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4568 oflag=sync || quota_error u $TSTUSR "write failed"
4570 $RUNAS $DD of=$testfile count=$limit || true
4572 # flush cache, ensure noquota flag is set on client
4573 cancel_lru_locks osc
4574 sync; sync_all_data || true
4576 # MDT0 shouldn't get EDQUOT with glimpse.
4577 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4578 quota_error u $TSTUSR \
4579 "user write success, but expect EDQUOT"
4581 # Now all members of qpool1 should get EDQUOT. Expect success
4582 # when write to DOM on MDT0, as it belongs to global pool.
4583 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4584 oflag=sync || quota_error u $TSTUSR "write failed"
4586 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4587 oflag=sync || quota_error u $TSTUSR "write failed"
4591 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4595 local qpool="qpool1"
4600 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4601 skip "Needs a client >= $VERSION_WITH_QP"
4603 setup_quota_test || error "setup quota failed with $?"
4604 stack_trap cleanup_quota_test EXIT
4606 # MDS returns EFAULT for unsupported quotactl command
4607 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4609 # create qpool and add OST0
4610 pool_add $qpool || error "pool_add failed"
4611 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4613 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4615 [ $rc -eq $err ] || error "setquota res $rc != $err"
4617 # If MDS supports QP, check that limit was set properly.
4618 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4619 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4620 echo "hard limit $bhard limit $limit"
4621 [ $bhard -ne $((limit*1024)) ] &&
4622 error "bhard:$bhard for $qpool!=$((limit*1024))"
4625 $LFS quota -u $TSTUSR --pool $qpool $DIR
4627 [ $rc -eq $err ] || error "quota res $rc != $err"
4631 run_test 70 "check lfs setquota/quota with a pool option"
4635 local limit=10 # 10M
4636 local global_limit=100 # 100M
4637 local testfile="$DIR/$tdir/$tfile-0"
4638 local qpool="qpool1"
4639 local qpool2="qpool2"
4641 [ "$ost1_FSTYPE" == zfs ] &&
4642 skip "ZFS grants some block space together with inode"
4643 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4645 setup_quota_test || error "setup quota failed with $?"
4646 stack_trap cleanup_quota_test EXIT
4649 set_ost_qtype $QTYPE || error "enable ost quota failed"
4652 log "User quota (block hardlimit:$global_limit MB)"
4653 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4654 error "set user quota failed"
4656 pool_add $qpool || error "pool_add failed"
4657 pool_add_targets $qpool 0 1 ||
4658 error "pool_add_targets failed"
4660 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4661 error "set user quota failed"
4663 pool_add $qpool2 || error "pool_add failed"
4664 pool_add_targets $qpool2 1 1 ||
4665 error "pool_add_targets failed"
4667 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4668 error "set user quota failed"
4670 # make sure the system is clean
4671 local used=$(getquota -u $TSTUSR global curspace)
4674 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4676 # create 1st component 1-10M
4677 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4678 #create 2nd component 10-30M
4679 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4680 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4682 # сheck normal use and out of quota with PFL
4683 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4684 test_1_check_write $testfile "user" $((limit*2))
4686 wait_delete_completed || error "wait_delete_completed failed"
4687 sync_all_data || true
4688 used=$(getquota -u $TSTUSR global curspace)
4689 [ $used -ne 0 ] && quota_error u $TSTUSR \
4690 "user quota isn't released after deletion"
4692 # create 1st component 1-10M
4693 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4694 # create 2nd component 10-30M
4695 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4696 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4698 # write to the 2nd component
4699 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4700 quota_error u $TSTUSR \
4701 "write failure, but expect success"
4702 # this time maybe cache write, ignore it's failure
4703 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4704 cancel_lru_locks osc
4705 sync; sync_all_data || true
4706 # write over limit in qpool2(2nd component 10-30M)
4707 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4708 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4709 # write to the 1st component - OST0 is empty
4710 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4711 quota_error u $TSTUSR "write failed"
4715 run_test 71a "Check PFL with quota pools"
4719 local global_limit=1000 # 1G
4720 local limit1=160 # 160M
4721 local limit2=10 # 10M
4722 local testfile="$DIR/$tdir/$tfile-0"
4723 local qpool="qpool1"
4724 local qpool2="qpool2"
4726 [ "$ost1_FSTYPE" == zfs ] &&
4727 skip "ZFS grants some block space together with inode"
4728 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4730 setup_quota_test || error "setup quota failed with $?"
4731 stack_trap cleanup_quota_test EXIT
4734 set_ost_qtype $QTYPE || error "enable ost quota failed"
4737 log "User quota (block hardlimit:$global_limit MB)"
4738 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4739 error "set user quota failed"
4741 pool_add $qpool || error "pool_add failed"
4742 pool_add_targets $qpool 0 1 ||
4743 error "pool_add_targets failed"
4745 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4746 error "set user quota failed"
4748 pool_add $qpool2 || error "pool_add failed"
4749 pool_add_targets $qpool2 1 1 ||
4750 error "pool_add_targets failed"
4752 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4753 error "set user quota failed"
4755 # make sure the system is clean
4756 local used=$(getquota -u $TSTUSR global curspace)
4759 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4761 # First component is on OST0, 2nd on OST1
4762 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4763 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4765 # fill the 1st component on OST0
4766 $RUNAS $DD of=$testfile count=128 ||
4767 quota_error u $TSTUSR "write failed"
4768 # write to the 2nd cmpnt on OST1
4769 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4770 quota_error u $TSTUSR "write failed"
4771 # this time maybe cache write, ignore it's failure
4772 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4774 cancel_lru_locks osc
4775 sync; sync_all_data || true
4776 # write over limit in qpool2
4777 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4778 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4782 run_test 71b "Check SEL with quota pools"
4786 local limit=10 # 10M
4787 local global_limit=50 # 50M
4788 local testfile="$DIR/$tdir/$tfile-0"
4789 local qpool="qpool1"
4792 setup_quota_test || error "setup quota failed with $?"
4793 stack_trap cleanup_quota_test EXIT
4796 set_ost_qtype $QTYPE || error "enable ost quota failed"
4799 log "User quota (block hardlimit:$global_limit MB)"
4800 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4801 error "set user quota failed"
4803 pool_add $qpool || error "pool_add failed"
4804 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4806 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4807 error "set user quota failed"
4809 # make sure the system is clean
4810 local used=$(getquota -u $TSTUSR global curspace)
4812 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4814 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4816 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4817 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4818 test_1_check_write $testfile "user" $limit
4819 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4821 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4822 # check that lfs quota -uv --pool prints only OST that
4823 # was added in a pool
4824 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4825 grep "OST\|MDT" && error "$qpool consists wrong targets"
4829 run_test 72 "lfs quota --pool prints only pool's OSTs"
4833 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4834 if $PQ_CLEANUP; then
4835 disable_project_quota
4838 reset_quota_settings
4843 check_and_cleanup_lustre
4844 export QUOTA_AUTO=$QUOTA_AUTO_OLD