3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 # 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.enabled=$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.enabled=$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_on_mdt0 $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
411 stack_trap cleanup_quota_test EXIT
414 cleanup_quota_test() {
415 echo "Delete files..."
417 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
418 echo "Wait for unlink objects finished..."
419 wait_delete_completed
420 sync_all_data || true
430 $LFS quota -v -$ugp $qid $DIR
432 if [ "$bf" == "a" -o "$bf" == "b" ]; then
433 usage=$(getquota -$ugp $qid global curspace)
434 if [ -z $usage ]; then
435 quota_error $ugp $qid \
436 "Query block quota failed ($ugp:$qid)."
438 [ $usage -ne 0 ] && quota_log $ugp $qid \
439 "Block quota isn't 0 ($ugp:$qid:$usage)."
443 if [ "$bf" == "a" -o "$bf" == "f" ]; then
444 usage=$(getquota -$ugp $qid global curinodes)
445 if [ -z $usage ]; then
446 quota_error $ugp $qid \
447 "Query file quota failed ($ugp:$qid)."
449 [ $usage -ne 0 ] && quota_log $ugp $qid \
450 "File quota isn't 0 ($ugp:$qid:$usage)."
455 project_quota_enabled () {
457 local zfeat="feature@project_quota"
459 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
460 local facet_fstype=${facet:0:3}1_FSTYPE
463 if [ "${!facet_fstype}" = "zfs" ]; then
464 devname=$(zpool_name ${facet})
465 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
466 grep -wq active || rc=1
468 [ ${facet:0:3} == "mds" ] &&
469 devname=$(mdsdevname ${facet:3}) ||
470 devname=$(ostdevname ${facet:3})
471 do_facet ${facet} $DEBUGFS -R features $devname |
472 grep -q project || rc=1
475 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
479 project_quota_enabled || enable_project_quota
481 reset_quota_settings() {
482 resetquota -u $TSTUSR
484 resetquota -g $TSTUSR
486 resetquota -u $TSTUSR2
487 resetquota -u $TSTID2
488 resetquota -g $TSTUSR2
489 resetquota -g $TSTID2
490 resetquota -p $TSTPRJID
495 do_nodes $(comma_list $(nodes_list)) \
496 "$LCTL set_param -n debug=+quota,trace"
501 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
502 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
503 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
504 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
506 test_quota_performance() {
507 local TESTFILE="$DIR/$tdir/$tfile-0"
508 local size=$1 # in MB
509 local stime=$(date +%s)
510 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
511 quota_error u $TSTUSR "write failure"
512 local etime=$(date +%s)
513 delta=$((etime - stime))
514 if [ $delta -gt 0 ]; then
515 rate=$((size * 1024 / delta))
516 if [ "$mds1_FSTYPE" = zfs ]; then
517 # LU-2872 - see LU-2887 for fix
519 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
521 [ $rate -gt 1024 ] ||
522 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
528 # test basic quota performance b=21696
531 [ "$SLOW" = "no" ] && MB=10
533 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
534 [ $free_space -le $((MB * 1024)) ] &&
535 skip "not enough space ${free_space} KB, " \
536 "required $((MB * 1024)) KB"
537 setup_quota_test || error "setup quota failed with $?"
539 set_ost_qtype "none" || error "disable ost quota failed"
540 test_quota_performance $MB
542 set_ost_qtype $QTYPE || error "enable ost quota failed"
543 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
544 error "set quota failed"
545 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"
576 check_write_fallocate() {
580 local short_qtype=${qtype:0:1}
583 log "Write ${count}MiB Using Fallocate"
584 $RUNAS fallocate -l${count}MiB $testfile ||
585 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
588 sync; sync_all_data || true
592 log "Write ${count}MiB Using Fallocate"
593 $RUNAS fallocate -l${count}MiB $testfile &&
594 quota_error $short_qtype $TSTUSR \
595 "Write success, expect EDQUOT" || true
598 # test block hardlimit
601 local testfile="$DIR/$tdir/$tfile-0"
603 setup_quota_test || error "setup quota failed with $?"
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"
658 testfile="$DIR/$tdir/$tfile-2"
659 # make sure the system is clean
660 used=$(getquota -p $TSTPRJID global curspace)
662 error "used space($used) for project $TSTPRJID isn't 0"
665 log "--------------------------------------"
666 log "Project quota (block hardlimit:$limit mb)"
667 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
668 error "set project quota failed"
670 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
671 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
672 change_project -p $TSTPRJID $testfile
674 test_1_check_write $testfile "project" $limit
679 used=$(getquota -p $TSTPRJID global curspace)
680 [ $used -ne 0 ] && quota_error p $TSTPRJID \
681 "project quota isn't released after deletion"
683 resetquota -p $TSTPRJID
685 run_test 1a "Block hard limit (normal use and out of quota)"
689 local global_limit=20 # MB
690 local testfile="$DIR/$tdir/$tfile-0"
694 setup_quota_test || error "setup quota failed with $?"
697 set_ost_qtype $QTYPE || error "enable ost quota failed"
700 log "User quota (block hardlimit:$global_limit MB)"
701 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
702 error "set user quota failed"
704 pool_add $qpool || error "pool_add failed"
705 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
706 error "pool_add_targets failed"
708 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
709 error "set user quota failed"
711 # make sure the system is clean
712 local used=$(getquota -u $TSTUSR global curspace)
714 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
716 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
718 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
719 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
721 test_1_check_write $testfile "user" $limit
724 wait_delete_completed || error "wait_delete_completed failed"
725 sync_all_data || true
726 used=$(getquota -u $TSTUSR global curspace $qpool)
727 [ $used -ne 0 ] && quota_error u $TSTUSR \
728 "user quota isn't released after deletion"
729 resetquota -u $TSTUSR
732 log "--------------------------------------"
733 log "Group quota (block hardlimit:$global_limit MB)"
734 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
735 error "set group quota failed"
737 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
738 error "set group quota failed"
740 testfile="$DIR/$tdir/$tfile-1"
741 # make sure the system is clean
742 used=$(getquota -g $TSTUSR global curspace $qpool)
743 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
745 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
746 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
748 test_1_check_write $testfile "group" $limit
751 wait_delete_completed || error "wait_delete_completed failed"
752 sync_all_data || true
753 used=$(getquota -g $TSTUSR global curspace $qpool)
754 [ $used -ne 0 ] && quota_error g $TSTUSR \
755 "Group quota isn't released after deletion"
756 resetquota -g $TSTUSR
758 if ! is_project_quota_supported; then
759 echo "Project quota is not supported"
763 testfile="$DIR/$tdir/$tfile-2"
764 # make sure the system is clean
765 used=$(getquota -p $TSTPRJID global curspace $qpool)
767 error "used space($used) for project $TSTPRJID isn't 0"
770 log "--------------------------------------"
771 log "Project quota (block hardlimit:$global_limit mb)"
772 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
773 error "set project quota failed"
775 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
776 error "set project quota failed"
779 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
780 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
781 change_project -p $TSTPRJID $testfile
783 test_1_check_write $testfile "project" $limit
788 used=$(getquota -p $TSTPRJID global curspace)
789 [ $used -eq 0 ] || quota_error p $TSTPRJID \
790 "project quota isn't released after deletion"
792 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
795 local global_limit=20 # MB
796 local testfile="$DIR/$tdir/$tfile-0"
797 local qpool1="qpool1"
798 local qpool2="qpool2"
801 setup_quota_test || error "setup quota failed with $?"
804 set_ost_qtype $QTYPE || error "enable ost quota failed"
807 log "User quota (block hardlimit:$global_limit MB)"
808 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
809 error "set user quota failed"
811 pool_add $qpool1 || error "pool_add failed"
812 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
813 error "pool_add_targets failed"
815 pool_add $qpool2 || error "pool_add failed"
816 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
817 error "pool_add_targets failed"
819 # create pools without hard limit
820 # initially such case raised several bugs
821 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
822 error "set user quota failed"
824 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
825 error "set user quota failed"
827 # make sure the system is clean
828 local used=$(getquota -u $TSTUSR global curspace)
830 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
832 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
834 test_1_check_write $testfile "user" $global_limit
836 used=$(getquota -u $TSTUSR global curspace $qpool1)
837 echo "qpool1 used $used"
838 used=$(getquota -u $TSTUSR global curspace $qpool2)
839 echo "qpool2 used $used"
842 wait_delete_completed || error "wait_delete_completed failed"
843 sync_all_data || true
845 used=$(getquota -u $TSTUSR global curspace $qpool1)
846 [ $used -eq 0 ] || quota_error u $TSTUSR \
847 "user quota isn't released after deletion"
849 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
854 local global_limit=20 # MB
855 local testfile="$DIR/$tdir/$tfile-0"
856 local qpool1="qpool1"
857 local qpool2="qpool2"
860 setup_quota_test || error "setup quota failed with $?"
863 set_ost_qtype $QTYPE || error "enable ost quota failed"
866 log "User quota (block hardlimit:$global_limit MB)"
867 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
868 error "set user quota failed"
870 pool_add $qpool1 || error "pool_add failed"
871 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
872 error "pool_add_targets failed"
874 pool_add $qpool2 || error "pool_add failed"
875 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
876 error "pool_add_targets failed"
878 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
879 error "set user quota failed"
881 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
882 error "set user quota failed"
884 # make sure the system is clean
885 local used=$(getquota -u $TSTUSR global curspace)
887 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
889 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
891 test_1_check_write $testfile "user" $limit1
893 used=$(getquota -u $TSTUSR global curspace $qpool1)
894 echo "qpool1 used $used"
895 used=$(getquota -u $TSTUSR global curspace $qpool2)
896 echo "qpool2 used $used"
899 wait_delete_completed || error "wait_delete_completed failed"
900 sync_all_data || true
902 used=$(getquota -u $TSTUSR global curspace $qpool1)
903 [ $used -eq 0 ] || quota_error u $TSTUSR \
904 "user quota isn't released after deletion"
906 run_test 1d "Quota pools: check block hardlimit on different pools"
910 local global_limit=53000000 # MB
911 local testfile="$DIR/$tdir/$tfile-0"
912 local testfile2="$DIR/$tdir/$tfile-1"
913 local qpool1="qpool1"
916 setup_quota_test || error "setup quota failed with $?"
919 set_ost_qtype $QTYPE || error "enable ost quota failed"
921 # global_limit is much greater than limit1 to get
922 # different qunit's on osts. Since 1st qunit shrinking
923 # on OST1(that belongs to qpool1), this qunit should
925 log "User quota (block hardlimit:$global_limit MB)"
926 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
927 error "set user quota failed"
929 pool_add $qpool1 || error "pool_add failed"
930 pool_add_targets $qpool1 1 1 ||
931 error "pool_add_targets failed"
933 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
934 error "set user quota failed"
936 # make sure the system is clean
937 local used=$(getquota -u $TSTUSR global curspace)
938 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
940 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
941 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
943 test_1_check_write $testfile "user" $limit1
945 $LFS setstripe $testfile2 -c 1 -i 0 ||
946 error "setstripe $testfile2 failed"
947 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
948 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
950 $RUNAS $DD of=$testfile2 count=20 ||
951 quota_error u $TSTUSR \
952 "$qtype write failure, but expect success"
956 wait_delete_completed || error "wait_delete_completed failed"
957 sync_all_data || true
959 used=$(getquota -u $TSTUSR global curspace $qpool1)
960 [ $used -eq 0 ] || quota_error u $TSTUSR \
961 "user quota isn't released after deletion"
963 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
966 local global_limit=200 # MB
968 local TESTDIR="$DIR/$tdir/"
969 local testfile="$TESTDIR/$tfile-0"
970 local qpool1="qpool1"
973 setup_quota_test || error "setup quota failed with $?"
976 set_ost_qtype $QTYPE || error "enable ost quota failed"
978 log "User quota (block hardlimit:$global_limit MB)"
979 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
980 error "set user quota failed"
982 pool_add $qpool1 || error "pool_add failed"
983 pool_add_targets $qpool1 0 0 ||
984 error "pool_add_targets failed"
986 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
987 error "set user quota failed"
989 # make sure the system is clean
990 local used=$(getquota -u $TSTUSR global curspace)
991 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
993 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
995 test_1_check_write $testfile "user" $limit1
997 pool_remove_target $qpool1 0
999 wait_delete_completed || error "wait_delete_completed failed"
1000 sync_all_data || true
1002 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1003 # qunit for appropriate element in lgd array should be set
1004 # correctly(4096). Earlier it was not changed continuing to be 1024.
1005 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1006 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1007 # as it already was 1024. As flag "need_update" for this qunit was
1008 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1009 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1010 # became > 10M. QMT returned EINPROGRESS in a loop.
1011 # Check that it doesn't hung anymore.
1012 test_1_check_write $testfile "user" $limit1
1014 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1018 local global_limit=40 # MB
1019 local testfile="$DIR/$tdir/$tfile-0"
1020 local qpool="qpool1"
1021 local mdmb_param="osc.*.max_dirty_mb"
1022 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1025 setup_quota_test || error "setup quota failed with $?"
1026 $LCTL set_param $mdmb_param=1
1027 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1030 set_ost_qtype $QTYPE || error "enable ost quota failed"
1033 log "User quota (block hardlimit:$global_limit MB)"
1034 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1035 error "set user quota failed"
1037 pool_add $qpool || error "pool_add failed"
1038 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1039 error "pool_add_targets failed"
1041 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1042 error "set user quota failed"
1044 # make sure the system is clean
1045 local used=$(getquota -u $TSTUSR global curspace)
1047 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1049 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1050 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1053 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1054 quota_error u $TSTUSR \
1055 "$qtype write failure, but expect success"
1056 log "Write out of block quota ..."
1057 # this time maybe cache write, ignore it's failure
1058 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1059 # flush cache, ensure noquota flag is set on client
1060 cancel_lru_locks osc
1061 sync; sync_all_data || true
1063 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1064 quota_error u $TSTUSR \
1065 "user write success, but expect EDQUOT"
1068 wait_delete_completed || error "wait_delete_completed failed"
1069 sync_all_data || true
1071 used=$(getquota -u $TSTUSR global curspace $qpool)
1072 [ $used -ne 0 ] && quota_error u $TSTUSR \
1073 "user quota isn't released after deletion"
1076 run_test 1g "Quota pools: Block hard limit with wide striping"
1080 local testfile="$DIR/$tdir/$tfile-0"
1082 check_set_fallocate_or_skip
1084 setup_quota_test || error "setup quota failed with $?"
1087 set_ost_qtype $QTYPE || error "enable ost quota failed"
1090 log "User quota (block hardlimit:$limit MB)"
1091 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1092 error "set user quota failed"
1094 # make sure the system is clean
1095 local used=$(getquota -u $TSTUSR global curspace)
1096 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1098 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1099 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1101 check_write_fallocate $testfile "user" $limit
1104 wait_delete_completed || error "wait_delete_completed failed"
1105 sync_all_data || true
1106 used=$(getquota -u $TSTUSR global curspace)
1107 [ $used -eq 0 ] || quota_error u $TSTUSR \
1108 "user quota isn't released after deletion"
1110 run_test 1h "Block hard limit test using fallocate"
1112 # test inode hardlimit
1114 local TESTFILE="$DIR/$tdir/$tfile-0"
1115 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1116 qmt.$FSNAME-QMT0000.md-0x0.info |
1117 awk '/least qunit/{ print $3 }')
1118 local L2=$(do_facet mds1 $LCTL get_param -n \
1119 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1121 [ $L2 -le $LIMIT ] || LIMIT=$L2
1123 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1125 local FREE_INODES=$(mdt_free_inodes 0)
1126 echo "$FREE_INODES free inodes on master MDT"
1127 [ $FREE_INODES -lt $LIMIT ] &&
1128 skip "not enough free inodes $FREE_INODES required $LIMIT"
1130 setup_quota_test || error "setup quota failed with $?"
1133 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1136 log "User quota (inode hardlimit:$LIMIT files)"
1137 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1138 error "set user quota failed"
1140 # make sure the system is clean
1141 local USED=$(getquota -u $TSTUSR global curinodes)
1142 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1144 log "Create $LIMIT files ..."
1145 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1146 quota_error u $TSTUSR "user create failure, but expect success"
1147 log "Create out of file quota ..."
1148 $RUNAS touch ${TESTFILE}_xxx &&
1149 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1152 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1153 rm -f ${TESTFILE}_xxx
1154 wait_delete_completed
1156 USED=$(getquota -u $TSTUSR global curinodes)
1157 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1158 "user quota isn't released after deletion"
1159 resetquota -u $TSTUSR
1162 log "--------------------------------------"
1163 log "Group quota (inode hardlimit:$LIMIT files)"
1164 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1165 error "set group quota failed"
1167 TESTFILE=$DIR/$tdir/$tfile-1
1168 # make sure the system is clean
1169 USED=$(getquota -g $TSTUSR global curinodes)
1170 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1172 log "Create $LIMIT files ..."
1173 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1174 quota_error g $TSTUSR "group create failure, but expect success"
1175 log "Create out of file quota ..."
1176 $RUNAS touch ${TESTFILE}_xxx &&
1177 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1180 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1181 rm -f ${TESTFILE}_xxx
1182 wait_delete_completed
1184 USED=$(getquota -g $TSTUSR global curinodes)
1185 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1186 "user quota isn't released after deletion"
1188 resetquota -g $TSTUSR
1189 ! is_project_quota_supported &&
1190 echo "Skip project quota is not supported" && return 0
1193 log "--------------------------------------"
1194 log "Project quota (inode hardlimit:$LIMIT files)"
1195 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1196 error "set project quota failed"
1198 TESTFILE=$DIR/$tdir/$tfile-1
1199 # make sure the system is clean
1200 USED=$(getquota -p $TSTPRJID global curinodes)
1202 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1204 change_project -sp $TSTPRJID $DIR/$tdir
1205 log "Create $LIMIT files ..."
1206 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1207 $TSTPRJID "project create fail, but expect success"
1208 log "Create out of file quota ..."
1209 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1210 "project create success, but expect EDQUOT"
1211 change_project -C $DIR/$tdir
1214 USED=$(getquota -p $TSTPRJID global curinodes)
1215 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1216 "project quota isn't released after deletion"
1219 run_test 2 "File hard limit (normal use and out of quota)"
1228 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1229 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1233 $LFS setstripe $testfile -c 1 -i 0
1234 chown $TSTUSR.$TSTUSR $testfile
1235 [ "$qtype" == "p" ] && is_project_quota_supported &&
1236 change_project -p $TSTPRJID $testfile
1238 echo "Write up to soft limit"
1239 $RUNAS $DD of=$testfile count=$limit ||
1240 quota_error a $TSTUSR "write failure, but expect success"
1241 OFFSET=$((limit * 1024))
1242 cancel_lru_locks osc
1244 echo "Write to exceed soft limit"
1245 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1246 quota_error a $TSTUSR "write failure, but expect success"
1247 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1248 cancel_lru_locks osc
1250 echo "mmap write when over soft limit"
1251 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1252 quota_error a $TSTUSR "mmap write failure, but expect success"
1253 cancel_lru_locks osc
1258 $SHOW_QUOTA_INFO_USER
1259 $SHOW_QUOTA_INFO_GROUP
1260 $SHOW_QUOTA_INFO_PROJID
1262 echo "Write before timer goes off"
1263 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1264 quota_error a $TSTUSR "write failure, but expect success"
1265 OFFSET=$((OFFSET + 1024))
1266 cancel_lru_locks osc
1268 wait_grace_time $qtype "block" $pool
1273 $SHOW_QUOTA_INFO_USER
1274 $SHOW_QUOTA_INFO_GROUP
1275 $SHOW_QUOTA_INFO_PROJID
1277 log "Write after timer goes off"
1278 # maybe cache write, ignore.
1279 # write up to soft least quint to consume all
1280 # possible slave granted space.
1281 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1282 count=$soft_limit seek=$OFFSET || true
1283 OFFSET=$((OFFSET + soft_limit))
1284 cancel_lru_locks osc
1285 log "Write after cancel lru locks"
1286 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1287 quota_error a $TSTUSR "write success, but expect EDQUOT"
1292 $SHOW_QUOTA_INFO_USER
1293 $SHOW_QUOTA_INFO_GROUP
1294 $SHOW_QUOTA_INFO_PROJID
1296 echo "Unlink file to stop timer"
1298 wait_delete_completed
1299 sync_all_data || true
1304 $SHOW_QUOTA_INFO_USER
1305 $SHOW_QUOTA_INFO_GROUP
1306 $SHOW_QUOTA_INFO_PROJID
1308 $LFS setstripe $testfile -c 1 -i 0
1309 chown $TSTUSR.$TSTUSR $testfile
1310 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1313 $RUNAS $DD of=$testfile count=$limit ||
1314 quota_error a $TSTUSR "write failure, but expect success"
1321 local grace=20 # seconds
1322 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1325 local testfile=$DIR/$tdir/$tfile-0
1327 # get minimum soft qunit size
1328 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1329 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1331 set_ost_qtype $QTYPE || error "enable ost quota failed"
1333 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1334 # make sure the system is clean
1335 local used=$(getquota -u $TSTUSR global curspace)
1336 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1338 $LFS setquota -t -u --block-grace $grace --inode-grace \
1339 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1340 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1341 error "set user quota failed"
1343 test_block_soft $testfile $grace $limit "u"
1345 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1346 testfile=$DIR/$tdir/$tfile-1
1347 # make sure the system is clean
1348 used=$(getquota -g $TSTUSR global curspace)
1349 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1351 $LFS setquota -t -g --block-grace $grace --inode-grace \
1352 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1353 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1354 error "set group quota failed"
1356 test_block_soft $testfile $grace $limit "g"
1358 if is_project_quota_supported; then
1359 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1360 testfile=$DIR/$tdir/$tfile-2
1361 # make sure the system is clean
1362 used=$(getquota -p $TSTPRJID global curspace)
1363 [ $used -ne 0 ] && error \
1364 "Used space($used) for project $TSTPRJID isn't 0."
1366 $LFS setquota -t -p --block-grace $grace --inode-grace \
1367 $MAX_IQ_TIME $DIR ||
1368 error "set project grace time failed"
1369 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1370 $DIR || error "set project quota failed"
1372 test_block_soft $testfile $grace $limit "p"
1373 resetquota -p $TSTPRJID
1374 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1375 $MAX_IQ_TIME $DIR ||
1376 error "restore project grace time failed"
1380 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1381 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1382 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1383 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1385 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1388 local grace=20 # seconds
1389 local qpool="qpool1"
1390 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1393 local testfile=$DIR/$tdir/$tfile-0
1396 # get minimum soft qunit size
1397 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1398 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1399 local glbl_limit=$((2*limit))
1400 local glbl_grace=$((2*grace))
1401 echo "limit $limit glbl_limit $glbl_limit"
1402 echo "grace $grace glbl_grace $glbl_grace"
1404 set_ost_qtype $QTYPE || error "enable ost quota failed"
1406 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1407 # make sure the system is clean
1408 local used=$(getquota -u $TSTUSR global curspace)
1409 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1411 pool_add $qpool || error "pool_add failed"
1412 pool_add_targets $qpool 0 1 ||
1413 error "pool_add_targets failed"
1415 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1416 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1417 $LFS setquota -t -u --block-grace $grace \
1418 --pool $qpool $DIR || error "set user grace time failed"
1420 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1421 error "set user quota failed"
1422 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1423 error "set user quota failed"
1425 test_block_soft $testfile $grace $limit "u" $qpool
1427 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1428 testfile=$DIR/$tdir/$tfile-1
1429 # make sure the system is clean
1430 used=$(getquota -g $TSTUSR global curspace)
1431 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1433 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1434 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1435 $LFS setquota -t -g --block-grace $grace \
1436 --pool $qpool $DIR || error "set group grace time failed"
1438 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1439 error "set group quota failed"
1440 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1441 error "set group quota failed"
1443 test_block_soft $testfile $grace $limit "g" $qpool
1445 if is_project_quota_supported; then
1446 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1447 testfile=$DIR/$tdir/$tfile-2
1448 # make sure the system is clean
1449 used=$(getquota -p $TSTPRJID global curspace)
1450 [ $used -ne 0 ] && error \
1451 "Used space($used) for project $TSTPRJID isn't 0."
1453 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1454 $MAX_IQ_TIME $DIR ||
1455 error "set project grace time failed"
1456 $LFS setquota -t -p --block-grace $grace \
1457 --pool $qpool $DIR ||
1458 error "set project grace time failed"
1460 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1461 $DIR || error "set project quota failed"
1462 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1463 --pool $qpool $DIR || error "set project quota failed"
1465 test_block_soft $testfile $grace $limit "p" $qpool
1466 resetquota -p $TSTPRJID
1467 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1468 $MAX_IQ_TIME $DIR ||
1469 error "restore project grace time failed"
1470 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1471 $DIR || error "set project grace time failed"
1475 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1476 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1477 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1478 --pool $qpool $DIR || error "restore user grace time failed"
1479 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1480 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1481 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1482 --pool $qpool $DIR || error "restore group grace time failed"
1484 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1487 local grace=20 # seconds
1488 local qpool="qpool1"
1489 local qpool2="qpool2"
1490 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1493 local testfile=$DIR/$tdir/$tfile-0
1496 # get minimum soft qunit size
1497 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1498 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1499 local limit2=$((limit+4))
1500 local glbl_limit=$((limit+8))
1501 local grace1=$((grace+10))
1503 local glbl_grace=$((grace+20))
1504 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1505 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1507 set_ost_qtype $QTYPE || error "enable ost quota failed"
1509 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1510 # make sure the system is clean
1511 local used=$(getquota -u $TSTUSR global curspace)
1512 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1514 pool_add $qpool || error "pool_add failed"
1515 pool_add_targets $qpool 0 1 ||
1516 error "pool_add_targets failed"
1518 pool_add $qpool2 || error "pool_add failed"
1519 pool_add_targets $qpool2 0 1 ||
1520 error "pool_add_targets failed"
1523 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1524 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1525 $LFS setquota -t -u --block-grace $grace1 \
1526 --pool $qpool $DIR || error "set user grace time failed"
1527 $LFS setquota -t -u --block-grace $grace2 \
1528 --pool $qpool2 $DIR || error "set user grace time failed"
1530 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1531 error "set user quota failed"
1532 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1533 error "set user quota failed"
1534 # qpool has minimum soft limit, but it's grace is grater than
1535 # grace period of qpool2. Thus write shouldn't fail when
1536 # hit qpool soft limit - only when reaches up qpool2 limit
1537 # after grace2 seconds.
1538 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1539 error "set user quota failed"
1541 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1544 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1545 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1546 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1547 --pool $qpool $DIR || error "restore user grace time failed"
1548 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1549 --pool $qpool2 $DIR || error "restore user grace time failed"
1551 run_test 3c "Quota pools: check block soft limit on different pools"
1558 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1559 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1562 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1564 echo "Create files to exceed soft limit"
1565 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1566 quota_error a $TSTUSR "create failure, but expect success"
1567 local trigger_time=$(date +%s)
1569 sync_all_data || true
1571 local cur_time=$(date +%s)
1572 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1573 error "Passed grace time $grace, $trigger_time, $cur_time"
1575 echo "Create file before timer goes off"
1576 $RUNAS touch ${TESTFILE}_before ||
1577 quota_error a $TSTUSR "failed create before timer expired," \
1578 "but expect success. $trigger_time, $cur_time"
1579 sync_all_data || true
1581 wait_grace_time $qtype "file"
1586 $SHOW_QUOTA_INFO_USER
1587 $SHOW_QUOTA_INFO_GROUP
1588 $SHOW_QUOTA_INFO_PROJID
1590 echo "Create file after timer goes off"
1591 # exceed least soft limit is possible
1592 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1593 quota_error a $TSTUSR "create after timer expired," \
1595 sync_all_data || true
1600 $SHOW_QUOTA_INFO_USER
1601 $SHOW_QUOTA_INFO_GROUP
1602 $SHOW_QUOTA_INFO_PROJID
1604 echo "Unlink files to stop timer"
1605 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1606 wait_delete_completed
1609 $RUNAS touch ${TESTFILE}_xxx ||
1610 quota_error a $TSTUSR "touch after timer stop failure," \
1611 "but expect success"
1612 sync_all_data || true
1620 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1621 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1622 local TESTFILE=$DIR/$tdir/$tfile-0
1625 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1627 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1628 # make sure the system is clean
1629 local USED=$(getquota -u $TSTUSR global curinodes)
1630 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1632 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1633 $GRACE $DIR || error "set user grace time failed"
1634 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1635 error "set user quota failed"
1637 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1639 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1641 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1642 # make sure the system is clean
1643 USED=$(getquota -g $TSTUSR global curinodes)
1644 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1646 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1647 $GRACE $DIR || error "set group grace time failed"
1648 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1649 error "set group quota failed"
1650 TESTFILE=$DIR/$tdir/$tfile-1
1652 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1654 if is_project_quota_supported; then
1655 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1656 # make sure the system is clean
1657 USED=$(getquota -p $TSTPRJID global curinodes)
1658 [ $USED -ne 0 ] && error \
1659 "Used space($USED) for project $TSTPRJID isn't 0."
1661 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1662 $GRACE $DIR || error "set project grace time failed"
1663 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1664 error "set project quota failed"
1666 TESTFILE=$DIR/$tdir/$tfile-1
1667 # one less than limit, because of parent directory included.
1668 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1669 resetquota -p $TSTPRJID
1670 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1671 $MAX_IQ_TIME $DIR ||
1672 error "restore project grace time failed"
1676 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1677 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1678 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1679 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1681 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1684 local GR_STR1="1w3d"
1685 local GR_STR2="1000s"
1687 local GR_STR4="1w2d3h4m5s"
1689 local GR_STR6="18446744073709551615"
1692 wait_delete_completed
1694 # test of valid grace strings handling
1695 echo "Valid grace strings test"
1696 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1697 $GR_STR2 $DIR || error "set user grace time failed"
1698 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1699 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1700 $GR_STR4 $DIR || error "set group grace time quota failed"
1701 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1703 # test of invalid grace strings handling
1704 echo " Invalid grace strings test"
1705 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1706 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1707 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1711 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1712 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1713 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1714 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1716 run_test 4b "Grace time strings handling"
1718 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1720 local BLIMIT=10 # MB
1721 local ILIMIT=10 # inodes
1723 setup_quota_test || error "setup quota failed with $?"
1725 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1726 set_ost_qtype $QTYPE || error "enable ost quota failed"
1728 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1729 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1730 error "set user quota failed"
1731 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1732 if is_project_quota_supported; then
1733 error "set group quota failed"
1734 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1735 -I $ILIMIT $DIR || error "set project quota failed"
1738 # make sure the system is clean
1739 local USED=$(getquota -u $TSTUSR global curinodes)
1740 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1741 USED=$(getquota -g $TSTUSR global curinodes)
1742 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1743 USED=$(getquota -u $TSTUSR global curspace)
1744 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1745 USED=$(getquota -g $TSTUSR global curspace)
1746 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1747 if is_project_quota_supported; then
1748 USED=$(getquota -p $TSTPRJID global curinodes)
1750 error "Used inode($USED) for project $TSTPRJID isn't 0."
1751 USED=$(getquota -p $TSTPRJID global curspace)
1753 error "Used block($USED) for project $TSTPRJID isn't 0."
1756 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1757 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1758 error "create failure, expect success"
1759 if is_project_quota_supported; then
1760 touch $DIR/$tdir/$tfile-0_1
1761 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1763 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1764 error "write failure, expect success"
1766 echo "Chown files to $TSTUSR.$TSTUSR ..."
1767 for i in $(seq 0 $ILIMIT); do
1768 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1769 quota_error a $TSTUSR "chown failure, expect success"
1773 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1774 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1776 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1778 # test dropping acquire request on master
1782 # Clear dmesg so watchdog is not triggered by previous
1784 do_facet ost1 dmesg -c > /dev/null
1786 setup_quota_test || error "setup quota failed with $?"
1788 # make sure the system is clean
1789 local USED=$(getquota -u $TSTUSR global curspace)
1790 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1792 # make sure no granted quota on ost
1793 set_ost_qtype $QTYPE || error "enable ost quota failed"
1794 resetquota -u $TSTUSR
1796 # create file for $TSTUSR
1797 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1798 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1799 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1801 # create file for $TSTUSR2
1802 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1803 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1804 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1806 # cache per-ID lock for $TSTUSR on slave
1807 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1808 error "set quota failed"
1809 $RUNAS $DD of=$TESTFILE count=1 ||
1810 error "write $TESTFILE failure, expect success"
1811 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1812 error "write $TESTFILE2 failure, expect success"
1814 if at_is_enabled; then
1815 at_max_saved=$(at_max_get ost1)
1816 at_max_set $TIMEOUT ost1
1818 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1819 # DQACQ is sent, which makes at_max to take effect
1820 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1823 wait_delete_completed
1827 sync_all_data || true
1829 #define QUOTA_DQACQ 601
1830 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1831 lustre_fail mds 0x513 601
1833 do_facet ost1 $LCTL set_param \
1834 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1836 # write to un-enforced ID ($TSTUSR2) should succeed
1837 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1838 error "write failure, expect success"
1840 # write to enforced ID ($TSTUSR) in background, exceeding limit
1841 # to make sure DQACQ is sent
1842 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1845 # watchdog timer uses a factor of 2
1846 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1847 sleep $((TIMEOUT * 2 + 1))
1849 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1851 # write should be blocked and never finished
1852 if ! ps -p $DDPID > /dev/null 2>&1; then
1854 error "write finished incorrectly!"
1859 # no watchdog is triggered
1860 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1861 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1862 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1863 [ -z "$watchdog" ] || error "$watchdog"
1865 rm -f $TMP/lustre-log-${TESTNAME}.log
1867 # write should continue then fail with EDQUOT
1871 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1872 if [ $count -ge 240 ]; then
1873 quota_error u $TSTUSR "dd not finished in $count secs"
1875 count=$((count + 1))
1876 if [ $((count % 30)) -eq 0 ]; then
1877 c_size=$(stat -c %s $TESTFILE)
1878 echo "Waiting $count secs. $c_size"
1884 run_test 6 "Test dropping acquire request on master"
1886 # quota reintegration (global index)
1888 local TESTFILE=$DIR/$tdir/$tfile
1891 [ "$SLOW" = "no" ] && LIMIT=5
1893 setup_quota_test || error "setup quota failed with $?"
1895 # make sure the system is clean
1896 local USED=$(getquota -u $TSTUSR global curspace)
1897 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1899 # make sure no granted quota on ost1
1900 set_ost_qtype $QTYPE || error "enable ost quota failed"
1901 resetquota -u $TSTUSR
1902 set_ost_qtype "none" || error "disable ost quota failed"
1904 local OSTUUID=$(ostuuid_from_index 0)
1905 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1907 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1910 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1911 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1916 echo "Enable quota & set quota limit for $TSTUSR"
1917 set_ost_qtype $QTYPE || error "enable ost quota failed"
1918 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1919 error "set quota failed"
1921 echo "Start ost1..."
1922 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1925 wait_ost_reint $QTYPE || error "reintegration failed"
1927 # hardlimit should have been fetched by slave during global
1928 # reintegration, write will exceed quota
1929 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1930 quota_error u $TSTUSR "write success, but expect EDQUOT"
1933 wait_delete_completed
1934 sync_all_data || true
1940 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1941 error "clear quota failed"
1943 echo "Start ost1..."
1944 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1947 wait_ost_reint $QTYPE || error "reintegration failed"
1949 # hardlimit should be cleared on slave during reintegration
1950 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1951 quota_error u $TSTUSR "write error, but expect success"
1953 run_test 7a "Quota reintegration (global index)"
1955 # quota reintegration (slave index)
1957 local limit=100000 # MB
1958 local TESTFILE=$DIR/$tdir/$tfile
1960 setup_quota_test || error "setup quota failed with $?"
1962 # make sure the system is clean
1963 local USED=$(getquota -u $TSTUSR global curspace)
1964 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1966 # make sure no granted quota on ost1
1967 set_ost_qtype $QTYPE || error "enable ost quota failed"
1968 resetquota -u $TSTUSR
1969 set_ost_qtype "none" || error "disable ost quota failed"
1971 local OSTUUID=$(ostuuid_from_index 0)
1972 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1974 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1977 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1978 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1980 # consume some space to make sure the granted space will not
1981 # be released during reconciliation
1982 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1983 error "consume space failure, expect success"
1985 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1986 lustre_fail mds 0xa02
1988 set_ost_qtype $QTYPE || error "enable ost quota failed"
1989 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1990 error "set quota failed"
1992 # ignore the write error
1993 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1995 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1999 echo "Restart ost to trigger reintegration..."
2001 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2004 wait_ost_reint $QTYPE || error "reintegration failed"
2006 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2007 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2012 run_test 7b "Quota reintegration (slave index)"
2014 # quota reintegration (restart mds during reintegration)
2017 local TESTFILE=$DIR/$tdir/$tfile
2019 [ "$SLOW" = "no" ] && LIMIT=5
2021 setup_quota_test || error "setup quota failed with $?"
2023 # make sure the system is clean
2024 local USED=$(getquota -u $TSTUSR global curspace)
2025 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2027 set_ost_qtype "none" || error "disable ost quota failed"
2028 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2029 error "set quota failed"
2031 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2032 lustre_fail ost 0xa03
2035 set_ost_qtype $QTYPE || error "enable ost quota failed"
2036 # trigger reintegration
2037 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2038 procf=${procf}quota_slave.force_reint
2039 do_facet ost1 $LCTL set_param $procf=1 ||
2040 error "force reintegration failed"
2048 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2051 # wait longer than usual to make sure the reintegration
2052 # is triggered by quota wb thread.
2053 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2055 # hardlimit should have been fetched by slave during global
2056 # reintegration, write will exceed quota
2057 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2058 quota_error u $TSTUSR "write success, but expect EDQUOT"
2061 run_test 7c "Quota reintegration (restart mds during reintegration)"
2063 # Quota reintegration (Transfer index in multiple bulks)
2065 local TESTFILE=$DIR/$tdir/$tfile
2066 local TESTFILE1="$DIR/$tdir/$tfile"-1
2069 setup_quota_test || error "setup quota failed with $?"
2071 set_ost_qtype "none" || error "disable ost quota failed"
2072 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2073 error "set quota for $TSTUSR failed"
2074 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2075 error "set quota for $TSTUSR2 failed"
2077 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2078 lustre_fail mds 0x608 0
2080 # enable quota to tirgger reintegration
2081 set_ost_qtype "u" || error "enable ost quota failed"
2082 wait_ost_reint "u" || error "reintegration failed"
2086 # hardlimit should have been fetched by slave during global
2087 # reintegration, write will exceed quota
2088 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2089 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2091 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2092 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2095 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2097 # quota reintegration (inode limits)
2099 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2101 # LU-2435: skip this quota test if underlying zfs version has not
2102 # supported native dnode accounting
2103 [ "$mds1_FSTYPE" == zfs ] && {
2104 local F="feature@userobj_accounting"
2105 local pool=$(zpool_name mds1)
2106 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2108 [[ "$feature" != *" active "* ]] &&
2109 skip "requires zpool with active userobj_accounting"
2112 local ilimit=$((1024 * 2)) # inodes
2113 local TESTFILE=$DIR/${tdir}-1/$tfile
2115 setup_quota_test || error "setup quota failed with $?"
2117 # make sure the system is clean
2118 local USED=$(getquota -u $TSTUSR global curinodes)
2119 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2121 # make sure no granted quota on mdt1
2122 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2123 resetquota -u $TSTUSR
2124 set_mdt_qtype "none" || error "disable mdt quota failed"
2126 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2127 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2128 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2131 echo "Stop mds${MDSCOUNT}..."
2134 echo "Enable quota & set quota limit for $TSTUSR"
2135 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2136 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2137 error "set quota failed"
2139 echo "Start mds${MDSCOUNT}..."
2140 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2143 wait_mdt_reint $QTYPE || error "reintegration failed"
2145 echo "create remote dir"
2146 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2147 error "create remote dir failed"
2148 chmod 0777 $DIR/${tdir}-1
2150 # hardlimit should have been fetched by slave during global
2151 # reintegration, create will exceed quota
2152 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2153 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2155 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2156 wait_delete_completed
2157 sync_all_data || true
2159 echo "Stop mds${MDSCOUNT}..."
2162 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2163 error "clear quota failed"
2165 echo "Start mds${MDSCOUNT}..."
2166 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2169 wait_mdt_reint $QTYPE || error "reintegration failed"
2171 # hardlimit should be cleared on slave during reintegration
2172 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2173 quota_error u $TSTUSR "create failed, expect success"
2175 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2176 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2178 run_test 7e "Quota reintegration (inode limits)"
2180 # run dbench with quota enabled
2182 local BLK_LIMIT="100g" #100G
2183 local FILE_LIMIT=1000000
2185 setup_quota_test || error "setup quota failed with $?"
2187 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2188 set_ost_qtype $QTYPE || error "enable ost quota failed"
2190 echo "Set enough high limit for user: $TSTUSR"
2191 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2192 error "set user quota failed"
2193 echo "Set enough high limit for group: $TSTUSR"
2194 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2195 error "set group quota failed"
2196 if is_project_quota_supported; then
2197 change_project -sp $TSTPRJID $DIR/$tdir
2198 echo "Set enough high limit for project: $TSTPRJID"
2199 $LFS setquota -p $TSTPRJID -b 0 \
2200 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2201 error "set project quota failed"
2205 [ "$SLOW" = "no" ] && duration=" -t 120"
2206 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2207 quota_error a $TSTUSR "dbench failed!"
2209 is_project_quota_supported && change_project -C $DIR/$tdir
2211 run_test 8 "Run dbench with quota enabled"
2213 # this check is just for test_9
2214 OST0_MIN=4900000 #4.67G
2216 check_whether_skip () {
2217 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2218 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2219 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2220 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2227 # run for fixing bug10707, it needs a big room. test for 64bit
2229 local filesize=$((1024 * 9 / 2)) # 4.5G
2231 check_whether_skip && return 0
2233 setup_quota_test || error "setup quota failed with $?"
2235 set_ost_qtype "ug" || error "enable ost quota failed"
2237 local TESTFILE="$DIR/$tdir/$tfile-0"
2238 local BLK_LIMIT=100G #100G
2239 local FILE_LIMIT=1000000
2241 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2243 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2245 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2246 error "set user quota failed"
2248 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2249 "for group: $TSTUSR"
2250 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2251 error "set group quota failed"
2253 quota_show_check a u $TSTUSR
2254 quota_show_check a g $TSTUSR
2256 echo "Create test file"
2257 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2258 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2260 log "Write the big file of 4.5G ..."
2261 $RUNAS $DD of=$TESTFILE count=$filesize ||
2262 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2272 run_test 9 "Block limit larger than 4GB (b10707)"
2275 local TESTFILE=$DIR/$tdir/$tfile
2277 setup_quota_test || error "setup quota failed with $?"
2279 # set limit to root user should fail
2280 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2281 error "set limit for root user successfully, expect failure"
2282 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2283 error "set limit for root group successfully, expect failure"
2284 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2285 error "set limit for project 0 successfully, expect failure"
2287 # root user can overrun quota
2288 set_ost_qtype "ug" || error "enable ost quota failed"
2290 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2291 error "set quota failed"
2292 quota_show_check b u $TSTUSR
2294 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2295 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2297 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2298 error "write failure, expect success"
2300 run_test 10 "Test quota for root user"
2303 local TESTFILE=$DIR/$tdir/$tfile
2304 setup_quota_test || error "setup quota failed with $?"
2306 set_mdt_qtype "ug" || error "enable mdt quota failed"
2307 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2308 error "set quota failed"
2310 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2311 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2313 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2314 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2317 local USED=$(getquota -u $TSTUSR global curinodes)
2318 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2320 run_test 11 "Chown/chgrp ignores quota"
2323 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2325 local blimit=22 # MB
2326 local blk_cnt=$((blimit - 5))
2327 local TESTFILE0="$DIR/$tdir/$tfile"-0
2328 local TESTFILE1="$DIR/$tdir/$tfile"-1
2330 setup_quota_test || error "setup quota failed with $?"
2332 set_ost_qtype "u" || error "enable ost quota failed"
2333 quota_show_check b u $TSTUSR
2335 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2336 error "set quota failed"
2338 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2339 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2340 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2341 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2343 echo "Write to ost0..."
2344 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2345 quota_error a $TSTUSR "dd failed"
2347 echo "Write to ost1..."
2348 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2349 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2351 echo "Free space from ost0..."
2353 wait_delete_completed
2354 sync_all_data || true
2356 echo "Write to ost1 after space freed from ost0..."
2357 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2358 quota_error a $TSTUSR "rebalancing failed"
2360 run_test 12a "Block quota rebalancing"
2363 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2365 local ilimit=$((1024 * 2)) # inodes
2366 local TESTFILE0=$DIR/$tdir/$tfile
2367 local TESTFILE1=$DIR/${tdir}-1/$tfile
2369 setup_quota_test || error "setup quota failed with $?"
2371 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2372 chmod 0777 $DIR/${tdir}-1
2374 set_mdt_qtype "u" || error "enable mdt quota failed"
2375 quota_show_check f u $TSTUSR
2377 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2378 error "set quota failed"
2380 echo "Create $ilimit files on mdt0..."
2381 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2382 quota_error u $TSTUSR "create failed, but expect success"
2384 echo "Create files on mdt1..."
2385 $RUNAS createmany -m $TESTFILE1 1 &&
2386 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2388 echo "Free space from mdt0..."
2389 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2390 wait_delete_completed
2391 sync_all_data || true
2393 echo "Create files on mdt1 after space freed from mdt0..."
2394 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2395 quota_error a $TSTUSR "rebalancing failed"
2397 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2398 error "unlink mdt1 files failed"
2399 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2401 run_test 12b "Inode quota rebalancing"
2404 local TESTFILE=$DIR/$tdir/$tfile
2405 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2406 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2408 setup_quota_test || error "setup quota failed with $?"
2410 set_ost_qtype "u" || error "enable ost quota failed"
2411 quota_show_check b u $TSTUSR
2413 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2414 error "set quota failed"
2415 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2416 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2418 # clear the locks in cache first
2419 do_facet ost1 $LCTL set_param -n $procf=clear
2420 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2421 [ $nlock -eq 0 ] || error "$nlock cached locks"
2423 # write to acquire the per-ID lock
2424 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2425 quota_error a $TSTUSR "dd failed"
2427 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2428 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2430 # clear quota doesn't trigger per-ID lock cancellation
2431 resetquota -u $TSTUSR
2432 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2433 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2435 # clear the per-ID lock
2436 do_facet ost1 $LCTL set_param -n $procf=clear
2437 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2438 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2440 # spare quota should be released
2441 local OSTUUID=$(ostuuid_from_index 0)
2442 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2443 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2444 [ $limit -le $space ] ||
2445 error "spare quota isn't released, limit:$limit, space:$space"
2447 run_test 13 "Cancel per-ID lock in the LRU list"
2450 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2452 wait_delete_completed
2453 sync_all_data || true
2456 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2457 error "set user quota failed"
2458 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2459 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2460 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2461 resetquota -u $TSTUSR
2464 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2465 error "set group quota failed"
2466 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2467 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2468 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2469 resetquota -g $TSTUSR
2471 run_test 15 "Set over 4T block quota"
2475 local BLKS=1 # 1M less than limit
2476 local TESTFILE=$DIR/$tdir/$tfile
2478 setup_quota_test || error "setup quota failed with $?"
2480 # make sure the system is clean
2481 local USED=$(getquota -u $TSTUSR global curspace)
2482 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2484 set_ost_qtype "ug" || error "enable ost quota failed"
2485 # make sure no granted quota on ost
2486 resetquota -u $TSTUSR
2487 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2488 error "set quota failed"
2490 quota_show_check b u $TSTUSR
2492 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2493 lustre_fail mds 0xa04 $err_code
2495 # write in background
2496 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2500 # write should be blocked and never finished
2501 if ! ps -p $DDPID > /dev/null 2>&1; then
2503 quota_error u $TSTUSR "write finished incorrectly!"
2511 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2513 if [ $count -gt $timeout ]; then
2514 quota_error u $TSTUSR "dd is not finished!"
2519 sync; sync_all_data || true
2521 USED=$(getquota -u $TSTUSR global curspace)
2522 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2523 "Used space(${USED}K) is less than ${BLKS}M"
2528 # DQACQ return recoverable error
2530 echo "DQACQ return -ENOLCK"
2532 test_17sub 37 || error "Handle -ENOLCK failed"
2534 echo "DQACQ return -EAGAIN"
2536 test_17sub 11 || error "Handle -EAGAIN failed"
2538 echo "DQACQ return -ETIMEDOUT"
2539 #define ETIMEDOUT 110
2540 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2542 echo "DQACQ return -ENOTCONN"
2543 #define ENOTCONN 107
2544 test_17sub 107 || error "Handle -ENOTCONN failed"
2547 run_test 17 "DQACQ return recoverable error"
2551 local blimit=200 # MB
2552 local TESTFILE="$DIR/$tdir/$tfile"
2554 setup_quota_test || error "setup quota failed with $?"
2556 set_ost_qtype "u" || error "enable ost quota failed"
2557 log "User quota (limit: $blimit)"
2558 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2559 error "set quota failed"
2560 quota_show_check b u $TSTUSR
2562 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2563 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2565 local timeout=$(sysctl -n lustre.timeout)
2567 if [ $io_type = "directio" ]; then
2568 log "Write 100M (directio) ..."
2569 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2571 log "Write 100M (buffered) ..."
2572 $RUNAS $DD of=$TESTFILE count=100 &
2576 replay_barrier $SINGLEMDS
2577 log "Fail mds for $((2 * timeout)) seconds"
2578 fail $SINGLEMDS $((2 * timeout))
2581 if at_is_enabled; then
2582 timeout=$(at_max_get mds)
2584 timeout=$(lctl get_param -n timeout)
2588 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2589 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2590 log "it took $count second"
2595 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2597 cancel_lru_locks mdc
2598 cancel_lru_locks osc
2601 local testfile_size=$(stat -c %s $TESTFILE)
2602 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2603 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2604 "got ${testfile_size}. Verifying file failed!"
2609 # test when mds does failover, the ost still could work well
2610 # this test shouldn't trigger watchdog b=14840
2612 # Clear dmesg so watchdog is not triggered by previous
2614 do_facet ost1 dmesg -c > /dev/null
2617 test_18_sub directio
2619 # check if watchdog is triggered
2620 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2621 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2622 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2623 [ -z "$watchdog" ] || error "$watchdog"
2624 rm -f $TMP/lustre-log-${TESTNAME}.log
2626 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2630 local TESTFILE=$DIR/$tdir/$tfile
2632 setup_quota_test || error "setup quota failed with $?"
2634 set_ost_qtype $QTYPE || error "enable ost quota failed"
2636 # bind file to a single OST
2637 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2638 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2640 echo "Set user quota (limit: ${blimit}M)"
2641 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2642 error "set user quota failed"
2643 quota_show_check b u $TSTUSR
2644 echo "Update quota limits"
2645 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2646 error "set group quota failed"
2647 quota_show_check b u $TSTUSR
2649 # first wirte might be cached
2650 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2651 cancel_lru_locks osc
2653 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2654 quota_error u $TSTUSR "Write success, expect failure"
2657 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2659 test_20() { # b15754
2660 local LSTR=(2g 1t 4k 3m) # limits strings
2662 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2665 resetquota -u $TSTUSR
2667 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2668 $MOUNT || error "could not set quota limits"
2669 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2670 --inode-softlimit ${LSTR[2]} \
2671 --inode-hardlimit ${LSTR[3]} \
2672 $MOUNT || error "could not set quota limits"
2674 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2675 error "bsoftlimit was not set properly"
2676 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2677 error "bhardlimit was not set properly"
2678 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2679 error "isoftlimit was not set properly"
2680 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2681 error "ihardlimit was not set properly"
2683 resetquota -u $TSTUSR
2685 run_test 20 "Test if setquota specifiers work properly (b15754)"
2692 local time=$(($(date +%s) + seconds))
2693 while [ $(date +%s) -lt $time ]; do
2694 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2698 # run for fixing bug16053, setquota shouldn't fail when writing and
2699 # deleting are happening
2701 local TESTFILE="$DIR/$tdir/$tfile"
2702 local BLIMIT=10 # 10G
2703 local ILIMIT=1000000
2705 setup_quota_test || error "setup quota failed with $?"
2707 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2709 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2710 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2711 error "set user quota failed"
2712 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2713 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2714 error "set group quota failed"
2715 if is_project_quota_supported; then
2716 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2717 "project: $TSTPRJID"
2718 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2719 $MOUNT || error "set project quota failed"
2722 # repeat writing on a 1M file
2723 test_21_sub ${TESTFILE}_1 1 30 &
2725 # repeat writing on a 128M file
2726 test_21_sub ${TESTFILE}_2 128 30 &
2729 local time=$(($(date +%s) + 30))
2731 while [ $(date +%s) -lt $time ]; do
2732 log "Set quota for $i times"
2733 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2734 -I $((ILIMIT + i)) $MOUNT ||
2735 error "Set user quota failed"
2736 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2737 -I $((ILIMIT + i)) $MOUNT ||
2738 error "Set group quota failed"
2739 if is_project_quota_supported; then
2740 $LFS setquota -p $TSTPRJID -b 0 -B \
2741 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2742 error "Set project quota failed"
2750 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2752 if [ $count -gt 60 ]; then
2753 quota_error a $TSTUSR "dd should be finished!"
2757 echo "(dd_pid=$DDPID1, time=$count)successful"
2761 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2763 if [ $count -gt 60 ]; then
2764 quota_error a $TSTUSR "dd should be finished!"
2768 echo "(dd_pid=$DDPID2, time=$count)successful"
2770 run_test 21 "Setquota while writing & deleting (b16053)"
2772 # enable/disable quota enforcement permanently
2774 echo "Set both mdt & ost quota type as ug"
2776 is_project_quota_supported && qtype=$QTYPE
2777 set_mdt_qtype $qtype || error "enable mdt quota failed"
2778 set_ost_qtype $qtype || error "enable ost quota failed"
2781 stopall || error "failed to stopall (1)"
2785 echo "Verify if quota is enabled"
2786 local qtype1=$(mdt_quota_type)
2787 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2788 qtype=$(ost_quota_type)
2789 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2791 echo "Set both mdt & ost quota type as none"
2792 set_mdt_qtype "none" || error "disable mdt quota failed"
2793 set_ost_qtype "none" || error "disable ost quota failed"
2796 stopall || error "failed to stopall (2)"
2801 echo "Verify if quota is disabled"
2802 qtype=$(mdt_quota_type)
2803 [ $qtype != "none" ] && error "mdt quota setting is lost"
2804 qtype=$(ost_quota_type)
2805 [ $qtype != "none" ] && error "ost quota setting is lost"
2809 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2812 local TESTFILE="$DIR/$tdir/$tfile"
2815 setup_quota_test || error "setup quota failed with $?"
2817 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2820 log "User quota (limit: $LIMIT MB)"
2821 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2822 error "set quota failed"
2823 quota_show_check b u $TSTUSR
2825 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2826 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2828 log "Step1: trigger EDQUOT with O_DIRECT"
2829 log "Write half of file"
2830 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2831 quota_error u $TSTUSR "(1) Write failure, expect success." \
2833 log "Write out of block quota ..."
2834 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2835 oflag=direct conv=notrunc &&
2836 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2840 log "Step2: rewrite should succeed"
2841 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2842 quota_error u $TSTUSR "(3) Write failure, expect success." \
2848 local OST0_UUID=$(ostuuid_from_index 0)
2849 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2850 [ $OST0_QUOTA_USED -ne 0 ] &&
2851 ($SHOW_QUOTA_USER; \
2852 quota_error u $TSTUSR "quota isn't released")
2857 [ "$ost1_FSTYPE" == zfs ] &&
2858 skip "Overwrite in place is not guaranteed to be " \
2859 "space neutral on ZFS"
2861 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2862 check_whether_skip && return 0
2863 log "run for 4MB test file"
2866 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2867 check_whether_skip && return 0
2868 log "run for 40MB test file"
2871 run_test 23 "Quota should be honored with directIO (b16125)"
2875 local TESTFILE="$DIR/$tdir/$tfile"
2877 setup_quota_test || error "setup quota failed with $?"
2879 set_ost_qtype $QTYPE || error "enable ost quota failed"
2881 # bind file to a single OST
2882 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2883 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2885 echo "Set user quota (limit: ${blimit}M)"
2886 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2887 error "set quota failed"
2889 # overrun quota by root user
2890 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2891 error "write failure, expect success"
2892 cancel_lru_locks osc
2893 sync_all_data || true
2895 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2897 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2899 test_27a() { # b19612
2900 $LFS quota $TSTUSR $DIR &&
2901 error "lfs succeeded with no type, but should have failed"
2902 $LFS setquota $TSTUSR $DIR &&
2903 error "lfs succeeded with no type, but should have failed"
2906 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2908 test_27b() { # b20200
2909 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2910 error "lfs setquota failed with uid argument"
2911 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2912 error "lfs stequota failed with gid argument"
2913 if is_project_quota_supported; then
2914 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2915 1000 $DIR || error \
2916 "lfs stequota failed with projid argument"
2918 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2919 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2920 if is_project_quota_supported; then
2921 $SHOW_QUOTA_PROJID ||
2922 error "lfs quota failed with projid argument"
2924 resetquota -u $TSTID
2925 resetquota -g $TSTID
2926 resetquota -p $TSTPRJID
2929 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2934 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2935 error "lfs setquota failed"
2937 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2938 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2939 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2940 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2942 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2943 error "lfs setquota for $TSTID failed"
2945 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2946 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2947 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2948 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2950 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2951 error "total allocated inode/block limit not printed"
2953 resetquota -u $TSTUSR
2955 run_test 27c "lfs quota should support human-readable output"
2962 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2963 error "set fraction block limit failed"
2964 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2965 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2966 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2967 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2969 resetquota -u $TSTUSR
2971 run_test 27d "lfs setquota should support fraction block limit"
2975 local TESTFILE="$DIR/$tdir/$tfile"
2978 setup_quota_test || error "setup quota failed with $?"
2980 set_ost_qtype "u" || error "enable ost quota failed"
2982 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2983 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2985 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2986 $MAX_IQ_TIME $DIR || error "set grace time failed"
2987 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2988 error "set quota failed"
2989 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2990 cancel_lru_locks osc
2992 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2993 # over-quota flag has not yet settled since we do not trigger async
2994 # events based on grace time period expiration
2996 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2997 cancel_lru_locks osc
2998 # now over-quota flag should be settled and further writes should fail
3000 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3001 error "grace times were reset"
3002 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3003 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3005 run_test 30 "Hard limit updates should not reset grace times"
3007 # basic usage tracking for user & group
3009 local INODES=10 # files
3010 local BLK_CNT=2 # MB each
3011 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3013 setup_quota_test || error "setup quota failed with $?"
3015 # make sure the system is clean
3016 local USED=$(getquota -u $TSTID global curspace)
3018 error "Used space ($USED) for user $TSTID isn't 0."
3019 USED=$(getquota -g $TSTID global curspace)
3021 error "Used space ($USED) for group $TSTID isn't 0."
3022 if is_project_quota_supported; then
3023 USED=$(getquota -p $TSTPRJID global curspace)
3024 [ $USED -ne 0 ] && error \
3025 "Used space ($USED) for project $TSTPRJID isn't 0."
3028 echo "Write files..."
3029 for i in $(seq 0 $INODES); do
3030 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3031 error "write failed"
3032 is_project_quota_supported &&
3033 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3034 echo "Iteration $i/$INODES completed"
3036 cancel_lru_locks osc
3038 echo "Wait for setattr on objects finished..."
3039 wait_delete_completed
3041 sync; sync_all_data || true
3043 echo "Verify disk usage after write"
3044 USED=$(getquota -u $TSTID global curspace)
3045 [ $USED -lt $TOTAL_BLKS ] &&
3046 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3047 USED=$(getquota -g $TSTID global curspace)
3048 [ $USED -lt $TOTAL_BLKS ] &&
3049 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3050 if is_project_quota_supported; then
3051 USED=$(getquota -p $TSTPRJID global curspace)
3052 [ $USED -lt $TOTAL_BLKS ] && error \
3053 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3056 echo "Verify inode usage after write"
3057 USED=$(getquota -u $TSTID global curinodes)
3058 [ $USED -lt $INODES ] &&
3059 error "Used inode for user $TSTID is $USED, expected $INODES"
3060 USED=$(getquota -g $TSTID global curinodes)
3061 [ $USED -lt $INODES ] &&
3062 error "Used inode for group $TSTID is $USED, expected $INODES"
3063 if is_project_quota_supported; then
3064 USED=$(getquota -p $TSTPRJID global curinodes)
3065 [ $USED -lt $INODES ] && error \
3066 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3071 echo "Verify disk usage after delete"
3072 USED=$(getquota -u $TSTID global curspace)
3073 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3074 USED=$(getquota -u $TSTID global curinodes)
3075 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3076 USED=$(getquota -g $TSTID global curspace)
3077 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3078 USED=$(getquota -g $TSTID global curinodes)
3079 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3080 if is_project_quota_supported; then
3081 USED=$(getquota -p $TSTPRJID global curspace)
3083 error "Used space for project $TSTPRJID isn't 0. $USED"
3084 USED=$(getquota -p $TSTPRJID global curinodes)
3086 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3089 run_test 33 "Basic usage tracking for user & group & project"
3091 # usage transfer test for user & group & project
3093 local BLK_CNT=2 # MB
3094 local project_supported="no"
3096 is_project_quota_supported && project_supported="yes"
3097 setup_quota_test || error "setup quota failed with $?"
3099 # make sure the system is clean
3100 local USED=$(getquota -u $TSTID global curspace)
3101 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3102 USED=$(getquota -g $TSTID global curspace)
3103 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3105 local USED=$(getquota -u $TSTID2 global curspace)
3106 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3107 if [ $project_supported == "yes" ]; then
3108 USED=$(getquota -p $TSTPRJID global curspace)
3109 [ $USED -ne 0 ] && error \
3110 "Used space ($USED) for Project $TSTPRJID isn't 0."
3113 echo "Write file..."
3114 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3115 error "write failed"
3116 cancel_lru_locks osc
3117 sync; sync_all_data || true
3119 echo "chown the file to user $TSTID"
3120 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3122 echo "Wait for setattr on objects finished..."
3123 wait_delete_completed
3125 BLK_CNT=$((BLK_CNT * 1024))
3127 echo "Verify disk usage for user $TSTID"
3128 USED=$(getquota -u $TSTID global curspace)
3129 [ $USED -lt $BLK_CNT ] &&
3130 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3131 USED=$(getquota -u $TSTID global curinodes)
3133 error "Used inodes for user $TSTID is $USED, expected 1"
3135 echo "chgrp the file to group $TSTID"
3136 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3138 echo "Wait for setattr on objects finished..."
3139 wait_delete_completed
3141 echo "Verify disk usage for group $TSTID"
3142 USED=$(getquota -g $TSTID global curspace)
3143 [ $USED -ge $BLK_CNT ] ||
3144 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3145 USED=$(getquota -g $TSTID global curinodes)
3147 error "Used inodes for group $TSTID is $USED, expected 1"
3149 # chown won't change the ost object group. LU-4345 */
3150 echo "chown the file to user $TSTID2"
3151 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3153 echo "Wait for setattr on objects finished..."
3154 wait_delete_completed
3156 echo "change_project project id to $TSTPRJID"
3157 [ $project_supported == "yes" ] &&
3158 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3159 echo "Wait for setattr on objects finished..."
3160 wait_delete_completed
3162 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3163 USED=$(getquota -u $TSTID2 global curspace)
3164 [ $USED -lt $BLK_CNT ] &&
3165 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3166 USED=$(getquota -u $TSTID global curspace)
3168 error "Used space for user $TSTID is $USED, expected 0"
3169 USED=$(getquota -g $TSTID global curspace)
3170 [ $USED -lt $BLK_CNT ] &&
3171 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3172 if [ $project_supported == "yes" ]; then
3173 USED=$(getquota -p $TSTPRJID global curspace)
3174 [ $USED -lt $BLK_CNT ] && error \
3175 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3179 run_test 34 "Usage transfer for user & group & project"
3181 # usage is still accessible across restart
3183 local BLK_CNT=2 # MB
3185 setup_quota_test || error "setup quota failed with $?"
3187 echo "Write file..."
3188 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3189 error "write failed"
3190 is_project_quota_supported &&
3191 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3192 cancel_lru_locks osc
3194 echo "Wait for setattr on objects finished..."
3195 wait_delete_completed
3197 sync; sync_all_data || true
3199 echo "Save disk usage before restart"
3200 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3201 [ $ORIG_USR_SPACE -eq 0 ] &&
3202 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3203 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3204 [ $ORIG_USR_INODES -eq 0 ] &&
3205 error "Used inodes for user $TSTID is 0, expected 1"
3206 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3207 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3208 [ $ORIG_GRP_SPACE -eq 0 ] &&
3209 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3210 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3211 [ $ORIG_GRP_INODES -eq 0 ] &&
3212 error "Used inodes for group $TSTID is 0, expected 1"
3213 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3215 if is_project_quota_supported; then
3216 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3217 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3218 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3219 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3220 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3221 "Used inodes for project $TSTPRJID is 0, expected 1"
3222 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3230 echo "Verify disk usage after restart"
3231 local USED=$(getquota -u $TSTID global curspace)
3232 [ $USED -eq $ORIG_USR_SPACE ] ||
3233 error "Used space for user $TSTID changed from " \
3234 "$ORIG_USR_SPACE to $USED"
3235 USED=$(getquota -u $TSTID global curinodes)
3236 [ $USED -eq $ORIG_USR_INODES ] ||
3237 error "Used inodes for user $TSTID changed from " \
3238 "$ORIG_USR_INODES to $USED"
3239 USED=$(getquota -g $TSTID global curspace)
3240 [ $USED -eq $ORIG_GRP_SPACE ] ||
3241 error "Used space for group $TSTID changed from " \
3242 "$ORIG_GRP_SPACE to $USED"
3243 USED=$(getquota -g $TSTID global curinodes)
3244 [ $USED -eq $ORIG_GRP_INODES ] ||
3245 error "Used inodes for group $TSTID changed from " \
3246 "$ORIG_GRP_INODES to $USED"
3247 if [ $project_supported == "yes" ]; then
3248 USED=$(getquota -p $TSTPRJID global curinodes)
3249 [ $USED -eq $ORIG_PRJ_INODES ] ||
3250 error "Used inodes for project $TSTPRJID " \
3251 "changed from $ORIG_PRJ_INODES to $USED"
3252 USED=$(getquota -p $TSTPRJID global curspace)
3253 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3254 error "Used space for project $TSTPRJID "\
3255 "changed from $ORIG_PRJ_SPACE to $USED"
3258 # check if the vfs_dq_init() is called before writing
3259 echo "Append to the same file..."
3260 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3261 error "write failed"
3262 cancel_lru_locks osc
3263 sync; sync_all_data || true
3265 echo "Verify space usage is increased"
3266 USED=$(getquota -u $TSTID global curspace)
3267 [ $USED -gt $ORIG_USR_SPACE ] ||
3268 error "Used space for user $TSTID isn't increased" \
3269 "orig:$ORIG_USR_SPACE, now:$USED"
3270 USED=$(getquota -g $TSTID global curspace)
3271 [ $USED -gt $ORIG_GRP_SPACE ] ||
3272 error "Used space for group $TSTID isn't increased" \
3273 "orig:$ORIG_GRP_SPACE, now:$USED"
3274 if [ $project_supported == "yes" ]; then
3275 USED=$(getquota -p $TSTPRJID global curspace)
3276 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3277 error "Used space for project $TSTPRJID isn't " \
3278 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3281 run_test 35 "Usage is still accessible across reboot"
3283 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3286 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3287 skip "Old server doesn't have LU-5006 fix."
3289 setup_quota_test || error "setup quota failed with $?"
3291 # make sure the system is clean
3292 local USED=$(getquota -u $TSTID global curspace)
3294 error "Used space ($USED) for user $TSTID isn't 0."
3296 # create file with MDS_OPEN_DELAY_CREATE flag
3297 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3298 error "Create file failed"
3300 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3301 oflag=sync || error "Write file failed"
3303 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3305 # wait for setattr on objects finished..."
3306 wait_delete_completed
3308 USED=$(getquota -u $TSTID global curspace)
3309 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3311 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3315 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3316 skip "Old server doesn't have LU-8801 fix."
3318 [ "$UID" != 0 ] && skip_env "must run as root" && return
3320 setup_quota_test || error "setup quota failed with $?"
3322 # make sure the system is clean
3323 local USED=$(getquota -u $TSTID global curspace)
3325 error "Used space ($USED) for user $TSTID isn't 0."
3326 USED=$(getquota -u $TSTID2 global curspace)
3328 error "Used space ($USED) for user $TSTID2 isn't 0."
3330 local TESTFILE="$DIR/$tdir/$tfile"
3331 local file_cnt=10000
3333 # Generate id entries in accounting file
3334 echo "Create $file_cnt files..."
3335 for i in `seq $file_cnt`; do
3337 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3338 error "failed to chown $TESTFILE-$i"
3340 cancel_lru_locks osc
3341 sync; sync_all_data || true
3343 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3344 procf=${procf}.quota_slave.acct_user
3347 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3348 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3349 echo "Found $acct_cnt id entries"
3351 [ $file_cnt -eq $acct_cnt ] || {
3352 do_facet mds1 $LCTL get_param $procf
3353 error "skipped id entries"
3356 run_test 38 "Quota accounting iterator doesn't skip id entries"
3359 local TESTFILE="$DIR/$tdir/project"
3360 ! is_project_quota_supported &&
3361 skip "Project quota is not supported"
3363 setup_quota_test || error "setup quota failed with $?"
3366 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3367 [ $projectid -ne 0 ] &&
3368 error "Project id should be 0 not $projectid"
3369 change_project -p 1024 $TESTFILE
3370 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3371 [ $projectid -ne 1024 ] &&
3372 error "Project id should be 1024 not $projectid"
3374 stopall || error "failed to stopall (1)"
3377 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3378 [ $projectid -eq 1024 ] ||
3379 error "Project id should be 1024 not $projectid"
3381 run_test 39 "Project ID interface works correctly"
3384 ! is_project_quota_supported &&
3385 skip "Project quota is not supported"
3386 local dir1="$DIR/$tdir/dir1"
3387 local dir2="$DIR/$tdir/dir2"
3389 setup_quota_test || error "setup quota failed with $?"
3391 mkdir -p $dir1 $dir2
3392 change_project -sp 1 $dir1 && touch $dir1/1
3393 change_project -sp 2 $dir2
3395 ln $dir1/1 $dir2/1_link &&
3396 error "Hard link across different project quota should fail"
3399 run_test 40a "Hard link across different project ID"
3402 ! is_project_quota_supported &&
3403 skip "Project quota is not supported"
3404 local dir1="$DIR/$tdir/dir1"
3405 local dir2="$DIR/$tdir/dir2"
3407 setup_quota_test || error "setup quota failed with $?"
3408 mkdir -p $dir1 $dir2
3409 change_project -sp 1 $dir1 && touch $dir1/1
3410 change_project -sp 2 $dir2
3412 mv $dir1/1 $dir2/2 || error "mv failed $?"
3413 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3414 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3416 run_test 40b "Mv across different project ID"
3419 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3420 ! is_project_quota_supported &&
3421 skip "Project quota is not supported"
3423 setup_quota_test || error "setup quota failed with $?"
3424 local dir="$DIR/$tdir/dir"
3426 mkdir -p $dir && change_project -sp 1 $dir
3427 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3428 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3429 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3430 touch $dir/remote_dir/file
3431 #verify inherit works file for remote dir.
3432 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3433 [ "$projid" != "1" ] &&
3434 error "file under remote dir expected 1 not $projid"
3436 #Agent inode should be ignored for project quota
3437 local used=$(getquota -p 1 global curinodes)
3439 error "file count expected 3 got $used"
3441 run_test 40c "Remote child Dir inherit project quota properly"
3444 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3445 is_project_quota_supported || skip "Project quota is not supported"
3447 setup_quota_test || error "setup quota failed with $?"
3448 local dir="$DIR/$tdir/dir"
3451 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3452 change_project -sp $TSTPRJID $dir ||
3453 error "change project on $dir failed"
3454 for i in $(seq 5); do
3455 mkdir -p $dir/d$i/d$i ||
3456 error "mkdir $dir/d$i/d$i failed"
3457 local projid=$($LFS project -d $dir/d$i/d$i |
3459 [ "$projid" == "$TSTPRJID" ] ||
3460 error "projid id expected $TSTPRJID not $projid"
3461 touch $dir/d$i/d$i/file
3462 #verify inherit works file for stripe dir.
3463 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3464 [ "$projid" == "$TSTPRJID" ] ||
3465 error "file under remote dir expected 1 not $projid"
3468 # account should be 1 + (2 + 1) *10 + 1 * 5
3469 local used=$(getquota -p $TSTPRJID global curinodes)
3471 error "file count expected 36 got $used"
3473 run_test 40d "Stripe Directory inherit project quota properly"
3476 is_project_quota_supported ||
3477 skip "Project quota is not supported"
3478 setup_quota_test || error "setup quota failed with $?"
3479 local dir="$DIR/$tdir/dir"
3482 local projid=$((testnum * 1000))
3486 # enable mdt/ost quota
3487 set_mdt_qtype ugp || error "enable mdt quota failed"
3488 set_ost_qtype ugp || error "enable ost quota failed"
3490 test_mkdir -p $dir && change_project -sp $projid $dir
3491 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3492 error "set project quota failed"
3497 # check if df output works as expected
3498 echo "== global statfs: $MOUNT =="
3499 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3501 echo "== project statfs (prjid=$projid): $dir =="
3502 df -kP $dir; df -iP $dir
3503 local bused=$(getquota -p $projid global curspace)
3504 local iused=$(getquota -p $projid global curinodes)
3505 # note trailing space to match double printf from awk
3506 local expected="$blimit $bused $ilimit $iused "
3508 wait_update $HOSTNAME \
3509 "{ df -kP $dir; df -iP $dir; } |
3510 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3512 error "failed to get correct statfs for project quota"
3514 run_test 41 "df should return projid-specific values"
3517 ! is_project_quota_supported &&
3518 skip "Project quota is not supported"
3520 setup_quota_test || error "setup quota failed with $?"
3521 local dir1="$DIR/$tdir/dir1"
3522 local dir2="$DIR/$tdir/dir2"
3524 mkdir -p $dir1 && change_project -sp 1 $dir1
3525 mkdir -p $dir2 && change_project -sp 2 $dir2
3526 for num in $(seq 1 10); do
3527 touch $dir1/file_$num $dir2/file_$num
3528 ln -s $dir1/file_$num $dir1/file_$num"_link"
3529 ln -s $dir2/file_$num $dir2/file_$num"_link"
3532 count=$($LFS find --projid 1 $DIR | wc -l)
3533 [ "$count" != 21 ] && error "expected 21 but got $count"
3535 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3536 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3537 [ $count -eq 22 ] || error "expected 22 but got $count"
3539 run_test 50 "Test if lfs find --projid works"
3542 ! is_project_quota_supported &&
3543 skip "Project quota is not supported"
3544 setup_quota_test || error "setup quota failed with $?"
3545 local dir="$DIR/$tdir/dir"
3547 mkdir $dir && change_project -sp 1 $dir
3548 local used=$(getquota -p 1 global curinodes)
3549 [ $used != "1" ] && error "expected 1 got $used"
3554 used=$(getquota -p 1 global curinodes)
3555 [ $used != "4" ] && error "expected 4 got $used"
3557 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3559 cp $DIR/$tdir/6 $dir/6
3560 used=$(getquota -p 1 global curinodes)
3561 [ $used != "5" ] && error "expected 5 got $used"
3564 mv $DIR/$tdir/6 $dir/7
3565 used=$(getquota -p 1 global curinodes)
3566 [ $used -eq 6 ] || error "expected 6 got $used"
3568 run_test 51 "Test project accounting with mv/cp"
3571 ! is_project_quota_supported &&
3572 skip "Project quota is not supported"
3573 setup_quota_test || error "setup quota failed with $?"
3574 local dir="$DIR/$tdir/dir"
3575 mkdir $dir && change_project -sp 1 $dir
3577 touch $DIR/$tdir/file
3578 #Try renaming a file into the project. This should fail.
3579 for num in $(seq 1 2000); do
3580 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3581 error "rename should fail"
3585 run_test 52 "Rename across different project ID"
3588 ! is_project_quota_supported &&
3589 skip "Project quota is not supported"
3590 setup_quota_test || error "setup quota failed with $?"
3591 local dir="$DIR/$tdir/dir"
3592 mkdir $dir && change_project -s $dir
3593 [[ $($LFS project -d $dir) =~ " P " ]] ||
3594 error "inherit attribute should be set"
3596 change_project -C $dir
3597 [[ $($LFS project -d $dir) =~ " - " ]] ||
3598 error "inherit attribute should be cleared"
3600 run_test 53 "Project inherit attribute could be cleared"
3603 ! is_project_quota_supported &&
3604 skip "Project quota is not supported"
3605 setup_quota_test || error "setup quota failed with $?"
3606 local testfile="$DIR/$tdir/$tfile-0"
3608 #set project ID/inherit attribute
3609 change_project -sp $TSTPRJID $DIR/$tdir
3610 $RUNAS createmany -m ${testfile} 100 ||
3611 error "create many files failed"
3613 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3614 # one more count for directory itself */
3618 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3619 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3621 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3622 [ $proj_count1 -eq $proj_count ] ||
3623 error "c2: expected $proj_count got $proj_count1"
3625 #clear project but with kept projid
3626 change_project -rCk $DIR/$tdir
3627 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3628 [ $proj_count1 -eq 1 ] ||
3629 error "c3: expected 1 got $proj_count1"
3631 #verify projid untouched.
3632 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3634 [ $proj_count1 -eq $proj_count ] ||
3635 error "c4: expected $proj_count got $proj_count1"
3638 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3639 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3640 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3642 #this time clear all
3643 change_project -rC $DIR/$tdir
3644 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3645 [ $proj_count1 -eq 0 ] ||
3646 error "c6: expected 0 got $proj_count1"
3648 unlinkmany ${testfile} 100 ||
3649 error "unlink many files failed"
3651 run_test 54 "basic lfs project interface test"
3654 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3655 skip "Not supported before 2.10.58."
3656 setup_quota_test || error "setup quota failed with $?"
3658 set_ost_qtype $QTYPE || error "enable ost quota failed"
3661 #add second group to TSTUSR
3662 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3665 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3666 error "failed to dd"
3668 cancel_lru_locks osc
3669 sync; sync_all_data || true
3671 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3672 error "failed to setquota on group $TSTUSR2"
3674 $LFS quota -v -g $TSTUSR2 $DIR
3676 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3677 error "chgrp should failed with -EDQUOT"
3679 USED=$(getquota -g $TSTUSR2 global curspace)
3682 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3683 error "failed to setquota on group $TSTUSR2"
3685 $LFS quota -v -g $TSTUSR2 $DIR
3687 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3688 error "chgrp should succeed"
3690 $LFS quota -v -g $TSTUSR2 $DIR
3692 run_test 55 "Chgrp should be affected by group quota"
3695 setup_quota_test || error "setup quota failed with $?"
3697 set_ost_qtype $QTYPE || error "enable ost quota failed"
3700 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3701 erro "failed to set grace time for usr quota"
3702 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3703 awk '{print $4 $8}')
3704 if [ "x$grace_time" != "x10s;10s" ]; then
3705 $LFS quota -t -u $DIR
3706 error "expected grace time: 10s;10s, got:$grace_time"
3709 run_test 56 "lfs quota -t should work well"
3712 setup_quota_test || error "setup quota failed with $?"
3714 local dir="$DIR/$tdir/dir"
3717 #command can process further if it hit some errors
3718 $LFS project -sp 1 $dir/pipe
3719 touch $dir/aaa $dir/bbb
3720 mkdir $dir/subdir -p
3721 touch $dir/subdir/aaa $dir/subdir/bbb
3722 #create one invalid link file
3723 ln -s $dir/not_exist_file $dir/ccc
3724 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3725 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3727 run_test 57 "lfs project could tolerate errors"
3730 [ "$mds1_FSTYPE" != ldiskfs ] &&
3731 skip "ldiskfs only test"
3732 disable_project_quota
3733 setup_quota_test || error "setup quota failed with $?"
3736 local testfile="$DIR/$tdir/$tfile-0"
3737 #make sure it did not crash kernel
3738 touch $testfile && lfs project -sp 1 $testfile
3740 enable_project_quota
3742 run_test 59 "lfs project dosen't crash kernel with project disabled"
3745 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3746 skip "Needs MDS version 2.11.53 or later."
3747 setup_quota_test || error "setup quota failed with $?"
3749 local testfile=$DIR/$tdir/$tfile
3752 set_mdt_qtype "ug" || error "enable mdt quota failed"
3754 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3755 error "set quota failed"
3756 quota_show_check a g $TSTUSR
3758 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3759 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3760 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3761 error "create many files failed"
3763 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3765 # root user can overrun quota
3766 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3767 error "root user should succeed"
3769 run_test 60 "Test quota for root with setgid"
3771 # test default quota
3772 test_default_quota() {
3773 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3774 skip "Not supported before 2.11.51."
3779 local qprjid=$TSTPRJID
3783 local LIMIT=20480 #20M disk space
3784 local TESTFILE="$DIR/$tdir/$tfile-0"
3787 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3788 echo "Project quota is not supported" && return 0
3790 [ $qtype == "-u" ] && qdtype="-U"
3791 [ $qtype == "-g" ] && qdtype="-G"
3792 [ $qtype == "-p" ] && {
3797 [ $qres_type == "meta" ] && {
3798 LIMIT=10240 #10K inodes
3803 qpool_cmd="--pool $3"
3804 # pool quotas don't work properly without global limit
3805 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3806 error "set global limit failed"
3809 setup_quota_test || error "setup quota failed with $?"
3813 # enable mdt/ost quota
3814 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3815 set_ost_qtype $QTYPE || error "enable ost quota failed"
3817 log "set to use default quota"
3818 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3819 error "set $qid to use default quota failed"
3821 log "set default quota"
3822 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3823 error "set $qid default quota failed"
3825 log "get default quota"
3826 $LFS quota $qdtype $DIR || error "get default quota failed"
3828 if [ $qres_type == "data" ]; then
3829 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
3830 grep "$MOUNT" | awk '{print $2}')
3831 [ $SLIMIT -eq $LIMIT ] ||
3832 error "the returned default quota is wrong"
3834 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3836 [ $SLIMIT -eq $LIMIT ] ||
3837 error "the returned default quota is wrong"
3840 # make sure the system is clean
3841 local USED=$(getquota $qtype $qid global curspace)
3842 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3844 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3845 error "setstripe $TESTFILE failed"
3846 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3848 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3850 log "Test not out of quota"
3851 if [ $qres_type == "data" ]; then
3852 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3853 quota_error $qtype $qid "write failed, expect succeed"
3855 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3856 quota_error $qtype $qid "create failed, expect succeed"
3858 unlinkmany $TESTFILE $((LIMIT/2))
3861 log "Test out of quota"
3862 # flush cache, ensure noquota flag is set on client
3863 cancel_lru_locks osc
3864 cancel_lru_locks mdc
3865 sync; sync_all_data || true
3866 if [ $qres_type == "data" ]; then
3867 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3868 quota_error $qtype $qid "write succeed, expect EDQUOT"
3870 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3871 quota_error $qtype $qid "create succeed, expect EDQUOT"
3873 unlinkmany $TESTFILE $((LIMIT*2))
3877 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
3878 error "setstripe $TESTFILE failed"
3879 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3881 log "Increase default quota"
3883 # LU-4505: sleep 5 seconds to enable quota acquire
3886 # increase default quota
3887 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
3888 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
3890 cancel_lru_locks osc
3891 cancel_lru_locks mdc
3892 sync; sync_all_data || true
3893 if [ $qres_type == "data" ]; then
3894 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3895 quota_error $qtype $qid "write failed, expect succeed"
3897 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3898 quota_error $qtype $qid "create failed, expect succeed"
3900 unlinkmany $TESTFILE $((LIMIT*2))
3903 log "Set quota to override default quota"
3904 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3905 error "set $qid quota failed"
3907 cancel_lru_locks osc
3908 cancel_lru_locks mdc
3909 sync; sync_all_data || true
3910 if [ $qres_type == "data" ]; then
3911 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3912 quota_error $qtype $qid "write succeed, expect EQUOT"
3914 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3915 quota_error $qtype $qid "create succeed, expect EQUOT"
3917 unlinkmany $TESTFILE $((LIMIT*2))
3920 log "Set to use default quota again"
3922 # LU-4505: sleep 5 seconds to enable quota acquire
3925 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
3926 error "set $qid to use default quota failed"
3928 cancel_lru_locks osc
3929 cancel_lru_locks mdc
3930 sync; sync_all_data || true
3931 if [ $qres_type == "data" ]; then
3932 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3933 quota_error $qtype $qid "write failed, expect succeed"
3935 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3936 quota_error $qtype $qid "create failed, expect succeed"
3938 unlinkmany $TESTFILE $((LIMIT*2))
3943 wait_delete_completed || error "wait_delete_completed failed"
3944 sync_all_data || true
3946 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
3947 error "reset default quota failed"
3948 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
3949 error "reset quota failed"
3954 test_default_quota "-u" "data"
3955 test_default_quota "-u" "meta"
3956 test_default_quota "-g" "data"
3957 test_default_quota "-g" "meta"
3958 test_default_quota "-p" "data"
3959 test_default_quota "-p" "meta"
3961 run_test 61 "default quota tests"
3964 ! is_project_quota_supported &&
3965 skip "Project quota is not supported"
3966 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3967 skip "chattr did not support project quota"
3968 setup_quota_test || error "setup quota failed with $?"
3969 local testdir=$DIR/$tdir/
3971 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3972 change_project -s $testdir
3973 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3974 error "inherit attribute should be set"
3975 # chattr used FS_IOC_SETFLAGS ioctl
3976 $RUNAS chattr -P $testdir &&
3977 error "regular user clear inherit should fail"
3978 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3979 error "inherit attribute should still be set"
3980 chattr -P $testdir || error "root failed to clear inherit"
3981 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3982 error "inherit attribute should be cleared"
3985 run_test 62 "Project inherit should be only changed by root"
3988 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3989 skip "Not supported before 2.11.55"
3993 local dd_failed=false
3994 local tdir_dom=${tdir}_dom
3995 local LIMIT=20480 #20M
3997 [ $qtype == "p" ] && ! is_project_quota_supported &&
3998 echo "Project quota is not supported" && return 0
4000 [ $qtype == "p" ] && qid=$TSTPRJID
4002 setup_quota_test || error "setup quota failed with $?"
4006 # enable mdt/ost quota
4007 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4008 set_ost_qtype $QTYPE || error "enable ost quota failed"
4010 # make sure the system is clean
4011 local USED=$(getquota -$qtype $qid global curspace)
4012 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4014 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4016 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4017 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4018 error "setstripe $tdir_dom failed"
4019 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4021 [ $qtype == "p" ] && {
4022 change_project -sp $TSTPRJID $DIR/$tdir
4023 change_project -sp $TSTPRJID $DIR/$tdir_dom
4026 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4027 error "set $qid quota failed"
4029 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4030 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4034 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4036 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4037 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4041 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4043 rm -f $DIR/$tdir_dom/*
4045 # flush cache, ensure noquota flag is set on client
4046 cancel_lru_locks osc
4047 cancel_lru_locks mdc
4048 sync; sync_all_data || true
4052 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4053 quota_error $qtype $qid "write failed, expect succeed"
4055 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4056 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4060 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4063 rm -f $DIR/$tdir_dom/*
4065 # flush cache, ensure noquota flag is set on client
4066 cancel_lru_locks osc
4067 cancel_lru_locks mdc
4068 sync; sync_all_data || true
4072 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4073 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4077 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4079 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4080 quota_error $qtype $qid "write succeed, expect EDQUOT"
4083 rm -fr $DIR/$tdir_dom
4085 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4086 error "reset usr quota failed"
4094 run_test 63 "quota on DoM tests"
4097 ! is_project_quota_supported &&
4098 skip "Project quota is not supported"
4099 setup_quota_test || error "setup quota failed with $?"
4100 local dir1="$DIR/$tdir/"
4103 ln -s $dir1/file $dir1/file_link
4106 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4107 error "set project should succeed"
4109 used=$(getquota -p $TSTPRJID global curinodes)
4110 [ $used -eq 4 ] || error "expected 4 got $used"
4111 $LFS project -rC $dir1 >&/dev/null ||
4112 error "clear project should succeed"
4114 used=$(getquota -p $TSTPRJID global curinodes)
4115 [ $used -eq 0 ] || error "expected 0 got $used"
4117 run_test 64 "lfs project on non dir/files should succeed"
4121 local TESTFILE="$DIR/$tdir/$tfile-0"
4123 setup_quota_test || error "setup quota failed with $?"
4124 set_ost_qtype $QTYPE || error "enable ost quota failed"
4128 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4129 error "failed to write"
4130 # flush cache, ensure noquota flag is set on client
4131 cancel_lru_locks osc
4132 sync; sync_all_data || true
4134 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4135 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4136 local quota_all=$($RUNAS $LFS quota $DIR)
4138 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4139 error "usr quota not match"
4140 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4141 error "grp quota not match"
4143 run_test 65 "Check lfs quota result"
4146 ! is_project_quota_supported &&
4147 skip "Project quota is not supported"
4148 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4149 skip "Not supported before 2.12.4"
4150 setup_quota_test || error "setup quota failed with $?"
4151 local old=$(do_facet mds1 $LCTL get_param -n \
4152 mdt.*.enable_chprojid_gid | head -1)
4153 local testdir=$DIR/$tdir/foo
4155 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4156 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4159 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4160 chown -R $TSTID:$TSTID $testdir
4161 change_project -sp $TSTPRJID $testdir
4162 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4164 $RUNAS lfs project -p 0 $testdir/foo &&
4165 error "nonroot user should fail to set projid"
4167 $RUNAS lfs project -C $testdir/foo &&
4168 error "nonroot user should fail to clear projid"
4170 change_project -C $testdir/foo || error "failed to clear project"
4172 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4173 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4174 "failed to set projid with normal user when enable_chprojid_gid=-1"
4176 $RUNAS lfs project -rC $testdir/ || error \
4177 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4179 touch $testdir/bar || error "failed touch $testdir/bar"
4180 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4181 "normal user should not be able to set projid on root owned file"
4183 change_project -p $TSTPRJID $testdir/bar || error \
4184 "root should be able to change its own file's projid"
4186 run_test 66 "nonroot user can not change project state in default"
4193 local short_qtype=${qtype:0:1}
4196 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4198 quota_usr) _runas=$RUNAS;;
4199 quota_2usr) _runas=$RUNAS2;;
4200 *) error "unknown quota parameter $4";;
4205 $_runas $DD of=$file count=$size ||
4206 quota_error $short_qtype $TSTUSR \
4207 "$qtype write failure, but expect success"
4209 cancel_lru_locks osc
4211 sync; sync_all_data || true
4220 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4222 do_facet mds1 $LCTL get_param $param |
4223 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4228 local testfile="$DIR/$tdir/$tfile-0"
4229 local testfile2="$DIR/$tdir/$tfile-1"
4230 local testfile3="$DIR/$tdir/$tfile-2"
4231 local qpool="qpool1"
4237 [ "$ost1_FSTYPE" == zfs ] &&
4238 skip "ZFS grants some block space together with inode"
4240 setup_quota_test || error "setup quota failed with $?"
4243 set_ost_qtype $QTYPE || error "enable ost quota failed"
4246 log "User quota (block hardlimit:$limit MB)"
4247 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4248 error "set user quota failed"
4250 # make sure the system is clean
4251 used=$(getquota -u $TSTUSR global curspace)
4252 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4254 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4255 echo "granted 0x0 before write $granted"
4257 # trigger reintegration
4258 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4259 procf=${procf}quota_slave.force_reint
4260 do_facet ost1 $LCTL set_param $procf=1 ||
4261 error "force reintegration failed"
4262 wait_ost_reint "u" || error "reintegration failed"
4263 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4264 [ $granted -ne 0 ] &&
4265 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4267 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4268 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4270 # write 10 MB to testfile
4271 test_67_write "$testfile" "user" 10 "quota_usr"
4273 # create qpool and add OST1
4274 pool_add $qpool || error "pool_add failed"
4275 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4276 # as quota_usr hasn't limits, lqe may absent. But it should be
4277 # created after the 1st direct qmt_get.
4278 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4280 # check granted - should be 0, as testfile is located only on OST0
4281 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4282 echo "global granted $granted"
4283 granted=$(getgranted $qpool "dt" $TSTID "usr")
4284 echo "$qpool granted $granted"
4285 [ $granted -ne 0 ] &&
4286 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4288 # add OST0 to qpool and check granted space
4289 pool_add_targets $qpool 0 1 ||
4290 error "pool_add_targets failed"
4291 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4292 echo "Granted $granted_mb MB"
4293 #should be 10M + qunit for each OST
4294 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4295 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4297 $LFS setstripe $testfile2 -c 1 -i 1 ||
4298 error "setstripe $testfile2 failed"
4299 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4300 # Write from another user and check that qpool1
4301 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4302 test_67_write "$testfile2" "user" 10 "quota_2usr"
4303 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4304 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4305 [ $granted -ne 0 ] &&
4306 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4308 # Granted space for quota_2usr in qpool1 should appear only
4309 # when global lqe for this user becomes enforced.
4310 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4311 error "set user quota failed"
4312 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4313 echo "granted_mb $granted_mb"
4314 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4315 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4317 $LFS setstripe $testfile3 -c 1 -i 0 ||
4318 error "setstripe $testfile3 failed"
4319 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4320 test_67_write "$testfile3" "user" 10 "quota_2usr"
4321 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4322 echo "$testfile3 granted_mb $granted_mb"
4323 [ $granted_mb -eq $limit ] ||
4324 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4326 # remove OST1 from the qpool1 and check granted space
4327 # should be 0 for TSTUSR and 10M for TSTUSR2
4328 pool_remove_target $qpool 0
4329 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4330 [ $granted_mb -eq 0 ] ||
4331 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4332 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4333 [ $granted_mb -eq 10 ] ||
4334 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4337 wait_delete_completed || error "wait_delete_completed failed"
4338 sync_all_data || true
4339 used=$(getquota -u $TSTUSR global curspace)
4340 [ $used -eq 0 ] || quota_error u $TSTUSR \
4341 "user quota isn't released after deletion"
4343 run_test 67 "quota pools recalculation"
4350 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4351 awk '/usr/ {getline; print $2}'
4356 local qpool="qpool1"
4359 setup_quota_test || error "setup quota failed with $?"
4362 set_ost_qtype $QTYPE || error "enable ost quota failed"
4364 # check slave number for glbal pool
4365 local nr=$(get_slave_nr "0x0" "usr")
4366 echo "nr result $nr"
4367 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4368 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4370 # create qpool and add OST1
4371 pool_add $qpool || error "pool_add failed"
4372 nr=$(get_slave_nr $qpool "usr")
4373 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4376 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4377 nr=$(get_slave_nr $qpool "usr")
4378 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4381 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4382 nr=$(get_slave_nr $qpool "usr")
4383 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4386 pool_remove_target $qpool 0
4387 nr=$(get_slave_nr $qpool "usr")
4388 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4391 pool_remove_target $qpool 1
4392 nr=$(get_slave_nr $qpool "usr")
4393 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4395 # Check again that all is fine with global pool
4396 nr=$(get_slave_nr "0x0" "usr")
4397 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4398 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4400 run_test 68 "slave number in quota pool changed after each add/remove OST"
4404 local global_limit=200 # MB
4406 local testfile="$DIR/$tdir/$tfile-0"
4407 local dom0="$DIR/$tdir/dom0"
4408 local qpool="qpool1"
4411 setup_quota_test || error "setup quota failed with $?"
4414 set_ost_qtype $QTYPE || error "enable ost quota failed"
4415 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4417 # Save DOM only at MDT0
4418 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4419 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4421 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4423 # create qpool and add OST0
4424 pool_add $qpool || error "pool_add failed"
4425 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4427 log "User quota (block hardlimit:$global_limit MB)"
4428 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4429 error "set user quota failed"
4431 log "User quota (block hardlimit:$limit MB)"
4432 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4433 error "set user quota failed"
4435 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4436 quota_error u $TSTUSR "write failed"
4438 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4439 oflag=sync || quota_error u $TSTUSR "write failed"
4441 $RUNAS $DD of=$testfile count=$limit || true
4443 # flush cache, ensure noquota flag is set on client
4444 cancel_lru_locks osc
4445 sync; sync_all_data || true
4447 # MDT0 shouldn't get EDQUOT with glimpse.
4448 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4449 quota_error u $TSTUSR \
4450 "user write success, but expect EDQUOT"
4452 # Now all members of qpool1 should get EDQUOT. Expect success
4453 # when write to DOM on MDT0, as it belongs to global pool.
4454 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4455 oflag=sync || quota_error u $TSTUSR "write failed"
4457 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4458 oflag=sync || quota_error u $TSTUSR "write failed"
4460 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4464 local qpool="qpool1"
4469 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4470 skip "Needs a client >= $VERSION_WITH_QP"
4472 setup_quota_test || error "setup quota failed with $?"
4474 # MDS returns EFAULT for unsupported quotactl command
4475 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4477 # create qpool and add OST0
4478 pool_add $qpool || error "pool_add failed"
4479 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4481 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4483 [ $rc -eq $err ] || error "setquota res $rc != $err"
4485 # If MDS supports QP, check that limit was set properly.
4486 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4487 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4488 echo "hard limit $bhard limit $limit"
4489 [ $bhard -ne $((limit*1024)) ] &&
4490 error "bhard:$bhard for $qpool!=$((limit*1024))"
4493 $LFS quota -u $TSTUSR --pool $qpool $DIR
4495 [ $rc -eq $err ] || error "quota res $rc != $err"
4497 run_test 70 "check lfs setquota/quota with a pool option"
4502 local global_limit=100 # MB
4503 local testfile="$DIR/$tdir/$tfile-0"
4504 local qpool="qpool1"
4505 local qpool2="qpool2"
4507 [ "$ost1_FSTYPE" == zfs ] &&
4508 skip "ZFS grants some block space together with inode"
4509 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4511 setup_quota_test || error "setup quota failed with $?"
4514 set_ost_qtype $QTYPE || error "enable ost quota failed"
4517 log "User quota (block hardlimit:$global_limit MB)"
4518 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4519 error "set user quota failed"
4521 pool_add $qpool || error "pool_add failed"
4522 pool_add_targets $qpool 0 1 ||
4523 error "pool_add_targets failed"
4525 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4526 error "set user quota failed"
4528 pool_add $qpool2 || error "pool_add failed"
4529 pool_add_targets $qpool2 1 1 ||
4530 error "pool_add_targets failed"
4532 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4533 error "set user quota failed"
4535 # make sure the system is clean
4536 local used=$(getquota -u $TSTUSR global curspace)
4539 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4541 # create 1st component 1-10M
4542 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4543 #create 2nd component 10-30M
4544 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4545 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4547 # сheck normal use and out of quota with PFL
4548 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4549 test_1_check_write $testfile "user" $((limit*2))
4551 wait_delete_completed || error "wait_delete_completed failed"
4552 sync_all_data || true
4553 used=$(getquota -u $TSTUSR global curspace)
4554 [ $used -ne 0 ] && quota_error u $TSTUSR \
4555 "user quota isn't released after deletion"
4557 # create 1st component 1-10M
4558 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4559 # create 2nd component 10-30M
4560 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4561 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4563 # write to the 2nd component
4564 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4565 quota_error u $TSTUSR \
4566 "write failure, but expect success"
4567 # this time maybe cache write, ignore it's failure
4568 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4569 cancel_lru_locks osc
4570 sync; sync_all_data || true
4571 # write over limit in qpool2(2nd component 10-30M)
4572 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4573 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4574 # write to the 1st component - OST0 is empty
4575 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4576 quota_error u $TSTUSR "write failed"
4578 run_test 71a "Check PFL with quota pools"
4582 local global_limit=1000 # MB
4583 local limit1=160 # MB
4584 local limit2=10 # MB
4585 local testfile="$DIR/$tdir/$tfile-0"
4586 local qpool="qpool1"
4587 local qpool2="qpool2"
4589 [ "$ost1_FSTYPE" == zfs ] &&
4590 skip "ZFS grants some block space together with inode"
4591 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4593 setup_quota_test || error "setup quota failed with $?"
4596 set_ost_qtype $QTYPE || error "enable ost quota failed"
4599 log "User quota (block hardlimit:$global_limit MB)"
4600 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4601 error "set user quota failed"
4603 pool_add $qpool || error "pool_add failed"
4604 pool_add_targets $qpool 0 1 ||
4605 error "pool_add_targets failed"
4607 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4608 error "set user quota failed"
4610 pool_add $qpool2 || error "pool_add failed"
4611 pool_add_targets $qpool2 1 1 ||
4612 error "pool_add_targets failed"
4614 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4615 error "set user quota failed"
4617 # make sure the system is clean
4618 local used=$(getquota -u $TSTUSR global curspace)
4621 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4623 # First component is on OST0, 2nd on OST1
4624 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4625 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4627 # fill the 1st component on OST0
4628 $RUNAS $DD of=$testfile count=128 ||
4629 quota_error u $TSTUSR "write failed"
4630 # write to the 2nd cmpnt on OST1
4631 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4632 quota_error u $TSTUSR "write failed"
4633 # this time maybe cache write, ignore it's failure
4634 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4636 cancel_lru_locks osc
4637 sync; sync_all_data || true
4638 # write over limit in qpool2
4639 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4640 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4643 run_test 71b "Check SEL with quota pools"
4648 local global_limit=50 # MB
4649 local testfile="$DIR/$tdir/$tfile-0"
4650 local qpool="qpool1"
4653 setup_quota_test || error "setup quota failed with $?"
4656 set_ost_qtype $QTYPE || error "enable ost quota failed"
4659 log "User quota (block hardlimit:$global_limit MB)"
4660 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4661 error "set user quota failed"
4663 pool_add $qpool || error "pool_add failed"
4664 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4666 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4667 error "set user quota failed"
4669 # make sure the system is clean
4670 local used=$(getquota -u $TSTUSR global curspace)
4672 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4674 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4676 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4677 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4678 test_1_check_write $testfile "user" $limit
4679 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4681 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4682 # check that lfs quota -uv --pool prints only OST that
4683 # was added in a pool
4684 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4685 grep "OST\|MDT" && error "$qpool consists wrong targets"
4688 run_test 72 "lfs quota --pool prints only pool's OSTs"
4692 local qpool="qpool1"
4696 pool_add $qpool || error "pool_add failed"
4697 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4698 error "pool_add_targets failed"
4700 test_default_quota "-u" "data" "qpool1"
4702 run_test 73a "default limits at OST Pool Quotas"
4706 local TESTFILE1="$DIR/$tdir/$tfile-1"
4708 local qpool="qpool1"
4712 setup_quota_test || error "setup quota failed with $?"
4714 set_ost_qtype $QTYPE || error "enable ost quota failed"
4716 # pool quotas don't work properly without global limit
4717 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4718 error "set global limit failed"
4720 pool_add $qpool || error "pool_add failed"
4721 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4722 error "pool_add_targets failed"
4724 log "set default quota for $qpool"
4725 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
4726 error "set default quota failed"
4728 log "Write from user that hasn't lqe"
4729 # Check that it doesn't cause a panic or a deadlock
4730 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
4731 # Have to use RUNAS_ID as resetquota creates lqes in
4732 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
4733 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
4735 cancel_lru_locks osc
4736 sync; sync_all_data || true
4738 run_test 73b "default OST Pool Quotas limit for new user"
4742 local global_limit=200 # 200M
4743 local limit=10 # 10M
4744 local limit2=50 # 50M
4745 local qpool="qpool1"
4746 local qpool2="qpool2"
4750 setup_quota_test || error "setup quota failed with $?"
4753 set_ost_qtype $QTYPE || error "enable ost quota failed"
4755 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4756 error "set user quota failed"
4758 pool_add $qpool || error "pool_add failed"
4759 pool_add_targets $qpool 0 1 ||
4760 error "pool_add_targets failed"
4762 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4763 error "set user quota failed"
4765 pool_add $qpool2 || error "pool_add failed"
4766 pool_add_targets $qpool2 1 1 ||
4767 error "pool_add_targets failed"
4769 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4770 error "set user quota failed"
4772 tmp=$(getquota -u $TSTUSR global bhardlimit)
4773 [ $tmp -eq $((global_limit * 1024)) ] ||
4774 error "wrong global limit $global_limit"
4776 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4777 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4779 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
4780 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
4782 # check limits in pools
4783 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4784 grep -A4 $qpool | awk 'NR == 4{print $4}')
4785 echo "pool limit for $qpool $tmp"
4786 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
4787 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
4788 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
4789 echo "pool limit for $qpool2 $tmp"
4790 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
4792 run_test 74 "check quota pools per user"
4794 function cleanup_quota_test_75()
4796 do_facet mgs $LCTL nodemap_modify --name default \
4797 --property admin --value 1
4798 do_facet mgs $LCTL nodemap_modify --name default \
4799 --property trusted --value 1
4800 do_facet mgs $LCTL nodemap_modify --name default \
4801 --property squash_uid --value 99
4802 do_facet mgs $LCTL nodemap_modify --name default \
4803 --property squash_gid --value 99
4805 wait_nm_sync default admin_nodemap
4806 wait_nm_sync default trusted_nodemap
4808 do_facet mgs $LCTL nodemap_activate 0
4811 resetquota -u $TSTUSR
4815 local dd_failed=false
4816 local LIMIT=20480 #20M
4819 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4820 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4821 oflag=sync || dd_failed=true
4824 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
4826 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
4827 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4828 oflag=sync || dd_failed=true
4831 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
4833 rm -f $DIR/$tdir_dom/*
4835 # flush cache, ensure noquota flag is set on client
4837 sync; sync_all_data || true
4841 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
4842 quota_error u $qid "write failed, expect succeed (2)"
4844 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4845 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4846 oflag=sync || dd_failed=true
4849 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
4852 rm -f $DIR/$tdir_dom/*
4854 # flush cache, ensure noquota flag is set on client
4856 sync; sync_all_data || true
4860 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
4861 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
4862 oflag=sync || dd_failed=true
4865 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
4867 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4868 quota_error u $qid "write succeed, expect EDQUOT (3)"
4874 local soft_limit=10 # MB
4875 local hard_limit=20 # MB
4876 local limit=$soft_limit
4877 local testfile="$DIR/$tdir/$tfile-0"
4878 local grace=20 # seconds
4879 local tdir_dom=${tdir}_dom
4881 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
4885 setup_quota_test || error "setup quota failed with $?"
4886 stack_trap cleanup_quota_test_75 EXIT
4889 set_ost_qtype $QTYPE || error "enable ost quota failed"
4890 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4892 local used=$(getquota -u $TSTID global curspace)
4893 $LFS setquota -t -u --block-grace $grace --inode-grace \
4894 $MAX_IQ_TIME $DIR || error "set user grace time failed"
4895 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
4896 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
4897 error "set user quota failed"
4899 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
4900 mkdir $DIR/$tdir_dom
4901 chmod 777 $DIR/$tdir_dom
4902 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4903 error "setstripe $tdir_dom failed"
4905 do_facet mgs $LCTL nodemap_activate 1
4907 do_facet mgs $LCTL nodemap_modify --name default \
4908 --property admin --value 0
4909 do_facet mgs $LCTL nodemap_modify --name default \
4910 --property trusted --value 0
4911 do_facet mgs $LCTL nodemap_modify --name default \
4912 --property deny_unknown --value 0
4913 do_facet mgs $LCTL nodemap_modify --name default \
4914 --property squash_uid --value $TSTID
4915 do_facet mgs $LCTL nodemap_modify --name default \
4916 --property squash_gid --value $TSTID
4917 cancel_lru_locks mdc
4918 wait_nm_sync default admin_nodemap
4919 wait_nm_sync default trusted_nodemap
4920 wait_nm_sync default squash_uid
4922 # mmap write when over soft limit
4924 $DD of=$testfile count=${limit} ||
4925 quota_error a "root write failure, but expect success (1)"
4926 OFFSET=$((limit * 1024))
4927 cancel_lru_locks osc
4929 echo "Write to exceed soft limit"
4930 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
4931 quota_error a $TSTUSR "root write failure, but expect success (2)"
4932 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
4933 cancel_lru_locks osc
4935 echo "mmap write when over soft limit"
4936 $MULTIOP $testfile.mmap OT40960SMW ||
4937 quota_error a $TSTUSR "mmap write failure, but expect success"
4938 cancel_lru_locks osc
4940 wait_delete_completed || error "wait_delete_completed failed (1)"
4941 sync_all_data || true
4943 # test for user hard limit
4946 $DD of=$testfile bs=1M count=$((limit/2)) ||
4947 quota_error u $TSTID \
4948 "root write failure, but expect success (3)"
4950 log "Write out of block quota ..."
4951 # possibly a cache write, ignore failure
4952 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
4953 # flush cache, ensure noquota flag is set on client
4954 cancel_lru_locks osc
4955 sync; sync_all_data || true
4956 # sync forced cache flush, but did not guarantee that slave
4957 # got new edquot through glimpse, so wait to make sure
4959 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
4960 quota_error u $TSTID \
4961 "user write success, but expect EDQUOT"
4963 wait_delete_completed || error "wait_delete_completed failed (2)"
4964 sync_all_data || true
4965 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
4966 quota_error u $TSTID "user quota not released after deletion"
4970 run_test 75 "nodemap squashed root respects quota enforcement"
4973 ! is_project_quota_supported &&
4974 skip "skip project quota unsupported"
4976 setup_quota_test || error "setup quota failed with $?"
4979 local testfile="$DIR/$tdir/$tfile-0"
4982 $LFS project -p 4294967295 $testfile &&
4983 error "set project ID should fail"
4986 run_test 76 "project ID 4294967295 should be not allowed"
4990 mount_client $MOUNT2 "ro"
4991 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
4992 error "lfs setquota should fail in read-only Lustre mount"
4995 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
4999 do_nodes $(comma_list $(nodes_list)) \
5000 "lctl set_param -n debug=-quota,trace"
5001 if $PQ_CLEANUP; then
5002 disable_project_quota
5005 reset_quota_settings
5010 check_and_cleanup_lustre
5011 export QUOTA_AUTO=$QUOTA_AUTO_OLD