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 u $TSTUSR \
930 "$qtype write failure, but expect success"
934 wait_delete_completed || error "wait_delete_completed failed"
935 sync_all_data || true
937 used=$(getquota -u $TSTUSR global curspace $qpool1)
938 [ $used -ne 0 ] && quota_error u $TSTUSR \
939 "user quota isn't released after deletion"
940 resetquota -u $TSTUSR
945 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
948 local global_limit=200 # 200M
949 local limit1=10 # 10M
950 local TESTDIR="$DIR/$tdir/"
951 local testfile="$TESTDIR/$tfile-0"
952 local qpool1="qpool1"
955 setup_quota_test || error "setup quota failed with $?"
956 stack_trap cleanup_quota_test EXIT
959 set_ost_qtype $QTYPE || error "enable ost quota failed"
961 log "User quota (block hardlimit:$global_limit MB)"
962 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
963 error "set user quota failed"
965 pool_add $qpool1 || error "pool_add failed"
966 pool_add_targets $qpool1 0 0 ||
967 error "pool_add_targets failed"
969 $LFS setquota -u $TSTUSR -B ${limit1}M -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"
1003 local limit=10 # 10M
1004 local global_limit=20 # 20M
1005 local testfile="$DIR/$tdir/$tfile-0"
1006 local qpool="qpool1"
1007 local mdmb_param="osc.*.max_dirty_mb"
1008 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1011 setup_quota_test || error "setup quota failed with $?"
1012 stack_trap cleanup_quota_test EXIT
1013 $LCTL set_param $mdmb_param=1
1014 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1017 set_ost_qtype $QTYPE || error "enable ost quota failed"
1020 log "User quota (block hardlimit:$global_limit MB)"
1021 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1022 error "set user quota failed"
1024 pool_add $qpool || error "pool_add failed"
1025 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1026 error "pool_add_targets failed"
1028 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
1029 error "set user quota failed"
1031 # make sure the system is clean
1032 local used=$(getquota -u $TSTUSR global curspace)
1034 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1036 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1037 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1040 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1041 quota_error u $TSTUSR \
1042 "$qtype write failure, but expect success"
1043 log "Write out of block quota ..."
1044 # this time maybe cache write, ignore it's failure
1045 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1046 # flush cache, ensure noquota flag is set on client
1047 cancel_lru_locks osc
1048 sync; sync_all_data || true
1050 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1051 quota_error u $TSTUSR \
1052 "user write success, but expect EDQUOT"
1055 wait_delete_completed || error "wait_delete_completed failed"
1056 sync_all_data || true
1058 used=$(getquota -u $TSTUSR global curspace $qpool)
1059 [ $used -ne 0 ] && quota_error u $TSTUSR \
1060 "user quota isn't released after deletion"
1063 run_test 1g "Quota pools: Block hard limit with wide striping"
1065 # test inode hardlimit
1067 local TESTFILE="$DIR/$tdir/$tfile-0"
1068 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
1069 qmt.$FSNAME-QMT0000.md-0x0.info |
1070 awk '/least qunit/{ print $3 }')
1071 local L2=$(do_facet mds1 $LCTL get_param -n \
1072 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1074 [ $L2 -le $LIMIT ] || LIMIT=$L2
1076 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
1078 local FREE_INODES=$(mdt_free_inodes 0)
1079 echo "$FREE_INODES free inodes on master MDT"
1080 [ $FREE_INODES -lt $LIMIT ] &&
1081 skip "not enough free inodes $FREE_INODES required $LIMIT"
1083 setup_quota_test || error "setup quota failed with $?"
1084 trap cleanup_quota_test EXIT
1087 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1090 log "User quota (inode hardlimit:$LIMIT files)"
1091 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1092 error "set user quota failed"
1094 # make sure the system is clean
1095 local USED=$(getquota -u $TSTUSR global curinodes)
1096 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
1098 log "Create $LIMIT files ..."
1099 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1100 quota_error u $TSTUSR "user create failure, but expect success"
1101 log "Create out of file quota ..."
1102 $RUNAS touch ${TESTFILE}_xxx &&
1103 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1106 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1107 rm -f ${TESTFILE}_xxx
1108 wait_delete_completed
1110 USED=$(getquota -u $TSTUSR global curinodes)
1111 [ $USED -ne 0 ] && quota_error u $TSTUSR \
1112 "user quota isn't released after deletion"
1113 resetquota -u $TSTUSR
1116 log "--------------------------------------"
1117 log "Group quota (inode hardlimit:$LIMIT files)"
1118 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1119 error "set group quota failed"
1121 TESTFILE=$DIR/$tdir/$tfile-1
1122 # make sure the system is clean
1123 USED=$(getquota -g $TSTUSR global curinodes)
1124 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
1126 log "Create $LIMIT files ..."
1127 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
1128 quota_error g $TSTUSR "group create failure, but expect success"
1129 log "Create out of file quota ..."
1130 $RUNAS touch ${TESTFILE}_xxx &&
1131 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1134 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
1135 rm -f ${TESTFILE}_xxx
1136 wait_delete_completed
1138 USED=$(getquota -g $TSTUSR global curinodes)
1139 [ $USED -ne 0 ] && quota_error g $TSTUSR \
1140 "user quota isn't released after deletion"
1142 resetquota -g $TSTUSR
1143 ! is_project_quota_supported && cleanup_quota_test &&
1144 echo "Skip project quota is not supported" && return 0
1147 log "--------------------------------------"
1148 log "Project quota (inode hardlimit:$LIMIT files)"
1149 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
1150 error "set project quota failed"
1152 TESTFILE=$DIR/$tdir/$tfile-1
1153 # make sure the system is clean
1154 USED=$(getquota -p $TSTPRJID global curinodes)
1156 error "Used inodes($USED) for project $TSTPRJID isn't 0"
1158 change_project -sp $TSTPRJID $DIR/$tdir
1159 log "Create $LIMIT files ..."
1160 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
1161 $TSTPRJID "project create fail, but expect success"
1162 log "Create out of file quota ..."
1163 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
1164 "project create success, but expect EDQUOT"
1165 change_project -C $DIR/$tdir
1168 USED=$(getquota -p $TSTPRJID global curinodes)
1169 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
1170 "project quota isn't released after deletion"
1173 run_test 2 "File hard limit (normal use and out of quota)"
1184 stack_trap cleanup_quota_test EXIT
1186 $LFS setstripe $testfile -c 1 -i 0
1187 chown $TSTUSR.$TSTUSR $testfile
1188 [ "$qtype" == "p" ] && is_project_quota_supported &&
1189 change_project -p $TSTPRJID $testfile
1191 echo "Write up to soft limit"
1192 $RUNAS $DD of=$testfile count=$limit ||
1193 quota_error a $TSTUSR "write failure, but expect success"
1194 OFFSET=$((limit * 1024))
1195 cancel_lru_locks osc
1197 echo "Write to exceed soft limit"
1198 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1199 quota_error a $TSTUSR "write failure, but expect success"
1200 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1201 cancel_lru_locks osc
1203 echo "mmap write when over soft limit"
1204 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1205 quota_error a $TSTUSR "mmap write failure, but expect success"
1206 cancel_lru_locks osc
1211 $SHOW_QUOTA_INFO_USER
1212 $SHOW_QUOTA_INFO_GROUP
1213 $SHOW_QUOTA_INFO_PROJID
1215 echo "Write before timer goes off"
1216 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1217 quota_error a $TSTUSR "write failure, but expect success"
1218 OFFSET=$((OFFSET + 1024))
1219 cancel_lru_locks osc
1221 wait_grace_time $qtype "block" $pool
1226 $SHOW_QUOTA_INFO_USER
1227 $SHOW_QUOTA_INFO_GROUP
1228 $SHOW_QUOTA_INFO_PROJID
1230 log "Write after timer goes off"
1231 # maybe cache write, ignore.
1232 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET || true
1233 OFFSET=$((OFFSET + 1024))
1234 cancel_lru_locks osc
1235 log "Write after cancel lru locks"
1236 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1237 quota_error a $TSTUSR "write success, but expect EDQUOT"
1242 $SHOW_QUOTA_INFO_USER
1243 $SHOW_QUOTA_INFO_GROUP
1244 $SHOW_QUOTA_INFO_PROJID
1246 echo "Unlink file to stop timer"
1248 wait_delete_completed
1249 sync_all_data || true
1254 $SHOW_QUOTA_INFO_USER
1255 $SHOW_QUOTA_INFO_GROUP
1256 $SHOW_QUOTA_INFO_PROJID
1258 $LFS setstripe $testfile -c 1 -i 0
1259 chown $TSTUSR.$TSTUSR $testfile
1260 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1263 $RUNAS $DD of=$testfile count=$limit ||
1264 quota_error a $TSTUSR "write failure, but expect success"
1271 local grace=20 # 20s
1272 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1275 local testfile=$DIR/$tdir/$tfile-0
1277 # get minimum soft qunit size
1278 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1279 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1281 set_ost_qtype $QTYPE || error "enable ost quota failed"
1283 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1284 # make sure the system is clean
1285 local used=$(getquota -u $TSTUSR global curspace)
1286 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1288 $LFS setquota -t -u --block-grace $grace --inode-grace \
1289 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1290 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1291 error "set user quota failed"
1293 test_block_soft $testfile $grace $limit "u"
1295 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1296 testfile=$DIR/$tdir/$tfile-1
1297 # make sure the system is clean
1298 used=$(getquota -g $TSTUSR global curspace)
1299 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1301 $LFS setquota -t -g --block-grace $grace --inode-grace \
1302 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1303 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1304 error "set group quota failed"
1306 test_block_soft $testfile $grace $limit "g"
1308 if is_project_quota_supported; then
1309 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1310 testfile=$DIR/$tdir/$tfile-2
1311 # make sure the system is clean
1312 used=$(getquota -p $TSTPRJID global curspace)
1313 [ $used -ne 0 ] && error \
1314 "Used space($used) for project $TSTPRJID isn't 0."
1316 $LFS setquota -t -p --block-grace $grace --inode-grace \
1317 $MAX_IQ_TIME $DIR ||
1318 error "set project grace time failed"
1319 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1320 $DIR || error "set project quota failed"
1322 test_block_soft $testfile $grace $limit "p"
1323 resetquota -p $TSTPRJID
1324 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1325 $MAX_IQ_TIME $DIR ||
1326 error "restore project grace time failed"
1330 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1331 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1332 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1333 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1335 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1338 local grace=20 # 20s
1339 local qpool="qpool1"
1340 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1343 local testfile=$DIR/$tdir/$tfile-0
1346 # get minimum soft qunit size
1347 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1348 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1349 local glbl_limit=$((2*limit))
1350 local glbl_grace=$((2*grace))
1351 echo "limit $limit glbl_limit $glbl_limit"
1352 echo "grace $grace glbl_grace $glbl_grace"
1354 set_ost_qtype $QTYPE || error "enable ost quota failed"
1356 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1357 # make sure the system is clean
1358 local used=$(getquota -u $TSTUSR global curspace)
1359 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1361 pool_add $qpool || error "pool_add failed"
1362 pool_add_targets $qpool 0 1 ||
1363 error "pool_add_targets failed"
1365 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1366 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1367 $LFS setquota -t -u --block-grace $grace \
1368 -o $qpool $DIR || error "set user grace time failed"
1370 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1371 error "set user quota failed"
1372 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1373 error "set user quota failed"
1375 test_block_soft $testfile $grace $limit "u" $qpool
1377 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1378 testfile=$DIR/$tdir/$tfile-1
1379 # make sure the system is clean
1380 used=$(getquota -g $TSTUSR global curspace)
1381 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1383 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1384 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1385 $LFS setquota -t -g --block-grace $grace \
1386 -o $qpool $DIR || error "set group grace time failed"
1388 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1389 error "set group quota failed"
1390 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1391 error "set group quota failed"
1393 test_block_soft $testfile $grace $limit "g" $qpool
1395 if is_project_quota_supported; then
1396 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1397 testfile=$DIR/$tdir/$tfile-2
1398 # make sure the system is clean
1399 used=$(getquota -p $TSTPRJID global curspace)
1400 [ $used -ne 0 ] && error \
1401 "Used space($used) for project $TSTPRJID isn't 0."
1403 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1404 $MAX_IQ_TIME $DIR ||
1405 error "set project grace time failed"
1406 $LFS setquota -t -p --block-grace $grace \
1407 -o $qpool $DIR || error "set project grace time failed"
1409 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1410 $DIR || error "set project quota failed"
1411 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -o $qpool $DIR ||
1412 error "set project quota failed"
1414 test_block_soft $testfile $grace $limit "p" $qpool
1415 resetquota -p $TSTPRJID
1416 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1417 $MAX_IQ_TIME $DIR ||
1418 error "restore project grace time failed"
1419 $LFS setquota -t -p --block-grace $MAX_DQ_TIME -o $qpool $DIR ||
1420 error "set project grace time failed"
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 -g --block-grace $MAX_DQ_TIME --inode-grace \
1429 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1430 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1431 -o $qpool $DIR || error "restore group grace time failed"
1433 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1436 local grace=20 # 20s
1437 local qpool="qpool1"
1438 local qpool2="qpool2"
1439 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1442 local testfile=$DIR/$tdir/$tfile-0
1445 # get minimum soft qunit size
1446 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1447 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1448 local limit2=$((limit+4))
1449 local glbl_limit=$((limit+8))
1450 local grace1=$((grace+10))
1452 local glbl_grace=$((grace+20))
1453 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1454 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1456 set_ost_qtype $QTYPE || error "enable ost quota failed"
1458 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1459 # make sure the system is clean
1460 local used=$(getquota -u $TSTUSR global curspace)
1461 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1463 pool_add $qpool || error "pool_add failed"
1464 pool_add_targets $qpool 0 1 ||
1465 error "pool_add_targets failed"
1467 pool_add $qpool2 || error "pool_add failed"
1468 pool_add_targets $qpool2 0 1 ||
1469 error "pool_add_targets failed"
1472 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1473 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1474 $LFS setquota -t -u --block-grace $grace1 \
1475 -o $qpool $DIR || error "set user grace time failed"
1476 $LFS setquota -t -u --block-grace $grace2 \
1477 -o $qpool2 $DIR || error "set user grace time failed"
1479 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1480 error "set user quota failed"
1481 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -o $qpool $DIR ||
1482 error "set user quota failed"
1483 # qpool has minimum soft limit, but it's grace is grater than
1484 # grace period of qpool2. Thus write shouldn't fail when
1485 # hit qpool soft limit - only when reaches up qpool2 limit
1486 # after grace2 seconds.
1487 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 -o $qpool2 $DIR ||
1488 error "set user quota failed"
1490 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1493 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1494 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1495 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1496 -o $qpool $DIR || error "restore user grace time failed"
1497 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1498 -o $qpool2 $DIR || error "restore user grace time failed"
1500 run_test 3c "Quota pools: check block soft limit on different pools"
1509 trap cleanup_quota_test EXIT
1510 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1512 echo "Create files to exceed soft limit"
1513 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1514 quota_error a $TSTUSR "create failure, but expect success"
1515 local trigger_time=$(date +%s)
1517 sync_all_data || true
1519 local cur_time=$(date +%s)
1520 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1521 error "Passed grace time $grace, $trigger_time, $cur_time"
1523 echo "Create file before timer goes off"
1524 $RUNAS touch ${TESTFILE}_before ||
1525 quota_error a $TSTUSR "failed create before timer expired," \
1526 "but expect success. $trigger_time, $cur_time"
1527 sync_all_data || true
1529 wait_grace_time $qtype "file"
1534 $SHOW_QUOTA_INFO_USER
1535 $SHOW_QUOTA_INFO_GROUP
1536 $SHOW_QUOTA_INFO_PROJID
1538 echo "Create file after timer goes off"
1539 # There is a window that space is accounted in the quota usage but
1540 # hasn't been decreased from the pending write, if we acquire quota
1541 # in this window, we'll acquire more than we needed.
1542 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
1543 sync_all_data || true
1544 $RUNAS touch ${TESTFILE}_after_3 &&
1545 quota_error a $TSTUSR "create after timer expired," \
1547 sync_all_data || true
1552 $SHOW_QUOTA_INFO_USER
1553 $SHOW_QUOTA_INFO_GROUP
1554 $SHOW_QUOTA_INFO_PROJID
1556 echo "Unlink files to stop timer"
1557 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1558 wait_delete_completed
1561 $RUNAS touch ${TESTFILE}_xxx ||
1562 quota_error a $TSTUSR "touch after timer stop failure," \
1563 "but expect success"
1564 sync_all_data || true
1572 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1573 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1574 local TESTFILE=$DIR/$tdir/$tfile-0
1577 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1579 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1580 # make sure the system is clean
1581 local USED=$(getquota -u $TSTUSR global curinodes)
1582 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1584 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1585 $GRACE $DIR || error "set user grace time failed"
1586 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1587 error "set user quota failed"
1589 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1591 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1593 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1594 # make sure the system is clean
1595 USED=$(getquota -g $TSTUSR global curinodes)
1596 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1598 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1599 $GRACE $DIR || error "set group grace time failed"
1600 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1601 error "set group quota failed"
1602 TESTFILE=$DIR/$tdir/$tfile-1
1604 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1606 if is_project_quota_supported; then
1607 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1608 # make sure the system is clean
1609 USED=$(getquota -p $TSTPRJID global curinodes)
1610 [ $USED -ne 0 ] && error \
1611 "Used space($USED) for project $TSTPRJID isn't 0."
1613 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1614 $GRACE $DIR || error "set project grace time failed"
1615 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1616 error "set project quota failed"
1618 TESTFILE=$DIR/$tdir/$tfile-1
1619 # one less than limit, because of parent directory included.
1620 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1621 resetquota -p $TSTPRJID
1622 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1623 $MAX_IQ_TIME $DIR ||
1624 error "restore project grace time failed"
1628 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1629 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1630 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1631 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1633 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1636 local GR_STR1="1w3d"
1637 local GR_STR2="1000s"
1639 local GR_STR4="1w2d3h4m5s"
1641 local GR_STR6="18446744073709551615"
1644 wait_delete_completed
1646 # test of valid grace strings handling
1647 echo "Valid grace strings test"
1648 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1649 $GR_STR2 $DIR || error "set user grace time failed"
1650 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1651 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1652 $GR_STR4 $DIR || error "set group grace time quota failed"
1653 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1655 # test of invalid grace strings handling
1656 echo " Invalid grace strings test"
1657 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1658 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1659 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1663 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1664 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1665 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1666 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1668 run_test 4b "Grace time strings handling"
1670 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1672 local BLIMIT=10 # 10M
1673 local ILIMIT=10 # 10 inodes
1675 setup_quota_test || error "setup quota failed with $?"
1676 trap cleanup_quota_test EXIT
1678 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1679 set_ost_qtype $QTYPE || error "enable ost quota failed"
1681 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1682 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1683 error "set user quota failed"
1684 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1685 if is_project_quota_supported; then
1686 error "set group quota failed"
1687 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1688 -I $ILIMIT $DIR || error "set project quota failed"
1691 # make sure the system is clean
1692 local USED=$(getquota -u $TSTUSR global curinodes)
1693 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1694 USED=$(getquota -g $TSTUSR global curinodes)
1695 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1696 USED=$(getquota -u $TSTUSR global curspace)
1697 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1698 USED=$(getquota -g $TSTUSR global curspace)
1699 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1700 if is_project_quota_supported; then
1701 USED=$(getquota -p $TSTPRJID global curinodes)
1703 error "Used inode($USED) for project $TSTPRJID isn't 0."
1704 USED=$(getquota -p $TSTPRJID global curspace)
1706 error "Used block($USED) for project $TSTPRJID isn't 0."
1709 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1710 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1711 error "create failure, expect success"
1712 if is_project_quota_supported; then
1713 touch $DIR/$tdir/$tfile-0_1
1714 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1716 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1717 error "write failure, expect success"
1719 echo "Chown files to $TSTUSR.$TSTUSR ..."
1720 for i in $(seq 0 $ILIMIT); do
1721 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1722 quota_error a $TSTUSR "chown failure, expect success"
1726 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1727 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1730 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1732 # test dropping acquire request on master
1736 # Clear dmesg so watchdog is not triggered by previous
1738 do_facet ost1 dmesg -c > /dev/null
1740 setup_quota_test || error "setup quota failed with $?"
1741 trap cleanup_quota_test EXIT
1743 # make sure the system is clean
1744 local USED=$(getquota -u $TSTUSR global curspace)
1745 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1747 # make sure no granted quota on ost
1748 set_ost_qtype $QTYPE || error "enable ost quota failed"
1749 resetquota -u $TSTUSR
1751 # create file for $TSTUSR
1752 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1753 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1754 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1756 # create file for $TSTUSR2
1757 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1758 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1759 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1761 # cache per-ID lock for $TSTUSR on slave
1762 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1763 error "set quota failed"
1764 $RUNAS $DD of=$TESTFILE count=1 ||
1765 error "write $TESTFILE failure, expect success"
1766 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1767 error "write $TESTFILE2 failure, expect success"
1769 if at_is_enabled; then
1770 at_max_saved=$(at_max_get ost1)
1771 at_max_set $TIMEOUT ost1
1773 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1774 # DQACQ is sent, which makes at_max to take effect
1775 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1778 wait_delete_completed
1782 sync_all_data || true
1784 #define QUOTA_DQACQ 601
1785 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1786 lustre_fail mds 0x513 601
1788 do_facet ost1 $LCTL set_param \
1789 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1791 # write to un-enforced ID ($TSTUSR2) should succeed
1792 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1793 error "write failure, expect success"
1795 # write to enforced ID ($TSTUSR) in background, exceeding limit
1796 # to make sure DQACQ is sent
1797 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1800 # watchdog timer uses a factor of 2
1801 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1802 sleep $((TIMEOUT * 2 + 1))
1804 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1806 # write should be blocked and never finished
1807 if ! ps -p $DDPID > /dev/null 2>&1; then
1809 error "write finished incorrectly!"
1814 # no watchdog is triggered
1815 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1816 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1817 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1818 [ -z "$watchdog" ] || error "$watchdog"
1820 rm -f $TMP/lustre-log-${TESTNAME}.log
1822 # write should continue then fail with EDQUOT
1826 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1827 if [ $count -ge 240 ]; then
1828 quota_error u $TSTUSR "dd not finished in $count secs"
1830 count=$((count + 1))
1831 if [ $((count % 30)) -eq 0 ]; then
1832 c_size=$(stat -c %s $TESTFILE)
1833 echo "Waiting $count secs. $c_size"
1841 run_test 6 "Test dropping acquire request on master"
1843 # quota reintegration (global index)
1845 local TESTFILE=$DIR/$tdir/$tfile
1846 local LIMIT=20 # 20M
1848 [ "$SLOW" = "no" ] && LIMIT=5
1850 setup_quota_test || error "setup quota failed with $?"
1851 trap cleanup_quota_test EXIT
1853 # make sure the system is clean
1854 local USED=$(getquota -u $TSTUSR global curspace)
1855 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1857 # make sure no granted quota on ost1
1858 set_ost_qtype $QTYPE || error "enable ost quota failed"
1859 resetquota -u $TSTUSR
1860 set_ost_qtype "none" || error "disable ost quota failed"
1862 local OSTUUID=$(ostuuid_from_index 0)
1863 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1865 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1868 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1869 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1874 echo "Enable quota & set quota limit for $TSTUSR"
1875 set_ost_qtype $QTYPE || error "enable ost quota failed"
1876 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1877 error "set quota failed"
1879 echo "Start ost1..."
1880 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1883 wait_ost_reint $QTYPE || error "reintegration failed"
1885 # hardlimit should have been fetched by slave during global
1886 # reintegration, write will exceed quota
1887 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1888 quota_error u $TSTUSR "write success, but expect EDQUOT"
1891 wait_delete_completed
1892 sync_all_data || true
1898 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1899 error "clear quota failed"
1901 echo "Start ost1..."
1902 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1905 wait_ost_reint $QTYPE || error "reintegration failed"
1907 # hardlimit should be cleared on slave during reintegration
1908 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1909 quota_error u $TSTUSR "write error, but expect success"
1913 run_test 7a "Quota reintegration (global index)"
1915 # quota reintegration (slave index)
1918 local TESTFILE=$DIR/$tdir/$tfile
1920 setup_quota_test || error "setup quota failed with $?"
1921 trap cleanup_quota_test EXIT
1923 # make sure the system is clean
1924 local USED=$(getquota -u $TSTUSR global curspace)
1925 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1927 # make sure no granted quota on ost1
1928 set_ost_qtype $QTYPE || error "enable ost quota failed"
1929 resetquota -u $TSTUSR
1930 set_ost_qtype "none" || error "disable ost quota failed"
1932 local OSTUUID=$(ostuuid_from_index 0)
1933 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1935 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1938 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1939 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1941 # consume some space to make sure the granted space will not
1942 # be released during reconciliation
1943 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1944 error "consume space failure, expect success"
1946 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1947 lustre_fail mds 0xa02
1949 set_ost_qtype $QTYPE || error "enable ost quota failed"
1950 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1951 error "set quota failed"
1953 # ignore the write error
1954 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1956 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1960 echo "Restart ost to trigger reintegration..."
1962 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1965 wait_ost_reint $QTYPE || error "reintegration failed"
1967 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1968 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1973 run_test 7b "Quota reintegration (slave index)"
1975 # quota reintegration (restart mds during reintegration)
1977 local LIMIT=20 # 20M
1978 local TESTFILE=$DIR/$tdir/$tfile
1980 [ "$SLOW" = "no" ] && LIMIT=5
1982 setup_quota_test || error "setup quota failed with $?"
1983 trap cleanup_quota_test EXIT
1985 # make sure the system is clean
1986 local USED=$(getquota -u $TSTUSR global curspace)
1987 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1989 set_ost_qtype "none" || error "disable ost quota failed"
1990 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1991 error "set quota failed"
1993 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1994 lustre_fail ost 0xa03
1997 set_ost_qtype $QTYPE || error "enable ost quota failed"
1998 # trigger reintegration
1999 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2000 procf=${procf}quota_slave.force_reint
2001 do_facet ost1 $LCTL set_param $procf=1 ||
2002 error "force reintegration failed"
2010 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2013 # wait longer than usual to make sure the reintegration
2014 # is triggered by quota wb thread.
2015 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2017 # hardlimit should have been fetched by slave during global
2018 # reintegration, write will exceed quota
2019 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2020 quota_error u $TSTUSR "write success, but expect EDQUOT"
2024 run_test 7c "Quota reintegration (restart mds during reintegration)"
2026 # Quota reintegration (Transfer index in multiple bulks)
2028 local TESTFILE=$DIR/$tdir/$tfile
2029 local TESTFILE1="$DIR/$tdir/$tfile"-1
2032 setup_quota_test || error "setup quota failed with $?"
2033 trap cleanup_quota_test EXIT
2035 set_ost_qtype "none" || error "disable ost quota failed"
2036 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2037 error "set quota for $TSTUSR failed"
2038 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2039 error "set quota for $TSTUSR2 failed"
2041 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2042 lustre_fail mds 0x608 0
2044 # enable quota to tirgger reintegration
2045 set_ost_qtype "u" || error "enable ost quota failed"
2046 wait_ost_reint "u" || error "reintegration failed"
2050 # hardlimit should have been fetched by slave during global
2051 # reintegration, write will exceed quota
2052 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2053 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2055 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2056 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2060 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2062 # quota reintegration (inode limits)
2064 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2066 # LU-2435: skip this quota test if underlying zfs version has not
2067 # supported native dnode accounting
2068 [ "$mds1_FSTYPE" == zfs ] && {
2069 local F="feature@userobj_accounting"
2070 local pool=$(zpool_name mds1)
2071 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2073 [[ "$feature" != *" active "* ]] &&
2074 skip "requires zpool with active userobj_accounting"
2077 local ilimit=$((1024 * 2)) # 2k inodes
2078 local TESTFILE=$DIR/${tdir}-1/$tfile
2080 setup_quota_test || error "setup quota failed with $?"
2081 trap cleanup_quota_test EXIT
2083 # make sure the system is clean
2084 local USED=$(getquota -u $TSTUSR global curinodes)
2085 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2087 # make sure no granted quota on mdt1
2088 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2089 resetquota -u $TSTUSR
2090 set_mdt_qtype "none" || error "disable mdt quota failed"
2092 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2093 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2094 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2097 echo "Stop mds${MDSCOUNT}..."
2100 echo "Enable quota & set quota limit for $TSTUSR"
2101 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2102 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2103 error "set quota failed"
2105 echo "Start mds${MDSCOUNT}..."
2106 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2109 wait_mdt_reint $QTYPE || error "reintegration failed"
2111 echo "create remote dir"
2112 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2113 error "create remote dir failed"
2114 chmod 0777 $DIR/${tdir}-1
2116 # hardlimit should have been fetched by slave during global
2117 # reintegration, create will exceed quota
2118 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2119 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2121 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2122 wait_delete_completed
2123 sync_all_data || true
2125 echo "Stop mds${MDSCOUNT}..."
2128 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2129 error "clear quota failed"
2131 echo "Start mds${MDSCOUNT}..."
2132 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2135 wait_mdt_reint $QTYPE || error "reintegration failed"
2137 # hardlimit should be cleared on slave during reintegration
2138 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2139 quota_error u $TSTUSR "create failed, expect success"
2141 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2142 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2146 run_test 7e "Quota reintegration (inode limits)"
2148 # run dbench with quota enabled
2150 local BLK_LIMIT="100g" #100G
2151 local FILE_LIMIT=1000000
2153 setup_quota_test || error "setup quota failed with $?"
2154 trap cleanup_quota_test EXIT
2156 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2157 set_ost_qtype $QTYPE || error "enable ost quota failed"
2159 echo "Set enough high limit for user: $TSTUSR"
2160 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2161 error "set user quota failed"
2162 echo "Set enough high limit for group: $TSTUSR"
2163 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2164 error "set group quota failed"
2165 if is_project_quota_supported; then
2166 change_project -sp $TSTPRJID $DIR/$tdir
2167 echo "Set enough high limit for project: $TSTPRJID"
2168 $LFS setquota -p $TSTPRJID -b 0 \
2169 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2170 error "set project quota failed"
2174 [ "$SLOW" = "no" ] && duration=" -t 120"
2175 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2176 quota_error a $TSTUSR "dbench failed!"
2178 is_project_quota_supported && change_project -C $DIR/$tdir
2181 run_test 8 "Run dbench with quota enabled"
2183 # this check is just for test_9
2184 OST0_MIN=4900000 #4.67G
2186 check_whether_skip () {
2187 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2188 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2189 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2190 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2197 # run for fixing bug10707, it needs a big room. test for 64bit
2199 local filesize=$((1024 * 9 / 2)) # 4.5G
2201 check_whether_skip && return 0
2203 setup_quota_test || error "setup quota failed with $?"
2204 trap cleanup_quota_test EXIT
2206 set_ost_qtype "ug" || error "enable ost quota failed"
2208 local TESTFILE="$DIR/$tdir/$tfile-0"
2209 local BLK_LIMIT=100G #100G
2210 local FILE_LIMIT=1000000
2212 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2214 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2216 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2217 error "set user quota failed"
2219 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2220 "for group: $TSTUSR"
2221 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2222 error "set group quota failed"
2224 quota_show_check a u $TSTUSR
2225 quota_show_check a g $TSTUSR
2227 echo "Create test file"
2228 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2229 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2231 log "Write the big file of 4.5G ..."
2232 $RUNAS $DD of=$TESTFILE count=$filesize ||
2233 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2243 run_test 9 "Block limit larger than 4GB (b10707)"
2246 local TESTFILE=$DIR/$tdir/$tfile
2248 setup_quota_test || error "setup quota failed with $?"
2249 trap cleanup_quota_test EXIT
2251 # set limit to root user should fail
2252 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2253 error "set limit for root user successfully, expect failure"
2254 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2255 error "set limit for root group successfully, expect failure"
2256 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2257 error "set limit for project 0 successfully, expect failure"
2259 # root user can overrun quota
2260 set_ost_qtype "ug" || error "enable ost quota failed"
2262 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2263 error "set quota failed"
2264 quota_show_check b u $TSTUSR
2266 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2267 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2269 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2270 error "write failure, expect success"
2274 run_test 10 "Test quota for root user"
2277 local TESTFILE=$DIR/$tdir/$tfile
2278 setup_quota_test || error "setup quota failed with $?"
2279 trap cleanup_quota_test EXIT
2281 set_mdt_qtype "ug" || error "enable mdt quota failed"
2282 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2283 error "set quota failed"
2285 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2286 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2288 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2289 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2292 local USED=$(getquota -u $TSTUSR global curinodes)
2293 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2297 run_test 11 "Chown/chgrp ignores quota"
2300 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2302 local blimit=22 # 22M
2303 local blk_cnt=$((blimit - 5))
2304 local TESTFILE0="$DIR/$tdir/$tfile"-0
2305 local TESTFILE1="$DIR/$tdir/$tfile"-1
2307 setup_quota_test || error "setup quota failed with $?"
2308 trap cleanup_quota_test EXIT
2310 set_ost_qtype "u" || error "enable ost quota failed"
2311 quota_show_check b u $TSTUSR
2313 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
2314 error "set quota failed"
2316 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2317 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2318 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2319 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2321 echo "Write to ost0..."
2322 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2323 quota_error a $TSTUSR "dd failed"
2325 echo "Write to ost1..."
2326 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2327 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2329 echo "Free space from ost0..."
2331 wait_delete_completed
2332 sync_all_data || true
2334 echo "Write to ost1 after space freed from ost0..."
2335 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2336 quota_error a $TSTUSR "rebalancing failed"
2340 run_test 12a "Block quota rebalancing"
2343 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2345 local ilimit=$((1024 * 2)) # 2k inodes
2346 local TESTFILE0=$DIR/$tdir/$tfile
2347 local TESTFILE1=$DIR/${tdir}-1/$tfile
2349 setup_quota_test || error "setup quota failed with $?"
2350 trap cleanup_quota_test EXIT
2352 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2353 chmod 0777 $DIR/${tdir}-1
2355 set_mdt_qtype "u" || error "enable mdt quota failed"
2356 quota_show_check f u $TSTUSR
2358 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2359 error "set quota failed"
2361 echo "Create $ilimit files on mdt0..."
2362 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2363 quota_error u $TSTUSR "create failed, but expect success"
2365 echo "Create files on mdt1..."
2366 $RUNAS createmany -m $TESTFILE1 1 &&
2367 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2369 echo "Free space from mdt0..."
2370 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2371 wait_delete_completed
2372 sync_all_data || true
2374 echo "Create files on mdt1 after space freed from mdt0..."
2375 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2376 quota_error a $TSTUSR "rebalancing failed"
2378 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2379 error "unlink mdt1 files failed"
2380 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2384 run_test 12b "Inode quota rebalancing"
2387 local TESTFILE=$DIR/$tdir/$tfile
2388 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2389 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2391 setup_quota_test || error "setup quota failed with $?"
2392 trap cleanup_quota_test EXIT
2394 set_ost_qtype "u" || error "enable ost quota failed"
2395 quota_show_check b u $TSTUSR
2397 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2398 error "set quota failed"
2399 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2400 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2402 # clear the locks in cache first
2403 do_facet ost1 $LCTL set_param -n $procf=clear
2404 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2405 [ $nlock -eq 0 ] || error "$nlock cached locks"
2407 # write to acquire the per-ID lock
2408 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2409 quota_error a $TSTUSR "dd failed"
2411 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2412 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2414 # clear quota doesn't trigger per-ID lock cancellation
2415 resetquota -u $TSTUSR
2416 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2417 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2419 # clear the per-ID lock
2420 do_facet ost1 $LCTL set_param -n $procf=clear
2421 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2422 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2424 # spare quota should be released
2425 local OSTUUID=$(ostuuid_from_index 0)
2426 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2427 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2428 [ $limit -le $space ] ||
2429 error "spare quota isn't released, limit:$limit, space:$space"
2433 run_test 13 "Cancel per-ID lock in the LRU list"
2436 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2438 wait_delete_completed
2439 sync_all_data || true
2442 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2443 error "set user quota failed"
2444 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2445 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2446 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2447 resetquota -u $TSTUSR
2450 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2451 error "set group quota failed"
2452 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2453 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2454 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2455 resetquota -g $TSTUSR
2457 run_test 15 "Set over 4T block quota"
2461 local BLKS=1 # 1M less than limit
2462 local TESTFILE=$DIR/$tdir/$tfile
2464 setup_quota_test || error "setup quota failed with $?"
2465 trap cleanup_quota_test EXIT
2467 # make sure the system is clean
2468 local USED=$(getquota -u $TSTUSR global curspace)
2469 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2471 set_ost_qtype "ug" || error "enable ost quota failed"
2472 # make sure no granted quota on ost
2473 resetquota -u $TSTUSR
2474 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2475 error "set quota failed"
2477 quota_show_check b u $TSTUSR
2479 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2480 lustre_fail mds 0xa04 $err_code
2482 # write in background
2483 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2487 # write should be blocked and never finished
2488 if ! ps -p $DDPID > /dev/null 2>&1; then
2490 quota_error u $TSTUSR "write finished incorrectly!"
2498 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2500 if [ $count -gt $timeout ]; then
2501 quota_error u $TSTUSR "dd is not finished!"
2506 sync; sync_all_data || true
2508 USED=$(getquota -u $TSTUSR global curspace)
2509 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2510 "Used space(${USED}K) is less than ${BLKS}M"
2515 # DQACQ return recoverable error
2517 echo "DQACQ return -ENOLCK"
2519 test_17sub 37 || error "Handle -ENOLCK failed"
2521 echo "DQACQ return -EAGAIN"
2523 test_17sub 11 || error "Handle -EAGAIN failed"
2525 echo "DQACQ return -ETIMEDOUT"
2526 #define ETIMEDOUT 110
2527 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2529 echo "DQACQ return -ENOTCONN"
2530 #define ENOTCONN 107
2531 test_17sub 107 || error "Handle -ENOTCONN failed"
2534 run_test 17 "DQACQ return recoverable error"
2538 local blimit="200m" # 200M
2539 local TESTFILE="$DIR/$tdir/$tfile"
2541 setup_quota_test || error "setup quota failed with $?"
2542 trap cleanup_quota_test EXIT
2544 set_ost_qtype "u" || error "enable ost quota failed"
2545 log "User quota (limit: $blimit)"
2546 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2547 error "set quota failed"
2548 quota_show_check b u $TSTUSR
2550 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2551 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2553 local timeout=$(sysctl -n lustre.timeout)
2555 if [ $io_type = "directio" ]; then
2556 log "Write 100M (directio) ..."
2557 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2559 log "Write 100M (buffered) ..."
2560 $RUNAS $DD of=$TESTFILE count=100 &
2564 replay_barrier $SINGLEMDS
2565 log "Fail mds for $((2 * timeout)) seconds"
2566 fail $SINGLEMDS $((2 * timeout))
2569 if at_is_enabled; then
2570 timeout=$(at_max_get mds)
2572 timeout=$(lctl get_param -n timeout)
2576 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2577 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2578 log "it took $count second"
2583 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2585 cancel_lru_locks mdc
2586 cancel_lru_locks osc
2589 local testfile_size=$(stat -c %s $TESTFILE)
2590 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2591 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2592 "got ${testfile_size}. Verifying file failed!"
2597 # test when mds does failover, the ost still could work well
2598 # this test shouldn't trigger watchdog b=14840
2600 # Clear dmesg so watchdog is not triggered by previous
2602 do_facet ost1 dmesg -c > /dev/null
2605 test_18_sub directio
2607 # check if watchdog is triggered
2608 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2609 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2610 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2611 [ -z "$watchdog" ] || error "$watchdog"
2612 rm -f $TMP/lustre-log-${TESTNAME}.log
2614 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2618 local TESTFILE=$DIR/$tdir/$tfile
2620 setup_quota_test || error "setup quota failed with $?"
2621 trap cleanup_quota_test EXIT
2623 set_ost_qtype $QTYPE || error "enable ost quota failed"
2625 # bind file to a single OST
2626 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2627 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2629 echo "Set user quota (limit: ${blimit}M)"
2630 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2631 error "set user quota failed"
2632 quota_show_check b u $TSTUSR
2633 echo "Update quota limits"
2634 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2635 error "set group quota failed"
2636 quota_show_check b u $TSTUSR
2638 # first wirte might be cached
2639 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2640 cancel_lru_locks osc
2642 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2643 quota_error u $TSTUSR "Write success, expect failure"
2648 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2650 test_20() { # b15754
2651 local LSTR=(2g 1t 4k 3m) # limits strings
2653 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2656 resetquota -u $TSTUSR
2658 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2659 $MOUNT || error "could not set quota limits"
2660 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2661 --inode-softlimit ${LSTR[2]} \
2662 --inode-hardlimit ${LSTR[3]} \
2663 $MOUNT || error "could not set quota limits"
2665 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2666 error "bsoftlimit was not set properly"
2667 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2668 error "bhardlimit was not set properly"
2669 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2670 error "isoftlimit was not set properly"
2671 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2672 error "ihardlimit was not set properly"
2674 resetquota -u $TSTUSR
2676 run_test 20 "Test if setquota specifiers work properly (b15754)"
2683 local time=$(($(date +%s) + seconds))
2684 while [ $(date +%s) -lt $time ]; do
2685 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2689 # run for fixing bug16053, setquota shouldn't fail when writing and
2690 # deleting are happening
2692 local TESTFILE="$DIR/$tdir/$tfile"
2693 local BLIMIT=10 # 10G
2694 local ILIMIT=1000000
2696 setup_quota_test || error "setup quota failed with $?"
2697 trap cleanup_quota_test EXIT
2699 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2701 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2702 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2703 error "set user quota failed"
2704 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2705 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2706 error "set group quota failed"
2707 if is_project_quota_supported; then
2708 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2709 "project: $TSTPRJID"
2710 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2711 $MOUNT || error "set project quota failed"
2714 # repeat writing on a 1M file
2715 test_21_sub ${TESTFILE}_1 1 30 &
2717 # repeat writing on a 128M file
2718 test_21_sub ${TESTFILE}_2 128 30 &
2721 local time=$(($(date +%s) + 30))
2723 while [ $(date +%s) -lt $time ]; do
2724 log "Set quota for $i times"
2725 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2726 -I $((ILIMIT + i)) $MOUNT ||
2727 error "Set user quota failed"
2728 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2729 -I $((ILIMIT + i)) $MOUNT ||
2730 error "Set group quota failed"
2731 if is_project_quota_supported; then
2732 $LFS setquota -p $TSTPRJID -b 0 -B \
2733 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2734 error "Set project quota failed"
2742 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2744 if [ $count -gt 60 ]; then
2745 quota_error a $TSTUSR "dd should be finished!"
2749 echo "(dd_pid=$DDPID1, time=$count)successful"
2753 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2755 if [ $count -gt 60 ]; then
2756 quota_error a $TSTUSR "dd should be finished!"
2760 echo "(dd_pid=$DDPID2, time=$count)successful"
2764 run_test 21 "Setquota while writing & deleting (b16053)"
2766 # enable/disable quota enforcement permanently
2768 echo "Set both mdt & ost quota type as ug"
2770 is_project_quota_supported && qtype=$QTYPE
2771 set_mdt_qtype $qtype || error "enable mdt quota failed"
2772 set_ost_qtype $qtype || error "enable ost quota failed"
2775 stopall || error "failed to stopall (1)"
2779 echo "Verify if quota is enabled"
2780 local qtype1=$(mdt_quota_type)
2781 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2782 qtype=$(ost_quota_type)
2783 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2785 echo "Set both mdt & ost quota type as none"
2786 set_mdt_qtype "none" || error "disable mdt quota failed"
2787 set_ost_qtype "none" || error "disable ost quota failed"
2790 stopall || error "failed to stopall (2)"
2795 echo "Verify if quota is disabled"
2796 qtype=$(mdt_quota_type)
2797 [ $qtype != "none" ] && error "mdt quota setting is lost"
2798 qtype=$(ost_quota_type)
2799 [ $qtype != "none" ] && error "ost quota setting is lost"
2803 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2806 local TESTFILE="$DIR/$tdir/$tfile"
2809 setup_quota_test || error "setup quota failed with $?"
2810 trap cleanup_quota_test EXIT
2812 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2815 log "User quota (limit: $LIMIT MB)"
2816 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2817 error "set quota failed"
2818 quota_show_check b u $TSTUSR
2820 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2821 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2823 log "Step1: trigger EDQUOT with O_DIRECT"
2824 log "Write half of file"
2825 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2826 quota_error u $TSTUSR "(1) Write failure, expect success." \
2828 log "Write out of block quota ..."
2829 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2830 oflag=direct conv=notrunc &&
2831 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2835 log "Step2: rewrite should succeed"
2836 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2837 quota_error u $TSTUSR "(3) Write failure, expect success." \
2843 local OST0_UUID=$(ostuuid_from_index 0)
2844 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2845 [ $OST0_QUOTA_USED -ne 0 ] &&
2846 ($SHOW_QUOTA_USER; \
2847 quota_error u $TSTUSR "quota isn't released")
2852 [ "$ost1_FSTYPE" == zfs ] &&
2853 skip "Overwrite in place is not guaranteed to be " \
2854 "space neutral on ZFS"
2856 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2857 check_whether_skip && return 0
2858 log "run for 4MB test file"
2861 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2862 check_whether_skip && return 0
2863 log "run for 40MB test file"
2866 run_test 23 "Quota should be honored with directIO (b16125)"
2870 local TESTFILE="$DIR/$tdir/$tfile"
2872 setup_quota_test || error "setup quota failed with $?"
2873 trap cleanup_quota_test EXIT
2875 set_ost_qtype $QTYPE || error "enable ost quota failed"
2877 # bind file to a single OST
2878 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2879 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2881 echo "Set user quota (limit: ${blimit}M)"
2882 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2883 error "set quota failed"
2885 # overrun quota by root user
2886 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2887 error "write failure, expect success"
2888 cancel_lru_locks osc
2889 sync_all_data || true
2891 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2895 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2897 test_27a() { # b19612
2898 $LFS quota $TSTUSR $DIR &&
2899 error "lfs succeeded with no type, but should have failed"
2900 $LFS setquota $TSTUSR $DIR &&
2901 error "lfs succeeded with no type, but should have failed"
2904 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2906 test_27b() { # b20200
2907 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2908 error "lfs setquota failed with uid argument"
2909 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2910 error "lfs stequota failed with gid argument"
2911 if is_project_quota_supported; then
2912 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2913 1000 $DIR || error \
2914 "lfs stequota failed with projid argument"
2916 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2917 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2918 if is_project_quota_supported; then
2919 $SHOW_QUOTA_PROJID ||
2920 error "lfs quota failed with projid argument"
2922 resetquota -u $TSTID
2923 resetquota -g $TSTID
2924 resetquota -p $TSTPRJID
2927 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2932 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2933 error "lfs setquota failed"
2935 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2936 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2937 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2938 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2940 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2941 error "lfs setquota for $TSTID failed"
2943 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2944 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2945 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2946 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2948 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2949 error "total allocated inode/block limit not printed"
2951 resetquota -u $TSTUSR
2953 run_test 27c "lfs quota should support human-readable output"
2960 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2961 error "set fraction block limit failed"
2962 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2963 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2964 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2965 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2967 resetquota -u $TSTUSR
2969 run_test 27d "lfs setquota should support fraction block limit"
2973 local TESTFILE="$DIR/$tdir/$tfile"
2976 setup_quota_test || error "setup quota failed with $?"
2977 trap cleanup_quota_test EXIT
2979 set_ost_qtype "u" || error "enable ost quota failed"
2981 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2982 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2984 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2985 $MAX_IQ_TIME $DIR || error "set grace time failed"
2986 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2987 error "set quota failed"
2988 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2989 cancel_lru_locks osc
2991 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2992 # over-quota flag has not yet settled since we do not trigger async
2993 # events based on grace time period expiration
2995 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2996 cancel_lru_locks osc
2997 # now over-quota flag should be settled and further writes should fail
2999 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3000 error "grace times were reset"
3003 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3004 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3006 run_test 30 "Hard limit updates should not reset grace times"
3008 # basic usage tracking for user & group
3010 local INODES=10 # 10 files
3011 local BLK_CNT=2 # of 2M each
3012 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3014 setup_quota_test || error "setup quota failed with $?"
3015 trap cleanup_quota_test EXIT
3017 # make sure the system is clean
3018 local USED=$(getquota -u $TSTID global curspace)
3020 error "Used space ($USED) for user $TSTID isn't 0."
3021 USED=$(getquota -g $TSTID global curspace)
3023 error "Used space ($USED) for group $TSTID isn't 0."
3024 if is_project_quota_supported; then
3025 USED=$(getquota -p $TSTPRJID global curspace)
3026 [ $USED -ne 0 ] && error \
3027 "Used space ($USED) for project $TSTPRJID isn't 0."
3030 echo "Write files..."
3031 for i in $(seq 0 $INODES); do
3032 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3033 error "write failed"
3034 is_project_quota_supported &&
3035 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3036 echo "Iteration $i/$INODES completed"
3038 cancel_lru_locks osc
3040 echo "Wait for setattr on objects finished..."
3041 wait_delete_completed
3043 sync; sync_all_data || true
3045 echo "Verify disk usage after write"
3046 USED=$(getquota -u $TSTID global curspace)
3047 [ $USED -lt $TOTAL_BLKS ] &&
3048 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3049 USED=$(getquota -g $TSTID global curspace)
3050 [ $USED -lt $TOTAL_BLKS ] &&
3051 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3052 if is_project_quota_supported; then
3053 USED=$(getquota -p $TSTPRJID global curspace)
3054 [ $USED -lt $TOTAL_BLKS ] && error \
3055 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3058 echo "Verify inode usage after write"
3059 USED=$(getquota -u $TSTID global curinodes)
3060 [ $USED -lt $INODES ] &&
3061 error "Used inode for user $TSTID is $USED, expected $INODES"
3062 USED=$(getquota -g $TSTID global curinodes)
3063 [ $USED -lt $INODES ] &&
3064 error "Used inode for group $TSTID is $USED, expected $INODES"
3065 if is_project_quota_supported; then
3066 USED=$(getquota -p $TSTPRJID global curinodes)
3067 [ $USED -lt $INODES ] && error \
3068 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3073 echo "Verify disk usage after delete"
3074 USED=$(getquota -u $TSTID global curspace)
3075 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3076 USED=$(getquota -u $TSTID global curinodes)
3077 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3078 USED=$(getquota -g $TSTID global curspace)
3079 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3080 USED=$(getquota -g $TSTID global curinodes)
3081 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3082 if is_project_quota_supported; then
3083 USED=$(getquota -p $TSTPRJID global curspace)
3085 error "Used space for project $TSTPRJID isn't 0. $USED"
3086 USED=$(getquota -p $TSTPRJID global curinodes)
3088 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3091 run_test 33 "Basic usage tracking for user & group & project"
3093 # usage transfer test for user & group & project
3095 local BLK_CNT=2 # 2MB
3096 local project_supported="no"
3098 is_project_quota_supported && project_supported="yes"
3099 setup_quota_test || error "setup quota failed with $?"
3100 trap cleanup_quota_test EXIT
3102 # make sure the system is clean
3103 local USED=$(getquota -u $TSTID global curspace)
3104 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3105 USED=$(getquota -g $TSTID global curspace)
3106 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3108 local USED=$(getquota -u $TSTID2 global curspace)
3109 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3110 if [ $project_supported == "yes" ]; then
3111 USED=$(getquota -p $TSTPRJID global curspace)
3112 [ $USED -ne 0 ] && error \
3113 "Used space ($USED) for Project $TSTPRJID isn't 0."
3116 echo "Write file..."
3117 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3118 error "write failed"
3119 cancel_lru_locks osc
3120 sync; sync_all_data || true
3122 echo "chown the file to user $TSTID"
3123 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3125 echo "Wait for setattr on objects finished..."
3126 wait_delete_completed
3128 BLK_CNT=$((BLK_CNT * 1024))
3130 echo "Verify disk usage for user $TSTID"
3131 USED=$(getquota -u $TSTID global curspace)
3132 [ $USED -lt $BLK_CNT ] &&
3133 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3134 USED=$(getquota -u $TSTID global curinodes)
3136 error "Used inodes for user $TSTID is $USED, expected 1"
3138 echo "chgrp the file to group $TSTID"
3139 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3141 echo "Wait for setattr on objects finished..."
3142 wait_delete_completed
3144 echo "Verify disk usage for group $TSTID"
3145 USED=$(getquota -g $TSTID global curspace)
3146 [ $USED -ge $BLK_CNT ] ||
3147 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3148 USED=$(getquota -g $TSTID global curinodes)
3150 error "Used inodes for group $TSTID is $USED, expected 1"
3152 # chown won't change the ost object group. LU-4345 */
3153 echo "chown the file to user $TSTID2"
3154 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3156 echo "Wait for setattr on objects finished..."
3157 wait_delete_completed
3159 echo "change_project project id to $TSTPRJID"
3160 [ $project_supported == "yes" ] &&
3161 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3162 echo "Wait for setattr on objects finished..."
3163 wait_delete_completed
3165 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3166 USED=$(getquota -u $TSTID2 global curspace)
3167 [ $USED -lt $BLK_CNT ] &&
3168 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3169 USED=$(getquota -u $TSTID global curspace)
3171 error "Used space for user $TSTID is $USED, expected 0"
3172 USED=$(getquota -g $TSTID global curspace)
3173 [ $USED -lt $BLK_CNT ] &&
3174 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3175 if [ $project_supported == "yes" ]; then
3176 USED=$(getquota -p $TSTPRJID global curspace)
3177 [ $USED -lt $BLK_CNT ] && error \
3178 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3183 run_test 34 "Usage transfer for user & group & project"
3185 # usage is still accessible across restart
3187 local BLK_CNT=2 # 2 MB
3189 setup_quota_test || error "setup quota failed with $?"
3190 trap cleanup_quota_test EXIT
3192 echo "Write file..."
3193 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3194 error "write failed"
3195 is_project_quota_supported &&
3196 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3197 cancel_lru_locks osc
3199 echo "Wait for setattr on objects finished..."
3200 wait_delete_completed
3202 sync; sync_all_data || true
3204 echo "Save disk usage before restart"
3205 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3206 [ $ORIG_USR_SPACE -eq 0 ] &&
3207 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3208 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3209 [ $ORIG_USR_INODES -eq 0 ] &&
3210 error "Used inodes for user $TSTID is 0, expected 1"
3211 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3212 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3213 [ $ORIG_GRP_SPACE -eq 0 ] &&
3214 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3215 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3216 [ $ORIG_GRP_INODES -eq 0 ] &&
3217 error "Used inodes for group $TSTID is 0, expected 1"
3218 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3220 if is_project_quota_supported; then
3221 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3222 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3223 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3224 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3225 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3226 "Used inodes for project $TSTPRJID is 0, expected 1"
3227 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3235 echo "Verify disk usage after restart"
3236 local USED=$(getquota -u $TSTID global curspace)
3237 [ $USED -eq $ORIG_USR_SPACE ] ||
3238 error "Used space for user $TSTID changed from " \
3239 "$ORIG_USR_SPACE to $USED"
3240 USED=$(getquota -u $TSTID global curinodes)
3241 [ $USED -eq $ORIG_USR_INODES ] ||
3242 error "Used inodes for user $TSTID changed from " \
3243 "$ORIG_USR_INODES to $USED"
3244 USED=$(getquota -g $TSTID global curspace)
3245 [ $USED -eq $ORIG_GRP_SPACE ] ||
3246 error "Used space for group $TSTID changed from " \
3247 "$ORIG_GRP_SPACE to $USED"
3248 USED=$(getquota -g $TSTID global curinodes)
3249 [ $USED -eq $ORIG_GRP_INODES ] ||
3250 error "Used inodes for group $TSTID changed from " \
3251 "$ORIG_GRP_INODES to $USED"
3252 if [ $project_supported == "yes" ]; then
3253 USED=$(getquota -p $TSTPRJID global curinodes)
3254 [ $USED -eq $ORIG_PRJ_INODES ] ||
3255 error "Used inodes for project $TSTPRJID " \
3256 "changed from $ORIG_PRJ_INODES to $USED"
3257 USED=$(getquota -p $TSTPRJID global curspace)
3258 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3259 error "Used space for project $TSTPRJID "\
3260 "changed from $ORIG_PRJ_SPACE to $USED"
3263 # check if the vfs_dq_init() is called before writing
3264 echo "Append to the same file..."
3265 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3266 error "write failed"
3267 cancel_lru_locks osc
3268 sync; sync_all_data || true
3270 echo "Verify space usage is increased"
3271 USED=$(getquota -u $TSTID global curspace)
3272 [ $USED -gt $ORIG_USR_SPACE ] ||
3273 error "Used space for user $TSTID isn't increased" \
3274 "orig:$ORIG_USR_SPACE, now:$USED"
3275 USED=$(getquota -g $TSTID global curspace)
3276 [ $USED -gt $ORIG_GRP_SPACE ] ||
3277 error "Used space for group $TSTID isn't increased" \
3278 "orig:$ORIG_GRP_SPACE, now:$USED"
3279 if [ $project_supported == "yes" ]; then
3280 USED=$(getquota -p $TSTPRJID global curspace)
3281 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3282 error "Used space for project $TSTPRJID isn't " \
3283 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3288 run_test 35 "Usage is still accessible across reboot"
3290 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3293 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3294 skip "Old server doesn't have LU-5006 fix."
3296 setup_quota_test || error "setup quota failed with $?"
3297 trap cleanup_quota_test EXIT
3299 # make sure the system is clean
3300 local USED=$(getquota -u $TSTID global curspace)
3302 error "Used space ($USED) for user $TSTID isn't 0."
3304 # create file with MDS_OPEN_DELAY_CREATE flag
3305 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3306 error "Create file failed"
3308 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3309 oflag=sync || error "Write file failed"
3311 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3313 # wait for setattr on objects finished..."
3314 wait_delete_completed
3316 USED=$(getquota -u $TSTID global curspace)
3317 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3321 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3325 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3326 skip "Old server doesn't have LU-8801 fix."
3328 [ "$UID" != 0 ] && skip_env "must run as root" && return
3330 setup_quota_test || error "setup quota failed with $?"
3331 trap cleanup_quota_test EXIT
3333 # make sure the system is clean
3334 local USED=$(getquota -u $TSTID global curspace)
3336 error "Used space ($USED) for user $TSTID isn't 0."
3337 USED=$(getquota -u $TSTID2 global curspace)
3339 error "Used space ($USED) for user $TSTID2 isn't 0."
3341 local TESTFILE="$DIR/$tdir/$tfile"
3342 local file_cnt=10000
3344 # Generate id entries in accounting file
3345 echo "Create $file_cnt files..."
3346 for i in `seq $file_cnt`; do
3348 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3349 error "failed to chown $TESTFILE-$i"
3351 cancel_lru_locks osc
3352 sync; sync_all_data || true
3354 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3355 procf=${procf}.quota_slave.acct_user
3358 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3359 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3360 echo "Found $acct_cnt id entries"
3362 [ $file_cnt -eq $acct_cnt ] || {
3363 do_facet mds1 $LCTL get_param $procf
3364 error "skipped id entries"
3369 run_test 38 "Quota accounting iterator doesn't skip id entries"
3372 local TESTFILE="$DIR/$tdir/project"
3373 ! is_project_quota_supported &&
3374 skip "Project quota is not supported"
3376 setup_quota_test || error "setup quota failed with $?"
3379 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3380 [ $projectid -ne 0 ] &&
3381 error "Project id should be 0 not $projectid"
3382 change_project -p 1024 $TESTFILE
3383 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3384 [ $projectid -ne 1024 ] &&
3385 error "Project id should be 1024 not $projectid"
3387 stopall || error "failed to stopall (1)"
3390 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3391 [ $projectid -ne 1024 ] &&
3392 error "Project id should be 1024 not $projectid"
3396 run_test 39 "Project ID interface works correctly"
3399 ! is_project_quota_supported &&
3400 skip "Project quota is not supported"
3401 local dir1="$DIR/$tdir/dir1"
3402 local dir2="$DIR/$tdir/dir2"
3404 setup_quota_test || error "setup quota failed with $?"
3406 mkdir -p $dir1 $dir2
3407 change_project -sp 1 $dir1 && touch $dir1/1
3408 change_project -sp 2 $dir2
3410 ln $dir1/1 $dir2/1_link &&
3411 error "Hard link across different project quota should fail"
3416 run_test 40a "Hard link across different project ID"
3419 ! is_project_quota_supported &&
3420 skip "Project quota is not supported"
3421 local dir1="$DIR/$tdir/dir1"
3422 local dir2="$DIR/$tdir/dir2"
3424 setup_quota_test || error "setup quota failed with $?"
3425 mkdir -p $dir1 $dir2
3426 change_project -sp 1 $dir1 && touch $dir1/1
3427 change_project -sp 2 $dir2
3429 mv $dir1/1 $dir2/2 || error "mv failed $?"
3430 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3431 if [ "$projid" != "2" ]; then
3432 error "project id expected 2 not $projid"
3437 run_test 40b "Mv across different project ID"
3440 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3441 ! is_project_quota_supported &&
3442 skip "Project quota is not supported"
3444 setup_quota_test || error "setup quota failed with $?"
3445 local dir="$DIR/$tdir/dir"
3447 mkdir -p $dir && change_project -sp 1 $dir
3448 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3449 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3450 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3451 touch $dir/remote_dir/file
3452 #verify inherit works file for remote dir.
3453 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3454 [ "$projid" != "1" ] &&
3455 error "file under remote dir expected 1 not $projid"
3457 #Agent inode should be ignored for project quota
3458 USED=$(getquota -p 1 global curinodes)
3459 [ "$USED" != "3" ] &&
3460 error "file count expected 3 got $USED"
3466 run_test 40c "Remote child Dir inherit project quota properly"
3469 ! is_project_quota_supported &&
3470 skip "Project quota is not supported"
3472 setup_quota_test || error "setup quota failed with $?"
3473 local dir1="$DIR/$tdir/dir1"
3474 local dir2="$DIR/$tdir/dir2"
3476 mkdir -p $dir1 && change_project -sp 1 $dir1
3477 mkdir -p $dir2 && change_project -sp 2 $dir2
3478 for num in $(seq 1 10); do
3479 touch $dir1/file_$num $dir2/file_$num
3480 ln -s $dir1/file_$num $dir1/file_$num"_link"
3481 ln -s $dir2/file_$num $dir2/file_$num"_link"
3484 count=$($LFS find --projid 1 $DIR | wc -l)
3485 [ "$count" != 21 ] && error "expected 21 but got $count"
3487 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3488 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3489 [ "$count" != 22 ] && error "expected 22 but got $count"
3494 run_test 50 "Test if lfs find --projid works"
3497 ! is_project_quota_supported &&
3498 skip "Project quota is not supported"
3499 setup_quota_test || error "setup quota failed with $?"
3500 local dir="$DIR/$tdir/dir"
3502 mkdir $dir && change_project -sp 1 $dir
3503 local used=$(getquota -p 1 global curinodes)
3504 [ $used != "1" ] && error "expected 1 got $used"
3509 used=$(getquota -p 1 global curinodes)
3510 [ $used != "4" ] && error "expected 4 got $used"
3512 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3514 cp $DIR/$tdir/6 $dir/6
3515 used=$(getquota -p 1 global curinodes)
3516 [ $used != "5" ] && error "expected 5 got $used"
3519 mv $DIR/$tdir/6 $dir/7
3520 used=$(getquota -p 1 global curinodes)
3521 [ $used != "6" ] && error "expected 6 got $used"
3526 run_test 51 "Test project accounting with mv/cp"
3529 ! is_project_quota_supported &&
3530 skip "Project quota is not supported"
3531 setup_quota_test || error "setup quota failed with $?"
3532 local dir="$DIR/$tdir/dir"
3533 mkdir $dir && change_project -sp 1 $dir
3535 touch $DIR/$tdir/file
3536 #Try renaming a file into the project. This should fail.
3537 for num in $(seq 1 2000); do
3538 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3539 error "rename should fail"
3544 run_test 52 "Rename across different project ID"
3547 ! is_project_quota_supported &&
3548 skip "Project quota is not supported"
3549 setup_quota_test || error "setup quota failed with $?"
3550 local dir="$DIR/$tdir/dir"
3551 mkdir $dir && change_project -s $dir
3552 lfs project -d $dir | grep P || error "inherit attribute should be set"
3554 change_project -C $dir
3555 lfs project -d $dir | grep P &&
3556 error "inherit attribute should be cleared"
3561 run_test 53 "Project inherit attribute could be cleared"
3564 ! is_project_quota_supported &&
3565 skip "Project quota is not supported"
3566 setup_quota_test || error "setup quota failed with $?"
3567 trap cleanup_quota_test EXIT
3568 local testfile="$DIR/$tdir/$tfile-0"
3570 #set project ID/inherit attribute
3571 change_project -sp $TSTPRJID $DIR/$tdir
3572 $RUNAS createmany -m ${testfile} 100 ||
3573 error "create many files failed"
3575 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3576 # one more count for directory itself */
3580 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3581 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3583 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3584 [ $proj_count1 -eq $proj_count ] ||
3585 error "c2: expected $proj_count got $proj_count1"
3587 #clear project but with kept projid
3588 change_project -rCk $DIR/$tdir
3589 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3590 [ $proj_count1 -eq 1 ] ||
3591 error "c3: expected 1 got $proj_count1"
3593 #verify projid untouched.
3594 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3596 [ $proj_count1 -eq $proj_count ] ||
3597 error "c4: expected $proj_count got $proj_count1"
3600 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3601 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3602 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3604 #this time clear all
3605 change_project -rC $DIR/$tdir
3606 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3607 [ $proj_count1 -eq 0 ] ||
3608 error "c6: expected 0 got $proj_count1"
3610 unlinkmany ${testfile} 100 ||
3611 error "unlink many files failed"
3615 run_test 54 "basic lfs project interface test"
3618 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3619 skip "Not supported before 2.10.58."
3620 setup_quota_test || error "setup quota failed with $?"
3622 set_ost_qtype $QTYPE || error "enable ost quota failed"
3625 #add second group to TSTUSR
3626 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3629 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3630 error "failed to dd"
3632 cancel_lru_locks osc
3633 sync; sync_all_data || true
3635 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3636 error "failed to setquota on group $TSTUSR2"
3638 $LFS quota -v -g $TSTUSR2 $DIR
3640 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3641 error "chgrp should failed with -EDQUOT"
3643 USED=$(getquota -g $TSTUSR2 global curspace)
3646 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3647 error "failed to setquota on group $TSTUSR2"
3649 $LFS quota -v -g $TSTUSR2 $DIR
3651 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3652 error "chgrp should succeed"
3654 $LFS quota -v -g $TSTUSR2 $DIR
3658 run_test 55 "Chgrp should be affected by group quota"
3661 setup_quota_test || error "setup quota failed with $?"
3663 set_ost_qtype $QTYPE || error "enable ost quota failed"
3666 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3667 erro "failed to set grace time for usr quota"
3668 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3669 awk '{print $4 $8}')
3670 if [ "x$grace_time" != "x10s;10s" ]; then
3671 $LFS quota -t -u $DIR
3672 error "expected grace time: 10s;10s, got:$grace_time"
3677 run_test 56 "lfs quota -t should work well"
3680 setup_quota_test || error "setup quota failed with $?"
3682 local dir="$DIR/$tdir/dir"
3685 #try to change pipe file should not hang and return failure
3686 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3687 awk -F ':' '{ print \\\$2 }'" \
3688 " unable to get xattr for fifo '$dir/pipe'" || return 1
3689 #command can process further if it hit some errors
3690 touch $dir/aaa $dir/bbb
3691 mkdir $dir/subdir -p
3692 touch $dir/subdir/aaa $dir/subdir/bbb
3693 #create one invalid link file
3694 ln -s $dir/not_exist_file $dir/ccc
3695 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3696 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3700 run_test 57 "lfs project could tolerate errors"
3703 [ "$mds1_FSTYPE" != ldiskfs ] &&
3704 skip "ldiskfs only test"
3705 disable_project_quota
3706 setup_quota_test || error "setup quota failed with $?"
3709 local testfile="$DIR/$tdir/$tfile-0"
3710 #make sure it did not crash kernel
3711 touch $testfile && lfs project -sp 1 $testfile
3713 enable_project_quota
3716 run_test 59 "lfs project dosen't crash kernel with project disabled"
3719 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3720 skip "Needs MDS version 2.11.53 or later."
3721 setup_quota_test || error "setup quota failed with $?"
3722 trap cleanup_quota_test EXIT
3724 local testfile=$DIR/$tdir/$tfile
3727 set_mdt_qtype "ug" || error "enable mdt quota failed"
3729 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3730 error "set quota failed"
3731 quota_show_check a g $TSTUSR
3733 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3734 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3735 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3736 error "create many files failed"
3738 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3740 # root user can overrun quota
3741 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3742 error "root user should succeed"
3746 run_test 60 "Test quota for root with setgid"
3748 # test default quota
3749 test_default_quota() {
3750 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3751 skip "Not supported before 2.11.51."
3756 local qprjid=$TSTPRJID
3760 local LIMIT=20480 #20M disk space
3761 local TESTFILE="$DIR/$tdir/$tfile-0"
3763 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3764 echo "Project quota is not supported" && return 0
3766 [ $qtype == "-u" ] && qdtype="-U"
3767 [ $qtype == "-g" ] && qdtype="-G"
3768 [ $qtype == "-p" ] && {
3773 [ $qpool == "meta" ] && {
3774 LIMIT=10240 #10K inodes
3779 setup_quota_test || error "setup quota failed with $?"
3780 trap cleanup_quota_test EXIT
3784 # enable mdt/ost quota
3785 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3786 set_ost_qtype $QTYPE || error "enable ost quota failed"
3788 log "set to use default quota"
3789 $LFS setquota $qtype $qid -d $DIR ||
3790 error "set $qid to use default quota failed"
3792 log "set default quota"
3793 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3794 error "set $qid default quota failed"
3796 log "get default quota"
3797 $LFS quota $qdtype $DIR || error "get default quota failed"
3799 if [ $qpool == "data" ]; then
3800 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3802 [ $SLIMIT -eq $LIMIT ] ||
3803 error "the returned default quota is wrong"
3805 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3807 [ $SLIMIT -eq $LIMIT ] ||
3808 error "the returned default quota is wrong"
3811 # make sure the system is clean
3812 local USED=$(getquota $qtype $qid global curspace)
3813 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3815 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3816 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3818 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3820 log "Test not out of quota"
3821 if [ $qpool == "data" ]; then
3822 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3823 quota_error $qtype $qid "write failed, expect succeed"
3825 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3826 quota_error $qtype $qid "create failed, expect succeed"
3828 unlinkmany $TESTFILE $((LIMIT/2))
3831 log "Test out of quota"
3832 # flush cache, ensure noquota flag is set on client
3833 cancel_lru_locks osc
3834 cancel_lru_locks mdc
3835 sync; sync_all_data || true
3836 if [ $qpool == "data" ]; then
3837 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3838 quota_error $qtype $qid "write succeed, expect EDQUOT"
3840 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3841 quota_error $qtype $qid "create succeed, expect EDQUOT"
3843 unlinkmany $TESTFILE $((LIMIT*2))
3846 log "Increase default quota"
3847 # increase default quota
3848 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3849 error "set default quota failed"
3851 cancel_lru_locks osc
3852 cancel_lru_locks mdc
3853 sync; sync_all_data || true
3854 if [ $qpool == "data" ]; then
3855 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3856 quota_error $qtype $qid "write failed, expect succeed"
3858 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3859 quota_error $qtype $qid "create failed, expect succeed"
3861 unlinkmany $TESTFILE $((LIMIT*2))
3864 log "Set quota to override default quota"
3865 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3866 error "set $qid quota failed"
3868 cancel_lru_locks osc
3869 cancel_lru_locks mdc
3870 sync; sync_all_data || true
3871 if [ $qpool == "data" ]; then
3872 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3873 quota_error $qtype $qid "write succeed, expect EQUOT"
3875 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3876 quota_error $qtype $qid "create succeed, expect EQUOT"
3878 unlinkmany $TESTFILE $((LIMIT*2))
3881 log "Set to use default quota again"
3882 $LFS setquota $qtype $qid -d $DIR ||
3883 error "set $qid to use default quota failed"
3885 cancel_lru_locks osc
3886 cancel_lru_locks mdc
3887 sync; sync_all_data || true
3888 if [ $qpool == "data" ]; then
3889 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3890 quota_error $qtype $qid "write failed, expect succeed"
3892 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3893 quota_error $qtype $qid "create failed, expect succeed"
3895 unlinkmany $TESTFILE $((LIMIT*2))
3900 wait_delete_completed || error "wait_delete_completed failed"
3901 sync_all_data || true
3902 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3903 error "reset default quota failed"
3904 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3905 error "reset quota failed"
3911 test_default_quota "-u" "data"
3912 test_default_quota "-u" "meta"
3913 test_default_quota "-g" "data"
3914 test_default_quota "-g" "meta"
3915 test_default_quota "-p" "data"
3916 test_default_quota "-p" "meta"
3918 run_test 61 "default quota tests"
3921 ! is_project_quota_supported &&
3922 skip "Project quota is not supported"
3923 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3924 skip "chattr did not support project quota"
3925 setup_quota_test || error "setup quota failed with $?"
3926 local testdir=$DIR/$tdir/
3928 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3929 change_project -s $testdir
3930 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3931 error "inherit attribute should be set"
3932 # chattr used FS_IOC_SETFLAGS ioctl
3933 $RUNAS chattr -P $testdir &&
3934 error "regular user clear inherit should fail"
3935 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3936 error "inherit attribute should still be set"
3937 chattr -P $testdir || error "root failed to clear inherit"
3938 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3939 error "inherit attribute should be cleared"
3942 run_test 62 "Project inherit should be only changed by root"
3945 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3946 skip "Not supported before 2.11.55"
3950 local dd_failed=false
3951 local tdir_dom=${tdir}_dom
3952 local LIMIT=20480 #20M
3954 [ $qtype == "p" ] && ! is_project_quota_supported &&
3955 echo "Project quota is not supported" && return 0
3957 [ $qtype == "p" ] && qid=$TSTPRJID
3959 setup_quota_test || error "setup quota failed with $?"
3960 trap cleanup_quota_test EXIT
3964 # enable mdt/ost quota
3965 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3966 set_ost_qtype $QTYPE || error "enable ost quota failed"
3968 # make sure the system is clean
3969 local USED=$(getquota -$qtype $qid global curspace)
3970 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3972 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3974 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3975 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3976 error "setstripe $tdir_dom failed"
3977 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3979 [ $qtype == "p" ] && {
3980 change_project -sp $TSTPRJID $DIR/$tdir
3981 change_project -sp $TSTPRJID $DIR/$tdir_dom
3984 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3985 error "set $qid quota failed"
3987 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3988 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3992 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3994 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3995 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3999 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4001 rm -f $DIR/$tdir_dom/*
4003 # flush cache, ensure noquota flag is set on client
4004 cancel_lru_locks osc
4005 cancel_lru_locks mdc
4006 sync; sync_all_data || true
4010 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4011 quota_error $qtype $qid "write failed, expect succeed"
4013 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4014 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4018 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4021 rm -f $DIR/$tdir_dom/*
4023 # flush cache, ensure noquota flag is set on client
4024 cancel_lru_locks osc
4025 cancel_lru_locks mdc
4026 sync; sync_all_data || true
4030 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4031 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4035 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4037 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4038 quota_error $qtype $qid "write succeed, expect EDQUOT"
4041 rm -fr $DIR/$tdir_dom
4043 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4044 error "reset usr quota failed"
4054 run_test 63 "quota on DoM tests"
4057 ! is_project_quota_supported &&
4058 skip "Project quota is not supported"
4059 setup_quota_test || error "setup quota failed with $?"
4060 local dir1="$DIR/$tdir/"
4063 ln -s $dir1/file $dir1/file_link
4065 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
4066 error "set symlink file's project should fail"
4068 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
4069 error "get symlink file's project should fail"
4073 run_test 64 "lfs project on symlink files should fail"
4077 local TESTFILE="$DIR/$tdir/$tfile-0"
4079 setup_quota_test || error "setup quota failed with $?"
4080 set_ost_qtype $QTYPE || error "enable ost quota failed"
4084 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4085 error "failed to write"
4086 # flush cache, ensure noquota flag is set on client
4087 cancel_lru_locks osc
4088 sync; sync_all_data || true
4090 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4091 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4092 local quota_all=$($RUNAS $LFS quota $DIR)
4094 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
4095 error "usr quota not match"
4096 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
4097 error "grp quota not match"
4103 run_test 65 "Check lfs quota result"
4106 ! is_project_quota_supported &&
4107 skip "Project quota is not supported"
4108 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4109 skip "Not supported before 2.12.4"
4110 setup_quota_test || error "setup quota failed with $?"
4111 stack_trap cleanup_quota_test EXIT
4112 local old=$(do_facet mds1 $LCTL get_param -n \
4113 mdt.*.enable_chprojid_gid | head -1)
4114 local testdir=$DIR/$tdir/foo
4116 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4117 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
4120 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
4121 chown -R $TSTID:$TSTID $testdir
4122 change_project -sp $TSTPRJID $testdir
4123 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4125 $RUNAS lfs project -p 0 $testdir/foo &&
4126 error "nonroot user should fail to set projid"
4128 $RUNAS lfs project -C $testdir/foo &&
4129 error "nonroot user should fail to clear projid"
4131 change_project -C $testdir/foo || error "failed to clear project"
4133 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4134 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4135 "failed to set projid with normal user when enable_chprojid_gid=-1"
4137 $RUNAS lfs project -rC $testdir/ || error \
4138 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4140 touch $testdir/bar || error "failed touch $testdir/bar"
4141 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4142 "normal user should not be able to set projid on root owned file"
4144 change_project -p $TSTPRJID $testdir/bar || error \
4145 "root should be able to change its own file's projid"
4149 run_test 66 "nonroot user can not change project state in default"
4156 local short_qtype=${qtype:0:1}
4159 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4161 quota_usr) _runas=$RUNAS;;
4162 quota_2usr) _runas=$RUNAS2;;
4163 *) error "unknown quota parameter $4";;
4168 $_runas $DD of=$file count=$size ||
4169 quota_error $short_qtype $TSTUSR \
4170 "$qtype write failure, but expect success"
4172 cancel_lru_locks osc
4174 sync; sync_all_data || true
4183 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4185 do_facet mds1 $LCTL get_param $param |
4186 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4190 local limit=20 # 20M
4191 local testfile="$DIR/$tdir/$tfile-0"
4192 local testfile2="$DIR/$tdir/$tfile-1"
4193 local testfile3="$DIR/$tdir/$tfile-2"
4194 local qpool="qpool1"
4200 [ "$ost1_FSTYPE" == zfs ] &&
4201 skip "ZFS grants some block space together with inode"
4203 setup_quota_test || error "setup quota failed with $?"
4204 trap cleanup_quota_test EXIT
4207 set_ost_qtype $QTYPE || error "enable ost quota failed"
4210 log "User quota (block hardlimit:$limit MB)"
4211 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4212 error "set user quota failed"
4214 # make sure the system is clean
4215 used=$(getquota -u $TSTUSR global curspace)
4216 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4218 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4219 echo "granted 0x0 before write $granted"
4221 # trigger reintegration
4222 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4223 procf=${procf}quota_slave.force_reint
4224 do_facet ost1 $LCTL set_param $procf=1 ||
4225 error "force reintegration failed"
4226 wait_ost_reint "u" || error "reintegration failed"
4227 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4228 [ $granted -ne 0 ] &&
4229 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4231 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4232 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4234 # write 10 MB to testfile
4235 test_67_write "$testfile" "user" 10 "quota_usr"
4237 # create qpool and add OST1
4238 pool_add $qpool || error "pool_add failed"
4239 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4240 # as quota_usr hasn't limits, lqe may absent. But it should be
4241 # created after the 1st direct qmt_get.
4242 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4244 # check granted - should be 0, as testfile is located only on OST0
4245 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4246 echo "global granted $granted"
4247 granted=$(getgranted $qpool "dt" $TSTID "usr")
4248 echo "$qpool granted $granted"
4249 [ $granted -ne 0 ] &&
4250 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4252 # add OST0 to qpool and check granted space
4253 pool_add_targets $qpool 0 1 ||
4254 error "pool_add_targets failed"
4255 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4256 echo "Granted $granted_mb MB"
4257 #should be 10M + qunit for each OST
4258 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4259 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4261 $LFS setstripe $testfile2 -c 1 -i 1 ||
4262 error "setstripe $testfile2 failed"
4263 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4264 # Write from another user and check that qpool1
4265 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4266 test_67_write "$testfile2" "user" 10 "quota_2usr"
4267 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4268 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4269 [ $granted -ne 0 ] &&
4270 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4272 # Granted space for quota_2usr in qpool1 should appear only
4273 # when global lqe for this user becomes enforced.
4274 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4275 error "set user quota failed"
4276 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4277 echo "granted_mb $granted_mb"
4278 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4279 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4281 $LFS setstripe $testfile3 -c 1 -i 0 ||
4282 error "setstripe $testfile3 failed"
4283 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4284 test_67_write "$testfile3" "user" 10 "quota_2usr"
4285 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4286 echo "$testfile3 granted_mb $granted_mb"
4287 [ $granted_mb -eq $limit ] ||
4288 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4290 # remove OST1 from the qpool1 and check granted space
4291 # should be 0 for TSTUSR and 10M for TSTUSR2
4292 pool_remove_target $qpool 0
4293 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4294 [ $granted_mb -eq 0 ] ||
4295 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4296 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4297 [ $granted_mb -eq 10 ] ||
4298 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4301 wait_delete_completed || error "wait_delete_completed failed"
4302 sync_all_data || true
4303 used=$(getquota -u $TSTUSR global curspace)
4304 [ $used -ne 0 ] && quota_error u $TSTUSR \
4305 "user quota isn't released after deletion"
4306 resetquota -u $TSTUSR
4310 run_test 67 "quota pools recalculation"
4317 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4318 awk '/usr/ {getline; print $2}'
4323 local qpool="qpool1"
4326 setup_quota_test || error "setup quota failed with $?"
4327 stack_trap cleanup_quota_test EXIT
4330 set_ost_qtype $QTYPE || error "enable ost quota failed"
4332 # check slave number for glbal pool
4333 local nr=$(get_slave_nr "0x0" "usr")
4334 echo "nr result $nr"
4335 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4336 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4338 # create qpool and add OST1
4339 pool_add $qpool || error "pool_add failed"
4340 nr=$(get_slave_nr $qpool "usr")
4341 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4344 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4345 nr=$(get_slave_nr $qpool "usr")
4346 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4349 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4350 nr=$(get_slave_nr $qpool "usr")
4351 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4354 pool_remove_target $qpool 0
4355 nr=$(get_slave_nr $qpool "usr")
4356 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4359 pool_remove_target $qpool 1
4360 nr=$(get_slave_nr $qpool "usr")
4361 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4363 # Check again that all is fine with global pool
4364 nr=$(get_slave_nr "0x0" "usr")
4365 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4366 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4370 run_test 68 "slave number in quota pool changed after each add/remove OST"
4374 local global_limit=200 # 200M
4375 local limit=10 # 10M
4376 local testfile="$DIR/$tdir/$tfile-0"
4377 local dom0="$DIR/$tdir/dom0"
4378 local qpool="qpool1"
4381 setup_quota_test || error "setup quota failed with $?"
4382 stack_trap cleanup_quota_test EXIT
4385 set_ost_qtype $QTYPE || error "enable ost quota failed"
4386 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4388 # Save DOM only at MDT0
4389 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4390 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4392 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4394 # create qpool and add OST0
4395 pool_add $qpool || error "pool_add failed"
4396 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4398 log "User quota (block hardlimit:$global_limit MB)"
4399 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4400 error "set user quota failed"
4402 log "User quota (block hardlimit:$limit MB)"
4403 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
4404 error "set user quota failed"
4406 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4407 quota_error u $TSTUSR "write failed"
4409 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4410 oflag=sync || quota_error u $TSTUSR "write failed"
4412 $RUNAS $DD of=$testfile count=$limit || true
4414 # flush cache, ensure noquota flag is set on client
4415 cancel_lru_locks osc
4416 sync; sync_all_data || true
4418 # MDT0 shouldn't get EDQUOT with glimpse.
4419 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4420 quota_error u $TSTUSR \
4421 "user write success, but expect EDQUOT"
4423 # Now all members of qpool1 should get EDQUOT. Expect success
4424 # when write to DOM on MDT0, as it belongs to global pool.
4425 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4426 oflag=sync || quota_error u $TSTUSR "write failed"
4428 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4429 oflag=sync || quota_error u $TSTUSR "write failed"
4433 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4437 local qpool="qpool1"
4442 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4443 skip "Needs a client >= $VERSION_WITH_QP"
4445 setup_quota_test || error "setup quota failed with $?"
4446 stack_trap cleanup_quota_test EXIT
4448 # MDS returns EFAULT for unsupported quotactl command
4449 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4451 # create qpool and add OST0
4452 pool_add $qpool || error "pool_add failed"
4453 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4455 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR
4457 [ $rc -eq $err ] || error "setquota res $rc != $err"
4459 # If MDS supports QP, check that limit was set properly.
4460 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4461 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4462 echo "hard limit $bhard limit $limit"
4463 [ $bhard -ne $((limit*1024)) ] &&
4464 error "bhard:$bhard for $qpool!=$((limit*1024))"
4467 $LFS quota -u $TSTUSR --pool $qpool $DIR
4469 [ $rc -eq $err ] || error "quota res $rc != $err"
4473 run_test 70 "check lfs setquota/quota with a pool option"
4477 local limit=10 # 10M
4478 local global_limit=100 # 100M
4479 local testfile="$DIR/$tdir/$tfile-0"
4480 local qpool="qpool1"
4481 local qpool2="qpool2"
4483 [ "$ost1_FSTYPE" == zfs ] &&
4484 skip "ZFS grants some block space together with inode"
4485 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4487 setup_quota_test || error "setup quota failed with $?"
4488 stack_trap cleanup_quota_test EXIT
4491 set_ost_qtype $QTYPE || error "enable ost quota failed"
4494 log "User quota (block hardlimit:$global_limit MB)"
4495 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4496 error "set user quota failed"
4498 pool_add $qpool || error "pool_add failed"
4499 pool_add_targets $qpool 0 1 ||
4500 error "pool_add_targets failed"
4502 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
4503 error "set user quota failed"
4505 pool_add $qpool2 || error "pool_add failed"
4506 pool_add_targets $qpool2 1 1 ||
4507 error "pool_add_targets failed"
4509 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool2 $DIR ||
4510 error "set user quota failed"
4512 # make sure the system is clean
4513 local used=$(getquota -u $TSTUSR global curspace)
4516 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4518 # create 1st component 1-10M
4519 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4520 #create 2nd component 10-30M
4521 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4522 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4524 # сheck normal use and out of quota with PFL
4525 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4526 test_1_check_write $testfile "user" $((limit*2))
4528 wait_delete_completed || error "wait_delete_completed failed"
4529 sync_all_data || true
4530 used=$(getquota -u $TSTUSR global curspace)
4531 [ $used -ne 0 ] && quota_error u $TSTUSR \
4532 "user quota isn't released after deletion"
4534 # create 1st component 1-10M
4535 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4536 # create 2nd component 10-30M
4537 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4538 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4540 # write to the 2nd component
4541 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4542 quota_error u $TSTUSR \
4543 "write failure, but expect success"
4544 # this time maybe cache write, ignore it's failure
4545 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4546 cancel_lru_locks osc
4547 sync; sync_all_data || true
4548 # write over limit in qpool2(2nd component 10-30M)
4549 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4550 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4551 # write to the 1st component - OST0 is empty
4552 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4553 quota_error u $TSTUSR "write failed"
4557 run_test 71a "Check PFL with quota pools"
4561 local global_limit=1000 # 1G
4562 local limit1=160 # 160M
4563 local limit2=10 # 10M
4564 local testfile="$DIR/$tdir/$tfile-0"
4565 local qpool="qpool1"
4566 local qpool2="qpool2"
4568 [ "$ost1_FSTYPE" == zfs ] &&
4569 skip "ZFS grants some block space together with inode"
4570 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4572 setup_quota_test || error "setup quota failed with $?"
4573 stack_trap cleanup_quota_test EXIT
4576 set_ost_qtype $QTYPE || error "enable ost quota failed"
4579 log "User quota (block hardlimit:$global_limit MB)"
4580 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4581 error "set user quota failed"
4583 pool_add $qpool || error "pool_add failed"
4584 pool_add_targets $qpool 0 1 ||
4585 error "pool_add_targets failed"
4587 $LFS setquota -u $TSTUSR -B ${limit1}M -o $qpool $DIR ||
4588 error "set user quota failed"
4590 pool_add $qpool2 || error "pool_add failed"
4591 pool_add_targets $qpool2 1 1 ||
4592 error "pool_add_targets failed"
4594 $LFS setquota -u $TSTUSR -B ${limit2}M -o $qpool2 $DIR ||
4595 error "set user quota failed"
4597 # make sure the system is clean
4598 local used=$(getquota -u $TSTUSR global curspace)
4601 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4603 # First component is on OST0, 2nd on OST1
4604 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4605 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4607 # fill the 1st component on OST0
4608 $RUNAS $DD of=$testfile count=128 ||
4609 quota_error u $TSTUSR "write failed"
4610 # write to the 2nd cmpnt on OST1
4611 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4612 quota_error u $TSTUSR "write failed"
4613 # this time maybe cache write, ignore it's failure
4614 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4616 cancel_lru_locks osc
4617 sync; sync_all_data || true
4618 # write over limit in qpool2
4619 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4620 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4624 run_test 71b "Check SEL with quota pools"
4628 local limit=10 # 10M
4629 local global_limit=50 # 50M
4630 local testfile="$DIR/$tdir/$tfile-0"
4631 local qpool="qpool1"
4634 setup_quota_test || error "setup quota failed with $?"
4635 stack_trap cleanup_quota_test EXIT
4638 set_ost_qtype $QTYPE || error "enable ost quota failed"
4641 log "User quota (block hardlimit:$global_limit MB)"
4642 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4643 error "set user quota failed"
4645 pool_add $qpool || error "pool_add failed"
4646 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4648 $LFS setquota -u $TSTUSR -B ${limit}M -o $qpool $DIR ||
4649 error "set user quota failed"
4651 # make sure the system is clean
4652 local used=$(getquota -u $TSTUSR global curspace)
4654 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4656 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4658 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4659 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4660 test_1_check_write $testfile "user" $limit
4661 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4663 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4664 # check that lfs quota -uv --pool prints only OST that
4665 # was added in a pool
4666 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4667 grep "OST\|MDT" && error "$qpool consists wrong targets"
4671 run_test 72 "lfs quota --pool prints only pool's OSTs"
4675 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
4676 if $PQ_CLEANUP; then
4677 disable_project_quota
4680 reset_quota_settings
4685 check_and_cleanup_lustre
4686 export QUOTA_AUTO=$QUOTA_AUTO_OLD