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 -o $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 -o $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 -o $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 -o $qpool1 $DIR ||
790 error "set user quota failed"
792 $LFS setquota -u $TSTUSR -B 0M -o $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 -o $qpool1 $DIR ||
852 error "set user quota failed"
854 $LFS setquota -u $TSTUSR -B ${limit2}M -o $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 -o $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 $short_qtype $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 -o $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"
1002 # test inode hardlimit
1004 local TESTFILE="$DIR/$tdir/$tfile-0"
1005 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1006 qmt.$FSNAME-QMT0000.md-0x0.info |
1007 awk '/least qunit/{ print $3 }')
1008 local L2=$(do_facet mds1 $LCTL get_param -n \
1009 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1011 [ $L2 -le $LIMIT ] || LIMIT=$L2
1013 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1015 local FREE_INODES=$(mdt_free_inodes 0)
1016 echo "$FREE_INODES free inodes on master MDT"
1017 [ $FREE_INODES -lt $LIMIT ] &&
1018 skip "not enough free inodes $FREE_INODES required $LIMIT"
1020 setup_quota_test || error "setup quota failed with $?"
1021 trap cleanup_quota_test EXIT
1024 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1027 log "User quota (inode hardlimit:$LIMIT files)"
1028 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1029 error "set user quota failed"
1031 # make sure the system is clean
1032 local USED=$(getquota -u $TSTUSR global curinodes)
1033 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1035 log "Create $LIMIT files ..."
1036 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1037 quota_error u $TSTUSR "user create failure, but expect success"
1038 log "Create out of file quota ..."
1039 $RUNAS touch ${TESTFILE}_xxx &&
1040 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1043 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1044 rm -f ${TESTFILE}_xxx
1045 wait_delete_completed
1047 USED=$(getquota -u $TSTUSR global curinodes)
1048 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1049 "user quota isn't released after deletion"
1050 resetquota -u $TSTUSR
1053 log "--------------------------------------"
1054 log "Group quota (inode hardlimit:$LIMIT files)"
1055 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1056 error "set group quota failed"
1058 TESTFILE=$DIR/$tdir/$tfile-1
1059 # make sure the system is clean
1060 USED=$(getquota -g $TSTUSR global curinodes)
1061 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1063 log "Create $LIMIT files ..."
1064 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1065 quota_error g $TSTUSR "group create failure, but expect success"
1066 log "Create out of file quota ..."
1067 $RUNAS touch ${TESTFILE}_xxx &&
1068 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1071 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1072 rm -f ${TESTFILE}_xxx
1073 wait_delete_completed
1075 USED=$(getquota -g $TSTUSR global curinodes)
1076 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1077 "user quota isn't released after deletion"
1079 resetquota -g $TSTUSR
1080 ! is_project_quota_supported && cleanup_quota_test &&
1081 echo "Skip project quota is not supported" && return 0
1084 log "--------------------------------------"
1085 log "Project quota (inode hardlimit:$LIMIT files)"
1086 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1087 error "set project quota failed"
1089 TESTFILE=$DIR/$tdir/$tfile-1
1090 # make sure the system is clean
1091 USED=$(getquota -p $TSTPRJID global curinodes)
1093 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1095 change_project -sp $TSTPRJID $DIR/$tdir
1096 log "Create $LIMIT files ..."
1097 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1098 $TSTPRJID "project create fail, but expect success"
1099 log "Create out of file quota ..."
1100 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1101 "project create success, but expect EDQUOT"
1102 change_project -C $DIR/$tdir
1105 USED=$(getquota -p $TSTPRJID global curinodes)
1106 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1107 "project quota isn't released after deletion"
1110 run_test 2 "File hard limit (normal use and out of quota)"
1121 stack_trap cleanup_quota_test EXIT
1123 $LFS setstripe $testfile -c 1 -i 0
1124 chown $TSTUSR.$TSTUSR $testfile
1125 [ "$qtype" == "p" ] && is_project_quota_supported &&
1126 change_project -p $TSTPRJID $testfile
1128 echo "Write up to soft limit"
1129 $RUNAS $DD of=$testfile count=$limit ||
1130 quota_error a $TSTUSR "write failure, but expect success"
1131 OFFSET=$((limit * 1024))
1132 cancel_lru_locks osc
1134 echo "Write to exceed soft limit"
1135 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1136 quota_error a $TSTUSR "write failure, but expect success"
1137 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1138 cancel_lru_locks osc
1140 echo "mmap write when over soft limit"
1141 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1142 quota_error a $TSTUSR "mmap write failure, but expect success"
1143 cancel_lru_locks osc
1148 $SHOW_QUOTA_INFO_USER
1149 $SHOW_QUOTA_INFO_GROUP
1150 $SHOW_QUOTA_INFO_PROJID
1152 echo "Write before timer goes off"
1153 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1154 quota_error a $TSTUSR "write failure, but expect success"
1155 OFFSET=$((OFFSET + 1024))
1156 cancel_lru_locks osc
1158 wait_grace_time $qtype "block" $pool
1163 $SHOW_QUOTA_INFO_USER
1164 $SHOW_QUOTA_INFO_GROUP
1165 $SHOW_QUOTA_INFO_PROJID
1167 log "Write after timer goes off"
1168 # maybe cache write, ignore.
1169 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1170 OFFSET=$((OFFSET + 1024))
1171 cancel_lru_locks osc
1172 log "Write after cancel lru locks"
1173 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1174 quota_error a $TSTUSR "write success, but expect EDQUOT"
1179 $SHOW_QUOTA_INFO_USER
1180 $SHOW_QUOTA_INFO_GROUP
1181 $SHOW_QUOTA_INFO_PROJID
1183 echo "Unlink file to stop timer"
1185 wait_delete_completed
1186 sync_all_data || true
1191 $SHOW_QUOTA_INFO_USER
1192 $SHOW_QUOTA_INFO_GROUP
1193 $SHOW_QUOTA_INFO_PROJID
1195 $LFS setstripe $testfile -c 1 -i 0
1196 chown $TSTUSR.$TSTUSR $testfile
1197 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1200 $RUNAS $DD of=$testfile count=$limit ||
1201 quota_error a $TSTUSR "write failure, but expect success"
1208 local grace=20 # 20s
1209 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1212 local testfile=$DIR/$tdir/$tfile-0
1214 # get minimum soft qunit size
1215 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1216 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1218 set_ost_qtype $QTYPE || error "enable ost quota failed"
1220 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1221 # make sure the system is clean
1222 local used=$(getquota -u $TSTUSR global curspace)
1223 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1225 $LFS setquota -t -u --block-grace $grace --inode-grace \
1226 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1227 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1228 error "set user quota failed"
1230 test_block_soft $testfile $grace $limit "u"
1232 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1233 testfile=$DIR/$tdir/$tfile-1
1234 # make sure the system is clean
1235 used=$(getquota -g $TSTUSR global curspace)
1236 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1238 $LFS setquota -t -g --block-grace $grace --inode-grace \
1239 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1240 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1241 error "set group quota failed"
1243 test_block_soft $testfile $grace $limit "g"
1245 if is_project_quota_supported; then
1246 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1247 testfile=$DIR/$tdir/$tfile-2
1248 # make sure the system is clean
1249 used=$(getquota -p $TSTPRJID global curspace)
1250 [ $used -ne 0 ] && error \
1251 "Used space($used) for project $TSTPRJID isn't 0."
1253 $LFS setquota -t -p --block-grace $grace --inode-grace \
1254 $MAX_IQ_TIME $DIR ||
1255 error "set project grace time failed"
1256 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1257 $DIR || error "set project quota failed"
1259 test_block_soft $testfile $grace $limit "p"
1260 resetquota -p $TSTPRJID
1261 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1262 $MAX_IQ_TIME $DIR ||
1263 error "restore project grace time failed"
1267 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1268 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1269 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1270 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1272 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1275 local grace=20 # 20s
1276 local qpool="qpool1"
1277 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1280 local testfile=$DIR/$tdir/$tfile-0
1283 # get minimum soft qunit size
1284 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1285 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1286 local glbl_limit=$((2*limit))
1287 local glbl_grace=$((2*grace))
1288 echo "limit $limit glbl_limit $glbl_limit"
1289 echo "grace $grace glbl_grace $glbl_grace"
1291 set_ost_qtype $QTYPE || error "enable ost quota failed"
1293 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1294 # make sure the system is clean
1295 local used=$(getquota -u $TSTUSR global curspace)
1296 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1298 pool_add $qpool || error "pool_add failed"
1299 pool_add_targets $qpool 0 1 ||
1300 error "pool_add_targets failed"
1302 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1303 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1304 $LFS setquota -t -u --block-grace $grace \
1305 -o $qpool $DIR || error "set user grace time failed"
1307 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1308 error "set user quota failed"
1309 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1310 error "set user quota failed"
1312 test_block_soft $testfile $grace $limit "u" $qpool
1314 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1315 testfile=$DIR/$tdir/$tfile-1
1316 # make sure the system is clean
1317 used=$(getquota -g $TSTUSR global curspace)
1318 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1320 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1321 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1322 $LFS setquota -t -g --block-grace $grace \
1323 -o $qpool $DIR || error "set group grace time failed"
1325 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1326 error "set group quota failed"
1327 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1328 error "set group quota failed"
1330 test_block_soft $testfile $grace $limit "g" $qpool
1332 if is_project_quota_supported; then
1333 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1334 testfile=$DIR/$tdir/$tfile-2
1335 # make sure the system is clean
1336 used=$(getquota -p $TSTPRJID global curspace)
1337 [ $used -ne 0 ] && error \
1338 "Used space($used) for project $TSTPRJID isn't 0."
1340 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1341 $MAX_IQ_TIME $DIR ||
1342 error "set project grace time failed"
1343 $LFS setquota -t -p --block-grace $grace \
1344 -o $qpool $DIR || error "set project grace time failed"
1346 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1347 $DIR || error "set project quota failed"
1348 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -o $qpool $DIR ||
1349 error "set project quota failed"
1351 test_block_soft $testfile $grace $limit "p" $qpool
1352 resetquota -p $TSTPRJID
1353 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1354 $MAX_IQ_TIME $DIR ||
1355 error "restore project grace time failed"
1356 $LFS setquota -t -p --block-grace $MAX_DQ_TIME -o $qpool $DIR ||
1357 error "set project grace time failed"
1361 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1362 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1363 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1364 -o $qpool $DIR || error "restore user grace time failed"
1365 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1366 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1367 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1368 -o $qpool $DIR || error "restore group grace time failed"
1370 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1373 local grace=20 # 20s
1374 local qpool="qpool1"
1375 local qpool2="qpool2"
1376 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1379 local testfile=$DIR/$tdir/$tfile-0
1382 # get minimum soft qunit size
1383 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1384 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1385 local limit2=$((limit+4))
1386 local glbl_limit=$((limit+8))
1387 local grace1=$((grace+10))
1389 local glbl_grace=$((grace+20))
1390 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1391 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1393 set_ost_qtype $QTYPE || error "enable ost quota failed"
1395 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1396 # make sure the system is clean
1397 local used=$(getquota -u $TSTUSR global curspace)
1398 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1400 pool_add $qpool || error "pool_add failed"
1401 pool_add_targets $qpool 0 1 ||
1402 error "pool_add_targets failed"
1404 pool_add $qpool2 || error "pool_add failed"
1405 pool_add_targets $qpool2 0 1 ||
1406 error "pool_add_targets failed"
1409 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1410 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1411 $LFS setquota -t -u --block-grace $grace1 \
1412 -o $qpool $DIR || error "set user grace time failed"
1413 $LFS setquota -t -u --block-grace $grace2 \
1414 -o $qpool2 $DIR || error "set user grace time failed"
1416 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1417 error "set user quota failed"
1418 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1419 error "set user quota failed"
1420 # qpool has minimum soft limit, but it's grace is grater than
1421 # grace period of qpool2. Thus write shouldn't fail when
1422 # hit qpool soft limit - only when reaches up qpool2 limit
1423 # after grace2 seconds.
1424 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 -o $qpool2 $DIR ||
1425 error "set user quota failed"
1427 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1430 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1431 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1432 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1433 -o $qpool $DIR || error "restore user grace time failed"
1434 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1435 -o $qpool2 $DIR || error "restore user grace time failed"
1437 run_test 3c "Quota pools: check block soft limit on different pools"
1446 trap cleanup_quota_test EXIT
1447 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1449 echo "Create files to exceed soft limit"
1450 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1451 quota_error a $TSTUSR "create failure, but expect success"
1452 local trigger_time=$(date +%s)
1454 sync_all_data || true
1456 local cur_time=$(date +%s)
1457 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1458 error "Passed grace time $grace, $trigger_time, $cur_time"
1460 echo "Create file before timer goes off"
1461 $RUNAS touch ${TESTFILE}_before ||
1462 quota_error a $TSTUSR "failed create before timer expired," \
1463 "but expect success. $trigger_time, $cur_time"
1464 sync_all_data || true
1466 wait_grace_time $qtype "file"
1471 $SHOW_QUOTA_INFO_USER
1472 $SHOW_QUOTA_INFO_GROUP
1473 $SHOW_QUOTA_INFO_PROJID
1475 echo "Create file after timer goes off"
1476 # There is a window that space is accounted in the quota usage but
1477 # hasn't been decreased from the pending write, if we acquire quota
1478 # in this window, we'll acquire more than we needed.
1479 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
1480 sync_all_data || true
1481 $RUNAS touch ${TESTFILE}_after_3 &&
1482 quota_error a $TSTUSR "create after timer expired," \
1484 sync_all_data || true
1489 $SHOW_QUOTA_INFO_USER
1490 $SHOW_QUOTA_INFO_GROUP
1491 $SHOW_QUOTA_INFO_PROJID
1493 echo "Unlink files to stop timer"
1494 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1495 wait_delete_completed
1498 $RUNAS touch ${TESTFILE}_xxx ||
1499 quota_error a $TSTUSR "touch after timer stop failure," \
1500 "but expect success"
1501 sync_all_data || true
1509 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1510 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1511 local TESTFILE=$DIR/$tdir/$tfile-0
1514 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1516 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1517 # make sure the system is clean
1518 local USED=$(getquota -u $TSTUSR global curinodes)
1519 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1521 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1522 $GRACE $DIR || error "set user grace time failed"
1523 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1524 error "set user quota failed"
1526 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1528 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1530 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1531 # make sure the system is clean
1532 USED=$(getquota -g $TSTUSR global curinodes)
1533 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1535 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1536 $GRACE $DIR || error "set group grace time failed"
1537 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1538 error "set group quota failed"
1539 TESTFILE=$DIR/$tdir/$tfile-1
1541 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1543 if is_project_quota_supported; then
1544 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1545 # make sure the system is clean
1546 USED=$(getquota -p $TSTPRJID global curinodes)
1547 [ $USED -ne 0 ] && error \
1548 "Used space($USED) for project $TSTPRJID isn't 0."
1550 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1551 $GRACE $DIR || error "set project grace time failed"
1552 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1553 error "set project quota failed"
1555 TESTFILE=$DIR/$tdir/$tfile-1
1556 # one less than limit, because of parent directory included.
1557 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1558 resetquota -p $TSTPRJID
1559 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1560 $MAX_IQ_TIME $DIR ||
1561 error "restore project grace time failed"
1565 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1566 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1567 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1568 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1570 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1573 local GR_STR1="1w3d"
1574 local GR_STR2="1000s"
1576 local GR_STR4="1w2d3h4m5s"
1578 local GR_STR6="18446744073709551615"
1581 wait_delete_completed
1583 # test of valid grace strings handling
1584 echo "Valid grace strings test"
1585 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1586 $GR_STR2 $DIR || error "set user grace time failed"
1587 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1588 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1589 $GR_STR4 $DIR || error "set group grace time quota failed"
1590 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1592 # test of invalid grace strings handling
1593 echo " Invalid grace strings test"
1594 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1595 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1596 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1600 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1601 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1602 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1603 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1605 run_test 4b "Grace time strings handling"
1607 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1609 local BLIMIT=10 # 10M
1610 local ILIMIT=10 # 10 inodes
1612 setup_quota_test || error "setup quota failed with $?"
1613 trap cleanup_quota_test EXIT
1615 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1616 set_ost_qtype $QTYPE || error "enable ost quota failed"
1618 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1619 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1620 error "set user quota failed"
1621 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1622 if is_project_quota_supported; then
1623 error "set group quota failed"
1624 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1625 -I $ILIMIT $DIR || error "set project quota failed"
1628 # make sure the system is clean
1629 local USED=$(getquota -u $TSTUSR global curinodes)
1630 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1631 USED=$(getquota -g $TSTUSR global curinodes)
1632 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1633 USED=$(getquota -u $TSTUSR global curspace)
1634 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1635 USED=$(getquota -g $TSTUSR global curspace)
1636 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1637 if is_project_quota_supported; then
1638 USED=$(getquota -p $TSTPRJID global curinodes)
1640 error "Used inode($USED) for project $TSTPRJID isn't 0."
1641 USED=$(getquota -p $TSTPRJID global curspace)
1643 error "Used block($USED) for project $TSTPRJID isn't 0."
1646 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1647 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1648 error "create failure, expect success"
1649 if is_project_quota_supported; then
1650 touch $DIR/$tdir/$tfile-0_1
1651 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1653 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1654 error "write failure, expect success"
1656 echo "Chown files to $TSTUSR.$TSTUSR ..."
1657 for i in $(seq 0 $ILIMIT); do
1658 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1659 quota_error a $TSTUSR "chown failure, expect success"
1663 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1664 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1667 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1669 # test dropping acquire request on master
1673 # Clear dmesg so watchdog is not triggered by previous
1675 do_facet ost1 dmesg -c > /dev/null
1677 setup_quota_test || error "setup quota failed with $?"
1678 trap cleanup_quota_test EXIT
1680 # make sure the system is clean
1681 local USED=$(getquota -u $TSTUSR global curspace)
1682 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1684 # make sure no granted quota on ost
1685 set_ost_qtype $QTYPE || error "enable ost quota failed"
1686 resetquota -u $TSTUSR
1688 # create file for $TSTUSR
1689 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1690 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1691 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1693 # create file for $TSTUSR2
1694 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1695 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1696 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1698 # cache per-ID lock for $TSTUSR on slave
1699 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1700 error "set quota failed"
1701 $RUNAS $DD of=$TESTFILE count=1 ||
1702 error "write $TESTFILE failure, expect success"
1703 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1704 error "write $TESTFILE2 failure, expect success"
1706 if at_is_enabled; then
1707 at_max_saved=$(at_max_get ost1)
1708 at_max_set $TIMEOUT ost1
1710 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1711 # DQACQ is sent, which makes at_max to take effect
1712 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1715 wait_delete_completed
1719 sync_all_data || true
1721 #define QUOTA_DQACQ 601
1722 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1723 lustre_fail mds 0x513 601
1725 do_facet ost1 $LCTL set_param \
1726 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1728 # write to un-enforced ID ($TSTUSR2) should succeed
1729 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1730 error "write failure, expect success"
1732 # write to enforced ID ($TSTUSR) in background, exceeding limit
1733 # to make sure DQACQ is sent
1734 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1737 # watchdog timer uses a factor of 2
1738 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1739 sleep $((TIMEOUT * 2 + 1))
1741 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1743 # write should be blocked and never finished
1744 if ! ps -p $DDPID > /dev/null 2>&1; then
1746 error "write finished incorrectly!"
1751 # no watchdog is triggered
1752 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1753 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1754 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1755 [ -z "$watchdog" ] || error "$watchdog"
1757 rm -f $TMP/lustre-log-${TESTNAME}.log
1759 # write should continue then fail with EDQUOT
1763 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1764 if [ $count -ge 240 ]; then
1765 quota_error u $TSTUSR "dd not finished in $count secs"
1767 count=$((count + 1))
1768 if [ $((count % 30)) -eq 0 ]; then
1769 c_size=$(stat -c %s $TESTFILE)
1770 echo "Waiting $count secs. $c_size"
1778 run_test 6 "Test dropping acquire request on master"
1780 # quota reintegration (global index)
1782 local TESTFILE=$DIR/$tdir/$tfile
1783 local LIMIT=20 # 20M
1785 [ "$SLOW" = "no" ] && LIMIT=5
1787 setup_quota_test || error "setup quota failed with $?"
1788 trap cleanup_quota_test EXIT
1790 # make sure the system is clean
1791 local USED=$(getquota -u $TSTUSR global curspace)
1792 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1794 # make sure no granted quota on ost1
1795 set_ost_qtype $QTYPE || error "enable ost quota failed"
1796 resetquota -u $TSTUSR
1797 set_ost_qtype "none" || error "disable ost quota failed"
1799 local OSTUUID=$(ostuuid_from_index 0)
1800 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1802 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1805 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1806 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1811 echo "Enable quota & set quota limit for $TSTUSR"
1812 set_ost_qtype $QTYPE || error "enable ost quota failed"
1813 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1814 error "set quota failed"
1816 echo "Start ost1..."
1817 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1820 wait_ost_reint $QTYPE || error "reintegration failed"
1822 # hardlimit should have been fetched by slave during global
1823 # reintegration, write will exceed quota
1824 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1825 quota_error u $TSTUSR "write success, but expect EDQUOT"
1828 wait_delete_completed
1829 sync_all_data || true
1835 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1836 error "clear quota failed"
1838 echo "Start ost1..."
1839 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1842 wait_ost_reint $QTYPE || error "reintegration failed"
1844 # hardlimit should be cleared on slave during reintegration
1845 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1846 quota_error u $TSTUSR "write error, but expect success"
1850 run_test 7a "Quota reintegration (global index)"
1852 # quota reintegration (slave index)
1855 local TESTFILE=$DIR/$tdir/$tfile
1857 setup_quota_test || error "setup quota failed with $?"
1858 trap cleanup_quota_test EXIT
1860 # make sure the system is clean
1861 local USED=$(getquota -u $TSTUSR global curspace)
1862 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1864 # make sure no granted quota on ost1
1865 set_ost_qtype $QTYPE || error "enable ost quota failed"
1866 resetquota -u $TSTUSR
1867 set_ost_qtype "none" || error "disable ost quota failed"
1869 local OSTUUID=$(ostuuid_from_index 0)
1870 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1872 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1875 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1876 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1878 # consume some space to make sure the granted space will not
1879 # be released during reconciliation
1880 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1881 error "consume space failure, expect success"
1883 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1884 lustre_fail mds 0xa02
1886 set_ost_qtype $QTYPE || error "enable ost quota failed"
1887 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1888 error "set quota failed"
1890 # ignore the write error
1891 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1893 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1897 echo "Restart ost to trigger reintegration..."
1899 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1902 wait_ost_reint $QTYPE || error "reintegration failed"
1904 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1905 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1910 run_test 7b "Quota reintegration (slave index)"
1912 # quota reintegration (restart mds during reintegration)
1914 local LIMIT=20 # 20M
1915 local TESTFILE=$DIR/$tdir/$tfile
1917 [ "$SLOW" = "no" ] && LIMIT=5
1919 setup_quota_test || error "setup quota failed with $?"
1920 trap cleanup_quota_test EXIT
1922 # make sure the system is clean
1923 local USED=$(getquota -u $TSTUSR global curspace)
1924 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1926 set_ost_qtype "none" || error "disable ost quota failed"
1927 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1928 error "set quota failed"
1930 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1931 lustre_fail ost 0xa03
1934 set_ost_qtype $QTYPE || error "enable ost quota failed"
1935 # trigger reintegration
1936 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1937 procf=${procf}quota_slave.force_reint
1938 do_facet ost1 $LCTL set_param $procf=1 ||
1939 error "force reintegration failed"
1947 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1950 # wait longer than usual to make sure the reintegration
1951 # is triggered by quota wb thread.
1952 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1954 # hardlimit should have been fetched by slave during global
1955 # reintegration, write will exceed quota
1956 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1957 quota_error u $TSTUSR "write success, but expect EDQUOT"
1961 run_test 7c "Quota reintegration (restart mds during reintegration)"
1963 # Quota reintegration (Transfer index in multiple bulks)
1965 local TESTFILE=$DIR/$tdir/$tfile
1966 local TESTFILE1="$DIR/$tdir/$tfile"-1
1969 setup_quota_test || error "setup quota failed with $?"
1970 trap cleanup_quota_test EXIT
1972 set_ost_qtype "none" || error "disable ost quota failed"
1973 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1974 error "set quota for $TSTUSR failed"
1975 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1976 error "set quota for $TSTUSR2 failed"
1978 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1979 lustre_fail mds 0x608 0
1981 # enable quota to tirgger reintegration
1982 set_ost_qtype "u" || error "enable ost quota failed"
1983 wait_ost_reint "u" || error "reintegration failed"
1987 # hardlimit should have been fetched by slave during global
1988 # reintegration, write will exceed quota
1989 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1990 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1992 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1993 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1997 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1999 # quota reintegration (inode limits)
2001 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2003 # LU-2435: skip this quota test if underlying zfs version has not
2004 # supported native dnode accounting
2005 [ "$mds1_FSTYPE" == zfs ] && {
2006 local F="feature@userobj_accounting"
2007 local pool=$(zpool_name mds1)
2008 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2010 [[ "$feature" != *" active "* ]] &&
2011 skip "requires zpool with active userobj_accounting"
2014 local ilimit=$((1024 * 2)) # 2k inodes
2015 local TESTFILE=$DIR/${tdir}-1/$tfile
2017 setup_quota_test || error "setup quota failed with $?"
2018 trap cleanup_quota_test EXIT
2020 # make sure the system is clean
2021 local USED=$(getquota -u $TSTUSR global curinodes)
2022 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2024 # make sure no granted quota on mdt1
2025 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2026 resetquota -u $TSTUSR
2027 set_mdt_qtype "none" || error "disable mdt quota failed"
2029 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2030 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2031 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2034 echo "Stop mds${MDSCOUNT}..."
2037 echo "Enable quota & set quota limit for $TSTUSR"
2038 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2039 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2040 error "set quota failed"
2042 echo "Start mds${MDSCOUNT}..."
2043 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2046 wait_mdt_reint $QTYPE || error "reintegration failed"
2048 echo "create remote dir"
2049 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2050 error "create remote dir failed"
2051 chmod 0777 $DIR/${tdir}-1
2053 # hardlimit should have been fetched by slave during global
2054 # reintegration, create will exceed quota
2055 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2056 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2058 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2059 wait_delete_completed
2060 sync_all_data || true
2062 echo "Stop mds${MDSCOUNT}..."
2065 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2066 error "clear quota failed"
2068 echo "Start mds${MDSCOUNT}..."
2069 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2072 wait_mdt_reint $QTYPE || error "reintegration failed"
2074 # hardlimit should be cleared on slave during reintegration
2075 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2076 quota_error u $TSTUSR "create failed, expect success"
2078 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2079 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2083 run_test 7e "Quota reintegration (inode limits)"
2085 # run dbench with quota enabled
2087 local BLK_LIMIT="100g" #100G
2088 local FILE_LIMIT=1000000
2090 setup_quota_test || error "setup quota failed with $?"
2091 trap cleanup_quota_test EXIT
2093 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2094 set_ost_qtype $QTYPE || error "enable ost quota failed"
2096 echo "Set enough high limit for user: $TSTUSR"
2097 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2098 error "set user quota failed"
2099 echo "Set enough high limit for group: $TSTUSR"
2100 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2101 error "set group quota failed"
2102 if is_project_quota_supported; then
2103 change_project -sp $TSTPRJID $DIR/$tdir
2104 echo "Set enough high limit for project: $TSTPRJID"
2105 $LFS setquota -p $TSTPRJID -b 0 \
2106 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2107 error "set project quota failed"
2111 [ "$SLOW" = "no" ] && duration=" -t 120"
2112 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2113 quota_error a $TSTUSR "dbench failed!"
2115 is_project_quota_supported && change_project -C $DIR/$tdir
2118 run_test 8 "Run dbench with quota enabled"
2120 # this check is just for test_9
2121 OST0_MIN=4900000 #4.67G
2123 check_whether_skip () {
2124 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2125 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2126 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2127 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2134 # run for fixing bug10707, it needs a big room. test for 64bit
2136 local filesize=$((1024 * 9 / 2)) # 4.5G
2138 check_whether_skip && return 0
2140 setup_quota_test || error "setup quota failed with $?"
2141 trap cleanup_quota_test EXIT
2143 set_ost_qtype "ug" || error "enable ost quota failed"
2145 local TESTFILE="$DIR/$tdir/$tfile-0"
2146 local BLK_LIMIT=100G #100G
2147 local FILE_LIMIT=1000000
2149 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2151 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2153 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2154 error "set user quota failed"
2156 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2157 "for group: $TSTUSR"
2158 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2159 error "set group quota failed"
2161 quota_show_check a u $TSTUSR
2162 quota_show_check a g $TSTUSR
2164 echo "Create test file"
2165 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2166 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2168 log "Write the big file of 4.5G ..."
2169 $RUNAS $DD of=$TESTFILE count=$filesize ||
2170 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2180 run_test 9 "Block limit larger than 4GB (b10707)"
2183 local TESTFILE=$DIR/$tdir/$tfile
2185 setup_quota_test || error "setup quota failed with $?"
2186 trap cleanup_quota_test EXIT
2188 # set limit to root user should fail
2189 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2190 error "set limit for root user successfully, expect failure"
2191 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2192 error "set limit for root group successfully, expect failure"
2193 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2194 error "set limit for project 0 successfully, expect failure"
2196 # root user can overrun quota
2197 set_ost_qtype "ug" || error "enable ost quota failed"
2199 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2200 error "set quota failed"
2201 quota_show_check b u $TSTUSR
2203 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2204 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2206 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2207 error "write failure, expect success"
2211 run_test 10 "Test quota for root user"
2214 local TESTFILE=$DIR/$tdir/$tfile
2215 setup_quota_test || error "setup quota failed with $?"
2216 trap cleanup_quota_test EXIT
2218 set_mdt_qtype "ug" || error "enable mdt quota failed"
2219 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2220 error "set quota failed"
2222 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2223 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2225 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2226 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2229 local USED=$(getquota -u $TSTUSR global curinodes)
2230 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2234 run_test 11 "Chown/chgrp ignores quota"
2237 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2239 local blimit=22 # 22M
2240 local blk_cnt=$((blimit - 5))
2241 local TESTFILE0="$DIR/$tdir/$tfile"-0
2242 local TESTFILE1="$DIR/$tdir/$tfile"-1
2244 setup_quota_test || error "setup quota failed with $?"
2245 trap cleanup_quota_test EXIT
2247 set_ost_qtype "u" || error "enable ost quota failed"
2248 quota_show_check b u $TSTUSR
2250 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2251 error "set quota failed"
2253 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2254 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2255 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2256 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2258 echo "Write to ost0..."
2259 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2260 quota_error a $TSTUSR "dd failed"
2262 echo "Write to ost1..."
2263 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2264 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2266 echo "Free space from ost0..."
2268 wait_delete_completed
2269 sync_all_data || true
2271 echo "Write to ost1 after space freed from ost0..."
2272 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2273 quota_error a $TSTUSR "rebalancing failed"
2277 run_test 12a "Block quota rebalancing"
2280 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2282 local ilimit=$((1024 * 2)) # 2k inodes
2283 local TESTFILE0=$DIR/$tdir/$tfile
2284 local TESTFILE1=$DIR/${tdir}-1/$tfile
2286 setup_quota_test || error "setup quota failed with $?"
2287 trap cleanup_quota_test EXIT
2289 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2290 chmod 0777 $DIR/${tdir}-1
2292 set_mdt_qtype "u" || error "enable mdt quota failed"
2293 quota_show_check f u $TSTUSR
2295 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2296 error "set quota failed"
2298 echo "Create $ilimit files on mdt0..."
2299 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2300 quota_error u $TSTUSR "create failed, but expect success"
2302 echo "Create files on mdt1..."
2303 $RUNAS createmany -m $TESTFILE1 1 &&
2304 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2306 echo "Free space from mdt0..."
2307 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2308 wait_delete_completed
2309 sync_all_data || true
2311 echo "Create files on mdt1 after space freed from mdt0..."
2312 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2313 quota_error a $TSTUSR "rebalancing failed"
2315 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2316 error "unlink mdt1 files failed"
2317 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2321 run_test 12b "Inode quota rebalancing"
2324 local TESTFILE=$DIR/$tdir/$tfile
2325 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2326 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2328 setup_quota_test || error "setup quota failed with $?"
2329 trap cleanup_quota_test EXIT
2331 set_ost_qtype "u" || error "enable ost quota failed"
2332 quota_show_check b u $TSTUSR
2334 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2335 error "set quota failed"
2336 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2337 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2339 # clear the locks in cache first
2340 do_facet ost1 $LCTL set_param -n $procf=clear
2341 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2342 [ $nlock -eq 0 ] || error "$nlock cached locks"
2344 # write to acquire the per-ID lock
2345 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2346 quota_error a $TSTUSR "dd failed"
2348 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2349 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2351 # clear quota doesn't trigger per-ID lock cancellation
2352 resetquota -u $TSTUSR
2353 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2354 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2356 # clear the per-ID lock
2357 do_facet ost1 $LCTL set_param -n $procf=clear
2358 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2359 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2361 # spare quota should be released
2362 local OSTUUID=$(ostuuid_from_index 0)
2363 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2364 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2365 [ $limit -le $space ] ||
2366 error "spare quota isn't released, limit:$limit, space:$space"
2370 run_test 13 "Cancel per-ID lock in the LRU list"
2373 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2375 wait_delete_completed
2376 sync_all_data || true
2379 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2380 error "set user quota failed"
2381 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2382 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2383 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2384 resetquota -u $TSTUSR
2387 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2388 error "set group quota failed"
2389 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2390 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2391 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2392 resetquota -g $TSTUSR
2394 run_test 15 "Set over 4T block quota"
2398 local BLKS=1 # 1M less than limit
2399 local TESTFILE=$DIR/$tdir/$tfile
2401 setup_quota_test || error "setup quota failed with $?"
2402 trap cleanup_quota_test EXIT
2404 # make sure the system is clean
2405 local USED=$(getquota -u $TSTUSR global curspace)
2406 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2408 set_ost_qtype "ug" || error "enable ost quota failed"
2409 # make sure no granted quota on ost
2410 resetquota -u $TSTUSR
2411 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2412 error "set quota failed"
2414 quota_show_check b u $TSTUSR
2416 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2417 lustre_fail mds 0xa04 $err_code
2419 # write in background
2420 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2424 # write should be blocked and never finished
2425 if ! ps -p $DDPID > /dev/null 2>&1; then
2427 quota_error u $TSTUSR "write finished incorrectly!"
2435 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2437 if [ $count -gt $timeout ]; then
2438 quota_error u $TSTUSR "dd is not finished!"
2443 sync; sync_all_data || true
2445 USED=$(getquota -u $TSTUSR global curspace)
2446 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2447 "Used space(${USED}K) is less than ${BLKS}M"
2452 # DQACQ return recoverable error
2454 echo "DQACQ return -ENOLCK"
2456 test_17sub 37 || error "Handle -ENOLCK failed"
2458 echo "DQACQ return -EAGAIN"
2460 test_17sub 11 || error "Handle -EAGAIN failed"
2462 echo "DQACQ return -ETIMEDOUT"
2463 #define ETIMEDOUT 110
2464 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2466 echo "DQACQ return -ENOTCONN"
2467 #define ENOTCONN 107
2468 test_17sub 107 || error "Handle -ENOTCONN failed"
2471 run_test 17 "DQACQ return recoverable error"
2475 local blimit="200m" # 200M
2476 local TESTFILE="$DIR/$tdir/$tfile"
2478 setup_quota_test || error "setup quota failed with $?"
2479 trap cleanup_quota_test EXIT
2481 set_ost_qtype "u" || error "enable ost quota failed"
2482 log "User quota (limit: $blimit)"
2483 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2484 error "set quota failed"
2485 quota_show_check b u $TSTUSR
2487 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2488 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2490 local timeout=$(sysctl -n lustre.timeout)
2492 if [ $io_type = "directio" ]; then
2493 log "Write 100M (directio) ..."
2494 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2496 log "Write 100M (buffered) ..."
2497 $RUNAS $DD of=$TESTFILE count=100 &
2501 replay_barrier $SINGLEMDS
2502 log "Fail mds for $((2 * timeout)) seconds"
2503 fail $SINGLEMDS $((2 * timeout))
2506 if at_is_enabled; then
2507 timeout=$(at_max_get mds)
2509 timeout=$(lctl get_param -n timeout)
2513 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2514 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2515 log "it took $count second"
2520 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2522 cancel_lru_locks mdc
2523 cancel_lru_locks osc
2526 local testfile_size=$(stat -c %s $TESTFILE)
2527 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2528 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2529 "got ${testfile_size}. Verifying file failed!"
2534 # test when mds does failover, the ost still could work well
2535 # this test shouldn't trigger watchdog b=14840
2537 # Clear dmesg so watchdog is not triggered by previous
2539 do_facet ost1 dmesg -c > /dev/null
2542 test_18_sub directio
2544 # check if watchdog is triggered
2545 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2546 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2547 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2548 [ -z "$watchdog" ] || error "$watchdog"
2549 rm -f $TMP/lustre-log-${TESTNAME}.log
2551 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2555 local TESTFILE=$DIR/$tdir/$tfile
2557 setup_quota_test || error "setup quota failed with $?"
2558 trap cleanup_quota_test EXIT
2560 set_ost_qtype $QTYPE || error "enable ost quota failed"
2562 # bind file to a single OST
2563 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2564 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2566 echo "Set user quota (limit: ${blimit}M)"
2567 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2568 error "set user quota failed"
2569 quota_show_check b u $TSTUSR
2570 echo "Update quota limits"
2571 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2572 error "set group quota failed"
2573 quota_show_check b u $TSTUSR
2575 # first wirte might be cached
2576 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2577 cancel_lru_locks osc
2579 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2580 quota_error u $TSTUSR "Write success, expect failure"
2585 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2587 test_20() { # b15754
2588 local LSTR=(2g 1t 4k 3m) # limits strings
2590 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2593 resetquota -u $TSTUSR
2595 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2596 $MOUNT || error "could not set quota limits"
2597 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2598 --inode-softlimit ${LSTR[2]} \
2599 --inode-hardlimit ${LSTR[3]} \
2600 $MOUNT || error "could not set quota limits"
2602 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2603 error "bsoftlimit was not set properly"
2604 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2605 error "bhardlimit was not set properly"
2606 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2607 error "isoftlimit was not set properly"
2608 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2609 error "ihardlimit was not set properly"
2611 resetquota -u $TSTUSR
2613 run_test 20 "Test if setquota specifiers work properly (b15754)"
2620 local time=$(($(date +%s) + seconds))
2621 while [ $(date +%s) -lt $time ]; do
2622 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2626 # run for fixing bug16053, setquota shouldn't fail when writing and
2627 # deleting are happening
2629 local TESTFILE="$DIR/$tdir/$tfile"
2630 local BLIMIT=10 # 10G
2631 local ILIMIT=1000000
2633 setup_quota_test || error "setup quota failed with $?"
2634 trap cleanup_quota_test EXIT
2636 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2638 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2639 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2640 error "set user quota failed"
2641 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2642 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2643 error "set group quota failed"
2644 if is_project_quota_supported; then
2645 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2646 "project: $TSTPRJID"
2647 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2648 $MOUNT || error "set project quota failed"
2651 # repeat writing on a 1M file
2652 test_21_sub ${TESTFILE}_1 1 30 &
2654 # repeat writing on a 128M file
2655 test_21_sub ${TESTFILE}_2 128 30 &
2658 local time=$(($(date +%s) + 30))
2660 while [ $(date +%s) -lt $time ]; do
2661 log "Set quota for $i times"
2662 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2663 -I $((ILIMIT + i)) $MOUNT ||
2664 error "Set user quota failed"
2665 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2666 -I $((ILIMIT + i)) $MOUNT ||
2667 error "Set group quota failed"
2668 if is_project_quota_supported; then
2669 $LFS setquota -p $TSTPRJID -b 0 -B \
2670 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2671 error "Set project quota failed"
2679 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2681 if [ $count -gt 60 ]; then
2682 quota_error a $TSTUSR "dd should be finished!"
2686 echo "(dd_pid=$DDPID1, time=$count)successful"
2690 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2692 if [ $count -gt 60 ]; then
2693 quota_error a $TSTUSR "dd should be finished!"
2697 echo "(dd_pid=$DDPID2, time=$count)successful"
2701 run_test 21 "Setquota while writing & deleting (b16053)"
2703 # enable/disable quota enforcement permanently
2705 echo "Set both mdt & ost quota type as ug"
2707 is_project_quota_supported && qtype=$QTYPE
2708 set_mdt_qtype $qtype || error "enable mdt quota failed"
2709 set_ost_qtype $qtype || error "enable ost quota failed"
2712 stopall || error "failed to stopall (1)"
2716 echo "Verify if quota is enabled"
2717 local qtype1=$(mdt_quota_type)
2718 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2719 qtype=$(ost_quota_type)
2720 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2722 echo "Set both mdt & ost quota type as none"
2723 set_mdt_qtype "none" || error "disable mdt quota failed"
2724 set_ost_qtype "none" || error "disable ost quota failed"
2727 stopall || error "failed to stopall (2)"
2732 echo "Verify if quota is disabled"
2733 qtype=$(mdt_quota_type)
2734 [ $qtype != "none" ] && error "mdt quota setting is lost"
2735 qtype=$(ost_quota_type)
2736 [ $qtype != "none" ] && error "ost quota setting is lost"
2740 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2743 local TESTFILE="$DIR/$tdir/$tfile"
2746 setup_quota_test || error "setup quota failed with $?"
2747 trap cleanup_quota_test EXIT
2749 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2752 log "User quota (limit: $LIMIT MB)"
2753 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2754 error "set quota failed"
2755 quota_show_check b u $TSTUSR
2757 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2758 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2760 log "Step1: trigger EDQUOT with O_DIRECT"
2761 log "Write half of file"
2762 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2763 quota_error u $TSTUSR "(1) Write failure, expect success." \
2765 log "Write out of block quota ..."
2766 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2767 oflag=direct conv=notrunc &&
2768 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2772 log "Step2: rewrite should succeed"
2773 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2774 quota_error u $TSTUSR "(3) Write failure, expect success." \
2780 local OST0_UUID=$(ostuuid_from_index 0)
2781 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2782 [ $OST0_QUOTA_USED -ne 0 ] &&
2783 ($SHOW_QUOTA_USER; \
2784 quota_error u $TSTUSR "quota isn't released")
2789 [ "$ost1_FSTYPE" == zfs ] &&
2790 skip "Overwrite in place is not guaranteed to be " \
2791 "space neutral on ZFS"
2793 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2794 check_whether_skip && return 0
2795 log "run for 4MB test file"
2798 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2799 check_whether_skip && return 0
2800 log "run for 40MB test file"
2803 run_test 23 "Quota should be honored with directIO (b16125)"
2807 local TESTFILE="$DIR/$tdir/$tfile"
2809 setup_quota_test || error "setup quota failed with $?"
2810 trap cleanup_quota_test EXIT
2812 set_ost_qtype $QTYPE || error "enable ost quota failed"
2814 # bind file to a single OST
2815 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2816 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2818 echo "Set user quota (limit: ${blimit}M)"
2819 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2820 error "set quota failed"
2822 # overrun quota by root user
2823 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2824 error "write failure, expect success"
2825 cancel_lru_locks osc
2826 sync_all_data || true
2828 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2832 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2834 test_27a() { # b19612
2835 $LFS quota $TSTUSR $DIR &&
2836 error "lfs succeeded with no type, but should have failed"
2837 $LFS setquota $TSTUSR $DIR &&
2838 error "lfs succeeded with no type, but should have failed"
2841 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2843 test_27b() { # b20200
2844 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2845 error "lfs setquota failed with uid argument"
2846 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2847 error "lfs stequota failed with gid argument"
2848 if is_project_quota_supported; then
2849 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2850 1000 $DIR || error \
2851 "lfs stequota failed with projid argument"
2853 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2854 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2855 if is_project_quota_supported; then
2856 $SHOW_QUOTA_PROJID ||
2857 error "lfs quota failed with projid argument"
2859 resetquota -u $TSTID
2860 resetquota -g $TSTID
2861 resetquota -p $TSTPRJID
2864 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2869 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2870 error "lfs setquota failed"
2872 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2873 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2874 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2875 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2877 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2878 error "lfs setquota for $TSTID failed"
2880 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2881 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2882 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2883 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2885 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2886 error "total allocated inode/block limit not printed"
2888 resetquota -u $TSTUSR
2890 run_test 27c "lfs quota should support human-readable output"
2897 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2898 error "set fraction block limit failed"
2899 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2900 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2901 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2902 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2904 resetquota -u $TSTUSR
2906 run_test 27d "lfs setquota should support fraction block limit"
2910 local TESTFILE="$DIR/$tdir/$tfile"
2913 setup_quota_test || error "setup quota failed with $?"
2914 trap cleanup_quota_test EXIT
2916 set_ost_qtype "u" || error "enable ost quota failed"
2918 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2919 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2921 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2922 $MAX_IQ_TIME $DIR || error "set grace time failed"
2923 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2924 error "set quota failed"
2925 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2926 cancel_lru_locks osc
2928 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2929 # over-quota flag has not yet settled since we do not trigger async
2930 # events based on grace time period expiration
2932 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2933 cancel_lru_locks osc
2934 # now over-quota flag should be settled and further writes should fail
2936 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2937 error "grace times were reset"
2940 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2941 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2943 run_test 30 "Hard limit updates should not reset grace times"
2945 # basic usage tracking for user & group
2947 local INODES=10 # 10 files
2948 local BLK_CNT=2 # of 2M each
2949 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2951 setup_quota_test || error "setup quota failed with $?"
2952 trap cleanup_quota_test EXIT
2954 # make sure the system is clean
2955 local USED=$(getquota -u $TSTID global curspace)
2957 error "Used space ($USED) for user $TSTID isn't 0."
2958 USED=$(getquota -g $TSTID global curspace)
2960 error "Used space ($USED) for group $TSTID isn't 0."
2961 if is_project_quota_supported; then
2962 USED=$(getquota -p $TSTPRJID global curspace)
2963 [ $USED -ne 0 ] && error \
2964 "Used space ($USED) for project $TSTPRJID isn't 0."
2967 echo "Write files..."
2968 for i in $(seq 0 $INODES); do
2969 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2970 error "write failed"
2971 is_project_quota_supported &&
2972 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2973 echo "Iteration $i/$INODES completed"
2975 cancel_lru_locks osc
2977 echo "Wait for setattr on objects finished..."
2978 wait_delete_completed
2980 sync; sync_all_data || true
2982 echo "Verify disk usage after write"
2983 USED=$(getquota -u $TSTID global curspace)
2984 [ $USED -lt $TOTAL_BLKS ] &&
2985 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2986 USED=$(getquota -g $TSTID global curspace)
2987 [ $USED -lt $TOTAL_BLKS ] &&
2988 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2989 if is_project_quota_supported; then
2990 USED=$(getquota -p $TSTPRJID global curspace)
2991 [ $USED -lt $TOTAL_BLKS ] && error \
2992 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2995 echo "Verify inode usage after write"
2996 USED=$(getquota -u $TSTID global curinodes)
2997 [ $USED -lt $INODES ] &&
2998 error "Used inode for user $TSTID is $USED, expected $INODES"
2999 USED=$(getquota -g $TSTID global curinodes)
3000 [ $USED -lt $INODES ] &&
3001 error "Used inode for group $TSTID is $USED, expected $INODES"
3002 if is_project_quota_supported; then
3003 USED=$(getquota -p $TSTPRJID global curinodes)
3004 [ $USED -lt $INODES ] && error \
3005 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3010 echo "Verify disk usage after delete"
3011 USED=$(getquota -u $TSTID global curspace)
3012 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3013 USED=$(getquota -u $TSTID global curinodes)
3014 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3015 USED=$(getquota -g $TSTID global curspace)
3016 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3017 USED=$(getquota -g $TSTID global curinodes)
3018 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3019 if is_project_quota_supported; then
3020 USED=$(getquota -p $TSTPRJID global curspace)
3022 error "Used space for project $TSTPRJID isn't 0. $USED"
3023 USED=$(getquota -p $TSTPRJID global curinodes)
3025 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3028 run_test 33 "Basic usage tracking for user & group & project"
3030 # usage transfer test for user & group & project
3032 local BLK_CNT=2 # 2MB
3033 local project_supported="no"
3035 is_project_quota_supported && project_supported="yes"
3036 setup_quota_test || error "setup quota failed with $?"
3037 trap cleanup_quota_test EXIT
3039 # make sure the system is clean
3040 local USED=$(getquota -u $TSTID global curspace)
3041 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3042 USED=$(getquota -g $TSTID global curspace)
3043 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3045 local USED=$(getquota -u $TSTID2 global curspace)
3046 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3047 if [ $project_supported == "yes" ]; then
3048 USED=$(getquota -p $TSTPRJID global curspace)
3049 [ $USED -ne 0 ] && error \
3050 "Used space ($USED) for Project $TSTPRJID isn't 0."
3053 echo "Write file..."
3054 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3055 error "write failed"
3056 cancel_lru_locks osc
3057 sync; sync_all_data || true
3059 echo "chown the file to user $TSTID"
3060 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3062 echo "Wait for setattr on objects finished..."
3063 wait_delete_completed
3065 BLK_CNT=$((BLK_CNT * 1024))
3067 echo "Verify disk usage for user $TSTID"
3068 USED=$(getquota -u $TSTID global curspace)
3069 [ $USED -lt $BLK_CNT ] &&
3070 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3071 USED=$(getquota -u $TSTID global curinodes)
3073 error "Used inodes for user $TSTID is $USED, expected 1"
3075 echo "chgrp the file to group $TSTID"
3076 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3078 echo "Wait for setattr on objects finished..."
3079 wait_delete_completed
3081 echo "Verify disk usage for group $TSTID"
3082 USED=$(getquota -g $TSTID global curspace)
3083 [ $USED -ge $BLK_CNT ] ||
3084 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3085 USED=$(getquota -g $TSTID global curinodes)
3087 error "Used inodes for group $TSTID is $USED, expected 1"
3089 # chown won't change the ost object group. LU-4345 */
3090 echo "chown the file to user $TSTID2"
3091 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3093 echo "Wait for setattr on objects finished..."
3094 wait_delete_completed
3096 echo "change_project project id to $TSTPRJID"
3097 [ $project_supported == "yes" ] &&
3098 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3099 echo "Wait for setattr on objects finished..."
3100 wait_delete_completed
3102 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3103 USED=$(getquota -u $TSTID2 global curspace)
3104 [ $USED -lt $BLK_CNT ] &&
3105 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3106 USED=$(getquota -u $TSTID global curspace)
3108 error "Used space for user $TSTID is $USED, expected 0"
3109 USED=$(getquota -g $TSTID global curspace)
3110 [ $USED -lt $BLK_CNT ] &&
3111 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3112 if [ $project_supported == "yes" ]; then
3113 USED=$(getquota -p $TSTPRJID global curspace)
3114 [ $USED -lt $BLK_CNT ] && error \
3115 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3120 run_test 34 "Usage transfer for user & group & project"
3122 # usage is still accessible across restart
3124 local BLK_CNT=2 # 2 MB
3126 setup_quota_test || error "setup quota failed with $?"
3127 trap cleanup_quota_test EXIT
3129 echo "Write file..."
3130 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3131 error "write failed"
3132 is_project_quota_supported &&
3133 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3134 cancel_lru_locks osc
3136 echo "Wait for setattr on objects finished..."
3137 wait_delete_completed
3139 sync; sync_all_data || true
3141 echo "Save disk usage before restart"
3142 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3143 [ $ORIG_USR_SPACE -eq 0 ] &&
3144 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3145 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3146 [ $ORIG_USR_INODES -eq 0 ] &&
3147 error "Used inodes for user $TSTID is 0, expected 1"
3148 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3149 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3150 [ $ORIG_GRP_SPACE -eq 0 ] &&
3151 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3152 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3153 [ $ORIG_GRP_INODES -eq 0 ] &&
3154 error "Used inodes for group $TSTID is 0, expected 1"
3155 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3157 if is_project_quota_supported; then
3158 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3159 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3160 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3161 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3162 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3163 "Used inodes for project $TSTPRJID is 0, expected 1"
3164 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3172 echo "Verify disk usage after restart"
3173 local USED=$(getquota -u $TSTID global curspace)
3174 [ $USED -eq $ORIG_USR_SPACE ] ||
3175 error "Used space for user $TSTID changed from " \
3176 "$ORIG_USR_SPACE to $USED"
3177 USED=$(getquota -u $TSTID global curinodes)
3178 [ $USED -eq $ORIG_USR_INODES ] ||
3179 error "Used inodes for user $TSTID changed from " \
3180 "$ORIG_USR_INODES to $USED"
3181 USED=$(getquota -g $TSTID global curspace)
3182 [ $USED -eq $ORIG_GRP_SPACE ] ||
3183 error "Used space for group $TSTID changed from " \
3184 "$ORIG_GRP_SPACE to $USED"
3185 USED=$(getquota -g $TSTID global curinodes)
3186 [ $USED -eq $ORIG_GRP_INODES ] ||
3187 error "Used inodes for group $TSTID changed from " \
3188 "$ORIG_GRP_INODES to $USED"
3189 if [ $project_supported == "yes" ]; then
3190 USED=$(getquota -p $TSTPRJID global curinodes)
3191 [ $USED -eq $ORIG_PRJ_INODES ] ||
3192 error "Used inodes for project $TSTPRJID " \
3193 "changed from $ORIG_PRJ_INODES to $USED"
3194 USED=$(getquota -p $TSTPRJID global curspace)
3195 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3196 error "Used space for project $TSTPRJID "\
3197 "changed from $ORIG_PRJ_SPACE to $USED"
3200 # check if the vfs_dq_init() is called before writing
3201 echo "Append to the same file..."
3202 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3203 error "write failed"
3204 cancel_lru_locks osc
3205 sync; sync_all_data || true
3207 echo "Verify space usage is increased"
3208 USED=$(getquota -u $TSTID global curspace)
3209 [ $USED -gt $ORIG_USR_SPACE ] ||
3210 error "Used space for user $TSTID isn't increased" \
3211 "orig:$ORIG_USR_SPACE, now:$USED"
3212 USED=$(getquota -g $TSTID global curspace)
3213 [ $USED -gt $ORIG_GRP_SPACE ] ||
3214 error "Used space for group $TSTID isn't increased" \
3215 "orig:$ORIG_GRP_SPACE, now:$USED"
3216 if [ $project_supported == "yes" ]; then
3217 USED=$(getquota -p $TSTPRJID global curspace)
3218 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3219 error "Used space for project $TSTPRJID isn't " \
3220 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3225 run_test 35 "Usage is still accessible across reboot"
3227 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3230 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3231 skip "Old server doesn't have LU-5006 fix."
3233 setup_quota_test || error "setup quota failed with $?"
3234 trap cleanup_quota_test EXIT
3236 # make sure the system is clean
3237 local USED=$(getquota -u $TSTID global curspace)
3239 error "Used space ($USED) for user $TSTID isn't 0."
3241 # create file with MDS_OPEN_DELAY_CREATE flag
3242 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3243 error "Create file failed"
3245 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3246 oflag=sync || error "Write file failed"
3248 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3250 # wait for setattr on objects finished..."
3251 wait_delete_completed
3253 USED=$(getquota -u $TSTID global curspace)
3254 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3258 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3262 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3263 skip "Old server doesn't have LU-8801 fix."
3265 [ "$UID" != 0 ] && skip_env "must run as root" && return
3267 setup_quota_test || error "setup quota failed with $?"
3268 trap cleanup_quota_test EXIT
3270 # make sure the system is clean
3271 local USED=$(getquota -u $TSTID global curspace)
3273 error "Used space ($USED) for user $TSTID isn't 0."
3274 USED=$(getquota -u $TSTID2 global curspace)
3276 error "Used space ($USED) for user $TSTID2 isn't 0."
3278 local TESTFILE="$DIR/$tdir/$tfile"
3279 local file_cnt=10000
3281 # Generate id entries in accounting file
3282 echo "Create $file_cnt files..."
3283 for i in `seq $file_cnt`; do
3285 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3286 error "failed to chown $TESTFILE-$i"
3288 cancel_lru_locks osc
3289 sync; sync_all_data || true
3291 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3292 procf=${procf}.quota_slave.acct_user
3295 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3296 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3297 echo "Found $acct_cnt id entries"
3299 [ $file_cnt -eq $acct_cnt ] || {
3300 do_facet mds1 $LCTL get_param $procf
3301 error "skipped id entries"
3306 run_test 38 "Quota accounting iterator doesn't skip id entries"
3309 local TESTFILE="$DIR/$tdir/project"
3310 ! is_project_quota_supported &&
3311 skip "Project quota is not supported"
3313 setup_quota_test || error "setup quota failed with $?"
3316 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3317 [ $projectid -ne 0 ] &&
3318 error "Project id should be 0 not $projectid"
3319 change_project -p 1024 $TESTFILE
3320 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3321 [ $projectid -ne 1024 ] &&
3322 error "Project id should be 1024 not $projectid"
3324 stopall || error "failed to stopall (1)"
3327 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3328 [ $projectid -ne 1024 ] &&
3329 error "Project id should be 1024 not $projectid"
3333 run_test 39 "Project ID interface works correctly"
3336 ! is_project_quota_supported &&
3337 skip "Project quota is not supported"
3338 local dir1="$DIR/$tdir/dir1"
3339 local dir2="$DIR/$tdir/dir2"
3341 setup_quota_test || error "setup quota failed with $?"
3343 mkdir -p $dir1 $dir2
3344 change_project -sp 1 $dir1 && touch $dir1/1
3345 change_project -sp 2 $dir2
3347 ln $dir1/1 $dir2/1_link &&
3348 error "Hard link across different project quota should fail"
3353 run_test 40a "Hard link across different project ID"
3356 ! is_project_quota_supported &&
3357 skip "Project quota is not supported"
3358 local dir1="$DIR/$tdir/dir1"
3359 local dir2="$DIR/$tdir/dir2"
3361 setup_quota_test || error "setup quota failed with $?"
3362 mkdir -p $dir1 $dir2
3363 change_project -sp 1 $dir1 && touch $dir1/1
3364 change_project -sp 2 $dir2
3366 mv $dir1/1 $dir2/2 || error "mv failed $?"
3367 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3368 if [ "$projid" != "2" ]; then
3369 error "project id expected 2 not $projid"
3374 run_test 40b "Mv across different project ID"
3377 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3378 ! is_project_quota_supported &&
3379 skip "Project quota is not supported"
3381 setup_quota_test || error "setup quota failed with $?"
3382 local dir="$DIR/$tdir/dir"
3384 mkdir -p $dir && change_project -sp 1 $dir
3385 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3386 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3387 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3388 touch $dir/remote_dir/file
3389 #verify inherit works file for remote dir.
3390 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3391 [ "$projid" != "1" ] &&
3392 error "file under remote dir expected 1 not $projid"
3394 #Agent inode should be ignored for project quota
3395 USED=$(getquota -p 1 global curinodes)
3396 [ "$USED" != "3" ] &&
3397 error "file count expected 3 got $USED"
3403 run_test 40c "Remote child Dir inherit project quota properly"
3406 ! is_project_quota_supported &&
3407 skip "Project quota is not supported"
3409 setup_quota_test || error "setup quota failed with $?"
3410 local dir1="$DIR/$tdir/dir1"
3411 local dir2="$DIR/$tdir/dir2"
3413 mkdir -p $dir1 && change_project -sp 1 $dir1
3414 mkdir -p $dir2 && change_project -sp 2 $dir2
3415 for num in $(seq 1 10); do
3416 touch $dir1/file_$num $dir2/file_$num
3417 ln -s $dir1/file_$num $dir1/file_$num"_link"
3418 ln -s $dir2/file_$num $dir2/file_$num"_link"
3421 count=$($LFS find --projid 1 $DIR | wc -l)
3422 [ "$count" != 21 ] && error "expected 21 but got $count"
3424 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3425 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3426 [ "$count" != 22 ] && error "expected 22 but got $count"
3431 run_test 50 "Test if lfs find --projid works"
3434 ! is_project_quota_supported &&
3435 skip "Project quota is not supported"
3436 setup_quota_test || error "setup quota failed with $?"
3437 local dir="$DIR/$tdir/dir"
3439 mkdir $dir && change_project -sp 1 $dir
3440 local used=$(getquota -p 1 global curinodes)
3441 [ $used != "1" ] && error "expected 1 got $used"
3446 used=$(getquota -p 1 global curinodes)
3447 [ $used != "4" ] && error "expected 4 got $used"
3449 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3451 cp $DIR/$tdir/6 $dir/6
3452 used=$(getquota -p 1 global curinodes)
3453 [ $used != "5" ] && error "expected 5 got $used"
3456 mv $DIR/$tdir/6 $dir/7
3457 used=$(getquota -p 1 global curinodes)
3458 [ $used != "6" ] && error "expected 6 got $used"
3463 run_test 51 "Test project accounting with mv/cp"
3466 ! is_project_quota_supported &&
3467 skip "Project quota is not supported"
3468 setup_quota_test || error "setup quota failed with $?"
3469 local dir="$DIR/$tdir/dir"
3470 mkdir $dir && change_project -sp 1 $dir
3472 touch $DIR/$tdir/file
3473 #Try renaming a file into the project. This should fail.
3474 for num in $(seq 1 2000); do
3475 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3476 error "rename should fail"
3481 run_test 52 "Rename across different project ID"
3484 ! is_project_quota_supported &&
3485 skip "Project quota is not supported"
3486 setup_quota_test || error "setup quota failed with $?"
3487 local dir="$DIR/$tdir/dir"
3488 mkdir $dir && change_project -s $dir
3489 lfs project -d $dir | grep P || error "inherit attribute should be set"
3491 change_project -C $dir
3492 lfs project -d $dir | grep P &&
3493 error "inherit attribute should be cleared"
3498 run_test 53 "Project inherit attribute could be cleared"
3501 ! is_project_quota_supported &&
3502 skip "Project quota is not supported"
3503 setup_quota_test || error "setup quota failed with $?"
3504 trap cleanup_quota_test EXIT
3505 local testfile="$DIR/$tdir/$tfile-0"
3507 #set project ID/inherit attribute
3508 change_project -sp $TSTPRJID $DIR/$tdir
3509 $RUNAS createmany -m ${testfile} 100 ||
3510 error "create many files failed"
3512 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3513 # one more count for directory itself */
3517 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3518 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3520 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3521 [ $proj_count1 -eq $proj_count ] ||
3522 error "c2: expected $proj_count got $proj_count1"
3524 #clear project but with kept projid
3525 change_project -rCk $DIR/$tdir
3526 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3527 [ $proj_count1 -eq 1 ] ||
3528 error "c3: expected 1 got $proj_count1"
3530 #verify projid untouched.
3531 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3533 [ $proj_count1 -eq $proj_count ] ||
3534 error "c4: expected $proj_count got $proj_count1"
3537 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3538 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3539 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3541 #this time clear all
3542 change_project -rC $DIR/$tdir
3543 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3544 [ $proj_count1 -eq 0 ] ||
3545 error "c6: expected 0 got $proj_count1"
3547 unlinkmany ${testfile} 100 ||
3548 error "unlink many files failed"
3552 run_test 54 "basic lfs project interface test"
3555 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3556 skip "Not supported before 2.10.58."
3557 setup_quota_test || error "setup quota failed with $?"
3559 set_ost_qtype $QTYPE || error "enable ost quota failed"
3562 #add second group to TSTUSR
3563 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3566 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3567 error "failed to dd"
3569 cancel_lru_locks osc
3570 sync; sync_all_data || true
3572 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3573 error "failed to setquota on group $TSTUSR2"
3575 $LFS quota -v -g $TSTUSR2 $DIR
3577 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3578 error "chgrp should failed with -EDQUOT"
3580 USED=$(getquota -g $TSTUSR2 global curspace)
3583 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3584 error "failed to setquota on group $TSTUSR2"
3586 $LFS quota -v -g $TSTUSR2 $DIR
3588 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3589 error "chgrp should succeed"
3591 $LFS quota -v -g $TSTUSR2 $DIR
3595 run_test 55 "Chgrp should be affected by group quota"
3598 setup_quota_test || error "setup quota failed with $?"
3600 set_ost_qtype $QTYPE || error "enable ost quota failed"
3603 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3604 erro "failed to set grace time for usr quota"
3605 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3606 awk '{print $4 $8}')
3607 if [ "x$grace_time" != "x10s;10s" ]; then
3608 $LFS quota -t -u $DIR
3609 error "expected grace time: 10s;10s, got:$grace_time"
3614 run_test 56 "lfs quota -t should work well"
3617 setup_quota_test || error "setup quota failed with $?"
3619 local dir="$DIR/$tdir/dir"
3622 #try to change pipe file should not hang and return failure
3623 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3624 awk -F ':' '{ print \\\$2 }'" \
3625 " unable to get xattr for fifo '$dir/pipe'" || return 1
3626 #command can process further if it hit some errors
3627 touch $dir/aaa $dir/bbb
3628 mkdir $dir/subdir -p
3629 touch $dir/subdir/aaa $dir/subdir/bbb
3630 #create one invalid link file
3631 ln -s $dir/not_exist_file $dir/ccc
3632 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3633 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3637 run_test 57 "lfs project could tolerate errors"
3640 [ "$mds1_FSTYPE" != ldiskfs ] &&
3641 skip "ldiskfs only test"
3642 disable_project_quota
3643 setup_quota_test || error "setup quota failed with $?"
3646 local testfile="$DIR/$tdir/$tfile-0"
3647 #make sure it did not crash kernel
3648 touch $testfile && lfs project -sp 1 $testfile
3650 enable_project_quota
3653 run_test 59 "lfs project dosen't crash kernel with project disabled"
3656 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3657 skip "Needs MDS version 2.11.53 or later."
3658 setup_quota_test || error "setup quota failed with $?"
3659 trap cleanup_quota_test EXIT
3661 local testfile=$DIR/$tdir/$tfile
3664 set_mdt_qtype "ug" || error "enable mdt quota failed"
3666 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3667 error "set quota failed"
3668 quota_show_check a g $TSTUSR
3670 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3671 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3672 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3673 error "create many files failed"
3675 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3677 # root user can overrun quota
3678 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3679 error "root user should succeed"
3683 run_test 60 "Test quota for root with setgid"
3685 # test default quota
3686 test_default_quota() {
3687 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3688 skip "Not supported before 2.11.51."
3693 local qprjid=$TSTPRJID
3697 local LIMIT=20480 #20M disk space
3698 local TESTFILE="$DIR/$tdir/$tfile-0"
3700 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3701 echo "Project quota is not supported" && return 0
3703 [ $qtype == "-u" ] && qdtype="-U"
3704 [ $qtype == "-g" ] && qdtype="-G"
3705 [ $qtype == "-p" ] && {
3710 [ $qpool == "meta" ] && {
3711 LIMIT=10240 #10K inodes
3716 setup_quota_test || error "setup quota failed with $?"
3717 trap cleanup_quota_test EXIT
3721 # enable mdt/ost quota
3722 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3723 set_ost_qtype $QTYPE || error "enable ost quota failed"
3725 log "set to use default quota"
3726 $LFS setquota $qtype $qid -d $DIR ||
3727 error "set $qid to use default quota failed"
3729 log "set default quota"
3730 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3731 error "set $qid default quota failed"
3733 log "get default quota"
3734 $LFS quota $qdtype $DIR || error "get default quota failed"
3736 if [ $qpool == "data" ]; then
3737 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3739 [ $SLIMIT -eq $LIMIT ] ||
3740 error "the returned default quota is wrong"
3742 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3744 [ $SLIMIT -eq $LIMIT ] ||
3745 error "the returned default quota is wrong"
3748 # make sure the system is clean
3749 local USED=$(getquota $qtype $qid global curspace)
3750 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3752 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3753 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3755 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3757 log "Test not out of quota"
3758 if [ $qpool == "data" ]; then
3759 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3760 quota_error $qtype $qid "write failed, expect succeed"
3762 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3763 quota_error $qtype $qid "create failed, expect succeed"
3765 unlinkmany $TESTFILE $((LIMIT/2))
3768 log "Test out of quota"
3769 # flush cache, ensure noquota flag is set on client
3770 cancel_lru_locks osc
3771 cancel_lru_locks mdc
3772 sync; sync_all_data || true
3773 if [ $qpool == "data" ]; then
3774 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3775 quota_error $qtype $qid "write succeed, expect EDQUOT"
3777 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3778 quota_error $qtype $qid "create succeed, expect EDQUOT"
3780 unlinkmany $TESTFILE $((LIMIT*2))
3783 log "Increase default quota"
3784 # increase default quota
3785 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3786 error "set default quota failed"
3788 cancel_lru_locks osc
3789 cancel_lru_locks mdc
3790 sync; sync_all_data || true
3791 if [ $qpool == "data" ]; then
3792 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3793 quota_error $qtype $qid "write failed, expect succeed"
3795 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3796 quota_error $qtype $qid "create failed, expect succeed"
3798 unlinkmany $TESTFILE $((LIMIT*2))
3801 log "Set quota to override default quota"
3802 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3803 error "set $qid quota failed"
3805 cancel_lru_locks osc
3806 cancel_lru_locks mdc
3807 sync; sync_all_data || true
3808 if [ $qpool == "data" ]; then
3809 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3810 quota_error $qtype $qid "write succeed, expect EQUOT"
3812 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3813 quota_error $qtype $qid "create succeed, expect EQUOT"
3815 unlinkmany $TESTFILE $((LIMIT*2))
3818 log "Set to use default quota again"
3819 $LFS setquota $qtype $qid -d $DIR ||
3820 error "set $qid to use default quota failed"
3822 cancel_lru_locks osc
3823 cancel_lru_locks mdc
3824 sync; sync_all_data || true
3825 if [ $qpool == "data" ]; then
3826 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3827 quota_error $qtype $qid "write failed, expect succeed"
3829 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3830 quota_error $qtype $qid "create failed, expect succeed"
3832 unlinkmany $TESTFILE $((LIMIT*2))
3837 wait_delete_completed || error "wait_delete_completed failed"
3838 sync_all_data || true
3839 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3840 error "reset default quota failed"
3841 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3842 error "reset quota failed"
3848 test_default_quota "-u" "data"
3849 test_default_quota "-u" "meta"
3850 test_default_quota "-g" "data"
3851 test_default_quota "-g" "meta"
3852 test_default_quota "-p" "data"
3853 test_default_quota "-p" "meta"
3855 run_test 61 "default quota tests"
3858 ! is_project_quota_supported &&
3859 skip "Project quota is not supported"
3860 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3861 skip "chattr did not support project quota"
3862 setup_quota_test || error "setup quota failed with $?"
3863 local testdir=$DIR/$tdir/
3865 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3866 change_project -s $testdir
3867 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3868 error "inherit attribute should be set"
3869 # chattr used FS_IOC_SETFLAGS ioctl
3870 $RUNAS chattr -P $testdir &&
3871 error "regular user clear inherit should fail"
3872 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3873 error "inherit attribute should still be set"
3874 chattr -P $testdir || error "root failed to clear inherit"
3875 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3876 error "inherit attribute should be cleared"
3879 run_test 62 "Project inherit should be only changed by root"
3882 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3883 skip "Not supported before 2.11.55"
3887 local dd_failed=false
3888 local tdir_dom=${tdir}_dom
3889 local LIMIT=20480 #20M
3891 [ $qtype == "p" ] && ! is_project_quota_supported &&
3892 echo "Project quota is not supported" && return 0
3894 [ $qtype == "p" ] && qid=$TSTPRJID
3896 setup_quota_test || error "setup quota failed with $?"
3897 trap cleanup_quota_test EXIT
3901 # enable mdt/ost quota
3902 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3903 set_ost_qtype $QTYPE || error "enable ost quota failed"
3905 # make sure the system is clean
3906 local USED=$(getquota -$qtype $qid global curspace)
3907 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3909 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3911 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3912 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3913 error "setstripe $tdir_dom failed"
3914 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3916 [ $qtype == "p" ] && {
3917 change_project -sp $TSTPRJID $DIR/$tdir
3918 change_project -sp $TSTPRJID $DIR/$tdir_dom
3921 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3922 error "set $qid quota failed"
3924 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3925 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3929 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3931 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3932 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3936 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3938 rm -f $DIR/$tdir_dom/*
3940 # flush cache, ensure noquota flag is set on client
3941 cancel_lru_locks osc
3942 cancel_lru_locks mdc
3943 sync; sync_all_data || true
3947 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3948 quota_error $qtype $qid "write failed, expect succeed"
3950 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3951 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3955 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3958 rm -f $DIR/$tdir_dom/*
3960 # flush cache, ensure noquota flag is set on client
3961 cancel_lru_locks osc
3962 cancel_lru_locks mdc
3963 sync; sync_all_data || true
3967 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3968 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3972 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3974 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3975 quota_error $qtype $qid "write succeed, expect EDQUOT"
3978 rm -fr $DIR/$tdir_dom
3980 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3981 error "reset usr quota failed"
3991 run_test 63 "quota on DoM tests"
3994 ! is_project_quota_supported &&
3995 skip "Project quota is not supported"
3996 setup_quota_test || error "setup quota failed with $?"
3997 local dir1="$DIR/$tdir/"
4000 ln -s $dir1/file $dir1/file_link
4002 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4003 error "set symlink file's project should fail"
4005 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4006 error "get symlink file's project should fail"
4010 run_test 64 "lfs project on symlink files should fail"
4014 local TESTFILE="$DIR/$tdir/$tfile-0"
4016 setup_quota_test || error "setup quota failed with $?"
4017 set_ost_qtype $QTYPE || error "enable ost quota failed"
4021 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4022 error "failed to write"
4023 # flush cache, ensure noquota flag is set on client
4024 cancel_lru_locks osc
4025 sync; sync_all_data || true
4027 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4028 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4029 local quota_all=$($RUNAS $LFS quota $DIR)
4031 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4032 error "usr quota not match"
4033 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4034 error "grp quota not match"
4040 run_test 65 "Check lfs quota result"
4043 ! is_project_quota_supported &&
4044 skip "Project quota is not supported"
4045 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4046 skip "Not supported before 2.12.4"
4047 setup_quota_test || error "setup quota failed with $?"
4048 stack_trap cleanup_quota_test EXIT
4049 local old=$(do_facet mds1 $LCTL get_param -n \
4050 mdt.*.enable_chprojid_gid | head -1)
4051 local testdir=$DIR/$tdir/foo
4053 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4054 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4057 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4058 chown -R $TSTID:$TSTID $testdir
4059 change_project -sp $TSTPRJID $testdir
4060 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4062 $RUNAS lfs project -p 0 $testdir/foo &&
4063 error "nonroot user should fail to set projid"
4065 $RUNAS lfs project -C $testdir/foo &&
4066 error "nonroot user should fail to clear projid"
4068 change_project -C $testdir/foo || error "failed to clear project"
4070 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4071 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4072 "failed to set projid with normal user when enable_chprojid_gid=-1"
4074 $RUNAS lfs project -rC $testdir/ || error \
4075 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4077 touch $testdir/bar || error "failed touch $testdir/bar"
4078 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4079 "normal user should not be able to set projid on root owned file"
4081 change_project -p $TSTPRJID $testdir/bar || error \
4082 "root should be able to change its own file's projid"
4086 run_test 66 "nonroot user can not change project state in default"
4093 local short_qtype=${qtype:0:1}
4096 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4098 quota_usr) _runas=$RUNAS;;
4099 quota_2usr) _runas=$RUNAS2;;
4100 *) error "unknown quota parameter $4";;
4105 $_runas $DD of=$file count=$size ||
4106 quota_error $short_qtype $TSTUSR \
4107 "$qtype write failure, but expect success"
4109 cancel_lru_locks osc
4111 sync; sync_all_data || true
4120 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4122 do_facet mds1 $LCTL get_param $param |
4123 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4127 local limit=20 # 20M
4128 local testfile="$DIR/$tdir/$tfile-0"
4129 local testfile2="$DIR/$tdir/$tfile-1"
4130 local testfile3="$DIR/$tdir/$tfile-2"
4131 local qpool="qpool1"
4137 [ "$ost1_FSTYPE" == zfs ] &&
4138 skip "ZFS grants some block space together with inode"
4140 setup_quota_test || error "setup quota failed with $?"
4141 trap cleanup_quota_test EXIT
4144 set_ost_qtype $QTYPE || error "enable ost quota failed"
4147 log "User quota (block hardlimit:$limit MB)"
4148 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4149 error "set user quota failed"
4151 # make sure the system is clean
4152 used=$(getquota -u $TSTUSR global curspace)
4153 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4155 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4156 echo "granted 0x0 before write $granted"
4158 # trigger reintegration
4159 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4160 procf=${procf}quota_slave.force_reint
4161 do_facet ost1 $LCTL set_param $procf=1 ||
4162 error "force reintegration failed"
4163 wait_ost_reint "u" || error "reintegration failed"
4164 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4165 [ $granted -ne 0 ] &&
4166 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4168 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4169 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4171 # write 10 MB to testfile
4172 test_67_write "$testfile" "user" 10 "quota_usr"
4174 # create qpool and add OST1
4175 pool_add $qpool || error "pool_add failed"
4176 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4177 # as quota_usr hasn't limits, lqe may absent. But it should be
4178 # created after the 1st direct qmt_get.
4179 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4181 # check granted - should be 0, as testfile is located only on OST0
4182 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4183 echo "global granted $granted"
4184 granted=$(getgranted $qpool "dt" $TSTID "usr")
4185 echo "$qpool granted $granted"
4186 [ $granted -ne 0 ] &&
4187 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4189 # add OST0 to qpool and check granted space
4190 pool_add_targets $qpool 0 1 ||
4191 error "pool_add_targets failed"
4192 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4193 echo "Granted $granted_mb MB"
4194 #should be 10M + qunit for each OST
4195 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4196 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4198 $LFS setstripe $testfile2 -c 1 -i 1 ||
4199 error "setstripe $testfile2 failed"
4200 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4201 # Write from another user and check that qpool1
4202 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4203 test_67_write "$testfile2" "user" 10 "quota_2usr"
4204 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4205 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4206 [ $granted -ne 0 ] &&
4207 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4209 # Granted space for quota_2usr in qpool1 should appear only
4210 # when global lqe for this user becomes enforced.
4211 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4212 error "set user quota failed"
4213 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4214 echo "granted_mb $granted_mb"
4215 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4216 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4218 $LFS setstripe $testfile3 -c 1 -i 0 ||
4219 error "setstripe $testfile3 failed"
4220 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4221 test_67_write "$testfile3" "user" 10 "quota_2usr"
4222 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4223 echo "$testfile3 granted_mb $granted_mb"
4224 [ $granted_mb -eq $limit ] ||
4225 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4227 # remove OST1 from the qpool1 and check granted space
4228 # should be 0 for TSTUSR and 10M for TSTUSR2
4229 pool_remove_target $qpool 0
4230 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4231 [ $granted_mb -eq 0 ] ||
4232 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4233 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4234 [ $granted_mb -eq 10 ] ||
4235 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4238 wait_delete_completed || error "wait_delete_completed failed"
4239 sync_all_data || true
4240 used=$(getquota -u $TSTUSR global curspace)
4241 [ $used -ne 0 ] && quota_error u $TSTUSR \
4242 "user quota isn't released after deletion"
4243 resetquota -u $TSTUSR
4247 run_test 67 "quota pools recalculation"
4254 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4255 awk '/usr/ {getline; print $2}'
4260 local qpool="qpool1"
4263 setup_quota_test || error "setup quota failed with $?"
4264 stack_trap cleanup_quota_test EXIT
4267 set_ost_qtype $QTYPE || error "enable ost quota failed"
4269 # check slave number for glbal pool
4270 local nr=$(get_slave_nr "0x0" "usr")
4271 echo "nr result $nr"
4272 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4273 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4275 # create qpool and add OST1
4276 pool_add $qpool || error "pool_add failed"
4277 nr=$(get_slave_nr $qpool "usr")
4278 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4281 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4282 nr=$(get_slave_nr $qpool "usr")
4283 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4286 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4287 nr=$(get_slave_nr $qpool "usr")
4288 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4291 pool_remove_target $qpool 0
4292 nr=$(get_slave_nr $qpool "usr")
4293 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4296 pool_remove_target $qpool 1
4297 nr=$(get_slave_nr $qpool "usr")
4298 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4300 # Check again that all is fine with global pool
4301 nr=$(get_slave_nr "0x0" "usr")
4302 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4303 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4307 run_test 68 "slave number in quota pool changed after each add/remove OST"
4311 local global_limit=200 # 200M
4312 local limit=10 # 10M
4313 local testfile="$DIR/$tdir/$tfile-0"
4314 local dom0="$DIR/$tdir/dom0"
4315 local qpool="qpool1"
4318 setup_quota_test || error "setup quota failed with $?"
4319 stack_trap cleanup_quota_test EXIT
4322 set_ost_qtype $QTYPE || error "enable ost quota failed"
4323 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4325 # Save DOM only at MDT0
4326 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4327 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4329 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4331 # create qpool and add OST0
4332 pool_add $qpool || error "pool_add failed"
4333 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4335 log "User quota (block hardlimit:$global_limit MB)"
4336 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4337 error "set user quota failed"
4339 log "User quota (block hardlimit:$limit MB)"
4340 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
4341 error "set user quota failed"
4343 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4344 quota_error u $TSTUSR "write failed"
4346 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4347 oflag=sync || quota_error u $TSTUSR "write failed"
4349 $RUNAS $DD of=$testfile count=$limit || true
4351 # flush cache, ensure noquota flag is set on client
4352 cancel_lru_locks osc
4353 sync; sync_all_data || true
4355 # MDT0 shouldn't get EDQUOT with glimpse.
4356 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4357 quota_error u $TSTUSR \
4358 "user write success, but expect EDQUOT"
4360 # Now all members of qpool1 should get EDQUOT. Expect success
4361 # when write to DOM on MDT0, as it belongs to global pool.
4362 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4363 oflag=sync || quota_error u $TSTUSR "write failed"
4365 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4366 oflag=sync || quota_error u $TSTUSR "write failed"
4370 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4374 local qpool="qpool1"
4379 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4380 skip "Needs a client >= $VERSION_WITH_QP"
4382 setup_quota_test || error "setup quota failed with $?"
4383 stack_trap cleanup_quota_test EXIT
4385 # MDS returns EFAULT for unsupported quotactl command
4386 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4388 # create qpool and add OST0
4389 pool_add $qpool || error "pool_add failed"
4390 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4392 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR
4394 [ $rc -eq $err ] || error "setquota res $rc != $err"
4396 # If MDS supports QP, check that limit was set properly.
4397 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4398 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4399 echo "hard limit $bhard limit $limit"
4400 [ $bhard -ne $((limit*1024)) ] &&
4401 error "bhard:$bhard for $qpool!=$((limit*1024))"
4404 $LFS quota -u $TSTUSR --pool $qpool $DIR
4406 [ $rc -eq $err ] || error "quota res $rc != $err"
4410 run_test 70 "check lfs setquota/quota with a pool option"
4414 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4415 if $PQ_CLEANUP; then
4416 disable_project_quota
4419 reset_quota_settings
4424 check_and_cleanup_lustre
4425 export QUOTA_AUTO=$QUOTA_AUTO_OLD