3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
33 TSTID=${TSTID:-"$(id -u $TSTUSR)"}
34 TSTID2=${TSTID2:-"$(id -u $TSTUSR2)"}
35 TSTPRJID=${TSTPRJID:-1000}
40 VERSION_WITH_QP="2.13.53"
42 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
43 skip "Needs MDS version $VERSION_WITH_QP or later."
46 require_dsh_mds || exit 0
47 require_dsh_ost || exit 0
49 # Does e2fsprogs support quota feature?
50 if [ "$mds1_FSTYPE" == ldiskfs ] &&
51 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
52 grep -q 'quota'"; then
53 skip_env "e2fsprogs doesn't support quota"
56 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
58 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
63 QUOTA_AUTO_OLD=$QUOTA_AUTO
66 check_and_setup_lustre
68 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
69 is_project_quota_supported || echo "project quota not supported/enabled"
71 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
72 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
73 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
74 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
75 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
78 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
83 local fail_val=${3:-0}
87 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
88 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
89 ost) NODES="$(comma_list $(osts_nodes))";;
92 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
98 lfs project $* || error "lfs project $* failed"
101 RUNAS="runas -u $TSTID -g $TSTID"
102 RUNAS2="runas -u $TSTID2 -g $TSTID2"
103 DD="dd if=/dev/zero bs=1M"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
110 # resetquota -p projid
113 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
114 error "clear quota for [type:$1 name:$2] failed"
118 (( "$#" == 2 )) || error "resetquota: wrong number of arguments: '$*'"
119 [[ "$1" == "-u" || "$1" == "-g" || "$1" == "-p" ]] ||
120 error "resetquota: wrong quota type '$1' passed"
122 resetquota_one "$1" "$2"
124 # 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 count=$($LFS find --user $local_id $DIR | wc -l)
136 log "Files for user ($local_id), count=$count:"
137 ($LFS find --user $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
142 $LFS quota -v -g $local_id $DIR
143 count=$($LFS find --group $local_id $DIR | wc -l)
144 log "Files for group ($local_id), count=$count:"
145 ($LFS find --group $local_id $DIR | head -n 4 |
146 xargs stat 2>/dev/null)
149 is_project_quota_supported || return 0
150 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
151 $LFS quota -v -p $TSTPRJID $DIR
152 count=$($LFS find --projid $TSTPRJID $DIR | wc -l)
153 log "Files for project ($TSTPRJID), count=$count:"
154 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
155 xargs stat 2>/dev/null)
171 # get quota for a user or a group
172 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
173 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
180 sync_all_data > /dev/null 2>&1 || true
182 [ "$#" != 4 -a "$#" != 5 ] &&
183 error "getquota: wrong number of arguments: $#"
184 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
185 error "getquota: wrong u/g/p specifier $1 passed"
198 *) error "unknown quota parameter $4";;
201 [ ! -z "$5" ] && pool_arg="--pool $5 "
202 [ "$uuid" = "global" ] && uuid=$DIR
204 $LFS quota -v "$1" "$2" $pool_arg $DIR |
205 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
206 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
211 # usage: set_mdt_qtype ugp|u|g|p|none
215 local mdts=$(get_facets MDS)
217 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
218 qtype=$(tr -d 'p' <<<$qtype)
220 if [[ $PERM_CMD == *"set_param -P"* ]]; then
221 do_facet mgs $PERM_CMD \
222 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
224 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
226 # we have to make sure each MDT received config changes
227 for mdt in ${mdts//,/ }; do
229 cmd="$LCTL get_param -n "
230 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
231 cmd=${cmd}.quota_slave.enabled
233 if $(facet_up $mdt); then
234 wait_update_facet $mdt "$cmd" "$qtype" || return 1
241 # usage: set_ost_qtype ugp|u|g|p|none
245 local osts=$(get_facets OST)
247 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
248 qtype=$(tr -d 'p' <<<$qtype)
250 if [[ $PERM_CMD == *"set_param -P"* ]]; then
251 do_facet mgs $PERM_CMD \
252 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
254 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
256 # we have to make sure each OST received config changes
257 for ost in ${osts//,/ }; do
259 cmd="$LCTL get_param -n "
260 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
261 cmd=${cmd}.quota_slave.enabled
263 if $(facet_up $ost); then
264 wait_update_facet $ost "$cmd" "$qtype" || return 1
270 wait_reintegration() {
274 local result="glb[1],slv[1],reint[0]"
279 if [ $ntype == "mdt" ]; then
280 tgts=$(get_facets MDS)
282 tgts=$(get_facets OST)
285 for tgt in ${tgts//,/ }; do
287 cmd="$LCTL get_param -n "
288 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
289 cmd=${cmd}.quota_slave.info
291 if $(facet_up $tgt); then
292 # reintegration starts after recovery completion
293 wait_recovery_complete $tgt
294 wait_update_facet $tgt "$cmd |
295 grep "$qtype" | awk '{ print \\\$3 }'" \
296 "$result" $max || return 1
306 if [[ "$qtype" =~ "u" ]]; then
307 wait_reintegration "mdt" "user" $max || return 1
310 if [[ "$qtype" =~ "g" ]]; then
311 wait_reintegration "mdt" "group" $max || return 1
314 if [[ "$qtype" =~ "p" ]]; then
315 ! is_project_quota_supported && return 0
316 wait_reintegration "mdt" "project" $max || return 1
325 if [[ "$qtype" =~ "u" ]]; then
326 wait_reintegration "ost" "user" $max || return 1
329 if [[ "$qtype" =~ "g" ]]; then
330 wait_reintegration "ost" "group" $max || return 1
333 if [[ "$qtype" =~ "p" ]]; then
334 ! is_project_quota_supported && return 0
335 wait_reintegration "ost" "project" $max || return 1
344 local extrasleep=${4:-5}
351 *) error "get_grace_time: Invalid quota type: $qtype"
356 echo "Quota info for $pool:"
357 $LFS quota -$qtype $qarg $parg $DIR
362 time=$(lfs quota -$qtype $qarg $parg $DIR|
363 awk 'NR == 3{ print $5 }')
366 time=$(lfs quota -$qtype $qarg $DIR|
367 awk 'NR == 3{ print $9 }')
370 error "Unknown quota type: $flavour"
374 local sleep_seconds=0
375 local orig_time=$time
377 echo "Grace time is $time"
378 # from lfs.c:__sec2str()
379 # const char spec[] = "smhdw";
380 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
381 [[ $time == *w* ]] && w_time=${time%w*} &&
382 let sleep_seconds+=$((w_time*7*24*60*60));
384 [[ $time == *d* ]] && d_time=${time%d*} &&
385 let sleep_seconds+=$((d_time*24*60*60));
387 [[ $time == *h* ]] && h_time=${time%h*} &&
388 let sleep_seconds+=$((h_time*60*60));
390 [[ $time == *m* ]] && m_time=${time%m*} &&
391 let sleep_seconds+=$((m_time*60));
393 [[ $time == *s* ]] && s_time=${time%s*} &&
394 let sleep_seconds+=$s_time
396 echo "Sleep through grace ..."
397 [ "$orig_time" == "-" ] &&
398 error "Grace timeout was not set or quota not exceeded"
399 if [ "$orig_time" == "expired" -o "$orig_time" == "none" ]; then
400 echo "...Grace timeout already expired"
402 let sleep_seconds+=$extrasleep
403 echo "...sleep $sleep_seconds seconds"
409 wait_delete_completed
410 echo "Creating test directory"
411 mkdir_on_mdt0 $DIR/$tdir || return 1
412 chmod 0777 $DIR/$tdir || return 2
413 # always clear fail_loc in case of fail_loc isn't cleared
414 # properly when previous test failed
415 lustre_fail mds_ost 0
416 stack_trap cleanup_quota_test EXIT
419 cleanup_quota_test() {
420 echo "Delete files..."
422 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
423 echo "Wait for unlink objects finished..."
424 wait_delete_completed
425 sync_all_data || true
435 $LFS quota -v -$ugp $qid $DIR
437 if [ "$bf" == "a" -o "$bf" == "b" ]; then
438 usage=$(getquota -$ugp $qid global curspace)
439 if [ -z $usage ]; then
440 quota_error $ugp $qid \
441 "Query block quota failed ($ugp:$qid)."
443 [ $usage -ne 0 ] && quota_log $ugp $qid \
444 "Block quota isn't 0 ($ugp:$qid:$usage)."
448 if [ "$bf" == "a" -o "$bf" == "f" ]; then
449 usage=$(getquota -$ugp $qid global curinodes)
450 if [ -z $usage ]; then
451 quota_error $ugp $qid \
452 "Query file quota failed ($ugp:$qid)."
454 [ $usage -ne 0 ] && quota_log $ugp $qid \
455 "File quota isn't 0 ($ugp:$qid:$usage)."
460 project_quota_enabled () {
462 local zfeat="feature@project_quota"
464 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
465 local facet_fstype=${facet:0:3}1_FSTYPE
468 if [ "${!facet_fstype}" = "zfs" ]; then
469 devname=$(zpool_name ${facet})
470 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
471 grep -wq active || rc=1
473 [ ${facet:0:3} == "mds" ] &&
474 devname=$(mdsdevname ${facet:3}) ||
475 devname=$(ostdevname ${facet:3})
476 do_facet ${facet} $DEBUGFS -R features $devname |
477 grep -q project || rc=1
480 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
484 project_quota_enabled || enable_project_quota
486 reset_quota_settings() {
487 resetquota_one -u $TSTUSR
488 [[ $(id -u $TSTUSR) == $TSTID ]] || resetquota_one -u $TSTID
489 resetquota_one -g $TSTUSR
490 [[ $(id -g $TSTUSR) == $TSTID ]] || resetquota_one -g $TSTID
491 resetquota_one -u $TSTUSR2
492 [[ $(id -u $TSTUSR2) == $TSTID2 ]] || resetquota_one -u $TSTID2
493 resetquota_one -g $TSTUSR2
494 [[ $(id -g $TSTUSR2) == $TSTID2 ]] || resetquota_one -g $TSTID2
495 is_project_quota_supported && resetquota_one -p $TSTPRJID
497 $LFS setquota -U -b 0 -B 0 -i 0 -I 0 $MOUNT ||
498 error "failed to reset default user quota"
499 $LFS setquota -G -b 0 -B 0 -i 0 -I 0 $MOUNT ||
500 error "failed to reset default group quota"
501 is_project_quota_supported &&
502 $LFS setquota -P -b 0 -B 0 -i 0 -I 0 $MOUNT ||
503 error "failed to reset default project quota"
519 usr) qtype="limit_user";;
520 grp) qtype="limit_group";;
521 prj) qtype="limit_project";;
522 *) error "unknown quota parameter $3";;
529 *) error "unknown quota parameter $5";;
532 do_facet $facet $LCTL get_param osd-*.*-${device}.quota_slave.$qtype |
533 awk '($3 == '$qid') {getline; print $'$spec'; exit;}' | tr -d ,
536 wait_quota_synced() {
546 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
547 while [[ $value != $limit_val ]]; do
548 (( interval != 0 )) ||
549 do_facet $facet $LCTL set_param \
550 osd-*.*-${device}.quota_slave.force_reint=1
553 (( interval <= 20 )) ||
554 error "quota ($value) don't update on QSD, $limit_val"
556 interval=$((interval + 1))
559 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
563 # make sure the system is clean
564 check_system_is_clean() {
567 lfs quota -uv quota_usr /mnt/lustre
568 for cur in "curspace" "curinodes";
570 used=$(getquota -u $TSTUSR global $cur)
571 [ $used -ne 0 ] && quota_error u $TSTUSR \
572 "Used ${cur:3}($used) for user $TSTUSR isn't 0."
574 used=$(getquota -u $TSTUSR2 global $cur)
575 [ $used -ne 0 ] && quota_error u $TSTUSR2 \
576 "Used ${cur:3}($used) for user $TSTUSR2 isn't 0."
578 used=$(getquota -g $TSTUSR global $cur)
579 [ $used -ne 0 ] && quota_error g $TSTUSR \
580 "Used ${cur:3}($used) for group $TSTUSR isn't 0."
582 used=$(getquota -g $TSTUSR2 global $cur)
583 [ $used -ne 0 ] && quota_error g $TSTUSR2 \
584 "Used ${cur:3}($used) for group $TSTUSR2 isn't 0."
586 if is_project_quota_supported; then
587 used=$(getquota -p $TSTPRJID global $cur)
588 [ $used -ne 0 ] && quota_error p $TSTPRJID \
589 "Used ${cur:3}($used) for project $TSTPRJID isn't 0"
597 do_nodes $(comma_list $(nodes_list)) \
598 "$LCTL set_param -n debug=+quota+trace"
603 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
604 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
605 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
606 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
607 check_system_is_clean
609 test_quota_performance() {
610 local TESTFILE="$DIR/$tdir/$tfile-0"
611 local size=$1 # in MB
612 local stime=$(date +%s)
613 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
614 quota_error u $TSTUSR "write failure"
615 local etime=$(date +%s)
616 delta=$((etime - stime))
617 if [ $delta -gt 0 ]; then
618 rate=$((size * 1024 / delta))
619 if [ "$mds1_FSTYPE" = zfs ]; then
620 # LU-2872 - see LU-2887 for fix
622 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
624 [ $rate -gt 1024 ] ||
625 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
631 # test basic quota performance b=21696
634 [ "$SLOW" = "no" ] && MB=10
636 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
637 [ $free_space -le $((MB * 1024)) ] &&
638 skip "not enough space ${free_space} KB, " \
639 "required $((MB * 1024)) KB"
640 setup_quota_test || error "setup quota failed with $?"
642 set_ost_qtype "none" || error "disable ost quota failed"
643 test_quota_performance $MB
645 set_ost_qtype $QTYPE || error "enable ost quota failed"
646 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
647 error "set quota failed"
648 test_quota_performance $MB
650 run_test 0 "Test basic quota performance"
652 # usage: test_1_check_write tfile user|group|project
653 test_1_check_write() {
657 local short_qtype=${qtype:0:1}
660 $RUNAS $DD of=$testfile count=$((limit/2)) ||
661 quota_error $short_qtype $TSTUSR \
662 "$qtype write failure, but expect success"
663 log "Write out of block quota ..."
664 # this time maybe cache write, ignore it's failure
665 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
666 # flush cache, ensure noquota flag is set on client
668 sync; sync_all_data || true
669 # sync means client wrote all it's cache, but id doesn't
670 # guarantee that slave received new edquot through glimpse.
671 # so wait a little to be sure slave got it.
673 $RUNAS $DD of=$testfile count=1 seek=$limit &&
674 quota_error $short_qtype $TSTUSR \
675 "user write success, but expect EDQUOT"
679 check_write_fallocate() {
683 local short_qtype=${qtype:0:1}
686 log "Write ${count}MiB Using Fallocate"
687 $RUNAS fallocate -l${count}MiB $testfile ||
688 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
691 sync; sync_all_data || true
695 log "Write ${count}MiB Using Fallocate"
696 $RUNAS fallocate -l${count}MiB $testfile &&
697 quota_error $short_qtype $TSTUSR \
698 "Write success, expect EDQUOT" || true
701 # test block hardlimit
704 local testfile="$DIR/$tdir/$tfile-0"
706 setup_quota_test || error "setup quota failed with $?"
709 set_ost_qtype $QTYPE || error "enable ost quota failed"
712 log "User quota (block hardlimit:$limit MB)"
713 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
714 error "set user quota failed"
716 # make sure the system is clean
717 local used=$(getquota -u $TSTUSR global curspace)
718 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
720 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
721 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
723 test_1_check_write $testfile "user" $limit
726 wait_delete_completed || error "wait_delete_completed failed"
727 sync_all_data || true
728 used=$(getquota -u $TSTUSR global curspace)
729 [ $used -ne 0 ] && quota_error u $TSTUSR \
730 "user quota isn't released after deletion"
731 resetquota -u $TSTUSR
734 log "--------------------------------------"
735 log "Group quota (block hardlimit:$limit MB)"
736 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
737 error "set group quota failed"
739 testfile="$DIR/$tdir/$tfile-1"
740 # make sure the system is clean
741 used=$(getquota -g $TSTUSR global curspace)
742 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
744 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
745 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
747 test_1_check_write $testfile "group" $limit
749 wait_delete_completed || error "wait_delete_completed failed"
750 sync_all_data || true
751 used=$(getquota -g $TSTUSR global curspace)
752 [ $used -ne 0 ] && quota_error g $TSTUSR \
753 "Group quota isn't released after deletion"
754 resetquota -g $TSTUSR
756 if ! is_project_quota_supported; then
757 echo "Project quota is not supported"
761 testfile="$DIR/$tdir/$tfile-2"
762 # make sure the system is clean
763 used=$(getquota -p $TSTPRJID global curspace)
765 error "used space($used) for project $TSTPRJID isn't 0"
768 log "--------------------------------------"
769 log "Project quota (block hardlimit:$limit mb)"
770 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
771 error "set project quota failed"
773 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
774 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
775 change_project -p $TSTPRJID $testfile
777 test_1_check_write $testfile "project" $limit
782 used=$(getquota -p $TSTPRJID global curspace)
783 [ $used -ne 0 ] && quota_error p $TSTPRJID \
784 "project quota isn't released after deletion"
786 resetquota -p $TSTPRJID
788 run_test 1a "Block hard limit (normal use and out of quota)"
791 (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
792 skip "Need MDS version at least 2.15.55"
795 local global_limit=20 # MB
796 local testfile="$DIR/$tdir/$tfile-0"
800 setup_quota_test || error "setup quota failed with $?"
803 set_ost_qtype $QTYPE || error "enable ost quota failed"
806 log "User quota (block hardlimit:$global_limit MB)"
807 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
808 error "set user quota failed"
810 pool_add $qpool || error "pool_add failed"
811 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
812 error "pool_add_targets failed"
814 # check qmt_pool_add dmesg error
815 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
817 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
818 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
820 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
821 error "set user quota failed"
823 # make sure the system is clean
824 local used=$(getquota -u $TSTUSR global curspace)
826 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
828 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
830 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
831 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
833 test_1_check_write $testfile "user" $limit
836 wait_delete_completed || error "wait_delete_completed failed"
837 sync_all_data || true
838 used=$(getquota -u $TSTUSR global curspace $qpool)
839 [ $used -ne 0 ] && quota_error u $TSTUSR \
840 "user quota isn't released after deletion"
841 resetquota -u $TSTUSR
844 log "--------------------------------------"
845 log "Group quota (block hardlimit:$global_limit MB)"
846 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
847 error "set group quota failed"
849 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
850 error "set group quota failed"
852 testfile="$DIR/$tdir/$tfile-1"
853 # make sure the system is clean
854 used=$(getquota -g $TSTUSR global curspace $qpool)
855 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
857 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
858 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
860 test_1_check_write $testfile "group" $limit
863 wait_delete_completed || error "wait_delete_completed failed"
864 sync_all_data || true
865 used=$(getquota -g $TSTUSR global curspace $qpool)
866 [ $used -ne 0 ] && quota_error g $TSTUSR \
867 "Group quota isn't released after deletion"
868 resetquota -g $TSTUSR
870 if ! is_project_quota_supported; then
871 echo "Project quota is not supported"
875 testfile="$DIR/$tdir/$tfile-2"
876 # make sure the system is clean
877 used=$(getquota -p $TSTPRJID global curspace $qpool)
879 error "used space($used) for project $TSTPRJID isn't 0"
882 log "--------------------------------------"
883 log "Project quota (block hardlimit:$global_limit mb)"
884 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
885 error "set project quota failed"
887 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
888 error "set project quota failed"
891 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
892 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
893 change_project -p $TSTPRJID $testfile
895 test_1_check_write $testfile "project" $limit
900 used=$(getquota -p $TSTPRJID global curspace)
901 [ $used -eq 0 ] || quota_error p $TSTPRJID \
902 "project quota isn't released after deletion"
904 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
907 local global_limit=20 # MB
908 local testfile="$DIR/$tdir/$tfile-0"
909 local qpool1="qpool1"
910 local qpool2="qpool2"
913 setup_quota_test || error "setup quota failed with $?"
916 set_ost_qtype $QTYPE || error "enable ost quota failed"
919 log "User quota (block hardlimit:$global_limit MB)"
920 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
921 error "set user quota failed"
923 pool_add $qpool1 || error "pool_add failed"
924 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
925 error "pool_add_targets failed"
927 pool_add $qpool2 || error "pool_add failed"
928 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
929 error "pool_add_targets failed"
931 # create pools without hard limit
932 # initially such case raised several bugs
933 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
934 error "set user quota failed"
936 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
937 error "set user quota failed"
939 # make sure the system is clean
940 local used=$(getquota -u $TSTUSR global curspace)
942 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
944 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
946 test_1_check_write $testfile "user" $global_limit
948 used=$(getquota -u $TSTUSR global curspace $qpool1)
949 echo "qpool1 used $used"
950 used=$(getquota -u $TSTUSR global curspace $qpool2)
951 echo "qpool2 used $used"
954 wait_delete_completed || error "wait_delete_completed failed"
955 sync_all_data || true
957 used=$(getquota -u $TSTUSR global curspace $qpool1)
958 [ $used -eq 0 ] || quota_error u $TSTUSR \
959 "user quota isn't released after deletion"
961 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
966 local global_limit=20 # MB
967 local testfile="$DIR/$tdir/$tfile-0"
968 local qpool1="qpool1"
969 local qpool2="qpool2"
972 setup_quota_test || error "setup quota failed with $?"
975 set_ost_qtype $QTYPE || error "enable ost quota failed"
978 log "User quota (block hardlimit:$global_limit MB)"
979 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
980 error "set user quota failed"
982 pool_add $qpool1 || error "pool_add failed"
983 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
984 error "pool_add_targets failed"
986 pool_add $qpool2 || error "pool_add failed"
987 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
988 error "pool_add_targets failed"
990 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
991 error "set user quota failed"
993 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
994 error "set user quota failed"
996 # make sure the system is clean
997 local used=$(getquota -u $TSTUSR global curspace)
999 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
1001 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
1003 test_1_check_write $testfile "user" $limit1
1005 used=$(getquota -u $TSTUSR global curspace $qpool1)
1006 echo "qpool1 used $used"
1007 used=$(getquota -u $TSTUSR global curspace $qpool2)
1008 echo "qpool2 used $used"
1011 wait_delete_completed || error "wait_delete_completed failed"
1012 sync_all_data || true
1014 used=$(getquota -u $TSTUSR global curspace $qpool1)
1015 [ $used -eq 0 ] || quota_error u $TSTUSR \
1016 "user quota isn't released after deletion"
1018 run_test 1d "Quota pools: check block hardlimit on different pools"
1021 local limit1=10 # MB
1022 local global_limit=53000000 # MB
1023 local testfile="$DIR/$tdir/$tfile-0"
1024 local testfile2="$DIR/$tdir/$tfile-1"
1025 local qpool1="qpool1"
1028 setup_quota_test || error "setup quota failed with $?"
1031 set_ost_qtype $QTYPE || error "enable ost quota failed"
1033 # global_limit is much greater than limit1 to get
1034 # different qunit's on osts. Since 1st qunit shrinking
1035 # on OST1(that belongs to qpool1), this qunit should
1037 log "User quota (block hardlimit:$global_limit MB)"
1038 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1039 error "set user quota failed"
1041 pool_add $qpool1 || error "pool_add failed"
1042 pool_add_targets $qpool1 1 1 ||
1043 error "pool_add_targets failed"
1045 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1046 error "set user quota failed"
1048 # make sure the system is clean
1049 local used=$(getquota -u $TSTUSR global curspace)
1050 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1052 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
1053 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1055 test_1_check_write $testfile "user" $limit1
1057 $LFS setstripe $testfile2 -c 1 -i 0 ||
1058 error "setstripe $testfile2 failed"
1059 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
1060 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
1062 $RUNAS $DD of=$testfile2 count=20 ||
1063 quota_error u $TSTUSR \
1064 "$qtype write failure, but expect success"
1068 wait_delete_completed || error "wait_delete_completed failed"
1069 sync_all_data || true
1071 used=$(getquota -u $TSTUSR global curspace $qpool1)
1072 [ $used -eq 0 ] || quota_error u $TSTUSR \
1073 "user quota isn't released after deletion"
1075 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
1078 local global_limit=200 # MB
1079 local limit1=10 # MB
1080 local TESTDIR="$DIR/$tdir/"
1081 local testfile="$TESTDIR/$tfile-0"
1082 local qpool1="qpool1"
1085 setup_quota_test || error "setup quota failed with $?"
1088 set_ost_qtype $QTYPE || error "enable ost quota failed"
1090 log "User quota (block hardlimit:$global_limit MB)"
1091 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1092 error "set user quota failed"
1094 pool_add $qpool1 || error "pool_add failed"
1095 pool_add_targets $qpool1 0 0 ||
1096 error "pool_add_targets failed"
1098 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1099 error "set user quota failed"
1101 # make sure the system is clean
1102 local used=$(getquota -u $TSTUSR global curspace)
1103 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1105 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1107 test_1_check_write $testfile "user" $limit1
1109 pool_remove_target $qpool1 0
1111 wait_delete_completed || error "wait_delete_completed failed"
1112 sync_all_data || true
1114 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1115 # qunit for appropriate element in lgd array should be set
1116 # correctly(4096). Earlier it was not changed continuing to be 1024.
1117 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1118 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1119 # as it already was 1024. As flag "need_update" for this qunit was
1120 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1121 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1122 # became > 10M. QMT returned EINPROGRESS in a loop.
1123 # Check that it doesn't hung anymore.
1124 test_1_check_write $testfile "user" $limit1
1126 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1130 local global_limit=40 # MB
1131 local testfile="$DIR/$tdir/$tfile-0"
1132 local qpool="qpool1"
1133 local mdmb_param="osc.*.max_dirty_mb"
1134 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1137 setup_quota_test || error "setup quota failed with $?"
1138 $LCTL set_param $mdmb_param=1
1139 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1142 set_ost_qtype $QTYPE || error "enable ost quota failed"
1145 log "User quota (block hardlimit:$global_limit MB)"
1146 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1147 error "set user quota failed"
1149 pool_add $qpool || error "pool_add failed"
1150 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1151 error "pool_add_targets failed"
1153 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1154 error "set user quota failed"
1156 # make sure the system is clean
1157 local used=$(getquota -u $TSTUSR global curspace)
1159 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1161 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1162 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1165 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1166 quota_error u $TSTUSR \
1167 "$qtype write failure, but expect success"
1168 log "Write out of block quota ..."
1169 # this time maybe cache write, ignore it's failure
1170 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1171 # flush cache, ensure noquota flag is set on client
1172 cancel_lru_locks osc
1173 sync; sync_all_data || true
1175 $RUNAS $DD of=$testfile count=$((OSTCOUNT*3)) seek=$limit &&
1176 quota_error u $TSTUSR \
1177 "user write success, but expect EDQUOT"
1180 wait_delete_completed || error "wait_delete_completed failed"
1181 sync_all_data || true
1183 used=$(getquota -u $TSTUSR global curspace $qpool)
1184 [ $used -ne 0 ] && quota_error u $TSTUSR \
1185 "user quota isn't released after deletion"
1188 run_test 1g "Quota pools: Block hard limit with wide striping"
1192 local testfile="$DIR/$tdir/$tfile-0"
1194 check_set_fallocate_or_skip
1196 setup_quota_test || error "setup quota failed with $?"
1199 set_ost_qtype $QTYPE || error "enable ost quota failed"
1202 log "User quota (block hardlimit:$limit MB)"
1203 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1204 error "set user quota failed"
1206 # make sure the system is clean
1207 local used=$(getquota -u $TSTUSR global curspace)
1208 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1210 $LFS setstripe $testfile -i 0 -c 1 || error "setstripe $testfile failed"
1211 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1213 wait_quota_synced ost1 OST0000 usr $TSTID hardlimit $((limit*1024))
1215 check_write_fallocate $testfile "user" $limit
1218 wait_delete_completed || error "wait_delete_completed failed"
1219 sync_all_data || true
1220 used=$(getquota -u $TSTUSR global curspace)
1221 [ $used -eq 0 ] || quota_error u $TSTUSR \
1222 "user quota isn't released after deletion"
1224 run_test 1h "Block hard limit test using fallocate"
1227 local global_limit=200 # 200M
1228 local limit1=10 # 10M
1229 local TESTDIR="$DIR/$tdir/"
1230 local testfile="$TESTDIR/$tfile-0"
1231 local testfile1="$TESTDIR/$tfile-1"
1232 local testfile2="$TESTDIR/$tfile-2"
1233 local qpool1="qpool1"
1236 setup_quota_test || error "setup quota failed with $?"
1239 set_ost_qtype $QTYPE || error "enable ost quota failed"
1241 log "User quota (block hardlimit:$global_limit MB)"
1242 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1243 error "set user quota failed"
1245 pool_add $qpool1 || error "pool_add failed"
1246 pool_add_targets $qpool1 0 0 ||
1247 error "pool_add_targets failed"
1249 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1250 error "set user quota failed"
1252 # make sure the system is clean
1253 local used=$(getquota -u $TSTUSR global curspace)
1254 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1256 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1259 test_1_check_write $testfile "user" $limit1
1260 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1261 error "set user quota failed"
1263 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1264 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1265 quota_error u $TSTUSR "write failure, but expect success"
1269 wait_delete_completed || error "wait_delete_completed failed"
1270 sync_all_data || true
1272 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1273 error "set user quota failed"
1274 test_1_check_write $testfile "user" $limit1
1275 local tmp_limit=$(($limit1*2))
1276 # increase pool limit
1277 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1278 error "set user quota failed"
1279 # now write shouldn't fail
1280 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1281 quota_error u $TSTUSR "write failure, but expect success"
1282 # decrease pool limit
1283 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1284 error "set user quota failed"
1285 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1286 # flush cache, ensure noquota flag is set on client
1287 cancel_lru_locks osc
1288 sync; sync_all_data || true
1289 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1290 quota_error u $TSTUSR "write success, but expect failure"
1293 run_test 1i "Quota pools: different limit and usage relations"
1297 local testfile="$DIR/$tdir/$tfile-0"
1299 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1300 skip "need OST at least 2.15.52.206"
1302 is_project_quota_supported ||
1303 skip "skip project quota unsupported"
1305 setup_quota_test || error "setup quota failed with $?"
1308 set_ost_qtype $QTYPE || error "enable ost quota failed"
1311 log "--------------------------------------"
1312 log "Project quota (block hardlimit:$limit mb)"
1313 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1314 error "set project quota failed"
1316 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1317 change_project -p $TSTPRJID $testfile
1319 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1320 do_facet ost1 $LCTL set_param $procf=1 ||
1321 error "enable root quotas for project failed"
1322 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1324 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1325 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1326 quota_error "project" $TSTPRJID "root write to project success"
1328 do_facet ost1 $LCTL set_param $procf=0 ||
1329 error "disable root quotas for project failed"
1331 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1332 quota_error "project" $TSTPRJID "root write to project failed"
1337 used=$(getquota -p $TSTPRJID global curspace)
1338 (( $used == 0 )) || quota_error p $TSTPRJID \
1339 "project quota isn't released after deletion"
1341 run_test 1j "Enable project quota enforcement for root"
1343 # test inode hardlimit
1345 local testfile="$DIR/$tdir/$tfile-0"
1346 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1347 qmt.$FSNAME-QMT0000.md-0x0.info |
1348 sed -e 's/least qunit/least_qunit/' |
1349 awk '/least_qunit/{ print $2 }')
1352 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1353 limit=$((least_qunit * 1024))
1354 echo "least_qunit: '$least_qunit', limit: '$limit'"
1356 local free_inodes=$(mdt_free_inodes 0)
1357 echo "$free_inodes free inodes on master MDT"
1358 [ $free_inodes -lt $limit ] &&
1359 skip "not enough free inodes $free_inodes required $limit"
1361 setup_quota_test || error "setup quota failed with $?"
1364 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1367 log "User quota (inode hardlimit:$limit files)"
1368 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1369 error "set user quota failed"
1371 # make sure the system is clean
1372 local used=$(getquota -u $TSTUSR global curinodes)
1373 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1375 log "Create $((limit - least_qunit)) files ..."
1376 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1377 quota_error u $TSTUSR "user create failure, but expect success"
1378 # it is ok, if it fails on the last qunit
1379 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1380 log "Create out of file quota ..."
1381 $RUNAS touch ${testfile}_xxx &&
1382 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1385 unlinkmany ${testfile} $((limit - least_qunit)) ||
1386 error "unlinkmany $testfile failed"
1387 # if 2nd createmany got EDQUOT, not all of nodes would be created
1388 unlinkmany ${testfile}_yyy $least_qunit || true
1389 rm -f ${testfile}_xxx
1390 wait_delete_completed
1392 used=$(getquota -u $TSTUSR global curinodes)
1393 [ $used -ne 0 ] && quota_error u $TSTUSR \
1394 "user quota isn't released after deletion"
1395 resetquota -u $TSTUSR
1398 log "--------------------------------------"
1399 log "Group quota (inode hardlimit:$limit files)"
1400 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1401 error "set group quota failed"
1403 testfile=$DIR/$tdir/$tfile-1
1404 # make sure the system is clean
1405 used=$(getquota -g $TSTUSR global curinodes)
1406 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1408 log "Create $limit files ..."
1409 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1410 quota_error g $TSTUSR "group create failure, but expect success"
1411 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1412 log "Create out of file quota ..."
1413 $RUNAS touch ${testfile}_xxx &&
1414 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1417 unlinkmany ${testfile} $((limit - least_qunit)) ||
1418 error "unlinkmany $testfile failed"
1419 unlinkmany ${testfile}_yyy $least_qunit || true
1420 rm -f ${testfile}_xxx
1421 wait_delete_completed
1423 used=$(getquota -g $TSTUSR global curinodes)
1424 [ $used -ne 0 ] && quota_error g $TSTUSR \
1425 "user quota isn't released after deletion"
1427 resetquota -g $TSTUSR
1428 ! is_project_quota_supported &&
1429 echo "Skip project quota is not supported" && return 0
1432 log "--------------------------------------"
1433 log "Project quota (inode hardlimit:$limit files)"
1434 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1435 error "set project quota failed"
1437 testfile=$DIR/$tdir/$tfile-1
1438 # make sure the system is clean
1439 used=$(getquota -p $TSTPRJID global curinodes)
1441 error "Used inodes($used) for project $TSTPRJID isn't 0"
1443 change_project -sp $TSTPRJID $DIR/$tdir
1444 log "Create $limit files ..."
1445 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1446 quota_error p $TSTPRJID \
1447 "project create fail, but expect success"
1448 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1449 log "Create out of file quota ..."
1450 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1451 "project create success, but expect EDQUOT"
1452 change_project -C $DIR/$tdir
1455 used=$(getquota -p $TSTPRJID global curinodes)
1456 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1457 "project quota isn't released after deletion"
1460 run_test 2 "File hard limit (normal use and out of quota)"
1469 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1470 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1474 $LFS setstripe $testfile -c 1 -i 0
1475 chown $TSTUSR.$TSTUSR $testfile
1476 [ "$qtype" == "p" ] && is_project_quota_supported &&
1477 change_project -p $TSTPRJID $testfile
1479 echo "Write up to soft limit"
1480 $RUNAS $DD of=$testfile count=$limit ||
1481 quota_error a $TSTUSR "write failure, but expect success"
1482 OFFSET=$((limit * 1024))
1483 cancel_lru_locks osc
1485 echo "Write to exceed soft limit"
1486 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1487 quota_error a $TSTUSR "write failure, but expect success"
1488 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1489 cancel_lru_locks osc
1491 echo "mmap write when over soft limit"
1492 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1493 quota_error a $TSTUSR "mmap write failure, but expect success"
1494 cancel_lru_locks osc
1499 $SHOW_QUOTA_INFO_USER
1500 $SHOW_QUOTA_INFO_GROUP
1501 $SHOW_QUOTA_INFO_PROJID
1503 echo "Write before timer goes off"
1504 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1505 quota_error a $TSTUSR "write failure, but expect success"
1506 OFFSET=$((OFFSET + 1024))
1507 cancel_lru_locks osc
1509 wait_grace_time $qtype "block" $pool
1514 $SHOW_QUOTA_INFO_USER
1515 $SHOW_QUOTA_INFO_GROUP
1516 $SHOW_QUOTA_INFO_PROJID
1518 log "Write after timer goes off"
1519 # maybe cache write, ignore.
1520 # write up to soft least quint to consume all
1521 # possible slave granted space.
1522 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1523 count=$soft_limit seek=$OFFSET || true
1524 OFFSET=$((OFFSET + soft_limit))
1525 cancel_lru_locks osc
1526 log "Write after cancel lru locks"
1527 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1528 quota_error a $TSTUSR "write success, but expect EDQUOT"
1533 $SHOW_QUOTA_INFO_USER
1534 $SHOW_QUOTA_INFO_GROUP
1535 $SHOW_QUOTA_INFO_PROJID
1537 echo "Unlink file to stop timer"
1539 wait_delete_completed
1540 sync_all_data || true
1545 $SHOW_QUOTA_INFO_USER
1546 $SHOW_QUOTA_INFO_GROUP
1547 $SHOW_QUOTA_INFO_PROJID
1549 $LFS setstripe $testfile -c 1 -i 0
1550 chown $TSTUSR.$TSTUSR $testfile
1551 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1554 $RUNAS $DD of=$testfile count=$limit ||
1555 quota_error a $TSTUSR "write failure, but expect success"
1562 local grace=20 # seconds
1563 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1566 local testfile=$DIR/$tdir/$tfile-0
1568 # get minimum soft qunit size
1569 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1570 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1572 set_ost_qtype $QTYPE || error "enable ost quota failed"
1574 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1575 # make sure the system is clean
1576 local used=$(getquota -u $TSTUSR global curspace)
1577 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1579 $LFS setquota -t -u --block-grace $grace --inode-grace \
1580 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1581 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1582 error "set user quota failed"
1584 test_block_soft $testfile $grace $limit "u"
1586 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1587 testfile=$DIR/$tdir/$tfile-1
1588 # make sure the system is clean
1589 used=$(getquota -g $TSTUSR global curspace)
1590 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1592 $LFS setquota -t -g --block-grace $grace --inode-grace \
1593 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1594 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1595 error "set group quota failed"
1597 test_block_soft $testfile $grace $limit "g"
1599 if is_project_quota_supported; then
1600 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1601 testfile=$DIR/$tdir/$tfile-2
1602 # make sure the system is clean
1603 used=$(getquota -p $TSTPRJID global curspace)
1604 [ $used -ne 0 ] && error \
1605 "Used space($used) for project $TSTPRJID isn't 0."
1607 $LFS setquota -t -p --block-grace $grace --inode-grace \
1608 $MAX_IQ_TIME $DIR ||
1609 error "set project grace time failed"
1610 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1611 $DIR || error "set project quota failed"
1613 test_block_soft $testfile $grace $limit "p"
1614 resetquota -p $TSTPRJID
1615 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1616 $MAX_IQ_TIME $DIR ||
1617 error "restore project grace time failed"
1621 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1622 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1623 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1624 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1626 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1629 local grace=20 # seconds
1630 local qpool="qpool1"
1631 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1634 local testfile=$DIR/$tdir/$tfile-0
1637 # get minimum soft qunit size
1638 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1639 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1640 local glbl_limit=$((2*limit))
1641 local glbl_grace=$((2*grace))
1642 echo "limit $limit glbl_limit $glbl_limit"
1643 echo "grace $grace glbl_grace $glbl_grace"
1645 set_ost_qtype $QTYPE || error "enable ost quota failed"
1647 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1648 # make sure the system is clean
1649 local used=$(getquota -u $TSTUSR global curspace)
1650 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1652 pool_add $qpool || error "pool_add failed"
1653 pool_add_targets $qpool 0 1 ||
1654 error "pool_add_targets failed"
1656 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1657 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1658 $LFS setquota -t -u --block-grace $grace \
1659 --pool $qpool $DIR || error "set user grace time failed"
1661 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1662 error "set user quota failed"
1663 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1664 error "set user quota failed"
1666 test_block_soft $testfile $grace $limit "u" $qpool
1668 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1669 testfile=$DIR/$tdir/$tfile-1
1670 # make sure the system is clean
1671 used=$(getquota -g $TSTUSR global curspace)
1672 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1674 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1675 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1676 $LFS setquota -t -g --block-grace $grace \
1677 --pool $qpool $DIR || error "set group grace time failed"
1679 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1680 error "set group quota failed"
1681 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1682 error "set group quota failed"
1684 test_block_soft $testfile $grace $limit "g" $qpool
1686 if is_project_quota_supported; then
1687 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1688 testfile=$DIR/$tdir/$tfile-2
1689 # make sure the system is clean
1690 used=$(getquota -p $TSTPRJID global curspace)
1691 [ $used -ne 0 ] && error \
1692 "Used space($used) for project $TSTPRJID isn't 0."
1694 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1695 $MAX_IQ_TIME $DIR ||
1696 error "set project grace time failed"
1697 $LFS setquota -t -p --block-grace $grace \
1698 --pool $qpool $DIR ||
1699 error "set project grace time failed"
1701 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1702 $DIR || error "set project quota failed"
1703 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1704 --pool $qpool $DIR || error "set project quota failed"
1706 test_block_soft $testfile $grace $limit "p" $qpool
1707 resetquota -p $TSTPRJID
1708 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1709 $MAX_IQ_TIME $DIR ||
1710 error "restore project grace time failed"
1711 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1712 $DIR || error "set project grace time failed"
1716 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1717 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1718 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1719 --pool $qpool $DIR || error "restore user grace time failed"
1720 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1721 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1722 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1723 --pool $qpool $DIR || error "restore group grace time failed"
1725 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1728 local grace=20 # seconds
1729 local qpool="qpool1"
1730 local qpool2="qpool2"
1731 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1734 local testfile=$DIR/$tdir/$tfile-0
1737 # get minimum soft qunit size
1738 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1739 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1740 local limit2=$((limit+4))
1741 local glbl_limit=$((limit+8))
1742 local grace1=$((grace+10))
1744 local glbl_grace=$((grace+20))
1745 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1746 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1748 set_ost_qtype $QTYPE || error "enable ost quota failed"
1750 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1751 # make sure the system is clean
1752 local used=$(getquota -u $TSTUSR global curspace)
1753 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1755 pool_add $qpool || error "pool_add failed"
1756 pool_add_targets $qpool 0 1 ||
1757 error "pool_add_targets failed"
1759 pool_add $qpool2 || error "pool_add failed"
1760 pool_add_targets $qpool2 0 1 ||
1761 error "pool_add_targets failed"
1763 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1764 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1765 $LFS setquota -t -u --block-grace $grace1 \
1766 --pool $qpool $DIR || error "set user grace time failed"
1767 $LFS setquota -t -u --block-grace $grace2 \
1768 --pool $qpool2 $DIR || error "set user grace time failed"
1770 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1771 error "set user quota failed"
1772 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1773 error "set user quota failed"
1774 # qpool has minimum soft limit, but its grace is greater than
1775 # the grace period of qpool2. Thus write shouldn't fail when
1776 # hit qpool soft limit - only when reaches up qpool2 limit
1777 # after grace2 seconds.
1778 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1779 error "set user quota failed"
1781 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1784 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1785 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1786 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1787 --pool $qpool $DIR || error "restore user grace time failed"
1788 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1789 --pool $qpool2 $DIR || error "restore user grace time failed"
1791 run_test 3c "Quota pools: check block soft limit on different pools"
1798 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1799 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1802 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1804 echo "Create files to exceed soft limit"
1805 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1806 quota_error a $TSTUSR "create failure, but expect success"
1807 local trigger_time=$(date +%s)
1809 sync_all_data || true
1811 local cur_time=$(date +%s)
1812 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1813 error "Passed grace time $grace, $trigger_time, $cur_time"
1815 echo "Create file before timer goes off"
1816 $RUNAS touch ${TESTFILE}_before ||
1817 quota_error a $TSTUSR "failed create before timer expired," \
1818 "but expect success. $trigger_time, $cur_time"
1819 sync_all_data || true
1821 wait_grace_time $qtype "file"
1826 $SHOW_QUOTA_INFO_USER
1827 $SHOW_QUOTA_INFO_GROUP
1828 $SHOW_QUOTA_INFO_PROJID
1830 echo "Create file after timer goes off"
1831 # exceed least soft limit is possible
1832 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1833 quota_error a $TSTUSR "create after timer expired," \
1835 sync_all_data || true
1840 $SHOW_QUOTA_INFO_USER
1841 $SHOW_QUOTA_INFO_GROUP
1842 $SHOW_QUOTA_INFO_PROJID
1844 echo "Unlink files to stop timer"
1845 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1846 wait_delete_completed
1849 $RUNAS touch ${TESTFILE}_xxx ||
1850 quota_error a $TSTUSR "touch after timer stop failure," \
1851 "but expect success"
1852 sync_all_data || true
1860 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1861 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1862 local TESTFILE=$DIR/$tdir/$tfile-0
1865 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1866 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1868 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1869 # make sure the system is clean
1870 local USED=$(getquota -u $TSTUSR global curinodes)
1871 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1873 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1874 $GRACE $DIR || error "set user grace time failed"
1875 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1876 error "set user quota failed"
1878 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1880 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1881 # make sure the system is clean
1882 USED=$(getquota -g $TSTUSR global curinodes)
1883 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1885 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1886 $GRACE $DIR || error "set group grace time failed"
1887 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1888 error "set group quota failed"
1889 TESTFILE=$DIR/$tdir/$tfile-1
1891 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1893 if is_project_quota_supported; then
1894 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1895 # make sure the system is clean
1896 USED=$(getquota -p $TSTPRJID global curinodes)
1897 [ $USED -ne 0 ] && error \
1898 "Used space($USED) for project $TSTPRJID isn't 0."
1900 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1901 $GRACE $DIR || error "set project grace time failed"
1902 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1903 error "set project quota failed"
1905 TESTFILE=$DIR/$tdir/$tfile-1
1906 # one less than limit, because of parent directory included.
1907 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1908 resetquota -p $TSTPRJID
1909 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1910 $MAX_IQ_TIME $DIR ||
1911 error "restore project grace time failed"
1915 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1916 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1917 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1918 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1920 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1923 local GR_STR1="1w3d"
1924 local GR_STR2="1000s"
1926 local GR_STR4="1w2d3h4m5s"
1928 local GR_STR6="18446744073709551615"
1931 wait_delete_completed
1933 # test of valid grace strings handling
1934 echo "Valid grace strings test"
1935 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1936 $GR_STR2 $DIR || error "set user grace time failed"
1937 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1938 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1939 $GR_STR4 $DIR || error "set group grace time quota failed"
1940 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1942 # test of invalid grace strings handling
1943 echo " Invalid grace strings test"
1944 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1945 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1946 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1950 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1951 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1952 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1953 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1955 run_test 4b "Grace time strings handling"
1957 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1959 local BLIMIT=10 # MB
1960 local ILIMIT=10 # inodes
1962 setup_quota_test || error "setup quota failed with $?"
1964 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1965 set_ost_qtype $QTYPE || error "enable ost quota failed"
1967 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1968 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1969 error "set user quota failed"
1970 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1971 if is_project_quota_supported; then
1972 error "set group quota failed"
1973 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1974 -I $ILIMIT $DIR || error "set project quota failed"
1977 # make sure the system is clean
1978 local USED=$(getquota -u $TSTUSR global curinodes)
1979 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1980 USED=$(getquota -g $TSTUSR global curinodes)
1981 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1982 USED=$(getquota -u $TSTUSR global curspace)
1983 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1984 USED=$(getquota -g $TSTUSR global curspace)
1985 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1986 if is_project_quota_supported; then
1987 USED=$(getquota -p $TSTPRJID global curinodes)
1989 error "Used inode($USED) for project $TSTPRJID isn't 0."
1990 USED=$(getquota -p $TSTPRJID global curspace)
1992 error "Used block($USED) for project $TSTPRJID isn't 0."
1995 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1996 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1997 error "create failure, expect success"
1998 if is_project_quota_supported; then
1999 touch $DIR/$tdir/$tfile-0_1
2000 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
2002 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
2003 error "write failure, expect success"
2005 echo "Chown files to $TSTUSR.$TSTUSR ..."
2006 for i in $(seq 0 $ILIMIT); do
2007 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
2008 quota_error a $TSTUSR "chown failure, expect success"
2012 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
2013 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
2015 run_test 5 "Chown & chgrp successfully even out of block/file quota"
2017 # test dropping acquire request on master
2021 # Clear dmesg so watchdog is not triggered by previous
2023 do_facet ost1 dmesg -c > /dev/null
2025 setup_quota_test || error "setup quota failed with $?"
2027 # make sure the system is clean
2028 local USED=$(getquota -u $TSTUSR global curspace)
2029 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2031 # make sure no granted quota on ost
2032 set_ost_qtype $QTYPE || error "enable ost quota failed"
2033 resetquota -u $TSTUSR
2035 # create file for $TSTUSR
2036 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
2037 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2038 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2040 # create file for $TSTUSR2
2041 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
2042 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
2043 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
2045 # cache per-ID lock for $TSTUSR on slave
2046 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2047 error "set quota failed"
2048 $RUNAS $DD of=$TESTFILE count=1 ||
2049 error "write $TESTFILE failure, expect success"
2050 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
2051 error "write $TESTFILE2 failure, expect success"
2053 if at_is_enabled; then
2054 at_max_saved=$(at_max_get ost1)
2055 at_max_set $TIMEOUT ost1
2057 # write to enforced ID ($TSTUSR) to exceed limit to make sure
2058 # DQACQ is sent, which makes at_max to take effect
2059 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
2062 wait_delete_completed
2066 sync_all_data || true
2068 #define QUOTA_DQACQ 601
2069 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
2070 lustre_fail mds 0x513 601
2072 do_facet ost1 $LCTL set_param \
2073 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
2075 # write to un-enforced ID ($TSTUSR2) should succeed
2076 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
2077 error "write failure, expect success"
2079 # write to enforced ID ($TSTUSR) in background, exceeding limit
2080 # to make sure DQACQ is sent
2081 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
2084 # watchdog timer uses a factor of 2
2085 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
2086 sleep $((TIMEOUT * 2 + 1))
2088 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
2090 # write should be blocked and never finished
2091 if ! ps -p $DDPID > /dev/null 2>&1; then
2093 error "write finished incorrectly!"
2098 # no watchdog is triggered
2099 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2100 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2101 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2102 [ -z "$watchdog" ] || error "$watchdog"
2104 rm -f $TMP/lustre-log-${TESTNAME}.log
2106 # write should continue then fail with EDQUOT
2110 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2111 if [ $count -ge 240 ]; then
2112 quota_error u $TSTUSR "dd not finished in $count secs"
2114 count=$((count + 1))
2115 if [ $((count % 30)) -eq 0 ]; then
2116 c_size=$(stat -c %s $TESTFILE)
2117 echo "Waiting $count secs. $c_size"
2123 run_test 6 "Test dropping acquire request on master"
2125 # quota reintegration (global index)
2127 local TESTFILE=$DIR/$tdir/$tfile
2130 [ "$SLOW" = "no" ] && LIMIT=5
2132 setup_quota_test || error "setup quota failed with $?"
2134 # make sure the system is clean
2135 local USED=$(getquota -u $TSTUSR global curspace)
2136 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2138 # make sure no granted quota on ost1
2139 set_ost_qtype $QTYPE || error "enable ost quota failed"
2140 resetquota -u $TSTUSR
2141 set_ost_qtype "none" || error "disable ost quota failed"
2143 local OSTUUID=$(ostuuid_from_index 0)
2144 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2146 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2149 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2150 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2155 echo "Enable quota & set quota limit for $TSTUSR"
2156 set_ost_qtype $QTYPE || error "enable ost quota failed"
2157 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2158 error "set quota failed"
2160 echo "Start ost1..."
2161 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2164 wait_ost_reint $QTYPE || error "reintegration failed"
2166 # hardlimit should have been fetched by slave during global
2167 # reintegration, write will exceed quota
2168 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2169 quota_error u $TSTUSR "write success, but expect EDQUOT"
2172 wait_delete_completed
2173 sync_all_data || true
2179 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2180 error "clear quota failed"
2182 echo "Start ost1..."
2183 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2186 wait_ost_reint $QTYPE || error "reintegration failed"
2188 # hardlimit should be cleared on slave during reintegration
2189 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2190 quota_error u $TSTUSR "write error, but expect success"
2192 run_test 7a "Quota reintegration (global index)"
2194 # quota reintegration (slave index)
2196 local limit=100000 # MB
2197 local TESTFILE=$DIR/$tdir/$tfile
2199 setup_quota_test || error "setup quota failed with $?"
2201 # make sure the system is clean
2202 local USED=$(getquota -u $TSTUSR global curspace)
2203 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2205 # make sure no granted quota on ost1
2206 set_ost_qtype $QTYPE || error "enable ost quota failed"
2207 resetquota -u $TSTUSR
2208 set_ost_qtype "none" || error "disable ost quota failed"
2210 local OSTUUID=$(ostuuid_from_index 0)
2211 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2213 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2216 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2217 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2219 # consume some space to make sure the granted space will not
2220 # be released during reconciliation
2221 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2222 error "consume space failure, expect success"
2224 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2225 lustre_fail mds 0xa02
2227 set_ost_qtype $QTYPE || error "enable ost quota failed"
2228 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2229 error "set quota failed"
2231 # ignore the write error
2232 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2234 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2238 echo "Restart ost to trigger reintegration..."
2240 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2243 wait_ost_reint $QTYPE || error "reintegration failed"
2245 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2246 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2251 run_test 7b "Quota reintegration (slave index)"
2253 # quota reintegration (restart mds during reintegration)
2256 local TESTFILE=$DIR/$tdir/$tfile
2258 [ "$SLOW" = "no" ] && LIMIT=5
2260 setup_quota_test || error "setup quota failed with $?"
2262 # make sure the system is clean
2263 local USED=$(getquota -u $TSTUSR global curspace)
2264 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2266 set_ost_qtype "none" || error "disable ost quota failed"
2267 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2268 error "set quota failed"
2270 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2271 lustre_fail ost 0xa03
2274 set_ost_qtype $QTYPE || error "enable ost quota failed"
2275 # trigger reintegration
2276 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2277 procf=${procf}quota_slave.force_reint
2278 do_facet ost1 $LCTL set_param $procf=1 ||
2279 error "force reintegration failed"
2287 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2290 # wait longer than usual to make sure the reintegration
2291 # is triggered by quota wb thread.
2292 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2294 # hardlimit should have been fetched by slave during global
2295 # reintegration, write will exceed quota
2296 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2297 quota_error u $TSTUSR "write success, but expect EDQUOT"
2300 run_test 7c "Quota reintegration (restart mds during reintegration)"
2302 # Quota reintegration (Transfer index in multiple bulks)
2304 local TESTFILE=$DIR/$tdir/$tfile
2305 local TESTFILE1="$DIR/$tdir/$tfile"-1
2308 setup_quota_test || error "setup quota failed with $?"
2310 set_ost_qtype "none" || error "disable ost quota failed"
2311 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2312 error "set quota for $TSTUSR failed"
2313 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2314 error "set quota for $TSTUSR2 failed"
2316 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2317 lustre_fail mds 0x608 0
2319 # enable quota to tirgger reintegration
2320 set_ost_qtype "u" || error "enable ost quota failed"
2321 wait_ost_reint "u" || error "reintegration failed"
2325 # hardlimit should have been fetched by slave during global
2326 # reintegration, write will exceed quota
2327 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2328 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2330 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2331 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2334 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2336 # quota reintegration (inode limits)
2338 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2340 # LU-2435: skip this quota test if underlying zfs version has not
2341 # supported native dnode accounting
2342 [ "$mds1_FSTYPE" == zfs ] && {
2343 local F="feature@userobj_accounting"
2344 local pool=$(zpool_name mds1)
2345 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2347 [[ "$feature" != *" active "* ]] &&
2348 skip "requires zpool with active userobj_accounting"
2351 local ilimit=$((1024 * 2)) # inodes
2352 local TESTFILE=$DIR/${tdir}-1/$tfile
2354 setup_quota_test || error "setup quota failed with $?"
2356 # make sure the system is clean
2357 local USED=$(getquota -u $TSTUSR global curinodes)
2358 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2360 # make sure no granted quota on mdt1
2361 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2362 resetquota -u $TSTUSR
2363 set_mdt_qtype "none" || error "disable mdt quota failed"
2365 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2366 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2367 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2370 echo "Stop mds${MDSCOUNT}..."
2373 echo "Enable quota & set quota limit for $TSTUSR"
2374 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2375 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2376 error "set quota failed"
2378 echo "Start mds${MDSCOUNT}..."
2379 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2382 wait_mdt_reint $QTYPE || error "reintegration failed"
2384 echo "create remote dir"
2385 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2386 error "create remote dir failed"
2387 chmod 0777 $DIR/${tdir}-1
2389 # hardlimit should have been fetched by slave during global
2390 # reintegration, create will exceed quota
2391 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2392 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2394 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2395 wait_delete_completed
2396 sync_all_data || true
2398 echo "Stop mds${MDSCOUNT}..."
2401 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2402 error "clear quota failed"
2404 echo "Start mds${MDSCOUNT}..."
2405 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2408 wait_mdt_reint $QTYPE || error "reintegration failed"
2410 # hardlimit should be cleared on slave during reintegration
2411 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2412 quota_error u $TSTUSR "create failed, expect success"
2414 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2415 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2417 run_test 7e "Quota reintegration (inode limits)"
2419 # run dbench with quota enabled
2421 local BLK_LIMIT="100g" #100G
2422 local FILE_LIMIT=1000000
2424 setup_quota_test || error "setup quota failed with $?"
2426 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2427 set_ost_qtype $QTYPE || error "enable ost quota failed"
2429 echo "Set enough high limit for user: $TSTUSR"
2430 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2431 error "set user quota failed"
2432 echo "Set enough high limit for group: $TSTUSR"
2433 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2434 error "set group quota failed"
2435 if is_project_quota_supported; then
2436 change_project -sp $TSTPRJID $DIR/$tdir
2437 echo "Set enough high limit for project: $TSTPRJID"
2438 $LFS setquota -p $TSTPRJID -b 0 \
2439 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2440 error "set project quota failed"
2444 [ "$SLOW" = "no" ] && duration=" -t 120"
2445 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2446 quota_error a $TSTUSR "dbench failed!"
2448 is_project_quota_supported && change_project -C $DIR/$tdir
2451 run_test 8 "Run dbench with quota enabled"
2453 # this check is just for test_9
2454 OST0_MIN=4900000 #4.67G
2456 check_whether_skip () {
2457 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2458 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2459 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2460 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2467 # run for fixing bug10707, it needs a big room. test for 64bit
2469 local filesize=$((1024 * 9 / 2)) # 4.5G
2471 check_whether_skip && return 0
2473 setup_quota_test || error "setup quota failed with $?"
2475 set_ost_qtype "ug" || error "enable ost quota failed"
2477 local TESTFILE="$DIR/$tdir/$tfile-0"
2478 local BLK_LIMIT=100G #100G
2479 local FILE_LIMIT=1000000
2481 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2483 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2485 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2486 error "set user quota failed"
2488 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2489 "for group: $TSTUSR"
2490 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2491 error "set group quota failed"
2493 quota_show_check a u $TSTUSR
2494 quota_show_check a g $TSTUSR
2496 echo "Create test file"
2497 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2498 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2500 log "Write the big file of 4.5G ..."
2501 $RUNAS $DD of=$TESTFILE count=$filesize ||
2502 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2512 run_test 9 "Block limit larger than 4GB (b10707)"
2515 local TESTFILE=$DIR/$tdir/$tfile
2517 setup_quota_test || error "setup quota failed with $?"
2519 # set limit to root user should fail
2520 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2521 error "set limit for root user successfully, expect failure"
2522 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2523 error "set limit for root group successfully, expect failure"
2524 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2525 error "set limit for project 0 successfully, expect failure"
2527 # root user can overrun quota
2528 set_ost_qtype "ug" || error "enable ost quota failed"
2530 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2531 error "set quota failed"
2532 quota_show_check b u $TSTUSR
2534 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2535 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2537 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2538 error "write failure, expect success"
2540 run_test 10 "Test quota for root user"
2543 local TESTFILE=$DIR/$tdir/$tfile
2544 setup_quota_test || error "setup quota failed with $?"
2546 set_mdt_qtype "ug" || error "enable mdt quota failed"
2547 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2548 error "set quota failed"
2550 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2551 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2553 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2554 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2557 local USED=$(getquota -u $TSTUSR global curinodes)
2558 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2560 run_test 11 "Chown/chgrp ignores quota"
2563 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2565 local blimit=22 # MB
2566 local blk_cnt=$((blimit - 5))
2567 local TESTFILE0="$DIR/$tdir/$tfile"-0
2568 local TESTFILE1="$DIR/$tdir/$tfile"-1
2570 setup_quota_test || error "setup quota failed with $?"
2572 set_ost_qtype "u" || error "enable ost quota failed"
2573 quota_show_check b u $TSTUSR
2575 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2576 error "set quota failed"
2578 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2579 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2580 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2581 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2583 echo "Write to ost0..."
2584 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2585 quota_error a $TSTUSR "dd failed"
2587 echo "Write to ost1..."
2588 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2589 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2591 echo "Free space from ost0..."
2593 wait_delete_completed
2594 sync_all_data || true
2596 echo "Write to ost1 after space freed from ost0..."
2597 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2598 quota_error a $TSTUSR "rebalancing failed"
2600 run_test 12a "Block quota rebalancing"
2603 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2605 local ilimit=$((1024 * 2)) # inodes
2606 local TESTFILE0=$DIR/$tdir/$tfile
2607 local TESTFILE1=$DIR/${tdir}-1/$tfile
2609 setup_quota_test || error "setup quota failed with $?"
2611 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2612 chmod 0777 $DIR/${tdir}-1
2614 set_mdt_qtype "u" || error "enable mdt quota failed"
2615 quota_show_check f u $TSTUSR
2617 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2618 error "set quota failed"
2620 echo "Create $ilimit files on mdt0..."
2621 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2622 quota_error u $TSTUSR "create failed, but expect success"
2624 echo "Create files on mdt1..."
2625 $RUNAS createmany -m $TESTFILE1 1 &&
2626 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2628 echo "Free space from mdt0..."
2629 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2630 wait_delete_completed
2631 sync_all_data || true
2633 echo "Create files on mdt1 after space freed from mdt0..."
2634 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2635 quota_error a $TSTUSR "rebalancing failed"
2637 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2638 error "unlink mdt1 files failed"
2639 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2641 run_test 12b "Inode quota rebalancing"
2644 local TESTFILE=$DIR/$tdir/$tfile
2645 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2646 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2648 setup_quota_test || error "setup quota failed with $?"
2650 set_ost_qtype "u" || error "enable ost quota failed"
2651 quota_show_check b u $TSTUSR
2653 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2654 error "set quota failed"
2655 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2656 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2658 # clear the locks in cache first
2659 do_facet ost1 $LCTL set_param -n $procf=clear
2660 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2661 [ $nlock -eq 0 ] || error "$nlock cached locks"
2663 # write to acquire the per-ID lock
2664 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2665 quota_error a $TSTUSR "dd failed"
2667 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2668 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2670 # clear quota doesn't trigger per-ID lock cancellation
2671 resetquota -u $TSTUSR
2672 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2673 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2675 # clear the per-ID lock
2676 do_facet ost1 $LCTL set_param -n $procf=clear
2677 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2678 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2680 # spare quota should be released
2681 local OSTUUID=$(ostuuid_from_index 0)
2682 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2683 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2684 [ $limit -le $space ] ||
2685 error "spare quota isn't released, limit:$limit, space:$space"
2687 run_test 13 "Cancel per-ID lock in the LRU list"
2691 (( $MDS1_VERSION >= $(version_code 2.15.54.67) )) ||
2692 skip "Need MDS >= v2_15_54-67-gdfe7d for qmt_site_recalc_cb fix"
2694 local qpool="qpool1"
2695 local tfile1="$DIR/$tdir/$tfile-0"
2698 setup_quota_test || error "setup quota failed with $?"
2700 set_ost_qtype $QTYPE || error "enable ost quota failed"
2702 $LFS setquota -u $TSTUSR -b 0 -B 100M -i 0 -I 0 $DIR ||
2703 error "set user quota failed"
2704 pool_add $qpool || error "pool_add failed"
2705 pool_add_targets $qpool 0 ||
2706 error "pool_add_targets failed"
2707 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
2708 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
2709 error "set user quota failed"
2711 # don't care about returned value
2712 $RUNAS $DD of=$tfile1 count=10 oflag=direct
2716 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2717 error "set user quota failed"
2719 # no panic after removing OST0000 from the pool
2720 pool_remove_target $qpool 0
2721 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2723 run_test 14 "check panic in qmt_site_recalc_cb"
2726 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2728 wait_delete_completed
2729 sync_all_data || true
2732 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2733 error "set user quota failed"
2734 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2735 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2736 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2737 resetquota -u $TSTUSR
2740 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2741 error "set group quota failed"
2742 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2743 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2744 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2745 resetquota -g $TSTUSR
2747 run_test 15 "Set over 4T block quota"
2751 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2752 skip "Not supported Lustre client before 2.14.55"
2754 setup_quota_test || error "setup quota failed with $?"
2756 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2757 error "failed to set quota for user $TSTUSR"
2758 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2759 error "failed to set quota for group $TSTUSR"
2761 $RUNAS $DD of=$DIR/$tdir/$tfile count=50 ||
2762 quota_error u $TSTUSR "write failure"
2764 $LFS quota -u $TSTUSR $MOUNT ||
2765 quota_error u $TSTUSR "failed to get quota"
2767 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2769 $LCTL --device %$OSC deactivate
2770 stack_trap "$LCTL --device %$OSC activate"
2772 $LFS quota -v -u $TSTUSR $MOUNT ||
2773 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2774 $LFS quota -v -g $TSTUSR $MOUNT ||
2775 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2777 (( $MDSCOUNT > 1 )) || return 0
2779 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2781 $LCTL --device %$MDC deactivate
2782 stack_trap "$LCTL --device %$MDC activate"
2784 $LFS quota -v -u $TSTUSR $MOUNT ||
2785 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2786 $LFS quota -v -g $TSTUSR $MOUNT ||
2787 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2789 run_test 16a "lfs quota should skip the inactive MDT/OST"
2800 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2801 skip "Not supported Lustre client before 2.14.55"
2803 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2806 if ! combined_mgs_mds ; then
2811 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2812 $(mdsdevname 1) $(mdsvdevname 1)
2813 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2814 $(mdsdevname 2) $(mdsvdevname 2)
2815 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2816 $(mdsdevname 3) $(mdsvdevname 3)
2818 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2819 $(ostdevname 1) $(ostvdevname 1)
2820 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2821 $(ostdevname 2) $(ostvdevname 2)
2823 stack_trap cleanup_16b
2825 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2826 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2827 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2828 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2829 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2831 mount_client $MOUNT || error "Unable to mount client"
2833 setup_quota_test || error "setup quota failed with $?"
2835 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2836 error "failed to set quota for user $TSTUSR"
2837 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2838 error "failed to set quota for group $TSTUSR"
2840 $RUNAS $DD of=$DIR/$tdir/$tfile count=10 ||
2841 quota_error u $TSTUSR "write failure"
2843 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2844 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2845 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2846 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2848 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2852 local BLKS=1 # 1M less than limit
2853 local TESTFILE=$DIR/$tdir/$tfile
2855 setup_quota_test || error "setup quota failed with $?"
2857 # make sure the system is clean
2858 local USED=$(getquota -u $TSTUSR global curspace)
2859 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2861 set_ost_qtype "ug" || error "enable ost quota failed"
2862 # make sure no granted quota on ost
2863 resetquota -u $TSTUSR
2864 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2865 error "set quota failed"
2867 quota_show_check b u $TSTUSR
2869 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2870 lustre_fail mds 0xa04 $err_code
2872 # write in background
2873 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2877 # write should be blocked and never finished
2878 if ! ps -p $DDPID > /dev/null 2>&1; then
2880 quota_error u $TSTUSR "write finished incorrectly!"
2888 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2890 if [ $count -gt $timeout ]; then
2891 quota_error u $TSTUSR "dd is not finished!"
2896 sync; sync_all_data || true
2898 USED=$(getquota -u $TSTUSR global curspace)
2899 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2900 "Used space(${USED}K) is less than ${BLKS}M"
2905 # DQACQ return recoverable error
2907 echo "DQACQ return -ENOLCK"
2909 test_17sub 37 || error "Handle -ENOLCK failed"
2911 echo "DQACQ return -EAGAIN"
2913 test_17sub 11 || error "Handle -EAGAIN failed"
2915 echo "DQACQ return -ETIMEDOUT"
2916 #define ETIMEDOUT 110
2917 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2919 echo "DQACQ return -ENOTCONN"
2920 #define ENOTCONN 107
2921 test_17sub 107 || error "Handle -ENOTCONN failed"
2924 run_test 17 "DQACQ return recoverable error"
2928 local blimit=200 # MB
2929 local TESTFILE="$DIR/$tdir/$tfile"
2931 setup_quota_test || error "setup quota failed with $?"
2933 set_ost_qtype "u" || error "enable ost quota failed"
2934 log "User quota (limit: $blimit)"
2935 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2936 error "set quota failed"
2937 quota_show_check b u $TSTUSR
2939 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2940 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2942 local timeout=$($LCTL get_param -n timeout)
2944 if [ $io_type = "directio" ]; then
2945 log "Write 100M (directio) ..."
2946 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2948 log "Write 100M (buffered) ..."
2949 $RUNAS $DD of=$TESTFILE count=100 &
2953 replay_barrier $SINGLEMDS
2954 log "Fail mds for $((2 * timeout)) seconds"
2955 fail $SINGLEMDS $((2 * timeout))
2958 if at_is_enabled; then
2959 timeout=$(at_max_get mds)
2961 timeout=$($LCTL get_param -n timeout)
2965 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2966 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2967 log "it took $count second"
2972 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2974 cancel_lru_locks mdc
2975 cancel_lru_locks osc
2978 local testfile_size=$(stat -c %s $TESTFILE)
2979 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2980 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2981 "got ${testfile_size}. Verifying file failed!"
2986 # test when mds does failover, the ost still could work well
2987 # this test shouldn't trigger watchdog b=14840
2989 # Clear dmesg so watchdog is not triggered by previous
2991 do_facet ost1 dmesg -c > /dev/null
2994 test_18_sub directio
2996 # check if watchdog is triggered
2997 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2998 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2999 { print; }' $TMP/lustre-log-${TESTNAME}.log)
3000 [ -z "$watchdog" ] || error "$watchdog"
3001 rm -f $TMP/lustre-log-${TESTNAME}.log
3003 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
3007 local TESTFILE=$DIR/$tdir/$tfile
3009 setup_quota_test || error "setup quota failed with $?"
3011 set_ost_qtype $QTYPE || error "enable ost quota failed"
3013 # bind file to a single OST
3014 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3015 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3017 echo "Set user quota (limit: ${blimit}M)"
3018 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
3019 error "set user quota failed"
3020 quota_show_check b u $TSTUSR
3021 echo "Update quota limits"
3022 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
3023 error "set group quota failed"
3024 quota_show_check b u $TSTUSR
3026 # first wirte might be cached
3027 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
3028 cancel_lru_locks osc
3030 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
3031 quota_error u $TSTUSR "Write success, expect failure"
3034 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
3036 test_20() { # b15754
3037 local LSTR=(2g 1t 4k 3m) # limits strings
3039 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
3042 resetquota -u $TSTUSR
3044 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
3045 $MOUNT || error "could not set quota limits"
3046 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
3047 --inode-softlimit ${LSTR[2]} \
3048 --inode-hardlimit ${LSTR[3]} \
3049 $MOUNT || error "could not set quota limits"
3051 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
3052 error "bsoftlimit was not set properly"
3053 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
3054 error "bhardlimit was not set properly"
3055 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
3056 error "isoftlimit was not set properly"
3057 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
3058 error "ihardlimit was not set properly"
3060 resetquota -u $TSTUSR
3062 run_test 20 "Test if setquota specifiers work properly (b15754)"
3069 local time=$(($(date +%s) + seconds))
3070 while [ $(date +%s) -lt $time ]; do
3071 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
3075 # run for fixing bug16053, setquota shouldn't fail when writing and
3076 # deleting are happening
3078 local TESTFILE="$DIR/$tdir/$tfile"
3079 local BLIMIT=10 # 10G
3080 local ILIMIT=1000000
3082 setup_quota_test || error "setup quota failed with $?"
3084 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3086 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
3087 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
3088 error "set user quota failed"
3089 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
3090 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
3091 error "set group quota failed"
3092 if is_project_quota_supported; then
3093 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
3094 "project: $TSTPRJID"
3095 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
3096 $MOUNT || error "set project quota failed"
3099 # repeat writing on a 1M file
3100 test_21_sub ${TESTFILE}_1 1 30 &
3102 # repeat writing on a 128M file
3103 test_21_sub ${TESTFILE}_2 128 30 &
3106 local time=$(($(date +%s) + 30))
3108 while [ $(date +%s) -lt $time ]; do
3109 log "Set quota for $i times"
3110 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3111 -I $((ILIMIT + i)) $MOUNT ||
3112 error "Set user quota failed"
3113 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3114 -I $((ILIMIT + i)) $MOUNT ||
3115 error "Set group quota failed"
3116 if is_project_quota_supported; then
3117 $LFS setquota -p $TSTPRJID -b 0 -B \
3118 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
3119 error "Set project quota failed"
3127 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
3129 if [ $count -gt 60 ]; then
3130 quota_error a $TSTUSR "dd should be finished!"
3134 echo "(dd_pid=$DDPID1, time=$count)successful"
3138 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
3140 if [ $count -gt 60 ]; then
3141 quota_error a $TSTUSR "dd should be finished!"
3145 echo "(dd_pid=$DDPID2, time=$count)successful"
3147 run_test 21 "Setquota while writing & deleting (b16053)"
3149 # enable/disable quota enforcement permanently
3151 echo "Set both mdt & ost quota type as ug"
3153 is_project_quota_supported && qtype=$QTYPE
3154 set_mdt_qtype $qtype || error "enable mdt quota failed"
3155 set_ost_qtype $qtype || error "enable ost quota failed"
3158 stopall || error "failed to stopall (1)"
3162 echo "Verify if quota is enabled"
3163 local qtype1=$(mdt_quota_type)
3164 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3165 qtype=$(ost_quota_type)
3166 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3168 echo "Set both mdt & ost quota type as none"
3169 set_mdt_qtype "none" || error "disable mdt quota failed"
3170 set_ost_qtype "none" || error "disable ost quota failed"
3173 stopall || error "failed to stopall (2)"
3178 echo "Verify if quota is disabled"
3179 qtype=$(mdt_quota_type)
3180 [ $qtype != "none" ] && error "mdt quota setting is lost"
3181 qtype=$(ost_quota_type)
3182 [ $qtype != "none" ] && error "ost quota setting is lost"
3186 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3189 local TESTFILE="$DIR/$tdir/$tfile"
3192 setup_quota_test || error "setup quota failed with $?"
3194 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3197 log "User quota (limit: $LIMIT MB)"
3198 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3199 error "set quota failed"
3200 quota_show_check b u $TSTUSR
3202 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3203 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3205 log "Step1: trigger EDQUOT with O_DIRECT"
3206 log "Write half of file"
3207 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3208 quota_error u $TSTUSR "(1) Write failure, expect success." \
3210 log "Write out of block quota ..."
3211 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3212 oflag=direct conv=notrunc &&
3213 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3217 log "Step2: rewrite should succeed"
3218 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3219 quota_error u $TSTUSR "(3) Write failure, expect success." \
3225 local OST0_UUID=$(ostuuid_from_index 0)
3226 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3227 [ $OST0_QUOTA_USED -ne 0 ] &&
3228 ($SHOW_QUOTA_USER; \
3229 quota_error u $TSTUSR "quota isn't released")
3234 [ "$ost1_FSTYPE" == zfs ] &&
3235 skip "Overwrite in place is not guaranteed to be " \
3236 "space neutral on ZFS"
3238 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3239 check_whether_skip && return 0
3240 log "run for 4MB test file"
3243 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3244 check_whether_skip && return 0
3245 log "run for 40MB test file"
3248 run_test 23 "Quota should be honored with directIO (b16125)"
3252 local TESTFILE="$DIR/$tdir/$tfile"
3254 setup_quota_test || error "setup quota failed with $?"
3256 set_ost_qtype $QTYPE || error "enable ost quota failed"
3258 # bind file to a single OST
3259 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3260 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3262 echo "Set user quota (limit: ${blimit}M)"
3263 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3264 error "set quota failed"
3266 # overrun quota by root user
3267 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3268 error "write failure, expect success"
3269 cancel_lru_locks osc
3270 sync_all_data || true
3272 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3274 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3278 (( $MDS1_VERSION >= $(version_code 2.15.55.145) )) ||
3279 skip "need MDS >= v2_15_55-145-g513b1cdbc for index version fix"
3281 local limit=10 # 10M
3282 local testfile="$DIR/$tdir/$tfile-0"
3283 local qpool="qpool1"
3286 setup_quota_test || error "setup quota failed with $?"
3289 set_ost_qtype $QTYPE || error "enable ost quota failed"
3291 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
3292 error "set user quota failed"
3294 pool_add $qpool || error "pool_add failed"
3295 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
3296 error "pool_add_targets failed"
3298 # increase ost index version to +200
3299 for i in {1..200}; do
3300 $LFS setquota -u $TSTUSR -B ${i}G --pool $qpool $DIR ||
3301 error "set user quota failed"
3303 $LFS setquota -u $TSTUSR -b 0 -B 0 --pool $qpool $DIR ||
3304 error "set user quota failed"
3306 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
3307 error "set user quota failed"
3309 local used=$(getquota -u $TSTUSR global curspace)
3310 (( used == 0)) || error "Used space($used) for user $TSTUSR isn't 0."
3312 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
3313 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
3315 test_1_check_write $testfile "user" $limit
3318 run_test 25 "check indexes versions"
3320 test_27a() { # b19612
3321 $LFS quota $TSTUSR $DIR &&
3322 error "lfs succeeded with no type, but should have failed"
3323 $LFS setquota $TSTUSR $DIR &&
3324 error "lfs succeeded with no type, but should have failed"
3327 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3329 test_27b() { # b20200
3330 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3331 error "lfs setquota failed with uid argument"
3332 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3333 error "lfs stequota failed with gid argument"
3334 if is_project_quota_supported; then
3335 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3336 1000 $DIR || error \
3337 "lfs stequota failed with projid argument"
3339 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3340 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3341 if is_project_quota_supported; then
3342 $SHOW_QUOTA_PROJID ||
3343 error "lfs quota failed with projid argument"
3344 resetquota_one -p $TSTPRJID
3346 resetquota -u $TSTID
3347 resetquota -g $TSTID
3350 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3355 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3356 error "lfs setquota failed"
3358 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3359 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3360 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3361 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3363 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3364 error "lfs setquota for $TSTID failed"
3366 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3367 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3368 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3369 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3371 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3372 error "total allocated inode/block limit not printed"
3374 resetquota -u $TSTUSR
3376 run_test 27c "lfs quota should support human-readable output"
3383 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3384 error "set fraction block limit failed"
3385 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3386 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3387 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3388 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3390 resetquota -u $TSTUSR
3392 run_test 27d "lfs setquota should support fraction block limit"
3396 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
3397 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
3400 local TESTFILE="$DIR/$tdir/$tfile"
3403 setup_quota_test || error "setup quota failed with $?"
3405 set_ost_qtype "u" || error "enable ost quota failed"
3407 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3408 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3410 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3411 $MAX_IQ_TIME $DIR || error "set grace time failed"
3412 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3413 error "set quota failed"
3414 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3415 cancel_lru_locks osc
3417 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3418 # over-quota flag has not yet settled since we do not trigger async
3419 # events based on grace time period expiration
3421 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3422 cancel_lru_locks osc
3423 # now over-quota flag should be settled and further writes should fail
3425 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3426 error "grace times were reset"
3427 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3428 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3430 run_test 30 "Hard limit updates should not reset grace times"
3432 # basic usage tracking for user & group
3434 local INODES=10 # files
3435 local BLK_CNT=2 # MB each
3436 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3438 setup_quota_test || error "setup quota failed with $?"
3440 # make sure the system is clean
3441 local USED=$(getquota -u $TSTID global curspace)
3443 error "Used space ($USED) for user $TSTID isn't 0."
3444 USED=$(getquota -g $TSTID global curspace)
3446 error "Used space ($USED) for group $TSTID isn't 0."
3447 if is_project_quota_supported; then
3448 USED=$(getquota -p $TSTPRJID global curspace)
3449 [ $USED -ne 0 ] && error \
3450 "Used space ($USED) for project $TSTPRJID isn't 0."
3453 echo "Write files..."
3454 for i in $(seq 0 $INODES); do
3455 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3456 error "write failed"
3457 is_project_quota_supported &&
3458 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3459 echo "Iteration $i/$INODES completed"
3461 cancel_lru_locks osc
3463 echo "Wait for setattr on objects finished..."
3464 wait_delete_completed
3466 sync; sync_all_data || true
3468 echo "Verify disk usage after write"
3469 USED=$(getquota -u $TSTID global curspace)
3470 [ $USED -lt $TOTAL_BLKS ] &&
3471 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3472 USED=$(getquota -g $TSTID global curspace)
3473 [ $USED -lt $TOTAL_BLKS ] &&
3474 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3475 if is_project_quota_supported; then
3476 USED=$(getquota -p $TSTPRJID global curspace)
3477 [ $USED -lt $TOTAL_BLKS ] && error \
3478 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3481 echo "Verify inode usage after write"
3482 USED=$(getquota -u $TSTID global curinodes)
3483 [ $USED -lt $INODES ] &&
3484 error "Used inode for user $TSTID is $USED, expected $INODES"
3485 USED=$(getquota -g $TSTID global curinodes)
3486 [ $USED -lt $INODES ] &&
3487 error "Used inode for group $TSTID is $USED, expected $INODES"
3488 if is_project_quota_supported; then
3489 USED=$(getquota -p $TSTPRJID global curinodes)
3490 [ $USED -lt $INODES ] && error \
3491 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3496 echo "Verify disk usage after delete"
3497 USED=$(getquota -u $TSTID global curspace)
3498 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3499 USED=$(getquota -u $TSTID global curinodes)
3500 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3501 USED=$(getquota -g $TSTID global curspace)
3502 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3503 USED=$(getquota -g $TSTID global curinodes)
3504 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3505 if is_project_quota_supported; then
3506 USED=$(getquota -p $TSTPRJID global curspace)
3508 error "Used space for project $TSTPRJID isn't 0. $USED"
3509 USED=$(getquota -p $TSTPRJID global curinodes)
3511 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3514 run_test 33 "Basic usage tracking for user & group & project"
3516 # usage transfer test for user & group & project
3518 local BLK_CNT=2 # MB
3519 local project_supported="no"
3521 is_project_quota_supported && project_supported="yes"
3522 setup_quota_test || error "setup quota failed with $?"
3524 # make sure the system is clean
3525 local USED=$(getquota -u $TSTID global curspace)
3526 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3527 USED=$(getquota -g $TSTID global curspace)
3528 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3530 local USED=$(getquota -u $TSTID2 global curspace)
3531 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3532 if [ $project_supported == "yes" ]; then
3533 USED=$(getquota -p $TSTPRJID global curspace)
3534 [ $USED -ne 0 ] && error \
3535 "Used space ($USED) for Project $TSTPRJID isn't 0."
3538 echo "Write file..."
3539 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3540 error "write failed"
3541 cancel_lru_locks osc
3542 sync; sync_all_data || true
3544 echo "chown the file to user $TSTID"
3545 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3547 echo "Wait for setattr on objects finished..."
3548 wait_delete_completed
3550 BLK_CNT=$((BLK_CNT * 1024))
3552 echo "Verify disk usage for user $TSTID"
3553 USED=$(getquota -u $TSTID global curspace)
3554 [ $USED -lt $BLK_CNT ] &&
3555 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3556 USED=$(getquota -u $TSTID global curinodes)
3558 error "Used inodes for user $TSTID is $USED, expected 1"
3560 echo "chgrp the file to group $TSTID"
3561 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3563 echo "Wait for setattr on objects finished..."
3564 wait_delete_completed
3566 echo "Verify disk usage for group $TSTID"
3567 USED=$(getquota -g $TSTID global curspace)
3568 [ $USED -ge $BLK_CNT ] ||
3569 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3570 USED=$(getquota -g $TSTID global curinodes)
3572 error "Used inodes for group $TSTID is $USED, expected 1"
3574 # chown won't change the ost object group. LU-4345 */
3575 echo "chown the file to user $TSTID2"
3576 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3578 echo "Wait for setattr on objects finished..."
3579 wait_delete_completed
3581 echo "change_project project id to $TSTPRJID"
3582 [ $project_supported == "yes" ] &&
3583 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3584 echo "Wait for setattr on objects finished..."
3585 wait_delete_completed
3587 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3588 USED=$(getquota -u $TSTID2 global curspace)
3589 [ $USED -lt $BLK_CNT ] &&
3590 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3591 USED=$(getquota -u $TSTID global curspace)
3593 error "Used space for user $TSTID is $USED, expected 0"
3594 USED=$(getquota -g $TSTID global curspace)
3595 [ $USED -lt $BLK_CNT ] &&
3596 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3597 if [ $project_supported == "yes" ]; then
3598 USED=$(getquota -p $TSTPRJID global curspace)
3599 [ $USED -lt $BLK_CNT ] && error \
3600 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3604 run_test 34 "Usage transfer for user & group & project"
3606 # usage is still accessible across restart
3608 local BLK_CNT=2 # MB
3610 setup_quota_test || error "setup quota failed with $?"
3612 echo "Write file..."
3613 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3614 error "write failed"
3615 is_project_quota_supported &&
3616 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3619 echo "Wait for setattr on objects finished..."
3620 wait_delete_completed
3622 sync; sync_all_data || true
3624 echo "Save disk usage before restart"
3625 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3626 [ $ORIG_USR_SPACE -eq 0 ] &&
3627 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3628 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3629 [ $ORIG_USR_INODES -eq 0 ] &&
3630 error "Used inodes for user $TSTID is 0, expected 1"
3631 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3632 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3633 [ $ORIG_GRP_SPACE -eq 0 ] &&
3634 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3635 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3636 [ $ORIG_GRP_INODES -eq 0 ] &&
3637 error "Used inodes for group $TSTID is 0, expected 1"
3638 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3640 if is_project_quota_supported; then
3641 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3642 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3643 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3644 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3645 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3646 "Used inodes for project $TSTPRJID is 0, expected 1"
3647 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3653 wait_recovery_complete
3656 echo "Verify disk usage after restart"
3657 local USED=$(getquota -u $TSTID global curspace)
3658 (( $USED == $ORIG_USR_SPACE )) || {
3659 ls -al $DIR/$tdir/$tfile
3660 $LFS quota -v -u $TSTID $DIR
3661 error "Used space for user $TSTID changed from " \
3662 "$ORIG_USR_SPACE to $USED"
3664 USED=$(getquota -u $TSTID global curinodes)
3665 [ $USED -eq $ORIG_USR_INODES ] ||
3666 error "Used inodes for user $TSTID changed from " \
3667 "$ORIG_USR_INODES to $USED"
3668 USED=$(getquota -g $TSTID global curspace)
3669 [ $USED -eq $ORIG_GRP_SPACE ] ||
3670 error "Used space for group $TSTID changed from " \
3671 "$ORIG_GRP_SPACE to $USED"
3672 USED=$(getquota -g $TSTID global curinodes)
3673 [ $USED -eq $ORIG_GRP_INODES ] ||
3674 error "Used inodes for group $TSTID changed from " \
3675 "$ORIG_GRP_INODES to $USED"
3676 if [[ $project_supported == "yes" ]]; then
3677 USED=$(getquota -p $TSTPRJID global curinodes)
3678 (( $USED == $ORIG_PRJ_INODES )) ||
3679 error "Used inodes for project $TSTPRJID " \
3680 "changed from $ORIG_PRJ_INODES to $USED"
3681 USED=$(getquota -p $TSTPRJID global curspace)
3682 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3683 error "Used space for project $TSTPRJID "\
3684 "changed from $ORIG_PRJ_SPACE to $USED"
3687 # check if the vfs_dq_init() is called before writing
3688 echo "Append to the same file..."
3689 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3690 error "write failed"
3691 cancel_lru_locks osc
3692 sync; sync_all_data || true
3694 echo "Verify space usage is increased"
3695 USED=$(getquota -u $TSTID global curspace)
3696 [ $USED -gt $ORIG_USR_SPACE ] ||
3697 error "Used space for user $TSTID isn't increased" \
3698 "orig:$ORIG_USR_SPACE, now:$USED"
3699 USED=$(getquota -g $TSTID global curspace)
3700 [ $USED -gt $ORIG_GRP_SPACE ] ||
3701 error "Used space for group $TSTID isn't increased" \
3702 "orig:$ORIG_GRP_SPACE, now:$USED"
3703 if [[ $project_supported == "yes" ]]; then
3704 USED=$(getquota -p $TSTPRJID global curspace)
3705 (( $USED > $ORIG_PRJ_SPACE )) ||
3706 error "Used space for project $TSTPRJID isn't " \
3707 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3710 run_test 35 "Usage is still accessible across reboot"
3712 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3715 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3716 skip "Old server doesn't have LU-5006 fix."
3718 setup_quota_test || error "setup quota failed with $?"
3720 # make sure the system is clean
3721 local USED=$(getquota -u $TSTID global curspace)
3723 error "Used space ($USED) for user $TSTID isn't 0."
3725 # create file with MDS_OPEN_DELAY_CREATE flag
3726 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3727 error "Create file failed"
3729 $DD of=$DIR/$tdir/$tfile count=1 conv=notrunc \
3730 oflag=sync || error "Write file failed"
3732 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3734 # wait for setattr on objects finished..."
3735 wait_delete_completed
3737 USED=$(getquota -u $TSTID global curspace)
3738 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3740 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3744 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3745 skip "Old server doesn't have LU-8801 fix."
3747 [ "$UID" != 0 ] && skip_env "must run as root" && return
3749 setup_quota_test || error "setup quota failed with $?"
3751 # make sure the system is clean
3752 local USED=$(getquota -u $TSTID global curspace)
3754 error "Used space ($USED) for user $TSTID isn't 0."
3755 USED=$(getquota -u $TSTID2 global curspace)
3757 error "Used space ($USED) for user $TSTID2 isn't 0."
3759 local TESTFILE="$DIR/$tdir/$tfile"
3760 local file_cnt=10000
3762 # Generate id entries in accounting file
3763 echo "Create $file_cnt files..."
3764 for i in `seq $file_cnt`; do
3766 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3767 error "failed to chown $TESTFILE-$i"
3769 cancel_lru_locks osc
3770 sync; sync_all_data || true
3772 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3773 procf=${procf}.quota_slave.acct_user
3776 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3777 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3778 echo "Found $acct_cnt id entries"
3780 [ $file_cnt -eq $acct_cnt ] || {
3781 do_facet mds1 $LCTL get_param $procf
3782 error "skipped id entries"
3785 run_test 38 "Quota accounting iterator doesn't skip id entries"
3788 local TESTFILE="$DIR/$tdir/project"
3789 ! is_project_quota_supported &&
3790 skip "Project quota is not supported"
3792 setup_quota_test || error "setup quota failed with $?"
3795 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3796 [ $projectid -ne 0 ] &&
3797 error "Project id should be 0 not $projectid"
3798 change_project -p 1024 $TESTFILE
3799 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3800 [ $projectid -ne 1024 ] &&
3801 error "Project id should be 1024 not $projectid"
3803 stopall || error "failed to stopall (1)"
3806 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3807 [ $projectid -eq 1024 ] ||
3808 error "Project id should be 1024 not $projectid"
3810 run_test 39 "Project ID interface works correctly"
3813 ! is_project_quota_supported &&
3814 skip "Project quota is not supported"
3815 local dir1="$DIR/$tdir/dir1"
3816 local dir2="$DIR/$tdir/dir2"
3818 setup_quota_test || error "setup quota failed with $?"
3820 mkdir -p $dir1 $dir2
3821 change_project -sp 1 $dir1 && touch $dir1/1
3822 change_project -sp 2 $dir2
3824 ln $dir1/1 $dir2/1_link &&
3825 error "Hard link across different project quota should fail"
3828 run_test 40a "Hard link across different project ID"
3831 ! is_project_quota_supported &&
3832 skip "Project quota is not supported"
3833 local dir1="$DIR/$tdir/dir1"
3834 local dir2="$DIR/$tdir/dir2"
3836 setup_quota_test || error "setup quota failed with $?"
3837 mkdir -p $dir1 $dir2
3838 change_project -sp 1 $dir1 && touch $dir1/1
3839 change_project -sp 2 $dir2
3841 mv $dir1/1 $dir2/2 || error "mv failed $?"
3842 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3843 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3845 run_test 40b "Mv across different project ID"
3848 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3849 ! is_project_quota_supported &&
3850 skip "Project quota is not supported"
3852 setup_quota_test || error "setup quota failed with $?"
3853 local dir="$DIR/$tdir/dir"
3855 mkdir -p $dir && change_project -sp 1 $dir
3856 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3857 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3858 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3859 touch $dir/remote_dir/file
3860 #verify inherit works file for remote dir.
3861 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3862 [ "$projid" != "1" ] &&
3863 error "file under remote dir expected 1 not $projid"
3865 #Agent inode should be ignored for project quota
3866 local used=$(getquota -p 1 global curinodes)
3868 error "file count expected 3 got $used"
3870 run_test 40c "Remote child Dir inherit project quota properly"
3873 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3874 is_project_quota_supported || skip "Project quota is not supported"
3876 setup_quota_test || error "setup quota failed with $?"
3877 local dir="$DIR/$tdir/dir"
3880 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3881 change_project -sp $TSTPRJID $dir ||
3882 error "change project on $dir failed"
3883 for i in $(seq 5); do
3884 mkdir -p $dir/d$i/d$i ||
3885 error "mkdir $dir/d$i/d$i failed"
3886 local projid=$($LFS project -d $dir/d$i/d$i |
3888 [ "$projid" == "$TSTPRJID" ] ||
3889 error "projid id expected $TSTPRJID not $projid"
3890 touch $dir/d$i/d$i/file
3891 #verify inherit works file for stripe dir.
3892 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3893 [ "$projid" == "$TSTPRJID" ] ||
3894 error "file under remote dir expected 1 not $projid"
3897 # account should be 1 + (2 + 1) *10 + 1 * 5
3898 local used=$(getquota -p $TSTPRJID global curinodes)
3900 error "file count expected 36 got $used"
3902 run_test 40d "Stripe Directory inherit project quota properly"
3905 is_project_quota_supported ||
3906 skip "Project quota is not supported"
3907 setup_quota_test || error "setup quota failed with $?"
3908 local dir="$DIR/$tdir/dir"
3911 local projid=$((testnum * 1000))
3915 # enable mdt/ost quota
3916 set_mdt_qtype ugp || error "enable mdt quota failed"
3917 set_ost_qtype ugp || error "enable ost quota failed"
3919 local statfs_prj_orig=$($LCTL get_param -n llite.*.statfs_project)
3920 (( statfs_prj_orig == 1 )) ||
3921 $LCTL set_param llite.*.statfs_project=1
3922 stack_trap "$LCTL set_param llite.*.statfs_project=$statfs_prj_orig"
3924 test_mkdir -p $dir && change_project -sp $projid $dir
3925 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3926 error "set project quota failed"
3931 # check if df output works as expected
3932 echo "== global statfs: $MOUNT =="
3933 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3935 echo "== project statfs (prjid=$projid): $dir =="
3936 df -kP $dir; df -iP $dir
3937 local bused=$(getquota -p $projid global curspace)
3938 local iused=$(getquota -p $projid global curinodes)
3939 local expected="$ilimit$iused"
3941 wait_update $HOSTNAME \
3942 "df -iP $dir | awk \\\"/$FSNAME/\\\"'{print \\\$2 \\\$3}'" \
3944 error "failed to get correct statfs for project quota"
3946 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $2}')
3947 (( expected == blimit )) ||
3948 error "blimit mismatch: $expected != $blimit"
3950 # zfs block size is 4K, while quota is printed in 1K, df result may be
3951 # larger than quota result, but it's no more than 3K
3952 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $3}')
3953 (( expected - bused < 4)) || error "bused mismatch: $expected != $bused"
3955 # disable statfs_project and check again
3956 $LCTL set_param llite.*.statfs_project=0
3958 expected=$({ df -kP $MOUNT; df -iP $MOUNT; } | \
3959 awk '/'$FSNAME'/ { printf "%d %d ", $2,$3 }')
3961 wait_update $HOSTNAME \
3962 "{ df -kP $dir; df -iP $dir; } |
3963 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3965 error "failed to get correct statfs when statfs_project=0"
3967 run_test 41 "df should return projid-specific values"
3978 eval $($LFS quota $qtype 2147483647 $MOUNT |
3979 awk 'NR = 2 {printf("bsl=%d;bhl=%d;isl=%d;ihl=%d;", \
3982 (( $bsl != 0 || $bhl != 0 || $isl != 0 || $ihl != 0 )) &&
3983 skip "qid 2147483647 is already used"
3985 $LFS setquota $qdtype -b 100M -B 200M $MOUNT ||
3986 error "fail to set default quota"
3988 eval $($LFS quota $qtype 2147483647 $MOUNT |
3989 awk 'NR = 2 {printf("bsl=%d;bhl=%d;isl=%d;ihl=%d;", \
3992 [ $bsl -ne 102400 -o $bhl -ne 204800 ] &&
3993 error "fail to include default block quota"
3995 $LFS setquota $qdtype -i 10K -I 20K $MOUNT ||
3996 error "fail to set default quota"
3998 eval $($LFS quota $qtype 2147483647 $MOUNT |
3999 awk 'NR = 2 {printf("bsl=%d;bhl=%d;isl=%d;ihl=%d;", \
4002 [ $isl -ne 10240 -o $ihl -ne 20480 ] &&
4003 error "fail to include default file quota"
4008 setup_quota_test || error "setup quota failed with $?"
4011 test_lfs_quota "-U" "-u"
4012 test_lfs_quota "-G" "-g"
4013 is_project_quota_supported && test_lfs_quota "-P" "-p"
4017 run_test 42 "lfs quota should include default quota info"
4025 local osd="osd-ldiskfs"
4027 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
4029 rm -f $DIR/$tdir/$tfile
4030 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
4031 chmod a+rw $DIR/$tdir/$tfile
4033 $LFS setquota $qtype $qid -B 300M $MOUNT
4034 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
4036 do_facet $SINGLEMDS \
4037 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
4038 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
4041 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
4042 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
4044 $LFS setquota $qtype $qid --delete $MOUNT
4045 do_facet $SINGLEMDS \
4046 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
4047 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
4050 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
4051 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
4053 $LFS setquota $qtype $qid -B 500M $MOUNT
4054 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
4055 do_facet $SINGLEMDS \
4056 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
4057 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
4058 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
4060 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
4061 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
4066 setup_quota_test || error "setup quota failed with $?"
4067 set_ost_qtype $QTYPE || error "enable ost quota failed"
4070 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
4071 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
4072 is_project_quota_supported &&
4073 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
4077 run_test 48 "lfs quota --delete should delete quota project ID"
4079 test_get_allquota() {
4087 local TFILE="$DIR/$tdir/$tfile-0"
4104 local qid_cnt=$file_cnt
4106 [ $end_qid -ne 0 ] && qid_cnt=$((end_qid - start_qid + 1))
4107 [ $end_qid -ge $file_cnt ] &&
4108 qid_cnt=$((qid_cnt - end_qid + file_cnt))
4109 [ $qid_cnt -le 0 ] && error "quota ID count is wrong"
4111 cnt=$($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | wc -l)
4112 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all usr quota"
4113 cnt=$($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | wc -l)
4114 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all grp quota"
4116 cancel_lru_locks osc
4117 sync; sync_all_data || true
4120 eval $($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT |
4121 awk 'NR > 2 {printf("u_blimits[%d]=%d;u_ilimits[%d]=%d; \
4122 u_busage[%d]=%d;u_iusage[%d]=%d;", \
4123 NR, $4, NR, $8, NR, $2, NR, $6)}')
4124 eval $($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT |
4125 awk 'NR > 2 {printf("g_blimits[%d]=%d;g_ilimits[%d]=%d; \
4126 g_busage[%d]=%d;g_iusage[%d]=%d;", \
4127 NR, $4, NR, $8, NR, $2, NR, $6)}')
4129 for i in $(seq $qid_cnt); do
4130 [ $i -le 2 ] && continue
4132 [ ${u_ilimits[$i]} -eq $u_ilimit ] ||
4133 error "file limit for user ID $((start_qid + i - 3)) is wrong"
4134 [ ${u_blimits[$i]} -eq $u_blimit ] ||
4135 error "block limit for user ID $((start_qid + i - 3)) is wrong"
4136 [ ${g_ilimits[$i]} -eq $g_ilimit ] ||
4137 error "file limit for group ID $((start_qid + i - 3)) is wrong"
4138 [ ${g_blimits[$i]} -eq $g_blimit ] ||
4139 error "block limit for group ID $((start_qid + i - 3)) is wrong"
4142 echo "Create $qid_cnt files..."
4143 createmany -S 4k -U $start_qid -G $start_qid -o ${TFILE} $qid_cnt ||
4144 error "failed to create many files"
4146 cancel_lru_locks osc
4147 sync; sync_all_data || true
4151 $LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | tail -n 50
4152 total=$((SECONDS - start))
4153 (( end - start > 0 )) &&
4154 echo "time=$total, rate=$((qid_cnt / total))/s" ||
4155 echo "time=0, rate=$qid_cnt/0"
4158 $LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | tail -n 50
4159 total=$((SECONDS - start))
4160 (( end - start > 0 )) &&
4161 echo "time=$total, rate=$((qid_cnt / total))/s" ||
4162 echo "time=0, rate=$qid_cnt/0"
4164 cnt=$($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | wc -l)
4165 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all usr quota"
4166 cnt=$($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | wc -l)
4167 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all grp quota"
4169 eval $($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT |
4170 awk 'NR > 2 {printf("u_blimits[%d]=%d;u_ilimits[%d]=%d; \
4171 u_busage2[%d]=%d;u_iusage2[%d]=%d;", \
4172 NR, $4, NR, $8, NR, $2, NR, $6)}')
4173 eval $($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT |
4174 awk 'NR > 2 {printf("g_blimits[%d]=%d;g_ilimits[%d]=%d; \
4175 g_busage2[%d]=%d;g_iusage2[%d]=%d;", \
4176 NR, $4, NR, $8, NR, $2, NR, $6)}')
4179 for i in $(seq $qid_cnt); do
4180 [ $i -le 2 ] && continue
4182 [ ${u_ilimits[$i]} -eq $u_ilimit ] ||
4183 error "file limit for user ID $((start_qid + i - 3)) is wrong"
4184 [ ${u_blimits[$i]} -eq $u_blimit ] ||
4185 error "block limit for user ID $((start_qid + i - 3)) is wrong"
4186 [ ${g_ilimits[$i]} -eq $g_ilimit ] ||
4187 error "file limit for group ID $((start_qid + i - 3)) is wrong"
4188 [ ${g_blimits[$i]} -eq $g_blimit ] ||
4189 error "block limit for group ID $((start_qid + i - 3)) is wrong"
4190 [ ${u_iusage2[$i]} -eq $((u_iusage[$i] + 1)) ] ||
4191 error "file usage for user ID $((start_qid + i - 3)) is wrong ${u_iusage[$i]}, ${u_iusage2[$i]}"
4192 [ ${u_busage2[$i]} -ge $((u_busage[$i] + 4)) ] ||
4193 error "block usage for user ID $((start_qid + i - 3)) is wrong ${u_busage[$i]}, ${u_busage2[$i]}"
4194 [ ${g_iusage2[$i]} -eq $((g_iusage[$i] + 1)) ] ||
4195 error "file usage for group ID $((start_qid + i - 3)) is wrong ${g_iusage[$i]}, ${g_iusage2[$i]}"
4196 [ ${g_busage2[$i]} -ge $((g_busage[$i] + 4)) ] ||
4197 error "block usage for group ID $((start_qid + i - 3)) is wrong ${g_busage[$i]}, ${g_busage2[$i]}"
4200 unlinkmany ${TFILE} $qid_cnt
4205 (( MDS1_VERSION >= $(version_code 2.15.60) )) ||
4206 skip "Need MDS version at least 2.15.60"
4208 local u_blimit=102400
4209 local u_ilimit=10240
4210 local g_blimit=204800
4211 local g_ilimit=20480
4214 setup_quota_test || error "setup quota failed with $?"
4215 stack_trap cleanup_quota_test EXIT
4217 [ "$SLOW" = "yes" ] && total_file_cnt=20000 || total_file_cnt=1000
4218 total_file_cnt=${NUM_QIDS:-$total_file_cnt}
4220 local start=$SECONDS
4222 echo "setquota for users and groups"
4223 #define OBD_FAIL_QUOTA_NOSYNC 0xA09
4224 do_facet mds1 $LCTL set_param fail_loc=0xa09
4225 for i in $(seq $total_file_cnt); do
4226 $LFS setquota -u $i -B ${u_blimit} -I ${u_ilimit} $MOUNT ||
4227 error "failed to setquota for usr $i"
4228 $LFS setquota -g $i -B ${g_blimit} -I ${g_ilimit} $MOUNT ||
4229 error "failed to setquota for grp $i"
4230 (( i % 1000 == 0)) &&
4231 echo "lfs setquota: $i / $((SECONDS - start)) seconds"
4233 do_facet mds1 $LCTL set_param fail_loc=0
4236 $LFS quota -a -u $MOUNT | tail -n 100
4237 echo "get all usr quota: $total_file_cnt / $((SECONDS - start)) seconds"
4240 $LFS quota -a -g $MOUNT | tail -n 100
4241 echo "get all grp quota: $total_file_cnt / $((SECONDS - start)) seconds"
4244 test_get_allquota $total_file_cnt $count $((count + 5000)) \
4245 $u_blimit $u_ilimit $g_blimit $g_ilimit
4246 test_get_allquota $total_file_cnt $count $((count + 5000)) \
4247 $u_blimit $u_ilimit $g_blimit $g_ilimit
4249 count=$((count + 5000))
4250 [ $count -gt $total_file_cnt ] && break
4253 do_facet mds1 $LCTL set_param fail_loc=0xa08
4254 for i in $(seq $total_file_cnt); do
4255 $LFS setquota -u $i --delete $MOUNT
4256 $LFS setquota -g $i --delete $MOUNT
4258 do_facet mds1 $LCTL set_param fail_loc=0
4263 run_test 49 "lfs quota -a prints the quota usage for all quota IDs"
4266 ! is_project_quota_supported &&
4267 skip "Project quota is not supported"
4269 setup_quota_test || error "setup quota failed with $?"
4270 local dir1="$DIR/$tdir/dir1"
4271 local dir2="$DIR/$tdir/dir2"
4273 mkdir -p $dir1 && change_project -sp 1 $dir1
4274 mkdir -p $dir2 && change_project -sp 2 $dir2
4275 for num in $(seq 1 10); do
4276 touch $dir1/file_$num $dir2/file_$num
4277 ln -s $dir1/file_$num $dir1/file_$num"_link"
4278 ln -s $dir2/file_$num $dir2/file_$num"_link"
4281 count=$($LFS find --projid 1 $DIR | wc -l)
4282 [ "$count" != 21 ] && error "expected 21 but got $count"
4284 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
4285 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
4286 [ $count -eq 22 ] || error "expected 22 but got $count"
4288 run_test 50 "Test if lfs find --projid works"
4291 ! is_project_quota_supported &&
4292 skip "Project quota is not supported"
4293 setup_quota_test || error "setup quota failed with $?"
4294 local dir="$DIR/$tdir/dir"
4296 mkdir $dir && change_project -sp 1 $dir
4297 local used=$(getquota -p 1 global curinodes)
4298 [ $used != "1" ] && error "expected 1 got $used"
4303 used=$(getquota -p 1 global curinodes)
4304 [ $used != "4" ] && error "expected 4 got $used"
4306 $DD of=$DIR/$tdir/6 count=1
4308 cp $DIR/$tdir/6 $dir/6
4309 used=$(getquota -p 1 global curinodes)
4310 [ $used != "5" ] && error "expected 5 got $used"
4313 mv $DIR/$tdir/6 $dir/7
4314 used=$(getquota -p 1 global curinodes)
4315 [ $used -eq 6 ] || error "expected 6 got $used"
4317 run_test 51 "Test project accounting with mv/cp"
4320 ! is_project_quota_supported &&
4321 skip "Project quota is not supported"
4323 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
4324 skip "Need MDS version at least 2.14.55"
4326 setup_quota_test || error "setup quota failed with $?"
4328 local dir1=$DIR/$tdir/t52_dir1
4329 local dir2=$DIR/$tdir/t52_dir2
4331 mkdir $dir1 || error "failed to mkdir $dir1"
4332 mkdir $dir2 || error "failed to mkdir $dir2"
4334 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
4335 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
4337 $DD of=$dir1/$tfile count=100 ||
4338 error "failed to create and write $dir1/$tfile"
4340 cancel_lru_locks osc
4341 sync; sync_all_data || true
4343 local attrs=($(lsattr -p $dir1/$tfile))
4344 (( ${attrs[0]} == 1000 )) ||
4345 error "project ID on $dir1/$tfile is not inherited"
4347 $LFS quota -p 1000 $DIR
4348 $LFS quota -p 1001 $DIR
4350 local prev_used=$(getquota -p 1000 global curspace)
4351 local prev_used2=$(getquota -p 1001 global curspace)
4353 mrename $dir1 $dir2/tdir || log "rename directory return $?"
4355 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
4356 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
4357 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
4359 attrs=($(lsattr -p $dir2/$tfile))
4360 (( ${attrs[0]} == 1001 )) ||
4361 error "project ID is not updated after rename"
4363 (( $inum_before == $inum_after )) ||
4364 error "inode is changed after rename: $inum_before, $inum_after"
4366 sync_all_data || true
4368 $LFS quota -p 1000 $DIR
4369 $LFS quota -p 1001 $DIR
4371 local new_used=$(getquota -p 1000 global curspace)
4372 local new_used2=$(getquota -p 1001 global curspace)
4374 (( $prev_used >= $new_used + 102400 )) ||
4375 error "quota is not deducted from old project ID"
4376 (( $prev_used2 <= $new_used2 - 102400 )) ||
4377 error "quota is not added for the new project ID"
4379 run_test 52 "Rename normal file across project ID"
4382 ! is_project_quota_supported &&
4383 skip "Project quota is not supported"
4384 setup_quota_test || error "setup quota failed with $?"
4385 local dir="$DIR/$tdir/dir"
4386 mkdir $dir && change_project -s $dir
4387 [[ $($LFS project -d $dir) =~ " P " ]] ||
4388 error "inherit attribute should be set"
4390 change_project -C $dir
4391 [[ $($LFS project -d $dir) =~ " - " ]] ||
4392 error "inherit attribute should be cleared"
4394 run_test 53 "Project inherit attribute could be cleared"
4397 ! is_project_quota_supported &&
4398 skip "Project quota is not supported"
4399 setup_quota_test || error "setup quota failed with $?"
4400 local testfile="$DIR/$tdir/$tfile-0"
4402 #set project ID/inherit attribute
4403 change_project -sp $TSTPRJID $DIR/$tdir
4404 $RUNAS createmany -m ${testfile} 100 ||
4405 error "create many files failed"
4407 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
4408 # one more count for directory itself */
4412 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4413 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
4415 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
4416 [ $proj_count1 -eq $proj_count ] ||
4417 error "c2: expected $proj_count got $proj_count1"
4419 #clear project but with kept projid
4420 change_project -rCk $DIR/$tdir
4421 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4422 [ $proj_count1 -eq 1 ] ||
4423 error "c3: expected 1 got $proj_count1"
4425 #verify projid untouched.
4426 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4428 [ $proj_count1 -eq $proj_count ] ||
4429 error "c4: expected $proj_count got $proj_count1"
4432 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
4433 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4434 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
4436 #this time clear all
4437 change_project -rC $DIR/$tdir
4438 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4439 [ $proj_count1 -eq 0 ] ||
4440 error "c6: expected 0 got $proj_count1"
4442 unlinkmany ${testfile} 100 ||
4443 error "unlink many files failed"
4445 run_test 54 "basic lfs project interface test"
4448 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4449 skip "Not supported before 2.10.58."
4450 setup_quota_test || error "setup quota failed with $?"
4452 set_ost_qtype $QTYPE || error "enable ost quota failed"
4455 #add second group to TSTUSR
4456 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4459 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4460 error "failed to dd"
4462 cancel_lru_locks osc
4463 sync; sync_all_data || true
4465 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4466 error "failed to setquota on group $TSTUSR2"
4468 $LFS quota -v -g $TSTUSR2 $DIR
4470 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4471 error "chgrp should failed with -EDQUOT"
4473 USED=$(getquota -g $TSTUSR2 global curspace)
4476 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4477 error "failed to setquota on group $TSTUSR2"
4479 $LFS quota -v -g $TSTUSR2 $DIR
4481 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4482 error "chgrp should succeed"
4484 $LFS quota -v -g $TSTUSR2 $DIR
4486 run_test 55 "Chgrp should be affected by group quota"
4489 setup_quota_test || error "setup quota failed with $?"
4491 set_ost_qtype $QTYPE || error "enable ost quota failed"
4494 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4495 erro "failed to set grace time for usr quota"
4496 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4497 awk '{print $4 $8}')
4498 if [ "x$grace_time" != "x10s;10s" ]; then
4499 $LFS quota -t -u $DIR
4500 error "expected grace time: 10s;10s, got:$grace_time"
4503 run_test 56 "lfs quota -t should work well"
4506 setup_quota_test || error "setup quota failed with $?"
4508 local dir="$DIR/$tdir/dir"
4511 #command can process further if it hit some errors
4512 $LFS project -sp 1 $dir/pipe
4513 touch $dir/aaa $dir/bbb
4514 mkdir $dir/subdir -p
4515 touch $dir/subdir/aaa $dir/subdir/bbb
4516 #create one invalid link file
4517 ln -s $dir/not_exist_file $dir/ccc
4518 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4519 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4521 run_test 57 "lfs project could tolerate errors"
4531 $LFS mirror extend -N2 $mirrorfile || error "failed to create mirror"
4533 local mirrors=$($LFS getstripe -N $testfile)
4534 [[ $mirrors == 3 ]] || error "mirror count $mirrors is wrong"
4536 cancel_lru_locks osc
4537 cancel_lru_locks mdc
4538 sync; sync_all_data || true
4540 local prev_usage=$(getquota -p $projid global curspace)
4542 $RUNAS $DD of=$testfile count=50 conv=nocreat oflag=direct ||
4543 quota_error p $projid "write failed, expect succeed"
4545 cancel_lru_locks osc
4546 cancel_lru_locks mdc
4547 sync; sync_all_data || true
4549 $RUNAS $LFS mirror resync $testfile || error "failed to resync mirror"
4551 local usage=$(getquota -p $projid global curspace)
4552 (( usage >= prev_usage + 150*1024 )) ||
4553 error "project quota $usage is wrong"
4555 $RUNAS $DD of=$testfile count=30 conv=nocreat seek=50 oflag=direct ||
4556 quota_error p $projid "write failed, expect succeed"
4558 $RUNAS $LFS mirror resync $testfile &&
4559 error "resync mirror succeed, expect EDQUOT"
4561 $LFS mirror delete --mirror-id 2 $testfile ||
4562 error "failed to delete the second mirror"
4563 $LFS mirror delete --mirror-id 3 $testfile ||
4564 error "failed to delete the third mirror"
4568 (( $MDS1_VERSION >= $(version_code 2.15.56) )) ||
4569 skip "need MDS 2.15.56 or later"
4571 is_project_quota_supported || skip "Project quota is not supported"
4573 local testdir="$DIR/$tdir"
4574 local testfile="$DIR/$tdir/$tfile"
4578 setup_quota_test || error "setup quota failed with $?"
4580 USED=$(getquota -p $projid global curspace)
4581 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid isn't 0"
4583 USED=$(getquota -p $projid2 global curspace)
4584 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid2 isn't 0"
4586 chown $TSTUSR.$TSTUSR $testdir || error "chown $testdir failed"
4588 set_ost_qtype ugp || error "enable ost quota failed"
4590 $LFS project -sp $projid $testdir || error "failed to set project ID"
4591 $LFS setquota -p $projid -B 200M $DIR ||
4592 error "failed to to set prj $projid quota"
4594 $RUNAS touch $testfile
4596 local id=$(lfs project -d $testfile | awk '{print $1}')
4597 [ "$id" != "$projid" ] && error "projid $projid is not inherited $id"
4599 echo "test by mirror created with normal file"
4600 test_mirror $projid $testfile $testfile
4602 $TRUNCATE $testfile 0
4603 wait_delete_completed || error "wait_delete_completed failed"
4604 sync_all_data || true
4606 $LFS project -sp $projid2 $testdir ||
4607 error "failed to set directory project ID"
4608 $LFS project -p $projid2 $testfile ||
4609 error "failed to set file project ID"
4610 $LFS setquota -p $projid -b 0 -B 0 $DIR ||
4611 error "failed to to reset prj quota"
4612 $LFS setquota -p $projid2 -B 200M $DIR ||
4613 error "failed to to set prj $projid2 quota"
4615 local fid=$($LFS path2fid $testfile)
4617 echo "test by mirror created with FID"
4618 test_mirror $projid2 $testfile $MOUNT/.lustre/fid/$fid
4620 run_test 58 "project ID should be kept for new mirrors created by FID"
4623 [ "$mds1_FSTYPE" != ldiskfs ] &&
4624 skip "ldiskfs only test"
4625 disable_project_quota
4626 setup_quota_test || error "setup quota failed with $?"
4629 local testfile="$DIR/$tdir/$tfile-0"
4630 #make sure it did not crash kernel
4631 touch $testfile && lfs project -sp 1 $testfile
4633 enable_project_quota
4635 run_test 59 "lfs project dosen't crash kernel with project disabled"
4638 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4639 skip "Needs MDS version 2.11.53 or later."
4640 setup_quota_test || error "setup quota failed with $?"
4642 local testfile=$DIR/$tdir/$tfile
4645 set_mdt_qtype "ug" || error "enable mdt quota failed"
4647 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4648 error "set quota failed"
4649 quota_show_check a g $TSTUSR
4651 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4652 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4653 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4654 error "create many files failed"
4656 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4658 # root user can overrun quota
4659 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4660 error "root user should succeed"
4662 run_test 60 "Test quota for root with setgid"
4664 # test default quota
4665 test_default_quota() {
4666 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4667 skip "Not supported before 2.11.51."
4672 local qprjid=$TSTPRJID
4676 local LIMIT=20480 #20M disk space
4677 local TESTFILE="$DIR/$tdir/$tfile-0"
4680 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4681 echo "Project quota is not supported" && return 0
4683 [ $qtype == "-u" ] && qdtype="-U"
4684 [ $qtype == "-g" ] && qdtype="-G"
4685 [ $qtype == "-p" ] && {
4690 [ $qres_type == "meta" ] && {
4691 LIMIT=10240 #10K inodes
4696 qpool_cmd="--pool $3"
4697 # pool quotas don't work properly without global limit
4698 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4699 error "set global limit failed"
4702 setup_quota_test || error "setup quota failed with $?"
4706 # enable mdt/ost quota
4707 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4708 set_ost_qtype $QTYPE || error "enable ost quota failed"
4710 log "set to use default quota"
4711 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4712 error "set $qid to use default quota failed"
4714 log "set default quota"
4715 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4716 error "set $qid default quota failed"
4718 log "get default quota"
4719 $LFS quota $qdtype $DIR || error "get default quota failed"
4721 if [ $qres_type == "data" ]; then
4722 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4723 grep "$MOUNT" | awk '{print $2}')
4724 [ $SLIMIT -eq $LIMIT ] ||
4725 error "the returned default quota is wrong"
4727 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4729 [ $SLIMIT -eq $LIMIT ] ||
4730 error "the returned default quota is wrong"
4733 # make sure the system is clean
4734 local USED=$(getquota $qtype $qid global curspace)
4735 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4737 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4738 error "setstripe $TESTFILE failed"
4739 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4741 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4743 log "Test not out of quota"
4744 if [ $qres_type == "data" ]; then
4745 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4746 quota_error $qtype $qid "write failed, expect succeed"
4748 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4749 quota_error $qtype $qid "create failed, expect succeed"
4751 unlinkmany $TESTFILE $((LIMIT/2))
4754 log "Test out of quota"
4755 # flush cache, ensure noquota flag is set on client
4756 cancel_lru_locks osc
4757 cancel_lru_locks mdc
4758 sync; sync_all_data || true
4759 if [ $qres_type == "data" ]; then
4760 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4761 quota_error $qtype $qid "write succeed, expect EDQUOT"
4763 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4764 quota_error $qtype $qid "create succeed, expect EDQUOT"
4766 unlinkmany $TESTFILE $((LIMIT*2))
4770 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4771 error "setstripe $TESTFILE failed"
4772 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4774 log "Increase default quota"
4776 # LU-4505: sleep 5 seconds to enable quota acquire
4779 # increase default quota
4780 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4781 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4783 cancel_lru_locks osc
4784 cancel_lru_locks mdc
4785 sync; sync_all_data || true
4786 if [ $qres_type == "data" ]; then
4787 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4788 quota_error $qtype $qid "write failed, expect succeed"
4790 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4791 quota_error $qtype $qid "create failed, expect succeed"
4793 unlinkmany $TESTFILE $((LIMIT*2))
4796 log "Set quota to override default quota"
4797 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4798 error "set $qid quota failed"
4800 cancel_lru_locks osc
4801 cancel_lru_locks mdc
4802 sync; sync_all_data || true
4803 if [ $qres_type == "data" ]; then
4804 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4805 quota_error $qtype $qid "write succeed, expect EQUOT"
4807 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4808 quota_error $qtype $qid "create succeed, expect EQUOT"
4810 unlinkmany $TESTFILE $((LIMIT*2))
4813 log "Set to use default quota again"
4815 # LU-4505: sleep 5 seconds to enable quota acquire
4818 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4819 error "set $qid to use default quota failed"
4821 cancel_lru_locks osc
4822 cancel_lru_locks mdc
4823 sync; sync_all_data || true
4824 if [ $qres_type == "data" ]; then
4825 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4826 quota_error $qtype $qid "write failed, expect succeed"
4828 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4829 quota_error $qtype $qid "create failed, expect succeed"
4831 unlinkmany $TESTFILE $((LIMIT*2))
4836 wait_delete_completed || error "wait_delete_completed failed"
4837 sync_all_data || true
4839 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4840 error "reset default quota failed"
4841 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4842 error "reset quota failed"
4847 test_default_quota "-u" "data"
4848 test_default_quota "-u" "meta"
4849 test_default_quota "-g" "data"
4850 test_default_quota "-g" "meta"
4851 test_default_quota "-p" "data"
4852 test_default_quota "-p" "meta"
4854 run_test 61 "default quota tests"
4857 ! is_project_quota_supported &&
4858 skip "Project quota is not supported"
4859 [[ "$(chattr -h 2>&1)" =~ "project" ||
4860 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4861 skip "chattr did not support project quota"
4862 setup_quota_test || error "setup quota failed with $?"
4863 local testdir=$DIR/$tdir/
4865 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4866 change_project -s $testdir
4867 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4868 error "inherit attribute should be set"
4869 # chattr used FS_IOC_SETFLAGS ioctl
4870 $RUNAS chattr -P $testdir &&
4871 error "regular user clear inherit should fail"
4872 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4873 error "inherit attribute should still be set"
4874 chattr -P $testdir || error "root failed to clear inherit"
4875 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4876 error "inherit attribute should be cleared"
4879 run_test 62 "Project inherit should be only changed by root"
4882 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4883 skip "Not supported before 2.11.55"
4887 local dd_failed=false
4888 local tdir_dom=${tdir}_dom
4889 local LIMIT=20480 #20M
4891 [ $qtype == "p" ] && ! is_project_quota_supported &&
4892 echo "Project quota is not supported" && return 0
4894 [ $qtype == "p" ] && qid=$TSTPRJID
4896 setup_quota_test || error "setup quota failed with $?"
4900 # enable mdt/ost quota
4901 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4902 set_ost_qtype $QTYPE || error "enable ost quota failed"
4904 # make sure the system is clean
4905 local USED=$(getquota -$qtype $qid global curspace)
4906 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4908 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4910 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4911 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4912 error "setstripe $tdir_dom failed"
4913 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4915 [ $qtype == "p" ] && {
4916 change_project -sp $TSTPRJID $DIR/$tdir
4917 change_project -sp $TSTPRJID $DIR/$tdir_dom
4920 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4921 error "set $qid quota failed"
4923 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4924 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4928 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4930 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4931 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4935 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4937 rm -f $DIR/$tdir_dom/*
4939 # flush cache, ensure noquota flag is set on client
4940 cancel_lru_locks osc
4941 cancel_lru_locks mdc
4942 sync; sync_all_data || true
4946 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4947 quota_error $qtype $qid "write failed, expect succeed"
4949 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4950 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4954 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4957 rm -f $DIR/$tdir_dom/*
4959 # flush cache, ensure noquota flag is set on client
4960 cancel_lru_locks osc
4961 cancel_lru_locks mdc
4962 sync; sync_all_data || true
4966 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4967 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4971 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4973 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4974 quota_error $qtype $qid "write succeed, expect EDQUOT"
4977 rm -fr $DIR/$tdir_dom
4979 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4980 error "reset usr quota failed"
4988 run_test 63 "quota on DoM tests"
4991 ! is_project_quota_supported &&
4992 skip "Project quota is not supported"
4993 setup_quota_test || error "setup quota failed with $?"
4994 local dir1="$DIR/$tdir/"
4997 ln -s $dir1/file $dir1/file_link
5000 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
5001 error "set project should succeed"
5003 used=$(getquota -p $TSTPRJID global curinodes)
5004 [ $used -eq 4 ] || error "expected 4 got $used"
5005 $LFS project -rC $dir1 >&/dev/null ||
5006 error "clear project should succeed"
5008 used=$(getquota -p $TSTPRJID global curinodes)
5009 [ $used -eq 0 ] || error "expected 0 got $used"
5011 run_test 64 "lfs project on non dir/files should succeed"
5015 local TESTFILE="$DIR/$tdir/$tfile-0"
5017 setup_quota_test || error "setup quota failed with $?"
5018 set_ost_qtype $QTYPE || error "enable ost quota failed"
5022 $RUNAS $DD of=$TESTFILE count=$SIZE ||
5023 error "failed to write"
5024 # flush cache, ensure noquota flag is set on client
5025 cancel_lru_locks osc
5026 sync; sync_all_data || true
5028 local quota_u=$($LFS quota -u $TSTUSR $DIR)
5029 local quota_g=$($LFS quota -g $TSTUSR $DIR)
5030 local quota_all=$($RUNAS $LFS quota $DIR)
5032 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
5033 error "usr quota not match"
5034 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
5035 error "grp quota not match"
5037 run_test 65 "Check lfs quota result"
5040 ! is_project_quota_supported &&
5041 skip "Project quota is not supported"
5042 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
5043 skip "Not supported before 2.12.4"
5044 setup_quota_test || error "setup quota failed with $?"
5045 local old=$(do_facet mds1 $LCTL get_param -n \
5046 mdt.*.enable_chprojid_gid | head -1)
5047 local testdir=$DIR/$tdir/foo
5049 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
5050 stack_trap "do_facet mds1 $LCTL \
5051 set_param mdt.*.enable_chprojid_gid=$old" EXIT
5053 mkdir_on_mdt0 $testdir || error "failed to mkdir"
5054 chown -R $TSTID:$TSTID $testdir
5055 change_project -sp $TSTPRJID $testdir
5056 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
5058 $RUNAS lfs project -p 0 $testdir/foo &&
5059 error "nonroot user should fail to set projid"
5061 $RUNAS lfs project -C $testdir/foo &&
5062 error "nonroot user should fail to clear projid"
5064 change_project -C $testdir/foo || error "failed to clear project"
5066 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
5067 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
5068 "failed to set projid with normal user when enable_chprojid_gid=-1"
5070 $RUNAS lfs project -rC $testdir/ || error \
5071 "failed to clear project state with normal user when enable_chprojid_gid=-1"
5073 touch $testdir/bar || error "failed touch $testdir/bar"
5074 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
5075 "normal user should not be able to set projid on root owned file"
5077 change_project -p $TSTPRJID $testdir/bar || error \
5078 "root should be able to change its own file's projid"
5080 run_test 66 "nonroot user can not change project state in default"
5087 local short_qtype=${qtype:0:1}
5090 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
5092 $TSTUSR) _runas=$RUNAS;;
5093 $TSTUSR2) _runas=$RUNAS2;;
5094 *) error "unknown quota parameter $4";;
5099 $_runas $DD of=$file count=$size ||
5100 quota_error $short_qtype $TSTUSR \
5101 "$qtype write failure, but expect success"
5103 cancel_lru_locks osc
5105 sync; sync_all_data || true
5114 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
5116 do_facet mds1 $LCTL get_param $param |
5117 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
5122 local testfile="$DIR/$tdir/$tfile-0"
5123 local testfile2="$DIR/$tdir/$tfile-1"
5124 local testfile3="$DIR/$tdir/$tfile-2"
5125 local qpool="qpool1"
5131 [ "$ost1_FSTYPE" == zfs ] &&
5132 skip "ZFS grants some block space together with inode"
5134 setup_quota_test || error "setup quota failed with $?"
5137 set_ost_qtype $QTYPE || error "enable ost quota failed"
5140 log "User quota (block hardlimit:$limit MB)"
5141 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5142 error "set user quota failed"
5144 # make sure the system is clean
5145 used=$(getquota -u $TSTUSR global curspace)
5146 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5148 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5149 echo "granted 0x0 before write $granted"
5151 # trigger reintegration
5152 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
5153 procf=${procf}quota_slave.force_reint
5154 do_facet ost1 $LCTL set_param $procf=1 ||
5155 error "force reintegration failed"
5156 wait_ost_reint "u" || error "reintegration failed"
5157 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5158 [ $granted -ne 0 ] &&
5159 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
5161 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
5162 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5164 # write 10 MB to testfile
5165 test_67_write "$testfile" "user" 10 "$TSTUSR"
5167 # create qpool and add OST1
5168 pool_add $qpool || error "pool_add failed"
5169 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5170 # as $TSTUSR hasn't limits, lqe may absent. But it should be
5171 # created after the 1st direct qmt_get.
5172 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5174 # check granted - should be 0, as testfile is located only on OST0
5175 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5176 echo "global granted $granted"
5177 granted=$(getgranted $qpool "dt" $TSTID "usr")
5178 echo "$qpool granted $granted"
5179 [ $granted -ne 0 ] &&
5180 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
5182 # add OST0 to qpool and check granted space
5183 pool_add_targets $qpool 0 1 ||
5184 error "pool_add_targets failed"
5185 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
5186 echo "Granted $granted_mb MB"
5187 #should be 10M + qunit for each OST
5188 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
5189 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
5191 $LFS setstripe $testfile2 -c 1 -i 1 ||
5192 error "setstripe $testfile2 failed"
5193 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
5194 # Write from another user and check that qpool1
5195 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
5196 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
5197 used=$(getquota -u $TSTUSR2 global curspace $qpool)
5198 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
5199 [ $granted -ne 0 ] &&
5200 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
5202 # Granted space for $TSTUSR2 in qpool1 should appear only
5203 # when global lqe for this user becomes enforced.
5204 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
5205 error "set user quota failed"
5206 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5207 echo "granted_mb $granted_mb"
5208 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
5209 error "Granted($granted) for $TSTUSR in $qpool is wrong."
5211 $LFS setstripe $testfile3 -c 1 -i 0 ||
5212 error "setstripe $testfile3 failed"
5213 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
5214 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
5215 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5216 echo "$testfile3 granted_mb $granted_mb"
5217 [ $granted_mb -eq $limit ] ||
5218 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
5220 # remove OST1 from the qpool1 and check granted space
5221 # should be 0 for TSTUSR and 10M for TSTUSR2
5222 pool_remove_target $qpool 0
5223 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
5224 [ $granted_mb -eq 0 ] ||
5225 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
5226 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5227 [ $granted_mb -eq 10 ] ||
5228 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
5231 wait_delete_completed || error "wait_delete_completed failed"
5232 sync_all_data || true
5233 used=$(getquota -u $TSTUSR global curspace)
5234 [ $used -eq 0 ] || quota_error u $TSTUSR \
5235 "user quota isn't released after deletion"
5237 run_test 67 "quota pools recalculation"
5244 wait_update_facet "--quiet" mds1 \
5245 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
5246 >/dev/null 2>&1 || echo foo" "">/dev/null ||
5247 error "mds1: failed to create quota pool $pool"
5249 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
5250 awk '/usr/ {getline; print $2}'
5255 local qpool="qpool1"
5258 setup_quota_test || error "setup quota failed with $?"
5261 set_ost_qtype $QTYPE || error "enable ost quota failed"
5263 # check slave number for glbal pool
5264 local nr=$(get_slave_nr "0x0" "usr")
5265 echo "nr result $nr"
5266 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
5267 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5269 # create qpool and add OST1
5270 pool_add $qpool || error "pool_add failed"
5271 nr=$(get_slave_nr $qpool "usr")
5272 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5275 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5276 nr=$(get_slave_nr $qpool "usr")
5277 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5280 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5281 nr=$(get_slave_nr $qpool "usr")
5282 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
5285 pool_remove_target $qpool 0
5286 nr=$(get_slave_nr $qpool "usr")
5287 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5290 pool_remove_target $qpool 1
5291 nr=$(get_slave_nr $qpool "usr")
5292 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5294 # Check again that all is fine with global pool
5295 nr=$(get_slave_nr "0x0" "usr")
5296 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
5297 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5299 run_test 68 "slave number in quota pool changed after each add/remove OST"
5303 local global_limit=200 # MB
5305 local testfile="$DIR/$tdir/$tfile-0"
5306 local dom0="$DIR/$tdir/dom0"
5307 local qpool="qpool1"
5310 setup_quota_test || error "setup quota failed with $?"
5313 set_ost_qtype $QTYPE || error "enable ost quota failed"
5314 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5316 # Save DOM only at MDT0
5317 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
5318 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
5320 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
5322 # create qpool and add OST0
5323 pool_add $qpool || error "pool_add failed"
5324 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5326 log "User quota (block hardlimit:$global_limit MB)"
5327 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5328 error "set user quota failed"
5330 log "User quota (block hardlimit:$limit MB)"
5331 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5332 error "set user quota failed"
5334 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
5335 quota_error u $TSTUSR "write failed"
5337 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5338 oflag=sync || quota_error u $TSTUSR "write failed"
5340 $RUNAS $DD of=$testfile count=$limit || true
5342 # flush cache, ensure noquota flag is set on client
5343 cancel_lru_locks osc
5344 sync; sync_all_data || true
5346 # MDT0 shouldn't get EDQUOT with glimpse.
5347 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
5348 quota_error u $TSTUSR \
5349 "user write success, but expect EDQUOT"
5351 # Now all members of qpool1 should get EDQUOT. Expect success
5352 # when write to DOM on MDT0, as it belongs to global pool.
5353 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
5354 oflag=sync || quota_error u $TSTUSR "write failed"
5356 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5357 oflag=sync || quota_error u $TSTUSR "write failed"
5359 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
5363 local qpool="qpool1"
5368 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
5369 skip "Needs a client >= $VERSION_WITH_QP"
5371 setup_quota_test || error "setup quota failed with $?"
5373 # MDS returns EFAULT for unsupported quotactl command
5374 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
5376 # create qpool and add OST0
5377 pool_add $qpool || error "pool_add failed"
5378 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5380 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
5382 [ $rc -eq $err ] || error "setquota res $rc != $err"
5384 # If MDS supports QP, check that limit was set properly.
5385 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
5386 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
5387 echo "hard limit $bhard limit $limit"
5388 [ $bhard -ne $((limit*1024)) ] &&
5389 error "bhard:$bhard for $qpool!=$((limit*1024))"
5392 $LFS quota -u $TSTUSR --pool $qpool $DIR
5394 [ $rc -eq $err ] || error "quota res $rc != $err"
5396 run_test 70a "check lfs setquota/quota with a pool option"
5400 local glbl_hard=200 # 200M
5401 local glbl_soft=100 # 100M
5402 local pool_hard=10 # 10M
5403 local qpool="qpool1"
5405 pool_add $qpool || error "pool_add failed"
5406 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5408 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
5409 error "set user quota failed"
5410 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
5411 error "set user quota failed"
5413 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5414 [ $tmp -eq $((pool_hard * 1024)) ] ||
5415 error "wrong block hard limit $tmp for $qpool"
5416 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
5417 # soft limit hasn't been set and should be zero
5418 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
5420 run_test 70b "lfs setquota pool works properly"
5425 local global_limit=100 # MB
5426 local testfile="$DIR/$tdir/$tfile-0"
5427 local qpool="qpool1"
5428 local qpool2="qpool2"
5430 [ "$ost1_FSTYPE" == zfs ] &&
5431 skip "ZFS grants some block space together with inode"
5432 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
5434 setup_quota_test || error "setup quota failed with $?"
5437 set_ost_qtype $QTYPE || error "enable ost quota failed"
5440 log "User quota (block hardlimit:$global_limit MB)"
5441 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5442 error "set user quota failed"
5444 pool_add $qpool || error "pool_add failed"
5445 pool_add_targets $qpool 0 1 ||
5446 error "pool_add_targets failed"
5448 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5449 error "set user quota failed"
5451 pool_add $qpool2 || error "pool_add failed"
5452 pool_add_targets $qpool2 1 1 ||
5453 error "pool_add_targets failed"
5455 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
5456 error "set user quota failed"
5458 # make sure the system is clean
5459 local used=$(getquota -u $TSTUSR global curspace)
5462 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5464 # create 1st component 1-10M
5465 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5466 #create 2nd component 10-30M
5467 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5468 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5470 # сheck normal use and out of quota with PFL
5471 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
5472 test_1_check_write $testfile "user" $((limit*2))
5474 wait_delete_completed || error "wait_delete_completed failed"
5475 sync_all_data || true
5476 used=$(getquota -u $TSTUSR global curspace)
5477 [ $used -ne 0 ] && quota_error u $TSTUSR \
5478 "user quota isn't released after deletion"
5480 # create 1st component 1-10M
5481 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5482 # create 2nd component 10-30M
5483 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5484 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5486 # write to the 2nd component
5487 $RUNAS $DD of=$testfile count=$limit seek=10 ||
5488 quota_error u $TSTUSR \
5489 "write failure, but expect success"
5490 # this time maybe cache write, ignore it's failure
5491 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
5492 cancel_lru_locks osc
5493 sync; sync_all_data || true
5494 # write over limit in qpool2(2nd component 10-30M)
5495 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
5496 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5497 # write to the 1st component - OST0 is empty
5498 $RUNAS $DD of=$testfile count=$limit seek=0 ||
5499 quota_error u $TSTUSR "write failed"
5501 run_test 71a "Check PFL with quota pools"
5505 local global_limit=1000 # MB
5506 local limit1=160 # MB
5507 local limit2=10 # MB
5508 local testfile="$DIR/$tdir/$tfile-0"
5509 local qpool="qpool1"
5510 local qpool2="qpool2"
5512 [ "$ost1_FSTYPE" == zfs ] &&
5513 skip "ZFS grants some block space together with inode"
5514 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
5516 setup_quota_test || error "setup quota failed with $?"
5519 set_ost_qtype $QTYPE || error "enable ost quota failed"
5522 log "User quota (block hardlimit:$global_limit MB)"
5523 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5524 error "set user quota failed"
5526 pool_add $qpool || error "pool_add failed"
5527 pool_add_targets $qpool 0 1 ||
5528 error "pool_add_targets failed"
5530 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
5531 error "set user quota failed"
5533 pool_add $qpool2 || error "pool_add failed"
5534 pool_add_targets $qpool2 1 1 ||
5535 error "pool_add_targets failed"
5537 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5538 error "set user quota failed"
5540 # make sure the system is clean
5541 local used=$(getquota -u $TSTUSR global curspace)
5544 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5546 # First component is on OST0, 2nd on OST1
5547 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5548 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5550 # fill the 1st component on OST0
5551 $RUNAS $DD of=$testfile count=128 ||
5552 quota_error u $TSTUSR "write failed"
5553 # write to the 2nd cmpnt on OST1
5554 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5555 quota_error u $TSTUSR "write failed"
5556 # this time maybe cache write, ignore it's failure
5557 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5559 cancel_lru_locks osc
5560 sync; sync_all_data || true
5561 # write over limit in qpool2
5562 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5563 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5566 run_test 71b "Check SEL with quota pools"
5571 local global_limit=50 # MB
5572 local testfile="$DIR/$tdir/$tfile-0"
5573 local qpool="qpool1"
5576 setup_quota_test || error "setup quota failed with $?"
5579 set_ost_qtype $QTYPE || error "enable ost quota failed"
5582 log "User quota (block hardlimit:$global_limit MB)"
5583 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5584 error "set user quota failed"
5586 pool_add $qpool || error "pool_add failed"
5587 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5589 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5590 error "set user quota failed"
5592 # make sure the system is clean
5593 local used=$(getquota -u $TSTUSR global curspace)
5595 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5597 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5599 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5600 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5601 test_1_check_write $testfile "user" $limit
5602 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5604 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5605 # check that lfs quota -uv --pool prints only OST that
5606 # was added in a pool
5607 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5608 grep "OST\|MDT" && error "$qpool consists wrong targets"
5611 run_test 72 "lfs quota --pool prints only pool's OSTs"
5615 (( $MDS1_VERSION >= $(version_code 2.14.51.158) )) ||
5616 skip "need MDS >= v2_14_51-158-g25a70a88 for default pool quota"
5618 local qpool="qpool1"
5622 pool_add $qpool || error "pool_add failed"
5623 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5624 error "pool_add_targets failed"
5626 test_default_quota "-u" "data" "qpool1"
5628 run_test 73a "default limits at OST Pool Quotas"
5632 (( $MDS1_VERSION >= $(version_code 2.14.52.91) )) ||
5633 skip "need MDS >= v2_14_52-91-g188112fc8 for nested lqe fix"
5635 local TESTFILE1="$DIR/$tdir/$tfile-1"
5637 local qpool="qpool1"
5641 setup_quota_test || error "setup quota failed with $?"
5643 set_ost_qtype $QTYPE || error "enable ost quota failed"
5645 # pool quotas don't work properly without global limit
5646 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5647 error "set global limit failed"
5649 pool_add $qpool || error "pool_add failed"
5650 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5651 error "pool_add_targets failed"
5653 log "set default quota for $qpool"
5654 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5655 error "set default quota failed"
5657 log "Write from user that hasn't lqe"
5658 # Check that it doesn't cause a panic or a deadlock
5659 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5660 # Have to use RUNAS_ID as resetquota creates lqes in
5661 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5662 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5664 cancel_lru_locks osc
5665 sync; sync_all_data || true
5667 run_test 73b "default OST Pool Quotas limit for new user"
5671 (( $MDS1_VERSION >= $(version_code 2.14.52.6) )) ||
5672 skip "need MDS >= v2_14_52-6-g8c19365416 for pool per-user fix"
5674 local global_limit=200 # 200M
5675 local limit=10 # 10M
5676 local limit2=50 # 50M
5677 local qpool="qpool1"
5678 local qpool2="qpool2"
5682 setup_quota_test || error "setup quota failed with $?"
5685 set_ost_qtype $QTYPE || error "enable ost quota failed"
5687 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5688 error "set user quota failed"
5690 pool_add $qpool || error "pool_add failed"
5691 pool_add_targets $qpool 0 1 ||
5692 error "pool_add_targets failed"
5694 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5695 error "set user quota failed"
5697 pool_add $qpool2 || error "pool_add failed"
5698 pool_add_targets $qpool2 1 1 ||
5699 error "pool_add_targets failed"
5701 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5702 error "set user quota failed"
5704 tmp=$(getquota -u $TSTUSR global bhardlimit)
5705 [ $tmp -eq $((global_limit * 1024)) ] ||
5706 error "wrong global limit $global_limit"
5708 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5709 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5711 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5712 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5714 # check limits in pools
5715 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5716 grep -A4 $qpool | awk 'NR == 4{print $4}')
5717 echo "pool limit for $qpool $tmp"
5718 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5719 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5720 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5721 echo "pool limit for $qpool2 $tmp"
5722 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5724 run_test 74 "check quota pools per user"
5726 function cleanup_quota_test_75()
5728 do_facet mgs $LCTL nodemap_modify --name default \
5729 --property admin --value 1
5730 do_facet mgs $LCTL nodemap_modify --name default \
5731 --property trusted --value 1
5732 do_facet mgs $LCTL nodemap_modify --name default \
5733 --property squash_uid --value 99
5734 do_facet mgs $LCTL nodemap_modify --name default \
5735 --property squash_gid --value 99
5737 wait_nm_sync default admin_nodemap
5738 wait_nm_sync default trusted_nodemap
5740 do_facet mgs $LCTL nodemap_activate 0
5743 resetquota -u $TSTUSR
5747 local dd_failed=false
5748 local LIMIT=20480 #20M
5751 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5752 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5753 conv=fsync || dd_failed=true
5756 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5758 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5759 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5760 conv=fsync || dd_failed=true
5763 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5765 rm -f $DIR/$tdir_dom/*
5767 # flush cache, ensure noquota flag is set on client
5769 sync; sync_all_data || true
5773 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5774 quota_error u $qid "write failed, expect succeed (2)"
5776 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5777 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5778 conv=fsync || dd_failed=true
5781 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5784 rm -f $DIR/$tdir_dom/*
5786 # flush cache, ensure noquota flag is set on client
5788 sync; sync_all_data || true
5792 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5793 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5794 conv=fsync || dd_failed=true
5797 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5799 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=direct &&
5800 quota_error u $qid "write succeed, expect EDQUOT (3)"
5806 (( $MDS1_VERSION >= $(version_code 2.14.52.68) )) ||
5807 skip "need MDS >= v2_14_52-68-ga4fbe7341b for squash root fix"
5809 local soft_limit=10 # MB
5810 local hard_limit=20 # MB
5811 local limit=$soft_limit
5812 local testfile="$DIR/$tdir/$tfile-0"
5813 local grace=20 # seconds
5814 local tdir_dom=${tdir}_dom
5816 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5820 setup_quota_test || error "setup quota failed with $?"
5821 stack_trap cleanup_quota_test_75 EXIT
5824 set_ost_qtype $QTYPE || error "enable ost quota failed"
5825 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5827 local used=$(getquota -u $TSTID global curspace)
5828 $LFS setquota -t -u --block-grace $grace --inode-grace \
5829 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5830 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5831 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5832 error "set user quota failed"
5834 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5835 mkdir $DIR/$tdir_dom
5836 chmod 777 $DIR/$tdir_dom
5837 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5838 error "setstripe $tdir_dom failed"
5840 do_facet mgs $LCTL nodemap_activate 1
5842 do_facet mgs $LCTL nodemap_modify --name default \
5843 --property admin --value 0
5844 do_facet mgs $LCTL nodemap_modify --name default \
5845 --property trusted --value 0
5846 do_facet mgs $LCTL nodemap_modify --name default \
5847 --property deny_unknown --value 0
5848 do_facet mgs $LCTL nodemap_modify --name default \
5849 --property squash_uid --value $TSTID
5850 do_facet mgs $LCTL nodemap_modify --name default \
5851 --property squash_gid --value $TSTID
5852 cancel_lru_locks mdc
5853 wait_nm_sync default admin_nodemap
5854 wait_nm_sync default trusted_nodemap
5855 wait_nm_sync default squash_uid
5857 # mmap write when over soft limit
5859 $DD of=$testfile count=${limit} || quota_error a $TSTUSR \
5860 "root write failure, but expect success (1)"
5861 OFFSET=$((limit * 1024))
5862 cancel_lru_locks osc
5864 echo "Write to exceed soft limit"
5865 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5866 quota_error a $TSTUSR "root write failure, but expect success (2)"
5867 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5868 cancel_lru_locks osc
5870 echo "mmap write when over soft limit"
5871 $MULTIOP $testfile.mmap OT40960SMW ||
5872 quota_error a $TSTUSR "mmap write failure, but expect success"
5873 cancel_lru_locks osc
5875 wait_delete_completed || error "wait_delete_completed failed (1)"
5876 sync_all_data || true
5878 # test for user hard limit
5881 $DD of=$testfile count=$((limit/2)) ||
5882 quota_error u $TSTID \
5883 "root write failure, but expect success (3)"
5885 log "Write out of block quota ..."
5886 # possibly a cache write, ignore failure
5887 $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
5888 # flush cache, ensure noquota flag is set on client
5889 cancel_lru_locks osc
5890 sync; sync_all_data || true
5891 # sync forced cache flush, but did not guarantee that slave
5892 # got new edquot through glimpse, so wait to make sure
5894 $DD of=$testfile count=1 seek=$limit conv=fsync &&
5895 quota_error u $TSTID \
5896 "user write success, but expect EDQUOT"
5898 wait_delete_completed || error "wait_delete_completed failed (2)"
5899 sync_all_data || true
5900 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5901 quota_error u $TSTID "user quota not released after deletion"
5905 run_test 75 "nodemap squashed root respects quota enforcement"
5908 (( $MDS1_VERSION >= $(version_code 2.14.52.109) )) ||
5909 skip "need MDS >= v2_14_52-109-g3ffa5d680f for bad PRJID fix"
5910 ! is_project_quota_supported &&
5911 skip "skip project quota unsupported"
5913 setup_quota_test || error "setup quota failed with $?"
5916 local testfile="$DIR/$tdir/$tfile-0"
5919 $LFS project -p 4294967295 $testfile &&
5920 error "set project ID should fail"
5923 run_test 76 "project ID 4294967295 should be not allowed"
5927 (( $MDS1_VERSION >= $(version_code 2.14.54.33) )) ||
5928 skip "need MDS >= v2_14_54-33-g29e00cecc6 for readonly fix"
5930 mount_client $MOUNT2 "ro"
5931 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5932 error "lfs setquota should fail in read-only Lustre mount"
5935 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5939 (( $OST1_VERSION >= $(version_code 2.14.55.173) )) ||
5940 skip "need OST >= v2_14_55-173-g789038c97a for fallocate fix"
5941 check_set_fallocate_or_skip
5943 setup_quota_test || error "setup quota failed with $?"
5946 set_ost_qtype $QTYPE || error "enable ost quota failed"
5948 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5949 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5952 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5953 error "lfs setquota failed"
5956 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5958 kbytes=$(lfs quota -u $TSTUSR $DIR |
5959 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5960 echo "kbytes returned:$kbytes"
5962 # For file size of 204800. We should be having roughly 200 kbytes
5963 # returned. Anything alarmingly low (50 taken as arbitrary value)
5964 # would bail out this TC. Also this also avoids $kbytes of 0
5965 # to be used in calculation below.
5966 (( $kbytes > 50 )) ||
5967 error "fallocate did not use quota. kbytes returned:$kbytes"
5969 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5970 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5972 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5973 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5974 error "fallocate did not use quota correctly"
5976 run_test 78A "Check fallocate increase quota usage"
5980 (( $CLIENT_VERSION >= $(version_code 2.15.0.37) )) ||
5981 skip "need client >= v2_15_50-37-g5fc934eb for falloc proj fix"
5982 (( $OST1_VERSION >= $(version_code 2.15.0.37) )) ||
5983 skip "need OST >= v2_15_50-37-g5fc934ebbb for falloc proj fix"
5984 check_set_fallocate_or_skip
5986 setup_quota_test || error "setup quota failed with $?"
5989 set_ost_qtype $QTYPE || error "enable ost quota failed"
5991 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5993 local projectid=5200 # Random project id to test
5995 change_project -sp $projectid $DIR/$tdir
5998 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5999 error "lfs setquota project failed"
6002 fallocate -l 204800 $DIR/$tdir/$tfile
6004 # Get curspace (kbytes) for $projectid
6005 local kbytes=$(getquota -p $projectid global curspace)
6007 echo "kbytes returned:$kbytes"
6009 # For file size of 204800. We should be having roughly 200 kbytes
6010 # returned. Anything alarmingly low (50 taken as arbitrary value)
6011 # would bail out this TC. Also this also avoids $kbytes of 0
6012 # to be used in calculation below.
6013 (( $kbytes > 50 )) ||
6014 error "fallocate did not use projectid. kbytes returned:$kbytes"
6016 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
6017 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
6019 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
6020 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
6021 error "fallocate did not use quota projectid correctly"
6023 run_test 78a "Check fallocate increase projectid usage"
6027 (( $MDS1_VERSION >= $(version_code 2.14.56.37) )) ||
6028 skip "need MDS >= v2_14_56-37-gc9901b68b4 for pool panic fix"
6030 local qpool="qpool1"
6031 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
6032 local stopf=$TMP/$tfile
6034 do_facet mds1 "touch $stopf" || error "can't create $stopf"
6035 do_facet mds1 "ls $stopf" || error "can't find $stopf"
6036 stack_trap "do_facet mds1 'rm -f $stopf'"
6037 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
6039 pool_add $qpool || error "pool_add failed"
6040 do_facet mds1 "rm $stopf"
6043 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
6047 (( $MDS1_VERSION >= $(version_code 2.14.56.51) )) ||
6048 skip "need MDS >= v2_14_56-51-g61ec1e0f2c for EDQUOT failover"
6050 local dir1="$DIR/$tdir/dir1"
6051 local dir2="$DIR/$tdir/dir2"
6052 local TESTFILE0="$dir1/$tfile-0"
6053 local TESTFILE1="$dir1/$tfile-1"
6054 local TESTFILE2="$dir1/$tfile-2"
6055 local TESTFILE3="$dir2/$tfile-0"
6056 local global_limit=100 # 100M
6057 local limit=10 # 10M
6058 local qpool="qpool1"
6060 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
6062 [ "$ost1_FSTYPE" == zfs ] &&
6063 skip "ZFS grants some block space together with inode"
6064 setup_quota_test || error "setup quota failed with $?"
6065 set_ost_qtype $QTYPE || error "enable ost quota failed"
6067 # make sure the system is clean
6068 local used=$(getquota -u $TSTUSR global curspace)
6069 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
6071 pool_add $qpool || error "pool_add failed"
6072 pool_add_targets $qpool 0 1 ||
6073 error "pool_add_targets failed"
6075 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
6076 error "set user quota failed"
6078 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
6079 error "set user quota failed"
6080 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6081 error "set user quota failed"
6083 mkdir -p $dir1 || error "failed to mkdir"
6084 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
6085 mkdir -p $dir2 || error "failed to mkdir"
6086 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
6088 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
6089 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
6094 $LFS quota -uv $TSTUSR $DIR
6095 #define OBD_FAIL_QUOTA_PREACQ 0xA06
6096 do_facet mds1 $LCTL set_param fail_loc=0xa06
6097 $RUNAS $DD of=$TESTFILE3 count=3 ||
6098 quota_error u $TSTUSR "write failed"
6099 $RUNAS $DD of=$TESTFILE2 count=7 ||
6100 quota_error u $TSTUSR "write failed"
6101 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
6102 quota_error u $TSTUSR "write failed"
6105 $LFS quota -uv --pool $qpool $TSTUSR $DIR
6109 do_facet mds1 $LCTL set_param fail_loc=0
6110 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
6111 $LFS quota -uv $TSTUSR --pool $qpool $DIR
6112 # OST0 needs some time to update quota usage after removing TESTFILE2
6114 $LFS quota -uv $TSTUSR --pool $qpool $DIR
6115 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
6116 quota_error u $TSTUSR "write failure, but expect success"
6118 run_test 80 "check for EDQUOT after OST failover"
6122 (( $MDS1_VERSION >= $(version_code 2.14.56.52) )) ||
6123 skip "need MDS >= v2_14_56-52-g862f0baa7c for qmt_pool_free fix"
6125 local global_limit=20 # 100M
6126 local testfile="$DIR/$tdir/$tfile-0"
6127 local qpool="qpool1"
6130 setup_quota_test || error "setup quota failed with $?"
6133 set_ost_qtype $QTYPE || error "enable ost quota failed"
6136 log "User quota (block hardlimit:$global_limit MB)"
6137 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
6139 pool_add $qpool || error "pool_add failed"
6140 #define OBD_FAIL_QUOTA_RECALC 0xA07
6141 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=10
6142 # added OST casues to start pool recalculation
6143 pool_add_targets $qpool 0 0 1
6144 stop mds1 -f || error "MDS umount failed"
6146 #start mds1 back to destroy created pool
6147 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
6150 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
6154 (( $MDS1_VERSION >= $(version_code 2.15.50.72) )) ||
6155 skip "need MDS >= v2_15_50-72-g61481796ac for over 8 QIDs fix"
6157 is_project_quota_supported || skip "skip project quota unsupported"
6159 setup_quota_test || error "setup quota failed with $?"
6162 local parent_dir="$DIR/$tdir.parent"
6163 local child_dir="$parent_dir/child"
6166 stack_trap "chown -R 0:0 $parent_dir"
6168 chown $TSTUSR:$TSTUSR $parent_dir ||
6169 error "failed to chown on $parent_dir"
6170 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
6171 error "failed to chown on $parent_dir"
6173 $LFS project -p 1000 $parent_dir ||
6174 error "failed to set project id on $parent_dir"
6175 $LFS project -p 1001 $child_dir ||
6176 error "failed to set project id on $child_dir"
6178 rmdir $child_dir || error "cannot remove child dir, test failed"
6180 run_test 82 "verify more than 8 qids for single operation"
6182 test_grace_with_default_quota()
6191 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
6192 error "clear default quota [$qdtype] failed"
6194 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
6195 error "reset quota [$qdtype] grace failed"
6198 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
6199 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
6202 $LFS setquota $qdtype -B 10G -i 10k $DIR
6205 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
6206 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
6208 [ "$bgrace" == "$bgrace2" ] ||
6209 error "set default quota shouldn't affect block grace"
6210 [ "$igrace" == "$igrace2" ] ||
6211 error "set default quota shouldn't affect inode grace"
6217 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
6218 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
6220 setup_quota_test || error "setup quota failed with $?"
6221 test_grace_with_default_quota "-u" "-U"
6222 test_grace_with_default_quota "-g" "-G"
6224 is_project_quota_supported || return 0
6225 test_grace_with_default_quota "-p" "-P"
6227 run_test 83 "Setting default quota shouldn't affect grace time"
6231 (( $MDS1_VERSION >= $(version_code 2.15.53.115) )) ||
6232 skip "need MDS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
6233 (( $OST1_VERSION >= $(version_code 2.15.53.115) )) ||
6234 skip "need OSS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
6236 local dir1="$DIR/$tdir/dir1"
6237 local TESTFILE1="$dir1/$tfile-1"
6245 setup_quota_test || error "setup quota failed with $?"
6247 set_ost_qtype $QTYPE || error "enable ost quota failed"
6249 pool_add $qp || error "pool_add failed"
6250 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
6251 error "pool_add_targets failed"
6253 $LFS setquota -g $TSTUSR -B 10G $DIR ||
6254 error "failed to set group quota for $TSTUSR"
6255 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
6256 error "set user quota failed"
6257 $LFS quota -gv $TSTUSR $DIR
6259 wait_quota_synced "ost1" "OST0000" "grp" $TSTID "hardlimit" "10485760"
6261 mkdir -p $dir1 || error "failed to mkdir"
6262 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
6264 $LFS setstripe -c 1 -i 0 $TESTFILE1
6265 $LFS getstripe $TESTFILE1
6266 chown $TSTUSR.$TSTUSR $TESTFILE1
6268 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
6269 quota_error g $TSTUSR "write failed"
6271 sync_all_data || true
6273 $LFS quota -gv $TSTUSR $DIR
6274 $LFS quota -gv --pool $qp $TSTUSR $DIR
6276 # the grant quota should be larger than 0
6278 while (( $waited < 60 )); do
6279 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6280 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6281 (( ${grant} > 0 && ${grant2} > 0 )) && break
6283 do_facet ost1 $LCTL set_param \
6284 osd-*.*-OST0000.quota_slave.force_reint=1
6286 waited=$((waited + 1))
6289 (( $waited >= 60)) && {
6290 $LFS quota -gv $TSTUSR $DIR
6291 $LFS quota -gv --pool $qp $TSTUSR $DIR
6294 (( ${grant} > 0 )) || error "pool grant is not increased after dd"
6295 (( ${grant2} > 0 )) || error "grant is not increased after dd"
6297 #define OBD_FAIL_QUOTA_GRANT 0xA08
6298 lustre_fail mds 0xa08
6299 lustre_fail ost 0xa08
6302 # clear quota limits to trigger updating grant quota
6303 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
6304 error "failed to clear the group quota for $TSTUSR"
6305 $LFS quota -gv $TSTUSR $DIR
6306 $LFS quota -gv --pool $qp $TSTUSR $DIR
6308 # the grant quota should be set as insane value
6310 while (( $waited < 60 )); do
6311 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6312 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6313 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
6316 waited=$((waited + 1))
6319 (( $waited >= 60)) && {
6320 $LFS quota -gv $TSTUSR $DIR
6321 $LFS quota -gv --pool $qp $TSTUSR $DIR
6324 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
6325 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
6327 lustre_fail mds_ost 0
6331 $LFS setquota -g $TSTUSR -r $DIR ||
6332 error "failed to reset group quota for $TSTUSR"
6335 $LFS quota -gv $TSTUSR $DIR
6336 $LFS quota -gv --pool $qp $TSTUSR $DIR
6338 # the grant quota should be reset
6339 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6340 (( ${#grant} == 20 )) && error "grant is not cleared"
6341 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6342 (( ${#grant} == 20 )) && error "pool grant is not cleared"
6344 $LFS quota -gv $TSTUSR --pool $qp $DIR
6345 $LFS quota -gv --pool $qp $TSTUSR $DIR
6346 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
6347 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
6349 # test whether the quota still works
6350 $LFS setquota -g $TSTUSR -B 100M $DIR ||
6351 error "failed to set group quota for $TSTUSR"
6352 $LFS quota -gv $TSTUSR $DIR
6354 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
6355 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
6357 $LFS setquota -g $TSTUSR -B 300M $DIR ||
6358 error "failed to set group quota for $TSTUSR"
6359 $LFS quota -gv $TSTUSR $DIR
6361 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
6362 quota_error g $TSTUSR "dd failed, expect succeed"
6364 run_test 84 "Reset quota should fix the insane granted quota"
6368 (( $MDS1_VERSION >= $(version_code 2.15.55.5) )) ||
6369 skip "need MDS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6370 (( $OST1_VERSION >= $(version_code 2.15.55.5) )) ||
6371 skip "need OSS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6374 local qpool="qpool1"
6375 local qpool2="qpool2"
6376 local tfile1="$DIR/$tdir/$tfile-0"
6378 (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
6380 setup_quota_test || error "setup quota failed with $?"
6383 set_ost_qtype $QTYPE || error "enable ost quota failed"
6385 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
6386 error "set user quota failed"
6388 pool_add $qpool || error "pool_add failed"
6389 pool_add_targets $qpool 0 1 ||
6390 error "pool_add_targets failed"
6392 pool_add $qpool2 || error "pool_add failed"
6393 pool_add_targets $qpool2 0 1 ||
6394 error "pool_add_targets failed"
6396 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
6397 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
6398 error "set user quota failed"
6399 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6400 error "set user quota failed"
6402 # don't care about returned value. Just check we don't hung on write.
6403 $RUNAS $DD of=$tfile1 count=10
6406 run_test 85 "do not hung at write with the least_qunit"
6408 test_preacquired_quota()
6415 [[ "$qtype" == "-p" ]] && change_project -sp $qid $DIR/$tdir
6417 $LFS setquota $qtype $qid -i 100K -I 100K $DIR ||
6418 error "failed to set file [$qtype] quota"
6420 $RUNAS createmany -m $test_dir/tfile- 5000 ||
6421 error "failed to create files, expect succeed"
6423 wait_zfs_commit $SINGLEMDS
6424 $LFS setquota $qtype $qid -i 2K -I 2K $DIR ||
6425 error "failed to decrease file [$qtype] quota"
6427 wait_quota_synced "mds1" "MDT0000" $qtype_name $qid "hardlimit" "2048"
6429 # make sure the lqe->lqe_edquot is set
6430 $RUNAS createmany -m $test_dir/tfile2- 10
6433 $RUNAS createmany -m $test_dir/tfile3- 30 &&
6434 error "succeed to create files, expect failed"
6436 rm -f $test_dir/tfile*
6437 $LFS setquota $qtype $qid -i 0 -I 0 $DIR ||
6438 error "failed to reset file user quota"
6443 (( $MDS1_VERSION >= $(version_code 2.15.57.41) )) ||
6444 skip "need MDS >= 2.15.57.41 for quota over limit release fix"
6446 local test_dir="$DIR/$tdir/test_dir"
6448 setup_quota_test || error "setup quota failed with %?"
6449 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
6451 $LFS setdirstripe -c 1 -i 0 $test_dir || error "setdirstripe failed"
6454 test_preacquired_quota "$test_dir" "-u" "usr" "$TSTID"
6455 test_preacquired_quota "$test_dir" "-g" "grp" "$TSTID"
6457 is_project_quota_supported || return 0
6458 test_preacquired_quota "$test_dir" "-p" "prj" "1000"
6460 run_test 86 "Pre-acquired quota should be released if quota is over limit"
6464 do_nodes $(comma_list $(nodes_list)) \
6465 "lctl set_param -n debug=-quota-trace"
6466 if $PQ_CLEANUP; then
6467 disable_project_quota
6470 reset_quota_settings
6474 complete_test $SECONDS
6475 check_and_cleanup_lustre
6476 export QUOTA_AUTO=$QUOTA_AUTO_OLD