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}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
42 VERSION_WITH_QP="2.13.53"
44 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
45 skip "Needs MDS version $VERSION_WITH_QP or later."
48 require_dsh_mds || exit 0
49 require_dsh_ost || exit 0
51 # Does e2fsprogs support quota feature?
52 if [ "$mds1_FSTYPE" == ldiskfs ] &&
53 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
54 grep -q 'quota'"; then
55 skip_env "e2fsprogs doesn't support quota"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 QUOTA_AUTO_OLD=$QUOTA_AUTO
68 check_and_setup_lustre
70 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
77 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
78 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
79 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
99 lfs project $* || error "lfs project $* failed"
102 RUNAS="runas -u $TSTID -g $TSTID"
103 RUNAS2="runas -u $TSTID2 -g $TSTID2"
104 DD="dd if=/dev/zero bs=1M"
108 # clear quota limits for a user or a group
109 # usage: resetquota -u username
110 # resetquota -g groupname
111 # resetquota -p projid
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 if [ $1 == "-p" ]; then
119 is_project_quota_supported || return 0
122 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
123 error "clear quota for [type:$1 name:$2] failed"
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" == "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 -u $TSTUSR
487 resetquota -g $TSTUSR
489 resetquota -u $TSTUSR2
490 resetquota -u $TSTID2
491 resetquota -g $TSTUSR2
492 resetquota -g $TSTID2
493 resetquota -p $TSTPRJID
498 do_nodes $(comma_list $(nodes_list)) \
499 "$LCTL set_param -n debug=+quota,trace"
504 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
505 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
506 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
507 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
509 test_quota_performance() {
510 local TESTFILE="$DIR/$tdir/$tfile-0"
511 local size=$1 # in MB
512 local stime=$(date +%s)
513 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
514 quota_error u $TSTUSR "write failure"
515 local etime=$(date +%s)
516 delta=$((etime - stime))
517 if [ $delta -gt 0 ]; then
518 rate=$((size * 1024 / delta))
519 if [ "$mds1_FSTYPE" = zfs ]; then
520 # LU-2872 - see LU-2887 for fix
522 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
524 [ $rate -gt 1024 ] ||
525 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
531 # test basic quota performance b=21696
534 [ "$SLOW" = "no" ] && MB=10
536 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
537 [ $free_space -le $((MB * 1024)) ] &&
538 skip "not enough space ${free_space} KB, " \
539 "required $((MB * 1024)) KB"
540 setup_quota_test || error "setup quota failed with $?"
542 set_ost_qtype "none" || error "disable ost quota failed"
543 test_quota_performance $MB
545 set_ost_qtype $QTYPE || error "enable ost quota failed"
546 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
547 error "set quota failed"
548 test_quota_performance $MB
550 run_test 0 "Test basic quota performance"
552 # usage: test_1_check_write tfile user|group|project
553 test_1_check_write() {
557 local short_qtype=${qtype:0:1}
560 $RUNAS $DD of=$testfile count=$((limit/2)) ||
561 quota_error $short_qtype $TSTUSR \
562 "$qtype write failure, but expect success"
563 log "Write out of block quota ..."
564 # this time maybe cache write, ignore it's failure
565 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
566 # flush cache, ensure noquota flag is set on client
568 sync; sync_all_data || true
569 # sync means client wrote all it's cache, but id doesn't
570 # guarantee that slave received new edquot through glimpse.
571 # so wait a little to be sure slave got it.
573 $RUNAS $DD of=$testfile count=1 seek=$limit &&
574 quota_error $short_qtype $TSTUSR \
575 "user write success, but expect EDQUOT"
579 check_write_fallocate() {
583 local short_qtype=${qtype:0:1}
586 log "Write ${count}MiB Using Fallocate"
587 $RUNAS fallocate -l${count}MiB $testfile ||
588 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
591 sync; sync_all_data || true
595 log "Write ${count}MiB Using Fallocate"
596 $RUNAS fallocate -l${count}MiB $testfile &&
597 quota_error $short_qtype $TSTUSR \
598 "Write success, expect EDQUOT" || true
601 # test block hardlimit
604 local testfile="$DIR/$tdir/$tfile-0"
606 setup_quota_test || error "setup quota failed with $?"
609 set_ost_qtype $QTYPE || error "enable ost quota failed"
612 log "User quota (block hardlimit:$limit MB)"
613 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
614 error "set user quota failed"
616 # make sure the system is clean
617 local used=$(getquota -u $TSTUSR global curspace)
618 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
620 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
621 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
623 test_1_check_write $testfile "user" $limit
626 wait_delete_completed || error "wait_delete_completed failed"
627 sync_all_data || true
628 used=$(getquota -u $TSTUSR global curspace)
629 [ $used -ne 0 ] && quota_error u $TSTUSR \
630 "user quota isn't released after deletion"
631 resetquota -u $TSTUSR
634 log "--------------------------------------"
635 log "Group quota (block hardlimit:$limit MB)"
636 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
637 error "set group quota failed"
639 testfile="$DIR/$tdir/$tfile-1"
640 # make sure the system is clean
641 used=$(getquota -g $TSTUSR global curspace)
642 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
644 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
645 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
647 test_1_check_write $testfile "group" $limit
649 wait_delete_completed || error "wait_delete_completed failed"
650 sync_all_data || true
651 used=$(getquota -g $TSTUSR global curspace)
652 [ $used -ne 0 ] && quota_error g $TSTUSR \
653 "Group quota isn't released after deletion"
654 resetquota -g $TSTUSR
656 if ! is_project_quota_supported; then
657 echo "Project quota is not supported"
661 testfile="$DIR/$tdir/$tfile-2"
662 # make sure the system is clean
663 used=$(getquota -p $TSTPRJID global curspace)
665 error "used space($used) for project $TSTPRJID isn't 0"
668 log "--------------------------------------"
669 log "Project quota (block hardlimit:$limit mb)"
670 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
671 error "set project quota failed"
673 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
674 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
675 change_project -p $TSTPRJID $testfile
677 test_1_check_write $testfile "project" $limit
682 used=$(getquota -p $TSTPRJID global curspace)
683 [ $used -ne 0 ] && quota_error p $TSTPRJID \
684 "project quota isn't released after deletion"
686 resetquota -p $TSTPRJID
688 run_test 1a "Block hard limit (normal use and out of quota)"
692 local global_limit=20 # MB
693 local testfile="$DIR/$tdir/$tfile-0"
697 setup_quota_test || error "setup quota failed with $?"
700 set_ost_qtype $QTYPE || error "enable ost quota failed"
703 log "User quota (block hardlimit:$global_limit MB)"
704 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
705 error "set user quota failed"
707 pool_add $qpool || error "pool_add failed"
708 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
709 error "pool_add_targets failed"
711 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
712 error "set user quota failed"
714 # make sure the system is clean
715 local used=$(getquota -u $TSTUSR global curspace)
717 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
719 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
721 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
722 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
724 test_1_check_write $testfile "user" $limit
727 wait_delete_completed || error "wait_delete_completed failed"
728 sync_all_data || true
729 used=$(getquota -u $TSTUSR global curspace $qpool)
730 [ $used -ne 0 ] && quota_error u $TSTUSR \
731 "user quota isn't released after deletion"
732 resetquota -u $TSTUSR
735 log "--------------------------------------"
736 log "Group quota (block hardlimit:$global_limit MB)"
737 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
738 error "set group quota failed"
740 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
741 error "set group quota failed"
743 testfile="$DIR/$tdir/$tfile-1"
744 # make sure the system is clean
745 used=$(getquota -g $TSTUSR global curspace $qpool)
746 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
748 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
749 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
751 test_1_check_write $testfile "group" $limit
754 wait_delete_completed || error "wait_delete_completed failed"
755 sync_all_data || true
756 used=$(getquota -g $TSTUSR global curspace $qpool)
757 [ $used -ne 0 ] && quota_error g $TSTUSR \
758 "Group quota isn't released after deletion"
759 resetquota -g $TSTUSR
761 if ! is_project_quota_supported; then
762 echo "Project quota is not supported"
766 testfile="$DIR/$tdir/$tfile-2"
767 # make sure the system is clean
768 used=$(getquota -p $TSTPRJID global curspace $qpool)
770 error "used space($used) for project $TSTPRJID isn't 0"
773 log "--------------------------------------"
774 log "Project quota (block hardlimit:$global_limit mb)"
775 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
776 error "set project quota failed"
778 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
779 error "set project quota failed"
782 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
783 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
784 change_project -p $TSTPRJID $testfile
786 test_1_check_write $testfile "project" $limit
791 used=$(getquota -p $TSTPRJID global curspace)
792 [ $used -eq 0 ] || quota_error p $TSTPRJID \
793 "project quota isn't released after deletion"
795 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
798 local global_limit=20 # MB
799 local testfile="$DIR/$tdir/$tfile-0"
800 local qpool1="qpool1"
801 local qpool2="qpool2"
804 setup_quota_test || error "setup quota failed with $?"
807 set_ost_qtype $QTYPE || error "enable ost quota failed"
810 log "User quota (block hardlimit:$global_limit MB)"
811 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
812 error "set user quota failed"
814 pool_add $qpool1 || error "pool_add failed"
815 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
816 error "pool_add_targets failed"
818 pool_add $qpool2 || error "pool_add failed"
819 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
820 error "pool_add_targets failed"
822 # create pools without hard limit
823 # initially such case raised several bugs
824 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
825 error "set user quota failed"
827 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
828 error "set user quota failed"
830 # make sure the system is clean
831 local used=$(getquota -u $TSTUSR global curspace)
833 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
835 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
837 test_1_check_write $testfile "user" $global_limit
839 used=$(getquota -u $TSTUSR global curspace $qpool1)
840 echo "qpool1 used $used"
841 used=$(getquota -u $TSTUSR global curspace $qpool2)
842 echo "qpool2 used $used"
845 wait_delete_completed || error "wait_delete_completed failed"
846 sync_all_data || true
848 used=$(getquota -u $TSTUSR global curspace $qpool1)
849 [ $used -eq 0 ] || quota_error u $TSTUSR \
850 "user quota isn't released after deletion"
852 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
857 local global_limit=20 # MB
858 local testfile="$DIR/$tdir/$tfile-0"
859 local qpool1="qpool1"
860 local qpool2="qpool2"
863 setup_quota_test || error "setup quota failed with $?"
866 set_ost_qtype $QTYPE || error "enable ost quota failed"
869 log "User quota (block hardlimit:$global_limit MB)"
870 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
871 error "set user quota failed"
873 pool_add $qpool1 || error "pool_add failed"
874 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
875 error "pool_add_targets failed"
877 pool_add $qpool2 || error "pool_add failed"
878 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
879 error "pool_add_targets failed"
881 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
882 error "set user quota failed"
884 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
885 error "set user quota failed"
887 # make sure the system is clean
888 local used=$(getquota -u $TSTUSR global curspace)
890 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
892 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
894 test_1_check_write $testfile "user" $limit1
896 used=$(getquota -u $TSTUSR global curspace $qpool1)
897 echo "qpool1 used $used"
898 used=$(getquota -u $TSTUSR global curspace $qpool2)
899 echo "qpool2 used $used"
902 wait_delete_completed || error "wait_delete_completed failed"
903 sync_all_data || true
905 used=$(getquota -u $TSTUSR global curspace $qpool1)
906 [ $used -eq 0 ] || quota_error u $TSTUSR \
907 "user quota isn't released after deletion"
909 run_test 1d "Quota pools: check block hardlimit on different pools"
913 local global_limit=53000000 # MB
914 local testfile="$DIR/$tdir/$tfile-0"
915 local testfile2="$DIR/$tdir/$tfile-1"
916 local qpool1="qpool1"
919 setup_quota_test || error "setup quota failed with $?"
922 set_ost_qtype $QTYPE || error "enable ost quota failed"
924 # global_limit is much greater than limit1 to get
925 # different qunit's on osts. Since 1st qunit shrinking
926 # on OST1(that belongs to qpool1), this qunit should
928 log "User quota (block hardlimit:$global_limit MB)"
929 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
930 error "set user quota failed"
932 pool_add $qpool1 || error "pool_add failed"
933 pool_add_targets $qpool1 1 1 ||
934 error "pool_add_targets failed"
936 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
937 error "set user quota failed"
939 # make sure the system is clean
940 local used=$(getquota -u $TSTUSR global curspace)
941 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
943 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
944 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
946 test_1_check_write $testfile "user" $limit1
948 $LFS setstripe $testfile2 -c 1 -i 0 ||
949 error "setstripe $testfile2 failed"
950 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
951 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
953 $RUNAS $DD of=$testfile2 count=20 ||
954 quota_error u $TSTUSR \
955 "$qtype write failure, but expect success"
959 wait_delete_completed || error "wait_delete_completed failed"
960 sync_all_data || true
962 used=$(getquota -u $TSTUSR global curspace $qpool1)
963 [ $used -eq 0 ] || quota_error u $TSTUSR \
964 "user quota isn't released after deletion"
966 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
969 local global_limit=200 # MB
971 local TESTDIR="$DIR/$tdir/"
972 local testfile="$TESTDIR/$tfile-0"
973 local qpool1="qpool1"
976 setup_quota_test || error "setup quota failed with $?"
979 set_ost_qtype $QTYPE || error "enable ost quota failed"
981 log "User quota (block hardlimit:$global_limit MB)"
982 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
983 error "set user quota failed"
985 pool_add $qpool1 || error "pool_add failed"
986 pool_add_targets $qpool1 0 0 ||
987 error "pool_add_targets failed"
989 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
990 error "set user quota failed"
992 # make sure the system is clean
993 local used=$(getquota -u $TSTUSR global curspace)
994 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
996 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
998 test_1_check_write $testfile "user" $limit1
1000 pool_remove_target $qpool1 0
1002 wait_delete_completed || error "wait_delete_completed failed"
1003 sync_all_data || true
1005 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1006 # qunit for appropriate element in lgd array should be set
1007 # correctly(4096). Earlier it was not changed continuing to be 1024.
1008 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1009 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1010 # as it already was 1024. As flag "need_update" for this qunit was
1011 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1012 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1013 # became > 10M. QMT returned EINPROGRESS in a loop.
1014 # Check that it doesn't hung anymore.
1015 test_1_check_write $testfile "user" $limit1
1017 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1021 local global_limit=40 # MB
1022 local testfile="$DIR/$tdir/$tfile-0"
1023 local qpool="qpool1"
1024 local mdmb_param="osc.*.max_dirty_mb"
1025 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1028 setup_quota_test || error "setup quota failed with $?"
1029 $LCTL set_param $mdmb_param=1
1030 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1033 set_ost_qtype $QTYPE || error "enable ost quota failed"
1036 log "User quota (block hardlimit:$global_limit MB)"
1037 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1038 error "set user quota failed"
1040 pool_add $qpool || error "pool_add failed"
1041 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1042 error "pool_add_targets failed"
1044 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1045 error "set user quota failed"
1047 # make sure the system is clean
1048 local used=$(getquota -u $TSTUSR global curspace)
1050 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1052 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1053 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1056 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1057 quota_error u $TSTUSR \
1058 "$qtype write failure, but expect success"
1059 log "Write out of block quota ..."
1060 # this time maybe cache write, ignore it's failure
1061 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1062 # flush cache, ensure noquota flag is set on client
1063 cancel_lru_locks osc
1064 sync; sync_all_data || true
1066 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1067 quota_error u $TSTUSR \
1068 "user write success, but expect EDQUOT"
1071 wait_delete_completed || error "wait_delete_completed failed"
1072 sync_all_data || true
1074 used=$(getquota -u $TSTUSR global curspace $qpool)
1075 [ $used -ne 0 ] && quota_error u $TSTUSR \
1076 "user quota isn't released after deletion"
1079 run_test 1g "Quota pools: Block hard limit with wide striping"
1083 local testfile="$DIR/$tdir/$tfile-0"
1085 check_set_fallocate_or_skip
1087 setup_quota_test || error "setup quota failed with $?"
1090 set_ost_qtype $QTYPE || error "enable ost quota failed"
1093 log "User quota (block hardlimit:$limit MB)"
1094 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1095 error "set user quota failed"
1097 # make sure the system is clean
1098 local used=$(getquota -u $TSTUSR global curspace)
1099 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1101 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1102 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1104 check_write_fallocate $testfile "user" $limit
1107 wait_delete_completed || error "wait_delete_completed failed"
1108 sync_all_data || true
1109 used=$(getquota -u $TSTUSR global curspace)
1110 [ $used -eq 0 ] || quota_error u $TSTUSR \
1111 "user quota isn't released after deletion"
1113 run_test 1h "Block hard limit test using fallocate"
1116 local global_limit=200 # 200M
1117 local limit1=10 # 10M
1118 local TESTDIR="$DIR/$tdir/"
1119 local testfile="$TESTDIR/$tfile-0"
1120 local testfile1="$TESTDIR/$tfile-1"
1121 local testfile2="$TESTDIR/$tfile-2"
1122 local qpool1="qpool1"
1125 setup_quota_test || error "setup quota failed with $?"
1126 stack_trap cleanup_quota_test EXIT
1129 set_ost_qtype $QTYPE || error "enable ost quota failed"
1131 log "User quota (block hardlimit:$global_limit MB)"
1132 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1133 error "set user quota failed"
1135 pool_add $qpool1 || error "pool_add failed"
1136 pool_add_targets $qpool1 0 0 ||
1137 error "pool_add_targets failed"
1139 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1140 error "set user quota failed"
1142 # make sure the system is clean
1143 local used=$(getquota -u $TSTUSR global curspace)
1144 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1146 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1149 test_1_check_write $testfile "user" $limit1
1150 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1151 error "set user quota failed"
1153 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1154 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1155 quota_error u $TSTUSR "write failure, but expect success"
1159 wait_delete_completed || error "wait_delete_completed failed"
1160 sync_all_data || true
1162 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1163 error "set user quota failed"
1164 test_1_check_write $testfile "user" $limit1
1165 local tmp_limit=$(($limit1*2))
1166 # increase pool limit
1167 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1168 error "set user quota failed"
1169 # now write shouldn't fail
1170 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1171 quota_error u $TSTUSR "write failure, but expect success"
1172 # decrease pool limit
1173 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1174 error "set user quota failed"
1175 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1176 # flush cache, ensure noquota flag is set on client
1177 cancel_lru_locks osc
1178 sync; sync_all_data || true
1179 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1180 quota_error u $TSTUSR "write success, but expect failure"
1183 run_test 1i "Quota pools: different limit and usage relations"
1185 # test inode hardlimit
1187 local testfile="$DIR/$tdir/$tfile-0"
1188 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1189 qmt.$FSNAME-QMT0000.md-0x0.info |
1190 sed -e 's/least qunit/least_qunit/' |
1191 awk '/least_qunit/{ print $2 }')
1194 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1195 limit=$((least_qunit * 1024))
1196 echo "least_qunit: '$least_qunit', limit: '$limit'"
1198 local free_inodes=$(mdt_free_inodes 0)
1199 echo "$free_inodes free inodes on master MDT"
1200 [ $free_inodes -lt $limit ] &&
1201 skip "not enough free inodes $free_inodes required $limit"
1203 setup_quota_test || error "setup quota failed with $?"
1206 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1209 log "User quota (inode hardlimit:$limit files)"
1210 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1211 error "set user quota failed"
1213 # make sure the system is clean
1214 local used=$(getquota -u $TSTUSR global curinodes)
1215 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1217 log "Create $((limit - least_qunit)) files ..."
1218 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1219 quota_error u $TSTUSR "user create failure, but expect success"
1220 # it is ok, if it fails on the last qunit
1221 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1222 log "Create out of file quota ..."
1223 $RUNAS touch ${testfile}_xxx &&
1224 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1227 unlinkmany ${testfile} $((limit - least_qunit)) ||
1228 error "unlinkmany $testfile failed"
1229 # if 2nd createmany got EDQUOT, not all of nodes would be created
1230 unlinkmany ${testfile}_yyy $least_qunit || true
1231 rm -f ${testfile}_xxx
1232 wait_delete_completed
1234 used=$(getquota -u $TSTUSR global curinodes)
1235 [ $used -ne 0 ] && quota_error u $TSTUSR \
1236 "user quota isn't released after deletion"
1237 resetquota -u $TSTUSR
1240 log "--------------------------------------"
1241 log "Group quota (inode hardlimit:$limit files)"
1242 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1243 error "set group quota failed"
1245 testfile=$DIR/$tdir/$tfile-1
1246 # make sure the system is clean
1247 used=$(getquota -g $TSTUSR global curinodes)
1248 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1250 log "Create $limit files ..."
1251 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1252 quota_error g $TSTUSR "group create failure, but expect success"
1253 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1254 log "Create out of file quota ..."
1255 $RUNAS touch ${testfile}_xxx &&
1256 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1259 unlinkmany ${testfile} $((limit - least_qunit)) ||
1260 error "unlinkmany $testfile failed"
1261 unlinkmany ${testfile}_yyy $least_qunit || true
1262 rm -f ${testfile}_xxx
1263 wait_delete_completed
1265 used=$(getquota -g $TSTUSR global curinodes)
1266 [ $used -ne 0 ] && quota_error g $TSTUSR \
1267 "user quota isn't released after deletion"
1269 resetquota -g $TSTUSR
1270 ! is_project_quota_supported &&
1271 echo "Skip project quota is not supported" && return 0
1274 log "--------------------------------------"
1275 log "Project quota (inode hardlimit:$limit files)"
1276 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1277 error "set project quota failed"
1279 testfile=$DIR/$tdir/$tfile-1
1280 # make sure the system is clean
1281 used=$(getquota -p $TSTPRJID global curinodes)
1283 error "Used inodes($used) for project $TSTPRJID isn't 0"
1285 change_project -sp $TSTPRJID $DIR/$tdir
1286 log "Create $limit files ..."
1287 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1288 quota_error p $TSTPRJID \
1289 "project create fail, but expect success"
1290 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1291 log "Create out of file quota ..."
1292 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1293 "project create success, but expect EDQUOT"
1294 change_project -C $DIR/$tdir
1297 used=$(getquota -p $TSTPRJID global curinodes)
1298 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1299 "project quota isn't released after deletion"
1302 run_test 2 "File hard limit (normal use and out of quota)"
1311 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1312 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1316 $LFS setstripe $testfile -c 1 -i 0
1317 chown $TSTUSR.$TSTUSR $testfile
1318 [ "$qtype" == "p" ] && is_project_quota_supported &&
1319 change_project -p $TSTPRJID $testfile
1321 echo "Write up to soft limit"
1322 $RUNAS $DD of=$testfile count=$limit ||
1323 quota_error a $TSTUSR "write failure, but expect success"
1324 OFFSET=$((limit * 1024))
1325 cancel_lru_locks osc
1327 echo "Write to exceed soft limit"
1328 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1329 quota_error a $TSTUSR "write failure, but expect success"
1330 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1331 cancel_lru_locks osc
1333 echo "mmap write when over soft limit"
1334 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1335 quota_error a $TSTUSR "mmap write failure, but expect success"
1336 cancel_lru_locks osc
1341 $SHOW_QUOTA_INFO_USER
1342 $SHOW_QUOTA_INFO_GROUP
1343 $SHOW_QUOTA_INFO_PROJID
1345 echo "Write before timer goes off"
1346 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1347 quota_error a $TSTUSR "write failure, but expect success"
1348 OFFSET=$((OFFSET + 1024))
1349 cancel_lru_locks osc
1351 wait_grace_time $qtype "block" $pool
1356 $SHOW_QUOTA_INFO_USER
1357 $SHOW_QUOTA_INFO_GROUP
1358 $SHOW_QUOTA_INFO_PROJID
1360 log "Write after timer goes off"
1361 # maybe cache write, ignore.
1362 # write up to soft least quint to consume all
1363 # possible slave granted space.
1364 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1365 count=$soft_limit seek=$OFFSET || true
1366 OFFSET=$((OFFSET + soft_limit))
1367 cancel_lru_locks osc
1368 log "Write after cancel lru locks"
1369 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1370 quota_error a $TSTUSR "write success, but expect EDQUOT"
1375 $SHOW_QUOTA_INFO_USER
1376 $SHOW_QUOTA_INFO_GROUP
1377 $SHOW_QUOTA_INFO_PROJID
1379 echo "Unlink file to stop timer"
1381 wait_delete_completed
1382 sync_all_data || true
1387 $SHOW_QUOTA_INFO_USER
1388 $SHOW_QUOTA_INFO_GROUP
1389 $SHOW_QUOTA_INFO_PROJID
1391 $LFS setstripe $testfile -c 1 -i 0
1392 chown $TSTUSR.$TSTUSR $testfile
1393 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1396 $RUNAS $DD of=$testfile count=$limit ||
1397 quota_error a $TSTUSR "write failure, but expect success"
1404 local grace=20 # seconds
1405 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1408 local testfile=$DIR/$tdir/$tfile-0
1410 # get minimum soft qunit size
1411 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1412 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1414 set_ost_qtype $QTYPE || error "enable ost quota failed"
1416 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1417 # make sure the system is clean
1418 local used=$(getquota -u $TSTUSR global curspace)
1419 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1421 $LFS setquota -t -u --block-grace $grace --inode-grace \
1422 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1423 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1424 error "set user quota failed"
1426 test_block_soft $testfile $grace $limit "u"
1428 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1429 testfile=$DIR/$tdir/$tfile-1
1430 # make sure the system is clean
1431 used=$(getquota -g $TSTUSR global curspace)
1432 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1434 $LFS setquota -t -g --block-grace $grace --inode-grace \
1435 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1436 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1437 error "set group quota failed"
1439 test_block_soft $testfile $grace $limit "g"
1441 if is_project_quota_supported; then
1442 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1443 testfile=$DIR/$tdir/$tfile-2
1444 # make sure the system is clean
1445 used=$(getquota -p $TSTPRJID global curspace)
1446 [ $used -ne 0 ] && error \
1447 "Used space($used) for project $TSTPRJID isn't 0."
1449 $LFS setquota -t -p --block-grace $grace --inode-grace \
1450 $MAX_IQ_TIME $DIR ||
1451 error "set project grace time failed"
1452 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1453 $DIR || error "set project quota failed"
1455 test_block_soft $testfile $grace $limit "p"
1456 resetquota -p $TSTPRJID
1457 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1458 $MAX_IQ_TIME $DIR ||
1459 error "restore project grace time failed"
1463 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1464 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1465 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1466 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1468 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1471 local grace=20 # seconds
1472 local qpool="qpool1"
1473 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1476 local testfile=$DIR/$tdir/$tfile-0
1479 # get minimum soft qunit size
1480 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1481 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1482 local glbl_limit=$((2*limit))
1483 local glbl_grace=$((2*grace))
1484 echo "limit $limit glbl_limit $glbl_limit"
1485 echo "grace $grace glbl_grace $glbl_grace"
1487 set_ost_qtype $QTYPE || error "enable ost quota failed"
1489 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1490 # make sure the system is clean
1491 local used=$(getquota -u $TSTUSR global curspace)
1492 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1494 pool_add $qpool || error "pool_add failed"
1495 pool_add_targets $qpool 0 1 ||
1496 error "pool_add_targets failed"
1498 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1499 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1500 $LFS setquota -t -u --block-grace $grace \
1501 --pool $qpool $DIR || error "set user grace time failed"
1503 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1504 error "set user quota failed"
1505 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1506 error "set user quota failed"
1508 test_block_soft $testfile $grace $limit "u" $qpool
1510 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1511 testfile=$DIR/$tdir/$tfile-1
1512 # make sure the system is clean
1513 used=$(getquota -g $TSTUSR global curspace)
1514 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1516 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1517 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1518 $LFS setquota -t -g --block-grace $grace \
1519 --pool $qpool $DIR || error "set group grace time failed"
1521 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1522 error "set group quota failed"
1523 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1524 error "set group quota failed"
1526 test_block_soft $testfile $grace $limit "g" $qpool
1528 if is_project_quota_supported; then
1529 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1530 testfile=$DIR/$tdir/$tfile-2
1531 # make sure the system is clean
1532 used=$(getquota -p $TSTPRJID global curspace)
1533 [ $used -ne 0 ] && error \
1534 "Used space($used) for project $TSTPRJID isn't 0."
1536 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1537 $MAX_IQ_TIME $DIR ||
1538 error "set project grace time failed"
1539 $LFS setquota -t -p --block-grace $grace \
1540 --pool $qpool $DIR ||
1541 error "set project grace time failed"
1543 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1544 $DIR || error "set project quota failed"
1545 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1546 --pool $qpool $DIR || error "set project quota failed"
1548 test_block_soft $testfile $grace $limit "p" $qpool
1549 resetquota -p $TSTPRJID
1550 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1551 $MAX_IQ_TIME $DIR ||
1552 error "restore project grace time failed"
1553 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1554 $DIR || error "set project grace time failed"
1558 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1559 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1560 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1561 --pool $qpool $DIR || error "restore user grace time failed"
1562 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1563 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1564 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1565 --pool $qpool $DIR || error "restore group grace time failed"
1567 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1570 local grace=20 # seconds
1571 local qpool="qpool1"
1572 local qpool2="qpool2"
1573 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1576 local testfile=$DIR/$tdir/$tfile-0
1579 # get minimum soft qunit size
1580 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1581 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1582 local limit2=$((limit+4))
1583 local glbl_limit=$((limit+8))
1584 local grace1=$((grace+10))
1586 local glbl_grace=$((grace+20))
1587 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1588 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1590 set_ost_qtype $QTYPE || error "enable ost quota failed"
1592 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1593 # make sure the system is clean
1594 local used=$(getquota -u $TSTUSR global curspace)
1595 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1597 pool_add $qpool || error "pool_add failed"
1598 pool_add_targets $qpool 0 1 ||
1599 error "pool_add_targets failed"
1601 pool_add $qpool2 || error "pool_add failed"
1602 pool_add_targets $qpool2 0 1 ||
1603 error "pool_add_targets failed"
1606 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1607 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1608 $LFS setquota -t -u --block-grace $grace1 \
1609 --pool $qpool $DIR || error "set user grace time failed"
1610 $LFS setquota -t -u --block-grace $grace2 \
1611 --pool $qpool2 $DIR || error "set user grace time failed"
1613 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1614 error "set user quota failed"
1615 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1616 error "set user quota failed"
1617 # qpool has minimum soft limit, but its grace is greater than
1618 # the grace period of qpool2. Thus write shouldn't fail when
1619 # hit qpool soft limit - only when reaches up qpool2 limit
1620 # after grace2 seconds.
1621 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1622 error "set user quota failed"
1624 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1627 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1628 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1629 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1630 --pool $qpool $DIR || error "restore user grace time failed"
1631 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1632 --pool $qpool2 $DIR || error "restore user grace time failed"
1634 run_test 3c "Quota pools: check block soft limit on different pools"
1641 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1642 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1645 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1647 echo "Create files to exceed soft limit"
1648 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1649 quota_error a $TSTUSR "create failure, but expect success"
1650 local trigger_time=$(date +%s)
1652 sync_all_data || true
1654 local cur_time=$(date +%s)
1655 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1656 error "Passed grace time $grace, $trigger_time, $cur_time"
1658 echo "Create file before timer goes off"
1659 $RUNAS touch ${TESTFILE}_before ||
1660 quota_error a $TSTUSR "failed create before timer expired," \
1661 "but expect success. $trigger_time, $cur_time"
1662 sync_all_data || true
1664 wait_grace_time $qtype "file"
1669 $SHOW_QUOTA_INFO_USER
1670 $SHOW_QUOTA_INFO_GROUP
1671 $SHOW_QUOTA_INFO_PROJID
1673 echo "Create file after timer goes off"
1674 # exceed least soft limit is possible
1675 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1676 quota_error a $TSTUSR "create after timer expired," \
1678 sync_all_data || true
1683 $SHOW_QUOTA_INFO_USER
1684 $SHOW_QUOTA_INFO_GROUP
1685 $SHOW_QUOTA_INFO_PROJID
1687 echo "Unlink files to stop timer"
1688 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1689 wait_delete_completed
1692 $RUNAS touch ${TESTFILE}_xxx ||
1693 quota_error a $TSTUSR "touch after timer stop failure," \
1694 "but expect success"
1695 sync_all_data || true
1703 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1704 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1705 local TESTFILE=$DIR/$tdir/$tfile-0
1708 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1710 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1711 # make sure the system is clean
1712 local USED=$(getquota -u $TSTUSR global curinodes)
1713 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1715 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1716 $GRACE $DIR || error "set user grace time failed"
1717 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1718 error "set user quota failed"
1720 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1722 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1724 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1725 # make sure the system is clean
1726 USED=$(getquota -g $TSTUSR global curinodes)
1727 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1729 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1730 $GRACE $DIR || error "set group grace time failed"
1731 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1732 error "set group quota failed"
1733 TESTFILE=$DIR/$tdir/$tfile-1
1735 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1737 if is_project_quota_supported; then
1738 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1739 # make sure the system is clean
1740 USED=$(getquota -p $TSTPRJID global curinodes)
1741 [ $USED -ne 0 ] && error \
1742 "Used space($USED) for project $TSTPRJID isn't 0."
1744 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1745 $GRACE $DIR || error "set project grace time failed"
1746 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1747 error "set project quota failed"
1749 TESTFILE=$DIR/$tdir/$tfile-1
1750 # one less than limit, because of parent directory included.
1751 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1752 resetquota -p $TSTPRJID
1753 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1754 $MAX_IQ_TIME $DIR ||
1755 error "restore project grace time failed"
1759 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1760 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1761 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1762 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1764 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1767 local GR_STR1="1w3d"
1768 local GR_STR2="1000s"
1770 local GR_STR4="1w2d3h4m5s"
1772 local GR_STR6="18446744073709551615"
1775 wait_delete_completed
1777 # test of valid grace strings handling
1778 echo "Valid grace strings test"
1779 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1780 $GR_STR2 $DIR || error "set user grace time failed"
1781 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1782 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1783 $GR_STR4 $DIR || error "set group grace time quota failed"
1784 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1786 # test of invalid grace strings handling
1787 echo " Invalid grace strings test"
1788 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1789 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1790 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1794 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1795 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1796 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1797 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1799 run_test 4b "Grace time strings handling"
1801 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1803 local BLIMIT=10 # MB
1804 local ILIMIT=10 # inodes
1806 setup_quota_test || error "setup quota failed with $?"
1808 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1809 set_ost_qtype $QTYPE || error "enable ost quota failed"
1811 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1812 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1813 error "set user quota failed"
1814 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1815 if is_project_quota_supported; then
1816 error "set group quota failed"
1817 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1818 -I $ILIMIT $DIR || error "set project quota failed"
1821 # make sure the system is clean
1822 local USED=$(getquota -u $TSTUSR global curinodes)
1823 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1824 USED=$(getquota -g $TSTUSR global curinodes)
1825 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1826 USED=$(getquota -u $TSTUSR global curspace)
1827 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1828 USED=$(getquota -g $TSTUSR global curspace)
1829 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1830 if is_project_quota_supported; then
1831 USED=$(getquota -p $TSTPRJID global curinodes)
1833 error "Used inode($USED) for project $TSTPRJID isn't 0."
1834 USED=$(getquota -p $TSTPRJID global curspace)
1836 error "Used block($USED) for project $TSTPRJID isn't 0."
1839 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1840 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1841 error "create failure, expect success"
1842 if is_project_quota_supported; then
1843 touch $DIR/$tdir/$tfile-0_1
1844 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1846 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1847 error "write failure, expect success"
1849 echo "Chown files to $TSTUSR.$TSTUSR ..."
1850 for i in $(seq 0 $ILIMIT); do
1851 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1852 quota_error a $TSTUSR "chown failure, expect success"
1856 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1857 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1859 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1861 # test dropping acquire request on master
1865 # Clear dmesg so watchdog is not triggered by previous
1867 do_facet ost1 dmesg -c > /dev/null
1869 setup_quota_test || error "setup quota failed with $?"
1871 # make sure the system is clean
1872 local USED=$(getquota -u $TSTUSR global curspace)
1873 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1875 # make sure no granted quota on ost
1876 set_ost_qtype $QTYPE || error "enable ost quota failed"
1877 resetquota -u $TSTUSR
1879 # create file for $TSTUSR
1880 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1881 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1882 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1884 # create file for $TSTUSR2
1885 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1886 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1887 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1889 # cache per-ID lock for $TSTUSR on slave
1890 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1891 error "set quota failed"
1892 $RUNAS $DD of=$TESTFILE count=1 ||
1893 error "write $TESTFILE failure, expect success"
1894 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1895 error "write $TESTFILE2 failure, expect success"
1897 if at_is_enabled; then
1898 at_max_saved=$(at_max_get ost1)
1899 at_max_set $TIMEOUT ost1
1901 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1902 # DQACQ is sent, which makes at_max to take effect
1903 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1906 wait_delete_completed
1910 sync_all_data || true
1912 #define QUOTA_DQACQ 601
1913 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1914 lustre_fail mds 0x513 601
1916 do_facet ost1 $LCTL set_param \
1917 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1919 # write to un-enforced ID ($TSTUSR2) should succeed
1920 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1921 error "write failure, expect success"
1923 # write to enforced ID ($TSTUSR) in background, exceeding limit
1924 # to make sure DQACQ is sent
1925 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1928 # watchdog timer uses a factor of 2
1929 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1930 sleep $((TIMEOUT * 2 + 1))
1932 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1934 # write should be blocked and never finished
1935 if ! ps -p $DDPID > /dev/null 2>&1; then
1937 error "write finished incorrectly!"
1942 # no watchdog is triggered
1943 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1944 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1945 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1946 [ -z "$watchdog" ] || error "$watchdog"
1948 rm -f $TMP/lustre-log-${TESTNAME}.log
1950 # write should continue then fail with EDQUOT
1954 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1955 if [ $count -ge 240 ]; then
1956 quota_error u $TSTUSR "dd not finished in $count secs"
1958 count=$((count + 1))
1959 if [ $((count % 30)) -eq 0 ]; then
1960 c_size=$(stat -c %s $TESTFILE)
1961 echo "Waiting $count secs. $c_size"
1967 run_test 6 "Test dropping acquire request on master"
1969 # quota reintegration (global index)
1971 local TESTFILE=$DIR/$tdir/$tfile
1974 [ "$SLOW" = "no" ] && LIMIT=5
1976 setup_quota_test || error "setup quota failed with $?"
1978 # make sure the system is clean
1979 local USED=$(getquota -u $TSTUSR global curspace)
1980 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1982 # make sure no granted quota on ost1
1983 set_ost_qtype $QTYPE || error "enable ost quota failed"
1984 resetquota -u $TSTUSR
1985 set_ost_qtype "none" || error "disable ost quota failed"
1987 local OSTUUID=$(ostuuid_from_index 0)
1988 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1990 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1993 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1994 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1999 echo "Enable quota & set quota limit for $TSTUSR"
2000 set_ost_qtype $QTYPE || error "enable ost quota failed"
2001 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2002 error "set quota failed"
2004 echo "Start ost1..."
2005 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2008 wait_ost_reint $QTYPE || error "reintegration failed"
2010 # hardlimit should have been fetched by slave during global
2011 # reintegration, write will exceed quota
2012 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2013 quota_error u $TSTUSR "write success, but expect EDQUOT"
2016 wait_delete_completed
2017 sync_all_data || true
2023 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2024 error "clear quota failed"
2026 echo "Start ost1..."
2027 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2030 wait_ost_reint $QTYPE || error "reintegration failed"
2032 # hardlimit should be cleared on slave during reintegration
2033 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2034 quota_error u $TSTUSR "write error, but expect success"
2036 run_test 7a "Quota reintegration (global index)"
2038 # quota reintegration (slave index)
2040 local limit=100000 # MB
2041 local TESTFILE=$DIR/$tdir/$tfile
2043 setup_quota_test || error "setup quota failed with $?"
2045 # make sure the system is clean
2046 local USED=$(getquota -u $TSTUSR global curspace)
2047 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2049 # make sure no granted quota on ost1
2050 set_ost_qtype $QTYPE || error "enable ost quota failed"
2051 resetquota -u $TSTUSR
2052 set_ost_qtype "none" || error "disable ost quota failed"
2054 local OSTUUID=$(ostuuid_from_index 0)
2055 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2057 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2060 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2061 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2063 # consume some space to make sure the granted space will not
2064 # be released during reconciliation
2065 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2066 error "consume space failure, expect success"
2068 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2069 lustre_fail mds 0xa02
2071 set_ost_qtype $QTYPE || error "enable ost quota failed"
2072 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2073 error "set quota failed"
2075 # ignore the write error
2076 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2078 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2082 echo "Restart ost to trigger reintegration..."
2084 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2087 wait_ost_reint $QTYPE || error "reintegration failed"
2089 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2090 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2095 run_test 7b "Quota reintegration (slave index)"
2097 # quota reintegration (restart mds during reintegration)
2100 local TESTFILE=$DIR/$tdir/$tfile
2102 [ "$SLOW" = "no" ] && LIMIT=5
2104 setup_quota_test || error "setup quota failed with $?"
2106 # make sure the system is clean
2107 local USED=$(getquota -u $TSTUSR global curspace)
2108 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2110 set_ost_qtype "none" || error "disable ost quota failed"
2111 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2112 error "set quota failed"
2114 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2115 lustre_fail ost 0xa03
2118 set_ost_qtype $QTYPE || error "enable ost quota failed"
2119 # trigger reintegration
2120 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2121 procf=${procf}quota_slave.force_reint
2122 do_facet ost1 $LCTL set_param $procf=1 ||
2123 error "force reintegration failed"
2131 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2134 # wait longer than usual to make sure the reintegration
2135 # is triggered by quota wb thread.
2136 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2138 # hardlimit should have been fetched by slave during global
2139 # reintegration, write will exceed quota
2140 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2141 quota_error u $TSTUSR "write success, but expect EDQUOT"
2144 run_test 7c "Quota reintegration (restart mds during reintegration)"
2146 # Quota reintegration (Transfer index in multiple bulks)
2148 local TESTFILE=$DIR/$tdir/$tfile
2149 local TESTFILE1="$DIR/$tdir/$tfile"-1
2152 setup_quota_test || error "setup quota failed with $?"
2154 set_ost_qtype "none" || error "disable ost quota failed"
2155 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2156 error "set quota for $TSTUSR failed"
2157 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2158 error "set quota for $TSTUSR2 failed"
2160 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2161 lustre_fail mds 0x608 0
2163 # enable quota to tirgger reintegration
2164 set_ost_qtype "u" || error "enable ost quota failed"
2165 wait_ost_reint "u" || error "reintegration failed"
2169 # hardlimit should have been fetched by slave during global
2170 # reintegration, write will exceed quota
2171 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2172 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2174 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2175 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2178 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2180 # quota reintegration (inode limits)
2182 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2184 # LU-2435: skip this quota test if underlying zfs version has not
2185 # supported native dnode accounting
2186 [ "$mds1_FSTYPE" == zfs ] && {
2187 local F="feature@userobj_accounting"
2188 local pool=$(zpool_name mds1)
2189 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2191 [[ "$feature" != *" active "* ]] &&
2192 skip "requires zpool with active userobj_accounting"
2195 local ilimit=$((1024 * 2)) # inodes
2196 local TESTFILE=$DIR/${tdir}-1/$tfile
2198 setup_quota_test || error "setup quota failed with $?"
2200 # make sure the system is clean
2201 local USED=$(getquota -u $TSTUSR global curinodes)
2202 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2204 # make sure no granted quota on mdt1
2205 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2206 resetquota -u $TSTUSR
2207 set_mdt_qtype "none" || error "disable mdt quota failed"
2209 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2210 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2211 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2214 echo "Stop mds${MDSCOUNT}..."
2217 echo "Enable quota & set quota limit for $TSTUSR"
2218 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2219 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2220 error "set quota failed"
2222 echo "Start mds${MDSCOUNT}..."
2223 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2226 wait_mdt_reint $QTYPE || error "reintegration failed"
2228 echo "create remote dir"
2229 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2230 error "create remote dir failed"
2231 chmod 0777 $DIR/${tdir}-1
2233 # hardlimit should have been fetched by slave during global
2234 # reintegration, create will exceed quota
2235 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2236 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2238 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2239 wait_delete_completed
2240 sync_all_data || true
2242 echo "Stop mds${MDSCOUNT}..."
2245 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2246 error "clear quota failed"
2248 echo "Start mds${MDSCOUNT}..."
2249 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2252 wait_mdt_reint $QTYPE || error "reintegration failed"
2254 # hardlimit should be cleared on slave during reintegration
2255 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2256 quota_error u $TSTUSR "create failed, expect success"
2258 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2259 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2261 run_test 7e "Quota reintegration (inode limits)"
2263 # run dbench with quota enabled
2265 local BLK_LIMIT="100g" #100G
2266 local FILE_LIMIT=1000000
2268 setup_quota_test || error "setup quota failed with $?"
2270 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2271 set_ost_qtype $QTYPE || error "enable ost quota failed"
2273 echo "Set enough high limit for user: $TSTUSR"
2274 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2275 error "set user quota failed"
2276 echo "Set enough high limit for group: $TSTUSR"
2277 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2278 error "set group quota failed"
2279 if is_project_quota_supported; then
2280 change_project -sp $TSTPRJID $DIR/$tdir
2281 echo "Set enough high limit for project: $TSTPRJID"
2282 $LFS setquota -p $TSTPRJID -b 0 \
2283 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2284 error "set project quota failed"
2288 [ "$SLOW" = "no" ] && duration=" -t 120"
2289 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2290 quota_error a $TSTUSR "dbench failed!"
2292 is_project_quota_supported && change_project -C $DIR/$tdir
2294 run_test 8 "Run dbench with quota enabled"
2296 # this check is just for test_9
2297 OST0_MIN=4900000 #4.67G
2299 check_whether_skip () {
2300 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2301 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2302 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2303 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2310 # run for fixing bug10707, it needs a big room. test for 64bit
2312 local filesize=$((1024 * 9 / 2)) # 4.5G
2314 check_whether_skip && return 0
2316 setup_quota_test || error "setup quota failed with $?"
2318 set_ost_qtype "ug" || error "enable ost quota failed"
2320 local TESTFILE="$DIR/$tdir/$tfile-0"
2321 local BLK_LIMIT=100G #100G
2322 local FILE_LIMIT=1000000
2324 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2326 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2328 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2329 error "set user quota failed"
2331 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2332 "for group: $TSTUSR"
2333 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2334 error "set group quota failed"
2336 quota_show_check a u $TSTUSR
2337 quota_show_check a g $TSTUSR
2339 echo "Create test file"
2340 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2341 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2343 log "Write the big file of 4.5G ..."
2344 $RUNAS $DD of=$TESTFILE count=$filesize ||
2345 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2355 run_test 9 "Block limit larger than 4GB (b10707)"
2358 local TESTFILE=$DIR/$tdir/$tfile
2360 setup_quota_test || error "setup quota failed with $?"
2362 # set limit to root user should fail
2363 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2364 error "set limit for root user successfully, expect failure"
2365 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2366 error "set limit for root group successfully, expect failure"
2367 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2368 error "set limit for project 0 successfully, expect failure"
2370 # root user can overrun quota
2371 set_ost_qtype "ug" || error "enable ost quota failed"
2373 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2374 error "set quota failed"
2375 quota_show_check b u $TSTUSR
2377 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2378 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2380 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2381 error "write failure, expect success"
2383 run_test 10 "Test quota for root user"
2386 local TESTFILE=$DIR/$tdir/$tfile
2387 setup_quota_test || error "setup quota failed with $?"
2389 set_mdt_qtype "ug" || error "enable mdt quota failed"
2390 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2391 error "set quota failed"
2393 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2394 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2396 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2397 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2400 local USED=$(getquota -u $TSTUSR global curinodes)
2401 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2403 run_test 11 "Chown/chgrp ignores quota"
2406 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2408 local blimit=22 # MB
2409 local blk_cnt=$((blimit - 5))
2410 local TESTFILE0="$DIR/$tdir/$tfile"-0
2411 local TESTFILE1="$DIR/$tdir/$tfile"-1
2413 setup_quota_test || error "setup quota failed with $?"
2415 set_ost_qtype "u" || error "enable ost quota failed"
2416 quota_show_check b u $TSTUSR
2418 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2419 error "set quota failed"
2421 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2422 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2423 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2424 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2426 echo "Write to ost0..."
2427 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2428 quota_error a $TSTUSR "dd failed"
2430 echo "Write to ost1..."
2431 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2432 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2434 echo "Free space from ost0..."
2436 wait_delete_completed
2437 sync_all_data || true
2439 echo "Write to ost1 after space freed from ost0..."
2440 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2441 quota_error a $TSTUSR "rebalancing failed"
2443 run_test 12a "Block quota rebalancing"
2446 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2448 local ilimit=$((1024 * 2)) # inodes
2449 local TESTFILE0=$DIR/$tdir/$tfile
2450 local TESTFILE1=$DIR/${tdir}-1/$tfile
2452 setup_quota_test || error "setup quota failed with $?"
2454 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2455 chmod 0777 $DIR/${tdir}-1
2457 set_mdt_qtype "u" || error "enable mdt quota failed"
2458 quota_show_check f u $TSTUSR
2460 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2461 error "set quota failed"
2463 echo "Create $ilimit files on mdt0..."
2464 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2465 quota_error u $TSTUSR "create failed, but expect success"
2467 echo "Create files on mdt1..."
2468 $RUNAS createmany -m $TESTFILE1 1 &&
2469 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2471 echo "Free space from mdt0..."
2472 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2473 wait_delete_completed
2474 sync_all_data || true
2476 echo "Create files on mdt1 after space freed from mdt0..."
2477 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2478 quota_error a $TSTUSR "rebalancing failed"
2480 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2481 error "unlink mdt1 files failed"
2482 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2484 run_test 12b "Inode quota rebalancing"
2487 local TESTFILE=$DIR/$tdir/$tfile
2488 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2489 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2491 setup_quota_test || error "setup quota failed with $?"
2493 set_ost_qtype "u" || error "enable ost quota failed"
2494 quota_show_check b u $TSTUSR
2496 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2497 error "set quota failed"
2498 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2499 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2501 # clear the locks in cache first
2502 do_facet ost1 $LCTL set_param -n $procf=clear
2503 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2504 [ $nlock -eq 0 ] || error "$nlock cached locks"
2506 # write to acquire the per-ID lock
2507 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2508 quota_error a $TSTUSR "dd failed"
2510 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2511 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2513 # clear quota doesn't trigger per-ID lock cancellation
2514 resetquota -u $TSTUSR
2515 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2516 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2518 # clear the per-ID lock
2519 do_facet ost1 $LCTL set_param -n $procf=clear
2520 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2521 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2523 # spare quota should be released
2524 local OSTUUID=$(ostuuid_from_index 0)
2525 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2526 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2527 [ $limit -le $space ] ||
2528 error "spare quota isn't released, limit:$limit, space:$space"
2530 run_test 13 "Cancel per-ID lock in the LRU list"
2533 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2535 wait_delete_completed
2536 sync_all_data || true
2539 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2540 error "set user quota failed"
2541 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2542 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2543 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2544 resetquota -u $TSTUSR
2547 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2548 error "set group quota failed"
2549 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2550 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2551 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2552 resetquota -g $TSTUSR
2554 run_test 15 "Set over 4T block quota"
2558 local BLKS=1 # 1M less than limit
2559 local TESTFILE=$DIR/$tdir/$tfile
2561 setup_quota_test || error "setup quota failed with $?"
2563 # make sure the system is clean
2564 local USED=$(getquota -u $TSTUSR global curspace)
2565 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2567 set_ost_qtype "ug" || error "enable ost quota failed"
2568 # make sure no granted quota on ost
2569 resetquota -u $TSTUSR
2570 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2571 error "set quota failed"
2573 quota_show_check b u $TSTUSR
2575 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2576 lustre_fail mds 0xa04 $err_code
2578 # write in background
2579 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2583 # write should be blocked and never finished
2584 if ! ps -p $DDPID > /dev/null 2>&1; then
2586 quota_error u $TSTUSR "write finished incorrectly!"
2594 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2596 if [ $count -gt $timeout ]; then
2597 quota_error u $TSTUSR "dd is not finished!"
2602 sync; sync_all_data || true
2604 USED=$(getquota -u $TSTUSR global curspace)
2605 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2606 "Used space(${USED}K) is less than ${BLKS}M"
2611 # DQACQ return recoverable error
2613 echo "DQACQ return -ENOLCK"
2615 test_17sub 37 || error "Handle -ENOLCK failed"
2617 echo "DQACQ return -EAGAIN"
2619 test_17sub 11 || error "Handle -EAGAIN failed"
2621 echo "DQACQ return -ETIMEDOUT"
2622 #define ETIMEDOUT 110
2623 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2625 echo "DQACQ return -ENOTCONN"
2626 #define ENOTCONN 107
2627 test_17sub 107 || error "Handle -ENOTCONN failed"
2630 run_test 17 "DQACQ return recoverable error"
2634 local blimit=200 # MB
2635 local TESTFILE="$DIR/$tdir/$tfile"
2637 setup_quota_test || error "setup quota failed with $?"
2639 set_ost_qtype "u" || error "enable ost quota failed"
2640 log "User quota (limit: $blimit)"
2641 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2642 error "set quota failed"
2643 quota_show_check b u $TSTUSR
2645 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2646 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2648 local timeout=$(sysctl -n lustre.timeout)
2650 if [ $io_type = "directio" ]; then
2651 log "Write 100M (directio) ..."
2652 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2654 log "Write 100M (buffered) ..."
2655 $RUNAS $DD of=$TESTFILE count=100 &
2659 replay_barrier $SINGLEMDS
2660 log "Fail mds for $((2 * timeout)) seconds"
2661 fail $SINGLEMDS $((2 * timeout))
2664 if at_is_enabled; then
2665 timeout=$(at_max_get mds)
2667 timeout=$(lctl get_param -n timeout)
2671 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2672 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2673 log "it took $count second"
2678 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2680 cancel_lru_locks mdc
2681 cancel_lru_locks osc
2684 local testfile_size=$(stat -c %s $TESTFILE)
2685 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2686 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2687 "got ${testfile_size}. Verifying file failed!"
2692 # test when mds does failover, the ost still could work well
2693 # this test shouldn't trigger watchdog b=14840
2695 # Clear dmesg so watchdog is not triggered by previous
2697 do_facet ost1 dmesg -c > /dev/null
2700 test_18_sub directio
2702 # check if watchdog is triggered
2703 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2704 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2705 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2706 [ -z "$watchdog" ] || error "$watchdog"
2707 rm -f $TMP/lustre-log-${TESTNAME}.log
2709 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2713 local TESTFILE=$DIR/$tdir/$tfile
2715 setup_quota_test || error "setup quota failed with $?"
2717 set_ost_qtype $QTYPE || error "enable ost quota failed"
2719 # bind file to a single OST
2720 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2721 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2723 echo "Set user quota (limit: ${blimit}M)"
2724 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2725 error "set user quota failed"
2726 quota_show_check b u $TSTUSR
2727 echo "Update quota limits"
2728 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2729 error "set group quota failed"
2730 quota_show_check b u $TSTUSR
2732 # first wirte might be cached
2733 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2734 cancel_lru_locks osc
2736 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2737 quota_error u $TSTUSR "Write success, expect failure"
2740 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2742 test_20() { # b15754
2743 local LSTR=(2g 1t 4k 3m) # limits strings
2745 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2748 resetquota -u $TSTUSR
2750 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2751 $MOUNT || error "could not set quota limits"
2752 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2753 --inode-softlimit ${LSTR[2]} \
2754 --inode-hardlimit ${LSTR[3]} \
2755 $MOUNT || error "could not set quota limits"
2757 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2758 error "bsoftlimit was not set properly"
2759 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2760 error "bhardlimit was not set properly"
2761 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2762 error "isoftlimit was not set properly"
2763 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2764 error "ihardlimit was not set properly"
2766 resetquota -u $TSTUSR
2768 run_test 20 "Test if setquota specifiers work properly (b15754)"
2775 local time=$(($(date +%s) + seconds))
2776 while [ $(date +%s) -lt $time ]; do
2777 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2781 # run for fixing bug16053, setquota shouldn't fail when writing and
2782 # deleting are happening
2784 local TESTFILE="$DIR/$tdir/$tfile"
2785 local BLIMIT=10 # 10G
2786 local ILIMIT=1000000
2788 setup_quota_test || error "setup quota failed with $?"
2790 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2792 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2793 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2794 error "set user quota failed"
2795 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2796 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2797 error "set group quota failed"
2798 if is_project_quota_supported; then
2799 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2800 "project: $TSTPRJID"
2801 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2802 $MOUNT || error "set project quota failed"
2805 # repeat writing on a 1M file
2806 test_21_sub ${TESTFILE}_1 1 30 &
2808 # repeat writing on a 128M file
2809 test_21_sub ${TESTFILE}_2 128 30 &
2812 local time=$(($(date +%s) + 30))
2814 while [ $(date +%s) -lt $time ]; do
2815 log "Set quota for $i times"
2816 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2817 -I $((ILIMIT + i)) $MOUNT ||
2818 error "Set user quota failed"
2819 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2820 -I $((ILIMIT + i)) $MOUNT ||
2821 error "Set group quota failed"
2822 if is_project_quota_supported; then
2823 $LFS setquota -p $TSTPRJID -b 0 -B \
2824 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2825 error "Set project quota failed"
2833 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2835 if [ $count -gt 60 ]; then
2836 quota_error a $TSTUSR "dd should be finished!"
2840 echo "(dd_pid=$DDPID1, time=$count)successful"
2844 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2846 if [ $count -gt 60 ]; then
2847 quota_error a $TSTUSR "dd should be finished!"
2851 echo "(dd_pid=$DDPID2, time=$count)successful"
2853 run_test 21 "Setquota while writing & deleting (b16053)"
2855 # enable/disable quota enforcement permanently
2857 echo "Set both mdt & ost quota type as ug"
2859 is_project_quota_supported && qtype=$QTYPE
2860 set_mdt_qtype $qtype || error "enable mdt quota failed"
2861 set_ost_qtype $qtype || error "enable ost quota failed"
2864 stopall || error "failed to stopall (1)"
2868 echo "Verify if quota is enabled"
2869 local qtype1=$(mdt_quota_type)
2870 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2871 qtype=$(ost_quota_type)
2872 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2874 echo "Set both mdt & ost quota type as none"
2875 set_mdt_qtype "none" || error "disable mdt quota failed"
2876 set_ost_qtype "none" || error "disable ost quota failed"
2879 stopall || error "failed to stopall (2)"
2884 echo "Verify if quota is disabled"
2885 qtype=$(mdt_quota_type)
2886 [ $qtype != "none" ] && error "mdt quota setting is lost"
2887 qtype=$(ost_quota_type)
2888 [ $qtype != "none" ] && error "ost quota setting is lost"
2892 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2895 local TESTFILE="$DIR/$tdir/$tfile"
2898 setup_quota_test || error "setup quota failed with $?"
2900 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2903 log "User quota (limit: $LIMIT MB)"
2904 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2905 error "set quota failed"
2906 quota_show_check b u $TSTUSR
2908 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2909 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2911 log "Step1: trigger EDQUOT with O_DIRECT"
2912 log "Write half of file"
2913 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2914 quota_error u $TSTUSR "(1) Write failure, expect success." \
2916 log "Write out of block quota ..."
2917 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2918 oflag=direct conv=notrunc &&
2919 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2923 log "Step2: rewrite should succeed"
2924 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2925 quota_error u $TSTUSR "(3) Write failure, expect success." \
2931 local OST0_UUID=$(ostuuid_from_index 0)
2932 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2933 [ $OST0_QUOTA_USED -ne 0 ] &&
2934 ($SHOW_QUOTA_USER; \
2935 quota_error u $TSTUSR "quota isn't released")
2940 [ "$ost1_FSTYPE" == zfs ] &&
2941 skip "Overwrite in place is not guaranteed to be " \
2942 "space neutral on ZFS"
2944 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2945 check_whether_skip && return 0
2946 log "run for 4MB test file"
2949 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2950 check_whether_skip && return 0
2951 log "run for 40MB test file"
2954 run_test 23 "Quota should be honored with directIO (b16125)"
2958 local TESTFILE="$DIR/$tdir/$tfile"
2960 setup_quota_test || error "setup quota failed with $?"
2962 set_ost_qtype $QTYPE || error "enable ost quota failed"
2964 # bind file to a single OST
2965 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2966 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2968 echo "Set user quota (limit: ${blimit}M)"
2969 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2970 error "set quota failed"
2972 # overrun quota by root user
2973 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2974 error "write failure, expect success"
2975 cancel_lru_locks osc
2976 sync_all_data || true
2978 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2980 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2982 test_27a() { # b19612
2983 $LFS quota $TSTUSR $DIR &&
2984 error "lfs succeeded with no type, but should have failed"
2985 $LFS setquota $TSTUSR $DIR &&
2986 error "lfs succeeded with no type, but should have failed"
2989 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2991 test_27b() { # b20200
2992 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2993 error "lfs setquota failed with uid argument"
2994 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2995 error "lfs stequota failed with gid argument"
2996 if is_project_quota_supported; then
2997 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2998 1000 $DIR || error \
2999 "lfs stequota failed with projid argument"
3001 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3002 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3003 if is_project_quota_supported; then
3004 $SHOW_QUOTA_PROJID ||
3005 error "lfs quota failed with projid argument"
3007 resetquota -u $TSTID
3008 resetquota -g $TSTID
3009 resetquota -p $TSTPRJID
3012 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3017 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3018 error "lfs setquota failed"
3020 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3021 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3022 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3023 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3025 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3026 error "lfs setquota for $TSTID failed"
3028 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3029 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3030 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3031 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3033 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3034 error "total allocated inode/block limit not printed"
3036 resetquota -u $TSTUSR
3038 run_test 27c "lfs quota should support human-readable output"
3045 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3046 error "set fraction block limit failed"
3047 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3048 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3049 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3050 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3052 resetquota -u $TSTUSR
3054 run_test 27d "lfs setquota should support fraction block limit"
3058 local TESTFILE="$DIR/$tdir/$tfile"
3061 setup_quota_test || error "setup quota failed with $?"
3063 set_ost_qtype "u" || error "enable ost quota failed"
3065 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3066 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3068 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3069 $MAX_IQ_TIME $DIR || error "set grace time failed"
3070 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3071 error "set quota failed"
3072 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3073 cancel_lru_locks osc
3075 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3076 # over-quota flag has not yet settled since we do not trigger async
3077 # events based on grace time period expiration
3079 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3080 cancel_lru_locks osc
3081 # now over-quota flag should be settled and further writes should fail
3083 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3084 error "grace times were reset"
3085 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3086 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3088 run_test 30 "Hard limit updates should not reset grace times"
3090 # basic usage tracking for user & group
3092 local INODES=10 # files
3093 local BLK_CNT=2 # MB each
3094 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3096 setup_quota_test || error "setup quota failed with $?"
3098 # make sure the system is clean
3099 local USED=$(getquota -u $TSTID global curspace)
3101 error "Used space ($USED) for user $TSTID isn't 0."
3102 USED=$(getquota -g $TSTID global curspace)
3104 error "Used space ($USED) for group $TSTID isn't 0."
3105 if is_project_quota_supported; then
3106 USED=$(getquota -p $TSTPRJID global curspace)
3107 [ $USED -ne 0 ] && error \
3108 "Used space ($USED) for project $TSTPRJID isn't 0."
3111 echo "Write files..."
3112 for i in $(seq 0 $INODES); do
3113 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3114 error "write failed"
3115 is_project_quota_supported &&
3116 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3117 echo "Iteration $i/$INODES completed"
3119 cancel_lru_locks osc
3121 echo "Wait for setattr on objects finished..."
3122 wait_delete_completed
3124 sync; sync_all_data || true
3126 echo "Verify disk usage after write"
3127 USED=$(getquota -u $TSTID global curspace)
3128 [ $USED -lt $TOTAL_BLKS ] &&
3129 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3130 USED=$(getquota -g $TSTID global curspace)
3131 [ $USED -lt $TOTAL_BLKS ] &&
3132 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3133 if is_project_quota_supported; then
3134 USED=$(getquota -p $TSTPRJID global curspace)
3135 [ $USED -lt $TOTAL_BLKS ] && error \
3136 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3139 echo "Verify inode usage after write"
3140 USED=$(getquota -u $TSTID global curinodes)
3141 [ $USED -lt $INODES ] &&
3142 error "Used inode for user $TSTID is $USED, expected $INODES"
3143 USED=$(getquota -g $TSTID global curinodes)
3144 [ $USED -lt $INODES ] &&
3145 error "Used inode for group $TSTID is $USED, expected $INODES"
3146 if is_project_quota_supported; then
3147 USED=$(getquota -p $TSTPRJID global curinodes)
3148 [ $USED -lt $INODES ] && error \
3149 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3154 echo "Verify disk usage after delete"
3155 USED=$(getquota -u $TSTID global curspace)
3156 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3157 USED=$(getquota -u $TSTID global curinodes)
3158 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3159 USED=$(getquota -g $TSTID global curspace)
3160 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3161 USED=$(getquota -g $TSTID global curinodes)
3162 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3163 if is_project_quota_supported; then
3164 USED=$(getquota -p $TSTPRJID global curspace)
3166 error "Used space for project $TSTPRJID isn't 0. $USED"
3167 USED=$(getquota -p $TSTPRJID global curinodes)
3169 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3172 run_test 33 "Basic usage tracking for user & group & project"
3174 # usage transfer test for user & group & project
3176 local BLK_CNT=2 # MB
3177 local project_supported="no"
3179 is_project_quota_supported && project_supported="yes"
3180 setup_quota_test || error "setup quota failed with $?"
3182 # make sure the system is clean
3183 local USED=$(getquota -u $TSTID global curspace)
3184 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3185 USED=$(getquota -g $TSTID global curspace)
3186 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3188 local USED=$(getquota -u $TSTID2 global curspace)
3189 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3190 if [ $project_supported == "yes" ]; then
3191 USED=$(getquota -p $TSTPRJID global curspace)
3192 [ $USED -ne 0 ] && error \
3193 "Used space ($USED) for Project $TSTPRJID isn't 0."
3196 echo "Write file..."
3197 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3198 error "write failed"
3199 cancel_lru_locks osc
3200 sync; sync_all_data || true
3202 echo "chown the file to user $TSTID"
3203 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3205 echo "Wait for setattr on objects finished..."
3206 wait_delete_completed
3208 BLK_CNT=$((BLK_CNT * 1024))
3210 echo "Verify disk usage for user $TSTID"
3211 USED=$(getquota -u $TSTID global curspace)
3212 [ $USED -lt $BLK_CNT ] &&
3213 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3214 USED=$(getquota -u $TSTID global curinodes)
3216 error "Used inodes for user $TSTID is $USED, expected 1"
3218 echo "chgrp the file to group $TSTID"
3219 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3221 echo "Wait for setattr on objects finished..."
3222 wait_delete_completed
3224 echo "Verify disk usage for group $TSTID"
3225 USED=$(getquota -g $TSTID global curspace)
3226 [ $USED -ge $BLK_CNT ] ||
3227 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3228 USED=$(getquota -g $TSTID global curinodes)
3230 error "Used inodes for group $TSTID is $USED, expected 1"
3232 # chown won't change the ost object group. LU-4345 */
3233 echo "chown the file to user $TSTID2"
3234 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3236 echo "Wait for setattr on objects finished..."
3237 wait_delete_completed
3239 echo "change_project project id to $TSTPRJID"
3240 [ $project_supported == "yes" ] &&
3241 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3242 echo "Wait for setattr on objects finished..."
3243 wait_delete_completed
3245 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3246 USED=$(getquota -u $TSTID2 global curspace)
3247 [ $USED -lt $BLK_CNT ] &&
3248 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3249 USED=$(getquota -u $TSTID global curspace)
3251 error "Used space for user $TSTID is $USED, expected 0"
3252 USED=$(getquota -g $TSTID global curspace)
3253 [ $USED -lt $BLK_CNT ] &&
3254 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3255 if [ $project_supported == "yes" ]; then
3256 USED=$(getquota -p $TSTPRJID global curspace)
3257 [ $USED -lt $BLK_CNT ] && error \
3258 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3262 run_test 34 "Usage transfer for user & group & project"
3264 # usage is still accessible across restart
3266 local BLK_CNT=2 # MB
3268 setup_quota_test || error "setup quota failed with $?"
3270 echo "Write file..."
3271 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3272 error "write failed"
3273 is_project_quota_supported &&
3274 change_project -p $TSTPRJID $DIR/$tdir/$tfile
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 "Save disk usage before restart"
3283 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3284 [ $ORIG_USR_SPACE -eq 0 ] &&
3285 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3286 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3287 [ $ORIG_USR_INODES -eq 0 ] &&
3288 error "Used inodes for user $TSTID is 0, expected 1"
3289 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3290 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3291 [ $ORIG_GRP_SPACE -eq 0 ] &&
3292 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3293 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3294 [ $ORIG_GRP_INODES -eq 0 ] &&
3295 error "Used inodes for group $TSTID is 0, expected 1"
3296 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3298 if is_project_quota_supported; then
3299 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3300 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3301 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3302 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3303 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3304 "Used inodes for project $TSTPRJID is 0, expected 1"
3305 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3313 echo "Verify disk usage after restart"
3314 local USED=$(getquota -u $TSTID global curspace)
3315 [ $USED -eq $ORIG_USR_SPACE ] ||
3316 error "Used space for user $TSTID changed from " \
3317 "$ORIG_USR_SPACE to $USED"
3318 USED=$(getquota -u $TSTID global curinodes)
3319 [ $USED -eq $ORIG_USR_INODES ] ||
3320 error "Used inodes for user $TSTID changed from " \
3321 "$ORIG_USR_INODES to $USED"
3322 USED=$(getquota -g $TSTID global curspace)
3323 [ $USED -eq $ORIG_GRP_SPACE ] ||
3324 error "Used space for group $TSTID changed from " \
3325 "$ORIG_GRP_SPACE to $USED"
3326 USED=$(getquota -g $TSTID global curinodes)
3327 [ $USED -eq $ORIG_GRP_INODES ] ||
3328 error "Used inodes for group $TSTID changed from " \
3329 "$ORIG_GRP_INODES to $USED"
3330 if [ $project_supported == "yes" ]; then
3331 USED=$(getquota -p $TSTPRJID global curinodes)
3332 [ $USED -eq $ORIG_PRJ_INODES ] ||
3333 error "Used inodes for project $TSTPRJID " \
3334 "changed from $ORIG_PRJ_INODES to $USED"
3335 USED=$(getquota -p $TSTPRJID global curspace)
3336 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3337 error "Used space for project $TSTPRJID "\
3338 "changed from $ORIG_PRJ_SPACE to $USED"
3341 # check if the vfs_dq_init() is called before writing
3342 echo "Append to the same file..."
3343 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3344 error "write failed"
3345 cancel_lru_locks osc
3346 sync; sync_all_data || true
3348 echo "Verify space usage is increased"
3349 USED=$(getquota -u $TSTID global curspace)
3350 [ $USED -gt $ORIG_USR_SPACE ] ||
3351 error "Used space for user $TSTID isn't increased" \
3352 "orig:$ORIG_USR_SPACE, now:$USED"
3353 USED=$(getquota -g $TSTID global curspace)
3354 [ $USED -gt $ORIG_GRP_SPACE ] ||
3355 error "Used space for group $TSTID isn't increased" \
3356 "orig:$ORIG_GRP_SPACE, now:$USED"
3357 if [ $project_supported == "yes" ]; then
3358 USED=$(getquota -p $TSTPRJID global curspace)
3359 [ $USED -gt $ORIG_PRJ_SPACE ] ||
3360 error "Used space for project $TSTPRJID isn't " \
3361 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3364 run_test 35 "Usage is still accessible across reboot"
3366 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3369 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3370 skip "Old server doesn't have LU-5006 fix."
3372 setup_quota_test || error "setup quota failed with $?"
3374 # make sure the system is clean
3375 local USED=$(getquota -u $TSTID global curspace)
3377 error "Used space ($USED) for user $TSTID isn't 0."
3379 # create file with MDS_OPEN_DELAY_CREATE flag
3380 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3381 error "Create file failed"
3383 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
3384 oflag=sync || error "Write file failed"
3386 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3388 # wait for setattr on objects finished..."
3389 wait_delete_completed
3391 USED=$(getquota -u $TSTID global curspace)
3392 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3394 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3398 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3399 skip "Old server doesn't have LU-8801 fix."
3401 [ "$UID" != 0 ] && skip_env "must run as root" && return
3403 setup_quota_test || error "setup quota failed with $?"
3405 # make sure the system is clean
3406 local USED=$(getquota -u $TSTID global curspace)
3408 error "Used space ($USED) for user $TSTID isn't 0."
3409 USED=$(getquota -u $TSTID2 global curspace)
3411 error "Used space ($USED) for user $TSTID2 isn't 0."
3413 local TESTFILE="$DIR/$tdir/$tfile"
3414 local file_cnt=10000
3416 # Generate id entries in accounting file
3417 echo "Create $file_cnt files..."
3418 for i in `seq $file_cnt`; do
3420 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3421 error "failed to chown $TESTFILE-$i"
3423 cancel_lru_locks osc
3424 sync; sync_all_data || true
3426 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3427 procf=${procf}.quota_slave.acct_user
3430 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3431 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3432 echo "Found $acct_cnt id entries"
3434 [ $file_cnt -eq $acct_cnt ] || {
3435 do_facet mds1 $LCTL get_param $procf
3436 error "skipped id entries"
3439 run_test 38 "Quota accounting iterator doesn't skip id entries"
3442 local TESTFILE="$DIR/$tdir/project"
3443 ! is_project_quota_supported &&
3444 skip "Project quota is not supported"
3446 setup_quota_test || error "setup quota failed with $?"
3449 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3450 [ $projectid -ne 0 ] &&
3451 error "Project id should be 0 not $projectid"
3452 change_project -p 1024 $TESTFILE
3453 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3454 [ $projectid -ne 1024 ] &&
3455 error "Project id should be 1024 not $projectid"
3457 stopall || error "failed to stopall (1)"
3460 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3461 [ $projectid -eq 1024 ] ||
3462 error "Project id should be 1024 not $projectid"
3464 run_test 39 "Project ID interface works correctly"
3467 ! is_project_quota_supported &&
3468 skip "Project quota is not supported"
3469 local dir1="$DIR/$tdir/dir1"
3470 local dir2="$DIR/$tdir/dir2"
3472 setup_quota_test || error "setup quota failed with $?"
3474 mkdir -p $dir1 $dir2
3475 change_project -sp 1 $dir1 && touch $dir1/1
3476 change_project -sp 2 $dir2
3478 ln $dir1/1 $dir2/1_link &&
3479 error "Hard link across different project quota should fail"
3482 run_test 40a "Hard link across different project ID"
3485 ! is_project_quota_supported &&
3486 skip "Project quota is not supported"
3487 local dir1="$DIR/$tdir/dir1"
3488 local dir2="$DIR/$tdir/dir2"
3490 setup_quota_test || error "setup quota failed with $?"
3491 mkdir -p $dir1 $dir2
3492 change_project -sp 1 $dir1 && touch $dir1/1
3493 change_project -sp 2 $dir2
3495 mv $dir1/1 $dir2/2 || error "mv failed $?"
3496 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3497 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3499 run_test 40b "Mv across different project ID"
3502 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3503 ! is_project_quota_supported &&
3504 skip "Project quota is not supported"
3506 setup_quota_test || error "setup quota failed with $?"
3507 local dir="$DIR/$tdir/dir"
3509 mkdir -p $dir && change_project -sp 1 $dir
3510 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3511 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3512 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3513 touch $dir/remote_dir/file
3514 #verify inherit works file for remote dir.
3515 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3516 [ "$projid" != "1" ] &&
3517 error "file under remote dir expected 1 not $projid"
3519 #Agent inode should be ignored for project quota
3520 local used=$(getquota -p 1 global curinodes)
3522 error "file count expected 3 got $used"
3524 run_test 40c "Remote child Dir inherit project quota properly"
3527 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3528 is_project_quota_supported || skip "Project quota is not supported"
3530 setup_quota_test || error "setup quota failed with $?"
3531 local dir="$DIR/$tdir/dir"
3534 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3535 change_project -sp $TSTPRJID $dir ||
3536 error "change project on $dir failed"
3537 for i in $(seq 5); do
3538 mkdir -p $dir/d$i/d$i ||
3539 error "mkdir $dir/d$i/d$i failed"
3540 local projid=$($LFS project -d $dir/d$i/d$i |
3542 [ "$projid" == "$TSTPRJID" ] ||
3543 error "projid id expected $TSTPRJID not $projid"
3544 touch $dir/d$i/d$i/file
3545 #verify inherit works file for stripe dir.
3546 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3547 [ "$projid" == "$TSTPRJID" ] ||
3548 error "file under remote dir expected 1 not $projid"
3551 # account should be 1 + (2 + 1) *10 + 1 * 5
3552 local used=$(getquota -p $TSTPRJID global curinodes)
3554 error "file count expected 36 got $used"
3556 run_test 40d "Stripe Directory inherit project quota properly"
3559 is_project_quota_supported ||
3560 skip "Project quota is not supported"
3561 setup_quota_test || error "setup quota failed with $?"
3562 local dir="$DIR/$tdir/dir"
3565 local projid=$((testnum * 1000))
3569 # enable mdt/ost quota
3570 set_mdt_qtype ugp || error "enable mdt quota failed"
3571 set_ost_qtype ugp || error "enable ost quota failed"
3573 test_mkdir -p $dir && change_project -sp $projid $dir
3574 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3575 error "set project quota failed"
3580 # check if df output works as expected
3581 echo "== global statfs: $MOUNT =="
3582 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3584 echo "== project statfs (prjid=$projid): $dir =="
3585 df -kP $dir; df -iP $dir
3586 local bused=$(getquota -p $projid global curspace)
3587 local iused=$(getquota -p $projid global curinodes)
3588 # note trailing space to match double printf from awk
3589 local expected="$blimit $bused $ilimit $iused "
3591 wait_update $HOSTNAME \
3592 "{ df -kP $dir; df -iP $dir; } |
3593 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3595 error "failed to get correct statfs for project quota"
3597 run_test 41 "df should return projid-specific values"
3605 local osd="osd-ldiskfs"
3607 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3609 rm -f $DIR/$tdir/$tfile
3610 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3611 chmod a+rw $DIR/$tdir/$tfile
3613 $LFS setquota $qtype $qid -B 300M $MOUNT
3614 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3615 error "failed to dd"
3617 do_facet $SINGLEMDS \
3618 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3619 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3622 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3623 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3625 $LFS setquota $qtype $qid --delete $MOUNT
3626 do_facet $SINGLEMDS \
3627 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3628 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3631 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3632 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3634 $LFS setquota $qtype $qid -B 500M $MOUNT
3635 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
3636 error "failed to dd"
3637 do_facet $SINGLEMDS \
3638 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3639 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3640 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3642 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3643 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3648 setup_quota_test || error "setup quota failed with $?"
3649 set_ost_qtype $QTYPE || error "enable ost quota failed"
3652 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3653 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3654 is_project_quota_supported &&
3655 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3659 run_test 48 "lfs quota --delete should delete quota project ID"
3662 ! is_project_quota_supported &&
3663 skip "Project quota is not supported"
3665 setup_quota_test || error "setup quota failed with $?"
3666 local dir1="$DIR/$tdir/dir1"
3667 local dir2="$DIR/$tdir/dir2"
3669 mkdir -p $dir1 && change_project -sp 1 $dir1
3670 mkdir -p $dir2 && change_project -sp 2 $dir2
3671 for num in $(seq 1 10); do
3672 touch $dir1/file_$num $dir2/file_$num
3673 ln -s $dir1/file_$num $dir1/file_$num"_link"
3674 ln -s $dir2/file_$num $dir2/file_$num"_link"
3677 count=$($LFS find --projid 1 $DIR | wc -l)
3678 [ "$count" != 21 ] && error "expected 21 but got $count"
3680 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3681 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3682 [ $count -eq 22 ] || error "expected 22 but got $count"
3684 run_test 50 "Test if lfs find --projid works"
3687 ! is_project_quota_supported &&
3688 skip "Project quota is not supported"
3689 setup_quota_test || error "setup quota failed with $?"
3690 local dir="$DIR/$tdir/dir"
3692 mkdir $dir && change_project -sp 1 $dir
3693 local used=$(getquota -p 1 global curinodes)
3694 [ $used != "1" ] && error "expected 1 got $used"
3699 used=$(getquota -p 1 global curinodes)
3700 [ $used != "4" ] && error "expected 4 got $used"
3702 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
3704 cp $DIR/$tdir/6 $dir/6
3705 used=$(getquota -p 1 global curinodes)
3706 [ $used != "5" ] && error "expected 5 got $used"
3709 mv $DIR/$tdir/6 $dir/7
3710 used=$(getquota -p 1 global curinodes)
3711 [ $used -eq 6 ] || error "expected 6 got $used"
3713 run_test 51 "Test project accounting with mv/cp"
3716 ! is_project_quota_supported &&
3717 skip "Project quota is not supported"
3719 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
3720 skip "Need MDS version at least 2.14.55"
3722 setup_quota_test || error "setup quota failed with $?"
3724 local dir1=$DIR/$tdir/t52_dir1
3725 local dir2=$DIR/$tdir/t52_dir2
3727 mkdir $dir1 || error "failed to mkdir $dir1"
3728 mkdir $dir2 || error "failed to mkdir $dir2"
3730 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
3731 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
3733 $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
3734 error "failed to create and write $tdir1/$tfile"
3736 cancel_lru_locks osc
3737 sync; sync_all_data || true
3739 local attrs=($(lsattr -p $dir1/$tfile))
3740 (( ${attrs[0]} == 1000 )) ||
3741 error "project ID on $dir1/$tfile is not inherited"
3743 $LFS quota -p 1000 $DIR
3744 $LFS quota -p 1001 $DIR
3746 local prev_used=$(getquota -p 1000 global curspace)
3747 local prev_used2=$(getquota -p 1001 global curspace)
3749 mrename $dir1 $dir2/tdir || log "rename directory return $?"
3751 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
3752 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
3753 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
3755 attrs=($(lsattr -p $dir2/$tfile))
3756 (( ${attrs[0]} == 1001 )) ||
3757 error "project ID is not updated after rename"
3759 (( $inum_before == $inum_after )) ||
3760 error "inode is changed after rename: $inum_before, $inum_after"
3762 sync_all_data || true
3764 $LFS quota -p 1000 $DIR
3765 $LFS quota -p 1001 $DIR
3767 local new_used=$(getquota -p 1000 global curspace)
3768 local new_used2=$(getquota -p 1001 global curspace)
3770 (( $prev_used >= $new_used + 102400 )) ||
3771 error "quota is not deducted from old project ID"
3772 (( $prev_used2 <= $new_used2 - 102400 )) ||
3773 error "quota is not added for the new project ID"
3775 run_test 52 "Rename normal file across project ID"
3778 ! is_project_quota_supported &&
3779 skip "Project quota is not supported"
3780 setup_quota_test || error "setup quota failed with $?"
3781 local dir="$DIR/$tdir/dir"
3782 mkdir $dir && change_project -s $dir
3783 [[ $($LFS project -d $dir) =~ " P " ]] ||
3784 error "inherit attribute should be set"
3786 change_project -C $dir
3787 [[ $($LFS project -d $dir) =~ " - " ]] ||
3788 error "inherit attribute should be cleared"
3790 run_test 53 "Project inherit attribute could be cleared"
3793 ! is_project_quota_supported &&
3794 skip "Project quota is not supported"
3795 setup_quota_test || error "setup quota failed with $?"
3796 local testfile="$DIR/$tdir/$tfile-0"
3798 #set project ID/inherit attribute
3799 change_project -sp $TSTPRJID $DIR/$tdir
3800 $RUNAS createmany -m ${testfile} 100 ||
3801 error "create many files failed"
3803 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3804 # one more count for directory itself */
3808 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3809 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3811 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3812 [ $proj_count1 -eq $proj_count ] ||
3813 error "c2: expected $proj_count got $proj_count1"
3815 #clear project but with kept projid
3816 change_project -rCk $DIR/$tdir
3817 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3818 [ $proj_count1 -eq 1 ] ||
3819 error "c3: expected 1 got $proj_count1"
3821 #verify projid untouched.
3822 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3824 [ $proj_count1 -eq $proj_count ] ||
3825 error "c4: expected $proj_count got $proj_count1"
3828 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3829 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3830 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3832 #this time clear all
3833 change_project -rC $DIR/$tdir
3834 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3835 [ $proj_count1 -eq 0 ] ||
3836 error "c6: expected 0 got $proj_count1"
3838 unlinkmany ${testfile} 100 ||
3839 error "unlink many files failed"
3841 run_test 54 "basic lfs project interface test"
3844 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3845 skip "Not supported before 2.10.58."
3846 setup_quota_test || error "setup quota failed with $?"
3848 set_ost_qtype $QTYPE || error "enable ost quota failed"
3851 #add second group to TSTUSR
3852 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3855 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3856 error "failed to dd"
3858 cancel_lru_locks osc
3859 sync; sync_all_data || true
3861 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3862 error "failed to setquota on group $TSTUSR2"
3864 $LFS quota -v -g $TSTUSR2 $DIR
3866 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3867 error "chgrp should failed with -EDQUOT"
3869 USED=$(getquota -g $TSTUSR2 global curspace)
3872 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3873 error "failed to setquota on group $TSTUSR2"
3875 $LFS quota -v -g $TSTUSR2 $DIR
3877 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3878 error "chgrp should succeed"
3880 $LFS quota -v -g $TSTUSR2 $DIR
3882 run_test 55 "Chgrp should be affected by group quota"
3885 setup_quota_test || error "setup quota failed with $?"
3887 set_ost_qtype $QTYPE || error "enable ost quota failed"
3890 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3891 erro "failed to set grace time for usr quota"
3892 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3893 awk '{print $4 $8}')
3894 if [ "x$grace_time" != "x10s;10s" ]; then
3895 $LFS quota -t -u $DIR
3896 error "expected grace time: 10s;10s, got:$grace_time"
3899 run_test 56 "lfs quota -t should work well"
3902 setup_quota_test || error "setup quota failed with $?"
3904 local dir="$DIR/$tdir/dir"
3907 #command can process further if it hit some errors
3908 $LFS project -sp 1 $dir/pipe
3909 touch $dir/aaa $dir/bbb
3910 mkdir $dir/subdir -p
3911 touch $dir/subdir/aaa $dir/subdir/bbb
3912 #create one invalid link file
3913 ln -s $dir/not_exist_file $dir/ccc
3914 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3915 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
3917 run_test 57 "lfs project could tolerate errors"
3920 [ "$mds1_FSTYPE" != ldiskfs ] &&
3921 skip "ldiskfs only test"
3922 disable_project_quota
3923 setup_quota_test || error "setup quota failed with $?"
3926 local testfile="$DIR/$tdir/$tfile-0"
3927 #make sure it did not crash kernel
3928 touch $testfile && lfs project -sp 1 $testfile
3930 enable_project_quota
3932 run_test 59 "lfs project dosen't crash kernel with project disabled"
3935 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3936 skip "Needs MDS version 2.11.53 or later."
3937 setup_quota_test || error "setup quota failed with $?"
3939 local testfile=$DIR/$tdir/$tfile
3942 set_mdt_qtype "ug" || error "enable mdt quota failed"
3944 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3945 error "set quota failed"
3946 quota_show_check a g $TSTUSR
3948 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3949 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3950 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3951 error "create many files failed"
3953 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3955 # root user can overrun quota
3956 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3957 error "root user should succeed"
3959 run_test 60 "Test quota for root with setgid"
3961 # test default quota
3962 test_default_quota() {
3963 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3964 skip "Not supported before 2.11.51."
3969 local qprjid=$TSTPRJID
3973 local LIMIT=20480 #20M disk space
3974 local TESTFILE="$DIR/$tdir/$tfile-0"
3977 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3978 echo "Project quota is not supported" && return 0
3980 [ $qtype == "-u" ] && qdtype="-U"
3981 [ $qtype == "-g" ] && qdtype="-G"
3982 [ $qtype == "-p" ] && {
3987 [ $qres_type == "meta" ] && {
3988 LIMIT=10240 #10K inodes
3993 qpool_cmd="--pool $3"
3994 # pool quotas don't work properly without global limit
3995 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
3996 error "set global limit failed"
3999 setup_quota_test || error "setup quota failed with $?"
4003 # enable mdt/ost quota
4004 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4005 set_ost_qtype $QTYPE || error "enable ost quota failed"
4007 log "set to use default quota"
4008 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4009 error "set $qid to use default quota failed"
4011 log "set default quota"
4012 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4013 error "set $qid default quota failed"
4015 log "get default quota"
4016 $LFS quota $qdtype $DIR || error "get default quota failed"
4018 if [ $qres_type == "data" ]; then
4019 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4020 grep "$MOUNT" | awk '{print $2}')
4021 [ $SLIMIT -eq $LIMIT ] ||
4022 error "the returned default quota is wrong"
4024 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4026 [ $SLIMIT -eq $LIMIT ] ||
4027 error "the returned default quota is wrong"
4030 # make sure the system is clean
4031 local USED=$(getquota $qtype $qid global curspace)
4032 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4034 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4035 error "setstripe $TESTFILE failed"
4036 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4038 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4040 log "Test not out of quota"
4041 if [ $qres_type == "data" ]; then
4042 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4043 quota_error $qtype $qid "write failed, expect succeed"
4045 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4046 quota_error $qtype $qid "create failed, expect succeed"
4048 unlinkmany $TESTFILE $((LIMIT/2))
4051 log "Test out of quota"
4052 # flush cache, ensure noquota flag is set on client
4053 cancel_lru_locks osc
4054 cancel_lru_locks mdc
4055 sync; sync_all_data || true
4056 if [ $qres_type == "data" ]; then
4057 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4058 quota_error $qtype $qid "write succeed, expect EDQUOT"
4060 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4061 quota_error $qtype $qid "create succeed, expect EDQUOT"
4063 unlinkmany $TESTFILE $((LIMIT*2))
4067 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4068 error "setstripe $TESTFILE failed"
4069 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4071 log "Increase default quota"
4073 # LU-4505: sleep 5 seconds to enable quota acquire
4076 # increase default quota
4077 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4078 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4080 cancel_lru_locks osc
4081 cancel_lru_locks mdc
4082 sync; sync_all_data || true
4083 if [ $qres_type == "data" ]; then
4084 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4085 quota_error $qtype $qid "write failed, expect succeed"
4087 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4088 quota_error $qtype $qid "create failed, expect succeed"
4090 unlinkmany $TESTFILE $((LIMIT*2))
4093 log "Set quota to override default quota"
4094 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4095 error "set $qid quota failed"
4097 cancel_lru_locks osc
4098 cancel_lru_locks mdc
4099 sync; sync_all_data || true
4100 if [ $qres_type == "data" ]; then
4101 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4102 quota_error $qtype $qid "write succeed, expect EQUOT"
4104 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4105 quota_error $qtype $qid "create succeed, expect EQUOT"
4107 unlinkmany $TESTFILE $((LIMIT*2))
4110 log "Set to use default quota again"
4112 # LU-4505: sleep 5 seconds to enable quota acquire
4115 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4116 error "set $qid to use default quota failed"
4118 cancel_lru_locks osc
4119 cancel_lru_locks mdc
4120 sync; sync_all_data || true
4121 if [ $qres_type == "data" ]; then
4122 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4123 quota_error $qtype $qid "write failed, expect succeed"
4125 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4126 quota_error $qtype $qid "create failed, expect succeed"
4128 unlinkmany $TESTFILE $((LIMIT*2))
4133 wait_delete_completed || error "wait_delete_completed failed"
4134 sync_all_data || true
4136 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4137 error "reset default quota failed"
4138 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4139 error "reset quota failed"
4144 test_default_quota "-u" "data"
4145 test_default_quota "-u" "meta"
4146 test_default_quota "-g" "data"
4147 test_default_quota "-g" "meta"
4148 test_default_quota "-p" "data"
4149 test_default_quota "-p" "meta"
4151 run_test 61 "default quota tests"
4154 ! is_project_quota_supported &&
4155 skip "Project quota is not supported"
4156 [[ "$(chattr -h 2>&1)" =~ "project" ||
4157 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4158 skip "chattr did not support project quota"
4159 setup_quota_test || error "setup quota failed with $?"
4160 local testdir=$DIR/$tdir/
4162 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4163 change_project -s $testdir
4164 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4165 error "inherit attribute should be set"
4166 # chattr used FS_IOC_SETFLAGS ioctl
4167 $RUNAS chattr -P $testdir &&
4168 error "regular user clear inherit should fail"
4169 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4170 error "inherit attribute should still be set"
4171 chattr -P $testdir || error "root failed to clear inherit"
4172 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4173 error "inherit attribute should be cleared"
4176 run_test 62 "Project inherit should be only changed by root"
4179 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4180 skip "Not supported before 2.11.55"
4184 local dd_failed=false
4185 local tdir_dom=${tdir}_dom
4186 local LIMIT=20480 #20M
4188 [ $qtype == "p" ] && ! is_project_quota_supported &&
4189 echo "Project quota is not supported" && return 0
4191 [ $qtype == "p" ] && qid=$TSTPRJID
4193 setup_quota_test || error "setup quota failed with $?"
4197 # enable mdt/ost quota
4198 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4199 set_ost_qtype $QTYPE || error "enable ost quota failed"
4201 # make sure the system is clean
4202 local USED=$(getquota -$qtype $qid global curspace)
4203 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4205 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4207 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4208 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4209 error "setstripe $tdir_dom failed"
4210 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4212 [ $qtype == "p" ] && {
4213 change_project -sp $TSTPRJID $DIR/$tdir
4214 change_project -sp $TSTPRJID $DIR/$tdir_dom
4217 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4218 error "set $qid quota failed"
4220 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4221 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4225 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4227 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4228 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4232 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4234 rm -f $DIR/$tdir_dom/*
4236 # flush cache, ensure noquota flag is set on client
4237 cancel_lru_locks osc
4238 cancel_lru_locks mdc
4239 sync; sync_all_data || true
4243 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4244 quota_error $qtype $qid "write failed, expect succeed"
4246 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4247 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4251 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4254 rm -f $DIR/$tdir_dom/*
4256 # flush cache, ensure noquota flag is set on client
4257 cancel_lru_locks osc
4258 cancel_lru_locks mdc
4259 sync; sync_all_data || true
4263 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4264 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4268 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4270 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4271 quota_error $qtype $qid "write succeed, expect EDQUOT"
4274 rm -fr $DIR/$tdir_dom
4276 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4277 error "reset usr quota failed"
4285 run_test 63 "quota on DoM tests"
4288 ! is_project_quota_supported &&
4289 skip "Project quota is not supported"
4290 setup_quota_test || error "setup quota failed with $?"
4291 local dir1="$DIR/$tdir/"
4294 ln -s $dir1/file $dir1/file_link
4297 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4298 error "set project should succeed"
4300 used=$(getquota -p $TSTPRJID global curinodes)
4301 [ $used -eq 4 ] || error "expected 4 got $used"
4302 $LFS project -rC $dir1 >&/dev/null ||
4303 error "clear project should succeed"
4305 used=$(getquota -p $TSTPRJID global curinodes)
4306 [ $used -eq 0 ] || error "expected 0 got $used"
4308 run_test 64 "lfs project on non dir/files should succeed"
4312 local TESTFILE="$DIR/$tdir/$tfile-0"
4314 setup_quota_test || error "setup quota failed with $?"
4315 set_ost_qtype $QTYPE || error "enable ost quota failed"
4319 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4320 error "failed to write"
4321 # flush cache, ensure noquota flag is set on client
4322 cancel_lru_locks osc
4323 sync; sync_all_data || true
4325 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4326 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4327 local quota_all=$($RUNAS $LFS quota $DIR)
4329 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4330 error "usr quota not match"
4331 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4332 error "grp quota not match"
4334 run_test 65 "Check lfs quota result"
4337 ! is_project_quota_supported &&
4338 skip "Project quota is not supported"
4339 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4340 skip "Not supported before 2.12.4"
4341 setup_quota_test || error "setup quota failed with $?"
4342 local old=$(do_facet mds1 $LCTL get_param -n \
4343 mdt.*.enable_chprojid_gid | head -1)
4344 local testdir=$DIR/$tdir/foo
4346 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4347 stack_trap "do_facet mds1 $LCTL \
4348 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4350 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4351 chown -R $TSTID:$TSTID $testdir
4352 change_project -sp $TSTPRJID $testdir
4353 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4355 $RUNAS lfs project -p 0 $testdir/foo &&
4356 error "nonroot user should fail to set projid"
4358 $RUNAS lfs project -C $testdir/foo &&
4359 error "nonroot user should fail to clear projid"
4361 change_project -C $testdir/foo || error "failed to clear project"
4363 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4364 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4365 "failed to set projid with normal user when enable_chprojid_gid=-1"
4367 $RUNAS lfs project -rC $testdir/ || error \
4368 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4370 touch $testdir/bar || error "failed touch $testdir/bar"
4371 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4372 "normal user should not be able to set projid on root owned file"
4374 change_project -p $TSTPRJID $testdir/bar || error \
4375 "root should be able to change its own file's projid"
4377 run_test 66 "nonroot user can not change project state in default"
4384 local short_qtype=${qtype:0:1}
4387 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4389 quota_usr) _runas=$RUNAS;;
4390 quota_2usr) _runas=$RUNAS2;;
4391 *) error "unknown quota parameter $4";;
4396 $_runas $DD of=$file count=$size ||
4397 quota_error $short_qtype $TSTUSR \
4398 "$qtype write failure, but expect success"
4400 cancel_lru_locks osc
4402 sync; sync_all_data || true
4411 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4413 do_facet mds1 $LCTL get_param $param |
4414 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4419 local testfile="$DIR/$tdir/$tfile-0"
4420 local testfile2="$DIR/$tdir/$tfile-1"
4421 local testfile3="$DIR/$tdir/$tfile-2"
4422 local qpool="qpool1"
4428 [ "$ost1_FSTYPE" == zfs ] &&
4429 skip "ZFS grants some block space together with inode"
4431 setup_quota_test || error "setup quota failed with $?"
4434 set_ost_qtype $QTYPE || error "enable ost quota failed"
4437 log "User quota (block hardlimit:$limit MB)"
4438 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4439 error "set user quota failed"
4441 # make sure the system is clean
4442 used=$(getquota -u $TSTUSR global curspace)
4443 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4445 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4446 echo "granted 0x0 before write $granted"
4448 # trigger reintegration
4449 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4450 procf=${procf}quota_slave.force_reint
4451 do_facet ost1 $LCTL set_param $procf=1 ||
4452 error "force reintegration failed"
4453 wait_ost_reint "u" || error "reintegration failed"
4454 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4455 [ $granted -ne 0 ] &&
4456 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4458 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4459 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4461 # write 10 MB to testfile
4462 test_67_write "$testfile" "user" 10 "quota_usr"
4464 # create qpool and add OST1
4465 pool_add $qpool || error "pool_add failed"
4466 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4467 # as quota_usr hasn't limits, lqe may absent. But it should be
4468 # created after the 1st direct qmt_get.
4469 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4471 # check granted - should be 0, as testfile is located only on OST0
4472 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4473 echo "global granted $granted"
4474 granted=$(getgranted $qpool "dt" $TSTID "usr")
4475 echo "$qpool granted $granted"
4476 [ $granted -ne 0 ] &&
4477 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4479 # add OST0 to qpool and check granted space
4480 pool_add_targets $qpool 0 1 ||
4481 error "pool_add_targets failed"
4482 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4483 echo "Granted $granted_mb MB"
4484 #should be 10M + qunit for each OST
4485 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4486 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4488 $LFS setstripe $testfile2 -c 1 -i 1 ||
4489 error "setstripe $testfile2 failed"
4490 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4491 # Write from another user and check that qpool1
4492 # shows correct granted, despite quota_2usr hasn't limits in qpool1.
4493 test_67_write "$testfile2" "user" 10 "quota_2usr"
4494 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4495 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4496 [ $granted -ne 0 ] &&
4497 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4499 # Granted space for quota_2usr in qpool1 should appear only
4500 # when global lqe for this user becomes enforced.
4501 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4502 error "set user quota failed"
4503 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4504 echo "granted_mb $granted_mb"
4505 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4506 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4508 $LFS setstripe $testfile3 -c 1 -i 0 ||
4509 error "setstripe $testfile3 failed"
4510 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4511 test_67_write "$testfile3" "user" 10 "quota_2usr"
4512 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4513 echo "$testfile3 granted_mb $granted_mb"
4514 [ $granted_mb -eq $limit ] ||
4515 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4517 # remove OST1 from the qpool1 and check granted space
4518 # should be 0 for TSTUSR and 10M for TSTUSR2
4519 pool_remove_target $qpool 0
4520 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4521 [ $granted_mb -eq 0 ] ||
4522 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4523 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4524 [ $granted_mb -eq 10 ] ||
4525 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4528 wait_delete_completed || error "wait_delete_completed failed"
4529 sync_all_data || true
4530 used=$(getquota -u $TSTUSR global curspace)
4531 [ $used -eq 0 ] || quota_error u $TSTUSR \
4532 "user quota isn't released after deletion"
4534 run_test 67 "quota pools recalculation"
4541 wait_update_facet mds1 \
4542 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4543 >/dev/null 2>&1 || echo foo" "" ||
4544 error "mds1: failed to create quota pool $pool"
4546 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4547 awk '/usr/ {getline; print $2}'
4552 local qpool="qpool1"
4555 setup_quota_test || error "setup quota failed with $?"
4558 set_ost_qtype $QTYPE || error "enable ost quota failed"
4560 # check slave number for glbal pool
4561 local nr=$(get_slave_nr "0x0" "usr")
4562 echo "nr result $nr"
4563 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4564 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4566 # create qpool and add OST1
4567 pool_add $qpool || error "pool_add failed"
4568 nr=$(get_slave_nr $qpool "usr")
4569 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4572 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4573 nr=$(get_slave_nr $qpool "usr")
4574 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4577 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4578 nr=$(get_slave_nr $qpool "usr")
4579 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4582 pool_remove_target $qpool 0
4583 nr=$(get_slave_nr $qpool "usr")
4584 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4587 pool_remove_target $qpool 1
4588 nr=$(get_slave_nr $qpool "usr")
4589 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4591 # Check again that all is fine with global pool
4592 nr=$(get_slave_nr "0x0" "usr")
4593 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4594 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4596 run_test 68 "slave number in quota pool changed after each add/remove OST"
4600 local global_limit=200 # MB
4602 local testfile="$DIR/$tdir/$tfile-0"
4603 local dom0="$DIR/$tdir/dom0"
4604 local qpool="qpool1"
4607 setup_quota_test || error "setup quota failed with $?"
4610 set_ost_qtype $QTYPE || error "enable ost quota failed"
4611 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4613 # Save DOM only at MDT0
4614 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4615 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4617 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4619 # create qpool and add OST0
4620 pool_add $qpool || error "pool_add failed"
4621 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4623 log "User quota (block hardlimit:$global_limit MB)"
4624 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4625 error "set user quota failed"
4627 log "User quota (block hardlimit:$limit MB)"
4628 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4629 error "set user quota failed"
4631 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4632 quota_error u $TSTUSR "write failed"
4634 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4635 oflag=sync || quota_error u $TSTUSR "write failed"
4637 $RUNAS $DD of=$testfile count=$limit || true
4639 # flush cache, ensure noquota flag is set on client
4640 cancel_lru_locks osc
4641 sync; sync_all_data || true
4643 # MDT0 shouldn't get EDQUOT with glimpse.
4644 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4645 quota_error u $TSTUSR \
4646 "user write success, but expect EDQUOT"
4648 # Now all members of qpool1 should get EDQUOT. Expect success
4649 # when write to DOM on MDT0, as it belongs to global pool.
4650 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4651 oflag=sync || quota_error u $TSTUSR "write failed"
4653 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4654 oflag=sync || quota_error u $TSTUSR "write failed"
4656 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4660 local qpool="qpool1"
4665 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4666 skip "Needs a client >= $VERSION_WITH_QP"
4668 setup_quota_test || error "setup quota failed with $?"
4670 # MDS returns EFAULT for unsupported quotactl command
4671 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4673 # create qpool and add OST0
4674 pool_add $qpool || error "pool_add failed"
4675 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4677 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4679 [ $rc -eq $err ] || error "setquota res $rc != $err"
4681 # If MDS supports QP, check that limit was set properly.
4682 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4683 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4684 echo "hard limit $bhard limit $limit"
4685 [ $bhard -ne $((limit*1024)) ] &&
4686 error "bhard:$bhard for $qpool!=$((limit*1024))"
4689 $LFS quota -u $TSTUSR --pool $qpool $DIR
4691 [ $rc -eq $err ] || error "quota res $rc != $err"
4693 run_test 70a "check lfs setquota/quota with a pool option"
4697 local glbl_hard=200 # 200M
4698 local glbl_soft=100 # 100M
4699 local pool_hard=10 # 10M
4700 local qpool="qpool1"
4702 pool_add $qpool || error "pool_add failed"
4703 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4705 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
4706 error "set user quota failed"
4707 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
4708 error "set user quota failed"
4710 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4711 [ $tmp -eq $((pool_hard * 1024)) ] ||
4712 error "wrong block hard limit $tmp for $qpool"
4713 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
4714 # soft limit hasn't been set and should be zero
4715 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
4717 run_test 70b "lfs setquota pool works properly"
4722 local global_limit=100 # MB
4723 local testfile="$DIR/$tdir/$tfile-0"
4724 local qpool="qpool1"
4725 local qpool2="qpool2"
4727 [ "$ost1_FSTYPE" == zfs ] &&
4728 skip "ZFS grants some block space together with inode"
4729 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
4731 setup_quota_test || error "setup quota failed with $?"
4734 set_ost_qtype $QTYPE || error "enable ost quota failed"
4737 log "User quota (block hardlimit:$global_limit MB)"
4738 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4739 error "set user quota failed"
4741 pool_add $qpool || error "pool_add failed"
4742 pool_add_targets $qpool 0 1 ||
4743 error "pool_add_targets failed"
4745 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4746 error "set user quota failed"
4748 pool_add $qpool2 || error "pool_add failed"
4749 pool_add_targets $qpool2 1 1 ||
4750 error "pool_add_targets failed"
4752 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
4753 error "set user quota failed"
4755 # make sure the system is clean
4756 local used=$(getquota -u $TSTUSR global curspace)
4759 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4761 # create 1st component 1-10M
4762 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4763 #create 2nd component 10-30M
4764 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4765 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4767 # сheck normal use and out of quota with PFL
4768 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
4769 test_1_check_write $testfile "user" $((limit*2))
4771 wait_delete_completed || error "wait_delete_completed failed"
4772 sync_all_data || true
4773 used=$(getquota -u $TSTUSR global curspace)
4774 [ $used -ne 0 ] && quota_error u $TSTUSR \
4775 "user quota isn't released after deletion"
4777 # create 1st component 1-10M
4778 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
4779 # create 2nd component 10-30M
4780 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
4781 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4783 # write to the 2nd component
4784 $RUNAS $DD of=$testfile count=$limit seek=10 ||
4785 quota_error u $TSTUSR \
4786 "write failure, but expect success"
4787 # this time maybe cache write, ignore it's failure
4788 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
4789 cancel_lru_locks osc
4790 sync; sync_all_data || true
4791 # write over limit in qpool2(2nd component 10-30M)
4792 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
4793 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4794 # write to the 1st component - OST0 is empty
4795 $RUNAS $DD of=$testfile count=$limit seek=0 ||
4796 quota_error u $TSTUSR "write failed"
4798 run_test 71a "Check PFL with quota pools"
4802 local global_limit=1000 # MB
4803 local limit1=160 # MB
4804 local limit2=10 # MB
4805 local testfile="$DIR/$tdir/$tfile-0"
4806 local qpool="qpool1"
4807 local qpool2="qpool2"
4809 [ "$ost1_FSTYPE" == zfs ] &&
4810 skip "ZFS grants some block space together with inode"
4811 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
4813 setup_quota_test || error "setup quota failed with $?"
4816 set_ost_qtype $QTYPE || error "enable ost quota failed"
4819 log "User quota (block hardlimit:$global_limit MB)"
4820 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4821 error "set user quota failed"
4823 pool_add $qpool || error "pool_add failed"
4824 pool_add_targets $qpool 0 1 ||
4825 error "pool_add_targets failed"
4827 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
4828 error "set user quota failed"
4830 pool_add $qpool2 || error "pool_add failed"
4831 pool_add_targets $qpool2 1 1 ||
4832 error "pool_add_targets failed"
4834 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4835 error "set user quota failed"
4837 # make sure the system is clean
4838 local used=$(getquota -u $TSTUSR global curspace)
4841 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4843 # First component is on OST0, 2nd on OST1
4844 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
4845 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4847 # fill the 1st component on OST0
4848 $RUNAS $DD of=$testfile count=128 ||
4849 quota_error u $TSTUSR "write failed"
4850 # write to the 2nd cmpnt on OST1
4851 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
4852 quota_error u $TSTUSR "write failed"
4853 # this time maybe cache write, ignore it's failure
4854 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
4856 cancel_lru_locks osc
4857 sync; sync_all_data || true
4858 # write over limit in qpool2
4859 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
4860 quota_error u $TSTUSR "user write success, but expect EDQUOT"
4863 run_test 71b "Check SEL with quota pools"
4868 local global_limit=50 # MB
4869 local testfile="$DIR/$tdir/$tfile-0"
4870 local qpool="qpool1"
4873 setup_quota_test || error "setup quota failed with $?"
4876 set_ost_qtype $QTYPE || error "enable ost quota failed"
4879 log "User quota (block hardlimit:$global_limit MB)"
4880 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4881 error "set user quota failed"
4883 pool_add $qpool || error "pool_add failed"
4884 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4886 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4887 error "set user quota failed"
4889 # make sure the system is clean
4890 local used=$(getquota -u $TSTUSR global curspace)
4892 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4894 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4896 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
4897 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4898 test_1_check_write $testfile "user" $limit
4899 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4901 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
4902 # check that lfs quota -uv --pool prints only OST that
4903 # was added in a pool
4904 lfs quota -v -u quota_usr --pool $qpool $DIR | grep -v "OST0001" |
4905 grep "OST\|MDT" && error "$qpool consists wrong targets"
4908 run_test 72 "lfs quota --pool prints only pool's OSTs"
4912 local qpool="qpool1"
4916 pool_add $qpool || error "pool_add failed"
4917 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4918 error "pool_add_targets failed"
4920 test_default_quota "-u" "data" "qpool1"
4922 run_test 73a "default limits at OST Pool Quotas"
4926 local TESTFILE1="$DIR/$tdir/$tfile-1"
4928 local qpool="qpool1"
4932 setup_quota_test || error "setup quota failed with $?"
4934 set_ost_qtype $QTYPE || error "enable ost quota failed"
4936 # pool quotas don't work properly without global limit
4937 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4938 error "set global limit failed"
4940 pool_add $qpool || error "pool_add failed"
4941 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
4942 error "pool_add_targets failed"
4944 log "set default quota for $qpool"
4945 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
4946 error "set default quota failed"
4948 log "Write from user that hasn't lqe"
4949 # Check that it doesn't cause a panic or a deadlock
4950 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
4951 # Have to use RUNAS_ID as resetquota creates lqes in
4952 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
4953 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
4955 cancel_lru_locks osc
4956 sync; sync_all_data || true
4958 run_test 73b "default OST Pool Quotas limit for new user"
4962 local global_limit=200 # 200M
4963 local limit=10 # 10M
4964 local limit2=50 # 50M
4965 local qpool="qpool1"
4966 local qpool2="qpool2"
4970 setup_quota_test || error "setup quota failed with $?"
4973 set_ost_qtype $QTYPE || error "enable ost quota failed"
4975 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4976 error "set user quota failed"
4978 pool_add $qpool || error "pool_add failed"
4979 pool_add_targets $qpool 0 1 ||
4980 error "pool_add_targets failed"
4982 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4983 error "set user quota failed"
4985 pool_add $qpool2 || error "pool_add failed"
4986 pool_add_targets $qpool2 1 1 ||
4987 error "pool_add_targets failed"
4989 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
4990 error "set user quota failed"
4992 tmp=$(getquota -u $TSTUSR global bhardlimit)
4993 [ $tmp -eq $((global_limit * 1024)) ] ||
4994 error "wrong global limit $global_limit"
4996 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
4997 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
4999 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5000 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5002 # check limits in pools
5003 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5004 grep -A4 $qpool | awk 'NR == 4{print $4}')
5005 echo "pool limit for $qpool $tmp"
5006 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5007 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5008 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5009 echo "pool limit for $qpool2 $tmp"
5010 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5012 run_test 74 "check quota pools per user"
5014 function cleanup_quota_test_75()
5016 do_facet mgs $LCTL nodemap_modify --name default \
5017 --property admin --value 1
5018 do_facet mgs $LCTL nodemap_modify --name default \
5019 --property trusted --value 1
5020 do_facet mgs $LCTL nodemap_modify --name default \
5021 --property squash_uid --value 99
5022 do_facet mgs $LCTL nodemap_modify --name default \
5023 --property squash_gid --value 99
5025 wait_nm_sync default admin_nodemap
5026 wait_nm_sync default trusted_nodemap
5028 do_facet mgs $LCTL nodemap_activate 0
5031 resetquota -u $TSTUSR
5035 local dd_failed=false
5036 local LIMIT=20480 #20M
5039 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5040 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5041 oflag=sync || dd_failed=true
5044 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5046 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5047 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5048 oflag=sync || dd_failed=true
5051 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5053 rm -f $DIR/$tdir_dom/*
5055 # flush cache, ensure noquota flag is set on client
5057 sync; sync_all_data || true
5061 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) oflag=sync ||
5062 quota_error u $qid "write failed, expect succeed (2)"
5064 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5065 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5066 oflag=sync || dd_failed=true
5069 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5072 rm -f $DIR/$tdir_dom/*
5074 # flush cache, ensure noquota flag is set on client
5076 sync; sync_all_data || true
5080 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5081 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5082 oflag=sync || dd_failed=true
5085 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5087 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
5088 quota_error u $qid "write succeed, expect EDQUOT (3)"
5094 local soft_limit=10 # MB
5095 local hard_limit=20 # MB
5096 local limit=$soft_limit
5097 local testfile="$DIR/$tdir/$tfile-0"
5098 local grace=20 # seconds
5099 local tdir_dom=${tdir}_dom
5101 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5105 setup_quota_test || error "setup quota failed with $?"
5106 stack_trap cleanup_quota_test_75 EXIT
5109 set_ost_qtype $QTYPE || error "enable ost quota failed"
5110 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5112 local used=$(getquota -u $TSTID global curspace)
5113 $LFS setquota -t -u --block-grace $grace --inode-grace \
5114 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5115 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5116 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5117 error "set user quota failed"
5119 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5120 mkdir $DIR/$tdir_dom
5121 chmod 777 $DIR/$tdir_dom
5122 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5123 error "setstripe $tdir_dom failed"
5125 do_facet mgs $LCTL nodemap_activate 1
5127 do_facet mgs $LCTL nodemap_modify --name default \
5128 --property admin --value 0
5129 do_facet mgs $LCTL nodemap_modify --name default \
5130 --property trusted --value 0
5131 do_facet mgs $LCTL nodemap_modify --name default \
5132 --property deny_unknown --value 0
5133 do_facet mgs $LCTL nodemap_modify --name default \
5134 --property squash_uid --value $TSTID
5135 do_facet mgs $LCTL nodemap_modify --name default \
5136 --property squash_gid --value $TSTID
5137 cancel_lru_locks mdc
5138 wait_nm_sync default admin_nodemap
5139 wait_nm_sync default trusted_nodemap
5140 wait_nm_sync default squash_uid
5142 # mmap write when over soft limit
5144 $DD of=$testfile count=${limit} ||
5145 quota_error a "root write failure, but expect success (1)"
5146 OFFSET=$((limit * 1024))
5147 cancel_lru_locks osc
5149 echo "Write to exceed soft limit"
5150 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5151 quota_error a $TSTUSR "root write failure, but expect success (2)"
5152 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5153 cancel_lru_locks osc
5155 echo "mmap write when over soft limit"
5156 $MULTIOP $testfile.mmap OT40960SMW ||
5157 quota_error a $TSTUSR "mmap write failure, but expect success"
5158 cancel_lru_locks osc
5160 wait_delete_completed || error "wait_delete_completed failed (1)"
5161 sync_all_data || true
5163 # test for user hard limit
5166 $DD of=$testfile bs=1M count=$((limit/2)) ||
5167 quota_error u $TSTID \
5168 "root write failure, but expect success (3)"
5170 log "Write out of block quota ..."
5171 # possibly a cache write, ignore failure
5172 $DD of=$testfile bs=1M count=$((limit/2)) seek=$((limit/2)) || true
5173 # flush cache, ensure noquota flag is set on client
5174 cancel_lru_locks osc
5175 sync; sync_all_data || true
5176 # sync forced cache flush, but did not guarantee that slave
5177 # got new edquot through glimpse, so wait to make sure
5179 $DD of=$testfile bs=1M count=1 seek=$limit conv=fsync &&
5180 quota_error u $TSTID \
5181 "user write success, but expect EDQUOT"
5183 wait_delete_completed || error "wait_delete_completed failed (2)"
5184 sync_all_data || true
5185 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5186 quota_error u $TSTID "user quota not released after deletion"
5190 run_test 75 "nodemap squashed root respects quota enforcement"
5193 ! is_project_quota_supported &&
5194 skip "skip project quota unsupported"
5196 setup_quota_test || error "setup quota failed with $?"
5199 local testfile="$DIR/$tdir/$tfile-0"
5202 $LFS project -p 4294967295 $testfile &&
5203 error "set project ID should fail"
5206 run_test 76 "project ID 4294967295 should be not allowed"
5210 mount_client $MOUNT2 "ro"
5211 lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5212 error "lfs setquota should fail in read-only Lustre mount"
5215 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5219 (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
5220 skip "need OST at least 2.14.55"
5221 check_set_fallocate_or_skip
5223 setup_quota_test || error "setup quota failed with $?"
5226 set_ost_qtype $QTYPE || error "enable ost quota failed"
5228 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5229 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5232 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5233 error "lfs setquota failed"
5236 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5238 kbytes=$(lfs quota -u $TSTUSR $DIR |
5239 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5240 echo "kbytes returned:$kbytes"
5242 # For file size of 204800. We should be having roughly 200 kbytes
5243 # returned. Anything alarmingly low (50 taken as arbitrary value)
5244 # would bail out this TC. Also this also avoids $kbytes of 0
5245 # to be used in calculation below.
5246 (( $kbytes > 50 )) ||
5247 error "fallocate did not use quota. kbytes returned:$kbytes"
5249 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5250 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5252 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5253 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5254 error "fallocate did not use quota correctly"
5256 run_test 78 "Check fallocate increase quota usage"
5260 (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
5261 skip "need client at least 2.15.0"
5262 (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
5263 skip "need OST at least 2.15.0"
5264 check_set_fallocate_or_skip
5266 setup_quota_test || error "setup quota failed with $?"
5269 set_ost_qtype $QTYPE || error "enable ost quota failed"
5271 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5273 local projectid=5200 # Random project id to test
5275 change_project -sp $projectid $DIR/$tdir
5278 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5279 error "lfs setquota project failed"
5282 fallocate -l 204800 $DIR/$tdir/$tfile
5284 # Get curspace (kbytes) for $projectid
5285 local kbytes=$(getquota -p $projectid global curspace)
5287 echo "kbytes returned:$kbytes"
5289 # For file size of 204800. We should be having roughly 200 kbytes
5290 # returned. Anything alarmingly low (50 taken as arbitrary value)
5291 # would bail out this TC. Also this also avoids $kbytes of 0
5292 # to be used in calculation below.
5293 (( $kbytes > 50 )) ||
5294 error "fallocate did not use projectid. kbytes returned:$kbytes"
5296 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5297 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5299 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5300 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5301 error "fallocate did not use quota projectid correctly"
5303 run_test 78a "Check fallocate increase projectid usage"
5307 local qpool="qpool1"
5308 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5309 local stopf=$TMP/$tfile
5311 do_facet mds1 "touch $stopf"
5312 stack_trap "do_facet mds1 'rm -f $stopf'"
5313 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5315 pool_add $qpool || error "pool_add failed"
5316 do_facet mds1 "rm $stopf"
5319 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5323 local dir1="$DIR/$tdir/dir1"
5324 local dir2="$DIR/$tdir/dir2"
5325 local TESTFILE0="$dir1/$tfile-0"
5326 local TESTFILE1="$dir1/$tfile-1"
5327 local TESTFILE2="$dir1/$tfile-2"
5328 local TESTFILE3="$dir2/$tfile-0"
5329 local global_limit=100 # 100M
5330 local limit=10 # 10M
5331 local qpool="qpool1"
5333 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5335 [ "$ost1_FSTYPE" == zfs ] &&
5336 skip "ZFS grants some block space together with inode"
5337 setup_quota_test || error "setup quota failed with $?"
5338 set_ost_qtype $QTYPE || error "enable ost quota failed"
5340 # make sure the system is clean
5341 local used=$(getquota -u $TSTUSR global curspace)
5342 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5344 pool_add $qpool || error "pool_add failed"
5345 pool_add_targets $qpool 0 1 ||
5346 error "pool_add_targets failed"
5348 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5349 error "set user quota failed"
5351 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5352 error "set user quota failed"
5353 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5354 error "set user quota failed"
5356 mkdir -p $dir1 || error "failed to mkdir"
5357 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5358 mkdir -p $dir2 || error "failed to mkdir"
5359 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5361 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5362 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5367 $LFS quota -uv $TSTUSR $DIR
5368 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5369 do_facet mds1 $LCTL set_param fail_loc=0xa06
5370 $RUNAS $DD of=$TESTFILE3 count=3 ||
5371 quota_error u $TSTUSR "write failed"
5372 $RUNAS $DD of=$TESTFILE2 count=7 ||
5373 quota_error u $TSTUSR "write failed"
5374 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5375 quota_error u $TSTUSR "write failed"
5378 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5382 do_facet mds1 $LCTL set_param fail_loc=0
5383 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5384 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5385 # OST0 needs some time to update quota usage after removing TESTFILE2
5387 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5388 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5389 quota_error u $TSTUSR "write failure, but expect success"
5391 run_test 80 "check for EDQUOT after OST failover"
5394 local global_limit=20 # 100M
5395 local testfile="$DIR/$tdir/$tfile-0"
5396 local qpool="qpool1"
5399 setup_quota_test || error "setup quota failed with $?"
5402 set_ost_qtype $QTYPE || error "enable ost quota failed"
5405 log "User quota (block hardlimit:$global_limit MB)"
5406 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5408 pool_add $qpool || error "pool_add failed"
5409 #define OBD_FAIL_QUOTA_RECALC 0xA07
5410 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5411 # added OST casues to start pool recalculation
5412 pool_add_targets $qpool 0 0 1
5413 stop mds1 -f || error "MDS umount failed"
5415 #start mds1 back to destroy created pool
5416 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5419 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5423 (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
5424 skip "need MDS 2.14.55 or later"
5425 is_project_quota_supported ||
5426 skip "skip project quota unsupported"
5428 setup_quota_test || error "setup quota failed with $?"
5429 stack_trap cleanup_quota_test
5432 local parent_dir="$DIR/$tdir.parent"
5433 local child_dir="$parent_dir/child"
5436 stack_trap "chown -R 0:0 $parent_dir"
5438 chown $TSTUSR:$TSTUSR $parent_dir ||
5439 error "failed to chown on $parent_dir"
5440 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5441 error "failed to chown on $parent_dir"
5443 $LFS project -p 1000 $parent_dir ||
5444 error "failed to set project id on $parent_dir"
5445 $LFS project -p 1001 $child_dir ||
5446 error "failed to set project id on $child_dir"
5448 rmdir $child_dir || error "cannot remove child dir, test failed"
5450 run_test 82 "verify more than 8 qids for single operation"
5454 do_nodes $(comma_list $(nodes_list)) \
5455 "lctl set_param -n debug=-quota,trace"
5456 if $PQ_CLEANUP; then
5457 disable_project_quota
5460 reset_quota_settings
5465 check_and_cleanup_lustre
5466 export QUOTA_AUTO=$QUOTA_AUTO_OLD