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 LIMIT=$((1024 * 1024)) # 1M inodes
1005 local TESTFILE="$DIR/$tdir/$tfile-0"
1007 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
1009 local FREE_INODES=$(mdt_free_inodes 0)
1010 echo "$FREE_INODES free inodes on master MDT"
1011 [ $FREE_INODES -lt $LIMIT ] &&
1012 skip "not enough free inodes $FREE_INODES required $LIMIT"
1014 setup_quota_test || error "setup quota failed with $?"
1015 trap cleanup_quota_test EXIT
1018 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1021 log "User quota (inode hardlimit:$LIMIT files)"
1022 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1023 error "set user quota failed"
1025 # make sure the system is clean
1026 local USED=$(getquota -u $TSTUSR global curinodes)
1027 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1029 log "Create $LIMIT files ..."
1030 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1031 quota_error u $TSTUSR "user create failure, but expect success"
1032 log "Create out of file quota ..."
1033 $RUNAS touch ${TESTFILE}_xxx &&
1034 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1037 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1038 rm -f ${TESTFILE}_xxx
1039 wait_delete_completed
1041 USED=$(getquota -u $TSTUSR global curinodes)
1042 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1043 "user quota isn't released after deletion"
1044 resetquota -u $TSTUSR
1047 log "--------------------------------------"
1048 log "Group quota (inode hardlimit:$LIMIT files)"
1049 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1050 error "set group quota failed"
1052 TESTFILE=$DIR/$tdir/$tfile-1
1053 # make sure the system is clean
1054 USED=$(getquota -g $TSTUSR global curinodes)
1055 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1057 log "Create $LIMIT files ..."
1058 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1059 quota_error g $TSTUSR "group create failure, but expect success"
1060 log "Create out of file quota ..."
1061 $RUNAS touch ${TESTFILE}_xxx &&
1062 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1065 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1066 rm -f ${TESTFILE}_xxx
1067 wait_delete_completed
1069 USED=$(getquota -g $TSTUSR global curinodes)
1070 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1071 "user quota isn't released after deletion"
1073 resetquota -g $TSTUSR
1074 ! is_project_quota_supported && cleanup_quota_test &&
1075 echo "Skip project quota is not supported" && return 0
1078 log "--------------------------------------"
1079 log "Project quota (inode hardlimit:$LIMIT files)"
1080 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1081 error "set project quota failed"
1083 TESTFILE=$DIR/$tdir/$tfile-1
1084 # make sure the system is clean
1085 USED=$(getquota -p $TSTPRJID global curinodes)
1087 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1089 change_project -sp $TSTPRJID $DIR/$tdir
1090 log "Create $LIMIT files ..."
1091 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1092 $TSTPRJID "project create fail, but expect success"
1093 log "Create out of file quota ..."
1094 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1095 "project create success, but expect EDQUOT"
1096 change_project -C $DIR/$tdir
1099 USED=$(getquota -p $TSTPRJID global curinodes)
1100 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1101 "project quota isn't released after deletion"
1104 run_test 2 "File hard limit (normal use and out of quota)"
1115 stack_trap cleanup_quota_test EXIT
1117 $LFS setstripe $testfile -c 1 -i 0
1118 chown $TSTUSR.$TSTUSR $testfile
1119 [ "$qtype" == "p" ] && is_project_quota_supported &&
1120 change_project -p $TSTPRJID $testfile
1122 echo "Write up to soft limit"
1123 $RUNAS $DD of=$testfile count=$limit ||
1124 quota_error a $TSTUSR "write failure, but expect success"
1125 OFFSET=$((limit * 1024))
1126 cancel_lru_locks osc
1128 echo "Write to exceed soft limit"
1129 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1130 quota_error a $TSTUSR "write failure, but expect success"
1131 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1132 cancel_lru_locks osc
1134 echo "mmap write when over soft limit"
1135 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1136 quota_error a $TSTUSR "mmap write failure, but expect success"
1137 cancel_lru_locks osc
1142 $SHOW_QUOTA_INFO_USER
1143 $SHOW_QUOTA_INFO_GROUP
1144 $SHOW_QUOTA_INFO_PROJID
1146 echo "Write before timer goes off"
1147 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1148 quota_error a $TSTUSR "write failure, but expect success"
1149 OFFSET=$((OFFSET + 1024))
1150 cancel_lru_locks osc
1152 wait_grace_time $qtype "block" $pool
1157 $SHOW_QUOTA_INFO_USER
1158 $SHOW_QUOTA_INFO_GROUP
1159 $SHOW_QUOTA_INFO_PROJID
1161 log "Write after timer goes off"
1162 # maybe cache write, ignore.
1163 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1164 OFFSET=$((OFFSET + 1024))
1165 cancel_lru_locks osc
1166 log "Write after cancel lru locks"
1167 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1168 quota_error a $TSTUSR "write success, but expect EDQUOT"
1173 $SHOW_QUOTA_INFO_USER
1174 $SHOW_QUOTA_INFO_GROUP
1175 $SHOW_QUOTA_INFO_PROJID
1177 echo "Unlink file to stop timer"
1179 wait_delete_completed
1180 sync_all_data || true
1185 $SHOW_QUOTA_INFO_USER
1186 $SHOW_QUOTA_INFO_GROUP
1187 $SHOW_QUOTA_INFO_PROJID
1189 $LFS setstripe $testfile -c 1 -i 0
1190 chown $TSTUSR.$TSTUSR $testfile
1191 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1194 $RUNAS $DD of=$testfile count=$limit ||
1195 quota_error a $TSTUSR "write failure, but expect success"
1202 local grace=20 # 20s
1203 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1206 local testfile=$DIR/$tdir/$tfile-0
1208 # get minimum soft qunit size
1209 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1210 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1212 set_ost_qtype $QTYPE || error "enable ost quota failed"
1214 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1215 # make sure the system is clean
1216 local used=$(getquota -u $TSTUSR global curspace)
1217 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1219 $LFS setquota -t -u --block-grace $grace --inode-grace \
1220 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1221 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1222 error "set user quota failed"
1224 test_block_soft $testfile $grace $limit "u"
1226 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1227 testfile=$DIR/$tdir/$tfile-1
1228 # make sure the system is clean
1229 used=$(getquota -g $TSTUSR global curspace)
1230 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1232 $LFS setquota -t -g --block-grace $grace --inode-grace \
1233 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1234 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1235 error "set group quota failed"
1237 test_block_soft $testfile $grace $limit "g"
1239 if is_project_quota_supported; then
1240 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1241 testfile=$DIR/$tdir/$tfile-2
1242 # make sure the system is clean
1243 used=$(getquota -p $TSTPRJID global curspace)
1244 [ $used -ne 0 ] && error \
1245 "Used space($used) for project $TSTPRJID isn't 0."
1247 $LFS setquota -t -p --block-grace $grace --inode-grace \
1248 $MAX_IQ_TIME $DIR ||
1249 error "set project grace time failed"
1250 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1251 $DIR || error "set project quota failed"
1253 test_block_soft $testfile $grace $limit "p"
1254 resetquota -p $TSTPRJID
1255 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1256 $MAX_IQ_TIME $DIR ||
1257 error "restore project grace time failed"
1261 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1262 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1263 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1264 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1266 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1269 local grace=20 # 20s
1270 local qpool="qpool1"
1271 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1274 local testfile=$DIR/$tdir/$tfile-0
1277 # get minimum soft qunit size
1278 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1279 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1280 local glbl_limit=$((2*limit))
1281 local glbl_grace=$((2*grace))
1282 echo "limit $limit glbl_limit $glbl_limit"
1283 echo "grace $grace glbl_grace $glbl_grace"
1285 set_ost_qtype $QTYPE || error "enable ost quota failed"
1287 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1288 # make sure the system is clean
1289 local used=$(getquota -u $TSTUSR global curspace)
1290 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1292 pool_add $qpool || error "pool_add failed"
1293 pool_add_targets $qpool 0 1 ||
1294 error "pool_add_targets failed"
1296 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1297 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1298 $LFS setquota -t -u --block-grace $grace \
1299 -o $qpool $DIR || error "set user grace time failed"
1301 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1302 error "set user quota failed"
1303 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1304 error "set user quota failed"
1306 test_block_soft $testfile $grace $limit "u" $qpool
1308 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1309 testfile=$DIR/$tdir/$tfile-1
1310 # make sure the system is clean
1311 used=$(getquota -g $TSTUSR global curspace)
1312 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1314 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1315 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1316 $LFS setquota -t -g --block-grace $grace \
1317 -o $qpool $DIR || error "set group grace time failed"
1319 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1320 error "set group quota failed"
1321 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1322 error "set group quota failed"
1324 test_block_soft $testfile $grace $limit "g" $qpool
1326 if is_project_quota_supported; then
1327 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1328 testfile=$DIR/$tdir/$tfile-2
1329 # make sure the system is clean
1330 used=$(getquota -p $TSTPRJID global curspace)
1331 [ $used -ne 0 ] && error \
1332 "Used space($used) for project $TSTPRJID isn't 0."
1334 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1335 $MAX_IQ_TIME $DIR ||
1336 error "set project grace time failed"
1337 $LFS setquota -t -p --block-grace $grace \
1338 -o $qpool $DIR || error "set project grace time failed"
1340 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1341 $DIR || error "set project quota failed"
1342 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -o $qpool $DIR ||
1343 error "set project quota failed"
1345 test_block_soft $testfile $grace $limit "p" $qpool
1346 resetquota -p $TSTPRJID
1347 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1348 $MAX_IQ_TIME $DIR ||
1349 error "restore project grace time failed"
1350 $LFS setquota -t -p --block-grace $MAX_DQ_TIME -o $qpool $DIR ||
1351 error "set project grace time failed"
1355 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1356 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1357 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1358 -o $qpool $DIR || error "restore user grace time failed"
1359 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1360 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1361 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1362 -o $qpool $DIR || error "restore group grace time failed"
1364 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1367 local grace=20 # 20s
1368 local qpool="qpool1"
1369 local qpool2="qpool2"
1370 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1373 local testfile=$DIR/$tdir/$tfile-0
1376 # get minimum soft qunit size
1377 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1378 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1379 local limit2=$((limit+4))
1380 local glbl_limit=$((limit+8))
1381 local grace1=$((grace+10))
1383 local glbl_grace=$((grace+20))
1384 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1385 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1387 set_ost_qtype $QTYPE || error "enable ost quota failed"
1389 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1390 # make sure the system is clean
1391 local used=$(getquota -u $TSTUSR global curspace)
1392 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1394 pool_add $qpool || error "pool_add failed"
1395 pool_add_targets $qpool 0 1 ||
1396 error "pool_add_targets failed"
1398 pool_add $qpool2 || error "pool_add failed"
1399 pool_add_targets $qpool2 0 1 ||
1400 error "pool_add_targets failed"
1403 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1404 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1405 $LFS setquota -t -u --block-grace $grace1 \
1406 -o $qpool $DIR || error "set user grace time failed"
1407 $LFS setquota -t -u --block-grace $grace2 \
1408 -o $qpool2 $DIR || error "set user grace time failed"
1410 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1411 error "set user quota failed"
1412 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1413 error "set user quota failed"
1414 # qpool has minimum soft limit, but it's grace is grater than
1415 # grace period of qpool2. Thus write shouldn't fail when
1416 # hit qpool soft limit - only when reaches up qpool2 limit
1417 # after grace2 seconds.
1418 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 -o $qpool2 $DIR ||
1419 error "set user quota failed"
1421 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1424 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1425 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1426 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1427 -o $qpool $DIR || error "restore user grace time failed"
1428 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1429 -o $qpool2 $DIR || error "restore user grace time failed"
1431 run_test 3c "Quota pools: check block soft limit on different pools"
1440 trap cleanup_quota_test EXIT
1441 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1443 echo "Create files to exceed soft limit"
1444 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1445 quota_error a $TSTUSR "create failure, but expect success"
1446 local trigger_time=$(date +%s)
1448 sync_all_data || true
1450 local cur_time=$(date +%s)
1451 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1452 error "Passed grace time $grace, $trigger_time, $cur_time"
1454 echo "Create file before timer goes off"
1455 $RUNAS touch ${TESTFILE}_before ||
1456 quota_error a $TSTUSR "failed create before timer expired," \
1457 "but expect success. $trigger_time, $cur_time"
1458 sync_all_data || true
1460 wait_grace_time $qtype "file"
1465 $SHOW_QUOTA_INFO_USER
1466 $SHOW_QUOTA_INFO_GROUP
1467 $SHOW_QUOTA_INFO_PROJID
1469 echo "Create file after timer goes off"
1470 # There is a window that space is accounted in the quota usage but
1471 # hasn't been decreased from the pending write, if we acquire quota
1472 # in this window, we'll acquire more than we needed.
1473 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
1474 sync_all_data || true
1475 $RUNAS touch ${TESTFILE}_after_3 &&
1476 quota_error a $TSTUSR "create after timer expired," \
1478 sync_all_data || true
1483 $SHOW_QUOTA_INFO_USER
1484 $SHOW_QUOTA_INFO_GROUP
1485 $SHOW_QUOTA_INFO_PROJID
1487 echo "Unlink files to stop timer"
1488 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1489 wait_delete_completed
1492 $RUNAS touch ${TESTFILE}_xxx ||
1493 quota_error a $TSTUSR "touch after timer stop failure," \
1494 "but expect success"
1495 sync_all_data || true
1503 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1504 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1505 local TESTFILE=$DIR/$tdir/$tfile-0
1508 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1510 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1511 # make sure the system is clean
1512 local USED=$(getquota -u $TSTUSR global curinodes)
1513 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1515 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1516 $GRACE $DIR || error "set user grace time failed"
1517 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1518 error "set user quota failed"
1520 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1522 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1524 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1525 # make sure the system is clean
1526 USED=$(getquota -g $TSTUSR global curinodes)
1527 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1529 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1530 $GRACE $DIR || error "set group grace time failed"
1531 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1532 error "set group quota failed"
1533 TESTFILE=$DIR/$tdir/$tfile-1
1535 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1537 if is_project_quota_supported; then
1538 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1539 # make sure the system is clean
1540 USED=$(getquota -p $TSTPRJID global curinodes)
1541 [ $USED -ne 0 ] && error \
1542 "Used space($USED) for project $TSTPRJID isn't 0."
1544 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1545 $GRACE $DIR || error "set project grace time failed"
1546 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1547 error "set project quota failed"
1549 TESTFILE=$DIR/$tdir/$tfile-1
1550 # one less than limit, because of parent directory included.
1551 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1552 resetquota -p $TSTPRJID
1553 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1554 $MAX_IQ_TIME $DIR ||
1555 error "restore project grace time failed"
1559 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1560 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1561 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1562 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1564 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1567 local GR_STR1="1w3d"
1568 local GR_STR2="1000s"
1570 local GR_STR4="1w2d3h4m5s"
1572 local GR_STR6="18446744073709551615"
1575 wait_delete_completed
1577 # test of valid grace strings handling
1578 echo "Valid grace strings test"
1579 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1580 $GR_STR2 $DIR || error "set user grace time failed"
1581 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1582 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1583 $GR_STR4 $DIR || error "set group grace time quota failed"
1584 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1586 # test of invalid grace strings handling
1587 echo " Invalid grace strings test"
1588 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1589 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1590 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1594 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1595 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1596 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1597 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1599 run_test 4b "Grace time strings handling"
1601 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1603 local BLIMIT=10 # 10M
1604 local ILIMIT=10 # 10 inodes
1606 setup_quota_test || error "setup quota failed with $?"
1607 trap cleanup_quota_test EXIT
1609 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1610 set_ost_qtype $QTYPE || error "enable ost quota failed"
1612 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1613 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1614 error "set user quota failed"
1615 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1616 if is_project_quota_supported; then
1617 error "set group quota failed"
1618 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1619 -I $ILIMIT $DIR || error "set project quota failed"
1622 # make sure the system is clean
1623 local USED=$(getquota -u $TSTUSR global curinodes)
1624 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1625 USED=$(getquota -g $TSTUSR global curinodes)
1626 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1627 USED=$(getquota -u $TSTUSR global curspace)
1628 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1629 USED=$(getquota -g $TSTUSR global curspace)
1630 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1631 if is_project_quota_supported; then
1632 USED=$(getquota -p $TSTPRJID global curinodes)
1634 error "Used inode($USED) for project $TSTPRJID isn't 0."
1635 USED=$(getquota -p $TSTPRJID global curspace)
1637 error "Used block($USED) for project $TSTPRJID isn't 0."
1640 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1641 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1642 error "create failure, expect success"
1643 if is_project_quota_supported; then
1644 touch $DIR/$tdir/$tfile-0_1
1645 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1647 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1648 error "write failure, expect success"
1650 echo "Chown files to $TSTUSR.$TSTUSR ..."
1651 for i in $(seq 0 $ILIMIT); do
1652 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1653 quota_error a $TSTUSR "chown failure, expect success"
1657 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1658 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1661 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1663 # test dropping acquire request on master
1667 # Clear dmesg so watchdog is not triggered by previous
1669 do_facet ost1 dmesg -c > /dev/null
1671 setup_quota_test || error "setup quota failed with $?"
1672 trap cleanup_quota_test EXIT
1674 # make sure the system is clean
1675 local USED=$(getquota -u $TSTUSR global curspace)
1676 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1678 # make sure no granted quota on ost
1679 set_ost_qtype $QTYPE || error "enable ost quota failed"
1680 resetquota -u $TSTUSR
1682 # create file for $TSTUSR
1683 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1684 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1685 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1687 # create file for $TSTUSR2
1688 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1689 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1690 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1692 # cache per-ID lock for $TSTUSR on slave
1693 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1694 error "set quota failed"
1695 $RUNAS $DD of=$TESTFILE count=1 ||
1696 error "write $TESTFILE failure, expect success"
1697 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1698 error "write $TESTFILE2 failure, expect success"
1700 if at_is_enabled; then
1701 at_max_saved=$(at_max_get ost1)
1702 at_max_set $TIMEOUT ost1
1704 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1705 # DQACQ is sent, which makes at_max to take effect
1706 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1709 wait_delete_completed
1713 sync_all_data || true
1715 #define QUOTA_DQACQ 601
1716 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1717 lustre_fail mds 0x513 601
1719 do_facet ost1 $LCTL set_param \
1720 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1722 # write to un-enforced ID ($TSTUSR2) should succeed
1723 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1724 error "write failure, expect success"
1726 # write to enforced ID ($TSTUSR) in background, exceeding limit
1727 # to make sure DQACQ is sent
1728 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1731 # watchdog timer uses a factor of 2
1732 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1733 sleep $((TIMEOUT * 2 + 1))
1735 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1737 # write should be blocked and never finished
1738 if ! ps -p $DDPID > /dev/null 2>&1; then
1740 error "write finished incorrectly!"
1745 # no watchdog is triggered
1746 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1747 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1748 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1749 [ -z "$watchdog" ] || error "$watchdog"
1751 rm -f $TMP/lustre-log-${TESTNAME}.log
1753 # write should continue then fail with EDQUOT
1757 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1758 if [ $count -ge 240 ]; then
1759 quota_error u $TSTUSR "dd not finished in $count secs"
1761 count=$((count + 1))
1762 if [ $((count % 30)) -eq 0 ]; then
1763 c_size=$(stat -c %s $TESTFILE)
1764 echo "Waiting $count secs. $c_size"
1772 run_test 6 "Test dropping acquire request on master"
1774 # quota reintegration (global index)
1776 local TESTFILE=$DIR/$tdir/$tfile
1777 local LIMIT=20 # 20M
1779 [ "$SLOW" = "no" ] && LIMIT=5
1781 setup_quota_test || error "setup quota failed with $?"
1782 trap cleanup_quota_test EXIT
1784 # make sure the system is clean
1785 local USED=$(getquota -u $TSTUSR global curspace)
1786 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1788 # make sure no granted quota on ost1
1789 set_ost_qtype $QTYPE || error "enable ost quota failed"
1790 resetquota -u $TSTUSR
1791 set_ost_qtype "none" || error "disable ost quota failed"
1793 local OSTUUID=$(ostuuid_from_index 0)
1794 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1796 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1799 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1800 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1805 echo "Enable quota & set quota limit for $TSTUSR"
1806 set_ost_qtype $QTYPE || error "enable ost quota failed"
1807 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1808 error "set quota failed"
1810 echo "Start ost1..."
1811 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1814 wait_ost_reint $QTYPE || error "reintegration failed"
1816 # hardlimit should have been fetched by slave during global
1817 # reintegration, write will exceed quota
1818 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1819 quota_error u $TSTUSR "write success, but expect EDQUOT"
1822 wait_delete_completed
1823 sync_all_data || true
1829 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1830 error "clear quota failed"
1832 echo "Start ost1..."
1833 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1836 wait_ost_reint $QTYPE || error "reintegration failed"
1838 # hardlimit should be cleared on slave during reintegration
1839 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1840 quota_error u $TSTUSR "write error, but expect success"
1844 run_test 7a "Quota reintegration (global index)"
1846 # quota reintegration (slave index)
1849 local TESTFILE=$DIR/$tdir/$tfile
1851 setup_quota_test || error "setup quota failed with $?"
1852 trap cleanup_quota_test EXIT
1854 # make sure the system is clean
1855 local USED=$(getquota -u $TSTUSR global curspace)
1856 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1858 # make sure no granted quota on ost1
1859 set_ost_qtype $QTYPE || error "enable ost quota failed"
1860 resetquota -u $TSTUSR
1861 set_ost_qtype "none" || error "disable ost quota failed"
1863 local OSTUUID=$(ostuuid_from_index 0)
1864 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1866 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1869 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1870 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1872 # consume some space to make sure the granted space will not
1873 # be released during reconciliation
1874 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1875 error "consume space failure, expect success"
1877 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1878 lustre_fail mds 0xa02
1880 set_ost_qtype $QTYPE || error "enable ost quota failed"
1881 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1882 error "set quota failed"
1884 # ignore the write error
1885 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1887 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1891 echo "Restart ost to trigger reintegration..."
1893 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1896 wait_ost_reint $QTYPE || error "reintegration failed"
1898 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1899 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1904 run_test 7b "Quota reintegration (slave index)"
1906 # quota reintegration (restart mds during reintegration)
1908 local LIMIT=20 # 20M
1909 local TESTFILE=$DIR/$tdir/$tfile
1911 [ "$SLOW" = "no" ] && LIMIT=5
1913 setup_quota_test || error "setup quota failed with $?"
1914 trap cleanup_quota_test EXIT
1916 # make sure the system is clean
1917 local USED=$(getquota -u $TSTUSR global curspace)
1918 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1920 set_ost_qtype "none" || error "disable ost quota failed"
1921 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1922 error "set quota failed"
1924 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1925 lustre_fail ost 0xa03
1928 set_ost_qtype $QTYPE || error "enable ost quota failed"
1929 # trigger reintegration
1930 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1931 procf=${procf}quota_slave.force_reint
1932 do_facet ost1 $LCTL set_param $procf=1 ||
1933 error "force reintegration failed"
1941 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1944 # wait longer than usual to make sure the reintegration
1945 # is triggered by quota wb thread.
1946 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1948 # hardlimit should have been fetched by slave during global
1949 # reintegration, write will exceed quota
1950 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1951 quota_error u $TSTUSR "write success, but expect EDQUOT"
1955 run_test 7c "Quota reintegration (restart mds during reintegration)"
1957 # Quota reintegration (Transfer index in multiple bulks)
1959 local TESTFILE=$DIR/$tdir/$tfile
1960 local TESTFILE1="$DIR/$tdir/$tfile"-1
1963 setup_quota_test || error "setup quota failed with $?"
1964 trap cleanup_quota_test EXIT
1966 set_ost_qtype "none" || error "disable ost quota failed"
1967 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1968 error "set quota for $TSTUSR failed"
1969 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1970 error "set quota for $TSTUSR2 failed"
1972 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1973 lustre_fail mds 0x608 0
1975 # enable quota to tirgger reintegration
1976 set_ost_qtype "u" || error "enable ost quota failed"
1977 wait_ost_reint "u" || error "reintegration failed"
1981 # hardlimit should have been fetched by slave during global
1982 # reintegration, write will exceed quota
1983 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1984 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1986 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1987 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1991 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1993 # quota reintegration (inode limits)
1995 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1997 # LU-2435: skip this quota test if underlying zfs version has not
1998 # supported native dnode accounting
1999 [ "$mds1_FSTYPE" == zfs ] && {
2000 local F="feature@userobj_accounting"
2001 local pool=$(zpool_name mds1)
2002 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2004 [[ "$feature" != *" active "* ]] &&
2005 skip "requires zpool with active userobj_accounting"
2008 local ilimit=$((1024 * 2)) # 2k inodes
2009 local TESTFILE=$DIR/${tdir}-1/$tfile
2011 setup_quota_test || error "setup quota failed with $?"
2012 trap cleanup_quota_test EXIT
2014 # make sure the system is clean
2015 local USED=$(getquota -u $TSTUSR global curinodes)
2016 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2018 # make sure no granted quota on mdt1
2019 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2020 resetquota -u $TSTUSR
2021 set_mdt_qtype "none" || error "disable mdt quota failed"
2023 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2024 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2025 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2028 echo "Stop mds${MDSCOUNT}..."
2031 echo "Enable quota & set quota limit for $TSTUSR"
2032 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2033 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2034 error "set quota failed"
2036 echo "Start mds${MDSCOUNT}..."
2037 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2040 wait_mdt_reint $QTYPE || error "reintegration failed"
2042 echo "create remote dir"
2043 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2044 error "create remote dir failed"
2045 chmod 0777 $DIR/${tdir}-1
2047 # hardlimit should have been fetched by slave during global
2048 # reintegration, create will exceed quota
2049 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2050 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2052 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2053 wait_delete_completed
2054 sync_all_data || true
2056 echo "Stop mds${MDSCOUNT}..."
2059 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2060 error "clear quota failed"
2062 echo "Start mds${MDSCOUNT}..."
2063 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2066 wait_mdt_reint $QTYPE || error "reintegration failed"
2068 # hardlimit should be cleared on slave during reintegration
2069 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2070 quota_error u $TSTUSR "create failed, expect success"
2072 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2073 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2077 run_test 7e "Quota reintegration (inode limits)"
2079 # run dbench with quota enabled
2081 local BLK_LIMIT="100g" #100G
2082 local FILE_LIMIT=1000000
2084 setup_quota_test || error "setup quota failed with $?"
2085 trap cleanup_quota_test EXIT
2087 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2088 set_ost_qtype $QTYPE || error "enable ost quota failed"
2090 echo "Set enough high limit for user: $TSTUSR"
2091 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2092 error "set user quota failed"
2093 echo "Set enough high limit for group: $TSTUSR"
2094 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2095 error "set group quota failed"
2096 if is_project_quota_supported; then
2097 change_project -sp $TSTPRJID $DIR/$tdir
2098 echo "Set enough high limit for project: $TSTPRJID"
2099 $LFS setquota -p $TSTPRJID -b 0 \
2100 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2101 error "set project quota failed"
2105 [ "$SLOW" = "no" ] && duration=" -t 120"
2106 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2107 quota_error a $TSTUSR "dbench failed!"
2109 is_project_quota_supported && change_project -C $DIR/$tdir
2112 run_test 8 "Run dbench with quota enabled"
2114 # this check is just for test_9
2115 OST0_MIN=4900000 #4.67G
2117 check_whether_skip () {
2118 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2119 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2120 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2121 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2128 # run for fixing bug10707, it needs a big room. test for 64bit
2130 local filesize=$((1024 * 9 / 2)) # 4.5G
2132 check_whether_skip && return 0
2134 setup_quota_test || error "setup quota failed with $?"
2135 trap cleanup_quota_test EXIT
2137 set_ost_qtype "ug" || error "enable ost quota failed"
2139 local TESTFILE="$DIR/$tdir/$tfile-0"
2140 local BLK_LIMIT=100G #100G
2141 local FILE_LIMIT=1000000
2143 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2145 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2147 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2148 error "set user quota failed"
2150 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2151 "for group: $TSTUSR"
2152 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2153 error "set group quota failed"
2155 quota_show_check a u $TSTUSR
2156 quota_show_check a g $TSTUSR
2158 echo "Create test file"
2159 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2160 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2162 log "Write the big file of 4.5G ..."
2163 $RUNAS $DD of=$TESTFILE count=$filesize ||
2164 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2174 run_test 9 "Block limit larger than 4GB (b10707)"
2177 local TESTFILE=$DIR/$tdir/$tfile
2179 setup_quota_test || error "setup quota failed with $?"
2180 trap cleanup_quota_test EXIT
2182 # set limit to root user should fail
2183 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2184 error "set limit for root user successfully, expect failure"
2185 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2186 error "set limit for root group successfully, expect failure"
2187 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2188 error "set limit for project 0 successfully, expect failure"
2190 # root user can overrun quota
2191 set_ost_qtype "ug" || error "enable ost quota failed"
2193 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2194 error "set quota failed"
2195 quota_show_check b u $TSTUSR
2197 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2198 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2200 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2201 error "write failure, expect success"
2205 run_test 10 "Test quota for root user"
2208 local TESTFILE=$DIR/$tdir/$tfile
2209 setup_quota_test || error "setup quota failed with $?"
2210 trap cleanup_quota_test EXIT
2212 set_mdt_qtype "ug" || error "enable mdt quota failed"
2213 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2214 error "set quota failed"
2216 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2217 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2219 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2220 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2223 local USED=$(getquota -u $TSTUSR global curinodes)
2224 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2228 run_test 11 "Chown/chgrp ignores quota"
2231 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2233 local blimit=22 # 22M
2234 local blk_cnt=$((blimit - 5))
2235 local TESTFILE0="$DIR/$tdir/$tfile"-0
2236 local TESTFILE1="$DIR/$tdir/$tfile"-1
2238 setup_quota_test || error "setup quota failed with $?"
2239 trap cleanup_quota_test EXIT
2241 set_ost_qtype "u" || error "enable ost quota failed"
2242 quota_show_check b u $TSTUSR
2244 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2245 error "set quota failed"
2247 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2248 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2249 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2250 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2252 echo "Write to ost0..."
2253 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2254 quota_error a $TSTUSR "dd failed"
2256 echo "Write to ost1..."
2257 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2258 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2260 echo "Free space from ost0..."
2262 wait_delete_completed
2263 sync_all_data || true
2265 echo "Write to ost1 after space freed from ost0..."
2266 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2267 quota_error a $TSTUSR "rebalancing failed"
2271 run_test 12a "Block quota rebalancing"
2274 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2276 local ilimit=$((1024 * 2)) # 2k inodes
2277 local TESTFILE0=$DIR/$tdir/$tfile
2278 local TESTFILE1=$DIR/${tdir}-1/$tfile
2280 setup_quota_test || error "setup quota failed with $?"
2281 trap cleanup_quota_test EXIT
2283 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2284 chmod 0777 $DIR/${tdir}-1
2286 set_mdt_qtype "u" || error "enable mdt quota failed"
2287 quota_show_check f u $TSTUSR
2289 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2290 error "set quota failed"
2292 echo "Create $ilimit files on mdt0..."
2293 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2294 quota_error u $TSTUSR "create failed, but expect success"
2296 echo "Create files on mdt1..."
2297 $RUNAS createmany -m $TESTFILE1 1 &&
2298 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2300 echo "Free space from mdt0..."
2301 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2302 wait_delete_completed
2303 sync_all_data || true
2305 echo "Create files on mdt1 after space freed from mdt0..."
2306 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2307 quota_error a $TSTUSR "rebalancing failed"
2309 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2310 error "unlink mdt1 files failed"
2311 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2315 run_test 12b "Inode quota rebalancing"
2318 local TESTFILE=$DIR/$tdir/$tfile
2319 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2320 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2322 setup_quota_test || error "setup quota failed with $?"
2323 trap cleanup_quota_test EXIT
2325 set_ost_qtype "u" || error "enable ost quota failed"
2326 quota_show_check b u $TSTUSR
2328 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2329 error "set quota failed"
2330 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2331 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2333 # clear the locks in cache first
2334 do_facet ost1 $LCTL set_param -n $procf=clear
2335 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2336 [ $nlock -eq 0 ] || error "$nlock cached locks"
2338 # write to acquire the per-ID lock
2339 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2340 quota_error a $TSTUSR "dd failed"
2342 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2343 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2345 # clear quota doesn't trigger per-ID lock cancellation
2346 resetquota -u $TSTUSR
2347 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2348 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2350 # clear the per-ID lock
2351 do_facet ost1 $LCTL set_param -n $procf=clear
2352 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2353 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2355 # spare quota should be released
2356 local OSTUUID=$(ostuuid_from_index 0)
2357 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2358 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2359 [ $limit -le $space ] ||
2360 error "spare quota isn't released, limit:$limit, space:$space"
2364 run_test 13 "Cancel per-ID lock in the LRU list"
2367 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2369 wait_delete_completed
2370 sync_all_data || true
2373 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2374 error "set user quota failed"
2375 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2376 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2377 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2378 resetquota -u $TSTUSR
2381 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2382 error "set group quota failed"
2383 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2384 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2385 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2386 resetquota -g $TSTUSR
2388 run_test 15 "Set over 4T block quota"
2392 local BLKS=1 # 1M less than limit
2393 local TESTFILE=$DIR/$tdir/$tfile
2395 setup_quota_test || error "setup quota failed with $?"
2396 trap cleanup_quota_test EXIT
2398 # make sure the system is clean
2399 local USED=$(getquota -u $TSTUSR global curspace)
2400 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2402 set_ost_qtype "ug" || error "enable ost quota failed"
2403 # make sure no granted quota on ost
2404 resetquota -u $TSTUSR
2405 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2406 error "set quota failed"
2408 quota_show_check b u $TSTUSR
2410 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2411 lustre_fail mds 0xa04 $err_code
2413 # write in background
2414 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2418 # write should be blocked and never finished
2419 if ! ps -p $DDPID > /dev/null 2>&1; then
2421 quota_error u $TSTUSR "write finished incorrectly!"
2429 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2431 if [ $count -gt $timeout ]; then
2432 quota_error u $TSTUSR "dd is not finished!"
2437 sync; sync_all_data || true
2439 USED=$(getquota -u $TSTUSR global curspace)
2440 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2441 "Used space(${USED}K) is less than ${BLKS}M"
2446 # DQACQ return recoverable error
2448 echo "DQACQ return -ENOLCK"
2450 test_17sub 37 || error "Handle -ENOLCK failed"
2452 echo "DQACQ return -EAGAIN"
2454 test_17sub 11 || error "Handle -EAGAIN failed"
2456 echo "DQACQ return -ETIMEDOUT"
2457 #define ETIMEDOUT 110
2458 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2460 echo "DQACQ return -ENOTCONN"
2461 #define ENOTCONN 107
2462 test_17sub 107 || error "Handle -ENOTCONN failed"
2465 run_test 17 "DQACQ return recoverable error"
2469 local blimit="200m" # 200M
2470 local TESTFILE="$DIR/$tdir/$tfile"
2472 setup_quota_test || error "setup quota failed with $?"
2473 trap cleanup_quota_test EXIT
2475 set_ost_qtype "u" || error "enable ost quota failed"
2476 log "User quota (limit: $blimit)"
2477 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2478 error "set quota failed"
2479 quota_show_check b u $TSTUSR
2481 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2482 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2484 local timeout=$(sysctl -n lustre.timeout)
2486 if [ $io_type = "directio" ]; then
2487 log "Write 100M (directio) ..."
2488 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2490 log "Write 100M (buffered) ..."
2491 $RUNAS $DD of=$TESTFILE count=100 &
2495 replay_barrier $SINGLEMDS
2496 log "Fail mds for $((2 * timeout)) seconds"
2497 fail $SINGLEMDS $((2 * timeout))
2500 if at_is_enabled; then
2501 timeout=$(at_max_get mds)
2503 timeout=$(lctl get_param -n timeout)
2507 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2508 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2509 log "it took $count second"
2514 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2516 cancel_lru_locks mdc
2517 cancel_lru_locks osc
2520 local testfile_size=$(stat -c %s $TESTFILE)
2521 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2522 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2523 "got ${testfile_size}. Verifying file failed!"
2528 # test when mds does failover, the ost still could work well
2529 # this test shouldn't trigger watchdog b=14840
2531 # Clear dmesg so watchdog is not triggered by previous
2533 do_facet ost1 dmesg -c > /dev/null
2536 test_18_sub directio
2538 # check if watchdog is triggered
2539 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2540 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2541 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2542 [ -z "$watchdog" ] || error "$watchdog"
2543 rm -f $TMP/lustre-log-${TESTNAME}.log
2545 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2549 local TESTFILE=$DIR/$tdir/$tfile
2551 setup_quota_test || error "setup quota failed with $?"
2552 trap cleanup_quota_test EXIT
2554 set_ost_qtype $QTYPE || error "enable ost quota failed"
2556 # bind file to a single OST
2557 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2558 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2560 echo "Set user quota (limit: ${blimit}M)"
2561 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2562 error "set user quota failed"
2563 quota_show_check b u $TSTUSR
2564 echo "Update quota limits"
2565 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2566 error "set group quota failed"
2567 quota_show_check b u $TSTUSR
2569 # first wirte might be cached
2570 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2571 cancel_lru_locks osc
2573 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2574 quota_error u $TSTUSR "Write success, expect failure"
2579 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2581 test_20() { # b15754
2582 local LSTR=(2g 1t 4k 3m) # limits strings
2584 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2587 resetquota -u $TSTUSR
2589 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2590 $MOUNT || error "could not set quota limits"
2591 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2592 --inode-softlimit ${LSTR[2]} \
2593 --inode-hardlimit ${LSTR[3]} \
2594 $MOUNT || error "could not set quota limits"
2596 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2597 error "bsoftlimit was not set properly"
2598 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2599 error "bhardlimit was not set properly"
2600 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2601 error "isoftlimit was not set properly"
2602 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2603 error "ihardlimit was not set properly"
2605 resetquota -u $TSTUSR
2607 run_test 20 "Test if setquota specifiers work properly (b15754)"
2614 local time=$(($(date +%s) + seconds))
2615 while [ $(date +%s) -lt $time ]; do
2616 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2620 # run for fixing bug16053, setquota shouldn't fail when writing and
2621 # deleting are happening
2623 local TESTFILE="$DIR/$tdir/$tfile"
2624 local BLIMIT=10 # 10G
2625 local ILIMIT=1000000
2627 setup_quota_test || error "setup quota failed with $?"
2628 trap cleanup_quota_test EXIT
2630 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2632 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2633 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2634 error "set user quota failed"
2635 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2636 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2637 error "set group quota failed"
2638 if is_project_quota_supported; then
2639 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2640 "project: $TSTPRJID"
2641 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2642 $MOUNT || error "set project quota failed"
2645 # repeat writing on a 1M file
2646 test_21_sub ${TESTFILE}_1 1 30 &
2648 # repeat writing on a 128M file
2649 test_21_sub ${TESTFILE}_2 128 30 &
2652 local time=$(($(date +%s) + 30))
2654 while [ $(date +%s) -lt $time ]; do
2655 log "Set quota for $i times"
2656 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2657 -I $((ILIMIT + i)) $MOUNT ||
2658 error "Set user quota failed"
2659 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2660 -I $((ILIMIT + i)) $MOUNT ||
2661 error "Set group quota failed"
2662 if is_project_quota_supported; then
2663 $LFS setquota -p $TSTPRJID -b 0 -B \
2664 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2665 error "Set project quota failed"
2673 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2675 if [ $count -gt 60 ]; then
2676 quota_error a $TSTUSR "dd should be finished!"
2680 echo "(dd_pid=$DDPID1, time=$count)successful"
2684 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2686 if [ $count -gt 60 ]; then
2687 quota_error a $TSTUSR "dd should be finished!"
2691 echo "(dd_pid=$DDPID2, time=$count)successful"
2695 run_test 21 "Setquota while writing & deleting (b16053)"
2697 # enable/disable quota enforcement permanently
2699 echo "Set both mdt & ost quota type as ug"
2701 is_project_quota_supported && qtype=$QTYPE
2702 set_mdt_qtype $qtype || error "enable mdt quota failed"
2703 set_ost_qtype $qtype || error "enable ost quota failed"
2706 stopall || error "failed to stopall (1)"
2710 echo "Verify if quota is enabled"
2711 local qtype1=$(mdt_quota_type)
2712 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2713 qtype=$(ost_quota_type)
2714 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2716 echo "Set both mdt & ost quota type as none"
2717 set_mdt_qtype "none" || error "disable mdt quota failed"
2718 set_ost_qtype "none" || error "disable ost quota failed"
2721 stopall || error "failed to stopall (2)"
2726 echo "Verify if quota is disabled"
2727 qtype=$(mdt_quota_type)
2728 [ $qtype != "none" ] && error "mdt quota setting is lost"
2729 qtype=$(ost_quota_type)
2730 [ $qtype != "none" ] && error "ost quota setting is lost"
2734 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2737 local TESTFILE="$DIR/$tdir/$tfile"
2740 setup_quota_test || error "setup quota failed with $?"
2741 trap cleanup_quota_test EXIT
2743 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2746 log "User quota (limit: $LIMIT MB)"
2747 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2748 error "set quota failed"
2749 quota_show_check b u $TSTUSR
2751 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2752 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2754 log "Step1: trigger EDQUOT with O_DIRECT"
2755 log "Write half of file"
2756 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2757 quota_error u $TSTUSR "(1) Write failure, expect success." \
2759 log "Write out of block quota ..."
2760 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2761 oflag=direct conv=notrunc &&
2762 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2766 log "Step2: rewrite should succeed"
2767 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2768 quota_error u $TSTUSR "(3) Write failure, expect success." \
2774 local OST0_UUID=$(ostuuid_from_index 0)
2775 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2776 [ $OST0_QUOTA_USED -ne 0 ] &&
2777 ($SHOW_QUOTA_USER; \
2778 quota_error u $TSTUSR "quota isn't released")
2783 [ "$ost1_FSTYPE" == zfs ] &&
2784 skip "Overwrite in place is not guaranteed to be " \
2785 "space neutral on ZFS"
2787 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2788 check_whether_skip && return 0
2789 log "run for 4MB test file"
2792 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2793 check_whether_skip && return 0
2794 log "run for 40MB test file"
2797 run_test 23 "Quota should be honored with directIO (b16125)"
2801 local TESTFILE="$DIR/$tdir/$tfile"
2803 setup_quota_test || error "setup quota failed with $?"
2804 trap cleanup_quota_test EXIT
2806 set_ost_qtype $QTYPE || error "enable ost quota failed"
2808 # bind file to a single OST
2809 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2810 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2812 echo "Set user quota (limit: ${blimit}M)"
2813 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2814 error "set quota failed"
2816 # overrun quota by root user
2817 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2818 error "write failure, expect success"
2819 cancel_lru_locks osc
2820 sync_all_data || true
2822 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2826 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2828 test_27a() { # b19612
2829 $LFS quota $TSTUSR $DIR &&
2830 error "lfs succeeded with no type, but should have failed"
2831 $LFS setquota $TSTUSR $DIR &&
2832 error "lfs succeeded with no type, but should have failed"
2835 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2837 test_27b() { # b20200
2838 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2839 error "lfs setquota failed with uid argument"
2840 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2841 error "lfs stequota failed with gid argument"
2842 if is_project_quota_supported; then
2843 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2844 1000 $DIR || error \
2845 "lfs stequota failed with projid argument"
2847 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2848 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2849 if is_project_quota_supported; then
2850 $SHOW_QUOTA_PROJID ||
2851 error "lfs quota failed with projid argument"
2853 resetquota -u $TSTID
2854 resetquota -g $TSTID
2855 resetquota -p $TSTPRJID
2858 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2863 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2864 error "lfs setquota failed"
2866 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2867 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2868 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2869 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2871 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2872 error "lfs setquota for $TSTID failed"
2874 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2875 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2876 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2877 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2879 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2880 error "total allocated inode/block limit not printed"
2882 resetquota -u $TSTUSR
2884 run_test 27c "lfs quota should support human-readable output"
2891 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2892 error "set fraction block limit failed"
2893 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2894 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2895 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2896 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2898 resetquota -u $TSTUSR
2900 run_test 27d "lfs setquota should support fraction block limit"
2904 local TESTFILE="$DIR/$tdir/$tfile"
2907 setup_quota_test || error "setup quota failed with $?"
2908 trap cleanup_quota_test EXIT
2910 set_ost_qtype "u" || error "enable ost quota failed"
2912 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2913 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2915 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2916 $MAX_IQ_TIME $DIR || error "set grace time failed"
2917 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2918 error "set quota failed"
2919 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2920 cancel_lru_locks osc
2922 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2923 # over-quota flag has not yet settled since we do not trigger async
2924 # events based on grace time period expiration
2926 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2927 cancel_lru_locks osc
2928 # now over-quota flag should be settled and further writes should fail
2930 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2931 error "grace times were reset"
2934 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2935 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2937 run_test 30 "Hard limit updates should not reset grace times"
2939 # basic usage tracking for user & group
2941 local INODES=10 # 10 files
2942 local BLK_CNT=2 # of 2M each
2943 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2945 setup_quota_test || error "setup quota failed with $?"
2946 trap cleanup_quota_test EXIT
2948 # make sure the system is clean
2949 local USED=$(getquota -u $TSTID global curspace)
2951 error "Used space ($USED) for user $TSTID isn't 0."
2952 USED=$(getquota -g $TSTID global curspace)
2954 error "Used space ($USED) for group $TSTID isn't 0."
2955 if is_project_quota_supported; then
2956 USED=$(getquota -p $TSTPRJID global curspace)
2957 [ $USED -ne 0 ] && error \
2958 "Used space ($USED) for project $TSTPRJID isn't 0."
2961 echo "Write files..."
2962 for i in $(seq 0 $INODES); do
2963 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2964 error "write failed"
2965 is_project_quota_supported &&
2966 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2967 echo "Iteration $i/$INODES completed"
2969 cancel_lru_locks osc
2971 echo "Wait for setattr on objects finished..."
2972 wait_delete_completed
2974 sync; sync_all_data || true
2976 echo "Verify disk usage after write"
2977 USED=$(getquota -u $TSTID global curspace)
2978 [ $USED -lt $TOTAL_BLKS ] &&
2979 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2980 USED=$(getquota -g $TSTID global curspace)
2981 [ $USED -lt $TOTAL_BLKS ] &&
2982 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2983 if is_project_quota_supported; then
2984 USED=$(getquota -p $TSTPRJID global curspace)
2985 [ $USED -lt $TOTAL_BLKS ] && error \
2986 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2989 echo "Verify inode usage after write"
2990 USED=$(getquota -u $TSTID global curinodes)
2991 [ $USED -lt $INODES ] &&
2992 error "Used inode for user $TSTID is $USED, expected $INODES"
2993 USED=$(getquota -g $TSTID global curinodes)
2994 [ $USED -lt $INODES ] &&
2995 error "Used inode for group $TSTID is $USED, expected $INODES"
2996 if is_project_quota_supported; then
2997 USED=$(getquota -p $TSTPRJID global curinodes)
2998 [ $USED -lt $INODES ] && error \
2999 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3004 echo "Verify disk usage after delete"
3005 USED=$(getquota -u $TSTID global curspace)
3006 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3007 USED=$(getquota -u $TSTID global curinodes)
3008 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3009 USED=$(getquota -g $TSTID global curspace)
3010 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3011 USED=$(getquota -g $TSTID global curinodes)
3012 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3013 if is_project_quota_supported; then
3014 USED=$(getquota -p $TSTPRJID global curspace)
3016 error "Used space for project $TSTPRJID isn't 0. $USED"
3017 USED=$(getquota -p $TSTPRJID global curinodes)
3019 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3022 run_test 33 "Basic usage tracking for user & group & project"
3024 # usage transfer test for user & group & project
3026 local BLK_CNT=2 # 2MB
3027 local project_supported="no"
3029 is_project_quota_supported && project_supported="yes"
3030 setup_quota_test || error "setup quota failed with $?"
3031 trap cleanup_quota_test EXIT
3033 # make sure the system is clean
3034 local USED=$(getquota -u $TSTID global curspace)
3035 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3036 USED=$(getquota -g $TSTID global curspace)
3037 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3039 local USED=$(getquota -u $TSTID2 global curspace)
3040 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3041 if [ $project_supported == "yes" ]; then
3042 USED=$(getquota -p $TSTPRJID global curspace)
3043 [ $USED -ne 0 ] && error \
3044 "Used space ($USED) for Project $TSTPRJID isn't 0."
3047 echo "Write file..."
3048 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3049 error "write failed"
3050 cancel_lru_locks osc
3051 sync; sync_all_data || true
3053 echo "chown the file to user $TSTID"
3054 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3056 echo "Wait for setattr on objects finished..."
3057 wait_delete_completed
3059 BLK_CNT=$((BLK_CNT * 1024))
3061 echo "Verify disk usage for user $TSTID"
3062 USED=$(getquota -u $TSTID global curspace)
3063 [ $USED -lt $BLK_CNT ] &&
3064 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3065 USED=$(getquota -u $TSTID global curinodes)
3067 error "Used inodes for user $TSTID is $USED, expected 1"
3069 echo "chgrp the file to group $TSTID"
3070 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3072 echo "Wait for setattr on objects finished..."
3073 wait_delete_completed
3075 echo "Verify disk usage for group $TSTID"
3076 USED=$(getquota -g $TSTID global curspace)
3077 [ $USED -ge $BLK_CNT ] ||
3078 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3079 USED=$(getquota -g $TSTID global curinodes)
3081 error "Used inodes for group $TSTID is $USED, expected 1"
3083 # chown won't change the ost object group. LU-4345 */
3084 echo "chown the file to user $TSTID2"
3085 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3087 echo "Wait for setattr on objects finished..."
3088 wait_delete_completed
3090 echo "change_project project id to $TSTPRJID"
3091 [ $project_supported == "yes" ] &&
3092 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3093 echo "Wait for setattr on objects finished..."
3094 wait_delete_completed
3096 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3097 USED=$(getquota -u $TSTID2 global curspace)
3098 [ $USED -lt $BLK_CNT ] &&
3099 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3100 USED=$(getquota -u $TSTID global curspace)
3102 error "Used space for user $TSTID is $USED, expected 0"
3103 USED=$(getquota -g $TSTID global curspace)
3104 [ $USED -lt $BLK_CNT ] &&
3105 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3106 if [ $project_supported == "yes" ]; then
3107 USED=$(getquota -p $TSTPRJID global curspace)
3108 [ $USED -lt $BLK_CNT ] && error \
3109 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3114 run_test 34 "Usage transfer for user & group & project"
3116 # usage is still accessible across restart
3118 local BLK_CNT=2 # 2 MB
3120 setup_quota_test || error "setup quota failed with $?"
3121 trap cleanup_quota_test EXIT
3123 echo "Write file..."
3124 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3125 error "write failed"
3126 is_project_quota_supported &&
3127 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3128 cancel_lru_locks osc
3130 echo "Wait for setattr on objects finished..."
3131 wait_delete_completed
3133 sync; sync_all_data || true
3135 echo "Save disk usage before restart"
3136 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3137 [ $ORIG_USR_SPACE -eq 0 ] &&
3138 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3139 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3140 [ $ORIG_USR_INODES -eq 0 ] &&
3141 error "Used inodes for user $TSTID is 0, expected 1"
3142 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3143 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3144 [ $ORIG_GRP_SPACE -eq 0 ] &&
3145 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3146 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3147 [ $ORIG_GRP_INODES -eq 0 ] &&
3148 error "Used inodes for group $TSTID is 0, expected 1"
3149 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3151 if is_project_quota_supported; then
3152 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3153 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3154 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3155 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3156 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3157 "Used inodes for project $TSTPRJID is 0, expected 1"
3158 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3166 echo "Verify disk usage after restart"
3167 local USED=$(getquota -u $TSTID global curspace)
3168 [ $USED -eq $ORIG_USR_SPACE ] ||
3169 error "Used space for user $TSTID changed from " \
3170 "$ORIG_USR_SPACE to $USED"
3171 USED=$(getquota -u $TSTID global curinodes)
3172 [ $USED -eq $ORIG_USR_INODES ] ||
3173 error "Used inodes for user $TSTID changed from " \
3174 "$ORIG_USR_INODES to $USED"
3175 USED=$(getquota -g $TSTID global curspace)
3176 [ $USED -eq $ORIG_GRP_SPACE ] ||
3177 error "Used space for group $TSTID changed from " \
3178 "$ORIG_GRP_SPACE to $USED"
3179 USED=$(getquota -g $TSTID global curinodes)
3180 [ $USED -eq $ORIG_GRP_INODES ] ||
3181 error "Used inodes for group $TSTID changed from " \
3182 "$ORIG_GRP_INODES to $USED"
3183 if [ $project_supported == "yes" ]; then
3184 USED=$(getquota -p $TSTPRJID global curinodes)
3185 [ $USED -eq $ORIG_PRJ_INODES ] ||
3186 error "Used inodes for project $TSTPRJID " \
3187 "changed from $ORIG_PRJ_INODES to $USED"
3188 USED=$(getquota -p $TSTPRJID global curspace)
3189 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3190 error "Used space for project $TSTPRJID "\
3191 "changed from $ORIG_PRJ_SPACE to $USED"
3194 # check if the vfs_dq_init() is called before writing
3195 echo "Append to the same file..."
3196 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3197 error "write failed"
3198 cancel_lru_locks osc
3199 sync; sync_all_data || true
3201 echo "Verify space usage is increased"
3202 USED=$(getquota -u $TSTID global curspace)
3203 [ $USED -gt $ORIG_USR_SPACE ] ||
3204 error "Used space for user $TSTID isn't increased" \
3205 "orig:$ORIG_USR_SPACE, now:$USED"
3206 USED=$(getquota -g $TSTID global curspace)
3207 [ $USED -gt $ORIG_GRP_SPACE ] ||
3208 error "Used space for group $TSTID isn't increased" \
3209 "orig:$ORIG_GRP_SPACE, now:$USED"
3210 if [ $project_supported == "yes" ]; then
3211 USED=$(getquota -p $TSTPRJID global curspace)
3212 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3213 error "Used space for project $TSTPRJID isn't " \
3214 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3219 run_test 35 "Usage is still accessible across reboot"
3221 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3224 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3225 skip "Old server doesn't have LU-5006 fix."
3227 setup_quota_test || error "setup quota failed with $?"
3228 trap cleanup_quota_test EXIT
3230 # make sure the system is clean
3231 local USED=$(getquota -u $TSTID global curspace)
3233 error "Used space ($USED) for user $TSTID isn't 0."
3235 # create file with MDS_OPEN_DELAY_CREATE flag
3236 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3237 error "Create file failed"
3239 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3240 oflag=sync || error "Write file failed"
3242 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3244 # wait for setattr on objects finished..."
3245 wait_delete_completed
3247 USED=$(getquota -u $TSTID global curspace)
3248 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3252 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3256 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3257 skip "Old server doesn't have LU-8801 fix."
3259 [ "$UID" != 0 ] && skip_env "must run as root" && return
3261 setup_quota_test || error "setup quota failed with $?"
3262 trap cleanup_quota_test EXIT
3264 # make sure the system is clean
3265 local USED=$(getquota -u $TSTID global curspace)
3267 error "Used space ($USED) for user $TSTID isn't 0."
3268 USED=$(getquota -u $TSTID2 global curspace)
3270 error "Used space ($USED) for user $TSTID2 isn't 0."
3272 local TESTFILE="$DIR/$tdir/$tfile"
3273 local file_cnt=10000
3275 # Generate id entries in accounting file
3276 echo "Create $file_cnt files..."
3277 for i in `seq $file_cnt`; do
3279 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3280 error "failed to chown $TESTFILE-$i"
3282 cancel_lru_locks osc
3283 sync; sync_all_data || true
3285 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3286 procf=${procf}.quota_slave.acct_user
3289 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3290 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3291 echo "Found $acct_cnt id entries"
3293 [ $file_cnt -eq $acct_cnt ] || {
3294 do_facet mds1 $LCTL get_param $procf
3295 error "skipped id entries"
3300 run_test 38 "Quota accounting iterator doesn't skip id entries"
3303 local TESTFILE="$DIR/$tdir/project"
3304 ! is_project_quota_supported &&
3305 skip "Project quota is not supported"
3307 setup_quota_test || error "setup quota failed with $?"
3310 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3311 [ $projectid -ne 0 ] &&
3312 error "Project id should be 0 not $projectid"
3313 change_project -p 1024 $TESTFILE
3314 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3315 [ $projectid -ne 1024 ] &&
3316 error "Project id should be 1024 not $projectid"
3318 stopall || error "failed to stopall (1)"
3321 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3322 [ $projectid -ne 1024 ] &&
3323 error "Project id should be 1024 not $projectid"
3327 run_test 39 "Project ID interface works correctly"
3330 ! is_project_quota_supported &&
3331 skip "Project quota is not supported"
3332 local dir1="$DIR/$tdir/dir1"
3333 local dir2="$DIR/$tdir/dir2"
3335 setup_quota_test || error "setup quota failed with $?"
3337 mkdir -p $dir1 $dir2
3338 change_project -sp 1 $dir1 && touch $dir1/1
3339 change_project -sp 2 $dir2
3341 ln $dir1/1 $dir2/1_link &&
3342 error "Hard link across different project quota should fail"
3347 run_test 40a "Hard link across different project ID"
3350 ! is_project_quota_supported &&
3351 skip "Project quota is not supported"
3352 local dir1="$DIR/$tdir/dir1"
3353 local dir2="$DIR/$tdir/dir2"
3355 setup_quota_test || error "setup quota failed with $?"
3356 mkdir -p $dir1 $dir2
3357 change_project -sp 1 $dir1 && touch $dir1/1
3358 change_project -sp 2 $dir2
3360 mv $dir1/1 $dir2/2 || error "mv failed $?"
3361 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3362 if [ "$projid" != "2" ]; then
3363 error "project id expected 2 not $projid"
3368 run_test 40b "Mv across different project ID"
3371 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3372 ! is_project_quota_supported &&
3373 skip "Project quota is not supported"
3375 setup_quota_test || error "setup quota failed with $?"
3376 local dir="$DIR/$tdir/dir"
3378 mkdir -p $dir && change_project -sp 1 $dir
3379 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3380 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3381 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3382 touch $dir/remote_dir/file
3383 #verify inherit works file for remote dir.
3384 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3385 [ "$projid" != "1" ] &&
3386 error "file under remote dir expected 1 not $projid"
3388 #Agent inode should be ignored for project quota
3389 USED=$(getquota -p 1 global curinodes)
3390 [ "$USED" != "3" ] &&
3391 error "file count expected 3 got $USED"
3397 run_test 40c "Remote child Dir inherit project quota properly"
3400 ! is_project_quota_supported &&
3401 skip "Project quota is not supported"
3403 setup_quota_test || error "setup quota failed with $?"
3404 local dir1="$DIR/$tdir/dir1"
3405 local dir2="$DIR/$tdir/dir2"
3407 mkdir -p $dir1 && change_project -sp 1 $dir1
3408 mkdir -p $dir2 && change_project -sp 2 $dir2
3409 for num in $(seq 1 10); do
3410 touch $dir1/file_$num $dir2/file_$num
3411 ln -s $dir1/file_$num $dir1/file_$num"_link"
3412 ln -s $dir2/file_$num $dir2/file_$num"_link"
3415 count=$($LFS find --projid 1 $DIR | wc -l)
3416 [ "$count" != 21 ] && error "expected 21 but got $count"
3418 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3419 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3420 [ "$count" != 22 ] && error "expected 22 but got $count"
3425 run_test 50 "Test if lfs find --projid works"
3428 ! is_project_quota_supported &&
3429 skip "Project quota is not supported"
3430 setup_quota_test || error "setup quota failed with $?"
3431 local dir="$DIR/$tdir/dir"
3433 mkdir $dir && change_project -sp 1 $dir
3434 local used=$(getquota -p 1 global curinodes)
3435 [ $used != "1" ] && error "expected 1 got $used"
3440 used=$(getquota -p 1 global curinodes)
3441 [ $used != "4" ] && error "expected 4 got $used"
3443 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3445 cp $DIR/$tdir/6 $dir/6
3446 used=$(getquota -p 1 global curinodes)
3447 [ $used != "5" ] && error "expected 5 got $used"
3450 mv $DIR/$tdir/6 $dir/7
3451 used=$(getquota -p 1 global curinodes)
3452 [ $used != "6" ] && error "expected 6 got $used"
3457 run_test 51 "Test project accounting with mv/cp"
3460 ! is_project_quota_supported &&
3461 skip "Project quota is not supported"
3462 setup_quota_test || error "setup quota failed with $?"
3463 local dir="$DIR/$tdir/dir"
3464 mkdir $dir && change_project -sp 1 $dir
3466 touch $DIR/$tdir/file
3467 #Try renaming a file into the project. This should fail.
3468 for num in $(seq 1 2000); do
3469 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3470 error "rename should fail"
3475 run_test 52 "Rename across different project ID"
3478 ! is_project_quota_supported &&
3479 skip "Project quota is not supported"
3480 setup_quota_test || error "setup quota failed with $?"
3481 local dir="$DIR/$tdir/dir"
3482 mkdir $dir && change_project -s $dir
3483 lfs project -d $dir | grep P || error "inherit attribute should be set"
3485 change_project -C $dir
3486 lfs project -d $dir | grep P &&
3487 error "inherit attribute should be cleared"
3492 run_test 53 "Project inherit attribute could be cleared"
3495 ! is_project_quota_supported &&
3496 skip "Project quota is not supported"
3497 setup_quota_test || error "setup quota failed with $?"
3498 trap cleanup_quota_test EXIT
3499 local testfile="$DIR/$tdir/$tfile-0"
3501 #set project ID/inherit attribute
3502 change_project -sp $TSTPRJID $DIR/$tdir
3503 $RUNAS createmany -m ${testfile} 100 ||
3504 error "create many files failed"
3506 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3507 # one more count for directory itself */
3511 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3512 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3514 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3515 [ $proj_count1 -eq $proj_count ] ||
3516 error "c2: expected $proj_count got $proj_count1"
3518 #clear project but with kept projid
3519 change_project -rCk $DIR/$tdir
3520 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3521 [ $proj_count1 -eq 1 ] ||
3522 error "c3: expected 1 got $proj_count1"
3524 #verify projid untouched.
3525 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3527 [ $proj_count1 -eq $proj_count ] ||
3528 error "c4: expected $proj_count got $proj_count1"
3531 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3532 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3533 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3535 #this time clear all
3536 change_project -rC $DIR/$tdir
3537 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3538 [ $proj_count1 -eq 0 ] ||
3539 error "c6: expected 0 got $proj_count1"
3541 unlinkmany ${testfile} 100 ||
3542 error "unlink many files failed"
3546 run_test 54 "basic lfs project interface test"
3549 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3550 skip "Not supported before 2.10.58."
3551 setup_quota_test || error "setup quota failed with $?"
3553 set_ost_qtype $QTYPE || error "enable ost quota failed"
3556 #add second group to TSTUSR
3557 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3560 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3561 error "failed to dd"
3563 cancel_lru_locks osc
3564 sync; sync_all_data || true
3566 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3567 error "failed to setquota on group $TSTUSR2"
3569 $LFS quota -v -g $TSTUSR2 $DIR
3571 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3572 error "chgrp should failed with -EDQUOT"
3574 USED=$(getquota -g $TSTUSR2 global curspace)
3577 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3578 error "failed to setquota on group $TSTUSR2"
3580 $LFS quota -v -g $TSTUSR2 $DIR
3582 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3583 error "chgrp should succeed"
3585 $LFS quota -v -g $TSTUSR2 $DIR
3589 run_test 55 "Chgrp should be affected by group quota"
3592 setup_quota_test || error "setup quota failed with $?"
3594 set_ost_qtype $QTYPE || error "enable ost quota failed"
3597 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3598 erro "failed to set grace time for usr quota"
3599 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3600 awk '{print $4 $8}')
3601 if [ "x$grace_time" != "x10s;10s" ]; then
3602 $LFS quota -t -u $DIR
3603 error "expected grace time: 10s;10s, got:$grace_time"
3608 run_test 56 "lfs quota -t should work well"
3611 setup_quota_test || error "setup quota failed with $?"
3613 local dir="$DIR/$tdir/dir"
3616 #try to change pipe file should not hang and return failure
3617 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3618 awk -F ':' '{ print \\\$2 }'" \
3619 " unable to get xattr for fifo '$dir/pipe'" || return 1
3620 #command can process further if it hit some errors
3621 touch $dir/aaa $dir/bbb
3622 mkdir $dir/subdir -p
3623 touch $dir/subdir/aaa $dir/subdir/bbb
3624 #create one invalid link file
3625 ln -s $dir/not_exist_file $dir/ccc
3626 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3627 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3631 run_test 57 "lfs project could tolerate errors"
3634 [ "$mds1_FSTYPE" != ldiskfs ] &&
3635 skip "ldiskfs only test"
3636 disable_project_quota
3637 setup_quota_test || error "setup quota failed with $?"
3640 local testfile="$DIR/$tdir/$tfile-0"
3641 #make sure it did not crash kernel
3642 touch $testfile && lfs project -sp 1 $testfile
3644 enable_project_quota
3647 run_test 59 "lfs project dosen't crash kernel with project disabled"
3650 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3651 skip "Needs MDS version 2.11.53 or later."
3652 setup_quota_test || error "setup quota failed with $?"
3653 trap cleanup_quota_test EXIT
3655 local testfile=$DIR/$tdir/$tfile
3658 set_mdt_qtype "ug" || error "enable mdt quota failed"
3660 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3661 error "set quota failed"
3662 quota_show_check a g $TSTUSR
3664 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3665 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3666 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3667 error "create many files failed"
3669 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3671 # root user can overrun quota
3672 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3673 error "root user should succeed"
3677 run_test 60 "Test quota for root with setgid"
3679 # test default quota
3680 test_default_quota() {
3681 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3682 skip "Not supported before 2.11.51."
3687 local qprjid=$TSTPRJID
3691 local LIMIT=20480 #20M disk space
3692 local TESTFILE="$DIR/$tdir/$tfile-0"
3694 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3695 echo "Project quota is not supported" && return 0
3697 [ $qtype == "-u" ] && qdtype="-U"
3698 [ $qtype == "-g" ] && qdtype="-G"
3699 [ $qtype == "-p" ] && {
3704 [ $qpool == "meta" ] && {
3705 LIMIT=10240 #10K inodes
3710 setup_quota_test || error "setup quota failed with $?"
3711 trap cleanup_quota_test EXIT
3715 # enable mdt/ost quota
3716 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3717 set_ost_qtype $QTYPE || error "enable ost quota failed"
3719 log "set to use default quota"
3720 $LFS setquota $qtype $qid -d $DIR ||
3721 error "set $qid to use default quota failed"
3723 log "set default quota"
3724 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3725 error "set $qid default quota failed"
3727 log "get default quota"
3728 $LFS quota $qdtype $DIR || error "get default quota failed"
3730 if [ $qpool == "data" ]; then
3731 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3733 [ $SLIMIT -eq $LIMIT ] ||
3734 error "the returned default quota is wrong"
3736 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3738 [ $SLIMIT -eq $LIMIT ] ||
3739 error "the returned default quota is wrong"
3742 # make sure the system is clean
3743 local USED=$(getquota $qtype $qid global curspace)
3744 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3746 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3747 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3749 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3751 log "Test not out of quota"
3752 if [ $qpool == "data" ]; then
3753 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3754 quota_error $qtype $qid "write failed, expect succeed"
3756 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3757 quota_error $qtype $qid "create failed, expect succeed"
3759 unlinkmany $TESTFILE $((LIMIT/2))
3762 log "Test out of quota"
3763 # flush cache, ensure noquota flag is set on client
3764 cancel_lru_locks osc
3765 cancel_lru_locks mdc
3766 sync; sync_all_data || true
3767 if [ $qpool == "data" ]; then
3768 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3769 quota_error $qtype $qid "write succeed, expect EDQUOT"
3771 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3772 quota_error $qtype $qid "create succeed, expect EDQUOT"
3774 unlinkmany $TESTFILE $((LIMIT*2))
3777 log "Increase default quota"
3778 # increase default quota
3779 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3780 error "set default quota failed"
3782 cancel_lru_locks osc
3783 cancel_lru_locks mdc
3784 sync; sync_all_data || true
3785 if [ $qpool == "data" ]; then
3786 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3787 quota_error $qtype $qid "write failed, expect succeed"
3789 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3790 quota_error $qtype $qid "create failed, expect succeed"
3792 unlinkmany $TESTFILE $((LIMIT*2))
3795 log "Set quota to override default quota"
3796 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3797 error "set $qid quota failed"
3799 cancel_lru_locks osc
3800 cancel_lru_locks mdc
3801 sync; sync_all_data || true
3802 if [ $qpool == "data" ]; then
3803 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3804 quota_error $qtype $qid "write succeed, expect EQUOT"
3806 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3807 quota_error $qtype $qid "create succeed, expect EQUOT"
3809 unlinkmany $TESTFILE $((LIMIT*2))
3812 log "Set to use default quota again"
3813 $LFS setquota $qtype $qid -d $DIR ||
3814 error "set $qid to use default quota failed"
3816 cancel_lru_locks osc
3817 cancel_lru_locks mdc
3818 sync; sync_all_data || true
3819 if [ $qpool == "data" ]; then
3820 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3821 quota_error $qtype $qid "write failed, expect succeed"
3823 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3824 quota_error $qtype $qid "create failed, expect succeed"
3826 unlinkmany $TESTFILE $((LIMIT*2))
3831 wait_delete_completed || error "wait_delete_completed failed"
3832 sync_all_data || true
3833 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3834 error "reset default quota failed"
3835 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3836 error "reset quota failed"
3842 test_default_quota "-u" "data"
3843 test_default_quota "-u" "meta"
3844 test_default_quota "-g" "data"
3845 test_default_quota "-g" "meta"
3846 test_default_quota "-p" "data"
3847 test_default_quota "-p" "meta"
3849 run_test 61 "default quota tests"
3852 ! is_project_quota_supported &&
3853 skip "Project quota is not supported"
3854 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3855 skip "chattr did not support project quota"
3856 setup_quota_test || error "setup quota failed with $?"
3857 local testdir=$DIR/$tdir/
3859 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3860 change_project -s $testdir
3861 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3862 error "inherit attribute should be set"
3863 # chattr used FS_IOC_SETFLAGS ioctl
3864 $RUNAS chattr -P $testdir &&
3865 error "regular user clear inherit should fail"
3866 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3867 error "inherit attribute should still be set"
3868 chattr -P $testdir || error "root failed to clear inherit"
3869 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3870 error "inherit attribute should be cleared"
3873 run_test 62 "Project inherit should be only changed by root"
3876 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3877 skip "Not supported before 2.11.55"
3881 local dd_failed=false
3882 local tdir_dom=${tdir}_dom
3883 local LIMIT=20480 #20M
3885 [ $qtype == "p" ] && ! is_project_quota_supported &&
3886 echo "Project quota is not supported" && return 0
3888 [ $qtype == "p" ] && qid=$TSTPRJID
3890 setup_quota_test || error "setup quota failed with $?"
3891 trap cleanup_quota_test EXIT
3895 # enable mdt/ost quota
3896 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3897 set_ost_qtype $QTYPE || error "enable ost quota failed"
3899 # make sure the system is clean
3900 local USED=$(getquota -$qtype $qid global curspace)
3901 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3903 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3905 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3906 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3907 error "setstripe $tdir_dom failed"
3908 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3910 [ $qtype == "p" ] && {
3911 change_project -sp $TSTPRJID $DIR/$tdir
3912 change_project -sp $TSTPRJID $DIR/$tdir_dom
3915 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3916 error "set $qid quota failed"
3918 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3919 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3923 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3925 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3926 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3930 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3932 rm -f $DIR/$tdir_dom/*
3934 # flush cache, ensure noquota flag is set on client
3935 cancel_lru_locks osc
3936 cancel_lru_locks mdc
3937 sync; sync_all_data || true
3941 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3942 quota_error $qtype $qid "write failed, expect succeed"
3944 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3945 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3949 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3952 rm -f $DIR/$tdir_dom/*
3954 # flush cache, ensure noquota flag is set on client
3955 cancel_lru_locks osc
3956 cancel_lru_locks mdc
3957 sync; sync_all_data || true
3961 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3962 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3966 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3968 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3969 quota_error $qtype $qid "write succeed, expect EDQUOT"
3972 rm -fr $DIR/$tdir_dom
3974 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3975 error "reset usr quota failed"
3985 run_test 63 "quota on DoM tests"
3988 ! is_project_quota_supported &&
3989 skip "Project quota is not supported"
3990 setup_quota_test || error "setup quota failed with $?"
3991 local dir1="$DIR/$tdir/"
3994 ln -s $dir1/file $dir1/file_link
3996 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3997 error "set symlink file's project should fail"
3999 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4000 error "get symlink file's project should fail"
4004 run_test 64 "lfs project on symlink files should fail"
4008 local TESTFILE="$DIR/$tdir/$tfile-0"
4010 setup_quota_test || error "setup quota failed with $?"
4011 set_ost_qtype $QTYPE || error "enable ost quota failed"
4015 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4016 error "failed to write"
4017 # flush cache, ensure noquota flag is set on client
4018 cancel_lru_locks osc
4019 sync; sync_all_data || true
4021 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4022 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4023 local quota_all=$($RUNAS $LFS quota $DIR)
4025 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4026 error "usr quota not match"
4027 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4028 error "grp quota not match"
4034 run_test 65 "Check lfs quota result"
4037 ! is_project_quota_supported &&
4038 skip "Project quota is not supported"
4039 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4040 skip "Not supported before 2.12.4"
4041 setup_quota_test || error "setup quota failed with $?"
4042 stack_trap cleanup_quota_test EXIT
4043 local old=$(do_facet mds1 $LCTL get_param -n \
4044 mdt.*.enable_chprojid_gid | head -1)
4045 local testdir=$DIR/$tdir/foo
4047 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4048 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4051 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4052 chown -R $TSTID:$TSTID $testdir
4053 change_project -sp $TSTPRJID $testdir
4054 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4056 $RUNAS lfs project -p 0 $testdir/foo &&
4057 error "nonroot user should fail to set projid"
4059 $RUNAS lfs project -C $testdir/foo &&
4060 error "nonroot user should fail to clear projid"
4062 change_project -C $testdir/foo || error "failed to clear project"
4064 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4065 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4066 "failed to set projid with normal user when enable_chprojid_gid=-1"
4068 $RUNAS lfs project -rC $testdir/ || error \
4069 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4071 touch $testdir/bar || error "failed touch $testdir/bar"
4072 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4073 "normal user should not be able to set projid on root owned file"
4075 change_project -p $TSTPRJID $testdir/bar || error \
4076 "root should be able to change its own file's projid"
4080 run_test 66 "nonroot user can not change project state in default"
4087 local short_qtype=${qtype:0:1}
4090 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4092 quota_usr) _runas=$RUNAS;;
4093 quota_2usr) _runas=$RUNAS2;;
4094 *) error "unknown quota parameter $4";;
4099 $_runas $DD of=$file count=$size ||
4100 quota_error $short_qtype $TSTUSR \
4101 "$qtype write failure, but expect success"
4103 cancel_lru_locks osc
4105 sync; sync_all_data || true
4114 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4116 do_facet mds1 $LCTL get_param $param |
4117 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4121 local limit=20 # 20M
4122 local testfile="$DIR/$tdir/$tfile-0"
4123 local testfile2="$DIR/$tdir/$tfile-1"
4124 local testfile3="$DIR/$tdir/$tfile-2"
4125 local qpool="qpool1"
4131 [ "$ost1_FSTYPE" == zfs ] &&
4132 skip "ZFS grants some block space together with inode"
4134 setup_quota_test || error "setup quota failed with $?"
4135 trap cleanup_quota_test EXIT
4138 set_ost_qtype $QTYPE || error "enable ost quota failed"
4141 log "User quota (block hardlimit:$limit MB)"
4142 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4143 error "set user quota failed"
4145 # make sure the system is clean
4146 used=$(getquota -u $TSTUSR global curspace)
4147 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4149 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4150 echo "granted 0x0 before write $granted"
4152 # trigger reintegration
4153 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4154 procf=${procf}quota_slave.force_reint
4155 do_facet ost1 $LCTL set_param $procf=1 ||
4156 error "force reintegration failed"
4157 wait_ost_reint "u" || error "reintegration failed"
4158 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4159 [ $granted -ne 0 ] &&
4160 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4162 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4163 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4165 # write 10 MB to testfile
4166 test_67_write "$testfile" "user" 10 "quota_usr"
4168 # create qpool and add OST1
4169 pool_add $qpool || error "pool_add failed"
4170 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4171 # as quota_usr hasn't limits, lqe may absent. But it should be
4172 # created after the 1st direct qmt_get.
4173 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4175 # check granted - should be 0, as testfile is located only on OST0
4176 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4177 echo "global granted $granted"
4178 granted=$(getgranted $qpool "dt" $TSTID "usr")
4179 echo "$qpool granted $granted"
4180 [ $granted -ne 0 ] &&
4181 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4183 # add OST0 to qpool and check granted space
4184 pool_add_targets $qpool 0 1 ||
4185 error "pool_add_targets failed"
4186 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4187 echo "Granted $granted_mb MB"
4188 #should be 10M + qunit for each OST
4189 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4190 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4192 $LFS setstripe $testfile2 -c 1 -i 1 ||
4193 error "setstripe $testfile2 failed"
4194 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4195 # Write from another user and check that qpool1
4196 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4197 test_67_write "$testfile2" "user" 10 "quota_2usr"
4198 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4199 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4200 [ $granted -ne 0 ] &&
4201 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4203 # Granted space for quota_2usr in qpool1 should appear only
4204 # when global lqe for this user becomes enforced.
4205 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4206 error "set user quota failed"
4207 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4208 echo "granted_mb $granted_mb"
4209 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4210 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4212 $LFS setstripe $testfile3 -c 1 -i 0 ||
4213 error "setstripe $testfile3 failed"
4214 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4215 test_67_write "$testfile3" "user" 10 "quota_2usr"
4216 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4217 echo "$testfile3 granted_mb $granted_mb"
4218 [ $granted_mb -eq $limit ] ||
4219 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4221 # remove OST1 from the qpool1 and check granted space
4222 # should be 0 for TSTUSR and 10M for TSTUSR2
4223 pool_remove_target $qpool 0
4224 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4225 [ $granted_mb -eq 0 ] ||
4226 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4227 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4228 [ $granted_mb -eq 10 ] ||
4229 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4232 wait_delete_completed || error "wait_delete_completed failed"
4233 sync_all_data || true
4234 used=$(getquota -u $TSTUSR global curspace)
4235 [ $used -ne 0 ] && quota_error u $TSTUSR \
4236 "user quota isn't released after deletion"
4237 resetquota -u $TSTUSR
4241 run_test 67 "quota pools recalculation"
4248 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4249 awk '/usr/ {getline; print $2}'
4254 local qpool="qpool1"
4257 setup_quota_test || error "setup quota failed with $?"
4258 stack_trap cleanup_quota_test EXIT
4261 set_ost_qtype $QTYPE || error "enable ost quota failed"
4263 # check slave number for glbal pool
4264 local nr=$(get_slave_nr "0x0" "usr")
4265 echo "nr result $nr"
4266 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4267 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4269 # create qpool and add OST1
4270 pool_add $qpool || error "pool_add failed"
4271 nr=$(get_slave_nr $qpool "usr")
4272 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4275 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4276 nr=$(get_slave_nr $qpool "usr")
4277 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4280 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4281 nr=$(get_slave_nr $qpool "usr")
4282 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4285 pool_remove_target $qpool 0
4286 nr=$(get_slave_nr $qpool "usr")
4287 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4290 pool_remove_target $qpool 1
4291 nr=$(get_slave_nr $qpool "usr")
4292 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4294 # Check again that all is fine with global pool
4295 nr=$(get_slave_nr "0x0" "usr")
4296 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4297 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4301 run_test 68 "slave number in quota pool changed after each add/remove OST"
4305 local global_limit=200 # 200M
4306 local limit=10 # 10M
4307 local testfile="$DIR/$tdir/$tfile-0"
4308 local dom0="$DIR/$tdir/dom0"
4309 local qpool="qpool1"
4312 setup_quota_test || error "setup quota failed with $?"
4313 stack_trap cleanup_quota_test EXIT
4316 set_ost_qtype $QTYPE || error "enable ost quota failed"
4317 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4319 # Save DOM only at MDT0
4320 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4321 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4323 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4325 # create qpool and add OST0
4326 pool_add $qpool || error "pool_add failed"
4327 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4329 log "User quota (block hardlimit:$global_limit MB)"
4330 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4331 error "set user quota failed"
4333 log "User quota (block hardlimit:$limit MB)"
4334 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
4335 error "set user quota failed"
4337 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4338 quota_error u $TSTUSR "write failed"
4340 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4341 oflag=sync || quota_error u $TSTUSR "write failed"
4343 $RUNAS $DD of=$testfile count=$limit || true
4345 # flush cache, ensure noquota flag is set on client
4346 cancel_lru_locks osc
4347 sync; sync_all_data || true
4349 # MDT0 shouldn't get EDQUOT with glimpse.
4350 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4351 quota_error u $TSTUSR \
4352 "user write success, but expect EDQUOT"
4354 # Now all members of qpool1 should get EDQUOT. Expect success
4355 # when write to DOM on MDT0, as it belongs to global pool.
4356 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4357 oflag=sync || quota_error u $TSTUSR "write failed"
4359 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4360 oflag=sync || quota_error u $TSTUSR "write failed"
4364 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4368 local qpool="qpool1"
4373 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4374 skip "Needs a client >= $VERSION_WITH_QP"
4376 setup_quota_test || error "setup quota failed with $?"
4377 stack_trap cleanup_quota_test EXIT
4379 # MDS returns EFAULT for unsupported quotactl command
4380 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4382 # create qpool and add OST0
4383 pool_add $qpool || error "pool_add failed"
4384 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4386 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR
4388 [ $rc -eq $err ] || error "setquota res $rc != $err"
4390 # If MDS supports QP, check that limit was set properly.
4391 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4392 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4393 echo "hard limit $bhard limit $limit"
4394 [ $bhard -ne $((limit*1024)) ] &&
4395 error "bhard:$bhard for $qpool!=$((limit*1024))"
4398 $LFS quota -u $TSTUSR --pool $qpool $DIR
4400 [ $rc -eq $err ] || error "quota res $rc != $err"
4404 run_test 70 "check lfs setquota/quota with a pool option"
4408 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4409 if $PQ_CLEANUP; then
4410 disable_project_quota
4413 reset_quota_settings
4418 check_and_cleanup_lustre
4419 export QUOTA_AUTO=$QUOTA_AUTO_OLD