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
509 usr) qtype="limit_user";;
510 grp) qtype="limit_group";;
511 *) error "unknown quota parameter $2";;
518 *) error "unknown quota parameter $4";;
521 do_facet $facet $LCTL get_param osd-*.*-OST0000.quota_slave.$qtype |
522 awk '($3 == '$qid') {getline; print $'$spec'; exit;}' | tr -d ,
525 wait_quota_setting_synced() {
533 value=$(get_quota_on_qsd ost1 $qtype $qid $limit_type)
534 while [[ $value != $limit_val ]]; do
535 (( interval != 0 )) ||
536 do_facet ost1 $LCTL set_param \
537 osd-*.*-OST0000.quota_slave.force_reint=1
539 (( interval <= 20 )) ||
540 error "quota ($value) don't update on QSD, $limit_val"
542 interval=$((interval + 1))
545 value=$(get_quota_on_qsd ost1 $qtype $qid $limit_type)
551 do_nodes $(comma_list $(nodes_list)) \
552 "$LCTL set_param -n debug=+quota+trace"
557 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
558 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
559 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
560 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
562 test_quota_performance() {
563 local TESTFILE="$DIR/$tdir/$tfile-0"
564 local size=$1 # in MB
565 local stime=$(date +%s)
566 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
567 quota_error u $TSTUSR "write failure"
568 local etime=$(date +%s)
569 delta=$((etime - stime))
570 if [ $delta -gt 0 ]; then
571 rate=$((size * 1024 / delta))
572 if [ "$mds1_FSTYPE" = zfs ]; then
573 # LU-2872 - see LU-2887 for fix
575 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
577 [ $rate -gt 1024 ] ||
578 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
584 # test basic quota performance b=21696
587 [ "$SLOW" = "no" ] && MB=10
589 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
590 [ $free_space -le $((MB * 1024)) ] &&
591 skip "not enough space ${free_space} KB, " \
592 "required $((MB * 1024)) KB"
593 setup_quota_test || error "setup quota failed with $?"
595 set_ost_qtype "none" || error "disable ost quota failed"
596 test_quota_performance $MB
598 set_ost_qtype $QTYPE || error "enable ost quota failed"
599 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
600 error "set quota failed"
601 test_quota_performance $MB
603 run_test 0 "Test basic quota performance"
605 # usage: test_1_check_write tfile user|group|project
606 test_1_check_write() {
610 local short_qtype=${qtype:0:1}
613 $RUNAS $DD of=$testfile count=$((limit/2)) ||
614 quota_error $short_qtype $TSTUSR \
615 "$qtype write failure, but expect success"
616 log "Write out of block quota ..."
617 # this time maybe cache write, ignore it's failure
618 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
619 # flush cache, ensure noquota flag is set on client
621 sync; sync_all_data || true
622 # sync means client wrote all it's cache, but id doesn't
623 # guarantee that slave received new edquot through glimpse.
624 # so wait a little to be sure slave got it.
626 $RUNAS $DD of=$testfile count=1 seek=$limit &&
627 quota_error $short_qtype $TSTUSR \
628 "user write success, but expect EDQUOT"
632 check_write_fallocate() {
636 local short_qtype=${qtype:0:1}
639 log "Write ${count}MiB Using Fallocate"
640 $RUNAS fallocate -l${count}MiB $testfile ||
641 quota_error $short_qtype $TSTUSR "Write ${count}MiB fail"
644 sync; sync_all_data || true
648 log "Write ${count}MiB Using Fallocate"
649 $RUNAS fallocate -l${count}MiB $testfile &&
650 quota_error $short_qtype $TSTUSR \
651 "Write success, expect EDQUOT" || true
654 # test block hardlimit
657 local testfile="$DIR/$tdir/$tfile-0"
659 setup_quota_test || error "setup quota failed with $?"
662 set_ost_qtype $QTYPE || error "enable ost quota failed"
665 log "User quota (block hardlimit:$limit MB)"
666 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
667 error "set user quota failed"
669 # make sure the system is clean
670 local used=$(getquota -u $TSTUSR global curspace)
671 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
673 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
674 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
676 test_1_check_write $testfile "user" $limit
679 wait_delete_completed || error "wait_delete_completed failed"
680 sync_all_data || true
681 used=$(getquota -u $TSTUSR global curspace)
682 [ $used -ne 0 ] && quota_error u $TSTUSR \
683 "user quota isn't released after deletion"
684 resetquota -u $TSTUSR
687 log "--------------------------------------"
688 log "Group quota (block hardlimit:$limit MB)"
689 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
690 error "set group quota failed"
692 testfile="$DIR/$tdir/$tfile-1"
693 # make sure the system is clean
694 used=$(getquota -g $TSTUSR global curspace)
695 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
697 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
698 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
700 test_1_check_write $testfile "group" $limit
702 wait_delete_completed || error "wait_delete_completed failed"
703 sync_all_data || true
704 used=$(getquota -g $TSTUSR global curspace)
705 [ $used -ne 0 ] && quota_error g $TSTUSR \
706 "Group quota isn't released after deletion"
707 resetquota -g $TSTUSR
709 if ! is_project_quota_supported; then
710 echo "Project quota is not supported"
714 testfile="$DIR/$tdir/$tfile-2"
715 # make sure the system is clean
716 used=$(getquota -p $TSTPRJID global curspace)
718 error "used space($used) for project $TSTPRJID isn't 0"
721 log "--------------------------------------"
722 log "Project quota (block hardlimit:$limit mb)"
723 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
724 error "set project quota failed"
726 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
727 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
728 change_project -p $TSTPRJID $testfile
730 test_1_check_write $testfile "project" $limit
735 used=$(getquota -p $TSTPRJID global curspace)
736 [ $used -ne 0 ] && quota_error p $TSTPRJID \
737 "project quota isn't released after deletion"
739 resetquota -p $TSTPRJID
741 run_test 1a "Block hard limit (normal use and out of quota)"
744 (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
745 skip "Need MDS version at least 2.15.55"
748 local global_limit=20 # MB
749 local testfile="$DIR/$tdir/$tfile-0"
753 setup_quota_test || error "setup quota failed with $?"
756 set_ost_qtype $QTYPE || error "enable ost quota failed"
759 log "User quota (block hardlimit:$global_limit MB)"
760 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
761 error "set user quota failed"
763 pool_add $qpool || error "pool_add failed"
764 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
765 error "pool_add_targets failed"
767 # check qmt_pool_add dmesg error
768 local msg_rgx="QMT0000: can't add to $FSNAME-OST0000.*pool.*$qpool"
770 dmesg_err=$(do_facet mds1 dmesg | grep "$msg_rgx" | tail -1)
771 [[ -z "$dmesg_err" ]] || error "found qmt_pool_add error: $dmesg_err"
773 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
774 error "set user quota failed"
776 # make sure the system is clean
777 local used=$(getquota -u $TSTUSR global curspace)
779 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
781 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
783 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
784 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
786 test_1_check_write $testfile "user" $limit
789 wait_delete_completed || error "wait_delete_completed failed"
790 sync_all_data || true
791 used=$(getquota -u $TSTUSR global curspace $qpool)
792 [ $used -ne 0 ] && quota_error u $TSTUSR \
793 "user quota isn't released after deletion"
794 resetquota -u $TSTUSR
797 log "--------------------------------------"
798 log "Group quota (block hardlimit:$global_limit MB)"
799 $LFS setquota -g $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
800 error "set group quota failed"
802 $LFS setquota -g $TSTUSR -b 0 -B ${limit}M --pool $qpool $DIR ||
803 error "set group quota failed"
805 testfile="$DIR/$tdir/$tfile-1"
806 # make sure the system is clean
807 used=$(getquota -g $TSTUSR global curspace $qpool)
808 [ $used -ne 0 ] && error "Used space ($used) for group $TSTUSR isn't 0"
810 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
811 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
813 test_1_check_write $testfile "group" $limit
816 wait_delete_completed || error "wait_delete_completed failed"
817 sync_all_data || true
818 used=$(getquota -g $TSTUSR global curspace $qpool)
819 [ $used -ne 0 ] && quota_error g $TSTUSR \
820 "Group quota isn't released after deletion"
821 resetquota -g $TSTUSR
823 if ! is_project_quota_supported; then
824 echo "Project quota is not supported"
828 testfile="$DIR/$tdir/$tfile-2"
829 # make sure the system is clean
830 used=$(getquota -p $TSTPRJID global curspace $qpool)
832 error "used space($used) for project $TSTPRJID isn't 0"
835 log "--------------------------------------"
836 log "Project quota (block hardlimit:$global_limit mb)"
837 $LFS setquota -p $TSTPRJID -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
838 error "set project quota failed"
840 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M --pool $qpool $DIR ||
841 error "set project quota failed"
844 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
845 chown $TSTUSR:$TSTUSR $testfile || error "chown $testfile failed"
846 change_project -p $TSTPRJID $testfile
848 test_1_check_write $testfile "project" $limit
853 used=$(getquota -p $TSTPRJID global curspace)
854 [ $used -eq 0 ] || quota_error p $TSTPRJID \
855 "project quota isn't released after deletion"
857 run_test 1b "Quota pools: Block hard limit (normal use and out of quota)"
860 local global_limit=20 # MB
861 local testfile="$DIR/$tdir/$tfile-0"
862 local qpool1="qpool1"
863 local qpool2="qpool2"
866 setup_quota_test || error "setup quota failed with $?"
869 set_ost_qtype $QTYPE || error "enable ost quota failed"
872 log "User quota (block hardlimit:$global_limit MB)"
873 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
874 error "set user quota failed"
876 pool_add $qpool1 || error "pool_add failed"
877 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
878 error "pool_add_targets failed"
880 pool_add $qpool2 || error "pool_add failed"
881 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
882 error "pool_add_targets failed"
884 # create pools without hard limit
885 # initially such case raised several bugs
886 $LFS setquota -u $TSTUSR -B 0M --pool $qpool1 $DIR ||
887 error "set user quota failed"
889 $LFS setquota -u $TSTUSR -B 0M --pool $qpool2 $DIR ||
890 error "set user quota failed"
892 # make sure the system is clean
893 local used=$(getquota -u $TSTUSR global curspace)
895 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
897 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
899 test_1_check_write $testfile "user" $global_limit
901 used=$(getquota -u $TSTUSR global curspace $qpool1)
902 echo "qpool1 used $used"
903 used=$(getquota -u $TSTUSR global curspace $qpool2)
904 echo "qpool2 used $used"
907 wait_delete_completed || error "wait_delete_completed failed"
908 sync_all_data || true
910 used=$(getquota -u $TSTUSR global curspace $qpool1)
911 [ $used -eq 0 ] || quota_error u $TSTUSR \
912 "user quota isn't released after deletion"
914 run_test 1c "Quota pools: check 3 pools with hardlimit only for global"
919 local global_limit=20 # MB
920 local testfile="$DIR/$tdir/$tfile-0"
921 local qpool1="qpool1"
922 local qpool2="qpool2"
925 setup_quota_test || error "setup quota failed with $?"
928 set_ost_qtype $QTYPE || error "enable ost quota failed"
931 log "User quota (block hardlimit:$global_limit MB)"
932 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
933 error "set user quota failed"
935 pool_add $qpool1 || error "pool_add failed"
936 pool_add_targets $qpool1 0 $(($OSTCOUNT - 1)) ||
937 error "pool_add_targets failed"
939 pool_add $qpool2 || error "pool_add failed"
940 pool_add_targets $qpool2 0 $(($OSTCOUNT - 1)) ||
941 error "pool_add_targets failed"
943 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
944 error "set user quota failed"
946 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
947 error "set user quota failed"
949 # make sure the system is clean
950 local used=$(getquota -u $TSTUSR global curspace)
952 [ $used -ne 0 ] && error "used space($used) for user $TSTUSR isn't 0."
954 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
956 test_1_check_write $testfile "user" $limit1
958 used=$(getquota -u $TSTUSR global curspace $qpool1)
959 echo "qpool1 used $used"
960 used=$(getquota -u $TSTUSR global curspace $qpool2)
961 echo "qpool2 used $used"
964 wait_delete_completed || error "wait_delete_completed failed"
965 sync_all_data || true
967 used=$(getquota -u $TSTUSR global curspace $qpool1)
968 [ $used -eq 0 ] || quota_error u $TSTUSR \
969 "user quota isn't released after deletion"
971 run_test 1d "Quota pools: check block hardlimit on different pools"
975 local global_limit=53000000 # MB
976 local testfile="$DIR/$tdir/$tfile-0"
977 local testfile2="$DIR/$tdir/$tfile-1"
978 local qpool1="qpool1"
981 setup_quota_test || error "setup quota failed with $?"
984 set_ost_qtype $QTYPE || error "enable ost quota failed"
986 # global_limit is much greater than limit1 to get
987 # different qunit's on osts. Since 1st qunit shrinking
988 # on OST1(that belongs to qpool1), this qunit should
990 log "User quota (block hardlimit:$global_limit MB)"
991 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
992 error "set user quota failed"
994 pool_add $qpool1 || error "pool_add failed"
995 pool_add_targets $qpool1 1 1 ||
996 error "pool_add_targets failed"
998 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
999 error "set user quota failed"
1001 # make sure the system is clean
1002 local used=$(getquota -u $TSTUSR global curspace)
1003 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1005 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
1006 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1008 test_1_check_write $testfile "user" $limit1
1010 $LFS setstripe $testfile2 -c 1 -i 0 ||
1011 error "setstripe $testfile2 failed"
1012 chown $TSTUSR.$TSTUSR $testfile2 || error "chown $testfile2 failed"
1013 # Now write to file with a stripe on OST0, that doesn't belong to qpool1
1015 $RUNAS $DD of=$testfile2 count=20 ||
1016 quota_error u $TSTUSR \
1017 "$qtype write failure, but expect success"
1021 wait_delete_completed || error "wait_delete_completed failed"
1022 sync_all_data || true
1024 used=$(getquota -u $TSTUSR global curspace $qpool1)
1025 [ $used -eq 0 ] || quota_error u $TSTUSR \
1026 "user quota isn't released after deletion"
1028 run_test 1e "Quota pools: global pool high block limit vs quota pool with small"
1031 local global_limit=200 # MB
1032 local limit1=10 # MB
1033 local TESTDIR="$DIR/$tdir/"
1034 local testfile="$TESTDIR/$tfile-0"
1035 local qpool1="qpool1"
1038 setup_quota_test || error "setup quota failed with $?"
1041 set_ost_qtype $QTYPE || error "enable ost quota failed"
1043 log "User quota (block hardlimit:$global_limit MB)"
1044 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1045 error "set user quota failed"
1047 pool_add $qpool1 || error "pool_add failed"
1048 pool_add_targets $qpool1 0 0 ||
1049 error "pool_add_targets failed"
1051 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1052 error "set user quota failed"
1054 # make sure the system is clean
1055 local used=$(getquota -u $TSTUSR global curspace)
1056 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1058 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1060 test_1_check_write $testfile "user" $limit1
1062 pool_remove_target $qpool1 0
1064 wait_delete_completed || error "wait_delete_completed failed"
1065 sync_all_data || true
1067 pool_add_targets $qpool1 0 0 || error "pool_add_targets failed"
1068 # qunit for appropriate element in lgd array should be set
1069 # correctly(4096). Earlier it was not changed continuing to be 1024.
1070 # This caused write to hung when it hit limit1 - qunit shrinking to 1024
1071 # for qpool1 lqe didn't cause changing qunit for OST0 in gld array
1072 # as it already was 1024. As flag "need_update" for this qunit was
1073 # not set, new qunit wasn't sent to OST0. Thus revoke was not set
1074 # for "qpool1" lqe and it couldn't set EDQUOT despite granted
1075 # became > 10M. QMT returned EINPROGRESS in a loop.
1076 # Check that it doesn't hung anymore.
1077 test_1_check_write $testfile "user" $limit1
1079 run_test 1f "Quota pools: correct qunit after removing/adding OST"
1083 local global_limit=40 # MB
1084 local testfile="$DIR/$tdir/$tfile-0"
1085 local qpool="qpool1"
1086 local mdmb_param="osc.*.max_dirty_mb"
1087 local max_dirty_mb=$($LCTL get_param -n $mdmb_param | head -1)
1090 setup_quota_test || error "setup quota failed with $?"
1091 $LCTL set_param $mdmb_param=1
1092 stack_trap "$LCTL set_param $mdmb_param=$max_dirty_mb" EXIT
1095 set_ost_qtype $QTYPE || error "enable ost quota failed"
1098 log "User quota (block hardlimit:$global_limit MB)"
1099 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1100 error "set user quota failed"
1102 pool_add $qpool || error "pool_add failed"
1103 pool_add_targets $qpool 0 $(($OSTCOUNT - 1)) ||
1104 error "pool_add_targets failed"
1106 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
1107 error "set user quota failed"
1109 # make sure the system is clean
1110 local used=$(getquota -u $TSTUSR global curspace)
1112 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1114 $LFS setstripe $testfile -C 200 || error "setstripe $testfile failed"
1115 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1118 $RUNAS $DD of=$testfile count=$((limit/2)) ||
1119 quota_error u $TSTUSR \
1120 "$qtype write failure, but expect success"
1121 log "Write out of block quota ..."
1122 # this time maybe cache write, ignore it's failure
1123 $RUNAS $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
1124 # flush cache, ensure noquota flag is set on client
1125 cancel_lru_locks osc
1126 sync; sync_all_data || true
1128 $RUNAS $DD of=$testfile count=$OSTCOUNT seek=$limit &&
1129 quota_error u $TSTUSR \
1130 "user write success, but expect EDQUOT"
1133 wait_delete_completed || error "wait_delete_completed failed"
1134 sync_all_data || true
1136 used=$(getquota -u $TSTUSR global curspace $qpool)
1137 [ $used -ne 0 ] && quota_error u $TSTUSR \
1138 "user quota isn't released after deletion"
1141 run_test 1g "Quota pools: Block hard limit with wide striping"
1145 local testfile="$DIR/$tdir/$tfile-0"
1147 check_set_fallocate_or_skip
1149 setup_quota_test || error "setup quota failed with $?"
1152 set_ost_qtype $QTYPE || error "enable ost quota failed"
1155 log "User quota (block hardlimit:$limit MB)"
1156 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1157 error "set user quota failed"
1159 # make sure the system is clean
1160 local used=$(getquota -u $TSTUSR global curspace)
1161 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1163 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
1164 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
1166 check_write_fallocate $testfile "user" $limit
1169 wait_delete_completed || error "wait_delete_completed failed"
1170 sync_all_data || true
1171 used=$(getquota -u $TSTUSR global curspace)
1172 [ $used -eq 0 ] || quota_error u $TSTUSR \
1173 "user quota isn't released after deletion"
1175 run_test 1h "Block hard limit test using fallocate"
1178 local global_limit=200 # 200M
1179 local limit1=10 # 10M
1180 local TESTDIR="$DIR/$tdir/"
1181 local testfile="$TESTDIR/$tfile-0"
1182 local testfile1="$TESTDIR/$tfile-1"
1183 local testfile2="$TESTDIR/$tfile-2"
1184 local qpool1="qpool1"
1187 setup_quota_test || error "setup quota failed with $?"
1190 set_ost_qtype $QTYPE || error "enable ost quota failed"
1192 log "User quota (block hardlimit:$global_limit MB)"
1193 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
1194 error "set user quota failed"
1196 pool_add $qpool1 || error "pool_add failed"
1197 pool_add_targets $qpool1 0 0 ||
1198 error "pool_add_targets failed"
1200 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1201 error "set user quota failed"
1203 # make sure the system is clean
1204 local used=$(getquota -u $TSTUSR global curspace)
1205 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1207 $LFS setstripe $TESTDIR -c 1 -i 0 || error "setstripe $TESTDIR failed"
1210 test_1_check_write $testfile "user" $limit1
1211 $LFS setquota -u $TSTUSR -B 0 --pool $qpool1 $DIR ||
1212 error "set user quota failed"
1214 $LFS quota -uv $TSTUSR --pool $qpool1 $DIR
1215 $RUNAS $DD of=$testfile1 count=$((limit1/2)) ||
1216 quota_error u $TSTUSR "write failure, but expect success"
1220 wait_delete_completed || error "wait_delete_completed failed"
1221 sync_all_data || true
1223 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1224 error "set user quota failed"
1225 test_1_check_write $testfile "user" $limit1
1226 local tmp_limit=$(($limit1*2))
1227 # increase pool limit
1228 $LFS setquota -u $TSTUSR -B ${tmp_limit}M --pool $qpool1 $DIR ||
1229 error "set user quota failed"
1230 # now write shouldn't fail
1231 $RUNAS $DD of=$testfile1 count=$((limit1/3)) ||
1232 quota_error u $TSTUSR "write failure, but expect success"
1233 # decrease pool limit
1234 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool1 $DIR ||
1235 error "set user quota failed"
1236 $RUNAS $DD of=$testfile2 count=$((limit1/3))
1237 # flush cache, ensure noquota flag is set on client
1238 cancel_lru_locks osc
1239 sync; sync_all_data || true
1240 $RUNAS $DD of=$testfile2 seek=$((limit1/3)) count=1 &&
1241 quota_error u $TSTUSR "write success, but expect failure"
1244 run_test 1i "Quota pools: different limit and usage relations"
1248 local testfile="$DIR/$tdir/$tfile-0"
1250 (( $OST1_VERSION >= $(version_code 2.15.52.206) )) ||
1251 skip "need OST at least 2.15.52.206"
1253 is_project_quota_supported ||
1254 skip "skip project quota unsupported"
1256 setup_quota_test || error "setup quota failed with $?"
1259 set_ost_qtype $QTYPE || error "enable ost quota failed"
1262 log "--------------------------------------"
1263 log "Project quota (block hardlimit:$limit mb)"
1264 $LFS setquota -p $TSTPRJID -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
1265 error "set project quota failed"
1267 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
1268 change_project -p $TSTPRJID $testfile
1270 local procf=osd-$ost1_FSTYPE.$FSNAME-OST0000.quota_slave.root_prj_enable
1271 do_facet ost1 $LCTL set_param $procf=1 ||
1272 error "enable root quotas for project failed"
1273 stack_trap "do_facet ost1 $LCTL set_param $procf=0"
1275 runas -u 0 -g 0 $DD of=$testfile count=$limit oflag=direct || true
1276 runas -u 0 -g 0 $DD of=$testfile count=$((limit/2)) seek=$limit oflag=direct &&
1277 quota_error "project" $TSTPRJID "root write to project success"
1279 do_facet ost1 $LCTL set_param $procf=0 ||
1280 error "disable root quotas for project failed"
1282 runas -u 0 -g 0 $DD of=$testfile count=$limit seek=$limit oflag=direct ||
1283 quota_error "project" $TSTPRJID "root write to project failed"
1288 used=$(getquota -p $TSTPRJID global curspace)
1289 (( $used == 0 )) || quota_error p $TSTPRJID \
1290 "project quota isn't released after deletion"
1292 run_test 1j "Enable project quota enforcement for root"
1294 # test inode hardlimit
1296 local testfile="$DIR/$tdir/$tfile-0"
1297 local least_qunit=$(do_facet mds1 $LCTL get_param -n \
1298 qmt.$FSNAME-QMT0000.md-0x0.info |
1299 sed -e 's/least qunit/least_qunit/' |
1300 awk '/least_qunit/{ print $2 }')
1303 [ "$SLOW" = "no" ] && limit=$((least_qunit * 2)) ||
1304 limit=$((least_qunit * 1024))
1305 echo "least_qunit: '$least_qunit', limit: '$limit'"
1307 local free_inodes=$(mdt_free_inodes 0)
1308 echo "$free_inodes free inodes on master MDT"
1309 [ $free_inodes -lt $limit ] &&
1310 skip "not enough free inodes $free_inodes required $limit"
1312 setup_quota_test || error "setup quota failed with $?"
1315 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1318 log "User quota (inode hardlimit:$limit files)"
1319 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1320 error "set user quota failed"
1322 # make sure the system is clean
1323 local used=$(getquota -u $TSTUSR global curinodes)
1324 [ $used -ne 0 ] && error "Used inodes($used) for user $TSTUSR isn't 0."
1326 log "Create $((limit - least_qunit)) files ..."
1327 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1328 quota_error u $TSTUSR "user create failure, but expect success"
1329 # it is ok, if it fails on the last qunit
1330 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1331 log "Create out of file quota ..."
1332 $RUNAS touch ${testfile}_xxx &&
1333 quota_error u $TSTUSR "user create success, but expect EDQUOT"
1336 unlinkmany ${testfile} $((limit - least_qunit)) ||
1337 error "unlinkmany $testfile failed"
1338 # if 2nd createmany got EDQUOT, not all of nodes would be created
1339 unlinkmany ${testfile}_yyy $least_qunit || true
1340 rm -f ${testfile}_xxx
1341 wait_delete_completed
1343 used=$(getquota -u $TSTUSR global curinodes)
1344 [ $used -ne 0 ] && quota_error u $TSTUSR \
1345 "user quota isn't released after deletion"
1346 resetquota -u $TSTUSR
1349 log "--------------------------------------"
1350 log "Group quota (inode hardlimit:$limit files)"
1351 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
1352 error "set group quota failed"
1354 testfile=$DIR/$tdir/$tfile-1
1355 # make sure the system is clean
1356 used=$(getquota -g $TSTUSR global curinodes)
1357 [ $used -ne 0 ] && error "Used inodes($used) for group $TSTUSR isn't 0."
1359 log "Create $limit files ..."
1360 $RUNAS createmany -m ${testfile} $((limit - least_qunit)) ||
1361 quota_error g $TSTUSR "group create failure, but expect success"
1362 $RUNAS createmany -m ${testfile}_yyy $least_qunit ||
1363 log "Create out of file quota ..."
1364 $RUNAS touch ${testfile}_xxx &&
1365 quota_error g $TSTUSR "group create success, but expect EDQUOT"
1368 unlinkmany ${testfile} $((limit - least_qunit)) ||
1369 error "unlinkmany $testfile failed"
1370 unlinkmany ${testfile}_yyy $least_qunit || true
1371 rm -f ${testfile}_xxx
1372 wait_delete_completed
1374 used=$(getquota -g $TSTUSR global curinodes)
1375 [ $used -ne 0 ] && quota_error g $TSTUSR \
1376 "user quota isn't released after deletion"
1378 resetquota -g $TSTUSR
1379 ! is_project_quota_supported &&
1380 echo "Skip project quota is not supported" && return 0
1383 log "--------------------------------------"
1384 log "Project quota (inode hardlimit:$limit files)"
1385 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $limit $DIR ||
1386 error "set project quota failed"
1388 testfile=$DIR/$tdir/$tfile-1
1389 # make sure the system is clean
1390 used=$(getquota -p $TSTPRJID global curinodes)
1392 error "Used inodes($used) for project $TSTPRJID isn't 0"
1394 change_project -sp $TSTPRJID $DIR/$tdir
1395 log "Create $limit files ..."
1396 $RUNAS createmany -m ${testfile} $((limit-least_qunit)) ||
1397 quota_error p $TSTPRJID \
1398 "project create fail, but expect success"
1399 $RUNAS createmany -m ${testfile}_yyy $least_qunit || true
1400 log "Create out of file quota ..."
1401 $RUNAS touch ${testfile}_xxx && quota_error p $TSTPRJID \
1402 "project create success, but expect EDQUOT"
1403 change_project -C $DIR/$tdir
1406 used=$(getquota -p $TSTPRJID global curinodes)
1407 [ $used -eq 0 ] || quota_error p $TSTPRJID \
1408 "project quota isn't released after deletion"
1411 run_test 2 "File hard limit (normal use and out of quota)"
1420 local soft_limit=$(do_facet $SINGLEMDS $LCTL get_param -n \
1421 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit)
1425 $LFS setstripe $testfile -c 1 -i 0
1426 chown $TSTUSR.$TSTUSR $testfile
1427 [ "$qtype" == "p" ] && is_project_quota_supported &&
1428 change_project -p $TSTPRJID $testfile
1430 echo "Write up to soft limit"
1431 $RUNAS $DD of=$testfile count=$limit ||
1432 quota_error a $TSTUSR "write failure, but expect success"
1433 OFFSET=$((limit * 1024))
1434 cancel_lru_locks osc
1436 echo "Write to exceed soft limit"
1437 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1438 quota_error a $TSTUSR "write failure, but expect success"
1439 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
1440 cancel_lru_locks osc
1442 echo "mmap write when over soft limit"
1443 $RUNAS $MULTIOP $testfile.mmap OT40960SMW ||
1444 quota_error a $TSTUSR "mmap write failure, but expect success"
1445 cancel_lru_locks osc
1450 $SHOW_QUOTA_INFO_USER
1451 $SHOW_QUOTA_INFO_GROUP
1452 $SHOW_QUOTA_INFO_PROJID
1454 echo "Write before timer goes off"
1455 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
1456 quota_error a $TSTUSR "write failure, but expect success"
1457 OFFSET=$((OFFSET + 1024))
1458 cancel_lru_locks osc
1460 wait_grace_time $qtype "block" $pool
1465 $SHOW_QUOTA_INFO_USER
1466 $SHOW_QUOTA_INFO_GROUP
1467 $SHOW_QUOTA_INFO_PROJID
1469 log "Write after timer goes off"
1470 # maybe cache write, ignore.
1471 # write up to soft least quint to consume all
1472 # possible slave granted space.
1473 $RUNAS dd if=/dev/zero of=$testfile bs=1K \
1474 count=$soft_limit seek=$OFFSET || true
1475 OFFSET=$((OFFSET + soft_limit))
1476 cancel_lru_locks osc
1477 log "Write after cancel lru locks"
1478 $RUNAS dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET &&
1479 quota_error a $TSTUSR "write success, but expect EDQUOT"
1484 $SHOW_QUOTA_INFO_USER
1485 $SHOW_QUOTA_INFO_GROUP
1486 $SHOW_QUOTA_INFO_PROJID
1488 echo "Unlink file to stop timer"
1490 wait_delete_completed
1491 sync_all_data || true
1496 $SHOW_QUOTA_INFO_USER
1497 $SHOW_QUOTA_INFO_GROUP
1498 $SHOW_QUOTA_INFO_PROJID
1500 $LFS setstripe $testfile -c 1 -i 0
1501 chown $TSTUSR.$TSTUSR $testfile
1502 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $testfile
1505 $RUNAS $DD of=$testfile count=$limit ||
1506 quota_error a $TSTUSR "write failure, but expect success"
1513 local grace=20 # seconds
1514 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1517 local testfile=$DIR/$tdir/$tfile-0
1519 # get minimum soft qunit size
1520 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1521 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1523 set_ost_qtype $QTYPE || error "enable ost quota failed"
1525 echo "User quota (soft limit:$limit MB grace:$grace seconds)"
1526 # make sure the system is clean
1527 local used=$(getquota -u $TSTUSR global curspace)
1528 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1530 $LFS setquota -t -u --block-grace $grace --inode-grace \
1531 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1532 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1533 error "set user quota failed"
1535 test_block_soft $testfile $grace $limit "u"
1537 echo "Group quota (soft limit:$limit MB grace:$grace seconds)"
1538 testfile=$DIR/$tdir/$tfile-1
1539 # make sure the system is clean
1540 used=$(getquota -g $TSTUSR global curspace)
1541 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1543 $LFS setquota -t -g --block-grace $grace --inode-grace \
1544 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1545 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 -i 0 -I 0 $DIR ||
1546 error "set group quota failed"
1548 test_block_soft $testfile $grace $limit "g"
1550 if is_project_quota_supported; then
1551 echo "Project quota (soft limit:$limit MB grace:$grace sec)"
1552 testfile=$DIR/$tdir/$tfile-2
1553 # make sure the system is clean
1554 used=$(getquota -p $TSTPRJID global curspace)
1555 [ $used -ne 0 ] && error \
1556 "Used space($used) for project $TSTPRJID isn't 0."
1558 $LFS setquota -t -p --block-grace $grace --inode-grace \
1559 $MAX_IQ_TIME $DIR ||
1560 error "set project grace time failed"
1561 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 -i 0 -I 0 \
1562 $DIR || error "set project quota failed"
1564 test_block_soft $testfile $grace $limit "p"
1565 resetquota -p $TSTPRJID
1566 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1567 $MAX_IQ_TIME $DIR ||
1568 error "restore project grace time failed"
1572 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1573 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1574 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1575 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1577 run_test 3a "Block soft limit (start timer, timer goes off, stop timer)"
1580 local grace=20 # seconds
1581 local qpool="qpool1"
1582 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1585 local testfile=$DIR/$tdir/$tfile-0
1588 # get minimum soft qunit size
1589 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1590 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1591 local glbl_limit=$((2*limit))
1592 local glbl_grace=$((2*grace))
1593 echo "limit $limit glbl_limit $glbl_limit"
1594 echo "grace $grace glbl_grace $glbl_grace"
1596 set_ost_qtype $QTYPE || error "enable ost quota failed"
1598 echo "User quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1599 # make sure the system is clean
1600 local used=$(getquota -u $TSTUSR global curspace)
1601 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1603 pool_add $qpool || error "pool_add failed"
1604 pool_add_targets $qpool 0 1 ||
1605 error "pool_add_targets failed"
1607 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1608 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1609 $LFS setquota -t -u --block-grace $grace \
1610 --pool $qpool $DIR || error "set user grace time failed"
1612 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1613 error "set user quota failed"
1614 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1615 error "set user quota failed"
1617 test_block_soft $testfile $grace $limit "u" $qpool
1619 echo "Group quota in $qpool(soft limit:$limit MB grace:$grace seconds)"
1620 testfile=$DIR/$tdir/$tfile-1
1621 # make sure the system is clean
1622 used=$(getquota -g $TSTUSR global curspace)
1623 [ $used -ne 0 ] && error "Used space($used) for group $TSTUSR isn't 0."
1625 $LFS setquota -t -g --block-grace $glbl_grace --inode-grace \
1626 $MAX_IQ_TIME $DIR || error "set group grace time failed"
1627 $LFS setquota -t -g --block-grace $grace \
1628 --pool $qpool $DIR || error "set group grace time failed"
1630 $LFS setquota -g $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1631 error "set group quota failed"
1632 $LFS setquota -g $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1633 error "set group quota failed"
1635 test_block_soft $testfile $grace $limit "g" $qpool
1637 if is_project_quota_supported; then
1638 echo "Project quota in $qpool(soft:$limit MB grace:$grace sec)"
1639 testfile=$DIR/$tdir/$tfile-2
1640 # make sure the system is clean
1641 used=$(getquota -p $TSTPRJID global curspace)
1642 [ $used -ne 0 ] && error \
1643 "Used space($used) for project $TSTPRJID isn't 0."
1645 $LFS setquota -t -p --block-grace $glbl_grace --inode-grace \
1646 $MAX_IQ_TIME $DIR ||
1647 error "set project grace time failed"
1648 $LFS setquota -t -p --block-grace $grace \
1649 --pool $qpool $DIR ||
1650 error "set project grace time failed"
1652 $LFS setquota -p $TSTPRJID -b ${glbl_limit}M -B 0 -i 0 -I 0 \
1653 $DIR || error "set project quota failed"
1654 $LFS setquota -p $TSTPRJID -b ${limit}M -B 0 \
1655 --pool $qpool $DIR || error "set project quota failed"
1657 test_block_soft $testfile $grace $limit "p" $qpool
1658 resetquota -p $TSTPRJID
1659 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1660 $MAX_IQ_TIME $DIR ||
1661 error "restore project grace time failed"
1662 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --pool $qpool \
1663 $DIR || error "set project grace time failed"
1667 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1668 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1669 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1670 --pool $qpool $DIR || error "restore user grace time failed"
1671 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1672 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1673 $LFS setquota -t -g --block-grace $MAX_DQ_TIME \
1674 --pool $qpool $DIR || error "restore group grace time failed"
1676 run_test 3b "Quota pools: Block soft limit (start timer, expires, stop timer)"
1679 local grace=20 # seconds
1680 local qpool="qpool1"
1681 local qpool2="qpool2"
1682 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
1685 local testfile=$DIR/$tdir/$tfile-0
1688 # get minimum soft qunit size
1689 local limit=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
1690 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
1691 local limit2=$((limit+4))
1692 local glbl_limit=$((limit+8))
1693 local grace1=$((grace+10))
1695 local glbl_grace=$((grace+20))
1696 echo "limit $limit limit2 $limit2 glbl_limit $glbl_limit"
1697 echo "grace1 $grace1 grace2 $grace2 glbl_grace $glbl_grace"
1699 set_ost_qtype $QTYPE || error "enable ost quota failed"
1701 echo "User quota in qpool2(soft:$limit2 MB grace:$grace2 seconds)"
1702 # make sure the system is clean
1703 local used=$(getquota -u $TSTUSR global curspace)
1704 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
1706 pool_add $qpool || error "pool_add failed"
1707 pool_add_targets $qpool 0 1 ||
1708 error "pool_add_targets failed"
1710 pool_add $qpool2 || error "pool_add failed"
1711 pool_add_targets $qpool2 0 1 ||
1712 error "pool_add_targets failed"
1714 $LFS setquota -t -u --block-grace $glbl_grace --inode-grace \
1715 $MAX_IQ_TIME $DIR || error "set user grace time failed"
1716 $LFS setquota -t -u --block-grace $grace1 \
1717 --pool $qpool $DIR || error "set user grace time failed"
1718 $LFS setquota -t -u --block-grace $grace2 \
1719 --pool $qpool2 $DIR || error "set user grace time failed"
1721 $LFS setquota -u $TSTUSR -b ${glbl_limit}M -B 0 -i 0 -I 0 $DIR ||
1722 error "set user quota failed"
1723 $LFS setquota -u $TSTUSR -b ${limit}M -B 0 --pool $qpool $DIR ||
1724 error "set user quota failed"
1725 # qpool has minimum soft limit, but its grace is greater than
1726 # the grace period of qpool2. Thus write shouldn't fail when
1727 # hit qpool soft limit - only when reaches up qpool2 limit
1728 # after grace2 seconds.
1729 $LFS setquota -u $TSTUSR -b ${limit2}M -B 0 --pool $qpool2 $DIR ||
1730 error "set user quota failed"
1732 test_block_soft $testfile $grace2 $limit2 "u" $qpool2
1735 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1736 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1737 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1738 --pool $qpool $DIR || error "restore user grace time failed"
1739 $LFS setquota -t -u --block-grace $MAX_DQ_TIME \
1740 --pool $qpool2 $DIR || error "restore user grace time failed"
1742 run_test 3c "Quota pools: check block soft limit on different pools"
1749 local SOFT_LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1750 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1753 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
1755 echo "Create files to exceed soft limit"
1756 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
1757 quota_error a $TSTUSR "create failure, but expect success"
1758 local trigger_time=$(date +%s)
1760 sync_all_data || true
1762 local cur_time=$(date +%s)
1763 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
1764 error "Passed grace time $grace, $trigger_time, $cur_time"
1766 echo "Create file before timer goes off"
1767 $RUNAS touch ${TESTFILE}_before ||
1768 quota_error a $TSTUSR "failed create before timer expired," \
1769 "but expect success. $trigger_time, $cur_time"
1770 sync_all_data || true
1772 wait_grace_time $qtype "file"
1777 $SHOW_QUOTA_INFO_USER
1778 $SHOW_QUOTA_INFO_GROUP
1779 $SHOW_QUOTA_INFO_PROJID
1781 echo "Create file after timer goes off"
1782 # exceed least soft limit is possible
1783 $RUNAS createmany -m ${TESTFILE}_after_3 $((SOFT_LIMIT + 1)) &&
1784 quota_error a $TSTUSR "create after timer expired," \
1786 sync_all_data || true
1791 $SHOW_QUOTA_INFO_USER
1792 $SHOW_QUOTA_INFO_GROUP
1793 $SHOW_QUOTA_INFO_PROJID
1795 echo "Unlink files to stop timer"
1796 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
1797 wait_delete_completed
1800 $RUNAS touch ${TESTFILE}_xxx ||
1801 quota_error a $TSTUSR "touch after timer stop failure," \
1802 "but expect success"
1803 sync_all_data || true
1811 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1812 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1813 local TESTFILE=$DIR/$tdir/$tfile-0
1816 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
1817 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1819 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1820 # make sure the system is clean
1821 local USED=$(getquota -u $TSTUSR global curinodes)
1822 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1824 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1825 $GRACE $DIR || error "set user grace time failed"
1826 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1827 error "set user quota failed"
1829 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1831 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1832 # make sure the system is clean
1833 USED=$(getquota -g $TSTUSR global curinodes)
1834 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1836 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1837 $GRACE $DIR || error "set group grace time failed"
1838 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1839 error "set group quota failed"
1840 TESTFILE=$DIR/$tdir/$tfile-1
1842 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1844 if is_project_quota_supported; then
1845 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1846 # make sure the system is clean
1847 USED=$(getquota -p $TSTPRJID global curinodes)
1848 [ $USED -ne 0 ] && error \
1849 "Used space($USED) for project $TSTPRJID isn't 0."
1851 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1852 $GRACE $DIR || error "set project grace time failed"
1853 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1854 error "set project quota failed"
1856 TESTFILE=$DIR/$tdir/$tfile-1
1857 # one less than limit, because of parent directory included.
1858 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1859 resetquota -p $TSTPRJID
1860 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1861 $MAX_IQ_TIME $DIR ||
1862 error "restore project grace time failed"
1866 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1867 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1868 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1869 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1871 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1874 local GR_STR1="1w3d"
1875 local GR_STR2="1000s"
1877 local GR_STR4="1w2d3h4m5s"
1879 local GR_STR6="18446744073709551615"
1882 wait_delete_completed
1884 # test of valid grace strings handling
1885 echo "Valid grace strings test"
1886 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1887 $GR_STR2 $DIR || error "set user grace time failed"
1888 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1889 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1890 $GR_STR4 $DIR || error "set group grace time quota failed"
1891 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1893 # test of invalid grace strings handling
1894 echo " Invalid grace strings test"
1895 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1896 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1897 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1901 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1902 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1903 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1904 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1906 run_test 4b "Grace time strings handling"
1908 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1910 local BLIMIT=10 # MB
1911 local ILIMIT=10 # inodes
1913 setup_quota_test || error "setup quota failed with $?"
1915 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1916 set_ost_qtype $QTYPE || error "enable ost quota failed"
1918 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1919 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1920 error "set user quota failed"
1921 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1922 if is_project_quota_supported; then
1923 error "set group quota failed"
1924 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1925 -I $ILIMIT $DIR || error "set project quota failed"
1928 # make sure the system is clean
1929 local USED=$(getquota -u $TSTUSR global curinodes)
1930 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1931 USED=$(getquota -g $TSTUSR global curinodes)
1932 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1933 USED=$(getquota -u $TSTUSR global curspace)
1934 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1935 USED=$(getquota -g $TSTUSR global curspace)
1936 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1937 if is_project_quota_supported; then
1938 USED=$(getquota -p $TSTPRJID global curinodes)
1940 error "Used inode($USED) for project $TSTPRJID isn't 0."
1941 USED=$(getquota -p $TSTPRJID global curspace)
1943 error "Used block($USED) for project $TSTPRJID isn't 0."
1946 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1947 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1948 error "create failure, expect success"
1949 if is_project_quota_supported; then
1950 touch $DIR/$tdir/$tfile-0_1
1951 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1953 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1954 error "write failure, expect success"
1956 echo "Chown files to $TSTUSR.$TSTUSR ..."
1957 for i in $(seq 0 $ILIMIT); do
1958 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1959 quota_error a $TSTUSR "chown failure, expect success"
1963 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1964 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1966 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1968 # test dropping acquire request on master
1972 # Clear dmesg so watchdog is not triggered by previous
1974 do_facet ost1 dmesg -c > /dev/null
1976 setup_quota_test || error "setup quota failed with $?"
1978 # make sure the system is clean
1979 local USED=$(getquota -u $TSTUSR global curspace)
1980 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1982 # make sure no granted quota on ost
1983 set_ost_qtype $QTYPE || error "enable ost quota failed"
1984 resetquota -u $TSTUSR
1986 # create file for $TSTUSR
1987 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1988 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1989 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1991 # create file for $TSTUSR2
1992 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1993 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1994 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1996 # cache per-ID lock for $TSTUSR on slave
1997 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1998 error "set quota failed"
1999 $RUNAS $DD of=$TESTFILE count=1 ||
2000 error "write $TESTFILE failure, expect success"
2001 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
2002 error "write $TESTFILE2 failure, expect success"
2004 if at_is_enabled; then
2005 at_max_saved=$(at_max_get ost1)
2006 at_max_set $TIMEOUT ost1
2008 # write to enforced ID ($TSTUSR) to exceed limit to make sure
2009 # DQACQ is sent, which makes at_max to take effect
2010 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
2013 wait_delete_completed
2017 sync_all_data || true
2019 #define QUOTA_DQACQ 601
2020 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
2021 lustre_fail mds 0x513 601
2023 do_facet ost1 $LCTL set_param \
2024 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
2026 # write to un-enforced ID ($TSTUSR2) should succeed
2027 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
2028 error "write failure, expect success"
2030 # write to enforced ID ($TSTUSR) in background, exceeding limit
2031 # to make sure DQACQ is sent
2032 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
2035 # watchdog timer uses a factor of 2
2036 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
2037 sleep $((TIMEOUT * 2 + 1))
2039 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
2041 # write should be blocked and never finished
2042 if ! ps -p $DDPID > /dev/null 2>&1; then
2044 error "write finished incorrectly!"
2049 # no watchdog is triggered
2050 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2051 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2052 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2053 [ -z "$watchdog" ] || error "$watchdog"
2055 rm -f $TMP/lustre-log-${TESTNAME}.log
2057 # write should continue then fail with EDQUOT
2061 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2062 if [ $count -ge 240 ]; then
2063 quota_error u $TSTUSR "dd not finished in $count secs"
2065 count=$((count + 1))
2066 if [ $((count % 30)) -eq 0 ]; then
2067 c_size=$(stat -c %s $TESTFILE)
2068 echo "Waiting $count secs. $c_size"
2074 run_test 6 "Test dropping acquire request on master"
2076 # quota reintegration (global index)
2078 local TESTFILE=$DIR/$tdir/$tfile
2081 [ "$SLOW" = "no" ] && LIMIT=5
2083 setup_quota_test || error "setup quota failed with $?"
2085 # make sure the system is clean
2086 local USED=$(getquota -u $TSTUSR global curspace)
2087 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2089 # make sure no granted quota on ost1
2090 set_ost_qtype $QTYPE || error "enable ost quota failed"
2091 resetquota -u $TSTUSR
2092 set_ost_qtype "none" || error "disable ost quota failed"
2094 local OSTUUID=$(ostuuid_from_index 0)
2095 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2097 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2100 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2101 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2106 echo "Enable quota & set quota limit for $TSTUSR"
2107 set_ost_qtype $QTYPE || error "enable ost quota failed"
2108 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2109 error "set quota failed"
2111 echo "Start ost1..."
2112 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2115 wait_ost_reint $QTYPE || error "reintegration failed"
2117 # hardlimit should have been fetched by slave during global
2118 # reintegration, write will exceed quota
2119 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2120 quota_error u $TSTUSR "write success, but expect EDQUOT"
2123 wait_delete_completed
2124 sync_all_data || true
2130 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2131 error "clear quota failed"
2133 echo "Start ost1..."
2134 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2137 wait_ost_reint $QTYPE || error "reintegration failed"
2139 # hardlimit should be cleared on slave during reintegration
2140 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
2141 quota_error u $TSTUSR "write error, but expect success"
2143 run_test 7a "Quota reintegration (global index)"
2145 # quota reintegration (slave index)
2147 local limit=100000 # MB
2148 local TESTFILE=$DIR/$tdir/$tfile
2150 setup_quota_test || error "setup quota failed with $?"
2152 # make sure the system is clean
2153 local USED=$(getquota -u $TSTUSR global curspace)
2154 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2156 # make sure no granted quota on ost1
2157 set_ost_qtype $QTYPE || error "enable ost quota failed"
2158 resetquota -u $TSTUSR
2159 set_ost_qtype "none" || error "disable ost quota failed"
2161 local OSTUUID=$(ostuuid_from_index 0)
2162 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2164 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
2167 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2168 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2170 # consume some space to make sure the granted space will not
2171 # be released during reconciliation
2172 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2173 error "consume space failure, expect success"
2175 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
2176 lustre_fail mds 0xa02
2178 set_ost_qtype $QTYPE || error "enable ost quota failed"
2179 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
2180 error "set quota failed"
2182 # ignore the write error
2183 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
2185 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2189 echo "Restart ost to trigger reintegration..."
2191 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2194 wait_ost_reint $QTYPE || error "reintegration failed"
2196 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2197 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
2202 run_test 7b "Quota reintegration (slave index)"
2204 # quota reintegration (restart mds during reintegration)
2207 local TESTFILE=$DIR/$tdir/$tfile
2209 [ "$SLOW" = "no" ] && LIMIT=5
2211 setup_quota_test || error "setup quota failed with $?"
2213 # make sure the system is clean
2214 local USED=$(getquota -u $TSTUSR global curspace)
2215 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2217 set_ost_qtype "none" || error "disable ost quota failed"
2218 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
2219 error "set quota failed"
2221 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
2222 lustre_fail ost 0xa03
2225 set_ost_qtype $QTYPE || error "enable ost quota failed"
2226 # trigger reintegration
2227 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
2228 procf=${procf}quota_slave.force_reint
2229 do_facet ost1 $LCTL set_param $procf=1 ||
2230 error "force reintegration failed"
2238 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
2241 # wait longer than usual to make sure the reintegration
2242 # is triggered by quota wb thread.
2243 wait_ost_reint $QTYPE 200 || error "reintegration failed"
2245 # hardlimit should have been fetched by slave during global
2246 # reintegration, write will exceed quota
2247 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
2248 quota_error u $TSTUSR "write success, but expect EDQUOT"
2251 run_test 7c "Quota reintegration (restart mds during reintegration)"
2253 # Quota reintegration (Transfer index in multiple bulks)
2255 local TESTFILE=$DIR/$tdir/$tfile
2256 local TESTFILE1="$DIR/$tdir/$tfile"-1
2259 setup_quota_test || error "setup quota failed with $?"
2261 set_ost_qtype "none" || error "disable ost quota failed"
2262 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
2263 error "set quota for $TSTUSR failed"
2264 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
2265 error "set quota for $TSTUSR2 failed"
2267 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
2268 lustre_fail mds 0x608 0
2270 # enable quota to tirgger reintegration
2271 set_ost_qtype "u" || error "enable ost quota failed"
2272 wait_ost_reint "u" || error "reintegration failed"
2276 # hardlimit should have been fetched by slave during global
2277 # reintegration, write will exceed quota
2278 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
2279 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
2281 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
2282 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
2285 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
2287 # quota reintegration (inode limits)
2289 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2291 # LU-2435: skip this quota test if underlying zfs version has not
2292 # supported native dnode accounting
2293 [ "$mds1_FSTYPE" == zfs ] && {
2294 local F="feature@userobj_accounting"
2295 local pool=$(zpool_name mds1)
2296 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
2298 [[ "$feature" != *" active "* ]] &&
2299 skip "requires zpool with active userobj_accounting"
2302 local ilimit=$((1024 * 2)) # inodes
2303 local TESTFILE=$DIR/${tdir}-1/$tfile
2305 setup_quota_test || error "setup quota failed with $?"
2307 # make sure the system is clean
2308 local USED=$(getquota -u $TSTUSR global curinodes)
2309 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
2311 # make sure no granted quota on mdt1
2312 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2313 resetquota -u $TSTUSR
2314 set_mdt_qtype "none" || error "disable mdt quota failed"
2316 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
2317 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
2318 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
2321 echo "Stop mds${MDSCOUNT}..."
2324 echo "Enable quota & set quota limit for $TSTUSR"
2325 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2326 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2327 error "set quota failed"
2329 echo "Start mds${MDSCOUNT}..."
2330 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2333 wait_mdt_reint $QTYPE || error "reintegration failed"
2335 echo "create remote dir"
2336 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
2337 error "create remote dir failed"
2338 chmod 0777 $DIR/${tdir}-1
2340 # hardlimit should have been fetched by slave during global
2341 # reintegration, create will exceed quota
2342 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
2343 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
2345 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
2346 wait_delete_completed
2347 sync_all_data || true
2349 echo "Stop mds${MDSCOUNT}..."
2352 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2353 error "clear quota failed"
2355 echo "Start mds${MDSCOUNT}..."
2356 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
2359 wait_mdt_reint $QTYPE || error "reintegration failed"
2361 # hardlimit should be cleared on slave during reintegration
2362 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
2363 quota_error u $TSTUSR "create failed, expect success"
2365 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
2366 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2368 run_test 7e "Quota reintegration (inode limits)"
2370 # run dbench with quota enabled
2372 local BLK_LIMIT="100g" #100G
2373 local FILE_LIMIT=1000000
2375 setup_quota_test || error "setup quota failed with $?"
2377 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
2378 set_ost_qtype $QTYPE || error "enable ost quota failed"
2380 echo "Set enough high limit for user: $TSTUSR"
2381 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2382 error "set user quota failed"
2383 echo "Set enough high limit for group: $TSTUSR"
2384 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2385 error "set group quota failed"
2386 if is_project_quota_supported; then
2387 change_project -sp $TSTPRJID $DIR/$tdir
2388 echo "Set enough high limit for project: $TSTPRJID"
2389 $LFS setquota -p $TSTPRJID -b 0 \
2390 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2391 error "set project quota failed"
2395 [ "$SLOW" = "no" ] && duration=" -t 120"
2396 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
2397 quota_error a $TSTUSR "dbench failed!"
2399 is_project_quota_supported && change_project -C $DIR/$tdir
2402 run_test 8 "Run dbench with quota enabled"
2404 # this check is just for test_9
2405 OST0_MIN=4900000 #4.67G
2407 check_whether_skip () {
2408 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
2409 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
2410 if [ $OST0_SIZE -lt $OST0_MIN ]; then
2411 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
2418 # run for fixing bug10707, it needs a big room. test for 64bit
2420 local filesize=$((1024 * 9 / 2)) # 4.5G
2422 check_whether_skip && return 0
2424 setup_quota_test || error "setup quota failed with $?"
2426 set_ost_qtype "ug" || error "enable ost quota failed"
2428 local TESTFILE="$DIR/$tdir/$tfile-0"
2429 local BLK_LIMIT=100G #100G
2430 local FILE_LIMIT=1000000
2432 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
2434 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2436 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2437 error "set user quota failed"
2439 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
2440 "for group: $TSTUSR"
2441 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
2442 error "set group quota failed"
2444 quota_show_check a u $TSTUSR
2445 quota_show_check a g $TSTUSR
2447 echo "Create test file"
2448 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2449 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2451 log "Write the big file of 4.5G ..."
2452 $RUNAS $DD of=$TESTFILE count=$filesize ||
2453 quota_error a $TSTUSR "write 4.5G file failure, expect success"
2463 run_test 9 "Block limit larger than 4GB (b10707)"
2466 local TESTFILE=$DIR/$tdir/$tfile
2468 setup_quota_test || error "setup quota failed with $?"
2470 # set limit to root user should fail
2471 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
2472 error "set limit for root user successfully, expect failure"
2473 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
2474 error "set limit for root group successfully, expect failure"
2475 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
2476 error "set limit for project 0 successfully, expect failure"
2478 # root user can overrun quota
2479 set_ost_qtype "ug" || error "enable ost quota failed"
2481 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
2482 error "set quota failed"
2483 quota_show_check b u $TSTUSR
2485 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
2486 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2488 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
2489 error "write failure, expect success"
2491 run_test 10 "Test quota for root user"
2494 local TESTFILE=$DIR/$tdir/$tfile
2495 setup_quota_test || error "setup quota failed with $?"
2497 set_mdt_qtype "ug" || error "enable mdt quota failed"
2498 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
2499 error "set quota failed"
2501 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
2502 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
2504 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
2505 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
2508 local USED=$(getquota -u $TSTUSR global curinodes)
2509 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
2511 run_test 11 "Chown/chgrp ignores quota"
2514 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
2516 local blimit=22 # MB
2517 local blk_cnt=$((blimit - 5))
2518 local TESTFILE0="$DIR/$tdir/$tfile"-0
2519 local TESTFILE1="$DIR/$tdir/$tfile"-1
2521 setup_quota_test || error "setup quota failed with $?"
2523 set_ost_qtype "u" || error "enable ost quota failed"
2524 quota_show_check b u $TSTUSR
2526 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $DIR ||
2527 error "set quota failed"
2529 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
2530 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
2531 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
2532 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
2534 echo "Write to ost0..."
2535 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
2536 quota_error a $TSTUSR "dd failed"
2538 echo "Write to ost1..."
2539 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
2540 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
2542 echo "Free space from ost0..."
2544 wait_delete_completed
2545 sync_all_data || true
2547 echo "Write to ost1 after space freed from ost0..."
2548 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
2549 quota_error a $TSTUSR "rebalancing failed"
2551 run_test 12a "Block quota rebalancing"
2554 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2556 local ilimit=$((1024 * 2)) # inodes
2557 local TESTFILE0=$DIR/$tdir/$tfile
2558 local TESTFILE1=$DIR/${tdir}-1/$tfile
2560 setup_quota_test || error "setup quota failed with $?"
2562 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
2563 chmod 0777 $DIR/${tdir}-1
2565 set_mdt_qtype "u" || error "enable mdt quota failed"
2566 quota_show_check f u $TSTUSR
2568 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
2569 error "set quota failed"
2571 echo "Create $ilimit files on mdt0..."
2572 $RUNAS createmany -m $TESTFILE0 $ilimit ||
2573 quota_error u $TSTUSR "create failed, but expect success"
2575 echo "Create files on mdt1..."
2576 $RUNAS createmany -m $TESTFILE1 1 &&
2577 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
2579 echo "Free space from mdt0..."
2580 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
2581 wait_delete_completed
2582 sync_all_data || true
2584 echo "Create files on mdt1 after space freed from mdt0..."
2585 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
2586 quota_error a $TSTUSR "rebalancing failed"
2588 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
2589 error "unlink mdt1 files failed"
2590 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
2592 run_test 12b "Inode quota rebalancing"
2595 local TESTFILE=$DIR/$tdir/$tfile
2596 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
2597 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
2599 setup_quota_test || error "setup quota failed with $?"
2601 set_ost_qtype "u" || error "enable ost quota failed"
2602 quota_show_check b u $TSTUSR
2604 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2605 error "set quota failed"
2606 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2607 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2609 # clear the locks in cache first
2610 do_facet ost1 $LCTL set_param -n $procf=clear
2611 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2612 [ $nlock -eq 0 ] || error "$nlock cached locks"
2614 # write to acquire the per-ID lock
2615 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
2616 quota_error a $TSTUSR "dd failed"
2618 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2619 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
2621 # clear quota doesn't trigger per-ID lock cancellation
2622 resetquota -u $TSTUSR
2623 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2624 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
2626 # clear the per-ID lock
2627 do_facet ost1 $LCTL set_param -n $procf=clear
2628 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
2629 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
2631 # spare quota should be released
2632 local OSTUUID=$(ostuuid_from_index 0)
2633 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
2634 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
2635 [ $limit -le $space ] ||
2636 error "spare quota isn't released, limit:$limit, space:$space"
2638 run_test 13 "Cancel per-ID lock in the LRU list"
2642 (( $MDS1_VERSION >= $(version_code 2.15.54.67) )) ||
2643 skip "Need MDS >= v2_15_54-67-gdfe7d for qmt_site_recalc_cb fix"
2645 local qpool="qpool1"
2646 local tfile1="$DIR/$tdir/$tfile-0"
2649 setup_quota_test || error "setup quota failed with $?"
2651 set_ost_qtype $QTYPE || error "enable ost quota failed"
2653 $LFS setquota -u $TSTUSR -b 0 -B 100M -i 0 -I 0 $DIR ||
2654 error "set user quota failed"
2655 pool_add $qpool || error "pool_add failed"
2656 pool_add_targets $qpool 0 ||
2657 error "pool_add_targets failed"
2658 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
2659 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
2660 error "set user quota failed"
2662 # don't care about returned value
2663 $RUNAS $DD of=$tfile1 count=10 oflag=direct
2667 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
2668 error "set user quota failed"
2670 # no panic after removing OST0000 from the pool
2671 pool_remove_target $qpool 0
2672 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
2674 run_test 14 "check panic in qmt_site_recalc_cb"
2677 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
2679 wait_delete_completed
2680 sync_all_data || true
2683 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2684 error "set user quota failed"
2685 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
2686 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2687 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2688 resetquota -u $TSTUSR
2691 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
2692 error "set group quota failed"
2693 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
2694 [ $TOTAL_LIMIT -eq $LIMIT ] ||
2695 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
2696 resetquota -g $TSTUSR
2698 run_test 15 "Set over 4T block quota"
2702 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2703 skip "Not supported Lustre client before 2.14.55"
2705 setup_quota_test || error "setup quota failed with $?"
2707 $LFS setquota -u $TSTUSR -B 500M -I 10K $MOUNT ||
2708 error "failed to set quota for user $TSTUSR"
2709 $LFS setquota -g $TSTUSR -B 500M -I 10K $MOUNT ||
2710 error "failed to set quota for group $TSTUSR"
2712 $RUNAS $DD of=$DIR/$tdir/$tfile count=50 ||
2713 quota_error u $TSTUSR "write failure"
2715 $LFS quota -u $TSTUSR $MOUNT ||
2716 quota_error u $TSTUSR "failed to get quota"
2718 local OSC=$($LCTL dl | grep OST0000-osc-[^M] | awk '{print $4}')
2720 $LCTL --device %$OSC deactivate
2721 stack_trap "$LCTL --device %$OSC activate"
2723 $LFS quota -v -u $TSTUSR $MOUNT ||
2724 quota_error u $TSTUSR "failed to get quota after deactivate OSC"
2725 $LFS quota -v -g $TSTUSR $MOUNT ||
2726 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2728 (( $MDSCOUNT > 1 )) || return 0
2730 local MDC=$($LCTL dl | grep MDT0001-mdc-[^M] | awk '{print $4}')
2732 $LCTL --device %$MDC deactivate
2733 stack_trap "$LCTL --device %$MDC activate"
2735 $LFS quota -v -u $TSTUSR $MOUNT ||
2736 quota_error u $TSTUSR "failed to get quota after deactivate MDC"
2737 $LFS quota -v -g $TSTUSR $MOUNT ||
2738 quota_error g $TSTUSR "failed to get quota after deactivate OSC"
2740 run_test 16a "lfs quota should skip the inactive MDT/OST"
2751 (( $CLIENT_VERSION < $(version_code 2.14.55) )) &&
2752 skip "Not supported Lustre client before 2.14.55"
2754 (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
2757 if ! combined_mgs_mds ; then
2762 add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
2763 $(mdsdevname 1) $(mdsvdevname 1)
2764 add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
2765 $(mdsdevname 2) $(mdsvdevname 2)
2766 add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=100 --reformat \
2767 $(mdsdevname 3) $(mdsvdevname 3)
2769 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=0 --reformat \
2770 $(ostdevname 1) $(ostvdevname 1)
2771 add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=100 --reformat \
2772 $(ostdevname 2) $(ostvdevname 2)
2774 stack_trap cleanup_16b
2776 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS || error "MDT1 start failed"
2777 start mds2 $(mdsdevname 2) $MDS_MOUNT_OPTS || error "MDT2 start failed"
2778 start mds3 $(mdsdevname 3) $MDS_MOUNT_OPTS || error "MDT3 start failed"
2779 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "OST1 start failed"
2780 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "OST2 start failed"
2782 mount_client $MOUNT || error "Unable to mount client"
2784 setup_quota_test || error "setup quota failed with $?"
2786 $LFS setquota -u $TSTUSR -B 100M -I 10K $MOUNT ||
2787 error "failed to set quota for user $TSTUSR"
2788 $LFS setquota -g $TSTUSR -B 100M -I 10K $MOUNT ||
2789 error "failed to set quota for group $TSTUSR"
2791 $RUNAS $DD of=$DIR/$tdir/$tfile count=10 ||
2792 quota_error u $TSTUSR "write failure"
2794 cnt=$($LFS quota -v -u $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2795 [ $cnt -le 5 ] || quota_error u $TSTUSR "failed to get user quota"
2796 cnt=$($LFS quota -v -g $TSTUSR $MOUNT | grep -ce "^$FSNAME-[MD|OS]T*")
2797 [ $cnt -le 5 ] || quota_error g $TSTUSR "failed to get group quota"
2799 run_test 16b "lfs quota should skip the nonexistent MDT/OST"
2803 local BLKS=1 # 1M less than limit
2804 local TESTFILE=$DIR/$tdir/$tfile
2806 setup_quota_test || error "setup quota failed with $?"
2808 # make sure the system is clean
2809 local USED=$(getquota -u $TSTUSR global curspace)
2810 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
2812 set_ost_qtype "ug" || error "enable ost quota failed"
2813 # make sure no granted quota on ost
2814 resetquota -u $TSTUSR
2815 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
2816 error "set quota failed"
2818 quota_show_check b u $TSTUSR
2820 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
2821 lustre_fail mds 0xa04 $err_code
2823 # write in background
2824 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
2828 # write should be blocked and never finished
2829 if ! ps -p $DDPID > /dev/null 2>&1; then
2831 quota_error u $TSTUSR "write finished incorrectly!"
2839 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2841 if [ $count -gt $timeout ]; then
2842 quota_error u $TSTUSR "dd is not finished!"
2847 sync; sync_all_data || true
2849 USED=$(getquota -u $TSTUSR global curspace)
2850 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
2851 "Used space(${USED}K) is less than ${BLKS}M"
2856 # DQACQ return recoverable error
2858 echo "DQACQ return -ENOLCK"
2860 test_17sub 37 || error "Handle -ENOLCK failed"
2862 echo "DQACQ return -EAGAIN"
2864 test_17sub 11 || error "Handle -EAGAIN failed"
2866 echo "DQACQ return -ETIMEDOUT"
2867 #define ETIMEDOUT 110
2868 test_17sub 110 || error "Handle -ETIMEDOUT failed"
2870 echo "DQACQ return -ENOTCONN"
2871 #define ENOTCONN 107
2872 test_17sub 107 || error "Handle -ENOTCONN failed"
2875 run_test 17 "DQACQ return recoverable error"
2879 local blimit=200 # MB
2880 local TESTFILE="$DIR/$tdir/$tfile"
2882 setup_quota_test || error "setup quota failed with $?"
2884 set_ost_qtype "u" || error "enable ost quota failed"
2885 log "User quota (limit: $blimit)"
2886 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2887 error "set quota failed"
2888 quota_show_check b u $TSTUSR
2890 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2891 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2893 local timeout=$($LCTL get_param -n timeout)
2895 if [ $io_type = "directio" ]; then
2896 log "Write 100M (directio) ..."
2897 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2899 log "Write 100M (buffered) ..."
2900 $RUNAS $DD of=$TESTFILE count=100 &
2904 replay_barrier $SINGLEMDS
2905 log "Fail mds for $((2 * timeout)) seconds"
2906 fail $SINGLEMDS $((2 * timeout))
2909 if at_is_enabled; then
2910 timeout=$(at_max_get mds)
2912 timeout=$($LCTL get_param -n timeout)
2916 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2917 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2918 log "it took $count second"
2923 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2925 cancel_lru_locks mdc
2926 cancel_lru_locks osc
2929 local testfile_size=$(stat -c %s $TESTFILE)
2930 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2931 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2932 "got ${testfile_size}. Verifying file failed!"
2937 # test when mds does failover, the ost still could work well
2938 # this test shouldn't trigger watchdog b=14840
2940 # Clear dmesg so watchdog is not triggered by previous
2942 do_facet ost1 dmesg -c > /dev/null
2945 test_18_sub directio
2947 # check if watchdog is triggered
2948 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2949 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
2950 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2951 [ -z "$watchdog" ] || error "$watchdog"
2952 rm -f $TMP/lustre-log-${TESTNAME}.log
2954 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2958 local TESTFILE=$DIR/$tdir/$tfile
2960 setup_quota_test || error "setup quota failed with $?"
2962 set_ost_qtype $QTYPE || error "enable ost quota failed"
2964 # bind file to a single OST
2965 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2966 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2968 echo "Set user quota (limit: ${blimit}M)"
2969 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2970 error "set user quota failed"
2971 quota_show_check b u $TSTUSR
2972 echo "Update quota limits"
2973 $LFS setquota -u $TSTUSR -b 0 -B ${blimit}M -i 0 -I 0 $MOUNT ||
2974 error "set group quota failed"
2975 quota_show_check b u $TSTUSR
2977 # first wirte might be cached
2978 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2979 cancel_lru_locks osc
2981 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2982 quota_error u $TSTUSR "Write success, expect failure"
2985 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2987 test_20() { # b15754
2988 local LSTR=(2g 1t 4k 3m) # limits strings
2990 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2993 resetquota -u $TSTUSR
2995 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2996 $MOUNT || error "could not set quota limits"
2997 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2998 --inode-softlimit ${LSTR[2]} \
2999 --inode-hardlimit ${LSTR[3]} \
3000 $MOUNT || error "could not set quota limits"
3002 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
3003 error "bsoftlimit was not set properly"
3004 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
3005 error "bhardlimit was not set properly"
3006 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
3007 error "isoftlimit was not set properly"
3008 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
3009 error "ihardlimit was not set properly"
3011 resetquota -u $TSTUSR
3013 run_test 20 "Test if setquota specifiers work properly (b15754)"
3020 local time=$(($(date +%s) + seconds))
3021 while [ $(date +%s) -lt $time ]; do
3022 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
3026 # run for fixing bug16053, setquota shouldn't fail when writing and
3027 # deleting are happening
3029 local TESTFILE="$DIR/$tdir/$tfile"
3030 local BLIMIT=10 # 10G
3031 local ILIMIT=1000000
3033 setup_quota_test || error "setup quota failed with $?"
3035 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3037 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
3038 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
3039 error "set user quota failed"
3040 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
3041 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
3042 error "set group quota failed"
3043 if is_project_quota_supported; then
3044 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
3045 "project: $TSTPRJID"
3046 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
3047 $MOUNT || error "set project quota failed"
3050 # repeat writing on a 1M file
3051 test_21_sub ${TESTFILE}_1 1 30 &
3053 # repeat writing on a 128M file
3054 test_21_sub ${TESTFILE}_2 128 30 &
3057 local time=$(($(date +%s) + 30))
3059 while [ $(date +%s) -lt $time ]; do
3060 log "Set quota for $i times"
3061 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3062 -I $((ILIMIT + i)) $MOUNT ||
3063 error "Set user quota failed"
3064 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
3065 -I $((ILIMIT + i)) $MOUNT ||
3066 error "Set group quota failed"
3067 if is_project_quota_supported; then
3068 $LFS setquota -p $TSTPRJID -b 0 -B \
3069 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
3070 error "Set project quota failed"
3078 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
3080 if [ $count -gt 60 ]; then
3081 quota_error a $TSTUSR "dd should be finished!"
3085 echo "(dd_pid=$DDPID1, time=$count)successful"
3089 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
3091 if [ $count -gt 60 ]; then
3092 quota_error a $TSTUSR "dd should be finished!"
3096 echo "(dd_pid=$DDPID2, time=$count)successful"
3098 run_test 21 "Setquota while writing & deleting (b16053)"
3100 # enable/disable quota enforcement permanently
3102 echo "Set both mdt & ost quota type as ug"
3104 is_project_quota_supported && qtype=$QTYPE
3105 set_mdt_qtype $qtype || error "enable mdt quota failed"
3106 set_ost_qtype $qtype || error "enable ost quota failed"
3109 stopall || error "failed to stopall (1)"
3113 echo "Verify if quota is enabled"
3114 local qtype1=$(mdt_quota_type)
3115 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
3116 qtype=$(ost_quota_type)
3117 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
3119 echo "Set both mdt & ost quota type as none"
3120 set_mdt_qtype "none" || error "disable mdt quota failed"
3121 set_ost_qtype "none" || error "disable ost quota failed"
3124 stopall || error "failed to stopall (2)"
3129 echo "Verify if quota is disabled"
3130 qtype=$(mdt_quota_type)
3131 [ $qtype != "none" ] && error "mdt quota setting is lost"
3132 qtype=$(ost_quota_type)
3133 [ $qtype != "none" ] && error "ost quota setting is lost"
3137 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
3140 local TESTFILE="$DIR/$tdir/$tfile"
3143 setup_quota_test || error "setup quota failed with $?"
3145 set_ost_qtype $QTYPE || error "Enable ost quota failed"
3148 log "User quota (limit: $LIMIT MB)"
3149 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
3150 error "set quota failed"
3151 quota_show_check b u $TSTUSR
3153 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
3154 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3156 log "Step1: trigger EDQUOT with O_DIRECT"
3157 log "Write half of file"
3158 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
3159 quota_error u $TSTUSR "(1) Write failure, expect success." \
3161 log "Write out of block quota ..."
3162 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
3163 oflag=direct conv=notrunc &&
3164 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
3168 log "Step2: rewrite should succeed"
3169 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
3170 quota_error u $TSTUSR "(3) Write failure, expect success." \
3176 local OST0_UUID=$(ostuuid_from_index 0)
3177 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
3178 [ $OST0_QUOTA_USED -ne 0 ] &&
3179 ($SHOW_QUOTA_USER; \
3180 quota_error u $TSTUSR "quota isn't released")
3185 [ "$ost1_FSTYPE" == zfs ] &&
3186 skip "Overwrite in place is not guaranteed to be " \
3187 "space neutral on ZFS"
3189 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
3190 check_whether_skip && return 0
3191 log "run for 4MB test file"
3194 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
3195 check_whether_skip && return 0
3196 log "run for 40MB test file"
3199 run_test 23 "Quota should be honored with directIO (b16125)"
3203 local TESTFILE="$DIR/$tdir/$tfile"
3205 setup_quota_test || error "setup quota failed with $?"
3207 set_ost_qtype $QTYPE || error "enable ost quota failed"
3209 # bind file to a single OST
3210 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
3211 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3213 echo "Set user quota (limit: ${blimit}M)"
3214 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
3215 error "set quota failed"
3217 # overrun quota by root user
3218 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
3219 error "write failure, expect success"
3220 cancel_lru_locks osc
3221 sync_all_data || true
3223 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
3225 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
3229 (( $MDS1_VERSION >= $(version_code 2.15.55.145) )) ||
3230 skip "need MDS >= v2_15_55-145-g513b1cdbc for index version fix"
3232 local limit=10 # 10M
3233 local testfile="$DIR/$tdir/$tfile-0"
3234 local qpool="qpool1"
3237 setup_quota_test || error "setup quota failed with $?"
3240 set_ost_qtype $QTYPE || error "enable ost quota failed"
3242 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
3243 error "set user quota failed"
3245 pool_add $qpool || error "pool_add failed"
3246 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
3247 error "pool_add_targets failed"
3249 # increase ost index version to +200
3250 for i in {1..200}; do
3251 $LFS setquota -u $TSTUSR -B ${i}G --pool $qpool $DIR ||
3252 error "set user quota failed"
3254 $LFS setquota -u $TSTUSR -b 0 -B 0 --pool $qpool $DIR ||
3255 error "set user quota failed"
3257 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
3258 error "set user quota failed"
3260 local used=$(getquota -u $TSTUSR global curspace)
3261 (( used == 0)) || error "Used space($used) for user $TSTUSR isn't 0."
3263 $LFS setstripe $testfile -c 1 || error "setstripe $testfile failed"
3264 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
3266 test_1_check_write $testfile "user" $limit
3269 run_test 25 "check indexes versions"
3271 test_27a() { # b19612
3272 $LFS quota $TSTUSR $DIR &&
3273 error "lfs succeeded with no type, but should have failed"
3274 $LFS setquota $TSTUSR $DIR &&
3275 error "lfs succeeded with no type, but should have failed"
3278 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
3280 test_27b() { # b20200
3281 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3282 error "lfs setquota failed with uid argument"
3283 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
3284 error "lfs stequota failed with gid argument"
3285 if is_project_quota_supported; then
3286 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
3287 1000 $DIR || error \
3288 "lfs stequota failed with projid argument"
3290 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
3291 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
3292 if is_project_quota_supported; then
3293 $SHOW_QUOTA_PROJID ||
3294 error "lfs quota failed with projid argument"
3295 resetquota_one -p $TSTPRJID
3297 resetquota -u $TSTID
3298 resetquota -g $TSTID
3301 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
3306 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
3307 error "lfs setquota failed"
3309 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3310 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
3311 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3312 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
3314 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
3315 error "lfs setquota for $TSTID failed"
3317 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
3318 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
3319 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
3320 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
3322 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
3323 error "total allocated inode/block limit not printed"
3325 resetquota -u $TSTUSR
3327 run_test 27c "lfs quota should support human-readable output"
3334 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
3335 error "set fraction block limit failed"
3336 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
3337 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
3338 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
3339 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
3341 resetquota -u $TSTUSR
3343 run_test 27d "lfs setquota should support fraction block limit"
3347 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
3348 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
3351 local TESTFILE="$DIR/$tdir/$tfile"
3354 setup_quota_test || error "setup quota failed with $?"
3356 set_ost_qtype "u" || error "enable ost quota failed"
3358 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
3359 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3361 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
3362 $MAX_IQ_TIME $DIR || error "set grace time failed"
3363 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
3364 error "set quota failed"
3365 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
3366 cancel_lru_locks osc
3368 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
3369 # over-quota flag has not yet settled since we do not trigger async
3370 # events based on grace time period expiration
3372 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
3373 cancel_lru_locks osc
3374 # now over-quota flag should be settled and further writes should fail
3376 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
3377 error "grace times were reset"
3378 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
3379 $MAX_IQ_TIME $DIR || error "restore grace time failed"
3381 run_test 30 "Hard limit updates should not reset grace times"
3383 # basic usage tracking for user & group
3385 local INODES=10 # files
3386 local BLK_CNT=2 # MB each
3387 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
3389 setup_quota_test || error "setup quota failed with $?"
3391 # make sure the system is clean
3392 local USED=$(getquota -u $TSTID global curspace)
3394 error "Used space ($USED) for user $TSTID isn't 0."
3395 USED=$(getquota -g $TSTID global curspace)
3397 error "Used space ($USED) for group $TSTID isn't 0."
3398 if is_project_quota_supported; then
3399 USED=$(getquota -p $TSTPRJID global curspace)
3400 [ $USED -ne 0 ] && error \
3401 "Used space ($USED) for project $TSTPRJID isn't 0."
3404 echo "Write files..."
3405 for i in $(seq 0 $INODES); do
3406 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
3407 error "write failed"
3408 is_project_quota_supported &&
3409 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
3410 echo "Iteration $i/$INODES completed"
3412 cancel_lru_locks osc
3414 echo "Wait for setattr on objects finished..."
3415 wait_delete_completed
3417 sync; sync_all_data || true
3419 echo "Verify disk usage after write"
3420 USED=$(getquota -u $TSTID global curspace)
3421 [ $USED -lt $TOTAL_BLKS ] &&
3422 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
3423 USED=$(getquota -g $TSTID global curspace)
3424 [ $USED -lt $TOTAL_BLKS ] &&
3425 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
3426 if is_project_quota_supported; then
3427 USED=$(getquota -p $TSTPRJID global curspace)
3428 [ $USED -lt $TOTAL_BLKS ] && error \
3429 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
3432 echo "Verify inode usage after write"
3433 USED=$(getquota -u $TSTID global curinodes)
3434 [ $USED -lt $INODES ] &&
3435 error "Used inode for user $TSTID is $USED, expected $INODES"
3436 USED=$(getquota -g $TSTID global curinodes)
3437 [ $USED -lt $INODES ] &&
3438 error "Used inode for group $TSTID is $USED, expected $INODES"
3439 if is_project_quota_supported; then
3440 USED=$(getquota -p $TSTPRJID global curinodes)
3441 [ $USED -lt $INODES ] && error \
3442 "Used inode for project $TSTPRJID is $USED, expected $INODES"
3447 echo "Verify disk usage after delete"
3448 USED=$(getquota -u $TSTID global curspace)
3449 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
3450 USED=$(getquota -u $TSTID global curinodes)
3451 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
3452 USED=$(getquota -g $TSTID global curspace)
3453 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
3454 USED=$(getquota -g $TSTID global curinodes)
3455 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
3456 if is_project_quota_supported; then
3457 USED=$(getquota -p $TSTPRJID global curspace)
3459 error "Used space for project $TSTPRJID isn't 0. $USED"
3460 USED=$(getquota -p $TSTPRJID global curinodes)
3462 error "Used inodes for project $TSTPRJID isn't 0. $USED"
3465 run_test 33 "Basic usage tracking for user & group & project"
3467 # usage transfer test for user & group & project
3469 local BLK_CNT=2 # MB
3470 local project_supported="no"
3472 is_project_quota_supported && project_supported="yes"
3473 setup_quota_test || error "setup quota failed with $?"
3475 # make sure the system is clean
3476 local USED=$(getquota -u $TSTID global curspace)
3477 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
3478 USED=$(getquota -g $TSTID global curspace)
3479 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
3481 local USED=$(getquota -u $TSTID2 global curspace)
3482 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
3483 if [ $project_supported == "yes" ]; then
3484 USED=$(getquota -p $TSTPRJID global curspace)
3485 [ $USED -ne 0 ] && error \
3486 "Used space ($USED) for Project $TSTPRJID isn't 0."
3489 echo "Write file..."
3490 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3491 error "write failed"
3492 cancel_lru_locks osc
3493 sync; sync_all_data || true
3495 echo "chown the file to user $TSTID"
3496 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
3498 echo "Wait for setattr on objects finished..."
3499 wait_delete_completed
3501 BLK_CNT=$((BLK_CNT * 1024))
3503 echo "Verify disk usage for user $TSTID"
3504 USED=$(getquota -u $TSTID global curspace)
3505 [ $USED -lt $BLK_CNT ] &&
3506 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
3507 USED=$(getquota -u $TSTID global curinodes)
3509 error "Used inodes for user $TSTID is $USED, expected 1"
3511 echo "chgrp the file to group $TSTID"
3512 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
3514 echo "Wait for setattr on objects finished..."
3515 wait_delete_completed
3517 echo "Verify disk usage for group $TSTID"
3518 USED=$(getquota -g $TSTID global curspace)
3519 [ $USED -ge $BLK_CNT ] ||
3520 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3521 USED=$(getquota -g $TSTID global curinodes)
3523 error "Used inodes for group $TSTID is $USED, expected 1"
3525 # chown won't change the ost object group. LU-4345 */
3526 echo "chown the file to user $TSTID2"
3527 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
3529 echo "Wait for setattr on objects finished..."
3530 wait_delete_completed
3532 echo "change_project project id to $TSTPRJID"
3533 [ $project_supported == "yes" ] &&
3534 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3535 echo "Wait for setattr on objects finished..."
3536 wait_delete_completed
3538 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
3539 USED=$(getquota -u $TSTID2 global curspace)
3540 [ $USED -lt $BLK_CNT ] &&
3541 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
3542 USED=$(getquota -u $TSTID global curspace)
3544 error "Used space for user $TSTID is $USED, expected 0"
3545 USED=$(getquota -g $TSTID global curspace)
3546 [ $USED -lt $BLK_CNT ] &&
3547 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
3548 if [ $project_supported == "yes" ]; then
3549 USED=$(getquota -p $TSTPRJID global curspace)
3550 [ $USED -lt $BLK_CNT ] && error \
3551 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
3555 run_test 34 "Usage transfer for user & group & project"
3557 # usage is still accessible across restart
3559 local BLK_CNT=2 # MB
3561 setup_quota_test || error "setup quota failed with $?"
3563 echo "Write file..."
3564 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
3565 error "write failed"
3566 is_project_quota_supported &&
3567 change_project -p $TSTPRJID $DIR/$tdir/$tfile
3570 echo "Wait for setattr on objects finished..."
3571 wait_delete_completed
3573 sync; sync_all_data || true
3575 echo "Save disk usage before restart"
3576 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
3577 [ $ORIG_USR_SPACE -eq 0 ] &&
3578 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
3579 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
3580 [ $ORIG_USR_INODES -eq 0 ] &&
3581 error "Used inodes for user $TSTID is 0, expected 1"
3582 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
3583 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
3584 [ $ORIG_GRP_SPACE -eq 0 ] &&
3585 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
3586 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
3587 [ $ORIG_GRP_INODES -eq 0 ] &&
3588 error "Used inodes for group $TSTID is 0, expected 1"
3589 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
3591 if is_project_quota_supported; then
3592 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
3593 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
3594 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
3595 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
3596 [ $ORIG_PRJ_INODES -eq 0 ] && error \
3597 "Used inodes for project $TSTPRJID is 0, expected 1"
3598 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
3604 wait_recovery_complete
3607 echo "Verify disk usage after restart"
3608 local USED=$(getquota -u $TSTID global curspace)
3609 (( $USED == $ORIG_USR_SPACE )) || {
3610 ls -al $DIR/$tdir/$tfile
3611 $LFS quota -v -u $TSTID $DIR
3612 error "Used space for user $TSTID changed from " \
3613 "$ORIG_USR_SPACE to $USED"
3615 USED=$(getquota -u $TSTID global curinodes)
3616 [ $USED -eq $ORIG_USR_INODES ] ||
3617 error "Used inodes for user $TSTID changed from " \
3618 "$ORIG_USR_INODES to $USED"
3619 USED=$(getquota -g $TSTID global curspace)
3620 [ $USED -eq $ORIG_GRP_SPACE ] ||
3621 error "Used space for group $TSTID changed from " \
3622 "$ORIG_GRP_SPACE to $USED"
3623 USED=$(getquota -g $TSTID global curinodes)
3624 [ $USED -eq $ORIG_GRP_INODES ] ||
3625 error "Used inodes for group $TSTID changed from " \
3626 "$ORIG_GRP_INODES to $USED"
3627 if [[ $project_supported == "yes" ]]; then
3628 USED=$(getquota -p $TSTPRJID global curinodes)
3629 (( $USED == $ORIG_PRJ_INODES )) ||
3630 error "Used inodes for project $TSTPRJID " \
3631 "changed from $ORIG_PRJ_INODES to $USED"
3632 USED=$(getquota -p $TSTPRJID global curspace)
3633 [ $USED -eq $ORIG_PRJ_SPACE ] ||
3634 error "Used space for project $TSTPRJID "\
3635 "changed from $ORIG_PRJ_SPACE to $USED"
3638 # check if the vfs_dq_init() is called before writing
3639 echo "Append to the same file..."
3640 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
3641 error "write failed"
3642 cancel_lru_locks osc
3643 sync; sync_all_data || true
3645 echo "Verify space usage is increased"
3646 USED=$(getquota -u $TSTID global curspace)
3647 [ $USED -gt $ORIG_USR_SPACE ] ||
3648 error "Used space for user $TSTID isn't increased" \
3649 "orig:$ORIG_USR_SPACE, now:$USED"
3650 USED=$(getquota -g $TSTID global curspace)
3651 [ $USED -gt $ORIG_GRP_SPACE ] ||
3652 error "Used space for group $TSTID isn't increased" \
3653 "orig:$ORIG_GRP_SPACE, now:$USED"
3654 if [[ $project_supported == "yes" ]]; then
3655 USED=$(getquota -p $TSTPRJID global curspace)
3656 (( $USED > $ORIG_PRJ_SPACE )) ||
3657 error "Used space for project $TSTPRJID isn't " \
3658 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
3661 run_test 35 "Usage is still accessible across reboot"
3663 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
3666 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
3667 skip "Old server doesn't have LU-5006 fix."
3669 setup_quota_test || error "setup quota failed with $?"
3671 # make sure the system is clean
3672 local USED=$(getquota -u $TSTID global curspace)
3674 error "Used space ($USED) for user $TSTID isn't 0."
3676 # create file with MDS_OPEN_DELAY_CREATE flag
3677 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
3678 error "Create file failed"
3680 $DD of=$DIR/$tdir/$tfile count=1 conv=notrunc \
3681 oflag=sync || error "Write file failed"
3683 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
3685 # wait for setattr on objects finished..."
3686 wait_delete_completed
3688 USED=$(getquota -u $TSTID global curspace)
3689 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
3691 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
3695 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
3696 skip "Old server doesn't have LU-8801 fix."
3698 [ "$UID" != 0 ] && skip_env "must run as root" && return
3700 setup_quota_test || error "setup quota failed with $?"
3702 # make sure the system is clean
3703 local USED=$(getquota -u $TSTID global curspace)
3705 error "Used space ($USED) for user $TSTID isn't 0."
3706 USED=$(getquota -u $TSTID2 global curspace)
3708 error "Used space ($USED) for user $TSTID2 isn't 0."
3710 local TESTFILE="$DIR/$tdir/$tfile"
3711 local file_cnt=10000
3713 # Generate id entries in accounting file
3714 echo "Create $file_cnt files..."
3715 for i in `seq $file_cnt`; do
3717 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
3718 error "failed to chown $TESTFILE-$i"
3720 cancel_lru_locks osc
3721 sync; sync_all_data || true
3723 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
3724 procf=${procf}.quota_slave.acct_user
3727 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
3728 awk '{if ($3 < 10000) {print $3}}' | wc -l)
3729 echo "Found $acct_cnt id entries"
3731 [ $file_cnt -eq $acct_cnt ] || {
3732 do_facet mds1 $LCTL get_param $procf
3733 error "skipped id entries"
3736 run_test 38 "Quota accounting iterator doesn't skip id entries"
3739 local TESTFILE="$DIR/$tdir/project"
3740 ! is_project_quota_supported &&
3741 skip "Project quota is not supported"
3743 setup_quota_test || error "setup quota failed with $?"
3746 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3747 [ $projectid -ne 0 ] &&
3748 error "Project id should be 0 not $projectid"
3749 change_project -p 1024 $TESTFILE
3750 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3751 [ $projectid -ne 1024 ] &&
3752 error "Project id should be 1024 not $projectid"
3754 stopall || error "failed to stopall (1)"
3757 projectid=$(lfs project $TESTFILE | awk '{print $1}')
3758 [ $projectid -eq 1024 ] ||
3759 error "Project id should be 1024 not $projectid"
3761 run_test 39 "Project ID interface works correctly"
3764 ! is_project_quota_supported &&
3765 skip "Project quota is not supported"
3766 local dir1="$DIR/$tdir/dir1"
3767 local dir2="$DIR/$tdir/dir2"
3769 setup_quota_test || error "setup quota failed with $?"
3771 mkdir -p $dir1 $dir2
3772 change_project -sp 1 $dir1 && touch $dir1/1
3773 change_project -sp 2 $dir2
3775 ln $dir1/1 $dir2/1_link &&
3776 error "Hard link across different project quota should fail"
3779 run_test 40a "Hard link across different project ID"
3782 ! is_project_quota_supported &&
3783 skip "Project quota is not supported"
3784 local dir1="$DIR/$tdir/dir1"
3785 local dir2="$DIR/$tdir/dir2"
3787 setup_quota_test || error "setup quota failed with $?"
3788 mkdir -p $dir1 $dir2
3789 change_project -sp 1 $dir1 && touch $dir1/1
3790 change_project -sp 2 $dir2
3792 mv $dir1/1 $dir2/2 || error "mv failed $?"
3793 local projid=$(lfs project $dir2/2 | awk '{print $1}')
3794 [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
3796 run_test 40b "Mv across different project ID"
3799 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3800 ! is_project_quota_supported &&
3801 skip "Project quota is not supported"
3803 setup_quota_test || error "setup quota failed with $?"
3804 local dir="$DIR/$tdir/dir"
3806 mkdir -p $dir && change_project -sp 1 $dir
3807 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
3808 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
3809 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
3810 touch $dir/remote_dir/file
3811 #verify inherit works file for remote dir.
3812 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
3813 [ "$projid" != "1" ] &&
3814 error "file under remote dir expected 1 not $projid"
3816 #Agent inode should be ignored for project quota
3817 local used=$(getquota -p 1 global curinodes)
3819 error "file count expected 3 got $used"
3821 run_test 40c "Remote child Dir inherit project quota properly"
3824 [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
3825 is_project_quota_supported || skip "Project quota is not supported"
3827 setup_quota_test || error "setup quota failed with $?"
3828 local dir="$DIR/$tdir/dir"
3831 $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
3832 change_project -sp $TSTPRJID $dir ||
3833 error "change project on $dir failed"
3834 for i in $(seq 5); do
3835 mkdir -p $dir/d$i/d$i ||
3836 error "mkdir $dir/d$i/d$i failed"
3837 local projid=$($LFS project -d $dir/d$i/d$i |
3839 [ "$projid" == "$TSTPRJID" ] ||
3840 error "projid id expected $TSTPRJID not $projid"
3841 touch $dir/d$i/d$i/file
3842 #verify inherit works file for stripe dir.
3843 local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
3844 [ "$projid" == "$TSTPRJID" ] ||
3845 error "file under remote dir expected 1 not $projid"
3848 # account should be 1 + (2 + 1) *10 + 1 * 5
3849 local used=$(getquota -p $TSTPRJID global curinodes)
3851 error "file count expected 36 got $used"
3853 run_test 40d "Stripe Directory inherit project quota properly"
3856 is_project_quota_supported ||
3857 skip "Project quota is not supported"
3858 setup_quota_test || error "setup quota failed with $?"
3859 local dir="$DIR/$tdir/dir"
3862 local projid=$((testnum * 1000))
3866 # enable mdt/ost quota
3867 set_mdt_qtype ugp || error "enable mdt quota failed"
3868 set_ost_qtype ugp || error "enable ost quota failed"
3870 test_mkdir -p $dir && change_project -sp $projid $dir
3871 $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
3872 error "set project quota failed"
3877 # check if df output works as expected
3878 echo "== global statfs: $MOUNT =="
3879 df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
3881 echo "== project statfs (prjid=$projid): $dir =="
3882 df -kP $dir; df -iP $dir
3883 local bused=$(getquota -p $projid global curspace)
3884 local iused=$(getquota -p $projid global curinodes)
3885 # note trailing space to match double printf from awk
3886 local expected="$blimit $bused $ilimit $iused "
3888 wait_update $HOSTNAME \
3889 "{ df -kP $dir; df -iP $dir; } |
3890 awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
3892 error "failed to get correct statfs for project quota"
3894 run_test 41 "df should return projid-specific values"
3902 local osd="osd-ldiskfs"
3904 [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
3906 rm -f $DIR/$tdir/$tfile
3907 $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3908 chmod a+rw $DIR/$tdir/$tfile
3910 $LFS setquota $qtype $qid -B 300M $MOUNT
3911 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3913 do_facet $SINGLEMDS \
3914 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3915 grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
3918 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3919 grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
3921 $LFS setquota $qtype $qid --delete $MOUNT
3922 do_facet $SINGLEMDS \
3923 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3924 grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
3927 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3928 grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
3930 $LFS setquota $qtype $qid -B 500M $MOUNT
3931 $RUNAS $DD of=$DIR/$tdir/$tfile count=1 || error "failed to dd"
3932 do_facet $SINGLEMDS \
3933 "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
3934 grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
3935 cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
3937 "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
3938 grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
3943 setup_quota_test || error "setup quota failed with $?"
3944 set_ost_qtype $QTYPE || error "enable ost quota failed"
3947 test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
3948 test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
3949 is_project_quota_supported &&
3950 test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
3954 run_test 48 "lfs quota --delete should delete quota project ID"
3957 ! is_project_quota_supported &&
3958 skip "Project quota is not supported"
3960 setup_quota_test || error "setup quota failed with $?"
3961 local dir1="$DIR/$tdir/dir1"
3962 local dir2="$DIR/$tdir/dir2"
3964 mkdir -p $dir1 && change_project -sp 1 $dir1
3965 mkdir -p $dir2 && change_project -sp 2 $dir2
3966 for num in $(seq 1 10); do
3967 touch $dir1/file_$num $dir2/file_$num
3968 ln -s $dir1/file_$num $dir1/file_$num"_link"
3969 ln -s $dir2/file_$num $dir2/file_$num"_link"
3972 count=$($LFS find --projid 1 $DIR | wc -l)
3973 [ "$count" != 21 ] && error "expected 21 but got $count"
3975 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
3976 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
3977 [ $count -eq 22 ] || error "expected 22 but got $count"
3979 run_test 50 "Test if lfs find --projid works"
3982 ! is_project_quota_supported &&
3983 skip "Project quota is not supported"
3984 setup_quota_test || error "setup quota failed with $?"
3985 local dir="$DIR/$tdir/dir"
3987 mkdir $dir && change_project -sp 1 $dir
3988 local used=$(getquota -p 1 global curinodes)
3989 [ $used != "1" ] && error "expected 1 got $used"
3994 used=$(getquota -p 1 global curinodes)
3995 [ $used != "4" ] && error "expected 4 got $used"
3997 $DD of=$DIR/$tdir/6 count=1
3999 cp $DIR/$tdir/6 $dir/6
4000 used=$(getquota -p 1 global curinodes)
4001 [ $used != "5" ] && error "expected 5 got $used"
4004 mv $DIR/$tdir/6 $dir/7
4005 used=$(getquota -p 1 global curinodes)
4006 [ $used -eq 6 ] || error "expected 6 got $used"
4008 run_test 51 "Test project accounting with mv/cp"
4011 ! is_project_quota_supported &&
4012 skip "Project quota is not supported"
4014 (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
4015 skip "Need MDS version at least 2.14.55"
4017 setup_quota_test || error "setup quota failed with $?"
4019 local dir1=$DIR/$tdir/t52_dir1
4020 local dir2=$DIR/$tdir/t52_dir2
4022 mkdir $dir1 || error "failed to mkdir $dir1"
4023 mkdir $dir2 || error "failed to mkdir $dir2"
4025 $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
4026 $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
4028 $DD of=$dir1/$tfile count=100 ||
4029 error "failed to create and write $dir1/$tfile"
4031 cancel_lru_locks osc
4032 sync; sync_all_data || true
4034 local attrs=($(lsattr -p $dir1/$tfile))
4035 (( ${attrs[0]} == 1000 )) ||
4036 error "project ID on $dir1/$tfile is not inherited"
4038 $LFS quota -p 1000 $DIR
4039 $LFS quota -p 1001 $DIR
4041 local prev_used=$(getquota -p 1000 global curspace)
4042 local prev_used2=$(getquota -p 1001 global curspace)
4044 mrename $dir1 $dir2/tdir || log "rename directory return $?"
4046 local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
4047 mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
4048 local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
4050 attrs=($(lsattr -p $dir2/$tfile))
4051 (( ${attrs[0]} == 1001 )) ||
4052 error "project ID is not updated after rename"
4054 (( $inum_before == $inum_after )) ||
4055 error "inode is changed after rename: $inum_before, $inum_after"
4057 sync_all_data || true
4059 $LFS quota -p 1000 $DIR
4060 $LFS quota -p 1001 $DIR
4062 local new_used=$(getquota -p 1000 global curspace)
4063 local new_used2=$(getquota -p 1001 global curspace)
4065 (( $prev_used >= $new_used + 102400 )) ||
4066 error "quota is not deducted from old project ID"
4067 (( $prev_used2 <= $new_used2 - 102400 )) ||
4068 error "quota is not added for the new project ID"
4070 run_test 52 "Rename normal file across project ID"
4073 ! is_project_quota_supported &&
4074 skip "Project quota is not supported"
4075 setup_quota_test || error "setup quota failed with $?"
4076 local dir="$DIR/$tdir/dir"
4077 mkdir $dir && change_project -s $dir
4078 [[ $($LFS project -d $dir) =~ " P " ]] ||
4079 error "inherit attribute should be set"
4081 change_project -C $dir
4082 [[ $($LFS project -d $dir) =~ " - " ]] ||
4083 error "inherit attribute should be cleared"
4085 run_test 53 "Project inherit attribute could be cleared"
4088 ! is_project_quota_supported &&
4089 skip "Project quota is not supported"
4090 setup_quota_test || error "setup quota failed with $?"
4091 local testfile="$DIR/$tdir/$tfile-0"
4093 #set project ID/inherit attribute
4094 change_project -sp $TSTPRJID $DIR/$tdir
4095 $RUNAS createmany -m ${testfile} 100 ||
4096 error "create many files failed"
4098 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
4099 # one more count for directory itself */
4103 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4104 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
4106 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
4107 [ $proj_count1 -eq $proj_count ] ||
4108 error "c2: expected $proj_count got $proj_count1"
4110 #clear project but with kept projid
4111 change_project -rCk $DIR/$tdir
4112 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4113 [ $proj_count1 -eq 1 ] ||
4114 error "c3: expected 1 got $proj_count1"
4116 #verify projid untouched.
4117 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4119 [ $proj_count1 -eq $proj_count ] ||
4120 error "c4: expected $proj_count got $proj_count1"
4123 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
4124 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
4125 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
4127 #this time clear all
4128 change_project -rC $DIR/$tdir
4129 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
4130 [ $proj_count1 -eq 0 ] ||
4131 error "c6: expected 0 got $proj_count1"
4133 unlinkmany ${testfile} 100 ||
4134 error "unlink many files failed"
4136 run_test 54 "basic lfs project interface test"
4139 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
4140 skip "Not supported before 2.10.58."
4141 setup_quota_test || error "setup quota failed with $?"
4143 set_ost_qtype $QTYPE || error "enable ost quota failed"
4146 #add second group to TSTUSR
4147 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
4150 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
4151 error "failed to dd"
4153 cancel_lru_locks osc
4154 sync; sync_all_data || true
4156 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
4157 error "failed to setquota on group $TSTUSR2"
4159 $LFS quota -v -g $TSTUSR2 $DIR
4161 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
4162 error "chgrp should failed with -EDQUOT"
4164 USED=$(getquota -g $TSTUSR2 global curspace)
4167 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
4168 error "failed to setquota on group $TSTUSR2"
4170 $LFS quota -v -g $TSTUSR2 $DIR
4172 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
4173 error "chgrp should succeed"
4175 $LFS quota -v -g $TSTUSR2 $DIR
4177 run_test 55 "Chgrp should be affected by group quota"
4180 setup_quota_test || error "setup quota failed with $?"
4182 set_ost_qtype $QTYPE || error "enable ost quota failed"
4185 $LFS setquota -t -u -b 10 -i 10 $DIR ||
4186 erro "failed to set grace time for usr quota"
4187 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
4188 awk '{print $4 $8}')
4189 if [ "x$grace_time" != "x10s;10s" ]; then
4190 $LFS quota -t -u $DIR
4191 error "expected grace time: 10s;10s, got:$grace_time"
4194 run_test 56 "lfs quota -t should work well"
4197 setup_quota_test || error "setup quota failed with $?"
4199 local dir="$DIR/$tdir/dir"
4202 #command can process further if it hit some errors
4203 $LFS project -sp 1 $dir/pipe
4204 touch $dir/aaa $dir/bbb
4205 mkdir $dir/subdir -p
4206 touch $dir/subdir/aaa $dir/subdir/bbb
4207 #create one invalid link file
4208 ln -s $dir/not_exist_file $dir/ccc
4209 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
4210 [ $cnt -eq 7 ] || error "expected 7 got $cnt"
4212 run_test 57 "lfs project could tolerate errors"
4215 [ "$mds1_FSTYPE" != ldiskfs ] &&
4216 skip "ldiskfs only test"
4217 disable_project_quota
4218 setup_quota_test || error "setup quota failed with $?"
4221 local testfile="$DIR/$tdir/$tfile-0"
4222 #make sure it did not crash kernel
4223 touch $testfile && lfs project -sp 1 $testfile
4225 enable_project_quota
4227 run_test 59 "lfs project dosen't crash kernel with project disabled"
4230 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
4231 skip "Needs MDS version 2.11.53 or later."
4232 setup_quota_test || error "setup quota failed with $?"
4234 local testfile=$DIR/$tdir/$tfile
4237 set_mdt_qtype "ug" || error "enable mdt quota failed"
4239 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
4240 error "set quota failed"
4241 quota_show_check a g $TSTUSR
4243 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
4244 chmod g+s $DIR/$tdir || error "chmod g+s failed"
4245 $RUNAS createmany -m ${testfile} $((limit-1)) ||
4246 error "create many files failed"
4248 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
4250 # root user can overrun quota
4251 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
4252 error "root user should succeed"
4254 run_test 60 "Test quota for root with setgid"
4256 # test default quota
4257 test_default_quota() {
4258 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
4259 skip "Not supported before 2.11.51."
4264 local qprjid=$TSTPRJID
4268 local LIMIT=20480 #20M disk space
4269 local TESTFILE="$DIR/$tdir/$tfile-0"
4272 [ $qtype == "-p" ] && ! is_project_quota_supported &&
4273 echo "Project quota is not supported" && return 0
4275 [ $qtype == "-u" ] && qdtype="-U"
4276 [ $qtype == "-g" ] && qdtype="-G"
4277 [ $qtype == "-p" ] && {
4282 [ $qres_type == "meta" ] && {
4283 LIMIT=10240 #10K inodes
4288 qpool_cmd="--pool $3"
4289 # pool quotas don't work properly without global limit
4290 $LFS setquota $qtype $qid -B1T -b1T $DIR ||
4291 error "set global limit failed"
4294 setup_quota_test || error "setup quota failed with $?"
4298 # enable mdt/ost quota
4299 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4300 set_ost_qtype $QTYPE || error "enable ost quota failed"
4302 log "set to use default quota"
4303 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4304 error "set $qid to use default quota failed"
4306 log "set default quota"
4307 $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4308 error "set $qid default quota failed"
4310 log "get default quota"
4311 $LFS quota $qdtype $DIR || error "get default quota failed"
4313 if [ $qres_type == "data" ]; then
4314 local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
4315 grep "$MOUNT" | awk '{print $2}')
4316 [ $SLIMIT -eq $LIMIT ] ||
4317 error "the returned default quota is wrong"
4319 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
4321 [ $SLIMIT -eq $LIMIT ] ||
4322 error "the returned default quota is wrong"
4325 # make sure the system is clean
4326 local USED=$(getquota $qtype $qid global curspace)
4327 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4329 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4330 error "setstripe $TESTFILE failed"
4331 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4333 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
4335 log "Test not out of quota"
4336 if [ $qres_type == "data" ]; then
4337 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
4338 quota_error $qtype $qid "write failed, expect succeed"
4340 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
4341 quota_error $qtype $qid "create failed, expect succeed"
4343 unlinkmany $TESTFILE $((LIMIT/2))
4346 log "Test out of quota"
4347 # flush cache, ensure noquota flag is set on client
4348 cancel_lru_locks osc
4349 cancel_lru_locks mdc
4350 sync; sync_all_data || true
4351 if [ $qres_type == "data" ]; then
4352 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4353 quota_error $qtype $qid "write succeed, expect EDQUOT"
4355 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4356 quota_error $qtype $qid "create succeed, expect EDQUOT"
4358 unlinkmany $TESTFILE $((LIMIT*2))
4362 $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
4363 error "setstripe $TESTFILE failed"
4364 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
4366 log "Increase default quota"
4368 # LU-4505: sleep 5 seconds to enable quota acquire
4371 # increase default quota
4372 $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
4373 $qh $((LIMIT*3)) $DIR || error "set default quota failed"
4375 cancel_lru_locks osc
4376 cancel_lru_locks mdc
4377 sync; sync_all_data || true
4378 if [ $qres_type == "data" ]; then
4379 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4380 quota_error $qtype $qid "write failed, expect succeed"
4382 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4383 quota_error $qtype $qid "create failed, expect succeed"
4385 unlinkmany $TESTFILE $((LIMIT*2))
4388 log "Set quota to override default quota"
4389 $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
4390 error "set $qid quota failed"
4392 cancel_lru_locks osc
4393 cancel_lru_locks mdc
4394 sync; sync_all_data || true
4395 if [ $qres_type == "data" ]; then
4396 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
4397 quota_error $qtype $qid "write succeed, expect EQUOT"
4399 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
4400 quota_error $qtype $qid "create succeed, expect EQUOT"
4402 unlinkmany $TESTFILE $((LIMIT*2))
4405 log "Set to use default quota again"
4407 # LU-4505: sleep 5 seconds to enable quota acquire
4410 $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
4411 error "set $qid to use default quota failed"
4413 cancel_lru_locks osc
4414 cancel_lru_locks mdc
4415 sync; sync_all_data || true
4416 if [ $qres_type == "data" ]; then
4417 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
4418 quota_error $qtype $qid "write failed, expect succeed"
4420 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
4421 quota_error $qtype $qid "create failed, expect succeed"
4423 unlinkmany $TESTFILE $((LIMIT*2))
4428 wait_delete_completed || error "wait_delete_completed failed"
4429 sync_all_data || true
4431 $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
4432 error "reset default quota failed"
4433 $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
4434 error "reset quota failed"
4439 test_default_quota "-u" "data"
4440 test_default_quota "-u" "meta"
4441 test_default_quota "-g" "data"
4442 test_default_quota "-g" "meta"
4443 test_default_quota "-p" "data"
4444 test_default_quota "-p" "meta"
4446 run_test 61 "default quota tests"
4449 ! is_project_quota_supported &&
4450 skip "Project quota is not supported"
4451 [[ "$(chattr -h 2>&1)" =~ "project" ||
4452 "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
4453 skip "chattr did not support project quota"
4454 setup_quota_test || error "setup quota failed with $?"
4455 local testdir=$DIR/$tdir/
4457 $RUNAS mkdir -p $testdir || error "failed to mkdir"
4458 change_project -s $testdir
4459 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4460 error "inherit attribute should be set"
4461 # chattr used FS_IOC_SETFLAGS ioctl
4462 $RUNAS chattr -P $testdir &&
4463 error "regular user clear inherit should fail"
4464 [[ $($LFS project -d $testdir) =~ "P" ]] ||
4465 error "inherit attribute should still be set"
4466 chattr -P $testdir || error "root failed to clear inherit"
4467 [[ $($LFS project -d $testdir) =~ "P" ]] &&
4468 error "inherit attribute should be cleared"
4471 run_test 62 "Project inherit should be only changed by root"
4474 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
4475 skip "Not supported before 2.11.55"
4479 local dd_failed=false
4480 local tdir_dom=${tdir}_dom
4481 local LIMIT=20480 #20M
4483 [ $qtype == "p" ] && ! is_project_quota_supported &&
4484 echo "Project quota is not supported" && return 0
4486 [ $qtype == "p" ] && qid=$TSTPRJID
4488 setup_quota_test || error "setup quota failed with $?"
4492 # enable mdt/ost quota
4493 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4494 set_ost_qtype $QTYPE || error "enable ost quota failed"
4496 # make sure the system is clean
4497 local USED=$(getquota -$qtype $qid global curspace)
4498 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
4500 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
4502 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
4503 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
4504 error "setstripe $tdir_dom failed"
4505 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
4507 [ $qtype == "p" ] && {
4508 change_project -sp $TSTPRJID $DIR/$tdir
4509 change_project -sp $TSTPRJID $DIR/$tdir_dom
4512 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
4513 error "set $qid quota failed"
4515 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4516 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4520 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4522 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
4523 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4527 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
4529 rm -f $DIR/$tdir_dom/*
4531 # flush cache, ensure noquota flag is set on client
4532 cancel_lru_locks osc
4533 cancel_lru_locks mdc
4534 sync; sync_all_data || true
4538 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
4539 quota_error $qtype $qid "write failed, expect succeed"
4541 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
4542 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4546 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
4549 rm -f $DIR/$tdir_dom/*
4551 # flush cache, ensure noquota flag is set on client
4552 cancel_lru_locks osc
4553 cancel_lru_locks mdc
4554 sync; sync_all_data || true
4558 for ((i = 0; i < $((LIMIT/2048)); i++)); do
4559 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
4563 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
4565 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
4566 quota_error $qtype $qid "write succeed, expect EDQUOT"
4569 rm -fr $DIR/$tdir_dom
4571 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
4572 error "reset usr quota failed"
4580 run_test 63 "quota on DoM tests"
4583 ! is_project_quota_supported &&
4584 skip "Project quota is not supported"
4585 setup_quota_test || error "setup quota failed with $?"
4586 local dir1="$DIR/$tdir/"
4589 ln -s $dir1/file $dir1/file_link
4592 $LFS project -srp $TSTPRJID $dir1 >&/dev/null ||
4593 error "set project should succeed"
4595 used=$(getquota -p $TSTPRJID global curinodes)
4596 [ $used -eq 4 ] || error "expected 4 got $used"
4597 $LFS project -rC $dir1 >&/dev/null ||
4598 error "clear project should succeed"
4600 used=$(getquota -p $TSTPRJID global curinodes)
4601 [ $used -eq 0 ] || error "expected 0 got $used"
4603 run_test 64 "lfs project on non dir/files should succeed"
4607 local TESTFILE="$DIR/$tdir/$tfile-0"
4609 setup_quota_test || error "setup quota failed with $?"
4610 set_ost_qtype $QTYPE || error "enable ost quota failed"
4614 $RUNAS $DD of=$TESTFILE count=$SIZE ||
4615 error "failed to write"
4616 # flush cache, ensure noquota flag is set on client
4617 cancel_lru_locks osc
4618 sync; sync_all_data || true
4620 local quota_u=$($LFS quota -u $TSTUSR $DIR)
4621 local quota_g=$($LFS quota -g $TSTUSR $DIR)
4622 local quota_all=$($RUNAS $LFS quota $DIR)
4624 [ "$(echo "$quota_all" | head -n3)" == "$quota_u" ] ||
4625 error "usr quota not match"
4626 [ "$(echo "$quota_all" | tail -n3)" == "$quota_g" ] ||
4627 error "grp quota not match"
4629 run_test 65 "Check lfs quota result"
4632 ! is_project_quota_supported &&
4633 skip "Project quota is not supported"
4634 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
4635 skip "Not supported before 2.12.4"
4636 setup_quota_test || error "setup quota failed with $?"
4637 local old=$(do_facet mds1 $LCTL get_param -n \
4638 mdt.*.enable_chprojid_gid | head -1)
4639 local testdir=$DIR/$tdir/foo
4641 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
4642 stack_trap "do_facet mds1 $LCTL \
4643 set_param mdt.*.enable_chprojid_gid=$old" EXIT
4645 mkdir_on_mdt0 $testdir || error "failed to mkdir"
4646 chown -R $TSTID:$TSTID $testdir
4647 change_project -sp $TSTPRJID $testdir
4648 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
4650 $RUNAS lfs project -p 0 $testdir/foo &&
4651 error "nonroot user should fail to set projid"
4653 $RUNAS lfs project -C $testdir/foo &&
4654 error "nonroot user should fail to clear projid"
4656 change_project -C $testdir/foo || error "failed to clear project"
4658 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
4659 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
4660 "failed to set projid with normal user when enable_chprojid_gid=-1"
4662 $RUNAS lfs project -rC $testdir/ || error \
4663 "failed to clear project state with normal user when enable_chprojid_gid=-1"
4665 touch $testdir/bar || error "failed touch $testdir/bar"
4666 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
4667 "normal user should not be able to set projid on root owned file"
4669 change_project -p $TSTPRJID $testdir/bar || error \
4670 "root should be able to change its own file's projid"
4672 run_test 66 "nonroot user can not change project state in default"
4679 local short_qtype=${qtype:0:1}
4682 echo "0 $0 1 $1 2 $2 3 $3 4 $4"
4684 $TSTUSR) _runas=$RUNAS;;
4685 $TSTUSR2) _runas=$RUNAS2;;
4686 *) error "unknown quota parameter $4";;
4691 $_runas $DD of=$file count=$size ||
4692 quota_error $short_qtype $TSTUSR \
4693 "$qtype write failure, but expect success"
4695 cancel_lru_locks osc
4697 sync; sync_all_data || true
4706 local param=qmt.$FSNAME-QMT0000.$ptype-$pool.glb-$qtype
4708 do_facet mds1 $LCTL get_param $param |
4709 grep -A2 $userid | awk -F'[, ]*' 'NR==2{print $9}'
4714 local testfile="$DIR/$tdir/$tfile-0"
4715 local testfile2="$DIR/$tdir/$tfile-1"
4716 local testfile3="$DIR/$tdir/$tfile-2"
4717 local qpool="qpool1"
4723 [ "$ost1_FSTYPE" == zfs ] &&
4724 skip "ZFS grants some block space together with inode"
4726 setup_quota_test || error "setup quota failed with $?"
4729 set_ost_qtype $QTYPE || error "enable ost quota failed"
4732 log "User quota (block hardlimit:$limit MB)"
4733 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
4734 error "set user quota failed"
4736 # make sure the system is clean
4737 used=$(getquota -u $TSTUSR global curspace)
4738 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
4740 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4741 echo "granted 0x0 before write $granted"
4743 # trigger reintegration
4744 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
4745 procf=${procf}quota_slave.force_reint
4746 do_facet ost1 $LCTL set_param $procf=1 ||
4747 error "force reintegration failed"
4748 wait_ost_reint "u" || error "reintegration failed"
4749 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4750 [ $granted -ne 0 ] &&
4751 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4753 $LFS setstripe $testfile -c 1 -i 0 || error "setstripe $testfile failed"
4754 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
4756 # write 10 MB to testfile
4757 test_67_write "$testfile" "user" 10 "$TSTUSR"
4759 # create qpool and add OST1
4760 pool_add $qpool || error "pool_add failed"
4761 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4762 # as $TSTUSR hasn't limits, lqe may absent. But it should be
4763 # created after the 1st direct qmt_get.
4764 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
4766 # check granted - should be 0, as testfile is located only on OST0
4767 granted=$(getgranted "0x0" "dt" $TSTID "usr")
4768 echo "global granted $granted"
4769 granted=$(getgranted $qpool "dt" $TSTID "usr")
4770 echo "$qpool granted $granted"
4771 [ $granted -ne 0 ] &&
4772 error "Granted($granted) for $TSTUSR in $qpool isn't 0."
4774 # add OST0 to qpool and check granted space
4775 pool_add_targets $qpool 0 1 ||
4776 error "pool_add_targets failed"
4777 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4778 echo "Granted $granted_mb MB"
4779 #should be 10M + qunit for each OST
4780 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4781 error "Granted($granted_mb) for $TSTUSR in $qpool is wrong."
4783 $LFS setstripe $testfile2 -c 1 -i 1 ||
4784 error "setstripe $testfile2 failed"
4785 chown $TSTUSR2.$TSTUSR2 $testfile2 || error "chown $testfile2 failed"
4786 # Write from another user and check that qpool1
4787 # shows correct granted, despite $TSTUSR2 hasn't limits in qpool1.
4788 test_67_write "$testfile2" "user" 10 "$TSTUSR2"
4789 used=$(getquota -u $TSTUSR2 global curspace $qpool)
4790 granted=$(getgranted $qpool "dt" $TSTID2 "usr")
4791 [ $granted -ne 0 ] &&
4792 error "Granted($granted) for $TSTUSR2 in $qpool isn't 0."
4794 # Granted space for $TSTUSR2 in qpool1 should appear only
4795 # when global lqe for this user becomes enforced.
4796 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
4797 error "set user quota failed"
4798 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4799 echo "granted_mb $granted_mb"
4800 [ $granted_mb -ge 10 -a $granted_mb -lt $limit ] ||
4801 error "Granted($granted) for $TSTUSR in $qpool is wrong."
4803 $LFS setstripe $testfile3 -c 1 -i 0 ||
4804 error "setstripe $testfile3 failed"
4805 chown $TSTUSR2.$TSTUSR2 $testfile3 || error "chown $testfile3 failed"
4806 test_67_write "$testfile3" "user" 10 "$TSTUSR2"
4807 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4808 echo "$testfile3 granted_mb $granted_mb"
4809 [ $granted_mb -eq $limit ] ||
4810 error "Granted($granted_mb) for $TSTUSR2 is not equal to 20M"
4812 # remove OST1 from the qpool1 and check granted space
4813 # should be 0 for TSTUSR and 10M for TSTUSR2
4814 pool_remove_target $qpool 0
4815 granted_mb=$(($(getgranted $qpool "dt" $TSTID "usr")/1024))
4816 [ $granted_mb -eq 0 ] ||
4817 error "Granted($granted_mb) for $TSTUSR in $qpool != 0."
4818 granted_mb=$(($(getgranted $qpool "dt" $TSTID2 "usr")/1024))
4819 [ $granted_mb -eq 10 ] ||
4820 error "Granted($granted_mb) for $TSTUSR2 is not equal to 10M"
4823 wait_delete_completed || error "wait_delete_completed failed"
4824 sync_all_data || true
4825 used=$(getquota -u $TSTUSR global curspace)
4826 [ $used -eq 0 ] || quota_error u $TSTUSR \
4827 "user quota isn't released after deletion"
4829 run_test 67 "quota pools recalculation"
4836 wait_update_facet "--quiet" mds1 \
4837 "$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info \
4838 >/dev/null 2>&1 || echo foo" "">/dev/null ||
4839 error "mds1: failed to create quota pool $pool"
4841 do_facet mds1 $LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$pool.info |
4842 awk '/usr/ {getline; print $2}'
4847 local qpool="qpool1"
4850 setup_quota_test || error "setup quota failed with $?"
4853 set_ost_qtype $QTYPE || error "enable ost quota failed"
4855 # check slave number for glbal pool
4856 local nr=$(get_slave_nr "0x0" "usr")
4857 echo "nr result $nr"
4858 [[ $nr != $((OSTCOUNT + MDSCOUNT)) ]] &&
4859 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4861 # create qpool and add OST1
4862 pool_add $qpool || error "pool_add failed"
4863 nr=$(get_slave_nr $qpool "usr")
4864 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4867 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
4868 nr=$(get_slave_nr $qpool "usr")
4869 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4872 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
4873 nr=$(get_slave_nr $qpool "usr")
4874 [[ $nr != 2 ]] && error "Slave number $nr for $qpool != 2"
4877 pool_remove_target $qpool 0
4878 nr=$(get_slave_nr $qpool "usr")
4879 [[ $nr != 1 ]] && error "Slave number $nr for $qpool != 1"
4882 pool_remove_target $qpool 1
4883 nr=$(get_slave_nr $qpool "usr")
4884 [[ $nr != 0 ]] && error "Slave number $nr for $qpool != 0"
4886 # Check again that all is fine with global pool
4887 nr=$(get_slave_nr "0x0" "usr")
4888 [[ $nr == $((OSTCOUNT + MDSCOUNT)) ]] ||
4889 error "Slave_nr $nr for global pool != ($OSTCOUNT + $MDSCOUNT)"
4891 run_test 68 "slave number in quota pool changed after each add/remove OST"
4895 local global_limit=200 # MB
4897 local testfile="$DIR/$tdir/$tfile-0"
4898 local dom0="$DIR/$tdir/dom0"
4899 local qpool="qpool1"
4902 setup_quota_test || error "setup quota failed with $?"
4905 set_ost_qtype $QTYPE || error "enable ost quota failed"
4906 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
4908 # Save DOM only at MDT0
4909 $LFS setdirstripe -c 1 -i 0 $dom0 || error "cannot create $dom0"
4910 $LFS setstripe -E 1M $dom0 -L mdt || error "setstripe to $dom0 failed"
4912 $LFS setstripe -c 1 -i 0 "$DIR/$tdir/"
4914 # create qpool and add OST0
4915 pool_add $qpool || error "pool_add failed"
4916 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4918 log "User quota (block hardlimit:$global_limit MB)"
4919 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
4920 error "set user quota failed"
4922 log "User quota (block hardlimit:$limit MB)"
4923 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
4924 error "set user quota failed"
4926 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 oflag=sync ||
4927 quota_error u $TSTUSR "write failed"
4929 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4930 oflag=sync || quota_error u $TSTUSR "write failed"
4932 $RUNAS $DD of=$testfile count=$limit || true
4934 # flush cache, ensure noquota flag is set on client
4935 cancel_lru_locks osc
4936 sync; sync_all_data || true
4938 # MDT0 shouldn't get EDQUOT with glimpse.
4939 $RUNAS $DD of=$testfile count=$limit seek=$limit &&
4940 quota_error u $TSTUSR \
4941 "user write success, but expect EDQUOT"
4943 # Now all members of qpool1 should get EDQUOT. Expect success
4944 # when write to DOM on MDT0, as it belongs to global pool.
4945 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 \
4946 oflag=sync || quota_error u $TSTUSR "write failed"
4948 $RUNAS dd if=/dev/zero of="$dom0/f1" bs=1K count=512 seek=512 \
4949 oflag=sync || quota_error u $TSTUSR "write failed"
4951 run_test 69 "EDQUOT at one of pools shouldn't affect DOM"
4955 local qpool="qpool1"
4960 [[ CLIENT_VERSION -lt $(version_code $VERSION_WITH_QP) ]] &&
4961 skip "Needs a client >= $VERSION_WITH_QP"
4963 setup_quota_test || error "setup quota failed with $?"
4965 # MDS returns EFAULT for unsupported quotactl command
4966 [[ $MDS1_VERSION -lt $(version_code $VERSION_WITH_QP) ]] && err=14
4968 # create qpool and add OST0
4969 pool_add $qpool || error "pool_add failed"
4970 pool_add_targets $qpool 0 0 || error "pool_add_targets failed"
4972 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR
4974 [ $rc -eq $err ] || error "setquota res $rc != $err"
4976 # If MDS supports QP, check that limit was set properly.
4977 if [[ $MDS1_VERSION -ge $(version_code $VERSION_WITH_QP) ]]; then
4978 bhard=$(getquota -u $TSTUSR global bhardlimit $qpool)
4979 echo "hard limit $bhard limit $limit"
4980 [ $bhard -ne $((limit*1024)) ] &&
4981 error "bhard:$bhard for $qpool!=$((limit*1024))"
4984 $LFS quota -u $TSTUSR --pool $qpool $DIR
4986 [ $rc -eq $err ] || error "quota res $rc != $err"
4988 run_test 70a "check lfs setquota/quota with a pool option"
4992 local glbl_hard=200 # 200M
4993 local glbl_soft=100 # 100M
4994 local pool_hard=10 # 10M
4995 local qpool="qpool1"
4997 pool_add $qpool || error "pool_add failed"
4998 pool_add_targets $qpool 0 1 || error "pool_add_targets failed"
5000 $LFS setquota -u $TSTUSR -b ${glbl_soft}M -B ${glbl_hard}M $DIR ||
5001 error "set user quota failed"
5002 $LFS setquota -u $TSTUSR -B ${pool_hard}M --pool $qpool $DIR ||
5003 error "set user quota failed"
5005 local tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5006 [ $tmp -eq $((pool_hard * 1024)) ] ||
5007 error "wrong block hard limit $tmp for $qpool"
5008 local tmp=$(getquota -u $TSTUSR global bsoftlimit $qpool)
5009 # soft limit hasn't been set and should be zero
5010 [ $tmp -eq 0 ] || error "wrong soft block limit $tmp for $qpool"
5012 run_test 70b "lfs setquota pool works properly"
5017 local global_limit=100 # MB
5018 local testfile="$DIR/$tdir/$tfile-0"
5019 local qpool="qpool1"
5020 local qpool2="qpool2"
5022 [ "$ost1_FSTYPE" == zfs ] &&
5023 skip "ZFS grants some block space together with inode"
5024 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs"
5026 setup_quota_test || error "setup quota failed with $?"
5029 set_ost_qtype $QTYPE || error "enable ost quota failed"
5032 log "User quota (block hardlimit:$global_limit MB)"
5033 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5034 error "set user quota failed"
5036 pool_add $qpool || error "pool_add failed"
5037 pool_add_targets $qpool 0 1 ||
5038 error "pool_add_targets failed"
5040 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5041 error "set user quota failed"
5043 pool_add $qpool2 || error "pool_add failed"
5044 pool_add_targets $qpool2 1 1 ||
5045 error "pool_add_targets failed"
5047 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool2 $DIR ||
5048 error "set user quota failed"
5050 # make sure the system is clean
5051 local used=$(getquota -u $TSTUSR global curspace)
5054 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5056 # create 1st component 1-10M
5057 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5058 #create 2nd component 10-30M
5059 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5060 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5062 # сheck normal use and out of quota with PFL
5063 # 1st element is in qppol1(OST0), 2nd in qpool2(OST2).
5064 test_1_check_write $testfile "user" $((limit*2))
5066 wait_delete_completed || error "wait_delete_completed failed"
5067 sync_all_data || true
5068 used=$(getquota -u $TSTUSR global curspace)
5069 [ $used -ne 0 ] && quota_error u $TSTUSR \
5070 "user quota isn't released after deletion"
5072 # create 1st component 1-10M
5073 $LFS setstripe -E 10M -S 1M -c 1 -i 0 $testfile
5074 # create 2nd component 10-30M
5075 $LFS setstripe --component-add -E 30M -c 1 -i 1 $testfile
5076 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5078 # write to the 2nd component
5079 $RUNAS $DD of=$testfile count=$limit seek=10 ||
5080 quota_error u $TSTUSR \
5081 "write failure, but expect success"
5082 # this time maybe cache write, ignore it's failure
5083 $RUNAS $DD of=$testfile count=$((2*limit)) seek=10 || true
5084 cancel_lru_locks osc
5085 sync; sync_all_data || true
5086 # write over limit in qpool2(2nd component 10-30M)
5087 $RUNAS $DD of=$testfile count=1 seek=$((10 + 2*limit)) &&
5088 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5089 # write to the 1st component - OST0 is empty
5090 $RUNAS $DD of=$testfile count=$limit seek=0 ||
5091 quota_error u $TSTUSR "write failed"
5093 run_test 71a "Check PFL with quota pools"
5097 local global_limit=1000 # MB
5098 local limit1=160 # MB
5099 local limit2=10 # MB
5100 local testfile="$DIR/$tdir/$tfile-0"
5101 local qpool="qpool1"
5102 local qpool2="qpool2"
5104 [ "$ost1_FSTYPE" == zfs ] &&
5105 skip "ZFS grants some block space together with inode"
5106 [[ $OSTCOUNT -lt 2 ]] && skip "need >= 2 OSTs" && return
5108 setup_quota_test || error "setup quota failed with $?"
5111 set_ost_qtype $QTYPE || error "enable ost quota failed"
5114 log "User quota (block hardlimit:$global_limit MB)"
5115 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5116 error "set user quota failed"
5118 pool_add $qpool || error "pool_add failed"
5119 pool_add_targets $qpool 0 1 ||
5120 error "pool_add_targets failed"
5122 $LFS setquota -u $TSTUSR -B ${limit1}M --pool $qpool $DIR ||
5123 error "set user quota failed"
5125 pool_add $qpool2 || error "pool_add failed"
5126 pool_add_targets $qpool2 1 1 ||
5127 error "pool_add_targets failed"
5129 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5130 error "set user quota failed"
5132 # make sure the system is clean
5133 local used=$(getquota -u $TSTUSR global curspace)
5136 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5138 # First component is on OST0, 2nd on OST1
5139 $LFS setstripe -E 128M -i 0 -z 64M -E -1 -i 1 -z 64M $testfile
5140 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5142 # fill the 1st component on OST0
5143 $RUNAS $DD of=$testfile count=128 ||
5144 quota_error u $TSTUSR "write failed"
5145 # write to the 2nd cmpnt on OST1
5146 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=128 ||
5147 quota_error u $TSTUSR "write failed"
5148 # this time maybe cache write, ignore it's failure
5149 $RUNAS $DD of=$testfile count=$((limit2/2)) seek=$((128 + limit2/2)) ||
5151 cancel_lru_locks osc
5152 sync; sync_all_data || true
5153 # write over limit in qpool2
5154 $RUNAS $DD of=$testfile count=2 seek=$((128 + limit2)) &&
5155 quota_error u $TSTUSR "user write success, but expect EDQUOT"
5158 run_test 71b "Check SEL with quota pools"
5163 local global_limit=50 # MB
5164 local testfile="$DIR/$tdir/$tfile-0"
5165 local qpool="qpool1"
5168 setup_quota_test || error "setup quota failed with $?"
5171 set_ost_qtype $QTYPE || error "enable ost quota failed"
5174 log "User quota (block hardlimit:$global_limit MB)"
5175 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5176 error "set user quota failed"
5178 pool_add $qpool || error "pool_add failed"
5179 pool_add_targets $qpool 1 1 || error "pool_add_targets failed"
5181 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5182 error "set user quota failed"
5184 # make sure the system is clean
5185 local used=$(getquota -u $TSTUSR global curspace)
5187 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR isn't 0."
5189 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5191 $LFS setstripe $testfile -c 1 -i 1 || error "setstripe $testfile failed"
5192 chown $TSTUSR.$TSTUSR $testfile || error "chown $testfile failed"
5193 test_1_check_write $testfile "user" $limit
5194 used=$(getquota -u $TSTUSR global bhardlimit $qpool)
5196 [ $used -ge $limit ] || error "used($used) is less than limit($limit)"
5197 # check that lfs quota -uv --pool prints only OST that
5198 # was added in a pool
5199 lfs quota -v -u $TSTUSR --pool $qpool $DIR | grep -v "OST0001" |
5200 grep "OST\|MDT" && error "$qpool consists wrong targets"
5203 run_test 72 "lfs quota --pool prints only pool's OSTs"
5207 (( $MDS1_VERSION >= $(version_code 2.14.51.158) )) ||
5208 skip "need MDS >= v2_14_51-158-g25a70a88 for default pool quota"
5210 local qpool="qpool1"
5214 pool_add $qpool || error "pool_add failed"
5215 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5216 error "pool_add_targets failed"
5218 test_default_quota "-u" "data" "qpool1"
5220 run_test 73a "default limits at OST Pool Quotas"
5224 (( $MDS1_VERSION >= $(version_code 2.14.52.91) )) ||
5225 skip "need MDS >= v2_14_52-91-g188112fc8 for nested lqe fix"
5227 local TESTFILE1="$DIR/$tdir/$tfile-1"
5229 local qpool="qpool1"
5233 setup_quota_test || error "setup quota failed with $?"
5235 set_ost_qtype $QTYPE || error "enable ost quota failed"
5237 # pool quotas don't work properly without global limit
5238 $LFS setquota -u $TSTUSR -b 0 -B ${limit}M -i 0 -I 0 $DIR ||
5239 error "set global limit failed"
5241 pool_add $qpool || error "pool_add failed"
5242 pool_add_targets $qpool 0 $((OSTCOUNT - 1)) ||
5243 error "pool_add_targets failed"
5245 log "set default quota for $qpool"
5246 $LFS setquota -U --pool $qpool -b ${limit}M -B ${limit}M $DIR ||
5247 error "set default quota failed"
5249 log "Write from user that hasn't lqe"
5250 # Check that it doesn't cause a panic or a deadlock
5251 # due to nested lqe lookups that rewrite 1st lqe in qti_lqes array.
5252 # Have to use RUNAS_ID as resetquota creates lqes in
5253 # the beginning for TSTUSR/TSTUSR2 when sets limits to 0.
5254 runas -u $RUNAS_ID -g $RUNAS_GID $DD of=$TESTFILE1 count=10
5256 cancel_lru_locks osc
5257 sync; sync_all_data || true
5259 run_test 73b "default OST Pool Quotas limit for new user"
5263 (( $MDS1_VERSION >= $(version_code 2.14.52.6) )) ||
5264 skip "need MDS >= v2_14_52-6-g8c19365416 for pool per-user fix"
5266 local global_limit=200 # 200M
5267 local limit=10 # 10M
5268 local limit2=50 # 50M
5269 local qpool="qpool1"
5270 local qpool2="qpool2"
5274 setup_quota_test || error "setup quota failed with $?"
5277 set_ost_qtype $QTYPE || error "enable ost quota failed"
5279 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5280 error "set user quota failed"
5282 pool_add $qpool || error "pool_add failed"
5283 pool_add_targets $qpool 0 1 ||
5284 error "pool_add_targets failed"
5286 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5287 error "set user quota failed"
5289 pool_add $qpool2 || error "pool_add failed"
5290 pool_add_targets $qpool2 1 1 ||
5291 error "pool_add_targets failed"
5293 $LFS setquota -u $TSTUSR -B ${limit2}M --pool $qpool2 $DIR ||
5294 error "set user quota failed"
5296 tmp=$(getquota -u $TSTUSR global bhardlimit)
5297 [ $tmp -eq $((global_limit * 1024)) ] ||
5298 error "wrong global limit $global_limit"
5300 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool)
5301 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit $tmp for $qpool"
5303 tmp=$(getquota -u $TSTUSR global bhardlimit $qpool2)
5304 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit $tmp for $qpool2"
5306 # check limits in pools
5307 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5308 grep -A4 $qpool | awk 'NR == 4{print $4}')
5309 echo "pool limit for $qpool $tmp"
5310 [ $tmp -eq $((limit * 1024)) ] || error "wrong limit:tmp for $qpool"
5311 tmp=$($LFS quota -u $TSTUSR --pool $DIR | \
5312 grep -A4 $qpool2 | awk 'NR == 4{print $4}')
5313 echo "pool limit for $qpool2 $tmp"
5314 [ $tmp -eq $((limit2 * 1024)) ] || error "wrong limit:$tmp for $qpool2"
5316 run_test 74 "check quota pools per user"
5318 function cleanup_quota_test_75()
5320 do_facet mgs $LCTL nodemap_modify --name default \
5321 --property admin --value 1
5322 do_facet mgs $LCTL nodemap_modify --name default \
5323 --property trusted --value 1
5324 do_facet mgs $LCTL nodemap_modify --name default \
5325 --property squash_uid --value 99
5326 do_facet mgs $LCTL nodemap_modify --name default \
5327 --property squash_gid --value 99
5329 wait_nm_sync default admin_nodemap
5330 wait_nm_sync default trusted_nodemap
5332 do_facet mgs $LCTL nodemap_activate 0
5335 resetquota -u $TSTUSR
5339 local dd_failed=false
5340 local LIMIT=20480 #20M
5343 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5344 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5345 conv=fsync || dd_failed=true
5348 $dd_failed && quota_error u $qid "write failed, expect succeed (1)"
5350 for ((i = $((LIMIT/2048-1)); i < $((LIMIT/1024 + 10)); i++)); do
5351 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5352 conv=fsync || dd_failed=true
5355 $dd_failed || quota_error u $qid "write succeed, expect EDQUOT (1)"
5357 rm -f $DIR/$tdir_dom/*
5359 # flush cache, ensure noquota flag is set on client
5361 sync; sync_all_data || true
5365 $DD of=$DIR/$tdir/file count=$((LIMIT/2048-1)) conv=fsync ||
5366 quota_error u $qid "write failed, expect succeed (2)"
5368 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
5369 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5370 conv=fsync || dd_failed=true
5373 $dd_failed || quota_error u $TSTID "write succeed, expect EDQUOT (2)"
5376 rm -f $DIR/$tdir_dom/*
5378 # flush cache, ensure noquota flag is set on client
5380 sync; sync_all_data || true
5384 for ((i = 0; i < $((LIMIT/2048-1)); i++)); do
5385 $DD of=$DIR/$tdir_dom/$tfile-$i count=1 \
5386 conv=fsync || dd_failed=true
5389 $dd_failed && quota_error u $qid "write failed, expect succeed (3)"
5391 $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=direct &&
5392 quota_error u $qid "write succeed, expect EDQUOT (3)"
5398 (( $MDS1_VERSION >= $(version_code 2.14.52.68) )) ||
5399 skip "need MDS >= v2_14_52-68-ga4fbe7341b for squash root fix"
5401 local soft_limit=10 # MB
5402 local hard_limit=20 # MB
5403 local limit=$soft_limit
5404 local testfile="$DIR/$tdir/$tfile-0"
5405 local grace=20 # seconds
5406 local tdir_dom=${tdir}_dom
5408 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
5412 setup_quota_test || error "setup quota failed with $?"
5413 stack_trap cleanup_quota_test_75 EXIT
5416 set_ost_qtype $QTYPE || error "enable ost quota failed"
5417 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
5419 local used=$(getquota -u $TSTID global curspace)
5420 $LFS setquota -t -u --block-grace $grace --inode-grace \
5421 $MAX_IQ_TIME $DIR || error "set user grace time failed"
5422 $LFS setquota -u $TSTUSR -b $((soft_limit+used/1024))M \
5423 -B $((hard_limit+used/1024))M -i 0 -I 0 $DIR ||
5424 error "set user quota failed"
5426 chmod 777 $DIR/$tdir || error "chmod 777 $DIR/$tdir failed"
5427 mkdir $DIR/$tdir_dom
5428 chmod 777 $DIR/$tdir_dom
5429 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
5430 error "setstripe $tdir_dom failed"
5432 do_facet mgs $LCTL nodemap_activate 1
5434 do_facet mgs $LCTL nodemap_modify --name default \
5435 --property admin --value 0
5436 do_facet mgs $LCTL nodemap_modify --name default \
5437 --property trusted --value 0
5438 do_facet mgs $LCTL nodemap_modify --name default \
5439 --property deny_unknown --value 0
5440 do_facet mgs $LCTL nodemap_modify --name default \
5441 --property squash_uid --value $TSTID
5442 do_facet mgs $LCTL nodemap_modify --name default \
5443 --property squash_gid --value $TSTID
5444 cancel_lru_locks mdc
5445 wait_nm_sync default admin_nodemap
5446 wait_nm_sync default trusted_nodemap
5447 wait_nm_sync default squash_uid
5449 # mmap write when over soft limit
5451 $DD of=$testfile count=${limit} || quota_error a $TSTUSR \
5452 "root write failure, but expect success (1)"
5453 OFFSET=$((limit * 1024))
5454 cancel_lru_locks osc
5456 echo "Write to exceed soft limit"
5457 dd if=/dev/zero of=$testfile bs=1K count=10 seek=$OFFSET ||
5458 quota_error a $TSTUSR "root write failure, but expect success (2)"
5459 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
5460 cancel_lru_locks osc
5462 echo "mmap write when over soft limit"
5463 $MULTIOP $testfile.mmap OT40960SMW ||
5464 quota_error a $TSTUSR "mmap write failure, but expect success"
5465 cancel_lru_locks osc
5467 wait_delete_completed || error "wait_delete_completed failed (1)"
5468 sync_all_data || true
5470 # test for user hard limit
5473 $DD of=$testfile count=$((limit/2)) ||
5474 quota_error u $TSTID \
5475 "root write failure, but expect success (3)"
5477 log "Write out of block quota ..."
5478 # possibly a cache write, ignore failure
5479 $DD of=$testfile count=$((limit/2)) seek=$((limit/2)) || true
5480 # flush cache, ensure noquota flag is set on client
5481 cancel_lru_locks osc
5482 sync; sync_all_data || true
5483 # sync forced cache flush, but did not guarantee that slave
5484 # got new edquot through glimpse, so wait to make sure
5486 $DD of=$testfile count=1 seek=$limit conv=fsync &&
5487 quota_error u $TSTID \
5488 "user write success, but expect EDQUOT"
5490 wait_delete_completed || error "wait_delete_completed failed (2)"
5491 sync_all_data || true
5492 [ $(getquota -u $TSTUSR global curspace) -eq $used ] ||
5493 quota_error u $TSTID "user quota not released after deletion"
5497 run_test 75 "nodemap squashed root respects quota enforcement"
5500 (( $MDS1_VERSION >= $(version_code 2.14.52.109) )) ||
5501 skip "need MDS >= v2_14_52-109-g3ffa5d680f for bad PRJID fix"
5502 ! is_project_quota_supported &&
5503 skip "skip project quota unsupported"
5505 setup_quota_test || error "setup quota failed with $?"
5508 local testfile="$DIR/$tdir/$tfile-0"
5511 $LFS project -p 4294967295 $testfile &&
5512 error "set project ID should fail"
5515 run_test 76 "project ID 4294967295 should be not allowed"
5519 (( $MDS1_VERSION >= $(version_code 2.14.54.33) )) ||
5520 skip "need MDS >= v2_14_54-33-g29e00cecc6 for readonly fix"
5522 mount_client $MOUNT2 "ro"
5523 lfs setquota -u $TSTUSR -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
5524 error "lfs setquota should fail in read-only Lustre mount"
5527 run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
5531 (( $OST1_VERSION >= $(version_code 2.14.55.173) )) ||
5532 skip "need OST >= v2_14_55-173-g789038c97a for fallocate fix"
5533 check_set_fallocate_or_skip
5535 setup_quota_test || error "setup quota failed with $?"
5538 set_ost_qtype $QTYPE || error "enable ost quota failed"
5540 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5541 chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
5544 $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
5545 error "lfs setquota failed"
5548 runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
5550 kbytes=$(lfs quota -u $TSTUSR $DIR |
5551 awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
5552 echo "kbytes returned:$kbytes"
5554 # For file size of 204800. We should be having roughly 200 kbytes
5555 # returned. Anything alarmingly low (50 taken as arbitrary value)
5556 # would bail out this TC. Also this also avoids $kbytes of 0
5557 # to be used in calculation below.
5558 (( $kbytes > 50 )) ||
5559 error "fallocate did not use quota. kbytes returned:$kbytes"
5561 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5562 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5564 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5565 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5566 error "fallocate did not use quota correctly"
5568 run_test 78A "Check fallocate increase quota usage"
5572 (( $CLIENT_VERSION >= $(version_code 2.15.0.37) )) ||
5573 skip "need client >= v2_15_50-37-g5fc934eb for falloc proj fix"
5574 (( $OST1_VERSION >= $(version_code 2.15.0.37) )) ||
5575 skip "need OST >= v2_15_50-37-g5fc934ebbb for falloc proj fix"
5576 check_set_fallocate_or_skip
5578 setup_quota_test || error "setup quota failed with $?"
5581 set_ost_qtype $QTYPE || error "enable ost quota failed"
5583 mkdir -p $DIR/$tdir || error "failed to create $tdir"
5585 local projectid=5200 # Random project id to test
5587 change_project -sp $projectid $DIR/$tdir
5590 $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
5591 error "lfs setquota project failed"
5594 fallocate -l 204800 $DIR/$tdir/$tfile
5596 # Get curspace (kbytes) for $projectid
5597 local kbytes=$(getquota -p $projectid global curspace)
5599 echo "kbytes returned:$kbytes"
5601 # For file size of 204800. We should be having roughly 200 kbytes
5602 # returned. Anything alarmingly low (50 taken as arbitrary value)
5603 # would bail out this TC. Also this also avoids $kbytes of 0
5604 # to be used in calculation below.
5605 (( $kbytes > 50 )) ||
5606 error "fallocate did not use projectid. kbytes returned:$kbytes"
5608 local expect_lo=$(($kbytes * 95 / 100)) # 5% below
5609 local expect_hi=$(($kbytes * 105 / 100)) # 5% above
5611 # Verify kbytes is 200 (204800/1024). With a permited 5% drift
5612 (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
5613 error "fallocate did not use quota projectid correctly"
5615 run_test 78a "Check fallocate increase projectid usage"
5619 (( $MDS1_VERSION >= $(version_code 2.14.56.37) )) ||
5620 skip "need MDS >= v2_14_56-37-gc9901b68b4 for pool panic fix"
5622 local qpool="qpool1"
5623 local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
5624 local stopf=$TMP/$tfile
5626 do_facet mds1 "touch $stopf"
5627 stack_trap "do_facet mds1 'rm -f $stopf'"
5628 do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
5630 pool_add $qpool || error "pool_add failed"
5631 do_facet mds1 "rm $stopf"
5634 run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
5638 (( $MDS1_VERSION >= $(version_code 2.14.56.51) )) ||
5639 skip "need MDS >= v2_14_56-51-g61ec1e0f2c for EDQUOT failover"
5641 local dir1="$DIR/$tdir/dir1"
5642 local dir2="$DIR/$tdir/dir2"
5643 local TESTFILE0="$dir1/$tfile-0"
5644 local TESTFILE1="$dir1/$tfile-1"
5645 local TESTFILE2="$dir1/$tfile-2"
5646 local TESTFILE3="$dir2/$tfile-0"
5647 local global_limit=100 # 100M
5648 local limit=10 # 10M
5649 local qpool="qpool1"
5651 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
5653 [ "$ost1_FSTYPE" == zfs ] &&
5654 skip "ZFS grants some block space together with inode"
5655 setup_quota_test || error "setup quota failed with $?"
5656 set_ost_qtype $QTYPE || error "enable ost quota failed"
5658 # make sure the system is clean
5659 local used=$(getquota -u $TSTUSR global curspace)
5660 [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
5662 pool_add $qpool || error "pool_add failed"
5663 pool_add_targets $qpool 0 1 ||
5664 error "pool_add_targets failed"
5666 $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
5667 error "set user quota failed"
5669 $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
5670 error "set user quota failed"
5671 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5672 error "set user quota failed"
5674 mkdir -p $dir1 || error "failed to mkdir"
5675 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5676 mkdir -p $dir2 || error "failed to mkdir"
5677 chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
5679 $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
5680 $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
5685 $LFS quota -uv $TSTUSR $DIR
5686 #define OBD_FAIL_QUOTA_PREACQ 0xA06
5687 do_facet mds1 $LCTL set_param fail_loc=0xa06
5688 $RUNAS $DD of=$TESTFILE3 count=3 ||
5689 quota_error u $TSTUSR "write failed"
5690 $RUNAS $DD of=$TESTFILE2 count=7 ||
5691 quota_error u $TSTUSR "write failed"
5692 $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
5693 quota_error u $TSTUSR "write failed"
5696 $LFS quota -uv --pool $qpool $TSTUSR $DIR
5700 do_facet mds1 $LCTL set_param fail_loc=0
5701 start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
5702 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5703 # OST0 needs some time to update quota usage after removing TESTFILE2
5705 $LFS quota -uv $TSTUSR --pool $qpool $DIR
5706 $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
5707 quota_error u $TSTUSR "write failure, but expect success"
5709 run_test 80 "check for EDQUOT after OST failover"
5713 (( $MDS1_VERSION >= $(version_code 2.14.56.52) )) ||
5714 skip "need MDS >= v2_14_56-52-g862f0baa7c for qmt_pool_free fix"
5716 local global_limit=20 # 100M
5717 local testfile="$DIR/$tdir/$tfile-0"
5718 local qpool="qpool1"
5721 setup_quota_test || error "setup quota failed with $?"
5724 set_ost_qtype $QTYPE || error "enable ost quota failed"
5727 log "User quota (block hardlimit:$global_limit MB)"
5728 $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
5730 pool_add $qpool || error "pool_add failed"
5731 #define OBD_FAIL_QUOTA_RECALC 0xA07
5732 do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
5733 # added OST casues to start pool recalculation
5734 pool_add_targets $qpool 0 0 1
5735 stop mds1 -f || error "MDS umount failed"
5737 #start mds1 back to destroy created pool
5738 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
5741 run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
5745 (( $MDS1_VERSION >= $(version_code 2.15.50.72) )) ||
5746 skip "need MDS >= v2_15_50-72-g61481796ac for over 8 QIDs fix"
5748 is_project_quota_supported || skip "skip project quota unsupported"
5750 setup_quota_test || error "setup quota failed with $?"
5753 local parent_dir="$DIR/$tdir.parent"
5754 local child_dir="$parent_dir/child"
5757 stack_trap "chown -R 0:0 $parent_dir"
5759 chown $TSTUSR:$TSTUSR $parent_dir ||
5760 error "failed to chown on $parent_dir"
5761 chown $TSTUSR2:$TSTUSRS2 $child_dir ||
5762 error "failed to chown on $parent_dir"
5764 $LFS project -p 1000 $parent_dir ||
5765 error "failed to set project id on $parent_dir"
5766 $LFS project -p 1001 $child_dir ||
5767 error "failed to set project id on $child_dir"
5769 rmdir $child_dir || error "cannot remove child dir, test failed"
5771 run_test 82 "verify more than 8 qids for single operation"
5773 test_grace_with_default_quota()
5782 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
5783 error "clear default quota [$qdtype] failed"
5785 $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR ||
5786 error "reset quota [$qdtype] grace failed"
5789 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5790 '{printf("bgrace=%s;igrace=%s;", $4, $9)}')
5793 $LFS setquota $qdtype -B 10G -i 10k $DIR
5796 eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \
5797 '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}')
5799 [ "$bgrace" == "$bgrace2" ] ||
5800 error "set default quota shouldn't affect block grace"
5801 [ "$igrace" == "$igrace2" ] ||
5802 error "set default quota shouldn't affect inode grace"
5808 (( $MDS1_VERSION >= $(version_code 2.15.51.29) )) ||
5809 skip "need MDS >= v2_15_51-29-gd4978678b4 for grace time fix"
5811 setup_quota_test || error "setup quota failed with $?"
5812 test_grace_with_default_quota "-u" "-U"
5813 test_grace_with_default_quota "-g" "-G"
5815 is_project_quota_supported || return 0
5816 test_grace_with_default_quota "-p" "-P"
5818 run_test 83 "Setting default quota shouldn't affect grace time"
5822 (( $MDS1_VERSION >= $(version_code 2.15.53.115) )) ||
5823 skip "need MDS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5824 (( $OST1_VERSION >= $(version_code 2.15.53.115) )) ||
5825 skip "need OSS >= v2_15_53-115-ga2fd4d3aee for insane quota fix"
5827 local dir1="$DIR/$tdir/dir1"
5828 local TESTFILE1="$dir1/$tfile-1"
5836 setup_quota_test || error "setup quota failed with $?"
5838 set_ost_qtype $QTYPE || error "enable ost quota failed"
5840 pool_add $qp || error "pool_add failed"
5841 pool_add_targets $qp 0 $(($OSTCOUNT - 1)) ||
5842 error "pool_add_targets failed"
5844 $LFS setquota -g $TSTUSR -B 10G $DIR ||
5845 error "failed to set group quota for $TSTUSR"
5846 $LFS setquota -g $TSTUSR -B 5G --pool $qp $DIR ||
5847 error "set user quota failed"
5848 $LFS quota -gv $TSTUSR $DIR
5850 wait_quota_setting_synced "grp" $TSTID "hardlimit" $((10*1024*1024))
5852 mkdir -p $dir1 || error "failed to mkdir"
5853 chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
5855 $LFS setstripe -c 1 -i 0 $TESTFILE1
5856 $LFS getstripe $TESTFILE1
5857 chown $TSTUSR.$TSTUSR $TESTFILE1
5859 $RUNAS $DD of=$TESTFILE1 count=60 conv=nocreat oflag=direct ||
5860 quota_error g $TSTUSR "write failed"
5862 sync_all_data || true
5864 $LFS quota -gv $TSTUSR $DIR
5865 $LFS quota -gv --pool $qp $TSTUSR $DIR
5867 # the grant quota should be larger than 0
5869 while (( $waited < 60 )); do
5870 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5871 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5872 (( ${grant} > 0 && ${grant2} > 0 )) && break
5874 do_facet ost1 $LCTL set_param \
5875 osd-*.*-OST0000.quota_slave.force_reint=1
5877 waited=$((waited + 1))
5880 (( $waited >= 60)) && {
5881 $LFS quota -gv $TSTUSR $DIR
5882 $LFS quota -gv --pool $qp $TSTUSR $DIR
5885 (( ${grant} > 0 )) || error "pool grant is not increased after dd"
5886 (( ${grant2} > 0 )) || error "grant is not increased after dd"
5888 #define OBD_FAIL_QUOTA_GRANT 0xA08
5889 lustre_fail mds 0xa08
5890 lustre_fail ost 0xa08
5893 # clear quota limits to trigger updating grant quota
5894 $LFS setquota -g $TSTUSR -b 0 -B 0 $DIR ||
5895 error "failed to clear the group quota for $TSTUSR"
5896 $LFS quota -gv $TSTUSR $DIR
5897 $LFS quota -gv --pool $qp $TSTUSR $DIR
5899 # the grant quota should be set as insane value
5901 while (( $waited < 60 )); do
5902 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5903 grant2=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5904 (( ${#grant} == 20 && ${#grant2} == 20 )) && break
5907 waited=$((waited + 1))
5910 (( $waited >= 60)) && {
5911 $LFS quota -gv $TSTUSR $DIR
5912 $LFS quota -gv --pool $qp $TSTUSR $DIR
5915 (( ${#grant} == 20 )) || error "pool grant is not set as insane value"
5916 (( ${#grant2} == 20 )) || error "grant is not set as insane value"
5918 lustre_fail mds_ost 0
5922 $LFS setquota -g $TSTUSR -r $DIR ||
5923 error "failed to reset group quota for $TSTUSR"
5926 $LFS quota -gv $TSTUSR $DIR
5927 $LFS quota -gv --pool $qp $TSTUSR $DIR
5929 # the grant quota should be reset
5930 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit)
5931 (( ${#grant} == 20 )) && error "grant is not cleared"
5932 grant=$(getquota -g $TSTUSR lustre-OST0000_UUID bhardlimit $qp)
5933 (( ${#grant} == 20 )) && error "pool grant is not cleared"
5935 $LFS quota -gv $TSTUSR --pool $qp $DIR
5936 $LFS quota -gv --pool $qp $TSTUSR $DIR
5937 local hlimit=$(getquota -g $TSTUSR global bhardlimit $qp)
5938 [ $hlimit -eq 5242880 ] || error "pool limit is changed"
5940 # test whether the quota still works
5941 $LFS setquota -g $TSTUSR -B 100M $DIR ||
5942 error "failed to set group quota for $TSTUSR"
5943 $LFS quota -gv $TSTUSR $DIR
5945 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct &&
5946 quota_error g $TSTUSR "dd succeed, expect EDQUOT"
5948 $LFS setquota -g $TSTUSR -B 300M $DIR ||
5949 error "failed to set group quota for $TSTUSR"
5950 $LFS quota -gv $TSTUSR $DIR
5952 $RUNAS $DD of=$TESTFILE1 count=200 conv=nocreat oflag=direct ||
5953 quota_error g $TSTUSR "dd failed, expect succeed"
5955 run_test 84 "Reset quota should fix the insane granted quota"
5959 (( $MDS1_VERSION >= $(version_code 2.15.55.5) )) ||
5960 skip "need MDS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
5961 (( $OST1_VERSION >= $(version_code 2.15.55.5) )) ||
5962 skip "need OSS >= v2_15_55-5-g6c0b4329d0 for least_qunit fix"
5965 local qpool="qpool1"
5966 local qpool2="qpool2"
5967 local tfile1="$DIR/$tdir/$tfile-0"
5969 (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
5971 setup_quota_test || error "setup quota failed with $?"
5974 set_ost_qtype $QTYPE || error "enable ost quota failed"
5976 $LFS setquota -u $TSTUSR -b 0 -B 50T -i 0 -I 0 $DIR ||
5977 error "set user quota failed"
5979 pool_add $qpool || error "pool_add failed"
5980 pool_add_targets $qpool 0 1 ||
5981 error "pool_add_targets failed"
5983 pool_add $qpool2 || error "pool_add failed"
5984 pool_add_targets $qpool2 0 1 ||
5985 error "pool_add_targets failed"
5987 $LFS setstripe -p $qpool $DIR/$tdir || error "cannot set stripe"
5988 $LFS setquota -u $TSTUSR -B 30M --pool $qpool $DIR ||
5989 error "set user quota failed"
5990 $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
5991 error "set user quota failed"
5993 # don't care about returned value. Just check we don't hung on write.
5994 $RUNAS $DD of=$tfile1 count=10
5997 run_test 85 "do not hung at write with the least_qunit"
6001 do_nodes $(comma_list $(nodes_list)) \
6002 "lctl set_param -n debug=-quota-trace"
6003 if $PQ_CLEANUP; then
6004 disable_project_quota
6007 reset_quota_settings
6011 complete_test $SECONDS
6012 check_and_cleanup_lustre
6013 export QUOTA_AUTO=$QUOTA_AUTO_OLD