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 LIMIT=$((1024 * 1024)) # 1M inodes
670 local TESTFILE="$DIR/$tdir/$tfile-0"
672 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
674 local FREE_INODES=$(mdt_free_inodes 0)
675 echo "$FREE_INODES free inodes on master MDT"
676 [ $FREE_INODES -lt $LIMIT ] &&
677 skip "not enough free inodes $FREE_INODES required $LIMIT"
679 setup_quota_test || error "setup quota failed with $?"
680 trap cleanup_quota_test EXIT
683 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
686 log "User quota (inode hardlimit:$LIMIT files)"
687 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
688 error "set user quota failed"
690 # make sure the system is clean
691 local USED=$(getquota -u $TSTUSR global curinodes)
692 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
694 log "Create $LIMIT files ..."
695 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
696 quota_error u $TSTUSR "user create failure, but expect success"
697 log "Create out of file quota ..."
698 $RUNAS touch ${TESTFILE}_xxx &&
699 quota_error u $TSTUSR "user create success, but expect EDQUOT"
702 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
703 rm -f ${TESTFILE}_xxx
704 wait_delete_completed
706 USED=$(getquota -u $TSTUSR global curinodes)
707 [ $USED -ne 0 ] && quota_error u $TSTUSR \
708 "user quota isn't released after deletion"
709 resetquota -u $TSTUSR
712 log "--------------------------------------"
713 log "Group quota (inode hardlimit:$LIMIT files)"
714 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
715 error "set group quota failed"
717 TESTFILE=$DIR/$tdir/$tfile-1
718 # make sure the system is clean
719 USED=$(getquota -g $TSTUSR global curinodes)
720 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
722 log "Create $LIMIT files ..."
723 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
724 quota_error g $TSTUSR "group create failure, but expect success"
725 log "Create out of file quota ..."
726 $RUNAS touch ${TESTFILE}_xxx &&
727 quota_error g $TSTUSR "group create success, but expect EDQUOT"
730 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
731 rm -f ${TESTFILE}_xxx
732 wait_delete_completed
734 USED=$(getquota -g $TSTUSR global curinodes)
735 [ $USED -ne 0 ] && quota_error g $TSTUSR \
736 "user quota isn't released after deletion"
738 resetquota -g $TSTUSR
739 ! is_project_quota_supported && cleanup_quota_test &&
740 echo "Skip project quota is not supported" && return 0
743 log "--------------------------------------"
744 log "Project quota (inode hardlimit:$LIMIT files)"
745 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
746 error "set project quota failed"
748 TESTFILE=$DIR/$tdir/$tfile-1
749 # make sure the system is clean
750 USED=$(getquota -p $TSTPRJID global curinodes)
752 error "Used inodes($USED) for project $TSTPRJID isn't 0"
754 change_project -sp $TSTPRJID $DIR/$tdir
755 log "Create $LIMIT files ..."
756 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
757 $TSTPRJID "project create fail, but expect success"
758 log "Create out of file quota ..."
759 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
760 "project create success, but expect EDQUOT"
761 change_project -C $DIR/$tdir
764 USED=$(getquota -p $TSTPRJID global curinodes)
765 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
766 "project quota isn't released after deletion"
768 resetquota -p $TSTPRJID
771 run_test 2 "File hard limit (normal use and out of quota)"
781 trap cleanup_quota_test EXIT
783 $SETSTRIPE $TESTFILE -c 1 -i 0
784 chown $TSTUSR.$TSTUSR $TESTFILE
785 [ "$qtype" == "p" ] && is_project_quota_supported &&
786 change_project -p $TSTPRJID $TESTFILE
788 echo "Write up to soft limit"
789 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
790 quota_error a $TSTUSR "write failure, but expect success"
791 OFFSET=$((LIMIT * 1024))
794 echo "Write to exceed soft limit"
795 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
796 quota_error a $TSTUSR "write failure, but expect success"
797 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
800 echo "mmap write when over soft limit"
801 $RUNAS $MULTIOP $TESTFILE.mmap OT40960SMW ||
802 quota_error a $TSTUSR "mmap write failure, but expect success"
808 $SHOW_QUOTA_INFO_USER
809 $SHOW_QUOTA_INFO_GROUP
810 $SHOW_QUOTA_INFO_PROJID
812 echo "Write before timer goes off"
813 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
814 quota_error a $TSTUSR "write failure, but expect success"
815 OFFSET=$((OFFSET + 1024))
818 wait_grace_time $qtype "block"
823 $SHOW_QUOTA_INFO_USER
824 $SHOW_QUOTA_INFO_GROUP
825 $SHOW_QUOTA_INFO_PROJID
827 echo "Write after timer goes off"
828 # maybe cache write, ignore.
829 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
830 OFFSET=$((OFFSET + 1024))
832 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
833 quota_error a $TSTUSR "write success, but expect EDQUOT"
838 $SHOW_QUOTA_INFO_USER
839 $SHOW_QUOTA_INFO_GROUP
840 $SHOW_QUOTA_INFO_PROJID
842 echo "Unlink file to stop timer"
844 wait_delete_completed
845 sync_all_data || true
850 $SHOW_QUOTA_INFO_USER
851 $SHOW_QUOTA_INFO_GROUP
852 $SHOW_QUOTA_INFO_PROJID
854 $SETSTRIPE $TESTFILE -c 1 -i 0
855 chown $TSTUSR.$TSTUSR $TESTFILE
856 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
859 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
860 quota_error a $TSTUSR "write failure, but expect success"
868 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
871 local TESTFILE=$DIR/$tdir/$tfile-0
873 # get minimum soft qunit size
874 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
875 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
877 set_ost_qtype $QTYPE || error "enable ost quota failed"
879 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
880 # make sure the system is clean
881 local USED=$(getquota -u $TSTUSR global curspace)
882 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
884 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
885 $MAX_IQ_TIME $DIR || error "set user grace time failed"
886 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
887 error "set user quota failed"
889 test_block_soft $TESTFILE $GRACE $LIMIT "u"
890 resetquota -u $TSTUSR
892 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
893 TESTFILE=$DIR/$tdir/$tfile-1
894 # make sure the system is clean
895 USED=$(getquota -g $TSTUSR global curspace)
896 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
898 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
899 $MAX_IQ_TIME $DIR || error "set group grace time failed"
900 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
901 error "set group quota failed"
903 test_block_soft $TESTFILE $GRACE $LIMIT "g"
904 resetquota -g $TSTUSR
906 if is_project_quota_supported; then
907 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
908 TESTFILE=$DIR/$tdir/$tfile-2
909 # make sure the system is clean
910 USED=$(getquota -p $TSTPRJID global curspace)
911 [ $USED -ne 0 ] && error \
912 "Used space($USED) for project $TSTPRJID isn't 0."
914 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
916 error "set project grace time failed"
917 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
918 $DIR || error "set project quota failed"
920 test_block_soft $TESTFILE $GRACE $LIMIT "p"
921 resetquota -p $TSTPRJID
922 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
924 error "restore project grace time failed"
928 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
929 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
930 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
931 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
933 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
942 trap cleanup_quota_test EXIT
943 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
945 echo "Create files to exceed soft limit"
946 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
947 quota_error a $TSTUSR "create failure, but expect success"
948 local trigger_time=$(date +%s)
950 sync_all_data || true
952 local cur_time=$(date +%s)
953 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
954 error "Passed grace time $grace, $trigger_time, $cur_time"
956 echo "Create file before timer goes off"
957 $RUNAS touch ${TESTFILE}_before ||
958 quota_error a $TSTUSR "failed create before timer expired," \
959 "but expect success. $trigger_time, $cur_time"
960 sync_all_data || true
962 wait_grace_time $qtype "file"
967 $SHOW_QUOTA_INFO_USER
968 $SHOW_QUOTA_INFO_GROUP
969 $SHOW_QUOTA_INFO_PROJID
971 echo "Create file after timer goes off"
972 # There is a window that space is accounted in the quota usage but
973 # hasn't been decreased from the pending write, if we acquire quota
974 # in this window, we'll acquire more than we needed.
975 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
976 sync_all_data || true
977 $RUNAS touch ${TESTFILE}_after_3 &&
978 quota_error a $TSTUSR "create after timer expired," \
980 sync_all_data || true
985 $SHOW_QUOTA_INFO_USER
986 $SHOW_QUOTA_INFO_GROUP
987 $SHOW_QUOTA_INFO_PROJID
989 echo "Unlink files to stop timer"
990 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
991 wait_delete_completed
994 $RUNAS touch ${TESTFILE}_xxx ||
995 quota_error a $TSTUSR "touch after timer stop failure," \
997 sync_all_data || true
1005 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1006 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1007 local TESTFILE=$DIR/$tdir/$tfile-0
1010 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1012 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1013 # make sure the system is clean
1014 local USED=$(getquota -u $TSTUSR global curinodes)
1015 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1017 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1018 $GRACE $DIR || error "set user grace time failed"
1019 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1020 error "set user quota failed"
1022 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1023 resetquota -u $TSTUSR
1025 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1026 # make sure the system is clean
1027 USED=$(getquota -g $TSTUSR global curinodes)
1028 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1030 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1031 $GRACE $DIR || error "set group grace time failed"
1032 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1033 error "set group quota failed"
1034 TESTFILE=$DIR/$tdir/$tfile-1
1036 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1037 resetquota -g $TSTUSR
1039 if is_project_quota_supported; then
1040 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1041 # make sure the system is clean
1042 USED=$(getquota -p $TSTPRJID global curinodes)
1043 [ $USED -ne 0 ] && error \
1044 "Used space($USED) for project $TSTPRJID isn't 0."
1046 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1047 $GRACE $DIR || error "set project grace time failed"
1048 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1049 error "set project quota failed"
1051 TESTFILE=$DIR/$tdir/$tfile-1
1052 # one less than limit, because of parent directory included.
1053 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1054 resetquota -p $TSTPRJID
1055 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1056 $MAX_IQ_TIME $DIR ||
1057 error "restore project grace time failed"
1061 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1062 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1063 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1064 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1066 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1069 local GR_STR1="1w3d"
1070 local GR_STR2="1000s"
1072 local GR_STR4="1w2d3h4m5s"
1074 local GR_STR6="18446744073709551615"
1077 wait_delete_completed
1079 # test of valid grace strings handling
1080 echo "Valid grace strings test"
1081 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1082 $GR_STR2 $DIR || error "set user grace time failed"
1083 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1084 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1085 $GR_STR4 $DIR || error "set group grace time quota failed"
1086 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1088 # test of invalid grace strings handling
1089 echo " Invalid grace strings test"
1090 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1091 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1092 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1096 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1097 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1098 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1099 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1101 run_test 4b "Grace time strings handling"
1103 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1105 local BLIMIT=10 # 10M
1106 local ILIMIT=10 # 10 inodes
1108 setup_quota_test || error "setup quota failed with $?"
1109 trap cleanup_quota_test EXIT
1111 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1112 set_ost_qtype $QTYPE || error "enable ost quota failed"
1114 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1115 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1116 error "set user quota failed"
1117 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1118 if is_project_quota_supported; then
1119 error "set group quota failed"
1120 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1121 -I $ILIMIT $DIR || error "set project quota failed"
1124 # make sure the system is clean
1125 local USED=$(getquota -u $TSTUSR global curinodes)
1126 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1127 USED=$(getquota -g $TSTUSR global curinodes)
1128 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1129 USED=$(getquota -u $TSTUSR global curspace)
1130 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1131 USED=$(getquota -g $TSTUSR global curspace)
1132 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1133 if is_project_quota_supported; then
1134 USED=$(getquota -p $TSTPRJID global curinodes)
1136 error "Used inode($USED) for project $TSTPRJID isn't 0."
1137 USED=$(getquota -p $TSTPRJID global curspace)
1139 error "Used block($USED) for project $TSTPRJID isn't 0."
1142 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1143 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1144 error "create failure, expect success"
1145 if is_project_quota_supported; then
1146 touch $DIR/$tdir/$tfile-0_1
1147 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1149 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1150 error "write failure, expect success"
1152 echo "Chown files to $TSTUSR.$TSTUSR ..."
1153 for i in $(seq 0 $ILIMIT); do
1154 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1155 quota_error a $TSTUSR "chown failure, expect success"
1159 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1160 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1163 resetquota -u $TSTUSR
1164 resetquota -g $TSTUSR
1165 resetquota -p $TSTPRJID
1167 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1169 # test dropping acquire request on master
1173 # Clear dmesg so watchdog is not triggered by previous
1175 do_facet ost1 dmesg -c > /dev/null
1177 setup_quota_test || error "setup quota failed with $?"
1178 trap cleanup_quota_test EXIT
1180 # make sure the system is clean
1181 local USED=$(getquota -u $TSTUSR global curspace)
1182 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1184 # make sure no granted quota on ost
1185 set_ost_qtype $QTYPE || error "enable ost quota failed"
1186 resetquota -u $TSTUSR
1188 # create file for $TSTUSR
1189 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1190 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1191 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1193 # create file for $TSTUSR2
1194 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1195 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1196 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1198 # cache per-ID lock for $TSTUSR on slave
1199 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1200 error "set quota failed"
1201 $RUNAS $DD of=$TESTFILE count=1 ||
1202 error "write $TESTFILE failure, expect success"
1203 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1204 error "write $TESTFILE2 failure, expect success"
1206 sync_all_data || true
1208 #define QUOTA_DQACQ 601
1209 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1210 lustre_fail mds 0x513 601
1212 if at_is_enabled; then
1213 at_max_saved=$(at_max_get ost1)
1214 at_max_set $TIMEOUT ost1
1217 do_facet ost1 $LCTL set_param \
1218 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1220 # write to un-enforced ID ($TSTUSR2) should succeed
1221 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1222 error "write failure, expect success"
1224 # write to enforced ID ($TSTUSR) in background, exceeding limit
1225 # to make sure DQACQ is sent
1226 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1229 # watchdog timer uses a factor of 2
1230 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1231 sleep $((TIMEOUT * 2 + 1))
1233 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1235 # write should be blocked and never finished
1236 if ! ps -p $DDPID > /dev/null 2>&1; then
1238 error "write finished incorrectly!"
1243 # no watchdog is triggered
1244 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1245 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1246 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1247 [ -z "$watchdog" ] || error "$watchdog"
1249 rm -f $TMP/lustre-log-${TESTNAME}.log
1251 # write should continue then fail with EDQUOT
1255 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1256 if [ $count -ge 240 ]; then
1257 quota_error u $TSTUSR "dd not finished in $count secs"
1259 count=$((count + 1))
1260 if [ $((count % 30)) -eq 0 ]; then
1261 c_size=$(stat -c %s $TESTFILE)
1262 echo "Waiting $count secs. $c_size"
1269 resetquota -u $TSTUSR
1271 run_test 6 "Test dropping acquire request on master"
1273 # quota reintegration (global index)
1275 local TESTFILE=$DIR/$tdir/$tfile
1276 local LIMIT=20 # 20M
1278 [ "$SLOW" = "no" ] && LIMIT=5
1280 setup_quota_test || error "setup quota failed with $?"
1281 trap cleanup_quota_test EXIT
1283 # make sure the system is clean
1284 local USED=$(getquota -u $TSTUSR global curspace)
1285 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1287 # make sure no granted quota on ost1
1288 set_ost_qtype $QTYPE || error "enable ost quota failed"
1289 resetquota -u $TSTUSR
1290 set_ost_qtype "none" || error "disable ost quota failed"
1292 local OSTUUID=$(ostuuid_from_index 0)
1293 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1295 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1298 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1299 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1304 echo "Enable quota & set quota limit for $TSTUSR"
1305 set_ost_qtype $QTYPE || error "enable ost quota failed"
1306 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1307 error "set quota failed"
1309 echo "Start ost1..."
1310 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1313 wait_ost_reint $QTYPE || error "reintegration failed"
1315 # hardlimit should have been fetched by slave during global
1316 # reintegration, write will exceed quota
1317 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1318 quota_error u $TSTUSR "write success, but expect EDQUOT"
1321 wait_delete_completed
1322 sync_all_data || true
1328 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1329 error "clear quota failed"
1331 echo "Start ost1..."
1332 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1335 wait_ost_reint $QTYPE || error "reintegration failed"
1337 # hardlimit should be cleared on slave during reintegration
1338 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1339 quota_error u $TSTUSR "write error, but expect success"
1342 resetquota -u $TSTUSR
1344 run_test 7a "Quota reintegration (global index)"
1346 # quota reintegration (slave index)
1349 local TESTFILE=$DIR/$tdir/$tfile
1351 setup_quota_test || error "setup quota failed with $?"
1352 trap cleanup_quota_test EXIT
1354 # make sure the system is clean
1355 local USED=$(getquota -u $TSTUSR global curspace)
1356 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1358 # make sure no granted quota on ost1
1359 set_ost_qtype $QTYPE || error "enable ost quota failed"
1360 resetquota -u $TSTUSR
1361 set_ost_qtype "none" || error "disable ost quota failed"
1363 local OSTUUID=$(ostuuid_from_index 0)
1364 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1366 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1369 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1370 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1372 # consume some space to make sure the granted space will not
1373 # be released during reconciliation
1374 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1375 error "consume space failure, expect success"
1377 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1378 lustre_fail mds 0xa02
1380 set_ost_qtype $QTYPE || error "enable ost quota failed"
1381 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1382 error "set quota failed"
1384 # ignore the write error
1385 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1387 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1391 echo "Restart ost to trigger reintegration..."
1393 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1396 wait_ost_reint $QTYPE || error "reintegration failed"
1398 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1399 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1402 resetquota -u $TSTUSR
1405 run_test 7b "Quota reintegration (slave index)"
1407 # quota reintegration (restart mds during reintegration)
1409 local LIMIT=20 # 20M
1410 local TESTFILE=$DIR/$tdir/$tfile
1412 [ "$SLOW" = "no" ] && LIMIT=5
1414 setup_quota_test || error "setup quota failed with $?"
1415 trap cleanup_quota_test EXIT
1417 # make sure the system is clean
1418 local USED=$(getquota -u $TSTUSR global curspace)
1419 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1421 set_ost_qtype "none" || error "disable ost quota failed"
1422 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1423 error "set quota failed"
1425 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1426 lustre_fail ost 0xa03
1429 set_ost_qtype $QTYPE || error "enable ost quota failed"
1430 # trigger reintegration
1431 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1432 procf=${procf}quota_slave.force_reint
1433 do_facet ost1 $LCTL set_param $procf=1 ||
1434 error "force reintegration failed"
1442 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1445 # wait longer than usual to make sure the reintegration
1446 # is triggered by quota wb thread.
1447 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1449 # hardlimit should have been fetched by slave during global
1450 # reintegration, write will exceed quota
1451 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1452 quota_error u $TSTUSR "write success, but expect EDQUOT"
1455 resetquota -u $TSTUSR
1457 run_test 7c "Quota reintegration (restart mds during reintegration)"
1459 # Quota reintegration (Transfer index in multiple bulks)
1461 local TESTFILE=$DIR/$tdir/$tfile
1462 local TESTFILE1="$DIR/$tdir/$tfile"-1
1465 setup_quota_test || error "setup quota failed with $?"
1466 trap cleanup_quota_test EXIT
1468 set_ost_qtype "none" || error "disable ost quota failed"
1469 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1470 error "set quota for $TSTUSR failed"
1471 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1472 error "set quota for $TSTUSR2 failed"
1474 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1475 lustre_fail mds 0x608 0
1477 # enable quota to tirgger reintegration
1478 set_ost_qtype "u" || error "enable ost quota failed"
1479 wait_ost_reint "u" || error "reintegration failed"
1483 # hardlimit should have been fetched by slave during global
1484 # reintegration, write will exceed quota
1485 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1486 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1488 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1489 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1492 resetquota -u $TSTUSR
1493 resetquota -u $TSTUSR2
1495 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1497 # quota reintegration (inode limits)
1499 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1501 # LU-2435: skip this quota test if underlying zfs version has not
1502 # supported native dnode accounting
1503 [ "$(facet_fstype mds1)" == "zfs" ] && {
1504 local F="feature@userobj_accounting"
1505 local pool=$(zpool_name mds1)
1506 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1508 [[ "$feature" != *" active "* ]] &&
1509 skip "requires zpool with active userobj_accounting"
1512 local ilimit=$((1024 * 2)) # 2k inodes
1513 local TESTFILE=$DIR/${tdir}-1/$tfile
1515 setup_quota_test || error "setup quota failed with $?"
1516 trap cleanup_quota_test EXIT
1518 # make sure the system is clean
1519 local USED=$(getquota -u $TSTUSR global curinodes)
1520 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1522 # make sure no granted quota on mdt1
1523 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1524 resetquota -u $TSTUSR
1525 set_mdt_qtype "none" || error "disable mdt quota failed"
1527 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1528 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1529 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1532 echo "Stop mds${MDSCOUNT}..."
1535 echo "Enable quota & set quota limit for $TSTUSR"
1536 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1537 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1538 error "set quota failed"
1540 echo "Start mds${MDSCOUNT}..."
1541 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1544 wait_mdt_reint $QTYPE || error "reintegration failed"
1546 echo "create remote dir"
1547 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1548 error "create remote dir failed"
1549 chmod 0777 $DIR/${tdir}-1
1551 # hardlimit should have been fetched by slave during global
1552 # reintegration, create will exceed quota
1553 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1554 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1556 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1557 wait_delete_completed
1558 sync_all_data || true
1560 echo "Stop mds${MDSCOUNT}..."
1563 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1564 error "clear quota failed"
1566 echo "Start mds${MDSCOUNT}..."
1567 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1570 wait_mdt_reint $QTYPE || error "reintegration failed"
1572 # hardlimit should be cleared on slave during reintegration
1573 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1574 quota_error u $TSTUSR "create failed, expect success"
1576 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1577 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1580 resetquota -u $TSTUSR
1582 run_test 7e "Quota reintegration (inode limits)"
1584 # run dbench with quota enabled
1586 local BLK_LIMIT="100g" #100G
1587 local FILE_LIMIT=1000000
1589 setup_quota_test || error "setup quota failed with $?"
1590 trap cleanup_quota_test EXIT
1592 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1593 set_ost_qtype $QTYPE || error "enable ost quota failed"
1595 echo "Set enough high limit for user: $TSTUSR"
1596 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1597 error "set user quota failed"
1598 echo "Set enough high limit for group: $TSTUSR"
1599 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1600 error "set group quota failed"
1601 if is_project_quota_supported; then
1602 change_project -sp $TSTPRJID $DIR/$tdir
1603 echo "Set enough high limit for project: $TSTPRJID"
1604 $LFS setquota -p $TSTPRJID -b 0 \
1605 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1606 error "set project quota failed"
1610 [ "$SLOW" = "no" ] && duration=" -t 120"
1611 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1612 quota_error a $TSTUSR "dbench failed!"
1614 is_project_quota_supported && change_project -C $DIR/$tdir
1616 resetquota -u $TSTUSR
1617 resetquota -g $TSTUSR
1618 resetquota -p $TSTPRJID
1620 run_test 8 "Run dbench with quota enabled"
1622 # this check is just for test_9
1623 OST0_MIN=4900000 #4.67G
1625 check_whether_skip () {
1626 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1627 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1628 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1629 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1636 # run for fixing bug10707, it needs a big room. test for 64bit
1638 local filesize=$((1024 * 9 / 2)) # 4.5G
1640 check_whether_skip && return 0
1642 setup_quota_test || error "setup quota failed with $?"
1643 trap cleanup_quota_test EXIT
1645 set_ost_qtype "ug" || error "enable ost quota failed"
1647 local TESTFILE="$DIR/$tdir/$tfile-0"
1648 local BLK_LIMIT=100G #100G
1649 local FILE_LIMIT=1000000
1651 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1653 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1655 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1656 error "set user quota failed"
1658 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1659 "for group: $TSTUSR"
1660 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1661 error "set group quota failed"
1663 quota_show_check a u $TSTUSR
1664 quota_show_check a g $TSTUSR
1666 echo "Create test file"
1667 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1668 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1670 log "Write the big file of 4.5G ..."
1671 $RUNAS $DD of=$TESTFILE count=$filesize ||
1672 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1678 resetquota -u $TSTUSR
1679 resetquota -g $TSTUSR
1684 run_test 9 "Block limit larger than 4GB (b10707)"
1687 local TESTFILE=$DIR/$tdir/$tfile
1689 setup_quota_test || error "setup quota failed with $?"
1690 trap cleanup_quota_test EXIT
1692 # set limit to root user should fail
1693 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1694 error "set limit for root user successfully, expect failure"
1695 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1696 error "set limit for root group successfully, expect failure"
1697 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1698 error "set limit for project 0 successfully, expect failure"
1700 # root user can overrun quota
1701 set_ost_qtype "ug" || error "enable ost quota failed"
1703 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1704 error "set quota failed"
1705 quota_show_check b u $TSTUSR
1707 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1708 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1710 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1711 error "write failure, expect success"
1714 resetquota -u $TSTUSR
1716 run_test 10 "Test quota for root user"
1719 local TESTFILE=$DIR/$tdir/$tfile
1720 setup_quota_test || error "setup quota failed with $?"
1721 trap cleanup_quota_test EXIT
1723 set_mdt_qtype "ug" || error "enable mdt quota failed"
1724 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1725 error "set quota failed"
1727 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1728 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1730 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1731 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1734 local USED=$(getquota -u $TSTUSR global curinodes)
1735 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1738 resetquota -u $TSTUSR
1740 run_test 11 "Chown/chgrp ignores quota"
1743 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1745 local blimit=22 # 22M
1746 local blk_cnt=$((blimit - 5))
1747 local TESTFILE0="$DIR/$tdir/$tfile"-0
1748 local TESTFILE1="$DIR/$tdir/$tfile"-1
1750 setup_quota_test || error "setup quota failed with $?"
1751 trap cleanup_quota_test EXIT
1753 set_ost_qtype "u" || error "enable ost quota failed"
1754 quota_show_check b u $TSTUSR
1756 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1757 error "set quota failed"
1759 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1760 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1761 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1762 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1764 echo "Write to ost0..."
1765 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1766 quota_error a $TSTUSR "dd failed"
1768 echo "Write to ost1..."
1769 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1770 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1772 echo "Free space from ost0..."
1774 wait_delete_completed
1775 sync_all_data || true
1777 echo "Write to ost1 after space freed from ost0..."
1778 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1779 quota_error a $TSTUSR "rebalancing failed"
1782 resetquota -u $TSTUSR
1784 run_test 12a "Block quota rebalancing"
1787 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1789 local ilimit=$((1024 * 2)) # 2k inodes
1790 local TESTFILE0=$DIR/$tdir/$tfile
1791 local TESTFILE1=$DIR/${tdir}-1/$tfile
1793 setup_quota_test || error "setup quota failed with $?"
1794 trap cleanup_quota_test EXIT
1796 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1797 chmod 0777 $DIR/${tdir}-1
1799 set_mdt_qtype "u" || error "enable mdt quota failed"
1800 quota_show_check f u $TSTUSR
1802 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1803 error "set quota failed"
1805 echo "Create $ilimit files on mdt0..."
1806 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1807 quota_error u $TSTUSR "create failed, but expect success"
1809 echo "Create files on mdt1..."
1810 $RUNAS createmany -m $TESTFILE1 1 &&
1811 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1813 echo "Free space from mdt0..."
1814 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1815 wait_delete_completed
1816 sync_all_data || true
1818 echo "Create files on mdt1 after space freed from mdt0..."
1819 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1820 quota_error a $TSTUSR "rebalancing failed"
1822 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1823 error "unlink mdt1 files failed"
1824 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1827 resetquota -u $TSTUSR
1829 run_test 12b "Inode quota rebalancing"
1832 local TESTFILE=$DIR/$tdir/$tfile
1833 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1834 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1836 setup_quota_test || error "setup quota failed with $?"
1837 trap cleanup_quota_test EXIT
1839 set_ost_qtype "u" || error "enable ost quota failed"
1840 quota_show_check b u $TSTUSR
1842 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1843 error "set quota failed"
1844 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1845 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1847 # clear the locks in cache first
1848 do_facet ost1 $LCTL set_param -n $procf=clear
1849 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1850 [ $nlock -eq 0 ] || error "$nlock cached locks"
1852 # write to acquire the per-ID lock
1853 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1854 quota_error a $TSTUSR "dd failed"
1856 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1857 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1859 # clear quota doesn't trigger per-ID lock cancellation
1860 resetquota -u $TSTUSR
1861 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1862 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1864 # clear the per-ID lock
1865 do_facet ost1 $LCTL set_param -n $procf=clear
1866 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1867 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1869 # spare quota should be released
1870 local OSTUUID=$(ostuuid_from_index 0)
1871 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1872 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1873 [ $limit -le $space ] ||
1874 error "spare quota isn't released, limit:$limit, space:$space"
1878 run_test 13 "Cancel per-ID lock in the LRU list"
1881 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1883 wait_delete_completed
1884 sync_all_data || true
1887 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1888 error "set user quota failed"
1889 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1890 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1891 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1892 resetquota -u $TSTUSR
1895 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1896 error "set group quota failed"
1897 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1898 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1899 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1900 resetquota -g $TSTUSR
1902 run_test 15 "Set over 4T block quota"
1906 local BLKS=1 # 1M less than limit
1907 local TESTFILE=$DIR/$tdir/$tfile
1909 setup_quota_test || error "setup quota failed with $?"
1910 trap cleanup_quota_test EXIT
1912 # make sure the system is clean
1913 local USED=$(getquota -u $TSTUSR global curspace)
1914 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1916 set_ost_qtype "ug" || error "enable ost quota failed"
1917 # make sure no granted quota on ost
1918 resetquota -u $TSTUSR
1919 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1920 error "set quota failed"
1922 quota_show_check b u $TSTUSR
1924 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1925 lustre_fail mds 0xa04 $err_code
1927 # write in background
1928 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1932 # write should be blocked and never finished
1933 if ! ps -p $DDPID > /dev/null 2>&1; then
1935 quota_error u $TSTUSR "write finished incorrectly!"
1943 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1945 if [ $count -gt $timeout ]; then
1946 quota_error u $TSTUSR "dd is not finished!"
1951 sync; sync_all_data || true
1953 USED=$(getquota -u $TSTUSR global curspace)
1954 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1955 "Used space(${USED}K) is less than ${BLKS}M"
1958 resetquota -u $TSTUSR
1961 # DQACQ return recoverable error
1963 echo "DQACQ return -ENOLCK"
1965 test_17sub 37 || error "Handle -ENOLCK failed"
1967 echo "DQACQ return -EAGAIN"
1969 test_17sub 11 || error "Handle -EAGAIN failed"
1971 echo "DQACQ return -ETIMEDOUT"
1972 #define ETIMEDOUT 110
1973 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1975 echo "DQACQ return -ENOTCONN"
1976 #define ENOTCONN 107
1977 test_17sub 107 || error "Handle -ENOTCONN failed"
1980 run_test 17 "DQACQ return recoverable error"
1984 local blimit="200m" # 200M
1985 local TESTFILE="$DIR/$tdir/$tfile"
1987 setup_quota_test || error "setup quota failed with $?"
1988 trap cleanup_quota_test EXIT
1990 set_ost_qtype "u" || error "enable ost quota failed"
1991 log "User quota (limit: $blimit)"
1992 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1993 error "set quota failed"
1994 quota_show_check b u $TSTUSR
1996 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1997 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1999 local timeout=$(sysctl -n lustre.timeout)
2001 if [ $io_type = "directio" ]; then
2002 log "Write 100M (directio) ..."
2003 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2005 log "Write 100M (buffered) ..."
2006 $RUNAS $DD of=$TESTFILE count=100 &
2010 replay_barrier $SINGLEMDS
2011 log "Fail mds for $((2 * timeout)) seconds"
2012 fail $SINGLEMDS $((2 * timeout))
2015 if at_is_enabled; then
2016 timeout=$(at_max_get mds)
2018 timeout=$(lctl get_param -n timeout)
2022 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2023 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2024 log "it took $count second"
2029 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2031 cancel_lru_locks mdc
2032 cancel_lru_locks osc
2035 local testfile_size=$(stat -c %s $TESTFILE)
2036 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2037 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2038 "got ${testfile_size}. Verifying file failed!"
2041 resetquota -u $TSTUSR
2044 # test when mds does failover, the ost still could work well
2045 # this test shouldn't trigger watchdog b=14840
2047 # Clear dmesg so watchdog is not triggered by previous
2049 do_facet ost1 dmesg -c > /dev/null
2052 test_18_sub directio
2054 # check if watchdog is triggered
2055 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2056 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2057 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2058 [ -z "$watchdog" ] || error "$watchdog"
2059 rm -f $TMP/lustre-log-${TESTNAME}.log
2061 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2065 local TESTFILE=$DIR/$tdir/$tfile
2067 setup_quota_test || error "setup quota failed with $?"
2068 trap cleanup_quota_test EXIT
2070 set_ost_qtype $QTYPE || error "enable ost quota failed"
2072 # bind file to a single OST
2073 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2074 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2076 echo "Set user quota (limit: ${blimit}M)"
2077 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2078 error "set user quota failed"
2079 quota_show_check b u $TSTUSR
2080 echo "Update quota limits"
2081 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2082 error "set group quota failed"
2083 quota_show_check b u $TSTUSR
2085 # first wirte might be cached
2086 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2087 cancel_lru_locks osc
2089 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2090 quota_error u $TSTUSR "Write success, expect failure"
2094 resetquota -u $TSTUSR
2096 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2098 test_20() { # b15754
2099 local LSTR=(2g 1t 4k 3m) # limits strings
2101 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2104 resetquota -u $TSTUSR
2106 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2107 $MOUNT || error "could not set quota limits"
2108 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2109 --inode-softlimit ${LSTR[2]} \
2110 --inode-hardlimit ${LSTR[3]} \
2111 $MOUNT || error "could not set quota limits"
2113 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2114 error "bsoftlimit was not set properly"
2115 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2116 error "bhardlimit was not set properly"
2117 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2118 error "isoftlimit was not set properly"
2119 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2120 error "ihardlimit was not set properly"
2122 resetquota -u $TSTUSR
2124 run_test 20 "Test if setquota specifiers work properly (b15754)"
2131 local time=$(($(date +%s) + seconds))
2132 while [ $(date +%s) -lt $time ]; do
2133 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2137 # run for fixing bug16053, setquota shouldn't fail when writing and
2138 # deleting are happening
2140 local TESTFILE="$DIR/$tdir/$tfile"
2141 local BLIMIT=10 # 10G
2142 local ILIMIT=1000000
2144 setup_quota_test || error "setup quota failed with $?"
2145 trap cleanup_quota_test EXIT
2147 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2149 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2150 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2151 error "set user quota failed"
2152 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2153 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2154 error "set group quota failed"
2155 if is_project_quota_supported; then
2156 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2157 "project: $TSTPRJID"
2158 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2159 $MOUNT || error "set project quota failed"
2162 # repeat writing on a 1M file
2163 test_21_sub ${TESTFILE}_1 1 30 &
2165 # repeat writing on a 128M file
2166 test_21_sub ${TESTFILE}_2 128 30 &
2169 local time=$(($(date +%s) + 30))
2171 while [ $(date +%s) -lt $time ]; do
2172 log "Set quota for $i times"
2173 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2174 -I $((ILIMIT + i)) $MOUNT ||
2175 error "Set user quota failed"
2176 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2177 -I $((ILIMIT + i)) $MOUNT ||
2178 error "Set group quota failed"
2179 if is_project_quota_supported; then
2180 $LFS setquota -p $TSTPRJID -b 0 -B \
2181 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2182 error "Set project quota failed"
2190 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2192 if [ $count -gt 60 ]; then
2193 quota_error a $TSTUSR "dd should be finished!"
2197 echo "(dd_pid=$DDPID1, time=$count)successful"
2201 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2203 if [ $count -gt 60 ]; then
2204 quota_error a $TSTUSR "dd should be finished!"
2208 echo "(dd_pid=$DDPID2, time=$count)successful"
2211 resetquota -u $TSTUSR
2212 resetquota -g $TSTUSR
2213 resetquota -p $TSTPRJID
2215 run_test 21 "Setquota while writing & deleting (b16053)"
2217 # enable/disable quota enforcement permanently
2219 echo "Set both mdt & ost quota type as ug"
2221 is_project_quota_supported && qtype=$QTYPE
2222 set_mdt_qtype $qtype || error "enable mdt quota failed"
2223 set_ost_qtype $qtype || error "enable ost quota failed"
2226 stopall || error "failed to stopall (1)"
2230 echo "Verify if quota is enabled"
2231 local qtype1=$(mdt_quota_type)
2232 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2233 qtype=$(ost_quota_type)
2234 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2236 echo "Set both mdt & ost quota type as none"
2237 set_mdt_qtype "none" || error "disable mdt quota failed"
2238 set_ost_qtype "none" || error "disable ost quota failed"
2241 stopall || error "failed to stopall (2)"
2246 echo "Verify if quota is disabled"
2247 qtype=$(mdt_quota_type)
2248 [ $qtype != "none" ] && error "mdt quota setting is lost"
2249 qtype=$(ost_quota_type)
2250 [ $qtype != "none" ] && error "ost quota setting is lost"
2254 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2257 local TESTFILE="$DIR/$tdir/$tfile"
2260 setup_quota_test || error "setup quota failed with $?"
2261 trap cleanup_quota_test EXIT
2263 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2266 log "User quota (limit: $LIMIT MB)"
2267 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2268 error "set quota failed"
2269 quota_show_check b u $TSTUSR
2271 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2272 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2274 log "Step1: trigger EDQUOT with O_DIRECT"
2275 log "Write half of file"
2276 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2277 quota_error u $TSTUSR "(1) Write failure, expect success." \
2279 log "Write out of block quota ..."
2280 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2281 oflag=direct conv=notrunc &&
2282 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2286 log "Step2: rewrite should succeed"
2287 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2288 quota_error u $TSTUSR "(3) Write failure, expect success." \
2294 local OST0_UUID=$(ostuuid_from_index 0)
2295 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2296 [ $OST0_QUOTA_USED -ne 0 ] &&
2297 ($SHOW_QUOTA_USER; \
2298 quota_error u $TSTUSR "quota isn't released")
2300 resetquota -u $TSTUSR
2304 [ $(facet_fstype ost1) == "zfs" ] &&
2305 skip "Overwrite in place is not guaranteed to be " \
2306 "space neutral on ZFS"
2308 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2309 check_whether_skip && return 0
2310 log "run for 4MB test file"
2313 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2314 check_whether_skip && return 0
2315 log "run for 40MB test file"
2318 run_test 23 "Quota should be honored with directIO (b16125)"
2322 local TESTFILE="$DIR/$tdir/$tfile"
2324 setup_quota_test || error "setup quota failed with $?"
2325 trap cleanup_quota_test EXIT
2327 set_ost_qtype $QTYPE || error "enable ost quota failed"
2329 # bind file to a single OST
2330 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2331 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2333 echo "Set user quota (limit: ${blimit}M)"
2334 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2335 error "set quota failed"
2337 # overrun quota by root user
2338 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2339 error "write failure, expect success"
2340 cancel_lru_locks osc
2341 sync_all_data || true
2343 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2346 resetquota -u $TSTUSR
2348 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2350 test_27a() { # b19612
2351 $LFS quota $TSTUSR $DIR &&
2352 error "lfs succeeded with no type, but should have failed"
2353 $LFS setquota $TSTUSR $DIR &&
2354 error "lfs succeeded with no type, but should have failed"
2357 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2359 test_27b() { # b20200
2360 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2361 error "lfs setquota failed with uid argument"
2362 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2363 error "lfs stequota failed with gid argument"
2364 if is_project_quota_supported; then
2365 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2366 1000 $DIR || error \
2367 "lfs stequota failed with projid argument"
2369 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2370 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2371 if is_project_quota_supported; then
2372 $SHOW_QUOTA_PROJID ||
2373 error "lfs quota failed with projid argument"
2375 resetquota -u $TSTUSR
2376 resetquota -g $TSTUSR
2377 resetquota -p $TSTPRJID
2380 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2385 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2386 error "lfs setquota failed"
2388 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2389 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2390 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2391 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2393 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2394 error "lfs setquota for $TSTID failed"
2396 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2397 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2398 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2399 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2401 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2402 error "total allocated inode/block limit not printed"
2404 resetquota -u $TSTUSR
2406 run_test 27c "lfs quota should support human-readable output"
2413 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2414 error "set fraction block limit failed"
2415 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2416 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2417 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2418 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2420 resetquota -u $TSTUSR
2422 run_test 27d "lfs setquota should support fraction block limit"
2426 local TESTFILE="$DIR/$tdir/$tfile"
2429 setup_quota_test || error "setup quota failed with $?"
2430 trap cleanup_quota_test EXIT
2432 set_ost_qtype "u" || error "enable ost quota failed"
2434 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2435 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2437 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2438 $MAX_IQ_TIME $DIR || error "set grace time failed"
2439 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2440 error "set quota failed"
2441 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2442 cancel_lru_locks osc
2444 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2445 # over-quota flag has not yet settled since we do not trigger async
2446 # events based on grace time period expiration
2448 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2449 cancel_lru_locks osc
2450 # now over-quota flag should be settled and further writes should fail
2452 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2453 error "grace times were reset"
2456 resetquota -u $TSTUSR
2457 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2458 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2460 run_test 30 "Hard limit updates should not reset grace times"
2462 # basic usage tracking for user & group
2464 local INODES=10 # 10 files
2465 local BLK_CNT=2 # of 2M each
2466 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2468 setup_quota_test || error "setup quota failed with $?"
2469 trap cleanup_quota_test EXIT
2471 # make sure the system is clean
2472 local USED=$(getquota -u $TSTID global curspace)
2474 error "Used space ($USED) for user $TSTID isn't 0."
2475 USED=$(getquota -g $TSTID global curspace)
2477 error "Used space ($USED) for group $TSTID isn't 0."
2478 if is_project_quota_supported; then
2479 USED=$(getquota -p $TSTPRJID global curspace)
2480 [ $USED -ne 0 ] && error \
2481 "Used space ($USED) for project $TSTPRJID isn't 0."
2484 echo "Write files..."
2485 for i in $(seq 0 $INODES); do
2486 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2487 error "write failed"
2488 is_project_quota_supported &&
2489 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2490 echo "Iteration $i/$INODES completed"
2492 cancel_lru_locks osc
2494 echo "Wait for setattr on objects finished..."
2495 wait_delete_completed
2497 sync; sync_all_data || true
2499 echo "Verify disk usage after write"
2500 USED=$(getquota -u $TSTID global curspace)
2501 [ $USED -lt $TOTAL_BLKS ] &&
2502 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2503 USED=$(getquota -g $TSTID global curspace)
2504 [ $USED -lt $TOTAL_BLKS ] &&
2505 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2506 if is_project_quota_supported; then
2507 USED=$(getquota -p $TSTPRJID global curspace)
2508 [ $USED -lt $TOTAL_BLKS ] && error \
2509 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2512 echo "Verify inode usage after write"
2513 USED=$(getquota -u $TSTID global curinodes)
2514 [ $USED -lt $INODES ] &&
2515 error "Used inode for user $TSTID is $USED, expected $INODES"
2516 USED=$(getquota -g $TSTID global curinodes)
2517 [ $USED -lt $INODES ] &&
2518 error "Used inode for group $TSTID is $USED, expected $INODES"
2519 if is_project_quota_supported; then
2520 USED=$(getquota -p $TSTPRJID global curinodes)
2521 [ $USED -lt $INODES ] && error \
2522 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2527 echo "Verify disk usage after delete"
2528 USED=$(getquota -u $TSTID global curspace)
2529 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2530 USED=$(getquota -u $TSTID global curinodes)
2531 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2532 USED=$(getquota -g $TSTID global curspace)
2533 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2534 USED=$(getquota -g $TSTID global curinodes)
2535 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2536 if is_project_quota_supported; then
2537 USED=$(getquota -p $TSTPRJID global curspace)
2539 error "Used space for project $TSTPRJID isn't 0. $USED"
2540 USED=$(getquota -p $TSTPRJID global curinodes)
2542 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2545 run_test 33 "Basic usage tracking for user & group & project"
2547 # usage transfer test for user & group & project
2549 local BLK_CNT=2 # 2MB
2550 local project_supported="no"
2552 is_project_quota_supported && project_supported="yes"
2553 setup_quota_test || error "setup quota failed with $?"
2554 trap cleanup_quota_test EXIT
2556 # make sure the system is clean
2557 local USED=$(getquota -u $TSTID global curspace)
2558 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2559 USED=$(getquota -g $TSTID global curspace)
2560 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2562 local USED=$(getquota -u $TSTID2 global curspace)
2563 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2564 if [ $project_supported == "yes" ]; then
2565 USED=$(getquota -p $TSTPRJID global curspace)
2566 [ $USED -ne 0 ] && error \
2567 "Used space ($USED) for Project $TSTPRJID isn't 0."
2570 echo "Write file..."
2571 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2572 error "write failed"
2573 cancel_lru_locks osc
2574 sync; sync_all_data || true
2576 echo "chown the file to user $TSTID"
2577 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2579 echo "Wait for setattr on objects finished..."
2580 wait_delete_completed
2582 BLK_CNT=$((BLK_CNT * 1024))
2584 echo "Verify disk usage for user $TSTID"
2585 USED=$(getquota -u $TSTID global curspace)
2586 [ $USED -lt $BLK_CNT ] &&
2587 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2588 USED=$(getquota -u $TSTID global curinodes)
2590 error "Used inodes for user $TSTID is $USED, expected 1"
2592 echo "chgrp the file to group $TSTID"
2593 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2595 echo "Wait for setattr on objects finished..."
2596 wait_delete_completed
2598 echo "Verify disk usage for group $TSTID"
2599 USED=$(getquota -g $TSTID global curspace)
2600 [ $USED -ge $BLK_CNT ] ||
2601 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2602 USED=$(getquota -g $TSTID global curinodes)
2604 error "Used inodes for group $TSTID is $USED, expected 1"
2606 # chown won't change the ost object group. LU-4345 */
2607 echo "chown the file to user $TSTID2"
2608 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2610 echo "Wait for setattr on objects finished..."
2611 wait_delete_completed
2613 echo "change_project project id to $TSTPRJID"
2614 [ $project_supported == "yes" ] &&
2615 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2616 echo "Wait for setattr on objects finished..."
2617 wait_delete_completed
2619 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2620 USED=$(getquota -u $TSTID2 global curspace)
2621 [ $USED -lt $BLK_CNT ] &&
2622 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2623 USED=$(getquota -u $TSTID global curspace)
2625 error "Used space for user $TSTID is $USED, expected 0"
2626 USED=$(getquota -g $TSTID global curspace)
2627 [ $USED -lt $BLK_CNT ] &&
2628 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2629 if [ $project_supported == "yes" ]; then
2630 USED=$(getquota -p $TSTPRJID global curspace)
2631 [ $USED -lt $BLK_CNT ] && error \
2632 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2637 run_test 34 "Usage transfer for user & group & project"
2639 # usage is still accessible across restart
2641 local BLK_CNT=2 # 2 MB
2643 setup_quota_test || error "setup quota failed with $?"
2644 trap cleanup_quota_test EXIT
2646 echo "Write file..."
2647 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2648 error "write failed"
2649 is_project_quota_supported &&
2650 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2651 cancel_lru_locks osc
2653 echo "Wait for setattr on objects finished..."
2654 wait_delete_completed
2656 sync; sync_all_data || true
2658 echo "Save disk usage before restart"
2659 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2660 [ $ORIG_USR_SPACE -eq 0 ] &&
2661 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2662 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2663 [ $ORIG_USR_INODES -eq 0 ] &&
2664 error "Used inodes for user $TSTID is 0, expected 1"
2665 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2666 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2667 [ $ORIG_GRP_SPACE -eq 0 ] &&
2668 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2669 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2670 [ $ORIG_GRP_INODES -eq 0 ] &&
2671 error "Used inodes for group $TSTID is 0, expected 1"
2672 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2674 if is_project_quota_supported; then
2675 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2676 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2677 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2678 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2679 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2680 "Used inodes for project $TSTPRJID is 0, expected 1"
2681 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2689 echo "Verify disk usage after restart"
2690 local USED=$(getquota -u $TSTID global curspace)
2691 [ $USED -eq $ORIG_USR_SPACE ] ||
2692 error "Used space for user $TSTID changed from " \
2693 "$ORIG_USR_SPACE to $USED"
2694 USED=$(getquota -u $TSTID global curinodes)
2695 [ $USED -eq $ORIG_USR_INODES ] ||
2696 error "Used inodes for user $TSTID changed from " \
2697 "$ORIG_USR_INODES to $USED"
2698 USED=$(getquota -g $TSTID global curspace)
2699 [ $USED -eq $ORIG_GRP_SPACE ] ||
2700 error "Used space for group $TSTID changed from " \
2701 "$ORIG_GRP_SPACE to $USED"
2702 USED=$(getquota -g $TSTID global curinodes)
2703 [ $USED -eq $ORIG_GRP_INODES ] ||
2704 error "Used inodes for group $TSTID changed from " \
2705 "$ORIG_GRP_INODES to $USED"
2706 if [ $project_supported == "yes" ]; then
2707 USED=$(getquota -p $TSTPRJID global curinodes)
2708 [ $USED -eq $ORIG_PRJ_INODES ] ||
2709 error "Used inodes for project $TSTPRJID " \
2710 "changed from $ORIG_PRJ_INODES to $USED"
2711 USED=$(getquota -p $TSTPRJID global curspace)
2712 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2713 error "Used space for project $TSTPRJID "\
2714 "changed from $ORIG_PRJ_SPACE to $USED"
2717 # check if the vfs_dq_init() is called before writing
2718 echo "Append to the same file..."
2719 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2720 error "write failed"
2721 cancel_lru_locks osc
2722 sync; sync_all_data || true
2724 echo "Verify space usage is increased"
2725 USED=$(getquota -u $TSTID global curspace)
2726 [ $USED -gt $ORIG_USR_SPACE ] ||
2727 error "Used space for user $TSTID isn't increased" \
2728 "orig:$ORIG_USR_SPACE, now:$USED"
2729 USED=$(getquota -g $TSTID global curspace)
2730 [ $USED -gt $ORIG_GRP_SPACE ] ||
2731 error "Used space for group $TSTID isn't increased" \
2732 "orig:$ORIG_GRP_SPACE, now:$USED"
2733 if [ $project_supported == "yes" ]; then
2734 USED=$(getquota -p $TSTPRJID global curspace)
2735 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2736 error "Used space for project $TSTPRJID isn't " \
2737 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2742 run_test 35 "Usage is still accessible across reboot"
2744 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2747 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2748 skip "Old server doesn't have LU-5006 fix."
2750 setup_quota_test || error "setup quota failed with $?"
2751 trap cleanup_quota_test EXIT
2753 # make sure the system is clean
2754 local USED=$(getquota -u $TSTID global curspace)
2756 error "Used space ($USED) for user $TSTID isn't 0."
2758 # create file with MDS_OPEN_DELAY_CREATE flag
2759 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2760 error "Create file failed"
2762 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2763 oflag=sync || error "Write file failed"
2765 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2767 # wait for setattr on objects finished..."
2768 wait_delete_completed
2770 USED=$(getquota -u $TSTID global curspace)
2771 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2775 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2779 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2780 skip "Old server doesn't have LU-8801 fix."
2782 [ "$UID" != 0 ] && skip_env "must run as root" && return
2784 setup_quota_test || error "setup quota failed with $?"
2785 trap cleanup_quota_test EXIT
2787 # make sure the system is clean
2788 local USED=$(getquota -u $TSTID global curspace)
2790 error "Used space ($USED) for user $TSTID isn't 0."
2791 USED=$(getquota -u $TSTID2 global curspace)
2793 error "Used space ($USED) for user $TSTID2 isn't 0."
2795 local TESTFILE="$DIR/$tdir/$tfile"
2796 local file_cnt=10000
2798 # Generate id entries in accounting file
2799 echo "Create $file_cnt files..."
2800 for i in `seq $file_cnt`; do
2802 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2803 error "failed to chown $TESTFILE-$i"
2805 cancel_lru_locks osc
2806 sync; sync_all_data || true
2808 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2809 procf=${procf}.quota_slave.acct_user
2812 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2813 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2814 echo "Found $acct_cnt id entries"
2816 [ $file_cnt -eq $acct_cnt ] || {
2817 do_facet mds1 $LCTL get_param $procf
2818 error "skipped id entries"
2823 run_test 38 "Quota accounting iterator doesn't skip id entries"
2826 local TESTFILE="$DIR/$tdir/project"
2827 ! is_project_quota_supported &&
2828 skip "Project quota is not supported"
2830 setup_quota_test || error "setup quota failed with $?"
2833 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2834 [ $projectid -ne 0 ] &&
2835 error "Project id should be 0 not $projectid"
2836 change_project -p 1024 $TESTFILE
2837 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2838 [ $projectid -ne 1024 ] &&
2839 error "Project id should be 1024 not $projectid"
2841 stopall || error "failed to stopall (1)"
2844 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2845 [ $projectid -ne 1024 ] &&
2846 error "Project id should be 1024 not $projectid"
2850 run_test 39 "Project ID interface works correctly"
2853 ! is_project_quota_supported &&
2854 skip "Project quota is not supported"
2855 local dir1="$DIR/$tdir/dir1"
2856 local dir2="$DIR/$tdir/dir2"
2858 setup_quota_test || error "setup quota failed with $?"
2860 mkdir -p $dir1 $dir2
2861 change_project -sp 1 $dir1 && touch $dir1/1
2862 change_project -sp 2 $dir2
2864 ln $dir1/1 $dir2/1_link &&
2865 error "Hard link across different project quota should fail"
2870 run_test 40a "Hard link across different project ID"
2873 ! is_project_quota_supported &&
2874 skip "Project quota is not supported"
2875 local dir1="$DIR/$tdir/dir1"
2876 local dir2="$DIR/$tdir/dir2"
2878 setup_quota_test || error "setup quota failed with $?"
2879 mkdir -p $dir1 $dir2
2880 change_project -sp 1 $dir1 && touch $dir1/1
2881 change_project -sp 2 $dir2
2883 mv $dir1/1 $dir2/2 || error "mv failed $?"
2884 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2885 if [ "$projid" != "2" ]; then
2886 error "project id expected 2 not $projid"
2891 run_test 40b "Mv across different project ID"
2894 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2895 ! is_project_quota_supported &&
2896 skip "Project quota is not supported"
2898 setup_quota_test || error "setup quota failed with $?"
2899 local dir="$DIR/$tdir/dir"
2901 mkdir -p $dir && change_project -sp 1 $dir
2902 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2903 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2904 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2905 touch $dir/remote_dir/file
2906 #verify inherit works file for remote dir.
2907 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2908 [ "$projid" != "1" ] &&
2909 error "file under remote dir expected 1 not $projid"
2911 #Agent inode should be ignored for project quota
2912 USED=$(getquota -p 1 global curinodes)
2913 [ "$USED" != "3" ] &&
2914 error "file count expected 3 got $USED"
2920 run_test 40c "Remote child Dir inherit project quota properly"
2923 ! is_project_quota_supported &&
2924 skip "Project quota is not supported"
2926 setup_quota_test || error "setup quota failed with $?"
2927 local dir1="$DIR/$tdir/dir1"
2928 local dir2="$DIR/$tdir/dir2"
2930 mkdir -p $dir1 && change_project -sp 1 $dir1
2931 mkdir -p $dir2 && change_project -sp 2 $dir2
2932 for num in $(seq 1 10); do
2933 touch $dir1/file_$num $dir2/file_$num
2934 ln -s $dir1/file_$num $dir1/file_$num"_link"
2935 ln -s $dir2/file_$num $dir2/file_$num"_link"
2938 count=$($LFS find --projid 1 $DIR | wc -l)
2939 [ "$count" != 21 ] && error "expected 21 but got $count"
2941 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2942 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2943 [ "$count" != 22 ] && error "expected 22 but got $count"
2948 run_test 50 "Test if lfs find --projid works"
2951 ! is_project_quota_supported &&
2952 skip "Project quota is not supported"
2953 setup_quota_test || error "setup quota failed with $?"
2954 local dir="$DIR/$tdir/dir"
2956 mkdir $dir && change_project -sp 1 $dir
2957 local used=$(getquota -p 1 global curinodes)
2958 [ $used != "1" ] && error "expected 1 got $used"
2963 used=$(getquota -p 1 global curinodes)
2964 [ $used != "4" ] && error "expected 4 got $used"
2966 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2968 cp $DIR/$tdir/6 $dir/6
2969 used=$(getquota -p 1 global curinodes)
2970 [ $used != "5" ] && error "expected 5 got $used"
2973 mv $DIR/$tdir/6 $dir/7
2974 used=$(getquota -p 1 global curinodes)
2975 [ $used != "6" ] && error "expected 6 got $used"
2980 run_test 51 "Test project accounting with mv/cp"
2983 ! is_project_quota_supported &&
2984 skip "Project quota is not supported"
2985 setup_quota_test || error "setup quota failed with $?"
2986 local dir="$DIR/$tdir/dir"
2987 mkdir $dir && change_project -sp 1 $dir
2989 touch $DIR/$tdir/file
2990 #Try renaming a file into the project. This should fail.
2991 for num in $(seq 1 2000); do
2992 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2993 error "rename should fail"
2998 run_test 52 "Rename across different project ID"
3001 ! is_project_quota_supported &&
3002 skip "Project quota is not supported"
3003 setup_quota_test || error "setup quota failed with $?"
3004 local dir="$DIR/$tdir/dir"
3005 mkdir $dir && change_project -s $dir
3006 lfs project -d $dir | grep P || error "inherit attribute should be set"
3008 change_project -C $dir
3009 lfs project -d $dir | grep P &&
3010 error "inherit attribute should be cleared"
3015 run_test 53 "Project inherit attribute could be cleared"
3018 ! is_project_quota_supported &&
3019 skip "Project quota is not supported"
3020 setup_quota_test || error "setup quota failed with $?"
3021 trap cleanup_quota_test EXIT
3022 local testfile="$DIR/$tdir/$tfile-0"
3024 #set project ID/inherit attribute
3025 change_project -sp $TSTPRJID $DIR/$tdir
3026 $RUNAS createmany -m ${testfile} 100 ||
3027 error "create many files failed"
3029 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3030 # one more count for directory itself */
3034 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3035 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3037 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3038 [ $proj_count1 -eq $proj_count ] ||
3039 error "c2: expected $proj_count got $proj_count1"
3041 #clear project but with kept projid
3042 change_project -rCk $DIR/$tdir
3043 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3044 [ $proj_count1 -eq 1 ] ||
3045 error "c3: expected 1 got $proj_count1"
3047 #verify projid untouched.
3048 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3050 [ $proj_count1 -eq $proj_count ] ||
3051 error "c4: expected $proj_count got $proj_count1"
3054 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3055 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3056 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3058 #this time clear all
3059 change_project -rC $DIR/$tdir
3060 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3061 [ $proj_count1 -eq 0 ] ||
3062 error "c6: expected 0 got $proj_count1"
3064 unlinkmany ${testfile} 100 ||
3065 error "unlink many files failed"
3069 run_test 54 "basic lfs project interface test"
3072 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3073 skip "Not supported before 2.10.58."
3074 setup_quota_test || error "setup quota failed with $?"
3076 set_ost_qtype $QTYPE || error "enable ost quota failed"
3079 #add second group to TSTUSR
3080 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3083 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3084 error "failed to dd"
3086 cancel_lru_locks osc
3087 sync; sync_all_data || true
3089 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3090 error "failed to setquota on group $TSTUSR2"
3092 $LFS quota -v -g $TSTUSR2 $DIR
3094 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3095 error "chgrp should failed with -EDQUOT"
3097 USED=$(getquota -g $TSTUSR2 global curspace)
3100 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3101 error "failed to setquota on group $TSTUSR2"
3103 $LFS quota -v -g $TSTUSR2 $DIR
3105 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3106 error "chgrp should succeed"
3108 $LFS quota -v -g $TSTUSR2 $DIR
3110 resetquota -g $TSTUSR2
3113 run_test 55 "Chgrp should be affected by group quota"
3116 setup_quota_test || error "setup quota failed with $?"
3118 set_ost_qtype $QTYPE || error "enable ost quota failed"
3121 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3122 erro "failed to set grace time for usr quota"
3123 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3124 awk '{print $4 $8}')
3125 if [ "x$grace_time" != "x10s;10s" ]; then
3126 $LFS quota -t -u $DIR
3127 error "expected grace time: 10s;10s, got:$grace_time"
3132 run_test 56 "lfs quota -t should work well"
3135 setup_quota_test || error "setup quota failed with $?"
3137 local dir="$DIR/$tdir/dir"
3140 #try to change pipe file should not hang and return failure
3141 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3142 awk -F ':' '{ print \\\$2 }'" \
3143 " unable to get xattr for fifo '$dir/pipe'" || return 1
3144 #command can process further if it hit some errors
3145 touch $dir/aaa $dir/bbb
3146 mkdir $dir/subdir -p
3147 touch $dir/subdir/aaa $dir/subdir/bbb
3148 #create one invalid link file
3149 ln -s $dir/not_exist_file $dir/ccc
3150 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3151 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3155 run_test 57 "lfs project could tolerate errors"
3158 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3159 skip "ldiskfs only test"
3160 disable_project_quota
3161 setup_quota_test || error "setup quota failed with $?"
3164 local testfile="$DIR/$tdir/$tfile-0"
3165 #make sure it did not crash kernel
3166 touch $testfile && lfs project -sp 1 $testfile
3168 enable_project_quota
3171 run_test 59 "lfs project dosen't crash kernel with project disabled"
3174 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3175 skip "Needs MDS version 2.11.53 or later."
3176 setup_quota_test || error "setup quota failed with $?"
3177 trap cleanup_quota_test EXIT
3179 local testfile=$DIR/$tdir/$tfile
3182 set_mdt_qtype "ug" || error "enable mdt quota failed"
3184 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3185 error "set quota failed"
3186 quota_show_check a g $TSTUSR
3188 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3189 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3190 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3191 error "create many files failed"
3193 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3195 # root user can overrun quota
3196 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3197 error "root user should succeed"
3200 resetquota -g $TSTUSR
3202 run_test 60 "Test quota for root with setgid"
3204 # test default quota
3205 test_default_quota() {
3206 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3207 skip "Not supported before 2.11.51."
3212 local qprjid=$TSTPRJID
3216 local LIMIT=20480 #20M disk space
3217 local TESTFILE="$DIR/$tdir/$tfile-0"
3219 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3220 echo "Project quota is not supported" && return 0
3222 [ $qtype == "-u" ] && qdtype="-U"
3223 [ $qtype == "-g" ] && qdtype="-G"
3224 [ $qtype == "-p" ] && {
3229 [ $qpool == "meta" ] && {
3230 LIMIT=10240 #10K inodes
3235 setup_quota_test || error "setup quota failed with $?"
3236 trap cleanup_quota_test EXIT
3240 # enable mdt/ost quota
3241 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3242 set_ost_qtype $QTYPE || error "enable ost quota failed"
3244 log "set to use default quota"
3245 $LFS setquota $qtype $qid -d $DIR ||
3246 error "set $qid to use default quota failed"
3248 log "set default quota"
3249 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3250 error "set $qid default quota failed"
3252 log "get default quota"
3253 $LFS quota $qdtype $DIR || error "get default quota failed"
3255 if [ $qpool == "data" ]; then
3256 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3258 [ $SLIMIT -eq $LIMIT ] ||
3259 error "the returned default quota is wrong"
3261 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3263 [ $SLIMIT -eq $LIMIT ] ||
3264 error "the returned default quota is wrong"
3267 # make sure the system is clean
3268 local USED=$(getquota $qtype $qid global curspace)
3269 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3271 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3272 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3274 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3276 log "Test not out of quota"
3277 if [ $qpool == "data" ]; then
3278 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3279 quota_error $qtype $qid "write failed, expect succeed"
3281 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3282 quota_error $qtype $qid "create failed, expect succeed"
3284 unlinkmany $TESTFILE $((LIMIT/2))
3287 log "Test out of quota"
3288 # flush cache, ensure noquota flag is set on client
3289 cancel_lru_locks osc
3290 cancel_lru_locks mdc
3291 sync; sync_all_data || true
3292 if [ $qpool == "data" ]; then
3293 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3294 quota_error $qtype $qid "write succeed, expect EDQUOT"
3296 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3297 quota_error $qtype $qid "create succeed, expect EDQUOT"
3299 unlinkmany $TESTFILE $((LIMIT*2))
3302 log "Increase default quota"
3303 # increase default quota
3304 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3305 error "set default quota failed"
3307 cancel_lru_locks osc
3308 cancel_lru_locks mdc
3309 sync; sync_all_data || true
3310 if [ $qpool == "data" ]; then
3311 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3312 quota_error $qtype $qid "write failed, expect succeed"
3314 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3315 quota_error $qtype $qid "create failed, expect succeed"
3317 unlinkmany $TESTFILE $((LIMIT*2))
3320 log "Set quota to override default quota"
3321 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3322 error "set $qid quota failed"
3324 cancel_lru_locks osc
3325 cancel_lru_locks mdc
3326 sync; sync_all_data || true
3327 if [ $qpool == "data" ]; then
3328 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3329 quota_error $qtype $qid "write succeed, expect EQUOT"
3331 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3332 quota_error $qtype $qid "create succeed, expect EQUOT"
3334 unlinkmany $TESTFILE $((LIMIT*2))
3337 log "Set to use default quota again"
3338 $LFS setquota $qtype $qid -d $DIR ||
3339 error "set $qid to use default quota failed"
3341 cancel_lru_locks osc
3342 cancel_lru_locks mdc
3343 sync; sync_all_data || true
3344 if [ $qpool == "data" ]; then
3345 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3346 quota_error $qtype $qid "write failed, expect succeed"
3348 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3349 quota_error $qtype $qid "create failed, expect succeed"
3351 unlinkmany $TESTFILE $((LIMIT*2))
3356 wait_delete_completed || error "wait_delete_completed failed"
3357 sync_all_data || true
3358 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3359 error "reset default quota failed"
3360 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3361 error "reset quota failed"
3367 test_default_quota "-u" "data"
3368 test_default_quota "-u" "meta"
3369 test_default_quota "-g" "data"
3370 test_default_quota "-g" "meta"
3371 test_default_quota "-p" "data"
3372 test_default_quota "-p" "meta"
3374 run_test 61 "default quota tests"
3377 ! is_project_quota_supported &&
3378 skip "Project quota is not supported"
3379 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3380 skip "chattr did not support project quota"
3381 setup_quota_test || error "setup quota failed with $?"
3382 local testdir=$DIR/$tdir/
3384 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3385 change_project -s $testdir
3386 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3387 error "inherit attribute should be set"
3388 # chattr used FS_IOC_SETFLAGS ioctl
3389 $RUNAS chattr -P $testdir &&
3390 error "regular user clear inherit should fail"
3391 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3392 error "inherit attribute should still be set"
3393 chattr -P $testdir || error "root failed to clear inherit"
3394 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3395 error "inherit attribute should be cleared"
3398 run_test 62 "Project inherit should be only changed by root"
3401 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3402 skip "Not supported before 2.11.55" && return
3406 local dd_failed=false
3407 local tdir_dom=${tdir}_dom
3408 local LIMIT=20480 #20M
3410 [ $qtype == "p" ] && ! is_project_quota_supported &&
3411 echo "Project quota is not supported" && return 0
3413 [ $qtype == "p" ] && qid=$TSTPRJID
3415 setup_quota_test || error "setup quota failed with $?"
3416 trap cleanup_quota_test EXIT
3420 # enable mdt/ost quota
3421 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3422 set_ost_qtype $QTYPE || error "enable ost quota failed"
3424 # make sure the system is clean
3425 local USED=$(getquota -$qtype $qid global curspace)
3426 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3428 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3430 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3431 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3432 error "setstripe $tdir_dom failed"
3433 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3435 [ $qtype == "p" ] && {
3436 change_project -sp $TSTPRJID $DIR/$tdir
3437 change_project -sp $TSTPRJID $DIR/$tdir_dom
3440 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3441 error "set $qid quota failed"
3443 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3444 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3448 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3450 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3451 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3455 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3457 rm -f $DIR/$tdir_dom/*
3459 # flush cache, ensure noquota flag is set on client
3460 cancel_lru_locks osc
3461 cancel_lru_locks mdc
3462 sync; sync_all_data || true
3466 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3467 quota_error $qtype $qid "write failed, expect succeed"
3469 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3470 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3474 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3477 rm -f $DIR/$tdir_dom/*
3479 # flush cache, ensure noquota flag is set on client
3480 cancel_lru_locks osc
3481 cancel_lru_locks mdc
3482 sync; sync_all_data || true
3486 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3487 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3491 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3493 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3494 quota_error $qtype $qid "write succeed, expect EDQUOT"
3497 rm -fr $DIR/$tdir_dom
3499 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3500 error "reset usr quota failed"
3510 run_test 63 "quota on DoM tests"
3513 ! is_project_quota_supported &&
3514 skip "Project quota is not supported"
3515 setup_quota_test || error "setup quota failed with $?"
3516 local dir1="$DIR/$tdir/"
3519 ln -s $dir1/file $dir1/file_link
3521 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3522 error "set symlink file's project should fail"
3524 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3525 error "get symlink file's project should fail"
3529 run_test 64 "lfs project on symlink files should fail"
3532 ! is_project_quota_supported &&
3533 skip "Project quota is not supported"
3534 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
3535 skip "Not supported before 2.12.4"
3536 setup_quota_test || error "setup quota failed with $?"
3537 stack_trap cleanup_quota_test EXIT
3538 local old=$(do_facet mds1 $LCTL get_param -n \
3539 mdt.*.enable_chprojid_gid | head -1)
3540 local testdir=$DIR/$tdir/foo
3542 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3543 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3546 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3547 chown -R $TSTID:$TSTID $testdir
3548 change_project -sp $TSTPRJID $testdir
3549 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3551 $RUNAS lfs project -p 0 $testdir/foo &&
3552 error "nonroot user should fail to set projid"
3554 $RUNAS lfs project -C $testdir/foo &&
3555 error "nonroot user should fail to clear projid"
3557 change_project -C $testdir/foo || error "failed to clear project"
3559 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3560 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3561 "failed to set projid with normal user when enable_chprojid_gid=-1"
3563 $RUNAS lfs project -rC $testdir/ || error \
3564 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3566 touch $testdir/bar || error "failed touch $testdir/bar"
3567 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3568 "normal user should not be able to set projid on root owned file"
3570 change_project -p $TSTPRJID $testdir/bar || error \
3571 "root should be able to change its own file's projid"
3575 run_test 66 "nonroot user can not change project state in default"
3579 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3580 disable_project_quota
3582 reset_quota_settings
3587 check_and_cleanup_lustre
3588 export QUOTA_AUTO=$QUOTA_AUTO_OLD