3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
38 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
40 require_dsh_mds || exit 0
41 require_dsh_ost || exit 0
43 # Does e2fsprogs support quota feature?
44 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
45 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
46 grep -q 'quota'"; then
47 skip_env "e2fsprogs doesn't support quota" && exit 0
50 # Test duration: 30 min
51 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
53 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
54 # bug number for skipped test: LU-2836 LU-6836 LU-2836
55 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6"
58 # Test duration: 21 9 min"
59 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
75 is_project_quota_supported() {
76 $ENABLE_PROJECT_QUOTAS || return 1
77 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
78 [ $(lustre_version_code $SINGLEMDS) -gt \
79 $(version_code 2.9.55) ] &&
80 lfs --help | grep project >&/dev/null &&
81 egrep -q "7." /etc/redhat-release && return 0
83 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
84 [ $(lustre_version_code $SINGLEMDS) -le \
85 $(version_code 2.10.53) ] && return 1
87 $ZPOOL upgrade -v | grep project_quota && return 0
93 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
94 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
95 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
96 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
97 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
98 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
99 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
100 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
107 local fail_val=${3:-0}
111 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
112 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
113 ost) NODES="$(comma_list $(osts_nodes))";;
116 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
121 echo "lfs project $*"
122 lfs project $* || error "lfs project $* failed"
125 RUNAS="runas -u $TSTID -g $TSTID"
126 RUNAS2="runas -u $TSTID2 -g $TSTID2"
127 DD="dd if=/dev/zero bs=1M"
131 # clear quota limits for a user or a group
132 # usage: resetquota -u username
133 # resetquota -g groupname
134 # resetquota -p projid
137 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
138 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
139 error "resetquota: wrong specifier $1 passed"
141 if [ $1 == "-p" ]; then
142 is_project_quota_supported || return 0
145 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
146 error "clear quota for [type:$1 name:$2] failed"
147 # give a chance to slave to release space
155 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
156 $LFS quota -v -u $local_id $DIR
157 log "Files for user ($local_id):"
158 ($LFS find --user $local_id $DIR | head -n 4 |
159 xargs stat 2>/dev/null)
162 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
163 $LFS quota -v -g $local_id $DIR
164 log "Files for group ($local_id):"
165 ($LFS find --group $local_id $DIR | head -n 4 |
166 xargs stat 2>/dev/null)
169 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
170 $LFS quota -v -p $TSTPRJID $DIR
171 log "Files for project ($TSTPRJID):"
172 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
173 xargs stat 2>/dev/null)
189 # get quota for a user or a group
190 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
191 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
196 sync_all_data > /dev/null 2>&1 || true
198 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
199 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
200 error "getquota: wrong u/g/p specifier $1 passed"
213 *) error "unknown quota parameter $4";;
216 [ "$uuid" = "global" ] && uuid=$DIR
218 $LFS quota -v "$1" "$2" $DIR |
219 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
220 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
225 # usage: set_mdt_qtype ugp|u|g|p|none
229 local mdts=$(get_facets MDS)
231 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
232 qtype=$(tr -d 'p' <<<$qtype)
234 if [[ $PERM_CMD = *"set_param -P"* ]]; then
235 do_facet mgs $PERM_CMD \
236 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
238 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
240 # we have to make sure each MDT received config changes
241 for mdt in ${mdts//,/ }; do
243 cmd="$LCTL get_param -n "
244 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
245 cmd=${cmd}.quota_slave.enabled
247 if $(facet_up $mdt); then
248 wait_update_facet $mdt "$cmd" "$qtype" || return 1
255 # usage: set_ost_qtype ugp|u|g|p|none
259 local osts=$(get_facets OST)
261 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
262 qtype=$(tr -d 'p' <<<$qtype)
264 if [[ $PERM_CMD = *"set_param -P"* ]]; then
265 do_facet mgs $PERM_CMD \
266 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
268 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
270 # we have to make sure each OST received config changes
271 for ost in ${osts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
275 cmd=${cmd}.quota_slave.enabled
277 if $(facet_up $ost); then
278 wait_update_facet $ost "$cmd" "$qtype" || return 1
284 wait_reintegration() {
288 local result="glb[1],slv[1],reint[0]"
293 if [ $ntype == "mdt" ]; then
294 tgts=$(get_facets MDS)
296 tgts=$(get_facets OST)
299 for tgt in ${tgts//,/ }; do
301 cmd="$LCTL get_param -n "
302 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
303 cmd=${cmd}.quota_slave.info
305 if $(facet_up $tgt); then
306 wait_update_facet $tgt "$cmd |
307 grep "$qtype" | awk '{ print \\\$3 }'" \
308 "$result" $max || return 1
318 if [[ "$qtype" =~ "u" ]]; then
319 wait_reintegration "mdt" "user" $max || return 1
322 if [[ "$qtype" =~ "g" ]]; then
323 wait_reintegration "mdt" "group" $max || return 1
326 if [[ "$qtype" =~ "p" ]]; then
327 ! is_project_quota_supported && return 0
328 wait_reintegration "mdt" "project" $max || return 1
337 if [[ "$qtype" =~ "u" ]]; then
338 wait_reintegration "ost" "user" $max || return 1
341 if [[ "$qtype" =~ "g" ]]; then
342 wait_reintegration "ost" "group" $max || return 1
345 if [[ "$qtype" =~ "p" ]]; then
346 ! is_project_quota_supported && return 0
347 wait_reintegration "ost" "project" $max || return 1
352 disable_project_quota() {
353 is_project_quota_supported || return 0
354 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
355 stopall || error "failed to stopall (1)"
357 for num in $(seq $MDSCOUNT); do
358 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
359 error "tune2fs $(mdsdevname $num) failed"
362 for num in $(seq $OSTCOUNT); do
363 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
364 error "tune2fs $(ostdevname $num) failed"
372 wait_delete_completed
373 echo "Creating test directory"
374 mkdir $DIR/$tdir || return 1
375 chmod 0777 $DIR/$tdir || return 2
376 # always clear fail_loc in case of fail_loc isn't cleared
377 # properly when previous test failed
378 lustre_fail mds_ost 0
381 cleanup_quota_test() {
383 echo "Delete files..."
385 echo "Wait for unlink objects finished..."
386 wait_delete_completed
387 sync_all_data || true
396 $LFS quota -v -$ugp $qid $DIR
398 if [ "$bf" == "a" -o "$bf" == "b" ]; then
399 usage=$(getquota -$ugp $qid global curspace)
400 if [ -z $usage ]; then
401 quota_error $ugp $qid \
402 "Query block quota failed ($ugp:$qid)."
404 [ $usage -ne 0 ] && quota_log $ugp $qid \
405 "Block quota isn't 0 ($ugp:$qid:$usage)."
409 if [ "$bf" == "a" -o "$bf" == "f" ]; then
410 usage=$(getquota -$ugp $qid global curinodes)
411 if [ -z $usage ]; then
412 quota_error $ugp $qid \
413 "Query file quota failed ($ugp:$qid)."
415 [ $usage -ne 0 ] && quota_log $ugp $qid \
416 "File quota isn't 0 ($ugp:$qid:$usage)."
421 enable_project_quota() {
422 is_project_quota_supported || return 0
423 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
424 stopall || error "failed to stopall (1)"
426 for num in $(seq $MDSCOUNT); do
427 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
428 error "tune2fs $(mdsdevname $num) failed"
431 for num in $(seq $OSTCOUNT); do
432 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
433 error "tune2fs $(ostdevname $num) failed"
441 reset_quota_settings() {
442 resetquota -u $TSTUSR
443 resetquota -g $TSTUSR
444 resetquota -u $TSTUSR2
445 resetquota -g $TSTUSR2
446 resetquota -p $TSTPRJID
451 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
456 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
457 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
458 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
459 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
461 test_quota_performance() {
462 local TESTFILE="$DIR/$tdir/$tfile-0"
463 local size=$1 # in MB
464 local stime=$(date +%s)
465 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
466 quota_error u $TSTUSR "write failure"
467 local etime=$(date +%s)
468 delta=$((etime - stime))
469 if [ $delta -gt 0 ]; then
470 rate=$((size * 1024 / delta))
471 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
472 # LU-2872 - see LU-2887 for fix
474 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
476 [ $rate -gt 1024 ] ||
477 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
483 # test basic quota performance b=21696
486 [ "$SLOW" = "no" ] && MB=10
488 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
489 [ $free_space -le $((MB * 1024)) ] &&
490 skip "not enough space ${free_space} KB, " \
491 "required $((MB * 1024)) KB" && return
492 setup_quota_test || error "setup quota failed with $?"
493 trap cleanup_quota_test EXIT
495 set_ost_qtype "none" || error "disable ost quota failed"
496 test_quota_performance $MB
498 set_ost_qtype $QTYPE || error "enable ost quota failed"
499 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
500 error "set quota failed"
501 test_quota_performance $MB
504 resetquota -u $TSTUSR
506 run_test 0 "Test basic quota performance"
508 # test block hardlimit
511 local TESTFILE="$DIR/$tdir/$tfile-0"
513 setup_quota_test || error "setup quota failed with $?"
514 trap cleanup_quota_test EXIT
517 set_ost_qtype $QTYPE || error "enable ost quota failed"
520 log "User quota (block hardlimit:$LIMIT MB)"
521 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
522 error "set user quota failed"
524 # make sure the system is clean
525 local USED=$(getquota -u $TSTUSR global curspace)
526 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
528 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
529 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
532 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
533 quota_error u $TSTUSR "user write failure, but expect success"
534 log "Write out of block quota ..."
535 # this time maybe cache write, ignore it's failure
536 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
537 # flush cache, ensure noquota flag is set on client
539 sync; sync_all_data || true
540 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
541 quota_error u $TSTUSR "user write success, but expect EDQUOT"
544 wait_delete_completed || error "wait_delete_completed failed"
545 sync_all_data || true
546 USED=$(getquota -u $TSTUSR global curspace)
547 [ $USED -ne 0 ] && quota_error u $TSTUSR \
548 "user quota isn't released after deletion"
549 resetquota -u $TSTUSR
552 log "--------------------------------------"
553 log "Group quota (block hardlimit:$LIMIT MB)"
554 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
555 error "set group quota failed"
557 TESTFILE="$DIR/$tdir/$tfile-1"
558 # make sure the system is clean
559 USED=$(getquota -g $TSTUSR global curspace)
560 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
562 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
563 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
566 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
567 quota_error g $TSTUSR "Group write failure, but expect success"
568 log "Write out of block quota ..."
569 # this time maybe cache write, ignore it's failure
570 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
572 sync; sync_all_data || true
573 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
574 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
576 wait_delete_completed || error "wait_delete_completed failed"
577 sync_all_data || true
578 USED=$(getquota -g $TSTUSR global curspace)
579 [ $USED -ne 0 ] && quota_error g $TSTUSR \
580 "Group quota isn't released after deletion"
581 resetquota -g $TSTUSR
583 if ! is_project_quota_supported; then
584 echo "Project quota is not supported"
589 TESTFILE="$DIR/$tdir/$tfile-2"
590 # make sure the system is clean
591 USED=$(getquota -p $TSTPRJID global curspace)
593 error "used space($USED) for project $TSTPRJID isn't 0"
596 log "--------------------------------------"
597 log "Project quota (block hardlimit:$LIMIT mb)"
598 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
599 error "set project quota failed"
601 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
602 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
603 change_project -p $TSTPRJID $TESTFILE
606 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
607 "project write failure, but expect success"
608 log "write out of block quota ..."
609 # this time maybe cache write, ignore it's failure
610 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
612 sync; sync_all_data || true
613 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
614 $TSTPRJID "project write success, but expect EDQUOT"
619 USED=$(getquota -p $TSTPRJID global curspace)
620 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
621 "project quota isn't released after deletion"
623 resetquota -p $TSTPRJID
625 run_test 1 "Block hard limit (normal use and out of quota)"
627 # test inode hardlimit
629 local LIMIT=$((1024 * 1024)) # 1M inodes
630 local TESTFILE="$DIR/$tdir/$tfile-0"
632 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
634 local FREE_INODES=$(mdt_free_inodes 0)
635 echo "$FREE_INODES free inodes on master MDT"
636 [ $FREE_INODES -lt $LIMIT ] &&
637 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
640 setup_quota_test || error "setup quota failed with $?"
641 trap cleanup_quota_test EXIT
644 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
647 log "User quota (inode hardlimit:$LIMIT files)"
648 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
649 error "set user quota failed"
651 # make sure the system is clean
652 local USED=$(getquota -u $TSTUSR global curinodes)
653 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
655 log "Create $LIMIT files ..."
656 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
657 quota_error u $TSTUSR "user create failure, but expect success"
658 log "Create out of file quota ..."
659 $RUNAS touch ${TESTFILE}_xxx &&
660 quota_error u $TSTUSR "user create success, but expect EDQUOT"
663 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
664 rm -f ${TESTFILE}_xxx
665 wait_delete_completed
667 USED=$(getquota -u $TSTUSR global curinodes)
668 [ $USED -ne 0 ] && quota_error u $TSTUSR \
669 "user quota isn't released after deletion"
670 resetquota -u $TSTUSR
673 log "--------------------------------------"
674 log "Group quota (inode hardlimit:$LIMIT files)"
675 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
676 error "set group quota failed"
678 TESTFILE=$DIR/$tdir/$tfile-1
679 # make sure the system is clean
680 USED=$(getquota -g $TSTUSR global curinodes)
681 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
683 log "Create $LIMIT files ..."
684 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
685 quota_error g $TSTUSR "group create failure, but expect success"
686 log "Create out of file quota ..."
687 $RUNAS touch ${TESTFILE}_xxx &&
688 quota_error g $TSTUSR "group create success, but expect EDQUOT"
691 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
692 rm -f ${TESTFILE}_xxx
693 wait_delete_completed
695 USED=$(getquota -g $TSTUSR global curinodes)
696 [ $USED -ne 0 ] && quota_error g $TSTUSR \
697 "user quota isn't released after deletion"
699 resetquota -g $TSTUSR
700 ! is_project_quota_supported && cleanup_quota_test &&
701 echo "Skip project quota is not supported" && return 0
704 log "--------------------------------------"
705 log "Project quota (inode hardlimit:$LIMIT files)"
706 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
707 error "set project quota failed"
709 TESTFILE=$DIR/$tdir/$tfile-1
710 # make sure the system is clean
711 USED=$(getquota -p $TSTPRJID global curinodes)
713 error "Used inodes($USED) for project $TSTPRJID isn't 0"
715 change_project -sp $TSTPRJID $DIR/$tdir
716 log "Create $LIMIT files ..."
717 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
718 $TSTPRJID "project create fail, but expect success"
719 log "Create out of file quota ..."
720 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
721 "project create success, but expect EDQUOT"
722 change_project -C $DIR/$tdir
725 USED=$(getquota -p $TSTPRJID global curinodes)
726 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
727 "project quota isn't released after deletion"
729 resetquota -p $TSTPRJID
732 run_test 2 "File hard limit (normal use and out of quota)"
736 local TIMER=$(($2 * 3 / 2))
742 trap cleanup_quota_test EXIT
744 $SETSTRIPE $TESTFILE -c 1 -i 0
745 chown $TSTUSR.$TSTUSR $TESTFILE
746 [ "$qtype" == "p" ] && is_project_quota_supported &&
747 change_project -p $TSTPRJID $TESTFILE
749 echo "Write up to soft limit"
750 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
751 quota_error a $TSTUSR "write failure, but expect success"
752 OFFSET=$((LIMIT * 1024))
755 echo "Write to exceed soft limit"
756 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
757 quota_error a $TSTUSR "write failure, but expect success"
758 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
764 $SHOW_QUOTA_INFO_USER
765 $SHOW_QUOTA_INFO_GROUP
766 $SHOW_QUOTA_INFO_PROJID
768 echo "Write before timer goes off"
769 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
770 quota_error a $TSTUSR "write failure, but expect success"
771 OFFSET=$((OFFSET + 1024))
774 echo "Sleep $TIMER seconds ..."
780 $SHOW_QUOTA_INFO_USER
781 $SHOW_QUOTA_INFO_GROUP
782 $SHOW_QUOTA_INFO_PROJID
784 echo "Write after timer goes off"
785 # maybe cache write, ignore.
786 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
787 OFFSET=$((OFFSET + 1024))
789 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
790 quota_error a $TSTUSR "write success, but expect EDQUOT"
795 $SHOW_QUOTA_INFO_USER
796 $SHOW_QUOTA_INFO_GROUP
797 $SHOW_QUOTA_INFO_PROJID
799 echo "Unlink file to stop timer"
801 wait_delete_completed
802 sync_all_data || true
807 $SHOW_QUOTA_INFO_USER
808 $SHOW_QUOTA_INFO_GROUP
809 $SHOW_QUOTA_INFO_PROJID
811 $SETSTRIPE $TESTFILE -c 1 -i 0
812 chown $TSTUSR.$TSTUSR $TESTFILE
813 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
816 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
817 quota_error a $TSTUSR "write failure, but expect success"
826 local TESTFILE=$DIR/$tdir/$tfile-0
828 set_ost_qtype $QTYPE || error "enable ost quota failed"
830 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
831 # make sure the system is clean
832 local USED=$(getquota -u $TSTUSR global curspace)
833 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
835 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
836 $MAX_IQ_TIME $DIR || error "set user grace time failed"
837 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
838 error "set user quota failed"
840 test_block_soft $TESTFILE $GRACE $LIMIT "u"
841 resetquota -u $TSTUSR
843 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
844 TESTFILE=$DIR/$tdir/$tfile-1
845 # make sure the system is clean
846 USED=$(getquota -g $TSTUSR global curspace)
847 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
849 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
850 $MAX_IQ_TIME $DIR || error "set group grace time failed"
851 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
852 error "set group quota failed"
854 test_block_soft $TESTFILE $GRACE $LIMIT "g"
855 resetquota -g $TSTUSR
857 if is_project_quota_supported; then
858 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
859 TESTFILE=$DIR/$tdir/$tfile-2
860 # make sure the system is clean
861 USED=$(getquota -p $TSTPRJID global curspace)
862 [ $USED -ne 0 ] && error \
863 "Used space($USED) for project $TSTPRJID isn't 0."
865 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
867 error "set project grace time failed"
868 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
869 $DIR || error "set project quota failed"
871 test_block_soft $TESTFILE $GRACE $LIMIT "p"
872 resetquota -p $TSTPRJID
873 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
875 error "restore project grace time failed"
879 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
880 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
881 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
882 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
884 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
890 local TIMER=$(($grace * 3 / 2))
893 trap cleanup_quota_test EXIT
894 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
896 echo "Create files to exceed soft limit"
897 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
898 quota_error a $TSTUSR "create failure, but expect success"
899 local trigger_time=$(date +%s)
901 sync_all_data || true
903 local cur_time=$(date +%s)
904 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
905 error "Passed grace time $grace, $trigger_time, $cur_time"
907 echo "Create file before timer goes off"
908 $RUNAS touch ${TESTFILE}_before ||
909 quota_error a $TSTUSR "failed create before timer expired," \
910 "but expect success. $trigger_time, $cur_time"
911 sync_all_data || true
913 echo "Sleep $TIMER seconds ..."
919 $SHOW_QUOTA_INFO_USER
920 $SHOW_QUOTA_INFO_GROUP
921 $SHOW_QUOTA_INFO_PROJID
923 echo "Create file after timer goes off"
924 # There is a window that space is accounted in the quota usage but
925 # hasn't been decreased from the pending write, if we acquire quota
926 # in this window, we'll acquire more than we needed.
927 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
928 sync_all_data || true
929 $RUNAS touch ${TESTFILE}_after_3 &&
930 quota_error a $TSTUSR "create after timer expired," \
932 sync_all_data || true
937 $SHOW_QUOTA_INFO_USER
938 $SHOW_QUOTA_INFO_GROUP
939 $SHOW_QUOTA_INFO_PROJID
941 echo "Unlink files to stop timer"
942 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
943 wait_delete_completed
946 $RUNAS touch ${TESTFILE}_xxx ||
947 quota_error a $TSTUSR "touch after timer stop failure," \
949 sync_all_data || true
957 local LIMIT=10 # inodes
958 local TESTFILE=$DIR/$tdir/$tfile-0
961 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
963 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
964 # make sure the system is clean
965 local USED=$(getquota -u $TSTUSR global curinodes)
966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
968 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
969 $GRACE $DIR || error "set user grace time failed"
970 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
971 error "set user quota failed"
973 test_file_soft $TESTFILE $LIMIT $GRACE
974 resetquota -u $TSTUSR
976 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
977 # make sure the system is clean
978 USED=$(getquota -g $TSTUSR global curinodes)
979 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
981 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
982 $GRACE $DIR || error "set group grace time failed"
983 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
984 error "set group quota failed"
985 TESTFILE=$DIR/$tdir/$tfile-1
987 test_file_soft $TESTFILE $LIMIT $GRACE
988 resetquota -g $TSTUSR
990 if is_project_quota_supported; then
991 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
992 # make sure the system is clean
993 USED=$(getquota -p $TSTPRJID global curinodes)
994 [ $USED -ne 0 ] && error \
995 "Used space($USED) for project $TSTPRJID isn't 0."
997 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
998 $GRACE $DIR || error "set project grace time failed"
999 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1000 error "set project quota failed"
1002 TESTFILE=$DIR/$tdir/$tfile-1
1003 # one less than limit, because of parent directory included.
1004 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1005 resetquota -p $TSTPRJID
1006 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1007 $MAX_IQ_TIME $DIR ||
1008 error "restore project grace time failed"
1012 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1013 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1014 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1015 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1017 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1020 local GR_STR1="1w3d"
1021 local GR_STR2="1000s"
1023 local GR_STR4="1w2d3h4m5s"
1025 local GR_STR6="18446744073709551615"
1028 wait_delete_completed
1030 # test of valid grace strings handling
1031 echo "Valid grace strings test"
1032 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1033 $GR_STR2 $DIR || error "set user grace time failed"
1034 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1035 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1036 $GR_STR4 $DIR || error "set group grace time quota failed"
1037 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1039 # test of invalid grace strings handling
1040 echo " Invalid grace strings test"
1041 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1042 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1043 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1047 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1048 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1049 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1050 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1052 run_test 4b "Grace time strings handling"
1054 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1056 local BLIMIT=10 # 10M
1057 local ILIMIT=10 # 10 inodes
1059 setup_quota_test || error "setup quota failed with $?"
1060 trap cleanup_quota_test EXIT
1062 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1063 set_ost_qtype $QTYPE || error "enable ost quota failed"
1065 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1066 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1067 error "set user quota failed"
1068 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1069 if is_project_quota_supported; then
1070 error "set group quota failed"
1071 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1072 -I $ILIMIT $DIR || error "set project quota failed"
1075 # make sure the system is clean
1076 local USED=$(getquota -u $TSTUSR global curinodes)
1077 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1078 USED=$(getquota -g $TSTUSR global curinodes)
1079 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1080 USED=$(getquota -u $TSTUSR global curspace)
1081 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1082 USED=$(getquota -g $TSTUSR global curspace)
1083 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1084 if is_project_quota_supported; then
1085 USED=$(getquota -p $TSTPRJID global curinodes)
1087 error "Used inode($USED) for project $TSTPRJID isn't 0."
1088 USED=$(getquota -p $TSTPRJID global curspace)
1090 error "Used block($USED) for project $TSTPRJID isn't 0."
1093 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1094 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1095 error "create failure, expect success"
1096 if is_project_quota_supported; then
1097 touch $DIR/$tdir/$tfile-0_1
1098 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1100 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1101 error "write failure, expect success"
1103 echo "Chown files to $TSTUSR.$TSTUSR ..."
1104 for i in $(seq 0 $ILIMIT); do
1105 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1106 quota_error a $TSTUSR "chown failure, expect success"
1110 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1111 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1114 resetquota -u $TSTUSR
1115 resetquota -g $TSTUSR
1116 resetquota -p $TSTPRJID
1118 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1120 # test dropping acquire request on master
1124 # Clear dmesg so watchdog is not triggered by previous
1126 do_facet ost1 dmesg -c > /dev/null
1128 setup_quota_test || error "setup quota failed with $?"
1129 trap cleanup_quota_test EXIT
1131 # make sure the system is clean
1132 local USED=$(getquota -u $TSTUSR global curspace)
1133 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1135 # make sure no granted quota on ost
1136 set_ost_qtype $QTYPE || error "enable ost quota failed"
1137 resetquota -u $TSTUSR
1139 # create file for $TSTUSR
1140 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1141 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1142 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1144 # create file for $TSTUSR2
1145 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1146 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1147 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1149 # cache per-ID lock for $TSTUSR on slave
1150 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1151 error "set quota failed"
1152 $RUNAS $DD of=$TESTFILE count=1 ||
1153 error "write $TESTFILE failure, expect success"
1154 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1155 error "write $TESTFILE2 failure, expect success"
1157 sync_all_data || true
1159 #define QUOTA_DQACQ 601
1160 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1161 lustre_fail mds 0x513 601
1163 # write to un-enforced ID ($TSTUSR2) should succeed
1164 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1165 error "write failure, expect success"
1167 # write to enforced ID ($TSTUSR) in background, exceeding limit
1168 # to make sure DQACQ is sent
1169 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1172 # watchdog timer uses a factor of 2
1173 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1174 sleep $((TIMEOUT * 2 + 1))
1176 # write should be blocked and never finished
1177 if ! ps -p $DDPID > /dev/null 2>&1; then
1179 error "write finished incorrectly!"
1184 # no watchdog is triggered
1185 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1186 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1187 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1188 [ -z "$watchdog" ] || error "$watchdog"
1190 rm -f $TMP/lustre-log-${TESTNAME}.log
1192 # write should continue then fail with EDQUOT
1196 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1197 if [ $count -ge 240 ]; then
1198 quota_error u $TSTUSR "dd not finished in $count secs"
1200 count=$((count + 1))
1201 if [ $((count % 30)) -eq 0 ]; then
1202 c_size=$(stat -c %s $TESTFILE)
1203 echo "Waiting $count secs. $c_size"
1210 resetquota -u $TSTUSR
1212 run_test 6 "Test dropping acquire request on master"
1214 # quota reintegration (global index)
1216 local TESTFILE=$DIR/$tdir/$tfile
1217 local LIMIT=20 # 20M
1219 [ "$SLOW" = "no" ] && LIMIT=5
1221 setup_quota_test || error "setup quota failed with $?"
1222 trap cleanup_quota_test EXIT
1224 # make sure the system is clean
1225 local USED=$(getquota -u $TSTUSR global curspace)
1226 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1228 # make sure no granted quota on ost1
1229 set_ost_qtype $QTYPE || error "enable ost quota failed"
1230 resetquota -u $TSTUSR
1231 set_ost_qtype "none" || error "disable ost quota failed"
1233 local OSTUUID=$(ostuuid_from_index 0)
1234 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1236 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1239 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1240 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1245 echo "Enable quota & set quota limit for $TSTUSR"
1246 set_ost_qtype $QTYPE || error "enable ost quota failed"
1247 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1248 error "set quota failed"
1250 echo "Start ost1..."
1251 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1254 wait_ost_reint $QTYPE || error "reintegration failed"
1256 # hardlimit should have been fetched by slave during global
1257 # reintegration, write will exceed quota
1258 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1259 quota_error u $TSTUSR "write success, but expect EDQUOT"
1262 wait_delete_completed
1263 sync_all_data || true
1269 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1270 error "clear quota failed"
1272 echo "Start ost1..."
1273 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1276 wait_ost_reint $QTYPE || error "reintegration failed"
1278 # hardlimit should be cleared on slave during reintegration
1279 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1280 quota_error u $TSTUSR "write error, but expect success"
1283 resetquota -u $TSTUSR
1285 run_test 7a "Quota reintegration (global index)"
1287 # quota reintegration (slave index)
1290 local TESTFILE=$DIR/$tdir/$tfile
1292 setup_quota_test || error "setup quota failed with $?"
1293 trap cleanup_quota_test EXIT
1295 # make sure the system is clean
1296 local USED=$(getquota -u $TSTUSR global curspace)
1297 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1299 # make sure no granted quota on ost1
1300 set_ost_qtype $QTYPE || error "enable ost quota failed"
1301 resetquota -u $TSTUSR
1302 set_ost_qtype "none" || error "disable ost quota failed"
1304 local OSTUUID=$(ostuuid_from_index 0)
1305 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1307 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1310 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1311 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1313 # consume some space to make sure the granted space will not
1314 # be released during reconciliation
1315 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1316 error "consume space failure, expect success"
1318 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1319 lustre_fail mds 0xa02
1321 set_ost_qtype $QTYPE || error "enable ost quota failed"
1322 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1323 error "set quota failed"
1325 # ignore the write error
1326 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1328 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1332 echo "Restart ost to trigger reintegration..."
1334 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1337 wait_ost_reint $QTYPE || error "reintegration failed"
1339 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1340 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1343 resetquota -u $TSTUSR
1346 run_test 7b "Quota reintegration (slave index)"
1348 # quota reintegration (restart mds during reintegration)
1350 local LIMIT=20 # 20M
1351 local TESTFILE=$DIR/$tdir/$tfile
1353 [ "$SLOW" = "no" ] && LIMIT=5
1355 setup_quota_test || error "setup quota failed with $?"
1356 trap cleanup_quota_test EXIT
1358 # make sure the system is clean
1359 local USED=$(getquota -u $TSTUSR global curspace)
1360 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1362 set_ost_qtype "none" || error "disable ost quota failed"
1363 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1364 error "set quota failed"
1366 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1367 lustre_fail ost 0xa03
1370 set_ost_qtype $QTYPE || error "enable ost quota failed"
1371 # trigger reintegration
1372 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1373 procf=${procf}quota_slave.force_reint
1374 do_facet ost1 $LCTL set_param $procf=1 ||
1375 error "force reintegration failed"
1383 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1386 # wait longer than usual to make sure the reintegration
1387 # is triggered by quota wb thread.
1388 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1390 # hardlimit should have been fetched by slave during global
1391 # reintegration, write will exceed quota
1392 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1393 quota_error u $TSTUSR "write success, but expect EDQUOT"
1396 resetquota -u $TSTUSR
1398 run_test 7c "Quota reintegration (restart mds during reintegration)"
1400 # Quota reintegration (Transfer index in multiple bulks)
1402 local TESTFILE=$DIR/$tdir/$tfile
1403 local TESTFILE1="$DIR/$tdir/$tfile"-1
1406 setup_quota_test || error "setup quota failed with $?"
1407 trap cleanup_quota_test EXIT
1409 set_ost_qtype "none" || error "disable ost quota failed"
1410 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1411 error "set quota for $TSTUSR failed"
1412 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1413 error "set quota for $TSTUSR2 failed"
1415 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1416 lustre_fail mds 0x608 0
1418 # enable quota to tirgger reintegration
1419 set_ost_qtype "u" || error "enable ost quota failed"
1420 wait_ost_reint "u" || error "reintegration failed"
1424 # hardlimit should have been fetched by slave during global
1425 # reintegration, write will exceed quota
1426 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1427 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1429 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1430 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1433 resetquota -u $TSTUSR
1434 resetquota -u $TSTUSR2
1436 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1438 # quota reintegration (inode limits)
1440 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
1442 # LU-2435: skip this quota test if underlying zfs version has not
1443 # supported native dnode accounting
1444 [ "$(facet_fstype mds1)" == "zfs" ] && {
1445 local F="feature@userobj_accounting"
1446 local pool=$(zpool_name mds1)
1447 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1449 [[ "$feature" != *" active "* ]] &&
1450 skip "requires zpool with active userobj_accounting" &&
1454 local ilimit=$((1024 * 2)) # 2k inodes
1455 local TESTFILE=$DIR/${tdir}-1/$tfile
1457 setup_quota_test || error "setup quota failed with $?"
1458 trap cleanup_quota_test EXIT
1460 # make sure the system is clean
1461 local USED=$(getquota -u $TSTUSR global curinodes)
1462 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1464 # make sure no granted quota on mdt1
1465 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1466 resetquota -u $TSTUSR
1467 set_mdt_qtype "none" || error "disable mdt quota failed"
1469 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1470 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1471 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1474 echo "Stop mds${MDSCOUNT}..."
1477 echo "Enable quota & set quota limit for $TSTUSR"
1478 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1479 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1480 error "set quota failed"
1482 echo "Start mds${MDSCOUNT}..."
1483 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1486 wait_mdt_reint $QTYPE || error "reintegration failed"
1488 echo "create remote dir"
1489 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1490 error "create remote dir failed"
1491 chmod 0777 $DIR/${tdir}-1
1493 # hardlimit should have been fetched by slave during global
1494 # reintegration, create will exceed quota
1495 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1496 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1498 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1499 wait_delete_completed
1500 sync_all_data || true
1502 echo "Stop mds${MDSCOUNT}..."
1505 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1506 error "clear quota failed"
1508 echo "Start mds${MDSCOUNT}..."
1509 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1512 wait_mdt_reint $QTYPE || error "reintegration failed"
1514 # hardlimit should be cleared on slave during reintegration
1515 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1516 quota_error u $TSTUSR "create failed, expect success"
1518 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1519 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1522 resetquota -u $TSTUSR
1524 run_test 7e "Quota reintegration (inode limits)"
1526 # run dbench with quota enabled
1528 local BLK_LIMIT="100g" #100G
1529 local FILE_LIMIT=1000000
1531 setup_quota_test || error "setup quota failed with $?"
1532 trap cleanup_quota_test EXIT
1534 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1535 set_ost_qtype $QTYPE || error "enable ost quota failed"
1537 echo "Set enough high limit for user: $TSTUSR"
1538 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1539 error "set user quota failed"
1540 echo "Set enough high limit for group: $TSTUSR"
1541 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1542 error "set group quota failed"
1543 if is_project_quota_supported; then
1544 change_project -sp $TSTPRJID $DIR/$tdir
1545 echo "Set enough high limit for project: $TSTPRJID"
1546 $LFS setquota -p $TSTPRJID -b 0 \
1547 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1548 error "set project quota failed"
1552 [ "$SLOW" = "no" ] && duration=" -t 120"
1553 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1554 quota_error a $TSTUSR "dbench failed!"
1556 is_project_quota_supported && change_project -C $DIR/$tdir
1558 resetquota -u $TSTUSR
1559 resetquota -g $TSTUSR
1560 resetquota -p $TSTPRJID
1562 run_test 8 "Run dbench with quota enabled"
1564 # this check is just for test_9
1565 OST0_MIN=4900000 #4.67G
1567 check_whether_skip () {
1568 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1569 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1570 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1571 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1578 # run for fixing bug10707, it needs a big room. test for 64bit
1580 local filesize=$((1024 * 9 / 2)) # 4.5G
1582 check_whether_skip && return 0
1584 setup_quota_test || error "setup quota failed with $?"
1585 trap cleanup_quota_test EXIT
1587 set_ost_qtype "ug" || error "enable ost quota failed"
1589 local TESTFILE="$DIR/$tdir/$tfile-0"
1590 local BLK_LIMIT=100G #100G
1591 local FILE_LIMIT=1000000
1593 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1595 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1597 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1598 error "set user quota failed"
1600 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1601 "for group: $TSTUSR"
1602 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1603 error "set group quota failed"
1605 quota_show_check a u $TSTUSR
1606 quota_show_check a g $TSTUSR
1608 echo "Create test file"
1609 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1610 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1612 log "Write the big file of 4.5G ..."
1613 $RUNAS $DD of=$TESTFILE count=$filesize ||
1614 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1620 resetquota -u $TSTUSR
1621 resetquota -g $TSTUSR
1626 run_test 9 "Block limit larger than 4GB (b10707)"
1629 local TESTFILE=$DIR/$tdir/$tfile
1631 setup_quota_test || error "setup quota failed with $?"
1632 trap cleanup_quota_test EXIT
1634 # set limit to root user should fail
1635 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1636 error "set limit for root user successfully, expect failure"
1637 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1638 error "set limit for root group successfully, expect failure"
1639 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1640 error "set limit for project 0 successfully, expect failure"
1642 # root user can overrun quota
1643 set_ost_qtype "ug" || error "enable ost quota failed"
1645 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1646 error "set quota failed"
1647 quota_show_check b u $TSTUSR
1649 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1650 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1652 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1653 error "write failure, expect success"
1656 resetquota -u $TSTUSR
1658 run_test 10 "Test quota for root user"
1661 local TESTFILE=$DIR/$tdir/$tfile
1662 setup_quota_test || error "setup quota failed with $?"
1663 trap cleanup_quota_test EXIT
1665 set_mdt_qtype "ug" || error "enable mdt quota failed"
1666 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1667 error "set quota failed"
1669 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1670 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1672 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1673 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1676 local USED=$(getquota -u $TSTUSR global curinodes)
1677 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1680 resetquota -u $TSTUSR
1682 run_test 11 "Chown/chgrp ignores quota"
1685 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs" && return
1687 local blimit=22 # 22M
1688 local blk_cnt=$((blimit - 5))
1689 local TESTFILE0="$DIR/$tdir/$tfile"-0
1690 local TESTFILE1="$DIR/$tdir/$tfile"-1
1692 setup_quota_test || error "setup quota failed with $?"
1693 trap cleanup_quota_test EXIT
1695 set_ost_qtype "u" || error "enable ost quota failed"
1696 quota_show_check b u $TSTUSR
1698 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1699 error "set quota failed"
1701 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1702 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1703 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1704 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1706 echo "Write to ost0..."
1707 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1708 quota_error a $TSTUSR "dd failed"
1710 echo "Write to ost1..."
1711 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1712 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1714 echo "Free space from ost0..."
1716 wait_delete_completed
1717 sync_all_data || true
1719 echo "Write to ost1 after space freed from ost0..."
1720 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1721 quota_error a $TSTUSR "rebalancing failed"
1724 resetquota -u $TSTUSR
1726 run_test 12a "Block quota rebalancing"
1729 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
1731 local ilimit=$((1024 * 2)) # 2k inodes
1732 local TESTFILE0=$DIR/$tdir/$tfile
1733 local TESTFILE1=$DIR/${tdir}-1/$tfile
1735 setup_quota_test || error "setup quota failed with $?"
1736 trap cleanup_quota_test EXIT
1738 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1739 chmod 0777 $DIR/${tdir}-1
1741 set_mdt_qtype "u" || error "enable mdt quota failed"
1742 quota_show_check f u $TSTUSR
1744 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1745 error "set quota failed"
1747 echo "Create $ilimit files on mdt0..."
1748 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1749 quota_error u $TSTUSR "create failed, but expect success"
1751 echo "Create files on mdt1..."
1752 $RUNAS createmany -m $TESTFILE1 1 &&
1753 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1755 echo "Free space from mdt0..."
1756 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1757 wait_delete_completed
1758 sync_all_data || true
1760 echo "Create files on mdt1 after space freed from mdt0..."
1761 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1762 quota_error a $TSTUSR "rebalancing failed"
1764 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1765 error "unlink mdt1 files failed"
1766 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1769 resetquota -u $TSTUSR
1771 run_test 12b "Inode quota rebalancing"
1774 local TESTFILE=$DIR/$tdir/$tfile
1775 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1776 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1778 setup_quota_test || error "setup quota failed with $?"
1779 trap cleanup_quota_test EXIT
1781 set_ost_qtype "u" || error "enable ost quota failed"
1782 quota_show_check b u $TSTUSR
1784 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1785 error "set quota failed"
1786 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1787 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1789 # clear the locks in cache first
1790 do_facet ost1 $LCTL set_param -n $procf=clear
1791 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1792 [ $nlock -eq 0 ] || error "$nlock cached locks"
1794 # write to acquire the per-ID lock
1795 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1796 quota_error a $TSTUSR "dd failed"
1798 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1799 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1801 # clear quota doesn't trigger per-ID lock cancellation
1802 resetquota -u $TSTUSR
1803 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1804 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1806 # clear the per-ID lock
1807 do_facet ost1 $LCTL set_param -n $procf=clear
1808 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1809 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1811 # spare quota should be released
1812 local OSTUUID=$(ostuuid_from_index 0)
1813 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1814 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1815 [ $limit -le $space ] ||
1816 error "spare quota isn't released, limit:$limit, space:$space"
1820 run_test 13 "Cancel per-ID lock in the LRU list"
1823 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1825 wait_delete_completed
1826 sync_all_data || true
1829 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1830 error "set user quota failed"
1831 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1832 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1833 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1834 resetquota -u $TSTUSR
1837 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1838 error "set group quota failed"
1839 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1840 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1841 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1842 resetquota -g $TSTUSR
1844 run_test 15 "Set over 4T block quota"
1848 local BLKS=1 # 1M less than limit
1849 local TESTFILE=$DIR/$tdir/$tfile
1851 setup_quota_test || error "setup quota failed with $?"
1852 trap cleanup_quota_test EXIT
1854 # make sure the system is clean
1855 local USED=$(getquota -u $TSTUSR global curspace)
1856 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1858 set_ost_qtype "ug" || error "enable ost quota failed"
1859 # make sure no granted quota on ost
1860 resetquota -u $TSTUSR
1861 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1862 error "set quota failed"
1864 quota_show_check b u $TSTUSR
1866 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1867 lustre_fail mds 0xa04 $err_code
1869 # write in background
1870 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1874 # write should be blocked and never finished
1875 if ! ps -p $DDPID > /dev/null 2>&1; then
1877 quota_error u $TSTUSR "write finished incorrectly!"
1885 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1887 if [ $count -gt $timeout ]; then
1888 quota_error u $TSTUSR "dd is not finished!"
1893 sync; sync_all_data || true
1895 USED=$(getquota -u $TSTUSR global curspace)
1896 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1897 "Used space(${USED}K) is less than ${BLKS}M"
1900 resetquota -u $TSTUSR
1903 # DQACQ return recoverable error
1905 echo "DQACQ return -ENOLCK"
1907 test_17sub 37 || error "Handle -ENOLCK failed"
1909 echo "DQACQ return -EAGAIN"
1911 test_17sub 11 || error "Handle -EAGAIN failed"
1913 echo "DQACQ return -ETIMEDOUT"
1914 #define ETIMEDOUT 110
1915 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1917 echo "DQACQ return -ENOTCONN"
1918 #define ENOTCONN 107
1919 test_17sub 107 || error "Handle -ENOTCONN failed"
1922 run_test 17 "DQACQ return recoverable error"
1926 local blimit="200m" # 200M
1927 local TESTFILE="$DIR/$tdir/$tfile"
1929 setup_quota_test || error "setup quota failed with $?"
1930 trap cleanup_quota_test EXIT
1932 set_ost_qtype "u" || error "enable ost quota failed"
1933 log "User quota (limit: $blimit)"
1934 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1935 error "set quota failed"
1936 quota_show_check b u $TSTUSR
1938 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1939 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1941 local timeout=$(sysctl -n lustre.timeout)
1943 if [ $io_type = "directio" ]; then
1944 log "Write 100M (directio) ..."
1945 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1947 log "Write 100M (buffered) ..."
1948 $RUNAS $DD of=$TESTFILE count=100 &
1952 replay_barrier $SINGLEMDS
1953 log "Fail mds for $((2 * timeout)) seconds"
1954 fail $SINGLEMDS $((2 * timeout))
1957 if at_is_enabled; then
1958 timeout=$(at_max_get mds)
1960 timeout=$(lctl get_param -n timeout)
1964 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1965 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1966 log "it took $count second"
1971 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1973 cancel_lru_locks mdc
1974 cancel_lru_locks osc
1977 local testfile_size=$(stat -c %s $TESTFILE)
1978 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1979 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1980 "got ${testfile_size}. Verifying file failed!"
1983 resetquota -u $TSTUSR
1986 # test when mds does failover, the ost still could work well
1987 # this test shouldn't trigger watchdog b=14840
1989 # Clear dmesg so watchdog is not triggered by previous
1991 do_facet ost1 dmesg -c > /dev/null
1994 test_18_sub directio
1996 # check if watchdog is triggered
1997 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1998 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1999 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2000 [ -z "$watchdog" ] || error "$watchdog"
2001 rm -f $TMP/lustre-log-${TESTNAME}.log
2003 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2007 local TESTFILE=$DIR/$tdir/$tfile
2009 setup_quota_test || error "setup quota failed with $?"
2010 trap cleanup_quota_test EXIT
2012 set_ost_qtype $QTYPE || error "enable ost quota failed"
2014 # bind file to a single OST
2015 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2016 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2018 echo "Set user quota (limit: ${blimit}M)"
2019 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2020 error "set user quota failed"
2021 quota_show_check b u $TSTUSR
2022 echo "Update quota limits"
2023 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2024 error "set group quota failed"
2025 quota_show_check b u $TSTUSR
2027 # first wirte might be cached
2028 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2029 cancel_lru_locks osc
2031 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2032 quota_error u $TSTUSR "Write success, expect failure"
2036 resetquota -u $TSTUSR
2038 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2040 test_20() { # b15754
2041 local LSTR=(2g 1t 4k 3m) # limits strings
2043 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2046 resetquota -u $TSTUSR
2048 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2049 $MOUNT || error "could not set quota limits"
2050 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2051 --inode-softlimit ${LSTR[2]} \
2052 --inode-hardlimit ${LSTR[3]} \
2053 $MOUNT || error "could not set quota limits"
2055 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2056 error "bsoftlimit was not set properly"
2057 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2058 error "bhardlimit was not set properly"
2059 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2060 error "isoftlimit was not set properly"
2061 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2062 error "ihardlimit was not set properly"
2064 resetquota -u $TSTUSR
2066 run_test 20 "Test if setquota specifiers work properly (b15754)"
2073 local time=$(($(date +%s) + seconds))
2074 while [ $(date +%s) -lt $time ]; do
2075 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2079 # run for fixing bug16053, setquota shouldn't fail when writing and
2080 # deleting are happening
2082 local TESTFILE="$DIR/$tdir/$tfile"
2083 local BLIMIT=10 # 10G
2084 local ILIMIT=1000000
2086 setup_quota_test || error "setup quota failed with $?"
2087 trap cleanup_quota_test EXIT
2089 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2091 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2092 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2093 error "set user quota failed"
2094 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2095 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2096 error "set group quota failed"
2097 if is_project_quota_supported; then
2098 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2099 "project: $TSTPRJID"
2100 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2101 $MOUNT || error "set project quota failed"
2104 # repeat writing on a 1M file
2105 test_21_sub ${TESTFILE}_1 1 30 &
2107 # repeat writing on a 128M file
2108 test_21_sub ${TESTFILE}_2 128 30 &
2111 local time=$(($(date +%s) + 30))
2113 while [ $(date +%s) -lt $time ]; do
2114 log "Set quota for $i times"
2115 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2116 -I $((ILIMIT + i)) $MOUNT ||
2117 error "Set user quota failed"
2118 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2119 -I $((ILIMIT + i)) $MOUNT ||
2120 error "Set group quota failed"
2121 if is_project_quota_supported; then
2122 $LFS setquota -p $TSTPRJID -b 0 -B \
2123 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2124 error "Set project quota failed"
2132 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2134 if [ $count -gt 60 ]; then
2135 quota_error a $TSTUSR "dd should be finished!"
2139 echo "(dd_pid=$DDPID1, time=$count)successful"
2143 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2145 if [ $count -gt 60 ]; then
2146 quota_error a $TSTUSR "dd should be finished!"
2150 echo "(dd_pid=$DDPID2, time=$count)successful"
2153 resetquota -u $TSTUSR
2154 resetquota -g $TSTUSR
2155 resetquota -p $TSTPRJID
2157 run_test 21 "Setquota while writing & deleting (b16053)"
2159 # enable/disable quota enforcement permanently
2161 echo "Set both mdt & ost quota type as ug"
2163 is_project_quota_supported && qtype=$QTYPE
2164 set_mdt_qtype $qtype || error "enable mdt quota failed"
2165 set_ost_qtype $qtype || error "enable ost quota failed"
2168 stopall || error "failed to stopall (1)"
2172 echo "Verify if quota is enabled"
2173 local qtype1=$(mdt_quota_type)
2174 [ $qtype1 != $qtype] && error "mdt quota setting is lost"
2175 qtype=$(ost_quota_type)
2176 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2178 echo "Set both mdt & ost quota type as none"
2179 set_mdt_qtype "none" || error "disable mdt quota failed"
2180 set_ost_qtype "none" || error "disable ost quota failed"
2183 stopall || error "failed to stopall (2)"
2188 echo "Verify if quota is disabled"
2189 qtype=$(mdt_quota_type)
2190 [ $qtype != "none" ] && error "mdt quota setting is lost"
2191 qtype=$(ost_quota_type)
2192 [ $qtype != "none" ] && error "ost quota setting is lost"
2196 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2199 local TESTFILE="$DIR/$tdir/$tfile"
2202 setup_quota_test || error "setup quota failed with $?"
2203 trap cleanup_quota_test EXIT
2205 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2208 log "User quota (limit: $LIMIT MB)"
2209 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2210 error "set quota failed"
2211 quota_show_check b u $TSTUSR
2213 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2214 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2216 log "Step1: trigger EDQUOT with O_DIRECT"
2217 log "Write half of file"
2218 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2219 quota_error u $TSTUSR "(1) Write failure, expect success." \
2221 log "Write out of block quota ..."
2222 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2223 oflag=direct conv=notrunc &&
2224 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2228 log "Step2: rewrite should succeed"
2229 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2230 quota_error u $TSTUSR "(3) Write failure, expect success." \
2236 local OST0_UUID=$(ostuuid_from_index 0)
2237 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2238 [ $OST0_QUOTA_USED -ne 0 ] &&
2239 ($SHOW_QUOTA_USER; \
2240 quota_error u $TSTUSR "quota isn't released")
2242 resetquota -u $TSTUSR
2246 [ $(facet_fstype ost1) == "zfs" ] &&
2247 skip "Overwrite in place is not guaranteed to be " \
2248 "space neutral on ZFS" && return
2250 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2251 check_whether_skip && return 0
2252 log "run for 4MB test file"
2255 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2256 check_whether_skip && return 0
2257 log "run for 40MB test file"
2260 run_test 23 "Quota should be honored with directIO (b16125)"
2264 local TESTFILE="$DIR/$tdir/$tfile"
2266 setup_quota_test || error "setup quota failed with $?"
2267 trap cleanup_quota_test EXIT
2269 set_ost_qtype $QTYPE || error "enable ost quota failed"
2271 # bind file to a single OST
2272 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2273 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2275 echo "Set user quota (limit: ${blimit}M)"
2276 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2277 error "set quota failed"
2279 # overrun quota by root user
2280 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2281 error "write failure, expect success"
2282 cancel_lru_locks osc
2283 sync_all_data || true
2285 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2288 resetquota -u $TSTUSR
2290 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2292 test_27a() { # b19612
2293 $LFS quota $TSTUSR $DIR &&
2294 error "lfs succeeded with no type, but should have failed"
2295 $LFS setquota $TSTUSR $DIR &&
2296 error "lfs succeeded with no type, but should have failed"
2299 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2301 test_27b() { # b20200
2302 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2303 error "lfs setquota failed with uid argument"
2304 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2305 error "lfs stequota failed with gid argument"
2306 if is_project_quota_supported; then
2307 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2308 1000 $DIR || error \
2309 "lfs stequota failed with projid argument"
2311 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2312 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2313 if is_project_quota_supported; then
2314 $SHOW_QUOTA_PROJID ||
2315 error "lfs quota failed with projid argument"
2317 resetquota -u $TSTUSR
2318 resetquota -g $TSTUSR
2319 resetquota -p $TSTPRJID
2322 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2327 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2328 error "lfs setquota failed"
2330 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2331 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2332 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2333 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2335 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2336 error "lfs setquota for $TSTID failed"
2338 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2339 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2340 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2341 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2343 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2344 error "total allocated inode/block limit not printed"
2346 resetquota -u $TSTUSR
2348 run_test 27c "lfs quota should support human-readable output"
2355 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2356 error "set fraction block limit failed"
2357 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2358 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2359 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2360 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2362 resetquota -u $TSTUSR
2364 run_test 27d "lfs setquota should support fraction block limit"
2368 local TESTFILE="$DIR/$tdir/$tfile"
2371 setup_quota_test || error "setup quota failed with $?"
2372 trap cleanup_quota_test EXIT
2374 set_ost_qtype "u" || error "enable ost quota failed"
2376 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2377 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2379 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2380 $MAX_IQ_TIME $DIR || error "set grace time failed"
2381 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2382 error "set quota failed"
2383 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2384 cancel_lru_locks osc
2386 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2387 # over-quota flag has not yet settled since we do not trigger async
2388 # events based on grace time period expiration
2390 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2391 cancel_lru_locks osc
2392 # now over-quota flag should be settled and further writes should fail
2394 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2395 error "grace times were reset"
2398 resetquota -u $TSTUSR
2399 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2400 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2402 run_test 30 "Hard limit updates should not reset grace times"
2404 # basic usage tracking for user & group
2406 local INODES=10 # 10 files
2407 local BLK_CNT=2 # of 2M each
2408 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2410 setup_quota_test || error "setup quota failed with $?"
2411 trap cleanup_quota_test EXIT
2413 # make sure the system is clean
2414 local USED=$(getquota -u $TSTID global curspace)
2416 error "Used space ($USED) for user $TSTID isn't 0."
2417 USED=$(getquota -g $TSTID global curspace)
2419 error "Used space ($USED) for group $TSTID isn't 0."
2420 if is_project_quota_supported; then
2421 USED=$(getquota -p $TSTPRJID global curspace)
2422 [ $USED -ne 0 ] && error \
2423 "Used space ($USED) for project $TSTPRJID isn't 0."
2426 echo "Write files..."
2427 for i in $(seq 0 $INODES); do
2428 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2429 error "write failed"
2430 is_project_quota_supported &&
2431 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2432 echo "Iteration $i/$INODES completed"
2434 cancel_lru_locks osc
2436 echo "Wait for setattr on objects finished..."
2437 wait_delete_completed
2439 sync; sync_all_data || true
2441 echo "Verify disk usage after write"
2442 USED=$(getquota -u $TSTID global curspace)
2443 [ $USED -lt $TOTAL_BLKS ] &&
2444 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2445 USED=$(getquota -g $TSTID global curspace)
2446 [ $USED -lt $TOTAL_BLKS ] &&
2447 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2448 if is_project_quota_supported; then
2449 USED=$(getquota -p $TSTPRJID global curspace)
2450 [ $USED -lt $TOTAL_BLKS ] && error \
2451 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2454 echo "Verify inode usage after write"
2455 USED=$(getquota -u $TSTID global curinodes)
2456 [ $USED -lt $INODES ] &&
2457 error "Used inode for user $TSTID is $USED, expected $INODES"
2458 USED=$(getquota -g $TSTID global curinodes)
2459 [ $USED -lt $INODES ] &&
2460 error "Used inode for group $TSTID is $USED, expected $INODES"
2461 if is_project_quota_supported; then
2462 USED=$(getquota -p $TSTPRJID global curinodes)
2463 [ $USED -lt $INODES ] && error \
2464 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2469 echo "Verify disk usage after delete"
2470 USED=$(getquota -u $TSTID global curspace)
2471 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2472 USED=$(getquota -u $TSTID global curinodes)
2473 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2474 USED=$(getquota -g $TSTID global curspace)
2475 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2476 USED=$(getquota -g $TSTID global curinodes)
2477 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2478 if is_project_quota_supported; then
2479 USED=$(getquota -p $TSTPRJID global curspace)
2481 error "Used space for project $TSTPRJID isn't 0. $USED"
2482 USED=$(getquota -p $TSTPRJID global curinodes)
2484 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2487 run_test 33 "Basic usage tracking for user & group & project"
2489 # usage transfer test for user & group & project
2491 local BLK_CNT=2 # 2MB
2492 local project_supported="no"
2494 is_project_quota_supported && project_supported="yes"
2495 setup_quota_test || error "setup quota failed with $?"
2496 trap cleanup_quota_test EXIT
2498 # make sure the system is clean
2499 local USED=$(getquota -u $TSTID global curspace)
2500 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2501 USED=$(getquota -g $TSTID global curspace)
2502 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2504 local USED=$(getquota -u $TSTID2 global curspace)
2505 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2506 if [ $project_supported == "yes" ]; then
2507 USED=$(getquota -p $TSTPRJID global curspace)
2508 [ $USED -ne 0 ] && error \
2509 "Used space ($USED) for Project $TSTPRJID isn't 0."
2512 echo "Write file..."
2513 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2514 error "write failed"
2515 cancel_lru_locks osc
2516 sync; sync_all_data || true
2518 echo "chown the file to user $TSTID"
2519 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2521 echo "Wait for setattr on objects finished..."
2522 wait_delete_completed
2524 BLK_CNT=$((BLK_CNT * 1024))
2526 echo "Verify disk usage for user $TSTID"
2527 USED=$(getquota -u $TSTID global curspace)
2528 [ $USED -lt $BLK_CNT ] &&
2529 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2530 USED=$(getquota -u $TSTID global curinodes)
2532 error "Used inodes for user $TSTID is $USED, expected 1"
2534 echo "chgrp the file to group $TSTID"
2535 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2537 echo "Wait for setattr on objects finished..."
2538 wait_delete_completed
2540 echo "Verify disk usage for group $TSTID"
2541 USED=$(getquota -g $TSTID global curspace)
2542 [ $USED -ge $BLK_CNT ] ||
2543 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2544 USED=$(getquota -g $TSTID global curinodes)
2546 error "Used inodes for group $TSTID is $USED, expected 1"
2548 # chown won't change the ost object group. LU-4345 */
2549 echo "chown the file to user $TSTID2"
2550 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2552 echo "Wait for setattr on objects finished..."
2553 wait_delete_completed
2555 echo "change_project project id to $TSTPRJID"
2556 [ $project_supported == "yes" ] &&
2557 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2558 echo "Wait for setattr on objects finished..."
2559 wait_delete_completed
2561 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2562 USED=$(getquota -u $TSTID2 global curspace)
2563 [ $USED -lt $BLK_CNT ] &&
2564 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2565 USED=$(getquota -u $TSTID global curspace)
2567 error "Used space for user $TSTID is $USED, expected 0"
2568 USED=$(getquota -g $TSTID global curspace)
2569 [ $USED -lt $BLK_CNT ] &&
2570 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2571 if [ $project_supported == "yes" ]; then
2572 USED=$(getquota -p $TSTPRJID global curspace)
2573 [ $USED -lt $BLK_CNT ] && error \
2574 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2579 run_test 34 "Usage transfer for user & group & project"
2581 # usage is still accessible across restart
2583 local BLK_CNT=2 # 2 MB
2585 setup_quota_test || error "setup quota failed with $?"
2586 trap cleanup_quota_test EXIT
2588 echo "Write file..."
2589 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2590 error "write failed"
2591 is_project_quota_supported &&
2592 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2593 cancel_lru_locks osc
2595 echo "Wait for setattr on objects finished..."
2596 wait_delete_completed
2598 sync; sync_all_data || true
2600 echo "Save disk usage before restart"
2601 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2602 [ $ORIG_USR_SPACE -eq 0 ] &&
2603 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2604 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2605 [ $ORIG_USR_INODES -eq 0 ] &&
2606 error "Used inodes for user $TSTID is 0, expected 1"
2607 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2608 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2609 [ $ORIG_GRP_SPACE -eq 0 ] &&
2610 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2611 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2612 [ $ORIG_GRP_INODES -eq 0 ] &&
2613 error "Used inodes for group $TSTID is 0, expected 1"
2614 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2616 if is_project_quota_supported; then
2617 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2618 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2619 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2620 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2621 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2622 "Used inodes for project $TSTPRJID is 0, expected 1"
2623 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2631 echo "Verify disk usage after restart"
2632 local USED=$(getquota -u $TSTID global curspace)
2633 [ $USED -eq $ORIG_USR_SPACE ] ||
2634 error "Used space for user $TSTID changed from " \
2635 "$ORIG_USR_SPACE to $USED"
2636 USED=$(getquota -u $TSTID global curinodes)
2637 [ $USED -eq $ORIG_USR_INODES ] ||
2638 error "Used inodes for user $TSTID changed from " \
2639 "$ORIG_USR_INODES to $USED"
2640 USED=$(getquota -g $TSTID global curspace)
2641 [ $USED -eq $ORIG_GRP_SPACE ] ||
2642 error "Used space for group $TSTID changed from " \
2643 "$ORIG_GRP_SPACE to $USED"
2644 USED=$(getquota -g $TSTID global curinodes)
2645 [ $USED -eq $ORIG_GRP_INODES ] ||
2646 error "Used inodes for group $TSTID changed from " \
2647 "$ORIG_GRP_INODES to $USED"
2648 if [ $project_supported == "yes" ]; then
2649 USED=$(getquota -p $TSTPRJID global curinodes)
2650 [ $USED -eq $ORIG_PRJ_INODES ] ||
2651 error "Used inodes for project $TSTPRJID " \
2652 "changed from $ORIG_PRJ_INODES to $USED"
2653 USED=$(getquota -p $TSTPRJID global curspace)
2654 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2655 error "Used space for project $TSTPRJID "\
2656 "changed from $ORIG_PRJ_SPACE to $USED"
2659 # check if the vfs_dq_init() is called before writing
2660 echo "Append to the same file..."
2661 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2662 error "write failed"
2663 cancel_lru_locks osc
2664 sync; sync_all_data || true
2666 echo "Verify space usage is increased"
2667 USED=$(getquota -u $TSTID global curspace)
2668 [ $USED -gt $ORIG_USR_SPACE ] ||
2669 error "Used space for user $TSTID isn't increased" \
2670 "orig:$ORIG_USR_SPACE, now:$USED"
2671 USED=$(getquota -g $TSTID global curspace)
2672 [ $USED -gt $ORIG_GRP_SPACE ] ||
2673 error "Used space for group $TSTID isn't increased" \
2674 "orig:$ORIG_GRP_SPACE, now:$USED"
2675 if [ $project_supported == "yes" ]; then
2676 USED=$(getquota -p $TSTPRJID global curspace)
2677 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2678 error "Used space for project $TSTPRJID isn't " \
2679 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2684 run_test 35 "Usage is still accessible across reboot"
2686 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2689 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2690 skip "Old server doesn't have LU-5006 fix." && return
2692 setup_quota_test || error "setup quota failed with $?"
2693 trap cleanup_quota_test EXIT
2695 # make sure the system is clean
2696 local USED=$(getquota -u $TSTID global curspace)
2698 error "Used space ($USED) for user $TSTID isn't 0."
2700 # create file with MDS_OPEN_DELAY_CREATE flag
2701 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2702 error "Create file failed"
2704 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2705 oflag=sync || error "Write file failed"
2707 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2709 # wait for setattr on objects finished..."
2710 wait_delete_completed
2712 USED=$(getquota -u $TSTID global curspace)
2713 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2717 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2721 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2722 skip "Old server doesn't have LU-8801 fix." && return
2724 [ "$UID" != 0 ] && skip_env "must run as root" && return
2726 setup_quota_test || error "setup quota failed with $?"
2727 trap cleanup_quota_test EXIT
2729 # make sure the system is clean
2730 local USED=$(getquota -u $TSTID global curspace)
2732 error "Used space ($USED) for user $TSTID isn't 0."
2733 USED=$(getquota -u $TSTID2 global curspace)
2735 error "Used space ($USED) for user $TSTID2 isn't 0."
2737 local TESTFILE="$DIR/$tdir/$tfile"
2738 local file_cnt=10000
2740 # Generate id entries in accounting file
2741 echo "Create $file_cnt files..."
2742 for i in `seq $file_cnt`; do
2744 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2745 error "failed to chown $TESTFILE-$i"
2747 cancel_lru_locks osc
2748 sync; sync_all_data || true
2750 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2751 procf=${procf}.quota_slave.acct_user
2754 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2755 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2756 echo "Found $acct_cnt id entries"
2758 [ $file_cnt -eq $acct_cnt ] || {
2759 do_facet mds1 $LCTL get_param $procf
2760 error "skipped id entries"
2765 run_test 38 "Quota accounting iterator doesn't skip id entries"
2768 local TESTFILE="$DIR/$tdir/project"
2769 ! is_project_quota_supported &&
2770 skip "Project quota is not supported" && return 0
2772 setup_quota_test || error "setup quota failed with $?"
2775 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2776 [ $projectid -ne 0 ] &&
2777 error "Project id should be 0 not $projectid"
2778 change_project -p 1024 $TESTFILE
2779 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2780 [ $projectid -ne 1024 ] &&
2781 error "Project id should be 1024 not $projectid"
2783 stopall || error "failed to stopall (1)"
2786 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2787 [ $projectid -ne 1024 ] &&
2788 error "Project id should be 1024 not $projectid"
2792 run_test 39 "Project ID interface works correctly"
2795 ! is_project_quota_supported &&
2796 skip "Project quota is not supported" && return 0
2797 local dir1="$DIR/$tdir/dir1"
2798 local dir2="$DIR/$tdir/dir2"
2800 setup_quota_test || error "setup quota failed with $?"
2802 mkdir -p $dir1 $dir2
2803 change_project -sp 1 $dir1 && touch $dir1/1
2804 change_project -sp 2 $dir2
2806 ln $dir1/1 $dir2/1_link &&
2807 error "Hard link across different project quota should fail"
2812 run_test 40a "Hard link across different project ID"
2815 ! is_project_quota_supported &&
2816 skip "Project quota is not supported" && return 0
2817 local dir1="$DIR/$tdir/dir1"
2818 local dir2="$DIR/$tdir/dir2"
2820 setup_quota_test || error "setup quota failed with $?"
2821 mkdir -p $dir1 $dir2
2822 change_project -sp 1 $dir1 && touch $dir1/1
2823 change_project -sp 2 $dir2
2825 mv $dir1/1 $dir2/2 || error "mv failed $?"
2826 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2827 if [ "$projid" != "2" ]; then
2828 error "project id expected 2 not $projid"
2833 run_test 40b "Mv across different project ID"
2836 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
2837 ! is_project_quota_supported &&
2838 skip "Project quota is not supported" && return 0
2840 setup_quota_test || error "setup quota failed with $?"
2841 local dir="$DIR/$tdir/dir"
2843 mkdir -p $dir && change_project -sp 1 $dir
2844 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2845 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2846 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2847 touch $dir/remote_dir/file
2848 #verify inherit works file for remote dir.
2849 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2850 [ "$projid" != "1" ] &&
2851 error "file under remote dir expected 1 not $projid"
2853 #Agent inode should be ignored for project quota
2854 USED=$(getquota -p 1 global curinodes)
2855 [ "$USED" != "3" ] &&
2856 error "file count expected 3 got $USED"
2862 run_test 40c "Remote child Dir inherit project quota properly"
2865 ! is_project_quota_supported &&
2866 skip "Project quota is not supported" && return 0
2868 setup_quota_test || error "setup quota failed with $?"
2869 local dir="$DIR/$tdir/dir"
2871 mkdir $dir && change_project -p 1 $dir
2872 count=$($LFS find --projid 1 $DIR | wc -l)
2873 [ "$count" != 1 ] && error "expected 1 but got $count"
2878 run_test 50 "Test if lfs find --projid works"
2881 ! is_project_quota_supported &&
2882 skip "Project quota is not supported" && return 0
2883 setup_quota_test || error "setup quota failed with $?"
2884 local dir="$DIR/$tdir/dir"
2886 mkdir $dir && change_project -sp 1 $dir
2887 local used=$(getquota -p 1 global curinodes)
2888 [ $used != "1" ] && error "expected 1 got $used"
2893 used=$(getquota -p 1 global curinodes)
2894 [ $used != "4" ] && error "expected 4 got $used"
2896 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2898 cp $DIR/$tdir/6 $dir/6
2899 used=$(getquota -p 1 global curinodes)
2900 [ $used != "5" ] && error "expected 5 got $used"
2903 mv $DIR/$tdir/6 $dir/7
2904 used=$(getquota -p 1 global curinodes)
2905 [ $used != "6" ] && error "expected 6 got $used"
2910 run_test 51 "Test project accounting with mv/cp"
2913 ! is_project_quota_supported &&
2914 skip "Project quota is not supported" && return 0
2915 setup_quota_test || error "setup quota failed with $?"
2916 local dir="$DIR/$tdir/dir"
2917 mkdir $dir && change_project -sp 1 $dir
2919 touch $DIR/$tdir/file
2920 #Try renaming a file into the project. This should fail.
2921 for num in $(seq 1 2000); do
2922 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2923 error "rename should fail"
2928 run_test 52 "Rename across different project ID"
2931 ! is_project_quota_supported &&
2932 skip "Project quota is not supported" && return 0
2933 setup_quota_test || error "setup quota failed with $?"
2934 local dir="$DIR/$tdir/dir"
2935 mkdir $dir && change_project -s $dir
2936 lfs project -d $dir | grep P || error "inherit attribute should be set"
2938 change_project -C $dir
2939 lfs project -d $dir | grep P &&
2940 error "inherit attribute should be cleared"
2945 run_test 53 "Project inherit attribute could be cleared"
2948 ! is_project_quota_supported &&
2949 skip "Project quota is not supported" && return 0
2950 setup_quota_test || error "setup quota failed with $?"
2951 trap cleanup_quota_test EXIT
2952 local testfile="$DIR/$tdir/$tfile-0"
2954 #set project ID/inherit attribute
2955 change_project -sp $TSTPRJID $DIR/$tdir
2956 $RUNAS createmany -m ${testfile} 100 ||
2957 error "create many files failed"
2959 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2960 # one more count for directory itself */
2964 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2965 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2967 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2968 [ $proj_count1 -eq $proj_count ] ||
2969 error "c2: expected $proj_count got $proj_count1"
2971 #clear project but with kept projid
2972 change_project -rCk $DIR/$tdir
2973 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2974 [ $proj_count1 -eq $proj_count ] ||
2975 error "c3: expected $proj_count got $proj_count1"
2977 #verify projid untouched.
2978 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2980 [ $proj_count1 -eq $proj_count ] ||
2981 error "c4: expected $proj_count got $proj_count1"
2984 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2985 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2986 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2988 #this time clear all
2989 change_project -rC $DIR/$tdir
2990 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2991 [ $proj_count1 -eq 0 ] ||
2992 error "c6: expected 0 got $proj_count1"
2994 unlinkmany ${testfile} 100 ||
2995 error "unlink many files failed"
2999 run_test 54 "basic lfs project interface test"
3002 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3003 skip "Not supported before 2.10.58." && return
3004 setup_quota_test || error "setup quota failed with $?"
3006 set_ost_qtype $QTYPE || error "enable ost quota failed"
3009 #add second group to TSTUSR
3010 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3013 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3014 error "failed to dd"
3016 cancel_lru_locks osc
3017 sync; sync_all_data || true
3019 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3020 error "failed to setquota on group $TSTUSR2"
3022 $LFS quota -v -g $TSTUSR2 $DIR
3024 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3025 error "chgrp should failed with -EDQUOT"
3027 USED=$(getquota -g $TSTUSR2 global curspace)
3030 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3031 error "failed to setquota on group $TSTUSR2"
3033 $LFS quota -v -g $TSTUSR2 $DIR
3035 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3036 error "chgrp should succeed"
3038 $LFS quota -v -g $TSTUSR2 $DIR
3040 resetquota -g $TSTUSR2
3043 run_test 55 "Chgrp should be affected by group quota"
3046 setup_quota_test || error "setup quota failed with $?"
3048 set_ost_qtype $QTYPE || error "enable ost quota failed"
3051 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3052 erro "failed to set grace time for usr quota"
3053 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3054 awk '{print $4 $8}')
3055 if [ "x$grace_time" != "x10s;10s" ]; then
3056 $LFS quota -t -u $DIR
3057 error "expected grace time: 10s;10s, got:$grace_time"
3062 run_test 56 "lfs quota -t should work well"
3065 setup_quota_test || error "setup quota failed with $?"
3067 local dir="$DIR/$tdir/dir"
3070 #try to change pipe file should not hang and return failure
3071 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3072 awk -F ':' '{ print \\\$2 }'" \
3073 " failed to get xattr for '$dir/pipe'" || return 1
3074 #command can process further if it hit some errors
3075 touch $dir/aaa $dir/bbb
3076 #create one invalid link file
3077 ln -s $dir/not_exist_file $dir/ccc
3078 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3079 [ $cnt -eq 2 ] || error "expected 2 got $cnt"
3083 run_test 57 "lfs project could tolerate errors"
3086 if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3087 skip "ldiskfs only test"
3090 disable_project_quota
3091 setup_quota_test || error "setup quota failed with $?"
3094 local testfile="$DIR/$tdir/$tfile-0"
3095 #make sure it did not crash kernel
3096 touch $testfile && lfs project -sp 1 $testfile
3098 enable_project_quota
3101 run_test 59 "lfs project dosen't crash kernel with project disabled"
3104 setup_quota_test || error "setup quota failed with $?"
3105 trap cleanup_quota_test EXIT
3106 local testfile=$DIR/$tdir/$tfile
3109 set_mdt_qtype "ug" || error "enable mdt quota failed"
3111 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3112 error "set quota failed"
3113 quota_show_check a g $TSTUSR
3115 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3116 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3117 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3118 error "create many files failed"
3120 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3122 # root user can overrun quota
3123 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3124 error "root user should succeed"
3127 resetquota -g $TSTUSR
3129 run_test 60 "Test quota for root with setgid"
3131 # test default quota
3132 test_default_quota() {
3133 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3134 skip "Not supported before 2.11.51." && return
3139 local qprjid=$TSTPRJID
3143 local LIMIT=20480 #20M disk space
3144 local TESTFILE="$DIR/$tdir/$tfile-0"
3146 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3147 echo "Project quota is not supported" && return 0
3149 [ $qtype == "-u" ] && qdtype="-U"
3150 [ $qtype == "-g" ] && qdtype="-G"
3151 [ $qtype == "-p" ] && {
3156 [ $qpool == "meta" ] && {
3157 LIMIT=10240 #10K inodes
3162 setup_quota_test || error "setup quota failed with $?"
3163 trap cleanup_quota_test EXIT
3167 # enable mdt/ost quota
3168 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3169 set_ost_qtype $QTYPE || error "enable ost quota failed"
3171 log "set to use default quota"
3172 $LFS setquota $qtype $qid -d $DIR ||
3173 error "set $qid to use default quota failed"
3175 log "set default quota"
3176 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3177 error "set $qid default quota failed"
3179 log "get default quota"
3180 $LFS quota $qdtype $DIR || error "get default quota failed"
3182 if [ $qpool == "data" ]; then
3183 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3185 [ $SLIMIT -eq $LIMIT ] ||
3186 error "the returned default quota is wrong"
3188 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3190 [ $SLIMIT -eq $LIMIT ] ||
3191 error "the returned default quota is wrong"
3194 # make sure the system is clean
3195 local USED=$(getquota $qtype $qid global curspace)
3196 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3198 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3199 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3201 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3203 log "Test not out of quota"
3204 if [ $qpool == "data" ]; then
3205 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3206 quota_error $qtype $qid "write failed, expect succeed"
3208 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3209 quota_error $qtype $qid "create failed, expect succeed"
3211 unlinkmany $TESTFILE $((LIMIT/2))
3214 log "Test out of quota"
3215 # flush cache, ensure noquota flag is set on client
3216 cancel_lru_locks osc
3217 cancel_lru_locks mdc
3218 sync; sync_all_data || true
3219 if [ $qpool == "data" ]; then
3220 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3221 quota_error $qtype $qid "write succeed, expect EDQUOT"
3223 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3224 quota_error $qtype $qid "create succeed, expect EDQUOT"
3226 unlinkmany $TESTFILE $((LIMIT*2))
3229 log "Increase default quota"
3230 # increase default quota
3231 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3232 error "set default quota failed"
3234 cancel_lru_locks osc
3235 cancel_lru_locks mdc
3236 sync; sync_all_data || true
3237 if [ $qpool == "data" ]; then
3238 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3239 quota_error $qtype $qid "write failed, expect succeed"
3241 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3242 quota_error $qtype $qid "create failed, expect succeed"
3244 unlinkmany $TESTFILE $((LIMIT*2))
3247 log "Set quota to override default quota"
3248 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3249 error "set $qid quota failed"
3251 cancel_lru_locks osc
3252 cancel_lru_locks mdc
3253 sync; sync_all_data || true
3254 if [ $qpool == "data" ]; then
3255 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3256 quota_error $qtype $qid "write succeed, expect EQUOT"
3258 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3259 quota_error $qtype $qid "create succeed, expect EQUOT"
3261 unlinkmany $TESTFILE $((LIMIT*2))
3264 log "Set to use default quota again"
3265 $LFS setquota $qtype $qid -d $DIR ||
3266 error "set $qid to use default quota failed"
3268 cancel_lru_locks osc
3269 cancel_lru_locks mdc
3270 sync; sync_all_data || true
3271 if [ $qpool == "data" ]; then
3272 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3273 quota_error $qtype $qid "write failed, expect succeed"
3275 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3276 quota_error $qtype $qid "create failed, expect succeed"
3278 unlinkmany $TESTFILE $((LIMIT*2))
3283 wait_delete_completed || error "wait_delete_completed failed"
3284 sync_all_data || true
3285 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3286 error "reset default quota failed"
3287 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3288 error "reset quota failed"
3294 test_default_quota "-u" "data"
3295 test_default_quota "-u" "meta"
3296 test_default_quota "-g" "data"
3297 test_default_quota "-g" "meta"
3298 test_default_quota "-p" "data"
3299 test_default_quota "-p" "meta"
3301 run_test 61 "default quota tests"
3305 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3306 disable_project_quota
3308 reset_quota_settings
3313 check_and_cleanup_lustre
3314 export QUOTA_AUTO=$QUOTA_AUTO_OLD