3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test: LU-6836
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4a"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 do_facet mds1 $ZPOOL upgrade -v |
89 grep project_quota && return 0
95 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
96 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
97 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
98 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
99 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
100 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
101 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
102 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
109 local fail_val=${3:-0}
113 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
114 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
115 ost) NODES="$(comma_list $(osts_nodes))";;
118 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
123 echo "lfs project $*"
124 lfs project $* || error "lfs project $* failed"
127 RUNAS="runas -u $TSTID -g $TSTID"
128 RUNAS2="runas -u $TSTID2 -g $TSTID2"
129 DD="dd if=/dev/zero bs=1M"
133 # clear quota limits for a user or a group
134 # usage: resetquota -u username
135 # resetquota -g groupname
136 # resetquota -p projid
139 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
140 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
141 error "resetquota: wrong specifier $1 passed"
143 if [ $1 == "-p" ]; then
144 is_project_quota_supported || return 0
147 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
148 error "clear quota for [type:$1 name:$2] failed"
149 # give a chance to slave to release space
157 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
158 $LFS quota -v -u $local_id $DIR
159 log "Files for user ($local_id):"
160 ($LFS find --user $local_id $DIR | head -n 4 |
161 xargs stat 2>/dev/null)
164 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
165 $LFS quota -v -g $local_id $DIR
166 log "Files for group ($local_id):"
167 ($LFS find --group $local_id $DIR | head -n 4 |
168 xargs stat 2>/dev/null)
171 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
172 $LFS quota -v -p $TSTPRJID $DIR
173 log "Files for project ($TSTPRJID):"
174 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
175 xargs stat 2>/dev/null)
191 # get quota for a user or a group
192 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
193 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
198 sync_all_data > /dev/null 2>&1 || true
200 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
201 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
202 error "getquota: wrong u/g/p specifier $1 passed"
215 *) error "unknown quota parameter $4";;
218 [ "$uuid" = "global" ] && uuid=$DIR
220 $LFS quota -v "$1" "$2" $DIR |
221 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
222 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
227 # usage: set_mdt_qtype ugp|u|g|p|none
231 local mdts=$(get_facets MDS)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD = *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
242 # we have to make sure each MDT received config changes
243 for mdt in ${mdts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $mdt); then
250 wait_update_facet $mdt "$cmd" "$qtype" || return 1
257 # usage: set_ost_qtype ugp|u|g|p|none
261 local osts=$(get_facets OST)
263 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
264 qtype=$(tr -d 'p' <<<$qtype)
266 if [[ $PERM_CMD = *"set_param -P"* ]]; then
267 do_facet mgs $PERM_CMD \
268 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
270 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
272 # we have to make sure each OST received config changes
273 for ost in ${osts//,/ }; do
275 cmd="$LCTL get_param -n "
276 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
277 cmd=${cmd}.quota_slave.enabled
279 if $(facet_up $ost); then
280 wait_update_facet $ost "$cmd" "$qtype" || return 1
286 wait_reintegration() {
290 local result="glb[1],slv[1],reint[0]"
295 if [ $ntype == "mdt" ]; then
296 tgts=$(get_facets MDS)
298 tgts=$(get_facets OST)
301 for tgt in ${tgts//,/ }; do
303 cmd="$LCTL get_param -n "
304 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
305 cmd=${cmd}.quota_slave.info
307 if $(facet_up $tgt); then
308 wait_update_facet $tgt "$cmd |
309 grep "$qtype" | awk '{ print \\\$3 }'" \
310 "$result" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "mdt" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "mdt" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "mdt" "project" $max || return 1
339 if [[ "$qtype" =~ "u" ]]; then
340 wait_reintegration "ost" "user" $max || return 1
343 if [[ "$qtype" =~ "g" ]]; then
344 wait_reintegration "ost" "group" $max || return 1
347 if [[ "$qtype" =~ "p" ]]; then
348 ! is_project_quota_supported && return 0
349 wait_reintegration "ost" "project" $max || return 1
354 disable_project_quota() {
355 is_project_quota_supported || return 0
356 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
357 stopall || error "failed to stopall (1)"
359 for num in $(seq $MDSCOUNT); do
360 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
361 error "tune2fs $(mdsdevname $num) failed"
364 for num in $(seq $OSTCOUNT); do
365 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
366 error "tune2fs $(ostdevname $num) failed"
376 local extrasleep=${3:-5}
382 *) error "get_grace_time: Invalid quota type: $qtype"
387 time=$(lfs quota -$qtype $qarg $DIR|
388 awk 'NR == 3{ print $5 }'| sed 's/s$//')
391 time=$(lfs quota -$qtype $qarg $DIR|
392 awk 'NR == 3{ print $9 }'| sed 's/s$//')
395 error "Unknown quota type: $flavour"
399 echo "Sleep through grace ..."
400 [ "$time" == "-" ] &&
401 error "Grace timeout was not set or quota not exceeded"
402 if [ "$time" == "none" ]; then
403 echo "...Grace timeout already expired"
405 let time+=$extrasleep
406 echo "...sleep $time seconds"
412 wait_delete_completed
413 echo "Creating test directory"
414 mkdir $DIR/$tdir || return 1
415 chmod 0777 $DIR/$tdir || return 2
416 # always clear fail_loc in case of fail_loc isn't cleared
417 # properly when previous test failed
418 lustre_fail mds_ost 0
421 cleanup_quota_test() {
423 echo "Delete files..."
425 echo "Wait for unlink objects finished..."
426 wait_delete_completed
427 sync_all_data || true
436 $LFS quota -v -$ugp $qid $DIR
438 if [ "$bf" == "a" -o "$bf" == "b" ]; then
439 usage=$(getquota -$ugp $qid global curspace)
440 if [ -z $usage ]; then
441 quota_error $ugp $qid \
442 "Query block quota failed ($ugp:$qid)."
444 [ $usage -ne 0 ] && quota_log $ugp $qid \
445 "Block quota isn't 0 ($ugp:$qid:$usage)."
449 if [ "$bf" == "a" -o "$bf" == "f" ]; then
450 usage=$(getquota -$ugp $qid global curinodes)
451 if [ -z $usage ]; then
452 quota_error $ugp $qid \
453 "Query file quota failed ($ugp:$qid)."
455 [ $usage -ne 0 ] && quota_log $ugp $qid \
456 "File quota isn't 0 ($ugp:$qid:$usage)."
461 enable_project_quota() {
462 is_project_quota_supported || return 0
463 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
464 stopall || error "failed to stopall (1)"
466 for num in $(seq $MDSCOUNT); do
467 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
468 error "tune2fs $(mdsdevname $num) failed"
471 for num in $(seq $OSTCOUNT); do
472 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
473 error "tune2fs $(ostdevname $num) failed"
481 reset_quota_settings() {
482 resetquota -u $TSTUSR
483 resetquota -g $TSTUSR
484 resetquota -u $TSTUSR2
485 resetquota -g $TSTUSR2
486 resetquota -p $TSTPRJID
491 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
496 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
497 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
498 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
499 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
501 test_quota_performance() {
502 local TESTFILE="$DIR/$tdir/$tfile-0"
503 local size=$1 # in MB
504 local stime=$(date +%s)
505 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
506 quota_error u $TSTUSR "write failure"
507 local etime=$(date +%s)
508 delta=$((etime - stime))
509 if [ $delta -gt 0 ]; then
510 rate=$((size * 1024 / delta))
511 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
512 # LU-2872 - see LU-2887 for fix
514 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
516 [ $rate -gt 1024 ] ||
517 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
523 # test basic quota performance b=21696
526 [ "$SLOW" = "no" ] && MB=10
528 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
529 [ $free_space -le $((MB * 1024)) ] &&
530 skip "not enough space ${free_space} KB, " \
531 "required $((MB * 1024)) KB"
532 setup_quota_test || error "setup quota failed with $?"
533 trap cleanup_quota_test EXIT
535 set_ost_qtype "none" || error "disable ost quota failed"
536 test_quota_performance $MB
538 set_ost_qtype $QTYPE || error "enable ost quota failed"
539 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
540 error "set quota failed"
541 test_quota_performance $MB
544 resetquota -u $TSTUSR
546 run_test 0 "Test basic quota performance"
548 # test block hardlimit
551 local TESTFILE="$DIR/$tdir/$tfile-0"
553 setup_quota_test || error "setup quota failed with $?"
554 trap cleanup_quota_test EXIT
557 set_ost_qtype $QTYPE || error "enable ost quota failed"
560 log "User quota (block hardlimit:$LIMIT MB)"
561 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
562 error "set user quota failed"
564 # make sure the system is clean
565 local USED=$(getquota -u $TSTUSR global curspace)
566 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
568 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
569 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
572 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
573 quota_error u $TSTUSR "user write failure, but expect success"
574 log "Write out of block quota ..."
575 # this time maybe cache write, ignore it's failure
576 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
577 # flush cache, ensure noquota flag is set on client
579 sync; sync_all_data || true
580 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
581 quota_error u $TSTUSR "user write success, but expect EDQUOT"
584 wait_delete_completed || error "wait_delete_completed failed"
585 sync_all_data || true
586 USED=$(getquota -u $TSTUSR global curspace)
587 [ $USED -ne 0 ] && quota_error u $TSTUSR \
588 "user quota isn't released after deletion"
589 resetquota -u $TSTUSR
592 log "--------------------------------------"
593 log "Group quota (block hardlimit:$LIMIT MB)"
594 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
595 error "set group quota failed"
597 TESTFILE="$DIR/$tdir/$tfile-1"
598 # make sure the system is clean
599 USED=$(getquota -g $TSTUSR global curspace)
600 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
602 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
603 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
606 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
607 quota_error g $TSTUSR "Group write failure, but expect success"
608 log "Write out of block quota ..."
609 # this time maybe cache write, ignore it's failure
610 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
612 sync; sync_all_data || true
613 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
614 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
616 wait_delete_completed || error "wait_delete_completed failed"
617 sync_all_data || true
618 USED=$(getquota -g $TSTUSR global curspace)
619 [ $USED -ne 0 ] && quota_error g $TSTUSR \
620 "Group quota isn't released after deletion"
621 resetquota -g $TSTUSR
623 if ! is_project_quota_supported; then
624 echo "Project quota is not supported"
629 TESTFILE="$DIR/$tdir/$tfile-2"
630 # make sure the system is clean
631 USED=$(getquota -p $TSTPRJID global curspace)
633 error "used space($USED) for project $TSTPRJID isn't 0"
636 log "--------------------------------------"
637 log "Project quota (block hardlimit:$LIMIT mb)"
638 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
639 error "set project quota failed"
641 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
642 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
643 change_project -p $TSTPRJID $TESTFILE
646 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
647 "project write failure, but expect success"
648 log "write out of block quota ..."
649 # this time maybe cache write, ignore it's failure
650 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
652 sync; sync_all_data || true
653 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
654 $TSTPRJID "project write success, but expect EDQUOT"
659 USED=$(getquota -p $TSTPRJID global curspace)
660 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
661 "project quota isn't released after deletion"
663 resetquota -p $TSTPRJID
665 run_test 1 "Block hard limit (normal use and out of quota)"
667 # test inode hardlimit
669 local TESTFILE="$DIR/$tdir/$tfile-0"
670 local LIMIT=$(do_facet mds1 $LCTL get_param -n \
671 qmt.$FSNAME-QMT0000.md-0x0.info |
672 awk '/least qunit/{ print $3 }')
673 local L2=$(do_facet mds1 $LCTL get_param -n \
674 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
676 [ $L2 -le $LIMIT ] || LIMIT=$L2
678 [ "$SLOW" = "no" ] || LIMIT=$((LIMIT * 1024))
680 local FREE_INODES=$(mdt_free_inodes 0)
681 echo "$FREE_INODES free inodes on master MDT"
682 [ $FREE_INODES -lt $LIMIT ] &&
683 skip "not enough free inodes $FREE_INODES required $LIMIT"
685 setup_quota_test || error "setup quota failed with $?"
686 trap cleanup_quota_test EXIT
689 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
692 log "User quota (inode hardlimit:$LIMIT files)"
693 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
694 error "set user quota failed"
696 # make sure the system is clean
697 local USED=$(getquota -u $TSTUSR global curinodes)
698 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
700 log "Create $LIMIT files ..."
701 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
702 quota_error u $TSTUSR "user create failure, but expect success"
703 log "Create out of file quota ..."
704 $RUNAS touch ${TESTFILE}_xxx &&
705 quota_error u $TSTUSR "user create success, but expect EDQUOT"
708 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
709 rm -f ${TESTFILE}_xxx
710 wait_delete_completed
712 USED=$(getquota -u $TSTUSR global curinodes)
713 [ $USED -ne 0 ] && quota_error u $TSTUSR \
714 "user quota isn't released after deletion"
715 resetquota -u $TSTUSR
718 log "--------------------------------------"
719 log "Group quota (inode hardlimit:$LIMIT files)"
720 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
721 error "set group quota failed"
723 TESTFILE=$DIR/$tdir/$tfile-1
724 # make sure the system is clean
725 USED=$(getquota -g $TSTUSR global curinodes)
726 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
728 log "Create $LIMIT files ..."
729 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
730 quota_error g $TSTUSR "group create failure, but expect success"
731 log "Create out of file quota ..."
732 $RUNAS touch ${TESTFILE}_xxx &&
733 quota_error g $TSTUSR "group create success, but expect EDQUOT"
736 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
737 rm -f ${TESTFILE}_xxx
738 wait_delete_completed
740 USED=$(getquota -g $TSTUSR global curinodes)
741 [ $USED -ne 0 ] && quota_error g $TSTUSR \
742 "user quota isn't released after deletion"
744 resetquota -g $TSTUSR
745 ! is_project_quota_supported && cleanup_quota_test &&
746 echo "Skip project quota is not supported" && return 0
749 log "--------------------------------------"
750 log "Project quota (inode hardlimit:$LIMIT files)"
751 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
752 error "set project quota failed"
754 TESTFILE=$DIR/$tdir/$tfile-1
755 # make sure the system is clean
756 USED=$(getquota -p $TSTPRJID global curinodes)
758 error "Used inodes($USED) for project $TSTPRJID isn't 0"
760 change_project -sp $TSTPRJID $DIR/$tdir
761 log "Create $LIMIT files ..."
762 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
763 $TSTPRJID "project create fail, but expect success"
764 log "Create out of file quota ..."
765 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
766 "project create success, but expect EDQUOT"
767 change_project -C $DIR/$tdir
770 USED=$(getquota -p $TSTPRJID global curinodes)
771 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
772 "project quota isn't released after deletion"
774 resetquota -p $TSTPRJID
777 run_test 2 "File hard limit (normal use and out of quota)"
787 trap cleanup_quota_test EXIT
789 $SETSTRIPE $TESTFILE -c 1 -i 0
790 chown $TSTUSR.$TSTUSR $TESTFILE
791 [ "$qtype" == "p" ] && is_project_quota_supported &&
792 change_project -p $TSTPRJID $TESTFILE
794 echo "Write up to soft limit"
795 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
796 quota_error a $TSTUSR "write failure, but expect success"
797 OFFSET=$((LIMIT * 1024))
800 echo "Write to exceed soft limit"
801 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
802 quota_error a $TSTUSR "write failure, but expect success"
803 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
806 echo "mmap write when over soft limit"
807 $RUNAS $MULTIOP $TESTFILE.mmap OT40960SMW ||
808 quota_error a $TSTUSR "mmap write failure, but expect success"
814 $SHOW_QUOTA_INFO_USER
815 $SHOW_QUOTA_INFO_GROUP
816 $SHOW_QUOTA_INFO_PROJID
818 echo "Write before timer goes off"
819 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
820 quota_error a $TSTUSR "write failure, but expect success"
821 OFFSET=$((OFFSET + 1024))
824 wait_grace_time $qtype "block"
829 $SHOW_QUOTA_INFO_USER
830 $SHOW_QUOTA_INFO_GROUP
831 $SHOW_QUOTA_INFO_PROJID
833 echo "Write after timer goes off"
834 # maybe cache write, ignore.
835 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
836 OFFSET=$((OFFSET + 1024))
838 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
839 quota_error a $TSTUSR "write success, but expect EDQUOT"
844 $SHOW_QUOTA_INFO_USER
845 $SHOW_QUOTA_INFO_GROUP
846 $SHOW_QUOTA_INFO_PROJID
848 echo "Unlink file to stop timer"
850 wait_delete_completed
851 sync_all_data || true
856 $SHOW_QUOTA_INFO_USER
857 $SHOW_QUOTA_INFO_GROUP
858 $SHOW_QUOTA_INFO_PROJID
860 $SETSTRIPE $TESTFILE -c 1 -i 0
861 chown $TSTUSR.$TSTUSR $TESTFILE
862 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
865 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
866 quota_error a $TSTUSR "write failure, but expect success"
874 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
877 local TESTFILE=$DIR/$tdir/$tfile-0
879 # get minimum soft qunit size
880 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
881 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
883 set_ost_qtype $QTYPE || error "enable ost quota failed"
885 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
886 # make sure the system is clean
887 local USED=$(getquota -u $TSTUSR global curspace)
888 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
890 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
891 $MAX_IQ_TIME $DIR || error "set user grace time failed"
892 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
893 error "set user quota failed"
895 test_block_soft $TESTFILE $GRACE $LIMIT "u"
896 resetquota -u $TSTUSR
898 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
899 TESTFILE=$DIR/$tdir/$tfile-1
900 # make sure the system is clean
901 USED=$(getquota -g $TSTUSR global curspace)
902 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
904 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
905 $MAX_IQ_TIME $DIR || error "set group grace time failed"
906 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
907 error "set group quota failed"
909 test_block_soft $TESTFILE $GRACE $LIMIT "g"
910 resetquota -g $TSTUSR
912 if is_project_quota_supported; then
913 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
914 TESTFILE=$DIR/$tdir/$tfile-2
915 # make sure the system is clean
916 USED=$(getquota -p $TSTPRJID global curspace)
917 [ $USED -ne 0 ] && error \
918 "Used space($USED) for project $TSTPRJID isn't 0."
920 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
922 error "set project grace time failed"
923 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
924 $DIR || error "set project quota failed"
926 test_block_soft $TESTFILE $GRACE $LIMIT "p"
927 resetquota -p $TSTPRJID
928 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
930 error "restore project grace time failed"
934 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
935 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
936 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
937 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
939 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
948 trap cleanup_quota_test EXIT
949 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
951 echo "Create files to exceed soft limit"
952 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
953 quota_error a $TSTUSR "create failure, but expect success"
954 local trigger_time=$(date +%s)
956 sync_all_data || true
958 local cur_time=$(date +%s)
959 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
960 error "Passed grace time $grace, $trigger_time, $cur_time"
962 echo "Create file before timer goes off"
963 $RUNAS touch ${TESTFILE}_before ||
964 quota_error a $TSTUSR "failed create before timer expired," \
965 "but expect success. $trigger_time, $cur_time"
966 sync_all_data || true
968 wait_grace_time $qtype "file"
973 $SHOW_QUOTA_INFO_USER
974 $SHOW_QUOTA_INFO_GROUP
975 $SHOW_QUOTA_INFO_PROJID
977 echo "Create file after timer goes off"
978 # There is a window that space is accounted in the quota usage but
979 # hasn't been decreased from the pending write, if we acquire quota
980 # in this window, we'll acquire more than we needed.
981 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
982 sync_all_data || true
983 $RUNAS touch ${TESTFILE}_after_3 &&
984 quota_error a $TSTUSR "create after timer expired," \
986 sync_all_data || true
991 $SHOW_QUOTA_INFO_USER
992 $SHOW_QUOTA_INFO_GROUP
993 $SHOW_QUOTA_INFO_PROJID
995 echo "Unlink files to stop timer"
996 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
997 wait_delete_completed
1000 $RUNAS touch ${TESTFILE}_xxx ||
1001 quota_error a $TSTUSR "touch after timer stop failure," \
1002 "but expect success"
1003 sync_all_data || true
1011 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1012 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1013 local TESTFILE=$DIR/$tdir/$tfile-0
1016 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1018 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1019 # make sure the system is clean
1020 local USED=$(getquota -u $TSTUSR global curinodes)
1021 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1023 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1024 $GRACE $DIR || error "set user grace time failed"
1025 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1026 error "set user quota failed"
1028 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1029 resetquota -u $TSTUSR
1031 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1032 # make sure the system is clean
1033 USED=$(getquota -g $TSTUSR global curinodes)
1034 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1036 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1037 $GRACE $DIR || error "set group grace time failed"
1038 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1039 error "set group quota failed"
1040 TESTFILE=$DIR/$tdir/$tfile-1
1042 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1043 resetquota -g $TSTUSR
1045 if is_project_quota_supported; then
1046 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1047 # make sure the system is clean
1048 USED=$(getquota -p $TSTPRJID global curinodes)
1049 [ $USED -ne 0 ] && error \
1050 "Used space($USED) for project $TSTPRJID isn't 0."
1052 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1053 $GRACE $DIR || error "set project grace time failed"
1054 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1055 error "set project quota failed"
1057 TESTFILE=$DIR/$tdir/$tfile-1
1058 # one less than limit, because of parent directory included.
1059 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1060 resetquota -p $TSTPRJID
1061 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1062 $MAX_IQ_TIME $DIR ||
1063 error "restore project grace time failed"
1067 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1068 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1069 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1070 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1072 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1075 local GR_STR1="1w3d"
1076 local GR_STR2="1000s"
1078 local GR_STR4="1w2d3h4m5s"
1080 local GR_STR6="18446744073709551615"
1083 wait_delete_completed
1085 # test of valid grace strings handling
1086 echo "Valid grace strings test"
1087 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1088 $GR_STR2 $DIR || error "set user grace time failed"
1089 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1090 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1091 $GR_STR4 $DIR || error "set group grace time quota failed"
1092 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1094 # test of invalid grace strings handling
1095 echo " Invalid grace strings test"
1096 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1097 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1098 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1102 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1103 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1104 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1105 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1107 run_test 4b "Grace time strings handling"
1109 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1111 local BLIMIT=10 # 10M
1112 local ILIMIT=10 # 10 inodes
1114 setup_quota_test || error "setup quota failed with $?"
1115 trap cleanup_quota_test EXIT
1117 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1118 set_ost_qtype $QTYPE || error "enable ost quota failed"
1120 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1121 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1122 error "set user quota failed"
1123 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1124 if is_project_quota_supported; then
1125 error "set group quota failed"
1126 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1127 -I $ILIMIT $DIR || error "set project quota failed"
1130 # make sure the system is clean
1131 local USED=$(getquota -u $TSTUSR global curinodes)
1132 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1133 USED=$(getquota -g $TSTUSR global curinodes)
1134 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1135 USED=$(getquota -u $TSTUSR global curspace)
1136 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1137 USED=$(getquota -g $TSTUSR global curspace)
1138 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1139 if is_project_quota_supported; then
1140 USED=$(getquota -p $TSTPRJID global curinodes)
1142 error "Used inode($USED) for project $TSTPRJID isn't 0."
1143 USED=$(getquota -p $TSTPRJID global curspace)
1145 error "Used block($USED) for project $TSTPRJID isn't 0."
1148 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1149 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1150 error "create failure, expect success"
1151 if is_project_quota_supported; then
1152 touch $DIR/$tdir/$tfile-0_1
1153 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1155 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1156 error "write failure, expect success"
1158 echo "Chown files to $TSTUSR.$TSTUSR ..."
1159 for i in $(seq 0 $ILIMIT); do
1160 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1161 quota_error a $TSTUSR "chown failure, expect success"
1165 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1166 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1169 resetquota -u $TSTUSR
1170 resetquota -g $TSTUSR
1171 resetquota -p $TSTPRJID
1173 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1175 # test dropping acquire request on master
1179 # Clear dmesg so watchdog is not triggered by previous
1181 do_facet ost1 dmesg -c > /dev/null
1183 setup_quota_test || error "setup quota failed with $?"
1184 trap cleanup_quota_test EXIT
1186 # make sure the system is clean
1187 local USED=$(getquota -u $TSTUSR global curspace)
1188 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1190 # make sure no granted quota on ost
1191 set_ost_qtype $QTYPE || error "enable ost quota failed"
1192 resetquota -u $TSTUSR
1194 # create file for $TSTUSR
1195 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1196 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1197 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1199 # create file for $TSTUSR2
1200 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1201 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1202 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1204 # cache per-ID lock for $TSTUSR on slave
1205 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1206 error "set quota failed"
1207 $RUNAS $DD of=$TESTFILE count=1 ||
1208 error "write $TESTFILE failure, expect success"
1209 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1210 error "write $TESTFILE2 failure, expect success"
1212 sync_all_data || true
1214 #define QUOTA_DQACQ 601
1215 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1216 lustre_fail mds 0x513 601
1218 if at_is_enabled; then
1219 at_max_saved=$(at_max_get ost1)
1220 at_max_set $TIMEOUT ost1
1223 do_facet ost1 $LCTL set_param \
1224 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1226 # write to un-enforced ID ($TSTUSR2) should succeed
1227 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1228 error "write failure, expect success"
1230 # write to enforced ID ($TSTUSR) in background, exceeding limit
1231 # to make sure DQACQ is sent
1232 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1235 # watchdog timer uses a factor of 2
1236 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1237 sleep $((TIMEOUT * 2 + 1))
1239 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1241 # write should be blocked and never finished
1242 if ! ps -p $DDPID > /dev/null 2>&1; then
1244 error "write finished incorrectly!"
1249 # no watchdog is triggered
1250 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1251 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1252 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1253 [ -z "$watchdog" ] || error "$watchdog"
1255 rm -f $TMP/lustre-log-${TESTNAME}.log
1257 # write should continue then fail with EDQUOT
1261 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1262 if [ $count -ge 240 ]; then
1263 quota_error u $TSTUSR "dd not finished in $count secs"
1265 count=$((count + 1))
1266 if [ $((count % 30)) -eq 0 ]; then
1267 c_size=$(stat -c %s $TESTFILE)
1268 echo "Waiting $count secs. $c_size"
1275 resetquota -u $TSTUSR
1277 run_test 6 "Test dropping acquire request on master"
1279 # quota reintegration (global index)
1281 local TESTFILE=$DIR/$tdir/$tfile
1282 local LIMIT=20 # 20M
1284 [ "$SLOW" = "no" ] && LIMIT=5
1286 setup_quota_test || error "setup quota failed with $?"
1287 trap cleanup_quota_test EXIT
1289 # make sure the system is clean
1290 local USED=$(getquota -u $TSTUSR global curspace)
1291 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1293 # make sure no granted quota on ost1
1294 set_ost_qtype $QTYPE || error "enable ost quota failed"
1295 resetquota -u $TSTUSR
1296 set_ost_qtype "none" || error "disable ost quota failed"
1298 local OSTUUID=$(ostuuid_from_index 0)
1299 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1301 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1304 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1305 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1310 echo "Enable quota & set quota limit for $TSTUSR"
1311 set_ost_qtype $QTYPE || error "enable ost quota failed"
1312 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1313 error "set quota failed"
1315 echo "Start ost1..."
1316 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1319 wait_ost_reint $QTYPE || error "reintegration failed"
1321 # hardlimit should have been fetched by slave during global
1322 # reintegration, write will exceed quota
1323 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1324 quota_error u $TSTUSR "write success, but expect EDQUOT"
1327 wait_delete_completed
1328 sync_all_data || true
1334 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1335 error "clear quota failed"
1337 echo "Start ost1..."
1338 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1341 wait_ost_reint $QTYPE || error "reintegration failed"
1343 # hardlimit should be cleared on slave during reintegration
1344 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1345 quota_error u $TSTUSR "write error, but expect success"
1348 resetquota -u $TSTUSR
1350 run_test 7a "Quota reintegration (global index)"
1352 # quota reintegration (slave index)
1355 local TESTFILE=$DIR/$tdir/$tfile
1357 setup_quota_test || error "setup quota failed with $?"
1358 trap cleanup_quota_test EXIT
1360 # make sure the system is clean
1361 local USED=$(getquota -u $TSTUSR global curspace)
1362 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1364 # make sure no granted quota on ost1
1365 set_ost_qtype $QTYPE || error "enable ost quota failed"
1366 resetquota -u $TSTUSR
1367 set_ost_qtype "none" || error "disable ost quota failed"
1369 local OSTUUID=$(ostuuid_from_index 0)
1370 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1372 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1375 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1376 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1378 # consume some space to make sure the granted space will not
1379 # be released during reconciliation
1380 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1381 error "consume space failure, expect success"
1383 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1384 lustre_fail mds 0xa02
1386 set_ost_qtype $QTYPE || error "enable ost quota failed"
1387 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1388 error "set quota failed"
1390 # ignore the write error
1391 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1393 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1397 echo "Restart ost to trigger reintegration..."
1399 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1402 wait_ost_reint $QTYPE || error "reintegration failed"
1404 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1405 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1408 resetquota -u $TSTUSR
1411 run_test 7b "Quota reintegration (slave index)"
1413 # quota reintegration (restart mds during reintegration)
1415 local LIMIT=20 # 20M
1416 local TESTFILE=$DIR/$tdir/$tfile
1418 [ "$SLOW" = "no" ] && LIMIT=5
1420 setup_quota_test || error "setup quota failed with $?"
1421 trap cleanup_quota_test EXIT
1423 # make sure the system is clean
1424 local USED=$(getquota -u $TSTUSR global curspace)
1425 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1427 set_ost_qtype "none" || error "disable ost quota failed"
1428 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1429 error "set quota failed"
1431 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1432 lustre_fail ost 0xa03
1435 set_ost_qtype $QTYPE || error "enable ost quota failed"
1436 # trigger reintegration
1437 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1438 procf=${procf}quota_slave.force_reint
1439 do_facet ost1 $LCTL set_param $procf=1 ||
1440 error "force reintegration failed"
1448 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1451 # wait longer than usual to make sure the reintegration
1452 # is triggered by quota wb thread.
1453 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1455 # hardlimit should have been fetched by slave during global
1456 # reintegration, write will exceed quota
1457 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1458 quota_error u $TSTUSR "write success, but expect EDQUOT"
1461 resetquota -u $TSTUSR
1463 run_test 7c "Quota reintegration (restart mds during reintegration)"
1465 # Quota reintegration (Transfer index in multiple bulks)
1467 local TESTFILE=$DIR/$tdir/$tfile
1468 local TESTFILE1="$DIR/$tdir/$tfile"-1
1471 setup_quota_test || error "setup quota failed with $?"
1472 trap cleanup_quota_test EXIT
1474 set_ost_qtype "none" || error "disable ost quota failed"
1475 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1476 error "set quota for $TSTUSR failed"
1477 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1478 error "set quota for $TSTUSR2 failed"
1480 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1481 lustre_fail mds 0x608 0
1483 # enable quota to tirgger reintegration
1484 set_ost_qtype "u" || error "enable ost quota failed"
1485 wait_ost_reint "u" || error "reintegration failed"
1489 # hardlimit should have been fetched by slave during global
1490 # reintegration, write will exceed quota
1491 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1492 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1494 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1495 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1498 resetquota -u $TSTUSR
1499 resetquota -u $TSTUSR2
1501 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1503 # quota reintegration (inode limits)
1505 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1507 # LU-2435: skip this quota test if underlying zfs version has not
1508 # supported native dnode accounting
1509 [ "$(facet_fstype mds1)" == "zfs" ] && {
1510 local F="feature@userobj_accounting"
1511 local pool=$(zpool_name mds1)
1512 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1514 [[ "$feature" != *" active "* ]] &&
1515 skip "requires zpool with active userobj_accounting"
1518 local ilimit=$((1024 * 2)) # 2k inodes
1519 local TESTFILE=$DIR/${tdir}-1/$tfile
1521 setup_quota_test || error "setup quota failed with $?"
1522 trap cleanup_quota_test EXIT
1524 # make sure the system is clean
1525 local USED=$(getquota -u $TSTUSR global curinodes)
1526 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1528 # make sure no granted quota on mdt1
1529 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1530 resetquota -u $TSTUSR
1531 set_mdt_qtype "none" || error "disable mdt quota failed"
1533 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1534 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1535 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1538 echo "Stop mds${MDSCOUNT}..."
1541 echo "Enable quota & set quota limit for $TSTUSR"
1542 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1543 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1544 error "set quota failed"
1546 echo "Start mds${MDSCOUNT}..."
1547 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1550 wait_mdt_reint $QTYPE || error "reintegration failed"
1552 echo "create remote dir"
1553 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1554 error "create remote dir failed"
1555 chmod 0777 $DIR/${tdir}-1
1557 # hardlimit should have been fetched by slave during global
1558 # reintegration, create will exceed quota
1559 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1560 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1562 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1563 wait_delete_completed
1564 sync_all_data || true
1566 echo "Stop mds${MDSCOUNT}..."
1569 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1570 error "clear quota failed"
1572 echo "Start mds${MDSCOUNT}..."
1573 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1576 wait_mdt_reint $QTYPE || error "reintegration failed"
1578 # hardlimit should be cleared on slave during reintegration
1579 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1580 quota_error u $TSTUSR "create failed, expect success"
1582 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1583 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1586 resetquota -u $TSTUSR
1588 run_test 7e "Quota reintegration (inode limits)"
1590 # run dbench with quota enabled
1592 local BLK_LIMIT="100g" #100G
1593 local FILE_LIMIT=1000000
1595 setup_quota_test || error "setup quota failed with $?"
1596 trap cleanup_quota_test EXIT
1598 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1599 set_ost_qtype $QTYPE || error "enable ost quota failed"
1601 echo "Set enough high limit for user: $TSTUSR"
1602 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1603 error "set user quota failed"
1604 echo "Set enough high limit for group: $TSTUSR"
1605 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1606 error "set group quota failed"
1607 if is_project_quota_supported; then
1608 change_project -sp $TSTPRJID $DIR/$tdir
1609 echo "Set enough high limit for project: $TSTPRJID"
1610 $LFS setquota -p $TSTPRJID -b 0 \
1611 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1612 error "set project quota failed"
1616 [ "$SLOW" = "no" ] && duration=" -t 120"
1617 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1618 quota_error a $TSTUSR "dbench failed!"
1620 is_project_quota_supported && change_project -C $DIR/$tdir
1622 resetquota -u $TSTUSR
1623 resetquota -g $TSTUSR
1624 resetquota -p $TSTPRJID
1626 run_test 8 "Run dbench with quota enabled"
1628 # this check is just for test_9
1629 OST0_MIN=4900000 #4.67G
1631 check_whether_skip () {
1632 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1633 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1634 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1635 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1642 # run for fixing bug10707, it needs a big room. test for 64bit
1644 local filesize=$((1024 * 9 / 2)) # 4.5G
1646 check_whether_skip && return 0
1648 setup_quota_test || error "setup quota failed with $?"
1649 trap cleanup_quota_test EXIT
1651 set_ost_qtype "ug" || error "enable ost quota failed"
1653 local TESTFILE="$DIR/$tdir/$tfile-0"
1654 local BLK_LIMIT=100G #100G
1655 local FILE_LIMIT=1000000
1657 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1659 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1661 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1662 error "set user quota failed"
1664 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1665 "for group: $TSTUSR"
1666 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1667 error "set group quota failed"
1669 quota_show_check a u $TSTUSR
1670 quota_show_check a g $TSTUSR
1672 echo "Create test file"
1673 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1674 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1676 log "Write the big file of 4.5G ..."
1677 $RUNAS $DD of=$TESTFILE count=$filesize ||
1678 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1684 resetquota -u $TSTUSR
1685 resetquota -g $TSTUSR
1690 run_test 9 "Block limit larger than 4GB (b10707)"
1693 local TESTFILE=$DIR/$tdir/$tfile
1695 setup_quota_test || error "setup quota failed with $?"
1696 trap cleanup_quota_test EXIT
1698 # set limit to root user should fail
1699 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1700 error "set limit for root user successfully, expect failure"
1701 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1702 error "set limit for root group successfully, expect failure"
1703 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1704 error "set limit for project 0 successfully, expect failure"
1706 # root user can overrun quota
1707 set_ost_qtype "ug" || error "enable ost quota failed"
1709 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1710 error "set quota failed"
1711 quota_show_check b u $TSTUSR
1713 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1714 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1716 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1717 error "write failure, expect success"
1720 resetquota -u $TSTUSR
1722 run_test 10 "Test quota for root user"
1725 local TESTFILE=$DIR/$tdir/$tfile
1726 setup_quota_test || error "setup quota failed with $?"
1727 trap cleanup_quota_test EXIT
1729 set_mdt_qtype "ug" || error "enable mdt quota failed"
1730 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1731 error "set quota failed"
1733 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1734 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1736 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1737 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1740 local USED=$(getquota -u $TSTUSR global curinodes)
1741 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1744 resetquota -u $TSTUSR
1746 run_test 11 "Chown/chgrp ignores quota"
1749 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1751 local blimit=22 # 22M
1752 local blk_cnt=$((blimit - 5))
1753 local TESTFILE0="$DIR/$tdir/$tfile"-0
1754 local TESTFILE1="$DIR/$tdir/$tfile"-1
1756 setup_quota_test || error "setup quota failed with $?"
1757 trap cleanup_quota_test EXIT
1759 set_ost_qtype "u" || error "enable ost quota failed"
1760 quota_show_check b u $TSTUSR
1762 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1763 error "set quota failed"
1765 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1766 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1767 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1768 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1770 echo "Write to ost0..."
1771 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1772 quota_error a $TSTUSR "dd failed"
1774 echo "Write to ost1..."
1775 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1776 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1778 echo "Free space from ost0..."
1780 wait_delete_completed
1781 sync_all_data || true
1783 echo "Write to ost1 after space freed from ost0..."
1784 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1785 quota_error a $TSTUSR "rebalancing failed"
1788 resetquota -u $TSTUSR
1790 run_test 12a "Block quota rebalancing"
1793 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1795 local ilimit=$((1024 * 2)) # 2k inodes
1796 local TESTFILE0=$DIR/$tdir/$tfile
1797 local TESTFILE1=$DIR/${tdir}-1/$tfile
1799 setup_quota_test || error "setup quota failed with $?"
1800 trap cleanup_quota_test EXIT
1802 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1803 chmod 0777 $DIR/${tdir}-1
1805 set_mdt_qtype "u" || error "enable mdt quota failed"
1806 quota_show_check f u $TSTUSR
1808 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1809 error "set quota failed"
1811 echo "Create $ilimit files on mdt0..."
1812 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1813 quota_error u $TSTUSR "create failed, but expect success"
1815 echo "Create files on mdt1..."
1816 $RUNAS createmany -m $TESTFILE1 1 &&
1817 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1819 echo "Free space from mdt0..."
1820 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1821 wait_delete_completed
1822 sync_all_data || true
1824 echo "Create files on mdt1 after space freed from mdt0..."
1825 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1826 quota_error a $TSTUSR "rebalancing failed"
1828 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1829 error "unlink mdt1 files failed"
1830 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1833 resetquota -u $TSTUSR
1835 run_test 12b "Inode quota rebalancing"
1838 local TESTFILE=$DIR/$tdir/$tfile
1839 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1840 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1842 setup_quota_test || error "setup quota failed with $?"
1843 trap cleanup_quota_test EXIT
1845 set_ost_qtype "u" || error "enable ost quota failed"
1846 quota_show_check b u $TSTUSR
1848 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1849 error "set quota failed"
1850 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1851 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1853 # clear the locks in cache first
1854 do_facet ost1 $LCTL set_param -n $procf=clear
1855 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1856 [ $nlock -eq 0 ] || error "$nlock cached locks"
1858 # write to acquire the per-ID lock
1859 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1860 quota_error a $TSTUSR "dd failed"
1862 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1863 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1865 # clear quota doesn't trigger per-ID lock cancellation
1866 resetquota -u $TSTUSR
1867 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1868 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1870 # clear the per-ID lock
1871 do_facet ost1 $LCTL set_param -n $procf=clear
1872 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1873 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1875 # spare quota should be released
1876 local OSTUUID=$(ostuuid_from_index 0)
1877 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1878 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1879 [ $limit -le $space ] ||
1880 error "spare quota isn't released, limit:$limit, space:$space"
1884 run_test 13 "Cancel per-ID lock in the LRU list"
1887 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1889 wait_delete_completed
1890 sync_all_data || true
1893 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1894 error "set user quota failed"
1895 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1896 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1897 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1898 resetquota -u $TSTUSR
1901 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1902 error "set group quota failed"
1903 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1904 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1905 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1906 resetquota -g $TSTUSR
1908 run_test 15 "Set over 4T block quota"
1912 local BLKS=1 # 1M less than limit
1913 local TESTFILE=$DIR/$tdir/$tfile
1915 setup_quota_test || error "setup quota failed with $?"
1916 trap cleanup_quota_test EXIT
1918 # make sure the system is clean
1919 local USED=$(getquota -u $TSTUSR global curspace)
1920 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1922 set_ost_qtype "ug" || error "enable ost quota failed"
1923 # make sure no granted quota on ost
1924 resetquota -u $TSTUSR
1925 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1926 error "set quota failed"
1928 quota_show_check b u $TSTUSR
1930 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1931 lustre_fail mds 0xa04 $err_code
1933 # write in background
1934 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1938 # write should be blocked and never finished
1939 if ! ps -p $DDPID > /dev/null 2>&1; then
1941 quota_error u $TSTUSR "write finished incorrectly!"
1949 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1951 if [ $count -gt $timeout ]; then
1952 quota_error u $TSTUSR "dd is not finished!"
1957 sync; sync_all_data || true
1959 USED=$(getquota -u $TSTUSR global curspace)
1960 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1961 "Used space(${USED}K) is less than ${BLKS}M"
1964 resetquota -u $TSTUSR
1967 # DQACQ return recoverable error
1969 echo "DQACQ return -ENOLCK"
1971 test_17sub 37 || error "Handle -ENOLCK failed"
1973 echo "DQACQ return -EAGAIN"
1975 test_17sub 11 || error "Handle -EAGAIN failed"
1977 echo "DQACQ return -ETIMEDOUT"
1978 #define ETIMEDOUT 110
1979 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1981 echo "DQACQ return -ENOTCONN"
1982 #define ENOTCONN 107
1983 test_17sub 107 || error "Handle -ENOTCONN failed"
1986 run_test 17 "DQACQ return recoverable error"
1990 local blimit="200m" # 200M
1991 local TESTFILE="$DIR/$tdir/$tfile"
1993 setup_quota_test || error "setup quota failed with $?"
1994 trap cleanup_quota_test EXIT
1996 set_ost_qtype "u" || error "enable ost quota failed"
1997 log "User quota (limit: $blimit)"
1998 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1999 error "set quota failed"
2000 quota_show_check b u $TSTUSR
2002 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2003 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2005 local timeout=$(sysctl -n lustre.timeout)
2007 if [ $io_type = "directio" ]; then
2008 log "Write 100M (directio) ..."
2009 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2011 log "Write 100M (buffered) ..."
2012 $RUNAS $DD of=$TESTFILE count=100 &
2016 replay_barrier $SINGLEMDS
2017 log "Fail mds for $((2 * timeout)) seconds"
2018 fail $SINGLEMDS $((2 * timeout))
2021 if at_is_enabled; then
2022 timeout=$(at_max_get mds)
2024 timeout=$(lctl get_param -n timeout)
2028 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2029 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2030 log "it took $count second"
2035 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2037 cancel_lru_locks mdc
2038 cancel_lru_locks osc
2041 local testfile_size=$(stat -c %s $TESTFILE)
2042 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2043 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2044 "got ${testfile_size}. Verifying file failed!"
2047 resetquota -u $TSTUSR
2050 # test when mds does failover, the ost still could work well
2051 # this test shouldn't trigger watchdog b=14840
2053 # Clear dmesg so watchdog is not triggered by previous
2055 do_facet ost1 dmesg -c > /dev/null
2058 test_18_sub directio
2060 # check if watchdog is triggered
2061 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2062 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2063 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2064 [ -z "$watchdog" ] || error "$watchdog"
2065 rm -f $TMP/lustre-log-${TESTNAME}.log
2067 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2071 local TESTFILE=$DIR/$tdir/$tfile
2073 setup_quota_test || error "setup quota failed with $?"
2074 trap cleanup_quota_test EXIT
2076 set_ost_qtype $QTYPE || error "enable ost quota failed"
2078 # bind file to a single OST
2079 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2080 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2082 echo "Set user quota (limit: ${blimit}M)"
2083 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2084 error "set user quota failed"
2085 quota_show_check b u $TSTUSR
2086 echo "Update quota limits"
2087 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2088 error "set group quota failed"
2089 quota_show_check b u $TSTUSR
2091 # first wirte might be cached
2092 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2093 cancel_lru_locks osc
2095 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2096 quota_error u $TSTUSR "Write success, expect failure"
2100 resetquota -u $TSTUSR
2102 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2104 test_20() { # b15754
2105 local LSTR=(2g 1t 4k 3m) # limits strings
2107 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2110 resetquota -u $TSTUSR
2112 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2113 $MOUNT || error "could not set quota limits"
2114 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2115 --inode-softlimit ${LSTR[2]} \
2116 --inode-hardlimit ${LSTR[3]} \
2117 $MOUNT || error "could not set quota limits"
2119 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2120 error "bsoftlimit was not set properly"
2121 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2122 error "bhardlimit was not set properly"
2123 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2124 error "isoftlimit was not set properly"
2125 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2126 error "ihardlimit was not set properly"
2128 resetquota -u $TSTUSR
2130 run_test 20 "Test if setquota specifiers work properly (b15754)"
2137 local time=$(($(date +%s) + seconds))
2138 while [ $(date +%s) -lt $time ]; do
2139 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2143 # run for fixing bug16053, setquota shouldn't fail when writing and
2144 # deleting are happening
2146 local TESTFILE="$DIR/$tdir/$tfile"
2147 local BLIMIT=10 # 10G
2148 local ILIMIT=1000000
2150 setup_quota_test || error "setup quota failed with $?"
2151 trap cleanup_quota_test EXIT
2153 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2155 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2156 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2157 error "set user quota failed"
2158 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2159 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2160 error "set group quota failed"
2161 if is_project_quota_supported; then
2162 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2163 "project: $TSTPRJID"
2164 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2165 $MOUNT || error "set project quota failed"
2168 # repeat writing on a 1M file
2169 test_21_sub ${TESTFILE}_1 1 30 &
2171 # repeat writing on a 128M file
2172 test_21_sub ${TESTFILE}_2 128 30 &
2175 local time=$(($(date +%s) + 30))
2177 while [ $(date +%s) -lt $time ]; do
2178 log "Set quota for $i times"
2179 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2180 -I $((ILIMIT + i)) $MOUNT ||
2181 error "Set user quota failed"
2182 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2183 -I $((ILIMIT + i)) $MOUNT ||
2184 error "Set group quota failed"
2185 if is_project_quota_supported; then
2186 $LFS setquota -p $TSTPRJID -b 0 -B \
2187 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2188 error "Set project quota failed"
2196 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2198 if [ $count -gt 60 ]; then
2199 quota_error a $TSTUSR "dd should be finished!"
2203 echo "(dd_pid=$DDPID1, time=$count)successful"
2207 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2209 if [ $count -gt 60 ]; then
2210 quota_error a $TSTUSR "dd should be finished!"
2214 echo "(dd_pid=$DDPID2, time=$count)successful"
2217 resetquota -u $TSTUSR
2218 resetquota -g $TSTUSR
2219 resetquota -p $TSTPRJID
2221 run_test 21 "Setquota while writing & deleting (b16053)"
2223 # enable/disable quota enforcement permanently
2225 echo "Set both mdt & ost quota type as ug"
2227 is_project_quota_supported && qtype=$QTYPE
2228 set_mdt_qtype $qtype || error "enable mdt quota failed"
2229 set_ost_qtype $qtype || error "enable ost quota failed"
2232 stopall || error "failed to stopall (1)"
2236 echo "Verify if quota is enabled"
2237 local qtype1=$(mdt_quota_type)
2238 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2239 qtype=$(ost_quota_type)
2240 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2242 echo "Set both mdt & ost quota type as none"
2243 set_mdt_qtype "none" || error "disable mdt quota failed"
2244 set_ost_qtype "none" || error "disable ost quota failed"
2247 stopall || error "failed to stopall (2)"
2252 echo "Verify if quota is disabled"
2253 qtype=$(mdt_quota_type)
2254 [ $qtype != "none" ] && error "mdt quota setting is lost"
2255 qtype=$(ost_quota_type)
2256 [ $qtype != "none" ] && error "ost quota setting is lost"
2260 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2263 local TESTFILE="$DIR/$tdir/$tfile"
2266 setup_quota_test || error "setup quota failed with $?"
2267 trap cleanup_quota_test EXIT
2269 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2272 log "User quota (limit: $LIMIT MB)"
2273 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2274 error "set quota failed"
2275 quota_show_check b u $TSTUSR
2277 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2278 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2280 log "Step1: trigger EDQUOT with O_DIRECT"
2281 log "Write half of file"
2282 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2283 quota_error u $TSTUSR "(1) Write failure, expect success." \
2285 log "Write out of block quota ..."
2286 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2287 oflag=direct conv=notrunc &&
2288 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2292 log "Step2: rewrite should succeed"
2293 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2294 quota_error u $TSTUSR "(3) Write failure, expect success." \
2300 local OST0_UUID=$(ostuuid_from_index 0)
2301 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2302 [ $OST0_QUOTA_USED -ne 0 ] &&
2303 ($SHOW_QUOTA_USER; \
2304 quota_error u $TSTUSR "quota isn't released")
2306 resetquota -u $TSTUSR
2310 [ $(facet_fstype ost1) == "zfs" ] &&
2311 skip "Overwrite in place is not guaranteed to be " \
2312 "space neutral on ZFS"
2314 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2315 check_whether_skip && return 0
2316 log "run for 4MB test file"
2319 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2320 check_whether_skip && return 0
2321 log "run for 40MB test file"
2324 run_test 23 "Quota should be honored with directIO (b16125)"
2328 local TESTFILE="$DIR/$tdir/$tfile"
2330 setup_quota_test || error "setup quota failed with $?"
2331 trap cleanup_quota_test EXIT
2333 set_ost_qtype $QTYPE || error "enable ost quota failed"
2335 # bind file to a single OST
2336 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2337 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2339 echo "Set user quota (limit: ${blimit}M)"
2340 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2341 error "set quota failed"
2343 # overrun quota by root user
2344 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2345 error "write failure, expect success"
2346 cancel_lru_locks osc
2347 sync_all_data || true
2349 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2352 resetquota -u $TSTUSR
2354 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2356 test_27a() { # b19612
2357 $LFS quota $TSTUSR $DIR &&
2358 error "lfs succeeded with no type, but should have failed"
2359 $LFS setquota $TSTUSR $DIR &&
2360 error "lfs succeeded with no type, but should have failed"
2363 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2365 test_27b() { # b20200
2366 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2367 error "lfs setquota failed with uid argument"
2368 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2369 error "lfs stequota failed with gid argument"
2370 if is_project_quota_supported; then
2371 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2372 1000 $DIR || error \
2373 "lfs stequota failed with projid argument"
2375 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2376 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2377 if is_project_quota_supported; then
2378 $SHOW_QUOTA_PROJID ||
2379 error "lfs quota failed with projid argument"
2381 resetquota -u $TSTUSR
2382 resetquota -g $TSTUSR
2383 resetquota -p $TSTPRJID
2386 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2391 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2392 error "lfs setquota failed"
2394 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2395 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2396 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2397 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2399 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2400 error "lfs setquota for $TSTID failed"
2402 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2403 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2404 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2405 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2407 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2408 error "total allocated inode/block limit not printed"
2410 resetquota -u $TSTUSR
2412 run_test 27c "lfs quota should support human-readable output"
2419 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2420 error "set fraction block limit failed"
2421 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2422 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2423 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2424 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2426 resetquota -u $TSTUSR
2428 run_test 27d "lfs setquota should support fraction block limit"
2432 local TESTFILE="$DIR/$tdir/$tfile"
2435 setup_quota_test || error "setup quota failed with $?"
2436 trap cleanup_quota_test EXIT
2438 set_ost_qtype "u" || error "enable ost quota failed"
2440 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2441 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2443 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2444 $MAX_IQ_TIME $DIR || error "set grace time failed"
2445 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2446 error "set quota failed"
2447 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2448 cancel_lru_locks osc
2450 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2451 # over-quota flag has not yet settled since we do not trigger async
2452 # events based on grace time period expiration
2454 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2455 cancel_lru_locks osc
2456 # now over-quota flag should be settled and further writes should fail
2458 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2459 error "grace times were reset"
2462 resetquota -u $TSTUSR
2463 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2464 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2466 run_test 30 "Hard limit updates should not reset grace times"
2468 # basic usage tracking for user & group
2470 local INODES=10 # 10 files
2471 local BLK_CNT=2 # of 2M each
2472 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2474 setup_quota_test || error "setup quota failed with $?"
2475 trap cleanup_quota_test EXIT
2477 # make sure the system is clean
2478 local USED=$(getquota -u $TSTID global curspace)
2480 error "Used space ($USED) for user $TSTID isn't 0."
2481 USED=$(getquota -g $TSTID global curspace)
2483 error "Used space ($USED) for group $TSTID isn't 0."
2484 if is_project_quota_supported; then
2485 USED=$(getquota -p $TSTPRJID global curspace)
2486 [ $USED -ne 0 ] && error \
2487 "Used space ($USED) for project $TSTPRJID isn't 0."
2490 echo "Write files..."
2491 for i in $(seq 0 $INODES); do
2492 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2493 error "write failed"
2494 is_project_quota_supported &&
2495 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2496 echo "Iteration $i/$INODES completed"
2498 cancel_lru_locks osc
2500 echo "Wait for setattr on objects finished..."
2501 wait_delete_completed
2503 sync; sync_all_data || true
2505 echo "Verify disk usage after write"
2506 USED=$(getquota -u $TSTID global curspace)
2507 [ $USED -lt $TOTAL_BLKS ] &&
2508 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2509 USED=$(getquota -g $TSTID global curspace)
2510 [ $USED -lt $TOTAL_BLKS ] &&
2511 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2512 if is_project_quota_supported; then
2513 USED=$(getquota -p $TSTPRJID global curspace)
2514 [ $USED -lt $TOTAL_BLKS ] && error \
2515 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2518 echo "Verify inode usage after write"
2519 USED=$(getquota -u $TSTID global curinodes)
2520 [ $USED -lt $INODES ] &&
2521 error "Used inode for user $TSTID is $USED, expected $INODES"
2522 USED=$(getquota -g $TSTID global curinodes)
2523 [ $USED -lt $INODES ] &&
2524 error "Used inode for group $TSTID is $USED, expected $INODES"
2525 if is_project_quota_supported; then
2526 USED=$(getquota -p $TSTPRJID global curinodes)
2527 [ $USED -lt $INODES ] && error \
2528 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2533 echo "Verify disk usage after delete"
2534 USED=$(getquota -u $TSTID global curspace)
2535 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2536 USED=$(getquota -u $TSTID global curinodes)
2537 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2538 USED=$(getquota -g $TSTID global curspace)
2539 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2540 USED=$(getquota -g $TSTID global curinodes)
2541 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2542 if is_project_quota_supported; then
2543 USED=$(getquota -p $TSTPRJID global curspace)
2545 error "Used space for project $TSTPRJID isn't 0. $USED"
2546 USED=$(getquota -p $TSTPRJID global curinodes)
2548 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2551 run_test 33 "Basic usage tracking for user & group & project"
2553 # usage transfer test for user & group & project
2555 local BLK_CNT=2 # 2MB
2556 local project_supported="no"
2558 is_project_quota_supported && project_supported="yes"
2559 setup_quota_test || error "setup quota failed with $?"
2560 trap cleanup_quota_test EXIT
2562 # make sure the system is clean
2563 local USED=$(getquota -u $TSTID global curspace)
2564 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2565 USED=$(getquota -g $TSTID global curspace)
2566 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2568 local USED=$(getquota -u $TSTID2 global curspace)
2569 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2570 if [ $project_supported == "yes" ]; then
2571 USED=$(getquota -p $TSTPRJID global curspace)
2572 [ $USED -ne 0 ] && error \
2573 "Used space ($USED) for Project $TSTPRJID isn't 0."
2576 echo "Write file..."
2577 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2578 error "write failed"
2579 cancel_lru_locks osc
2580 sync; sync_all_data || true
2582 echo "chown the file to user $TSTID"
2583 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2585 echo "Wait for setattr on objects finished..."
2586 wait_delete_completed
2588 BLK_CNT=$((BLK_CNT * 1024))
2590 echo "Verify disk usage for user $TSTID"
2591 USED=$(getquota -u $TSTID global curspace)
2592 [ $USED -lt $BLK_CNT ] &&
2593 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2594 USED=$(getquota -u $TSTID global curinodes)
2596 error "Used inodes for user $TSTID is $USED, expected 1"
2598 echo "chgrp the file to group $TSTID"
2599 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2601 echo "Wait for setattr on objects finished..."
2602 wait_delete_completed
2604 echo "Verify disk usage for group $TSTID"
2605 USED=$(getquota -g $TSTID global curspace)
2606 [ $USED -ge $BLK_CNT ] ||
2607 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2608 USED=$(getquota -g $TSTID global curinodes)
2610 error "Used inodes for group $TSTID is $USED, expected 1"
2612 # chown won't change the ost object group. LU-4345 */
2613 echo "chown the file to user $TSTID2"
2614 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2616 echo "Wait for setattr on objects finished..."
2617 wait_delete_completed
2619 echo "change_project project id to $TSTPRJID"
2620 [ $project_supported == "yes" ] &&
2621 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2622 echo "Wait for setattr on objects finished..."
2623 wait_delete_completed
2625 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2626 USED=$(getquota -u $TSTID2 global curspace)
2627 [ $USED -lt $BLK_CNT ] &&
2628 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2629 USED=$(getquota -u $TSTID global curspace)
2631 error "Used space for user $TSTID is $USED, expected 0"
2632 USED=$(getquota -g $TSTID global curspace)
2633 [ $USED -lt $BLK_CNT ] &&
2634 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2635 if [ $project_supported == "yes" ]; then
2636 USED=$(getquota -p $TSTPRJID global curspace)
2637 [ $USED -lt $BLK_CNT ] && error \
2638 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2643 run_test 34 "Usage transfer for user & group & project"
2645 # usage is still accessible across restart
2647 local BLK_CNT=2 # 2 MB
2649 setup_quota_test || error "setup quota failed with $?"
2650 trap cleanup_quota_test EXIT
2652 echo "Write file..."
2653 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2654 error "write failed"
2655 is_project_quota_supported &&
2656 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2657 cancel_lru_locks osc
2659 echo "Wait for setattr on objects finished..."
2660 wait_delete_completed
2662 sync; sync_all_data || true
2664 echo "Save disk usage before restart"
2665 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2666 [ $ORIG_USR_SPACE -eq 0 ] &&
2667 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2668 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2669 [ $ORIG_USR_INODES -eq 0 ] &&
2670 error "Used inodes for user $TSTID is 0, expected 1"
2671 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2672 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2673 [ $ORIG_GRP_SPACE -eq 0 ] &&
2674 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2675 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2676 [ $ORIG_GRP_INODES -eq 0 ] &&
2677 error "Used inodes for group $TSTID is 0, expected 1"
2678 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2680 if is_project_quota_supported; then
2681 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2682 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2683 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2684 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2685 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2686 "Used inodes for project $TSTPRJID is 0, expected 1"
2687 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2695 echo "Verify disk usage after restart"
2696 local USED=$(getquota -u $TSTID global curspace)
2697 [ $USED -eq $ORIG_USR_SPACE ] ||
2698 error "Used space for user $TSTID changed from " \
2699 "$ORIG_USR_SPACE to $USED"
2700 USED=$(getquota -u $TSTID global curinodes)
2701 [ $USED -eq $ORIG_USR_INODES ] ||
2702 error "Used inodes for user $TSTID changed from " \
2703 "$ORIG_USR_INODES to $USED"
2704 USED=$(getquota -g $TSTID global curspace)
2705 [ $USED -eq $ORIG_GRP_SPACE ] ||
2706 error "Used space for group $TSTID changed from " \
2707 "$ORIG_GRP_SPACE to $USED"
2708 USED=$(getquota -g $TSTID global curinodes)
2709 [ $USED -eq $ORIG_GRP_INODES ] ||
2710 error "Used inodes for group $TSTID changed from " \
2711 "$ORIG_GRP_INODES to $USED"
2712 if [ $project_supported == "yes" ]; then
2713 USED=$(getquota -p $TSTPRJID global curinodes)
2714 [ $USED -eq $ORIG_PRJ_INODES ] ||
2715 error "Used inodes for project $TSTPRJID " \
2716 "changed from $ORIG_PRJ_INODES to $USED"
2717 USED=$(getquota -p $TSTPRJID global curspace)
2718 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2719 error "Used space for project $TSTPRJID "\
2720 "changed from $ORIG_PRJ_SPACE to $USED"
2723 # check if the vfs_dq_init() is called before writing
2724 echo "Append to the same file..."
2725 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2726 error "write failed"
2727 cancel_lru_locks osc
2728 sync; sync_all_data || true
2730 echo "Verify space usage is increased"
2731 USED=$(getquota -u $TSTID global curspace)
2732 [ $USED -gt $ORIG_USR_SPACE ] ||
2733 error "Used space for user $TSTID isn't increased" \
2734 "orig:$ORIG_USR_SPACE, now:$USED"
2735 USED=$(getquota -g $TSTID global curspace)
2736 [ $USED -gt $ORIG_GRP_SPACE ] ||
2737 error "Used space for group $TSTID isn't increased" \
2738 "orig:$ORIG_GRP_SPACE, now:$USED"
2739 if [ $project_supported == "yes" ]; then
2740 USED=$(getquota -p $TSTPRJID global curspace)
2741 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2742 error "Used space for project $TSTPRJID isn't " \
2743 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2748 run_test 35 "Usage is still accessible across reboot"
2750 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2753 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2754 skip "Old server doesn't have LU-5006 fix."
2756 setup_quota_test || error "setup quota failed with $?"
2757 trap cleanup_quota_test EXIT
2759 # make sure the system is clean
2760 local USED=$(getquota -u $TSTID global curspace)
2762 error "Used space ($USED) for user $TSTID isn't 0."
2764 # create file with MDS_OPEN_DELAY_CREATE flag
2765 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2766 error "Create file failed"
2768 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2769 oflag=sync || error "Write file failed"
2771 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2773 # wait for setattr on objects finished..."
2774 wait_delete_completed
2776 USED=$(getquota -u $TSTID global curspace)
2777 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2781 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2785 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2786 skip "Old server doesn't have LU-8801 fix."
2788 [ "$UID" != 0 ] && skip_env "must run as root" && return
2790 setup_quota_test || error "setup quota failed with $?"
2791 trap cleanup_quota_test EXIT
2793 # make sure the system is clean
2794 local USED=$(getquota -u $TSTID global curspace)
2796 error "Used space ($USED) for user $TSTID isn't 0."
2797 USED=$(getquota -u $TSTID2 global curspace)
2799 error "Used space ($USED) for user $TSTID2 isn't 0."
2801 local TESTFILE="$DIR/$tdir/$tfile"
2802 local file_cnt=10000
2804 # Generate id entries in accounting file
2805 echo "Create $file_cnt files..."
2806 for i in `seq $file_cnt`; do
2808 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2809 error "failed to chown $TESTFILE-$i"
2811 cancel_lru_locks osc
2812 sync; sync_all_data || true
2814 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2815 procf=${procf}.quota_slave.acct_user
2818 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2819 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2820 echo "Found $acct_cnt id entries"
2822 [ $file_cnt -eq $acct_cnt ] || {
2823 do_facet mds1 $LCTL get_param $procf
2824 error "skipped id entries"
2829 run_test 38 "Quota accounting iterator doesn't skip id entries"
2832 local TESTFILE="$DIR/$tdir/project"
2833 ! is_project_quota_supported &&
2834 skip "Project quota is not supported"
2836 setup_quota_test || error "setup quota failed with $?"
2839 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2840 [ $projectid -ne 0 ] &&
2841 error "Project id should be 0 not $projectid"
2842 change_project -p 1024 $TESTFILE
2843 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2844 [ $projectid -ne 1024 ] &&
2845 error "Project id should be 1024 not $projectid"
2847 stopall || error "failed to stopall (1)"
2850 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2851 [ $projectid -ne 1024 ] &&
2852 error "Project id should be 1024 not $projectid"
2856 run_test 39 "Project ID interface works correctly"
2859 ! is_project_quota_supported &&
2860 skip "Project quota is not supported"
2861 local dir1="$DIR/$tdir/dir1"
2862 local dir2="$DIR/$tdir/dir2"
2864 setup_quota_test || error "setup quota failed with $?"
2866 mkdir -p $dir1 $dir2
2867 change_project -sp 1 $dir1 && touch $dir1/1
2868 change_project -sp 2 $dir2
2870 ln $dir1/1 $dir2/1_link &&
2871 error "Hard link across different project quota should fail"
2876 run_test 40a "Hard link across different project ID"
2879 ! is_project_quota_supported &&
2880 skip "Project quota is not supported"
2881 local dir1="$DIR/$tdir/dir1"
2882 local dir2="$DIR/$tdir/dir2"
2884 setup_quota_test || error "setup quota failed with $?"
2885 mkdir -p $dir1 $dir2
2886 change_project -sp 1 $dir1 && touch $dir1/1
2887 change_project -sp 2 $dir2
2889 mv $dir1/1 $dir2/2 || error "mv failed $?"
2890 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2891 if [ "$projid" != "2" ]; then
2892 error "project id expected 2 not $projid"
2897 run_test 40b "Mv across different project ID"
2900 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2901 ! is_project_quota_supported &&
2902 skip "Project quota is not supported"
2904 setup_quota_test || error "setup quota failed with $?"
2905 local dir="$DIR/$tdir/dir"
2907 mkdir -p $dir && change_project -sp 1 $dir
2908 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2909 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2910 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2911 touch $dir/remote_dir/file
2912 #verify inherit works file for remote dir.
2913 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2914 [ "$projid" != "1" ] &&
2915 error "file under remote dir expected 1 not $projid"
2917 #Agent inode should be ignored for project quota
2918 USED=$(getquota -p 1 global curinodes)
2919 [ "$USED" != "3" ] &&
2920 error "file count expected 3 got $USED"
2926 run_test 40c "Remote child Dir inherit project quota properly"
2929 ! is_project_quota_supported &&
2930 skip "Project quota is not supported"
2932 setup_quota_test || error "setup quota failed with $?"
2933 local dir1="$DIR/$tdir/dir1"
2934 local dir2="$DIR/$tdir/dir2"
2936 mkdir -p $dir1 && change_project -sp 1 $dir1
2937 mkdir -p $dir2 && change_project -sp 2 $dir2
2938 for num in $(seq 1 10); do
2939 touch $dir1/file_$num $dir2/file_$num
2940 ln -s $dir1/file_$num $dir1/file_$num"_link"
2941 ln -s $dir2/file_$num $dir2/file_$num"_link"
2944 count=$($LFS find --projid 1 $DIR | wc -l)
2945 [ "$count" != 21 ] && error "expected 21 but got $count"
2947 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2948 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2949 [ "$count" != 22 ] && error "expected 22 but got $count"
2954 run_test 50 "Test if lfs find --projid works"
2957 ! is_project_quota_supported &&
2958 skip "Project quota is not supported"
2959 setup_quota_test || error "setup quota failed with $?"
2960 local dir="$DIR/$tdir/dir"
2962 mkdir $dir && change_project -sp 1 $dir
2963 local used=$(getquota -p 1 global curinodes)
2964 [ $used != "1" ] && error "expected 1 got $used"
2969 used=$(getquota -p 1 global curinodes)
2970 [ $used != "4" ] && error "expected 4 got $used"
2972 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2974 cp $DIR/$tdir/6 $dir/6
2975 used=$(getquota -p 1 global curinodes)
2976 [ $used != "5" ] && error "expected 5 got $used"
2979 mv $DIR/$tdir/6 $dir/7
2980 used=$(getquota -p 1 global curinodes)
2981 [ $used != "6" ] && error "expected 6 got $used"
2986 run_test 51 "Test project accounting with mv/cp"
2989 ! is_project_quota_supported &&
2990 skip "Project quota is not supported"
2991 setup_quota_test || error "setup quota failed with $?"
2992 local dir="$DIR/$tdir/dir"
2993 mkdir $dir && change_project -sp 1 $dir
2995 touch $DIR/$tdir/file
2996 #Try renaming a file into the project. This should fail.
2997 for num in $(seq 1 2000); do
2998 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2999 error "rename should fail"
3004 run_test 52 "Rename across different project ID"
3007 ! is_project_quota_supported &&
3008 skip "Project quota is not supported"
3009 setup_quota_test || error "setup quota failed with $?"
3010 local dir="$DIR/$tdir/dir"
3011 mkdir $dir && change_project -s $dir
3012 lfs project -d $dir | grep P || error "inherit attribute should be set"
3014 change_project -C $dir
3015 lfs project -d $dir | grep P &&
3016 error "inherit attribute should be cleared"
3021 run_test 53 "Project inherit attribute could be cleared"
3024 ! is_project_quota_supported &&
3025 skip "Project quota is not supported"
3026 setup_quota_test || error "setup quota failed with $?"
3027 trap cleanup_quota_test EXIT
3028 local testfile="$DIR/$tdir/$tfile-0"
3030 #set project ID/inherit attribute
3031 change_project -sp $TSTPRJID $DIR/$tdir
3032 $RUNAS createmany -m ${testfile} 100 ||
3033 error "create many files failed"
3035 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3036 # one more count for directory itself */
3040 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3041 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3043 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3044 [ $proj_count1 -eq $proj_count ] ||
3045 error "c2: expected $proj_count got $proj_count1"
3047 #clear project but with kept projid
3048 change_project -rCk $DIR/$tdir
3049 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3050 [ $proj_count1 -eq 1 ] ||
3051 error "c3: expected 1 got $proj_count1"
3053 #verify projid untouched.
3054 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3056 [ $proj_count1 -eq $proj_count ] ||
3057 error "c4: expected $proj_count got $proj_count1"
3060 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3061 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3062 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3064 #this time clear all
3065 change_project -rC $DIR/$tdir
3066 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3067 [ $proj_count1 -eq 0 ] ||
3068 error "c6: expected 0 got $proj_count1"
3070 unlinkmany ${testfile} 100 ||
3071 error "unlink many files failed"
3075 run_test 54 "basic lfs project interface test"
3078 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3079 skip "Not supported before 2.10.58."
3080 setup_quota_test || error "setup quota failed with $?"
3082 set_ost_qtype $QTYPE || error "enable ost quota failed"
3085 #add second group to TSTUSR
3086 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3089 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3090 error "failed to dd"
3092 cancel_lru_locks osc
3093 sync; sync_all_data || true
3095 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3096 error "failed to setquota on group $TSTUSR2"
3098 $LFS quota -v -g $TSTUSR2 $DIR
3100 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3101 error "chgrp should failed with -EDQUOT"
3103 USED=$(getquota -g $TSTUSR2 global curspace)
3106 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3107 error "failed to setquota on group $TSTUSR2"
3109 $LFS quota -v -g $TSTUSR2 $DIR
3111 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3112 error "chgrp should succeed"
3114 $LFS quota -v -g $TSTUSR2 $DIR
3116 resetquota -g $TSTUSR2
3119 run_test 55 "Chgrp should be affected by group quota"
3122 setup_quota_test || error "setup quota failed with $?"
3124 set_ost_qtype $QTYPE || error "enable ost quota failed"
3127 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3128 erro "failed to set grace time for usr quota"
3129 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3130 awk '{print $4 $8}')
3131 if [ "x$grace_time" != "x10s;10s" ]; then
3132 $LFS quota -t -u $DIR
3133 error "expected grace time: 10s;10s, got:$grace_time"
3138 run_test 56 "lfs quota -t should work well"
3141 setup_quota_test || error "setup quota failed with $?"
3143 local dir="$DIR/$tdir/dir"
3146 #try to change pipe file should not hang and return failure
3147 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3148 awk -F ':' '{ print \\\$2 }'" \
3149 " unable to get xattr for fifo '$dir/pipe'" || return 1
3150 #command can process further if it hit some errors
3151 touch $dir/aaa $dir/bbb
3152 mkdir $dir/subdir -p
3153 touch $dir/subdir/aaa $dir/subdir/bbb
3154 #create one invalid link file
3155 ln -s $dir/not_exist_file $dir/ccc
3156 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3157 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3161 run_test 57 "lfs project could tolerate errors"
3164 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3165 skip "ldiskfs only test"
3166 disable_project_quota
3167 setup_quota_test || error "setup quota failed with $?"
3170 local testfile="$DIR/$tdir/$tfile-0"
3171 #make sure it did not crash kernel
3172 touch $testfile && lfs project -sp 1 $testfile
3174 enable_project_quota
3177 run_test 59 "lfs project dosen't crash kernel with project disabled"
3180 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3181 skip "Needs MDS version 2.11.53 or later."
3182 setup_quota_test || error "setup quota failed with $?"
3183 trap cleanup_quota_test EXIT
3185 local testfile=$DIR/$tdir/$tfile
3188 set_mdt_qtype "ug" || error "enable mdt quota failed"
3190 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3191 error "set quota failed"
3192 quota_show_check a g $TSTUSR
3194 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3195 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3196 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3197 error "create many files failed"
3199 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3201 # root user can overrun quota
3202 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3203 error "root user should succeed"
3206 resetquota -g $TSTUSR
3208 run_test 60 "Test quota for root with setgid"
3210 # test default quota
3211 test_default_quota() {
3212 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3213 skip "Not supported before 2.11.51."
3218 local qprjid=$TSTPRJID
3222 local LIMIT=20480 #20M disk space
3223 local TESTFILE="$DIR/$tdir/$tfile-0"
3225 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3226 echo "Project quota is not supported" && return 0
3228 [ $qtype == "-u" ] && qdtype="-U"
3229 [ $qtype == "-g" ] && qdtype="-G"
3230 [ $qtype == "-p" ] && {
3235 [ $qpool == "meta" ] && {
3236 LIMIT=10240 #10K inodes
3241 setup_quota_test || error "setup quota failed with $?"
3242 trap cleanup_quota_test EXIT
3246 # enable mdt/ost quota
3247 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3248 set_ost_qtype $QTYPE || error "enable ost quota failed"
3250 log "set to use default quota"
3251 $LFS setquota $qtype $qid -d $DIR ||
3252 error "set $qid to use default quota failed"
3254 log "set default quota"
3255 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3256 error "set $qid default quota failed"
3258 log "get default quota"
3259 $LFS quota $qdtype $DIR || error "get default quota failed"
3261 if [ $qpool == "data" ]; then
3262 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3264 [ $SLIMIT -eq $LIMIT ] ||
3265 error "the returned default quota is wrong"
3267 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3269 [ $SLIMIT -eq $LIMIT ] ||
3270 error "the returned default quota is wrong"
3273 # make sure the system is clean
3274 local USED=$(getquota $qtype $qid global curspace)
3275 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3277 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3278 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3280 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3282 log "Test not out of quota"
3283 if [ $qpool == "data" ]; then
3284 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3285 quota_error $qtype $qid "write failed, expect succeed"
3287 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3288 quota_error $qtype $qid "create failed, expect succeed"
3290 unlinkmany $TESTFILE $((LIMIT/2))
3293 log "Test out of quota"
3294 # flush cache, ensure noquota flag is set on client
3295 cancel_lru_locks osc
3296 cancel_lru_locks mdc
3297 sync; sync_all_data || true
3298 if [ $qpool == "data" ]; then
3299 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3300 quota_error $qtype $qid "write succeed, expect EDQUOT"
3302 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3303 quota_error $qtype $qid "create succeed, expect EDQUOT"
3305 unlinkmany $TESTFILE $((LIMIT*2))
3308 log "Increase default quota"
3309 # increase default quota
3310 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3311 error "set default quota failed"
3313 cancel_lru_locks osc
3314 cancel_lru_locks mdc
3315 sync; sync_all_data || true
3316 if [ $qpool == "data" ]; then
3317 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3318 quota_error $qtype $qid "write failed, expect succeed"
3320 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3321 quota_error $qtype $qid "create failed, expect succeed"
3323 unlinkmany $TESTFILE $((LIMIT*2))
3326 log "Set quota to override default quota"
3327 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3328 error "set $qid quota failed"
3330 cancel_lru_locks osc
3331 cancel_lru_locks mdc
3332 sync; sync_all_data || true
3333 if [ $qpool == "data" ]; then
3334 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3335 quota_error $qtype $qid "write succeed, expect EQUOT"
3337 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3338 quota_error $qtype $qid "create succeed, expect EQUOT"
3340 unlinkmany $TESTFILE $((LIMIT*2))
3343 log "Set to use default quota again"
3344 $LFS setquota $qtype $qid -d $DIR ||
3345 error "set $qid to use default quota failed"
3347 cancel_lru_locks osc
3348 cancel_lru_locks mdc
3349 sync; sync_all_data || true
3350 if [ $qpool == "data" ]; then
3351 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3352 quota_error $qtype $qid "write failed, expect succeed"
3354 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3355 quota_error $qtype $qid "create failed, expect succeed"
3357 unlinkmany $TESTFILE $((LIMIT*2))
3362 wait_delete_completed || error "wait_delete_completed failed"
3363 sync_all_data || true
3364 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3365 error "reset default quota failed"
3366 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3367 error "reset quota failed"
3373 test_default_quota "-u" "data"
3374 test_default_quota "-u" "meta"
3375 test_default_quota "-g" "data"
3376 test_default_quota "-g" "meta"
3377 test_default_quota "-p" "data"
3378 test_default_quota "-p" "meta"
3380 run_test 61 "default quota tests"
3383 ! is_project_quota_supported &&
3384 skip "Project quota is not supported"
3385 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3386 skip "chattr did not support project quota"
3387 setup_quota_test || error "setup quota failed with $?"
3388 local testdir=$DIR/$tdir/
3390 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3391 change_project -s $testdir
3392 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3393 error "inherit attribute should be set"
3394 # chattr used FS_IOC_SETFLAGS ioctl
3395 $RUNAS chattr -P $testdir &&
3396 error "regular user clear inherit should fail"
3397 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3398 error "inherit attribute should still be set"
3399 chattr -P $testdir || error "root failed to clear inherit"
3400 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3401 error "inherit attribute should be cleared"
3404 run_test 62 "Project inherit should be only changed by root"
3407 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3408 skip "Not supported before 2.11.55" && return
3412 local dd_failed=false
3413 local tdir_dom=${tdir}_dom
3414 local LIMIT=20480 #20M
3416 [ $qtype == "p" ] && ! is_project_quota_supported &&
3417 echo "Project quota is not supported" && return 0
3419 [ $qtype == "p" ] && qid=$TSTPRJID
3421 setup_quota_test || error "setup quota failed with $?"
3422 trap cleanup_quota_test EXIT
3426 # enable mdt/ost quota
3427 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3428 set_ost_qtype $QTYPE || error "enable ost quota failed"
3430 # make sure the system is clean
3431 local USED=$(getquota -$qtype $qid global curspace)
3432 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3434 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3436 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3437 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3438 error "setstripe $tdir_dom failed"
3439 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3441 [ $qtype == "p" ] && {
3442 change_project -sp $TSTPRJID $DIR/$tdir
3443 change_project -sp $TSTPRJID $DIR/$tdir_dom
3446 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3447 error "set $qid quota failed"
3449 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3450 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3454 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3456 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3457 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3461 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3463 rm -f $DIR/$tdir_dom/*
3465 # flush cache, ensure noquota flag is set on client
3466 cancel_lru_locks osc
3467 cancel_lru_locks mdc
3468 sync; sync_all_data || true
3472 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3473 quota_error $qtype $qid "write failed, expect succeed"
3475 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3476 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3480 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3483 rm -f $DIR/$tdir_dom/*
3485 # flush cache, ensure noquota flag is set on client
3486 cancel_lru_locks osc
3487 cancel_lru_locks mdc
3488 sync; sync_all_data || true
3492 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3493 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3497 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3499 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3500 quota_error $qtype $qid "write succeed, expect EDQUOT"
3503 rm -fr $DIR/$tdir_dom
3505 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3506 error "reset usr quota failed"
3516 run_test 63 "quota on DoM tests"
3519 ! is_project_quota_supported &&
3520 skip "Project quota is not supported"
3521 setup_quota_test || error "setup quota failed with $?"
3522 local dir1="$DIR/$tdir/"
3525 ln -s $dir1/file $dir1/file_link
3527 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3528 error "set symlink file's project should fail"
3530 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3531 error "get symlink file's project should fail"
3535 run_test 64 "lfs project on symlink files should fail"
3538 ! is_project_quota_supported &&
3539 skip "Project quota is not supported"
3540 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
3541 skip "Not supported before 2.12.4"
3542 setup_quota_test || error "setup quota failed with $?"
3543 stack_trap cleanup_quota_test EXIT
3544 local old=$(do_facet mds1 $LCTL get_param -n \
3545 mdt.*.enable_chprojid_gid | head -1)
3546 local testdir=$DIR/$tdir/foo
3548 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3549 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3552 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3553 chown -R $TSTID:$TSTID $testdir
3554 change_project -sp $TSTPRJID $testdir
3555 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3557 $RUNAS lfs project -p 0 $testdir/foo &&
3558 error "nonroot user should fail to set projid"
3560 $RUNAS lfs project -C $testdir/foo &&
3561 error "nonroot user should fail to clear projid"
3563 change_project -C $testdir/foo || error "failed to clear project"
3565 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3566 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3567 "failed to set projid with normal user when enable_chprojid_gid=-1"
3569 $RUNAS lfs project -rC $testdir/ || error \
3570 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3572 touch $testdir/bar || error "failed touch $testdir/bar"
3573 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3574 "normal user should not be able to set projid on root owned file"
3576 change_project -p $TSTPRJID $testdir/bar || error \
3577 "root should be able to change its own file's projid"
3581 run_test 66 "nonroot user can not change project state in default"
3585 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3586 disable_project_quota
3588 reset_quota_settings
3593 check_and_cleanup_lustre
3594 export QUOTA_AUTO=$QUOTA_AUTO_OLD