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
803 $SHOW_QUOTA_INFO_USER
804 $SHOW_QUOTA_INFO_GROUP
805 $SHOW_QUOTA_INFO_PROJID
807 echo "Write before timer goes off"
808 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
809 quota_error a $TSTUSR "write failure, but expect success"
810 OFFSET=$((OFFSET + 1024))
813 wait_grace_time $qtype "block"
818 $SHOW_QUOTA_INFO_USER
819 $SHOW_QUOTA_INFO_GROUP
820 $SHOW_QUOTA_INFO_PROJID
822 echo "Write after timer goes off"
823 # maybe cache write, ignore.
824 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
825 OFFSET=$((OFFSET + 1024))
827 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
828 quota_error a $TSTUSR "write success, but expect EDQUOT"
833 $SHOW_QUOTA_INFO_USER
834 $SHOW_QUOTA_INFO_GROUP
835 $SHOW_QUOTA_INFO_PROJID
837 echo "Unlink file to stop timer"
839 wait_delete_completed
840 sync_all_data || true
845 $SHOW_QUOTA_INFO_USER
846 $SHOW_QUOTA_INFO_GROUP
847 $SHOW_QUOTA_INFO_PROJID
849 $SETSTRIPE $TESTFILE -c 1 -i 0
850 chown $TSTUSR.$TSTUSR $TESTFILE
851 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
854 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
855 quota_error a $TSTUSR "write failure, but expect success"
863 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
866 local TESTFILE=$DIR/$tdir/$tfile-0
868 # get minimum soft qunit size
869 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
870 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
872 set_ost_qtype $QTYPE || error "enable ost quota failed"
874 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
875 # make sure the system is clean
876 local USED=$(getquota -u $TSTUSR global curspace)
877 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
879 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
880 $MAX_IQ_TIME $DIR || error "set user grace time failed"
881 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
882 error "set user quota failed"
884 test_block_soft $TESTFILE $GRACE $LIMIT "u"
885 resetquota -u $TSTUSR
887 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
888 TESTFILE=$DIR/$tdir/$tfile-1
889 # make sure the system is clean
890 USED=$(getquota -g $TSTUSR global curspace)
891 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
893 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
894 $MAX_IQ_TIME $DIR || error "set group grace time failed"
895 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
896 error "set group quota failed"
898 test_block_soft $TESTFILE $GRACE $LIMIT "g"
899 resetquota -g $TSTUSR
901 if is_project_quota_supported; then
902 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
903 TESTFILE=$DIR/$tdir/$tfile-2
904 # make sure the system is clean
905 USED=$(getquota -p $TSTPRJID global curspace)
906 [ $USED -ne 0 ] && error \
907 "Used space($USED) for project $TSTPRJID isn't 0."
909 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
911 error "set project grace time failed"
912 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
913 $DIR || error "set project quota failed"
915 test_block_soft $TESTFILE $GRACE $LIMIT "p"
916 resetquota -p $TSTPRJID
917 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
919 error "restore project grace time failed"
923 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
924 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
925 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
926 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
928 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
937 trap cleanup_quota_test EXIT
938 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
940 echo "Create files to exceed soft limit"
941 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
942 quota_error a $TSTUSR "create failure, but expect success"
943 local trigger_time=$(date +%s)
945 sync_all_data || true
947 local cur_time=$(date +%s)
948 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
949 error "Passed grace time $grace, $trigger_time, $cur_time"
951 echo "Create file before timer goes off"
952 $RUNAS touch ${TESTFILE}_before ||
953 quota_error a $TSTUSR "failed create before timer expired," \
954 "but expect success. $trigger_time, $cur_time"
955 sync_all_data || true
957 wait_grace_time $qtype "file"
962 $SHOW_QUOTA_INFO_USER
963 $SHOW_QUOTA_INFO_GROUP
964 $SHOW_QUOTA_INFO_PROJID
966 echo "Create file after timer goes off"
967 # There is a window that space is accounted in the quota usage but
968 # hasn't been decreased from the pending write, if we acquire quota
969 # in this window, we'll acquire more than we needed.
970 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
971 sync_all_data || true
972 $RUNAS touch ${TESTFILE}_after_3 &&
973 quota_error a $TSTUSR "create after timer expired," \
975 sync_all_data || true
980 $SHOW_QUOTA_INFO_USER
981 $SHOW_QUOTA_INFO_GROUP
982 $SHOW_QUOTA_INFO_PROJID
984 echo "Unlink files to stop timer"
985 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
986 wait_delete_completed
989 $RUNAS touch ${TESTFILE}_xxx ||
990 quota_error a $TSTUSR "touch after timer stop failure," \
992 sync_all_data || true
1000 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
1001 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
1002 local TESTFILE=$DIR/$tdir/$tfile-0
1005 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1007 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1008 # make sure the system is clean
1009 local USED=$(getquota -u $TSTUSR global curinodes)
1010 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1012 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1013 $GRACE $DIR || error "set user grace time failed"
1014 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1015 error "set user quota failed"
1017 test_file_soft $TESTFILE $LIMIT $GRACE "u"
1018 resetquota -u $TSTUSR
1020 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
1021 # make sure the system is clean
1022 USED=$(getquota -g $TSTUSR global curinodes)
1023 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
1025 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1026 $GRACE $DIR || error "set group grace time failed"
1027 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1028 error "set group quota failed"
1029 TESTFILE=$DIR/$tdir/$tfile-1
1031 test_file_soft $TESTFILE $LIMIT $GRACE "g"
1032 resetquota -g $TSTUSR
1034 if is_project_quota_supported; then
1035 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1036 # make sure the system is clean
1037 USED=$(getquota -p $TSTPRJID global curinodes)
1038 [ $USED -ne 0 ] && error \
1039 "Used space($USED) for project $TSTPRJID isn't 0."
1041 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1042 $GRACE $DIR || error "set project grace time failed"
1043 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1044 error "set project quota failed"
1046 TESTFILE=$DIR/$tdir/$tfile-1
1047 # one less than limit, because of parent directory included.
1048 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1049 resetquota -p $TSTPRJID
1050 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1051 $MAX_IQ_TIME $DIR ||
1052 error "restore project grace time failed"
1056 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1057 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1058 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1059 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1061 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1064 local GR_STR1="1w3d"
1065 local GR_STR2="1000s"
1067 local GR_STR4="1w2d3h4m5s"
1069 local GR_STR6="18446744073709551615"
1072 wait_delete_completed
1074 # test of valid grace strings handling
1075 echo "Valid grace strings test"
1076 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1077 $GR_STR2 $DIR || error "set user grace time failed"
1078 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1079 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1080 $GR_STR4 $DIR || error "set group grace time quota failed"
1081 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1083 # test of invalid grace strings handling
1084 echo " Invalid grace strings test"
1085 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1086 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1087 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1091 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1092 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1093 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1094 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1096 run_test 4b "Grace time strings handling"
1098 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1100 local BLIMIT=10 # 10M
1101 local ILIMIT=10 # 10 inodes
1103 setup_quota_test || error "setup quota failed with $?"
1104 trap cleanup_quota_test EXIT
1106 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1107 set_ost_qtype $QTYPE || error "enable ost quota failed"
1109 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1110 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1111 error "set user quota failed"
1112 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1113 if is_project_quota_supported; then
1114 error "set group quota failed"
1115 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1116 -I $ILIMIT $DIR || error "set project quota failed"
1119 # make sure the system is clean
1120 local USED=$(getquota -u $TSTUSR global curinodes)
1121 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1122 USED=$(getquota -g $TSTUSR global curinodes)
1123 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1124 USED=$(getquota -u $TSTUSR global curspace)
1125 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1126 USED=$(getquota -g $TSTUSR global curspace)
1127 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1128 if is_project_quota_supported; then
1129 USED=$(getquota -p $TSTPRJID global curinodes)
1131 error "Used inode($USED) for project $TSTPRJID isn't 0."
1132 USED=$(getquota -p $TSTPRJID global curspace)
1134 error "Used block($USED) for project $TSTPRJID isn't 0."
1137 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1138 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1139 error "create failure, expect success"
1140 if is_project_quota_supported; then
1141 touch $DIR/$tdir/$tfile-0_1
1142 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1144 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1145 error "write failure, expect success"
1147 echo "Chown files to $TSTUSR.$TSTUSR ..."
1148 for i in $(seq 0 $ILIMIT); do
1149 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1150 quota_error a $TSTUSR "chown failure, expect success"
1154 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1155 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1158 resetquota -u $TSTUSR
1159 resetquota -g $TSTUSR
1160 resetquota -p $TSTPRJID
1162 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1164 # test dropping acquire request on master
1168 # Clear dmesg so watchdog is not triggered by previous
1170 do_facet ost1 dmesg -c > /dev/null
1172 setup_quota_test || error "setup quota failed with $?"
1173 trap cleanup_quota_test EXIT
1175 # make sure the system is clean
1176 local USED=$(getquota -u $TSTUSR global curspace)
1177 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1179 # make sure no granted quota on ost
1180 set_ost_qtype $QTYPE || error "enable ost quota failed"
1181 resetquota -u $TSTUSR
1183 # create file for $TSTUSR
1184 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1185 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1186 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1188 # create file for $TSTUSR2
1189 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1190 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1191 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1193 # cache per-ID lock for $TSTUSR on slave
1194 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1195 error "set quota failed"
1196 $RUNAS $DD of=$TESTFILE count=1 ||
1197 error "write $TESTFILE failure, expect success"
1198 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1199 error "write $TESTFILE2 failure, expect success"
1201 sync_all_data || true
1203 #define QUOTA_DQACQ 601
1204 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1205 lustre_fail mds 0x513 601
1207 if at_is_enabled; then
1208 at_max_saved=$(at_max_get ost1)
1209 at_max_set $TIMEOUT ost1
1212 do_facet ost1 $LCTL set_param \
1213 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1215 # write to un-enforced ID ($TSTUSR2) should succeed
1216 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1217 error "write failure, expect success"
1219 # write to enforced ID ($TSTUSR) in background, exceeding limit
1220 # to make sure DQACQ is sent
1221 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1224 # watchdog timer uses a factor of 2
1225 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1226 sleep $((TIMEOUT * 2 + 1))
1228 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1230 # write should be blocked and never finished
1231 if ! ps -p $DDPID > /dev/null 2>&1; then
1233 error "write finished incorrectly!"
1238 # no watchdog is triggered
1239 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1240 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1241 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1242 [ -z "$watchdog" ] || error "$watchdog"
1244 rm -f $TMP/lustre-log-${TESTNAME}.log
1246 # write should continue then fail with EDQUOT
1250 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1251 if [ $count -ge 240 ]; then
1252 quota_error u $TSTUSR "dd not finished in $count secs"
1254 count=$((count + 1))
1255 if [ $((count % 30)) -eq 0 ]; then
1256 c_size=$(stat -c %s $TESTFILE)
1257 echo "Waiting $count secs. $c_size"
1264 resetquota -u $TSTUSR
1266 run_test 6 "Test dropping acquire request on master"
1268 # quota reintegration (global index)
1270 local TESTFILE=$DIR/$tdir/$tfile
1271 local LIMIT=20 # 20M
1273 [ "$SLOW" = "no" ] && LIMIT=5
1275 setup_quota_test || error "setup quota failed with $?"
1276 trap cleanup_quota_test EXIT
1278 # make sure the system is clean
1279 local USED=$(getquota -u $TSTUSR global curspace)
1280 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1282 # make sure no granted quota on ost1
1283 set_ost_qtype $QTYPE || error "enable ost quota failed"
1284 resetquota -u $TSTUSR
1285 set_ost_qtype "none" || error "disable ost quota failed"
1287 local OSTUUID=$(ostuuid_from_index 0)
1288 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1290 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1293 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1294 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1299 echo "Enable quota & set quota limit for $TSTUSR"
1300 set_ost_qtype $QTYPE || error "enable ost quota failed"
1301 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1302 error "set quota failed"
1304 echo "Start ost1..."
1305 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1308 wait_ost_reint $QTYPE || error "reintegration failed"
1310 # hardlimit should have been fetched by slave during global
1311 # reintegration, write will exceed quota
1312 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1313 quota_error u $TSTUSR "write success, but expect EDQUOT"
1316 wait_delete_completed
1317 sync_all_data || true
1323 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1324 error "clear quota failed"
1326 echo "Start ost1..."
1327 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1330 wait_ost_reint $QTYPE || error "reintegration failed"
1332 # hardlimit should be cleared on slave during reintegration
1333 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1334 quota_error u $TSTUSR "write error, but expect success"
1337 resetquota -u $TSTUSR
1339 run_test 7a "Quota reintegration (global index)"
1341 # quota reintegration (slave index)
1344 local TESTFILE=$DIR/$tdir/$tfile
1346 setup_quota_test || error "setup quota failed with $?"
1347 trap cleanup_quota_test EXIT
1349 # make sure the system is clean
1350 local USED=$(getquota -u $TSTUSR global curspace)
1351 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1353 # make sure no granted quota on ost1
1354 set_ost_qtype $QTYPE || error "enable ost quota failed"
1355 resetquota -u $TSTUSR
1356 set_ost_qtype "none" || error "disable ost quota failed"
1358 local OSTUUID=$(ostuuid_from_index 0)
1359 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1361 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1364 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1365 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1367 # consume some space to make sure the granted space will not
1368 # be released during reconciliation
1369 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1370 error "consume space failure, expect success"
1372 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1373 lustre_fail mds 0xa02
1375 set_ost_qtype $QTYPE || error "enable ost quota failed"
1376 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1377 error "set quota failed"
1379 # ignore the write error
1380 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1382 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1386 echo "Restart ost to trigger reintegration..."
1388 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1391 wait_ost_reint $QTYPE || error "reintegration failed"
1393 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1394 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1397 resetquota -u $TSTUSR
1400 run_test 7b "Quota reintegration (slave index)"
1402 # quota reintegration (restart mds during reintegration)
1404 local LIMIT=20 # 20M
1405 local TESTFILE=$DIR/$tdir/$tfile
1407 [ "$SLOW" = "no" ] && LIMIT=5
1409 setup_quota_test || error "setup quota failed with $?"
1410 trap cleanup_quota_test EXIT
1412 # make sure the system is clean
1413 local USED=$(getquota -u $TSTUSR global curspace)
1414 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1416 set_ost_qtype "none" || error "disable ost quota failed"
1417 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1418 error "set quota failed"
1420 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1421 lustre_fail ost 0xa03
1424 set_ost_qtype $QTYPE || error "enable ost quota failed"
1425 # trigger reintegration
1426 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1427 procf=${procf}quota_slave.force_reint
1428 do_facet ost1 $LCTL set_param $procf=1 ||
1429 error "force reintegration failed"
1437 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1440 # wait longer than usual to make sure the reintegration
1441 # is triggered by quota wb thread.
1442 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1444 # hardlimit should have been fetched by slave during global
1445 # reintegration, write will exceed quota
1446 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1447 quota_error u $TSTUSR "write success, but expect EDQUOT"
1450 resetquota -u $TSTUSR
1452 run_test 7c "Quota reintegration (restart mds during reintegration)"
1454 # Quota reintegration (Transfer index in multiple bulks)
1456 local TESTFILE=$DIR/$tdir/$tfile
1457 local TESTFILE1="$DIR/$tdir/$tfile"-1
1460 setup_quota_test || error "setup quota failed with $?"
1461 trap cleanup_quota_test EXIT
1463 set_ost_qtype "none" || error "disable ost quota failed"
1464 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1465 error "set quota for $TSTUSR failed"
1466 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1467 error "set quota for $TSTUSR2 failed"
1469 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1470 lustre_fail mds 0x608 0
1472 # enable quota to tirgger reintegration
1473 set_ost_qtype "u" || error "enable ost quota failed"
1474 wait_ost_reint "u" || error "reintegration failed"
1478 # hardlimit should have been fetched by slave during global
1479 # reintegration, write will exceed quota
1480 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1481 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1483 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1484 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1487 resetquota -u $TSTUSR
1488 resetquota -u $TSTUSR2
1490 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1492 # quota reintegration (inode limits)
1494 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1496 # LU-2435: skip this quota test if underlying zfs version has not
1497 # supported native dnode accounting
1498 [ "$(facet_fstype mds1)" == "zfs" ] && {
1499 local F="feature@userobj_accounting"
1500 local pool=$(zpool_name mds1)
1501 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1503 [[ "$feature" != *" active "* ]] &&
1504 skip "requires zpool with active userobj_accounting"
1507 local ilimit=$((1024 * 2)) # 2k inodes
1508 local TESTFILE=$DIR/${tdir}-1/$tfile
1510 setup_quota_test || error "setup quota failed with $?"
1511 trap cleanup_quota_test EXIT
1513 # make sure the system is clean
1514 local USED=$(getquota -u $TSTUSR global curinodes)
1515 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1517 # make sure no granted quota on mdt1
1518 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1519 resetquota -u $TSTUSR
1520 set_mdt_qtype "none" || error "disable mdt quota failed"
1522 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1523 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1524 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1527 echo "Stop mds${MDSCOUNT}..."
1530 echo "Enable quota & set quota limit for $TSTUSR"
1531 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1532 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1533 error "set quota failed"
1535 echo "Start mds${MDSCOUNT}..."
1536 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1539 wait_mdt_reint $QTYPE || error "reintegration failed"
1541 echo "create remote dir"
1542 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1543 error "create remote dir failed"
1544 chmod 0777 $DIR/${tdir}-1
1546 # hardlimit should have been fetched by slave during global
1547 # reintegration, create will exceed quota
1548 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1549 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1551 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1552 wait_delete_completed
1553 sync_all_data || true
1555 echo "Stop mds${MDSCOUNT}..."
1558 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1559 error "clear quota failed"
1561 echo "Start mds${MDSCOUNT}..."
1562 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1565 wait_mdt_reint $QTYPE || error "reintegration failed"
1567 # hardlimit should be cleared on slave during reintegration
1568 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1569 quota_error u $TSTUSR "create failed, expect success"
1571 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1572 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1575 resetquota -u $TSTUSR
1577 run_test 7e "Quota reintegration (inode limits)"
1579 # run dbench with quota enabled
1581 local BLK_LIMIT="100g" #100G
1582 local FILE_LIMIT=1000000
1584 setup_quota_test || error "setup quota failed with $?"
1585 trap cleanup_quota_test EXIT
1587 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1588 set_ost_qtype $QTYPE || error "enable ost quota failed"
1590 echo "Set enough high limit for user: $TSTUSR"
1591 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1592 error "set user quota failed"
1593 echo "Set enough high limit for group: $TSTUSR"
1594 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1595 error "set group quota failed"
1596 if is_project_quota_supported; then
1597 change_project -sp $TSTPRJID $DIR/$tdir
1598 echo "Set enough high limit for project: $TSTPRJID"
1599 $LFS setquota -p $TSTPRJID -b 0 \
1600 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set project quota failed"
1605 [ "$SLOW" = "no" ] && duration=" -t 120"
1606 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1607 quota_error a $TSTUSR "dbench failed!"
1609 is_project_quota_supported && change_project -C $DIR/$tdir
1611 resetquota -u $TSTUSR
1612 resetquota -g $TSTUSR
1613 resetquota -p $TSTPRJID
1615 run_test 8 "Run dbench with quota enabled"
1617 # this check is just for test_9
1618 OST0_MIN=4900000 #4.67G
1620 check_whether_skip () {
1621 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1622 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1623 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1624 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1631 # run for fixing bug10707, it needs a big room. test for 64bit
1633 local filesize=$((1024 * 9 / 2)) # 4.5G
1635 check_whether_skip && return 0
1637 setup_quota_test || error "setup quota failed with $?"
1638 trap cleanup_quota_test EXIT
1640 set_ost_qtype "ug" || error "enable ost quota failed"
1642 local TESTFILE="$DIR/$tdir/$tfile-0"
1643 local BLK_LIMIT=100G #100G
1644 local FILE_LIMIT=1000000
1646 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1648 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1650 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1651 error "set user quota failed"
1653 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1654 "for group: $TSTUSR"
1655 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1656 error "set group quota failed"
1658 quota_show_check a u $TSTUSR
1659 quota_show_check a g $TSTUSR
1661 echo "Create test file"
1662 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1663 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1665 log "Write the big file of 4.5G ..."
1666 $RUNAS $DD of=$TESTFILE count=$filesize ||
1667 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1673 resetquota -u $TSTUSR
1674 resetquota -g $TSTUSR
1679 run_test 9 "Block limit larger than 4GB (b10707)"
1682 local TESTFILE=$DIR/$tdir/$tfile
1684 setup_quota_test || error "setup quota failed with $?"
1685 trap cleanup_quota_test EXIT
1687 # set limit to root user should fail
1688 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1689 error "set limit for root user successfully, expect failure"
1690 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1691 error "set limit for root group successfully, expect failure"
1692 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1693 error "set limit for project 0 successfully, expect failure"
1695 # root user can overrun quota
1696 set_ost_qtype "ug" || error "enable ost quota failed"
1698 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1699 error "set quota failed"
1700 quota_show_check b u $TSTUSR
1702 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1703 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1705 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1706 error "write failure, expect success"
1709 resetquota -u $TSTUSR
1711 run_test 10 "Test quota for root user"
1714 local TESTFILE=$DIR/$tdir/$tfile
1715 setup_quota_test || error "setup quota failed with $?"
1716 trap cleanup_quota_test EXIT
1718 set_mdt_qtype "ug" || error "enable mdt quota failed"
1719 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1720 error "set quota failed"
1722 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1723 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1725 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1726 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1729 local USED=$(getquota -u $TSTUSR global curinodes)
1730 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1733 resetquota -u $TSTUSR
1735 run_test 11 "Chown/chgrp ignores quota"
1738 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1740 local blimit=22 # 22M
1741 local blk_cnt=$((blimit - 5))
1742 local TESTFILE0="$DIR/$tdir/$tfile"-0
1743 local TESTFILE1="$DIR/$tdir/$tfile"-1
1745 setup_quota_test || error "setup quota failed with $?"
1746 trap cleanup_quota_test EXIT
1748 set_ost_qtype "u" || error "enable ost quota failed"
1749 quota_show_check b u $TSTUSR
1751 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1752 error "set quota failed"
1754 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1755 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1756 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1757 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1759 echo "Write to ost0..."
1760 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1761 quota_error a $TSTUSR "dd failed"
1763 echo "Write to ost1..."
1764 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1765 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1767 echo "Free space from ost0..."
1769 wait_delete_completed
1770 sync_all_data || true
1772 echo "Write to ost1 after space freed from ost0..."
1773 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1774 quota_error a $TSTUSR "rebalancing failed"
1777 resetquota -u $TSTUSR
1779 run_test 12a "Block quota rebalancing"
1782 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1784 local ilimit=$((1024 * 2)) # 2k inodes
1785 local TESTFILE0=$DIR/$tdir/$tfile
1786 local TESTFILE1=$DIR/${tdir}-1/$tfile
1788 setup_quota_test || error "setup quota failed with $?"
1789 trap cleanup_quota_test EXIT
1791 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1792 chmod 0777 $DIR/${tdir}-1
1794 set_mdt_qtype "u" || error "enable mdt quota failed"
1795 quota_show_check f u $TSTUSR
1797 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1798 error "set quota failed"
1800 echo "Create $ilimit files on mdt0..."
1801 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1802 quota_error u $TSTUSR "create failed, but expect success"
1804 echo "Create files on mdt1..."
1805 $RUNAS createmany -m $TESTFILE1 1 &&
1806 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1808 echo "Free space from mdt0..."
1809 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1810 wait_delete_completed
1811 sync_all_data || true
1813 echo "Create files on mdt1 after space freed from mdt0..."
1814 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1815 quota_error a $TSTUSR "rebalancing failed"
1817 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1818 error "unlink mdt1 files failed"
1819 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1822 resetquota -u $TSTUSR
1824 run_test 12b "Inode quota rebalancing"
1827 local TESTFILE=$DIR/$tdir/$tfile
1828 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1829 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1831 setup_quota_test || error "setup quota failed with $?"
1832 trap cleanup_quota_test EXIT
1834 set_ost_qtype "u" || error "enable ost quota failed"
1835 quota_show_check b u $TSTUSR
1837 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1838 error "set quota failed"
1839 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1840 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1842 # clear the locks in cache first
1843 do_facet ost1 $LCTL set_param -n $procf=clear
1844 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1845 [ $nlock -eq 0 ] || error "$nlock cached locks"
1847 # write to acquire the per-ID lock
1848 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1849 quota_error a $TSTUSR "dd failed"
1851 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1852 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1854 # clear quota doesn't trigger per-ID lock cancellation
1855 resetquota -u $TSTUSR
1856 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1857 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1859 # clear the per-ID lock
1860 do_facet ost1 $LCTL set_param -n $procf=clear
1861 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1862 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1864 # spare quota should be released
1865 local OSTUUID=$(ostuuid_from_index 0)
1866 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1867 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1868 [ $limit -le $space ] ||
1869 error "spare quota isn't released, limit:$limit, space:$space"
1873 run_test 13 "Cancel per-ID lock in the LRU list"
1876 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1878 wait_delete_completed
1879 sync_all_data || true
1882 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1883 error "set user quota failed"
1884 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1885 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1886 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1887 resetquota -u $TSTUSR
1890 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1891 error "set group quota failed"
1892 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1893 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1894 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1895 resetquota -g $TSTUSR
1897 run_test 15 "Set over 4T block quota"
1901 local BLKS=1 # 1M less than limit
1902 local TESTFILE=$DIR/$tdir/$tfile
1904 setup_quota_test || error "setup quota failed with $?"
1905 trap cleanup_quota_test EXIT
1907 # make sure the system is clean
1908 local USED=$(getquota -u $TSTUSR global curspace)
1909 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1911 set_ost_qtype "ug" || error "enable ost quota failed"
1912 # make sure no granted quota on ost
1913 resetquota -u $TSTUSR
1914 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1915 error "set quota failed"
1917 quota_show_check b u $TSTUSR
1919 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1920 lustre_fail mds 0xa04 $err_code
1922 # write in background
1923 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1927 # write should be blocked and never finished
1928 if ! ps -p $DDPID > /dev/null 2>&1; then
1930 quota_error u $TSTUSR "write finished incorrectly!"
1938 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1940 if [ $count -gt $timeout ]; then
1941 quota_error u $TSTUSR "dd is not finished!"
1946 sync; sync_all_data || true
1948 USED=$(getquota -u $TSTUSR global curspace)
1949 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1950 "Used space(${USED}K) is less than ${BLKS}M"
1953 resetquota -u $TSTUSR
1956 # DQACQ return recoverable error
1958 echo "DQACQ return -ENOLCK"
1960 test_17sub 37 || error "Handle -ENOLCK failed"
1962 echo "DQACQ return -EAGAIN"
1964 test_17sub 11 || error "Handle -EAGAIN failed"
1966 echo "DQACQ return -ETIMEDOUT"
1967 #define ETIMEDOUT 110
1968 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1970 echo "DQACQ return -ENOTCONN"
1971 #define ENOTCONN 107
1972 test_17sub 107 || error "Handle -ENOTCONN failed"
1975 run_test 17 "DQACQ return recoverable error"
1979 local blimit="200m" # 200M
1980 local TESTFILE="$DIR/$tdir/$tfile"
1982 setup_quota_test || error "setup quota failed with $?"
1983 trap cleanup_quota_test EXIT
1985 set_ost_qtype "u" || error "enable ost quota failed"
1986 log "User quota (limit: $blimit)"
1987 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1988 error "set quota failed"
1989 quota_show_check b u $TSTUSR
1991 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1992 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1994 local timeout=$(sysctl -n lustre.timeout)
1996 if [ $io_type = "directio" ]; then
1997 log "Write 100M (directio) ..."
1998 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
2000 log "Write 100M (buffered) ..."
2001 $RUNAS $DD of=$TESTFILE count=100 &
2005 replay_barrier $SINGLEMDS
2006 log "Fail mds for $((2 * timeout)) seconds"
2007 fail $SINGLEMDS $((2 * timeout))
2010 if at_is_enabled; then
2011 timeout=$(at_max_get mds)
2013 timeout=$(lctl get_param -n timeout)
2017 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
2018 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
2019 log "it took $count second"
2024 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
2026 cancel_lru_locks mdc
2027 cancel_lru_locks osc
2030 local testfile_size=$(stat -c %s $TESTFILE)
2031 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
2032 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
2033 "got ${testfile_size}. Verifying file failed!"
2036 resetquota -u $TSTUSR
2039 # test when mds does failover, the ost still could work well
2040 # this test shouldn't trigger watchdog b=14840
2042 # Clear dmesg so watchdog is not triggered by previous
2044 do_facet ost1 dmesg -c > /dev/null
2047 test_18_sub directio
2049 # check if watchdog is triggered
2050 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2051 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2052 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2053 [ -z "$watchdog" ] || error "$watchdog"
2054 rm -f $TMP/lustre-log-${TESTNAME}.log
2056 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2060 local TESTFILE=$DIR/$tdir/$tfile
2062 setup_quota_test || error "setup quota failed with $?"
2063 trap cleanup_quota_test EXIT
2065 set_ost_qtype $QTYPE || error "enable ost quota failed"
2067 # bind file to a single OST
2068 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2069 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2071 echo "Set user quota (limit: ${blimit}M)"
2072 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2073 error "set user quota failed"
2074 quota_show_check b u $TSTUSR
2075 echo "Update quota limits"
2076 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2077 error "set group quota failed"
2078 quota_show_check b u $TSTUSR
2080 # first wirte might be cached
2081 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2082 cancel_lru_locks osc
2084 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2085 quota_error u $TSTUSR "Write success, expect failure"
2089 resetquota -u $TSTUSR
2091 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2093 test_20() { # b15754
2094 local LSTR=(2g 1t 4k 3m) # limits strings
2096 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2099 resetquota -u $TSTUSR
2101 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2102 $MOUNT || error "could not set quota limits"
2103 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2104 --inode-softlimit ${LSTR[2]} \
2105 --inode-hardlimit ${LSTR[3]} \
2106 $MOUNT || error "could not set quota limits"
2108 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2109 error "bsoftlimit was not set properly"
2110 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2111 error "bhardlimit was not set properly"
2112 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2113 error "isoftlimit was not set properly"
2114 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2115 error "ihardlimit was not set properly"
2117 resetquota -u $TSTUSR
2119 run_test 20 "Test if setquota specifiers work properly (b15754)"
2126 local time=$(($(date +%s) + seconds))
2127 while [ $(date +%s) -lt $time ]; do
2128 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2132 # run for fixing bug16053, setquota shouldn't fail when writing and
2133 # deleting are happening
2135 local TESTFILE="$DIR/$tdir/$tfile"
2136 local BLIMIT=10 # 10G
2137 local ILIMIT=1000000
2139 setup_quota_test || error "setup quota failed with $?"
2140 trap cleanup_quota_test EXIT
2142 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2144 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2145 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2146 error "set user quota failed"
2147 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2148 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2149 error "set group quota failed"
2150 if is_project_quota_supported; then
2151 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2152 "project: $TSTPRJID"
2153 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2154 $MOUNT || error "set project quota failed"
2157 # repeat writing on a 1M file
2158 test_21_sub ${TESTFILE}_1 1 30 &
2160 # repeat writing on a 128M file
2161 test_21_sub ${TESTFILE}_2 128 30 &
2164 local time=$(($(date +%s) + 30))
2166 while [ $(date +%s) -lt $time ]; do
2167 log "Set quota for $i times"
2168 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2169 -I $((ILIMIT + i)) $MOUNT ||
2170 error "Set user quota failed"
2171 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2172 -I $((ILIMIT + i)) $MOUNT ||
2173 error "Set group quota failed"
2174 if is_project_quota_supported; then
2175 $LFS setquota -p $TSTPRJID -b 0 -B \
2176 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2177 error "Set project quota failed"
2185 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2187 if [ $count -gt 60 ]; then
2188 quota_error a $TSTUSR "dd should be finished!"
2192 echo "(dd_pid=$DDPID1, time=$count)successful"
2196 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2198 if [ $count -gt 60 ]; then
2199 quota_error a $TSTUSR "dd should be finished!"
2203 echo "(dd_pid=$DDPID2, time=$count)successful"
2206 resetquota -u $TSTUSR
2207 resetquota -g $TSTUSR
2208 resetquota -p $TSTPRJID
2210 run_test 21 "Setquota while writing & deleting (b16053)"
2212 # enable/disable quota enforcement permanently
2214 echo "Set both mdt & ost quota type as ug"
2216 is_project_quota_supported && qtype=$QTYPE
2217 set_mdt_qtype $qtype || error "enable mdt quota failed"
2218 set_ost_qtype $qtype || error "enable ost quota failed"
2221 stopall || error "failed to stopall (1)"
2225 echo "Verify if quota is enabled"
2226 local qtype1=$(mdt_quota_type)
2227 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2228 qtype=$(ost_quota_type)
2229 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2231 echo "Set both mdt & ost quota type as none"
2232 set_mdt_qtype "none" || error "disable mdt quota failed"
2233 set_ost_qtype "none" || error "disable ost quota failed"
2236 stopall || error "failed to stopall (2)"
2241 echo "Verify if quota is disabled"
2242 qtype=$(mdt_quota_type)
2243 [ $qtype != "none" ] && error "mdt quota setting is lost"
2244 qtype=$(ost_quota_type)
2245 [ $qtype != "none" ] && error "ost quota setting is lost"
2249 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2252 local TESTFILE="$DIR/$tdir/$tfile"
2255 setup_quota_test || error "setup quota failed with $?"
2256 trap cleanup_quota_test EXIT
2258 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2261 log "User quota (limit: $LIMIT MB)"
2262 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2263 error "set quota failed"
2264 quota_show_check b u $TSTUSR
2266 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2267 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2269 log "Step1: trigger EDQUOT with O_DIRECT"
2270 log "Write half of file"
2271 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2272 quota_error u $TSTUSR "(1) Write failure, expect success." \
2274 log "Write out of block quota ..."
2275 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2276 oflag=direct conv=notrunc &&
2277 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2281 log "Step2: rewrite should succeed"
2282 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2283 quota_error u $TSTUSR "(3) Write failure, expect success." \
2289 local OST0_UUID=$(ostuuid_from_index 0)
2290 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2291 [ $OST0_QUOTA_USED -ne 0 ] &&
2292 ($SHOW_QUOTA_USER; \
2293 quota_error u $TSTUSR "quota isn't released")
2295 resetquota -u $TSTUSR
2299 [ $(facet_fstype ost1) == "zfs" ] &&
2300 skip "Overwrite in place is not guaranteed to be " \
2301 "space neutral on ZFS"
2303 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2304 check_whether_skip && return 0
2305 log "run for 4MB test file"
2308 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2309 check_whether_skip && return 0
2310 log "run for 40MB test file"
2313 run_test 23 "Quota should be honored with directIO (b16125)"
2317 local TESTFILE="$DIR/$tdir/$tfile"
2319 setup_quota_test || error "setup quota failed with $?"
2320 trap cleanup_quota_test EXIT
2322 set_ost_qtype $QTYPE || error "enable ost quota failed"
2324 # bind file to a single OST
2325 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2326 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2328 echo "Set user quota (limit: ${blimit}M)"
2329 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2330 error "set quota failed"
2332 # overrun quota by root user
2333 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2334 error "write failure, expect success"
2335 cancel_lru_locks osc
2336 sync_all_data || true
2338 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2341 resetquota -u $TSTUSR
2343 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2345 test_27a() { # b19612
2346 $LFS quota $TSTUSR $DIR &&
2347 error "lfs succeeded with no type, but should have failed"
2348 $LFS setquota $TSTUSR $DIR &&
2349 error "lfs succeeded with no type, but should have failed"
2352 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2354 test_27b() { # b20200
2355 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2356 error "lfs setquota failed with uid argument"
2357 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2358 error "lfs stequota failed with gid argument"
2359 if is_project_quota_supported; then
2360 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2361 1000 $DIR || error \
2362 "lfs stequota failed with projid argument"
2364 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2365 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2366 if is_project_quota_supported; then
2367 $SHOW_QUOTA_PROJID ||
2368 error "lfs quota failed with projid argument"
2370 resetquota -u $TSTUSR
2371 resetquota -g $TSTUSR
2372 resetquota -p $TSTPRJID
2375 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2380 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2381 error "lfs setquota failed"
2383 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2384 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2385 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2386 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2388 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2389 error "lfs setquota for $TSTID failed"
2391 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2392 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2393 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2394 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2396 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2397 error "total allocated inode/block limit not printed"
2399 resetquota -u $TSTUSR
2401 run_test 27c "lfs quota should support human-readable output"
2408 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2409 error "set fraction block limit failed"
2410 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2411 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2412 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2413 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2415 resetquota -u $TSTUSR
2417 run_test 27d "lfs setquota should support fraction block limit"
2421 local TESTFILE="$DIR/$tdir/$tfile"
2424 setup_quota_test || error "setup quota failed with $?"
2425 trap cleanup_quota_test EXIT
2427 set_ost_qtype "u" || error "enable ost quota failed"
2429 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2430 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2432 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2433 $MAX_IQ_TIME $DIR || error "set grace time failed"
2434 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2435 error "set quota failed"
2436 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2437 cancel_lru_locks osc
2439 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2440 # over-quota flag has not yet settled since we do not trigger async
2441 # events based on grace time period expiration
2443 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2444 cancel_lru_locks osc
2445 # now over-quota flag should be settled and further writes should fail
2447 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2448 error "grace times were reset"
2451 resetquota -u $TSTUSR
2452 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2453 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2455 run_test 30 "Hard limit updates should not reset grace times"
2457 # basic usage tracking for user & group
2459 local INODES=10 # 10 files
2460 local BLK_CNT=2 # of 2M each
2461 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2463 setup_quota_test || error "setup quota failed with $?"
2464 trap cleanup_quota_test EXIT
2466 # make sure the system is clean
2467 local USED=$(getquota -u $TSTID global curspace)
2469 error "Used space ($USED) for user $TSTID isn't 0."
2470 USED=$(getquota -g $TSTID global curspace)
2472 error "Used space ($USED) for group $TSTID isn't 0."
2473 if is_project_quota_supported; then
2474 USED=$(getquota -p $TSTPRJID global curspace)
2475 [ $USED -ne 0 ] && error \
2476 "Used space ($USED) for project $TSTPRJID isn't 0."
2479 echo "Write files..."
2480 for i in $(seq 0 $INODES); do
2481 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2482 error "write failed"
2483 is_project_quota_supported &&
2484 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2485 echo "Iteration $i/$INODES completed"
2487 cancel_lru_locks osc
2489 echo "Wait for setattr on objects finished..."
2490 wait_delete_completed
2492 sync; sync_all_data || true
2494 echo "Verify disk usage after write"
2495 USED=$(getquota -u $TSTID global curspace)
2496 [ $USED -lt $TOTAL_BLKS ] &&
2497 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2498 USED=$(getquota -g $TSTID global curspace)
2499 [ $USED -lt $TOTAL_BLKS ] &&
2500 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2501 if is_project_quota_supported; then
2502 USED=$(getquota -p $TSTPRJID global curspace)
2503 [ $USED -lt $TOTAL_BLKS ] && error \
2504 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2507 echo "Verify inode usage after write"
2508 USED=$(getquota -u $TSTID global curinodes)
2509 [ $USED -lt $INODES ] &&
2510 error "Used inode for user $TSTID is $USED, expected $INODES"
2511 USED=$(getquota -g $TSTID global curinodes)
2512 [ $USED -lt $INODES ] &&
2513 error "Used inode for group $TSTID is $USED, expected $INODES"
2514 if is_project_quota_supported; then
2515 USED=$(getquota -p $TSTPRJID global curinodes)
2516 [ $USED -lt $INODES ] && error \
2517 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2522 echo "Verify disk usage after delete"
2523 USED=$(getquota -u $TSTID global curspace)
2524 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2525 USED=$(getquota -u $TSTID global curinodes)
2526 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2527 USED=$(getquota -g $TSTID global curspace)
2528 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2529 USED=$(getquota -g $TSTID global curinodes)
2530 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2531 if is_project_quota_supported; then
2532 USED=$(getquota -p $TSTPRJID global curspace)
2534 error "Used space for project $TSTPRJID isn't 0. $USED"
2535 USED=$(getquota -p $TSTPRJID global curinodes)
2537 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2540 run_test 33 "Basic usage tracking for user & group & project"
2542 # usage transfer test for user & group & project
2544 local BLK_CNT=2 # 2MB
2545 local project_supported="no"
2547 is_project_quota_supported && project_supported="yes"
2548 setup_quota_test || error "setup quota failed with $?"
2549 trap cleanup_quota_test EXIT
2551 # make sure the system is clean
2552 local USED=$(getquota -u $TSTID global curspace)
2553 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2554 USED=$(getquota -g $TSTID global curspace)
2555 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2557 local USED=$(getquota -u $TSTID2 global curspace)
2558 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2559 if [ $project_supported == "yes" ]; then
2560 USED=$(getquota -p $TSTPRJID global curspace)
2561 [ $USED -ne 0 ] && error \
2562 "Used space ($USED) for Project $TSTPRJID isn't 0."
2565 echo "Write file..."
2566 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2567 error "write failed"
2568 cancel_lru_locks osc
2569 sync; sync_all_data || true
2571 echo "chown the file to user $TSTID"
2572 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2574 echo "Wait for setattr on objects finished..."
2575 wait_delete_completed
2577 BLK_CNT=$((BLK_CNT * 1024))
2579 echo "Verify disk usage for user $TSTID"
2580 USED=$(getquota -u $TSTID global curspace)
2581 [ $USED -lt $BLK_CNT ] &&
2582 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2583 USED=$(getquota -u $TSTID global curinodes)
2585 error "Used inodes for user $TSTID is $USED, expected 1"
2587 echo "chgrp the file to group $TSTID"
2588 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2590 echo "Wait for setattr on objects finished..."
2591 wait_delete_completed
2593 echo "Verify disk usage for group $TSTID"
2594 USED=$(getquota -g $TSTID global curspace)
2595 [ $USED -ge $BLK_CNT ] ||
2596 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2597 USED=$(getquota -g $TSTID global curinodes)
2599 error "Used inodes for group $TSTID is $USED, expected 1"
2601 # chown won't change the ost object group. LU-4345 */
2602 echo "chown the file to user $TSTID2"
2603 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2605 echo "Wait for setattr on objects finished..."
2606 wait_delete_completed
2608 echo "change_project project id to $TSTPRJID"
2609 [ $project_supported == "yes" ] &&
2610 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2611 echo "Wait for setattr on objects finished..."
2612 wait_delete_completed
2614 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2615 USED=$(getquota -u $TSTID2 global curspace)
2616 [ $USED -lt $BLK_CNT ] &&
2617 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2618 USED=$(getquota -u $TSTID global curspace)
2620 error "Used space for user $TSTID is $USED, expected 0"
2621 USED=$(getquota -g $TSTID global curspace)
2622 [ $USED -lt $BLK_CNT ] &&
2623 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2624 if [ $project_supported == "yes" ]; then
2625 USED=$(getquota -p $TSTPRJID global curspace)
2626 [ $USED -lt $BLK_CNT ] && error \
2627 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2632 run_test 34 "Usage transfer for user & group & project"
2634 # usage is still accessible across restart
2636 local BLK_CNT=2 # 2 MB
2638 setup_quota_test || error "setup quota failed with $?"
2639 trap cleanup_quota_test EXIT
2641 echo "Write file..."
2642 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2643 error "write failed"
2644 is_project_quota_supported &&
2645 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2646 cancel_lru_locks osc
2648 echo "Wait for setattr on objects finished..."
2649 wait_delete_completed
2651 sync; sync_all_data || true
2653 echo "Save disk usage before restart"
2654 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2655 [ $ORIG_USR_SPACE -eq 0 ] &&
2656 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2657 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2658 [ $ORIG_USR_INODES -eq 0 ] &&
2659 error "Used inodes for user $TSTID is 0, expected 1"
2660 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2661 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2662 [ $ORIG_GRP_SPACE -eq 0 ] &&
2663 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2664 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2665 [ $ORIG_GRP_INODES -eq 0 ] &&
2666 error "Used inodes for group $TSTID is 0, expected 1"
2667 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2669 if is_project_quota_supported; then
2670 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2671 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2672 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2673 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2674 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2675 "Used inodes for project $TSTPRJID is 0, expected 1"
2676 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2684 echo "Verify disk usage after restart"
2685 local USED=$(getquota -u $TSTID global curspace)
2686 [ $USED -eq $ORIG_USR_SPACE ] ||
2687 error "Used space for user $TSTID changed from " \
2688 "$ORIG_USR_SPACE to $USED"
2689 USED=$(getquota -u $TSTID global curinodes)
2690 [ $USED -eq $ORIG_USR_INODES ] ||
2691 error "Used inodes for user $TSTID changed from " \
2692 "$ORIG_USR_INODES to $USED"
2693 USED=$(getquota -g $TSTID global curspace)
2694 [ $USED -eq $ORIG_GRP_SPACE ] ||
2695 error "Used space for group $TSTID changed from " \
2696 "$ORIG_GRP_SPACE to $USED"
2697 USED=$(getquota -g $TSTID global curinodes)
2698 [ $USED -eq $ORIG_GRP_INODES ] ||
2699 error "Used inodes for group $TSTID changed from " \
2700 "$ORIG_GRP_INODES to $USED"
2701 if [ $project_supported == "yes" ]; then
2702 USED=$(getquota -p $TSTPRJID global curinodes)
2703 [ $USED -eq $ORIG_PRJ_INODES ] ||
2704 error "Used inodes for project $TSTPRJID " \
2705 "changed from $ORIG_PRJ_INODES to $USED"
2706 USED=$(getquota -p $TSTPRJID global curspace)
2707 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2708 error "Used space for project $TSTPRJID "\
2709 "changed from $ORIG_PRJ_SPACE to $USED"
2712 # check if the vfs_dq_init() is called before writing
2713 echo "Append to the same file..."
2714 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2715 error "write failed"
2716 cancel_lru_locks osc
2717 sync; sync_all_data || true
2719 echo "Verify space usage is increased"
2720 USED=$(getquota -u $TSTID global curspace)
2721 [ $USED -gt $ORIG_USR_SPACE ] ||
2722 error "Used space for user $TSTID isn't increased" \
2723 "orig:$ORIG_USR_SPACE, now:$USED"
2724 USED=$(getquota -g $TSTID global curspace)
2725 [ $USED -gt $ORIG_GRP_SPACE ] ||
2726 error "Used space for group $TSTID isn't increased" \
2727 "orig:$ORIG_GRP_SPACE, now:$USED"
2728 if [ $project_supported == "yes" ]; then
2729 USED=$(getquota -p $TSTPRJID global curspace)
2730 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2731 error "Used space for project $TSTPRJID isn't " \
2732 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2737 run_test 35 "Usage is still accessible across reboot"
2739 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2742 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2743 skip "Old server doesn't have LU-5006 fix."
2745 setup_quota_test || error "setup quota failed with $?"
2746 trap cleanup_quota_test EXIT
2748 # make sure the system is clean
2749 local USED=$(getquota -u $TSTID global curspace)
2751 error "Used space ($USED) for user $TSTID isn't 0."
2753 # create file with MDS_OPEN_DELAY_CREATE flag
2754 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2755 error "Create file failed"
2757 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2758 oflag=sync || error "Write file failed"
2760 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2762 # wait for setattr on objects finished..."
2763 wait_delete_completed
2765 USED=$(getquota -u $TSTID global curspace)
2766 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2770 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2774 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2775 skip "Old server doesn't have LU-8801 fix."
2777 [ "$UID" != 0 ] && skip_env "must run as root" && return
2779 setup_quota_test || error "setup quota failed with $?"
2780 trap cleanup_quota_test EXIT
2782 # make sure the system is clean
2783 local USED=$(getquota -u $TSTID global curspace)
2785 error "Used space ($USED) for user $TSTID isn't 0."
2786 USED=$(getquota -u $TSTID2 global curspace)
2788 error "Used space ($USED) for user $TSTID2 isn't 0."
2790 local TESTFILE="$DIR/$tdir/$tfile"
2791 local file_cnt=10000
2793 # Generate id entries in accounting file
2794 echo "Create $file_cnt files..."
2795 for i in `seq $file_cnt`; do
2797 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2798 error "failed to chown $TESTFILE-$i"
2800 cancel_lru_locks osc
2801 sync; sync_all_data || true
2803 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2804 procf=${procf}.quota_slave.acct_user
2807 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2808 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2809 echo "Found $acct_cnt id entries"
2811 [ $file_cnt -eq $acct_cnt ] || {
2812 do_facet mds1 $LCTL get_param $procf
2813 error "skipped id entries"
2818 run_test 38 "Quota accounting iterator doesn't skip id entries"
2821 local TESTFILE="$DIR/$tdir/project"
2822 ! is_project_quota_supported &&
2823 skip "Project quota is not supported"
2825 setup_quota_test || error "setup quota failed with $?"
2828 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2829 [ $projectid -ne 0 ] &&
2830 error "Project id should be 0 not $projectid"
2831 change_project -p 1024 $TESTFILE
2832 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2833 [ $projectid -ne 1024 ] &&
2834 error "Project id should be 1024 not $projectid"
2836 stopall || error "failed to stopall (1)"
2839 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2840 [ $projectid -ne 1024 ] &&
2841 error "Project id should be 1024 not $projectid"
2845 run_test 39 "Project ID interface works correctly"
2848 ! is_project_quota_supported &&
2849 skip "Project quota is not supported"
2850 local dir1="$DIR/$tdir/dir1"
2851 local dir2="$DIR/$tdir/dir2"
2853 setup_quota_test || error "setup quota failed with $?"
2855 mkdir -p $dir1 $dir2
2856 change_project -sp 1 $dir1 && touch $dir1/1
2857 change_project -sp 2 $dir2
2859 ln $dir1/1 $dir2/1_link &&
2860 error "Hard link across different project quota should fail"
2865 run_test 40a "Hard link across different project ID"
2868 ! is_project_quota_supported &&
2869 skip "Project quota is not supported"
2870 local dir1="$DIR/$tdir/dir1"
2871 local dir2="$DIR/$tdir/dir2"
2873 setup_quota_test || error "setup quota failed with $?"
2874 mkdir -p $dir1 $dir2
2875 change_project -sp 1 $dir1 && touch $dir1/1
2876 change_project -sp 2 $dir2
2878 mv $dir1/1 $dir2/2 || error "mv failed $?"
2879 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2880 if [ "$projid" != "2" ]; then
2881 error "project id expected 2 not $projid"
2886 run_test 40b "Mv across different project ID"
2889 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2890 ! is_project_quota_supported &&
2891 skip "Project quota is not supported"
2893 setup_quota_test || error "setup quota failed with $?"
2894 local dir="$DIR/$tdir/dir"
2896 mkdir -p $dir && change_project -sp 1 $dir
2897 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2898 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2899 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2900 touch $dir/remote_dir/file
2901 #verify inherit works file for remote dir.
2902 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2903 [ "$projid" != "1" ] &&
2904 error "file under remote dir expected 1 not $projid"
2906 #Agent inode should be ignored for project quota
2907 USED=$(getquota -p 1 global curinodes)
2908 [ "$USED" != "3" ] &&
2909 error "file count expected 3 got $USED"
2915 run_test 40c "Remote child Dir inherit project quota properly"
2918 ! is_project_quota_supported &&
2919 skip "Project quota is not supported"
2921 setup_quota_test || error "setup quota failed with $?"
2922 local dir1="$DIR/$tdir/dir1"
2923 local dir2="$DIR/$tdir/dir2"
2925 mkdir -p $dir1 && change_project -sp 1 $dir1
2926 mkdir -p $dir2 && change_project -sp 2 $dir2
2927 for num in $(seq 1 10); do
2928 touch $dir1/file_$num $dir2/file_$num
2929 ln -s $dir1/file_$num $dir1/file_$num"_link"
2930 ln -s $dir2/file_$num $dir2/file_$num"_link"
2933 count=$($LFS find --projid 1 $DIR | wc -l)
2934 [ "$count" != 21 ] && error "expected 21 but got $count"
2936 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2937 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2938 [ "$count" != 22 ] && error "expected 22 but got $count"
2943 run_test 50 "Test if lfs find --projid works"
2946 ! is_project_quota_supported &&
2947 skip "Project quota is not supported"
2948 setup_quota_test || error "setup quota failed with $?"
2949 local dir="$DIR/$tdir/dir"
2951 mkdir $dir && change_project -sp 1 $dir
2952 local used=$(getquota -p 1 global curinodes)
2953 [ $used != "1" ] && error "expected 1 got $used"
2958 used=$(getquota -p 1 global curinodes)
2959 [ $used != "4" ] && error "expected 4 got $used"
2961 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2963 cp $DIR/$tdir/6 $dir/6
2964 used=$(getquota -p 1 global curinodes)
2965 [ $used != "5" ] && error "expected 5 got $used"
2968 mv $DIR/$tdir/6 $dir/7
2969 used=$(getquota -p 1 global curinodes)
2970 [ $used != "6" ] && error "expected 6 got $used"
2975 run_test 51 "Test project accounting with mv/cp"
2978 ! is_project_quota_supported &&
2979 skip "Project quota is not supported"
2980 setup_quota_test || error "setup quota failed with $?"
2981 local dir="$DIR/$tdir/dir"
2982 mkdir $dir && change_project -sp 1 $dir
2984 touch $DIR/$tdir/file
2985 #Try renaming a file into the project. This should fail.
2986 for num in $(seq 1 2000); do
2987 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2988 error "rename should fail"
2993 run_test 52 "Rename across different project ID"
2996 ! is_project_quota_supported &&
2997 skip "Project quota is not supported"
2998 setup_quota_test || error "setup quota failed with $?"
2999 local dir="$DIR/$tdir/dir"
3000 mkdir $dir && change_project -s $dir
3001 lfs project -d $dir | grep P || error "inherit attribute should be set"
3003 change_project -C $dir
3004 lfs project -d $dir | grep P &&
3005 error "inherit attribute should be cleared"
3010 run_test 53 "Project inherit attribute could be cleared"
3013 ! is_project_quota_supported &&
3014 skip "Project quota is not supported"
3015 setup_quota_test || error "setup quota failed with $?"
3016 trap cleanup_quota_test EXIT
3017 local testfile="$DIR/$tdir/$tfile-0"
3019 #set project ID/inherit attribute
3020 change_project -sp $TSTPRJID $DIR/$tdir
3021 $RUNAS createmany -m ${testfile} 100 ||
3022 error "create many files failed"
3024 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
3025 # one more count for directory itself */
3029 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3030 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
3032 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
3033 [ $proj_count1 -eq $proj_count ] ||
3034 error "c2: expected $proj_count got $proj_count1"
3036 #clear project but with kept projid
3037 change_project -rCk $DIR/$tdir
3038 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3039 [ $proj_count1 -eq 1 ] ||
3040 error "c3: expected 1 got $proj_count1"
3042 #verify projid untouched.
3043 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3045 [ $proj_count1 -eq $proj_count ] ||
3046 error "c4: expected $proj_count got $proj_count1"
3049 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3050 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3051 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3053 #this time clear all
3054 change_project -rC $DIR/$tdir
3055 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3056 [ $proj_count1 -eq 0 ] ||
3057 error "c6: expected 0 got $proj_count1"
3059 unlinkmany ${testfile} 100 ||
3060 error "unlink many files failed"
3064 run_test 54 "basic lfs project interface test"
3067 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3068 skip "Not supported before 2.10.58."
3069 setup_quota_test || error "setup quota failed with $?"
3071 set_ost_qtype $QTYPE || error "enable ost quota failed"
3074 #add second group to TSTUSR
3075 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3078 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3079 error "failed to dd"
3081 cancel_lru_locks osc
3082 sync; sync_all_data || true
3084 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3085 error "failed to setquota on group $TSTUSR2"
3087 $LFS quota -v -g $TSTUSR2 $DIR
3089 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3090 error "chgrp should failed with -EDQUOT"
3092 USED=$(getquota -g $TSTUSR2 global curspace)
3095 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3096 error "failed to setquota on group $TSTUSR2"
3098 $LFS quota -v -g $TSTUSR2 $DIR
3100 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3101 error "chgrp should succeed"
3103 $LFS quota -v -g $TSTUSR2 $DIR
3105 resetquota -g $TSTUSR2
3108 run_test 55 "Chgrp should be affected by group quota"
3111 setup_quota_test || error "setup quota failed with $?"
3113 set_ost_qtype $QTYPE || error "enable ost quota failed"
3116 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3117 erro "failed to set grace time for usr quota"
3118 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3119 awk '{print $4 $8}')
3120 if [ "x$grace_time" != "x10s;10s" ]; then
3121 $LFS quota -t -u $DIR
3122 error "expected grace time: 10s;10s, got:$grace_time"
3127 run_test 56 "lfs quota -t should work well"
3130 setup_quota_test || error "setup quota failed with $?"
3132 local dir="$DIR/$tdir/dir"
3135 #try to change pipe file should not hang and return failure
3136 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3137 awk -F ':' '{ print \\\$2 }'" \
3138 " unable to get xattr for fifo '$dir/pipe'" || return 1
3139 #command can process further if it hit some errors
3140 touch $dir/aaa $dir/bbb
3141 mkdir $dir/subdir -p
3142 touch $dir/subdir/aaa $dir/subdir/bbb
3143 #create one invalid link file
3144 ln -s $dir/not_exist_file $dir/ccc
3145 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3146 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3150 run_test 57 "lfs project could tolerate errors"
3153 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3154 skip "ldiskfs only test"
3155 disable_project_quota
3156 setup_quota_test || error "setup quota failed with $?"
3159 local testfile="$DIR/$tdir/$tfile-0"
3160 #make sure it did not crash kernel
3161 touch $testfile && lfs project -sp 1 $testfile
3163 enable_project_quota
3166 run_test 59 "lfs project dosen't crash kernel with project disabled"
3169 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3170 skip "Needs MDS version 2.11.53 or later."
3171 setup_quota_test || error "setup quota failed with $?"
3172 trap cleanup_quota_test EXIT
3174 local testfile=$DIR/$tdir/$tfile
3177 set_mdt_qtype "ug" || error "enable mdt quota failed"
3179 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3180 error "set quota failed"
3181 quota_show_check a g $TSTUSR
3183 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3184 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3185 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3186 error "create many files failed"
3188 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3190 # root user can overrun quota
3191 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3192 error "root user should succeed"
3195 resetquota -g $TSTUSR
3197 run_test 60 "Test quota for root with setgid"
3199 # test default quota
3200 test_default_quota() {
3201 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3202 skip "Not supported before 2.11.51."
3207 local qprjid=$TSTPRJID
3211 local LIMIT=20480 #20M disk space
3212 local TESTFILE="$DIR/$tdir/$tfile-0"
3214 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3215 echo "Project quota is not supported" && return 0
3217 [ $qtype == "-u" ] && qdtype="-U"
3218 [ $qtype == "-g" ] && qdtype="-G"
3219 [ $qtype == "-p" ] && {
3224 [ $qpool == "meta" ] && {
3225 LIMIT=10240 #10K inodes
3230 setup_quota_test || error "setup quota failed with $?"
3231 trap cleanup_quota_test EXIT
3235 # enable mdt/ost quota
3236 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3237 set_ost_qtype $QTYPE || error "enable ost quota failed"
3239 log "set to use default quota"
3240 $LFS setquota $qtype $qid -d $DIR ||
3241 error "set $qid to use default quota failed"
3243 log "set default quota"
3244 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3245 error "set $qid default quota failed"
3247 log "get default quota"
3248 $LFS quota $qdtype $DIR || error "get default quota failed"
3250 if [ $qpool == "data" ]; then
3251 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3253 [ $SLIMIT -eq $LIMIT ] ||
3254 error "the returned default quota is wrong"
3256 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3258 [ $SLIMIT -eq $LIMIT ] ||
3259 error "the returned default quota is wrong"
3262 # make sure the system is clean
3263 local USED=$(getquota $qtype $qid global curspace)
3264 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3266 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3267 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3269 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3271 log "Test not out of quota"
3272 if [ $qpool == "data" ]; then
3273 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3274 quota_error $qtype $qid "write failed, expect succeed"
3276 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3277 quota_error $qtype $qid "create failed, expect succeed"
3279 unlinkmany $TESTFILE $((LIMIT/2))
3282 log "Test out of quota"
3283 # flush cache, ensure noquota flag is set on client
3284 cancel_lru_locks osc
3285 cancel_lru_locks mdc
3286 sync; sync_all_data || true
3287 if [ $qpool == "data" ]; then
3288 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3289 quota_error $qtype $qid "write succeed, expect EDQUOT"
3291 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3292 quota_error $qtype $qid "create succeed, expect EDQUOT"
3294 unlinkmany $TESTFILE $((LIMIT*2))
3297 log "Increase default quota"
3298 # increase default quota
3299 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3300 error "set default quota failed"
3302 cancel_lru_locks osc
3303 cancel_lru_locks mdc
3304 sync; sync_all_data || true
3305 if [ $qpool == "data" ]; then
3306 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3307 quota_error $qtype $qid "write failed, expect succeed"
3309 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3310 quota_error $qtype $qid "create failed, expect succeed"
3312 unlinkmany $TESTFILE $((LIMIT*2))
3315 log "Set quota to override default quota"
3316 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3317 error "set $qid quota failed"
3319 cancel_lru_locks osc
3320 cancel_lru_locks mdc
3321 sync; sync_all_data || true
3322 if [ $qpool == "data" ]; then
3323 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3324 quota_error $qtype $qid "write succeed, expect EQUOT"
3326 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3327 quota_error $qtype $qid "create succeed, expect EQUOT"
3329 unlinkmany $TESTFILE $((LIMIT*2))
3332 log "Set to use default quota again"
3333 $LFS setquota $qtype $qid -d $DIR ||
3334 error "set $qid to use default quota failed"
3336 cancel_lru_locks osc
3337 cancel_lru_locks mdc
3338 sync; sync_all_data || true
3339 if [ $qpool == "data" ]; then
3340 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3341 quota_error $qtype $qid "write failed, expect succeed"
3343 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3344 quota_error $qtype $qid "create failed, expect succeed"
3346 unlinkmany $TESTFILE $((LIMIT*2))
3351 wait_delete_completed || error "wait_delete_completed failed"
3352 sync_all_data || true
3353 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3354 error "reset default quota failed"
3355 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3356 error "reset quota failed"
3362 test_default_quota "-u" "data"
3363 test_default_quota "-u" "meta"
3364 test_default_quota "-g" "data"
3365 test_default_quota "-g" "meta"
3366 test_default_quota "-p" "data"
3367 test_default_quota "-p" "meta"
3369 run_test 61 "default quota tests"
3372 ! is_project_quota_supported &&
3373 skip "Project quota is not supported"
3374 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3375 skip "chattr did not support project quota"
3376 setup_quota_test || error "setup quota failed with $?"
3377 local testdir=$DIR/$tdir/
3379 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3380 change_project -s $testdir
3381 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3382 error "inherit attribute should be set"
3383 # chattr used FS_IOC_SETFLAGS ioctl
3384 $RUNAS chattr -P $testdir &&
3385 error "regular user clear inherit should fail"
3386 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3387 error "inherit attribute should still be set"
3388 chattr -P $testdir || error "root failed to clear inherit"
3389 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3390 error "inherit attribute should be cleared"
3393 run_test 62 "Project inherit should be only changed by root"
3396 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3397 skip "Not supported before 2.11.55" && return
3401 local dd_failed=false
3402 local tdir_dom=${tdir}_dom
3403 local LIMIT=20480 #20M
3405 [ $qtype == "p" ] && ! is_project_quota_supported &&
3406 echo "Project quota is not supported" && return 0
3408 [ $qtype == "p" ] && qid=$TSTPRJID
3410 setup_quota_test || error "setup quota failed with $?"
3411 trap cleanup_quota_test EXIT
3415 # enable mdt/ost quota
3416 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3417 set_ost_qtype $QTYPE || error "enable ost quota failed"
3419 # make sure the system is clean
3420 local USED=$(getquota -$qtype $qid global curspace)
3421 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3423 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3425 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3426 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3427 error "setstripe $tdir_dom failed"
3428 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3430 [ $qtype == "p" ] && {
3431 change_project -sp $TSTPRJID $DIR/$tdir
3432 change_project -sp $TSTPRJID $DIR/$tdir_dom
3435 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3436 error "set $qid quota failed"
3438 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3439 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3443 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3445 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3446 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3450 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3452 rm -f $DIR/$tdir_dom/*
3454 # flush cache, ensure noquota flag is set on client
3455 cancel_lru_locks osc
3456 cancel_lru_locks mdc
3457 sync; sync_all_data || true
3461 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3462 quota_error $qtype $qid "write failed, expect succeed"
3464 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3465 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3469 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3472 rm -f $DIR/$tdir_dom/*
3474 # flush cache, ensure noquota flag is set on client
3475 cancel_lru_locks osc
3476 cancel_lru_locks mdc
3477 sync; sync_all_data || true
3481 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3482 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3486 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3488 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3489 quota_error $qtype $qid "write succeed, expect EDQUOT"
3492 rm -fr $DIR/$tdir_dom
3494 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3495 error "reset usr quota failed"
3505 run_test 63 "quota on DoM tests"
3508 ! is_project_quota_supported &&
3509 skip "Project quota is not supported"
3510 setup_quota_test || error "setup quota failed with $?"
3511 local dir1="$DIR/$tdir/"
3514 ln -s $dir1/file $dir1/file_link
3516 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3517 error "set symlink file's project should fail"
3519 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3520 error "get symlink file's project should fail"
3524 run_test 64 "lfs project on symlink files should fail"
3528 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3529 disable_project_quota
3531 reset_quota_settings
3536 check_and_cleanup_lustre
3537 export QUOTA_AUTO=$QUOTA_AUTO_OLD