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 "Required more 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 zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
1416 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] &&
1417 skip "requires zfs version at least 0.7.0" && return
1420 local ilimit=$((1024 * 2)) # 2k inodes
1421 local TESTFILE=$DIR/${tdir}-1/$tfile
1423 setup_quota_test || error "setup quota failed with $?"
1424 trap cleanup_quota_test EXIT
1426 # make sure the system is clean
1427 local USED=$(getquota -u $TSTUSR global curinodes)
1428 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1430 # make sure no granted quota on mdt1
1431 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1432 resetquota -u $TSTUSR
1433 set_mdt_qtype "none" || error "disable mdt quota failed"
1435 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1436 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1437 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1440 echo "Stop mds${MDSCOUNT}..."
1443 echo "Enable quota & set quota limit for $TSTUSR"
1444 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1445 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1446 error "set quota failed"
1448 echo "Start mds${MDSCOUNT}..."
1449 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1452 wait_mdt_reint $QTYPE || error "reintegration failed"
1454 echo "create remote dir"
1455 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1456 error "create remote dir failed"
1457 chmod 0777 $DIR/${tdir}-1
1459 # hardlimit should have been fetched by slave during global
1460 # reintegration, create will exceed quota
1461 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1462 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1464 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1465 wait_delete_completed
1466 sync_all_data || true
1468 echo "Stop mds${MDSCOUNT}..."
1471 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1472 error "clear quota failed"
1474 echo "Start mds${MDSCOUNT}..."
1475 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1478 wait_mdt_reint $QTYPE || error "reintegration failed"
1480 # hardlimit should be cleared on slave during reintegration
1481 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1482 quota_error -u $TSTUSR "create failed, expect success"
1484 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1485 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1488 resetquota -u $TSTUSR
1490 run_test 7e "Quota reintegration (inode limits)"
1492 # run dbench with quota enabled
1494 local BLK_LIMIT="100g" #100G
1495 local FILE_LIMIT=1000000
1497 setup_quota_test || error "setup quota failed with $?"
1498 trap cleanup_quota_test EXIT
1500 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1501 set_ost_qtype $QTYPE || error "enable ost quota failed"
1503 echo "Set enough high limit for user: $TSTUSR"
1504 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1505 error "set user quota failed"
1506 echo "Set enough high limit for group: $TSTUSR"
1507 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1508 error "set group quota failed"
1509 if is_project_quota_supported; then
1510 change_project +P $DIR/$tdir && change_project -p \
1511 $TSTPRJID -d $DIR/$tdir
1512 echo "Set enough high limit for project: $TSTPRJID"
1513 $LFS setquota -p $TSTPRJID -b 0 \
1514 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1515 error "set project quota failed"
1519 [ "$SLOW" = "no" ] && duration=" -t 120"
1520 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1521 quota_error a $TSTUSR "dbench failed!"
1523 is_project_quota_supported && change_project -P $DIR/$tdir &&
1524 change_project -dp 0 $DIR/$tdir
1526 resetquota -u $TSTUSR
1527 resetquota -g $TSTUSR
1528 resetquota -p $TSTPRJID
1530 run_test 8 "Run dbench with quota enabled"
1532 # this check is just for test_9
1533 OST0_MIN=4900000 #4.67G
1535 check_whether_skip () {
1536 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1537 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1538 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1539 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1546 # run for fixing bug10707, it needs a big room. test for 64bit
1548 local filesize=$((1024 * 9 / 2)) # 4.5G
1550 check_whether_skip && return 0
1552 setup_quota_test || error "setup quota failed with $?"
1553 trap cleanup_quota_test EXIT
1555 set_ost_qtype "ug" || error "enable ost quota failed"
1557 local TESTFILE="$DIR/$tdir/$tfile-0"
1558 local BLK_LIMIT=100G #100G
1559 local FILE_LIMIT=1000000
1561 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1563 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1565 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1566 error "set user quota failed"
1568 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1569 "for group: $TSTUSR"
1570 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1571 error "set group quota failed"
1573 quota_show_check a u $TSTUSR
1574 quota_show_check a g $TSTUSR
1576 echo "Create test file"
1577 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1578 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1580 log "Write the big file of 4.5G ..."
1581 $RUNAS $DD of=$TESTFILE count=$filesize ||
1582 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1588 resetquota -u $TSTUSR
1589 resetquota -g $TSTUSR
1594 run_test 9 "Block limit larger than 4GB (b10707)"
1597 local TESTFILE=$DIR/$tdir/$tfile
1599 setup_quota_test || error "setup quota failed with $?"
1600 trap cleanup_quota_test EXIT
1602 # set limit to root user should fail
1603 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1604 error "set limit for root user successfully, expect failure"
1605 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1606 error "set limit for root group successfully, expect failure"
1607 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1608 error "set limit for project 0 successfully, expect failure"
1610 # root user can overrun quota
1611 set_ost_qtype "ug" || error "enable ost quota failed"
1613 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1614 error "set quota failed"
1615 quota_show_check b u $TSTUSR
1617 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1618 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1620 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1621 error "write failure, expect success"
1624 resetquota -u $TSTUSR
1626 run_test 10 "Test quota for root user"
1629 local TESTFILE=$DIR/$tdir/$tfile
1630 setup_quota_test || error "setup quota failed with $?"
1631 trap cleanup_quota_test EXIT
1633 set_mdt_qtype "ug" || error "enable mdt quota failed"
1634 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1635 error "set quota failed"
1637 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1638 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1640 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1641 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1644 local USED=$(getquota -u $TSTUSR global curinodes)
1645 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1648 resetquota -u $TSTUSR
1650 run_test 11 "Chown/chgrp ignores quota"
1653 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1655 local blimit=22 # 22M
1656 local blk_cnt=$((blimit - 5))
1657 local TESTFILE0="$DIR/$tdir/$tfile"-0
1658 local TESTFILE1="$DIR/$tdir/$tfile"-1
1660 setup_quota_test || error "setup quota failed with $?"
1661 trap cleanup_quota_test EXIT
1663 set_ost_qtype "u" || error "enable ost quota failed"
1664 quota_show_check b u $TSTUSR
1666 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1667 error "set quota failed"
1669 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1670 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1671 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1672 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1674 echo "Write to ost0..."
1675 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1676 quota_error a $TSTUSR "dd failed"
1678 echo "Write to ost1..."
1679 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1680 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1682 echo "Free space from ost0..."
1684 wait_delete_completed
1685 sync_all_data || true
1687 echo "Write to ost1 after space freed from ost0..."
1688 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1689 quota_error a $TSTUSR "rebalancing failed"
1692 resetquota -u $TSTUSR
1694 run_test 12a "Block quota rebalancing"
1697 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1699 local ilimit=$((1024 * 2)) # 2k inodes
1700 local TESTFILE0=$DIR/$tdir/$tfile
1701 local TESTFILE1=$DIR/${tdir}-1/$tfile
1703 setup_quota_test || error "setup quota failed with $?"
1704 trap cleanup_quota_test EXIT
1706 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1707 chmod 0777 $DIR/${tdir}-1
1709 set_mdt_qtype "u" || error "enable mdt quota failed"
1710 quota_show_check f u $TSTUSR
1712 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1713 error "set quota failed"
1715 echo "Create $ilimit files on mdt0..."
1716 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1717 quota_error u $TSTUSR "create failed, but expect success"
1719 echo "Create files on mdt1..."
1720 $RUNAS createmany -m $TESTFILE1 1 &&
1721 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1723 echo "Free space from mdt0..."
1724 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1725 wait_delete_completed
1726 sync_all_data || true
1728 echo "Create files on mdt1 after space freed from mdt0..."
1729 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1730 quota_error a $TSTUSR "rebalancing failed"
1732 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1733 error "unlink mdt1 files failed"
1734 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1737 resetquota -u $TSTUSR
1739 run_test 12b "Inode quota rebalancing"
1742 local TESTFILE=$DIR/$tdir/$tfile
1743 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1744 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1746 setup_quota_test || error "setup quota failed with $?"
1747 trap cleanup_quota_test EXIT
1749 set_ost_qtype "u" || error "enable ost quota failed"
1750 quota_show_check b u $TSTUSR
1752 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1753 error "set quota failed"
1754 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1755 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1757 # clear the locks in cache first
1758 do_facet ost1 $LCTL set_param -n $procf=clear
1759 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1760 [ $nlock -eq 0 ] || error "$nlock cached locks"
1762 # write to acquire the per-ID lock
1763 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1764 quota_error a $TSTUSR "dd failed"
1766 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1767 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1769 # clear quota doesn't trigger per-ID lock cancellation
1770 resetquota -u $TSTUSR
1771 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1772 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1774 # clear the per-ID lock
1775 do_facet ost1 $LCTL set_param -n $procf=clear
1776 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1777 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1779 # spare quota should be released
1780 local OSTUUID=$(ostuuid_from_index 0)
1781 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1782 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1783 [ $limit -le $space ] ||
1784 error "spare quota isn't released, limit:$limit, space:$space"
1788 run_test 13 "Cancel per-ID lock in the LRU list"
1791 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1793 wait_delete_completed
1794 sync_all_data || true
1797 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1798 error "set user quota failed"
1799 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1800 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1801 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1802 resetquota -u $TSTUSR
1805 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1806 error "set group quota failed"
1807 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1808 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1809 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1810 resetquota -g $TSTUSR
1812 run_test 15 "Set over 4T block quota"
1816 local BLKS=1 # 1M less than limit
1817 local TESTFILE=$DIR/$tdir/$tfile
1819 setup_quota_test || error "setup quota failed with $?"
1820 trap cleanup_quota_test EXIT
1822 # make sure the system is clean
1823 local USED=$(getquota -u $TSTUSR global curspace)
1824 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1826 set_ost_qtype "ug" || error "enable ost quota failed"
1827 # make sure no granted quota on ost
1828 resetquota -u $TSTUSR
1829 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1830 error "set quota failed"
1832 quota_show_check b u $TSTUSR
1834 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1835 lustre_fail mds 0xa04 $err_code
1837 # write in background
1838 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1842 # write should be blocked and never finished
1843 if ! ps -p $DDPID > /dev/null 2>&1; then
1845 quota_error u $TSTUSR "write finished incorrectly!"
1853 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1855 if [ $count -gt $timeout ]; then
1856 quota_error u $TSTUSR "dd is not finished!"
1861 sync; sync_all_data || true
1863 USED=$(getquota -u $TSTUSR global curspace)
1864 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1865 "Used space(${USED}K) is less than ${BLKS}M"
1868 resetquota -u $TSTUSR
1871 # DQACQ return recoverable error
1873 echo "DQACQ return -ENOLCK"
1875 test_17sub 37 || error "Handle -ENOLCK failed"
1877 echo "DQACQ return -EAGAIN"
1879 test_17sub 11 || error "Handle -EAGAIN failed"
1881 echo "DQACQ return -ETIMEDOUT"
1882 #define ETIMEDOUT 110
1883 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1885 echo "DQACQ return -ENOTCONN"
1886 #define ENOTCONN 107
1887 test_17sub 107 || error "Handle -ENOTCONN failed"
1890 run_test 17 "DQACQ return recoverable error"
1894 local blimit="200m" # 200M
1895 local TESTFILE="$DIR/$tdir/$tfile"
1897 setup_quota_test || error "setup quota failed with $?"
1898 trap cleanup_quota_test EXIT
1900 set_ost_qtype "u" || error "enable ost quota failed"
1901 log "User quota (limit: $blimit)"
1902 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1903 error "set quota failed"
1904 quota_show_check b u $TSTUSR
1906 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1907 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1909 local timeout=$(sysctl -n lustre.timeout)
1911 if [ $io_type = "directio" ]; then
1912 log "Write 100M (directio) ..."
1913 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1915 log "Write 100M (buffered) ..."
1916 $RUNAS $DD of=$TESTFILE count=100 &
1920 replay_barrier $SINGLEMDS
1921 log "Fail mds for $((2 * timeout)) seconds"
1922 fail $SINGLEMDS $((2 * timeout))
1925 if at_is_enabled; then
1926 timeout=$(at_max_get mds)
1928 timeout=$(lctl get_param -n timeout)
1932 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1933 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1934 log "it took $count second"
1939 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1941 cancel_lru_locks mdc
1942 cancel_lru_locks osc
1945 local testfile_size=$(stat -c %s $TESTFILE)
1946 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1947 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1948 "got ${testfile_size}. Verifying file failed!"
1951 resetquota -u $TSTUSR
1954 # test when mds does failover, the ost still could work well
1955 # this test shouldn't trigger watchdog b=14840
1957 # Clear dmesg so watchdog is not triggered by previous
1959 do_facet ost1 dmesg -c > /dev/null
1962 test_18_sub directio
1964 # check if watchdog is triggered
1965 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1966 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1967 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1968 [ -z "$watchdog" ] || error "$watchdog"
1969 rm -f $TMP/lustre-log-${TESTNAME}.log
1971 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1975 local TESTFILE=$DIR/$tdir/$tfile
1977 setup_quota_test || error "setup quota failed with $?"
1978 trap cleanup_quota_test EXIT
1980 set_ost_qtype $QTYPE || error "enable ost quota failed"
1982 # bind file to a single OST
1983 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1984 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1986 echo "Set user quota (limit: ${blimit}M)"
1987 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1988 error "set user quota failed"
1989 quota_show_check b u $TSTUSR
1990 echo "Update quota limits"
1991 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1992 error "set group quota failed"
1993 quota_show_check b u $TSTUSR
1995 # first wirte might be cached
1996 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1997 cancel_lru_locks osc
1999 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2000 quota_error u $TSTUSR "Write success, expect failure"
2004 resetquota -u $TSTUSR
2006 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2008 test_20() { # b15754
2009 local LSTR=(2g 1t 4k 3m) # limits strings
2011 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2014 resetquota -u $TSTUSR
2016 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2017 $MOUNT || error "could not set quota limits"
2018 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2019 --inode-softlimit ${LSTR[2]} \
2020 --inode-hardlimit ${LSTR[3]} \
2021 $MOUNT || error "could not set quota limits"
2023 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2024 error "bsoftlimit was not set properly"
2025 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2026 error "bhardlimit was not set properly"
2027 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2028 error "isoftlimit was not set properly"
2029 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2030 error "ihardlimit was not set properly"
2032 resetquota -u $TSTUSR
2034 run_test 20 "Test if setquota specifiers work properly (b15754)"
2041 local time=$(($(date +%s) + seconds))
2042 while [ $(date +%s) -lt $time ]; do
2043 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2047 # run for fixing bug16053, setquota shouldn't fail when writing and
2048 # deleting are happening
2050 local TESTFILE="$DIR/$tdir/$tfile"
2051 local BLIMIT=10 # 10G
2052 local ILIMIT=1000000
2054 setup_quota_test || error "setup quota failed with $?"
2055 trap cleanup_quota_test EXIT
2057 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2059 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2060 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2061 error "set user quota failed"
2062 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2063 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2064 error "set group quota failed"
2065 if is_project_quota_supported; then
2066 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2067 "project: $TSTPRJID"
2068 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2069 $MOUNT || error "set project quota failed"
2072 # repeat writing on a 1M file
2073 test_21_sub ${TESTFILE}_1 1 30 &
2075 # repeat writing on a 128M file
2076 test_21_sub ${TESTFILE}_2 128 30 &
2079 local time=$(($(date +%s) + 30))
2081 while [ $(date +%s) -lt $time ]; do
2082 log "Set quota for $i times"
2083 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2084 -I $((ILIMIT + i)) $MOUNT ||
2085 error "Set user quota failed"
2086 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2087 -I $((ILIMIT + i)) $MOUNT ||
2088 error "Set group quota failed"
2089 if is_project_quota_supported; then
2090 $LFS setquota -p $TSTPRJID -b 0 -B \
2091 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2092 error "Set project quota failed"
2100 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2102 if [ $count -gt 60 ]; then
2103 quota_error a $TSTUSR "dd should be finished!"
2107 echo "(dd_pid=$DDPID1, time=$count)successful"
2111 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2113 if [ $count -gt 60 ]; then
2114 quota_error a $TSTUSR "dd should be finished!"
2118 echo "(dd_pid=$DDPID2, time=$count)successful"
2121 resetquota -u $TSTUSR
2122 resetquota -g $TSTUSR
2123 resetquota -p $TSTPRJID
2125 run_test 21 "Setquota while writing & deleting (b16053)"
2127 # enable/disable quota enforcement permanently
2129 echo "Set both mdt & ost quota type as ug"
2131 is_project_quota_supported && qtype=$QTYPE
2132 set_mdt_qtype $qtype || error "enable mdt quota failed"
2133 set_ost_qtype $qtype || error "enable ost quota failed"
2136 stopall || error "failed to stopall (1)"
2140 echo "Verify if quota is enabled"
2141 local qtype1=$(mdt_quota_type)
2142 [ $qtype1 != $qtype] && error "mdt quota setting is lost"
2143 qtype=$(ost_quota_type)
2144 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2146 echo "Set both mdt & ost quota type as none"
2147 set_mdt_qtype "none" || error "disable mdt quota failed"
2148 set_ost_qtype "none" || error "disable ost quota failed"
2151 stopall || error "failed to stopall (2)"
2156 echo "Verify if quota is disabled"
2157 qtype=$(mdt_quota_type)
2158 [ $qtype != "none" ] && error "mdt quota setting is lost"
2159 qtype=$(ost_quota_type)
2160 [ $qtype != "none" ] && error "ost quota setting is lost"
2164 run_test 22 "enable/disable quota by 'lctl conf_param'"
2167 local TESTFILE="$DIR/$tdir/$tfile"
2170 setup_quota_test || error "setup quota failed with $?"
2171 trap cleanup_quota_test EXIT
2173 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2176 log "User quota (limit: $LIMIT MB)"
2177 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2178 error "set quota failed"
2179 quota_show_check b u $TSTUSR
2181 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2182 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2184 log "Step1: trigger EDQUOT with O_DIRECT"
2185 log "Write half of file"
2186 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2187 quota_error u $TSTUSR "(1) Write failure, expect success." \
2189 log "Write out of block quota ..."
2190 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2191 oflag=direct conv=notrunc &&
2192 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2196 log "Step2: rewrite should succeed"
2197 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2198 quota_error u $TSTUSR "(3) Write failure, expect success." \
2204 local OST0_UUID=$(ostuuid_from_index 0)
2205 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2206 [ $OST0_QUOTA_USED -ne 0 ] &&
2207 ($SHOW_QUOTA_USER; \
2208 quota_error u $TSTUSR "quota isn't released")
2210 resetquota -u $TSTUSR
2214 [ $(facet_fstype ost1) == "zfs" ] &&
2215 skip "Overwrite in place is not guaranteed to be " \
2216 "space neutral on ZFS" && return
2218 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2219 check_whether_skip && return 0
2220 log "run for 4MB test file"
2223 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2224 check_whether_skip && return 0
2225 log "run for 40MB test file"
2228 run_test 23 "Quota should be honored with directIO (b16125)"
2232 local TESTFILE="$DIR/$tdir/$tfile"
2234 setup_quota_test || error "setup quota failed with $?"
2235 trap cleanup_quota_test EXIT
2237 set_ost_qtype $QTYPE || error "enable ost quota failed"
2239 # bind file to a single OST
2240 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2241 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2243 echo "Set user quota (limit: ${blimit}M)"
2244 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2245 error "set quota failed"
2247 # overrun quota by root user
2248 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2249 error "write failure, expect success"
2250 cancel_lru_locks osc
2251 sync_all_data || true
2253 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2256 resetquota -u $TSTUSR
2258 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2260 test_27a() { # b19612
2261 $LFS quota $TSTUSR $DIR &&
2262 error "lfs succeeded with no type, but should have failed"
2263 $LFS setquota $TSTUSR $DIR &&
2264 error "lfs succeeded with no type, but should have failed"
2267 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2269 test_27b() { # b20200
2270 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2271 error "lfs setquota failed with uid argument"
2272 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2273 error "lfs stequota failed with gid argument"
2274 if is_project_quota_supported; then
2275 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2276 1000 $DIR || error \
2277 "lfs stequota failed with projid argument"
2279 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2280 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2281 if is_project_quota_supported; then
2282 $SHOW_QUOTA_PROJID ||
2283 error "lfs quota failed with projid argument"
2285 resetquota -u $TSTUSR
2286 resetquota -g $TSTUSR
2287 resetquota -p $TSTPRJID
2290 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2295 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2296 error "lfs setquota failed"
2298 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2299 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2300 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2301 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2303 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2304 error "lfs setquota for $TSTID failed"
2306 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2307 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2308 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2309 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2311 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2312 error "total allocated inode/block limit not printed"
2314 resetquota -u $TSTUSR
2316 run_test 27c "lfs quota should support human-readable output"
2323 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2324 error "set fraction block limit failed"
2325 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2326 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2327 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2328 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2330 resetquota -u $TSTUSR
2332 run_test 27d "lfs setquota should support fraction block limit"
2336 local TESTFILE="$DIR/$tdir/$tfile"
2339 setup_quota_test || error "setup quota failed with $?"
2340 trap cleanup_quota_test EXIT
2342 set_ost_qtype "u" || error "enable ost quota failed"
2344 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2345 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2347 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2348 $MAX_IQ_TIME $DIR || error "set grace time failed"
2349 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2350 error "set quota failed"
2351 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2352 cancel_lru_locks osc
2354 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2355 # over-quota flag has not yet settled since we do not trigger async
2356 # events based on grace time period expiration
2358 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2359 cancel_lru_locks osc
2360 # now over-quota flag should be settled and further writes should fail
2362 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2363 error "grace times were reset"
2366 resetquota -u $TSTUSR
2367 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2368 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2370 run_test 30 "Hard limit updates should not reset grace times"
2372 # basic usage tracking for user & group
2374 local INODES=10 # 10 files
2375 local BLK_CNT=2 # of 2M each
2376 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2378 setup_quota_test || error "setup quota failed with $?"
2379 trap cleanup_quota_test EXIT
2381 # make sure the system is clean
2382 local USED=$(getquota -u $TSTID global curspace)
2384 error "Used space ($USED) for user $TSTID isn't 0."
2385 USED=$(getquota -g $TSTID global curspace)
2387 error "Used space ($USED) for group $TSTID isn't 0."
2388 if is_project_quota_supported; then
2389 USED=$(getquota -p $TSTPRJID global curspace)
2390 [ $USED -ne 0 ] && error \
2391 "Used space ($USED) for project $TSTPRJID isn't 0."
2394 echo "Write files..."
2395 for i in $(seq 0 $INODES); do
2396 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2397 error "write failed"
2398 is_project_quota_supported &&
2399 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2400 echo "Iteration $i/$INODES completed"
2402 cancel_lru_locks osc
2404 echo "Wait for setattr on objects finished..."
2405 wait_delete_completed
2407 sync; sync_all_data || true
2409 echo "Verify disk usage after write"
2410 USED=$(getquota -u $TSTID global curspace)
2411 [ $USED -lt $TOTAL_BLKS ] &&
2412 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2413 USED=$(getquota -g $TSTID global curspace)
2414 [ $USED -lt $TOTAL_BLKS ] &&
2415 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2416 if is_project_quota_supported; then
2417 USED=$(getquota -p $TSTPRJID global curspace)
2418 [ $USED -lt $TOTAL_BLKS ] && error \
2419 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2422 echo "Verify inode usage after write"
2423 USED=$(getquota -u $TSTID global curinodes)
2424 [ $USED -lt $INODES ] &&
2425 error "Used inode for user $TSTID is $USED, expected $INODES"
2426 USED=$(getquota -g $TSTID global curinodes)
2427 [ $USED -lt $INODES ] &&
2428 error "Used inode for group $TSTID is $USED, expected $INODES"
2429 if is_project_quota_supported; then
2430 USED=$(getquota -p $TSTPRJID global curinodes)
2431 [ $USED -lt $INODES ] && error \
2432 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2437 echo "Verify disk usage after delete"
2438 USED=$(getquota -u $TSTID global curspace)
2439 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2440 USED=$(getquota -u $TSTID global curinodes)
2441 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2442 USED=$(getquota -g $TSTID global curspace)
2443 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2444 USED=$(getquota -g $TSTID global curinodes)
2445 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2446 if is_project_quota_supported; then
2447 USED=$(getquota -p $TSTPRJID global curinodes)
2449 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2452 run_test 33 "Basic usage tracking for user & group & project"
2454 # usage transfer test for user & group & project
2456 local BLK_CNT=2 # 2MB
2457 local project_supported="no"
2459 is_project_quota_supported && project_supported="yes"
2460 setup_quota_test || error "setup quota failed with $?"
2461 trap cleanup_quota_test EXIT
2463 # make sure the system is clean
2464 local USED=$(getquota -u $TSTID global curspace)
2465 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2466 USED=$(getquota -g $TSTID global curspace)
2467 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2469 local USED=$(getquota -u $TSTID2 global curspace)
2470 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2471 if [ $project_supported == "yes" ]; then
2472 USED=$(getquota -p $TSTPRJID global curspace)
2473 [ $USED -ne 0 ] && error \
2474 "Used space ($USED) for Project $TSTPRJID isn't 0."
2477 echo "Write file..."
2478 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2479 error "write failed"
2480 cancel_lru_locks osc
2481 sync; sync_all_data || true
2483 echo "chown the file to user $TSTID"
2484 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2486 echo "Wait for setattr on objects finished..."
2487 wait_delete_completed
2489 BLK_CNT=$((BLK_CNT * 1024))
2491 echo "Verify disk usage for user $TSTID"
2492 USED=$(getquota -u $TSTID global curspace)
2493 [ $USED -lt $BLK_CNT ] &&
2494 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2495 USED=$(getquota -u $TSTID global curinodes)
2497 error "Used inodes for user $TSTID is $USED, expected 1"
2499 echo "chgrp the file to group $TSTID"
2500 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2502 echo "Wait for setattr on objects finished..."
2503 wait_delete_completed
2505 echo "Verify disk usage for group $TSTID"
2506 USED=$(getquota -g $TSTID global curspace)
2507 [ $USED -ge $BLK_CNT ] ||
2508 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2509 USED=$(getquota -g $TSTID global curinodes)
2511 error "Used inodes for group $TSTID is $USED, expected 1"
2513 # chown won't change the ost object group. LU-4345 */
2514 echo "chown the file to user $TSTID2"
2515 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2517 echo "Wait for setattr on objects finished..."
2518 wait_delete_completed
2520 echo "change_project project id to $TSTPRJID"
2521 [ $project_supported == "yes" ] &&
2522 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2523 echo "Wait for setattr on objects finished..."
2524 wait_delete_completed
2526 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2527 USED=$(getquota -u $TSTID2 global curspace)
2528 [ $USED -lt $BLK_CNT ] &&
2529 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2530 USED=$(getquota -u $TSTID global curspace)
2532 error "Used space for user $TSTID is $USED, expected 0"
2533 USED=$(getquota -g $TSTID global curspace)
2534 [ $USED -lt $BLK_CNT ] &&
2535 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2536 if [ $project_supported == "yes" ]; then
2537 USED=$(getquota -p $TSTPRJID global curspace)
2538 [ $USED -lt $BLK_CNT ] && error \
2539 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2544 run_test 34 "Usage transfer for user & group & project"
2546 # usage is still accessible across restart
2548 local BLK_CNT=2 # 2 MB
2550 setup_quota_test || error "setup quota failed with $?"
2551 trap cleanup_quota_test EXIT
2553 echo "Write file..."
2554 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2555 error "write failed"
2556 is_project_quota_supported &&
2557 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2558 cancel_lru_locks osc
2560 echo "Wait for setattr on objects finished..."
2561 wait_delete_completed
2563 sync; sync_all_data || true
2565 echo "Save disk usage before restart"
2566 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2567 [ $ORIG_USR_SPACE -eq 0 ] &&
2568 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2569 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2570 [ $ORIG_USR_INODES -eq 0 ] &&
2571 error "Used inodes for user $TSTID is 0, expected 1"
2572 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2573 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2574 [ $ORIG_GRP_SPACE -eq 0 ] &&
2575 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2576 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2577 [ $ORIG_GRP_INODES -eq 0 ] &&
2578 error "Used inodes for group $TSTID is 0, expected 1"
2579 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2581 if is_project_quota_supported; then
2582 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2583 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2584 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2585 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2586 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2587 "Used inodes for project $TSTPRJID is 0, expected 1"
2588 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2592 local ORIG_REFORMAT=$REFORMAT
2594 cleanup_and_setup_lustre
2595 REFORMAT=$ORIG_REFORMAT
2598 echo "Verify disk usage after restart"
2599 local USED=$(getquota -u $TSTID global curspace)
2600 [ $USED -eq $ORIG_USR_SPACE ] ||
2601 error "Used space for user $TSTID changed from " \
2602 "$ORIG_USR_SPACE to $USED"
2603 USED=$(getquota -u $TSTID global curinodes)
2604 [ $USED -eq $ORIG_USR_INODES ] ||
2605 error "Used inodes for user $TSTID changed from " \
2606 "$ORIG_USR_INODES to $USED"
2607 USED=$(getquota -g $TSTID global curspace)
2608 [ $USED -eq $ORIG_GRP_SPACE ] ||
2609 error "Used space for group $TSTID changed from " \
2610 "$ORIG_GRP_SPACE to $USED"
2611 USED=$(getquota -g $TSTID global curinodes)
2612 [ $USED -eq $ORIG_GRP_INODES ] ||
2613 error "Used inodes for group $TSTID changed from " \
2614 "$ORIG_GRP_INODES to $USED"
2615 if [ $project_supported == "yes" ]; then
2616 USED=$(getquota -p $TSTPRJID global curinodes)
2617 [ $USED -eq $ORIG_PRJ_INODES ] ||
2618 error "Used inodes for project $TSTPRJID " \
2619 "changed from $ORIG_PRJ_INODES to $USED"
2620 USED=$(getquota -p $TSTPRJID global curspace)
2621 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2622 error "Used space for project $TSTPRJID "\
2623 "changed from $ORIG_PRJ_SPACE to $USED"
2626 # check if the vfs_dq_init() is called before writing
2627 echo "Append to the same file..."
2628 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2629 error "write failed"
2630 cancel_lru_locks osc
2631 sync; sync_all_data || true
2633 echo "Verify space usage is increased"
2634 USED=$(getquota -u $TSTID global curspace)
2635 [ $USED -gt $ORIG_USR_SPACE ] ||
2636 error "Used space for user $TSTID isn't increased" \
2637 "orig:$ORIG_USR_SPACE, now:$USED"
2638 USED=$(getquota -g $TSTID global curspace)
2639 [ $USED -gt $ORIG_GRP_SPACE ] ||
2640 error "Used space for group $TSTID isn't increased" \
2641 "orig:$ORIG_GRP_SPACE, now:$USED"
2642 if [ $project_supported == "yes" ]; then
2643 USED=$(getquota -p $TSTPRJID global curspace)
2644 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2645 error "Used space for project $TSTPRJID isn't " \
2646 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2651 run_test 35 "Usage is still accessible across reboot"
2653 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2656 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2657 skip "Old server doesn't have LU-5006 fix." && return
2659 setup_quota_test || error "setup quota failed with $?"
2660 trap cleanup_quota_test EXIT
2662 # make sure the system is clean
2663 local USED=$(getquota -u $TSTID global curspace)
2665 error "Used space ($USED) for user $TSTID isn't 0."
2667 # create file with MDS_OPEN_DELAY_CREATE flag
2668 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2669 error "Create file failed"
2671 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2672 oflag=sync || error "Write file failed"
2674 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2676 # wait for setattr on objects finished..."
2677 wait_delete_completed
2679 USED=$(getquota -u $TSTID global curspace)
2680 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2684 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2688 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2689 skip "Old server doesn't have LU-8801 fix." && return
2691 [ "$UID" != 0 ] && skip_env "must run as root" && return
2693 setup_quota_test || error "setup quota failed with $?"
2694 trap cleanup_quota_test EXIT
2696 # make sure the system is clean
2697 local USED=$(getquota -u $TSTID global curspace)
2699 error "Used space ($USED) for user $TSTID isn't 0."
2700 USED=$(getquota -u $TSTID2 global curspace)
2702 error "Used space ($USED) for user $TSTID2 isn't 0."
2704 local TESTFILE="$DIR/$tdir/$tfile"
2705 local file_cnt=10000
2707 # Generate id entries in accounting file
2708 echo "Create $file_cnt files..."
2709 for i in `seq $file_cnt`; do
2711 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2713 cancel_lru_locks osc
2714 sync; sync_all_data || true
2716 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2717 procf=${procf}.quota_slave.acct_user
2720 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2721 echo "Found $acct_cnt id entries"
2723 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2727 run_test 38 "Quota accounting iterator doesn't skip id entries"
2730 local TESTFILE="$DIR/$tdir/project"
2731 ! is_project_quota_supported &&
2732 skip "Project quota is not supported" && return 0
2734 setup_quota_test || error "setup quota failed with $?"
2737 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2738 [ $projectid -ne 0 ] &&
2739 error "Project id should be 0 not $projectid"
2740 change_project -p 1024 $TESTFILE
2741 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2742 [ $projectid -ne 1024 ] &&
2743 error "Project id should be 1024 not $projectid"
2745 stopall || error "failed to stopall (1)"
2748 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2749 [ $projectid -ne 1024 ] &&
2750 error "Project id should be 1024 not $projectid"
2754 run_test 39 "Project ID interface works correctly"
2757 ! is_project_quota_supported &&
2758 skip "Project quota is not supported" && return 0
2759 local dir1="$DIR/$tdir/dir1"
2760 local dir2="$DIR/$tdir/dir2"
2762 setup_quota_test || error "setup quota failed with $?"
2764 mkdir -p $dir1 $dir2
2765 change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
2766 change_project +P $dir2 && change_project -p 2 -d $dir2
2768 ln $dir1/1 $dir2/1_link &&
2769 error "Hard link across different project quota should fail"
2774 run_test 40a "Hard link across different project ID"
2777 ! is_project_quota_supported &&
2778 skip "Project quota is not supported" && return 0
2779 local dir1="$DIR/$tdir/dir1"
2780 local dir2="$DIR/$tdir/dir2"
2782 setup_quota_test || error "setup quota failed with $?"
2783 mkdir -p $dir1 $dir2
2784 change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
2785 change_project +P $dir2 && change_project -p 2 -d $dir2
2787 mv $dir1/1 $dir2/2 || error "mv failed $?"
2788 local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
2789 if [ "$projid" != "2" ]; then
2790 error "project id expected 2 not $projid"
2795 run_test 40b "Mv across different project ID"
2798 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
2799 ! is_project_quota_supported &&
2800 skip "Project quota is not supported" && return 0
2802 setup_quota_test || error "setup quota failed with $?"
2803 local dir="$DIR/$tdir/dir"
2805 mkdir -p $dir && change_project +P $dir && change_project -dp 1 $dir
2806 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2807 local projid=$(lsattr -dp $dir/remote_dir | awk '{print $1}')
2808 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2809 touch $dir/remote_dir/file
2810 #verify inherit works file for remote dir.
2811 local projid=$(lsattr -dp $dir/remote_dir/file | awk '{print $1}')
2812 [ "$projid" != "1" ] &&
2813 error "file under remote dir expected 1 not $projid"
2815 #Agent inode should be ignored for project quota
2816 USED=$(getquota -p 1 global curinodes)
2817 [ "$USED" != "3" ] &&
2818 error "file count expected 3 got $USED"
2824 run_test 40c "Remote child Dir inherit project quota properly"
2827 ! is_project_quota_supported &&
2828 skip "Project quota is not supported" && return 0
2830 setup_quota_test || error "setup quota failed with $?"
2831 local dir="$DIR/$tdir/dir"
2833 mkdir $dir && change_project -dp 1 $dir
2834 count=$($LFS find --projid 1 $DIR | wc -l)
2835 [ "$count" != 1 ] && error "expected 1 but got $count"
2840 run_test 50 "Test if lfs find --projid works"
2843 ! is_project_quota_supported &&
2844 skip "Project quota is not supported" && return 0
2845 setup_quota_test || error "setup quota failed with $?"
2846 local dir="$DIR/$tdir/dir"
2848 mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
2849 local used=$(getquota -p 1 global curinodes)
2850 [ $used != "1" ] && error "expected 1 got $used"
2855 used=$(getquota -p 1 global curinodes)
2856 [ $used != "4" ] && error "expected 4 got $used"
2858 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2860 cp $DIR/$tdir/6 $dir/6
2861 used=$(getquota -p 1 global curinodes)
2862 [ $used != "5" ] && error "expected 5 got $used"
2865 mv $DIR/$tdir/6 $dir/7
2866 used=$(getquota -p 1 global curinodes)
2867 [ $used != "6" ] && error "expected 6 got $used"
2872 run_test 51 "Test project accounting with mv/cp"
2875 ! is_project_quota_supported &&
2876 skip "Project quota is not supported" && return 0
2877 setup_quota_test || error "setup quota failed with $?"
2878 local dir="$DIR/$tdir/dir"
2879 mkdir $dir && change_project -dp 1 $dir && change_project +P $dir
2881 touch $DIR/$tdir/file
2882 #Try renaming a file into the project. This should fail.
2883 for num in $(seq 1 2000); do
2884 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2885 error "rename should fail"
2890 run_test 52 "Rename across different project ID"
2894 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2895 disable_project_quota
2901 check_and_cleanup_lustre
2902 export QUOTA_AUTO=$QUOTA_AUTO_OLD