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 if at_is_enabled; then
1213 at_max_saved=$(at_max_get ost1)
1214 at_max_set $TIMEOUT ost1
1216 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1217 # DQACQ is sent, which makes at_max to take effect
1218 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1221 wait_delete_completed
1225 sync_all_data || true
1227 #define QUOTA_DQACQ 601
1228 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1229 lustre_fail mds 0x513 601
1231 do_facet ost1 $LCTL set_param \
1232 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1234 # write to un-enforced ID ($TSTUSR2) should succeed
1235 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1236 error "write failure, expect success"
1238 # write to enforced ID ($TSTUSR) in background, exceeding limit
1239 # to make sure DQACQ is sent
1240 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1243 # watchdog timer uses a factor of 2
1244 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1245 sleep $((TIMEOUT * 2 + 1))
1247 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1249 # write should be blocked and never finished
1250 if ! ps -p $DDPID > /dev/null 2>&1; then
1252 error "write finished incorrectly!"
1257 # no watchdog is triggered
1258 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1259 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1260 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1261 [ -z "$watchdog" ] || error "$watchdog"
1263 rm -f $TMP/lustre-log-${TESTNAME}.log
1265 # write should continue then fail with EDQUOT
1269 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1270 if [ $count -ge 240 ]; then
1271 quota_error u $TSTUSR "dd not finished in $count secs"
1273 count=$((count + 1))
1274 if [ $((count % 30)) -eq 0 ]; then
1275 c_size=$(stat -c %s $TESTFILE)
1276 echo "Waiting $count secs. $c_size"
1283 resetquota -u $TSTUSR
1285 run_test 6 "Test dropping acquire request on master"
1287 # quota reintegration (global index)
1289 local TESTFILE=$DIR/$tdir/$tfile
1290 local LIMIT=20 # 20M
1292 [ "$SLOW" = "no" ] && LIMIT=5
1294 setup_quota_test || error "setup quota failed with $?"
1295 trap cleanup_quota_test EXIT
1297 # make sure the system is clean
1298 local USED=$(getquota -u $TSTUSR global curspace)
1299 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1301 # make sure no granted quota on ost1
1302 set_ost_qtype $QTYPE || error "enable ost quota failed"
1303 resetquota -u $TSTUSR
1304 set_ost_qtype "none" || error "disable ost quota failed"
1306 local OSTUUID=$(ostuuid_from_index 0)
1307 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1309 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1312 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1313 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1318 echo "Enable quota & set quota limit for $TSTUSR"
1319 set_ost_qtype $QTYPE || error "enable ost quota failed"
1320 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1321 error "set quota failed"
1323 echo "Start ost1..."
1324 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1327 wait_ost_reint $QTYPE || error "reintegration failed"
1329 # hardlimit should have been fetched by slave during global
1330 # reintegration, write will exceed quota
1331 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1332 quota_error u $TSTUSR "write success, but expect EDQUOT"
1335 wait_delete_completed
1336 sync_all_data || true
1342 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1343 error "clear quota failed"
1345 echo "Start ost1..."
1346 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1349 wait_ost_reint $QTYPE || error "reintegration failed"
1351 # hardlimit should be cleared on slave during reintegration
1352 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1353 quota_error u $TSTUSR "write error, but expect success"
1356 resetquota -u $TSTUSR
1358 run_test 7a "Quota reintegration (global index)"
1360 # quota reintegration (slave index)
1363 local TESTFILE=$DIR/$tdir/$tfile
1365 setup_quota_test || error "setup quota failed with $?"
1366 trap cleanup_quota_test EXIT
1368 # make sure the system is clean
1369 local USED=$(getquota -u $TSTUSR global curspace)
1370 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1372 # make sure no granted quota on ost1
1373 set_ost_qtype $QTYPE || error "enable ost quota failed"
1374 resetquota -u $TSTUSR
1375 set_ost_qtype "none" || error "disable ost quota failed"
1377 local OSTUUID=$(ostuuid_from_index 0)
1378 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1380 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1383 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1384 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1386 # consume some space to make sure the granted space will not
1387 # be released during reconciliation
1388 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1389 error "consume space failure, expect success"
1391 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1392 lustre_fail mds 0xa02
1394 set_ost_qtype $QTYPE || error "enable ost quota failed"
1395 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1396 error "set quota failed"
1398 # ignore the write error
1399 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1401 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1405 echo "Restart ost to trigger reintegration..."
1407 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1410 wait_ost_reint $QTYPE || error "reintegration failed"
1412 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1413 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1416 resetquota -u $TSTUSR
1419 run_test 7b "Quota reintegration (slave index)"
1421 # quota reintegration (restart mds during reintegration)
1423 local LIMIT=20 # 20M
1424 local TESTFILE=$DIR/$tdir/$tfile
1426 [ "$SLOW" = "no" ] && LIMIT=5
1428 setup_quota_test || error "setup quota failed with $?"
1429 trap cleanup_quota_test EXIT
1431 # make sure the system is clean
1432 local USED=$(getquota -u $TSTUSR global curspace)
1433 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1435 set_ost_qtype "none" || error "disable ost quota failed"
1436 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1437 error "set quota failed"
1439 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1440 lustre_fail ost 0xa03
1443 set_ost_qtype $QTYPE || error "enable ost quota failed"
1444 # trigger reintegration
1445 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1446 procf=${procf}quota_slave.force_reint
1447 do_facet ost1 $LCTL set_param $procf=1 ||
1448 error "force reintegration failed"
1456 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1459 # wait longer than usual to make sure the reintegration
1460 # is triggered by quota wb thread.
1461 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1463 # hardlimit should have been fetched by slave during global
1464 # reintegration, write will exceed quota
1465 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1466 quota_error u $TSTUSR "write success, but expect EDQUOT"
1469 resetquota -u $TSTUSR
1471 run_test 7c "Quota reintegration (restart mds during reintegration)"
1473 # Quota reintegration (Transfer index in multiple bulks)
1475 local TESTFILE=$DIR/$tdir/$tfile
1476 local TESTFILE1="$DIR/$tdir/$tfile"-1
1479 setup_quota_test || error "setup quota failed with $?"
1480 trap cleanup_quota_test EXIT
1482 set_ost_qtype "none" || error "disable ost quota failed"
1483 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1484 error "set quota for $TSTUSR failed"
1485 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1486 error "set quota for $TSTUSR2 failed"
1488 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1489 lustre_fail mds 0x608 0
1491 # enable quota to tirgger reintegration
1492 set_ost_qtype "u" || error "enable ost quota failed"
1493 wait_ost_reint "u" || error "reintegration failed"
1497 # hardlimit should have been fetched by slave during global
1498 # reintegration, write will exceed quota
1499 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1500 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1502 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1503 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1506 resetquota -u $TSTUSR
1507 resetquota -u $TSTUSR2
1509 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1511 # quota reintegration (inode limits)
1513 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1515 # LU-2435: skip this quota test if underlying zfs version has not
1516 # supported native dnode accounting
1517 [ "$(facet_fstype mds1)" == "zfs" ] && {
1518 local F="feature@userobj_accounting"
1519 local pool=$(zpool_name mds1)
1520 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1522 [[ "$feature" != *" active "* ]] &&
1523 skip "requires zpool with active userobj_accounting"
1526 local ilimit=$((1024 * 2)) # 2k inodes
1527 local TESTFILE=$DIR/${tdir}-1/$tfile
1529 setup_quota_test || error "setup quota failed with $?"
1530 trap cleanup_quota_test EXIT
1532 # make sure the system is clean
1533 local USED=$(getquota -u $TSTUSR global curinodes)
1534 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1536 # make sure no granted quota on mdt1
1537 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1538 resetquota -u $TSTUSR
1539 set_mdt_qtype "none" || error "disable mdt quota failed"
1541 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1542 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1543 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1546 echo "Stop mds${MDSCOUNT}..."
1549 echo "Enable quota & set quota limit for $TSTUSR"
1550 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1551 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1552 error "set quota failed"
1554 echo "Start mds${MDSCOUNT}..."
1555 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1558 wait_mdt_reint $QTYPE || error "reintegration failed"
1560 echo "create remote dir"
1561 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1562 error "create remote dir failed"
1563 chmod 0777 $DIR/${tdir}-1
1565 # hardlimit should have been fetched by slave during global
1566 # reintegration, create will exceed quota
1567 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1568 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1570 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1571 wait_delete_completed
1572 sync_all_data || true
1574 echo "Stop mds${MDSCOUNT}..."
1577 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1578 error "clear quota failed"
1580 echo "Start mds${MDSCOUNT}..."
1581 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1584 wait_mdt_reint $QTYPE || error "reintegration failed"
1586 # hardlimit should be cleared on slave during reintegration
1587 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1588 quota_error u $TSTUSR "create failed, expect success"
1590 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1591 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1594 resetquota -u $TSTUSR
1596 run_test 7e "Quota reintegration (inode limits)"
1598 # run dbench with quota enabled
1600 local BLK_LIMIT="100g" #100G
1601 local FILE_LIMIT=1000000
1603 setup_quota_test || error "setup quota failed with $?"
1604 trap cleanup_quota_test EXIT
1606 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1607 set_ost_qtype $QTYPE || error "enable ost quota failed"
1609 echo "Set enough high limit for user: $TSTUSR"
1610 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1611 error "set user quota failed"
1612 echo "Set enough high limit for group: $TSTUSR"
1613 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1614 error "set group quota failed"
1615 if is_project_quota_supported; then
1616 change_project -sp $TSTPRJID $DIR/$tdir
1617 echo "Set enough high limit for project: $TSTPRJID"
1618 $LFS setquota -p $TSTPRJID -b 0 \
1619 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1620 error "set project quota failed"
1624 [ "$SLOW" = "no" ] && duration=" -t 120"
1625 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1626 quota_error a $TSTUSR "dbench failed!"
1628 is_project_quota_supported && change_project -C $DIR/$tdir
1630 resetquota -u $TSTUSR
1631 resetquota -g $TSTUSR
1632 resetquota -p $TSTPRJID
1634 run_test 8 "Run dbench with quota enabled"
1636 # this check is just for test_9
1637 OST0_MIN=4900000 #4.67G
1639 check_whether_skip () {
1640 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1641 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1642 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1643 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1650 # run for fixing bug10707, it needs a big room. test for 64bit
1652 local filesize=$((1024 * 9 / 2)) # 4.5G
1654 check_whether_skip && return 0
1656 setup_quota_test || error "setup quota failed with $?"
1657 trap cleanup_quota_test EXIT
1659 set_ost_qtype "ug" || error "enable ost quota failed"
1661 local TESTFILE="$DIR/$tdir/$tfile-0"
1662 local BLK_LIMIT=100G #100G
1663 local FILE_LIMIT=1000000
1665 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1667 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1669 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1670 error "set user quota failed"
1672 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1673 "for group: $TSTUSR"
1674 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1675 error "set group quota failed"
1677 quota_show_check a u $TSTUSR
1678 quota_show_check a g $TSTUSR
1680 echo "Create test file"
1681 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1682 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1684 log "Write the big file of 4.5G ..."
1685 $RUNAS $DD of=$TESTFILE count=$filesize ||
1686 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1692 resetquota -u $TSTUSR
1693 resetquota -g $TSTUSR
1698 run_test 9 "Block limit larger than 4GB (b10707)"
1701 local TESTFILE=$DIR/$tdir/$tfile
1703 setup_quota_test || error "setup quota failed with $?"
1704 trap cleanup_quota_test EXIT
1706 # set limit to root user should fail
1707 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1708 error "set limit for root user successfully, expect failure"
1709 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1710 error "set limit for root group successfully, expect failure"
1711 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1712 error "set limit for project 0 successfully, expect failure"
1714 # root user can overrun quota
1715 set_ost_qtype "ug" || error "enable ost quota failed"
1717 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1718 error "set quota failed"
1719 quota_show_check b u $TSTUSR
1721 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1722 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1724 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1725 error "write failure, expect success"
1728 resetquota -u $TSTUSR
1730 run_test 10 "Test quota for root user"
1733 local TESTFILE=$DIR/$tdir/$tfile
1734 setup_quota_test || error "setup quota failed with $?"
1735 trap cleanup_quota_test EXIT
1737 set_mdt_qtype "ug" || error "enable mdt quota failed"
1738 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1739 error "set quota failed"
1741 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1742 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1744 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1745 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1748 local USED=$(getquota -u $TSTUSR global curinodes)
1749 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1752 resetquota -u $TSTUSR
1754 run_test 11 "Chown/chgrp ignores quota"
1757 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1759 local blimit=22 # 22M
1760 local blk_cnt=$((blimit - 5))
1761 local TESTFILE0="$DIR/$tdir/$tfile"-0
1762 local TESTFILE1="$DIR/$tdir/$tfile"-1
1764 setup_quota_test || error "setup quota failed with $?"
1765 trap cleanup_quota_test EXIT
1767 set_ost_qtype "u" || error "enable ost quota failed"
1768 quota_show_check b u $TSTUSR
1770 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1771 error "set quota failed"
1773 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1774 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1775 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1776 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1778 echo "Write to ost0..."
1779 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1780 quota_error a $TSTUSR "dd failed"
1782 echo "Write to ost1..."
1783 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1784 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1786 echo "Free space from ost0..."
1788 wait_delete_completed
1789 sync_all_data || true
1791 echo "Write to ost1 after space freed from ost0..."
1792 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1793 quota_error a $TSTUSR "rebalancing failed"
1796 resetquota -u $TSTUSR
1798 run_test 12a "Block quota rebalancing"
1801 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1803 local ilimit=$((1024 * 2)) # 2k inodes
1804 local TESTFILE0=$DIR/$tdir/$tfile
1805 local TESTFILE1=$DIR/${tdir}-1/$tfile
1807 setup_quota_test || error "setup quota failed with $?"
1808 trap cleanup_quota_test EXIT
1810 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1811 chmod 0777 $DIR/${tdir}-1
1813 set_mdt_qtype "u" || error "enable mdt quota failed"
1814 quota_show_check f u $TSTUSR
1816 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1817 error "set quota failed"
1819 echo "Create $ilimit files on mdt0..."
1820 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1821 quota_error u $TSTUSR "create failed, but expect success"
1823 echo "Create files on mdt1..."
1824 $RUNAS createmany -m $TESTFILE1 1 &&
1825 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1827 echo "Free space from mdt0..."
1828 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1829 wait_delete_completed
1830 sync_all_data || true
1832 echo "Create files on mdt1 after space freed from mdt0..."
1833 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1834 quota_error a $TSTUSR "rebalancing failed"
1836 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1837 error "unlink mdt1 files failed"
1838 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1841 resetquota -u $TSTUSR
1843 run_test 12b "Inode quota rebalancing"
1846 local TESTFILE=$DIR/$tdir/$tfile
1847 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1848 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1850 setup_quota_test || error "setup quota failed with $?"
1851 trap cleanup_quota_test EXIT
1853 set_ost_qtype "u" || error "enable ost quota failed"
1854 quota_show_check b u $TSTUSR
1856 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1857 error "set quota failed"
1858 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1859 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1861 # clear the locks in cache first
1862 do_facet ost1 $LCTL set_param -n $procf=clear
1863 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1864 [ $nlock -eq 0 ] || error "$nlock cached locks"
1866 # write to acquire the per-ID lock
1867 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1868 quota_error a $TSTUSR "dd failed"
1870 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1871 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1873 # clear quota doesn't trigger per-ID lock cancellation
1874 resetquota -u $TSTUSR
1875 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1876 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1878 # clear the per-ID lock
1879 do_facet ost1 $LCTL set_param -n $procf=clear
1880 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1881 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1883 # spare quota should be released
1884 local OSTUUID=$(ostuuid_from_index 0)
1885 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1886 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1887 [ $limit -le $space ] ||
1888 error "spare quota isn't released, limit:$limit, space:$space"
1892 run_test 13 "Cancel per-ID lock in the LRU list"
1895 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1897 wait_delete_completed
1898 sync_all_data || true
1901 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1902 error "set user quota failed"
1903 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1904 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1905 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1906 resetquota -u $TSTUSR
1909 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1910 error "set group quota failed"
1911 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1912 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1913 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1914 resetquota -g $TSTUSR
1916 run_test 15 "Set over 4T block quota"
1920 local BLKS=1 # 1M less than limit
1921 local TESTFILE=$DIR/$tdir/$tfile
1923 setup_quota_test || error "setup quota failed with $?"
1924 trap cleanup_quota_test EXIT
1926 # make sure the system is clean
1927 local USED=$(getquota -u $TSTUSR global curspace)
1928 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1930 set_ost_qtype "ug" || error "enable ost quota failed"
1931 # make sure no granted quota on ost
1932 resetquota -u $TSTUSR
1933 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1934 error "set quota failed"
1936 quota_show_check b u $TSTUSR
1938 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1939 lustre_fail mds 0xa04 $err_code
1941 # write in background
1942 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1946 # write should be blocked and never finished
1947 if ! ps -p $DDPID > /dev/null 2>&1; then
1949 quota_error u $TSTUSR "write finished incorrectly!"
1957 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1959 if [ $count -gt $timeout ]; then
1960 quota_error u $TSTUSR "dd is not finished!"
1965 sync; sync_all_data || true
1967 USED=$(getquota -u $TSTUSR global curspace)
1968 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1969 "Used space(${USED}K) is less than ${BLKS}M"
1972 resetquota -u $TSTUSR
1975 # DQACQ return recoverable error
1977 echo "DQACQ return -ENOLCK"
1979 test_17sub 37 || error "Handle -ENOLCK failed"
1981 echo "DQACQ return -EAGAIN"
1983 test_17sub 11 || error "Handle -EAGAIN failed"
1985 echo "DQACQ return -ETIMEDOUT"
1986 #define ETIMEDOUT 110
1987 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1989 echo "DQACQ return -ENOTCONN"
1990 #define ENOTCONN 107
1991 test_17sub 107 || error "Handle -ENOTCONN failed"
1994 run_test 17 "DQACQ return recoverable error"
1998 local blimit="200m" # 200M
1999 local TESTFILE="$DIR/$tdir/$tfile"
2001 setup_quota_test || error "setup quota failed with $?"
2002 trap cleanup_quota_test EXIT
2004 set_ost_qtype "u" || error "enable ost quota failed"
2005 log "User quota (limit: $blimit)"
2006 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
2007 error "set quota failed"
2008 quota_show_check b u $TSTUSR
2010 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2011 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2013 local timeout=$(sysctl -n lustre.timeout)
2015 if [ $io_type = "directio" ]; then
2016 log "Write 100M (directio) ..."
2017 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2019 log "Write 100M (buffered) ..."
2020 $RUNAS $DD of=$TESTFILE count=100 &
2024 replay_barrier $SINGLEMDS
2025 log "Fail mds for $((2 * timeout)) seconds"
2026 fail $SINGLEMDS $((2 * timeout))
2029 if at_is_enabled; then
2030 timeout=$(at_max_get mds)
2032 timeout=$(lctl get_param -n timeout)
2036 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2037 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2038 log "it took $count second"
2043 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2045 cancel_lru_locks mdc
2046 cancel_lru_locks osc
2049 local testfile_size=$(stat -c %s $TESTFILE)
2050 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2051 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2052 "got ${testfile_size}. Verifying file failed!"
2055 resetquota -u $TSTUSR
2058 # test when mds does failover, the ost still could work well
2059 # this test shouldn't trigger watchdog b=14840
2061 # Clear dmesg so watchdog is not triggered by previous
2063 do_facet ost1 dmesg -c > /dev/null
2066 test_18_sub directio
2068 # check if watchdog is triggered
2069 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2070 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2071 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2072 [ -z "$watchdog" ] || error "$watchdog"
2073 rm -f $TMP/lustre-log-${TESTNAME}.log
2075 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2079 local TESTFILE=$DIR/$tdir/$tfile
2081 setup_quota_test || error "setup quota failed with $?"
2082 trap cleanup_quota_test EXIT
2084 set_ost_qtype $QTYPE || error "enable ost quota failed"
2086 # bind file to a single OST
2087 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2088 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2090 echo "Set user quota (limit: ${blimit}M)"
2091 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2092 error "set user quota failed"
2093 quota_show_check b u $TSTUSR
2094 echo "Update quota limits"
2095 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2096 error "set group quota failed"
2097 quota_show_check b u $TSTUSR
2099 # first wirte might be cached
2100 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2101 cancel_lru_locks osc
2103 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2104 quota_error u $TSTUSR "Write success, expect failure"
2108 resetquota -u $TSTUSR
2110 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2112 test_20() { # b15754
2113 local LSTR=(2g 1t 4k 3m) # limits strings
2115 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2118 resetquota -u $TSTUSR
2120 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2121 $MOUNT || error "could not set quota limits"
2122 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2123 --inode-softlimit ${LSTR[2]} \
2124 --inode-hardlimit ${LSTR[3]} \
2125 $MOUNT || error "could not set quota limits"
2127 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2128 error "bsoftlimit was not set properly"
2129 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2130 error "bhardlimit was not set properly"
2131 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2132 error "isoftlimit was not set properly"
2133 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2134 error "ihardlimit was not set properly"
2136 resetquota -u $TSTUSR
2138 run_test 20 "Test if setquota specifiers work properly (b15754)"
2145 local time=$(($(date +%s) + seconds))
2146 while [ $(date +%s) -lt $time ]; do
2147 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2151 # run for fixing bug16053, setquota shouldn't fail when writing and
2152 # deleting are happening
2154 local TESTFILE="$DIR/$tdir/$tfile"
2155 local BLIMIT=10 # 10G
2156 local ILIMIT=1000000
2158 setup_quota_test || error "setup quota failed with $?"
2159 trap cleanup_quota_test EXIT
2161 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2163 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2164 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2165 error "set user quota failed"
2166 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2167 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2168 error "set group quota failed"
2169 if is_project_quota_supported; then
2170 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2171 "project: $TSTPRJID"
2172 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2173 $MOUNT || error "set project quota failed"
2176 # repeat writing on a 1M file
2177 test_21_sub ${TESTFILE}_1 1 30 &
2179 # repeat writing on a 128M file
2180 test_21_sub ${TESTFILE}_2 128 30 &
2183 local time=$(($(date +%s) + 30))
2185 while [ $(date +%s) -lt $time ]; do
2186 log "Set quota for $i times"
2187 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2188 -I $((ILIMIT + i)) $MOUNT ||
2189 error "Set user quota failed"
2190 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2191 -I $((ILIMIT + i)) $MOUNT ||
2192 error "Set group quota failed"
2193 if is_project_quota_supported; then
2194 $LFS setquota -p $TSTPRJID -b 0 -B \
2195 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2196 error "Set project quota failed"
2204 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2206 if [ $count -gt 60 ]; then
2207 quota_error a $TSTUSR "dd should be finished!"
2211 echo "(dd_pid=$DDPID1, time=$count)successful"
2215 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2217 if [ $count -gt 60 ]; then
2218 quota_error a $TSTUSR "dd should be finished!"
2222 echo "(dd_pid=$DDPID2, time=$count)successful"
2225 resetquota -u $TSTUSR
2226 resetquota -g $TSTUSR
2227 resetquota -p $TSTPRJID
2229 run_test 21 "Setquota while writing & deleting (b16053)"
2231 # enable/disable quota enforcement permanently
2233 echo "Set both mdt & ost quota type as ug"
2235 is_project_quota_supported && qtype=$QTYPE
2236 set_mdt_qtype $qtype || error "enable mdt quota failed"
2237 set_ost_qtype $qtype || error "enable ost quota failed"
2240 stopall || error "failed to stopall (1)"
2244 echo "Verify if quota is enabled"
2245 local qtype1=$(mdt_quota_type)
2246 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2247 qtype=$(ost_quota_type)
2248 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2250 echo "Set both mdt & ost quota type as none"
2251 set_mdt_qtype "none" || error "disable mdt quota failed"
2252 set_ost_qtype "none" || error "disable ost quota failed"
2255 stopall || error "failed to stopall (2)"
2260 echo "Verify if quota is disabled"
2261 qtype=$(mdt_quota_type)
2262 [ $qtype != "none" ] && error "mdt quota setting is lost"
2263 qtype=$(ost_quota_type)
2264 [ $qtype != "none" ] && error "ost quota setting is lost"
2268 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2271 local TESTFILE="$DIR/$tdir/$tfile"
2274 setup_quota_test || error "setup quota failed with $?"
2275 trap cleanup_quota_test EXIT
2277 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2280 log "User quota (limit: $LIMIT MB)"
2281 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2282 error "set quota failed"
2283 quota_show_check b u $TSTUSR
2285 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2286 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2288 log "Step1: trigger EDQUOT with O_DIRECT"
2289 log "Write half of file"
2290 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2291 quota_error u $TSTUSR "(1) Write failure, expect success." \
2293 log "Write out of block quota ..."
2294 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2295 oflag=direct conv=notrunc &&
2296 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2300 log "Step2: rewrite should succeed"
2301 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2302 quota_error u $TSTUSR "(3) Write failure, expect success." \
2308 local OST0_UUID=$(ostuuid_from_index 0)
2309 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2310 [ $OST0_QUOTA_USED -ne 0 ] &&
2311 ($SHOW_QUOTA_USER; \
2312 quota_error u $TSTUSR "quota isn't released")
2314 resetquota -u $TSTUSR
2318 [ $(facet_fstype ost1) == "zfs" ] &&
2319 skip "Overwrite in place is not guaranteed to be " \
2320 "space neutral on ZFS"
2322 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2323 check_whether_skip && return 0
2324 log "run for 4MB test file"
2327 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2328 check_whether_skip && return 0
2329 log "run for 40MB test file"
2332 run_test 23 "Quota should be honored with directIO (b16125)"
2336 local TESTFILE="$DIR/$tdir/$tfile"
2338 setup_quota_test || error "setup quota failed with $?"
2339 trap cleanup_quota_test EXIT
2341 set_ost_qtype $QTYPE || error "enable ost quota failed"
2343 # bind file to a single OST
2344 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2345 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2347 echo "Set user quota (limit: ${blimit}M)"
2348 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2349 error "set quota failed"
2351 # overrun quota by root user
2352 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2353 error "write failure, expect success"
2354 cancel_lru_locks osc
2355 sync_all_data || true
2357 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2360 resetquota -u $TSTUSR
2362 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2364 test_27a() { # b19612
2365 $LFS quota $TSTUSR $DIR &&
2366 error "lfs succeeded with no type, but should have failed"
2367 $LFS setquota $TSTUSR $DIR &&
2368 error "lfs succeeded with no type, but should have failed"
2371 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2373 test_27b() { # b20200
2374 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2375 error "lfs setquota failed with uid argument"
2376 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2377 error "lfs stequota failed with gid argument"
2378 if is_project_quota_supported; then
2379 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2380 1000 $DIR || error \
2381 "lfs stequota failed with projid argument"
2383 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2384 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2385 if is_project_quota_supported; then
2386 $SHOW_QUOTA_PROJID ||
2387 error "lfs quota failed with projid argument"
2389 resetquota -u $TSTUSR
2390 resetquota -g $TSTUSR
2391 resetquota -p $TSTPRJID
2394 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2399 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2400 error "lfs setquota failed"
2402 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2403 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2404 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2405 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2407 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2408 error "lfs setquota for $TSTID failed"
2410 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2411 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2412 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2413 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2415 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2416 error "total allocated inode/block limit not printed"
2418 resetquota -u $TSTUSR
2420 run_test 27c "lfs quota should support human-readable output"
2427 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2428 error "set fraction block limit failed"
2429 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2430 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2431 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2432 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2434 resetquota -u $TSTUSR
2436 run_test 27d "lfs setquota should support fraction block limit"
2440 local TESTFILE="$DIR/$tdir/$tfile"
2443 setup_quota_test || error "setup quota failed with $?"
2444 trap cleanup_quota_test EXIT
2446 set_ost_qtype "u" || error "enable ost quota failed"
2448 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2449 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2451 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2452 $MAX_IQ_TIME $DIR || error "set grace time failed"
2453 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2454 error "set quota failed"
2455 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2456 cancel_lru_locks osc
2458 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2459 # over-quota flag has not yet settled since we do not trigger async
2460 # events based on grace time period expiration
2462 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2463 cancel_lru_locks osc
2464 # now over-quota flag should be settled and further writes should fail
2466 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2467 error "grace times were reset"
2470 resetquota -u $TSTUSR
2471 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2472 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2474 run_test 30 "Hard limit updates should not reset grace times"
2476 # basic usage tracking for user & group
2478 local INODES=10 # 10 files
2479 local BLK_CNT=2 # of 2M each
2480 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2482 setup_quota_test || error "setup quota failed with $?"
2483 trap cleanup_quota_test EXIT
2485 # make sure the system is clean
2486 local USED=$(getquota -u $TSTID global curspace)
2488 error "Used space ($USED) for user $TSTID isn't 0."
2489 USED=$(getquota -g $TSTID global curspace)
2491 error "Used space ($USED) for group $TSTID isn't 0."
2492 if is_project_quota_supported; then
2493 USED=$(getquota -p $TSTPRJID global curspace)
2494 [ $USED -ne 0 ] && error \
2495 "Used space ($USED) for project $TSTPRJID isn't 0."
2498 echo "Write files..."
2499 for i in $(seq 0 $INODES); do
2500 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2501 error "write failed"
2502 is_project_quota_supported &&
2503 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2504 echo "Iteration $i/$INODES completed"
2506 cancel_lru_locks osc
2508 echo "Wait for setattr on objects finished..."
2509 wait_delete_completed
2511 sync; sync_all_data || true
2513 echo "Verify disk usage after write"
2514 USED=$(getquota -u $TSTID global curspace)
2515 [ $USED -lt $TOTAL_BLKS ] &&
2516 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2517 USED=$(getquota -g $TSTID global curspace)
2518 [ $USED -lt $TOTAL_BLKS ] &&
2519 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2520 if is_project_quota_supported; then
2521 USED=$(getquota -p $TSTPRJID global curspace)
2522 [ $USED -lt $TOTAL_BLKS ] && error \
2523 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2526 echo "Verify inode usage after write"
2527 USED=$(getquota -u $TSTID global curinodes)
2528 [ $USED -lt $INODES ] &&
2529 error "Used inode for user $TSTID is $USED, expected $INODES"
2530 USED=$(getquota -g $TSTID global curinodes)
2531 [ $USED -lt $INODES ] &&
2532 error "Used inode for group $TSTID is $USED, expected $INODES"
2533 if is_project_quota_supported; then
2534 USED=$(getquota -p $TSTPRJID global curinodes)
2535 [ $USED -lt $INODES ] && error \
2536 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2541 echo "Verify disk usage after delete"
2542 USED=$(getquota -u $TSTID global curspace)
2543 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2544 USED=$(getquota -u $TSTID global curinodes)
2545 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2546 USED=$(getquota -g $TSTID global curspace)
2547 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2548 USED=$(getquota -g $TSTID global curinodes)
2549 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2550 if is_project_quota_supported; then
2551 USED=$(getquota -p $TSTPRJID global curspace)
2553 error "Used space for project $TSTPRJID isn't 0. $USED"
2554 USED=$(getquota -p $TSTPRJID global curinodes)
2556 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2559 run_test 33 "Basic usage tracking for user & group & project"
2561 # usage transfer test for user & group & project
2563 local BLK_CNT=2 # 2MB
2564 local project_supported="no"
2566 is_project_quota_supported && project_supported="yes"
2567 setup_quota_test || error "setup quota failed with $?"
2568 trap cleanup_quota_test EXIT
2570 # make sure the system is clean
2571 local USED=$(getquota -u $TSTID global curspace)
2572 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2573 USED=$(getquota -g $TSTID global curspace)
2574 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2576 local USED=$(getquota -u $TSTID2 global curspace)
2577 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2578 if [ $project_supported == "yes" ]; then
2579 USED=$(getquota -p $TSTPRJID global curspace)
2580 [ $USED -ne 0 ] && error \
2581 "Used space ($USED) for Project $TSTPRJID isn't 0."
2584 echo "Write file..."
2585 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2586 error "write failed"
2587 cancel_lru_locks osc
2588 sync; sync_all_data || true
2590 echo "chown the file to user $TSTID"
2591 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2593 echo "Wait for setattr on objects finished..."
2594 wait_delete_completed
2596 BLK_CNT=$((BLK_CNT * 1024))
2598 echo "Verify disk usage for user $TSTID"
2599 USED=$(getquota -u $TSTID global curspace)
2600 [ $USED -lt $BLK_CNT ] &&
2601 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2602 USED=$(getquota -u $TSTID global curinodes)
2604 error "Used inodes for user $TSTID is $USED, expected 1"
2606 echo "chgrp the file to group $TSTID"
2607 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2609 echo "Wait for setattr on objects finished..."
2610 wait_delete_completed
2612 echo "Verify disk usage for group $TSTID"
2613 USED=$(getquota -g $TSTID global curspace)
2614 [ $USED -ge $BLK_CNT ] ||
2615 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2616 USED=$(getquota -g $TSTID global curinodes)
2618 error "Used inodes for group $TSTID is $USED, expected 1"
2620 # chown won't change the ost object group. LU-4345 */
2621 echo "chown the file to user $TSTID2"
2622 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2624 echo "Wait for setattr on objects finished..."
2625 wait_delete_completed
2627 echo "change_project project id to $TSTPRJID"
2628 [ $project_supported == "yes" ] &&
2629 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2630 echo "Wait for setattr on objects finished..."
2631 wait_delete_completed
2633 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2634 USED=$(getquota -u $TSTID2 global curspace)
2635 [ $USED -lt $BLK_CNT ] &&
2636 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2637 USED=$(getquota -u $TSTID global curspace)
2639 error "Used space for user $TSTID is $USED, expected 0"
2640 USED=$(getquota -g $TSTID global curspace)
2641 [ $USED -lt $BLK_CNT ] &&
2642 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2643 if [ $project_supported == "yes" ]; then
2644 USED=$(getquota -p $TSTPRJID global curspace)
2645 [ $USED -lt $BLK_CNT ] && error \
2646 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2651 run_test 34 "Usage transfer for user & group & project"
2653 # usage is still accessible across restart
2655 local BLK_CNT=2 # 2 MB
2657 setup_quota_test || error "setup quota failed with $?"
2658 trap cleanup_quota_test EXIT
2660 echo "Write file..."
2661 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2662 error "write failed"
2663 is_project_quota_supported &&
2664 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2665 cancel_lru_locks osc
2667 echo "Wait for setattr on objects finished..."
2668 wait_delete_completed
2670 sync; sync_all_data || true
2672 echo "Save disk usage before restart"
2673 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2674 [ $ORIG_USR_SPACE -eq 0 ] &&
2675 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2676 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2677 [ $ORIG_USR_INODES -eq 0 ] &&
2678 error "Used inodes for user $TSTID is 0, expected 1"
2679 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2680 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2681 [ $ORIG_GRP_SPACE -eq 0 ] &&
2682 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2683 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2684 [ $ORIG_GRP_INODES -eq 0 ] &&
2685 error "Used inodes for group $TSTID is 0, expected 1"
2686 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2688 if is_project_quota_supported; then
2689 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2690 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2691 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2692 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2693 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2694 "Used inodes for project $TSTPRJID is 0, expected 1"
2695 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2703 echo "Verify disk usage after restart"
2704 local USED=$(getquota -u $TSTID global curspace)
2705 [ $USED -eq $ORIG_USR_SPACE ] ||
2706 error "Used space for user $TSTID changed from " \
2707 "$ORIG_USR_SPACE to $USED"
2708 USED=$(getquota -u $TSTID global curinodes)
2709 [ $USED -eq $ORIG_USR_INODES ] ||
2710 error "Used inodes for user $TSTID changed from " \
2711 "$ORIG_USR_INODES to $USED"
2712 USED=$(getquota -g $TSTID global curspace)
2713 [ $USED -eq $ORIG_GRP_SPACE ] ||
2714 error "Used space for group $TSTID changed from " \
2715 "$ORIG_GRP_SPACE to $USED"
2716 USED=$(getquota -g $TSTID global curinodes)
2717 [ $USED -eq $ORIG_GRP_INODES ] ||
2718 error "Used inodes for group $TSTID changed from " \
2719 "$ORIG_GRP_INODES to $USED"
2720 if [ $project_supported == "yes" ]; then
2721 USED=$(getquota -p $TSTPRJID global curinodes)
2722 [ $USED -eq $ORIG_PRJ_INODES ] ||
2723 error "Used inodes for project $TSTPRJID " \
2724 "changed from $ORIG_PRJ_INODES to $USED"
2725 USED=$(getquota -p $TSTPRJID global curspace)
2726 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2727 error "Used space for project $TSTPRJID "\
2728 "changed from $ORIG_PRJ_SPACE to $USED"
2731 # check if the vfs_dq_init() is called before writing
2732 echo "Append to the same file..."
2733 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2734 error "write failed"
2735 cancel_lru_locks osc
2736 sync; sync_all_data || true
2738 echo "Verify space usage is increased"
2739 USED=$(getquota -u $TSTID global curspace)
2740 [ $USED -gt $ORIG_USR_SPACE ] ||
2741 error "Used space for user $TSTID isn't increased" \
2742 "orig:$ORIG_USR_SPACE, now:$USED"
2743 USED=$(getquota -g $TSTID global curspace)
2744 [ $USED -gt $ORIG_GRP_SPACE ] ||
2745 error "Used space for group $TSTID isn't increased" \
2746 "orig:$ORIG_GRP_SPACE, now:$USED"
2747 if [ $project_supported == "yes" ]; then
2748 USED=$(getquota -p $TSTPRJID global curspace)
2749 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2750 error "Used space for project $TSTPRJID isn't " \
2751 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2756 run_test 35 "Usage is still accessible across reboot"
2758 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2761 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2762 skip "Old server doesn't have LU-5006 fix."
2764 setup_quota_test || error "setup quota failed with $?"
2765 trap cleanup_quota_test EXIT
2767 # make sure the system is clean
2768 local USED=$(getquota -u $TSTID global curspace)
2770 error "Used space ($USED) for user $TSTID isn't 0."
2772 # create file with MDS_OPEN_DELAY_CREATE flag
2773 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2774 error "Create file failed"
2776 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2777 oflag=sync || error "Write file failed"
2779 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2781 # wait for setattr on objects finished..."
2782 wait_delete_completed
2784 USED=$(getquota -u $TSTID global curspace)
2785 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2789 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2793 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2794 skip "Old server doesn't have LU-8801 fix."
2796 [ "$UID" != 0 ] && skip_env "must run as root" && return
2798 setup_quota_test || error "setup quota failed with $?"
2799 trap cleanup_quota_test EXIT
2801 # make sure the system is clean
2802 local USED=$(getquota -u $TSTID global curspace)
2804 error "Used space ($USED) for user $TSTID isn't 0."
2805 USED=$(getquota -u $TSTID2 global curspace)
2807 error "Used space ($USED) for user $TSTID2 isn't 0."
2809 local TESTFILE="$DIR/$tdir/$tfile"
2810 local file_cnt=10000
2812 # Generate id entries in accounting file
2813 echo "Create $file_cnt files..."
2814 for i in `seq $file_cnt`; do
2816 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2817 error "failed to chown $TESTFILE-$i"
2819 cancel_lru_locks osc
2820 sync; sync_all_data || true
2822 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2823 procf=${procf}.quota_slave.acct_user
2826 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2827 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2828 echo "Found $acct_cnt id entries"
2830 [ $file_cnt -eq $acct_cnt ] || {
2831 do_facet mds1 $LCTL get_param $procf
2832 error "skipped id entries"
2837 run_test 38 "Quota accounting iterator doesn't skip id entries"
2840 local TESTFILE="$DIR/$tdir/project"
2841 ! is_project_quota_supported &&
2842 skip "Project quota is not supported"
2844 setup_quota_test || error "setup quota failed with $?"
2847 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2848 [ $projectid -ne 0 ] &&
2849 error "Project id should be 0 not $projectid"
2850 change_project -p 1024 $TESTFILE
2851 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2852 [ $projectid -ne 1024 ] &&
2853 error "Project id should be 1024 not $projectid"
2855 stopall || error "failed to stopall (1)"
2858 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2859 [ $projectid -ne 1024 ] &&
2860 error "Project id should be 1024 not $projectid"
2864 run_test 39 "Project ID interface works correctly"
2867 ! is_project_quota_supported &&
2868 skip "Project quota is not supported"
2869 local dir1="$DIR/$tdir/dir1"
2870 local dir2="$DIR/$tdir/dir2"
2872 setup_quota_test || error "setup quota failed with $?"
2874 mkdir -p $dir1 $dir2
2875 change_project -sp 1 $dir1 && touch $dir1/1
2876 change_project -sp 2 $dir2
2878 ln $dir1/1 $dir2/1_link &&
2879 error "Hard link across different project quota should fail"
2884 run_test 40a "Hard link across different project ID"
2887 ! is_project_quota_supported &&
2888 skip "Project quota is not supported"
2889 local dir1="$DIR/$tdir/dir1"
2890 local dir2="$DIR/$tdir/dir2"
2892 setup_quota_test || error "setup quota failed with $?"
2893 mkdir -p $dir1 $dir2
2894 change_project -sp 1 $dir1 && touch $dir1/1
2895 change_project -sp 2 $dir2
2897 mv $dir1/1 $dir2/2 || error "mv failed $?"
2898 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2899 if [ "$projid" != "2" ]; then
2900 error "project id expected 2 not $projid"
2905 run_test 40b "Mv across different project ID"
2908 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2909 ! is_project_quota_supported &&
2910 skip "Project quota is not supported"
2912 setup_quota_test || error "setup quota failed with $?"
2913 local dir="$DIR/$tdir/dir"
2915 mkdir -p $dir && change_project -sp 1 $dir
2916 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2917 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2918 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2919 touch $dir/remote_dir/file
2920 #verify inherit works file for remote dir.
2921 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2922 [ "$projid" != "1" ] &&
2923 error "file under remote dir expected 1 not $projid"
2925 #Agent inode should be ignored for project quota
2926 USED=$(getquota -p 1 global curinodes)
2927 [ "$USED" != "3" ] &&
2928 error "file count expected 3 got $USED"
2934 run_test 40c "Remote child Dir inherit project quota properly"
2937 ! is_project_quota_supported &&
2938 skip "Project quota is not supported"
2940 setup_quota_test || error "setup quota failed with $?"
2941 local dir1="$DIR/$tdir/dir1"
2942 local dir2="$DIR/$tdir/dir2"
2944 mkdir -p $dir1 && change_project -sp 1 $dir1
2945 mkdir -p $dir2 && change_project -sp 2 $dir2
2946 for num in $(seq 1 10); do
2947 touch $dir1/file_$num $dir2/file_$num
2948 ln -s $dir1/file_$num $dir1/file_$num"_link"
2949 ln -s $dir2/file_$num $dir2/file_$num"_link"
2952 count=$($LFS find --projid 1 $DIR | wc -l)
2953 [ "$count" != 21 ] && error "expected 21 but got $count"
2955 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2956 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2957 [ "$count" != 22 ] && error "expected 22 but got $count"
2962 run_test 50 "Test if lfs find --projid works"
2965 ! is_project_quota_supported &&
2966 skip "Project quota is not supported"
2967 setup_quota_test || error "setup quota failed with $?"
2968 local dir="$DIR/$tdir/dir"
2970 mkdir $dir && change_project -sp 1 $dir
2971 local used=$(getquota -p 1 global curinodes)
2972 [ $used != "1" ] && error "expected 1 got $used"
2977 used=$(getquota -p 1 global curinodes)
2978 [ $used != "4" ] && error "expected 4 got $used"
2980 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2982 cp $DIR/$tdir/6 $dir/6
2983 used=$(getquota -p 1 global curinodes)
2984 [ $used != "5" ] && error "expected 5 got $used"
2987 mv $DIR/$tdir/6 $dir/7
2988 used=$(getquota -p 1 global curinodes)
2989 [ $used != "6" ] && error "expected 6 got $used"
2994 run_test 51 "Test project accounting with mv/cp"
2997 ! is_project_quota_supported &&
2998 skip "Project quota is not supported"
2999 setup_quota_test || error "setup quota failed with $?"
3000 local dir="$DIR/$tdir/dir"
3001 mkdir $dir && change_project -sp 1 $dir
3003 touch $DIR/$tdir/file
3004 #Try renaming a file into the project. This should fail.
3005 for num in $(seq 1 2000); do
3006 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
3007 error "rename should fail"
3012 run_test 52 "Rename across different project ID"
3015 ! is_project_quota_supported &&
3016 skip "Project quota is not supported"
3017 setup_quota_test || error "setup quota failed with $?"
3018 local dir="$DIR/$tdir/dir"
3019 mkdir $dir && change_project -s $dir
3020 lfs project -d $dir | grep P || error "inherit attribute should be set"
3022 change_project -C $dir
3023 lfs project -d $dir | grep P &&
3024 error "inherit attribute should be cleared"
3029 run_test 53 "Project inherit attribute could be cleared"
3032 ! is_project_quota_supported &&
3033 skip "Project quota is not supported"
3034 setup_quota_test || error "setup quota failed with $?"
3035 trap cleanup_quota_test EXIT
3036 local testfile="$DIR/$tdir/$tfile-0"
3038 #set project ID/inherit attribute
3039 change_project -sp $TSTPRJID $DIR/$tdir
3040 $RUNAS createmany -m ${testfile} 100 ||
3041 error "create many files failed"
3043 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3044 # one more count for directory itself */
3048 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3049 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3051 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3052 [ $proj_count1 -eq $proj_count ] ||
3053 error "c2: expected $proj_count got $proj_count1"
3055 #clear project but with kept projid
3056 change_project -rCk $DIR/$tdir
3057 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3058 [ $proj_count1 -eq 1 ] ||
3059 error "c3: expected 1 got $proj_count1"
3061 #verify projid untouched.
3062 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3064 [ $proj_count1 -eq $proj_count ] ||
3065 error "c4: expected $proj_count got $proj_count1"
3068 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3069 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3070 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3072 #this time clear all
3073 change_project -rC $DIR/$tdir
3074 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3075 [ $proj_count1 -eq 0 ] ||
3076 error "c6: expected 0 got $proj_count1"
3078 unlinkmany ${testfile} 100 ||
3079 error "unlink many files failed"
3083 run_test 54 "basic lfs project interface test"
3086 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3087 skip "Not supported before 2.10.58."
3088 setup_quota_test || error "setup quota failed with $?"
3090 set_ost_qtype $QTYPE || error "enable ost quota failed"
3093 #add second group to TSTUSR
3094 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3097 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3098 error "failed to dd"
3100 cancel_lru_locks osc
3101 sync; sync_all_data || true
3103 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3104 error "failed to setquota on group $TSTUSR2"
3106 $LFS quota -v -g $TSTUSR2 $DIR
3108 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3109 error "chgrp should failed with -EDQUOT"
3111 USED=$(getquota -g $TSTUSR2 global curspace)
3114 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3115 error "failed to setquota on group $TSTUSR2"
3117 $LFS quota -v -g $TSTUSR2 $DIR
3119 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3120 error "chgrp should succeed"
3122 $LFS quota -v -g $TSTUSR2 $DIR
3124 resetquota -g $TSTUSR2
3127 run_test 55 "Chgrp should be affected by group quota"
3130 setup_quota_test || error "setup quota failed with $?"
3132 set_ost_qtype $QTYPE || error "enable ost quota failed"
3135 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3136 erro "failed to set grace time for usr quota"
3137 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3138 awk '{print $4 $8}')
3139 if [ "x$grace_time" != "x10s;10s" ]; then
3140 $LFS quota -t -u $DIR
3141 error "expected grace time: 10s;10s, got:$grace_time"
3146 run_test 56 "lfs quota -t should work well"
3149 setup_quota_test || error "setup quota failed with $?"
3151 local dir="$DIR/$tdir/dir"
3154 #try to change pipe file should not hang and return failure
3155 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3156 awk -F ':' '{ print \\\$2 }'" \
3157 " unable to get xattr for fifo '$dir/pipe'" || return 1
3158 #command can process further if it hit some errors
3159 touch $dir/aaa $dir/bbb
3160 mkdir $dir/subdir -p
3161 touch $dir/subdir/aaa $dir/subdir/bbb
3162 #create one invalid link file
3163 ln -s $dir/not_exist_file $dir/ccc
3164 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3165 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3169 run_test 57 "lfs project could tolerate errors"
3172 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3173 skip "ldiskfs only test"
3174 disable_project_quota
3175 setup_quota_test || error "setup quota failed with $?"
3178 local testfile="$DIR/$tdir/$tfile-0"
3179 #make sure it did not crash kernel
3180 touch $testfile && lfs project -sp 1 $testfile
3182 enable_project_quota
3185 run_test 59 "lfs project dosen't crash kernel with project disabled"
3188 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3189 skip "Needs MDS version 2.11.53 or later."
3190 setup_quota_test || error "setup quota failed with $?"
3191 trap cleanup_quota_test EXIT
3193 local testfile=$DIR/$tdir/$tfile
3196 set_mdt_qtype "ug" || error "enable mdt quota failed"
3198 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3199 error "set quota failed"
3200 quota_show_check a g $TSTUSR
3202 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3203 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3204 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3205 error "create many files failed"
3207 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3209 # root user can overrun quota
3210 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3211 error "root user should succeed"
3214 resetquota -g $TSTUSR
3216 run_test 60 "Test quota for root with setgid"
3218 # test default quota
3219 test_default_quota() {
3220 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3221 skip "Not supported before 2.11.51."
3226 local qprjid=$TSTPRJID
3230 local LIMIT=20480 #20M disk space
3231 local TESTFILE="$DIR/$tdir/$tfile-0"
3233 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3234 echo "Project quota is not supported" && return 0
3236 [ $qtype == "-u" ] && qdtype="-U"
3237 [ $qtype == "-g" ] && qdtype="-G"
3238 [ $qtype == "-p" ] && {
3243 [ $qpool == "meta" ] && {
3244 LIMIT=10240 #10K inodes
3249 setup_quota_test || error "setup quota failed with $?"
3250 trap cleanup_quota_test EXIT
3254 # enable mdt/ost quota
3255 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3256 set_ost_qtype $QTYPE || error "enable ost quota failed"
3258 log "set to use default quota"
3259 $LFS setquota $qtype $qid -d $DIR ||
3260 error "set $qid to use default quota failed"
3262 log "set default quota"
3263 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3264 error "set $qid default quota failed"
3266 log "get default quota"
3267 $LFS quota $qdtype $DIR || error "get default quota failed"
3269 if [ $qpool == "data" ]; then
3270 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3272 [ $SLIMIT -eq $LIMIT ] ||
3273 error "the returned default quota is wrong"
3275 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3277 [ $SLIMIT -eq $LIMIT ] ||
3278 error "the returned default quota is wrong"
3281 # make sure the system is clean
3282 local USED=$(getquota $qtype $qid global curspace)
3283 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3285 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3286 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3288 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3290 log "Test not out of quota"
3291 if [ $qpool == "data" ]; then
3292 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3293 quota_error $qtype $qid "write failed, expect succeed"
3295 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3296 quota_error $qtype $qid "create failed, expect succeed"
3298 unlinkmany $TESTFILE $((LIMIT/2))
3301 log "Test out of quota"
3302 # flush cache, ensure noquota flag is set on client
3303 cancel_lru_locks osc
3304 cancel_lru_locks mdc
3305 sync; sync_all_data || true
3306 if [ $qpool == "data" ]; then
3307 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3308 quota_error $qtype $qid "write succeed, expect EDQUOT"
3310 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3311 quota_error $qtype $qid "create succeed, expect EDQUOT"
3313 unlinkmany $TESTFILE $((LIMIT*2))
3316 log "Increase default quota"
3317 # increase default quota
3318 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3319 error "set default quota failed"
3321 cancel_lru_locks osc
3322 cancel_lru_locks mdc
3323 sync; sync_all_data || true
3324 if [ $qpool == "data" ]; then
3325 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3326 quota_error $qtype $qid "write failed, expect succeed"
3328 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3329 quota_error $qtype $qid "create failed, expect succeed"
3331 unlinkmany $TESTFILE $((LIMIT*2))
3334 log "Set quota to override default quota"
3335 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3336 error "set $qid quota failed"
3338 cancel_lru_locks osc
3339 cancel_lru_locks mdc
3340 sync; sync_all_data || true
3341 if [ $qpool == "data" ]; then
3342 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3343 quota_error $qtype $qid "write succeed, expect EQUOT"
3345 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3346 quota_error $qtype $qid "create succeed, expect EQUOT"
3348 unlinkmany $TESTFILE $((LIMIT*2))
3351 log "Set to use default quota again"
3352 $LFS setquota $qtype $qid -d $DIR ||
3353 error "set $qid to use default quota failed"
3355 cancel_lru_locks osc
3356 cancel_lru_locks mdc
3357 sync; sync_all_data || true
3358 if [ $qpool == "data" ]; then
3359 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3360 quota_error $qtype $qid "write failed, expect succeed"
3362 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3363 quota_error $qtype $qid "create failed, expect succeed"
3365 unlinkmany $TESTFILE $((LIMIT*2))
3370 wait_delete_completed || error "wait_delete_completed failed"
3371 sync_all_data || true
3372 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3373 error "reset default quota failed"
3374 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3375 error "reset quota failed"
3381 test_default_quota "-u" "data"
3382 test_default_quota "-u" "meta"
3383 test_default_quota "-g" "data"
3384 test_default_quota "-g" "meta"
3385 test_default_quota "-p" "data"
3386 test_default_quota "-p" "meta"
3388 run_test 61 "default quota tests"
3391 ! is_project_quota_supported &&
3392 skip "Project quota is not supported"
3393 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3394 skip "chattr did not support project quota"
3395 setup_quota_test || error "setup quota failed with $?"
3396 local testdir=$DIR/$tdir/
3398 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3399 change_project -s $testdir
3400 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3401 error "inherit attribute should be set"
3402 # chattr used FS_IOC_SETFLAGS ioctl
3403 $RUNAS chattr -P $testdir &&
3404 error "regular user clear inherit should fail"
3405 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3406 error "inherit attribute should still be set"
3407 chattr -P $testdir || error "root failed to clear inherit"
3408 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3409 error "inherit attribute should be cleared"
3412 run_test 62 "Project inherit should be only changed by root"
3415 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3416 skip "Not supported before 2.11.55" && return
3420 local dd_failed=false
3421 local tdir_dom=${tdir}_dom
3422 local LIMIT=20480 #20M
3424 [ $qtype == "p" ] && ! is_project_quota_supported &&
3425 echo "Project quota is not supported" && return 0
3427 [ $qtype == "p" ] && qid=$TSTPRJID
3429 setup_quota_test || error "setup quota failed with $?"
3430 trap cleanup_quota_test EXIT
3434 # enable mdt/ost quota
3435 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3436 set_ost_qtype $QTYPE || error "enable ost quota failed"
3438 # make sure the system is clean
3439 local USED=$(getquota -$qtype $qid global curspace)
3440 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3442 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3444 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3445 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3446 error "setstripe $tdir_dom failed"
3447 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3449 [ $qtype == "p" ] && {
3450 change_project -sp $TSTPRJID $DIR/$tdir
3451 change_project -sp $TSTPRJID $DIR/$tdir_dom
3454 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3455 error "set $qid quota failed"
3457 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3458 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3462 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3464 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3465 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3469 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3471 rm -f $DIR/$tdir_dom/*
3473 # flush cache, ensure noquota flag is set on client
3474 cancel_lru_locks osc
3475 cancel_lru_locks mdc
3476 sync; sync_all_data || true
3480 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3481 quota_error $qtype $qid "write failed, expect succeed"
3483 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3484 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3488 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3491 rm -f $DIR/$tdir_dom/*
3493 # flush cache, ensure noquota flag is set on client
3494 cancel_lru_locks osc
3495 cancel_lru_locks mdc
3496 sync; sync_all_data || true
3500 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3501 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3505 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3507 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3508 quota_error $qtype $qid "write succeed, expect EDQUOT"
3511 rm -fr $DIR/$tdir_dom
3513 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3514 error "reset usr quota failed"
3524 run_test 63 "quota on DoM tests"
3527 ! is_project_quota_supported &&
3528 skip "Project quota is not supported"
3529 setup_quota_test || error "setup quota failed with $?"
3530 local dir1="$DIR/$tdir/"
3533 ln -s $dir1/file $dir1/file_link
3535 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3536 error "set symlink file's project should fail"
3538 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3539 error "get symlink file's project should fail"
3543 run_test 64 "lfs project on symlink files should fail"
3546 ! is_project_quota_supported &&
3547 skip "Project quota is not supported"
3548 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
3549 skip "Not supported before 2.12.4"
3550 setup_quota_test || error "setup quota failed with $?"
3551 stack_trap cleanup_quota_test EXIT
3552 local old=$(do_facet mds1 $LCTL get_param -n \
3553 mdt.*.enable_chprojid_gid | head -1)
3554 local testdir=$DIR/$tdir/foo
3556 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3557 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3560 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3561 chown -R $TSTID:$TSTID $testdir
3562 change_project -sp $TSTPRJID $testdir
3563 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3565 $RUNAS lfs project -p 0 $testdir/foo &&
3566 error "nonroot user should fail to set projid"
3568 $RUNAS lfs project -C $testdir/foo &&
3569 error "nonroot user should fail to clear projid"
3571 change_project -C $testdir/foo || error "failed to clear project"
3573 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3574 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3575 "failed to set projid with normal user when enable_chprojid_gid=-1"
3577 $RUNAS lfs project -rC $testdir/ || error \
3578 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3580 touch $testdir/bar || error "failed touch $testdir/bar"
3581 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3582 "normal user should not be able to set projid on root owned file"
3584 change_project -p $TSTPRJID $testdir/bar || error \
3585 "root should be able to change its own file's projid"
3589 run_test 66 "nonroot user can not change project state in default"
3593 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3594 disable_project_quota
3596 reset_quota_settings
3601 check_and_cleanup_lustre
3602 export QUOTA_AUTO=$QUOTA_AUTO_OLD