3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 # QP exists since this version. Should be finally set before landing.
43 VERSION_WITH_QP="2.13.53"
45 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
46 skip "Needs MDS version $VERSION_WITH_QP or later."
49 require_dsh_mds || exit 0
50 require_dsh_ost || exit 0
52 # Does e2fsprogs support quota feature?
53 if [ "$mds1_FSTYPE" == ldiskfs ] &&
54 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
55 grep -q 'quota'"; then
56 skip_env "e2fsprogs doesn't support quota"
59 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
61 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
66 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 check_and_setup_lustre
71 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
73 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
74 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
75 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
76 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
77 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
80 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
85 local fail_val=${3:-0}
89 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
90 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
91 ost) NODES="$(comma_list $(osts_nodes))";;
94 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
100 lfs project $* || error "lfs project $* failed"
103 RUNAS="runas -u $TSTID -g $TSTID"
104 RUNAS2="runas -u $TSTID2 -g $TSTID2"
105 DD="dd if=/dev/zero bs=1M"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
112 # resetquota -p projid
115 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
116 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
117 error "resetquota: wrong specifier $1 passed"
119 if [ $1 == "-p" ]; then
120 is_project_quota_supported || return 0
123 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
124 error "clear quota for [type:$1 name:$2] failed"
125 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 log "Files for user ($local_id):"
136 ($LFS find --user $local_id $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
140 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
141 $LFS quota -v -g $local_id $DIR
142 log "Files for group ($local_id):"
143 ($LFS find --group $local_id $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
147 is_project_quota_supported || return 0
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
149 $LFS quota -v -p $TSTPRJID $DIR
150 log "Files for project ($TSTPRJID):"
151 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
168 # get quota for a user or a group
169 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
170 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
177 sync_all_data > /dev/null 2>&1 || true
179 [ "$#" != 4 -a "$#" != 5 ] &&
180 error "getquota: wrong number of arguments: $#"
181 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
182 error "getquota: wrong u/g/p specifier $1 passed"
195 *) error "unknown quota parameter $4";;
198 [ ! -z "$5" ] && pool_arg="--pool $5 "
199 [ "$uuid" = "global" ] && uuid=$DIR
201 $LFS quota -v "$1" "$2" $pool_arg $DIR |
202 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
203 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
208 # usage: set_mdt_qtype ugp|u|g|p|none
212 local mdts=$(get_facets MDS)
214 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
215 qtype=$(tr -d 'p' <<<$qtype)
217 if [[ $PERM_CMD == *"set_param -P"* ]]; then
218 do_facet mgs $PERM_CMD \
219 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
221 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
223 # we have to make sure each MDT received config changes
224 for mdt in ${mdts//,/ }; do
226 cmd="$LCTL get_param -n "
227 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
228 cmd=${cmd}.quota_slave.enabled
230 if $(facet_up $mdt); then
231 wait_update_facet $mdt "$cmd" "$qtype" || return 1
238 # usage: set_ost_qtype ugp|u|g|p|none
242 local osts=$(get_facets OST)
244 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
245 qtype=$(tr -d 'p' <<<$qtype)
247 if [[ $PERM_CMD == *"set_param -P"* ]]; then
248 do_facet mgs $PERM_CMD \
249 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
251 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
253 # we have to make sure each OST received config changes
254 for ost in ${osts//,/ }; do
256 cmd="$LCTL get_param -n "
257 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
258 cmd=${cmd}.quota_slave.enabled
260 if $(facet_up $ost); then
261 wait_update_facet $ost "$cmd" "$qtype" || return 1
267 wait_reintegration() {
271 local result="glb[1],slv[1],reint[0]"
276 if [ $ntype == "mdt" ]; then
277 tgts=$(get_facets MDS)
279 tgts=$(get_facets OST)
282 for tgt in ${tgts//,/ }; do
284 cmd="$LCTL get_param -n "
285 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
286 cmd=${cmd}.quota_slave.info
288 if $(facet_up $tgt); then
289 wait_update_facet $tgt "$cmd |
290 grep "$qtype" | awk '{ print \\\$3 }'" \
291 "$result" $max || return 1
301 if [[ "$qtype" =~ "u" ]]; then
302 wait_reintegration "mdt" "user" $max || return 1
305 if [[ "$qtype" =~ "g" ]]; then
306 wait_reintegration "mdt" "group" $max || return 1
309 if [[ "$qtype" =~ "p" ]]; then
310 ! is_project_quota_supported && return 0
311 wait_reintegration "mdt" "project" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "ost" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "ost" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "ost" "project" $max || return 1
339 local extrasleep=${4:-5}
346 *) error "get_grace_time: Invalid quota type: $qtype"
351 echo "Quota info for $pool:"
352 $LFS quota -$qtype $qarg $parg $DIR
357 time=$(lfs quota -$qtype $qarg $parg $DIR|
358 awk 'NR == 3{ print $5 }'| sed 's/s$//')
361 time=$(lfs quota -$qtype $qarg $DIR|
362 awk 'NR == 3{ print $9 }'| sed 's/s$//')
365 error "Unknown quota type: $flavour"
369 # from lfs.c:__sec2str()
370 # const char spec[] = "smhdw";
371 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
372 [[ $time == *m* ]] && time=${time//m/} && time=$((time*60));
373 [[ $time == *h* ]] && time=${time//h/} && time=$((time*60*60));
374 [[ $time == *d* ]] && time=${time//d/} && time=$((time*24*60*60));
375 [[ $time == *w* ]] && time=${time//w/} && time=$((time*7*24*60*60));
377 echo "Sleep through grace ..."
378 [ "$time" == "-" ] &&
379 error "Grace timeout was not set or quota not exceeded"
380 if [ "$time" == "none" ]; then
381 echo "...Grace timeout already expired"
383 let time+=$extrasleep
384 echo "...sleep $time seconds"
390 wait_delete_completed
391 echo "Creating test directory"
392 mkdir $DIR/$tdir || return 1
393 chmod 0777 $DIR/$tdir || return 2
394 # always clear fail_loc in case of fail_loc isn't cleared
395 # properly when previous test failed
396 lustre_fail mds_ost 0
399 cleanup_quota_test() {
400 echo "Delete files..."
402 echo "Wait for unlink objects finished..."
403 wait_delete_completed
404 sync_all_data || true
414 $LFS quota -v -$ugp $qid $DIR
416 if [ "$bf" == "a" -o "$bf" == "b" ]; then
417 usage=$(getquota -$ugp $qid global curspace)
418 if [ -z $usage ]; then
419 quota_error $ugp $qid \
420 "Query block quota failed ($ugp:$qid)."
422 [ $usage -ne 0 ] && quota_log $ugp $qid \
423 "Block quota isn't 0 ($ugp:$qid:$usage)."
427 if [ "$bf" == "a" -o "$bf" == "f" ]; then
428 usage=$(getquota -$ugp $qid global curinodes)
429 if [ -z $usage ]; then
430 quota_error $ugp $qid \
431 "Query file quota failed ($ugp:$qid)."
433 [ $usage -ne 0 ] && quota_log $ugp $qid \
434 "File quota isn't 0 ($ugp:$qid:$usage)."
439 project_quota_enabled () {
441 local zfeat="feature@project_quota"
443 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
444 local facet_fstype=${facet:0:3}1_FSTYPE
447 if [ "${!facet_fstype}" = "zfs" ]; then
448 devname=$(zpool_name ${facet})
449 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
450 grep -wq active || rc=1
452 [ ${facet:0:3} == "mds" ] &&
453 devname=$(mdsdevname ${facet:3}) ||
454 devname=$(ostdevname ${facet:3})
455 do_facet ${facet} $DEBUGFS -R features $devname |
456 grep -q project || rc=1
459 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
463 project_quota_enabled || enable_project_quota
465 reset_quota_settings() {
466 resetquota -u $TSTUSR
468 resetquota -g $TSTUSR
470 resetquota -u $TSTUSR2
471 resetquota -u $TSTID2
472 resetquota -g $TSTUSR2
473 resetquota -g $TSTID2
474 resetquota -p $TSTPRJID
479 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota+trace"
484 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
485 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
486 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
487 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
489 test_quota_performance() {
490 local TESTFILE="$DIR/$tdir/$tfile-0"
491 local size=$1 # in MB
492 local stime=$(date +%s)
493 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
494 quota_error u $TSTUSR "write failure"
495 local etime=$(date +%s)
496 delta=$((etime - stime))
497 if [ $delta -gt 0 ]; then
498 rate=$((size * 1024 / delta))
499 if [ "$mds1_FSTYPE" = zfs ]; then
500 # LU-2872 - see LU-2887 for fix
502 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
504 [ $rate -gt 1024 ] ||
505 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
511 # test basic quota performance b=21696
514 [ "$SLOW" = "no" ] && MB=10
516 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
517 [ $free_space -le $((MB * 1024)) ] &&
518 skip "not enough space ${free_space} KB, " \
519 "required $((MB * 1024)) KB"
520 setup_quota_test || error "setup quota failed with $?"
521 trap cleanup_quota_test EXIT
523 set_ost_qtype "none" || error "disable ost quota failed"
524 test_quota_performance $MB
526 set_ost_qtype $QTYPE || error "enable ost quota failed"
527 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
528 error "set quota failed"
529 test_quota_performance $MB
533 run_test 0 "Test basic quota performance"
535 # usage: test_1_check_write tfile user|group|project
536 test_1_check_write() {
540 local short_qtype=${qtype:0:1}
543 $RUNAS $DD of=$testfile count=$((limit/2)) ||
544 quota_error $short_qtype $TSTUSR \
545 "$qtype write failure, but expect success"
546 log "Write out of block quota ..."
547 # this time maybe cache write, ignore it's failure
548 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
549 # flush cache, ensure noquota flag is set on client
551 sync; sync_all_data || true
552 # sync means client wrote all it's cache, but id doesn't
553 # garantee that slave got new edquot trough glimpse.
554 # so wait a little to be sure slave got it.
556 $RUNAS $DD of=$testfile count=1 seek=$limit &&
557 quota_error $short_qtype $TSTUSR \
558 "user write success, but expect EDQUOT"
561 # test block hardlimit
564 local testfile="$DIR/$tdir/$tfile-0"
566 setup_quota_test || error "setup quota failed with $?"
567 trap cleanup_quota_test EXIT
570 set_ost_qtype $QTYPE || error "enable ost quota failed"
573 log "User quota (block hardlimit:$limit MB)"
574 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
575 error "set user quota failed"
577 # make sure the system is clean
578 local used=$(getquota -u $TSTUSR global curspace)
579 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
581 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
582 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
584 test_1_check_write $testfile "user" $limit
587 wait_delete_completed || error "wait_delete_completed failed"
588 sync_all_data || true
589 used=$(getquota -u $TSTUSR global curspace)
590 [ $used -ne 0 ] && quota_error u $TSTUSR \
591 "user quota isn't released after deletion"
592 resetquota -u $TSTUSR
595 log "--------------------------------------"
596 log "Group quota (block hardlimit:$limit MB)"
597 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
598 error "set group quota failed"
600 testfile="$DIR/$tdir/$tfile-1"
601 # make sure the system is clean
602 used=$(getquota -g $TSTUSR global curspace)
603 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
605 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
606 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
608 test_1_check_write $testfile "group" $limit
610 wait_delete_completed || error "wait_delete_completed failed"
611 sync_all_data || true
612 used=$(getquota -g $TSTUSR global curspace)
613 [ $used -ne 0 ] && quota_error g $TSTUSR \
614 "Group quota isn't released after deletion"
615 resetquota -g $TSTUSR
617 if ! is_project_quota_supported; then
618 echo "Project quota is not supported"
623 testfile="$DIR/$tdir/$tfile-2"
624 # make sure the system is clean
625 used=$(getquota -p $TSTPRJID global curspace)
627 error "used space($used) for project $TSTPRJID isn't 0"
630 log "--------------------------------------"
631 log "Project quota (block hardlimit:$limit mb)"
632 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
633 error "set project quota failed"
635 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
636 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
637 change_project -p $TSTPRJID $testfile
639 test_1_check_write $testfile "project" $limit
644 used=$(getquota -p $TSTPRJID global curspace)
645 [ $used -ne 0 ] && quota_error p $TSTPRJID \
646 "project quota isn't released after deletion"
648 resetquota -p $TSTPRJID
650 run_test 1a "Block hard limit (normal use and out of quota)"
654 local global_limit=20 # 100M
655 local testfile="$DIR/$tdir/$tfile-0"
659 setup_quota_test || error "setup quota failed with $?"
660 stack_trap cleanup_quota_test EXIT
663 set_ost_qtype $QTYPE || error "enable ost quota failed"
666 log "User quota (block hardlimit:$global_limit MB)"
667 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
668 error "set user quota failed"
670 pool_add $qpool || error "pool_add failed"
671 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
672 error "pool_add_targets failed"
674 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
675 error "set user quota failed"
677 # make sure the system is clean
678 local used=$(getquota -u $TSTUSR global curspace)
680 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
682 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
684 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
685 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
687 test_1_check_write $testfile "user" $limit
690 wait_delete_completed || error "wait_delete_completed failed"
691 sync_all_data || true
692 used=$(getquota -u $TSTUSR global curspace $qpool)
693 [ $used -ne 0 ] && quota_error u $TSTUSR \
694 "user quota isn't released after deletion"
695 resetquota -u $TSTUSR
698 log "--------------------------------------"
699 log "Group quota (block hardlimit:$global_limit MB)"
700 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
701 error "set group quota failed"
703 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
704 error "set group quota failed"
706 testfile="$DIR/$tdir/$tfile-1"
707 # make sure the system is clean
708 used=$(getquota -g $TSTUSR global curspace $qpool)
709 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
711 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
712 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
714 test_1_check_write $testfile "group" $limit
717 wait_delete_completed || error "wait_delete_completed failed"
718 sync_all_data || true
719 used=$(getquota -g $TSTUSR global curspace $qpool)
720 [ $used -ne 0 ] && quota_error g $TSTUSR \
721 "Group quota isn't released after deletion"
722 resetquota -g $TSTUSR
724 if ! is_project_quota_supported; then
725 echo "Project quota is not supported"
730 testfile="$DIR/$tdir/$tfile-2"
731 # make sure the system is clean
732 used=$(getquota -p $TSTPRJID global curspace $qpool)
734 error "used space($used) for project $TSTPRJID isn't 0"
737 log "--------------------------------------"
738 log "Project quota (block hardlimit:$global_limit mb)"
739 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
740 error "set project quota failed"
742 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
743 error "set project quota failed"
746 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
747 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
748 change_project -p $TSTPRJID $testfile
750 test_1_check_write $testfile "project" $limit
755 used=$(getquota -p $TSTPRJID global curspace)
756 [ $used -eq 0 ] || quota_error p $TSTPRJID \
757 "project quota isn't released after deletion"
759 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
762 local global_limit=20 # 100M
763 local testfile="$DIR/$tdir/$tfile-0"
764 local qpool1="qpool1"
765 local qpool2="qpool2"
768 setup_quota_test || error "setup quota failed with $?"
769 stack_trap cleanup_quota_test EXIT
772 set_ost_qtype $QTYPE || error "enable ost quota failed"
775 log "User quota (block hardlimit:$global_limit MB)"
776 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
777 error "set user quota failed"
779 pool_add $qpool1 || error "pool_add failed"
780 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
781 error "pool_add_targets failed"
783 pool_add $qpool2 || error "pool_add failed"
784 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
785 error "pool_add_targets failed"
787 # create pools without hard limit
788 # initially such case raised several bugs
789 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
790 error "set user quota failed"
792 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
793 error "set user quota failed"
795 # make sure the system is clean
796 local used=$(getquota -u $TSTUSR global curspace)
798 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
800 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
802 test_1_check_write $testfile "user" $global_limit
804 used=$(getquota -u $TSTUSR global curspace $qpool1)
805 echo "qpool1 used $used"
806 used=$(getquota -u $TSTUSR global curspace $qpool2)
807 echo "qpool2 used $used"
810 wait_delete_completed || error "wait_delete_completed failed"
811 sync_all_data || true
813 used=$(getquota -u $TSTUSR global curspace $qpool1)
814 [ $used -ne 0 ] && quota_error u $TSTUSR \
815 "user quota isn't released after deletion"
816 resetquota -u $TSTUSR
821 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
824 local limit1=10 # 10M
825 local limit2=12 # 12M
826 local global_limit=20 # 100M
827 local testfile="$DIR/$tdir/$tfile-0"
828 local qpool1="qpool1"
829 local qpool2="qpool2"
832 setup_quota_test || error "setup quota failed with $?"
833 stack_trap cleanup_quota_test EXIT
836 set_ost_qtype $QTYPE || error "enable ost quota failed"
839 log "User quota (block hardlimit:$global_limit MB)"
840 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
841 error "set user quota failed"
843 pool_add $qpool1 || error "pool_add failed"
844 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
845 error "pool_add_targets failed"
847 pool_add $qpool2 || error "pool_add failed"
848 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
849 error "pool_add_targets failed"
851 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
852 error "set user quota failed"
854 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
855 error "set user quota failed"
857 # make sure the system is clean
858 local used=$(getquota -u $TSTUSR global curspace)
860 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
862 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
864 test_1_check_write $testfile "user" $limit1
866 used=$(getquota -u $TSTUSR global curspace $qpool1)
867 echo "qpool1 used $used"
868 used=$(getquota -u $TSTUSR global curspace $qpool2)
869 echo "qpool2 used $used"
872 wait_delete_completed || error "wait_delete_completed failed"
873 sync_all_data || true
875 used=$(getquota -u $TSTUSR global curspace $qpool1)
876 [ $used -ne 0 ] && quota_error u $TSTUSR \
877 "user quota isn't released after deletion"
878 resetquota -u $TSTUSR
883 run_test 1d "Quota pools: check block hardlimit on different pools"
886 local limit1=10 # 10M
887 local global_limit=200 # 200M
888 local testfile="$DIR/$tdir/$tfile-0"
889 local testfile2="$DIR/$tdir/$tfile-1"
890 local qpool1="qpool1"
893 setup_quota_test || error "setup quota failed with $?"
894 stack_trap cleanup_quota_test EXIT
897 set_ost_qtype $QTYPE || error "enable ost quota failed"
899 # global_limit is much greater than limit1 to get
900 # different qunit's on osts. Since 1st qunit shrinking
901 # on OST1(that belongs to qpool1), this qunit should
903 log "User quota (block hardlimit:$global_limit MB)"
904 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
905 error "set user quota failed"
907 pool_add $qpool1 || error "pool_add failed"
908 pool_add_targets $qpool1 1 1 ||
909 error "pool_add_targets failed"
911 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
912 error "set user quota failed"
914 # make sure the system is clean
915 local used=$(getquota -u $TSTUSR global curspace)
916 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
918 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
919 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
921 test_1_check_write $testfile "user" $limit1
923 $LFS setstripe $testfile2 -c 1 -i 0 ||
924 error "setstripe $testfile2 failed"
925 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
926 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
928 $RUNAS $DD of=$testfile2 count=20 ||
929 quota_error u $TSTUSR \
930 "$qtype write failure, but expect success"
934 wait_delete_completed || error "wait_delete_completed failed"
935 sync_all_data || true
937 used=$(getquota -u $TSTUSR global curspace $qpool1)
938 [ $used -ne 0 ] && quota_error u $TSTUSR \
939 "user quota isn't released after deletion"
940 resetquota -u $TSTUSR
945 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
948 local global_limit=200 # 200M
949 local limit1=10 # 10M
950 local TESTDIR="$DIR/$tdir/"
951 local testfile="$TESTDIR/$tfile-0"
952 local qpool1="qpool1"
955 setup_quota_test || error "setup quota failed with $?"
956 stack_trap cleanup_quota_test EXIT
959 set_ost_qtype $QTYPE || error "enable ost quota failed"
961 log "User quota (block hardlimit:$global_limit MB)"
962 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
963 error "set user quota failed"
965 pool_add $qpool1 || error "pool_add failed"
966 pool_add_targets $qpool1 0 0 ||
967 error "pool_add_targets failed"
969 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
970 error "set user quota failed"
972 # make sure the system is clean
973 local used=$(getquota -u $TSTUSR global curspace)
974 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
976 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
978 test_1_check_write $testfile "user" $limit1
980 pool_remove_target $qpool1 0
982 wait_delete_completed || error "wait_delete_completed failed"
983 sync_all_data || true
985 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
986 # qunit for appropriate element in lgd array should be set
987 # correctly(4096). Earlier it was not changed continuing to be 1024.
988 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
989 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
990 # as it already was 1024. As flag "need_update" for this qunit was
991 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
992 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
993 # became > 10M. QMT returned EINPROGRESS in a loop.
994 # Check that it doesn't hung anymore.
995 test_1_check_write $testfile "user" $limit1
1000 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1003 local limit=20 # 20M
1004 local global_limit=40 # 40M
1005 local testfile="$DIR/$tdir/$tfile-0"
1006 local qpool="qpool1"
1007 local mdmb_param="osc.*.max_dirty_mb"
1008 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1011 setup_quota_test || error "setup quota failed with $?"
1012 stack_trap cleanup_quota_test EXIT
1013 $LCTL set_param $mdmb_param=1
1014 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1017 set_ost_qtype $QTYPE || error "enable ost quota failed"
1020 log "User quota (block hardlimit:$global_limit MB)"
1021 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1022 error "set user quota failed"
1024 pool_add $qpool || error "pool_add failed"
1025 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1026 error "pool_add_targets failed"
1028 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1029 error "set user quota failed"
1031 # make sure the system is clean
1032 local used=$(getquota -u $TSTUSR global curspace)
1034 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1036 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1037 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1040 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1041 quota_error u $TSTUSR \
1042 "$qtype write failure, but expect success"
1043 log "Write out of block quota ..."
1044 # this time maybe cache write, ignore it's failure
1045 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1046 # flush cache, ensure noquota flag is set on client
1047 cancel_lru_locks osc
1048 sync; sync_all_data || true
1050 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1051 quota_error u $TSTUSR \
1052 "user write success, but expect EDQUOT"
1055 wait_delete_completed || error "wait_delete_completed failed"
1056 sync_all_data || true
1058 used=$(getquota -u $TSTUSR global curspace $qpool)
1059 [ $used -ne 0 ] && quota_error u $TSTUSR \
1060 "user quota isn't released after deletion"
1063 run_test 1g "Quota pools: Block hard limit with wide striping"
1065 # test inode hardlimit
1067 local TESTFILE="$DIR/$tdir/$tfile-0"
1068 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1069 qmt.$FSNAME-QMT0000.md-0x0.info |
1070 awk '/least qunit/{ print $3 }')
1071 local L2=$(do_facet mds1 $LCTL get_param -n \
1072 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1074 [ $L2 -le $LIMIT ] || LIMIT=$L2
1076 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1078 local FREE_INODES=$(mdt_free_inodes 0)
1079 echo "$FREE_INODES free inodes on master MDT"
1080 [ $FREE_INODES -lt $LIMIT ] &&
1081 skip "not enough free inodes $FREE_INODES required $LIMIT"
1083 setup_quota_test || error "setup quota failed with $?"
1084 trap cleanup_quota_test EXIT
1087 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1090 log "User quota (inode hardlimit:$LIMIT files)"
1091 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1092 error "set user quota failed"
1094 # make sure the system is clean
1095 local USED=$(getquota -u $TSTUSR global curinodes)
1096 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1098 log "Create $LIMIT files ..."
1099 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1100 quota_error u $TSTUSR "user create failure, but expect success"
1101 log "Create out of file quota ..."
1102 $RUNAS touch ${TESTFILE}_xxx &&
1103 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1106 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1107 rm -f ${TESTFILE}_xxx
1108 wait_delete_completed
1110 USED=$(getquota -u $TSTUSR global curinodes)
1111 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1112 "user quota isn't released after deletion"
1113 resetquota -u $TSTUSR
1116 log "--------------------------------------"
1117 log "Group quota (inode hardlimit:$LIMIT files)"
1118 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1119 error "set group quota failed"
1121 TESTFILE=$DIR/$tdir/$tfile-1
1122 # make sure the system is clean
1123 USED=$(getquota -g $TSTUSR global curinodes)
1124 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1126 log "Create $LIMIT files ..."
1127 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1128 quota_error g $TSTUSR "group create failure, but expect success"
1129 log "Create out of file quota ..."
1130 $RUNAS touch ${TESTFILE}_xxx &&
1131 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1134 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1135 rm -f ${TESTFILE}_xxx
1136 wait_delete_completed
1138 USED=$(getquota -g $TSTUSR global curinodes)
1139 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1140 "user quota isn't released after deletion"
1142 resetquota -g $TSTUSR
1143 ! is_project_quota_supported && cleanup_quota_test &&
1144 echo "Skip project quota is not supported" && return 0
1147 log "--------------------------------------"
1148 log "Project quota (inode hardlimit:$LIMIT files)"
1149 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1150 error "set project quota failed"
1152 TESTFILE=$DIR/$tdir/$tfile-1
1153 # make sure the system is clean
1154 USED=$(getquota -p $TSTPRJID global curinodes)
1156 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1158 change_project -sp $TSTPRJID $DIR/$tdir
1159 log "Create $LIMIT files ..."
1160 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1161 $TSTPRJID "project create fail, but expect success"
1162 log "Create out of file quota ..."
1163 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1164 "project create success, but expect EDQUOT"
1165 change_project -C $DIR/$tdir
1168 USED=$(getquota -p $TSTPRJID global curinodes)
1169 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1170 "project quota isn't released after deletion"
1173 run_test 2 "File hard limit (normal use and out of quota)"
1184 stack_trap cleanup_quota_test EXIT
1186 $LFS setstripe $testfile -c 1 -i 0
1187 chown $TSTUSR.$TSTUSR $testfile
1188 [ "$qtype" == "p" ] && is_project_quota_supported &&
1189 change_project -p $TSTPRJID $testfile
1191 echo "Write up to soft limit"
1192 $RUNAS $DD of=$testfile count=$limit ||
1193 quota_error a $TSTUSR "write failure, but expect success"
1194 OFFSET=$((limit * 1024))
1195 cancel_lru_locks osc
1197 echo "Write to exceed soft limit"
1198 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1199 quota_error a $TSTUSR "write failure, but expect success"
1200 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1201 cancel_lru_locks osc
1203 echo "mmap write when over soft limit"
1204 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1205 quota_error a $TSTUSR "mmap write failure, but expect success"
1206 cancel_lru_locks osc
1211 $SHOW_QUOTA_INFO_USER
1212 $SHOW_QUOTA_INFO_GROUP
1213 $SHOW_QUOTA_INFO_PROJID
1215 echo "Write before timer goes off"
1216 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1217 quota_error a $TSTUSR "write failure, but expect success"
1218 OFFSET=$((OFFSET + 1024))
1219 cancel_lru_locks osc
1221 wait_grace_time $qtype "block" $pool
1226 $SHOW_QUOTA_INFO_USER
1227 $SHOW_QUOTA_INFO_GROUP
1228 $SHOW_QUOTA_INFO_PROJID
1230 log "Write after timer goes off"
1231 # maybe cache write, ignore.
1232 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1233 OFFSET=$((OFFSET + 1024))
1234 cancel_lru_locks osc
1235 log "Write after cancel lru locks"
1236 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1237 quota_error a $TSTUSR "write success, but expect EDQUOT"
1242 $SHOW_QUOTA_INFO_USER
1243 $SHOW_QUOTA_INFO_GROUP
1244 $SHOW_QUOTA_INFO_PROJID
1246 echo "Unlink file to stop timer"
1248 wait_delete_completed
1249 sync_all_data || true
1254 $SHOW_QUOTA_INFO_USER
1255 $SHOW_QUOTA_INFO_GROUP
1256 $SHOW_QUOTA_INFO_PROJID
1258 $LFS setstripe $testfile -c 1 -i 0
1259 chown $TSTUSR.$TSTUSR $testfile
1260 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1263 $RUNAS $DD of=$testfile count=$limit ||
1264 quota_error a $TSTUSR "write failure, but expect success"
1271 local grace=20 # 20s
1272 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1275 local testfile=$DIR/$tdir/$tfile-0
1277 # get minimum soft qunit size
1278 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1279 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1281 set_ost_qtype $QTYPE || error "enable ost quota failed"
1283 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1284 # make sure the system is clean
1285 local used=$(getquota -u $TSTUSR global curspace)
1286 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1288 $LFS setquota -t -u --block-grace $grace --inode-grace \
1289 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1290 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1291 error "set user quota failed"
1293 test_block_soft $testfile $grace $limit "u"
1295 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1296 testfile=$DIR/$tdir/$tfile-1
1297 # make sure the system is clean
1298 used=$(getquota -g $TSTUSR global curspace)
1299 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1301 $LFS setquota -t -g --block-grace $grace --inode-grace \
1302 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1303 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1304 error "set group quota failed"
1306 test_block_soft $testfile $grace $limit "g"
1308 if is_project_quota_supported; then
1309 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1310 testfile=$DIR/$tdir/$tfile-2
1311 # make sure the system is clean
1312 used=$(getquota -p $TSTPRJID global curspace)
1313 [ $used -ne 0 ] && error \
1314 "Used space($used) for project $TSTPRJID isn't 0."
1316 $LFS setquota -t -p --block-grace $grace --inode-grace \
1317 $MAX_IQ_TIME $DIR ||
1318 error "set project grace time failed"
1319 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1320 $DIR || error "set project quota failed"
1322 test_block_soft $testfile $grace $limit "p"
1323 resetquota -p $TSTPRJID
1324 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1325 $MAX_IQ_TIME $DIR ||
1326 error "restore project grace time failed"
1330 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1331 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1332 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1333 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1335 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1338 local grace=20 # 20s
1339 local qpool="qpool1"
1340 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1343 local testfile=$DIR/$tdir/$tfile-0
1346 # get minimum soft qunit size
1347 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1348 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1349 local glbl_limit=$((2*limit))
1350 local glbl_grace=$((2*grace))
1351 echo "limit $limit glbl_limit $glbl_limit"
1352 echo "grace $grace glbl_grace $glbl_grace"
1354 set_ost_qtype $QTYPE || error "enable ost quota failed"
1356 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1357 # make sure the system is clean
1358 local used=$(getquota -u $TSTUSR global curspace)
1359 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1361 pool_add $qpool || error "pool_add failed"
1362 pool_add_targets $qpool 0 1 ||
1363 error "pool_add_targets failed"
1365 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1366 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1367 $LFS setquota -t -u --block-grace $grace \
1368 --pool $qpool $DIR || error "set user grace time failed"
1370 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1371 error "set user quota failed"
1372 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1373 error "set user quota failed"
1375 test_block_soft $testfile $grace $limit "u" $qpool
1377 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1378 testfile=$DIR/$tdir/$tfile-1
1379 # make sure the system is clean
1380 used=$(getquota -g $TSTUSR global curspace)
1381 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1383 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1384 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1385 $LFS setquota -t -g --block-grace $grace \
1386 --pool $qpool $DIR || error "set group grace time failed"
1388 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1389 error "set group quota failed"
1390 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1391 error "set group quota failed"
1393 test_block_soft $testfile $grace $limit "g" $qpool
1395 if is_project_quota_supported; then
1396 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1397 testfile=$DIR/$tdir/$tfile-2
1398 # make sure the system is clean
1399 used=$(getquota -p $TSTPRJID global curspace)
1400 [ $used -ne 0 ] && error \
1401 "Used space($used) for project $TSTPRJID isn't 0."
1403 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1404 $MAX_IQ_TIME $DIR ||
1405 error "set project grace time failed"
1406 $LFS setquota -t -p --block-grace $grace \
1407 --pool $qpool $DIR ||
1408 error "set project grace time failed"
1410 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1411 $DIR || error "set project quota failed"
1412 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1413 --pool $qpool $DIR || error "set project quota failed"
1415 test_block_soft $testfile $grace $limit "p" $qpool
1416 resetquota -p $TSTPRJID
1417 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1418 $MAX_IQ_TIME $DIR ||
1419 error "restore project grace time failed"
1420 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1421 $DIR || error "set project grace time failed"
1425 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1426 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1427 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1428 --pool $qpool $DIR || error "restore user grace time failed"
1429 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1430 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1431 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1432 --pool $qpool $DIR || error "restore group grace time failed"
1434 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1437 local grace=20 # 20s
1438 local qpool="qpool1"
1439 local qpool2="qpool2"
1440 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1443 local testfile=$DIR/$tdir/$tfile-0
1446 # get minimum soft qunit size
1447 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1448 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1449 local limit2=$((limit+4))
1450 local glbl_limit=$((limit+8))
1451 local grace1=$((grace+10))
1453 local glbl_grace=$((grace+20))
1454 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1455 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1457 set_ost_qtype $QTYPE || error "enable ost quota failed"
1459 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1460 # make sure the system is clean
1461 local used=$(getquota -u $TSTUSR global curspace)
1462 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1464 pool_add $qpool || error "pool_add failed"
1465 pool_add_targets $qpool 0 1 ||
1466 error "pool_add_targets failed"
1468 pool_add $qpool2 || error "pool_add failed"
1469 pool_add_targets $qpool2 0 1 ||
1470 error "pool_add_targets failed"
1473 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1474 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1475 $LFS setquota -t -u --block-grace $grace1 \
1476 --pool $qpool $DIR || error "set user grace time failed"
1477 $LFS setquota -t -u --block-grace $grace2 \
1478 --pool $qpool2 $DIR || error "set user grace time failed"
1480 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1481 error "set user quota failed"
1482 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1483 error "set user quota failed"
1484 # qpool has minimum soft limit, but it's grace is grater than
1485 # grace period of qpool2. Thus write shouldn't fail when
1486 # hit qpool soft limit - only when reaches up qpool2 limit
1487 # after grace2 seconds.
1488 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1489 error "set user quota failed"
1491 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1494 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1495 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1496 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1497 --pool $qpool $DIR || error "restore user grace time failed"
1498 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1499 --pool $qpool2 $DIR || error "restore user grace time failed"
1501 run_test 3c "Quota pools: check block soft limit on different pools"
1510 trap cleanup_quota_test EXIT
1511 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1513 echo "Create files to exceed soft limit"
1514 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1515 quota_error a $TSTUSR "create failure, but expect success"
1516 local trigger_time=$(date +%s)
1518 sync_all_data || true
1520 local cur_time=$(date +%s)
1521 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1522 error "Passed grace time $grace, $trigger_time, $cur_time"
1524 echo "Create file before timer goes off"
1525 $RUNAS touch ${TESTFILE}_before ||
1526 quota_error a $TSTUSR "failed create before timer expired," \
1527 "but expect success. $trigger_time, $cur_time"
1528 sync_all_data || true
1530 wait_grace_time $qtype "file"
1535 $SHOW_QUOTA_INFO_USER
1536 $SHOW_QUOTA_INFO_GROUP
1537 $SHOW_QUOTA_INFO_PROJID
1539 echo "Create file after timer goes off"
1540 # There is a window that space is accounted in the quota usage but
1541 # hasn't been decreased from the pending write, if we acquire quota
1542 # in this window, we'll acquire more than we needed.
1543 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
1544 sync_all_data || true
1545 $RUNAS touch ${TESTFILE}_after_3 &&
1546 quota_error a $TSTUSR "create after timer expired," \
1548 sync_all_data || true
1553 $SHOW_QUOTA_INFO_USER
1554 $SHOW_QUOTA_INFO_GROUP
1555 $SHOW_QUOTA_INFO_PROJID
1557 echo "Unlink files to stop timer"
1558 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1559 wait_delete_completed
1562 $RUNAS touch ${TESTFILE}_xxx ||
1563 quota_error a $TSTUSR "touch after timer stop failure," \
1564 "but expect success"
1565 sync_all_data || true
1573 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1574 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1575 local TESTFILE=$DIR/$tdir/$tfile-0
1578 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1580 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1581 # make sure the system is clean
1582 local USED=$(getquota -u $TSTUSR global curinodes)
1583 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1585 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1586 $GRACE $DIR || error "set user grace time failed"
1587 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1588 error "set user quota failed"
1590 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1592 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1594 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1595 # make sure the system is clean
1596 USED=$(getquota -g $TSTUSR global curinodes)
1597 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1599 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1600 $GRACE $DIR || error "set group grace time failed"
1601 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1602 error "set group quota failed"
1603 TESTFILE=$DIR/$tdir/$tfile-1
1605 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1607 if is_project_quota_supported; then
1608 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1609 # make sure the system is clean
1610 USED=$(getquota -p $TSTPRJID global curinodes)
1611 [ $USED -ne 0 ] && error \
1612 "Used space($USED) for project $TSTPRJID isn't 0."
1614 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1615 $GRACE $DIR || error "set project grace time failed"
1616 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1617 error "set project quota failed"
1619 TESTFILE=$DIR/$tdir/$tfile-1
1620 # one less than limit, because of parent directory included.
1621 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1622 resetquota -p $TSTPRJID
1623 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1624 $MAX_IQ_TIME $DIR ||
1625 error "restore project grace time failed"
1629 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1630 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1631 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1632 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1634 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1637 local GR_STR1="1w3d"
1638 local GR_STR2="1000s"
1640 local GR_STR4="1w2d3h4m5s"
1642 local GR_STR6="18446744073709551615"
1645 wait_delete_completed
1647 # test of valid grace strings handling
1648 echo "Valid grace strings test"
1649 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1650 $GR_STR2 $DIR || error "set user grace time failed"
1651 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1652 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1653 $GR_STR4 $DIR || error "set group grace time quota failed"
1654 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1656 # test of invalid grace strings handling
1657 echo " Invalid grace strings test"
1658 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1659 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1660 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1664 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1665 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1666 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1667 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1669 run_test 4b "Grace time strings handling"
1671 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1673 local BLIMIT=10 # 10M
1674 local ILIMIT=10 # 10 inodes
1676 setup_quota_test || error "setup quota failed with $?"
1677 trap cleanup_quota_test EXIT
1679 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1680 set_ost_qtype $QTYPE || error "enable ost quota failed"
1682 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1683 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1684 error "set user quota failed"
1685 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1686 if is_project_quota_supported; then
1687 error "set group quota failed"
1688 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1689 -I $ILIMIT $DIR || error "set project quota failed"
1692 # make sure the system is clean
1693 local USED=$(getquota -u $TSTUSR global curinodes)
1694 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1695 USED=$(getquota -g $TSTUSR global curinodes)
1696 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1697 USED=$(getquota -u $TSTUSR global curspace)
1698 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1699 USED=$(getquota -g $TSTUSR global curspace)
1700 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1701 if is_project_quota_supported; then
1702 USED=$(getquota -p $TSTPRJID global curinodes)
1704 error "Used inode($USED) for project $TSTPRJID isn't 0."
1705 USED=$(getquota -p $TSTPRJID global curspace)
1707 error "Used block($USED) for project $TSTPRJID isn't 0."
1710 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1711 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1712 error "create failure, expect success"
1713 if is_project_quota_supported; then
1714 touch $DIR/$tdir/$tfile-0_1
1715 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1717 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1718 error "write failure, expect success"
1720 echo "Chown files to $TSTUSR.$TSTUSR ..."
1721 for i in $(seq 0 $ILIMIT); do
1722 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1723 quota_error a $TSTUSR "chown failure, expect success"
1727 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1728 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1731 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1733 # test dropping acquire request on master
1737 # Clear dmesg so watchdog is not triggered by previous
1739 do_facet ost1 dmesg -c > /dev/null
1741 setup_quota_test || error "setup quota failed with $?"
1742 trap cleanup_quota_test EXIT
1744 # make sure the system is clean
1745 local USED=$(getquota -u $TSTUSR global curspace)
1746 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1748 # make sure no granted quota on ost
1749 set_ost_qtype $QTYPE || error "enable ost quota failed"
1750 resetquota -u $TSTUSR
1752 # create file for $TSTUSR
1753 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1754 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1755 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1757 # create file for $TSTUSR2
1758 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1759 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1760 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1762 # cache per-ID lock for $TSTUSR on slave
1763 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1764 error "set quota failed"
1765 $RUNAS $DD of=$TESTFILE count=1 ||
1766 error "write $TESTFILE failure, expect success"
1767 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1768 error "write $TESTFILE2 failure, expect success"
1770 if at_is_enabled; then
1771 at_max_saved=$(at_max_get ost1)
1772 at_max_set $TIMEOUT ost1
1774 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1775 # DQACQ is sent, which makes at_max to take effect
1776 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1779 wait_delete_completed
1783 sync_all_data || true
1785 #define QUOTA_DQACQ 601
1786 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1787 lustre_fail mds 0x513 601
1789 do_facet ost1 $LCTL set_param \
1790 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1792 # write to un-enforced ID ($TSTUSR2) should succeed
1793 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1794 error "write failure, expect success"
1796 # write to enforced ID ($TSTUSR) in background, exceeding limit
1797 # to make sure DQACQ is sent
1798 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1801 # watchdog timer uses a factor of 2
1802 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1803 sleep $((TIMEOUT * 2 + 1))
1805 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1807 # write should be blocked and never finished
1808 if ! ps -p $DDPID > /dev/null 2>&1; then
1810 error "write finished incorrectly!"
1815 # no watchdog is triggered
1816 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1817 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1818 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1819 [ -z "$watchdog" ] || error "$watchdog"
1821 rm -f $TMP/lustre-log-${TESTNAME}.log
1823 # write should continue then fail with EDQUOT
1827 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1828 if [ $count -ge 240 ]; then
1829 quota_error u $TSTUSR "dd not finished in $count secs"
1831 count=$((count + 1))
1832 if [ $((count % 30)) -eq 0 ]; then
1833 c_size=$(stat -c %s $TESTFILE)
1834 echo "Waiting $count secs. $c_size"
1842 run_test 6 "Test dropping acquire request on master"
1844 # quota reintegration (global index)
1846 local TESTFILE=$DIR/$tdir/$tfile
1847 local LIMIT=20 # 20M
1849 [ "$SLOW" = "no" ] && LIMIT=5
1851 setup_quota_test || error "setup quota failed with $?"
1852 trap cleanup_quota_test EXIT
1854 # make sure the system is clean
1855 local USED=$(getquota -u $TSTUSR global curspace)
1856 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1858 # make sure no granted quota on ost1
1859 set_ost_qtype $QTYPE || error "enable ost quota failed"
1860 resetquota -u $TSTUSR
1861 set_ost_qtype "none" || error "disable ost quota failed"
1863 local OSTUUID=$(ostuuid_from_index 0)
1864 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1866 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1869 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1870 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1875 echo "Enable quota & set quota limit for $TSTUSR"
1876 set_ost_qtype $QTYPE || error "enable ost quota failed"
1877 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1878 error "set quota failed"
1880 echo "Start ost1..."
1881 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1884 wait_ost_reint $QTYPE || error "reintegration failed"
1886 # hardlimit should have been fetched by slave during global
1887 # reintegration, write will exceed quota
1888 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1889 quota_error u $TSTUSR "write success, but expect EDQUOT"
1892 wait_delete_completed
1893 sync_all_data || true
1899 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1900 error "clear quota failed"
1902 echo "Start ost1..."
1903 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1906 wait_ost_reint $QTYPE || error "reintegration failed"
1908 # hardlimit should be cleared on slave during reintegration
1909 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1910 quota_error u $TSTUSR "write error, but expect success"
1914 run_test 7a "Quota reintegration (global index)"
1916 # quota reintegration (slave index)
1919 local TESTFILE=$DIR/$tdir/$tfile
1921 setup_quota_test || error "setup quota failed with $?"
1922 trap cleanup_quota_test EXIT
1924 # make sure the system is clean
1925 local USED=$(getquota -u $TSTUSR global curspace)
1926 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1928 # make sure no granted quota on ost1
1929 set_ost_qtype $QTYPE || error "enable ost quota failed"
1930 resetquota -u $TSTUSR
1931 set_ost_qtype "none" || error "disable ost quota failed"
1933 local OSTUUID=$(ostuuid_from_index 0)
1934 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1936 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1939 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1940 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1942 # consume some space to make sure the granted space will not
1943 # be released during reconciliation
1944 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1945 error "consume space failure, expect success"
1947 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1948 lustre_fail mds 0xa02
1950 set_ost_qtype $QTYPE || error "enable ost quota failed"
1951 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1952 error "set quota failed"
1954 # ignore the write error
1955 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1957 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1961 echo "Restart ost to trigger reintegration..."
1963 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1966 wait_ost_reint $QTYPE || error "reintegration failed"
1968 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1969 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1974 run_test 7b "Quota reintegration (slave index)"
1976 # quota reintegration (restart mds during reintegration)
1978 local LIMIT=20 # 20M
1979 local TESTFILE=$DIR/$tdir/$tfile
1981 [ "$SLOW" = "no" ] && LIMIT=5
1983 setup_quota_test || error "setup quota failed with $?"
1984 trap cleanup_quota_test EXIT
1986 # make sure the system is clean
1987 local USED=$(getquota -u $TSTUSR global curspace)
1988 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1990 set_ost_qtype "none" || error "disable ost quota failed"
1991 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1992 error "set quota failed"
1994 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1995 lustre_fail ost 0xa03
1998 set_ost_qtype $QTYPE || error "enable ost quota failed"
1999 # trigger reintegration
2000 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2001 procf=${procf}quota_slave.force_reint
2002 do_facet ost1 $LCTL set_param $procf=1 ||
2003 error "force reintegration failed"
2011 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2014 # wait longer than usual to make sure the reintegration
2015 # is triggered by quota wb thread.
2016 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2018 # hardlimit should have been fetched by slave during global
2019 # reintegration, write will exceed quota
2020 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2021 quota_error u $TSTUSR "write success, but expect EDQUOT"
2025 run_test 7c "Quota reintegration (restart mds during reintegration)"
2027 # Quota reintegration (Transfer index in multiple bulks)
2029 local TESTFILE=$DIR/$tdir/$tfile
2030 local TESTFILE1="$DIR/$tdir/$tfile"-1
2033 setup_quota_test || error "setup quota failed with $?"
2034 trap cleanup_quota_test EXIT
2036 set_ost_qtype "none" || error "disable ost quota failed"
2037 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2038 error "set quota for $TSTUSR failed"
2039 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2040 error "set quota for $TSTUSR2 failed"
2042 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2043 lustre_fail mds 0x608 0
2045 # enable quota to tirgger reintegration
2046 set_ost_qtype "u" || error "enable ost quota failed"
2047 wait_ost_reint "u" || error "reintegration failed"
2051 # hardlimit should have been fetched by slave during global
2052 # reintegration, write will exceed quota
2053 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2054 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2056 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2057 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2061 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2063 # quota reintegration (inode limits)
2065 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2067 # LU-2435: skip this quota test if underlying zfs version has not
2068 # supported native dnode accounting
2069 [ "$mds1_FSTYPE" == zfs ] && {
2070 local F="feature@userobj_accounting"
2071 local pool=$(zpool_name mds1)
2072 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2074 [[ "$feature" != *" active "* ]] &&
2075 skip "requires zpool with active userobj_accounting"
2078 local ilimit=$((1024 * 2)) # 2k inodes
2079 local TESTFILE=$DIR/${tdir}-1/$tfile
2081 setup_quota_test || error "setup quota failed with $?"
2082 trap cleanup_quota_test EXIT
2084 # make sure the system is clean
2085 local USED=$(getquota -u $TSTUSR global curinodes)
2086 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2088 # make sure no granted quota on mdt1
2089 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2090 resetquota -u $TSTUSR
2091 set_mdt_qtype "none" || error "disable mdt quota failed"
2093 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2094 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2095 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2098 echo "Stop mds${MDSCOUNT}..."
2101 echo "Enable quota & set quota limit for $TSTUSR"
2102 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2103 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2104 error "set quota failed"
2106 echo "Start mds${MDSCOUNT}..."
2107 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2110 wait_mdt_reint $QTYPE || error "reintegration failed"
2112 echo "create remote dir"
2113 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2114 error "create remote dir failed"
2115 chmod 0777 $DIR/${tdir}-1
2117 # hardlimit should have been fetched by slave during global
2118 # reintegration, create will exceed quota
2119 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2120 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2122 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2123 wait_delete_completed
2124 sync_all_data || true
2126 echo "Stop mds${MDSCOUNT}..."
2129 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2130 error "clear quota failed"
2132 echo "Start mds${MDSCOUNT}..."
2133 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2136 wait_mdt_reint $QTYPE || error "reintegration failed"
2138 # hardlimit should be cleared on slave during reintegration
2139 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2140 quota_error u $TSTUSR "create failed, expect success"
2142 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2143 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2147 run_test 7e "Quota reintegration (inode limits)"
2149 # run dbench with quota enabled
2151 local BLK_LIMIT="100g" #100G
2152 local FILE_LIMIT=1000000
2154 setup_quota_test || error "setup quota failed with $?"
2155 trap cleanup_quota_test EXIT
2157 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2158 set_ost_qtype $QTYPE || error "enable ost quota failed"
2160 echo "Set enough high limit for user: $TSTUSR"
2161 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2162 error "set user quota failed"
2163 echo "Set enough high limit for group: $TSTUSR"
2164 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2165 error "set group quota failed"
2166 if is_project_quota_supported; then
2167 change_project -sp $TSTPRJID $DIR/$tdir
2168 echo "Set enough high limit for project: $TSTPRJID"
2169 $LFS setquota -p $TSTPRJID -b 0 \
2170 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2171 error "set project quota failed"
2175 [ "$SLOW" = "no" ] && duration=" -t 120"
2176 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2177 quota_error a $TSTUSR "dbench failed!"
2179 is_project_quota_supported && change_project -C $DIR/$tdir
2182 run_test 8 "Run dbench with quota enabled"
2184 # this check is just for test_9
2185 OST0_MIN=4900000 #4.67G
2187 check_whether_skip () {
2188 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2189 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2190 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2191 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2198 # run for fixing bug10707, it needs a big room. test for 64bit
2200 local filesize=$((1024 * 9 / 2)) # 4.5G
2202 check_whether_skip && return 0
2204 setup_quota_test || error "setup quota failed with $?"
2205 trap cleanup_quota_test EXIT
2207 set_ost_qtype "ug" || error "enable ost quota failed"
2209 local TESTFILE="$DIR/$tdir/$tfile-0"
2210 local BLK_LIMIT=100G #100G
2211 local FILE_LIMIT=1000000
2213 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2215 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2217 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2218 error "set user quota failed"
2220 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2221 "for group: $TSTUSR"
2222 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2223 error "set group quota failed"
2225 quota_show_check a u $TSTUSR
2226 quota_show_check a g $TSTUSR
2228 echo "Create test file"
2229 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2230 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2232 log "Write the big file of 4.5G ..."
2233 $RUNAS $DD of=$TESTFILE count=$filesize ||
2234 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2244 run_test 9 "Block limit larger than 4GB (b10707)"
2247 local TESTFILE=$DIR/$tdir/$tfile
2249 setup_quota_test || error "setup quota failed with $?"
2250 trap cleanup_quota_test EXIT
2252 # set limit to root user should fail
2253 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2254 error "set limit for root user successfully, expect failure"
2255 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2256 error "set limit for root group successfully, expect failure"
2257 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2258 error "set limit for project 0 successfully, expect failure"
2260 # root user can overrun quota
2261 set_ost_qtype "ug" || error "enable ost quota failed"
2263 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2264 error "set quota failed"
2265 quota_show_check b u $TSTUSR
2267 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2268 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2270 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2271 error "write failure, expect success"
2275 run_test 10 "Test quota for root user"
2278 local TESTFILE=$DIR/$tdir/$tfile
2279 setup_quota_test || error "setup quota failed with $?"
2280 trap cleanup_quota_test EXIT
2282 set_mdt_qtype "ug" || error "enable mdt quota failed"
2283 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2284 error "set quota failed"
2286 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2287 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2289 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2290 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2293 local USED=$(getquota -u $TSTUSR global curinodes)
2294 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2298 run_test 11 "Chown/chgrp ignores quota"
2301 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2303 local blimit=22 # 22M
2304 local blk_cnt=$((blimit - 5))
2305 local TESTFILE0="$DIR/$tdir/$tfile"-0
2306 local TESTFILE1="$DIR/$tdir/$tfile"-1
2308 setup_quota_test || error "setup quota failed with $?"
2309 trap cleanup_quota_test EXIT
2311 set_ost_qtype "u" || error "enable ost quota failed"
2312 quota_show_check b u $TSTUSR
2314 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2315 error "set quota failed"
2317 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2318 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2319 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2320 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2322 echo "Write to ost0..."
2323 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2324 quota_error a $TSTUSR "dd failed"
2326 echo "Write to ost1..."
2327 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2328 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2330 echo "Free space from ost0..."
2332 wait_delete_completed
2333 sync_all_data || true
2335 echo "Write to ost1 after space freed from ost0..."
2336 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2337 quota_error a $TSTUSR "rebalancing failed"
2341 run_test 12a "Block quota rebalancing"
2344 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2346 local ilimit=$((1024 * 2)) # 2k inodes
2347 local TESTFILE0=$DIR/$tdir/$tfile
2348 local TESTFILE1=$DIR/${tdir}-1/$tfile
2350 setup_quota_test || error "setup quota failed with $?"
2351 trap cleanup_quota_test EXIT
2353 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2354 chmod 0777 $DIR/${tdir}-1
2356 set_mdt_qtype "u" || error "enable mdt quota failed"
2357 quota_show_check f u $TSTUSR
2359 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2360 error "set quota failed"
2362 echo "Create $ilimit files on mdt0..."
2363 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2364 quota_error u $TSTUSR "create failed, but expect success"
2366 echo "Create files on mdt1..."
2367 $RUNAS createmany -m $TESTFILE1 1 &&
2368 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2370 echo "Free space from mdt0..."
2371 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2372 wait_delete_completed
2373 sync_all_data || true
2375 echo "Create files on mdt1 after space freed from mdt0..."
2376 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2377 quota_error a $TSTUSR "rebalancing failed"
2379 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2380 error "unlink mdt1 files failed"
2381 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2385 run_test 12b "Inode quota rebalancing"
2388 local TESTFILE=$DIR/$tdir/$tfile
2389 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2390 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2392 setup_quota_test || error "setup quota failed with $?"
2393 trap cleanup_quota_test EXIT
2395 set_ost_qtype "u" || error "enable ost quota failed"
2396 quota_show_check b u $TSTUSR
2398 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2399 error "set quota failed"
2400 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2401 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2403 # clear the locks in cache first
2404 do_facet ost1 $LCTL set_param -n $procf=clear
2405 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2406 [ $nlock -eq 0 ] || error "$nlock cached locks"
2408 # write to acquire the per-ID lock
2409 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2410 quota_error a $TSTUSR "dd failed"
2412 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2413 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2415 # clear quota doesn't trigger per-ID lock cancellation
2416 resetquota -u $TSTUSR
2417 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2418 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2420 # clear the per-ID lock
2421 do_facet ost1 $LCTL set_param -n $procf=clear
2422 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2423 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2425 # spare quota should be released
2426 local OSTUUID=$(ostuuid_from_index 0)
2427 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2428 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2429 [ $limit -le $space ] ||
2430 error "spare quota isn't released, limit:$limit, space:$space"
2434 run_test 13 "Cancel per-ID lock in the LRU list"
2437 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2439 wait_delete_completed
2440 sync_all_data || true
2443 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2444 error "set user quota failed"
2445 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2446 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2447 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2448 resetquota -u $TSTUSR
2451 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2452 error "set group quota failed"
2453 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2454 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2455 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2456 resetquota -g $TSTUSR
2458 run_test 15 "Set over 4T block quota"
2462 local BLKS=1 # 1M less than limit
2463 local TESTFILE=$DIR/$tdir/$tfile
2465 setup_quota_test || error "setup quota failed with $?"
2466 trap cleanup_quota_test EXIT
2468 # make sure the system is clean
2469 local USED=$(getquota -u $TSTUSR global curspace)
2470 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2472 set_ost_qtype "ug" || error "enable ost quota failed"
2473 # make sure no granted quota on ost
2474 resetquota -u $TSTUSR
2475 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2476 error "set quota failed"
2478 quota_show_check b u $TSTUSR
2480 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2481 lustre_fail mds 0xa04 $err_code
2483 # write in background
2484 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2488 # write should be blocked and never finished
2489 if ! ps -p $DDPID > /dev/null 2>&1; then
2491 quota_error u $TSTUSR "write finished incorrectly!"
2499 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2501 if [ $count -gt $timeout ]; then
2502 quota_error u $TSTUSR "dd is not finished!"
2507 sync; sync_all_data || true
2509 USED=$(getquota -u $TSTUSR global curspace)
2510 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2511 "Used space(${USED}K) is less than ${BLKS}M"
2516 # DQACQ return recoverable error
2518 echo "DQACQ return -ENOLCK"
2520 test_17sub 37 || error "Handle -ENOLCK failed"
2522 echo "DQACQ return -EAGAIN"
2524 test_17sub 11 || error "Handle -EAGAIN failed"
2526 echo "DQACQ return -ETIMEDOUT"
2527 #define ETIMEDOUT 110
2528 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2530 echo "DQACQ return -ENOTCONN"
2531 #define ENOTCONN 107
2532 test_17sub 107 || error "Handle -ENOTCONN failed"
2535 run_test 17 "DQACQ return recoverable error"
2539 local blimit="200m" # 200M
2540 local TESTFILE="$DIR/$tdir/$tfile"
2542 setup_quota_test || error "setup quota failed with $?"
2543 trap cleanup_quota_test EXIT
2545 set_ost_qtype "u" || error "enable ost quota failed"
2546 log "User quota (limit: $blimit)"
2547 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2548 error "set quota failed"
2549 quota_show_check b u $TSTUSR
2551 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2552 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2554 local timeout=$(sysctl -n lustre.timeout)
2556 if [ $io_type = "directio" ]; then
2557 log "Write 100M (directio) ..."
2558 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2560 log "Write 100M (buffered) ..."
2561 $RUNAS $DD of=$TESTFILE count=100 &
2565 replay_barrier $SINGLEMDS
2566 log "Fail mds for $((2 * timeout)) seconds"
2567 fail $SINGLEMDS $((2 * timeout))
2570 if at_is_enabled; then
2571 timeout=$(at_max_get mds)
2573 timeout=$(lctl get_param -n timeout)
2577 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2578 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2579 log "it took $count second"
2584 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2586 cancel_lru_locks mdc
2587 cancel_lru_locks osc
2590 local testfile_size=$(stat -c %s $TESTFILE)
2591 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2592 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2593 "got ${testfile_size}. Verifying file failed!"
2598 # test when mds does failover, the ost still could work well
2599 # this test shouldn't trigger watchdog b=14840
2601 # Clear dmesg so watchdog is not triggered by previous
2603 do_facet ost1 dmesg -c > /dev/null
2606 test_18_sub directio
2608 # check if watchdog is triggered
2609 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2610 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2611 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2612 [ -z "$watchdog" ] || error "$watchdog"
2613 rm -f $TMP/lustre-log-${TESTNAME}.log
2615 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2619 local TESTFILE=$DIR/$tdir/$tfile
2621 setup_quota_test || error "setup quota failed with $?"
2622 trap cleanup_quota_test EXIT
2624 set_ost_qtype $QTYPE || error "enable ost quota failed"
2626 # bind file to a single OST
2627 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2628 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2630 echo "Set user quota (limit: ${blimit}M)"
2631 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2632 error "set user quota failed"
2633 quota_show_check b u $TSTUSR
2634 echo "Update quota limits"
2635 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2636 error "set group quota failed"
2637 quota_show_check b u $TSTUSR
2639 # first wirte might be cached
2640 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2641 cancel_lru_locks osc
2643 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2644 quota_error u $TSTUSR "Write success, expect failure"
2649 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2651 test_20() { # b15754
2652 local LSTR=(2g 1t 4k 3m) # limits strings
2654 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2657 resetquota -u $TSTUSR
2659 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2660 $MOUNT || error "could not set quota limits"
2661 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2662 --inode-softlimit ${LSTR[2]} \
2663 --inode-hardlimit ${LSTR[3]} \
2664 $MOUNT || error "could not set quota limits"
2666 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2667 error "bsoftlimit was not set properly"
2668 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2669 error "bhardlimit was not set properly"
2670 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2671 error "isoftlimit was not set properly"
2672 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2673 error "ihardlimit was not set properly"
2675 resetquota -u $TSTUSR
2677 run_test 20 "Test if setquota specifiers work properly (b15754)"
2684 local time=$(($(date +%s) + seconds))
2685 while [ $(date +%s) -lt $time ]; do
2686 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2690 # run for fixing bug16053, setquota shouldn't fail when writing and
2691 # deleting are happening
2693 local TESTFILE="$DIR/$tdir/$tfile"
2694 local BLIMIT=10 # 10G
2695 local ILIMIT=1000000
2697 setup_quota_test || error "setup quota failed with $?"
2698 trap cleanup_quota_test EXIT
2700 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2702 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2703 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2704 error "set user quota failed"
2705 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2706 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2707 error "set group quota failed"
2708 if is_project_quota_supported; then
2709 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2710 "project: $TSTPRJID"
2711 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2712 $MOUNT || error "set project quota failed"
2715 # repeat writing on a 1M file
2716 test_21_sub ${TESTFILE}_1 1 30 &
2718 # repeat writing on a 128M file
2719 test_21_sub ${TESTFILE}_2 128 30 &
2722 local time=$(($(date +%s) + 30))
2724 while [ $(date +%s) -lt $time ]; do
2725 log "Set quota for $i times"
2726 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2727 -I $((ILIMIT + i)) $MOUNT ||
2728 error "Set user quota failed"
2729 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2730 -I $((ILIMIT + i)) $MOUNT ||
2731 error "Set group quota failed"
2732 if is_project_quota_supported; then
2733 $LFS setquota -p $TSTPRJID -b 0 -B \
2734 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2735 error "Set project quota failed"
2743 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2745 if [ $count -gt 60 ]; then
2746 quota_error a $TSTUSR "dd should be finished!"
2750 echo "(dd_pid=$DDPID1, time=$count)successful"
2754 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2756 if [ $count -gt 60 ]; then
2757 quota_error a $TSTUSR "dd should be finished!"
2761 echo "(dd_pid=$DDPID2, time=$count)successful"
2765 run_test 21 "Setquota while writing & deleting (b16053)"
2767 # enable/disable quota enforcement permanently
2769 echo "Set both mdt & ost quota type as ug"
2771 is_project_quota_supported && qtype=$QTYPE
2772 set_mdt_qtype $qtype || error "enable mdt quota failed"
2773 set_ost_qtype $qtype || error "enable ost quota failed"
2776 stopall || error "failed to stopall (1)"
2780 echo "Verify if quota is enabled"
2781 local qtype1=$(mdt_quota_type)
2782 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2783 qtype=$(ost_quota_type)
2784 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2786 echo "Set both mdt & ost quota type as none"
2787 set_mdt_qtype "none" || error "disable mdt quota failed"
2788 set_ost_qtype "none" || error "disable ost quota failed"
2791 stopall || error "failed to stopall (2)"
2796 echo "Verify if quota is disabled"
2797 qtype=$(mdt_quota_type)
2798 [ $qtype != "none" ] && error "mdt quota setting is lost"
2799 qtype=$(ost_quota_type)
2800 [ $qtype != "none" ] && error "ost quota setting is lost"
2804 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2807 local TESTFILE="$DIR/$tdir/$tfile"
2810 setup_quota_test || error "setup quota failed with $?"
2811 trap cleanup_quota_test EXIT
2813 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2816 log "User quota (limit: $LIMIT MB)"
2817 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2818 error "set quota failed"
2819 quota_show_check b u $TSTUSR
2821 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2822 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2824 log "Step1: trigger EDQUOT with O_DIRECT"
2825 log "Write half of file"
2826 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2827 quota_error u $TSTUSR "(1) Write failure, expect success." \
2829 log "Write out of block quota ..."
2830 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2831 oflag=direct conv=notrunc &&
2832 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2836 log "Step2: rewrite should succeed"
2837 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2838 quota_error u $TSTUSR "(3) Write failure, expect success." \
2844 local OST0_UUID=$(ostuuid_from_index 0)
2845 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2846 [ $OST0_QUOTA_USED -ne 0 ] &&
2847 ($SHOW_QUOTA_USER; \
2848 quota_error u $TSTUSR "quota isn't released")
2853 [ "$ost1_FSTYPE" == zfs ] &&
2854 skip "Overwrite in place is not guaranteed to be " \
2855 "space neutral on ZFS"
2857 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2858 check_whether_skip && return 0
2859 log "run for 4MB test file"
2862 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2863 check_whether_skip && return 0
2864 log "run for 40MB test file"
2867 run_test 23 "Quota should be honored with directIO (b16125)"
2871 local TESTFILE="$DIR/$tdir/$tfile"
2873 setup_quota_test || error "setup quota failed with $?"
2874 trap cleanup_quota_test EXIT
2876 set_ost_qtype $QTYPE || error "enable ost quota failed"
2878 # bind file to a single OST
2879 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2880 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2882 echo "Set user quota (limit: ${blimit}M)"
2883 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2884 error "set quota failed"
2886 # overrun quota by root user
2887 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2888 error "write failure, expect success"
2889 cancel_lru_locks osc
2890 sync_all_data || true
2892 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2896 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2898 test_27a() { # b19612
2899 $LFS quota $TSTUSR $DIR &&
2900 error "lfs succeeded with no type, but should have failed"
2901 $LFS setquota $TSTUSR $DIR &&
2902 error "lfs succeeded with no type, but should have failed"
2905 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2907 test_27b() { # b20200
2908 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2909 error "lfs setquota failed with uid argument"
2910 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2911 error "lfs stequota failed with gid argument"
2912 if is_project_quota_supported; then
2913 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2914 1000 $DIR || error \
2915 "lfs stequota failed with projid argument"
2917 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2918 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2919 if is_project_quota_supported; then
2920 $SHOW_QUOTA_PROJID ||
2921 error "lfs quota failed with projid argument"
2923 resetquota -u $TSTID
2924 resetquota -g $TSTID
2925 resetquota -p $TSTPRJID
2928 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2933 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2934 error "lfs setquota failed"
2936 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2937 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2938 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2939 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2941 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2942 error "lfs setquota for $TSTID failed"
2944 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2945 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2946 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2947 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2949 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2950 error "total allocated inode/block limit not printed"
2952 resetquota -u $TSTUSR
2954 run_test 27c "lfs quota should support human-readable output"
2961 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2962 error "set fraction block limit failed"
2963 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2964 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2965 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2966 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2968 resetquota -u $TSTUSR
2970 run_test 27d "lfs setquota should support fraction block limit"
2974 local TESTFILE="$DIR/$tdir/$tfile"
2977 setup_quota_test || error "setup quota failed with $?"
2978 trap cleanup_quota_test EXIT
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"
3004 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3005 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3007 run_test 30 "Hard limit updates should not reset grace times"
3009 # basic usage tracking for user & group
3011 local INODES=10 # 10 files
3012 local BLK_CNT=2 # of 2M each
3013 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3015 setup_quota_test || error "setup quota failed with $?"
3016 trap cleanup_quota_test EXIT
3018 # make sure the system is clean
3019 local USED=$(getquota -u $TSTID global curspace)
3021 error "Used space ($USED) for user $TSTID isn't 0."
3022 USED=$(getquota -g $TSTID global curspace)
3024 error "Used space ($USED) for group $TSTID isn't 0."
3025 if is_project_quota_supported; then
3026 USED=$(getquota -p $TSTPRJID global curspace)
3027 [ $USED -ne 0 ] && error \
3028 "Used space ($USED) for project $TSTPRJID isn't 0."
3031 echo "Write files..."
3032 for i in $(seq 0 $INODES); do
3033 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3034 error "write failed"
3035 is_project_quota_supported &&
3036 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3037 echo "Iteration $i/$INODES completed"
3039 cancel_lru_locks osc
3041 echo "Wait for setattr on objects finished..."
3042 wait_delete_completed
3044 sync; sync_all_data || true
3046 echo "Verify disk usage after write"
3047 USED=$(getquota -u $TSTID global curspace)
3048 [ $USED -lt $TOTAL_BLKS ] &&
3049 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3050 USED=$(getquota -g $TSTID global curspace)
3051 [ $USED -lt $TOTAL_BLKS ] &&
3052 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3053 if is_project_quota_supported; then
3054 USED=$(getquota -p $TSTPRJID global curspace)
3055 [ $USED -lt $TOTAL_BLKS ] && error \
3056 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3059 echo "Verify inode usage after write"
3060 USED=$(getquota -u $TSTID global curinodes)
3061 [ $USED -lt $INODES ] &&
3062 error "Used inode for user $TSTID is $USED, expected $INODES"
3063 USED=$(getquota -g $TSTID global curinodes)
3064 [ $USED -lt $INODES ] &&
3065 error "Used inode for group $TSTID is $USED, expected $INODES"
3066 if is_project_quota_supported; then
3067 USED=$(getquota -p $TSTPRJID global curinodes)
3068 [ $USED -lt $INODES ] && error \
3069 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3074 echo "Verify disk usage after delete"
3075 USED=$(getquota -u $TSTID global curspace)
3076 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3077 USED=$(getquota -u $TSTID global curinodes)
3078 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3079 USED=$(getquota -g $TSTID global curspace)
3080 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3081 USED=$(getquota -g $TSTID global curinodes)
3082 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3083 if is_project_quota_supported; then
3084 USED=$(getquota -p $TSTPRJID global curspace)
3086 error "Used space for project $TSTPRJID isn't 0. $USED"
3087 USED=$(getquota -p $TSTPRJID global curinodes)
3089 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3092 run_test 33 "Basic usage tracking for user & group & project"
3094 # usage transfer test for user & group & project
3096 local BLK_CNT=2 # 2MB
3097 local project_supported="no"
3099 is_project_quota_supported && project_supported="yes"
3100 setup_quota_test || error "setup quota failed with $?"
3101 trap cleanup_quota_test EXIT
3103 # make sure the system is clean
3104 local USED=$(getquota -u $TSTID global curspace)
3105 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3106 USED=$(getquota -g $TSTID global curspace)
3107 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3109 local USED=$(getquota -u $TSTID2 global curspace)
3110 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3111 if [ $project_supported == "yes" ]; then
3112 USED=$(getquota -p $TSTPRJID global curspace)
3113 [ $USED -ne 0 ] && error \
3114 "Used space ($USED) for Project $TSTPRJID isn't 0."
3117 echo "Write file..."
3118 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3119 error "write failed"
3120 cancel_lru_locks osc
3121 sync; sync_all_data || true
3123 echo "chown the file to user $TSTID"
3124 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3126 echo "Wait for setattr on objects finished..."
3127 wait_delete_completed
3129 BLK_CNT=$((BLK_CNT * 1024))
3131 echo "Verify disk usage for user $TSTID"
3132 USED=$(getquota -u $TSTID global curspace)
3133 [ $USED -lt $BLK_CNT ] &&
3134 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3135 USED=$(getquota -u $TSTID global curinodes)
3137 error "Used inodes for user $TSTID is $USED, expected 1"
3139 echo "chgrp the file to group $TSTID"
3140 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3142 echo "Wait for setattr on objects finished..."
3143 wait_delete_completed
3145 echo "Verify disk usage for group $TSTID"
3146 USED=$(getquota -g $TSTID global curspace)
3147 [ $USED -ge $BLK_CNT ] ||
3148 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3149 USED=$(getquota -g $TSTID global curinodes)
3151 error "Used inodes for group $TSTID is $USED, expected 1"
3153 # chown won't change the ost object group. LU-4345 */
3154 echo "chown the file to user $TSTID2"
3155 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3157 echo "Wait for setattr on objects finished..."
3158 wait_delete_completed
3160 echo "change_project project id to $TSTPRJID"
3161 [ $project_supported == "yes" ] &&
3162 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3163 echo "Wait for setattr on objects finished..."
3164 wait_delete_completed
3166 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3167 USED=$(getquota -u $TSTID2 global curspace)
3168 [ $USED -lt $BLK_CNT ] &&
3169 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3170 USED=$(getquota -u $TSTID global curspace)
3172 error "Used space for user $TSTID is $USED, expected 0"
3173 USED=$(getquota -g $TSTID global curspace)
3174 [ $USED -lt $BLK_CNT ] &&
3175 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3176 if [ $project_supported == "yes" ]; then
3177 USED=$(getquota -p $TSTPRJID global curspace)
3178 [ $USED -lt $BLK_CNT ] && error \
3179 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3184 run_test 34 "Usage transfer for user & group & project"
3186 # usage is still accessible across restart
3188 local BLK_CNT=2 # 2 MB
3190 setup_quota_test || error "setup quota failed with $?"
3191 trap cleanup_quota_test EXIT
3193 echo "Write file..."
3194 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3195 error "write failed"
3196 is_project_quota_supported &&
3197 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3198 cancel_lru_locks osc
3200 echo "Wait for setattr on objects finished..."
3201 wait_delete_completed
3203 sync; sync_all_data || true
3205 echo "Save disk usage before restart"
3206 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3207 [ $ORIG_USR_SPACE -eq 0 ] &&
3208 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3209 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3210 [ $ORIG_USR_INODES -eq 0 ] &&
3211 error "Used inodes for user $TSTID is 0, expected 1"
3212 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3213 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3214 [ $ORIG_GRP_SPACE -eq 0 ] &&
3215 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3216 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3217 [ $ORIG_GRP_INODES -eq 0 ] &&
3218 error "Used inodes for group $TSTID is 0, expected 1"
3219 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3221 if is_project_quota_supported; then
3222 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3223 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3224 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3225 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3226 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3227 "Used inodes for project $TSTPRJID is 0, expected 1"
3228 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3236 echo "Verify disk usage after restart"
3237 local USED=$(getquota -u $TSTID global curspace)
3238 [ $USED -eq $ORIG_USR_SPACE ] ||
3239 error "Used space for user $TSTID changed from " \
3240 "$ORIG_USR_SPACE to $USED"
3241 USED=$(getquota -u $TSTID global curinodes)
3242 [ $USED -eq $ORIG_USR_INODES ] ||
3243 error "Used inodes for user $TSTID changed from " \
3244 "$ORIG_USR_INODES to $USED"
3245 USED=$(getquota -g $TSTID global curspace)
3246 [ $USED -eq $ORIG_GRP_SPACE ] ||
3247 error "Used space for group $TSTID changed from " \
3248 "$ORIG_GRP_SPACE to $USED"
3249 USED=$(getquota -g $TSTID global curinodes)
3250 [ $USED -eq $ORIG_GRP_INODES ] ||
3251 error "Used inodes for group $TSTID changed from " \
3252 "$ORIG_GRP_INODES to $USED"
3253 if [ $project_supported == "yes" ]; then
3254 USED=$(getquota -p $TSTPRJID global curinodes)
3255 [ $USED -eq $ORIG_PRJ_INODES ] ||
3256 error "Used inodes for project $TSTPRJID " \
3257 "changed from $ORIG_PRJ_INODES to $USED"
3258 USED=$(getquota -p $TSTPRJID global curspace)
3259 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3260 error "Used space for project $TSTPRJID "\
3261 "changed from $ORIG_PRJ_SPACE to $USED"
3264 # check if the vfs_dq_init() is called before writing
3265 echo "Append to the same file..."
3266 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3267 error "write failed"
3268 cancel_lru_locks osc
3269 sync; sync_all_data || true
3271 echo "Verify space usage is increased"
3272 USED=$(getquota -u $TSTID global curspace)
3273 [ $USED -gt $ORIG_USR_SPACE ] ||
3274 error "Used space for user $TSTID isn't increased" \
3275 "orig:$ORIG_USR_SPACE, now:$USED"
3276 USED=$(getquota -g $TSTID global curspace)
3277 [ $USED -gt $ORIG_GRP_SPACE ] ||
3278 error "Used space for group $TSTID isn't increased" \
3279 "orig:$ORIG_GRP_SPACE, now:$USED"
3280 if [ $project_supported == "yes" ]; then
3281 USED=$(getquota -p $TSTPRJID global curspace)
3282 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3283 error "Used space for project $TSTPRJID isn't " \
3284 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3289 run_test 35 "Usage is still accessible across reboot"
3291 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3294 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3295 skip "Old server doesn't have LU-5006 fix."
3297 setup_quota_test || error "setup quota failed with $?"
3298 trap cleanup_quota_test EXIT
3300 # make sure the system is clean
3301 local USED=$(getquota -u $TSTID global curspace)
3303 error "Used space ($USED) for user $TSTID isn't 0."
3305 # create file with MDS_OPEN_DELAY_CREATE flag
3306 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3307 error "Create file failed"
3309 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3310 oflag=sync || error "Write file failed"
3312 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3314 # wait for setattr on objects finished..."
3315 wait_delete_completed
3317 USED=$(getquota -u $TSTID global curspace)
3318 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3322 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3326 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3327 skip "Old server doesn't have LU-8801 fix."
3329 [ "$UID" != 0 ] && skip_env "must run as root" && return
3331 setup_quota_test || error "setup quota failed with $?"
3332 trap cleanup_quota_test EXIT
3334 # make sure the system is clean
3335 local USED=$(getquota -u $TSTID global curspace)
3337 error "Used space ($USED) for user $TSTID isn't 0."
3338 USED=$(getquota -u $TSTID2 global curspace)
3340 error "Used space ($USED) for user $TSTID2 isn't 0."
3342 local TESTFILE="$DIR/$tdir/$tfile"
3343 local file_cnt=10000
3345 # Generate id entries in accounting file
3346 echo "Create $file_cnt files..."
3347 for i in `seq $file_cnt`; do
3349 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3350 error "failed to chown $TESTFILE-$i"
3352 cancel_lru_locks osc
3353 sync; sync_all_data || true
3355 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3356 procf=${procf}.quota_slave.acct_user
3359 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3360 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3361 echo "Found $acct_cnt id entries"
3363 [ $file_cnt -eq $acct_cnt ] || {
3364 do_facet mds1 $LCTL get_param $procf
3365 error "skipped id entries"
3370 run_test 38 "Quota accounting iterator doesn't skip id entries"
3373 local TESTFILE="$DIR/$tdir/project"
3374 ! is_project_quota_supported &&
3375 skip "Project quota is not supported"
3377 setup_quota_test || error "setup quota failed with $?"
3380 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3381 [ $projectid -ne 0 ] &&
3382 error "Project id should be 0 not $projectid"
3383 change_project -p 1024 $TESTFILE
3384 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3385 [ $projectid -ne 1024 ] &&
3386 error "Project id should be 1024 not $projectid"
3388 stopall || error "failed to stopall (1)"
3391 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3392 [ $projectid -ne 1024 ] &&
3393 error "Project id should be 1024 not $projectid"
3397 run_test 39 "Project ID interface works correctly"
3400 ! is_project_quota_supported &&
3401 skip "Project quota is not supported"
3402 local dir1="$DIR/$tdir/dir1"
3403 local dir2="$DIR/$tdir/dir2"
3405 setup_quota_test || error "setup quota failed with $?"
3407 mkdir -p $dir1 $dir2
3408 change_project -sp 1 $dir1 && touch $dir1/1
3409 change_project -sp 2 $dir2
3411 ln $dir1/1 $dir2/1_link &&
3412 error "Hard link across different project quota should fail"
3417 run_test 40a "Hard link across different project ID"
3420 ! is_project_quota_supported &&
3421 skip "Project quota is not supported"
3422 local dir1="$DIR/$tdir/dir1"
3423 local dir2="$DIR/$tdir/dir2"
3425 setup_quota_test || error "setup quota failed with $?"
3426 mkdir -p $dir1 $dir2
3427 change_project -sp 1 $dir1 && touch $dir1/1
3428 change_project -sp 2 $dir2
3430 mv $dir1/1 $dir2/2 || error "mv failed $?"
3431 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3432 if [ "$projid" != "2" ]; then
3433 error "project id expected 2 not $projid"
3438 run_test 40b "Mv across different project ID"
3441 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3442 ! is_project_quota_supported &&
3443 skip "Project quota is not supported"
3445 setup_quota_test || error "setup quota failed with $?"
3446 local dir="$DIR/$tdir/dir"
3448 mkdir -p $dir && change_project -sp 1 $dir
3449 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3450 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3451 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3452 touch $dir/remote_dir/file
3453 #verify inherit works file for remote dir.
3454 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3455 [ "$projid" != "1" ] &&
3456 error "file under remote dir expected 1 not $projid"
3458 #Agent inode should be ignored for project quota
3459 USED=$(getquota -p 1 global curinodes)
3460 [ "$USED" != "3" ] &&
3461 error "file count expected 3 got $USED"
3467 run_test 40c "Remote child Dir inherit project quota properly"
3470 ! is_project_quota_supported &&
3471 skip "Project quota is not supported"
3473 setup_quota_test || error "setup quota failed with $?"
3474 local dir1="$DIR/$tdir/dir1"
3475 local dir2="$DIR/$tdir/dir2"
3477 mkdir -p $dir1 && change_project -sp 1 $dir1
3478 mkdir -p $dir2 && change_project -sp 2 $dir2
3479 for num in $(seq 1 10); do
3480 touch $dir1/file_$num $dir2/file_$num
3481 ln -s $dir1/file_$num $dir1/file_$num"_link"
3482 ln -s $dir2/file_$num $dir2/file_$num"_link"
3485 count=$($LFS find --projid 1 $DIR | wc -l)
3486 [ "$count" != 21 ] && error "expected 21 but got $count"
3488 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3489 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3490 [ "$count" != 22 ] && error "expected 22 but got $count"
3495 run_test 50 "Test if lfs find --projid works"
3498 ! is_project_quota_supported &&
3499 skip "Project quota is not supported"
3500 setup_quota_test || error "setup quota failed with $?"
3501 local dir="$DIR/$tdir/dir"
3503 mkdir $dir && change_project -sp 1 $dir
3504 local used=$(getquota -p 1 global curinodes)
3505 [ $used != "1" ] && error "expected 1 got $used"
3510 used=$(getquota -p 1 global curinodes)
3511 [ $used != "4" ] && error "expected 4 got $used"
3513 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3515 cp $DIR/$tdir/6 $dir/6
3516 used=$(getquota -p 1 global curinodes)
3517 [ $used != "5" ] && error "expected 5 got $used"
3520 mv $DIR/$tdir/6 $dir/7
3521 used=$(getquota -p 1 global curinodes)
3522 [ $used != "6" ] && error "expected 6 got $used"
3527 run_test 51 "Test project accounting with mv/cp"
3530 ! is_project_quota_supported &&
3531 skip "Project quota is not supported"
3532 setup_quota_test || error "setup quota failed with $?"
3533 local dir="$DIR/$tdir/dir"
3534 mkdir $dir && change_project -sp 1 $dir
3536 touch $DIR/$tdir/file
3537 #Try renaming a file into the project. This should fail.
3538 for num in $(seq 1 2000); do
3539 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3540 error "rename should fail"
3545 run_test 52 "Rename across different project ID"
3548 ! is_project_quota_supported &&
3549 skip "Project quota is not supported"
3550 setup_quota_test || error "setup quota failed with $?"
3551 local dir="$DIR/$tdir/dir"
3552 mkdir $dir && change_project -s $dir
3553 lfs project -d $dir | grep P || error "inherit attribute should be set"
3555 change_project -C $dir
3556 lfs project -d $dir | grep P &&
3557 error "inherit attribute should be cleared"
3562 run_test 53 "Project inherit attribute could be cleared"
3565 ! is_project_quota_supported &&
3566 skip "Project quota is not supported"
3567 setup_quota_test || error "setup quota failed with $?"
3568 trap cleanup_quota_test EXIT
3569 local testfile="$DIR/$tdir/$tfile-0"
3571 #set project ID/inherit attribute
3572 change_project -sp $TSTPRJID $DIR/$tdir
3573 $RUNAS createmany -m ${testfile} 100 ||
3574 error "create many files failed"
3576 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3577 # one more count for directory itself */
3581 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3582 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3584 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3585 [ $proj_count1 -eq $proj_count ] ||
3586 error "c2: expected $proj_count got $proj_count1"
3588 #clear project but with kept projid
3589 change_project -rCk $DIR/$tdir
3590 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3591 [ $proj_count1 -eq 1 ] ||
3592 error "c3: expected 1 got $proj_count1"
3594 #verify projid untouched.
3595 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3597 [ $proj_count1 -eq $proj_count ] ||
3598 error "c4: expected $proj_count got $proj_count1"
3601 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3602 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3603 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3605 #this time clear all
3606 change_project -rC $DIR/$tdir
3607 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3608 [ $proj_count1 -eq 0 ] ||
3609 error "c6: expected 0 got $proj_count1"
3611 unlinkmany ${testfile} 100 ||
3612 error "unlink many files failed"
3616 run_test 54 "basic lfs project interface test"
3619 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3620 skip "Not supported before 2.10.58."
3621 setup_quota_test || error "setup quota failed with $?"
3623 set_ost_qtype $QTYPE || error "enable ost quota failed"
3626 #add second group to TSTUSR
3627 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3630 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3631 error "failed to dd"
3633 cancel_lru_locks osc
3634 sync; sync_all_data || true
3636 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3637 error "failed to setquota on group $TSTUSR2"
3639 $LFS quota -v -g $TSTUSR2 $DIR
3641 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3642 error "chgrp should failed with -EDQUOT"
3644 USED=$(getquota -g $TSTUSR2 global curspace)
3647 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3648 error "failed to setquota on group $TSTUSR2"
3650 $LFS quota -v -g $TSTUSR2 $DIR
3652 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3653 error "chgrp should succeed"
3655 $LFS quota -v -g $TSTUSR2 $DIR
3659 run_test 55 "Chgrp should be affected by group quota"
3662 setup_quota_test || error "setup quota failed with $?"
3664 set_ost_qtype $QTYPE || error "enable ost quota failed"
3667 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3668 erro "failed to set grace time for usr quota"
3669 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3670 awk '{print $4 $8}')
3671 if [ "x$grace_time" != "x10s;10s" ]; then
3672 $LFS quota -t -u $DIR
3673 error "expected grace time: 10s;10s, got:$grace_time"
3678 run_test 56 "lfs quota -t should work well"
3681 setup_quota_test || error "setup quota failed with $?"
3683 local dir="$DIR/$tdir/dir"
3686 #try to change pipe file should not hang and return failure
3687 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3688 awk -F ':' '{ print \\\$2 }'" \
3689 " unable to get xattr for fifo '$dir/pipe'" || return 1
3690 #command can process further if it hit some errors
3691 touch $dir/aaa $dir/bbb
3692 mkdir $dir/subdir -p
3693 touch $dir/subdir/aaa $dir/subdir/bbb
3694 #create one invalid link file
3695 ln -s $dir/not_exist_file $dir/ccc
3696 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3697 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3701 run_test 57 "lfs project could tolerate errors"
3704 [ "$mds1_FSTYPE" != ldiskfs ] &&
3705 skip "ldiskfs only test"
3706 disable_project_quota
3707 setup_quota_test || error "setup quota failed with $?"
3710 local testfile="$DIR/$tdir/$tfile-0"
3711 #make sure it did not crash kernel
3712 touch $testfile && lfs project -sp 1 $testfile
3714 enable_project_quota
3717 run_test 59 "lfs project dosen't crash kernel with project disabled"
3720 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3721 skip "Needs MDS version 2.11.53 or later."
3722 setup_quota_test || error "setup quota failed with $?"
3723 trap cleanup_quota_test EXIT
3725 local testfile=$DIR/$tdir/$tfile
3728 set_mdt_qtype "ug" || error "enable mdt quota failed"
3730 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3731 error "set quota failed"
3732 quota_show_check a g $TSTUSR
3734 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3735 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3736 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3737 error "create many files failed"
3739 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3741 # root user can overrun quota
3742 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3743 error "root user should succeed"
3747 run_test 60 "Test quota for root with setgid"
3749 # test default quota
3750 test_default_quota() {
3751 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3752 skip "Not supported before 2.11.51."
3757 local qprjid=$TSTPRJID
3761 local LIMIT=20480 #20M disk space
3762 local TESTFILE="$DIR/$tdir/$tfile-0"
3764 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3765 echo "Project quota is not supported" && return 0
3767 [ $qtype == "-u" ] && qdtype="-U"
3768 [ $qtype == "-g" ] && qdtype="-G"
3769 [ $qtype == "-p" ] && {
3774 [ $qpool == "meta" ] && {
3775 LIMIT=10240 #10K inodes
3780 setup_quota_test || error "setup quota failed with $?"
3781 trap cleanup_quota_test EXIT
3785 # enable mdt/ost quota
3786 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3787 set_ost_qtype $QTYPE || error "enable ost quota failed"
3789 log "set to use default quota"
3790 $LFS setquota $qtype $qid -d $DIR ||
3791 error "set $qid to use default quota failed"
3793 log "set default quota"
3794 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3795 error "set $qid default quota failed"
3797 log "get default quota"
3798 $LFS quota $qdtype $DIR || error "get default quota failed"
3800 if [ $qpool == "data" ]; then
3801 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3803 [ $SLIMIT -eq $LIMIT ] ||
3804 error "the returned default quota is wrong"
3806 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3808 [ $SLIMIT -eq $LIMIT ] ||
3809 error "the returned default quota is wrong"
3812 # make sure the system is clean
3813 local USED=$(getquota $qtype $qid global curspace)
3814 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3816 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3817 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3819 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3821 log "Test not out of quota"
3822 if [ $qpool == "data" ]; then
3823 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3824 quota_error $qtype $qid "write failed, expect succeed"
3826 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3827 quota_error $qtype $qid "create failed, expect succeed"
3829 unlinkmany $TESTFILE $((LIMIT/2))
3832 log "Test out of quota"
3833 # flush cache, ensure noquota flag is set on client
3834 cancel_lru_locks osc
3835 cancel_lru_locks mdc
3836 sync; sync_all_data || true
3837 if [ $qpool == "data" ]; then
3838 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3839 quota_error $qtype $qid "write succeed, expect EDQUOT"
3841 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3842 quota_error $qtype $qid "create succeed, expect EDQUOT"
3844 unlinkmany $TESTFILE $((LIMIT*2))
3847 log "Increase default quota"
3848 # increase default quota
3849 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3850 error "set default quota failed"
3852 cancel_lru_locks osc
3853 cancel_lru_locks mdc
3854 sync; sync_all_data || true
3855 if [ $qpool == "data" ]; then
3856 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3857 quota_error $qtype $qid "write failed, expect succeed"
3859 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3860 quota_error $qtype $qid "create failed, expect succeed"
3862 unlinkmany $TESTFILE $((LIMIT*2))
3865 log "Set quota to override default quota"
3866 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3867 error "set $qid quota failed"
3869 cancel_lru_locks osc
3870 cancel_lru_locks mdc
3871 sync; sync_all_data || true
3872 if [ $qpool == "data" ]; then
3873 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3874 quota_error $qtype $qid "write succeed, expect EQUOT"
3876 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3877 quota_error $qtype $qid "create succeed, expect EQUOT"
3879 unlinkmany $TESTFILE $((LIMIT*2))
3882 log "Set to use default quota again"
3883 $LFS setquota $qtype $qid -d $DIR ||
3884 error "set $qid to use default quota failed"
3886 cancel_lru_locks osc
3887 cancel_lru_locks mdc
3888 sync; sync_all_data || true
3889 if [ $qpool == "data" ]; then
3890 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3891 quota_error $qtype $qid "write failed, expect succeed"
3893 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3894 quota_error $qtype $qid "create failed, expect succeed"
3896 unlinkmany $TESTFILE $((LIMIT*2))
3901 wait_delete_completed || error "wait_delete_completed failed"
3902 sync_all_data || true
3903 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3904 error "reset default quota failed"
3905 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3906 error "reset quota failed"
3912 test_default_quota "-u" "data"
3913 test_default_quota "-u" "meta"
3914 test_default_quota "-g" "data"
3915 test_default_quota "-g" "meta"
3916 test_default_quota "-p" "data"
3917 test_default_quota "-p" "meta"
3919 run_test 61 "default quota tests"
3922 ! is_project_quota_supported &&
3923 skip "Project quota is not supported"
3924 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3925 skip "chattr did not support project quota"
3926 setup_quota_test || error "setup quota failed with $?"
3927 local testdir=$DIR/$tdir/
3929 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3930 change_project -s $testdir
3931 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3932 error "inherit attribute should be set"
3933 # chattr used FS_IOC_SETFLAGS ioctl
3934 $RUNAS chattr -P $testdir &&
3935 error "regular user clear inherit should fail"
3936 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3937 error "inherit attribute should still be set"
3938 chattr -P $testdir || error "root failed to clear inherit"
3939 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3940 error "inherit attribute should be cleared"
3943 run_test 62 "Project inherit should be only changed by root"
3946 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3947 skip "Not supported before 2.11.55"
3951 local dd_failed=false
3952 local tdir_dom=${tdir}_dom
3953 local LIMIT=20480 #20M
3955 [ $qtype == "p" ] && ! is_project_quota_supported &&
3956 echo "Project quota is not supported" && return 0
3958 [ $qtype == "p" ] && qid=$TSTPRJID
3960 setup_quota_test || error "setup quota failed with $?"
3961 trap cleanup_quota_test EXIT
3965 # enable mdt/ost quota
3966 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3967 set_ost_qtype $QTYPE || error "enable ost quota failed"
3969 # make sure the system is clean
3970 local USED=$(getquota -$qtype $qid global curspace)
3971 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3973 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3975 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3976 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3977 error "setstripe $tdir_dom failed"
3978 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3980 [ $qtype == "p" ] && {
3981 change_project -sp $TSTPRJID $DIR/$tdir
3982 change_project -sp $TSTPRJID $DIR/$tdir_dom
3985 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3986 error "set $qid quota failed"
3988 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3989 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3993 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3995 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3996 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4000 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4002 rm -f $DIR/$tdir_dom/*
4004 # flush cache, ensure noquota flag is set on client
4005 cancel_lru_locks osc
4006 cancel_lru_locks mdc
4007 sync; sync_all_data || true
4011 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4012 quota_error $qtype $qid "write failed, expect succeed"
4014 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4015 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4019 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4022 rm -f $DIR/$tdir_dom/*
4024 # flush cache, ensure noquota flag is set on client
4025 cancel_lru_locks osc
4026 cancel_lru_locks mdc
4027 sync; sync_all_data || true
4031 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4032 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4036 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4038 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4039 quota_error $qtype $qid "write succeed, expect EDQUOT"
4042 rm -fr $DIR/$tdir_dom
4044 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4045 error "reset usr quota failed"
4055 run_test 63 "quota on DoM tests"
4058 ! is_project_quota_supported &&
4059 skip "Project quota is not supported"
4060 setup_quota_test || error "setup quota failed with $?"
4061 local dir1="$DIR/$tdir/"
4064 ln -s $dir1/file $dir1/file_link
4066 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4067 error "set symlink file's project should fail"
4069 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4070 error "get symlink file's project should fail"
4074 run_test 64 "lfs project on symlink files should fail"
4078 local TESTFILE="$DIR/$tdir/$tfile-0"
4080 setup_quota_test || error "setup quota failed with $?"
4081 set_ost_qtype $QTYPE || error "enable ost quota failed"
4085 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4086 error "failed to write"
4087 # flush cache, ensure noquota flag is set on client
4088 cancel_lru_locks osc
4089 sync; sync_all_data || true
4091 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4092 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4093 local quota_all=$($RUNAS $LFS quota $DIR)
4095 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4096 error "usr quota not match"
4097 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4098 error "grp quota not match"
4104 run_test 65 "Check lfs quota result"
4107 ! is_project_quota_supported &&
4108 skip "Project quota is not supported"
4109 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4110 skip "Not supported before 2.12.4"
4111 setup_quota_test || error "setup quota failed with $?"
4112 stack_trap cleanup_quota_test EXIT
4113 local old=$(do_facet mds1 $LCTL get_param -n \
4114 mdt.*.enable_chprojid_gid | head -1)
4115 local testdir=$DIR/$tdir/foo
4117 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4118 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4121 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4122 chown -R $TSTID:$TSTID $testdir
4123 change_project -sp $TSTPRJID $testdir
4124 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4126 $RUNAS lfs project -p 0 $testdir/foo &&
4127 error "nonroot user should fail to set projid"
4129 $RUNAS lfs project -C $testdir/foo &&
4130 error "nonroot user should fail to clear projid"
4132 change_project -C $testdir/foo || error "failed to clear project"
4134 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4135 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4136 "failed to set projid with normal user when enable_chprojid_gid=-1"
4138 $RUNAS lfs project -rC $testdir/ || error \
4139 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4141 touch $testdir/bar || error "failed touch $testdir/bar"
4142 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4143 "normal user should not be able to set projid on root owned file"
4145 change_project -p $TSTPRJID $testdir/bar || error \
4146 "root should be able to change its own file's projid"
4150 run_test 66 "nonroot user can not change project state in default"
4157 local short_qtype=${qtype:0:1}
4160 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4162 quota_usr) _runas=$RUNAS;;
4163 quota_2usr) _runas=$RUNAS2;;
4164 *) error "unknown quota parameter $4";;
4169 $_runas $DD of=$file count=$size ||
4170 quota_error $short_qtype $TSTUSR \
4171 "$qtype write failure, but expect success"
4173 cancel_lru_locks osc
4175 sync; sync_all_data || true
4184 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4186 do_facet mds1 $LCTL get_param $param |
4187 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4191 local limit=20 # 20M
4192 local testfile="$DIR/$tdir/$tfile-0"
4193 local testfile2="$DIR/$tdir/$tfile-1"
4194 local testfile3="$DIR/$tdir/$tfile-2"
4195 local qpool="qpool1"
4201 [ "$ost1_FSTYPE" == zfs ] &&
4202 skip "ZFS grants some block space together with inode"
4204 setup_quota_test || error "setup quota failed with $?"
4205 trap cleanup_quota_test EXIT
4208 set_ost_qtype $QTYPE || error "enable ost quota failed"
4211 log "User quota (block hardlimit:$limit MB)"
4212 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4213 error "set user quota failed"
4215 # make sure the system is clean
4216 used=$(getquota -u $TSTUSR global curspace)
4217 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4219 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4220 echo "granted 0x0 before write $granted"
4222 # trigger reintegration
4223 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4224 procf=${procf}quota_slave.force_reint
4225 do_facet ost1 $LCTL set_param $procf=1 ||
4226 error "force reintegration failed"
4227 wait_ost_reint "u" || error "reintegration failed"
4228 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4229 [ $granted -ne 0 ] &&
4230 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4232 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4233 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4235 # write 10 MB to testfile
4236 test_67_write "$testfile" "user" 10 "quota_usr"
4238 # create qpool and add OST1
4239 pool_add $qpool || error "pool_add failed"
4240 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4241 # as quota_usr hasn't limits, lqe may absent. But it should be
4242 # created after the 1st direct qmt_get.
4243 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4245 # check granted - should be 0, as testfile is located only on OST0
4246 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4247 echo "global granted $granted"
4248 granted=$(getgranted $qpool "dt" $TSTID "usr")
4249 echo "$qpool granted $granted"
4250 [ $granted -ne 0 ] &&
4251 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4253 # add OST0 to qpool and check granted space
4254 pool_add_targets $qpool 0 1 ||
4255 error "pool_add_targets failed"
4256 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4257 echo "Granted $granted_mb MB"
4258 #should be 10M + qunit for each OST
4259 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4260 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4262 $LFS setstripe $testfile2 -c 1 -i 1 ||
4263 error "setstripe $testfile2 failed"
4264 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4265 # Write from another user and check that qpool1
4266 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4267 test_67_write "$testfile2" "user" 10 "quota_2usr"
4268 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4269 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4270 [ $granted -ne 0 ] &&
4271 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4273 # Granted space for quota_2usr in qpool1 should appear only
4274 # when global lqe for this user becomes enforced.
4275 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4276 error "set user quota failed"
4277 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4278 echo "granted_mb $granted_mb"
4279 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4280 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4282 $LFS setstripe $testfile3 -c 1 -i 0 ||
4283 error "setstripe $testfile3 failed"
4284 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4285 test_67_write "$testfile3" "user" 10 "quota_2usr"
4286 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4287 echo "$testfile3 granted_mb $granted_mb"
4288 [ $granted_mb -eq $limit ] ||
4289 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4291 # remove OST1 from the qpool1 and check granted space
4292 # should be 0 for TSTUSR and 10M for TSTUSR2
4293 pool_remove_target $qpool 0
4294 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4295 [ $granted_mb -eq 0 ] ||
4296 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4297 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4298 [ $granted_mb -eq 10 ] ||
4299 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4302 wait_delete_completed || error "wait_delete_completed failed"
4303 sync_all_data || true
4304 used=$(getquota -u $TSTUSR global curspace)
4305 [ $used -ne 0 ] && quota_error u $TSTUSR \
4306 "user quota isn't released after deletion"
4307 resetquota -u $TSTUSR
4311 run_test 67 "quota pools recalculation"
4318 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4319 awk '/usr/ {getline; print $2}'
4324 local qpool="qpool1"
4327 setup_quota_test || error "setup quota failed with $?"
4328 stack_trap cleanup_quota_test EXIT
4331 set_ost_qtype $QTYPE || error "enable ost quota failed"
4333 # check slave number for glbal pool
4334 local nr=$(get_slave_nr "0x0" "usr")
4335 echo "nr result $nr"
4336 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4337 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4339 # create qpool and add OST1
4340 pool_add $qpool || error "pool_add failed"
4341 nr=$(get_slave_nr $qpool "usr")
4342 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4345 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4346 nr=$(get_slave_nr $qpool "usr")
4347 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4350 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4351 nr=$(get_slave_nr $qpool "usr")
4352 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4355 pool_remove_target $qpool 0
4356 nr=$(get_slave_nr $qpool "usr")
4357 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4360 pool_remove_target $qpool 1
4361 nr=$(get_slave_nr $qpool "usr")
4362 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4364 # Check again that all is fine with global pool
4365 nr=$(get_slave_nr "0x0" "usr")
4366 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4367 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4371 run_test 68 "slave number in quota pool changed after each add/remove OST"
4375 local global_limit=200 # 200M
4376 local limit=10 # 10M
4377 local testfile="$DIR/$tdir/$tfile-0"
4378 local dom0="$DIR/$tdir/dom0"
4379 local qpool="qpool1"
4382 setup_quota_test || error "setup quota failed with $?"
4383 stack_trap cleanup_quota_test EXIT
4386 set_ost_qtype $QTYPE || error "enable ost quota failed"
4387 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4389 # Save DOM only at MDT0
4390 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4391 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4393 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4395 # create qpool and add OST0
4396 pool_add $qpool || error "pool_add failed"
4397 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4399 log "User quota (block hardlimit:$global_limit MB)"
4400 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4401 error "set user quota failed"
4403 log "User quota (block hardlimit:$limit MB)"
4404 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4405 error "set user quota failed"
4407 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4408 quota_error u $TSTUSR "write failed"
4410 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4411 oflag=sync || quota_error u $TSTUSR "write failed"
4413 $RUNAS $DD of=$testfile count=$limit || true
4415 # flush cache, ensure noquota flag is set on client
4416 cancel_lru_locks osc
4417 sync; sync_all_data || true
4419 # MDT0 shouldn't get EDQUOT with glimpse.
4420 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4421 quota_error u $TSTUSR \
4422 "user write success, but expect EDQUOT"
4424 # Now all members of qpool1 should get EDQUOT. Expect success
4425 # when write to DOM on MDT0, as it belongs to global pool.
4426 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4427 oflag=sync || quota_error u $TSTUSR "write failed"
4429 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4430 oflag=sync || quota_error u $TSTUSR "write failed"
4434 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4438 local qpool="qpool1"
4443 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4444 skip "Needs a client >= $VERSION_WITH_QP"
4446 setup_quota_test || error "setup quota failed with $?"
4447 stack_trap cleanup_quota_test EXIT
4449 # MDS returns EFAULT for unsupported quotactl command
4450 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4452 # create qpool and add OST0
4453 pool_add $qpool || error "pool_add failed"
4454 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4456 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4458 [ $rc -eq $err ] || error "setquota res $rc != $err"
4460 # If MDS supports QP, check that limit was set properly.
4461 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4462 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4463 echo "hard limit $bhard limit $limit"
4464 [ $bhard -ne $((limit*1024)) ] &&
4465 error "bhard:$bhard for $qpool!=$((limit*1024))"
4468 $LFS quota -u $TSTUSR --pool $qpool $DIR
4470 [ $rc -eq $err ] || error "quota res $rc != $err"
4474 run_test 70 "check lfs setquota/quota with a pool option"
4478 local limit=10 # 10M
4479 local global_limit=100 # 100M
4480 local testfile="$DIR/$tdir/$tfile-0"
4481 local qpool="qpool1"
4482 local qpool2="qpool2"
4484 [ "$ost1_FSTYPE" == zfs ] &&
4485 skip "ZFS grants some block space together with inode"
4486 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4488 setup_quota_test || error "setup quota failed with $?"
4489 stack_trap cleanup_quota_test EXIT
4492 set_ost_qtype $QTYPE || error "enable ost quota failed"
4495 log "User quota (block hardlimit:$global_limit MB)"
4496 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4497 error "set user quota failed"
4499 pool_add $qpool || error "pool_add failed"
4500 pool_add_targets $qpool 0 1 ||
4501 error "pool_add_targets failed"
4503 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4504 error "set user quota failed"
4506 pool_add $qpool2 || error "pool_add failed"
4507 pool_add_targets $qpool2 1 1 ||
4508 error "pool_add_targets failed"
4510 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4511 error "set user quota failed"
4513 # make sure the system is clean
4514 local used=$(getquota -u $TSTUSR global curspace)
4517 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4519 # create 1st component 1-10M
4520 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4521 #create 2nd component 10-30M
4522 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4523 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4525 # сheck normal use and out of quota with PFL
4526 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4527 test_1_check_write $testfile "user" $((limit*2))
4529 wait_delete_completed || error "wait_delete_completed failed"
4530 sync_all_data || true
4531 used=$(getquota -u $TSTUSR global curspace)
4532 [ $used -ne 0 ] && quota_error u $TSTUSR \
4533 "user quota isn't released after deletion"
4535 # create 1st component 1-10M
4536 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4537 # create 2nd component 10-30M
4538 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4539 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4541 # write to the 2nd component
4542 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4543 quota_error u $TSTUSR \
4544 "write failure, but expect success"
4545 # this time maybe cache write, ignore it's failure
4546 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4547 cancel_lru_locks osc
4548 sync; sync_all_data || true
4549 # write over limit in qpool2(2nd component 10-30M)
4550 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4551 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4552 # write to the 1st component - OST0 is empty
4553 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4554 quota_error u $TSTUSR "write failed"
4558 run_test 71a "Check PFL with quota pools"
4562 local global_limit=1000 # 1G
4563 local limit1=160 # 160M
4564 local limit2=10 # 10M
4565 local testfile="$DIR/$tdir/$tfile-0"
4566 local qpool="qpool1"
4567 local qpool2="qpool2"
4569 [ "$ost1_FSTYPE" == zfs ] &&
4570 skip "ZFS grants some block space together with inode"
4571 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4573 setup_quota_test || error "setup quota failed with $?"
4574 stack_trap cleanup_quota_test EXIT
4577 set_ost_qtype $QTYPE || error "enable ost quota failed"
4580 log "User quota (block hardlimit:$global_limit MB)"
4581 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4582 error "set user quota failed"
4584 pool_add $qpool || error "pool_add failed"
4585 pool_add_targets $qpool 0 1 ||
4586 error "pool_add_targets failed"
4588 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4589 error "set user quota failed"
4591 pool_add $qpool2 || error "pool_add failed"
4592 pool_add_targets $qpool2 1 1 ||
4593 error "pool_add_targets failed"
4595 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4596 error "set user quota failed"
4598 # make sure the system is clean
4599 local used=$(getquota -u $TSTUSR global curspace)
4602 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4604 # First component is on OST0, 2nd on OST1
4605 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4606 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4608 # fill the 1st component on OST0
4609 $RUNAS $DD of=$testfile count=128 ||
4610 quota_error u $TSTUSR "write failed"
4611 # write to the 2nd cmpnt on OST1
4612 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4613 quota_error u $TSTUSR "write failed"
4614 # this time maybe cache write, ignore it's failure
4615 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4617 cancel_lru_locks osc
4618 sync; sync_all_data || true
4619 # write over limit in qpool2
4620 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4621 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4625 run_test 71b "Check SEL with quota pools"
4629 local limit=10 # 10M
4630 local global_limit=50 # 50M
4631 local testfile="$DIR/$tdir/$tfile-0"
4632 local qpool="qpool1"
4635 setup_quota_test || error "setup quota failed with $?"
4636 stack_trap cleanup_quota_test EXIT
4639 set_ost_qtype $QTYPE || error "enable ost quota failed"
4642 log "User quota (block hardlimit:$global_limit MB)"
4643 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4644 error "set user quota failed"
4646 pool_add $qpool || error "pool_add failed"
4647 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4649 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4650 error "set user quota failed"
4652 # make sure the system is clean
4653 local used=$(getquota -u $TSTUSR global curspace)
4655 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4657 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4659 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4660 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4661 test_1_check_write $testfile "user" $limit
4662 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4664 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4665 # check that lfs quota -uv --pool prints only OST that
4666 # was added in a pool
4667 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4668 grep "OST\|MDT" && error "$qpool consists wrong targets"
4672 run_test 72 "lfs quota --pool prints only pool's OSTs"
4676 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4677 if $PQ_CLEANUP; then
4678 disable_project_quota
4681 reset_quota_settings
4686 check_and_cleanup_lustre
4687 export QUOTA_AUTO=$QUOTA_AUTO_OLD