3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
38 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
40 require_dsh_mds || exit 0
41 require_dsh_ost || exit 0
43 # Does e2fsprogs support quota feature?
44 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
45 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
46 grep -q 'quota'"; then
47 skip_env "e2fsprogs doesn't support quota" && exit 0
50 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
51 # bug number for skipped test: LU-2836 LU-6836 LU-2836
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6"
53 # bug number for skipped test: LU-5638
54 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 is_project_quota_supported() {
75 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
76 [ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.55) ] &&
77 egrep -q "7." /etc/redhat-release &&
78 man chattr | grep project >&/dev/null
81 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
82 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
83 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
84 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
85 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
86 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
87 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
88 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
95 local fail_val=${3:-0}
99 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
100 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
101 ost) NODES="$(comma_list $(osts_nodes))";;
104 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
110 chattr $* || error "chattr $* failed"
113 RUNAS="runas -u $TSTID -g $TSTID"
114 RUNAS2="runas -u $TSTID2 -g $TSTID2"
115 DD="dd if=/dev/zero bs=1M"
119 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
120 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
121 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
122 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
124 # clear quota limits for a user or a group
125 # usage: resetquota -u username
126 # resetquota -g groupname
127 # resetquota -p projid
130 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
131 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
132 error "resetquota: wrong specifier $1 passed"
134 if [ $1 == "-p" ]; then
135 is_project_quota_supported || return 0
138 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
139 error "clear quota for [type:$1 name:$2] failed"
140 # give a chance to slave to release space
148 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
149 $LFS quota -v -u $local_id $DIR
150 log "Files for user ($local_id):"
151 ($LFS find --user $local_id $DIR | head -n 4 |
152 xargs stat 2>/dev/null)
155 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
156 $LFS quota -v -g $local_id $DIR
157 log "Files for group ($local_id):"
158 ($LFS find --group $local_id $DIR | head -n 4 |
159 xargs stat 2>/dev/null)
162 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
163 $LFS quota -v -p $local_id $DIR
164 log "Files for project ($local_id):"
165 ($LFS find --projid $local_id $DIR | head -n 4 |
166 xargs stat 2>/dev/null)
182 # get quota for a user or a group
183 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
184 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
189 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
190 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
191 error "getquota: wrong u/g/p specifier $1 passed"
204 *) error "unknown quota parameter $4";;
207 [ "$uuid" = "global" ] && uuid=$DIR
209 $LFS quota -v "$1" "$2" $DIR |
210 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
211 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
216 # usage: set_mdt_qtype ugp|u|g|p|none
220 local mdts=$(get_facets MDS)
222 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
223 qtype=$(tr -d 'p' <<<$qtype)
224 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
225 # we have to make sure each MDT received config changes
226 for mdt in ${mdts//,/ }; do
228 cmd="$LCTL get_param -n "
229 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
230 cmd=${cmd}.quota_slave.enabled
232 if $(facet_up $mdt); then
233 wait_update_facet $mdt "$cmd" "$qtype" || return 1
240 # usage: set_ost_qtype ugp|u|g|p|none
244 local osts=$(get_facets OST)
246 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
247 qtype=$(tr -d 'p' <<<$qtype)
248 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
249 # we have to make sure each OST received config changes
250 for ost in ${osts//,/ }; do
252 cmd="$LCTL get_param -n "
253 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
254 cmd=${cmd}.quota_slave.enabled
256 if $(facet_up $ost); then
257 wait_update_facet $ost "$cmd" "$qtype" || return 1
263 wait_reintegration() {
267 local result="glb[1],slv[1],reint[0]"
272 if [ $ntype == "mdt" ]; then
273 tgts=$(get_facets MDS)
275 tgts=$(get_facets OST)
278 for tgt in ${tgts//,/ }; do
280 cmd="$LCTL get_param -n "
281 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
282 cmd=${cmd}.quota_slave.info
284 if $(facet_up $tgt); then
285 wait_update_facet $tgt "$cmd |
286 grep "$qtype" | awk '{ print \\\$3 }'" \
287 "$result" $max || return 1
297 if [[ "$qtype" =~ "u" ]]; then
298 wait_reintegration "mdt" "user" $max || return 1
301 if [[ "$qtype" =~ "g" ]]; then
302 wait_reintegration "mdt" "group" $max || return 1
305 if [[ "$qtype" =~ "p" ]]; then
306 ! is_project_quota_supported && return 0
307 wait_reintegration "mdt" "project" $max || return 1
316 if [[ "$qtype" =~ "u" ]]; then
317 wait_reintegration "ost" "user" $max || return 1
320 if [[ "$qtype" =~ "g" ]]; then
321 wait_reintegration "ost" "group" $max || return 1
324 if [[ "$qtype" =~ "p" ]]; then
325 ! is_project_quota_supported && return 0
326 wait_reintegration "ost" "project" $max || return 1
331 disable_project_quota() {
332 is_project_quota_supported || return 0
333 stopall || error "failed to stopall (1)"
335 for num in $(seq $MDSCOUNT); do
336 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
337 error "tune2fs $(mdsdevname $num) failed"
340 for num in $(seq $OSTCOUNT); do
341 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
342 error "tune2fs $(ostdevname $num) failed"
350 wait_delete_completed
351 echo "Creating test directory"
352 mkdir $DIR/$tdir || return 1
353 chmod 0777 $DIR/$tdir || return 2
354 # always clear fail_loc in case of fail_loc isn't cleared
355 # properly when previous test failed
356 lustre_fail mds_ost 0
359 cleanup_quota_test() {
361 echo "Delete files..."
363 echo "Wait for unlink objects finished..."
364 wait_delete_completed
365 sync_all_data || true
374 $LFS quota -v -$ugp $qid $DIR
376 if [ "$bf" == "a" -o "$bf" == "b" ]; then
377 usage=$(getquota -$ugp $qid global curspace)
378 if [ -z $usage ]; then
379 quota_error $ugp $qid \
380 "Query block quota failed ($ugp:$qid)."
382 [ $usage -ne 0 ] && quota_log $ugp $qid \
383 "Block quota isn't 0 ($ugp:$qid:$usage)."
387 if [ "$bf" == "a" -o "$bf" == "f" ]; then
388 usage=$(getquota -$ugp $qid global curinodes)
389 if [ -z $usage ]; then
390 quota_error $ugp $qid \
391 "Query file quota failed ($ugp:$qid)."
393 [ $usage -ne 0 ] && quota_log $ugp $qid \
394 "File quota isn't 0 ($ugp:$qid:$usage)."
399 enable_project_quota() {
400 is_project_quota_supported || return 0
401 stopall || error "failed to stopall (1)"
403 for num in $(seq $MDSCOUNT); do
404 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
405 error "tune2fs $(mdsdevname $num) failed"
408 for num in $(seq $OSTCOUNT); do
409 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
410 error "tune2fs $(ostdevname $num) failed"
420 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
424 resetquota -u $TSTUSR
425 resetquota -g $TSTUSR
426 resetquota -u $TSTUSR2
427 resetquota -g $TSTUSR2
428 resetquota -p $TSTPRJID
430 test_quota_performance() {
431 local TESTFILE="$DIR/$tdir/$tfile-0"
432 local size=$1 # in MB
433 local stime=$(date +%s)
434 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
435 quota_error u $TSTUSR "write failure"
436 local etime=$(date +%s)
437 delta=$((etime - stime))
438 if [ $delta -gt 0 ]; then
439 rate=$((size * 1024 / delta))
440 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
441 # LU-2872 - see LU-2887 for fix
443 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
445 [ $rate -gt 1024 ] ||
446 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
452 # test basic quota performance b=21696
455 [ "$SLOW" = "no" ] && MB=10
457 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
458 [ $free_space -le $((MB * 1024)) ] &&
459 skip "not enough space ${free_space} KB, " \
460 "required $((MB * 1024)) KB" && return
461 setup_quota_test || error "setup quota failed with $?"
462 trap cleanup_quota_test EXIT
464 set_ost_qtype "none" || error "disable ost quota failed"
465 test_quota_performance $MB
467 set_ost_qtype $QTYPE || error "enable ost quota failed"
468 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
469 error "set quota failed"
470 test_quota_performance $MB
473 resetquota -u $TSTUSR
475 run_test 0 "Test basic quota performance"
477 # test block hardlimit
480 local TESTFILE="$DIR/$tdir/$tfile-0"
482 setup_quota_test || error "setup quota failed with $?"
483 trap cleanup_quota_test EXIT
486 set_ost_qtype $QTYPE || error "enable ost quota failed"
489 log "User quota (block hardlimit:$LIMIT MB)"
490 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
491 error "set user quota failed"
493 # make sure the system is clean
494 local USED=$(getquota -u $TSTUSR global curspace)
495 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
497 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
498 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
501 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
502 quota_error u $TSTUSR "user write failure, but expect success"
503 log "Write out of block quota ..."
504 # this time maybe cache write, ignore it's failure
505 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
506 # flush cache, ensure noquota flag is set on client
508 sync; sync_all_data || true
509 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
510 quota_error u $TSTUSR "user write success, but expect EDQUOT"
513 wait_delete_completed || error "wait_delete_completed failed"
514 sync_all_data || true
515 USED=$(getquota -u $TSTUSR global curspace)
516 [ $USED -ne 0 ] && quota_error u $TSTUSR \
517 "user quota isn't released after deletion"
518 resetquota -u $TSTUSR
521 log "--------------------------------------"
522 log "Group quota (block hardlimit:$LIMIT MB)"
523 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
524 error "set group quota failed"
526 TESTFILE="$DIR/$tdir/$tfile-1"
527 # make sure the system is clean
528 USED=$(getquota -g $TSTUSR global curspace)
529 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
531 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
532 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
535 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
536 quota_error g $TSTUSR "Group write failure, but expect success"
537 log "Write out of block quota ..."
538 # this time maybe cache write, ignore it's failure
539 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
541 sync; sync_all_data || true
542 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
543 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
545 wait_delete_completed || error "wait_delete_completed failed"
546 sync_all_data || true
547 USED=$(getquota -g $TSTUSR global curspace)
548 [ $USED -ne 0 ] && quota_error g $TSTUSR \
549 "Group quota isn't released after deletion"
550 resetquota -g $TSTUSR
552 if ! is_project_quota_supported; then
553 echo "Project quota is not supported"
558 TESTFILE="$DIR/$tdir/$tfile-2"
559 # make sure the system is clean
560 USED=$(getquota -p $TSTPRJID global curspace)
562 error "used space($USED) for project $TSTPRJID isn't 0"
565 log "--------------------------------------"
566 log "project quota (block hardlimit:$LIMIT mb)"
567 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
568 error "set project quota failed"
570 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
571 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
572 change_project -p $TSTPRJID $TESTFILE
575 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
576 "project write failure, but expect success"
577 log "write out of block quota ..."
578 # this time maybe cache write, ignore it's failure
579 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
581 sync; sync_all_data || true
582 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
583 $TSTPRJID "project write success, but expect edquot"
588 USED=$(getquota -p $TSTPRJID global curspace)
589 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
590 "project quota isn't released after deletion"
592 resetquota -p $TSTPRJID
594 run_test 1 "Block hard limit (normal use and out of quota)"
596 # test inode hardlimit
598 local LIMIT=$((1024 * 1024)) # 1M inodes
599 local TESTFILE="$DIR/$tdir/$tfile-0"
601 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
603 local FREE_INODES=$(mdt_free_inodes 0)
604 echo "$FREE_INODES free inodes on master MDT"
605 [ $FREE_INODES -lt $LIMIT ] &&
606 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
609 setup_quota_test || error "setup quota failed with $?"
610 trap cleanup_quota_test EXIT
613 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
616 log "User quota (inode hardlimit:$LIMIT files)"
617 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
618 error "set user quota failed"
620 # make sure the system is clean
621 local USED=$(getquota -u $TSTUSR global curinodes)
622 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
624 log "Create $LIMIT files ..."
625 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
626 quota_error u $TSTUSR "user create failure, but expect success"
627 log "Create out of file quota ..."
628 $RUNAS touch ${TESTFILE}_xxx &&
629 quota_error u $TSTUSR "user create success, but expect EDQUOT"
632 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
633 rm -f ${TESTFILE}_xxx
634 wait_delete_completed
636 USED=$(getquota -u $TSTUSR global curinodes)
637 [ $USED -ne 0 ] && quota_error u $TSTUSR \
638 "user quota isn't released after deletion"
639 resetquota -u $TSTUSR
642 log "--------------------------------------"
643 log "Group quota (inode hardlimit:$LIMIT files)"
644 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
645 error "set group quota failed"
647 TESTFILE=$DIR/$tdir/$tfile-1
648 # make sure the system is clean
649 USED=$(getquota -g $TSTUSR global curinodes)
650 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
652 log "Create $LIMIT files ..."
653 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
654 quota_error g $TSTUSR "group create failure, but expect success"
655 log "Create out of file quota ..."
656 $RUNAS touch ${TESTFILE}_xxx &&
657 quota_error g $TSTUSR "group create success, but expect EDQUOT"
660 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
661 rm -f ${TESTFILE}_xxx
662 wait_delete_completed
664 USED=$(getquota -g $TSTUSR global curinodes)
665 [ $USED -ne 0 ] && quota_error g $TSTUSR \
666 "user quota isn't released after deletion"
668 resetquota -g $TSTUSR
669 ! is_project_quota_supported && cleanup_quota_test &&
670 echo "Skip project quota is not supported" && return 0
673 log "--------------------------------------"
674 log "Project quota (inode hardlimit:$LIMIT files)"
675 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
676 error "set project quota failed"
678 TESTFILE=$DIR/$tdir/$tfile-1
679 # make sure the system is clean
680 USED=$(getquota -p $TSTPRJID global curinodes)
682 error "Used inodes($USED) for project $TSTPRJID isn't 0"
684 change_project +P $DIR/$tdir/
685 change_project -p $TSTPRJID -d $DIR/$tdir
686 log "Create $LIMIT files ..."
687 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
688 $TSTPRJID "project create fail, but expect success"
689 log "Create out of file quota ..."
690 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
691 "project create success, but expect EDQUOT"
692 change_project -P $DIR/$tdir
693 change_project -p 0 -d $DIR/$tdir
696 USED=$(getquota -p $TSTPRJID global curinodes)
697 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
698 "project quota isn't released after deletion"
700 resetquota -p $TSTPRJID
703 run_test 2 "File hard limit (normal use and out of quota)"
707 local TIMER=$(($2 * 3 / 2))
713 trap cleanup_quota_test EXIT
715 $SETSTRIPE $TESTFILE -c 1 -i 0
716 chown $TSTUSR.$TSTUSR $TESTFILE
717 [ "$qtype" == "p" ] && is_project_quota_supported &&
718 change_project -p $TSTPRJID $TESTFILE
720 echo "Write up to soft limit"
721 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
722 quota_error a $TSTUSR "write failure, but expect success"
723 OFFSET=$((LIMIT * 1024))
726 echo "Write to exceed soft limit"
727 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
728 quota_error a $TSTUSR "write failure, but expect success"
729 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
735 $SHOW_QUOTA_INFO_USER
736 $SHOW_QUOTA_INFO_GROUP
737 $SHOW_QUOTA_INFO_PROJID
739 echo "Write before timer goes off"
740 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
741 quota_error a $TSTUSR "write failure, but expect success"
742 OFFSET=$((OFFSET + 1024))
745 echo "Sleep $TIMER seconds ..."
751 $SHOW_QUOTA_INFO_USER
752 $SHOW_QUOTA_INFO_GROUP
753 $SHOW_QUOTA_INFO_PROJID
755 echo "Write after timer goes off"
756 # maybe cache write, ignore.
757 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
758 OFFSET=$((OFFSET + 1024))
760 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
761 quota_error a $TSTUSR "write success, but expect EDQUOT"
766 $SHOW_QUOTA_INFO_USER
767 $SHOW_QUOTA_INFO_GROUP
768 $SHOW_QUOTA_INFO_PROJID
770 echo "Unlink file to stop timer"
772 wait_delete_completed
773 sync_all_data || true
778 $SHOW_QUOTA_INFO_USER
779 $SHOW_QUOTA_INFO_GROUP
780 $SHOW_QUOTA_INFO_PROJID
782 $SETSTRIPE $TESTFILE -c 1 -i 0
783 chown $TSTUSR.$TSTUSR $TESTFILE
784 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
787 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
788 quota_error a $TSTUSR "write failure, but expect success"
797 local TESTFILE=$DIR/$tdir/$tfile-0
799 set_ost_qtype $QTYPE || error "enable ost quota failed"
801 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
802 # make sure the system is clean
803 local USED=$(getquota -u $TSTUSR global curspace)
804 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
806 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
807 $MAX_IQ_TIME $DIR || error "set user grace time failed"
808 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
809 error "set user quota failed"
811 test_block_soft $TESTFILE $GRACE $LIMIT "u"
812 resetquota -u $TSTUSR
814 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
815 TESTFILE=$DIR/$tdir/$tfile-1
816 # make sure the system is clean
817 USED=$(getquota -g $TSTUSR global curspace)
818 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
820 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
821 $MAX_IQ_TIME $DIR || error "set group grace time failed"
822 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
823 error "set group quota failed"
825 test_block_soft $TESTFILE $GRACE $LIMIT "g"
826 resetquota -g $TSTUSR
828 if is_project_quota_supported; then
829 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
830 TESTFILE=$DIR/$tdir/$tfile-2
831 # make sure the system is clean
832 USED=$(getquota -p $TSTPRJID global curspace)
833 [ $USED -ne 0 ] && error \
834 "Used space($USED) for project $TSTPROJID isn't 0."
836 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
838 error "set project grace time failed"
839 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
840 $DIR || error "set project quota failed"
842 test_block_soft $TESTFILE $GRACE $LIMIT "p"
843 resetquota -p $TSTPRJID
844 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
846 error "restore project grace time failed"
850 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
851 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
852 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
853 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
855 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
861 local TIMER=$(($grace * 3 / 2))
864 trap cleanup_quota_test EXIT
865 is_project_quota_supported && change_project +P $DIR/$tdir/ &&
866 change_project -p $TSTPRJID -d $DIR/$tdir
868 echo "Create files to exceed soft limit"
869 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
870 quota_error a $TSTUSR "create failure, but expect success"
871 local trigger_time=$(date +%s)
873 sync_all_data || true
875 local cur_time=$(date +%s)
876 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
877 error "Passed grace time $grace, $trigger_time, $cur_time"
879 echo "Create file before timer goes off"
880 $RUNAS touch ${TESTFILE}_before ||
881 quota_error a $TSTUSR "failed create before timer expired," \
882 "but expect success. $trigger_time, $cur_time"
883 sync_all_data || true
885 echo "Sleep $TIMER seconds ..."
891 $SHOW_QUOTA_INFO_USER
892 $SHOW_QUOTA_INFO_GROUP
893 $SHOW_QUOTA_INFO_PROJID
895 echo "Create file after timer goes off"
896 # There is a window that space is accounted in the quota usage but
897 # hasn't been decreased from the pending write, if we acquire quota
898 # in this window, we'll acquire more than we needed.
899 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
900 sync_all_data || true
901 $RUNAS touch ${TESTFILE}_after_3 &&
902 quota_error a $TSTUSR "create after timer expired," \
904 sync_all_data || true
909 $SHOW_QUOTA_INFO_USER
910 $SHOW_QUOTA_INFO_GROUP
911 $SHOW_QUOTA_INFO_PROJID
913 echo "Unlink files to stop timer"
914 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
915 wait_delete_completed
918 $RUNAS touch ${TESTFILE}_xxx ||
919 quota_error a $TSTUSR "touch after timer stop failure," \
921 sync_all_data || true
929 local LIMIT=10 # inodes
930 local TESTFILE=$DIR/$tdir/$tfile-0
933 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
935 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
936 # make sure the system is clean
937 local USED=$(getquota -u $TSTUSR global curinodes)
938 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
940 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
941 $GRACE $DIR || error "set user grace time failed"
942 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
943 error "set user quota failed"
945 test_file_soft $TESTFILE $LIMIT $GRACE
946 resetquota -u $TSTUSR
948 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
949 # make sure the system is clean
950 USED=$(getquota -g $TSTUSR global curinodes)
951 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
953 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
954 $GRACE $DIR || error "set group grace time failed"
955 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
956 error "set group quota failed"
957 TESTFILE=$DIR/$tdir/$tfile-1
959 test_file_soft $TESTFILE $LIMIT $GRACE
960 resetquota -g $TSTUSR
962 if is_project_quota_supported; then
963 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
964 # make sure the system is clean
965 USED=$(getquota -p $TSTPRJID global curinodes)
966 [ $USED -ne 0 ] && error \
967 "Used space($USED) for project $TSTPRJID isn't 0."
969 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
970 $GRACE $DIR || error "set project grace time failed"
971 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
972 error "set project quota failed"
974 TESTFILE=$DIR/$tdir/$tfile-1
975 # one less than limit, because of parent directory included.
976 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
977 resetquota -p $TSTPRJID
978 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
980 error "restore project grace time failed"
984 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
985 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
986 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
987 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
989 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
993 local GR_STR2="1000s"
995 local GR_STR4="1w2d3h4m5s"
997 local GR_STR6="18446744073709551615"
1000 wait_delete_completed
1002 # test of valid grace strings handling
1003 echo "Valid grace strings test"
1004 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1005 $GR_STR2 $DIR || error "set user grace time failed"
1006 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1007 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1008 $GR_STR4 $DIR || error "set group grace time quota failed"
1009 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1011 # test of invalid grace strings handling
1012 echo " Invalid grace strings test"
1013 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1014 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1015 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1019 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1020 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1021 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1022 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1024 run_test 4b "Grace time strings handling"
1026 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1028 local BLIMIT=10 # 10M
1029 local ILIMIT=10 # 10 inodes
1031 setup_quota_test || error "setup quota failed with $?"
1032 trap cleanup_quota_test EXIT
1034 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1035 set_ost_qtype $QTYPE || error "enable ost quota failed"
1037 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1038 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1039 error "set user quota failed"
1040 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1041 if is_project_quota_supported; then
1042 error "set group quota failed"
1043 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1044 -I $ILIMIT $DIR || error "set project quota failed"
1047 # make sure the system is clean
1048 local USED=$(getquota -u $TSTUSR global curinodes)
1049 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1050 USED=$(getquota -g $TSTUSR global curinodes)
1051 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1052 USED=$(getquota -u $TSTUSR global curspace)
1053 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1054 USED=$(getquota -g $TSTUSR global curspace)
1055 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1056 if is_project_quota_supported; then
1057 USED=$(getquota -p $TSTPRJID global curspace)
1059 error "Used block($USED) for project $TSTPRJID isn't 0."
1062 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1063 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1064 error "create failure, expect success"
1065 if is_project_quota_supported; then
1066 touch $DIR/$tdir/$tfile-0_1
1067 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1069 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1070 error "write failure, expect success"
1072 echo "Chown files to $TSTUSR.$TSTUSR ..."
1073 for i in $(seq 0 $ILIMIT); do
1074 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1075 quota_error a $TSTUSR "chown failure, expect success"
1079 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1080 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1083 resetquota -u $TSTUSR
1084 resetquota -g $TSTUSR
1085 resetquota -p $TSTPRJID
1087 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1089 # test dropping acquire request on master
1093 # Clear dmesg so watchdog is not triggered by previous
1095 do_facet ost1 dmesg -c > /dev/null
1097 setup_quota_test || error "setup quota failed with $?"
1098 trap cleanup_quota_test EXIT
1100 # make sure the system is clean
1101 local USED=$(getquota -u $TSTUSR global curspace)
1102 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1104 # make sure no granted quota on ost
1105 set_ost_qtype $QTYPE || error "enable ost quota failed"
1106 resetquota -u $TSTUSR
1108 # create file for $TSTUSR
1109 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1110 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1111 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1113 # create file for $TSTUSR2
1114 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1115 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1116 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1118 # cache per-ID lock for $TSTUSR on slave
1119 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1120 error "set quota failed"
1121 $RUNAS $DD of=$TESTFILE count=1 ||
1122 error "write $TESTFILE failure, expect success"
1123 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1124 error "write $TESTFILE2 failure, expect success"
1126 sync_all_data || true
1128 #define QUOTA_DQACQ 601
1129 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1130 lustre_fail mds 0x513 601
1132 # write to un-enforced ID ($TSTUSR2) should succeed
1133 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1134 error "write failure, expect success"
1136 # write to enforced ID ($TSTUSR) in background, exceeding limit
1137 # to make sure DQACQ is sent
1138 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1141 # watchdog timer uses a factor of 2
1142 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1143 sleep $((TIMEOUT * 2 + 1))
1145 # write should be blocked and never finished
1146 if ! ps -p $DDPID > /dev/null 2>&1; then
1148 error "write finished incorrectly!"
1153 # no watchdog is triggered
1154 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1155 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1156 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1157 [ -z "$watchdog" ] || error "$watchdog"
1159 rm -f $TMP/lustre-log-${TESTNAME}.log
1161 # write should continue then fail with EDQUOT
1165 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1166 if [ $count -ge 240 ]; then
1167 quota_error u $TSTUSR "dd not finished in $count secs"
1169 count=$((count + 1))
1170 if [ $((count % 30)) -eq 0 ]; then
1171 c_size=$(stat -c %s $TESTFILE)
1172 echo "Waiting $count secs. $c_size"
1179 resetquota -u $TSTUSR
1181 run_test 6 "Test dropping acquire request on master"
1183 # quota reintegration (global index)
1185 local TESTFILE=$DIR/$tdir/$tfile
1186 local LIMIT=20 # 20M
1188 [ "$SLOW" = "no" ] && LIMIT=5
1190 setup_quota_test || error "setup quota failed with $?"
1191 trap cleanup_quota_test EXIT
1193 # make sure the system is clean
1194 local USED=$(getquota -u $TSTUSR global curspace)
1195 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1197 # make sure no granted quota on ost1
1198 set_ost_qtype $QTYPE || error "enable ost quota failed"
1199 resetquota -u $TSTUSR
1200 set_ost_qtype "none" || error "disable ost quota failed"
1202 local OSTUUID=$(ostuuid_from_index 0)
1203 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1205 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1208 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1209 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1214 echo "Enable quota & set quota limit for $TSTUSR"
1215 set_ost_qtype $QTYPE || error "enable ost quota failed"
1216 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1217 error "set quota failed"
1219 echo "Start ost1..."
1220 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1223 wait_ost_reint $QTYPE || error "reintegration failed"
1225 # hardlimit should have been fetched by slave during global
1226 # reintegration, write will exceed quota
1227 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1228 quota_error u $TSTUSR "write success, but expect EDQUOT"
1231 wait_delete_completed
1232 sync_all_data || true
1238 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1239 error "clear quota failed"
1241 echo "Start ost1..."
1242 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1245 wait_ost_reint $QTYPE || error "reintegration failed"
1247 # hardlimit should be cleared on slave during reintegration
1248 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1249 quota_error u $TSTUSR "write error, but expect success"
1252 resetquota -u $TSTUSR
1254 run_test 7a "Quota reintegration (global index)"
1256 # quota reintegration (slave index)
1259 local TESTFILE=$DIR/$tdir/$tfile
1261 setup_quota_test || error "setup quota failed with $?"
1262 trap cleanup_quota_test EXIT
1264 # make sure the system is clean
1265 local USED=$(getquota -u $TSTUSR global curspace)
1266 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1268 # make sure no granted quota on ost1
1269 set_ost_qtype $QTYPE || error "enable ost quota failed"
1270 resetquota -u $TSTUSR
1271 set_ost_qtype "none" || error "disable ost quota failed"
1273 local OSTUUID=$(ostuuid_from_index 0)
1274 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1276 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1279 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1280 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1282 # consume some space to make sure the granted space will not
1283 # be released during reconciliation
1284 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1285 error "consume space failure, expect success"
1287 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1288 lustre_fail mds 0xa02
1290 set_ost_qtype $QTYPE || error "enable ost quota failed"
1291 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1292 error "set quota failed"
1294 # ignore the write error
1295 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1297 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1301 echo "Restart ost to trigger reintegration..."
1303 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1306 wait_ost_reint $QTYPE || error "reintegration failed"
1308 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1309 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1312 resetquota -u $TSTUSR
1315 run_test 7b "Quota reintegration (slave index)"
1317 # quota reintegration (restart mds during reintegration)
1319 local LIMIT=20 # 20M
1320 local TESTFILE=$DIR/$tdir/$tfile
1322 [ "$SLOW" = "no" ] && LIMIT=5
1324 setup_quota_test || error "setup quota failed with $?"
1325 trap cleanup_quota_test EXIT
1327 # make sure the system is clean
1328 local USED=$(getquota -u $TSTUSR global curspace)
1329 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1331 set_ost_qtype "none" || error "disable ost quota failed"
1332 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1333 error "set quota failed"
1335 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1336 lustre_fail ost 0xa03
1339 set_ost_qtype $QTYPE || error "enable ost quota failed"
1340 # trigger reintegration
1341 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1342 procf=${procf}quota_slave.force_reint
1343 do_facet ost1 $LCTL set_param $procf=1 ||
1344 error "force reintegration failed"
1352 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1355 # wait longer than usual to make sure the reintegration
1356 # is triggered by quota wb thread.
1357 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1359 # hardlimit should have been fetched by slave during global
1360 # reintegration, write will exceed quota
1361 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1362 quota_error u $TSTUSR "write success, but expect EDQUOT"
1365 resetquota -u $TSTUSR
1367 run_test 7c "Quota reintegration (restart mds during reintegration)"
1369 # Quota reintegration (Transfer index in multiple bulks)
1371 local TESTFILE=$DIR/$tdir/$tfile
1372 local TESTFILE1="$DIR/$tdir/$tfile"-1
1375 setup_quota_test || error "setup quota failed with $?"
1376 trap cleanup_quota_test EXIT
1378 set_ost_qtype "none" || error "disable ost quota failed"
1379 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1380 error "set quota for $TSTUSR failed"
1381 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1382 error "set quota for $TSTUSR2 failed"
1384 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1385 lustre_fail mds 0x608 0
1387 # enable quota to tirgger reintegration
1388 set_ost_qtype "u" || error "enable ost quota failed"
1389 wait_ost_reint "u" || error "reintegration failed"
1393 # hardlimit should have been fetched by slave during global
1394 # reintegration, write will exceed quota
1395 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1396 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1398 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1399 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1402 resetquota -u $TSTUSR
1403 resetquota -u $TSTUSR2
1405 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1407 # quota reintegration (inode limits)
1409 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
1411 # LU-2435: skip this quota test if underlying zfs version has not
1412 # supported native dnode accounting
1413 [ "$(facet_fstype mds1)" == "zfs" ] && {
1414 local F="feature@userobj_accounting"
1415 local pool=$(zpool_name mds1)
1416 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1418 [[ "$feature" != *" active "* ]] &&
1419 skip "requires zpool with active userobj_accounting" &&
1423 local ilimit=$((1024 * 2)) # 2k inodes
1424 local TESTFILE=$DIR/${tdir}-1/$tfile
1426 setup_quota_test || error "setup quota failed with $?"
1427 trap cleanup_quota_test EXIT
1429 # make sure the system is clean
1430 local USED=$(getquota -u $TSTUSR global curinodes)
1431 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1433 # make sure no granted quota on mdt1
1434 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1435 resetquota -u $TSTUSR
1436 set_mdt_qtype "none" || error "disable mdt quota failed"
1438 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1439 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1440 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1443 echo "Stop mds${MDSCOUNT}..."
1446 echo "Enable quota & set quota limit for $TSTUSR"
1447 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1448 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1449 error "set quota failed"
1451 echo "Start mds${MDSCOUNT}..."
1452 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1455 wait_mdt_reint $QTYPE || error "reintegration failed"
1457 echo "create remote dir"
1458 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1459 error "create remote dir failed"
1460 chmod 0777 $DIR/${tdir}-1
1462 # hardlimit should have been fetched by slave during global
1463 # reintegration, create will exceed quota
1464 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1465 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1467 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1468 wait_delete_completed
1469 sync_all_data || true
1471 echo "Stop mds${MDSCOUNT}..."
1474 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1475 error "clear quota failed"
1477 echo "Start mds${MDSCOUNT}..."
1478 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1481 wait_mdt_reint $QTYPE || error "reintegration failed"
1483 # hardlimit should be cleared on slave during reintegration
1484 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1485 quota_error -u $TSTUSR "create failed, expect success"
1487 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1488 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1491 resetquota -u $TSTUSR
1493 run_test 7e "Quota reintegration (inode limits)"
1495 # run dbench with quota enabled
1497 local BLK_LIMIT="100g" #100G
1498 local FILE_LIMIT=1000000
1500 setup_quota_test || error "setup quota failed with $?"
1501 trap cleanup_quota_test EXIT
1503 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1504 set_ost_qtype $QTYPE || error "enable ost quota failed"
1506 echo "Set enough high limit for user: $TSTUSR"
1507 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1508 error "set user quota failed"
1509 echo "Set enough high limit for group: $TSTUSR"
1510 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1511 error "set group quota failed"
1512 if is_project_quota_supported; then
1513 change_project +P $DIR/$tdir && change_project -p \
1514 $TSTPRJID -d $DIR/$tdir
1515 echo "Set enough high limit for project: $TSTPRJID"
1516 $LFS setquota -p $TSTPRJID -b 0 \
1517 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1518 error "set project quota failed"
1522 [ "$SLOW" = "no" ] && duration=" -t 120"
1523 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1524 quota_error a $TSTUSR "dbench failed!"
1526 is_project_quota_supported && change_project -P $DIR/$tdir &&
1527 change_project -dp 0 $DIR/$tdir
1529 resetquota -u $TSTUSR
1530 resetquota -g $TSTUSR
1531 resetquota -p $TSTPRJID
1533 run_test 8 "Run dbench with quota enabled"
1535 # this check is just for test_9
1536 OST0_MIN=4900000 #4.67G
1538 check_whether_skip () {
1539 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1540 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1541 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1542 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1549 # run for fixing bug10707, it needs a big room. test for 64bit
1551 local filesize=$((1024 * 9 / 2)) # 4.5G
1553 check_whether_skip && return 0
1555 setup_quota_test || error "setup quota failed with $?"
1556 trap cleanup_quota_test EXIT
1558 set_ost_qtype "ug" || error "enable ost quota failed"
1560 local TESTFILE="$DIR/$tdir/$tfile-0"
1561 local BLK_LIMIT=100G #100G
1562 local FILE_LIMIT=1000000
1564 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1566 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1568 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1569 error "set user quota failed"
1571 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1572 "for group: $TSTUSR"
1573 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1574 error "set group quota failed"
1576 quota_show_check a u $TSTUSR
1577 quota_show_check a g $TSTUSR
1579 echo "Create test file"
1580 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1581 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1583 log "Write the big file of 4.5G ..."
1584 $RUNAS $DD of=$TESTFILE count=$filesize ||
1585 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1591 resetquota -u $TSTUSR
1592 resetquota -g $TSTUSR
1597 run_test 9 "Block limit larger than 4GB (b10707)"
1600 local TESTFILE=$DIR/$tdir/$tfile
1602 setup_quota_test || error "setup quota failed with $?"
1603 trap cleanup_quota_test EXIT
1605 # set limit to root user should fail
1606 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1607 error "set limit for root user successfully, expect failure"
1608 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1609 error "set limit for root group successfully, expect failure"
1610 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1611 error "set limit for project 0 successfully, expect failure"
1613 # root user can overrun quota
1614 set_ost_qtype "ug" || error "enable ost quota failed"
1616 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1617 error "set quota failed"
1618 quota_show_check b u $TSTUSR
1620 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1621 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1623 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1624 error "write failure, expect success"
1627 resetquota -u $TSTUSR
1629 run_test 10 "Test quota for root user"
1632 local TESTFILE=$DIR/$tdir/$tfile
1633 setup_quota_test || error "setup quota failed with $?"
1634 trap cleanup_quota_test EXIT
1636 set_mdt_qtype "ug" || error "enable mdt quota failed"
1637 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1638 error "set quota failed"
1640 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1641 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1643 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1644 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1647 local USED=$(getquota -u $TSTUSR global curinodes)
1648 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1651 resetquota -u $TSTUSR
1653 run_test 11 "Chown/chgrp ignores quota"
1656 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs" && return
1658 local blimit=22 # 22M
1659 local blk_cnt=$((blimit - 5))
1660 local TESTFILE0="$DIR/$tdir/$tfile"-0
1661 local TESTFILE1="$DIR/$tdir/$tfile"-1
1663 setup_quota_test || error "setup quota failed with $?"
1664 trap cleanup_quota_test EXIT
1666 set_ost_qtype "u" || error "enable ost quota failed"
1667 quota_show_check b u $TSTUSR
1669 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1670 error "set quota failed"
1672 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1673 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1674 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1675 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1677 echo "Write to ost0..."
1678 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1679 quota_error a $TSTUSR "dd failed"
1681 echo "Write to ost1..."
1682 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1683 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1685 echo "Free space from ost0..."
1687 wait_delete_completed
1688 sync_all_data || true
1690 echo "Write to ost1 after space freed from ost0..."
1691 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1692 quota_error a $TSTUSR "rebalancing failed"
1695 resetquota -u $TSTUSR
1697 run_test 12a "Block quota rebalancing"
1700 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
1702 local ilimit=$((1024 * 2)) # 2k inodes
1703 local TESTFILE0=$DIR/$tdir/$tfile
1704 local TESTFILE1=$DIR/${tdir}-1/$tfile
1706 setup_quota_test || error "setup quota failed with $?"
1707 trap cleanup_quota_test EXIT
1709 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1710 chmod 0777 $DIR/${tdir}-1
1712 set_mdt_qtype "u" || error "enable mdt quota failed"
1713 quota_show_check f u $TSTUSR
1715 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1716 error "set quota failed"
1718 echo "Create $ilimit files on mdt0..."
1719 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1720 quota_error u $TSTUSR "create failed, but expect success"
1722 echo "Create files on mdt1..."
1723 $RUNAS createmany -m $TESTFILE1 1 &&
1724 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1726 echo "Free space from mdt0..."
1727 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1728 wait_delete_completed
1729 sync_all_data || true
1731 echo "Create files on mdt1 after space freed from mdt0..."
1732 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1733 quota_error a $TSTUSR "rebalancing failed"
1735 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1736 error "unlink mdt1 files failed"
1737 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1740 resetquota -u $TSTUSR
1742 run_test 12b "Inode quota rebalancing"
1745 local TESTFILE=$DIR/$tdir/$tfile
1746 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1747 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1749 setup_quota_test || error "setup quota failed with $?"
1750 trap cleanup_quota_test EXIT
1752 set_ost_qtype "u" || error "enable ost quota failed"
1753 quota_show_check b u $TSTUSR
1755 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1756 error "set quota failed"
1757 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1758 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1760 # clear the locks in cache first
1761 do_facet ost1 $LCTL set_param -n $procf=clear
1762 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1763 [ $nlock -eq 0 ] || error "$nlock cached locks"
1765 # write to acquire the per-ID lock
1766 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1767 quota_error a $TSTUSR "dd failed"
1769 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1770 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1772 # clear quota doesn't trigger per-ID lock cancellation
1773 resetquota -u $TSTUSR
1774 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1775 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1777 # clear the per-ID lock
1778 do_facet ost1 $LCTL set_param -n $procf=clear
1779 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1780 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1782 # spare quota should be released
1783 local OSTUUID=$(ostuuid_from_index 0)
1784 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1785 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1786 [ $limit -le $space ] ||
1787 error "spare quota isn't released, limit:$limit, space:$space"
1791 run_test 13 "Cancel per-ID lock in the LRU list"
1794 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1796 wait_delete_completed
1797 sync_all_data || true
1800 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1801 error "set user quota failed"
1802 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1803 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1804 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1805 resetquota -u $TSTUSR
1808 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1809 error "set group quota failed"
1810 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1811 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1812 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1813 resetquota -g $TSTUSR
1815 run_test 15 "Set over 4T block quota"
1819 local BLKS=1 # 1M less than limit
1820 local TESTFILE=$DIR/$tdir/$tfile
1822 setup_quota_test || error "setup quota failed with $?"
1823 trap cleanup_quota_test EXIT
1825 # make sure the system is clean
1826 local USED=$(getquota -u $TSTUSR global curspace)
1827 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1829 set_ost_qtype "ug" || error "enable ost quota failed"
1830 # make sure no granted quota on ost
1831 resetquota -u $TSTUSR
1832 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1833 error "set quota failed"
1835 quota_show_check b u $TSTUSR
1837 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1838 lustre_fail mds 0xa04 $err_code
1840 # write in background
1841 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1845 # write should be blocked and never finished
1846 if ! ps -p $DDPID > /dev/null 2>&1; then
1848 quota_error u $TSTUSR "write finished incorrectly!"
1856 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1858 if [ $count -gt $timeout ]; then
1859 quota_error u $TSTUSR "dd is not finished!"
1864 sync; sync_all_data || true
1866 USED=$(getquota -u $TSTUSR global curspace)
1867 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1868 "Used space(${USED}K) is less than ${BLKS}M"
1871 resetquota -u $TSTUSR
1874 # DQACQ return recoverable error
1876 echo "DQACQ return -ENOLCK"
1878 test_17sub 37 || error "Handle -ENOLCK failed"
1880 echo "DQACQ return -EAGAIN"
1882 test_17sub 11 || error "Handle -EAGAIN failed"
1884 echo "DQACQ return -ETIMEDOUT"
1885 #define ETIMEDOUT 110
1886 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1888 echo "DQACQ return -ENOTCONN"
1889 #define ENOTCONN 107
1890 test_17sub 107 || error "Handle -ENOTCONN failed"
1893 run_test 17 "DQACQ return recoverable error"
1897 local blimit="200m" # 200M
1898 local TESTFILE="$DIR/$tdir/$tfile"
1900 setup_quota_test || error "setup quota failed with $?"
1901 trap cleanup_quota_test EXIT
1903 set_ost_qtype "u" || error "enable ost quota failed"
1904 log "User quota (limit: $blimit)"
1905 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1906 error "set quota failed"
1907 quota_show_check b u $TSTUSR
1909 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1910 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1912 local timeout=$(sysctl -n lustre.timeout)
1914 if [ $io_type = "directio" ]; then
1915 log "Write 100M (directio) ..."
1916 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1918 log "Write 100M (buffered) ..."
1919 $RUNAS $DD of=$TESTFILE count=100 &
1923 replay_barrier $SINGLEMDS
1924 log "Fail mds for $((2 * timeout)) seconds"
1925 fail $SINGLEMDS $((2 * timeout))
1928 if at_is_enabled; then
1929 timeout=$(at_max_get mds)
1931 timeout=$(lctl get_param -n timeout)
1935 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1936 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1937 log "it took $count second"
1942 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1944 cancel_lru_locks mdc
1945 cancel_lru_locks osc
1948 local testfile_size=$(stat -c %s $TESTFILE)
1949 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1950 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1951 "got ${testfile_size}. Verifying file failed!"
1954 resetquota -u $TSTUSR
1957 # test when mds does failover, the ost still could work well
1958 # this test shouldn't trigger watchdog b=14840
1960 # Clear dmesg so watchdog is not triggered by previous
1962 do_facet ost1 dmesg -c > /dev/null
1965 test_18_sub directio
1967 # check if watchdog is triggered
1968 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1969 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1970 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1971 [ -z "$watchdog" ] || error "$watchdog"
1972 rm -f $TMP/lustre-log-${TESTNAME}.log
1974 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1978 local TESTFILE=$DIR/$tdir/$tfile
1980 setup_quota_test || error "setup quota failed with $?"
1981 trap cleanup_quota_test EXIT
1983 set_ost_qtype $QTYPE || error "enable ost quota failed"
1985 # bind file to a single OST
1986 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1987 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1989 echo "Set user quota (limit: ${blimit}M)"
1990 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1991 error "set user quota failed"
1992 quota_show_check b u $TSTUSR
1993 echo "Update quota limits"
1994 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1995 error "set group quota failed"
1996 quota_show_check b u $TSTUSR
1998 # first wirte might be cached
1999 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2000 cancel_lru_locks osc
2002 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2003 quota_error u $TSTUSR "Write success, expect failure"
2007 resetquota -u $TSTUSR
2009 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2011 test_20() { # b15754
2012 local LSTR=(2g 1t 4k 3m) # limits strings
2014 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2017 resetquota -u $TSTUSR
2019 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2020 $MOUNT || error "could not set quota limits"
2021 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2022 --inode-softlimit ${LSTR[2]} \
2023 --inode-hardlimit ${LSTR[3]} \
2024 $MOUNT || error "could not set quota limits"
2026 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2027 error "bsoftlimit was not set properly"
2028 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2029 error "bhardlimit was not set properly"
2030 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2031 error "isoftlimit was not set properly"
2032 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2033 error "ihardlimit was not set properly"
2035 resetquota -u $TSTUSR
2037 run_test 20 "Test if setquota specifiers work properly (b15754)"
2044 local time=$(($(date +%s) + seconds))
2045 while [ $(date +%s) -lt $time ]; do
2046 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2050 # run for fixing bug16053, setquota shouldn't fail when writing and
2051 # deleting are happening
2053 local TESTFILE="$DIR/$tdir/$tfile"
2054 local BLIMIT=10 # 10G
2055 local ILIMIT=1000000
2057 setup_quota_test || error "setup quota failed with $?"
2058 trap cleanup_quota_test EXIT
2060 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2062 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2063 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2064 error "set user quota failed"
2065 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2066 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2067 error "set group quota failed"
2068 if is_project_quota_supported; then
2069 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2070 "project: $TSTPRJID"
2071 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2072 $MOUNT || error "set project quota failed"
2075 # repeat writing on a 1M file
2076 test_21_sub ${TESTFILE}_1 1 30 &
2078 # repeat writing on a 128M file
2079 test_21_sub ${TESTFILE}_2 128 30 &
2082 local time=$(($(date +%s) + 30))
2084 while [ $(date +%s) -lt $time ]; do
2085 log "Set quota for $i times"
2086 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2087 -I $((ILIMIT + i)) $MOUNT ||
2088 error "Set user quota failed"
2089 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2090 -I $((ILIMIT + i)) $MOUNT ||
2091 error "Set group quota failed"
2092 if is_project_quota_supported; then
2093 $LFS setquota -p $TSTPRJID -b 0 -B \
2094 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2095 error "Set project quota failed"
2103 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2105 if [ $count -gt 60 ]; then
2106 quota_error a $TSTUSR "dd should be finished!"
2110 echo "(dd_pid=$DDPID1, time=$count)successful"
2114 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2116 if [ $count -gt 60 ]; then
2117 quota_error a $TSTUSR "dd should be finished!"
2121 echo "(dd_pid=$DDPID2, time=$count)successful"
2124 resetquota -u $TSTUSR
2125 resetquota -g $TSTUSR
2126 resetquota -p $TSTPRJID
2128 run_test 21 "Setquota while writing & deleting (b16053)"
2130 # enable/disable quota enforcement permanently
2132 echo "Set both mdt & ost quota type as ug"
2134 is_project_quota_supported && qtype=$QTYPE
2135 set_mdt_qtype $qtype || error "enable mdt quota failed"
2136 set_ost_qtype $qtype || error "enable ost quota failed"
2139 stopall || error "failed to stopall (1)"
2143 echo "Verify if quota is enabled"
2144 local qtype1=$(mdt_quota_type)
2145 [ $qtype1 != $qtype] && error "mdt quota setting is lost"
2146 qtype=$(ost_quota_type)
2147 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2149 echo "Set both mdt & ost quota type as none"
2150 set_mdt_qtype "none" || error "disable mdt quota failed"
2151 set_ost_qtype "none" || error "disable ost quota failed"
2154 stopall || error "failed to stopall (2)"
2159 echo "Verify if quota is disabled"
2160 qtype=$(mdt_quota_type)
2161 [ $qtype != "none" ] && error "mdt quota setting is lost"
2162 qtype=$(ost_quota_type)
2163 [ $qtype != "none" ] && error "ost quota setting is lost"
2167 run_test 22 "enable/disable quota by 'lctl conf_param'"
2170 local TESTFILE="$DIR/$tdir/$tfile"
2173 setup_quota_test || error "setup quota failed with $?"
2174 trap cleanup_quota_test EXIT
2176 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2179 log "User quota (limit: $LIMIT MB)"
2180 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2181 error "set quota failed"
2182 quota_show_check b u $TSTUSR
2184 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2185 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2187 log "Step1: trigger EDQUOT with O_DIRECT"
2188 log "Write half of file"
2189 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2190 quota_error u $TSTUSR "(1) Write failure, expect success." \
2192 log "Write out of block quota ..."
2193 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2194 oflag=direct conv=notrunc &&
2195 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2199 log "Step2: rewrite should succeed"
2200 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2201 quota_error u $TSTUSR "(3) Write failure, expect success." \
2207 local OST0_UUID=$(ostuuid_from_index 0)
2208 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2209 [ $OST0_QUOTA_USED -ne 0 ] &&
2210 ($SHOW_QUOTA_USER; \
2211 quota_error u $TSTUSR "quota isn't released")
2213 resetquota -u $TSTUSR
2217 [ $(facet_fstype ost1) == "zfs" ] &&
2218 skip "Overwrite in place is not guaranteed to be " \
2219 "space neutral on ZFS" && return
2221 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2222 check_whether_skip && return 0
2223 log "run for 4MB test file"
2226 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2227 check_whether_skip && return 0
2228 log "run for 40MB test file"
2231 run_test 23 "Quota should be honored with directIO (b16125)"
2235 local TESTFILE="$DIR/$tdir/$tfile"
2237 setup_quota_test || error "setup quota failed with $?"
2238 trap cleanup_quota_test EXIT
2240 set_ost_qtype $QTYPE || error "enable ost quota failed"
2242 # bind file to a single OST
2243 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2244 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2246 echo "Set user quota (limit: ${blimit}M)"
2247 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2248 error "set quota failed"
2250 # overrun quota by root user
2251 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2252 error "write failure, expect success"
2253 cancel_lru_locks osc
2254 sync_all_data || true
2256 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2259 resetquota -u $TSTUSR
2261 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2263 test_27a() { # b19612
2264 $LFS quota $TSTUSR $DIR &&
2265 error "lfs succeeded with no type, but should have failed"
2266 $LFS setquota $TSTUSR $DIR &&
2267 error "lfs succeeded with no type, but should have failed"
2270 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2272 test_27b() { # b20200
2273 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2274 error "lfs setquota failed with uid argument"
2275 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2276 error "lfs stequota failed with gid argument"
2277 if is_project_quota_supported; then
2278 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2279 1000 $DIR || error \
2280 "lfs stequota failed with projid argument"
2282 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2283 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2284 if is_project_quota_supported; then
2285 $SHOW_QUOTA_PROJID ||
2286 error "lfs quota failed with projid argument"
2288 resetquota -u $TSTUSR
2289 resetquota -g $TSTUSR
2290 resetquota -p $TSTPRJID
2293 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2298 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2299 error "lfs setquota failed"
2301 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2302 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2303 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2304 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2306 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2307 error "lfs setquota for $TSTID failed"
2309 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2310 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2311 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2312 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2314 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2315 error "total allocated inode/block limit not printed"
2317 resetquota -u $TSTUSR
2319 run_test 27c "lfs quota should support human-readable output"
2326 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2327 error "set fraction block limit failed"
2328 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2329 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2330 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2331 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2333 resetquota -u $TSTUSR
2335 run_test 27d "lfs setquota should support fraction block limit"
2339 local TESTFILE="$DIR/$tdir/$tfile"
2342 setup_quota_test || error "setup quota failed with $?"
2343 trap cleanup_quota_test EXIT
2345 set_ost_qtype "u" || error "enable ost quota failed"
2347 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2348 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2350 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2351 $MAX_IQ_TIME $DIR || error "set grace time failed"
2352 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2353 error "set quota failed"
2354 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2355 cancel_lru_locks osc
2357 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2358 # over-quota flag has not yet settled since we do not trigger async
2359 # events based on grace time period expiration
2361 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2362 cancel_lru_locks osc
2363 # now over-quota flag should be settled and further writes should fail
2365 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2366 error "grace times were reset"
2369 resetquota -u $TSTUSR
2370 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2371 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2373 run_test 30 "Hard limit updates should not reset grace times"
2375 # basic usage tracking for user & group
2377 local INODES=10 # 10 files
2378 local BLK_CNT=2 # of 2M each
2379 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2381 setup_quota_test || error "setup quota failed with $?"
2382 trap cleanup_quota_test EXIT
2384 # make sure the system is clean
2385 local USED=$(getquota -u $TSTID global curspace)
2387 error "Used space ($USED) for user $TSTID isn't 0."
2388 USED=$(getquota -g $TSTID global curspace)
2390 error "Used space ($USED) for group $TSTID isn't 0."
2391 if is_project_quota_supported; then
2392 USED=$(getquota -p $TSTPRJID global curspace)
2393 [ $USED -ne 0 ] && error \
2394 "Used space ($USED) for project $TSTPRJID isn't 0."
2397 echo "Write files..."
2398 for i in $(seq 0 $INODES); do
2399 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2400 error "write failed"
2401 is_project_quota_supported &&
2402 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2403 echo "Iteration $i/$INODES completed"
2405 cancel_lru_locks osc
2407 echo "Wait for setattr on objects finished..."
2408 wait_delete_completed
2410 sync; sync_all_data || true
2412 echo "Verify disk usage after write"
2413 USED=$(getquota -u $TSTID global curspace)
2414 [ $USED -lt $TOTAL_BLKS ] &&
2415 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2416 USED=$(getquota -g $TSTID global curspace)
2417 [ $USED -lt $TOTAL_BLKS ] &&
2418 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2419 if is_project_quota_supported; then
2420 USED=$(getquota -p $TSTPRJID global curspace)
2421 [ $USED -lt $TOTAL_BLKS ] && error \
2422 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2425 echo "Verify inode usage after write"
2426 USED=$(getquota -u $TSTID global curinodes)
2427 [ $USED -lt $INODES ] &&
2428 error "Used inode for user $TSTID is $USED, expected $INODES"
2429 USED=$(getquota -g $TSTID global curinodes)
2430 [ $USED -lt $INODES ] &&
2431 error "Used inode for group $TSTID is $USED, expected $INODES"
2432 if is_project_quota_supported; then
2433 USED=$(getquota -p $TSTPRJID global curinodes)
2434 [ $USED -lt $INODES ] && error \
2435 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2440 echo "Verify disk usage after delete"
2441 USED=$(getquota -u $TSTID global curspace)
2442 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2443 USED=$(getquota -u $TSTID global curinodes)
2444 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2445 USED=$(getquota -g $TSTID global curspace)
2446 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2447 USED=$(getquota -g $TSTID global curinodes)
2448 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2449 if is_project_quota_supported; then
2450 USED=$(getquota -p $TSTPRJID global curinodes)
2452 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2455 run_test 33 "Basic usage tracking for user & group & project"
2457 # usage transfer test for user & group & project
2459 local BLK_CNT=2 # 2MB
2460 local project_supported="no"
2462 is_project_quota_supported && project_supported="yes"
2463 setup_quota_test || error "setup quota failed with $?"
2464 trap cleanup_quota_test EXIT
2466 # make sure the system is clean
2467 local USED=$(getquota -u $TSTID global curspace)
2468 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2469 USED=$(getquota -g $TSTID global curspace)
2470 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2472 local USED=$(getquota -u $TSTID2 global curspace)
2473 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2474 if [ $project_supported == "yes" ]; then
2475 USED=$(getquota -p $TSTPRJID global curspace)
2476 [ $USED -ne 0 ] && error \
2477 "Used space ($USED) for Project $TSTPRJID isn't 0."
2480 echo "Write file..."
2481 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2482 error "write failed"
2483 cancel_lru_locks osc
2484 sync; sync_all_data || true
2486 echo "chown the file to user $TSTID"
2487 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2489 echo "Wait for setattr on objects finished..."
2490 wait_delete_completed
2492 BLK_CNT=$((BLK_CNT * 1024))
2494 echo "Verify disk usage for user $TSTID"
2495 USED=$(getquota -u $TSTID global curspace)
2496 [ $USED -lt $BLK_CNT ] &&
2497 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2498 USED=$(getquota -u $TSTID global curinodes)
2500 error "Used inodes for user $TSTID is $USED, expected 1"
2502 echo "chgrp the file to group $TSTID"
2503 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2505 echo "Wait for setattr on objects finished..."
2506 wait_delete_completed
2508 echo "Verify disk usage for group $TSTID"
2509 USED=$(getquota -g $TSTID global curspace)
2510 [ $USED -ge $BLK_CNT ] ||
2511 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2512 USED=$(getquota -g $TSTID global curinodes)
2514 error "Used inodes for group $TSTID is $USED, expected 1"
2516 # chown won't change the ost object group. LU-4345 */
2517 echo "chown the file to user $TSTID2"
2518 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2520 echo "Wait for setattr on objects finished..."
2521 wait_delete_completed
2523 echo "change_project project id to $TSTPRJID"
2524 [ $project_supported == "yes" ] &&
2525 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2526 echo "Wait for setattr on objects finished..."
2527 wait_delete_completed
2529 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2530 USED=$(getquota -u $TSTID2 global curspace)
2531 [ $USED -lt $BLK_CNT ] &&
2532 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2533 USED=$(getquota -u $TSTID global curspace)
2535 error "Used space for user $TSTID is $USED, expected 0"
2536 USED=$(getquota -g $TSTID global curspace)
2537 [ $USED -lt $BLK_CNT ] &&
2538 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2539 if [ $project_supported == "yes" ]; then
2540 USED=$(getquota -p $TSTPRJID global curspace)
2541 [ $USED -lt $BLK_CNT ] && error \
2542 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2547 run_test 34 "Usage transfer for user & group & project"
2549 # usage is still accessible across restart
2551 local BLK_CNT=2 # 2 MB
2553 setup_quota_test || error "setup quota failed with $?"
2554 trap cleanup_quota_test EXIT
2556 echo "Write file..."
2557 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2558 error "write failed"
2559 is_project_quota_supported &&
2560 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2561 cancel_lru_locks osc
2563 echo "Wait for setattr on objects finished..."
2564 wait_delete_completed
2566 sync; sync_all_data || true
2568 echo "Save disk usage before restart"
2569 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2570 [ $ORIG_USR_SPACE -eq 0 ] &&
2571 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2572 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2573 [ $ORIG_USR_INODES -eq 0 ] &&
2574 error "Used inodes for user $TSTID is 0, expected 1"
2575 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2576 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2577 [ $ORIG_GRP_SPACE -eq 0 ] &&
2578 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2579 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2580 [ $ORIG_GRP_INODES -eq 0 ] &&
2581 error "Used inodes for group $TSTID is 0, expected 1"
2582 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2584 if is_project_quota_supported; then
2585 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2586 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2587 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2588 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2589 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2590 "Used inodes for project $TSTPRJID is 0, expected 1"
2591 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2595 local ORIG_REFORMAT=$REFORMAT
2597 cleanup_and_setup_lustre
2598 REFORMAT=$ORIG_REFORMAT
2601 echo "Verify disk usage after restart"
2602 local USED=$(getquota -u $TSTID global curspace)
2603 [ $USED -eq $ORIG_USR_SPACE ] ||
2604 error "Used space for user $TSTID changed from " \
2605 "$ORIG_USR_SPACE to $USED"
2606 USED=$(getquota -u $TSTID global curinodes)
2607 [ $USED -eq $ORIG_USR_INODES ] ||
2608 error "Used inodes for user $TSTID changed from " \
2609 "$ORIG_USR_INODES to $USED"
2610 USED=$(getquota -g $TSTID global curspace)
2611 [ $USED -eq $ORIG_GRP_SPACE ] ||
2612 error "Used space for group $TSTID changed from " \
2613 "$ORIG_GRP_SPACE to $USED"
2614 USED=$(getquota -g $TSTID global curinodes)
2615 [ $USED -eq $ORIG_GRP_INODES ] ||
2616 error "Used inodes for group $TSTID changed from " \
2617 "$ORIG_GRP_INODES to $USED"
2618 if [ $project_supported == "yes" ]; then
2619 USED=$(getquota -p $TSTPRJID global curinodes)
2620 [ $USED -eq $ORIG_PRJ_INODES ] ||
2621 error "Used inodes for project $TSTPRJID " \
2622 "changed from $ORIG_PRJ_INODES to $USED"
2623 USED=$(getquota -p $TSTPRJID global curspace)
2624 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2625 error "Used space for project $TSTPRJID "\
2626 "changed from $ORIG_PRJ_SPACE to $USED"
2629 # check if the vfs_dq_init() is called before writing
2630 echo "Append to the same file..."
2631 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2632 error "write failed"
2633 cancel_lru_locks osc
2634 sync; sync_all_data || true
2636 echo "Verify space usage is increased"
2637 USED=$(getquota -u $TSTID global curspace)
2638 [ $USED -gt $ORIG_USR_SPACE ] ||
2639 error "Used space for user $TSTID isn't increased" \
2640 "orig:$ORIG_USR_SPACE, now:$USED"
2641 USED=$(getquota -g $TSTID global curspace)
2642 [ $USED -gt $ORIG_GRP_SPACE ] ||
2643 error "Used space for group $TSTID isn't increased" \
2644 "orig:$ORIG_GRP_SPACE, now:$USED"
2645 if [ $project_supported == "yes" ]; then
2646 USED=$(getquota -p $TSTPRJID global curspace)
2647 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2648 error "Used space for project $TSTPRJID isn't " \
2649 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2654 run_test 35 "Usage is still accessible across reboot"
2656 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2659 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2660 skip "Old server doesn't have LU-5006 fix." && return
2662 setup_quota_test || error "setup quota failed with $?"
2663 trap cleanup_quota_test EXIT
2665 # make sure the system is clean
2666 local USED=$(getquota -u $TSTID global curspace)
2668 error "Used space ($USED) for user $TSTID isn't 0."
2670 # create file with MDS_OPEN_DELAY_CREATE flag
2671 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2672 error "Create file failed"
2674 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2675 oflag=sync || error "Write file failed"
2677 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2679 # wait for setattr on objects finished..."
2680 wait_delete_completed
2682 USED=$(getquota -u $TSTID global curspace)
2683 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2687 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2691 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2692 skip "Old server doesn't have LU-8801 fix." && return
2694 [ "$UID" != 0 ] && skip_env "must run as root" && return
2696 setup_quota_test || error "setup quota failed with $?"
2697 trap cleanup_quota_test EXIT
2699 # make sure the system is clean
2700 local USED=$(getquota -u $TSTID global curspace)
2702 error "Used space ($USED) for user $TSTID isn't 0."
2703 USED=$(getquota -u $TSTID2 global curspace)
2705 error "Used space ($USED) for user $TSTID2 isn't 0."
2707 local TESTFILE="$DIR/$tdir/$tfile"
2708 local file_cnt=10000
2710 # Generate id entries in accounting file
2711 echo "Create $file_cnt files..."
2712 for i in `seq $file_cnt`; do
2714 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2716 cancel_lru_locks osc
2717 sync; sync_all_data || true
2719 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2720 procf=${procf}.quota_slave.acct_user
2723 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2724 echo "Found $acct_cnt id entries"
2726 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2730 run_test 38 "Quota accounting iterator doesn't skip id entries"
2733 local TESTFILE="$DIR/$tdir/project"
2734 ! is_project_quota_supported &&
2735 skip "Project quota is not supported" && return 0
2737 setup_quota_test || error "setup quota failed with $?"
2740 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2741 [ $projectid -ne 0 ] &&
2742 error "Project id should be 0 not $projectid"
2743 change_project -p 1024 $TESTFILE
2744 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2745 [ $projectid -ne 1024 ] &&
2746 error "Project id should be 1024 not $projectid"
2748 stopall || error "failed to stopall (1)"
2751 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2752 [ $projectid -ne 1024 ] &&
2753 error "Project id should be 1024 not $projectid"
2757 run_test 39 "Project ID interface works correctly"
2760 ! is_project_quota_supported &&
2761 skip "Project quota is not supported" && return 0
2762 local dir1="$DIR/$tdir/dir1"
2763 local dir2="$DIR/$tdir/dir2"
2765 setup_quota_test || error "setup quota failed with $?"
2767 mkdir -p $dir1 $dir2
2768 change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
2769 change_project +P $dir2 && change_project -p 2 -d $dir2
2771 ln $dir1/1 $dir2/1_link &&
2772 error "Hard link across different project quota should fail"
2777 run_test 40a "Hard link across different project ID"
2780 ! is_project_quota_supported &&
2781 skip "Project quota is not supported" && return 0
2782 local dir1="$DIR/$tdir/dir1"
2783 local dir2="$DIR/$tdir/dir2"
2785 setup_quota_test || error "setup quota failed with $?"
2786 mkdir -p $dir1 $dir2
2787 change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
2788 change_project +P $dir2 && change_project -p 2 -d $dir2
2790 mv $dir1/1 $dir2/2 || error "mv failed $?"
2791 local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
2792 if [ "$projid" != "2" ]; then
2793 error "project id expected 2 not $projid"
2798 run_test 40b "Mv across different project ID"
2801 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
2802 ! is_project_quota_supported &&
2803 skip "Project quota is not supported" && return 0
2805 setup_quota_test || error "setup quota failed with $?"
2806 local dir="$DIR/$tdir/dir"
2808 mkdir -p $dir && change_project +P $dir && change_project -dp 1 $dir
2809 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2810 local projid=$(lsattr -dp $dir/remote_dir | awk '{print $1}')
2811 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2812 touch $dir/remote_dir/file
2813 #verify inherit works file for remote dir.
2814 local projid=$(lsattr -dp $dir/remote_dir/file | awk '{print $1}')
2815 [ "$projid" != "1" ] &&
2816 error "file under remote dir expected 1 not $projid"
2818 #Agent inode should be ignored for project quota
2819 USED=$(getquota -p 1 global curinodes)
2820 [ "$USED" != "3" ] &&
2821 error "file count expected 3 got $USED"
2827 run_test 40c "Remote child Dir inherit project quota properly"
2830 ! is_project_quota_supported &&
2831 skip "Project quota is not supported" && return 0
2833 setup_quota_test || error "setup quota failed with $?"
2834 local dir="$DIR/$tdir/dir"
2836 mkdir $dir && change_project -dp 1 $dir
2837 count=$($LFS find --projid 1 $DIR | wc -l)
2838 [ "$count" != 1 ] && error "expected 1 but got $count"
2843 run_test 50 "Test if lfs find --projid works"
2846 ! is_project_quota_supported &&
2847 skip "Project quota is not supported" && return 0
2848 setup_quota_test || error "setup quota failed with $?"
2849 local dir="$DIR/$tdir/dir"
2851 mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
2852 local used=$(getquota -p 1 global curinodes)
2853 [ $used != "1" ] && error "expected 1 got $used"
2858 used=$(getquota -p 1 global curinodes)
2859 [ $used != "4" ] && error "expected 4 got $used"
2861 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2863 cp $DIR/$tdir/6 $dir/6
2864 used=$(getquota -p 1 global curinodes)
2865 [ $used != "5" ] && error "expected 5 got $used"
2868 mv $DIR/$tdir/6 $dir/7
2869 used=$(getquota -p 1 global curinodes)
2870 [ $used != "6" ] && error "expected 6 got $used"
2875 run_test 51 "Test project accounting with mv/cp"
2878 ! is_project_quota_supported &&
2879 skip "Project quota is not supported" && return 0
2880 setup_quota_test || error "setup quota failed with $?"
2881 local dir="$DIR/$tdir/dir"
2882 mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
2884 touch $DIR/$tdir/file
2885 #Try renaming a file into the project. This should fail.
2886 for num in $(seq 1 2000); do
2887 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2888 error "rename should fail"
2893 run_test 52 "Rename across different project ID"
2897 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2898 disable_project_quota
2904 check_and_cleanup_lustre
2905 export QUOTA_AUTO=$QUOTA_AUTO_OLD