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 wait_update_facet $tgt "$cmd |
293 grep "$qtype" | awk '{ print \\\$3 }'" \
294 "$result" $max || return 1
304 if [[ "$qtype" =~ "u" ]]; then
305 wait_reintegration "mdt" "user" $max || return 1
308 if [[ "$qtype" =~ "g" ]]; then
309 wait_reintegration "mdt" "group" $max || return 1
312 if [[ "$qtype" =~ "p" ]]; then
313 ! is_project_quota_supported && return 0
314 wait_reintegration "mdt" "project" $max || return 1
323 if [[ "$qtype" =~ "u" ]]; then
324 wait_reintegration "ost" "user" $max || return 1
327 if [[ "$qtype" =~ "g" ]]; then
328 wait_reintegration "ost" "group" $max || return 1
331 if [[ "$qtype" =~ "p" ]]; then
332 ! is_project_quota_supported && return 0
333 wait_reintegration "ost" "project" $max || return 1
342 local extrasleep=${4:-5}
349 *) error "get_grace_time: Invalid quota type: $qtype"
354 echo "Quota info for $pool:"
355 $LFS quota -$qtype $qarg $parg $DIR
360 time=$(lfs quota -$qtype $qarg $parg $DIR|
361 awk 'NR == 3{ print $5 }')
364 time=$(lfs quota -$qtype $qarg $DIR|
365 awk 'NR == 3{ print $9 }')
368 error "Unknown quota type: $flavour"
372 local sleep_seconds=0
373 local orig_time=$time
375 echo "Grace time is $time"
376 # from lfs.c:__sec2str()
377 # const char spec[] = "smhdw";
378 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
379 [[ $time == *w* ]] && w_time=${time%w*} &&
380 let sleep_seconds+=$((w_time*7*24*60*60));
382 [[ $time == *d* ]] && d_time=${time%d*} &&
383 let sleep_seconds+=$((d_time*24*60*60));
385 [[ $time == *h* ]] && h_time=${time%h*} &&
386 let sleep_seconds+=$((h_time*60*60));
388 [[ $time == *m* ]] && m_time=${time%m*} &&
389 let sleep_seconds+=$((m_time*60));
391 [[ $time == *s* ]] && s_time=${time%s*} &&
392 let sleep_seconds+=$s_time
394 echo "Sleep through grace ..."
395 [ "$orig_time" == "-" ] &&
396 error "Grace timeout was not set or quota not exceeded"
397 if [ "$orig_time" == "expired" -o "$orig_time" == "none" ]; then
398 echo "...Grace timeout already expired"
400 let sleep_seconds+=$extrasleep
401 echo "...sleep $sleep_seconds seconds"
407 wait_delete_completed
408 echo "Creating test directory"
409 mkdir_on_mdt0 $DIR/$tdir || return 1
410 chmod 0777 $DIR/$tdir || return 2
411 # always clear fail_loc in case of fail_loc isn't cleared
412 # properly when previous test failed
413 lustre_fail mds_ost 0
414 stack_trap cleanup_quota_test EXIT
417 cleanup_quota_test() {
418 echo "Delete files..."
420 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
421 echo "Wait for unlink objects finished..."
422 wait_delete_completed
423 sync_all_data || true
433 $LFS quota -v -$ugp $qid $DIR
435 if [ "$bf" == "a" -o "$bf" == "b" ]; then
436 usage=$(getquota -$ugp $qid global curspace)
437 if [ -z $usage ]; then
438 quota_error $ugp $qid \
439 "Query block quota failed ($ugp:$qid)."
441 [ $usage -ne 0 ] && quota_log $ugp $qid \
442 "Block quota isn't 0 ($ugp:$qid:$usage)."
446 if [ "$bf" == "a" -o "$bf" == "f" ]; then
447 usage=$(getquota -$ugp $qid global curinodes)
448 if [ -z $usage ]; then
449 quota_error $ugp $qid \
450 "Query file quota failed ($ugp:$qid)."
452 [ $usage -ne 0 ] && quota_log $ugp $qid \
453 "File quota isn't 0 ($ugp:$qid:$usage)."
458 project_quota_enabled () {
460 local zfeat="feature@project_quota"
462 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
463 local facet_fstype=${facet:0:3}1_FSTYPE
466 if [ "${!facet_fstype}" = "zfs" ]; then
467 devname=$(zpool_name ${facet})
468 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
469 grep -wq active || rc=1
471 [ ${facet:0:3} == "mds" ] &&
472 devname=$(mdsdevname ${facet:3}) ||
473 devname=$(ostdevname ${facet:3})
474 do_facet ${facet} $DEBUGFS -R features $devname |
475 grep -q project || rc=1
478 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
482 project_quota_enabled || enable_project_quota
484 reset_quota_settings() {
485 resetquota_one -u $TSTUSR
486 [[ $(id -u $TSTUSR) == $TSTID ]] || resetquota_one -u $TSTID
487 resetquota_one -g $TSTUSR
488 [[ $(id -g $TSTUSR) == $TSTID ]] || resetquota_one -g $TSTID
489 resetquota_one -u $TSTUSR2
490 [[ $(id -u $TSTUSR2) == $TSTID2 ]] || resetquota_one -u $TSTID2
491 resetquota_one -g $TSTUSR2
492 [[ $(id -g $TSTUSR2) == $TSTID2 ]] || resetquota_one -g $TSTID2
493 is_project_quota_supported && resetquota_one -p $TSTPRJID
500 do_nodes $(comma_list $(nodes_list)) \
501 "$LCTL set_param -n debug=+quota+trace"
506 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
507 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
508 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
509 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
511 test_quota_performance() {
512 local TESTFILE="$DIR/$tdir/$tfile-0"
513 local size=$1 # in MB
514 local stime=$(date +%s)
515 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
516 quota_error u $TSTUSR "write failure"
517 local etime=$(date +%s)
518 delta=$((etime - stime))
519 if [ $delta -gt 0 ]; then
520 rate=$((size * 1024 / delta))
521 if [ "$mds1_FSTYPE" = zfs ]; then
522 # LU-2872 - see LU-2887 for fix
524 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
526 [ $rate -gt 1024 ] ||
527 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
533 # test basic quota performance b=21696
536 [ "$SLOW" = "no" ] && MB=10
538 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
539 [ $free_space -le $((MB * 1024)) ] &&
540 skip "not enough space ${free_space} KB, " \
541 "required $((MB * 1024)) KB"
542 setup_quota_test || error "setup quota failed with $?"
544 set_ost_qtype "none" || error "disable ost quota failed"
545 test_quota_performance $MB
547 set_ost_qtype $QTYPE || error "enable ost quota failed"
548 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
549 error "set quota failed"
550 test_quota_performance $MB
552 run_test 0 "Test basic quota performance"
554 # usage: test_1_check_write tfile user|group|project
555 test_1_check_write() {
559 local short_qtype=${qtype:0:1}
562 $RUNAS $DD of=$testfile count=$((limit/2)) ||
563 quota_error $short_qtype $TSTUSR \
564 "$qtype write failure, but expect success"
565 log "Write out of block quota ..."
566 # this time maybe cache write, ignore it's failure
567 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
568 # flush cache, ensure noquota flag is set on client
570 sync; sync_all_data || true
571 # sync means client wrote all it's cache, but id doesn't
572 # guarantee that slave received new edquot through glimpse.
573 # so wait a little to be sure slave got it.
575 $RUNAS $DD of=$testfile count=1 seek=$limit &&
576 quota_error $short_qtype $TSTUSR \
577 "user write success, but expect EDQUOT"
581 check_write_fallocate() {
585 local short_qtype=${qtype:0:1}
588 log "Write ${count}MiB Using Fallocate"
589 $RUNAS fallocate -l${count}MiB $testfile ||
590 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
593 sync; sync_all_data || true
597 log "Write ${count}MiB Using Fallocate"
598 $RUNAS fallocate -l${count}MiB $testfile &&
599 quota_error $short_qtype $TSTUSR \
600 "Write success, expect EDQUOT" || true
603 # test block hardlimit
606 local testfile="$DIR/$tdir/$tfile-0"
608 setup_quota_test || error "setup quota failed with $?"
611 set_ost_qtype $QTYPE || error "enable ost quota failed"
614 log "User quota (block hardlimit:$limit MB)"
615 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
616 error "set user quota failed"
618 # make sure the system is clean
619 local used=$(getquota -u $TSTUSR global curspace)
620 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
622 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
623 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
625 test_1_check_write $testfile "user" $limit
628 wait_delete_completed || error "wait_delete_completed failed"
629 sync_all_data || true
630 used=$(getquota -u $TSTUSR global curspace)
631 [ $used -ne 0 ] && quota_error u $TSTUSR \
632 "user quota isn't released after deletion"
633 resetquota -u $TSTUSR
636 log "--------------------------------------"
637 log "Group quota (block hardlimit:$limit MB)"
638 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
639 error "set group quota failed"
641 testfile="$DIR/$tdir/$tfile-1"
642 # make sure the system is clean
643 used=$(getquota -g $TSTUSR global curspace)
644 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
646 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
647 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
649 test_1_check_write $testfile "group" $limit
651 wait_delete_completed || error "wait_delete_completed failed"
652 sync_all_data || true
653 used=$(getquota -g $TSTUSR global curspace)
654 [ $used -ne 0 ] && quota_error g $TSTUSR \
655 "Group quota isn't released after deletion"
656 resetquota -g $TSTUSR
658 if ! is_project_quota_supported; then
659 echo "Project quota is not supported"
663 testfile="$DIR/$tdir/$tfile-2"
664 # make sure the system is clean
665 used=$(getquota -p $TSTPRJID global curspace)
667 error "used space($used) for project $TSTPRJID isn't 0"
670 log "--------------------------------------"
671 log "Project quota (block hardlimit:$limit mb)"
672 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
673 error "set project quota failed"
675 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
676 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
677 change_project -p $TSTPRJID $testfile
679 test_1_check_write $testfile "project" $limit
684 used=$(getquota -p $TSTPRJID global curspace)
685 [ $used -ne 0 ] && quota_error p $TSTPRJID \
686 "project quota isn't released after deletion"
688 resetquota -p $TSTPRJID
690 run_test 1a "Block hard limit (normal use and out of quota)"
694 local global_limit=20 # MB
695 local testfile="$DIR/$tdir/$tfile-0"
699 setup_quota_test || error "setup quota failed with $?"
702 set_ost_qtype $QTYPE || error "enable ost quota failed"
705 log "User quota (block hardlimit:$global_limit MB)"
706 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
707 error "set user quota failed"
709 pool_add $qpool || error "pool_add failed"
710 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
711 error "pool_add_targets failed"
713 # check qmt_pool_add dmesg error
714 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
716 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
717 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
719 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
720 error "set user quota failed"
722 # make sure the system is clean
723 local used=$(getquota -u $TSTUSR global curspace)
725 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
727 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
729 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
730 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
732 test_1_check_write $testfile "user" $limit
735 wait_delete_completed || error "wait_delete_completed failed"
736 sync_all_data || true
737 used=$(getquota -u $TSTUSR global curspace $qpool)
738 [ $used -ne 0 ] && quota_error u $TSTUSR \
739 "user quota isn't released after deletion"
740 resetquota -u $TSTUSR
743 log "--------------------------------------"
744 log "Group quota (block hardlimit:$global_limit MB)"
745 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
746 error "set group quota failed"
748 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
749 error "set group quota failed"
751 testfile="$DIR/$tdir/$tfile-1"
752 # make sure the system is clean
753 used=$(getquota -g $TSTUSR global curspace $qpool)
754 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
756 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
757 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
759 test_1_check_write $testfile "group" $limit
762 wait_delete_completed || error "wait_delete_completed failed"
763 sync_all_data || true
764 used=$(getquota -g $TSTUSR global curspace $qpool)
765 [ $used -ne 0 ] && quota_error g $TSTUSR \
766 "Group quota isn't released after deletion"
767 resetquota -g $TSTUSR
769 if ! is_project_quota_supported; then
770 echo "Project quota is not supported"
774 testfile="$DIR/$tdir/$tfile-2"
775 # make sure the system is clean
776 used=$(getquota -p $TSTPRJID global curspace $qpool)
778 error "used space($used) for project $TSTPRJID isn't 0"
781 log "--------------------------------------"
782 log "Project quota (block hardlimit:$global_limit mb)"
783 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
784 error "set project quota failed"
786 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
787 error "set project quota failed"
790 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
791 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
792 change_project -p $TSTPRJID $testfile
794 test_1_check_write $testfile "project" $limit
799 used=$(getquota -p $TSTPRJID global curspace)
800 [ $used -eq 0 ] || quota_error p $TSTPRJID \
801 "project quota isn't released after deletion"
803 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
806 local global_limit=20 # MB
807 local testfile="$DIR/$tdir/$tfile-0"
808 local qpool1="qpool1"
809 local qpool2="qpool2"
812 setup_quota_test || error "setup quota failed with $?"
815 set_ost_qtype $QTYPE || error "enable ost quota failed"
818 log "User quota (block hardlimit:$global_limit MB)"
819 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
820 error "set user quota failed"
822 pool_add $qpool1 || error "pool_add failed"
823 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
824 error "pool_add_targets failed"
826 pool_add $qpool2 || error "pool_add failed"
827 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
828 error "pool_add_targets failed"
830 # create pools without hard limit
831 # initially such case raised several bugs
832 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
833 error "set user quota failed"
835 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
836 error "set user quota failed"
838 # make sure the system is clean
839 local used=$(getquota -u $TSTUSR global curspace)
841 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
843 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
845 test_1_check_write $testfile "user" $global_limit
847 used=$(getquota -u $TSTUSR global curspace $qpool1)
848 echo "qpool1 used $used"
849 used=$(getquota -u $TSTUSR global curspace $qpool2)
850 echo "qpool2 used $used"
853 wait_delete_completed || error "wait_delete_completed failed"
854 sync_all_data || true
856 used=$(getquota -u $TSTUSR global curspace $qpool1)
857 [ $used -eq 0 ] || quota_error u $TSTUSR \
858 "user quota isn't released after deletion"
860 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
865 local global_limit=20 # MB
866 local testfile="$DIR/$tdir/$tfile-0"
867 local qpool1="qpool1"
868 local qpool2="qpool2"
871 setup_quota_test || error "setup quota failed with $?"
874 set_ost_qtype $QTYPE || error "enable ost quota failed"
877 log "User quota (block hardlimit:$global_limit MB)"
878 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
879 error "set user quota failed"
881 pool_add $qpool1 || error "pool_add failed"
882 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
883 error "pool_add_targets failed"
885 pool_add $qpool2 || error "pool_add failed"
886 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
887 error "pool_add_targets failed"
889 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
890 error "set user quota failed"
892 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
893 error "set user quota failed"
895 # make sure the system is clean
896 local used=$(getquota -u $TSTUSR global curspace)
898 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
900 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
902 test_1_check_write $testfile "user" $limit1
904 used=$(getquota -u $TSTUSR global curspace $qpool1)
905 echo "qpool1 used $used"
906 used=$(getquota -u $TSTUSR global curspace $qpool2)
907 echo "qpool2 used $used"
910 wait_delete_completed || error "wait_delete_completed failed"
911 sync_all_data || true
913 used=$(getquota -u $TSTUSR global curspace $qpool1)
914 [ $used -eq 0 ] || quota_error u $TSTUSR \
915 "user quota isn't released after deletion"
917 run_test 1d "Quota pools: check block hardlimit on different pools"
921 local global_limit=53000000 # MB
922 local testfile="$DIR/$tdir/$tfile-0"
923 local testfile2="$DIR/$tdir/$tfile-1"
924 local qpool1="qpool1"
927 setup_quota_test || error "setup quota failed with $?"
930 set_ost_qtype $QTYPE || error "enable ost quota failed"
932 # global_limit is much greater than limit1 to get
933 # different qunit's on osts. Since 1st qunit shrinking
934 # on OST1(that belongs to qpool1), this qunit should
936 log "User quota (block hardlimit:$global_limit MB)"
937 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
938 error "set user quota failed"
940 pool_add $qpool1 || error "pool_add failed"
941 pool_add_targets $qpool1 1 1 ||
942 error "pool_add_targets failed"
944 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
945 error "set user quota failed"
947 # make sure the system is clean
948 local used=$(getquota -u $TSTUSR global curspace)
949 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
951 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
952 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
954 test_1_check_write $testfile "user" $limit1
956 $LFS setstripe $testfile2 -c 1 -i 0 ||
957 error "setstripe $testfile2 failed"
958 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
959 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
961 $RUNAS $DD of=$testfile2 count=20 ||
962 quota_error u $TSTUSR \
963 "$qtype write failure, but expect success"
967 wait_delete_completed || error "wait_delete_completed failed"
968 sync_all_data || true
970 used=$(getquota -u $TSTUSR global curspace $qpool1)
971 [ $used -eq 0 ] || quota_error u $TSTUSR \
972 "user quota isn't released after deletion"
974 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
977 local global_limit=200 # MB
979 local TESTDIR="$DIR/$tdir/"
980 local testfile="$TESTDIR/$tfile-0"
981 local qpool1="qpool1"
984 setup_quota_test || error "setup quota failed with $?"
987 set_ost_qtype $QTYPE || error "enable ost quota failed"
989 log "User quota (block hardlimit:$global_limit MB)"
990 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
991 error "set user quota failed"
993 pool_add $qpool1 || error "pool_add failed"
994 pool_add_targets $qpool1 0 0 ||
995 error "pool_add_targets failed"
997 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
998 error "set user quota failed"
1000 # make sure the system is clean
1001 local used=$(getquota -u $TSTUSR global curspace)
1002 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1004 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1006 test_1_check_write $testfile "user" $limit1
1008 pool_remove_target $qpool1 0
1010 wait_delete_completed || error "wait_delete_completed failed"
1011 sync_all_data || true
1013 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1014 # qunit for appropriate element in lgd array should be set
1015 # correctly(4096). Earlier it was not changed continuing to be 1024.
1016 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1017 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1018 # as it already was 1024. As flag "need_update" for this qunit was
1019 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1020 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1021 # became > 10M. QMT returned EINPROGRESS in a loop.
1022 # Check that it doesn't hung anymore.
1023 test_1_check_write $testfile "user" $limit1
1025 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1029 local global_limit=40 # MB
1030 local testfile="$DIR/$tdir/$tfile-0"
1031 local qpool="qpool1"
1032 local mdmb_param="osc.*.max_dirty_mb"
1033 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1036 setup_quota_test || error "setup quota failed with $?"
1037 $LCTL set_param $mdmb_param=1
1038 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1041 set_ost_qtype $QTYPE || error "enable ost quota failed"
1044 log "User quota (block hardlimit:$global_limit MB)"
1045 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1046 error "set user quota failed"
1048 pool_add $qpool || error "pool_add failed"
1049 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1050 error "pool_add_targets failed"
1052 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1053 error "set user quota failed"
1055 # make sure the system is clean
1056 local used=$(getquota -u $TSTUSR global curspace)
1058 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1060 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1061 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1064 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1065 quota_error u $TSTUSR \
1066 "$qtype write failure, but expect success"
1067 log "Write out of block quota ..."
1068 # this time maybe cache write, ignore it's failure
1069 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1070 # flush cache, ensure noquota flag is set on client
1071 cancel_lru_locks osc
1072 sync; sync_all_data || true
1074 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1075 quota_error u $TSTUSR \
1076 "user write success, but expect EDQUOT"
1079 wait_delete_completed || error "wait_delete_completed failed"
1080 sync_all_data || true
1082 used=$(getquota -u $TSTUSR global curspace $qpool)
1083 [ $used -ne 0 ] && quota_error u $TSTUSR \
1084 "user quota isn't released after deletion"
1087 run_test 1g "Quota pools: Block hard limit with wide striping"
1091 local testfile="$DIR/$tdir/$tfile-0"
1093 check_set_fallocate_or_skip
1095 setup_quota_test || error "setup quota failed with $?"
1098 set_ost_qtype $QTYPE || error "enable ost quota failed"
1101 log "User quota (block hardlimit:$limit MB)"
1102 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1103 error "set user quota failed"
1105 # make sure the system is clean
1106 local used=$(getquota -u $TSTUSR global curspace)
1107 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1109 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1110 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1112 check_write_fallocate $testfile "user" $limit
1115 wait_delete_completed || error "wait_delete_completed failed"
1116 sync_all_data || true
1117 used=$(getquota -u $TSTUSR global curspace)
1118 [ $used -eq 0 ] || quota_error u $TSTUSR \
1119 "user quota isn't released after deletion"
1121 run_test 1h "Block hard limit test using fallocate"
1124 local global_limit=200 # 200M
1125 local limit1=10 # 10M
1126 local TESTDIR="$DIR/$tdir/"
1127 local testfile="$TESTDIR/$tfile-0"
1128 local testfile1="$TESTDIR/$tfile-1"
1129 local testfile2="$TESTDIR/$tfile-2"
1130 local qpool1="qpool1"
1133 setup_quota_test || error "setup quota failed with $?"
1136 set_ost_qtype $QTYPE || error "enable ost quota failed"
1138 log "User quota (block hardlimit:$global_limit MB)"
1139 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1140 error "set user quota failed"
1142 pool_add $qpool1 || error "pool_add failed"
1143 pool_add_targets $qpool1 0 0 ||
1144 error "pool_add_targets failed"
1146 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1147 error "set user quota failed"
1149 # make sure the system is clean
1150 local used=$(getquota -u $TSTUSR global curspace)
1151 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1153 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1156 test_1_check_write $testfile "user" $limit1
1157 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1158 error "set user quota failed"
1160 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1161 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1162 quota_error u $TSTUSR "write failure, but expect success"
1166 wait_delete_completed || error "wait_delete_completed failed"
1167 sync_all_data || true
1169 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1170 error "set user quota failed"
1171 test_1_check_write $testfile "user" $limit1
1172 local tmp_limit=$(($limit1*2))
1173 # increase pool limit
1174 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1175 error "set user quota failed"
1176 # now write shouldn't fail
1177 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1178 quota_error u $TSTUSR "write failure, but expect success"
1179 # decrease pool limit
1180 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1181 error "set user quota failed"
1182 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1183 # flush cache, ensure noquota flag is set on client
1184 cancel_lru_locks osc
1185 sync; sync_all_data || true
1186 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1187 quota_error u $TSTUSR "write success, but expect failure"
1190 run_test 1i "Quota pools: different limit and usage relations"
1194 local testfile="$DIR/$tdir/$tfile-0"
1196 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1197 skip "need OST at least 2.15.52.206"
1199 is_project_quota_supported ||
1200 skip "skip project quota unsupported"
1202 setup_quota_test || error "setup quota failed with $?"
1205 set_ost_qtype $QTYPE || error "enable ost quota failed"
1208 log "--------------------------------------"
1209 log "Project quota (block hardlimit:$limit mb)"
1210 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1211 error "set project quota failed"
1213 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1214 change_project -p $TSTPRJID $testfile
1216 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1217 do_facet ost1 $LCTL set_param $procf=1 ||
1218 error "enable root quotas for project failed"
1219 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1221 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1222 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1223 quota_error "project" $TSTPRJID "root write to project success"
1225 do_facet ost1 $LCTL set_param $procf=0 ||
1226 error "disable root quotas for project failed"
1228 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1229 quota_error "project" $TSTPRJID "root write to project failed"
1234 used=$(getquota -p $TSTPRJID global curspace)
1235 (( $used == 0 )) || quota_error p $TSTPRJID \
1236 "project quota isn't released after deletion"
1238 run_test 1j "Enable project quota enforcement for root"
1240 # test inode hardlimit
1242 local testfile="$DIR/$tdir/$tfile-0"
1243 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1244 qmt.$FSNAME-QMT0000.md-0x0.info |
1245 sed -e 's/least qunit/least_qunit/' |
1246 awk '/least_qunit/{ print $2 }')
1249 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1250 limit=$((least_qunit * 1024))
1251 echo "least_qunit: '$least_qunit', limit: '$limit'"
1253 local free_inodes=$(mdt_free_inodes 0)
1254 echo "$free_inodes free inodes on master MDT"
1255 [ $free_inodes -lt $limit ] &&
1256 skip "not enough free inodes $free_inodes required $limit"
1258 setup_quota_test || error "setup quota failed with $?"
1261 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1264 log "User quota (inode hardlimit:$limit files)"
1265 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1266 error "set user quota failed"
1268 # make sure the system is clean
1269 local used=$(getquota -u $TSTUSR global curinodes)
1270 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1272 log "Create $((limit - least_qunit)) files ..."
1273 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1274 quota_error u $TSTUSR "user create failure, but expect success"
1275 # it is ok, if it fails on the last qunit
1276 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1277 log "Create out of file quota ..."
1278 $RUNAS touch ${testfile}_xxx &&
1279 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1282 unlinkmany ${testfile} $((limit - least_qunit)) ||
1283 error "unlinkmany $testfile failed"
1284 # if 2nd createmany got EDQUOT, not all of nodes would be created
1285 unlinkmany ${testfile}_yyy $least_qunit || true
1286 rm -f ${testfile}_xxx
1287 wait_delete_completed
1289 used=$(getquota -u $TSTUSR global curinodes)
1290 [ $used -ne 0 ] && quota_error u $TSTUSR \
1291 "user quota isn't released after deletion"
1292 resetquota -u $TSTUSR
1295 log "--------------------------------------"
1296 log "Group quota (inode hardlimit:$limit files)"
1297 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1298 error "set group quota failed"
1300 testfile=$DIR/$tdir/$tfile-1
1301 # make sure the system is clean
1302 used=$(getquota -g $TSTUSR global curinodes)
1303 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1305 log "Create $limit files ..."
1306 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1307 quota_error g $TSTUSR "group create failure, but expect success"
1308 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1309 log "Create out of file quota ..."
1310 $RUNAS touch ${testfile}_xxx &&
1311 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1314 unlinkmany ${testfile} $((limit - least_qunit)) ||
1315 error "unlinkmany $testfile failed"
1316 unlinkmany ${testfile}_yyy $least_qunit || true
1317 rm -f ${testfile}_xxx
1318 wait_delete_completed
1320 used=$(getquota -g $TSTUSR global curinodes)
1321 [ $used -ne 0 ] && quota_error g $TSTUSR \
1322 "user quota isn't released after deletion"
1324 resetquota -g $TSTUSR
1325 ! is_project_quota_supported &&
1326 echo "Skip project quota is not supported" && return 0
1329 log "--------------------------------------"
1330 log "Project quota (inode hardlimit:$limit files)"
1331 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1332 error "set project quota failed"
1334 testfile=$DIR/$tdir/$tfile-1
1335 # make sure the system is clean
1336 used=$(getquota -p $TSTPRJID global curinodes)
1338 error "Used inodes($used) for project $TSTPRJID isn't 0"
1340 change_project -sp $TSTPRJID $DIR/$tdir
1341 log "Create $limit files ..."
1342 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1343 quota_error p $TSTPRJID \
1344 "project create fail, but expect success"
1345 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1346 log "Create out of file quota ..."
1347 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1348 "project create success, but expect EDQUOT"
1349 change_project -C $DIR/$tdir
1352 used=$(getquota -p $TSTPRJID global curinodes)
1353 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1354 "project quota isn't released after deletion"
1357 run_test 2 "File hard limit (normal use and out of quota)"
1366 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1367 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1371 $LFS setstripe $testfile -c 1 -i 0
1372 chown $TSTUSR.$TSTUSR $testfile
1373 [ "$qtype" == "p" ] && is_project_quota_supported &&
1374 change_project -p $TSTPRJID $testfile
1376 echo "Write up to soft limit"
1377 $RUNAS $DD of=$testfile count=$limit ||
1378 quota_error a $TSTUSR "write failure, but expect success"
1379 OFFSET=$((limit * 1024))
1380 cancel_lru_locks osc
1382 echo "Write to exceed soft limit"
1383 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1384 quota_error a $TSTUSR "write failure, but expect success"
1385 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1386 cancel_lru_locks osc
1388 echo "mmap write when over soft limit"
1389 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1390 quota_error a $TSTUSR "mmap write failure, but expect success"
1391 cancel_lru_locks osc
1396 $SHOW_QUOTA_INFO_USER
1397 $SHOW_QUOTA_INFO_GROUP
1398 $SHOW_QUOTA_INFO_PROJID
1400 echo "Write before timer goes off"
1401 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1402 quota_error a $TSTUSR "write failure, but expect success"
1403 OFFSET=$((OFFSET + 1024))
1404 cancel_lru_locks osc
1406 wait_grace_time $qtype "block" $pool
1411 $SHOW_QUOTA_INFO_USER
1412 $SHOW_QUOTA_INFO_GROUP
1413 $SHOW_QUOTA_INFO_PROJID
1415 log "Write after timer goes off"
1416 # maybe cache write, ignore.
1417 # write up to soft least quint to consume all
1418 # possible slave granted space.
1419 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1420 count=$soft_limit seek=$OFFSET || true
1421 OFFSET=$((OFFSET + soft_limit))
1422 cancel_lru_locks osc
1423 log "Write after cancel lru locks"
1424 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1425 quota_error a $TSTUSR "write success, but expect EDQUOT"
1430 $SHOW_QUOTA_INFO_USER
1431 $SHOW_QUOTA_INFO_GROUP
1432 $SHOW_QUOTA_INFO_PROJID
1434 echo "Unlink file to stop timer"
1436 wait_delete_completed
1437 sync_all_data || true
1442 $SHOW_QUOTA_INFO_USER
1443 $SHOW_QUOTA_INFO_GROUP
1444 $SHOW_QUOTA_INFO_PROJID
1446 $LFS setstripe $testfile -c 1 -i 0
1447 chown $TSTUSR.$TSTUSR $testfile
1448 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1451 $RUNAS $DD of=$testfile count=$limit ||
1452 quota_error a $TSTUSR "write failure, but expect success"
1459 local grace=20 # seconds
1460 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1463 local testfile=$DIR/$tdir/$tfile-0
1465 # get minimum soft qunit size
1466 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1467 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1469 set_ost_qtype $QTYPE || error "enable ost quota failed"
1471 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1472 # make sure the system is clean
1473 local used=$(getquota -u $TSTUSR global curspace)
1474 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1476 $LFS setquota -t -u --block-grace $grace --inode-grace \
1477 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1478 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1479 error "set user quota failed"
1481 test_block_soft $testfile $grace $limit "u"
1483 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1484 testfile=$DIR/$tdir/$tfile-1
1485 # make sure the system is clean
1486 used=$(getquota -g $TSTUSR global curspace)
1487 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1489 $LFS setquota -t -g --block-grace $grace --inode-grace \
1490 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1491 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1492 error "set group quota failed"
1494 test_block_soft $testfile $grace $limit "g"
1496 if is_project_quota_supported; then
1497 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1498 testfile=$DIR/$tdir/$tfile-2
1499 # make sure the system is clean
1500 used=$(getquota -p $TSTPRJID global curspace)
1501 [ $used -ne 0 ] && error \
1502 "Used space($used) for project $TSTPRJID isn't 0."
1504 $LFS setquota -t -p --block-grace $grace --inode-grace \
1505 $MAX_IQ_TIME $DIR ||
1506 error "set project grace time failed"
1507 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1508 $DIR || error "set project quota failed"
1510 test_block_soft $testfile $grace $limit "p"
1511 resetquota -p $TSTPRJID
1512 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1513 $MAX_IQ_TIME $DIR ||
1514 error "restore project grace time failed"
1518 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1519 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1520 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1521 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1523 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1526 local grace=20 # seconds
1527 local qpool="qpool1"
1528 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1531 local testfile=$DIR/$tdir/$tfile-0
1534 # get minimum soft qunit size
1535 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1536 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1537 local glbl_limit=$((2*limit))
1538 local glbl_grace=$((2*grace))
1539 echo "limit $limit glbl_limit $glbl_limit"
1540 echo "grace $grace glbl_grace $glbl_grace"
1542 set_ost_qtype $QTYPE || error "enable ost quota failed"
1544 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1545 # make sure the system is clean
1546 local used=$(getquota -u $TSTUSR global curspace)
1547 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1549 pool_add $qpool || error "pool_add failed"
1550 pool_add_targets $qpool 0 1 ||
1551 error "pool_add_targets failed"
1553 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1554 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1555 $LFS setquota -t -u --block-grace $grace \
1556 --pool $qpool $DIR || error "set user grace time failed"
1558 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1559 error "set user quota failed"
1560 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1561 error "set user quota failed"
1563 test_block_soft $testfile $grace $limit "u" $qpool
1565 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1566 testfile=$DIR/$tdir/$tfile-1
1567 # make sure the system is clean
1568 used=$(getquota -g $TSTUSR global curspace)
1569 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1571 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1572 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1573 $LFS setquota -t -g --block-grace $grace \
1574 --pool $qpool $DIR || error "set group grace time failed"
1576 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1577 error "set group quota failed"
1578 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1579 error "set group quota failed"
1581 test_block_soft $testfile $grace $limit "g" $qpool
1583 if is_project_quota_supported; then
1584 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1585 testfile=$DIR/$tdir/$tfile-2
1586 # make sure the system is clean
1587 used=$(getquota -p $TSTPRJID global curspace)
1588 [ $used -ne 0 ] && error \
1589 "Used space($used) for project $TSTPRJID isn't 0."
1591 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1592 $MAX_IQ_TIME $DIR ||
1593 error "set project grace time failed"
1594 $LFS setquota -t -p --block-grace $grace \
1595 --pool $qpool $DIR ||
1596 error "set project grace time failed"
1598 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1599 $DIR || error "set project quota failed"
1600 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1601 --pool $qpool $DIR || error "set project quota failed"
1603 test_block_soft $testfile $grace $limit "p" $qpool
1604 resetquota -p $TSTPRJID
1605 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1606 $MAX_IQ_TIME $DIR ||
1607 error "restore project grace time failed"
1608 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1609 $DIR || error "set project grace time failed"
1613 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1614 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1615 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1616 --pool $qpool $DIR || error "restore user grace time failed"
1617 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1618 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1619 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1620 --pool $qpool $DIR || error "restore group grace time failed"
1622 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1625 local grace=20 # seconds
1626 local qpool="qpool1"
1627 local qpool2="qpool2"
1628 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1631 local testfile=$DIR/$tdir/$tfile-0
1634 # get minimum soft qunit size
1635 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1636 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1637 local limit2=$((limit+4))
1638 local glbl_limit=$((limit+8))
1639 local grace1=$((grace+10))
1641 local glbl_grace=$((grace+20))
1642 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1643 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1645 set_ost_qtype $QTYPE || error "enable ost quota failed"
1647 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 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 pool_add $qpool2 || error "pool_add failed"
1657 pool_add_targets $qpool2 0 1 ||
1658 error "pool_add_targets failed"
1661 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1662 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1663 $LFS setquota -t -u --block-grace $grace1 \
1664 --pool $qpool $DIR || error "set user grace time failed"
1665 $LFS setquota -t -u --block-grace $grace2 \
1666 --pool $qpool2 $DIR || error "set user grace time failed"
1668 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1669 error "set user quota failed"
1670 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1671 error "set user quota failed"
1672 # qpool has minimum soft limit, but its grace is greater than
1673 # the grace period of qpool2. Thus write shouldn't fail when
1674 # hit qpool soft limit - only when reaches up qpool2 limit
1675 # after grace2 seconds.
1676 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1677 error "set user quota failed"
1679 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1682 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1683 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1684 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1685 --pool $qpool $DIR || error "restore user grace time failed"
1686 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1687 --pool $qpool2 $DIR || error "restore user grace time failed"
1689 run_test 3c "Quota pools: check block soft limit on different pools"
1696 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1697 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1700 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1702 echo "Create files to exceed soft limit"
1703 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1704 quota_error a $TSTUSR "create failure, but expect success"
1705 local trigger_time=$(date +%s)
1707 sync_all_data || true
1709 local cur_time=$(date +%s)
1710 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1711 error "Passed grace time $grace, $trigger_time, $cur_time"
1713 echo "Create file before timer goes off"
1714 $RUNAS touch ${TESTFILE}_before ||
1715 quota_error a $TSTUSR "failed create before timer expired," \
1716 "but expect success. $trigger_time, $cur_time"
1717 sync_all_data || true
1719 wait_grace_time $qtype "file"
1724 $SHOW_QUOTA_INFO_USER
1725 $SHOW_QUOTA_INFO_GROUP
1726 $SHOW_QUOTA_INFO_PROJID
1728 echo "Create file after timer goes off"
1729 # exceed least soft limit is possible
1730 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1731 quota_error a $TSTUSR "create after timer expired," \
1733 sync_all_data || true
1738 $SHOW_QUOTA_INFO_USER
1739 $SHOW_QUOTA_INFO_GROUP
1740 $SHOW_QUOTA_INFO_PROJID
1742 echo "Unlink files to stop timer"
1743 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1744 wait_delete_completed
1747 $RUNAS touch ${TESTFILE}_xxx ||
1748 quota_error a $TSTUSR "touch after timer stop failure," \
1749 "but expect success"
1750 sync_all_data || true
1758 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1759 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1760 local TESTFILE=$DIR/$tdir/$tfile-0
1763 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1764 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1766 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1767 # make sure the system is clean
1768 local USED=$(getquota -u $TSTUSR global curinodes)
1769 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1771 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1772 $GRACE $DIR || error "set user grace time failed"
1773 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1774 error "set user quota failed"
1776 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1778 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1779 # make sure the system is clean
1780 USED=$(getquota -g $TSTUSR global curinodes)
1781 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1783 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1784 $GRACE $DIR || error "set group grace time failed"
1785 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1786 error "set group quota failed"
1787 TESTFILE=$DIR/$tdir/$tfile-1
1789 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1791 if is_project_quota_supported; then
1792 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1793 # make sure the system is clean
1794 USED=$(getquota -p $TSTPRJID global curinodes)
1795 [ $USED -ne 0 ] && error \
1796 "Used space($USED) for project $TSTPRJID isn't 0."
1798 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1799 $GRACE $DIR || error "set project grace time failed"
1800 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1801 error "set project quota failed"
1803 TESTFILE=$DIR/$tdir/$tfile-1
1804 # one less than limit, because of parent directory included.
1805 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1806 resetquota -p $TSTPRJID
1807 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1808 $MAX_IQ_TIME $DIR ||
1809 error "restore project grace time failed"
1813 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1814 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1815 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1816 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1818 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1821 local GR_STR1="1w3d"
1822 local GR_STR2="1000s"
1824 local GR_STR4="1w2d3h4m5s"
1826 local GR_STR6="18446744073709551615"
1829 wait_delete_completed
1831 # test of valid grace strings handling
1832 echo "Valid grace strings test"
1833 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1834 $GR_STR2 $DIR || error "set user grace time failed"
1835 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1836 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1837 $GR_STR4 $DIR || error "set group grace time quota failed"
1838 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1840 # test of invalid grace strings handling
1841 echo " Invalid grace strings test"
1842 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1843 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1844 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1848 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1849 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1850 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1851 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1853 run_test 4b "Grace time strings handling"
1855 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1857 local BLIMIT=10 # MB
1858 local ILIMIT=10 # inodes
1860 setup_quota_test || error "setup quota failed with $?"
1862 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1863 set_ost_qtype $QTYPE || error "enable ost quota failed"
1865 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1866 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1867 error "set user quota failed"
1868 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1869 if is_project_quota_supported; then
1870 error "set group quota failed"
1871 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1872 -I $ILIMIT $DIR || error "set project quota failed"
1875 # make sure the system is clean
1876 local USED=$(getquota -u $TSTUSR global curinodes)
1877 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1878 USED=$(getquota -g $TSTUSR global curinodes)
1879 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1880 USED=$(getquota -u $TSTUSR global curspace)
1881 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1882 USED=$(getquota -g $TSTUSR global curspace)
1883 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1884 if is_project_quota_supported; then
1885 USED=$(getquota -p $TSTPRJID global curinodes)
1887 error "Used inode($USED) for project $TSTPRJID isn't 0."
1888 USED=$(getquota -p $TSTPRJID global curspace)
1890 error "Used block($USED) for project $TSTPRJID isn't 0."
1893 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1894 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1895 error "create failure, expect success"
1896 if is_project_quota_supported; then
1897 touch $DIR/$tdir/$tfile-0_1
1898 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1900 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1901 error "write failure, expect success"
1903 echo "Chown files to $TSTUSR.$TSTUSR ..."
1904 for i in $(seq 0 $ILIMIT); do
1905 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1906 quota_error a $TSTUSR "chown failure, expect success"
1910 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1911 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1913 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1915 # test dropping acquire request on master
1919 # Clear dmesg so watchdog is not triggered by previous
1921 do_facet ost1 dmesg -c > /dev/null
1923 setup_quota_test || error "setup quota failed with $?"
1925 # make sure the system is clean
1926 local USED=$(getquota -u $TSTUSR global curspace)
1927 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1929 # make sure no granted quota on ost
1930 set_ost_qtype $QTYPE || error "enable ost quota failed"
1931 resetquota -u $TSTUSR
1933 # create file for $TSTUSR
1934 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1935 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1936 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1938 # create file for $TSTUSR2
1939 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1940 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1941 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1943 # cache per-ID lock for $TSTUSR on slave
1944 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1945 error "set quota failed"
1946 $RUNAS $DD of=$TESTFILE count=1 ||
1947 error "write $TESTFILE failure, expect success"
1948 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1949 error "write $TESTFILE2 failure, expect success"
1951 if at_is_enabled; then
1952 at_max_saved=$(at_max_get ost1)
1953 at_max_set $TIMEOUT ost1
1955 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1956 # DQACQ is sent, which makes at_max to take effect
1957 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1960 wait_delete_completed
1964 sync_all_data || true
1966 #define QUOTA_DQACQ 601
1967 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1968 lustre_fail mds 0x513 601
1970 do_facet ost1 $LCTL set_param \
1971 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1973 # write to un-enforced ID ($TSTUSR2) should succeed
1974 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1975 error "write failure, expect success"
1977 # write to enforced ID ($TSTUSR) in background, exceeding limit
1978 # to make sure DQACQ is sent
1979 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1982 # watchdog timer uses a factor of 2
1983 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1984 sleep $((TIMEOUT * 2 + 1))
1986 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1988 # write should be blocked and never finished
1989 if ! ps -p $DDPID > /dev/null 2>&1; then
1991 error "write finished incorrectly!"
1996 # no watchdog is triggered
1997 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1998 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1999 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2000 [ -z "$watchdog" ] || error "$watchdog"
2002 rm -f $TMP/lustre-log-${TESTNAME}.log
2004 # write should continue then fail with EDQUOT
2008 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2009 if [ $count -ge 240 ]; then
2010 quota_error u $TSTUSR "dd not finished in $count secs"
2012 count=$((count + 1))
2013 if [ $((count % 30)) -eq 0 ]; then
2014 c_size=$(stat -c %s $TESTFILE)
2015 echo "Waiting $count secs. $c_size"
2021 run_test 6 "Test dropping acquire request on master"
2023 # quota reintegration (global index)
2025 local TESTFILE=$DIR/$tdir/$tfile
2028 [ "$SLOW" = "no" ] && LIMIT=5
2030 setup_quota_test || error "setup quota failed with $?"
2032 # make sure the system is clean
2033 local USED=$(getquota -u $TSTUSR global curspace)
2034 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2036 # make sure no granted quota on ost1
2037 set_ost_qtype $QTYPE || error "enable ost quota failed"
2038 resetquota -u $TSTUSR
2039 set_ost_qtype "none" || error "disable ost quota failed"
2041 local OSTUUID=$(ostuuid_from_index 0)
2042 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2044 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2047 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2048 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2053 echo "Enable quota & set quota limit for $TSTUSR"
2054 set_ost_qtype $QTYPE || error "enable ost quota failed"
2055 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2056 error "set quota failed"
2058 echo "Start ost1..."
2059 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2062 wait_ost_reint $QTYPE || error "reintegration failed"
2064 # hardlimit should have been fetched by slave during global
2065 # reintegration, write will exceed quota
2066 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2067 quota_error u $TSTUSR "write success, but expect EDQUOT"
2070 wait_delete_completed
2071 sync_all_data || true
2077 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2078 error "clear quota failed"
2080 echo "Start ost1..."
2081 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2084 wait_ost_reint $QTYPE || error "reintegration failed"
2086 # hardlimit should be cleared on slave during reintegration
2087 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2088 quota_error u $TSTUSR "write error, but expect success"
2090 run_test 7a "Quota reintegration (global index)"
2092 # quota reintegration (slave index)
2094 local limit=100000 # MB
2095 local TESTFILE=$DIR/$tdir/$tfile
2097 setup_quota_test || error "setup quota failed with $?"
2099 # make sure the system is clean
2100 local USED=$(getquota -u $TSTUSR global curspace)
2101 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2103 # make sure no granted quota on ost1
2104 set_ost_qtype $QTYPE || error "enable ost quota failed"
2105 resetquota -u $TSTUSR
2106 set_ost_qtype "none" || error "disable ost quota failed"
2108 local OSTUUID=$(ostuuid_from_index 0)
2109 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2111 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2114 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2115 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2117 # consume some space to make sure the granted space will not
2118 # be released during reconciliation
2119 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2120 error "consume space failure, expect success"
2122 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2123 lustre_fail mds 0xa02
2125 set_ost_qtype $QTYPE || error "enable ost quota failed"
2126 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2127 error "set quota failed"
2129 # ignore the write error
2130 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2132 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2136 echo "Restart ost to trigger reintegration..."
2138 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2141 wait_ost_reint $QTYPE || error "reintegration failed"
2143 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2144 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2149 run_test 7b "Quota reintegration (slave index)"
2151 # quota reintegration (restart mds during reintegration)
2154 local TESTFILE=$DIR/$tdir/$tfile
2156 [ "$SLOW" = "no" ] && LIMIT=5
2158 setup_quota_test || error "setup quota failed with $?"
2160 # make sure the system is clean
2161 local USED=$(getquota -u $TSTUSR global curspace)
2162 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2164 set_ost_qtype "none" || error "disable ost quota failed"
2165 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2166 error "set quota failed"
2168 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2169 lustre_fail ost 0xa03
2172 set_ost_qtype $QTYPE || error "enable ost quota failed"
2173 # trigger reintegration
2174 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2175 procf=${procf}quota_slave.force_reint
2176 do_facet ost1 $LCTL set_param $procf=1 ||
2177 error "force reintegration failed"
2185 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2188 # wait longer than usual to make sure the reintegration
2189 # is triggered by quota wb thread.
2190 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2192 # hardlimit should have been fetched by slave during global
2193 # reintegration, write will exceed quota
2194 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2195 quota_error u $TSTUSR "write success, but expect EDQUOT"
2198 run_test 7c "Quota reintegration (restart mds during reintegration)"
2200 # Quota reintegration (Transfer index in multiple bulks)
2202 local TESTFILE=$DIR/$tdir/$tfile
2203 local TESTFILE1="$DIR/$tdir/$tfile"-1
2206 setup_quota_test || error "setup quota failed with $?"
2208 set_ost_qtype "none" || error "disable ost quota failed"
2209 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2210 error "set quota for $TSTUSR failed"
2211 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2212 error "set quota for $TSTUSR2 failed"
2214 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2215 lustre_fail mds 0x608 0
2217 # enable quota to tirgger reintegration
2218 set_ost_qtype "u" || error "enable ost quota failed"
2219 wait_ost_reint "u" || error "reintegration failed"
2223 # hardlimit should have been fetched by slave during global
2224 # reintegration, write will exceed quota
2225 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2226 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2228 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2229 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2232 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2234 # quota reintegration (inode limits)
2236 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2238 # LU-2435: skip this quota test if underlying zfs version has not
2239 # supported native dnode accounting
2240 [ "$mds1_FSTYPE" == zfs ] && {
2241 local F="feature@userobj_accounting"
2242 local pool=$(zpool_name mds1)
2243 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2245 [[ "$feature" != *" active "* ]] &&
2246 skip "requires zpool with active userobj_accounting"
2249 local ilimit=$((1024 * 2)) # inodes
2250 local TESTFILE=$DIR/${tdir}-1/$tfile
2252 setup_quota_test || error "setup quota failed with $?"
2254 # make sure the system is clean
2255 local USED=$(getquota -u $TSTUSR global curinodes)
2256 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2258 # make sure no granted quota on mdt1
2259 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2260 resetquota -u $TSTUSR
2261 set_mdt_qtype "none" || error "disable mdt quota failed"
2263 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2264 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2265 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2268 echo "Stop mds${MDSCOUNT}..."
2271 echo "Enable quota & set quota limit for $TSTUSR"
2272 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2273 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2274 error "set quota failed"
2276 echo "Start mds${MDSCOUNT}..."
2277 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2280 wait_mdt_reint $QTYPE || error "reintegration failed"
2282 echo "create remote dir"
2283 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2284 error "create remote dir failed"
2285 chmod 0777 $DIR/${tdir}-1
2287 # hardlimit should have been fetched by slave during global
2288 # reintegration, create will exceed quota
2289 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2290 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2292 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2293 wait_delete_completed
2294 sync_all_data || true
2296 echo "Stop mds${MDSCOUNT}..."
2299 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2300 error "clear quota failed"
2302 echo "Start mds${MDSCOUNT}..."
2303 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2306 wait_mdt_reint $QTYPE || error "reintegration failed"
2308 # hardlimit should be cleared on slave during reintegration
2309 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2310 quota_error u $TSTUSR "create failed, expect success"
2312 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2313 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2315 run_test 7e "Quota reintegration (inode limits)"
2317 # run dbench with quota enabled
2319 local BLK_LIMIT="100g" #100G
2320 local FILE_LIMIT=1000000
2322 setup_quota_test || error "setup quota failed with $?"
2324 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2325 set_ost_qtype $QTYPE || error "enable ost quota failed"
2327 echo "Set enough high limit for user: $TSTUSR"
2328 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2329 error "set user quota failed"
2330 echo "Set enough high limit for group: $TSTUSR"
2331 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2332 error "set group quota failed"
2333 if is_project_quota_supported; then
2334 change_project -sp $TSTPRJID $DIR/$tdir
2335 echo "Set enough high limit for project: $TSTPRJID"
2336 $LFS setquota -p $TSTPRJID -b 0 \
2337 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2338 error "set project quota failed"
2342 [ "$SLOW" = "no" ] && duration=" -t 120"
2343 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2344 quota_error a $TSTUSR "dbench failed!"
2346 is_project_quota_supported && change_project -C $DIR/$tdir
2349 run_test 8 "Run dbench with quota enabled"
2351 # this check is just for test_9
2352 OST0_MIN=4900000 #4.67G
2354 check_whether_skip () {
2355 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2356 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2357 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2358 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2365 # run for fixing bug10707, it needs a big room. test for 64bit
2367 local filesize=$((1024 * 9 / 2)) # 4.5G
2369 check_whether_skip && return 0
2371 setup_quota_test || error "setup quota failed with $?"
2373 set_ost_qtype "ug" || error "enable ost quota failed"
2375 local TESTFILE="$DIR/$tdir/$tfile-0"
2376 local BLK_LIMIT=100G #100G
2377 local FILE_LIMIT=1000000
2379 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2381 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2383 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2384 error "set user quota failed"
2386 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2387 "for group: $TSTUSR"
2388 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2389 error "set group quota failed"
2391 quota_show_check a u $TSTUSR
2392 quota_show_check a g $TSTUSR
2394 echo "Create test file"
2395 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2396 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2398 log "Write the big file of 4.5G ..."
2399 $RUNAS $DD of=$TESTFILE count=$filesize ||
2400 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2410 run_test 9 "Block limit larger than 4GB (b10707)"
2413 local TESTFILE=$DIR/$tdir/$tfile
2415 setup_quota_test || error "setup quota failed with $?"
2417 # set limit to root user should fail
2418 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2419 error "set limit for root user successfully, expect failure"
2420 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2421 error "set limit for root group successfully, expect failure"
2422 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2423 error "set limit for project 0 successfully, expect failure"
2425 # root user can overrun quota
2426 set_ost_qtype "ug" || error "enable ost quota failed"
2428 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2429 error "set quota failed"
2430 quota_show_check b u $TSTUSR
2432 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2433 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2435 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2436 error "write failure, expect success"
2438 run_test 10 "Test quota for root user"
2441 local TESTFILE=$DIR/$tdir/$tfile
2442 setup_quota_test || error "setup quota failed with $?"
2444 set_mdt_qtype "ug" || error "enable mdt quota failed"
2445 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2446 error "set quota failed"
2448 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2449 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2451 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2452 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2455 local USED=$(getquota -u $TSTUSR global curinodes)
2456 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2458 run_test 11 "Chown/chgrp ignores quota"
2461 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2463 local blimit=22 # MB
2464 local blk_cnt=$((blimit - 5))
2465 local TESTFILE0="$DIR/$tdir/$tfile"-0
2466 local TESTFILE1="$DIR/$tdir/$tfile"-1
2468 setup_quota_test || error "setup quota failed with $?"
2470 set_ost_qtype "u" || error "enable ost quota failed"
2471 quota_show_check b u $TSTUSR
2473 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2474 error "set quota failed"
2476 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2477 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2478 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2479 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2481 echo "Write to ost0..."
2482 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2483 quota_error a $TSTUSR "dd failed"
2485 echo "Write to ost1..."
2486 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2487 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2489 echo "Free space from ost0..."
2491 wait_delete_completed
2492 sync_all_data || true
2494 echo "Write to ost1 after space freed from ost0..."
2495 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2496 quota_error a $TSTUSR "rebalancing failed"
2498 run_test 12a "Block quota rebalancing"
2501 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2503 local ilimit=$((1024 * 2)) # inodes
2504 local TESTFILE0=$DIR/$tdir/$tfile
2505 local TESTFILE1=$DIR/${tdir}-1/$tfile
2507 setup_quota_test || error "setup quota failed with $?"
2509 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2510 chmod 0777 $DIR/${tdir}-1
2512 set_mdt_qtype "u" || error "enable mdt quota failed"
2513 quota_show_check f u $TSTUSR
2515 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2516 error "set quota failed"
2518 echo "Create $ilimit files on mdt0..."
2519 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2520 quota_error u $TSTUSR "create failed, but expect success"
2522 echo "Create files on mdt1..."
2523 $RUNAS createmany -m $TESTFILE1 1 &&
2524 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2526 echo "Free space from mdt0..."
2527 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2528 wait_delete_completed
2529 sync_all_data || true
2531 echo "Create files on mdt1 after space freed from mdt0..."
2532 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2533 quota_error a $TSTUSR "rebalancing failed"
2535 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2536 error "unlink mdt1 files failed"
2537 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2539 run_test 12b "Inode quota rebalancing"
2542 local TESTFILE=$DIR/$tdir/$tfile
2543 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2544 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2546 setup_quota_test || error "setup quota failed with $?"
2548 set_ost_qtype "u" || error "enable ost quota failed"
2549 quota_show_check b u $TSTUSR
2551 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2552 error "set quota failed"
2553 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2554 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2556 # clear the locks in cache first
2557 do_facet ost1 $LCTL set_param -n $procf=clear
2558 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2559 [ $nlock -eq 0 ] || error "$nlock cached locks"
2561 # write to acquire the per-ID lock
2562 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2563 quota_error a $TSTUSR "dd failed"
2565 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2566 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2568 # clear quota doesn't trigger per-ID lock cancellation
2569 resetquota -u $TSTUSR
2570 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2571 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2573 # clear the per-ID lock
2574 do_facet ost1 $LCTL set_param -n $procf=clear
2575 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2576 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2578 # spare quota should be released
2579 local OSTUUID=$(ostuuid_from_index 0)
2580 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2581 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2582 [ $limit -le $space ] ||
2583 error "spare quota isn't released, limit:$limit, space:$space"
2585 run_test 13 "Cancel per-ID lock in the LRU list"
2588 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2590 wait_delete_completed
2591 sync_all_data || true
2594 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2595 error "set user quota failed"
2596 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2597 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2598 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2599 resetquota -u $TSTUSR
2602 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2603 error "set group quota failed"
2604 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2605 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2606 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2607 resetquota -g $TSTUSR
2609 run_test 15 "Set over 4T block quota"
2613 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2614 skip "Not supported Lustre client before 2.14.55"
2616 setup_quota_test || error "setup quota failed with $?"
2618 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2619 error "failed to set quota for user $TSTUSR"
2620 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2621 error "failed to set quota for group $TSTUSR"
2623 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=50 ||
2624 quota_error u $TSTUSR "write failure"
2626 $LFS quota -u $TSTUSR $MOUNT ||
2627 quota_error u $TSTUSR "failed to get quota"
2629 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2631 $LCTL --device %$OSC deactivate
2632 stack_trap "$LCTL --device %$OSC activate"
2634 $LFS quota -v -u $TSTUSR $MOUNT ||
2635 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2636 $LFS quota -v -g $TSTUSR $MOUNT ||
2637 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2639 (( $MDSCOUNT > 1 )) || return 0
2641 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2643 $LCTL --device %$MDC deactivate
2644 stack_trap "$LCTL --device %$MDC activate"
2646 $LFS quota -v -u $TSTUSR $MOUNT ||
2647 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2648 $LFS quota -v -g $TSTUSR $MOUNT ||
2649 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2651 run_test 16a "lfs quota should skip the inactive MDT/OST"
2662 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2663 skip "Not supported Lustre client before 2.14.55"
2665 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2668 if ! combined_mgs_mds ; then
2673 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2674 $(mdsdevname 1) $(mdsvdevname 1)
2675 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2676 $(mdsdevname 2) $(mdsvdevname 2)
2677 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2678 $(mdsdevname 3) $(mdsvdevname 3)
2680 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2681 $(ostdevname 1) $(ostvdevname 1)
2682 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2683 $(ostdevname 2) $(ostvdevname 2)
2685 stack_trap cleanup_16b
2687 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2688 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2689 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2690 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2691 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2693 mount_client $MOUNT || error "Unable to mount client"
2695 setup_quota_test || error "setup quota failed with $?"
2697 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2698 error "failed to set quota for user $TSTUSR"
2699 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2700 error "failed to set quota for group $TSTUSR"
2702 $RUNAS $DD of=$DIR/$tdir/$tfile bs=1M count=10 ||
2703 quota_error u $TSTUSR "write failure"
2705 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2706 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2707 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2708 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2710 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2714 local BLKS=1 # 1M less than limit
2715 local TESTFILE=$DIR/$tdir/$tfile
2717 setup_quota_test || error "setup quota failed with $?"
2719 # make sure the system is clean
2720 local USED=$(getquota -u $TSTUSR global curspace)
2721 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2723 set_ost_qtype "ug" || error "enable ost quota failed"
2724 # make sure no granted quota on ost
2725 resetquota -u $TSTUSR
2726 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2727 error "set quota failed"
2729 quota_show_check b u $TSTUSR
2731 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2732 lustre_fail mds 0xa04 $err_code
2734 # write in background
2735 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2739 # write should be blocked and never finished
2740 if ! ps -p $DDPID > /dev/null 2>&1; then
2742 quota_error u $TSTUSR "write finished incorrectly!"
2750 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2752 if [ $count -gt $timeout ]; then
2753 quota_error u $TSTUSR "dd is not finished!"
2758 sync; sync_all_data || true
2760 USED=$(getquota -u $TSTUSR global curspace)
2761 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2762 "Used space(${USED}K) is less than ${BLKS}M"
2767 # DQACQ return recoverable error
2769 echo "DQACQ return -ENOLCK"
2771 test_17sub 37 || error "Handle -ENOLCK failed"
2773 echo "DQACQ return -EAGAIN"
2775 test_17sub 11 || error "Handle -EAGAIN failed"
2777 echo "DQACQ return -ETIMEDOUT"
2778 #define ETIMEDOUT 110
2779 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2781 echo "DQACQ return -ENOTCONN"
2782 #define ENOTCONN 107
2783 test_17sub 107 || error "Handle -ENOTCONN failed"
2786 run_test 17 "DQACQ return recoverable error"
2790 local blimit=200 # MB
2791 local TESTFILE="$DIR/$tdir/$tfile"
2793 setup_quota_test || error "setup quota failed with $?"
2795 set_ost_qtype "u" || error "enable ost quota failed"
2796 log "User quota (limit: $blimit)"
2797 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2798 error "set quota failed"
2799 quota_show_check b u $TSTUSR
2801 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2802 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2804 local timeout=$(sysctl -n lustre.timeout)
2806 if [ $io_type = "directio" ]; then
2807 log "Write 100M (directio) ..."
2808 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2810 log "Write 100M (buffered) ..."
2811 $RUNAS $DD of=$TESTFILE count=100 &
2815 replay_barrier $SINGLEMDS
2816 log "Fail mds for $((2 * timeout)) seconds"
2817 fail $SINGLEMDS $((2 * timeout))
2820 if at_is_enabled; then
2821 timeout=$(at_max_get mds)
2823 timeout=$(lctl get_param -n timeout)
2827 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2828 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2829 log "it took $count second"
2834 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2836 cancel_lru_locks mdc
2837 cancel_lru_locks osc
2840 local testfile_size=$(stat -c %s $TESTFILE)
2841 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2842 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2843 "got ${testfile_size}. Verifying file failed!"
2848 # test when mds does failover, the ost still could work well
2849 # this test shouldn't trigger watchdog b=14840
2851 # Clear dmesg so watchdog is not triggered by previous
2853 do_facet ost1 dmesg -c > /dev/null
2856 test_18_sub directio
2858 # check if watchdog is triggered
2859 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2860 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2861 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2862 [ -z "$watchdog" ] || error "$watchdog"
2863 rm -f $TMP/lustre-log-${TESTNAME}.log
2865 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2869 local TESTFILE=$DIR/$tdir/$tfile
2871 setup_quota_test || error "setup quota failed with $?"
2873 set_ost_qtype $QTYPE || error "enable ost quota failed"
2875 # bind file to a single OST
2876 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2877 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2879 echo "Set user quota (limit: ${blimit}M)"
2880 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2881 error "set user quota failed"
2882 quota_show_check b u $TSTUSR
2883 echo "Update quota limits"
2884 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2885 error "set group quota failed"
2886 quota_show_check b u $TSTUSR
2888 # first wirte might be cached
2889 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2890 cancel_lru_locks osc
2892 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2893 quota_error u $TSTUSR "Write success, expect failure"
2896 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2898 test_20() { # b15754
2899 local LSTR=(2g 1t 4k 3m) # limits strings
2901 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2904 resetquota -u $TSTUSR
2906 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2907 $MOUNT || error "could not set quota limits"
2908 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2909 --inode-softlimit ${LSTR[2]} \
2910 --inode-hardlimit ${LSTR[3]} \
2911 $MOUNT || error "could not set quota limits"
2913 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2914 error "bsoftlimit was not set properly"
2915 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2916 error "bhardlimit was not set properly"
2917 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2918 error "isoftlimit was not set properly"
2919 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2920 error "ihardlimit was not set properly"
2922 resetquota -u $TSTUSR
2924 run_test 20 "Test if setquota specifiers work properly (b15754)"
2931 local time=$(($(date +%s) + seconds))
2932 while [ $(date +%s) -lt $time ]; do
2933 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2937 # run for fixing bug16053, setquota shouldn't fail when writing and
2938 # deleting are happening
2940 local TESTFILE="$DIR/$tdir/$tfile"
2941 local BLIMIT=10 # 10G
2942 local ILIMIT=1000000
2944 setup_quota_test || error "setup quota failed with $?"
2946 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2948 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2949 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2950 error "set user quota failed"
2951 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2952 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2953 error "set group quota failed"
2954 if is_project_quota_supported; then
2955 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2956 "project: $TSTPRJID"
2957 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2958 $MOUNT || error "set project quota failed"
2961 # repeat writing on a 1M file
2962 test_21_sub ${TESTFILE}_1 1 30 &
2964 # repeat writing on a 128M file
2965 test_21_sub ${TESTFILE}_2 128 30 &
2968 local time=$(($(date +%s) + 30))
2970 while [ $(date +%s) -lt $time ]; do
2971 log "Set quota for $i times"
2972 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2973 -I $((ILIMIT + i)) $MOUNT ||
2974 error "Set user quota failed"
2975 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2976 -I $((ILIMIT + i)) $MOUNT ||
2977 error "Set group quota failed"
2978 if is_project_quota_supported; then
2979 $LFS setquota -p $TSTPRJID -b 0 -B \
2980 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2981 error "Set project quota failed"
2989 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2991 if [ $count -gt 60 ]; then
2992 quota_error a $TSTUSR "dd should be finished!"
2996 echo "(dd_pid=$DDPID1, time=$count)successful"
3000 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
3002 if [ $count -gt 60 ]; then
3003 quota_error a $TSTUSR "dd should be finished!"
3007 echo "(dd_pid=$DDPID2, time=$count)successful"
3009 run_test 21 "Setquota while writing & deleting (b16053)"
3011 # enable/disable quota enforcement permanently
3013 echo "Set both mdt & ost quota type as ug"
3015 is_project_quota_supported && qtype=$QTYPE
3016 set_mdt_qtype $qtype || error "enable mdt quota failed"
3017 set_ost_qtype $qtype || error "enable ost quota failed"
3020 stopall || error "failed to stopall (1)"
3024 echo "Verify if quota is enabled"
3025 local qtype1=$(mdt_quota_type)
3026 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3027 qtype=$(ost_quota_type)
3028 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3030 echo "Set both mdt & ost quota type as none"
3031 set_mdt_qtype "none" || error "disable mdt quota failed"
3032 set_ost_qtype "none" || error "disable ost quota failed"
3035 stopall || error "failed to stopall (2)"
3040 echo "Verify if quota is disabled"
3041 qtype=$(mdt_quota_type)
3042 [ $qtype != "none" ] && error "mdt quota setting is lost"
3043 qtype=$(ost_quota_type)
3044 [ $qtype != "none" ] && error "ost quota setting is lost"
3048 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3051 local TESTFILE="$DIR/$tdir/$tfile"
3054 setup_quota_test || error "setup quota failed with $?"
3056 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3059 log "User quota (limit: $LIMIT MB)"
3060 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3061 error "set quota failed"
3062 quota_show_check b u $TSTUSR
3064 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3065 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3067 log "Step1: trigger EDQUOT with O_DIRECT"
3068 log "Write half of file"
3069 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3070 quota_error u $TSTUSR "(1) Write failure, expect success." \
3072 log "Write out of block quota ..."
3073 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3074 oflag=direct conv=notrunc &&
3075 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3079 log "Step2: rewrite should succeed"
3080 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3081 quota_error u $TSTUSR "(3) Write failure, expect success." \
3087 local OST0_UUID=$(ostuuid_from_index 0)
3088 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3089 [ $OST0_QUOTA_USED -ne 0 ] &&
3090 ($SHOW_QUOTA_USER; \
3091 quota_error u $TSTUSR "quota isn't released")
3096 [ "$ost1_FSTYPE" == zfs ] &&
3097 skip "Overwrite in place is not guaranteed to be " \
3098 "space neutral on ZFS"
3100 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3101 check_whether_skip && return 0
3102 log "run for 4MB test file"
3105 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3106 check_whether_skip && return 0
3107 log "run for 40MB test file"
3110 run_test 23 "Quota should be honored with directIO (b16125)"
3114 local TESTFILE="$DIR/$tdir/$tfile"
3116 setup_quota_test || error "setup quota failed with $?"
3118 set_ost_qtype $QTYPE || error "enable ost quota failed"
3120 # bind file to a single OST
3121 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3122 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3124 echo "Set user quota (limit: ${blimit}M)"
3125 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3126 error "set quota failed"
3128 # overrun quota by root user
3129 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3130 error "write failure, expect success"
3131 cancel_lru_locks osc
3132 sync_all_data || true
3134 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3136 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3138 test_27a() { # b19612
3139 $LFS quota $TSTUSR $DIR &&
3140 error "lfs succeeded with no type, but should have failed"
3141 $LFS setquota $TSTUSR $DIR &&
3142 error "lfs succeeded with no type, but should have failed"
3145 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3147 test_27b() { # b20200
3148 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3149 error "lfs setquota failed with uid argument"
3150 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3151 error "lfs stequota failed with gid argument"
3152 if is_project_quota_supported; then
3153 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3154 1000 $DIR || error \
3155 "lfs stequota failed with projid argument"
3157 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3158 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3159 if is_project_quota_supported; then
3160 $SHOW_QUOTA_PROJID ||
3161 error "lfs quota failed with projid argument"
3162 resetquota_one -p $TSTPRJID
3164 resetquota -u $TSTID
3165 resetquota -g $TSTID
3168 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3173 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3174 error "lfs setquota failed"
3176 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3177 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3178 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3179 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3181 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3182 error "lfs setquota for $TSTID failed"
3184 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3185 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3186 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3187 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3189 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3190 error "total allocated inode/block limit not printed"
3192 resetquota -u $TSTUSR
3194 run_test 27c "lfs quota should support human-readable output"
3201 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3202 error "set fraction block limit failed"
3203 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3204 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3205 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3206 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3208 resetquota -u $TSTUSR
3210 run_test 27d "lfs setquota should support fraction block limit"
3214 local TESTFILE="$DIR/$tdir/$tfile"
3217 setup_quota_test || error "setup quota failed with $?"
3219 set_ost_qtype "u" || error "enable ost quota failed"
3221 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3222 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3224 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3225 $MAX_IQ_TIME $DIR || error "set grace time failed"
3226 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3227 error "set quota failed"
3228 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3229 cancel_lru_locks osc
3231 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3232 # over-quota flag has not yet settled since we do not trigger async
3233 # events based on grace time period expiration
3235 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3236 cancel_lru_locks osc
3237 # now over-quota flag should be settled and further writes should fail
3239 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3240 error "grace times were reset"
3241 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3242 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3244 run_test 30 "Hard limit updates should not reset grace times"
3246 # basic usage tracking for user & group
3248 local INODES=10 # files
3249 local BLK_CNT=2 # MB each
3250 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3252 setup_quota_test || error "setup quota failed with $?"
3254 # make sure the system is clean
3255 local USED=$(getquota -u $TSTID global curspace)
3257 error "Used space ($USED) for user $TSTID isn't 0."
3258 USED=$(getquota -g $TSTID global curspace)
3260 error "Used space ($USED) for group $TSTID isn't 0."
3261 if is_project_quota_supported; then
3262 USED=$(getquota -p $TSTPRJID global curspace)
3263 [ $USED -ne 0 ] && error \
3264 "Used space ($USED) for project $TSTPRJID isn't 0."
3267 echo "Write files..."
3268 for i in $(seq 0 $INODES); do
3269 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3270 error "write failed"
3271 is_project_quota_supported &&
3272 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3273 echo "Iteration $i/$INODES completed"
3275 cancel_lru_locks osc
3277 echo "Wait for setattr on objects finished..."
3278 wait_delete_completed
3280 sync; sync_all_data || true
3282 echo "Verify disk usage after write"
3283 USED=$(getquota -u $TSTID global curspace)
3284 [ $USED -lt $TOTAL_BLKS ] &&
3285 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3286 USED=$(getquota -g $TSTID global curspace)
3287 [ $USED -lt $TOTAL_BLKS ] &&
3288 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3289 if is_project_quota_supported; then
3290 USED=$(getquota -p $TSTPRJID global curspace)
3291 [ $USED -lt $TOTAL_BLKS ] && error \
3292 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3295 echo "Verify inode usage after write"
3296 USED=$(getquota -u $TSTID global curinodes)
3297 [ $USED -lt $INODES ] &&
3298 error "Used inode for user $TSTID is $USED, expected $INODES"
3299 USED=$(getquota -g $TSTID global curinodes)
3300 [ $USED -lt $INODES ] &&
3301 error "Used inode for group $TSTID is $USED, expected $INODES"
3302 if is_project_quota_supported; then
3303 USED=$(getquota -p $TSTPRJID global curinodes)
3304 [ $USED -lt $INODES ] && error \
3305 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3310 echo "Verify disk usage after delete"
3311 USED=$(getquota -u $TSTID global curspace)
3312 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3313 USED=$(getquota -u $TSTID global curinodes)
3314 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3315 USED=$(getquota -g $TSTID global curspace)
3316 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3317 USED=$(getquota -g $TSTID global curinodes)
3318 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3319 if is_project_quota_supported; then
3320 USED=$(getquota -p $TSTPRJID global curspace)
3322 error "Used space for project $TSTPRJID isn't 0. $USED"
3323 USED=$(getquota -p $TSTPRJID global curinodes)
3325 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3328 run_test 33 "Basic usage tracking for user & group & project"
3330 # usage transfer test for user & group & project
3332 local BLK_CNT=2 # MB
3333 local project_supported="no"
3335 is_project_quota_supported && project_supported="yes"
3336 setup_quota_test || error "setup quota failed with $?"
3338 # make sure the system is clean
3339 local USED=$(getquota -u $TSTID global curspace)
3340 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3341 USED=$(getquota -g $TSTID global curspace)
3342 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3344 local USED=$(getquota -u $TSTID2 global curspace)
3345 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3346 if [ $project_supported == "yes" ]; then
3347 USED=$(getquota -p $TSTPRJID global curspace)
3348 [ $USED -ne 0 ] && error \
3349 "Used space ($USED) for Project $TSTPRJID isn't 0."
3352 echo "Write file..."
3353 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3354 error "write failed"
3355 cancel_lru_locks osc
3356 sync; sync_all_data || true
3358 echo "chown the file to user $TSTID"
3359 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3361 echo "Wait for setattr on objects finished..."
3362 wait_delete_completed
3364 BLK_CNT=$((BLK_CNT * 1024))
3366 echo "Verify disk usage for user $TSTID"
3367 USED=$(getquota -u $TSTID global curspace)
3368 [ $USED -lt $BLK_CNT ] &&
3369 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3370 USED=$(getquota -u $TSTID global curinodes)
3372 error "Used inodes for user $TSTID is $USED, expected 1"
3374 echo "chgrp the file to group $TSTID"
3375 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3377 echo "Wait for setattr on objects finished..."
3378 wait_delete_completed
3380 echo "Verify disk usage for group $TSTID"
3381 USED=$(getquota -g $TSTID global curspace)
3382 [ $USED -ge $BLK_CNT ] ||
3383 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3384 USED=$(getquota -g $TSTID global curinodes)
3386 error "Used inodes for group $TSTID is $USED, expected 1"
3388 # chown won't change the ost object group. LU-4345 */
3389 echo "chown the file to user $TSTID2"
3390 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3392 echo "Wait for setattr on objects finished..."
3393 wait_delete_completed
3395 echo "change_project project id to $TSTPRJID"
3396 [ $project_supported == "yes" ] &&
3397 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3398 echo "Wait for setattr on objects finished..."
3399 wait_delete_completed
3401 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3402 USED=$(getquota -u $TSTID2 global curspace)
3403 [ $USED -lt $BLK_CNT ] &&
3404 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3405 USED=$(getquota -u $TSTID global curspace)
3407 error "Used space for user $TSTID is $USED, expected 0"
3408 USED=$(getquota -g $TSTID global curspace)
3409 [ $USED -lt $BLK_CNT ] &&
3410 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3411 if [ $project_supported == "yes" ]; then
3412 USED=$(getquota -p $TSTPRJID global curspace)
3413 [ $USED -lt $BLK_CNT ] && error \
3414 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3418 run_test 34 "Usage transfer for user & group & project"
3420 # usage is still accessible across restart
3422 local BLK_CNT=2 # MB
3424 setup_quota_test || error "setup quota failed with $?"
3426 echo "Write file..."
3427 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3428 error "write failed"
3429 is_project_quota_supported &&
3430 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3431 cancel_lru_locks osc
3433 echo "Wait for setattr on objects finished..."
3434 wait_delete_completed
3436 sync; sync_all_data || true
3438 echo "Save disk usage before restart"
3439 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3440 [ $ORIG_USR_SPACE -eq 0 ] &&
3441 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3442 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3443 [ $ORIG_USR_INODES -eq 0 ] &&
3444 error "Used inodes for user $TSTID is 0, expected 1"
3445 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3446 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3447 [ $ORIG_GRP_SPACE -eq 0 ] &&
3448 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3449 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3450 [ $ORIG_GRP_INODES -eq 0 ] &&
3451 error "Used inodes for group $TSTID is 0, expected 1"
3452 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3454 if is_project_quota_supported; then
3455 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3456 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3457 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3458 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3459 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3460 "Used inodes for project $TSTPRJID is 0, expected 1"
3461 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3469 echo "Verify disk usage after restart"
3470 local USED=$(getquota -u $TSTID global curspace)
3471 [ $USED -eq $ORIG_USR_SPACE ] ||
3472 error "Used space for user $TSTID changed from " \
3473 "$ORIG_USR_SPACE to $USED"
3474 USED=$(getquota -u $TSTID global curinodes)
3475 [ $USED -eq $ORIG_USR_INODES ] ||
3476 error "Used inodes for user $TSTID changed from " \
3477 "$ORIG_USR_INODES to $USED"
3478 USED=$(getquota -g $TSTID global curspace)
3479 [ $USED -eq $ORIG_GRP_SPACE ] ||
3480 error "Used space for group $TSTID changed from " \
3481 "$ORIG_GRP_SPACE to $USED"
3482 USED=$(getquota -g $TSTID global curinodes)
3483 [ $USED -eq $ORIG_GRP_INODES ] ||
3484 error "Used inodes for group $TSTID changed from " \
3485 "$ORIG_GRP_INODES to $USED"
3486 if [ $project_supported == "yes" ]; then
3487 USED=$(getquota -p $TSTPRJID global curinodes)
3488 [ $USED -eq $ORIG_PRJ_INODES ] ||
3489 error "Used inodes for project $TSTPRJID " \
3490 "changed from $ORIG_PRJ_INODES to $USED"
3491 USED=$(getquota -p $TSTPRJID global curspace)
3492 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3493 error "Used space for project $TSTPRJID "\
3494 "changed from $ORIG_PRJ_SPACE to $USED"
3497 # check if the vfs_dq_init() is called before writing
3498 echo "Append to the same file..."
3499 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3500 error "write failed"
3501 cancel_lru_locks osc
3502 sync; sync_all_data || true
3504 echo "Verify space usage is increased"
3505 USED=$(getquota -u $TSTID global curspace)
3506 [ $USED -gt $ORIG_USR_SPACE ] ||
3507 error "Used space for user $TSTID isn't increased" \
3508 "orig:$ORIG_USR_SPACE, now:$USED"
3509 USED=$(getquota -g $TSTID global curspace)
3510 [ $USED -gt $ORIG_GRP_SPACE ] ||
3511 error "Used space for group $TSTID isn't increased" \
3512 "orig:$ORIG_GRP_SPACE, now:$USED"
3513 if [ $project_supported == "yes" ]; then
3514 USED=$(getquota -p $TSTPRJID global curspace)
3515 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3516 error "Used space for project $TSTPRJID isn't " \
3517 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3520 run_test 35 "Usage is still accessible across reboot"
3522 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3525 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3526 skip "Old server doesn't have LU-5006 fix."
3528 setup_quota_test || error "setup quota failed with $?"
3530 # make sure the system is clean
3531 local USED=$(getquota -u $TSTID global curspace)
3533 error "Used space ($USED) for user $TSTID isn't 0."
3535 # create file with MDS_OPEN_DELAY_CREATE flag
3536 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3537 error "Create file failed"
3539 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3540 oflag=sync || error "Write file failed"
3542 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3544 # wait for setattr on objects finished..."
3545 wait_delete_completed
3547 USED=$(getquota -u $TSTID global curspace)
3548 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3550 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3554 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3555 skip "Old server doesn't have LU-8801 fix."
3557 [ "$UID" != 0 ] && skip_env "must run as root" && return
3559 setup_quota_test || error "setup quota failed with $?"
3561 # make sure the system is clean
3562 local USED=$(getquota -u $TSTID global curspace)
3564 error "Used space ($USED) for user $TSTID isn't 0."
3565 USED=$(getquota -u $TSTID2 global curspace)
3567 error "Used space ($USED) for user $TSTID2 isn't 0."
3569 local TESTFILE="$DIR/$tdir/$tfile"
3570 local file_cnt=10000
3572 # Generate id entries in accounting file
3573 echo "Create $file_cnt files..."
3574 for i in `seq $file_cnt`; do
3576 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3577 error "failed to chown $TESTFILE-$i"
3579 cancel_lru_locks osc
3580 sync; sync_all_data || true
3582 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3583 procf=${procf}.quota_slave.acct_user
3586 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3587 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3588 echo "Found $acct_cnt id entries"
3590 [ $file_cnt -eq $acct_cnt ] || {
3591 do_facet mds1 $LCTL get_param $procf
3592 error "skipped id entries"
3595 run_test 38 "Quota accounting iterator doesn't skip id entries"
3598 local TESTFILE="$DIR/$tdir/project"
3599 ! is_project_quota_supported &&
3600 skip "Project quota is not supported"
3602 setup_quota_test || error "setup quota failed with $?"
3605 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3606 [ $projectid -ne 0 ] &&
3607 error "Project id should be 0 not $projectid"
3608 change_project -p 1024 $TESTFILE
3609 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3610 [ $projectid -ne 1024 ] &&
3611 error "Project id should be 1024 not $projectid"
3613 stopall || error "failed to stopall (1)"
3616 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3617 [ $projectid -eq 1024 ] ||
3618 error "Project id should be 1024 not $projectid"
3620 run_test 39 "Project ID interface works correctly"
3623 ! is_project_quota_supported &&
3624 skip "Project quota is not supported"
3625 local dir1="$DIR/$tdir/dir1"
3626 local dir2="$DIR/$tdir/dir2"
3628 setup_quota_test || error "setup quota failed with $?"
3630 mkdir -p $dir1 $dir2
3631 change_project -sp 1 $dir1 && touch $dir1/1
3632 change_project -sp 2 $dir2
3634 ln $dir1/1 $dir2/1_link &&
3635 error "Hard link across different project quota should fail"
3638 run_test 40a "Hard link across different project ID"
3641 ! is_project_quota_supported &&
3642 skip "Project quota is not supported"
3643 local dir1="$DIR/$tdir/dir1"
3644 local dir2="$DIR/$tdir/dir2"
3646 setup_quota_test || error "setup quota failed with $?"
3647 mkdir -p $dir1 $dir2
3648 change_project -sp 1 $dir1 && touch $dir1/1
3649 change_project -sp 2 $dir2
3651 mv $dir1/1 $dir2/2 || error "mv failed $?"
3652 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3653 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3655 run_test 40b "Mv across different project ID"
3658 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3659 ! is_project_quota_supported &&
3660 skip "Project quota is not supported"
3662 setup_quota_test || error "setup quota failed with $?"
3663 local dir="$DIR/$tdir/dir"
3665 mkdir -p $dir && change_project -sp 1 $dir
3666 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3667 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3668 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3669 touch $dir/remote_dir/file
3670 #verify inherit works file for remote dir.
3671 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3672 [ "$projid" != "1" ] &&
3673 error "file under remote dir expected 1 not $projid"
3675 #Agent inode should be ignored for project quota
3676 local used=$(getquota -p 1 global curinodes)
3678 error "file count expected 3 got $used"
3680 run_test 40c "Remote child Dir inherit project quota properly"
3683 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3684 is_project_quota_supported || skip "Project quota is not supported"
3686 setup_quota_test || error "setup quota failed with $?"
3687 local dir="$DIR/$tdir/dir"
3690 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3691 change_project -sp $TSTPRJID $dir ||
3692 error "change project on $dir failed"
3693 for i in $(seq 5); do
3694 mkdir -p $dir/d$i/d$i ||
3695 error "mkdir $dir/d$i/d$i failed"
3696 local projid=$($LFS project -d $dir/d$i/d$i |
3698 [ "$projid" == "$TSTPRJID" ] ||
3699 error "projid id expected $TSTPRJID not $projid"
3700 touch $dir/d$i/d$i/file
3701 #verify inherit works file for stripe dir.
3702 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3703 [ "$projid" == "$TSTPRJID" ] ||
3704 error "file under remote dir expected 1 not $projid"
3707 # account should be 1 + (2 + 1) *10 + 1 * 5
3708 local used=$(getquota -p $TSTPRJID global curinodes)
3710 error "file count expected 36 got $used"
3712 run_test 40d "Stripe Directory inherit project quota properly"
3715 is_project_quota_supported ||
3716 skip "Project quota is not supported"
3717 setup_quota_test || error "setup quota failed with $?"
3718 local dir="$DIR/$tdir/dir"
3721 local projid=$((testnum * 1000))
3725 # enable mdt/ost quota
3726 set_mdt_qtype ugp || error "enable mdt quota failed"
3727 set_ost_qtype ugp || error "enable ost quota failed"
3729 test_mkdir -p $dir && change_project -sp $projid $dir
3730 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3731 error "set project quota failed"
3736 # check if df output works as expected
3737 echo "== global statfs: $MOUNT =="
3738 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3740 echo "== project statfs (prjid=$projid): $dir =="
3741 df -kP $dir; df -iP $dir
3742 local bused=$(getquota -p $projid global curspace)
3743 local iused=$(getquota -p $projid global curinodes)
3744 # note trailing space to match double printf from awk
3745 local expected="$blimit $bused $ilimit $iused "
3747 wait_update $HOSTNAME \
3748 "{ df -kP $dir; df -iP $dir; } |
3749 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3751 error "failed to get correct statfs for project quota"
3753 run_test 41 "df should return projid-specific values"
3761 local osd="osd-ldiskfs"
3763 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3765 rm -f $DIR/$tdir/$tfile
3766 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3767 chmod a+rw $DIR/$tdir/$tfile
3769 $LFS setquota $qtype $qid -B 300M $MOUNT
3770 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3771 error "failed to dd"
3773 do_facet $SINGLEMDS \
3774 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3775 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3778 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3779 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3781 $LFS setquota $qtype $qid --delete $MOUNT
3782 do_facet $SINGLEMDS \
3783 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3784 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3787 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3788 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3790 $LFS setquota $qtype $qid -B 500M $MOUNT
3791 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3792 error "failed to dd"
3793 do_facet $SINGLEMDS \
3794 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3795 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3796 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3798 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3799 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3804 setup_quota_test || error "setup quota failed with $?"
3805 set_ost_qtype $QTYPE || error "enable ost quota failed"
3808 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3809 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3810 is_project_quota_supported &&
3811 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3815 run_test 48 "lfs quota --delete should delete quota project ID"
3818 ! is_project_quota_supported &&
3819 skip "Project quota is not supported"
3821 setup_quota_test || error "setup quota failed with $?"
3822 local dir1="$DIR/$tdir/dir1"
3823 local dir2="$DIR/$tdir/dir2"
3825 mkdir -p $dir1 && change_project -sp 1 $dir1
3826 mkdir -p $dir2 && change_project -sp 2 $dir2
3827 for num in $(seq 1 10); do
3828 touch $dir1/file_$num $dir2/file_$num
3829 ln -s $dir1/file_$num $dir1/file_$num"_link"
3830 ln -s $dir2/file_$num $dir2/file_$num"_link"
3833 count=$($LFS find --projid 1 $DIR | wc -l)
3834 [ "$count" != 21 ] && error "expected 21 but got $count"
3836 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3837 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3838 [ $count -eq 22 ] || error "expected 22 but got $count"
3840 run_test 50 "Test if lfs find --projid works"
3843 ! is_project_quota_supported &&
3844 skip "Project quota is not supported"
3845 setup_quota_test || error "setup quota failed with $?"
3846 local dir="$DIR/$tdir/dir"
3848 mkdir $dir && change_project -sp 1 $dir
3849 local used=$(getquota -p 1 global curinodes)
3850 [ $used != "1" ] && error "expected 1 got $used"
3855 used=$(getquota -p 1 global curinodes)
3856 [ $used != "4" ] && error "expected 4 got $used"
3858 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3860 cp $DIR/$tdir/6 $dir/6
3861 used=$(getquota -p 1 global curinodes)
3862 [ $used != "5" ] && error "expected 5 got $used"
3865 mv $DIR/$tdir/6 $dir/7
3866 used=$(getquota -p 1 global curinodes)
3867 [ $used -eq 6 ] || error "expected 6 got $used"
3869 run_test 51 "Test project accounting with mv/cp"
3872 ! is_project_quota_supported &&
3873 skip "Project quota is not supported"
3875 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3876 skip "Need MDS version at least 2.14.55"
3878 setup_quota_test || error "setup quota failed with $?"
3880 local dir1=$DIR/$tdir/t52_dir1
3881 local dir2=$DIR/$tdir/t52_dir2
3883 mkdir $dir1 || error "failed to mkdir $dir1"
3884 mkdir $dir2 || error "failed to mkdir $dir2"
3886 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3887 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3889 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3890 error "failed to create and write $tdir1/$tfile"
3892 cancel_lru_locks osc
3893 sync; sync_all_data || true
3895 local attrs=($(lsattr -p $dir1/$tfile))
3896 (( ${attrs[0]} == 1000 )) ||
3897 error "project ID on $dir1/$tfile is not inherited"
3899 $LFS quota -p 1000 $DIR
3900 $LFS quota -p 1001 $DIR
3902 local prev_used=$(getquota -p 1000 global curspace)
3903 local prev_used2=$(getquota -p 1001 global curspace)
3905 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3907 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3908 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3909 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3911 attrs=($(lsattr -p $dir2/$tfile))
3912 (( ${attrs[0]} == 1001 )) ||
3913 error "project ID is not updated after rename"
3915 (( $inum_before == $inum_after )) ||
3916 error "inode is changed after rename: $inum_before, $inum_after"
3918 sync_all_data || true
3920 $LFS quota -p 1000 $DIR
3921 $LFS quota -p 1001 $DIR
3923 local new_used=$(getquota -p 1000 global curspace)
3924 local new_used2=$(getquota -p 1001 global curspace)
3926 (( $prev_used >= $new_used + 102400 )) ||
3927 error "quota is not deducted from old project ID"
3928 (( $prev_used2 <= $new_used2 - 102400 )) ||
3929 error "quota is not added for the new project ID"
3931 run_test 52 "Rename normal file across project ID"
3934 ! is_project_quota_supported &&
3935 skip "Project quota is not supported"
3936 setup_quota_test || error "setup quota failed with $?"
3937 local dir="$DIR/$tdir/dir"
3938 mkdir $dir && change_project -s $dir
3939 [[ $($LFS project -d $dir) =~ " P " ]] ||
3940 error "inherit attribute should be set"
3942 change_project -C $dir
3943 [[ $($LFS project -d $dir) =~ " - " ]] ||
3944 error "inherit attribute should be cleared"
3946 run_test 53 "Project inherit attribute could be cleared"
3949 ! is_project_quota_supported &&
3950 skip "Project quota is not supported"
3951 setup_quota_test || error "setup quota failed with $?"
3952 local testfile="$DIR/$tdir/$tfile-0"
3954 #set project ID/inherit attribute
3955 change_project -sp $TSTPRJID $DIR/$tdir
3956 $RUNAS createmany -m ${testfile} 100 ||
3957 error "create many files failed"
3959 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3960 # one more count for directory itself */
3964 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3965 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3967 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3968 [ $proj_count1 -eq $proj_count ] ||
3969 error "c2: expected $proj_count got $proj_count1"
3971 #clear project but with kept projid
3972 change_project -rCk $DIR/$tdir
3973 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3974 [ $proj_count1 -eq 1 ] ||
3975 error "c3: expected 1 got $proj_count1"
3977 #verify projid untouched.
3978 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3980 [ $proj_count1 -eq $proj_count ] ||
3981 error "c4: expected $proj_count got $proj_count1"
3984 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3985 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3986 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3988 #this time clear all
3989 change_project -rC $DIR/$tdir
3990 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3991 [ $proj_count1 -eq 0 ] ||
3992 error "c6: expected 0 got $proj_count1"
3994 unlinkmany ${testfile} 100 ||
3995 error "unlink many files failed"
3997 run_test 54 "basic lfs project interface test"
4000 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4001 skip "Not supported before 2.10.58."
4002 setup_quota_test || error "setup quota failed with $?"
4004 set_ost_qtype $QTYPE || error "enable ost quota failed"
4007 #add second group to TSTUSR
4008 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4011 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4012 error "failed to dd"
4014 cancel_lru_locks osc
4015 sync; sync_all_data || true
4017 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4018 error "failed to setquota on group $TSTUSR2"
4020 $LFS quota -v -g $TSTUSR2 $DIR
4022 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4023 error "chgrp should failed with -EDQUOT"
4025 USED=$(getquota -g $TSTUSR2 global curspace)
4028 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4029 error "failed to setquota on group $TSTUSR2"
4031 $LFS quota -v -g $TSTUSR2 $DIR
4033 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4034 error "chgrp should succeed"
4036 $LFS quota -v -g $TSTUSR2 $DIR
4038 run_test 55 "Chgrp should be affected by group quota"
4041 setup_quota_test || error "setup quota failed with $?"
4043 set_ost_qtype $QTYPE || error "enable ost quota failed"
4046 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4047 erro "failed to set grace time for usr quota"
4048 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4049 awk '{print $4 $8}')
4050 if [ "x$grace_time" != "x10s;10s" ]; then
4051 $LFS quota -t -u $DIR
4052 error "expected grace time: 10s;10s, got:$grace_time"
4055 run_test 56 "lfs quota -t should work well"
4058 setup_quota_test || error "setup quota failed with $?"
4060 local dir="$DIR/$tdir/dir"
4063 #command can process further if it hit some errors
4064 $LFS project -sp 1 $dir/pipe
4065 touch $dir/aaa $dir/bbb
4066 mkdir $dir/subdir -p
4067 touch $dir/subdir/aaa $dir/subdir/bbb
4068 #create one invalid link file
4069 ln -s $dir/not_exist_file $dir/ccc
4070 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4071 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4073 run_test 57 "lfs project could tolerate errors"
4076 [ "$mds1_FSTYPE" != ldiskfs ] &&
4077 skip "ldiskfs only test"
4078 disable_project_quota
4079 setup_quota_test || error "setup quota failed with $?"
4082 local testfile="$DIR/$tdir/$tfile-0"
4083 #make sure it did not crash kernel
4084 touch $testfile && lfs project -sp 1 $testfile
4086 enable_project_quota
4088 run_test 59 "lfs project dosen't crash kernel with project disabled"
4091 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4092 skip "Needs MDS version 2.11.53 or later."
4093 setup_quota_test || error "setup quota failed with $?"
4095 local testfile=$DIR/$tdir/$tfile
4098 set_mdt_qtype "ug" || error "enable mdt quota failed"
4100 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4101 error "set quota failed"
4102 quota_show_check a g $TSTUSR
4104 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4105 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4106 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4107 error "create many files failed"
4109 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4111 # root user can overrun quota
4112 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4113 error "root user should succeed"
4115 run_test 60 "Test quota for root with setgid"
4117 # test default quota
4118 test_default_quota() {
4119 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4120 skip "Not supported before 2.11.51."
4125 local qprjid=$TSTPRJID
4129 local LIMIT=20480 #20M disk space
4130 local TESTFILE="$DIR/$tdir/$tfile-0"
4133 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4134 echo "Project quota is not supported" && return 0
4136 [ $qtype == "-u" ] && qdtype="-U"
4137 [ $qtype == "-g" ] && qdtype="-G"
4138 [ $qtype == "-p" ] && {
4143 [ $qres_type == "meta" ] && {
4144 LIMIT=10240 #10K inodes
4149 qpool_cmd="--pool $3"
4150 # pool quotas don't work properly without global limit
4151 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4152 error "set global limit failed"
4155 setup_quota_test || error "setup quota failed with $?"
4159 # enable mdt/ost quota
4160 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4161 set_ost_qtype $QTYPE || error "enable ost quota failed"
4163 log "set to use default quota"
4164 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4165 error "set $qid to use default quota failed"
4167 log "set default quota"
4168 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4169 error "set $qid default quota failed"
4171 log "get default quota"
4172 $LFS quota $qdtype $DIR || error "get default quota failed"
4174 if [ $qres_type == "data" ]; then
4175 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4176 grep "$MOUNT" | awk '{print $2}')
4177 [ $SLIMIT -eq $LIMIT ] ||
4178 error "the returned default quota is wrong"
4180 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4182 [ $SLIMIT -eq $LIMIT ] ||
4183 error "the returned default quota is wrong"
4186 # make sure the system is clean
4187 local USED=$(getquota $qtype $qid global curspace)
4188 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4190 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4191 error "setstripe $TESTFILE failed"
4192 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4194 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4196 log "Test not out of quota"
4197 if [ $qres_type == "data" ]; then
4198 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4199 quota_error $qtype $qid "write failed, expect succeed"
4201 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4202 quota_error $qtype $qid "create failed, expect succeed"
4204 unlinkmany $TESTFILE $((LIMIT/2))
4207 log "Test out of quota"
4208 # flush cache, ensure noquota flag is set on client
4209 cancel_lru_locks osc
4210 cancel_lru_locks mdc
4211 sync; sync_all_data || true
4212 if [ $qres_type == "data" ]; then
4213 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4214 quota_error $qtype $qid "write succeed, expect EDQUOT"
4216 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4217 quota_error $qtype $qid "create succeed, expect EDQUOT"
4219 unlinkmany $TESTFILE $((LIMIT*2))
4223 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4224 error "setstripe $TESTFILE failed"
4225 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4227 log "Increase default quota"
4229 # LU-4505: sleep 5 seconds to enable quota acquire
4232 # increase default quota
4233 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4234 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4236 cancel_lru_locks osc
4237 cancel_lru_locks mdc
4238 sync; sync_all_data || true
4239 if [ $qres_type == "data" ]; then
4240 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4241 quota_error $qtype $qid "write failed, expect succeed"
4243 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4244 quota_error $qtype $qid "create failed, expect succeed"
4246 unlinkmany $TESTFILE $((LIMIT*2))
4249 log "Set quota to override default quota"
4250 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4251 error "set $qid quota failed"
4253 cancel_lru_locks osc
4254 cancel_lru_locks mdc
4255 sync; sync_all_data || true
4256 if [ $qres_type == "data" ]; then
4257 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4258 quota_error $qtype $qid "write succeed, expect EQUOT"
4260 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4261 quota_error $qtype $qid "create succeed, expect EQUOT"
4263 unlinkmany $TESTFILE $((LIMIT*2))
4266 log "Set to use default quota again"
4268 # LU-4505: sleep 5 seconds to enable quota acquire
4271 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4272 error "set $qid to use default quota failed"
4274 cancel_lru_locks osc
4275 cancel_lru_locks mdc
4276 sync; sync_all_data || true
4277 if [ $qres_type == "data" ]; then
4278 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4279 quota_error $qtype $qid "write failed, expect succeed"
4281 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4282 quota_error $qtype $qid "create failed, expect succeed"
4284 unlinkmany $TESTFILE $((LIMIT*2))
4289 wait_delete_completed || error "wait_delete_completed failed"
4290 sync_all_data || true
4292 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4293 error "reset default quota failed"
4294 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4295 error "reset quota failed"
4300 test_default_quota "-u" "data"
4301 test_default_quota "-u" "meta"
4302 test_default_quota "-g" "data"
4303 test_default_quota "-g" "meta"
4304 test_default_quota "-p" "data"
4305 test_default_quota "-p" "meta"
4307 run_test 61 "default quota tests"
4310 ! is_project_quota_supported &&
4311 skip "Project quota is not supported"
4312 [[ "$(chattr -h 2>&1)" =~ "project" ||
4313 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4314 skip "chattr did not support project quota"
4315 setup_quota_test || error "setup quota failed with $?"
4316 local testdir=$DIR/$tdir/
4318 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4319 change_project -s $testdir
4320 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4321 error "inherit attribute should be set"
4322 # chattr used FS_IOC_SETFLAGS ioctl
4323 $RUNAS chattr -P $testdir &&
4324 error "regular user clear inherit should fail"
4325 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4326 error "inherit attribute should still be set"
4327 chattr -P $testdir || error "root failed to clear inherit"
4328 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4329 error "inherit attribute should be cleared"
4332 run_test 62 "Project inherit should be only changed by root"
4335 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4336 skip "Not supported before 2.11.55"
4340 local dd_failed=false
4341 local tdir_dom=${tdir}_dom
4342 local LIMIT=20480 #20M
4344 [ $qtype == "p" ] && ! is_project_quota_supported &&
4345 echo "Project quota is not supported" && return 0
4347 [ $qtype == "p" ] && qid=$TSTPRJID
4349 setup_quota_test || error "setup quota failed with $?"
4353 # enable mdt/ost quota
4354 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4355 set_ost_qtype $QTYPE || error "enable ost quota failed"
4357 # make sure the system is clean
4358 local USED=$(getquota -$qtype $qid global curspace)
4359 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4361 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4363 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4364 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4365 error "setstripe $tdir_dom failed"
4366 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4368 [ $qtype == "p" ] && {
4369 change_project -sp $TSTPRJID $DIR/$tdir
4370 change_project -sp $TSTPRJID $DIR/$tdir_dom
4373 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4374 error "set $qid quota failed"
4376 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4377 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4381 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4383 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4384 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4388 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4390 rm -f $DIR/$tdir_dom/*
4392 # flush cache, ensure noquota flag is set on client
4393 cancel_lru_locks osc
4394 cancel_lru_locks mdc
4395 sync; sync_all_data || true
4399 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4400 quota_error $qtype $qid "write failed, expect succeed"
4402 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4403 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4407 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4410 rm -f $DIR/$tdir_dom/*
4412 # flush cache, ensure noquota flag is set on client
4413 cancel_lru_locks osc
4414 cancel_lru_locks mdc
4415 sync; sync_all_data || true
4419 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4420 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4424 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4426 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4427 quota_error $qtype $qid "write succeed, expect EDQUOT"
4430 rm -fr $DIR/$tdir_dom
4432 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4433 error "reset usr quota failed"
4441 run_test 63 "quota on DoM tests"
4444 ! is_project_quota_supported &&
4445 skip "Project quota is not supported"
4446 setup_quota_test || error "setup quota failed with $?"
4447 local dir1="$DIR/$tdir/"
4450 ln -s $dir1/file $dir1/file_link
4453 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4454 error "set project should succeed"
4456 used=$(getquota -p $TSTPRJID global curinodes)
4457 [ $used -eq 4 ] || error "expected 4 got $used"
4458 $LFS project -rC $dir1 >&/dev/null ||
4459 error "clear project should succeed"
4461 used=$(getquota -p $TSTPRJID global curinodes)
4462 [ $used -eq 0 ] || error "expected 0 got $used"
4464 run_test 64 "lfs project on non dir/files should succeed"
4468 local TESTFILE="$DIR/$tdir/$tfile-0"
4470 setup_quota_test || error "setup quota failed with $?"
4471 set_ost_qtype $QTYPE || error "enable ost quota failed"
4475 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4476 error "failed to write"
4477 # flush cache, ensure noquota flag is set on client
4478 cancel_lru_locks osc
4479 sync; sync_all_data || true
4481 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4482 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4483 local quota_all=$($RUNAS $LFS quota $DIR)
4485 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4486 error "usr quota not match"
4487 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4488 error "grp quota not match"
4490 run_test 65 "Check lfs quota result"
4493 ! is_project_quota_supported &&
4494 skip "Project quota is not supported"
4495 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4496 skip "Not supported before 2.12.4"
4497 setup_quota_test || error "setup quota failed with $?"
4498 local old=$(do_facet mds1 $LCTL get_param -n \
4499 mdt.*.enable_chprojid_gid | head -1)
4500 local testdir=$DIR/$tdir/foo
4502 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4503 stack_trap "do_facet mds1 $LCTL \
4504 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4506 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4507 chown -R $TSTID:$TSTID $testdir
4508 change_project -sp $TSTPRJID $testdir
4509 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4511 $RUNAS lfs project -p 0 $testdir/foo &&
4512 error "nonroot user should fail to set projid"
4514 $RUNAS lfs project -C $testdir/foo &&
4515 error "nonroot user should fail to clear projid"
4517 change_project -C $testdir/foo || error "failed to clear project"
4519 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4520 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4521 "failed to set projid with normal user when enable_chprojid_gid=-1"
4523 $RUNAS lfs project -rC $testdir/ || error \
4524 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4526 touch $testdir/bar || error "failed touch $testdir/bar"
4527 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4528 "normal user should not be able to set projid on root owned file"
4530 change_project -p $TSTPRJID $testdir/bar || error \
4531 "root should be able to change its own file's projid"
4533 run_test 66 "nonroot user can not change project state in default"
4540 local short_qtype=${qtype:0:1}
4543 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4545 $TSTUSR) _runas=$RUNAS;;
4546 $TSTUSR2) _runas=$RUNAS2;;
4547 *) error "unknown quota parameter $4";;
4552 $_runas $DD of=$file count=$size ||
4553 quota_error $short_qtype $TSTUSR \
4554 "$qtype write failure, but expect success"
4556 cancel_lru_locks osc
4558 sync; sync_all_data || true
4567 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4569 do_facet mds1 $LCTL get_param $param |
4570 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4575 local testfile="$DIR/$tdir/$tfile-0"
4576 local testfile2="$DIR/$tdir/$tfile-1"
4577 local testfile3="$DIR/$tdir/$tfile-2"
4578 local qpool="qpool1"
4584 [ "$ost1_FSTYPE" == zfs ] &&
4585 skip "ZFS grants some block space together with inode"
4587 setup_quota_test || error "setup quota failed with $?"
4590 set_ost_qtype $QTYPE || error "enable ost quota failed"
4593 log "User quota (block hardlimit:$limit MB)"
4594 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4595 error "set user quota failed"
4597 # make sure the system is clean
4598 used=$(getquota -u $TSTUSR global curspace)
4599 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4601 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4602 echo "granted 0x0 before write $granted"
4604 # trigger reintegration
4605 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4606 procf=${procf}quota_slave.force_reint
4607 do_facet ost1 $LCTL set_param $procf=1 ||
4608 error "force reintegration failed"
4609 wait_ost_reint "u" || error "reintegration failed"
4610 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4611 [ $granted -ne 0 ] &&
4612 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4614 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4615 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4617 # write 10 MB to testfile
4618 test_67_write "$testfile" "user" 10 "$TSTUSR"
4620 # create qpool and add OST1
4621 pool_add $qpool || error "pool_add failed"
4622 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4623 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4624 # created after the 1st direct qmt_get.
4625 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4627 # check granted - should be 0, as testfile is located only on OST0
4628 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4629 echo "global granted $granted"
4630 granted=$(getgranted $qpool "dt" $TSTID "usr")
4631 echo "$qpool granted $granted"
4632 [ $granted -ne 0 ] &&
4633 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4635 # add OST0 to qpool and check granted space
4636 pool_add_targets $qpool 0 1 ||
4637 error "pool_add_targets failed"
4638 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4639 echo "Granted $granted_mb MB"
4640 #should be 10M + qunit for each OST
4641 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4642 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4644 $LFS setstripe $testfile2 -c 1 -i 1 ||
4645 error "setstripe $testfile2 failed"
4646 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4647 # Write from another user and check that qpool1
4648 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4649 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4650 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4651 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4652 [ $granted -ne 0 ] &&
4653 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4655 # Granted space for $TSTUSR2 in qpool1 should appear only
4656 # when global lqe for this user becomes enforced.
4657 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4658 error "set user quota failed"
4659 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4660 echo "granted_mb $granted_mb"
4661 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4662 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4664 $LFS setstripe $testfile3 -c 1 -i 0 ||
4665 error "setstripe $testfile3 failed"
4666 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4667 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4668 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4669 echo "$testfile3 granted_mb $granted_mb"
4670 [ $granted_mb -eq $limit ] ||
4671 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4673 # remove OST1 from the qpool1 and check granted space
4674 # should be 0 for TSTUSR and 10M for TSTUSR2
4675 pool_remove_target $qpool 0
4676 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4677 [ $granted_mb -eq 0 ] ||
4678 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4679 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4680 [ $granted_mb -eq 10 ] ||
4681 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4684 wait_delete_completed || error "wait_delete_completed failed"
4685 sync_all_data || true
4686 used=$(getquota -u $TSTUSR global curspace)
4687 [ $used -eq 0 ] || quota_error u $TSTUSR \
4688 "user quota isn't released after deletion"
4690 run_test 67 "quota pools recalculation"
4697 wait_update_facet mds1 \
4698 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4699 >/dev/null 2>&1 || echo foo" "" ||
4700 error "mds1: failed to create quota pool $pool"
4702 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4703 awk '/usr/ {getline; print $2}'
4708 local qpool="qpool1"
4711 setup_quota_test || error "setup quota failed with $?"
4714 set_ost_qtype $QTYPE || error "enable ost quota failed"
4716 # check slave number for glbal pool
4717 local nr=$(get_slave_nr "0x0" "usr")
4718 echo "nr result $nr"
4719 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4720 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4722 # create qpool and add OST1
4723 pool_add $qpool || error "pool_add failed"
4724 nr=$(get_slave_nr $qpool "usr")
4725 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4728 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4729 nr=$(get_slave_nr $qpool "usr")
4730 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4733 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4734 nr=$(get_slave_nr $qpool "usr")
4735 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4738 pool_remove_target $qpool 0
4739 nr=$(get_slave_nr $qpool "usr")
4740 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4743 pool_remove_target $qpool 1
4744 nr=$(get_slave_nr $qpool "usr")
4745 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4747 # Check again that all is fine with global pool
4748 nr=$(get_slave_nr "0x0" "usr")
4749 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4750 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4752 run_test 68 "slave number in quota pool changed after each add/remove OST"
4756 local global_limit=200 # MB
4758 local testfile="$DIR/$tdir/$tfile-0"
4759 local dom0="$DIR/$tdir/dom0"
4760 local qpool="qpool1"
4763 setup_quota_test || error "setup quota failed with $?"
4766 set_ost_qtype $QTYPE || error "enable ost quota failed"
4767 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4769 # Save DOM only at MDT0
4770 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4771 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4773 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4775 # create qpool and add OST0
4776 pool_add $qpool || error "pool_add failed"
4777 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4779 log "User quota (block hardlimit:$global_limit MB)"
4780 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4781 error "set user quota failed"
4783 log "User quota (block hardlimit:$limit MB)"
4784 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4785 error "set user quota failed"
4787 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4788 quota_error u $TSTUSR "write failed"
4790 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4791 oflag=sync || quota_error u $TSTUSR "write failed"
4793 $RUNAS $DD of=$testfile count=$limit || true
4795 # flush cache, ensure noquota flag is set on client
4796 cancel_lru_locks osc
4797 sync; sync_all_data || true
4799 # MDT0 shouldn't get EDQUOT with glimpse.
4800 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4801 quota_error u $TSTUSR \
4802 "user write success, but expect EDQUOT"
4804 # Now all members of qpool1 should get EDQUOT. Expect success
4805 # when write to DOM on MDT0, as it belongs to global pool.
4806 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4807 oflag=sync || quota_error u $TSTUSR "write failed"
4809 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4810 oflag=sync || quota_error u $TSTUSR "write failed"
4812 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4816 local qpool="qpool1"
4821 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4822 skip "Needs a client >= $VERSION_WITH_QP"
4824 setup_quota_test || error "setup quota failed with $?"
4826 # MDS returns EFAULT for unsupported quotactl command
4827 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4829 # create qpool and add OST0
4830 pool_add $qpool || error "pool_add failed"
4831 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4833 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4835 [ $rc -eq $err ] || error "setquota res $rc != $err"
4837 # If MDS supports QP, check that limit was set properly.
4838 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4839 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4840 echo "hard limit $bhard limit $limit"
4841 [ $bhard -ne $((limit*1024)) ] &&
4842 error "bhard:$bhard for $qpool!=$((limit*1024))"
4845 $LFS quota -u $TSTUSR --pool $qpool $DIR
4847 [ $rc -eq $err ] || error "quota res $rc != $err"
4849 run_test 70a "check lfs setquota/quota with a pool option"
4853 local glbl_hard=200 # 200M
4854 local glbl_soft=100 # 100M
4855 local pool_hard=10 # 10M
4856 local qpool="qpool1"
4858 pool_add $qpool || error "pool_add failed"
4859 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4861 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4862 error "set user quota failed"
4863 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4864 error "set user quota failed"
4866 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4867 [ $tmp -eq $((pool_hard * 1024)) ] ||
4868 error "wrong block hard limit $tmp for $qpool"
4869 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4870 # soft limit hasn't been set and should be zero
4871 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4873 run_test 70b "lfs setquota pool works properly"
4878 local global_limit=100 # MB
4879 local testfile="$DIR/$tdir/$tfile-0"
4880 local qpool="qpool1"
4881 local qpool2="qpool2"
4883 [ "$ost1_FSTYPE" == zfs ] &&
4884 skip "ZFS grants some block space together with inode"
4885 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4887 setup_quota_test || error "setup quota failed with $?"
4890 set_ost_qtype $QTYPE || error "enable ost quota failed"
4893 log "User quota (block hardlimit:$global_limit MB)"
4894 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4895 error "set user quota failed"
4897 pool_add $qpool || error "pool_add failed"
4898 pool_add_targets $qpool 0 1 ||
4899 error "pool_add_targets failed"
4901 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4902 error "set user quota failed"
4904 pool_add $qpool2 || error "pool_add failed"
4905 pool_add_targets $qpool2 1 1 ||
4906 error "pool_add_targets failed"
4908 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4909 error "set user quota failed"
4911 # make sure the system is clean
4912 local used=$(getquota -u $TSTUSR global curspace)
4915 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4917 # create 1st component 1-10M
4918 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4919 #create 2nd component 10-30M
4920 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4921 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4923 # сheck normal use and out of quota with PFL
4924 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4925 test_1_check_write $testfile "user" $((limit*2))
4927 wait_delete_completed || error "wait_delete_completed failed"
4928 sync_all_data || true
4929 used=$(getquota -u $TSTUSR global curspace)
4930 [ $used -ne 0 ] && quota_error u $TSTUSR \
4931 "user quota isn't released after deletion"
4933 # create 1st component 1-10M
4934 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4935 # create 2nd component 10-30M
4936 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4937 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4939 # write to the 2nd component
4940 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4941 quota_error u $TSTUSR \
4942 "write failure, but expect success"
4943 # this time maybe cache write, ignore it's failure
4944 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4945 cancel_lru_locks osc
4946 sync; sync_all_data || true
4947 # write over limit in qpool2(2nd component 10-30M)
4948 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4949 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4950 # write to the 1st component - OST0 is empty
4951 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4952 quota_error u $TSTUSR "write failed"
4954 run_test 71a "Check PFL with quota pools"
4958 local global_limit=1000 # MB
4959 local limit1=160 # MB
4960 local limit2=10 # MB
4961 local testfile="$DIR/$tdir/$tfile-0"
4962 local qpool="qpool1"
4963 local qpool2="qpool2"
4965 [ "$ost1_FSTYPE" == zfs ] &&
4966 skip "ZFS grants some block space together with inode"
4967 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4969 setup_quota_test || error "setup quota failed with $?"
4972 set_ost_qtype $QTYPE || error "enable ost quota failed"
4975 log "User quota (block hardlimit:$global_limit MB)"
4976 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4977 error "set user quota failed"
4979 pool_add $qpool || error "pool_add failed"
4980 pool_add_targets $qpool 0 1 ||
4981 error "pool_add_targets failed"
4983 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4984 error "set user quota failed"
4986 pool_add $qpool2 || error "pool_add failed"
4987 pool_add_targets $qpool2 1 1 ||
4988 error "pool_add_targets failed"
4990 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4991 error "set user quota failed"
4993 # make sure the system is clean
4994 local used=$(getquota -u $TSTUSR global curspace)
4997 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4999 # First component is on OST0, 2nd on OST1
5000 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5001 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5003 # fill the 1st component on OST0
5004 $RUNAS $DD of=$testfile count=128 ||
5005 quota_error u $TSTUSR "write failed"
5006 # write to the 2nd cmpnt on OST1
5007 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5008 quota_error u $TSTUSR "write failed"
5009 # this time maybe cache write, ignore it's failure
5010 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5012 cancel_lru_locks osc
5013 sync; sync_all_data || true
5014 # write over limit in qpool2
5015 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5016 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5019 run_test 71b "Check SEL with quota pools"
5024 local global_limit=50 # MB
5025 local testfile="$DIR/$tdir/$tfile-0"
5026 local qpool="qpool1"
5029 setup_quota_test || error "setup quota failed with $?"
5032 set_ost_qtype $QTYPE || error "enable ost quota failed"
5035 log "User quota (block hardlimit:$global_limit MB)"
5036 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5037 error "set user quota failed"
5039 pool_add $qpool || error "pool_add failed"
5040 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5042 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5043 error "set user quota failed"
5045 # make sure the system is clean
5046 local used=$(getquota -u $TSTUSR global curspace)
5048 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5050 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5052 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5053 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5054 test_1_check_write $testfile "user" $limit
5055 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5057 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5058 # check that lfs quota -uv --pool prints only OST that
5059 # was added in a pool
5060 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5061 grep "OST\|MDT" && error "$qpool consists wrong targets"
5064 run_test 72 "lfs quota --pool prints only pool's OSTs"
5068 local qpool="qpool1"
5072 pool_add $qpool || error "pool_add failed"
5073 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5074 error "pool_add_targets failed"
5076 test_default_quota "-u" "data" "qpool1"
5078 run_test 73a "default limits at OST Pool Quotas"
5082 local TESTFILE1="$DIR/$tdir/$tfile-1"
5084 local qpool="qpool1"
5088 setup_quota_test || error "setup quota failed with $?"
5090 set_ost_qtype $QTYPE || error "enable ost quota failed"
5092 # pool quotas don't work properly without global limit
5093 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5094 error "set global limit failed"
5096 pool_add $qpool || error "pool_add failed"
5097 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5098 error "pool_add_targets failed"
5100 log "set default quota for $qpool"
5101 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5102 error "set default quota failed"
5104 log "Write from user that hasn't lqe"
5105 # Check that it doesn't cause a panic or a deadlock
5106 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5107 # Have to use RUNAS_ID as resetquota creates lqes in
5108 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5109 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5111 cancel_lru_locks osc
5112 sync; sync_all_data || true
5114 run_test 73b "default OST Pool Quotas limit for new user"
5118 local global_limit=200 # 200M
5119 local limit=10 # 10M
5120 local limit2=50 # 50M
5121 local qpool="qpool1"
5122 local qpool2="qpool2"
5126 setup_quota_test || error "setup quota failed with $?"
5129 set_ost_qtype $QTYPE || error "enable ost quota failed"
5131 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5132 error "set user quota failed"
5134 pool_add $qpool || error "pool_add failed"
5135 pool_add_targets $qpool 0 1 ||
5136 error "pool_add_targets failed"
5138 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5139 error "set user quota failed"
5141 pool_add $qpool2 || error "pool_add failed"
5142 pool_add_targets $qpool2 1 1 ||
5143 error "pool_add_targets failed"
5145 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5146 error "set user quota failed"
5148 tmp=$(getquota -u $TSTUSR global bhardlimit)
5149 [ $tmp -eq $((global_limit * 1024)) ] ||
5150 error "wrong global limit $global_limit"
5152 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5153 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5155 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5156 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5158 # check limits in pools
5159 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5160 grep -A4 $qpool | awk 'NR == 4{print $4}')
5161 echo "pool limit for $qpool $tmp"
5162 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5163 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5164 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5165 echo "pool limit for $qpool2 $tmp"
5166 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5168 run_test 74 "check quota pools per user"
5170 function cleanup_quota_test_75()
5172 do_facet mgs $LCTL nodemap_modify --name default \
5173 --property admin --value 1
5174 do_facet mgs $LCTL nodemap_modify --name default \
5175 --property trusted --value 1
5176 do_facet mgs $LCTL nodemap_modify --name default \
5177 --property squash_uid --value 99
5178 do_facet mgs $LCTL nodemap_modify --name default \
5179 --property squash_gid --value 99
5181 wait_nm_sync default admin_nodemap
5182 wait_nm_sync default trusted_nodemap
5184 do_facet mgs $LCTL nodemap_activate 0
5187 resetquota -u $TSTUSR
5191 local dd_failed=false
5192 local LIMIT=20480 #20M
5195 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5196 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5197 conv=fsync || dd_failed=true
5200 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5202 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5203 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5204 conv=fsync || dd_failed=true
5207 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5209 rm -f $DIR/$tdir_dom/*
5211 # flush cache, ensure noquota flag is set on client
5213 sync; sync_all_data || true
5217 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5218 quota_error u $qid "write failed, expect succeed (2)"
5220 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5221 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5222 conv=fsync || dd_failed=true
5225 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5228 rm -f $DIR/$tdir_dom/*
5230 # flush cache, ensure noquota flag is set on client
5232 sync; sync_all_data || true
5236 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5237 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5238 conv=fsync || dd_failed=true
5241 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5243 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) conv=fsync &&
5244 quota_error u $qid "write succeed, expect EDQUOT (3)"
5250 local soft_limit=10 # MB
5251 local hard_limit=20 # MB
5252 local limit=$soft_limit
5253 local testfile="$DIR/$tdir/$tfile-0"
5254 local grace=20 # seconds
5255 local tdir_dom=${tdir}_dom
5257 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5261 setup_quota_test || error "setup quota failed with $?"
5262 stack_trap cleanup_quota_test_75 EXIT
5265 set_ost_qtype $QTYPE || error "enable ost quota failed"
5266 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5268 local used=$(getquota -u $TSTID global curspace)
5269 $LFS setquota -t -u --block-grace $grace --inode-grace \
5270 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5271 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5272 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5273 error "set user quota failed"
5275 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5276 mkdir $DIR/$tdir_dom
5277 chmod 777 $DIR/$tdir_dom
5278 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5279 error "setstripe $tdir_dom failed"
5281 do_facet mgs $LCTL nodemap_activate 1
5283 do_facet mgs $LCTL nodemap_modify --name default \
5284 --property admin --value 0
5285 do_facet mgs $LCTL nodemap_modify --name default \
5286 --property trusted --value 0
5287 do_facet mgs $LCTL nodemap_modify --name default \
5288 --property deny_unknown --value 0
5289 do_facet mgs $LCTL nodemap_modify --name default \
5290 --property squash_uid --value $TSTID
5291 do_facet mgs $LCTL nodemap_modify --name default \
5292 --property squash_gid --value $TSTID
5293 cancel_lru_locks mdc
5294 wait_nm_sync default admin_nodemap
5295 wait_nm_sync default trusted_nodemap
5296 wait_nm_sync default squash_uid
5298 # mmap write when over soft limit
5300 $DD of=$testfile count=${limit} ||
5301 quota_error a "root write failure, but expect success (1)"
5302 OFFSET=$((limit * 1024))
5303 cancel_lru_locks osc
5305 echo "Write to exceed soft limit"
5306 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5307 quota_error a $TSTUSR "root write failure, but expect success (2)"
5308 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5309 cancel_lru_locks osc
5311 echo "mmap write when over soft limit"
5312 $MULTIOP $testfile.mmap OT40960SMW ||
5313 quota_error a $TSTUSR "mmap write failure, but expect success"
5314 cancel_lru_locks osc
5316 wait_delete_completed || error "wait_delete_completed failed (1)"
5317 sync_all_data || true
5319 # test for user hard limit
5322 $DD of=$testfile bs=1M count=$((limit/2)) ||
5323 quota_error u $TSTID \
5324 "root write failure, but expect success (3)"
5326 log "Write out of block quota ..."
5327 # possibly a cache write, ignore failure
5328 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5329 # flush cache, ensure noquota flag is set on client
5330 cancel_lru_locks osc
5331 sync; sync_all_data || true
5332 # sync forced cache flush, but did not guarantee that slave
5333 # got new edquot through glimpse, so wait to make sure
5335 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5336 quota_error u $TSTID \
5337 "user write success, but expect EDQUOT"
5339 wait_delete_completed || error "wait_delete_completed failed (2)"
5340 sync_all_data || true
5341 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5342 quota_error u $TSTID "user quota not released after deletion"
5346 run_test 75 "nodemap squashed root respects quota enforcement"
5349 ! is_project_quota_supported &&
5350 skip "skip project quota unsupported"
5352 setup_quota_test || error "setup quota failed with $?"
5355 local testfile="$DIR/$tdir/$tfile-0"
5358 $LFS project -p 4294967295 $testfile &&
5359 error "set project ID should fail"
5362 run_test 76 "project ID 4294967295 should be not allowed"
5366 mount_client $MOUNT2 "ro"
5367 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5368 error "lfs setquota should fail in read-only Lustre mount"
5371 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5375 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5376 skip "need OST at least 2.14.55"
5377 check_set_fallocate_or_skip
5379 setup_quota_test || error "setup quota failed with $?"
5382 set_ost_qtype $QTYPE || error "enable ost quota failed"
5384 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5385 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5388 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5389 error "lfs setquota failed"
5392 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5394 kbytes=$(lfs quota -u $TSTUSR $DIR |
5395 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5396 echo "kbytes returned:$kbytes"
5398 # For file size of 204800. We should be having roughly 200 kbytes
5399 # returned. Anything alarmingly low (50 taken as arbitrary value)
5400 # would bail out this TC. Also this also avoids $kbytes of 0
5401 # to be used in calculation below.
5402 (( $kbytes > 50 )) ||
5403 error "fallocate did not use quota. kbytes returned:$kbytes"
5405 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5406 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5408 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5409 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5410 error "fallocate did not use quota correctly"
5412 run_test 78 "Check fallocate increase quota usage"
5416 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5417 skip "need client at least 2.15.0"
5418 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5419 skip "need OST at least 2.15.0"
5420 check_set_fallocate_or_skip
5422 setup_quota_test || error "setup quota failed with $?"
5425 set_ost_qtype $QTYPE || error "enable ost quota failed"
5427 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5429 local projectid=5200 # Random project id to test
5431 change_project -sp $projectid $DIR/$tdir
5434 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5435 error "lfs setquota project failed"
5438 fallocate -l 204800 $DIR/$tdir/$tfile
5440 # Get curspace (kbytes) for $projectid
5441 local kbytes=$(getquota -p $projectid global curspace)
5443 echo "kbytes returned:$kbytes"
5445 # For file size of 204800. We should be having roughly 200 kbytes
5446 # returned. Anything alarmingly low (50 taken as arbitrary value)
5447 # would bail out this TC. Also this also avoids $kbytes of 0
5448 # to be used in calculation below.
5449 (( $kbytes > 50 )) ||
5450 error "fallocate did not use projectid. kbytes returned:$kbytes"
5452 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5453 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5455 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5456 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5457 error "fallocate did not use quota projectid correctly"
5459 run_test 78a "Check fallocate increase projectid usage"
5463 local qpool="qpool1"
5464 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5465 local stopf=$TMP/$tfile
5467 do_facet mds1 "touch $stopf"
5468 stack_trap "do_facet mds1 'rm -f $stopf'"
5469 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5471 pool_add $qpool || error "pool_add failed"
5472 do_facet mds1 "rm $stopf"
5475 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5479 local dir1="$DIR/$tdir/dir1"
5480 local dir2="$DIR/$tdir/dir2"
5481 local TESTFILE0="$dir1/$tfile-0"
5482 local TESTFILE1="$dir1/$tfile-1"
5483 local TESTFILE2="$dir1/$tfile-2"
5484 local TESTFILE3="$dir2/$tfile-0"
5485 local global_limit=100 # 100M
5486 local limit=10 # 10M
5487 local qpool="qpool1"
5489 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5491 [ "$ost1_FSTYPE" == zfs ] &&
5492 skip "ZFS grants some block space together with inode"
5493 setup_quota_test || error "setup quota failed with $?"
5494 set_ost_qtype $QTYPE || error "enable ost quota failed"
5496 # make sure the system is clean
5497 local used=$(getquota -u $TSTUSR global curspace)
5498 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5500 pool_add $qpool || error "pool_add failed"
5501 pool_add_targets $qpool 0 1 ||
5502 error "pool_add_targets failed"
5504 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5505 error "set user quota failed"
5507 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5508 error "set user quota failed"
5509 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5510 error "set user quota failed"
5512 mkdir -p $dir1 || error "failed to mkdir"
5513 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5514 mkdir -p $dir2 || error "failed to mkdir"
5515 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5517 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5518 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5523 $LFS quota -uv $TSTUSR $DIR
5524 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5525 do_facet mds1 $LCTL set_param fail_loc=0xa06
5526 $RUNAS $DD of=$TESTFILE3 count=3 ||
5527 quota_error u $TSTUSR "write failed"
5528 $RUNAS $DD of=$TESTFILE2 count=7 ||
5529 quota_error u $TSTUSR "write failed"
5530 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5531 quota_error u $TSTUSR "write failed"
5534 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5538 do_facet mds1 $LCTL set_param fail_loc=0
5539 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5540 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5541 # OST0 needs some time to update quota usage after removing TESTFILE2
5543 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5544 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5545 quota_error u $TSTUSR "write failure, but expect success"
5547 run_test 80 "check for EDQUOT after OST failover"
5550 local global_limit=20 # 100M
5551 local testfile="$DIR/$tdir/$tfile-0"
5552 local qpool="qpool1"
5555 setup_quota_test || error "setup quota failed with $?"
5558 set_ost_qtype $QTYPE || error "enable ost quota failed"
5561 log "User quota (block hardlimit:$global_limit MB)"
5562 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5564 pool_add $qpool || error "pool_add failed"
5565 #define OBD_FAIL_QUOTA_RECALC 0xA07
5566 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5567 # added OST casues to start pool recalculation
5568 pool_add_targets $qpool 0 0 1
5569 stop mds1 -f || error "MDS umount failed"
5571 #start mds1 back to destroy created pool
5572 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5575 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5579 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5580 skip "need MDS 2.14.55 or later"
5581 is_project_quota_supported ||
5582 skip "skip project quota unsupported"
5584 setup_quota_test || error "setup quota failed with $?"
5587 local parent_dir="$DIR/$tdir.parent"
5588 local child_dir="$parent_dir/child"
5591 stack_trap "chown -R 0:0 $parent_dir"
5593 chown $TSTUSR:$TSTUSR $parent_dir ||
5594 error "failed to chown on $parent_dir"
5595 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5596 error "failed to chown on $parent_dir"
5598 $LFS project -p 1000 $parent_dir ||
5599 error "failed to set project id on $parent_dir"
5600 $LFS project -p 1001 $child_dir ||
5601 error "failed to set project id on $child_dir"
5603 rmdir $child_dir || error "cannot remove child dir, test failed"
5605 run_test 82 "verify more than 8 qids for single operation"
5607 test_grace_with_default_quota()
5616 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5617 error "clear default quota [$qdtype] failed"
5619 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5620 error "reset quota [$qdtype] grace failed"
5623 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5624 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5627 $LFS setquota $qdtype -B 10G -i 10k $DIR
5630 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5631 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5633 [ "$bgrace" == "$bgrace2" ] ||
5634 error "set default quota shouldn't affect block grace"
5635 [ "$igrace" == "$igrace2" ] ||
5636 error "set default quota shouldn't affect inode grace"
5642 setup_quota_test || error "setup quota failed with $?"
5643 test_grace_with_default_quota "-u" "-U"
5644 test_grace_with_default_quota "-g" "-G"
5646 is_project_quota_supported || return 0
5647 test_grace_with_default_quota "-p" "-P"
5649 run_test 83 "Setting default quota shouldn't affect grace time"
5653 (( $MDS1_VERSION >= $(version_code 2.15.53) )) ||
5654 skip "need MDS 2.15.53 or later"
5656 local dir1="$DIR/$tdir/dir1"
5657 local TESTFILE1="$dir1/$tfile-1"
5665 setup_quota_test || error "setup quota failed with $?"
5667 set_ost_qtype $QTYPE || error "enable ost quota failed"
5669 pool_add $qp || error "pool_add failed"
5670 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
5671 error "pool_add_targets failed"
5673 $LFS setquota -g $TSTUSR -B 10G $DIR ||
5674 error "failed to set group quota for $TSTUSR"
5675 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
5676 error "set user quota failed"
5677 $LFS quota -gv $TSTUSR $DIR
5679 mkdir -p $dir1 || error "failed to mkdir"
5680 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5682 $LFS setstripe -c 1 -i 0 $TESTFILE1
5683 $LFS getstripe $TESTFILE1
5684 chown $TSTUSR.$TSTUSR $TESTFILE1
5686 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
5687 quota_error g $TSTUSR "write failed"
5691 $LFS quota -gv $TSTUSR $DIR
5693 #define OBD_FAIL_QUOTA_GRANT 0xA08
5694 lustre_fail mds 0xa08
5695 lustre_fail ost 0xa08
5698 # clear quota limits to trigger updating grant quota
5699 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
5700 error "failed to clear the group quota for $TSTUSR"
5701 $LFS quota -gv $TSTUSR $DIR
5703 # the grant quota should be set as insane value
5705 while (( $waited < 60 )); do
5706 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5707 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5708 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
5711 waited=$((waited + 1))
5714 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
5715 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
5717 lustre_fail mds_ost 0
5721 $LFS setquota -g $TSTUSR -r $DIR ||
5722 error "failed to reset group quota for $TSTUSR"
5725 $LFS quota -gv $TSTUSR $DIR
5727 # the grant quota should be reset
5728 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5729 (( ${#grant} == 20 )) && error "grant is not cleared"
5730 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5731 (( ${#grant} == 20 )) && error "pool grant is not cleared"
5733 $LFS quota -gv $TSTUSR --pool $qp $DIR
5734 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
5735 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
5737 # test whether the quota still works
5738 $LFS setquota -g $TSTUSR -B 100M $DIR ||
5739 error "failed to set group quota for $TSTUSR"
5740 $LFS quota -gv $TSTUSR $DIR
5742 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
5743 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
5745 $LFS setquota -g $TSTUSR -B 300M $DIR ||
5746 error "failed to set group quota for $TSTUSR"
5747 $LFS quota -gv $TSTUSR $DIR
5749 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
5750 quota_error g $TSTUSR "dd failed, expect succeed"
5752 run_test 84 "Reset quota should fix the insane granted quota"
5756 do_nodes $(comma_list $(nodes_list)) \
5757 "lctl set_param -n debug=-quota-trace"
5758 if $PQ_CLEANUP; then
5759 disable_project_quota
5762 reset_quota_settings
5767 check_and_cleanup_lustre
5768 export QUOTA_AUTO=$QUOTA_AUTO_OLD