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: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
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}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test:
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 $ZPOOL upgrade -v | grep project_quota && return 0
94 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
95 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
96 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
97 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
98 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
99 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
100 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
101 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
108 local fail_val=${3:-0}
112 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
113 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
114 ost) NODES="$(comma_list $(osts_nodes))";;
117 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
122 echo "lfs project $*"
123 lfs project $* || error "lfs project $* failed"
126 RUNAS="runas -u $TSTID -g $TSTID"
127 RUNAS2="runas -u $TSTID2 -g $TSTID2"
128 DD="dd if=/dev/zero bs=1M"
132 # clear quota limits for a user or a group
133 # usage: resetquota -u username
134 # resetquota -g groupname
135 # resetquota -p projid
138 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
139 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
140 error "resetquota: wrong specifier $1 passed"
142 if [ $1 == "-p" ]; then
143 is_project_quota_supported || return 0
146 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
147 error "clear quota for [type:$1 name:$2] failed"
148 # give a chance to slave to release space
156 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
157 $LFS quota -v -u $local_id $DIR
158 log "Files for user ($local_id):"
159 ($LFS find --user $local_id $DIR | head -n 4 |
160 xargs stat 2>/dev/null)
163 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
164 $LFS quota -v -g $local_id $DIR
165 log "Files for group ($local_id):"
166 ($LFS find --group $local_id $DIR | head -n 4 |
167 xargs stat 2>/dev/null)
170 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
171 $LFS quota -v -p $TSTPRJID $DIR
172 log "Files for project ($TSTPRJID):"
173 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
174 xargs stat 2>/dev/null)
190 # get quota for a user or a group
191 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
192 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
197 sync_all_data > /dev/null 2>&1 || true
199 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
200 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
201 error "getquota: wrong u/g/p specifier $1 passed"
214 *) error "unknown quota parameter $4";;
217 [ "$uuid" = "global" ] && uuid=$DIR
219 $LFS quota -v "$1" "$2" $DIR |
220 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
221 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
226 # usage: set_mdt_qtype ugp|u|g|p|none
230 local mdts=$(get_facets MDS)
232 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
233 qtype=$(tr -d 'p' <<<$qtype)
235 if [[ $PERM_CMD == *"set_param -P"* ]]; then
236 do_facet mgs $PERM_CMD \
237 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
239 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
241 # we have to make sure each MDT received config changes
242 for mdt in ${mdts//,/ }; do
244 cmd="$LCTL get_param -n "
245 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
246 cmd=${cmd}.quota_slave.enabled
248 if $(facet_up $mdt); then
249 wait_update_facet $mdt "$cmd" "$qtype" || return 1
256 # usage: set_ost_qtype ugp|u|g|p|none
260 local osts=$(get_facets OST)
262 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
263 qtype=$(tr -d 'p' <<<$qtype)
265 if [[ $PERM_CMD == *"set_param -P"* ]]; then
266 do_facet mgs $PERM_CMD \
267 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
269 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
271 # we have to make sure each OST received config changes
272 for ost in ${osts//,/ }; do
274 cmd="$LCTL get_param -n "
275 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
276 cmd=${cmd}.quota_slave.enabled
278 if $(facet_up $ost); then
279 wait_update_facet $ost "$cmd" "$qtype" || return 1
285 wait_reintegration() {
289 local result="glb[1],slv[1],reint[0]"
294 if [ $ntype == "mdt" ]; then
295 tgts=$(get_facets MDS)
297 tgts=$(get_facets OST)
300 for tgt in ${tgts//,/ }; do
302 cmd="$LCTL get_param -n "
303 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
304 cmd=${cmd}.quota_slave.info
306 if $(facet_up $tgt); then
307 wait_update_facet $tgt "$cmd |
308 grep "$qtype" | awk '{ print \\\$3 }'" \
309 "$result" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "mdt" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "mdt" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "mdt" "project" $max || return 1
338 if [[ "$qtype" =~ "u" ]]; then
339 wait_reintegration "ost" "user" $max || return 1
342 if [[ "$qtype" =~ "g" ]]; then
343 wait_reintegration "ost" "group" $max || return 1
346 if [[ "$qtype" =~ "p" ]]; then
347 ! is_project_quota_supported && return 0
348 wait_reintegration "ost" "project" $max || return 1
353 disable_project_quota() {
354 is_project_quota_supported || return 0
355 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
356 stopall || error "failed to stopall (1)"
358 for num in $(seq $MDSCOUNT); do
359 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
360 error "tune2fs $(mdsdevname $num) failed"
363 for num in $(seq $OSTCOUNT); do
364 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
365 error "tune2fs $(ostdevname $num) failed"
373 wait_delete_completed
374 echo "Creating test directory"
375 mkdir $DIR/$tdir || return 1
376 chmod 0777 $DIR/$tdir || return 2
377 # always clear fail_loc in case of fail_loc isn't cleared
378 # properly when previous test failed
379 lustre_fail mds_ost 0
382 cleanup_quota_test() {
384 echo "Delete files..."
386 echo "Wait for unlink objects finished..."
387 wait_delete_completed
388 sync_all_data || true
398 $LFS quota -v -$ugp $qid $DIR
400 if [ "$bf" == "a" -o "$bf" == "b" ]; then
401 usage=$(getquota -$ugp $qid global curspace)
402 if [ -z $usage ]; then
403 quota_error $ugp $qid \
404 "Query block quota failed ($ugp:$qid)."
406 [ $usage -ne 0 ] && quota_log $ugp $qid \
407 "Block quota isn't 0 ($ugp:$qid:$usage)."
411 if [ "$bf" == "a" -o "$bf" == "f" ]; then
412 usage=$(getquota -$ugp $qid global curinodes)
413 if [ -z $usage ]; then
414 quota_error $ugp $qid \
415 "Query file quota failed ($ugp:$qid)."
417 [ $usage -ne 0 ] && quota_log $ugp $qid \
418 "File quota isn't 0 ($ugp:$qid:$usage)."
423 enable_project_quota() {
424 is_project_quota_supported || return 0
425 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
426 stopall || error "failed to stopall (1)"
428 for num in $(seq $MDSCOUNT); do
429 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
430 error "tune2fs $(mdsdevname $num) failed"
433 for num in $(seq $OSTCOUNT); do
434 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
435 error "tune2fs $(ostdevname $num) failed"
442 project_quota_enabled () {
444 for num in $(seq $MDSCOUNT); do
445 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
446 grep -q project || rc=1
448 for num in $(seq $OSTCOUNT); do
449 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
450 grep -q project || rc=1
452 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
456 project_quota_enabled || enable_project_quota
458 reset_quota_settings() {
459 resetquota -u $TSTUSR
460 resetquota -g $TSTUSR
461 resetquota -u $TSTUSR2
462 resetquota -g $TSTUSR2
463 resetquota -p $TSTPRJID
468 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
473 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
474 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
475 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
476 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
478 test_quota_performance() {
479 local TESTFILE="$DIR/$tdir/$tfile-0"
480 local size=$1 # in MB
481 local stime=$(date +%s)
482 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
483 quota_error u $TSTUSR "write failure"
484 local etime=$(date +%s)
485 delta=$((etime - stime))
486 if [ $delta -gt 0 ]; then
487 rate=$((size * 1024 / delta))
488 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
489 # LU-2872 - see LU-2887 for fix
491 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
493 [ $rate -gt 1024 ] ||
494 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
500 # test basic quota performance b=21696
503 [ "$SLOW" = "no" ] && MB=10
505 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
506 [ $free_space -le $((MB * 1024)) ] &&
507 skip "not enough space ${free_space} KB, " \
508 "required $((MB * 1024)) KB"
509 setup_quota_test || error "setup quota failed with $?"
510 trap cleanup_quota_test EXIT
512 set_ost_qtype "none" || error "disable ost quota failed"
513 test_quota_performance $MB
515 set_ost_qtype $QTYPE || error "enable ost quota failed"
516 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
517 error "set quota failed"
518 test_quota_performance $MB
522 run_test 0 "Test basic quota performance"
524 # test block hardlimit
527 local TESTFILE="$DIR/$tdir/$tfile-0"
529 setup_quota_test || error "setup quota failed with $?"
530 trap cleanup_quota_test EXIT
533 set_ost_qtype $QTYPE || error "enable ost quota failed"
536 log "User quota (block hardlimit:$LIMIT MB)"
537 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
538 error "set user quota failed"
540 # make sure the system is clean
541 local USED=$(getquota -u $TSTUSR global curspace)
542 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
544 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
545 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
548 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
549 quota_error u $TSTUSR "user write failure, but expect success"
550 log "Write out of block quota ..."
551 # this time maybe cache write, ignore it's failure
552 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
553 # flush cache, ensure noquota flag is set on client
555 sync; sync_all_data || true
556 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
557 quota_error u $TSTUSR "user write success, but expect EDQUOT"
560 wait_delete_completed || error "wait_delete_completed failed"
561 sync_all_data || true
562 USED=$(getquota -u $TSTUSR global curspace)
563 [ $USED -ne 0 ] && quota_error u $TSTUSR \
564 "user quota isn't released after deletion"
565 resetquota -u $TSTUSR
568 log "--------------------------------------"
569 log "Group quota (block hardlimit:$LIMIT MB)"
570 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
571 error "set group quota failed"
573 TESTFILE="$DIR/$tdir/$tfile-1"
574 # make sure the system is clean
575 USED=$(getquota -g $TSTUSR global curspace)
576 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
578 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
579 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
582 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
583 quota_error g $TSTUSR "Group write failure, but expect success"
584 log "Write out of block quota ..."
585 # this time maybe cache write, ignore it's failure
586 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
588 sync; sync_all_data || true
589 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
590 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
592 wait_delete_completed || error "wait_delete_completed failed"
593 sync_all_data || true
594 USED=$(getquota -g $TSTUSR global curspace)
595 [ $USED -ne 0 ] && quota_error g $TSTUSR \
596 "Group quota isn't released after deletion"
597 resetquota -g $TSTUSR
599 if ! is_project_quota_supported; then
600 echo "Project quota is not supported"
605 TESTFILE="$DIR/$tdir/$tfile-2"
606 # make sure the system is clean
607 USED=$(getquota -p $TSTPRJID global curspace)
609 error "used space($USED) for project $TSTPRJID isn't 0"
612 log "--------------------------------------"
613 log "Project quota (block hardlimit:$LIMIT mb)"
614 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
615 error "set project quota failed"
617 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
618 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
619 change_project -p $TSTPRJID $TESTFILE
622 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
623 "project write failure, but expect success"
624 log "write out of block quota ..."
625 # this time maybe cache write, ignore it's failure
626 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
628 sync; sync_all_data || true
629 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
630 $TSTPRJID "project write success, but expect EDQUOT"
635 USED=$(getquota -p $TSTPRJID global curspace)
636 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
637 "project quota isn't released after deletion"
639 run_test 1 "Block hard limit (normal use and out of quota)"
641 # test inode hardlimit
643 local LIMIT=$((1024 * 1024)) # 1M inodes
644 local TESTFILE="$DIR/$tdir/$tfile-0"
646 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
648 local FREE_INODES=$(mdt_free_inodes 0)
649 echo "$FREE_INODES free inodes on master MDT"
650 [ $FREE_INODES -lt $LIMIT ] &&
651 skip "not enough free inodes $FREE_INODES required $LIMIT"
653 setup_quota_test || error "setup quota failed with $?"
654 trap cleanup_quota_test EXIT
657 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
660 log "User quota (inode hardlimit:$LIMIT files)"
661 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
662 error "set user quota failed"
664 # make sure the system is clean
665 local USED=$(getquota -u $TSTUSR global curinodes)
666 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
668 log "Create $LIMIT files ..."
669 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
670 quota_error u $TSTUSR "user create failure, but expect success"
671 log "Create out of file quota ..."
672 $RUNAS touch ${TESTFILE}_xxx &&
673 quota_error u $TSTUSR "user create success, but expect EDQUOT"
676 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
677 rm -f ${TESTFILE}_xxx
678 wait_delete_completed
680 USED=$(getquota -u $TSTUSR global curinodes)
681 [ $USED -ne 0 ] && quota_error u $TSTUSR \
682 "user quota isn't released after deletion"
683 resetquota -u $TSTUSR
686 log "--------------------------------------"
687 log "Group quota (inode hardlimit:$LIMIT files)"
688 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
689 error "set group quota failed"
691 TESTFILE=$DIR/$tdir/$tfile-1
692 # make sure the system is clean
693 USED=$(getquota -g $TSTUSR global curinodes)
694 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
696 log "Create $LIMIT files ..."
697 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
698 quota_error g $TSTUSR "group create failure, but expect success"
699 log "Create out of file quota ..."
700 $RUNAS touch ${TESTFILE}_xxx &&
701 quota_error g $TSTUSR "group create success, but expect EDQUOT"
704 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
705 rm -f ${TESTFILE}_xxx
706 wait_delete_completed
708 USED=$(getquota -g $TSTUSR global curinodes)
709 [ $USED -ne 0 ] && quota_error g $TSTUSR \
710 "user quota isn't released after deletion"
712 resetquota -g $TSTUSR
713 ! is_project_quota_supported && cleanup_quota_test &&
714 echo "Skip project quota is not supported" && return 0
717 log "--------------------------------------"
718 log "Project quota (inode hardlimit:$LIMIT files)"
719 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
720 error "set project quota failed"
722 TESTFILE=$DIR/$tdir/$tfile-1
723 # make sure the system is clean
724 USED=$(getquota -p $TSTPRJID global curinodes)
726 error "Used inodes($USED) for project $TSTPRJID isn't 0"
728 change_project -sp $TSTPRJID $DIR/$tdir
729 log "Create $LIMIT files ..."
730 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
731 $TSTPRJID "project create fail, but expect success"
732 log "Create out of file quota ..."
733 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
734 "project create success, but expect EDQUOT"
735 change_project -C $DIR/$tdir
738 USED=$(getquota -p $TSTPRJID global curinodes)
739 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
740 "project quota isn't released after deletion"
743 run_test 2 "File hard limit (normal use and out of quota)"
747 local TIMER=$(($2 * 3 / 2))
753 trap cleanup_quota_test EXIT
755 $LFS setstripe $TESTFILE -c 1 -i 0
756 chown $TSTUSR.$TSTUSR $TESTFILE
757 [ "$qtype" == "p" ] && is_project_quota_supported &&
758 change_project -p $TSTPRJID $TESTFILE
760 echo "Write up to soft limit"
761 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
762 quota_error a $TSTUSR "write failure, but expect success"
763 OFFSET=$((LIMIT * 1024))
766 echo "Write to exceed soft limit"
767 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
768 quota_error a $TSTUSR "write failure, but expect success"
769 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
775 $SHOW_QUOTA_INFO_USER
776 $SHOW_QUOTA_INFO_GROUP
777 $SHOW_QUOTA_INFO_PROJID
779 echo "Write before timer goes off"
780 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
781 quota_error a $TSTUSR "write failure, but expect success"
782 OFFSET=$((OFFSET + 1024))
785 echo "Sleep $TIMER seconds ..."
791 $SHOW_QUOTA_INFO_USER
792 $SHOW_QUOTA_INFO_GROUP
793 $SHOW_QUOTA_INFO_PROJID
795 echo "Write after timer goes off"
796 # maybe cache write, ignore.
797 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
798 OFFSET=$((OFFSET + 1024))
800 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
801 quota_error a $TSTUSR "write success, but expect EDQUOT"
806 $SHOW_QUOTA_INFO_USER
807 $SHOW_QUOTA_INFO_GROUP
808 $SHOW_QUOTA_INFO_PROJID
810 echo "Unlink file to stop timer"
812 wait_delete_completed
813 sync_all_data || true
818 $SHOW_QUOTA_INFO_USER
819 $SHOW_QUOTA_INFO_GROUP
820 $SHOW_QUOTA_INFO_PROJID
822 $LFS setstripe $TESTFILE -c 1 -i 0
823 chown $TSTUSR.$TSTUSR $TESTFILE
824 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
827 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
828 quota_error a $TSTUSR "write failure, but expect success"
837 local TESTFILE=$DIR/$tdir/$tfile-0
839 set_ost_qtype $QTYPE || error "enable ost quota failed"
841 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
842 # make sure the system is clean
843 local USED=$(getquota -u $TSTUSR global curspace)
844 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
846 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
847 $MAX_IQ_TIME $DIR || error "set user grace time failed"
848 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
849 error "set user quota failed"
851 test_block_soft $TESTFILE $GRACE $LIMIT "u"
853 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
854 TESTFILE=$DIR/$tdir/$tfile-1
855 # make sure the system is clean
856 USED=$(getquota -g $TSTUSR global curspace)
857 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
859 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
860 $MAX_IQ_TIME $DIR || error "set group grace time failed"
861 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
862 error "set group quota failed"
864 test_block_soft $TESTFILE $GRACE $LIMIT "g"
866 if is_project_quota_supported; then
867 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
868 TESTFILE=$DIR/$tdir/$tfile-2
869 # make sure the system is clean
870 USED=$(getquota -p $TSTPRJID global curspace)
871 [ $USED -ne 0 ] && error \
872 "Used space($USED) for project $TSTPRJID isn't 0."
874 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
876 error "set project grace time failed"
877 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
878 $DIR || error "set project quota failed"
880 test_block_soft $TESTFILE $GRACE $LIMIT "p"
881 resetquota -p $TSTPRJID
882 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
884 error "restore project grace time failed"
888 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
889 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
890 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
891 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
893 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
899 local TIMER=$(($grace * 3 / 2))
902 trap cleanup_quota_test EXIT
903 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
905 echo "Create files to exceed soft limit"
906 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
907 quota_error a $TSTUSR "create failure, but expect success"
908 local trigger_time=$(date +%s)
910 sync_all_data || true
912 local cur_time=$(date +%s)
913 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
914 error "Passed grace time $grace, $trigger_time, $cur_time"
916 echo "Create file before timer goes off"
917 $RUNAS touch ${TESTFILE}_before ||
918 quota_error a $TSTUSR "failed create before timer expired," \
919 "but expect success. $trigger_time, $cur_time"
920 sync_all_data || true
922 echo "Sleep $TIMER seconds ..."
928 $SHOW_QUOTA_INFO_USER
929 $SHOW_QUOTA_INFO_GROUP
930 $SHOW_QUOTA_INFO_PROJID
932 echo "Create file after timer goes off"
933 # There is a window that space is accounted in the quota usage but
934 # hasn't been decreased from the pending write, if we acquire quota
935 # in this window, we'll acquire more than we needed.
936 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
937 sync_all_data || true
938 $RUNAS touch ${TESTFILE}_after_3 &&
939 quota_error a $TSTUSR "create after timer expired," \
941 sync_all_data || true
946 $SHOW_QUOTA_INFO_USER
947 $SHOW_QUOTA_INFO_GROUP
948 $SHOW_QUOTA_INFO_PROJID
950 echo "Unlink files to stop timer"
951 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
952 wait_delete_completed
955 $RUNAS touch ${TESTFILE}_xxx ||
956 quota_error a $TSTUSR "touch after timer stop failure," \
958 sync_all_data || true
966 local LIMIT=10 # inodes
967 local TESTFILE=$DIR/$tdir/$tfile-0
970 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
972 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
973 # make sure the system is clean
974 local USED=$(getquota -u $TSTUSR global curinodes)
975 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
977 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
978 $GRACE $DIR || error "set user grace time failed"
979 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
980 error "set user quota failed"
982 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
984 test_file_soft $TESTFILE $LIMIT $GRACE
986 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
987 # make sure the system is clean
988 USED=$(getquota -g $TSTUSR global curinodes)
989 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
991 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
992 $GRACE $DIR || error "set group grace time failed"
993 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
994 error "set group quota failed"
995 TESTFILE=$DIR/$tdir/$tfile-1
997 test_file_soft $TESTFILE $LIMIT $GRACE
999 if is_project_quota_supported; then
1000 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1001 # make sure the system is clean
1002 USED=$(getquota -p $TSTPRJID global curinodes)
1003 [ $USED -ne 0 ] && error \
1004 "Used space($USED) for project $TSTPRJID isn't 0."
1006 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1007 $GRACE $DIR || error "set project grace time failed"
1008 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1009 error "set project quota failed"
1011 TESTFILE=$DIR/$tdir/$tfile-1
1012 # one less than limit, because of parent directory included.
1013 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1014 resetquota -p $TSTPRJID
1015 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1016 $MAX_IQ_TIME $DIR ||
1017 error "restore project grace time failed"
1021 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1022 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1023 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1024 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1026 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1029 local GR_STR1="1w3d"
1030 local GR_STR2="1000s"
1032 local GR_STR4="1w2d3h4m5s"
1034 local GR_STR6="18446744073709551615"
1037 wait_delete_completed
1039 # test of valid grace strings handling
1040 echo "Valid grace strings test"
1041 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1042 $GR_STR2 $DIR || error "set user grace time failed"
1043 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1044 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1045 $GR_STR4 $DIR || error "set group grace time quota failed"
1046 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1048 # test of invalid grace strings handling
1049 echo " Invalid grace strings test"
1050 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1051 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1052 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1056 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1057 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1058 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1059 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1061 run_test 4b "Grace time strings handling"
1063 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1065 local BLIMIT=10 # 10M
1066 local ILIMIT=10 # 10 inodes
1068 setup_quota_test || error "setup quota failed with $?"
1069 trap cleanup_quota_test EXIT
1071 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1072 set_ost_qtype $QTYPE || error "enable ost quota failed"
1074 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1075 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1076 error "set user quota failed"
1077 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1078 if is_project_quota_supported; then
1079 error "set group quota failed"
1080 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1081 -I $ILIMIT $DIR || error "set project quota failed"
1084 # make sure the system is clean
1085 local USED=$(getquota -u $TSTUSR global curinodes)
1086 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1087 USED=$(getquota -g $TSTUSR global curinodes)
1088 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1089 USED=$(getquota -u $TSTUSR global curspace)
1090 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1091 USED=$(getquota -g $TSTUSR global curspace)
1092 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1093 if is_project_quota_supported; then
1094 USED=$(getquota -p $TSTPRJID global curinodes)
1096 error "Used inode($USED) for project $TSTPRJID isn't 0."
1097 USED=$(getquota -p $TSTPRJID global curspace)
1099 error "Used block($USED) for project $TSTPRJID isn't 0."
1102 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1103 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1104 error "create failure, expect success"
1105 if is_project_quota_supported; then
1106 touch $DIR/$tdir/$tfile-0_1
1107 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1109 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1110 error "write failure, expect success"
1112 echo "Chown files to $TSTUSR.$TSTUSR ..."
1113 for i in $(seq 0 $ILIMIT); do
1114 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1115 quota_error a $TSTUSR "chown failure, expect success"
1119 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1120 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1123 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1125 # test dropping acquire request on master
1129 # Clear dmesg so watchdog is not triggered by previous
1131 do_facet ost1 dmesg -c > /dev/null
1133 setup_quota_test || error "setup quota failed with $?"
1134 trap cleanup_quota_test EXIT
1136 # make sure the system is clean
1137 local USED=$(getquota -u $TSTUSR global curspace)
1138 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1140 # make sure no granted quota on ost
1141 set_ost_qtype $QTYPE || error "enable ost quota failed"
1142 resetquota -u $TSTUSR
1144 # create file for $TSTUSR
1145 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1146 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1147 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1149 # create file for $TSTUSR2
1150 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1151 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1152 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1154 # cache per-ID lock for $TSTUSR on slave
1155 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1156 error "set quota failed"
1157 $RUNAS $DD of=$TESTFILE count=1 ||
1158 error "write $TESTFILE failure, expect success"
1159 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1160 error "write $TESTFILE2 failure, expect success"
1162 sync_all_data || true
1164 #define QUOTA_DQACQ 601
1165 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1166 lustre_fail mds 0x513 601
1168 do_facet ost1 $LCTL set_param \
1169 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1171 # write to un-enforced ID ($TSTUSR2) should succeed
1172 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1173 error "write failure, expect success"
1175 # write to enforced ID ($TSTUSR) in background, exceeding limit
1176 # to make sure DQACQ is sent
1177 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1180 # watchdog timer uses a factor of 2
1181 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1182 sleep $((TIMEOUT * 2 + 1))
1184 # write should be blocked and never finished
1185 if ! ps -p $DDPID > /dev/null 2>&1; then
1187 error "write finished incorrectly!"
1192 # no watchdog is triggered
1193 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1194 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1195 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1196 [ -z "$watchdog" ] || error "$watchdog"
1198 rm -f $TMP/lustre-log-${TESTNAME}.log
1200 # write should continue then fail with EDQUOT
1204 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1205 if [ $count -ge 240 ]; then
1206 quota_error u $TSTUSR "dd not finished in $count secs"
1208 count=$((count + 1))
1209 if [ $((count % 30)) -eq 0 ]; then
1210 c_size=$(stat -c %s $TESTFILE)
1211 echo "Waiting $count secs. $c_size"
1219 run_test 6 "Test dropping acquire request on master"
1221 # quota reintegration (global index)
1223 local TESTFILE=$DIR/$tdir/$tfile
1224 local LIMIT=20 # 20M
1226 [ "$SLOW" = "no" ] && LIMIT=5
1228 setup_quota_test || error "setup quota failed with $?"
1229 trap cleanup_quota_test EXIT
1231 # make sure the system is clean
1232 local USED=$(getquota -u $TSTUSR global curspace)
1233 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1235 # make sure no granted quota on ost1
1236 set_ost_qtype $QTYPE || error "enable ost quota failed"
1237 resetquota -u $TSTUSR
1238 set_ost_qtype "none" || error "disable ost quota failed"
1240 local OSTUUID=$(ostuuid_from_index 0)
1241 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1243 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1246 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1247 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1252 echo "Enable quota & set quota limit for $TSTUSR"
1253 set_ost_qtype $QTYPE || error "enable ost quota failed"
1254 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1255 error "set quota failed"
1257 echo "Start ost1..."
1258 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1261 wait_ost_reint $QTYPE || error "reintegration failed"
1263 # hardlimit should have been fetched by slave during global
1264 # reintegration, write will exceed quota
1265 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1266 quota_error u $TSTUSR "write success, but expect EDQUOT"
1269 wait_delete_completed
1270 sync_all_data || true
1276 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1277 error "clear quota failed"
1279 echo "Start ost1..."
1280 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1283 wait_ost_reint $QTYPE || error "reintegration failed"
1285 # hardlimit should be cleared on slave during reintegration
1286 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1287 quota_error u $TSTUSR "write error, but expect success"
1291 run_test 7a "Quota reintegration (global index)"
1293 # quota reintegration (slave index)
1296 local TESTFILE=$DIR/$tdir/$tfile
1298 setup_quota_test || error "setup quota failed with $?"
1299 trap cleanup_quota_test EXIT
1301 # make sure the system is clean
1302 local USED=$(getquota -u $TSTUSR global curspace)
1303 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1305 # make sure no granted quota on ost1
1306 set_ost_qtype $QTYPE || error "enable ost quota failed"
1307 resetquota -u $TSTUSR
1308 set_ost_qtype "none" || error "disable ost quota failed"
1310 local OSTUUID=$(ostuuid_from_index 0)
1311 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1313 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1316 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1317 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1319 # consume some space to make sure the granted space will not
1320 # be released during reconciliation
1321 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1322 error "consume space failure, expect success"
1324 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1325 lustre_fail mds 0xa02
1327 set_ost_qtype $QTYPE || error "enable ost quota failed"
1328 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1329 error "set quota failed"
1331 # ignore the write error
1332 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1334 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1338 echo "Restart ost to trigger reintegration..."
1340 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1343 wait_ost_reint $QTYPE || error "reintegration failed"
1345 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1346 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1351 run_test 7b "Quota reintegration (slave index)"
1353 # quota reintegration (restart mds during reintegration)
1355 local LIMIT=20 # 20M
1356 local TESTFILE=$DIR/$tdir/$tfile
1358 [ "$SLOW" = "no" ] && LIMIT=5
1360 setup_quota_test || error "setup quota failed with $?"
1361 trap cleanup_quota_test EXIT
1363 # make sure the system is clean
1364 local USED=$(getquota -u $TSTUSR global curspace)
1365 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1367 set_ost_qtype "none" || error "disable ost quota failed"
1368 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1369 error "set quota failed"
1371 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1372 lustre_fail ost 0xa03
1375 set_ost_qtype $QTYPE || error "enable ost quota failed"
1376 # trigger reintegration
1377 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1378 procf=${procf}quota_slave.force_reint
1379 do_facet ost1 $LCTL set_param $procf=1 ||
1380 error "force reintegration failed"
1388 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1391 # wait longer than usual to make sure the reintegration
1392 # is triggered by quota wb thread.
1393 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1395 # hardlimit should have been fetched by slave during global
1396 # reintegration, write will exceed quota
1397 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1398 quota_error u $TSTUSR "write success, but expect EDQUOT"
1402 run_test 7c "Quota reintegration (restart mds during reintegration)"
1404 # Quota reintegration (Transfer index in multiple bulks)
1406 local TESTFILE=$DIR/$tdir/$tfile
1407 local TESTFILE1="$DIR/$tdir/$tfile"-1
1410 setup_quota_test || error "setup quota failed with $?"
1411 trap cleanup_quota_test EXIT
1413 set_ost_qtype "none" || error "disable ost quota failed"
1414 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1415 error "set quota for $TSTUSR failed"
1416 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1417 error "set quota for $TSTUSR2 failed"
1419 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1420 lustre_fail mds 0x608 0
1422 # enable quota to tirgger reintegration
1423 set_ost_qtype "u" || error "enable ost quota failed"
1424 wait_ost_reint "u" || error "reintegration failed"
1428 # hardlimit should have been fetched by slave during global
1429 # reintegration, write will exceed quota
1430 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1431 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1433 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1434 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1438 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1440 # quota reintegration (inode limits)
1442 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1444 # LU-2435: skip this quota test if underlying zfs version has not
1445 # supported native dnode accounting
1446 [ "$(facet_fstype mds1)" == "zfs" ] && {
1447 local F="feature@userobj_accounting"
1448 local pool=$(zpool_name mds1)
1449 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1451 [[ "$feature" != *" active "* ]] &&
1452 skip "requires zpool with active userobj_accounting"
1455 local ilimit=$((1024 * 2)) # 2k inodes
1456 local TESTFILE=$DIR/${tdir}-1/$tfile
1458 setup_quota_test || error "setup quota failed with $?"
1459 trap cleanup_quota_test EXIT
1461 # make sure the system is clean
1462 local USED=$(getquota -u $TSTUSR global curinodes)
1463 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1465 # make sure no granted quota on mdt1
1466 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1467 resetquota -u $TSTUSR
1468 set_mdt_qtype "none" || error "disable mdt quota failed"
1470 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1471 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1472 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1475 echo "Stop mds${MDSCOUNT}..."
1478 echo "Enable quota & set quota limit for $TSTUSR"
1479 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1480 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1481 error "set quota failed"
1483 echo "Start mds${MDSCOUNT}..."
1484 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1487 wait_mdt_reint $QTYPE || error "reintegration failed"
1489 echo "create remote dir"
1490 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1491 error "create remote dir failed"
1492 chmod 0777 $DIR/${tdir}-1
1494 # hardlimit should have been fetched by slave during global
1495 # reintegration, create will exceed quota
1496 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1497 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1499 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1500 wait_delete_completed
1501 sync_all_data || true
1503 echo "Stop mds${MDSCOUNT}..."
1506 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1507 error "clear quota failed"
1509 echo "Start mds${MDSCOUNT}..."
1510 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1513 wait_mdt_reint $QTYPE || error "reintegration failed"
1515 # hardlimit should be cleared on slave during reintegration
1516 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1517 quota_error u $TSTUSR "create failed, expect success"
1519 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1520 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
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
1559 run_test 8 "Run dbench with quota enabled"
1561 # this check is just for test_9
1562 OST0_MIN=4900000 #4.67G
1564 check_whether_skip () {
1565 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1566 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1567 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1568 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1575 # run for fixing bug10707, it needs a big room. test for 64bit
1577 local filesize=$((1024 * 9 / 2)) # 4.5G
1579 check_whether_skip && return 0
1581 setup_quota_test || error "setup quota failed with $?"
1582 trap cleanup_quota_test EXIT
1584 set_ost_qtype "ug" || error "enable ost quota failed"
1586 local TESTFILE="$DIR/$tdir/$tfile-0"
1587 local BLK_LIMIT=100G #100G
1588 local FILE_LIMIT=1000000
1590 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1592 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1594 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1595 error "set user quota failed"
1597 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1598 "for group: $TSTUSR"
1599 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1600 error "set group quota failed"
1602 quota_show_check a u $TSTUSR
1603 quota_show_check a g $TSTUSR
1605 echo "Create test file"
1606 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1607 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1609 log "Write the big file of 4.5G ..."
1610 $RUNAS $DD of=$TESTFILE count=$filesize ||
1611 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1621 run_test 9 "Block limit larger than 4GB (b10707)"
1624 local TESTFILE=$DIR/$tdir/$tfile
1626 setup_quota_test || error "setup quota failed with $?"
1627 trap cleanup_quota_test EXIT
1629 # set limit to root user should fail
1630 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1631 error "set limit for root user successfully, expect failure"
1632 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1633 error "set limit for root group successfully, expect failure"
1634 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1635 error "set limit for project 0 successfully, expect failure"
1637 # root user can overrun quota
1638 set_ost_qtype "ug" || error "enable ost quota failed"
1640 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1641 error "set quota failed"
1642 quota_show_check b u $TSTUSR
1644 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1645 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1647 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1648 error "write failure, expect success"
1652 run_test 10 "Test quota for root user"
1655 local TESTFILE=$DIR/$tdir/$tfile
1656 setup_quota_test || error "setup quota failed with $?"
1657 trap cleanup_quota_test EXIT
1659 set_mdt_qtype "ug" || error "enable mdt quota failed"
1660 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1661 error "set quota failed"
1663 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1664 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1666 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1667 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1670 local USED=$(getquota -u $TSTUSR global curinodes)
1671 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1675 run_test 11 "Chown/chgrp ignores quota"
1678 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1680 local blimit=22 # 22M
1681 local blk_cnt=$((blimit - 5))
1682 local TESTFILE0="$DIR/$tdir/$tfile"-0
1683 local TESTFILE1="$DIR/$tdir/$tfile"-1
1685 setup_quota_test || error "setup quota failed with $?"
1686 trap cleanup_quota_test EXIT
1688 set_ost_qtype "u" || error "enable ost quota failed"
1689 quota_show_check b u $TSTUSR
1691 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1692 error "set quota failed"
1694 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1695 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1696 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1697 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1699 echo "Write to ost0..."
1700 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1701 quota_error a $TSTUSR "dd failed"
1703 echo "Write to ost1..."
1704 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1705 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1707 echo "Free space from ost0..."
1709 wait_delete_completed
1710 sync_all_data || true
1712 echo "Write to ost1 after space freed from ost0..."
1713 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1714 quota_error a $TSTUSR "rebalancing failed"
1718 run_test 12a "Block quota rebalancing"
1721 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1723 local ilimit=$((1024 * 2)) # 2k inodes
1724 local TESTFILE0=$DIR/$tdir/$tfile
1725 local TESTFILE1=$DIR/${tdir}-1/$tfile
1727 setup_quota_test || error "setup quota failed with $?"
1728 trap cleanup_quota_test EXIT
1730 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1731 chmod 0777 $DIR/${tdir}-1
1733 set_mdt_qtype "u" || error "enable mdt quota failed"
1734 quota_show_check f u $TSTUSR
1736 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1737 error "set quota failed"
1739 echo "Create $ilimit files on mdt0..."
1740 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1741 quota_error u $TSTUSR "create failed, but expect success"
1743 echo "Create files on mdt1..."
1744 $RUNAS createmany -m $TESTFILE1 1 &&
1745 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1747 echo "Free space from mdt0..."
1748 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1749 wait_delete_completed
1750 sync_all_data || true
1752 echo "Create files on mdt1 after space freed from mdt0..."
1753 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1754 quota_error a $TSTUSR "rebalancing failed"
1756 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1757 error "unlink mdt1 files failed"
1758 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1762 run_test 12b "Inode quota rebalancing"
1765 local TESTFILE=$DIR/$tdir/$tfile
1766 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1767 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1769 setup_quota_test || error "setup quota failed with $?"
1770 trap cleanup_quota_test EXIT
1772 set_ost_qtype "u" || error "enable ost quota failed"
1773 quota_show_check b u $TSTUSR
1775 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1776 error "set quota failed"
1777 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1778 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1780 # clear the locks in cache first
1781 do_facet ost1 $LCTL set_param -n $procf=clear
1782 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1783 [ $nlock -eq 0 ] || error "$nlock cached locks"
1785 # write to acquire the per-ID lock
1786 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1787 quota_error a $TSTUSR "dd failed"
1789 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1790 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1792 # clear quota doesn't trigger per-ID lock cancellation
1793 resetquota -u $TSTUSR
1794 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1795 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1797 # clear the per-ID lock
1798 do_facet ost1 $LCTL set_param -n $procf=clear
1799 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1800 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1802 # spare quota should be released
1803 local OSTUUID=$(ostuuid_from_index 0)
1804 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1805 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1806 [ $limit -le $space ] ||
1807 error "spare quota isn't released, limit:$limit, space:$space"
1811 run_test 13 "Cancel per-ID lock in the LRU list"
1814 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1816 wait_delete_completed
1817 sync_all_data || true
1820 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1821 error "set user quota failed"
1822 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1823 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1824 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1825 resetquota -u $TSTUSR
1828 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1829 error "set group quota failed"
1830 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1831 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1832 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1833 resetquota -g $TSTUSR
1835 run_test 15 "Set over 4T block quota"
1839 local BLKS=1 # 1M less than limit
1840 local TESTFILE=$DIR/$tdir/$tfile
1842 setup_quota_test || error "setup quota failed with $?"
1843 trap cleanup_quota_test EXIT
1845 # make sure the system is clean
1846 local USED=$(getquota -u $TSTUSR global curspace)
1847 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1849 set_ost_qtype "ug" || error "enable ost quota failed"
1850 # make sure no granted quota on ost
1851 resetquota -u $TSTUSR
1852 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1853 error "set quota failed"
1855 quota_show_check b u $TSTUSR
1857 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1858 lustre_fail mds 0xa04 $err_code
1860 # write in background
1861 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1865 # write should be blocked and never finished
1866 if ! ps -p $DDPID > /dev/null 2>&1; then
1868 quota_error u $TSTUSR "write finished incorrectly!"
1876 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1878 if [ $count -gt $timeout ]; then
1879 quota_error u $TSTUSR "dd is not finished!"
1884 sync; sync_all_data || true
1886 USED=$(getquota -u $TSTUSR global curspace)
1887 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1888 "Used space(${USED}K) is less than ${BLKS}M"
1893 # DQACQ return recoverable error
1895 echo "DQACQ return -ENOLCK"
1897 test_17sub 37 || error "Handle -ENOLCK failed"
1899 echo "DQACQ return -EAGAIN"
1901 test_17sub 11 || error "Handle -EAGAIN failed"
1903 echo "DQACQ return -ETIMEDOUT"
1904 #define ETIMEDOUT 110
1905 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1907 echo "DQACQ return -ENOTCONN"
1908 #define ENOTCONN 107
1909 test_17sub 107 || error "Handle -ENOTCONN failed"
1912 run_test 17 "DQACQ return recoverable error"
1916 local blimit="200m" # 200M
1917 local TESTFILE="$DIR/$tdir/$tfile"
1919 setup_quota_test || error "setup quota failed with $?"
1920 trap cleanup_quota_test EXIT
1922 set_ost_qtype "u" || error "enable ost quota failed"
1923 log "User quota (limit: $blimit)"
1924 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1925 error "set quota failed"
1926 quota_show_check b u $TSTUSR
1928 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1929 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1931 local timeout=$(sysctl -n lustre.timeout)
1933 if [ $io_type = "directio" ]; then
1934 log "Write 100M (directio) ..."
1935 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1937 log "Write 100M (buffered) ..."
1938 $RUNAS $DD of=$TESTFILE count=100 &
1942 replay_barrier $SINGLEMDS
1943 log "Fail mds for $((2 * timeout)) seconds"
1944 fail $SINGLEMDS $((2 * timeout))
1947 if at_is_enabled; then
1948 timeout=$(at_max_get mds)
1950 timeout=$(lctl get_param -n timeout)
1954 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1955 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1956 log "it took $count second"
1961 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1963 cancel_lru_locks mdc
1964 cancel_lru_locks osc
1967 local testfile_size=$(stat -c %s $TESTFILE)
1968 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1969 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1970 "got ${testfile_size}. Verifying file failed!"
1975 # test when mds does failover, the ost still could work well
1976 # this test shouldn't trigger watchdog b=14840
1978 # Clear dmesg so watchdog is not triggered by previous
1980 do_facet ost1 dmesg -c > /dev/null
1983 test_18_sub directio
1985 # check if watchdog is triggered
1986 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1987 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1988 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1989 [ -z "$watchdog" ] || error "$watchdog"
1990 rm -f $TMP/lustre-log-${TESTNAME}.log
1992 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1996 local TESTFILE=$DIR/$tdir/$tfile
1998 setup_quota_test || error "setup quota failed with $?"
1999 trap cleanup_quota_test EXIT
2001 set_ost_qtype $QTYPE || error "enable ost quota failed"
2003 # bind file to a single OST
2004 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2005 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2007 echo "Set user quota (limit: ${blimit}M)"
2008 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2009 error "set user quota failed"
2010 quota_show_check b u $TSTUSR
2011 echo "Update quota limits"
2012 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2013 error "set group quota failed"
2014 quota_show_check b u $TSTUSR
2016 # first wirte might be cached
2017 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2018 cancel_lru_locks osc
2020 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2021 quota_error u $TSTUSR "Write success, expect failure"
2026 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2028 test_20() { # b15754
2029 local LSTR=(2g 1t 4k 3m) # limits strings
2031 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2034 resetquota -u $TSTUSR
2036 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2037 $MOUNT || error "could not set quota limits"
2038 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2039 --inode-softlimit ${LSTR[2]} \
2040 --inode-hardlimit ${LSTR[3]} \
2041 $MOUNT || error "could not set quota limits"
2043 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2044 error "bsoftlimit was not set properly"
2045 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2046 error "bhardlimit was not set properly"
2047 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2048 error "isoftlimit was not set properly"
2049 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2050 error "ihardlimit was not set properly"
2052 resetquota -u $TSTUSR
2054 run_test 20 "Test if setquota specifiers work properly (b15754)"
2061 local time=$(($(date +%s) + seconds))
2062 while [ $(date +%s) -lt $time ]; do
2063 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2067 # run for fixing bug16053, setquota shouldn't fail when writing and
2068 # deleting are happening
2070 local TESTFILE="$DIR/$tdir/$tfile"
2071 local BLIMIT=10 # 10G
2072 local ILIMIT=1000000
2074 setup_quota_test || error "setup quota failed with $?"
2075 trap cleanup_quota_test EXIT
2077 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2079 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2080 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2081 error "set user quota failed"
2082 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2083 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2084 error "set group quota failed"
2085 if is_project_quota_supported; then
2086 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2087 "project: $TSTPRJID"
2088 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2089 $MOUNT || error "set project quota failed"
2092 # repeat writing on a 1M file
2093 test_21_sub ${TESTFILE}_1 1 30 &
2095 # repeat writing on a 128M file
2096 test_21_sub ${TESTFILE}_2 128 30 &
2099 local time=$(($(date +%s) + 30))
2101 while [ $(date +%s) -lt $time ]; do
2102 log "Set quota for $i times"
2103 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2104 -I $((ILIMIT + i)) $MOUNT ||
2105 error "Set user quota failed"
2106 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2107 -I $((ILIMIT + i)) $MOUNT ||
2108 error "Set group quota failed"
2109 if is_project_quota_supported; then
2110 $LFS setquota -p $TSTPRJID -b 0 -B \
2111 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2112 error "Set project quota failed"
2120 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2122 if [ $count -gt 60 ]; then
2123 quota_error a $TSTUSR "dd should be finished!"
2127 echo "(dd_pid=$DDPID1, time=$count)successful"
2131 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2133 if [ $count -gt 60 ]; then
2134 quota_error a $TSTUSR "dd should be finished!"
2138 echo "(dd_pid=$DDPID2, time=$count)successful"
2142 run_test 21 "Setquota while writing & deleting (b16053)"
2144 # enable/disable quota enforcement permanently
2146 echo "Set both mdt & ost quota type as ug"
2148 is_project_quota_supported && qtype=$QTYPE
2149 set_mdt_qtype $qtype || error "enable mdt quota failed"
2150 set_ost_qtype $qtype || error "enable ost quota failed"
2153 stopall || error "failed to stopall (1)"
2157 echo "Verify if quota is enabled"
2158 local qtype1=$(mdt_quota_type)
2159 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2160 qtype=$(ost_quota_type)
2161 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2163 echo "Set both mdt & ost quota type as none"
2164 set_mdt_qtype "none" || error "disable mdt quota failed"
2165 set_ost_qtype "none" || error "disable ost quota failed"
2168 stopall || error "failed to stopall (2)"
2173 echo "Verify if quota is disabled"
2174 qtype=$(mdt_quota_type)
2175 [ $qtype != "none" ] && error "mdt quota setting is lost"
2176 qtype=$(ost_quota_type)
2177 [ $qtype != "none" ] && error "ost quota setting is lost"
2181 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2184 local TESTFILE="$DIR/$tdir/$tfile"
2187 setup_quota_test || error "setup quota failed with $?"
2188 trap cleanup_quota_test EXIT
2190 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2193 log "User quota (limit: $LIMIT MB)"
2194 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2195 error "set quota failed"
2196 quota_show_check b u $TSTUSR
2198 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2199 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2201 log "Step1: trigger EDQUOT with O_DIRECT"
2202 log "Write half of file"
2203 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2204 quota_error u $TSTUSR "(1) Write failure, expect success." \
2206 log "Write out of block quota ..."
2207 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2208 oflag=direct conv=notrunc &&
2209 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2213 log "Step2: rewrite should succeed"
2214 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2215 quota_error u $TSTUSR "(3) Write failure, expect success." \
2221 local OST0_UUID=$(ostuuid_from_index 0)
2222 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2223 [ $OST0_QUOTA_USED -ne 0 ] &&
2224 ($SHOW_QUOTA_USER; \
2225 quota_error u $TSTUSR "quota isn't released")
2230 [ $(facet_fstype ost1) == "zfs" ] &&
2231 skip "Overwrite in place is not guaranteed to be " \
2232 "space neutral on ZFS"
2234 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2235 check_whether_skip && return 0
2236 log "run for 4MB test file"
2239 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2240 check_whether_skip && return 0
2241 log "run for 40MB test file"
2244 run_test 23 "Quota should be honored with directIO (b16125)"
2248 local TESTFILE="$DIR/$tdir/$tfile"
2250 setup_quota_test || error "setup quota failed with $?"
2251 trap cleanup_quota_test EXIT
2253 set_ost_qtype $QTYPE || error "enable ost quota failed"
2255 # bind file to a single OST
2256 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2257 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2259 echo "Set user quota (limit: ${blimit}M)"
2260 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2261 error "set quota failed"
2263 # overrun quota by root user
2264 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2265 error "write failure, expect success"
2266 cancel_lru_locks osc
2267 sync_all_data || true
2269 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2273 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2275 test_27a() { # b19612
2276 $LFS quota $TSTUSR $DIR &&
2277 error "lfs succeeded with no type, but should have failed"
2278 $LFS setquota $TSTUSR $DIR &&
2279 error "lfs succeeded with no type, but should have failed"
2282 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2284 test_27b() { # b20200
2285 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2286 error "lfs setquota failed with uid argument"
2287 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2288 error "lfs stequota failed with gid argument"
2289 if is_project_quota_supported; then
2290 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2291 1000 $DIR || error \
2292 "lfs stequota failed with projid argument"
2294 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2295 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2296 if is_project_quota_supported; then
2297 $SHOW_QUOTA_PROJID ||
2298 error "lfs quota failed with projid argument"
2300 resetquota -u $TSTUSR
2301 resetquota -g $TSTUSR
2302 resetquota -p $TSTPRJID
2305 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2310 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2311 error "lfs setquota failed"
2313 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2314 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2315 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2316 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2318 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2319 error "lfs setquota for $TSTID failed"
2321 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2322 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2323 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2324 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2326 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2327 error "total allocated inode/block limit not printed"
2329 resetquota -u $TSTUSR
2331 run_test 27c "lfs quota should support human-readable output"
2338 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2339 error "set fraction block limit failed"
2340 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2341 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2342 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2343 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2345 resetquota -u $TSTUSR
2347 run_test 27d "lfs setquota should support fraction block limit"
2351 local TESTFILE="$DIR/$tdir/$tfile"
2354 setup_quota_test || error "setup quota failed with $?"
2355 trap cleanup_quota_test EXIT
2357 set_ost_qtype "u" || error "enable ost quota failed"
2359 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2360 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2362 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2363 $MAX_IQ_TIME $DIR || error "set grace time failed"
2364 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2365 error "set quota failed"
2366 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2367 cancel_lru_locks osc
2369 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2370 # over-quota flag has not yet settled since we do not trigger async
2371 # events based on grace time period expiration
2373 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2374 cancel_lru_locks osc
2375 # now over-quota flag should be settled and further writes should fail
2377 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2378 error "grace times were reset"
2381 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2382 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2384 run_test 30 "Hard limit updates should not reset grace times"
2386 # basic usage tracking for user & group
2388 local INODES=10 # 10 files
2389 local BLK_CNT=2 # of 2M each
2390 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2392 setup_quota_test || error "setup quota failed with $?"
2393 trap cleanup_quota_test EXIT
2395 # make sure the system is clean
2396 local USED=$(getquota -u $TSTID global curspace)
2398 error "Used space ($USED) for user $TSTID isn't 0."
2399 USED=$(getquota -g $TSTID global curspace)
2401 error "Used space ($USED) for group $TSTID isn't 0."
2402 if is_project_quota_supported; then
2403 USED=$(getquota -p $TSTPRJID global curspace)
2404 [ $USED -ne 0 ] && error \
2405 "Used space ($USED) for project $TSTPRJID isn't 0."
2408 echo "Write files..."
2409 for i in $(seq 0 $INODES); do
2410 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2411 error "write failed"
2412 is_project_quota_supported &&
2413 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2414 echo "Iteration $i/$INODES completed"
2416 cancel_lru_locks osc
2418 echo "Wait for setattr on objects finished..."
2419 wait_delete_completed
2421 sync; sync_all_data || true
2423 echo "Verify disk usage after write"
2424 USED=$(getquota -u $TSTID global curspace)
2425 [ $USED -lt $TOTAL_BLKS ] &&
2426 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2427 USED=$(getquota -g $TSTID global curspace)
2428 [ $USED -lt $TOTAL_BLKS ] &&
2429 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2430 if is_project_quota_supported; then
2431 USED=$(getquota -p $TSTPRJID global curspace)
2432 [ $USED -lt $TOTAL_BLKS ] && error \
2433 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2436 echo "Verify inode usage after write"
2437 USED=$(getquota -u $TSTID global curinodes)
2438 [ $USED -lt $INODES ] &&
2439 error "Used inode for user $TSTID is $USED, expected $INODES"
2440 USED=$(getquota -g $TSTID global curinodes)
2441 [ $USED -lt $INODES ] &&
2442 error "Used inode for group $TSTID is $USED, expected $INODES"
2443 if is_project_quota_supported; then
2444 USED=$(getquota -p $TSTPRJID global curinodes)
2445 [ $USED -lt $INODES ] && error \
2446 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2451 echo "Verify disk usage after delete"
2452 USED=$(getquota -u $TSTID global curspace)
2453 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2454 USED=$(getquota -u $TSTID global curinodes)
2455 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2456 USED=$(getquota -g $TSTID global curspace)
2457 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2458 USED=$(getquota -g $TSTID global curinodes)
2459 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2460 if is_project_quota_supported; then
2461 USED=$(getquota -p $TSTPRJID global curspace)
2463 error "Used space for project $TSTPRJID isn't 0. $USED"
2464 USED=$(getquota -p $TSTPRJID global curinodes)
2466 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2469 run_test 33 "Basic usage tracking for user & group & project"
2471 # usage transfer test for user & group & project
2473 local BLK_CNT=2 # 2MB
2474 local project_supported="no"
2476 is_project_quota_supported && project_supported="yes"
2477 setup_quota_test || error "setup quota failed with $?"
2478 trap cleanup_quota_test EXIT
2480 # make sure the system is clean
2481 local USED=$(getquota -u $TSTID global curspace)
2482 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2483 USED=$(getquota -g $TSTID global curspace)
2484 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2486 local USED=$(getquota -u $TSTID2 global curspace)
2487 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2488 if [ $project_supported == "yes" ]; then
2489 USED=$(getquota -p $TSTPRJID global curspace)
2490 [ $USED -ne 0 ] && error \
2491 "Used space ($USED) for Project $TSTPRJID isn't 0."
2494 echo "Write file..."
2495 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2496 error "write failed"
2497 cancel_lru_locks osc
2498 sync; sync_all_data || true
2500 echo "chown the file to user $TSTID"
2501 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2503 echo "Wait for setattr on objects finished..."
2504 wait_delete_completed
2506 BLK_CNT=$((BLK_CNT * 1024))
2508 echo "Verify disk usage for user $TSTID"
2509 USED=$(getquota -u $TSTID global curspace)
2510 [ $USED -lt $BLK_CNT ] &&
2511 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2512 USED=$(getquota -u $TSTID global curinodes)
2514 error "Used inodes for user $TSTID is $USED, expected 1"
2516 echo "chgrp the file to group $TSTID"
2517 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2519 echo "Wait for setattr on objects finished..."
2520 wait_delete_completed
2522 echo "Verify disk usage for group $TSTID"
2523 USED=$(getquota -g $TSTID global curspace)
2524 [ $USED -ge $BLK_CNT ] ||
2525 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2526 USED=$(getquota -g $TSTID global curinodes)
2528 error "Used inodes for group $TSTID is $USED, expected 1"
2530 # chown won't change the ost object group. LU-4345 */
2531 echo "chown the file to user $TSTID2"
2532 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2534 echo "Wait for setattr on objects finished..."
2535 wait_delete_completed
2537 echo "change_project project id to $TSTPRJID"
2538 [ $project_supported == "yes" ] &&
2539 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2540 echo "Wait for setattr on objects finished..."
2541 wait_delete_completed
2543 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2544 USED=$(getquota -u $TSTID2 global curspace)
2545 [ $USED -lt $BLK_CNT ] &&
2546 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2547 USED=$(getquota -u $TSTID global curspace)
2549 error "Used space for user $TSTID is $USED, expected 0"
2550 USED=$(getquota -g $TSTID global curspace)
2551 [ $USED -lt $BLK_CNT ] &&
2552 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2553 if [ $project_supported == "yes" ]; then
2554 USED=$(getquota -p $TSTPRJID global curspace)
2555 [ $USED -lt $BLK_CNT ] && error \
2556 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2561 run_test 34 "Usage transfer for user & group & project"
2563 # usage is still accessible across restart
2565 local BLK_CNT=2 # 2 MB
2567 setup_quota_test || error "setup quota failed with $?"
2568 trap cleanup_quota_test EXIT
2570 echo "Write file..."
2571 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2572 error "write failed"
2573 is_project_quota_supported &&
2574 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2575 cancel_lru_locks osc
2577 echo "Wait for setattr on objects finished..."
2578 wait_delete_completed
2580 sync; sync_all_data || true
2582 echo "Save disk usage before restart"
2583 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2584 [ $ORIG_USR_SPACE -eq 0 ] &&
2585 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2586 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2587 [ $ORIG_USR_INODES -eq 0 ] &&
2588 error "Used inodes for user $TSTID is 0, expected 1"
2589 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2590 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2591 [ $ORIG_GRP_SPACE -eq 0 ] &&
2592 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2593 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2594 [ $ORIG_GRP_INODES -eq 0 ] &&
2595 error "Used inodes for group $TSTID is 0, expected 1"
2596 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2598 if is_project_quota_supported; then
2599 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2600 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2601 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2602 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2603 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2604 "Used inodes for project $TSTPRJID is 0, expected 1"
2605 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2613 echo "Verify disk usage after restart"
2614 local USED=$(getquota -u $TSTID global curspace)
2615 [ $USED -eq $ORIG_USR_SPACE ] ||
2616 error "Used space for user $TSTID changed from " \
2617 "$ORIG_USR_SPACE to $USED"
2618 USED=$(getquota -u $TSTID global curinodes)
2619 [ $USED -eq $ORIG_USR_INODES ] ||
2620 error "Used inodes for user $TSTID changed from " \
2621 "$ORIG_USR_INODES to $USED"
2622 USED=$(getquota -g $TSTID global curspace)
2623 [ $USED -eq $ORIG_GRP_SPACE ] ||
2624 error "Used space for group $TSTID changed from " \
2625 "$ORIG_GRP_SPACE to $USED"
2626 USED=$(getquota -g $TSTID global curinodes)
2627 [ $USED -eq $ORIG_GRP_INODES ] ||
2628 error "Used inodes for group $TSTID changed from " \
2629 "$ORIG_GRP_INODES to $USED"
2630 if [ $project_supported == "yes" ]; then
2631 USED=$(getquota -p $TSTPRJID global curinodes)
2632 [ $USED -eq $ORIG_PRJ_INODES ] ||
2633 error "Used inodes for project $TSTPRJID " \
2634 "changed from $ORIG_PRJ_INODES to $USED"
2635 USED=$(getquota -p $TSTPRJID global curspace)
2636 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2637 error "Used space for project $TSTPRJID "\
2638 "changed from $ORIG_PRJ_SPACE to $USED"
2641 # check if the vfs_dq_init() is called before writing
2642 echo "Append to the same file..."
2643 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2644 error "write failed"
2645 cancel_lru_locks osc
2646 sync; sync_all_data || true
2648 echo "Verify space usage is increased"
2649 USED=$(getquota -u $TSTID global curspace)
2650 [ $USED -gt $ORIG_USR_SPACE ] ||
2651 error "Used space for user $TSTID isn't increased" \
2652 "orig:$ORIG_USR_SPACE, now:$USED"
2653 USED=$(getquota -g $TSTID global curspace)
2654 [ $USED -gt $ORIG_GRP_SPACE ] ||
2655 error "Used space for group $TSTID isn't increased" \
2656 "orig:$ORIG_GRP_SPACE, now:$USED"
2657 if [ $project_supported == "yes" ]; then
2658 USED=$(getquota -p $TSTPRJID global curspace)
2659 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2660 error "Used space for project $TSTPRJID isn't " \
2661 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2666 run_test 35 "Usage is still accessible across reboot"
2668 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2671 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2672 skip "Old server doesn't have LU-5006 fix."
2674 setup_quota_test || error "setup quota failed with $?"
2675 trap cleanup_quota_test EXIT
2677 # make sure the system is clean
2678 local USED=$(getquota -u $TSTID global curspace)
2680 error "Used space ($USED) for user $TSTID isn't 0."
2682 # create file with MDS_OPEN_DELAY_CREATE flag
2683 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2684 error "Create file failed"
2686 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2687 oflag=sync || error "Write file failed"
2689 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2691 # wait for setattr on objects finished..."
2692 wait_delete_completed
2694 USED=$(getquota -u $TSTID global curspace)
2695 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2699 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2703 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2704 skip "Old server doesn't have LU-8801 fix."
2706 [ "$UID" != 0 ] && skip_env "must run as root" && return
2708 setup_quota_test || error "setup quota failed with $?"
2709 trap cleanup_quota_test EXIT
2711 # make sure the system is clean
2712 local USED=$(getquota -u $TSTID global curspace)
2714 error "Used space ($USED) for user $TSTID isn't 0."
2715 USED=$(getquota -u $TSTID2 global curspace)
2717 error "Used space ($USED) for user $TSTID2 isn't 0."
2719 local TESTFILE="$DIR/$tdir/$tfile"
2720 local file_cnt=10000
2722 # Generate id entries in accounting file
2723 echo "Create $file_cnt files..."
2724 for i in `seq $file_cnt`; do
2726 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2727 error "failed to chown $TESTFILE-$i"
2729 cancel_lru_locks osc
2730 sync; sync_all_data || true
2732 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2733 procf=${procf}.quota_slave.acct_user
2736 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2737 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2738 echo "Found $acct_cnt id entries"
2740 [ $file_cnt -eq $acct_cnt ] || {
2741 do_facet mds1 $LCTL get_param $procf
2742 error "skipped id entries"
2747 run_test 38 "Quota accounting iterator doesn't skip id entries"
2750 local TESTFILE="$DIR/$tdir/project"
2751 ! is_project_quota_supported &&
2752 skip "Project quota is not supported"
2754 setup_quota_test || error "setup quota failed with $?"
2757 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2758 [ $projectid -ne 0 ] &&
2759 error "Project id should be 0 not $projectid"
2760 change_project -p 1024 $TESTFILE
2761 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2762 [ $projectid -ne 1024 ] &&
2763 error "Project id should be 1024 not $projectid"
2765 stopall || error "failed to stopall (1)"
2768 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2769 [ $projectid -ne 1024 ] &&
2770 error "Project id should be 1024 not $projectid"
2774 run_test 39 "Project ID interface works correctly"
2777 ! is_project_quota_supported &&
2778 skip "Project quota is not supported"
2779 local dir1="$DIR/$tdir/dir1"
2780 local dir2="$DIR/$tdir/dir2"
2782 setup_quota_test || error "setup quota failed with $?"
2784 mkdir -p $dir1 $dir2
2785 change_project -sp 1 $dir1 && touch $dir1/1
2786 change_project -sp 2 $dir2
2788 ln $dir1/1 $dir2/1_link &&
2789 error "Hard link across different project quota should fail"
2794 run_test 40a "Hard link across different project ID"
2797 ! is_project_quota_supported &&
2798 skip "Project quota is not supported"
2799 local dir1="$DIR/$tdir/dir1"
2800 local dir2="$DIR/$tdir/dir2"
2802 setup_quota_test || error "setup quota failed with $?"
2803 mkdir -p $dir1 $dir2
2804 change_project -sp 1 $dir1 && touch $dir1/1
2805 change_project -sp 2 $dir2
2807 mv $dir1/1 $dir2/2 || error "mv failed $?"
2808 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2809 if [ "$projid" != "2" ]; then
2810 error "project id expected 2 not $projid"
2815 run_test 40b "Mv across different project ID"
2818 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2819 ! is_project_quota_supported &&
2820 skip "Project quota is not supported"
2822 setup_quota_test || error "setup quota failed with $?"
2823 local dir="$DIR/$tdir/dir"
2825 mkdir -p $dir && change_project -sp 1 $dir
2826 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2827 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2828 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2829 touch $dir/remote_dir/file
2830 #verify inherit works file for remote dir.
2831 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2832 [ "$projid" != "1" ] &&
2833 error "file under remote dir expected 1 not $projid"
2835 #Agent inode should be ignored for project quota
2836 USED=$(getquota -p 1 global curinodes)
2837 [ "$USED" != "3" ] &&
2838 error "file count expected 3 got $USED"
2844 run_test 40c "Remote child Dir inherit project quota properly"
2847 ! is_project_quota_supported &&
2848 skip "Project quota is not supported"
2850 setup_quota_test || error "setup quota failed with $?"
2851 local dir1="$DIR/$tdir/dir1"
2852 local dir2="$DIR/$tdir/dir2"
2854 mkdir -p $dir1 && change_project -sp 1 $dir1
2855 mkdir -p $dir2 && change_project -sp 2 $dir2
2856 for num in $(seq 1 10); do
2857 touch $dir1/file_$num $dir2/file_$num
2858 ln -s $dir1/file_$num $dir1/file_$num"_link"
2859 ln -s $dir2/file_$num $dir2/file_$num"_link"
2862 count=$($LFS find --projid 1 $DIR | wc -l)
2863 [ "$count" != 21 ] && error "expected 21 but got $count"
2865 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2866 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2867 [ "$count" != 22 ] && error "expected 22 but got $count"
2872 run_test 50 "Test if lfs find --projid works"
2875 ! is_project_quota_supported &&
2876 skip "Project quota is not supported"
2877 setup_quota_test || error "setup quota failed with $?"
2878 local dir="$DIR/$tdir/dir"
2880 mkdir $dir && change_project -sp 1 $dir
2881 local used=$(getquota -p 1 global curinodes)
2882 [ $used != "1" ] && error "expected 1 got $used"
2887 used=$(getquota -p 1 global curinodes)
2888 [ $used != "4" ] && error "expected 4 got $used"
2890 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2892 cp $DIR/$tdir/6 $dir/6
2893 used=$(getquota -p 1 global curinodes)
2894 [ $used != "5" ] && error "expected 5 got $used"
2897 mv $DIR/$tdir/6 $dir/7
2898 used=$(getquota -p 1 global curinodes)
2899 [ $used != "6" ] && error "expected 6 got $used"
2904 run_test 51 "Test project accounting with mv/cp"
2907 ! is_project_quota_supported &&
2908 skip "Project quota is not supported"
2909 setup_quota_test || error "setup quota failed with $?"
2910 local dir="$DIR/$tdir/dir"
2911 mkdir $dir && change_project -sp 1 $dir
2913 touch $DIR/$tdir/file
2914 #Try renaming a file into the project. This should fail.
2915 for num in $(seq 1 2000); do
2916 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2917 error "rename should fail"
2922 run_test 52 "Rename across different project ID"
2925 ! is_project_quota_supported &&
2926 skip "Project quota is not supported"
2927 setup_quota_test || error "setup quota failed with $?"
2928 local dir="$DIR/$tdir/dir"
2929 mkdir $dir && change_project -s $dir
2930 lfs project -d $dir | grep P || error "inherit attribute should be set"
2932 change_project -C $dir
2933 lfs project -d $dir | grep P &&
2934 error "inherit attribute should be cleared"
2939 run_test 53 "Project inherit attribute could be cleared"
2942 ! is_project_quota_supported &&
2943 skip "Project quota is not supported"
2944 setup_quota_test || error "setup quota failed with $?"
2945 trap cleanup_quota_test EXIT
2946 local testfile="$DIR/$tdir/$tfile-0"
2948 #set project ID/inherit attribute
2949 change_project -sp $TSTPRJID $DIR/$tdir
2950 $RUNAS createmany -m ${testfile} 100 ||
2951 error "create many files failed"
2953 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2954 # one more count for directory itself */
2958 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2959 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2961 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2962 [ $proj_count1 -eq $proj_count ] ||
2963 error "c2: expected $proj_count got $proj_count1"
2965 #clear project but with kept projid
2966 change_project -rCk $DIR/$tdir
2967 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2968 [ $proj_count1 -eq $proj_count ] ||
2969 error "c3: expected $proj_count got $proj_count1"
2971 #verify projid untouched.
2972 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2974 [ $proj_count1 -eq $proj_count ] ||
2975 error "c4: expected $proj_count got $proj_count1"
2978 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2979 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2980 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2982 #this time clear all
2983 change_project -rC $DIR/$tdir
2984 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2985 [ $proj_count1 -eq 0 ] ||
2986 error "c6: expected 0 got $proj_count1"
2988 unlinkmany ${testfile} 100 ||
2989 error "unlink many files failed"
2993 run_test 54 "basic lfs project interface test"
2996 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
2997 skip "Not supported before 2.10.58."
2998 setup_quota_test || error "setup quota failed with $?"
3000 set_ost_qtype $QTYPE || error "enable ost quota failed"
3003 #add second group to TSTUSR
3004 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3007 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3008 error "failed to dd"
3010 cancel_lru_locks osc
3011 sync; sync_all_data || true
3013 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3014 error "failed to setquota on group $TSTUSR2"
3016 $LFS quota -v -g $TSTUSR2 $DIR
3018 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3019 error "chgrp should failed with -EDQUOT"
3021 USED=$(getquota -g $TSTUSR2 global curspace)
3024 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3025 error "failed to setquota on group $TSTUSR2"
3027 $LFS quota -v -g $TSTUSR2 $DIR
3029 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3030 error "chgrp should succeed"
3032 $LFS quota -v -g $TSTUSR2 $DIR
3036 run_test 55 "Chgrp should be affected by group quota"
3039 setup_quota_test || error "setup quota failed with $?"
3041 set_ost_qtype $QTYPE || error "enable ost quota failed"
3044 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3045 erro "failed to set grace time for usr quota"
3046 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3047 awk '{print $4 $8}')
3048 if [ "x$grace_time" != "x10s;10s" ]; then
3049 $LFS quota -t -u $DIR
3050 error "expected grace time: 10s;10s, got:$grace_time"
3055 run_test 56 "lfs quota -t should work well"
3058 setup_quota_test || error "setup quota failed with $?"
3060 local dir="$DIR/$tdir/dir"
3063 #try to change pipe file should not hang and return failure
3064 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3065 awk -F ':' '{ print \\\$2 }'" \
3066 " failed to get xattr for '$dir/pipe'" || return 1
3067 #command can process further if it hit some errors
3068 touch $dir/aaa $dir/bbb
3069 mkdir $dir/subdir -p
3070 touch $dir/subdir/aaa $dir/subdir/bbb
3071 #create one invalid link file
3072 ln -s $dir/not_exist_file $dir/ccc
3073 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3074 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3078 run_test 57 "lfs project could tolerate errors"
3081 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3082 skip "ldiskfs only test"
3083 disable_project_quota
3084 setup_quota_test || error "setup quota failed with $?"
3087 local testfile="$DIR/$tdir/$tfile-0"
3088 #make sure it did not crash kernel
3089 touch $testfile && lfs project -sp 1 $testfile
3091 enable_project_quota
3094 run_test 59 "lfs project dosen't crash kernel with project disabled"
3097 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3098 skip "Needs MDS version 2.11.53 or later."
3099 setup_quota_test || error "setup quota failed with $?"
3100 trap cleanup_quota_test EXIT
3102 local testfile=$DIR/$tdir/$tfile
3105 set_mdt_qtype "ug" || error "enable mdt quota failed"
3107 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3108 error "set quota failed"
3109 quota_show_check a g $TSTUSR
3111 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3112 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3113 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3114 error "create many files failed"
3116 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3118 # root user can overrun quota
3119 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3120 error "root user should succeed"
3124 run_test 60 "Test quota for root with setgid"
3126 # test default quota
3127 test_default_quota() {
3128 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3129 skip "Not supported before 2.11.51."
3134 local qprjid=$TSTPRJID
3138 local LIMIT=20480 #20M disk space
3139 local TESTFILE="$DIR/$tdir/$tfile-0"
3141 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3142 echo "Project quota is not supported" && return 0
3144 [ $qtype == "-u" ] && qdtype="-U"
3145 [ $qtype == "-g" ] && qdtype="-G"
3146 [ $qtype == "-p" ] && {
3151 [ $qpool == "meta" ] && {
3152 LIMIT=10240 #10K inodes
3157 setup_quota_test || error "setup quota failed with $?"
3158 trap cleanup_quota_test EXIT
3162 # enable mdt/ost quota
3163 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3164 set_ost_qtype $QTYPE || error "enable ost quota failed"
3166 log "set to use default quota"
3167 $LFS setquota $qtype $qid -d $DIR ||
3168 error "set $qid to use default quota failed"
3170 log "set default quota"
3171 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3172 error "set $qid default quota failed"
3174 log "get default quota"
3175 $LFS quota $qdtype $DIR || error "get default quota failed"
3177 if [ $qpool == "data" ]; then
3178 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3180 [ $SLIMIT -eq $LIMIT ] ||
3181 error "the returned default quota is wrong"
3183 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3185 [ $SLIMIT -eq $LIMIT ] ||
3186 error "the returned default quota is wrong"
3189 # make sure the system is clean
3190 local USED=$(getquota $qtype $qid global curspace)
3191 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3193 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3194 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3196 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3198 log "Test not out of quota"
3199 if [ $qpool == "data" ]; then
3200 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3201 quota_error $qtype $qid "write failed, expect succeed"
3203 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3204 quota_error $qtype $qid "create failed, expect succeed"
3206 unlinkmany $TESTFILE $((LIMIT/2))
3209 log "Test out of quota"
3210 # flush cache, ensure noquota flag is set on client
3211 cancel_lru_locks osc
3212 cancel_lru_locks mdc
3213 sync; sync_all_data || true
3214 if [ $qpool == "data" ]; then
3215 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3216 quota_error $qtype $qid "write succeed, expect EDQUOT"
3218 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3219 quota_error $qtype $qid "create succeed, expect EDQUOT"
3221 unlinkmany $TESTFILE $((LIMIT*2))
3224 log "Increase default quota"
3225 # increase default quota
3226 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3227 error "set default quota failed"
3229 cancel_lru_locks osc
3230 cancel_lru_locks mdc
3231 sync; sync_all_data || true
3232 if [ $qpool == "data" ]; then
3233 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3234 quota_error $qtype $qid "write failed, expect succeed"
3236 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3237 quota_error $qtype $qid "create failed, expect succeed"
3239 unlinkmany $TESTFILE $((LIMIT*2))
3242 log "Set quota to override default quota"
3243 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3244 error "set $qid quota failed"
3246 cancel_lru_locks osc
3247 cancel_lru_locks mdc
3248 sync; sync_all_data || true
3249 if [ $qpool == "data" ]; then
3250 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3251 quota_error $qtype $qid "write succeed, expect EQUOT"
3253 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3254 quota_error $qtype $qid "create succeed, expect EQUOT"
3256 unlinkmany $TESTFILE $((LIMIT*2))
3259 log "Set to use default quota again"
3260 $LFS setquota $qtype $qid -d $DIR ||
3261 error "set $qid to use default quota failed"
3263 cancel_lru_locks osc
3264 cancel_lru_locks mdc
3265 sync; sync_all_data || true
3266 if [ $qpool == "data" ]; then
3267 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3268 quota_error $qtype $qid "write failed, expect succeed"
3270 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3271 quota_error $qtype $qid "create failed, expect succeed"
3273 unlinkmany $TESTFILE $((LIMIT*2))
3278 wait_delete_completed || error "wait_delete_completed failed"
3279 sync_all_data || true
3280 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3281 error "reset default quota failed"
3282 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3283 error "reset quota failed"
3289 test_default_quota "-u" "data"
3290 test_default_quota "-u" "meta"
3291 test_default_quota "-g" "data"
3292 test_default_quota "-g" "meta"
3293 test_default_quota "-p" "data"
3294 test_default_quota "-p" "meta"
3296 run_test 61 "default quota tests"
3299 ! is_project_quota_supported &&
3300 skip "Project quota is not supported"
3301 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3302 skip "chattr did not support project quota"
3303 setup_quota_test || error "setup quota failed with $?"
3304 local testdir=$DIR/$tdir/
3306 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3307 change_project -s $testdir
3308 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3309 error "inherit attribute should be set"
3310 # chattr used FS_IOC_SETFLAGS ioctl
3311 $RUNAS chattr -P $testdir &&
3312 error "regular user clear inherit should fail"
3313 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3314 error "inherit attribute should still be set"
3315 chattr -P $testdir || error "root failed to clear inherit"
3316 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3317 error "inherit attribute should be cleared"
3320 run_test 62 "Project inherit should be only changed by root"
3323 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3324 skip "Not supported before 2.11.55" && return
3328 local dd_failed=false
3329 local tdir_dom=${tdir}_dom
3330 local LIMIT=20480 #20M
3332 [ $qtype == "p" ] && ! is_project_quota_supported &&
3333 echo "Project quota is not supported" && return 0
3335 [ $qtype == "p" ] && qid=$TSTPRJID
3337 setup_quota_test || error "setup quota failed with $?"
3338 trap cleanup_quota_test EXIT
3342 # enable mdt/ost quota
3343 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3344 set_ost_qtype $QTYPE || error "enable ost quota failed"
3346 # make sure the system is clean
3347 local USED=$(getquota -$qtype $qid global curspace)
3348 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3350 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3352 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3353 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3354 error "setstripe $tdir_dom failed"
3355 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3357 [ $qtype == "p" ] && {
3358 change_project -sp $TSTPRJID $DIR/$tdir
3359 change_project -sp $TSTPRJID $DIR/$tdir_dom
3362 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3363 error "set $qid quota failed"
3365 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3366 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3370 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3372 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3373 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3377 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3379 rm -f $DIR/$tdir_dom/*
3381 # flush cache, ensure noquota flag is set on client
3382 cancel_lru_locks osc
3383 cancel_lru_locks mdc
3384 sync; sync_all_data || true
3388 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3389 quota_error $qtype $qid "write failed, expect succeed"
3391 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3392 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3396 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3399 rm -f $DIR/$tdir_dom/*
3401 # flush cache, ensure noquota flag is set on client
3402 cancel_lru_locks osc
3403 cancel_lru_locks mdc
3404 sync; sync_all_data || true
3408 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3409 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3413 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3415 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3416 quota_error $qtype $qid "write succeed, expect EDQUOT"
3419 rm -fr $DIR/$tdir_dom
3421 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3422 error "reset usr quota failed"
3432 run_test 63 "quota on DoM tests"
3436 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3437 if $PQ_CLEANUP; then
3438 disable_project_quota
3441 reset_quota_settings
3446 check_and_cleanup_lustre
3447 export QUOTA_AUTO=$QUOTA_AUTO_OLD