3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
33 TSTID=${TSTID:-"$(id -u $TSTUSR)"}
34 TSTID2=${TSTID2:-"$(id -u $TSTUSR2)"}
35 TSTPRJID=${TSTPRJID:-1000}
40 VERSION_WITH_QP="2.13.53"
42 [ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ] &&
43 skip "Needs MDS version $VERSION_WITH_QP or later."
46 require_dsh_mds || exit 0
47 require_dsh_ost || exit 0
49 # Does e2fsprogs support quota feature?
50 if [ "$mds1_FSTYPE" == ldiskfs ] &&
51 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
52 grep -q 'quota'"; then
53 skip_env "e2fsprogs doesn't support quota"
56 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
58 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
63 QUOTA_AUTO_OLD=$QUOTA_AUTO
66 check_and_setup_lustre
68 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
69 is_project_quota_supported || echo "project quota not supported/enabled"
71 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
72 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
73 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
74 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
75 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
78 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
83 local fail_val=${3:-0}
87 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
88 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
89 ost) NODES="$(comma_list $(osts_nodes))";;
92 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
98 lfs project $* || error "lfs project $* failed"
101 RUNAS="runas -u $TSTID -g $TSTID"
102 RUNAS2="runas -u $TSTID2 -g $TSTID2"
103 DD="dd if=/dev/zero bs=1M"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
110 # resetquota -p projid
113 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
114 error "clear quota for [type:$1 name:$2] failed"
118 (( "$#" == 2 )) || error "resetquota: wrong number of arguments: '$*'"
119 [[ "$1" == "-u" || "$1" == "-g" || "$1" == "-p" ]] ||
120 error "resetquota: wrong quota type '$1' passed"
122 resetquota_one "$1" "$2"
124 # give a chance to slave to release space
133 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
134 $LFS quota -v -u $local_id $DIR
135 count=$($LFS find --user $local_id $DIR | wc -l)
136 log "Files for user ($local_id), count=$count:"
137 ($LFS find --user $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
142 $LFS quota -v -g $local_id $DIR
143 count=$($LFS find --group $local_id $DIR | wc -l)
144 log "Files for group ($local_id), count=$count:"
145 ($LFS find --group $local_id $DIR | head -n 4 |
146 xargs stat 2>/dev/null)
149 is_project_quota_supported || return 0
150 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
151 $LFS quota -v -p $TSTPRJID $DIR
152 count=$($LFS find --projid $TSTPRJID $DIR | wc -l)
153 log "Files for project ($TSTPRJID), count=$count:"
154 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
155 xargs stat 2>/dev/null)
171 # get quota for a user or a group
172 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
173 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace \
180 sync_all_data > /dev/null 2>&1 || true
182 [ "$#" != 4 -a "$#" != 5 ] &&
183 error "getquota: wrong number of arguments: $#"
184 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
185 error "getquota: wrong u/g/p specifier $1 passed"
198 *) error "unknown quota parameter $4";;
201 [ ! -z "$5" ] && pool_arg="--pool $5 "
202 [ "$uuid" = "global" ] && uuid=$DIR
204 $LFS quota -v "$1" "$2" $pool_arg $DIR |
205 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
206 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
211 # usage: set_mdt_qtype ugp|u|g|p|none
215 local mdts=$(get_facets MDS)
217 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
218 qtype=$(tr -d 'p' <<<$qtype)
220 if [[ $PERM_CMD == *"set_param -P"* ]]; then
221 do_facet mgs $PERM_CMD \
222 osd-*.$FSNAME-MDT*.quota_slave.enabled=$qtype
224 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
226 # we have to make sure each MDT received config changes
227 for mdt in ${mdts//,/ }; do
229 cmd="$LCTL get_param -n "
230 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
231 cmd=${cmd}.quota_slave.enabled
233 if $(facet_up $mdt); then
234 wait_update_facet $mdt "$cmd" "$qtype" || return 1
241 # usage: set_ost_qtype ugp|u|g|p|none
245 local osts=$(get_facets OST)
247 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
248 qtype=$(tr -d 'p' <<<$qtype)
250 if [[ $PERM_CMD == *"set_param -P"* ]]; then
251 do_facet mgs $PERM_CMD \
252 osd-*.$FSNAME-OST*.quota_slave.enabled=$qtype
254 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
256 # we have to make sure each OST received config changes
257 for ost in ${osts//,/ }; do
259 cmd="$LCTL get_param -n "
260 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
261 cmd=${cmd}.quota_slave.enabled
263 if $(facet_up $ost); then
264 wait_update_facet $ost "$cmd" "$qtype" || return 1
270 wait_reintegration() {
274 local result="glb[1],slv[1],reint[0]"
279 if [ $ntype == "mdt" ]; then
280 tgts=$(get_facets MDS)
282 tgts=$(get_facets OST)
285 for tgt in ${tgts//,/ }; do
287 cmd="$LCTL get_param -n "
288 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
289 cmd=${cmd}.quota_slave.info
291 if $(facet_up $tgt); then
292 # reintegration starts after recovery completion
293 wait_recovery_complete $tgt
294 wait_update_facet $tgt "$cmd |
295 grep "$qtype" | awk '{ print \\\$3 }'" \
296 "$result" $max || return 1
306 if [[ "$qtype" =~ "u" ]]; then
307 wait_reintegration "mdt" "user" $max || return 1
310 if [[ "$qtype" =~ "g" ]]; then
311 wait_reintegration "mdt" "group" $max || return 1
314 if [[ "$qtype" =~ "p" ]]; then
315 ! is_project_quota_supported && return 0
316 wait_reintegration "mdt" "project" $max || return 1
325 if [[ "$qtype" =~ "u" ]]; then
326 wait_reintegration "ost" "user" $max || return 1
329 if [[ "$qtype" =~ "g" ]]; then
330 wait_reintegration "ost" "group" $max || return 1
333 if [[ "$qtype" =~ "p" ]]; then
334 ! is_project_quota_supported && return 0
335 wait_reintegration "ost" "project" $max || return 1
344 local extrasleep=${4:-5}
351 *) error "get_grace_time: Invalid quota type: $qtype"
356 echo "Quota info for $pool:"
357 $LFS quota -$qtype $qarg $parg $DIR
362 time=$(lfs quota -$qtype $qarg $parg $DIR|
363 awk 'NR == 3{ print $5 }')
366 time=$(lfs quota -$qtype $qarg $DIR|
367 awk 'NR == 3{ print $9 }')
370 error "Unknown quota type: $flavour"
374 local sleep_seconds=0
375 local orig_time=$time
377 echo "Grace time is $time"
378 # from lfs.c:__sec2str()
379 # const char spec[] = "smhdw";
380 # {1, 60, 60*60, 24*60*60, 7*24*60*60};
381 [[ $time == *w* ]] && w_time=${time%w*} &&
382 let sleep_seconds+=$((w_time*7*24*60*60));
384 [[ $time == *d* ]] && d_time=${time%d*} &&
385 let sleep_seconds+=$((d_time*24*60*60));
387 [[ $time == *h* ]] && h_time=${time%h*} &&
388 let sleep_seconds+=$((h_time*60*60));
390 [[ $time == *m* ]] && m_time=${time%m*} &&
391 let sleep_seconds+=$((m_time*60));
393 [[ $time == *s* ]] && s_time=${time%s*} &&
394 let sleep_seconds+=$s_time
396 echo "Sleep through grace ..."
397 [ "$orig_time" == "-" ] &&
398 error "Grace timeout was not set or quota not exceeded"
399 if [ "$orig_time" == "expired" -o "$orig_time" == "none" ]; then
400 echo "...Grace timeout already expired"
402 let sleep_seconds+=$extrasleep
403 echo "...sleep $sleep_seconds seconds"
409 wait_delete_completed
410 echo "Creating test directory"
411 mkdir_on_mdt0 $DIR/$tdir || return 1
412 chmod 0777 $DIR/$tdir || return 2
413 # always clear fail_loc in case of fail_loc isn't cleared
414 # properly when previous test failed
415 lustre_fail mds_ost 0
416 stack_trap cleanup_quota_test EXIT
419 cleanup_quota_test() {
420 echo "Delete files..."
422 [ -d $DIR/${tdir}_dom ] && rm -rf $DIR/${tdir}_dom
423 echo "Wait for unlink objects finished..."
424 wait_delete_completed
425 sync_all_data || true
435 $LFS quota -v -$ugp $qid $DIR
437 if [ "$bf" == "a" -o "$bf" == "b" ]; then
438 usage=$(getquota -$ugp $qid global curspace)
439 if [ -z $usage ]; then
440 quota_error $ugp $qid \
441 "Query block quota failed ($ugp:$qid)."
443 [ $usage -ne 0 ] && quota_log $ugp $qid \
444 "Block quota isn't 0 ($ugp:$qid:$usage)."
448 if [ "$bf" == "a" -o "$bf" == "f" ]; then
449 usage=$(getquota -$ugp $qid global curinodes)
450 if [ -z $usage ]; then
451 quota_error $ugp $qid \
452 "Query file quota failed ($ugp:$qid)."
454 [ $usage -ne 0 ] && quota_log $ugp $qid \
455 "File quota isn't 0 ($ugp:$qid:$usage)."
460 project_quota_enabled () {
462 local zfeat="feature@project_quota"
464 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
465 local facet_fstype=${facet:0:3}1_FSTYPE
468 if [ "${!facet_fstype}" = "zfs" ]; then
469 devname=$(zpool_name ${facet})
470 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
471 grep -wq active || rc=1
473 [ ${facet:0:3} == "mds" ] &&
474 devname=$(mdsdevname ${facet:3}) ||
475 devname=$(ostdevname ${facet:3})
476 do_facet ${facet} $DEBUGFS -R features $devname |
477 grep -q project || rc=1
480 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
484 project_quota_enabled || enable_project_quota
486 reset_quota_settings() {
487 resetquota_one -u $TSTUSR
488 [[ $(id -u $TSTUSR) == $TSTID ]] || resetquota_one -u $TSTID
489 resetquota_one -g $TSTUSR
490 [[ $(id -g $TSTUSR) == $TSTID ]] || resetquota_one -g $TSTID
491 resetquota_one -u $TSTUSR2
492 [[ $(id -u $TSTUSR2) == $TSTID2 ]] || resetquota_one -u $TSTID2
493 resetquota_one -g $TSTUSR2
494 [[ $(id -g $TSTUSR2) == $TSTID2 ]] || resetquota_one -g $TSTID2
495 is_project_quota_supported && resetquota_one -p $TSTPRJID
511 usr) qtype="limit_user";;
512 grp) qtype="limit_group";;
513 prj) qtype="limit_project";;
514 *) error "unknown quota parameter $3";;
521 *) error "unknown quota parameter $5";;
524 do_facet $facet $LCTL get_param osd-*.*-${device}.quota_slave.$qtype |
525 awk '($3 == '$qid') {getline; print $'$spec'; exit;}' | tr -d ,
528 wait_quota_synced() {
538 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
539 while [[ $value != $limit_val ]]; do
540 (( interval != 0 )) ||
541 do_facet $facet $LCTL set_param \
542 osd-*.*-${device}.quota_slave.force_reint=1
545 (( interval <= 20 )) ||
546 error "quota ($value) don't update on QSD, $limit_val"
548 interval=$((interval + 1))
551 value=$(get_quota_on_qsd $facet $device $qtype $qid $limit_type)
555 # make sure the system is clean
556 check_system_is_clean() {
559 lfs quota -uv quota_usr /mnt/lustre
560 for cur in "curspace" "curinodes";
562 used=$(getquota -u $TSTUSR global $cur)
563 [ $used -ne 0 ] && quota_error u $TSTUSR \
564 "Used ${cur:3}($used) for user $TSTUSR isn't 0."
566 used=$(getquota -u $TSTUSR2 global $cur)
567 [ $used -ne 0 ] && quota_error u $TSTUSR2 \
568 "Used ${cur:3}($used) for user $TSTUSR2 isn't 0."
570 used=$(getquota -g $TSTUSR global $cur)
571 [ $used -ne 0 ] && quota_error g $TSTUSR \
572 "Used ${cur:3}($used) for group $TSTUSR isn't 0."
574 used=$(getquota -g $TSTUSR2 global $cur)
575 [ $used -ne 0 ] && quota_error g $TSTUSR2 \
576 "Used ${cur:3}($used) for group $TSTUSR2 isn't 0."
578 if is_project_quota_supported; then
579 used=$(getquota -p $TSTPRJID global $cur)
580 [ $used -ne 0 ] && quota_error p $TSTPRJID \
581 "Used ${cur:3}($used) for project $TSTPRJID isn't 0"
589 do_nodes $(comma_list $(nodes_list)) \
590 "$LCTL set_param -n debug=+quota+trace"
595 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
596 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
597 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
598 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
599 check_system_is_clean
601 test_quota_performance() {
602 local TESTFILE="$DIR/$tdir/$tfile-0"
603 local size=$1 # in MB
604 local stime=$(date +%s)
605 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
606 quota_error u $TSTUSR "write failure"
607 local etime=$(date +%s)
608 delta=$((etime - stime))
609 if [ $delta -gt 0 ]; then
610 rate=$((size * 1024 / delta))
611 if [ "$mds1_FSTYPE" = zfs ]; then
612 # LU-2872 - see LU-2887 for fix
614 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
616 [ $rate -gt 1024 ] ||
617 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
623 # test basic quota performance b=21696
626 [ "$SLOW" = "no" ] && MB=10
628 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
629 [ $free_space -le $((MB * 1024)) ] &&
630 skip "not enough space ${free_space} KB, " \
631 "required $((MB * 1024)) KB"
632 setup_quota_test || error "setup quota failed with $?"
634 set_ost_qtype "none" || error "disable ost quota failed"
635 test_quota_performance $MB
637 set_ost_qtype $QTYPE || error "enable ost quota failed"
638 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
639 error "set quota failed"
640 test_quota_performance $MB
642 run_test 0 "Test basic quota performance"
644 # usage: test_1_check_write tfile user|group|project
645 test_1_check_write() {
649 local short_qtype=${qtype:0:1}
652 $RUNAS $DD of=$testfile count=$((limit/2)) ||
653 quota_error $short_qtype $TSTUSR \
654 "$qtype write failure, but expect success"
655 log "Write out of block quota ..."
656 # this time maybe cache write, ignore it's failure
657 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
658 # flush cache, ensure noquota flag is set on client
660 sync; sync_all_data || true
661 # sync means client wrote all it's cache, but id doesn't
662 # guarantee that slave received new edquot through glimpse.
663 # so wait a little to be sure slave got it.
665 $RUNAS $DD of=$testfile count=1 seek=$limit &&
666 quota_error $short_qtype $TSTUSR \
667 "user write success, but expect EDQUOT"
671 check_write_fallocate() {
675 local short_qtype=${qtype:0:1}
678 log "Write ${count}MiB Using Fallocate"
679 $RUNAS fallocate -l${count}MiB $testfile ||
680 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
683 sync; sync_all_data || true
687 log "Write ${count}MiB Using Fallocate"
688 $RUNAS fallocate -l${count}MiB $testfile &&
689 quota_error $short_qtype $TSTUSR \
690 "Write success, expect EDQUOT" || true
693 # test block hardlimit
696 local testfile="$DIR/$tdir/$tfile-0"
698 setup_quota_test || error "setup quota failed with $?"
701 set_ost_qtype $QTYPE || error "enable ost quota failed"
704 log "User quota (block hardlimit:$limit MB)"
705 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
706 error "set user quota failed"
708 # make sure the system is clean
709 local used=$(getquota -u $TSTUSR global curspace)
710 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
712 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
713 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
715 test_1_check_write $testfile "user" $limit
718 wait_delete_completed || error "wait_delete_completed failed"
719 sync_all_data || true
720 used=$(getquota -u $TSTUSR global curspace)
721 [ $used -ne 0 ] && quota_error u $TSTUSR \
722 "user quota isn't released after deletion"
723 resetquota -u $TSTUSR
726 log "--------------------------------------"
727 log "Group quota (block hardlimit:$limit MB)"
728 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
729 error "set group quota failed"
731 testfile="$DIR/$tdir/$tfile-1"
732 # make sure the system is clean
733 used=$(getquota -g $TSTUSR global curspace)
734 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
736 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
737 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
739 test_1_check_write $testfile "group" $limit
741 wait_delete_completed || error "wait_delete_completed failed"
742 sync_all_data || true
743 used=$(getquota -g $TSTUSR global curspace)
744 [ $used -ne 0 ] && quota_error g $TSTUSR \
745 "Group quota isn't released after deletion"
746 resetquota -g $TSTUSR
748 if ! is_project_quota_supported; then
749 echo "Project quota is not supported"
753 testfile="$DIR/$tdir/$tfile-2"
754 # make sure the system is clean
755 used=$(getquota -p $TSTPRJID global curspace)
757 error "used space($used) for project $TSTPRJID isn't 0"
760 log "--------------------------------------"
761 log "Project quota (block hardlimit:$limit mb)"
762 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
763 error "set project quota failed"
765 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
766 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
767 change_project -p $TSTPRJID $testfile
769 test_1_check_write $testfile "project" $limit
774 used=$(getquota -p $TSTPRJID global curspace)
775 [ $used -ne 0 ] && quota_error p $TSTPRJID \
776 "project quota isn't released after deletion"
778 resetquota -p $TSTPRJID
780 run_test 1a "Block hard limit (normal use and out of quota)"
783 (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
784 skip "Need MDS version at least 2.15.55"
787 local global_limit=20 # MB
788 local testfile="$DIR/$tdir/$tfile-0"
792 setup_quota_test || error "setup quota failed with $?"
795 set_ost_qtype $QTYPE || error "enable ost quota failed"
798 log "User quota (block hardlimit:$global_limit MB)"
799 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
800 error "set user quota failed"
802 pool_add $qpool || error "pool_add failed"
803 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
804 error "pool_add_targets failed"
806 # check qmt_pool_add dmesg error
807 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
809 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
810 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
812 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
813 error "set user quota failed"
815 # make sure the system is clean
816 local used=$(getquota -u $TSTUSR global curspace)
818 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
820 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
822 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
823 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
825 test_1_check_write $testfile "user" $limit
828 wait_delete_completed || error "wait_delete_completed failed"
829 sync_all_data || true
830 used=$(getquota -u $TSTUSR global curspace $qpool)
831 [ $used -ne 0 ] && quota_error u $TSTUSR \
832 "user quota isn't released after deletion"
833 resetquota -u $TSTUSR
836 log "--------------------------------------"
837 log "Group quota (block hardlimit:$global_limit MB)"
838 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
839 error "set group quota failed"
841 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
842 error "set group quota failed"
844 testfile="$DIR/$tdir/$tfile-1"
845 # make sure the system is clean
846 used=$(getquota -g $TSTUSR global curspace $qpool)
847 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
849 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
850 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
852 test_1_check_write $testfile "group" $limit
855 wait_delete_completed || error "wait_delete_completed failed"
856 sync_all_data || true
857 used=$(getquota -g $TSTUSR global curspace $qpool)
858 [ $used -ne 0 ] && quota_error g $TSTUSR \
859 "Group quota isn't released after deletion"
860 resetquota -g $TSTUSR
862 if ! is_project_quota_supported; then
863 echo "Project quota is not supported"
867 testfile="$DIR/$tdir/$tfile-2"
868 # make sure the system is clean
869 used=$(getquota -p $TSTPRJID global curspace $qpool)
871 error "used space($used) for project $TSTPRJID isn't 0"
874 log "--------------------------------------"
875 log "Project quota (block hardlimit:$global_limit mb)"
876 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
877 error "set project quota failed"
879 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
880 error "set project quota failed"
883 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
884 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
885 change_project -p $TSTPRJID $testfile
887 test_1_check_write $testfile "project" $limit
892 used=$(getquota -p $TSTPRJID global curspace)
893 [ $used -eq 0 ] || quota_error p $TSTPRJID \
894 "project quota isn't released after deletion"
896 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
899 local global_limit=20 # MB
900 local testfile="$DIR/$tdir/$tfile-0"
901 local qpool1="qpool1"
902 local qpool2="qpool2"
905 setup_quota_test || error "setup quota failed with $?"
908 set_ost_qtype $QTYPE || error "enable ost quota failed"
911 log "User quota (block hardlimit:$global_limit MB)"
912 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
913 error "set user quota failed"
915 pool_add $qpool1 || error "pool_add failed"
916 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
917 error "pool_add_targets failed"
919 pool_add $qpool2 || error "pool_add failed"
920 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
921 error "pool_add_targets failed"
923 # create pools without hard limit
924 # initially such case raised several bugs
925 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
926 error "set user quota failed"
928 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
929 error "set user quota failed"
931 # make sure the system is clean
932 local used=$(getquota -u $TSTUSR global curspace)
934 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
936 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
938 test_1_check_write $testfile "user" $global_limit
940 used=$(getquota -u $TSTUSR global curspace $qpool1)
941 echo "qpool1 used $used"
942 used=$(getquota -u $TSTUSR global curspace $qpool2)
943 echo "qpool2 used $used"
946 wait_delete_completed || error "wait_delete_completed failed"
947 sync_all_data || true
949 used=$(getquota -u $TSTUSR global curspace $qpool1)
950 [ $used -eq 0 ] || quota_error u $TSTUSR \
951 "user quota isn't released after deletion"
953 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
958 local global_limit=20 # MB
959 local testfile="$DIR/$tdir/$tfile-0"
960 local qpool1="qpool1"
961 local qpool2="qpool2"
964 setup_quota_test || error "setup quota failed with $?"
967 set_ost_qtype $QTYPE || error "enable ost quota failed"
970 log "User quota (block hardlimit:$global_limit MB)"
971 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
972 error "set user quota failed"
974 pool_add $qpool1 || error "pool_add failed"
975 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
976 error "pool_add_targets failed"
978 pool_add $qpool2 || error "pool_add failed"
979 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
980 error "pool_add_targets failed"
982 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
983 error "set user quota failed"
985 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
986 error "set user quota failed"
988 # make sure the system is clean
989 local used=$(getquota -u $TSTUSR global curspace)
991 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
993 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
995 test_1_check_write $testfile "user" $limit1
997 used=$(getquota -u $TSTUSR global curspace $qpool1)
998 echo "qpool1 used $used"
999 used=$(getquota -u $TSTUSR global curspace $qpool2)
1000 echo "qpool2 used $used"
1003 wait_delete_completed || error "wait_delete_completed failed"
1004 sync_all_data || true
1006 used=$(getquota -u $TSTUSR global curspace $qpool1)
1007 [ $used -eq 0 ] || quota_error u $TSTUSR \
1008 "user quota isn't released after deletion"
1010 run_test 1d "Quota pools: check block hardlimit on different pools"
1013 local limit1=10 # MB
1014 local global_limit=53000000 # MB
1015 local testfile="$DIR/$tdir/$tfile-0"
1016 local testfile2="$DIR/$tdir/$tfile-1"
1017 local qpool1="qpool1"
1020 setup_quota_test || error "setup quota failed with $?"
1023 set_ost_qtype $QTYPE || error "enable ost quota failed"
1025 # global_limit is much greater than limit1 to get
1026 # different qunit's on osts. Since 1st qunit shrinking
1027 # on OST1(that belongs to qpool1), this qunit should
1029 log "User quota (block hardlimit:$global_limit MB)"
1030 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1031 error "set user quota failed"
1033 pool_add $qpool1 || error "pool_add failed"
1034 pool_add_targets $qpool1 1 1 ||
1035 error "pool_add_targets failed"
1037 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1038 error "set user quota failed"
1040 # make sure the system is clean
1041 local used=$(getquota -u $TSTUSR global curspace)
1042 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1044 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
1045 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1047 test_1_check_write $testfile "user" $limit1
1049 $LFS setstripe $testfile2 -c 1 -i 0 ||
1050 error "setstripe $testfile2 failed"
1051 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
1052 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
1054 $RUNAS $DD of=$testfile2 count=20 ||
1055 quota_error u $TSTUSR \
1056 "$qtype write failure, but expect success"
1060 wait_delete_completed || error "wait_delete_completed failed"
1061 sync_all_data || true
1063 used=$(getquota -u $TSTUSR global curspace $qpool1)
1064 [ $used -eq 0 ] || quota_error u $TSTUSR \
1065 "user quota isn't released after deletion"
1067 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
1070 local global_limit=200 # MB
1071 local limit1=10 # MB
1072 local TESTDIR="$DIR/$tdir/"
1073 local testfile="$TESTDIR/$tfile-0"
1074 local qpool1="qpool1"
1077 setup_quota_test || error "setup quota failed with $?"
1080 set_ost_qtype $QTYPE || error "enable ost quota failed"
1082 log "User quota (block hardlimit:$global_limit MB)"
1083 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1084 error "set user quota failed"
1086 pool_add $qpool1 || error "pool_add failed"
1087 pool_add_targets $qpool1 0 0 ||
1088 error "pool_add_targets failed"
1090 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1091 error "set user quota failed"
1093 # make sure the system is clean
1094 local used=$(getquota -u $TSTUSR global curspace)
1095 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1097 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1099 test_1_check_write $testfile "user" $limit1
1101 pool_remove_target $qpool1 0
1103 wait_delete_completed || error "wait_delete_completed failed"
1104 sync_all_data || true
1106 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1107 # qunit for appropriate element in lgd array should be set
1108 # correctly(4096). Earlier it was not changed continuing to be 1024.
1109 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1110 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1111 # as it already was 1024. As flag "need_update" for this qunit was
1112 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1113 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1114 # became > 10M. QMT returned EINPROGRESS in a loop.
1115 # Check that it doesn't hung anymore.
1116 test_1_check_write $testfile "user" $limit1
1118 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1122 local global_limit=40 # MB
1123 local testfile="$DIR/$tdir/$tfile-0"
1124 local qpool="qpool1"
1125 local mdmb_param="osc.*.max_dirty_mb"
1126 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1129 setup_quota_test || error "setup quota failed with $?"
1130 $LCTL set_param $mdmb_param=1
1131 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1134 set_ost_qtype $QTYPE || error "enable ost quota failed"
1137 log "User quota (block hardlimit:$global_limit MB)"
1138 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1139 error "set user quota failed"
1141 pool_add $qpool || error "pool_add failed"
1142 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1143 error "pool_add_targets failed"
1145 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1146 error "set user quota failed"
1148 # make sure the system is clean
1149 local used=$(getquota -u $TSTUSR global curspace)
1151 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1153 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1154 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1157 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1158 quota_error u $TSTUSR \
1159 "$qtype write failure, but expect success"
1160 log "Write out of block quota ..."
1161 # this time maybe cache write, ignore it's failure
1162 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1163 # flush cache, ensure noquota flag is set on client
1164 cancel_lru_locks osc
1165 sync; sync_all_data || true
1167 $RUNAS $DD of=$testfile count=$((OSTCOUNT*3)) seek=$limit &&
1168 quota_error u $TSTUSR \
1169 "user write success, but expect EDQUOT"
1172 wait_delete_completed || error "wait_delete_completed failed"
1173 sync_all_data || true
1175 used=$(getquota -u $TSTUSR global curspace $qpool)
1176 [ $used -ne 0 ] && quota_error u $TSTUSR \
1177 "user quota isn't released after deletion"
1180 run_test 1g "Quota pools: Block hard limit with wide striping"
1184 local testfile="$DIR/$tdir/$tfile-0"
1186 check_set_fallocate_or_skip
1188 setup_quota_test || error "setup quota failed with $?"
1191 set_ost_qtype $QTYPE || error "enable ost quota failed"
1194 log "User quota (block hardlimit:$limit MB)"
1195 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1196 error "set user quota failed"
1198 # make sure the system is clean
1199 local used=$(getquota -u $TSTUSR global curspace)
1200 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1202 $LFS setstripe $testfile -i 0 -c 1 || error "setstripe $testfile failed"
1203 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1205 wait_quota_synced ost1 OST0000 usr $TSTID hardlimit $((limit*1024))
1207 check_write_fallocate $testfile "user" $limit
1210 wait_delete_completed || error "wait_delete_completed failed"
1211 sync_all_data || true
1212 used=$(getquota -u $TSTUSR global curspace)
1213 [ $used -eq 0 ] || quota_error u $TSTUSR \
1214 "user quota isn't released after deletion"
1216 run_test 1h "Block hard limit test using fallocate"
1219 local global_limit=200 # 200M
1220 local limit1=10 # 10M
1221 local TESTDIR="$DIR/$tdir/"
1222 local testfile="$TESTDIR/$tfile-0"
1223 local testfile1="$TESTDIR/$tfile-1"
1224 local testfile2="$TESTDIR/$tfile-2"
1225 local qpool1="qpool1"
1228 setup_quota_test || error "setup quota failed with $?"
1231 set_ost_qtype $QTYPE || error "enable ost quota failed"
1233 log "User quota (block hardlimit:$global_limit MB)"
1234 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1235 error "set user quota failed"
1237 pool_add $qpool1 || error "pool_add failed"
1238 pool_add_targets $qpool1 0 0 ||
1239 error "pool_add_targets failed"
1241 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1242 error "set user quota failed"
1244 # make sure the system is clean
1245 local used=$(getquota -u $TSTUSR global curspace)
1246 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1248 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1251 test_1_check_write $testfile "user" $limit1
1252 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1253 error "set user quota failed"
1255 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1256 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1257 quota_error u $TSTUSR "write failure, but expect success"
1261 wait_delete_completed || error "wait_delete_completed failed"
1262 sync_all_data || true
1264 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1265 error "set user quota failed"
1266 test_1_check_write $testfile "user" $limit1
1267 local tmp_limit=$(($limit1*2))
1268 # increase pool limit
1269 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1270 error "set user quota failed"
1271 # now write shouldn't fail
1272 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1273 quota_error u $TSTUSR "write failure, but expect success"
1274 # decrease pool limit
1275 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1276 error "set user quota failed"
1277 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1278 # flush cache, ensure noquota flag is set on client
1279 cancel_lru_locks osc
1280 sync; sync_all_data || true
1281 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1282 quota_error u $TSTUSR "write success, but expect failure"
1285 run_test 1i "Quota pools: different limit and usage relations"
1289 local testfile="$DIR/$tdir/$tfile-0"
1291 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1292 skip "need OST at least 2.15.52.206"
1294 is_project_quota_supported ||
1295 skip "skip project quota unsupported"
1297 setup_quota_test || error "setup quota failed with $?"
1300 set_ost_qtype $QTYPE || error "enable ost quota failed"
1303 log "--------------------------------------"
1304 log "Project quota (block hardlimit:$limit mb)"
1305 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1306 error "set project quota failed"
1308 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1309 change_project -p $TSTPRJID $testfile
1311 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1312 do_facet ost1 $LCTL set_param $procf=1 ||
1313 error "enable root quotas for project failed"
1314 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1316 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1317 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1318 quota_error "project" $TSTPRJID "root write to project success"
1320 do_facet ost1 $LCTL set_param $procf=0 ||
1321 error "disable root quotas for project failed"
1323 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1324 quota_error "project" $TSTPRJID "root write to project failed"
1329 used=$(getquota -p $TSTPRJID global curspace)
1330 (( $used == 0 )) || quota_error p $TSTPRJID \
1331 "project quota isn't released after deletion"
1333 run_test 1j "Enable project quota enforcement for root"
1335 # test inode hardlimit
1337 local testfile="$DIR/$tdir/$tfile-0"
1338 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1339 qmt.$FSNAME-QMT0000.md-0x0.info |
1340 sed -e 's/least qunit/least_qunit/' |
1341 awk '/least_qunit/{ print $2 }')
1344 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1345 limit=$((least_qunit * 1024))
1346 echo "least_qunit: '$least_qunit', limit: '$limit'"
1348 local free_inodes=$(mdt_free_inodes 0)
1349 echo "$free_inodes free inodes on master MDT"
1350 [ $free_inodes -lt $limit ] &&
1351 skip "not enough free inodes $free_inodes required $limit"
1353 setup_quota_test || error "setup quota failed with $?"
1356 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1359 log "User quota (inode hardlimit:$limit files)"
1360 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1361 error "set user quota failed"
1363 # make sure the system is clean
1364 local used=$(getquota -u $TSTUSR global curinodes)
1365 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1367 log "Create $((limit - least_qunit)) files ..."
1368 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1369 quota_error u $TSTUSR "user create failure, but expect success"
1370 # it is ok, if it fails on the last qunit
1371 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1372 log "Create out of file quota ..."
1373 $RUNAS touch ${testfile}_xxx &&
1374 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1377 unlinkmany ${testfile} $((limit - least_qunit)) ||
1378 error "unlinkmany $testfile failed"
1379 # if 2nd createmany got EDQUOT, not all of nodes would be created
1380 unlinkmany ${testfile}_yyy $least_qunit || true
1381 rm -f ${testfile}_xxx
1382 wait_delete_completed
1384 used=$(getquota -u $TSTUSR global curinodes)
1385 [ $used -ne 0 ] && quota_error u $TSTUSR \
1386 "user quota isn't released after deletion"
1387 resetquota -u $TSTUSR
1390 log "--------------------------------------"
1391 log "Group quota (inode hardlimit:$limit files)"
1392 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1393 error "set group quota failed"
1395 testfile=$DIR/$tdir/$tfile-1
1396 # make sure the system is clean
1397 used=$(getquota -g $TSTUSR global curinodes)
1398 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1400 log "Create $limit files ..."
1401 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1402 quota_error g $TSTUSR "group create failure, but expect success"
1403 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1404 log "Create out of file quota ..."
1405 $RUNAS touch ${testfile}_xxx &&
1406 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1409 unlinkmany ${testfile} $((limit - least_qunit)) ||
1410 error "unlinkmany $testfile failed"
1411 unlinkmany ${testfile}_yyy $least_qunit || true
1412 rm -f ${testfile}_xxx
1413 wait_delete_completed
1415 used=$(getquota -g $TSTUSR global curinodes)
1416 [ $used -ne 0 ] && quota_error g $TSTUSR \
1417 "user quota isn't released after deletion"
1419 resetquota -g $TSTUSR
1420 ! is_project_quota_supported &&
1421 echo "Skip project quota is not supported" && return 0
1424 log "--------------------------------------"
1425 log "Project quota (inode hardlimit:$limit files)"
1426 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1427 error "set project quota failed"
1429 testfile=$DIR/$tdir/$tfile-1
1430 # make sure the system is clean
1431 used=$(getquota -p $TSTPRJID global curinodes)
1433 error "Used inodes($used) for project $TSTPRJID isn't 0"
1435 change_project -sp $TSTPRJID $DIR/$tdir
1436 log "Create $limit files ..."
1437 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1438 quota_error p $TSTPRJID \
1439 "project create fail, but expect success"
1440 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1441 log "Create out of file quota ..."
1442 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1443 "project create success, but expect EDQUOT"
1444 change_project -C $DIR/$tdir
1447 used=$(getquota -p $TSTPRJID global curinodes)
1448 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1449 "project quota isn't released after deletion"
1452 run_test 2 "File hard limit (normal use and out of quota)"
1461 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1462 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1466 $LFS setstripe $testfile -c 1 -i 0
1467 chown $TSTUSR.$TSTUSR $testfile
1468 [ "$qtype" == "p" ] && is_project_quota_supported &&
1469 change_project -p $TSTPRJID $testfile
1471 echo "Write up to soft limit"
1472 $RUNAS $DD of=$testfile count=$limit ||
1473 quota_error a $TSTUSR "write failure, but expect success"
1474 OFFSET=$((limit * 1024))
1475 cancel_lru_locks osc
1477 echo "Write to exceed soft limit"
1478 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1479 quota_error a $TSTUSR "write failure, but expect success"
1480 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1481 cancel_lru_locks osc
1483 echo "mmap write when over soft limit"
1484 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1485 quota_error a $TSTUSR "mmap write failure, but expect success"
1486 cancel_lru_locks osc
1491 $SHOW_QUOTA_INFO_USER
1492 $SHOW_QUOTA_INFO_GROUP
1493 $SHOW_QUOTA_INFO_PROJID
1495 echo "Write before timer goes off"
1496 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1497 quota_error a $TSTUSR "write failure, but expect success"
1498 OFFSET=$((OFFSET + 1024))
1499 cancel_lru_locks osc
1501 wait_grace_time $qtype "block" $pool
1506 $SHOW_QUOTA_INFO_USER
1507 $SHOW_QUOTA_INFO_GROUP
1508 $SHOW_QUOTA_INFO_PROJID
1510 log "Write after timer goes off"
1511 # maybe cache write, ignore.
1512 # write up to soft least quint to consume all
1513 # possible slave granted space.
1514 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1515 count=$soft_limit seek=$OFFSET || true
1516 OFFSET=$((OFFSET + soft_limit))
1517 cancel_lru_locks osc
1518 log "Write after cancel lru locks"
1519 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1520 quota_error a $TSTUSR "write success, but expect EDQUOT"
1525 $SHOW_QUOTA_INFO_USER
1526 $SHOW_QUOTA_INFO_GROUP
1527 $SHOW_QUOTA_INFO_PROJID
1529 echo "Unlink file to stop timer"
1531 wait_delete_completed
1532 sync_all_data || true
1537 $SHOW_QUOTA_INFO_USER
1538 $SHOW_QUOTA_INFO_GROUP
1539 $SHOW_QUOTA_INFO_PROJID
1541 $LFS setstripe $testfile -c 1 -i 0
1542 chown $TSTUSR.$TSTUSR $testfile
1543 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1546 $RUNAS $DD of=$testfile count=$limit ||
1547 quota_error a $TSTUSR "write failure, but expect success"
1554 local grace=20 # seconds
1555 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1558 local testfile=$DIR/$tdir/$tfile-0
1560 # get minimum soft qunit size
1561 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1562 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1564 set_ost_qtype $QTYPE || error "enable ost quota failed"
1566 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1567 # make sure the system is clean
1568 local used=$(getquota -u $TSTUSR global curspace)
1569 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1571 $LFS setquota -t -u --block-grace $grace --inode-grace \
1572 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1573 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1574 error "set user quota failed"
1576 test_block_soft $testfile $grace $limit "u"
1578 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1579 testfile=$DIR/$tdir/$tfile-1
1580 # make sure the system is clean
1581 used=$(getquota -g $TSTUSR global curspace)
1582 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1584 $LFS setquota -t -g --block-grace $grace --inode-grace \
1585 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1586 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1587 error "set group quota failed"
1589 test_block_soft $testfile $grace $limit "g"
1591 if is_project_quota_supported; then
1592 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1593 testfile=$DIR/$tdir/$tfile-2
1594 # make sure the system is clean
1595 used=$(getquota -p $TSTPRJID global curspace)
1596 [ $used -ne 0 ] && error \
1597 "Used space($used) for project $TSTPRJID isn't 0."
1599 $LFS setquota -t -p --block-grace $grace --inode-grace \
1600 $MAX_IQ_TIME $DIR ||
1601 error "set project grace time failed"
1602 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1603 $DIR || error "set project quota failed"
1605 test_block_soft $testfile $grace $limit "p"
1606 resetquota -p $TSTPRJID
1607 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1608 $MAX_IQ_TIME $DIR ||
1609 error "restore project grace time failed"
1613 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1614 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1615 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1616 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1618 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1621 local grace=20 # seconds
1622 local qpool="qpool1"
1623 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1626 local testfile=$DIR/$tdir/$tfile-0
1629 # get minimum soft qunit size
1630 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1631 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1632 local glbl_limit=$((2*limit))
1633 local glbl_grace=$((2*grace))
1634 echo "limit $limit glbl_limit $glbl_limit"
1635 echo "grace $grace glbl_grace $glbl_grace"
1637 set_ost_qtype $QTYPE || error "enable ost quota failed"
1639 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1640 # make sure the system is clean
1641 local used=$(getquota -u $TSTUSR global curspace)
1642 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1644 pool_add $qpool || error "pool_add failed"
1645 pool_add_targets $qpool 0 1 ||
1646 error "pool_add_targets failed"
1648 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1649 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1650 $LFS setquota -t -u --block-grace $grace \
1651 --pool $qpool $DIR || error "set user grace time failed"
1653 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1654 error "set user quota failed"
1655 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1656 error "set user quota failed"
1658 test_block_soft $testfile $grace $limit "u" $qpool
1660 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1661 testfile=$DIR/$tdir/$tfile-1
1662 # make sure the system is clean
1663 used=$(getquota -g $TSTUSR global curspace)
1664 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1666 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1667 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1668 $LFS setquota -t -g --block-grace $grace \
1669 --pool $qpool $DIR || error "set group grace time failed"
1671 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1672 error "set group quota failed"
1673 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1674 error "set group quota failed"
1676 test_block_soft $testfile $grace $limit "g" $qpool
1678 if is_project_quota_supported; then
1679 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1680 testfile=$DIR/$tdir/$tfile-2
1681 # make sure the system is clean
1682 used=$(getquota -p $TSTPRJID global curspace)
1683 [ $used -ne 0 ] && error \
1684 "Used space($used) for project $TSTPRJID isn't 0."
1686 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1687 $MAX_IQ_TIME $DIR ||
1688 error "set project grace time failed"
1689 $LFS setquota -t -p --block-grace $grace \
1690 --pool $qpool $DIR ||
1691 error "set project grace time failed"
1693 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1694 $DIR || error "set project quota failed"
1695 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1696 --pool $qpool $DIR || error "set project quota failed"
1698 test_block_soft $testfile $grace $limit "p" $qpool
1699 resetquota -p $TSTPRJID
1700 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1701 $MAX_IQ_TIME $DIR ||
1702 error "restore project grace time failed"
1703 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1704 $DIR || error "set project grace time failed"
1708 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1709 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1710 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1711 --pool $qpool $DIR || error "restore user grace time failed"
1712 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1713 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1714 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1715 --pool $qpool $DIR || error "restore group grace time failed"
1717 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1720 local grace=20 # seconds
1721 local qpool="qpool1"
1722 local qpool2="qpool2"
1723 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1726 local testfile=$DIR/$tdir/$tfile-0
1729 # get minimum soft qunit size
1730 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1731 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1732 local limit2=$((limit+4))
1733 local glbl_limit=$((limit+8))
1734 local grace1=$((grace+10))
1736 local glbl_grace=$((grace+20))
1737 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1738 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1740 set_ost_qtype $QTYPE || error "enable ost quota failed"
1742 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1743 # make sure the system is clean
1744 local used=$(getquota -u $TSTUSR global curspace)
1745 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1747 pool_add $qpool || error "pool_add failed"
1748 pool_add_targets $qpool 0 1 ||
1749 error "pool_add_targets failed"
1751 pool_add $qpool2 || error "pool_add failed"
1752 pool_add_targets $qpool2 0 1 ||
1753 error "pool_add_targets failed"
1755 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1756 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1757 $LFS setquota -t -u --block-grace $grace1 \
1758 --pool $qpool $DIR || error "set user grace time failed"
1759 $LFS setquota -t -u --block-grace $grace2 \
1760 --pool $qpool2 $DIR || error "set user grace time failed"
1762 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1763 error "set user quota failed"
1764 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1765 error "set user quota failed"
1766 # qpool has minimum soft limit, but its grace is greater than
1767 # the grace period of qpool2. Thus write shouldn't fail when
1768 # hit qpool soft limit - only when reaches up qpool2 limit
1769 # after grace2 seconds.
1770 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1771 error "set user quota failed"
1773 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1776 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1777 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1778 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1779 --pool $qpool $DIR || error "restore user grace time failed"
1780 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1781 --pool $qpool2 $DIR || error "restore user grace time failed"
1783 run_test 3c "Quota pools: check block soft limit on different pools"
1790 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1791 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1794 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1796 echo "Create files to exceed soft limit"
1797 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1798 quota_error a $TSTUSR "create failure, but expect success"
1799 local trigger_time=$(date +%s)
1801 sync_all_data || true
1803 local cur_time=$(date +%s)
1804 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1805 error "Passed grace time $grace, $trigger_time, $cur_time"
1807 echo "Create file before timer goes off"
1808 $RUNAS touch ${TESTFILE}_before ||
1809 quota_error a $TSTUSR "failed create before timer expired," \
1810 "but expect success. $trigger_time, $cur_time"
1811 sync_all_data || true
1813 wait_grace_time $qtype "file"
1818 $SHOW_QUOTA_INFO_USER
1819 $SHOW_QUOTA_INFO_GROUP
1820 $SHOW_QUOTA_INFO_PROJID
1822 echo "Create file after timer goes off"
1823 # exceed least soft limit is possible
1824 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1825 quota_error a $TSTUSR "create after timer expired," \
1827 sync_all_data || true
1832 $SHOW_QUOTA_INFO_USER
1833 $SHOW_QUOTA_INFO_GROUP
1834 $SHOW_QUOTA_INFO_PROJID
1836 echo "Unlink files to stop timer"
1837 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1838 wait_delete_completed
1841 $RUNAS touch ${TESTFILE}_xxx ||
1842 quota_error a $TSTUSR "touch after timer stop failure," \
1843 "but expect success"
1844 sync_all_data || true
1852 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1853 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1854 local TESTFILE=$DIR/$tdir/$tfile-0
1857 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1858 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1860 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1861 # make sure the system is clean
1862 local USED=$(getquota -u $TSTUSR global curinodes)
1863 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1865 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1866 $GRACE $DIR || error "set user grace time failed"
1867 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1868 error "set user quota failed"
1870 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1872 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1873 # make sure the system is clean
1874 USED=$(getquota -g $TSTUSR global curinodes)
1875 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1877 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1878 $GRACE $DIR || error "set group grace time failed"
1879 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1880 error "set group quota failed"
1881 TESTFILE=$DIR/$tdir/$tfile-1
1883 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1885 if is_project_quota_supported; then
1886 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1887 # make sure the system is clean
1888 USED=$(getquota -p $TSTPRJID global curinodes)
1889 [ $USED -ne 0 ] && error \
1890 "Used space($USED) for project $TSTPRJID isn't 0."
1892 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1893 $GRACE $DIR || error "set project grace time failed"
1894 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1895 error "set project quota failed"
1897 TESTFILE=$DIR/$tdir/$tfile-1
1898 # one less than limit, because of parent directory included.
1899 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1900 resetquota -p $TSTPRJID
1901 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1902 $MAX_IQ_TIME $DIR ||
1903 error "restore project grace time failed"
1907 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1908 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1909 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1910 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1912 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1915 local GR_STR1="1w3d"
1916 local GR_STR2="1000s"
1918 local GR_STR4="1w2d3h4m5s"
1920 local GR_STR6="18446744073709551615"
1923 wait_delete_completed
1925 # test of valid grace strings handling
1926 echo "Valid grace strings test"
1927 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1928 $GR_STR2 $DIR || error "set user grace time failed"
1929 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1930 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1931 $GR_STR4 $DIR || error "set group grace time quota failed"
1932 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1934 # test of invalid grace strings handling
1935 echo " Invalid grace strings test"
1936 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1937 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1938 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1942 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1943 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1944 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1945 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1947 run_test 4b "Grace time strings handling"
1949 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1951 local BLIMIT=10 # MB
1952 local ILIMIT=10 # inodes
1954 setup_quota_test || error "setup quota failed with $?"
1956 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1957 set_ost_qtype $QTYPE || error "enable ost quota failed"
1959 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1960 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1961 error "set user quota failed"
1962 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1963 if is_project_quota_supported; then
1964 error "set group quota failed"
1965 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1966 -I $ILIMIT $DIR || error "set project quota failed"
1969 # make sure the system is clean
1970 local USED=$(getquota -u $TSTUSR global curinodes)
1971 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1972 USED=$(getquota -g $TSTUSR global curinodes)
1973 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1974 USED=$(getquota -u $TSTUSR global curspace)
1975 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1976 USED=$(getquota -g $TSTUSR global curspace)
1977 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1978 if is_project_quota_supported; then
1979 USED=$(getquota -p $TSTPRJID global curinodes)
1981 error "Used inode($USED) for project $TSTPRJID isn't 0."
1982 USED=$(getquota -p $TSTPRJID global curspace)
1984 error "Used block($USED) for project $TSTPRJID isn't 0."
1987 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1988 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1989 error "create failure, expect success"
1990 if is_project_quota_supported; then
1991 touch $DIR/$tdir/$tfile-0_1
1992 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1994 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1995 error "write failure, expect success"
1997 echo "Chown files to $TSTUSR.$TSTUSR ..."
1998 for i in $(seq 0 $ILIMIT); do
1999 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
2000 quota_error a $TSTUSR "chown failure, expect success"
2004 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
2005 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
2007 run_test 5 "Chown & chgrp successfully even out of block/file quota"
2009 # test dropping acquire request on master
2013 # Clear dmesg so watchdog is not triggered by previous
2015 do_facet ost1 dmesg -c > /dev/null
2017 setup_quota_test || error "setup quota failed with $?"
2019 # make sure the system is clean
2020 local USED=$(getquota -u $TSTUSR global curspace)
2021 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2023 # make sure no granted quota on ost
2024 set_ost_qtype $QTYPE || error "enable ost quota failed"
2025 resetquota -u $TSTUSR
2027 # create file for $TSTUSR
2028 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
2029 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2030 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2032 # create file for $TSTUSR2
2033 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
2034 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
2035 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
2037 # cache per-ID lock for $TSTUSR on slave
2038 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2039 error "set quota failed"
2040 $RUNAS $DD of=$TESTFILE count=1 ||
2041 error "write $TESTFILE failure, expect success"
2042 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
2043 error "write $TESTFILE2 failure, expect success"
2045 if at_is_enabled; then
2046 at_max_saved=$(at_max_get ost1)
2047 at_max_set $TIMEOUT ost1
2049 # write to enforced ID ($TSTUSR) to exceed limit to make sure
2050 # DQACQ is sent, which makes at_max to take effect
2051 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
2054 wait_delete_completed
2058 sync_all_data || true
2060 #define QUOTA_DQACQ 601
2061 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
2062 lustre_fail mds 0x513 601
2064 do_facet ost1 $LCTL set_param \
2065 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
2067 # write to un-enforced ID ($TSTUSR2) should succeed
2068 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
2069 error "write failure, expect success"
2071 # write to enforced ID ($TSTUSR) in background, exceeding limit
2072 # to make sure DQACQ is sent
2073 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
2076 # watchdog timer uses a factor of 2
2077 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
2078 sleep $((TIMEOUT * 2 + 1))
2080 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
2082 # write should be blocked and never finished
2083 if ! ps -p $DDPID > /dev/null 2>&1; then
2085 error "write finished incorrectly!"
2090 # no watchdog is triggered
2091 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2092 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2093 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2094 [ -z "$watchdog" ] || error "$watchdog"
2096 rm -f $TMP/lustre-log-${TESTNAME}.log
2098 # write should continue then fail with EDQUOT
2102 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2103 if [ $count -ge 240 ]; then
2104 quota_error u $TSTUSR "dd not finished in $count secs"
2106 count=$((count + 1))
2107 if [ $((count % 30)) -eq 0 ]; then
2108 c_size=$(stat -c %s $TESTFILE)
2109 echo "Waiting $count secs. $c_size"
2115 run_test 6 "Test dropping acquire request on master"
2117 # quota reintegration (global index)
2119 local TESTFILE=$DIR/$tdir/$tfile
2122 [ "$SLOW" = "no" ] && LIMIT=5
2124 setup_quota_test || error "setup quota failed with $?"
2126 # make sure the system is clean
2127 local USED=$(getquota -u $TSTUSR global curspace)
2128 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2130 # make sure no granted quota on ost1
2131 set_ost_qtype $QTYPE || error "enable ost quota failed"
2132 resetquota -u $TSTUSR
2133 set_ost_qtype "none" || error "disable ost quota failed"
2135 local OSTUUID=$(ostuuid_from_index 0)
2136 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2138 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2141 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2142 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2147 echo "Enable quota & set quota limit for $TSTUSR"
2148 set_ost_qtype $QTYPE || error "enable ost quota failed"
2149 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2150 error "set quota failed"
2152 echo "Start ost1..."
2153 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2156 wait_ost_reint $QTYPE || error "reintegration failed"
2158 # hardlimit should have been fetched by slave during global
2159 # reintegration, write will exceed quota
2160 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2161 quota_error u $TSTUSR "write success, but expect EDQUOT"
2164 wait_delete_completed
2165 sync_all_data || true
2171 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2172 error "clear quota failed"
2174 echo "Start ost1..."
2175 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2178 wait_ost_reint $QTYPE || error "reintegration failed"
2180 # hardlimit should be cleared on slave during reintegration
2181 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2182 quota_error u $TSTUSR "write error, but expect success"
2184 run_test 7a "Quota reintegration (global index)"
2186 # quota reintegration (slave index)
2188 local limit=100000 # MB
2189 local TESTFILE=$DIR/$tdir/$tfile
2191 setup_quota_test || error "setup quota failed with $?"
2193 # make sure the system is clean
2194 local USED=$(getquota -u $TSTUSR global curspace)
2195 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2197 # make sure no granted quota on ost1
2198 set_ost_qtype $QTYPE || error "enable ost quota failed"
2199 resetquota -u $TSTUSR
2200 set_ost_qtype "none" || error "disable ost quota failed"
2202 local OSTUUID=$(ostuuid_from_index 0)
2203 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2205 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2208 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2209 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2211 # consume some space to make sure the granted space will not
2212 # be released during reconciliation
2213 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2214 error "consume space failure, expect success"
2216 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2217 lustre_fail mds 0xa02
2219 set_ost_qtype $QTYPE || error "enable ost quota failed"
2220 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2221 error "set quota failed"
2223 # ignore the write error
2224 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2226 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2230 echo "Restart ost to trigger reintegration..."
2232 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2235 wait_ost_reint $QTYPE || error "reintegration failed"
2237 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2238 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2243 run_test 7b "Quota reintegration (slave index)"
2245 # quota reintegration (restart mds during reintegration)
2248 local TESTFILE=$DIR/$tdir/$tfile
2250 [ "$SLOW" = "no" ] && LIMIT=5
2252 setup_quota_test || error "setup quota failed with $?"
2254 # make sure the system is clean
2255 local USED=$(getquota -u $TSTUSR global curspace)
2256 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2258 set_ost_qtype "none" || error "disable ost quota failed"
2259 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2260 error "set quota failed"
2262 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2263 lustre_fail ost 0xa03
2266 set_ost_qtype $QTYPE || error "enable ost quota failed"
2267 # trigger reintegration
2268 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2269 procf=${procf}quota_slave.force_reint
2270 do_facet ost1 $LCTL set_param $procf=1 ||
2271 error "force reintegration failed"
2279 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2282 # wait longer than usual to make sure the reintegration
2283 # is triggered by quota wb thread.
2284 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2286 # hardlimit should have been fetched by slave during global
2287 # reintegration, write will exceed quota
2288 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2289 quota_error u $TSTUSR "write success, but expect EDQUOT"
2292 run_test 7c "Quota reintegration (restart mds during reintegration)"
2294 # Quota reintegration (Transfer index in multiple bulks)
2296 local TESTFILE=$DIR/$tdir/$tfile
2297 local TESTFILE1="$DIR/$tdir/$tfile"-1
2300 setup_quota_test || error "setup quota failed with $?"
2302 set_ost_qtype "none" || error "disable ost quota failed"
2303 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2304 error "set quota for $TSTUSR failed"
2305 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2306 error "set quota for $TSTUSR2 failed"
2308 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2309 lustre_fail mds 0x608 0
2311 # enable quota to tirgger reintegration
2312 set_ost_qtype "u" || error "enable ost quota failed"
2313 wait_ost_reint "u" || error "reintegration failed"
2317 # hardlimit should have been fetched by slave during global
2318 # reintegration, write will exceed quota
2319 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2320 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2322 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2323 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2326 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2328 # quota reintegration (inode limits)
2330 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2332 # LU-2435: skip this quota test if underlying zfs version has not
2333 # supported native dnode accounting
2334 [ "$mds1_FSTYPE" == zfs ] && {
2335 local F="feature@userobj_accounting"
2336 local pool=$(zpool_name mds1)
2337 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2339 [[ "$feature" != *" active "* ]] &&
2340 skip "requires zpool with active userobj_accounting"
2343 local ilimit=$((1024 * 2)) # inodes
2344 local TESTFILE=$DIR/${tdir}-1/$tfile
2346 setup_quota_test || error "setup quota failed with $?"
2348 # make sure the system is clean
2349 local USED=$(getquota -u $TSTUSR global curinodes)
2350 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2352 # make sure no granted quota on mdt1
2353 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2354 resetquota -u $TSTUSR
2355 set_mdt_qtype "none" || error "disable mdt quota failed"
2357 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2358 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2359 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2362 echo "Stop mds${MDSCOUNT}..."
2365 echo "Enable quota & set quota limit for $TSTUSR"
2366 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2367 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2368 error "set quota failed"
2370 echo "Start mds${MDSCOUNT}..."
2371 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2374 wait_mdt_reint $QTYPE || error "reintegration failed"
2376 echo "create remote dir"
2377 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2378 error "create remote dir failed"
2379 chmod 0777 $DIR/${tdir}-1
2381 # hardlimit should have been fetched by slave during global
2382 # reintegration, create will exceed quota
2383 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2384 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2386 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2387 wait_delete_completed
2388 sync_all_data || true
2390 echo "Stop mds${MDSCOUNT}..."
2393 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2394 error "clear quota failed"
2396 echo "Start mds${MDSCOUNT}..."
2397 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2400 wait_mdt_reint $QTYPE || error "reintegration failed"
2402 # hardlimit should be cleared on slave during reintegration
2403 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2404 quota_error u $TSTUSR "create failed, expect success"
2406 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2407 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2409 run_test 7e "Quota reintegration (inode limits)"
2411 # run dbench with quota enabled
2413 local BLK_LIMIT="100g" #100G
2414 local FILE_LIMIT=1000000
2416 setup_quota_test || error "setup quota failed with $?"
2418 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2419 set_ost_qtype $QTYPE || error "enable ost quota failed"
2421 echo "Set enough high limit for user: $TSTUSR"
2422 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2423 error "set user quota failed"
2424 echo "Set enough high limit for group: $TSTUSR"
2425 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2426 error "set group quota failed"
2427 if is_project_quota_supported; then
2428 change_project -sp $TSTPRJID $DIR/$tdir
2429 echo "Set enough high limit for project: $TSTPRJID"
2430 $LFS setquota -p $TSTPRJID -b 0 \
2431 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2432 error "set project quota failed"
2436 [ "$SLOW" = "no" ] && duration=" -t 120"
2437 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2438 quota_error a $TSTUSR "dbench failed!"
2440 is_project_quota_supported && change_project -C $DIR/$tdir
2443 run_test 8 "Run dbench with quota enabled"
2445 # this check is just for test_9
2446 OST0_MIN=4900000 #4.67G
2448 check_whether_skip () {
2449 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2450 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2451 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2452 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2459 # run for fixing bug10707, it needs a big room. test for 64bit
2461 local filesize=$((1024 * 9 / 2)) # 4.5G
2463 check_whether_skip && return 0
2465 setup_quota_test || error "setup quota failed with $?"
2467 set_ost_qtype "ug" || error "enable ost quota failed"
2469 local TESTFILE="$DIR/$tdir/$tfile-0"
2470 local BLK_LIMIT=100G #100G
2471 local FILE_LIMIT=1000000
2473 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2475 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2477 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2478 error "set user quota failed"
2480 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2481 "for group: $TSTUSR"
2482 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2483 error "set group quota failed"
2485 quota_show_check a u $TSTUSR
2486 quota_show_check a g $TSTUSR
2488 echo "Create test file"
2489 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2490 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2492 log "Write the big file of 4.5G ..."
2493 $RUNAS $DD of=$TESTFILE count=$filesize ||
2494 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2504 run_test 9 "Block limit larger than 4GB (b10707)"
2507 local TESTFILE=$DIR/$tdir/$tfile
2509 setup_quota_test || error "setup quota failed with $?"
2511 # set limit to root user should fail
2512 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2513 error "set limit for root user successfully, expect failure"
2514 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2515 error "set limit for root group successfully, expect failure"
2516 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2517 error "set limit for project 0 successfully, expect failure"
2519 # root user can overrun quota
2520 set_ost_qtype "ug" || error "enable ost quota failed"
2522 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2523 error "set quota failed"
2524 quota_show_check b u $TSTUSR
2526 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2527 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2529 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2530 error "write failure, expect success"
2532 run_test 10 "Test quota for root user"
2535 local TESTFILE=$DIR/$tdir/$tfile
2536 setup_quota_test || error "setup quota failed with $?"
2538 set_mdt_qtype "ug" || error "enable mdt quota failed"
2539 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2540 error "set quota failed"
2542 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2543 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2545 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2546 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2549 local USED=$(getquota -u $TSTUSR global curinodes)
2550 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2552 run_test 11 "Chown/chgrp ignores quota"
2555 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2557 local blimit=22 # MB
2558 local blk_cnt=$((blimit - 5))
2559 local TESTFILE0="$DIR/$tdir/$tfile"-0
2560 local TESTFILE1="$DIR/$tdir/$tfile"-1
2562 setup_quota_test || error "setup quota failed with $?"
2564 set_ost_qtype "u" || error "enable ost quota failed"
2565 quota_show_check b u $TSTUSR
2567 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2568 error "set quota failed"
2570 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2571 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2572 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2573 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2575 echo "Write to ost0..."
2576 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2577 quota_error a $TSTUSR "dd failed"
2579 echo "Write to ost1..."
2580 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2581 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2583 echo "Free space from ost0..."
2585 wait_delete_completed
2586 sync_all_data || true
2588 echo "Write to ost1 after space freed from ost0..."
2589 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2590 quota_error a $TSTUSR "rebalancing failed"
2592 run_test 12a "Block quota rebalancing"
2595 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2597 local ilimit=$((1024 * 2)) # inodes
2598 local TESTFILE0=$DIR/$tdir/$tfile
2599 local TESTFILE1=$DIR/${tdir}-1/$tfile
2601 setup_quota_test || error "setup quota failed with $?"
2603 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2604 chmod 0777 $DIR/${tdir}-1
2606 set_mdt_qtype "u" || error "enable mdt quota failed"
2607 quota_show_check f u $TSTUSR
2609 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2610 error "set quota failed"
2612 echo "Create $ilimit files on mdt0..."
2613 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2614 quota_error u $TSTUSR "create failed, but expect success"
2616 echo "Create files on mdt1..."
2617 $RUNAS createmany -m $TESTFILE1 1 &&
2618 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2620 echo "Free space from mdt0..."
2621 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2622 wait_delete_completed
2623 sync_all_data || true
2625 echo "Create files on mdt1 after space freed from mdt0..."
2626 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2627 quota_error a $TSTUSR "rebalancing failed"
2629 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2630 error "unlink mdt1 files failed"
2631 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2633 run_test 12b "Inode quota rebalancing"
2636 local TESTFILE=$DIR/$tdir/$tfile
2637 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2638 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2640 setup_quota_test || error "setup quota failed with $?"
2642 set_ost_qtype "u" || error "enable ost quota failed"
2643 quota_show_check b u $TSTUSR
2645 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2646 error "set quota failed"
2647 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2648 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2650 # clear the locks in cache first
2651 do_facet ost1 $LCTL set_param -n $procf=clear
2652 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2653 [ $nlock -eq 0 ] || error "$nlock cached locks"
2655 # write to acquire the per-ID lock
2656 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2657 quota_error a $TSTUSR "dd failed"
2659 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2660 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2662 # clear quota doesn't trigger per-ID lock cancellation
2663 resetquota -u $TSTUSR
2664 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2665 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2667 # clear the per-ID lock
2668 do_facet ost1 $LCTL set_param -n $procf=clear
2669 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2670 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2672 # spare quota should be released
2673 local OSTUUID=$(ostuuid_from_index 0)
2674 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2675 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2676 [ $limit -le $space ] ||
2677 error "spare quota isn't released, limit:$limit, space:$space"
2679 run_test 13 "Cancel per-ID lock in the LRU list"
2683 (( $MDS1_VERSION >= $(version_code 2.15.54.67) )) ||
2684 skip "Need MDS >= v2_15_54-67-gdfe7d for qmt_site_recalc_cb fix"
2686 local qpool="qpool1"
2687 local tfile1="$DIR/$tdir/$tfile-0"
2690 setup_quota_test || error "setup quota failed with $?"
2692 set_ost_qtype $QTYPE || error "enable ost quota failed"
2694 $LFS setquota -u $TSTUSR -b 0 -B 100M -i 0 -I 0 $DIR ||
2695 error "set user quota failed"
2696 pool_add $qpool || error "pool_add failed"
2697 pool_add_targets $qpool 0 ||
2698 error "pool_add_targets failed"
2699 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
2700 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
2701 error "set user quota failed"
2703 # don't care about returned value
2704 $RUNAS $DD of=$tfile1 count=10 oflag=direct
2708 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2709 error "set user quota failed"
2711 # no panic after removing OST0000 from the pool
2712 pool_remove_target $qpool 0
2713 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2715 run_test 14 "check panic in qmt_site_recalc_cb"
2718 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2720 wait_delete_completed
2721 sync_all_data || true
2724 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2725 error "set user quota failed"
2726 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2727 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2728 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2729 resetquota -u $TSTUSR
2732 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2733 error "set group quota failed"
2734 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2735 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2736 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2737 resetquota -g $TSTUSR
2739 run_test 15 "Set over 4T block quota"
2743 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2744 skip "Not supported Lustre client before 2.14.55"
2746 setup_quota_test || error "setup quota failed with $?"
2748 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2749 error "failed to set quota for user $TSTUSR"
2750 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2751 error "failed to set quota for group $TSTUSR"
2753 $RUNAS $DD of=$DIR/$tdir/$tfile count=50 ||
2754 quota_error u $TSTUSR "write failure"
2756 $LFS quota -u $TSTUSR $MOUNT ||
2757 quota_error u $TSTUSR "failed to get quota"
2759 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2761 $LCTL --device %$OSC deactivate
2762 stack_trap "$LCTL --device %$OSC activate"
2764 $LFS quota -v -u $TSTUSR $MOUNT ||
2765 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2766 $LFS quota -v -g $TSTUSR $MOUNT ||
2767 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2769 (( $MDSCOUNT > 1 )) || return 0
2771 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2773 $LCTL --device %$MDC deactivate
2774 stack_trap "$LCTL --device %$MDC activate"
2776 $LFS quota -v -u $TSTUSR $MOUNT ||
2777 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2778 $LFS quota -v -g $TSTUSR $MOUNT ||
2779 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2781 run_test 16a "lfs quota should skip the inactive MDT/OST"
2792 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2793 skip "Not supported Lustre client before 2.14.55"
2795 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2798 if ! combined_mgs_mds ; then
2803 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2804 $(mdsdevname 1) $(mdsvdevname 1)
2805 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2806 $(mdsdevname 2) $(mdsvdevname 2)
2807 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2808 $(mdsdevname 3) $(mdsvdevname 3)
2810 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2811 $(ostdevname 1) $(ostvdevname 1)
2812 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2813 $(ostdevname 2) $(ostvdevname 2)
2815 stack_trap cleanup_16b
2817 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2818 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2819 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2820 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2821 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2823 mount_client $MOUNT || error "Unable to mount client"
2825 setup_quota_test || error "setup quota failed with $?"
2827 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2828 error "failed to set quota for user $TSTUSR"
2829 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2830 error "failed to set quota for group $TSTUSR"
2832 $RUNAS $DD of=$DIR/$tdir/$tfile count=10 ||
2833 quota_error u $TSTUSR "write failure"
2835 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2836 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2837 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2838 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2840 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2844 local BLKS=1 # 1M less than limit
2845 local TESTFILE=$DIR/$tdir/$tfile
2847 setup_quota_test || error "setup quota failed with $?"
2849 # make sure the system is clean
2850 local USED=$(getquota -u $TSTUSR global curspace)
2851 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2853 set_ost_qtype "ug" || error "enable ost quota failed"
2854 # make sure no granted quota on ost
2855 resetquota -u $TSTUSR
2856 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2857 error "set quota failed"
2859 quota_show_check b u $TSTUSR
2861 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2862 lustre_fail mds 0xa04 $err_code
2864 # write in background
2865 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2869 # write should be blocked and never finished
2870 if ! ps -p $DDPID > /dev/null 2>&1; then
2872 quota_error u $TSTUSR "write finished incorrectly!"
2880 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2882 if [ $count -gt $timeout ]; then
2883 quota_error u $TSTUSR "dd is not finished!"
2888 sync; sync_all_data || true
2890 USED=$(getquota -u $TSTUSR global curspace)
2891 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2892 "Used space(${USED}K) is less than ${BLKS}M"
2897 # DQACQ return recoverable error
2899 echo "DQACQ return -ENOLCK"
2901 test_17sub 37 || error "Handle -ENOLCK failed"
2903 echo "DQACQ return -EAGAIN"
2905 test_17sub 11 || error "Handle -EAGAIN failed"
2907 echo "DQACQ return -ETIMEDOUT"
2908 #define ETIMEDOUT 110
2909 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2911 echo "DQACQ return -ENOTCONN"
2912 #define ENOTCONN 107
2913 test_17sub 107 || error "Handle -ENOTCONN failed"
2916 run_test 17 "DQACQ return recoverable error"
2920 local blimit=200 # MB
2921 local TESTFILE="$DIR/$tdir/$tfile"
2923 setup_quota_test || error "setup quota failed with $?"
2925 set_ost_qtype "u" || error "enable ost quota failed"
2926 log "User quota (limit: $blimit)"
2927 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2928 error "set quota failed"
2929 quota_show_check b u $TSTUSR
2931 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2932 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2934 local timeout=$($LCTL get_param -n timeout)
2936 if [ $io_type = "directio" ]; then
2937 log "Write 100M (directio) ..."
2938 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2940 log "Write 100M (buffered) ..."
2941 $RUNAS $DD of=$TESTFILE count=100 &
2945 replay_barrier $SINGLEMDS
2946 log "Fail mds for $((2 * timeout)) seconds"
2947 fail $SINGLEMDS $((2 * timeout))
2950 if at_is_enabled; then
2951 timeout=$(at_max_get mds)
2953 timeout=$($LCTL get_param -n timeout)
2957 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2958 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2959 log "it took $count second"
2964 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2966 cancel_lru_locks mdc
2967 cancel_lru_locks osc
2970 local testfile_size=$(stat -c %s $TESTFILE)
2971 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2972 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2973 "got ${testfile_size}. Verifying file failed!"
2978 # test when mds does failover, the ost still could work well
2979 # this test shouldn't trigger watchdog b=14840
2981 # Clear dmesg so watchdog is not triggered by previous
2983 do_facet ost1 dmesg -c > /dev/null
2986 test_18_sub directio
2988 # check if watchdog is triggered
2989 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2990 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2991 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2992 [ -z "$watchdog" ] || error "$watchdog"
2993 rm -f $TMP/lustre-log-${TESTNAME}.log
2995 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2999 local TESTFILE=$DIR/$tdir/$tfile
3001 setup_quota_test || error "setup quota failed with $?"
3003 set_ost_qtype $QTYPE || error "enable ost quota failed"
3005 # bind file to a single OST
3006 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3007 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3009 echo "Set user quota (limit: ${blimit}M)"
3010 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
3011 error "set user quota failed"
3012 quota_show_check b u $TSTUSR
3013 echo "Update quota limits"
3014 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
3015 error "set group quota failed"
3016 quota_show_check b u $TSTUSR
3018 # first wirte might be cached
3019 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
3020 cancel_lru_locks osc
3022 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
3023 quota_error u $TSTUSR "Write success, expect failure"
3026 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
3028 test_20() { # b15754
3029 local LSTR=(2g 1t 4k 3m) # limits strings
3031 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
3034 resetquota -u $TSTUSR
3036 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
3037 $MOUNT || error "could not set quota limits"
3038 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
3039 --inode-softlimit ${LSTR[2]} \
3040 --inode-hardlimit ${LSTR[3]} \
3041 $MOUNT || error "could not set quota limits"
3043 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
3044 error "bsoftlimit was not set properly"
3045 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
3046 error "bhardlimit was not set properly"
3047 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
3048 error "isoftlimit was not set properly"
3049 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
3050 error "ihardlimit was not set properly"
3052 resetquota -u $TSTUSR
3054 run_test 20 "Test if setquota specifiers work properly (b15754)"
3061 local time=$(($(date +%s) + seconds))
3062 while [ $(date +%s) -lt $time ]; do
3063 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
3067 # run for fixing bug16053, setquota shouldn't fail when writing and
3068 # deleting are happening
3070 local TESTFILE="$DIR/$tdir/$tfile"
3071 local BLIMIT=10 # 10G
3072 local ILIMIT=1000000
3074 setup_quota_test || error "setup quota failed with $?"
3076 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3078 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
3079 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
3080 error "set user quota failed"
3081 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
3082 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
3083 error "set group quota failed"
3084 if is_project_quota_supported; then
3085 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
3086 "project: $TSTPRJID"
3087 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
3088 $MOUNT || error "set project quota failed"
3091 # repeat writing on a 1M file
3092 test_21_sub ${TESTFILE}_1 1 30 &
3094 # repeat writing on a 128M file
3095 test_21_sub ${TESTFILE}_2 128 30 &
3098 local time=$(($(date +%s) + 30))
3100 while [ $(date +%s) -lt $time ]; do
3101 log "Set quota for $i times"
3102 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3103 -I $((ILIMIT + i)) $MOUNT ||
3104 error "Set user quota failed"
3105 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3106 -I $((ILIMIT + i)) $MOUNT ||
3107 error "Set group quota failed"
3108 if is_project_quota_supported; then
3109 $LFS setquota -p $TSTPRJID -b 0 -B \
3110 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
3111 error "Set project quota failed"
3119 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
3121 if [ $count -gt 60 ]; then
3122 quota_error a $TSTUSR "dd should be finished!"
3126 echo "(dd_pid=$DDPID1, time=$count)successful"
3130 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
3132 if [ $count -gt 60 ]; then
3133 quota_error a $TSTUSR "dd should be finished!"
3137 echo "(dd_pid=$DDPID2, time=$count)successful"
3139 run_test 21 "Setquota while writing & deleting (b16053)"
3141 # enable/disable quota enforcement permanently
3143 echo "Set both mdt & ost quota type as ug"
3145 is_project_quota_supported && qtype=$QTYPE
3146 set_mdt_qtype $qtype || error "enable mdt quota failed"
3147 set_ost_qtype $qtype || error "enable ost quota failed"
3150 stopall || error "failed to stopall (1)"
3154 echo "Verify if quota is enabled"
3155 local qtype1=$(mdt_quota_type)
3156 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3157 qtype=$(ost_quota_type)
3158 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3160 echo "Set both mdt & ost quota type as none"
3161 set_mdt_qtype "none" || error "disable mdt quota failed"
3162 set_ost_qtype "none" || error "disable ost quota failed"
3165 stopall || error "failed to stopall (2)"
3170 echo "Verify if quota is disabled"
3171 qtype=$(mdt_quota_type)
3172 [ $qtype != "none" ] && error "mdt quota setting is lost"
3173 qtype=$(ost_quota_type)
3174 [ $qtype != "none" ] && error "ost quota setting is lost"
3178 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3181 local TESTFILE="$DIR/$tdir/$tfile"
3184 setup_quota_test || error "setup quota failed with $?"
3186 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3189 log "User quota (limit: $LIMIT MB)"
3190 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3191 error "set quota failed"
3192 quota_show_check b u $TSTUSR
3194 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3195 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3197 log "Step1: trigger EDQUOT with O_DIRECT"
3198 log "Write half of file"
3199 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3200 quota_error u $TSTUSR "(1) Write failure, expect success." \
3202 log "Write out of block quota ..."
3203 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3204 oflag=direct conv=notrunc &&
3205 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3209 log "Step2: rewrite should succeed"
3210 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3211 quota_error u $TSTUSR "(3) Write failure, expect success." \
3217 local OST0_UUID=$(ostuuid_from_index 0)
3218 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3219 [ $OST0_QUOTA_USED -ne 0 ] &&
3220 ($SHOW_QUOTA_USER; \
3221 quota_error u $TSTUSR "quota isn't released")
3226 [ "$ost1_FSTYPE" == zfs ] &&
3227 skip "Overwrite in place is not guaranteed to be " \
3228 "space neutral on ZFS"
3230 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3231 check_whether_skip && return 0
3232 log "run for 4MB test file"
3235 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3236 check_whether_skip && return 0
3237 log "run for 40MB test file"
3240 run_test 23 "Quota should be honored with directIO (b16125)"
3244 local TESTFILE="$DIR/$tdir/$tfile"
3246 setup_quota_test || error "setup quota failed with $?"
3248 set_ost_qtype $QTYPE || error "enable ost quota failed"
3250 # bind file to a single OST
3251 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3252 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3254 echo "Set user quota (limit: ${blimit}M)"
3255 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3256 error "set quota failed"
3258 # overrun quota by root user
3259 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3260 error "write failure, expect success"
3261 cancel_lru_locks osc
3262 sync_all_data || true
3264 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3266 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3270 (( $MDS1_VERSION >= $(version_code 2.15.55.145) )) ||
3271 skip "need MDS >= v2_15_55-145-g513b1cdbc for index version fix"
3273 local limit=10 # 10M
3274 local testfile="$DIR/$tdir/$tfile-0"
3275 local qpool="qpool1"
3278 setup_quota_test || error "setup quota failed with $?"
3281 set_ost_qtype $QTYPE || error "enable ost quota failed"
3283 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
3284 error "set user quota failed"
3286 pool_add $qpool || error "pool_add failed"
3287 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
3288 error "pool_add_targets failed"
3290 # increase ost index version to +200
3291 for i in {1..200}; do
3292 $LFS setquota -u $TSTUSR -B ${i}G --pool $qpool $DIR ||
3293 error "set user quota failed"
3295 $LFS setquota -u $TSTUSR -b 0 -B 0 --pool $qpool $DIR ||
3296 error "set user quota failed"
3298 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
3299 error "set user quota failed"
3301 local used=$(getquota -u $TSTUSR global curspace)
3302 (( used == 0)) || error "Used space($used) for user $TSTUSR isn't 0."
3304 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
3305 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
3307 test_1_check_write $testfile "user" $limit
3310 run_test 25 "check indexes versions"
3312 test_27a() { # b19612
3313 $LFS quota $TSTUSR $DIR &&
3314 error "lfs succeeded with no type, but should have failed"
3315 $LFS setquota $TSTUSR $DIR &&
3316 error "lfs succeeded with no type, but should have failed"
3319 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3321 test_27b() { # b20200
3322 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3323 error "lfs setquota failed with uid argument"
3324 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3325 error "lfs stequota failed with gid argument"
3326 if is_project_quota_supported; then
3327 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3328 1000 $DIR || error \
3329 "lfs stequota failed with projid argument"
3331 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3332 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3333 if is_project_quota_supported; then
3334 $SHOW_QUOTA_PROJID ||
3335 error "lfs quota failed with projid argument"
3336 resetquota_one -p $TSTPRJID
3338 resetquota -u $TSTID
3339 resetquota -g $TSTID
3342 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3347 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3348 error "lfs setquota failed"
3350 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3351 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3352 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3353 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3355 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3356 error "lfs setquota for $TSTID failed"
3358 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3359 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3360 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3361 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3363 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3364 error "total allocated inode/block limit not printed"
3366 resetquota -u $TSTUSR
3368 run_test 27c "lfs quota should support human-readable output"
3375 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3376 error "set fraction block limit failed"
3377 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3378 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3379 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3380 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3382 resetquota -u $TSTUSR
3384 run_test 27d "lfs setquota should support fraction block limit"
3388 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
3389 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
3392 local TESTFILE="$DIR/$tdir/$tfile"
3395 setup_quota_test || error "setup quota failed with $?"
3397 set_ost_qtype "u" || error "enable ost quota failed"
3399 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3400 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3402 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3403 $MAX_IQ_TIME $DIR || error "set grace time failed"
3404 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3405 error "set quota failed"
3406 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3407 cancel_lru_locks osc
3409 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3410 # over-quota flag has not yet settled since we do not trigger async
3411 # events based on grace time period expiration
3413 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3414 cancel_lru_locks osc
3415 # now over-quota flag should be settled and further writes should fail
3417 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3418 error "grace times were reset"
3419 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3420 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3422 run_test 30 "Hard limit updates should not reset grace times"
3424 # basic usage tracking for user & group
3426 local INODES=10 # files
3427 local BLK_CNT=2 # MB each
3428 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3430 setup_quota_test || error "setup quota failed with $?"
3432 # make sure the system is clean
3433 local USED=$(getquota -u $TSTID global curspace)
3435 error "Used space ($USED) for user $TSTID isn't 0."
3436 USED=$(getquota -g $TSTID global curspace)
3438 error "Used space ($USED) for group $TSTID isn't 0."
3439 if is_project_quota_supported; then
3440 USED=$(getquota -p $TSTPRJID global curspace)
3441 [ $USED -ne 0 ] && error \
3442 "Used space ($USED) for project $TSTPRJID isn't 0."
3445 echo "Write files..."
3446 for i in $(seq 0 $INODES); do
3447 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3448 error "write failed"
3449 is_project_quota_supported &&
3450 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3451 echo "Iteration $i/$INODES completed"
3453 cancel_lru_locks osc
3455 echo "Wait for setattr on objects finished..."
3456 wait_delete_completed
3458 sync; sync_all_data || true
3460 echo "Verify disk usage after write"
3461 USED=$(getquota -u $TSTID global curspace)
3462 [ $USED -lt $TOTAL_BLKS ] &&
3463 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3464 USED=$(getquota -g $TSTID global curspace)
3465 [ $USED -lt $TOTAL_BLKS ] &&
3466 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3467 if is_project_quota_supported; then
3468 USED=$(getquota -p $TSTPRJID global curspace)
3469 [ $USED -lt $TOTAL_BLKS ] && error \
3470 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3473 echo "Verify inode usage after write"
3474 USED=$(getquota -u $TSTID global curinodes)
3475 [ $USED -lt $INODES ] &&
3476 error "Used inode for user $TSTID is $USED, expected $INODES"
3477 USED=$(getquota -g $TSTID global curinodes)
3478 [ $USED -lt $INODES ] &&
3479 error "Used inode for group $TSTID is $USED, expected $INODES"
3480 if is_project_quota_supported; then
3481 USED=$(getquota -p $TSTPRJID global curinodes)
3482 [ $USED -lt $INODES ] && error \
3483 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3488 echo "Verify disk usage after delete"
3489 USED=$(getquota -u $TSTID global curspace)
3490 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3491 USED=$(getquota -u $TSTID global curinodes)
3492 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3493 USED=$(getquota -g $TSTID global curspace)
3494 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3495 USED=$(getquota -g $TSTID global curinodes)
3496 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3497 if is_project_quota_supported; then
3498 USED=$(getquota -p $TSTPRJID global curspace)
3500 error "Used space for project $TSTPRJID isn't 0. $USED"
3501 USED=$(getquota -p $TSTPRJID global curinodes)
3503 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3506 run_test 33 "Basic usage tracking for user & group & project"
3508 # usage transfer test for user & group & project
3510 local BLK_CNT=2 # MB
3511 local project_supported="no"
3513 is_project_quota_supported && project_supported="yes"
3514 setup_quota_test || error "setup quota failed with $?"
3516 # make sure the system is clean
3517 local USED=$(getquota -u $TSTID global curspace)
3518 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3519 USED=$(getquota -g $TSTID global curspace)
3520 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3522 local USED=$(getquota -u $TSTID2 global curspace)
3523 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3524 if [ $project_supported == "yes" ]; then
3525 USED=$(getquota -p $TSTPRJID global curspace)
3526 [ $USED -ne 0 ] && error \
3527 "Used space ($USED) for Project $TSTPRJID isn't 0."
3530 echo "Write file..."
3531 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3532 error "write failed"
3533 cancel_lru_locks osc
3534 sync; sync_all_data || true
3536 echo "chown the file to user $TSTID"
3537 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3539 echo "Wait for setattr on objects finished..."
3540 wait_delete_completed
3542 BLK_CNT=$((BLK_CNT * 1024))
3544 echo "Verify disk usage for user $TSTID"
3545 USED=$(getquota -u $TSTID global curspace)
3546 [ $USED -lt $BLK_CNT ] &&
3547 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3548 USED=$(getquota -u $TSTID global curinodes)
3550 error "Used inodes for user $TSTID is $USED, expected 1"
3552 echo "chgrp the file to group $TSTID"
3553 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3555 echo "Wait for setattr on objects finished..."
3556 wait_delete_completed
3558 echo "Verify disk usage for group $TSTID"
3559 USED=$(getquota -g $TSTID global curspace)
3560 [ $USED -ge $BLK_CNT ] ||
3561 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3562 USED=$(getquota -g $TSTID global curinodes)
3564 error "Used inodes for group $TSTID is $USED, expected 1"
3566 # chown won't change the ost object group. LU-4345 */
3567 echo "chown the file to user $TSTID2"
3568 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3570 echo "Wait for setattr on objects finished..."
3571 wait_delete_completed
3573 echo "change_project project id to $TSTPRJID"
3574 [ $project_supported == "yes" ] &&
3575 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3576 echo "Wait for setattr on objects finished..."
3577 wait_delete_completed
3579 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3580 USED=$(getquota -u $TSTID2 global curspace)
3581 [ $USED -lt $BLK_CNT ] &&
3582 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3583 USED=$(getquota -u $TSTID global curspace)
3585 error "Used space for user $TSTID is $USED, expected 0"
3586 USED=$(getquota -g $TSTID global curspace)
3587 [ $USED -lt $BLK_CNT ] &&
3588 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3589 if [ $project_supported == "yes" ]; then
3590 USED=$(getquota -p $TSTPRJID global curspace)
3591 [ $USED -lt $BLK_CNT ] && error \
3592 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3596 run_test 34 "Usage transfer for user & group & project"
3598 # usage is still accessible across restart
3600 local BLK_CNT=2 # MB
3602 setup_quota_test || error "setup quota failed with $?"
3604 echo "Write file..."
3605 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3606 error "write failed"
3607 is_project_quota_supported &&
3608 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3611 echo "Wait for setattr on objects finished..."
3612 wait_delete_completed
3614 sync; sync_all_data || true
3616 echo "Save disk usage before restart"
3617 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3618 [ $ORIG_USR_SPACE -eq 0 ] &&
3619 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3620 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3621 [ $ORIG_USR_INODES -eq 0 ] &&
3622 error "Used inodes for user $TSTID is 0, expected 1"
3623 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3624 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3625 [ $ORIG_GRP_SPACE -eq 0 ] &&
3626 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3627 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3628 [ $ORIG_GRP_INODES -eq 0 ] &&
3629 error "Used inodes for group $TSTID is 0, expected 1"
3630 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3632 if is_project_quota_supported; then
3633 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3634 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3635 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3636 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3637 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3638 "Used inodes for project $TSTPRJID is 0, expected 1"
3639 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3645 wait_recovery_complete
3648 echo "Verify disk usage after restart"
3649 local USED=$(getquota -u $TSTID global curspace)
3650 (( $USED == $ORIG_USR_SPACE )) || {
3651 ls -al $DIR/$tdir/$tfile
3652 $LFS quota -v -u $TSTID $DIR
3653 error "Used space for user $TSTID changed from " \
3654 "$ORIG_USR_SPACE to $USED"
3656 USED=$(getquota -u $TSTID global curinodes)
3657 [ $USED -eq $ORIG_USR_INODES ] ||
3658 error "Used inodes for user $TSTID changed from " \
3659 "$ORIG_USR_INODES to $USED"
3660 USED=$(getquota -g $TSTID global curspace)
3661 [ $USED -eq $ORIG_GRP_SPACE ] ||
3662 error "Used space for group $TSTID changed from " \
3663 "$ORIG_GRP_SPACE to $USED"
3664 USED=$(getquota -g $TSTID global curinodes)
3665 [ $USED -eq $ORIG_GRP_INODES ] ||
3666 error "Used inodes for group $TSTID changed from " \
3667 "$ORIG_GRP_INODES to $USED"
3668 if [[ $project_supported == "yes" ]]; then
3669 USED=$(getquota -p $TSTPRJID global curinodes)
3670 (( $USED == $ORIG_PRJ_INODES )) ||
3671 error "Used inodes for project $TSTPRJID " \
3672 "changed from $ORIG_PRJ_INODES to $USED"
3673 USED=$(getquota -p $TSTPRJID global curspace)
3674 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3675 error "Used space for project $TSTPRJID "\
3676 "changed from $ORIG_PRJ_SPACE to $USED"
3679 # check if the vfs_dq_init() is called before writing
3680 echo "Append to the same file..."
3681 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3682 error "write failed"
3683 cancel_lru_locks osc
3684 sync; sync_all_data || true
3686 echo "Verify space usage is increased"
3687 USED=$(getquota -u $TSTID global curspace)
3688 [ $USED -gt $ORIG_USR_SPACE ] ||
3689 error "Used space for user $TSTID isn't increased" \
3690 "orig:$ORIG_USR_SPACE, now:$USED"
3691 USED=$(getquota -g $TSTID global curspace)
3692 [ $USED -gt $ORIG_GRP_SPACE ] ||
3693 error "Used space for group $TSTID isn't increased" \
3694 "orig:$ORIG_GRP_SPACE, now:$USED"
3695 if [[ $project_supported == "yes" ]]; then
3696 USED=$(getquota -p $TSTPRJID global curspace)
3697 (( $USED > $ORIG_PRJ_SPACE )) ||
3698 error "Used space for project $TSTPRJID isn't " \
3699 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3702 run_test 35 "Usage is still accessible across reboot"
3704 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3707 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3708 skip "Old server doesn't have LU-5006 fix."
3710 setup_quota_test || error "setup quota failed with $?"
3712 # make sure the system is clean
3713 local USED=$(getquota -u $TSTID global curspace)
3715 error "Used space ($USED) for user $TSTID isn't 0."
3717 # create file with MDS_OPEN_DELAY_CREATE flag
3718 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3719 error "Create file failed"
3721 $DD of=$DIR/$tdir/$tfile count=1 conv=notrunc \
3722 oflag=sync || error "Write file failed"
3724 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3726 # wait for setattr on objects finished..."
3727 wait_delete_completed
3729 USED=$(getquota -u $TSTID global curspace)
3730 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3732 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3736 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3737 skip "Old server doesn't have LU-8801 fix."
3739 [ "$UID" != 0 ] && skip_env "must run as root" && return
3741 setup_quota_test || error "setup quota failed with $?"
3743 # make sure the system is clean
3744 local USED=$(getquota -u $TSTID global curspace)
3746 error "Used space ($USED) for user $TSTID isn't 0."
3747 USED=$(getquota -u $TSTID2 global curspace)
3749 error "Used space ($USED) for user $TSTID2 isn't 0."
3751 local TESTFILE="$DIR/$tdir/$tfile"
3752 local file_cnt=10000
3754 # Generate id entries in accounting file
3755 echo "Create $file_cnt files..."
3756 for i in `seq $file_cnt`; do
3758 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3759 error "failed to chown $TESTFILE-$i"
3761 cancel_lru_locks osc
3762 sync; sync_all_data || true
3764 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3765 procf=${procf}.quota_slave.acct_user
3768 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3769 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3770 echo "Found $acct_cnt id entries"
3772 [ $file_cnt -eq $acct_cnt ] || {
3773 do_facet mds1 $LCTL get_param $procf
3774 error "skipped id entries"
3777 run_test 38 "Quota accounting iterator doesn't skip id entries"
3780 local TESTFILE="$DIR/$tdir/project"
3781 ! is_project_quota_supported &&
3782 skip "Project quota is not supported"
3784 setup_quota_test || error "setup quota failed with $?"
3787 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3788 [ $projectid -ne 0 ] &&
3789 error "Project id should be 0 not $projectid"
3790 change_project -p 1024 $TESTFILE
3791 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3792 [ $projectid -ne 1024 ] &&
3793 error "Project id should be 1024 not $projectid"
3795 stopall || error "failed to stopall (1)"
3798 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3799 [ $projectid -eq 1024 ] ||
3800 error "Project id should be 1024 not $projectid"
3802 run_test 39 "Project ID interface works correctly"
3805 ! is_project_quota_supported &&
3806 skip "Project quota is not supported"
3807 local dir1="$DIR/$tdir/dir1"
3808 local dir2="$DIR/$tdir/dir2"
3810 setup_quota_test || error "setup quota failed with $?"
3812 mkdir -p $dir1 $dir2
3813 change_project -sp 1 $dir1 && touch $dir1/1
3814 change_project -sp 2 $dir2
3816 ln $dir1/1 $dir2/1_link &&
3817 error "Hard link across different project quota should fail"
3820 run_test 40a "Hard link across different project ID"
3823 ! is_project_quota_supported &&
3824 skip "Project quota is not supported"
3825 local dir1="$DIR/$tdir/dir1"
3826 local dir2="$DIR/$tdir/dir2"
3828 setup_quota_test || error "setup quota failed with $?"
3829 mkdir -p $dir1 $dir2
3830 change_project -sp 1 $dir1 && touch $dir1/1
3831 change_project -sp 2 $dir2
3833 mv $dir1/1 $dir2/2 || error "mv failed $?"
3834 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3835 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3837 run_test 40b "Mv across different project ID"
3840 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3841 ! is_project_quota_supported &&
3842 skip "Project quota is not supported"
3844 setup_quota_test || error "setup quota failed with $?"
3845 local dir="$DIR/$tdir/dir"
3847 mkdir -p $dir && change_project -sp 1 $dir
3848 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3849 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3850 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3851 touch $dir/remote_dir/file
3852 #verify inherit works file for remote dir.
3853 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3854 [ "$projid" != "1" ] &&
3855 error "file under remote dir expected 1 not $projid"
3857 #Agent inode should be ignored for project quota
3858 local used=$(getquota -p 1 global curinodes)
3860 error "file count expected 3 got $used"
3862 run_test 40c "Remote child Dir inherit project quota properly"
3865 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3866 is_project_quota_supported || skip "Project quota is not supported"
3868 setup_quota_test || error "setup quota failed with $?"
3869 local dir="$DIR/$tdir/dir"
3872 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3873 change_project -sp $TSTPRJID $dir ||
3874 error "change project on $dir failed"
3875 for i in $(seq 5); do
3876 mkdir -p $dir/d$i/d$i ||
3877 error "mkdir $dir/d$i/d$i failed"
3878 local projid=$($LFS project -d $dir/d$i/d$i |
3880 [ "$projid" == "$TSTPRJID" ] ||
3881 error "projid id expected $TSTPRJID not $projid"
3882 touch $dir/d$i/d$i/file
3883 #verify inherit works file for stripe dir.
3884 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3885 [ "$projid" == "$TSTPRJID" ] ||
3886 error "file under remote dir expected 1 not $projid"
3889 # account should be 1 + (2 + 1) *10 + 1 * 5
3890 local used=$(getquota -p $TSTPRJID global curinodes)
3892 error "file count expected 36 got $used"
3894 run_test 40d "Stripe Directory inherit project quota properly"
3897 is_project_quota_supported ||
3898 skip "Project quota is not supported"
3899 setup_quota_test || error "setup quota failed with $?"
3900 local dir="$DIR/$tdir/dir"
3903 local projid=$((testnum * 1000))
3907 # enable mdt/ost quota
3908 set_mdt_qtype ugp || error "enable mdt quota failed"
3909 set_ost_qtype ugp || error "enable ost quota failed"
3911 local statfs_prj_orig=$($LCTL get_param -n llite.*.statfs_project)
3912 (( statfs_prj_orig == 1 )) ||
3913 $LCTL set_param llite.*.statfs_project=1
3914 stack_trap "$LCTL set_param llite.*.statfs_project=$statfs_prj_orig"
3916 test_mkdir -p $dir && change_project -sp $projid $dir
3917 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3918 error "set project quota failed"
3923 # check if df output works as expected
3924 echo "== global statfs: $MOUNT =="
3925 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3927 echo "== project statfs (prjid=$projid): $dir =="
3928 df -kP $dir; df -iP $dir
3929 local bused=$(getquota -p $projid global curspace)
3930 local iused=$(getquota -p $projid global curinodes)
3931 local expected="$ilimit$iused"
3933 wait_update $HOSTNAME \
3934 "df -iP $dir | awk \\\"/$FSNAME/\\\"'{print \\\$2 \\\$3}'" \
3936 error "failed to get correct statfs for project quota"
3938 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $2}')
3939 (( expected == blimit )) ||
3940 error "blimit mismatch: $expected != $blimit"
3942 # zfs block size is 4K, while quota is printed in 1K, df result may be
3943 # larger than quota result, but it's no more than 3K
3944 expected=$(df -kP $dir | awk "/$FSNAME/"' {print $3}')
3945 (( expected - bused < 4)) || error "bused mismatch: $expected != $bused"
3947 # disable statfs_project and check again
3948 $LCTL set_param llite.*.statfs_project=0
3950 expected=$({ df -kP $MOUNT; df -iP $MOUNT; } | \
3951 awk '/'$FSNAME'/ { printf "%d %d ", $2,$3 }')
3953 wait_update $HOSTNAME \
3954 "{ df -kP $dir; df -iP $dir; } |
3955 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3957 error "failed to get correct statfs when statfs_project=0"
3959 run_test 41 "df should return projid-specific values"
3967 local osd="osd-ldiskfs"
3969 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3971 rm -f $DIR/$tdir/$tfile
3972 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3973 chmod a+rw $DIR/$tdir/$tfile
3975 $LFS setquota $qtype $qid -B 300M $MOUNT
3976 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3978 do_facet $SINGLEMDS \
3979 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3980 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3983 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3984 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3986 $LFS setquota $qtype $qid --delete $MOUNT
3987 do_facet $SINGLEMDS \
3988 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3989 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3992 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3993 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3995 $LFS setquota $qtype $qid -B 500M $MOUNT
3996 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3997 do_facet $SINGLEMDS \
3998 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3999 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
4000 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
4002 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
4003 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
4008 setup_quota_test || error "setup quota failed with $?"
4009 set_ost_qtype $QTYPE || error "enable ost quota failed"
4012 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
4013 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
4014 is_project_quota_supported &&
4015 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
4019 run_test 48 "lfs quota --delete should delete quota project ID"
4021 test_get_allquota() {
4029 local TFILE="$DIR/$tdir/$tfile-0"
4046 local qid_cnt=$file_cnt
4048 [ $end_qid -ne 0 ] && qid_cnt=$((end_qid - start_qid + 1))
4049 [ $end_qid -ge $file_cnt ] &&
4050 qid_cnt=$((qid_cnt - end_qid + file_cnt))
4051 [ $qid_cnt -le 0 ] && error "quota ID count is wrong"
4053 cnt=$($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | wc -l)
4054 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all usr quota"
4055 cnt=$($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | wc -l)
4056 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all grp quota"
4058 cancel_lru_locks osc
4059 sync; sync_all_data || true
4062 eval $($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT |
4063 awk 'NR > 2 {printf("u_blimits[%d]=%d;u_ilimits[%d]=%d; \
4064 u_busage[%d]=%d;u_iusage[%d]=%d;", \
4065 NR, $4, NR, $8, NR, $2, NR, $6)}')
4066 eval $($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT |
4067 awk 'NR > 2 {printf("g_blimits[%d]=%d;g_ilimits[%d]=%d; \
4068 g_busage[%d]=%d;g_iusage[%d]=%d;", \
4069 NR, $4, NR, $8, NR, $2, NR, $6)}')
4071 for i in $(seq $qid_cnt); do
4072 [ $i -le 2 ] && continue
4074 [ ${u_ilimits[$i]} -eq $u_ilimit ] ||
4075 error "file limit for user ID $((start_qid + i - 3)) is wrong"
4076 [ ${u_blimits[$i]} -eq $u_blimit ] ||
4077 error "block limit for user ID $((start_qid + i - 3)) is wrong"
4078 [ ${g_ilimits[$i]} -eq $g_ilimit ] ||
4079 error "file limit for group ID $((start_qid + i - 3)) is wrong"
4080 [ ${g_blimits[$i]} -eq $g_blimit ] ||
4081 error "block limit for group ID $((start_qid + i - 3)) is wrong"
4084 echo "Create $qid_cnt files..."
4085 createmany -S 4k -U $start_qid -G $start_qid -o ${TFILE} $qid_cnt ||
4086 error "failed to create many files"
4088 cancel_lru_locks osc
4089 sync; sync_all_data || true
4093 $LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | tail -n 50
4094 total=$((SECONDS - start))
4095 (( end - start > 0 )) &&
4096 echo "time=$total, rate=$((qid_cnt / total))/s" ||
4097 echo "time=0, rate=$qid_cnt/0"
4100 $LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | tail -n 50
4101 total=$((SECONDS - start))
4102 (( end - start > 0 )) &&
4103 echo "time=$total, rate=$((qid_cnt / total))/s" ||
4104 echo "time=0, rate=$qid_cnt/0"
4106 cnt=$($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT | wc -l)
4107 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all usr quota"
4108 cnt=$($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT | wc -l)
4109 [ $cnt -ge $((qid_cnt + 2)) ] || error "failed to get all grp quota"
4111 eval $($LFS quota -a -s $start_qid -e $end_qid -u $MOUNT |
4112 awk 'NR > 2 {printf("u_blimits[%d]=%d;u_ilimits[%d]=%d; \
4113 u_busage2[%d]=%d;u_iusage2[%d]=%d;", \
4114 NR, $4, NR, $8, NR, $2, NR, $6)}')
4115 eval $($LFS quota -a -s $start_qid -e $end_qid -g $MOUNT |
4116 awk 'NR > 2 {printf("g_blimits[%d]=%d;g_ilimits[%d]=%d; \
4117 g_busage2[%d]=%d;g_iusage2[%d]=%d;", \
4118 NR, $4, NR, $8, NR, $2, NR, $6)}')
4121 for i in $(seq $qid_cnt); do
4122 [ $i -le 2 ] && continue
4124 [ ${u_ilimits[$i]} -eq $u_ilimit ] ||
4125 error "file limit for user ID $((start_qid + i - 3)) is wrong"
4126 [ ${u_blimits[$i]} -eq $u_blimit ] ||
4127 error "block limit for user ID $((start_qid + i - 3)) is wrong"
4128 [ ${g_ilimits[$i]} -eq $g_ilimit ] ||
4129 error "file limit for group ID $((start_qid + i - 3)) is wrong"
4130 [ ${g_blimits[$i]} -eq $g_blimit ] ||
4131 error "block limit for group ID $((start_qid + i - 3)) is wrong"
4132 [ ${u_iusage2[$i]} -eq $((u_iusage[$i] + 1)) ] ||
4133 error "file usage for user ID $((start_qid + i - 3)) is wrong ${u_iusage[$i]}, ${u_iusage2[$i]}"
4134 [ ${u_busage2[$i]} -ge $((u_busage[$i] + 4)) ] ||
4135 error "block usage for user ID $((start_qid + i - 3)) is wrong ${u_busage[$i]}, ${u_busage2[$i]}"
4136 [ ${g_iusage2[$i]} -eq $((g_iusage[$i] + 1)) ] ||
4137 error "file usage for group ID $((start_qid + i - 3)) is wrong ${g_iusage[$i]}, ${g_iusage2[$i]}"
4138 [ ${g_busage2[$i]} -ge $((g_busage[$i] + 4)) ] ||
4139 error "block usage for group ID $((start_qid + i - 3)) is wrong ${g_busage[$i]}, ${g_busage2[$i]}"
4142 unlinkmany ${TFILE} $qid_cnt
4147 (( MDS1_VERSION >= $(version_code 2.15.60) )) ||
4148 skip "Need MDS version at least 2.15.60"
4150 local u_blimit=102400
4151 local u_ilimit=10240
4152 local g_blimit=204800
4153 local g_ilimit=20480
4156 setup_quota_test || error "setup quota failed with $?"
4157 stack_trap cleanup_quota_test EXIT
4159 [ "$SLOW" = "yes" ] && total_file_cnt=20000 || total_file_cnt=1000
4160 total_file_cnt=${NUM_QIDS:-$total_file_cnt}
4162 local start=$SECONDS
4164 echo "setquota for users and groups"
4165 #define OBD_FAIL_QUOTA_NOSYNC 0xA09
4166 do_facet mds1 $LCTL set_param fail_loc=0xa09
4167 for i in $(seq $total_file_cnt); do
4168 $LFS setquota -u $i -B ${u_blimit} -I ${u_ilimit} $MOUNT ||
4169 error "failed to setquota for usr $i"
4170 $LFS setquota -g $i -B ${g_blimit} -I ${g_ilimit} $MOUNT ||
4171 error "failed to setquota for grp $i"
4172 (( i % 1000 == 0)) &&
4173 echo "lfs setquota: $i / $((SECONDS - start)) seconds"
4175 do_facet mds1 $LCTL set_param fail_loc=0
4178 $LFS quota -a -u $MOUNT | tail -n 100
4179 echo "get all usr quota: $total_file_cnt / $((SECONDS - start)) seconds"
4182 $LFS quota -a -g $MOUNT | tail -n 100
4183 echo "get all grp quota: $total_file_cnt / $((SECONDS - start)) seconds"
4186 test_get_allquota $total_file_cnt $count $((count + 5000)) \
4187 $u_blimit $u_ilimit $g_blimit $g_ilimit
4188 test_get_allquota $total_file_cnt $count $((count + 5000)) \
4189 $u_blimit $u_ilimit $g_blimit $g_ilimit
4191 count=$((count + 5000))
4192 [ $count -gt $total_file_cnt ] && break
4195 do_facet mds1 $LCTL set_param fail_loc=0xa08
4196 for i in $(seq $total_file_cnt); do
4197 $LFS setquota -u $i --delete $MOUNT
4198 $LFS setquota -g $i --delete $MOUNT
4200 do_facet mds1 $LCTL set_param fail_loc=0
4205 run_test 49 "lfs quota -a prints the quota usage for all quota IDs"
4208 ! is_project_quota_supported &&
4209 skip "Project quota is not supported"
4211 setup_quota_test || error "setup quota failed with $?"
4212 local dir1="$DIR/$tdir/dir1"
4213 local dir2="$DIR/$tdir/dir2"
4215 mkdir -p $dir1 && change_project -sp 1 $dir1
4216 mkdir -p $dir2 && change_project -sp 2 $dir2
4217 for num in $(seq 1 10); do
4218 touch $dir1/file_$num $dir2/file_$num
4219 ln -s $dir1/file_$num $dir1/file_$num"_link"
4220 ln -s $dir2/file_$num $dir2/file_$num"_link"
4223 count=$($LFS find --projid 1 $DIR | wc -l)
4224 [ "$count" != 21 ] && error "expected 21 but got $count"
4226 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
4227 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
4228 [ $count -eq 22 ] || error "expected 22 but got $count"
4230 run_test 50 "Test if lfs find --projid works"
4233 ! is_project_quota_supported &&
4234 skip "Project quota is not supported"
4235 setup_quota_test || error "setup quota failed with $?"
4236 local dir="$DIR/$tdir/dir"
4238 mkdir $dir && change_project -sp 1 $dir
4239 local used=$(getquota -p 1 global curinodes)
4240 [ $used != "1" ] && error "expected 1 got $used"
4245 used=$(getquota -p 1 global curinodes)
4246 [ $used != "4" ] && error "expected 4 got $used"
4248 $DD of=$DIR/$tdir/6 count=1
4250 cp $DIR/$tdir/6 $dir/6
4251 used=$(getquota -p 1 global curinodes)
4252 [ $used != "5" ] && error "expected 5 got $used"
4255 mv $DIR/$tdir/6 $dir/7
4256 used=$(getquota -p 1 global curinodes)
4257 [ $used -eq 6 ] || error "expected 6 got $used"
4259 run_test 51 "Test project accounting with mv/cp"
4262 ! is_project_quota_supported &&
4263 skip "Project quota is not supported"
4265 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
4266 skip "Need MDS version at least 2.14.55"
4268 setup_quota_test || error "setup quota failed with $?"
4270 local dir1=$DIR/$tdir/t52_dir1
4271 local dir2=$DIR/$tdir/t52_dir2
4273 mkdir $dir1 || error "failed to mkdir $dir1"
4274 mkdir $dir2 || error "failed to mkdir $dir2"
4276 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
4277 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
4279 $DD of=$dir1/$tfile count=100 ||
4280 error "failed to create and write $dir1/$tfile"
4282 cancel_lru_locks osc
4283 sync; sync_all_data || true
4285 local attrs=($(lsattr -p $dir1/$tfile))
4286 (( ${attrs[0]} == 1000 )) ||
4287 error "project ID on $dir1/$tfile is not inherited"
4289 $LFS quota -p 1000 $DIR
4290 $LFS quota -p 1001 $DIR
4292 local prev_used=$(getquota -p 1000 global curspace)
4293 local prev_used2=$(getquota -p 1001 global curspace)
4295 mrename $dir1 $dir2/tdir || log "rename directory return $?"
4297 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
4298 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
4299 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
4301 attrs=($(lsattr -p $dir2/$tfile))
4302 (( ${attrs[0]} == 1001 )) ||
4303 error "project ID is not updated after rename"
4305 (( $inum_before == $inum_after )) ||
4306 error "inode is changed after rename: $inum_before, $inum_after"
4308 sync_all_data || true
4310 $LFS quota -p 1000 $DIR
4311 $LFS quota -p 1001 $DIR
4313 local new_used=$(getquota -p 1000 global curspace)
4314 local new_used2=$(getquota -p 1001 global curspace)
4316 (( $prev_used >= $new_used + 102400 )) ||
4317 error "quota is not deducted from old project ID"
4318 (( $prev_used2 <= $new_used2 - 102400 )) ||
4319 error "quota is not added for the new project ID"
4321 run_test 52 "Rename normal file across project ID"
4324 ! is_project_quota_supported &&
4325 skip "Project quota is not supported"
4326 setup_quota_test || error "setup quota failed with $?"
4327 local dir="$DIR/$tdir/dir"
4328 mkdir $dir && change_project -s $dir
4329 [[ $($LFS project -d $dir) =~ " P " ]] ||
4330 error "inherit attribute should be set"
4332 change_project -C $dir
4333 [[ $($LFS project -d $dir) =~ " - " ]] ||
4334 error "inherit attribute should be cleared"
4336 run_test 53 "Project inherit attribute could be cleared"
4339 ! is_project_quota_supported &&
4340 skip "Project quota is not supported"
4341 setup_quota_test || error "setup quota failed with $?"
4342 local testfile="$DIR/$tdir/$tfile-0"
4344 #set project ID/inherit attribute
4345 change_project -sp $TSTPRJID $DIR/$tdir
4346 $RUNAS createmany -m ${testfile} 100 ||
4347 error "create many files failed"
4349 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
4350 # one more count for directory itself */
4354 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4355 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
4357 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
4358 [ $proj_count1 -eq $proj_count ] ||
4359 error "c2: expected $proj_count got $proj_count1"
4361 #clear project but with kept projid
4362 change_project -rCk $DIR/$tdir
4363 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4364 [ $proj_count1 -eq 1 ] ||
4365 error "c3: expected 1 got $proj_count1"
4367 #verify projid untouched.
4368 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4370 [ $proj_count1 -eq $proj_count ] ||
4371 error "c4: expected $proj_count got $proj_count1"
4374 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
4375 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4376 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
4378 #this time clear all
4379 change_project -rC $DIR/$tdir
4380 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4381 [ $proj_count1 -eq 0 ] ||
4382 error "c6: expected 0 got $proj_count1"
4384 unlinkmany ${testfile} 100 ||
4385 error "unlink many files failed"
4387 run_test 54 "basic lfs project interface test"
4390 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4391 skip "Not supported before 2.10.58."
4392 setup_quota_test || error "setup quota failed with $?"
4394 set_ost_qtype $QTYPE || error "enable ost quota failed"
4397 #add second group to TSTUSR
4398 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4401 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4402 error "failed to dd"
4404 cancel_lru_locks osc
4405 sync; sync_all_data || true
4407 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4408 error "failed to setquota on group $TSTUSR2"
4410 $LFS quota -v -g $TSTUSR2 $DIR
4412 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4413 error "chgrp should failed with -EDQUOT"
4415 USED=$(getquota -g $TSTUSR2 global curspace)
4418 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4419 error "failed to setquota on group $TSTUSR2"
4421 $LFS quota -v -g $TSTUSR2 $DIR
4423 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4424 error "chgrp should succeed"
4426 $LFS quota -v -g $TSTUSR2 $DIR
4428 run_test 55 "Chgrp should be affected by group quota"
4431 setup_quota_test || error "setup quota failed with $?"
4433 set_ost_qtype $QTYPE || error "enable ost quota failed"
4436 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4437 erro "failed to set grace time for usr quota"
4438 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4439 awk '{print $4 $8}')
4440 if [ "x$grace_time" != "x10s;10s" ]; then
4441 $LFS quota -t -u $DIR
4442 error "expected grace time: 10s;10s, got:$grace_time"
4445 run_test 56 "lfs quota -t should work well"
4448 setup_quota_test || error "setup quota failed with $?"
4450 local dir="$DIR/$tdir/dir"
4453 #command can process further if it hit some errors
4454 $LFS project -sp 1 $dir/pipe
4455 touch $dir/aaa $dir/bbb
4456 mkdir $dir/subdir -p
4457 touch $dir/subdir/aaa $dir/subdir/bbb
4458 #create one invalid link file
4459 ln -s $dir/not_exist_file $dir/ccc
4460 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4461 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4463 run_test 57 "lfs project could tolerate errors"
4473 $LFS mirror extend -N2 $mirrorfile || error "failed to create mirror"
4475 local mirrors=$($LFS getstripe -N $testfile)
4476 [[ $mirrors == 3 ]] || error "mirror count $mirrors is wrong"
4478 cancel_lru_locks osc
4479 cancel_lru_locks mdc
4480 sync; sync_all_data || true
4482 local prev_usage=$(getquota -p $projid global curspace)
4484 $RUNAS $DD of=$testfile count=50 conv=nocreat oflag=direct ||
4485 quota_error p $projid "write failed, expect succeed"
4487 cancel_lru_locks osc
4488 cancel_lru_locks mdc
4489 sync; sync_all_data || true
4491 $RUNAS $LFS mirror resync $testfile || error "failed to resync mirror"
4493 local usage=$(getquota -p $projid global curspace)
4494 (( usage >= prev_usage + 150*1024 )) ||
4495 error "project quota $usage is wrong"
4497 $RUNAS $DD of=$testfile count=30 conv=nocreat seek=50 oflag=direct ||
4498 quota_error p $projid "write failed, expect succeed"
4500 $RUNAS $LFS mirror resync $testfile &&
4501 error "resync mirror succeed, expect EDQUOT"
4503 $LFS mirror delete --mirror-id 2 $testfile ||
4504 error "failed to delete the second mirror"
4505 $LFS mirror delete --mirror-id 3 $testfile ||
4506 error "failed to delete the third mirror"
4510 (( $MDS1_VERSION >= $(version_code 2.15.56) )) ||
4511 skip "need MDS 2.15.56 or later"
4513 is_project_quota_supported || skip "Project quota is not supported"
4515 local testdir="$DIR/$tdir"
4516 local testfile="$DIR/$tdir/$tfile"
4520 setup_quota_test || error "setup quota failed with $?"
4522 USED=$(getquota -p $projid global curspace)
4523 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid isn't 0"
4525 USED=$(getquota -p $projid2 global curspace)
4526 [ $USED -ne 0 ] && error "Used space ($USED) for proj $projid2 isn't 0"
4528 chown $TSTUSR.$TSTUSR $testdir || error "chown $testdir failed"
4530 set_ost_qtype ugp || error "enable ost quota failed"
4532 $LFS project -sp $projid $testdir || error "failed to set project ID"
4533 $LFS setquota -p $projid -B 200M $DIR ||
4534 error "failed to to set prj $projid quota"
4536 $RUNAS touch $testfile
4538 local id=$(lfs project -d $testfile | awk '{print $1}')
4539 [ "$id" != "$projid" ] && error "projid $projid is not inherited $id"
4541 echo "test by mirror created with normal file"
4542 test_mirror $projid $testfile $testfile
4544 $TRUNCATE $testfile 0
4545 wait_delete_completed || error "wait_delete_completed failed"
4546 sync_all_data || true
4548 $LFS project -sp $projid2 $testdir ||
4549 error "failed to set directory project ID"
4550 $LFS project -p $projid2 $testfile ||
4551 error "failed to set file project ID"
4552 $LFS setquota -p $projid -b 0 -B 0 $DIR ||
4553 error "failed to to reset prj quota"
4554 $LFS setquota -p $projid2 -B 200M $DIR ||
4555 error "failed to to set prj $projid2 quota"
4557 local fid=$($LFS path2fid $testfile)
4559 echo "test by mirror created with FID"
4560 test_mirror $projid2 $testfile $MOUNT/.lustre/fid/$fid
4562 run_test 58 "project ID should be kept for new mirrors created by FID"
4565 [ "$mds1_FSTYPE" != ldiskfs ] &&
4566 skip "ldiskfs only test"
4567 disable_project_quota
4568 setup_quota_test || error "setup quota failed with $?"
4571 local testfile="$DIR/$tdir/$tfile-0"
4572 #make sure it did not crash kernel
4573 touch $testfile && lfs project -sp 1 $testfile
4575 enable_project_quota
4577 run_test 59 "lfs project dosen't crash kernel with project disabled"
4580 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4581 skip "Needs MDS version 2.11.53 or later."
4582 setup_quota_test || error "setup quota failed with $?"
4584 local testfile=$DIR/$tdir/$tfile
4587 set_mdt_qtype "ug" || error "enable mdt quota failed"
4589 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4590 error "set quota failed"
4591 quota_show_check a g $TSTUSR
4593 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4594 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4595 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4596 error "create many files failed"
4598 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4600 # root user can overrun quota
4601 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4602 error "root user should succeed"
4604 run_test 60 "Test quota for root with setgid"
4606 # test default quota
4607 test_default_quota() {
4608 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4609 skip "Not supported before 2.11.51."
4614 local qprjid=$TSTPRJID
4618 local LIMIT=20480 #20M disk space
4619 local TESTFILE="$DIR/$tdir/$tfile-0"
4622 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4623 echo "Project quota is not supported" && return 0
4625 [ $qtype == "-u" ] && qdtype="-U"
4626 [ $qtype == "-g" ] && qdtype="-G"
4627 [ $qtype == "-p" ] && {
4632 [ $qres_type == "meta" ] && {
4633 LIMIT=10240 #10K inodes
4638 qpool_cmd="--pool $3"
4639 # pool quotas don't work properly without global limit
4640 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4641 error "set global limit failed"
4644 setup_quota_test || error "setup quota failed with $?"
4648 # enable mdt/ost quota
4649 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4650 set_ost_qtype $QTYPE || error "enable ost quota failed"
4652 log "set to use default quota"
4653 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4654 error "set $qid to use default quota failed"
4656 log "set default quota"
4657 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4658 error "set $qid default quota failed"
4660 log "get default quota"
4661 $LFS quota $qdtype $DIR || error "get default quota failed"
4663 if [ $qres_type == "data" ]; then
4664 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4665 grep "$MOUNT" | awk '{print $2}')
4666 [ $SLIMIT -eq $LIMIT ] ||
4667 error "the returned default quota is wrong"
4669 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4671 [ $SLIMIT -eq $LIMIT ] ||
4672 error "the returned default quota is wrong"
4675 # make sure the system is clean
4676 local USED=$(getquota $qtype $qid global curspace)
4677 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4679 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4680 error "setstripe $TESTFILE failed"
4681 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4683 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4685 log "Test not out of quota"
4686 if [ $qres_type == "data" ]; then
4687 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4688 quota_error $qtype $qid "write failed, expect succeed"
4690 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4691 quota_error $qtype $qid "create failed, expect succeed"
4693 unlinkmany $TESTFILE $((LIMIT/2))
4696 log "Test out of quota"
4697 # flush cache, ensure noquota flag is set on client
4698 cancel_lru_locks osc
4699 cancel_lru_locks mdc
4700 sync; sync_all_data || true
4701 if [ $qres_type == "data" ]; then
4702 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4703 quota_error $qtype $qid "write succeed, expect EDQUOT"
4705 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4706 quota_error $qtype $qid "create succeed, expect EDQUOT"
4708 unlinkmany $TESTFILE $((LIMIT*2))
4712 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4713 error "setstripe $TESTFILE failed"
4714 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4716 log "Increase default quota"
4718 # LU-4505: sleep 5 seconds to enable quota acquire
4721 # increase default quota
4722 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4723 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4725 cancel_lru_locks osc
4726 cancel_lru_locks mdc
4727 sync; sync_all_data || true
4728 if [ $qres_type == "data" ]; then
4729 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4730 quota_error $qtype $qid "write failed, expect succeed"
4732 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4733 quota_error $qtype $qid "create failed, expect succeed"
4735 unlinkmany $TESTFILE $((LIMIT*2))
4738 log "Set quota to override default quota"
4739 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4740 error "set $qid quota failed"
4742 cancel_lru_locks osc
4743 cancel_lru_locks mdc
4744 sync; sync_all_data || true
4745 if [ $qres_type == "data" ]; then
4746 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4747 quota_error $qtype $qid "write succeed, expect EQUOT"
4749 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4750 quota_error $qtype $qid "create succeed, expect EQUOT"
4752 unlinkmany $TESTFILE $((LIMIT*2))
4755 log "Set to use default quota again"
4757 # LU-4505: sleep 5 seconds to enable quota acquire
4760 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4761 error "set $qid to use default quota failed"
4763 cancel_lru_locks osc
4764 cancel_lru_locks mdc
4765 sync; sync_all_data || true
4766 if [ $qres_type == "data" ]; then
4767 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4768 quota_error $qtype $qid "write failed, expect succeed"
4770 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4771 quota_error $qtype $qid "create failed, expect succeed"
4773 unlinkmany $TESTFILE $((LIMIT*2))
4778 wait_delete_completed || error "wait_delete_completed failed"
4779 sync_all_data || true
4781 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4782 error "reset default quota failed"
4783 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4784 error "reset quota failed"
4789 test_default_quota "-u" "data"
4790 test_default_quota "-u" "meta"
4791 test_default_quota "-g" "data"
4792 test_default_quota "-g" "meta"
4793 test_default_quota "-p" "data"
4794 test_default_quota "-p" "meta"
4796 run_test 61 "default quota tests"
4799 ! is_project_quota_supported &&
4800 skip "Project quota is not supported"
4801 [[ "$(chattr -h 2>&1)" =~ "project" ||
4802 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4803 skip "chattr did not support project quota"
4804 setup_quota_test || error "setup quota failed with $?"
4805 local testdir=$DIR/$tdir/
4807 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4808 change_project -s $testdir
4809 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4810 error "inherit attribute should be set"
4811 # chattr used FS_IOC_SETFLAGS ioctl
4812 $RUNAS chattr -P $testdir &&
4813 error "regular user clear inherit should fail"
4814 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4815 error "inherit attribute should still be set"
4816 chattr -P $testdir || error "root failed to clear inherit"
4817 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4818 error "inherit attribute should be cleared"
4821 run_test 62 "Project inherit should be only changed by root"
4824 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4825 skip "Not supported before 2.11.55"
4829 local dd_failed=false
4830 local tdir_dom=${tdir}_dom
4831 local LIMIT=20480 #20M
4833 [ $qtype == "p" ] && ! is_project_quota_supported &&
4834 echo "Project quota is not supported" && return 0
4836 [ $qtype == "p" ] && qid=$TSTPRJID
4838 setup_quota_test || error "setup quota failed with $?"
4842 # enable mdt/ost quota
4843 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4844 set_ost_qtype $QTYPE || error "enable ost quota failed"
4846 # make sure the system is clean
4847 local USED=$(getquota -$qtype $qid global curspace)
4848 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4850 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4852 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4853 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4854 error "setstripe $tdir_dom failed"
4855 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4857 [ $qtype == "p" ] && {
4858 change_project -sp $TSTPRJID $DIR/$tdir
4859 change_project -sp $TSTPRJID $DIR/$tdir_dom
4862 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4863 error "set $qid quota failed"
4865 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4866 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4870 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4872 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4873 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4877 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4879 rm -f $DIR/$tdir_dom/*
4881 # flush cache, ensure noquota flag is set on client
4882 cancel_lru_locks osc
4883 cancel_lru_locks mdc
4884 sync; sync_all_data || true
4888 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4889 quota_error $qtype $qid "write failed, expect succeed"
4891 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4892 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4896 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4899 rm -f $DIR/$tdir_dom/*
4901 # flush cache, ensure noquota flag is set on client
4902 cancel_lru_locks osc
4903 cancel_lru_locks mdc
4904 sync; sync_all_data || true
4908 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4909 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4913 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4915 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4916 quota_error $qtype $qid "write succeed, expect EDQUOT"
4919 rm -fr $DIR/$tdir_dom
4921 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4922 error "reset usr quota failed"
4930 run_test 63 "quota on DoM tests"
4933 ! is_project_quota_supported &&
4934 skip "Project quota is not supported"
4935 setup_quota_test || error "setup quota failed with $?"
4936 local dir1="$DIR/$tdir/"
4939 ln -s $dir1/file $dir1/file_link
4942 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4943 error "set project should succeed"
4945 used=$(getquota -p $TSTPRJID global curinodes)
4946 [ $used -eq 4 ] || error "expected 4 got $used"
4947 $LFS project -rC $dir1 >&/dev/null ||
4948 error "clear project should succeed"
4950 used=$(getquota -p $TSTPRJID global curinodes)
4951 [ $used -eq 0 ] || error "expected 0 got $used"
4953 run_test 64 "lfs project on non dir/files should succeed"
4957 local TESTFILE="$DIR/$tdir/$tfile-0"
4959 setup_quota_test || error "setup quota failed with $?"
4960 set_ost_qtype $QTYPE || error "enable ost quota failed"
4964 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4965 error "failed to write"
4966 # flush cache, ensure noquota flag is set on client
4967 cancel_lru_locks osc
4968 sync; sync_all_data || true
4970 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4971 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4972 local quota_all=$($RUNAS $LFS quota $DIR)
4974 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4975 error "usr quota not match"
4976 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4977 error "grp quota not match"
4979 run_test 65 "Check lfs quota result"
4982 ! is_project_quota_supported &&
4983 skip "Project quota is not supported"
4984 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4985 skip "Not supported before 2.12.4"
4986 setup_quota_test || error "setup quota failed with $?"
4987 local old=$(do_facet mds1 $LCTL get_param -n \
4988 mdt.*.enable_chprojid_gid | head -1)
4989 local testdir=$DIR/$tdir/foo
4991 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4992 stack_trap "do_facet mds1 $LCTL \
4993 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4995 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4996 chown -R $TSTID:$TSTID $testdir
4997 change_project -sp $TSTPRJID $testdir
4998 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
5000 $RUNAS lfs project -p 0 $testdir/foo &&
5001 error "nonroot user should fail to set projid"
5003 $RUNAS lfs project -C $testdir/foo &&
5004 error "nonroot user should fail to clear projid"
5006 change_project -C $testdir/foo || error "failed to clear project"
5008 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
5009 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
5010 "failed to set projid with normal user when enable_chprojid_gid=-1"
5012 $RUNAS lfs project -rC $testdir/ || error \
5013 "failed to clear project state with normal user when enable_chprojid_gid=-1"
5015 touch $testdir/bar || error "failed touch $testdir/bar"
5016 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
5017 "normal user should not be able to set projid on root owned file"
5019 change_project -p $TSTPRJID $testdir/bar || error \
5020 "root should be able to change its own file's projid"
5022 run_test 66 "nonroot user can not change project state in default"
5029 local short_qtype=${qtype:0:1}
5032 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
5034 $TSTUSR) _runas=$RUNAS;;
5035 $TSTUSR2) _runas=$RUNAS2;;
5036 *) error "unknown quota parameter $4";;
5041 $_runas $DD of=$file count=$size ||
5042 quota_error $short_qtype $TSTUSR \
5043 "$qtype write failure, but expect success"
5045 cancel_lru_locks osc
5047 sync; sync_all_data || true
5056 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
5058 do_facet mds1 $LCTL get_param $param |
5059 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
5064 local testfile="$DIR/$tdir/$tfile-0"
5065 local testfile2="$DIR/$tdir/$tfile-1"
5066 local testfile3="$DIR/$tdir/$tfile-2"
5067 local qpool="qpool1"
5073 [ "$ost1_FSTYPE" == zfs ] &&
5074 skip "ZFS grants some block space together with inode"
5076 setup_quota_test || error "setup quota failed with $?"
5079 set_ost_qtype $QTYPE || error "enable ost quota failed"
5082 log "User quota (block hardlimit:$limit MB)"
5083 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5084 error "set user quota failed"
5086 # make sure the system is clean
5087 used=$(getquota -u $TSTUSR global curspace)
5088 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5090 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5091 echo "granted 0x0 before write $granted"
5093 # trigger reintegration
5094 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
5095 procf=${procf}quota_slave.force_reint
5096 do_facet ost1 $LCTL set_param $procf=1 ||
5097 error "force reintegration failed"
5098 wait_ost_reint "u" || error "reintegration failed"
5099 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5100 [ $granted -ne 0 ] &&
5101 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
5103 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
5104 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5106 # write 10 MB to testfile
5107 test_67_write "$testfile" "user" 10 "$TSTUSR"
5109 # create qpool and add OST1
5110 pool_add $qpool || error "pool_add failed"
5111 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5112 # as $TSTUSR hasn't limits, lqe may absent. But it should be
5113 # created after the 1st direct qmt_get.
5114 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5116 # check granted - should be 0, as testfile is located only on OST0
5117 granted=$(getgranted "0x0" "dt" $TSTID "usr")
5118 echo "global granted $granted"
5119 granted=$(getgranted $qpool "dt" $TSTID "usr")
5120 echo "$qpool granted $granted"
5121 [ $granted -ne 0 ] &&
5122 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
5124 # add OST0 to qpool and check granted space
5125 pool_add_targets $qpool 0 1 ||
5126 error "pool_add_targets failed"
5127 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
5128 echo "Granted $granted_mb MB"
5129 #should be 10M + qunit for each OST
5130 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
5131 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
5133 $LFS setstripe $testfile2 -c 1 -i 1 ||
5134 error "setstripe $testfile2 failed"
5135 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
5136 # Write from another user and check that qpool1
5137 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
5138 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
5139 used=$(getquota -u $TSTUSR2 global curspace $qpool)
5140 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
5141 [ $granted -ne 0 ] &&
5142 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
5144 # Granted space for $TSTUSR2 in qpool1 should appear only
5145 # when global lqe for this user becomes enforced.
5146 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
5147 error "set user quota failed"
5148 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5149 echo "granted_mb $granted_mb"
5150 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
5151 error "Granted($granted) for $TSTUSR in $qpool is wrong."
5153 $LFS setstripe $testfile3 -c 1 -i 0 ||
5154 error "setstripe $testfile3 failed"
5155 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
5156 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
5157 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5158 echo "$testfile3 granted_mb $granted_mb"
5159 [ $granted_mb -eq $limit ] ||
5160 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
5162 # remove OST1 from the qpool1 and check granted space
5163 # should be 0 for TSTUSR and 10M for TSTUSR2
5164 pool_remove_target $qpool 0
5165 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
5166 [ $granted_mb -eq 0 ] ||
5167 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
5168 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
5169 [ $granted_mb -eq 10 ] ||
5170 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
5173 wait_delete_completed || error "wait_delete_completed failed"
5174 sync_all_data || true
5175 used=$(getquota -u $TSTUSR global curspace)
5176 [ $used -eq 0 ] || quota_error u $TSTUSR \
5177 "user quota isn't released after deletion"
5179 run_test 67 "quota pools recalculation"
5186 wait_update_facet "--quiet" mds1 \
5187 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
5188 >/dev/null 2>&1 || echo foo" "">/dev/null ||
5189 error "mds1: failed to create quota pool $pool"
5191 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
5192 awk '/usr/ {getline; print $2}'
5197 local qpool="qpool1"
5200 setup_quota_test || error "setup quota failed with $?"
5203 set_ost_qtype $QTYPE || error "enable ost quota failed"
5205 # check slave number for glbal pool
5206 local nr=$(get_slave_nr "0x0" "usr")
5207 echo "nr result $nr"
5208 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
5209 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5211 # create qpool and add OST1
5212 pool_add $qpool || error "pool_add failed"
5213 nr=$(get_slave_nr $qpool "usr")
5214 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5217 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5218 nr=$(get_slave_nr $qpool "usr")
5219 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5222 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5223 nr=$(get_slave_nr $qpool "usr")
5224 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
5227 pool_remove_target $qpool 0
5228 nr=$(get_slave_nr $qpool "usr")
5229 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
5232 pool_remove_target $qpool 1
5233 nr=$(get_slave_nr $qpool "usr")
5234 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
5236 # Check again that all is fine with global pool
5237 nr=$(get_slave_nr "0x0" "usr")
5238 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
5239 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
5241 run_test 68 "slave number in quota pool changed after each add/remove OST"
5245 local global_limit=200 # MB
5247 local testfile="$DIR/$tdir/$tfile-0"
5248 local dom0="$DIR/$tdir/dom0"
5249 local qpool="qpool1"
5252 setup_quota_test || error "setup quota failed with $?"
5255 set_ost_qtype $QTYPE || error "enable ost quota failed"
5256 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5258 # Save DOM only at MDT0
5259 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
5260 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
5262 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
5264 # create qpool and add OST0
5265 pool_add $qpool || error "pool_add failed"
5266 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5268 log "User quota (block hardlimit:$global_limit MB)"
5269 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5270 error "set user quota failed"
5272 log "User quota (block hardlimit:$limit MB)"
5273 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5274 error "set user quota failed"
5276 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
5277 quota_error u $TSTUSR "write failed"
5279 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5280 oflag=sync || quota_error u $TSTUSR "write failed"
5282 $RUNAS $DD of=$testfile count=$limit || true
5284 # flush cache, ensure noquota flag is set on client
5285 cancel_lru_locks osc
5286 sync; sync_all_data || true
5288 # MDT0 shouldn't get EDQUOT with glimpse.
5289 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
5290 quota_error u $TSTUSR \
5291 "user write success, but expect EDQUOT"
5293 # Now all members of qpool1 should get EDQUOT. Expect success
5294 # when write to DOM on MDT0, as it belongs to global pool.
5295 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
5296 oflag=sync || quota_error u $TSTUSR "write failed"
5298 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
5299 oflag=sync || quota_error u $TSTUSR "write failed"
5301 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
5305 local qpool="qpool1"
5310 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
5311 skip "Needs a client >= $VERSION_WITH_QP"
5313 setup_quota_test || error "setup quota failed with $?"
5315 # MDS returns EFAULT for unsupported quotactl command
5316 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
5318 # create qpool and add OST0
5319 pool_add $qpool || error "pool_add failed"
5320 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
5322 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
5324 [ $rc -eq $err ] || error "setquota res $rc != $err"
5326 # If MDS supports QP, check that limit was set properly.
5327 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
5328 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
5329 echo "hard limit $bhard limit $limit"
5330 [ $bhard -ne $((limit*1024)) ] &&
5331 error "bhard:$bhard for $qpool!=$((limit*1024))"
5334 $LFS quota -u $TSTUSR --pool $qpool $DIR
5336 [ $rc -eq $err ] || error "quota res $rc != $err"
5338 run_test 70a "check lfs setquota/quota with a pool option"
5342 local glbl_hard=200 # 200M
5343 local glbl_soft=100 # 100M
5344 local pool_hard=10 # 10M
5345 local qpool="qpool1"
5347 pool_add $qpool || error "pool_add failed"
5348 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5350 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
5351 error "set user quota failed"
5352 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
5353 error "set user quota failed"
5355 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5356 [ $tmp -eq $((pool_hard * 1024)) ] ||
5357 error "wrong block hard limit $tmp for $qpool"
5358 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
5359 # soft limit hasn't been set and should be zero
5360 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
5362 run_test 70b "lfs setquota pool works properly"
5367 local global_limit=100 # MB
5368 local testfile="$DIR/$tdir/$tfile-0"
5369 local qpool="qpool1"
5370 local qpool2="qpool2"
5372 [ "$ost1_FSTYPE" == zfs ] &&
5373 skip "ZFS grants some block space together with inode"
5374 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
5376 setup_quota_test || error "setup quota failed with $?"
5379 set_ost_qtype $QTYPE || error "enable ost quota failed"
5382 log "User quota (block hardlimit:$global_limit MB)"
5383 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5384 error "set user quota failed"
5386 pool_add $qpool || error "pool_add failed"
5387 pool_add_targets $qpool 0 1 ||
5388 error "pool_add_targets failed"
5390 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5391 error "set user quota failed"
5393 pool_add $qpool2 || error "pool_add failed"
5394 pool_add_targets $qpool2 1 1 ||
5395 error "pool_add_targets failed"
5397 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
5398 error "set user quota failed"
5400 # make sure the system is clean
5401 local used=$(getquota -u $TSTUSR global curspace)
5404 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5406 # create 1st component 1-10M
5407 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5408 #create 2nd component 10-30M
5409 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5410 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5412 # сheck normal use and out of quota with PFL
5413 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
5414 test_1_check_write $testfile "user" $((limit*2))
5416 wait_delete_completed || error "wait_delete_completed failed"
5417 sync_all_data || true
5418 used=$(getquota -u $TSTUSR global curspace)
5419 [ $used -ne 0 ] && quota_error u $TSTUSR \
5420 "user quota isn't released after deletion"
5422 # create 1st component 1-10M
5423 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5424 # create 2nd component 10-30M
5425 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5426 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5428 # write to the 2nd component
5429 $RUNAS $DD of=$testfile count=$limit seek=10 ||
5430 quota_error u $TSTUSR \
5431 "write failure, but expect success"
5432 # this time maybe cache write, ignore it's failure
5433 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
5434 cancel_lru_locks osc
5435 sync; sync_all_data || true
5436 # write over limit in qpool2(2nd component 10-30M)
5437 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
5438 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5439 # write to the 1st component - OST0 is empty
5440 $RUNAS $DD of=$testfile count=$limit seek=0 ||
5441 quota_error u $TSTUSR "write failed"
5443 run_test 71a "Check PFL with quota pools"
5447 local global_limit=1000 # MB
5448 local limit1=160 # MB
5449 local limit2=10 # MB
5450 local testfile="$DIR/$tdir/$tfile-0"
5451 local qpool="qpool1"
5452 local qpool2="qpool2"
5454 [ "$ost1_FSTYPE" == zfs ] &&
5455 skip "ZFS grants some block space together with inode"
5456 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
5458 setup_quota_test || error "setup quota failed with $?"
5461 set_ost_qtype $QTYPE || error "enable ost quota failed"
5464 log "User quota (block hardlimit:$global_limit MB)"
5465 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5466 error "set user quota failed"
5468 pool_add $qpool || error "pool_add failed"
5469 pool_add_targets $qpool 0 1 ||
5470 error "pool_add_targets failed"
5472 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
5473 error "set user quota failed"
5475 pool_add $qpool2 || error "pool_add failed"
5476 pool_add_targets $qpool2 1 1 ||
5477 error "pool_add_targets failed"
5479 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5480 error "set user quota failed"
5482 # make sure the system is clean
5483 local used=$(getquota -u $TSTUSR global curspace)
5486 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5488 # First component is on OST0, 2nd on OST1
5489 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5490 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5492 # fill the 1st component on OST0
5493 $RUNAS $DD of=$testfile count=128 ||
5494 quota_error u $TSTUSR "write failed"
5495 # write to the 2nd cmpnt on OST1
5496 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5497 quota_error u $TSTUSR "write failed"
5498 # this time maybe cache write, ignore it's failure
5499 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5501 cancel_lru_locks osc
5502 sync; sync_all_data || true
5503 # write over limit in qpool2
5504 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5505 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5508 run_test 71b "Check SEL with quota pools"
5513 local global_limit=50 # MB
5514 local testfile="$DIR/$tdir/$tfile-0"
5515 local qpool="qpool1"
5518 setup_quota_test || error "setup quota failed with $?"
5521 set_ost_qtype $QTYPE || error "enable ost quota failed"
5524 log "User quota (block hardlimit:$global_limit MB)"
5525 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5526 error "set user quota failed"
5528 pool_add $qpool || error "pool_add failed"
5529 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5531 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5532 error "set user quota failed"
5534 # make sure the system is clean
5535 local used=$(getquota -u $TSTUSR global curspace)
5537 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5539 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5541 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5542 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5543 test_1_check_write $testfile "user" $limit
5544 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5546 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5547 # check that lfs quota -uv --pool prints only OST that
5548 # was added in a pool
5549 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5550 grep "OST\|MDT" && error "$qpool consists wrong targets"
5553 run_test 72 "lfs quota --pool prints only pool's OSTs"
5557 (( $MDS1_VERSION >= $(version_code 2.14.51.158) )) ||
5558 skip "need MDS >= v2_14_51-158-g25a70a88 for default pool quota"
5560 local qpool="qpool1"
5564 pool_add $qpool || error "pool_add failed"
5565 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5566 error "pool_add_targets failed"
5568 test_default_quota "-u" "data" "qpool1"
5570 run_test 73a "default limits at OST Pool Quotas"
5574 (( $MDS1_VERSION >= $(version_code 2.14.52.91) )) ||
5575 skip "need MDS >= v2_14_52-91-g188112fc8 for nested lqe fix"
5577 local TESTFILE1="$DIR/$tdir/$tfile-1"
5579 local qpool="qpool1"
5583 setup_quota_test || error "setup quota failed with $?"
5585 set_ost_qtype $QTYPE || error "enable ost quota failed"
5587 # pool quotas don't work properly without global limit
5588 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5589 error "set global limit failed"
5591 pool_add $qpool || error "pool_add failed"
5592 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5593 error "pool_add_targets failed"
5595 log "set default quota for $qpool"
5596 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5597 error "set default quota failed"
5599 log "Write from user that hasn't lqe"
5600 # Check that it doesn't cause a panic or a deadlock
5601 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5602 # Have to use RUNAS_ID as resetquota creates lqes in
5603 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5604 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5606 cancel_lru_locks osc
5607 sync; sync_all_data || true
5609 run_test 73b "default OST Pool Quotas limit for new user"
5613 (( $MDS1_VERSION >= $(version_code 2.14.52.6) )) ||
5614 skip "need MDS >= v2_14_52-6-g8c19365416 for pool per-user fix"
5616 local global_limit=200 # 200M
5617 local limit=10 # 10M
5618 local limit2=50 # 50M
5619 local qpool="qpool1"
5620 local qpool2="qpool2"
5624 setup_quota_test || error "setup quota failed with $?"
5627 set_ost_qtype $QTYPE || error "enable ost quota failed"
5629 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5630 error "set user quota failed"
5632 pool_add $qpool || error "pool_add failed"
5633 pool_add_targets $qpool 0 1 ||
5634 error "pool_add_targets failed"
5636 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5637 error "set user quota failed"
5639 pool_add $qpool2 || error "pool_add failed"
5640 pool_add_targets $qpool2 1 1 ||
5641 error "pool_add_targets failed"
5643 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5644 error "set user quota failed"
5646 tmp=$(getquota -u $TSTUSR global bhardlimit)
5647 [ $tmp -eq $((global_limit * 1024)) ] ||
5648 error "wrong global limit $global_limit"
5650 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5651 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5653 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5654 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5656 # check limits in pools
5657 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5658 grep -A4 $qpool | awk 'NR == 4{print $4}')
5659 echo "pool limit for $qpool $tmp"
5660 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5661 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5662 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5663 echo "pool limit for $qpool2 $tmp"
5664 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5666 run_test 74 "check quota pools per user"
5668 function cleanup_quota_test_75()
5670 do_facet mgs $LCTL nodemap_modify --name default \
5671 --property admin --value 1
5672 do_facet mgs $LCTL nodemap_modify --name default \
5673 --property trusted --value 1
5674 do_facet mgs $LCTL nodemap_modify --name default \
5675 --property squash_uid --value 99
5676 do_facet mgs $LCTL nodemap_modify --name default \
5677 --property squash_gid --value 99
5679 wait_nm_sync default admin_nodemap
5680 wait_nm_sync default trusted_nodemap
5682 do_facet mgs $LCTL nodemap_activate 0
5685 resetquota -u $TSTUSR
5689 local dd_failed=false
5690 local LIMIT=20480 #20M
5693 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5694 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5695 conv=fsync || dd_failed=true
5698 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5700 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5701 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5702 conv=fsync || dd_failed=true
5705 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5707 rm -f $DIR/$tdir_dom/*
5709 # flush cache, ensure noquota flag is set on client
5711 sync; sync_all_data || true
5715 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5716 quota_error u $qid "write failed, expect succeed (2)"
5718 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5719 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5720 conv=fsync || dd_failed=true
5723 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5726 rm -f $DIR/$tdir_dom/*
5728 # flush cache, ensure noquota flag is set on client
5730 sync; sync_all_data || true
5734 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5735 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5736 conv=fsync || dd_failed=true
5739 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5741 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=direct &&
5742 quota_error u $qid "write succeed, expect EDQUOT (3)"
5748 (( $MDS1_VERSION >= $(version_code 2.14.52.68) )) ||
5749 skip "need MDS >= v2_14_52-68-ga4fbe7341b for squash root fix"
5751 local soft_limit=10 # MB
5752 local hard_limit=20 # MB
5753 local limit=$soft_limit
5754 local testfile="$DIR/$tdir/$tfile-0"
5755 local grace=20 # seconds
5756 local tdir_dom=${tdir}_dom
5758 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5762 setup_quota_test || error "setup quota failed with $?"
5763 stack_trap cleanup_quota_test_75 EXIT
5766 set_ost_qtype $QTYPE || error "enable ost quota failed"
5767 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5769 local used=$(getquota -u $TSTID global curspace)
5770 $LFS setquota -t -u --block-grace $grace --inode-grace \
5771 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5772 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5773 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5774 error "set user quota failed"
5776 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5777 mkdir $DIR/$tdir_dom
5778 chmod 777 $DIR/$tdir_dom
5779 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5780 error "setstripe $tdir_dom failed"
5782 do_facet mgs $LCTL nodemap_activate 1
5784 do_facet mgs $LCTL nodemap_modify --name default \
5785 --property admin --value 0
5786 do_facet mgs $LCTL nodemap_modify --name default \
5787 --property trusted --value 0
5788 do_facet mgs $LCTL nodemap_modify --name default \
5789 --property deny_unknown --value 0
5790 do_facet mgs $LCTL nodemap_modify --name default \
5791 --property squash_uid --value $TSTID
5792 do_facet mgs $LCTL nodemap_modify --name default \
5793 --property squash_gid --value $TSTID
5794 cancel_lru_locks mdc
5795 wait_nm_sync default admin_nodemap
5796 wait_nm_sync default trusted_nodemap
5797 wait_nm_sync default squash_uid
5799 # mmap write when over soft limit
5801 $DD of=$testfile count=${limit} || quota_error a $TSTUSR \
5802 "root write failure, but expect success (1)"
5803 OFFSET=$((limit * 1024))
5804 cancel_lru_locks osc
5806 echo "Write to exceed soft limit"
5807 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5808 quota_error a $TSTUSR "root write failure, but expect success (2)"
5809 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5810 cancel_lru_locks osc
5812 echo "mmap write when over soft limit"
5813 $MULTIOP $testfile.mmap OT40960SMW ||
5814 quota_error a $TSTUSR "mmap write failure, but expect success"
5815 cancel_lru_locks osc
5817 wait_delete_completed || error "wait_delete_completed failed (1)"
5818 sync_all_data || true
5820 # test for user hard limit
5823 $DD of=$testfile count=$((limit/2)) ||
5824 quota_error u $TSTID \
5825 "root write failure, but expect success (3)"
5827 log "Write out of block quota ..."
5828 # possibly a cache write, ignore failure
5829 $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
5830 # flush cache, ensure noquota flag is set on client
5831 cancel_lru_locks osc
5832 sync; sync_all_data || true
5833 # sync forced cache flush, but did not guarantee that slave
5834 # got new edquot through glimpse, so wait to make sure
5836 $DD of=$testfile count=1 seek=$limit conv=fsync &&
5837 quota_error u $TSTID \
5838 "user write success, but expect EDQUOT"
5840 wait_delete_completed || error "wait_delete_completed failed (2)"
5841 sync_all_data || true
5842 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5843 quota_error u $TSTID "user quota not released after deletion"
5847 run_test 75 "nodemap squashed root respects quota enforcement"
5850 (( $MDS1_VERSION >= $(version_code 2.14.52.109) )) ||
5851 skip "need MDS >= v2_14_52-109-g3ffa5d680f for bad PRJID fix"
5852 ! is_project_quota_supported &&
5853 skip "skip project quota unsupported"
5855 setup_quota_test || error "setup quota failed with $?"
5858 local testfile="$DIR/$tdir/$tfile-0"
5861 $LFS project -p 4294967295 $testfile &&
5862 error "set project ID should fail"
5865 run_test 76 "project ID 4294967295 should be not allowed"
5869 (( $MDS1_VERSION >= $(version_code 2.14.54.33) )) ||
5870 skip "need MDS >= v2_14_54-33-g29e00cecc6 for readonly fix"
5872 mount_client $MOUNT2 "ro"
5873 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5874 error "lfs setquota should fail in read-only Lustre mount"
5877 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5881 (( $OST1_VERSION >= $(version_code 2.14.55.173) )) ||
5882 skip "need OST >= v2_14_55-173-g789038c97a for fallocate fix"
5883 check_set_fallocate_or_skip
5885 setup_quota_test || error "setup quota failed with $?"
5888 set_ost_qtype $QTYPE || error "enable ost quota failed"
5890 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5891 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5894 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5895 error "lfs setquota failed"
5898 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5900 kbytes=$(lfs quota -u $TSTUSR $DIR |
5901 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5902 echo "kbytes returned:$kbytes"
5904 # For file size of 204800. We should be having roughly 200 kbytes
5905 # returned. Anything alarmingly low (50 taken as arbitrary value)
5906 # would bail out this TC. Also this also avoids $kbytes of 0
5907 # to be used in calculation below.
5908 (( $kbytes > 50 )) ||
5909 error "fallocate did not use quota. kbytes returned:$kbytes"
5911 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5912 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5914 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5915 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5916 error "fallocate did not use quota correctly"
5918 run_test 78A "Check fallocate increase quota usage"
5922 (( $CLIENT_VERSION >= $(version_code 2.15.0.37) )) ||
5923 skip "need client >= v2_15_50-37-g5fc934eb for falloc proj fix"
5924 (( $OST1_VERSION >= $(version_code 2.15.0.37) )) ||
5925 skip "need OST >= v2_15_50-37-g5fc934ebbb for falloc proj fix"
5926 check_set_fallocate_or_skip
5928 setup_quota_test || error "setup quota failed with $?"
5931 set_ost_qtype $QTYPE || error "enable ost quota failed"
5933 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5935 local projectid=5200 # Random project id to test
5937 change_project -sp $projectid $DIR/$tdir
5940 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5941 error "lfs setquota project failed"
5944 fallocate -l 204800 $DIR/$tdir/$tfile
5946 # Get curspace (kbytes) for $projectid
5947 local kbytes=$(getquota -p $projectid global curspace)
5949 echo "kbytes returned:$kbytes"
5951 # For file size of 204800. We should be having roughly 200 kbytes
5952 # returned. Anything alarmingly low (50 taken as arbitrary value)
5953 # would bail out this TC. Also this also avoids $kbytes of 0
5954 # to be used in calculation below.
5955 (( $kbytes > 50 )) ||
5956 error "fallocate did not use projectid. kbytes returned:$kbytes"
5958 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5959 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5961 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5962 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5963 error "fallocate did not use quota projectid correctly"
5965 run_test 78a "Check fallocate increase projectid usage"
5969 (( $MDS1_VERSION >= $(version_code 2.14.56.37) )) ||
5970 skip "need MDS >= v2_14_56-37-gc9901b68b4 for pool panic fix"
5972 local qpool="qpool1"
5973 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5974 local stopf=$TMP/$tfile
5976 do_facet mds1 "touch $stopf" || error "can't create $stopf"
5977 do_facet mds1 "ls $stopf" || error "can't find $stopf"
5978 stack_trap "do_facet mds1 'rm -f $stopf'"
5979 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5981 pool_add $qpool || error "pool_add failed"
5982 do_facet mds1 "rm $stopf"
5985 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5989 (( $MDS1_VERSION >= $(version_code 2.14.56.51) )) ||
5990 skip "need MDS >= v2_14_56-51-g61ec1e0f2c for EDQUOT failover"
5992 local dir1="$DIR/$tdir/dir1"
5993 local dir2="$DIR/$tdir/dir2"
5994 local TESTFILE0="$dir1/$tfile-0"
5995 local TESTFILE1="$dir1/$tfile-1"
5996 local TESTFILE2="$dir1/$tfile-2"
5997 local TESTFILE3="$dir2/$tfile-0"
5998 local global_limit=100 # 100M
5999 local limit=10 # 10M
6000 local qpool="qpool1"
6002 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
6004 [ "$ost1_FSTYPE" == zfs ] &&
6005 skip "ZFS grants some block space together with inode"
6006 setup_quota_test || error "setup quota failed with $?"
6007 set_ost_qtype $QTYPE || error "enable ost quota failed"
6009 # make sure the system is clean
6010 local used=$(getquota -u $TSTUSR global curspace)
6011 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
6013 pool_add $qpool || error "pool_add failed"
6014 pool_add_targets $qpool 0 1 ||
6015 error "pool_add_targets failed"
6017 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
6018 error "set user quota failed"
6020 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
6021 error "set user quota failed"
6022 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6023 error "set user quota failed"
6025 mkdir -p $dir1 || error "failed to mkdir"
6026 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
6027 mkdir -p $dir2 || error "failed to mkdir"
6028 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
6030 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
6031 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
6036 $LFS quota -uv $TSTUSR $DIR
6037 #define OBD_FAIL_QUOTA_PREACQ 0xA06
6038 do_facet mds1 $LCTL set_param fail_loc=0xa06
6039 $RUNAS $DD of=$TESTFILE3 count=3 ||
6040 quota_error u $TSTUSR "write failed"
6041 $RUNAS $DD of=$TESTFILE2 count=7 ||
6042 quota_error u $TSTUSR "write failed"
6043 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
6044 quota_error u $TSTUSR "write failed"
6047 $LFS quota -uv --pool $qpool $TSTUSR $DIR
6051 do_facet mds1 $LCTL set_param fail_loc=0
6052 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
6053 $LFS quota -uv $TSTUSR --pool $qpool $DIR
6054 # OST0 needs some time to update quota usage after removing TESTFILE2
6056 $LFS quota -uv $TSTUSR --pool $qpool $DIR
6057 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
6058 quota_error u $TSTUSR "write failure, but expect success"
6060 run_test 80 "check for EDQUOT after OST failover"
6064 (( $MDS1_VERSION >= $(version_code 2.14.56.52) )) ||
6065 skip "need MDS >= v2_14_56-52-g862f0baa7c for qmt_pool_free fix"
6067 local global_limit=20 # 100M
6068 local testfile="$DIR/$tdir/$tfile-0"
6069 local qpool="qpool1"
6072 setup_quota_test || error "setup quota failed with $?"
6075 set_ost_qtype $QTYPE || error "enable ost quota failed"
6078 log "User quota (block hardlimit:$global_limit MB)"
6079 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
6081 pool_add $qpool || error "pool_add failed"
6082 #define OBD_FAIL_QUOTA_RECALC 0xA07
6083 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=10
6084 # added OST casues to start pool recalculation
6085 pool_add_targets $qpool 0 0 1
6086 stop mds1 -f || error "MDS umount failed"
6088 #start mds1 back to destroy created pool
6089 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
6092 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
6096 (( $MDS1_VERSION >= $(version_code 2.15.50.72) )) ||
6097 skip "need MDS >= v2_15_50-72-g61481796ac for over 8 QIDs fix"
6099 is_project_quota_supported || skip "skip project quota unsupported"
6101 setup_quota_test || error "setup quota failed with $?"
6104 local parent_dir="$DIR/$tdir.parent"
6105 local child_dir="$parent_dir/child"
6108 stack_trap "chown -R 0:0 $parent_dir"
6110 chown $TSTUSR:$TSTUSR $parent_dir ||
6111 error "failed to chown on $parent_dir"
6112 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
6113 error "failed to chown on $parent_dir"
6115 $LFS project -p 1000 $parent_dir ||
6116 error "failed to set project id on $parent_dir"
6117 $LFS project -p 1001 $child_dir ||
6118 error "failed to set project id on $child_dir"
6120 rmdir $child_dir || error "cannot remove child dir, test failed"
6122 run_test 82 "verify more than 8 qids for single operation"
6124 test_grace_with_default_quota()
6133 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
6134 error "clear default quota [$qdtype] failed"
6136 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
6137 error "reset quota [$qdtype] grace failed"
6140 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
6141 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
6144 $LFS setquota $qdtype -B 10G -i 10k $DIR
6147 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
6148 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
6150 [ "$bgrace" == "$bgrace2" ] ||
6151 error "set default quota shouldn't affect block grace"
6152 [ "$igrace" == "$igrace2" ] ||
6153 error "set default quota shouldn't affect inode grace"
6159 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
6160 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
6162 setup_quota_test || error "setup quota failed with $?"
6163 test_grace_with_default_quota "-u" "-U"
6164 test_grace_with_default_quota "-g" "-G"
6166 is_project_quota_supported || return 0
6167 test_grace_with_default_quota "-p" "-P"
6169 run_test 83 "Setting default quota shouldn't affect grace time"
6173 (( $MDS1_VERSION >= $(version_code 2.15.53.115) )) ||
6174 skip "need MDS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
6175 (( $OST1_VERSION >= $(version_code 2.15.53.115) )) ||
6176 skip "need OSS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
6178 local dir1="$DIR/$tdir/dir1"
6179 local TESTFILE1="$dir1/$tfile-1"
6187 setup_quota_test || error "setup quota failed with $?"
6189 set_ost_qtype $QTYPE || error "enable ost quota failed"
6191 pool_add $qp || error "pool_add failed"
6192 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
6193 error "pool_add_targets failed"
6195 $LFS setquota -g $TSTUSR -B 10G $DIR ||
6196 error "failed to set group quota for $TSTUSR"
6197 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
6198 error "set user quota failed"
6199 $LFS quota -gv $TSTUSR $DIR
6201 wait_quota_synced "ost1" "OST0000" "grp" $TSTID "hardlimit" "10485760"
6203 mkdir -p $dir1 || error "failed to mkdir"
6204 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
6206 $LFS setstripe -c 1 -i 0 $TESTFILE1
6207 $LFS getstripe $TESTFILE1
6208 chown $TSTUSR.$TSTUSR $TESTFILE1
6210 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
6211 quota_error g $TSTUSR "write failed"
6213 sync_all_data || true
6215 $LFS quota -gv $TSTUSR $DIR
6216 $LFS quota -gv --pool $qp $TSTUSR $DIR
6218 # the grant quota should be larger than 0
6220 while (( $waited < 60 )); do
6221 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6222 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6223 (( ${grant} > 0 && ${grant2} > 0 )) && break
6225 do_facet ost1 $LCTL set_param \
6226 osd-*.*-OST0000.quota_slave.force_reint=1
6228 waited=$((waited + 1))
6231 (( $waited >= 60)) && {
6232 $LFS quota -gv $TSTUSR $DIR
6233 $LFS quota -gv --pool $qp $TSTUSR $DIR
6236 (( ${grant} > 0 )) || error "pool grant is not increased after dd"
6237 (( ${grant2} > 0 )) || error "grant is not increased after dd"
6239 #define OBD_FAIL_QUOTA_GRANT 0xA08
6240 lustre_fail mds 0xa08
6241 lustre_fail ost 0xa08
6244 # clear quota limits to trigger updating grant quota
6245 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
6246 error "failed to clear the group quota for $TSTUSR"
6247 $LFS quota -gv $TSTUSR $DIR
6248 $LFS quota -gv --pool $qp $TSTUSR $DIR
6250 # the grant quota should be set as insane value
6252 while (( $waited < 60 )); do
6253 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6254 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6255 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
6258 waited=$((waited + 1))
6261 (( $waited >= 60)) && {
6262 $LFS quota -gv $TSTUSR $DIR
6263 $LFS quota -gv --pool $qp $TSTUSR $DIR
6266 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
6267 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
6269 lustre_fail mds_ost 0
6273 $LFS setquota -g $TSTUSR -r $DIR ||
6274 error "failed to reset group quota for $TSTUSR"
6277 $LFS quota -gv $TSTUSR $DIR
6278 $LFS quota -gv --pool $qp $TSTUSR $DIR
6280 # the grant quota should be reset
6281 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
6282 (( ${#grant} == 20 )) && error "grant is not cleared"
6283 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
6284 (( ${#grant} == 20 )) && error "pool grant is not cleared"
6286 $LFS quota -gv $TSTUSR --pool $qp $DIR
6287 $LFS quota -gv --pool $qp $TSTUSR $DIR
6288 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
6289 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
6291 # test whether the quota still works
6292 $LFS setquota -g $TSTUSR -B 100M $DIR ||
6293 error "failed to set group quota for $TSTUSR"
6294 $LFS quota -gv $TSTUSR $DIR
6296 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
6297 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
6299 $LFS setquota -g $TSTUSR -B 300M $DIR ||
6300 error "failed to set group quota for $TSTUSR"
6301 $LFS quota -gv $TSTUSR $DIR
6303 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
6304 quota_error g $TSTUSR "dd failed, expect succeed"
6306 run_test 84 "Reset quota should fix the insane granted quota"
6310 (( $MDS1_VERSION >= $(version_code 2.15.55.5) )) ||
6311 skip "need MDS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6312 (( $OST1_VERSION >= $(version_code 2.15.55.5) )) ||
6313 skip "need OSS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
6316 local qpool="qpool1"
6317 local qpool2="qpool2"
6318 local tfile1="$DIR/$tdir/$tfile-0"
6320 (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
6322 setup_quota_test || error "setup quota failed with $?"
6325 set_ost_qtype $QTYPE || error "enable ost quota failed"
6327 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
6328 error "set user quota failed"
6330 pool_add $qpool || error "pool_add failed"
6331 pool_add_targets $qpool 0 1 ||
6332 error "pool_add_targets failed"
6334 pool_add $qpool2 || error "pool_add failed"
6335 pool_add_targets $qpool2 0 1 ||
6336 error "pool_add_targets failed"
6338 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
6339 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
6340 error "set user quota failed"
6341 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
6342 error "set user quota failed"
6344 # don't care about returned value. Just check we don't hung on write.
6345 $RUNAS $DD of=$tfile1 count=10
6348 run_test 85 "do not hung at write with the least_qunit"
6350 test_preacquired_quota()
6357 [[ "$qtype" == "-p" ]] && change_project -sp $qid $DIR/$tdir
6359 $LFS setquota $qtype $qid -i 100K -I 100K $DIR ||
6360 error "failed to set file [$qtype] quota"
6362 $RUNAS createmany -m $test_dir/tfile- 5000 ||
6363 error "failed to create files, expect succeed"
6365 wait_zfs_commit $SINGLEMDS
6366 $LFS setquota $qtype $qid -i 2K -I 2K $DIR ||
6367 error "failed to decrease file [$qtype] quota"
6369 wait_quota_synced "mds1" "MDT0000" $qtype_name $qid "hardlimit" "2048"
6371 # make sure the lqe->lqe_edquot is set
6372 $RUNAS createmany -m $test_dir/tfile2- 10
6375 $RUNAS createmany -m $test_dir/tfile3- 30 &&
6376 error "succeed to create files, expect failed"
6378 rm -f $test_dir/tfile*
6379 $LFS setquota $qtype $qid -i 0 -I 0 $DIR ||
6380 error "failed to reset file user quota"
6385 (( $MDS1_VERSION >= $(version_code 2.15.57.41) )) ||
6386 skip "need MDS >= 2.15.57.41 for quota over limit release fix"
6388 local test_dir="$DIR/$tdir/test_dir"
6390 setup_quota_test || error "setup quota failed with %?"
6391 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
6393 $LFS setdirstripe -c 1 -i 0 $test_dir || error "setdirstripe failed"
6396 test_preacquired_quota "$test_dir" "-u" "usr" "$TSTID"
6397 test_preacquired_quota "$test_dir" "-g" "grp" "$TSTID"
6399 is_project_quota_supported || return 0
6400 test_preacquired_quota "$test_dir" "-p" "prj" "1000"
6402 run_test 86 "Pre-acquired quota should be released if quota is over limit"
6406 do_nodes $(comma_list $(nodes_list)) \
6407 "lctl set_param -n debug=-quota-trace"
6408 if $PQ_CLEANUP; then
6409 disable_project_quota
6412 reset_quota_settings
6416 complete_test $SECONDS
6417 check_and_cleanup_lustre
6418 export QUOTA_AUTO=$QUOTA_AUTO_OLD