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 $ZPOOL upgrade -v | grep project_quota && return 0
94 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
95 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
96 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
97 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
98 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
99 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
100 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
101 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
108 local fail_val=${3:-0}
112 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
113 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
114 ost) NODES="$(comma_list $(osts_nodes))";;
117 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
122 echo "lfs project $*"
123 lfs project $* || error "lfs project $* failed"
126 RUNAS="runas -u $TSTID -g $TSTID"
127 RUNAS2="runas -u $TSTID2 -g $TSTID2"
128 DD="dd if=/dev/zero bs=1M"
132 # clear quota limits for a user or a group
133 # usage: resetquota -u username
134 # resetquota -g groupname
135 # resetquota -p projid
138 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
139 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
140 error "resetquota: wrong specifier $1 passed"
142 if [ $1 == "-p" ]; then
143 is_project_quota_supported || return 0
146 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
147 error "clear quota for [type:$1 name:$2] failed"
148 # give a chance to slave to release space
156 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
157 $LFS quota -v -u $local_id $DIR
158 log "Files for user ($local_id):"
159 ($LFS find --user $local_id $DIR | head -n 4 |
160 xargs stat 2>/dev/null)
163 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
164 $LFS quota -v -g $local_id $DIR
165 log "Files for group ($local_id):"
166 ($LFS find --group $local_id $DIR | head -n 4 |
167 xargs stat 2>/dev/null)
170 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
171 $LFS quota -v -p $TSTPRJID $DIR
172 log "Files for project ($TSTPRJID):"
173 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
174 xargs stat 2>/dev/null)
190 # get quota for a user or a group
191 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
192 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
197 sync_all_data > /dev/null 2>&1 || true
199 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
200 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
201 error "getquota: wrong u/g/p specifier $1 passed"
214 *) error "unknown quota parameter $4";;
217 [ "$uuid" = "global" ] && uuid=$DIR
219 $LFS quota -v "$1" "$2" $DIR |
220 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
221 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
226 # usage: set_mdt_qtype ugp|u|g|p|none
230 local mdts=$(get_facets MDS)
232 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
233 qtype=$(tr -d 'p' <<<$qtype)
235 if [[ $PERM_CMD == *"set_param -P"* ]]; then
236 do_facet mgs $PERM_CMD \
237 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
239 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
241 # we have to make sure each MDT received config changes
242 for mdt in ${mdts//,/ }; do
244 cmd="$LCTL get_param -n "
245 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
246 cmd=${cmd}.quota_slave.enabled
248 if $(facet_up $mdt); then
249 wait_update_facet $mdt "$cmd" "$qtype" || return 1
256 # usage: set_ost_qtype ugp|u|g|p|none
260 local osts=$(get_facets OST)
262 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
263 qtype=$(tr -d 'p' <<<$qtype)
265 if [[ $PERM_CMD == *"set_param -P"* ]]; then
266 do_facet mgs $PERM_CMD \
267 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
269 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
271 # we have to make sure each OST received config changes
272 for ost in ${osts//,/ }; do
274 cmd="$LCTL get_param -n "
275 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
276 cmd=${cmd}.quota_slave.enabled
278 if $(facet_up $ost); then
279 wait_update_facet $ost "$cmd" "$qtype" || return 1
285 wait_reintegration() {
289 local result="glb[1],slv[1],reint[0]"
294 if [ $ntype == "mdt" ]; then
295 tgts=$(get_facets MDS)
297 tgts=$(get_facets OST)
300 for tgt in ${tgts//,/ }; do
302 cmd="$LCTL get_param -n "
303 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
304 cmd=${cmd}.quota_slave.info
306 if $(facet_up $tgt); then
307 wait_update_facet $tgt "$cmd |
308 grep "$qtype" | awk '{ print \\\$3 }'" \
309 "$result" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "mdt" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "mdt" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "mdt" "project" $max || return 1
338 if [[ "$qtype" =~ "u" ]]; then
339 wait_reintegration "ost" "user" $max || return 1
342 if [[ "$qtype" =~ "g" ]]; then
343 wait_reintegration "ost" "group" $max || return 1
346 if [[ "$qtype" =~ "p" ]]; then
347 ! is_project_quota_supported && return 0
348 wait_reintegration "ost" "project" $max || return 1
353 disable_project_quota() {
354 is_project_quota_supported || return 0
355 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
356 stopall || error "failed to stopall (1)"
358 for num in $(seq $MDSCOUNT); do
359 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
360 error "tune2fs $(mdsdevname $num) failed"
363 for num in $(seq $OSTCOUNT); do
364 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
365 error "tune2fs $(ostdevname $num) failed"
373 wait_delete_completed
374 echo "Creating test directory"
375 mkdir $DIR/$tdir || return 1
376 chmod 0777 $DIR/$tdir || return 2
377 # always clear fail_loc in case of fail_loc isn't cleared
378 # properly when previous test failed
379 lustre_fail mds_ost 0
382 cleanup_quota_test() {
384 echo "Delete files..."
386 echo "Wait for unlink objects finished..."
387 wait_delete_completed
388 sync_all_data || true
397 $LFS quota -v -$ugp $qid $DIR
399 if [ "$bf" == "a" -o "$bf" == "b" ]; then
400 usage=$(getquota -$ugp $qid global curspace)
401 if [ -z $usage ]; then
402 quota_error $ugp $qid \
403 "Query block quota failed ($ugp:$qid)."
405 [ $usage -ne 0 ] && quota_log $ugp $qid \
406 "Block quota isn't 0 ($ugp:$qid:$usage)."
410 if [ "$bf" == "a" -o "$bf" == "f" ]; then
411 usage=$(getquota -$ugp $qid global curinodes)
412 if [ -z $usage ]; then
413 quota_error $ugp $qid \
414 "Query file quota failed ($ugp:$qid)."
416 [ $usage -ne 0 ] && quota_log $ugp $qid \
417 "File quota isn't 0 ($ugp:$qid:$usage)."
422 enable_project_quota() {
423 is_project_quota_supported || return 0
424 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
425 stopall || error "failed to stopall (1)"
427 for num in $(seq $MDSCOUNT); do
428 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
429 error "tune2fs $(mdsdevname $num) failed"
432 for num in $(seq $OSTCOUNT); do
433 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
434 error "tune2fs $(ostdevname $num) failed"
441 project_quota_enabled () {
443 for num in $(seq $MDSCOUNT); do
444 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
445 grep -q project || rc=1
447 for num in $(seq $OSTCOUNT); do
448 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
449 grep -q project || rc=1
451 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
455 project_quota_enabled || enable_project_quota
457 reset_quota_settings() {
458 resetquota -u $TSTUSR
459 resetquota -g $TSTUSR
460 resetquota -u $TSTUSR2
461 resetquota -g $TSTUSR2
462 resetquota -p $TSTPRJID
467 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
472 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
473 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
474 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
475 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
477 test_quota_performance() {
478 local TESTFILE="$DIR/$tdir/$tfile-0"
479 local size=$1 # in MB
480 local stime=$(date +%s)
481 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
482 quota_error u $TSTUSR "write failure"
483 local etime=$(date +%s)
484 delta=$((etime - stime))
485 if [ $delta -gt 0 ]; then
486 rate=$((size * 1024 / delta))
487 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
488 # LU-2872 - see LU-2887 for fix
490 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
492 [ $rate -gt 1024 ] ||
493 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
499 # test basic quota performance b=21696
502 [ "$SLOW" = "no" ] && MB=10
504 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
505 [ $free_space -le $((MB * 1024)) ] &&
506 skip "not enough space ${free_space} KB, " \
507 "required $((MB * 1024)) KB"
508 setup_quota_test || error "setup quota failed with $?"
509 trap cleanup_quota_test EXIT
511 set_ost_qtype "none" || error "disable ost quota failed"
512 test_quota_performance $MB
514 set_ost_qtype $QTYPE || error "enable ost quota failed"
515 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
516 error "set quota failed"
517 test_quota_performance $MB
520 resetquota -u $TSTUSR
522 run_test 0 "Test basic quota performance"
524 # test block hardlimit
527 local TESTFILE="$DIR/$tdir/$tfile-0"
529 setup_quota_test || error "setup quota failed with $?"
530 trap cleanup_quota_test EXIT
533 set_ost_qtype $QTYPE || error "enable ost quota failed"
536 log "User quota (block hardlimit:$LIMIT MB)"
537 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
538 error "set user quota failed"
540 # make sure the system is clean
541 local USED=$(getquota -u $TSTUSR global curspace)
542 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
544 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
545 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
548 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
549 quota_error u $TSTUSR "user write failure, but expect success"
550 log "Write out of block quota ..."
551 # this time maybe cache write, ignore it's failure
552 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
553 # flush cache, ensure noquota flag is set on client
555 sync; sync_all_data || true
556 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
557 quota_error u $TSTUSR "user write success, but expect EDQUOT"
560 wait_delete_completed || error "wait_delete_completed failed"
561 sync_all_data || true
562 USED=$(getquota -u $TSTUSR global curspace)
563 [ $USED -ne 0 ] && quota_error u $TSTUSR \
564 "user quota isn't released after deletion"
565 resetquota -u $TSTUSR
568 log "--------------------------------------"
569 log "Group quota (block hardlimit:$LIMIT MB)"
570 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
571 error "set group quota failed"
573 TESTFILE="$DIR/$tdir/$tfile-1"
574 # make sure the system is clean
575 USED=$(getquota -g $TSTUSR global curspace)
576 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
578 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
579 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
582 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
583 quota_error g $TSTUSR "Group write failure, but expect success"
584 log "Write out of block quota ..."
585 # this time maybe cache write, ignore it's failure
586 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
588 sync; sync_all_data || true
589 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
590 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
592 wait_delete_completed || error "wait_delete_completed failed"
593 sync_all_data || true
594 USED=$(getquota -g $TSTUSR global curspace)
595 [ $USED -ne 0 ] && quota_error g $TSTUSR \
596 "Group quota isn't released after deletion"
597 resetquota -g $TSTUSR
599 if ! is_project_quota_supported; then
600 echo "Project quota is not supported"
605 TESTFILE="$DIR/$tdir/$tfile-2"
606 # make sure the system is clean
607 USED=$(getquota -p $TSTPRJID global curspace)
609 error "used space($USED) for project $TSTPRJID isn't 0"
612 log "--------------------------------------"
613 log "Project quota (block hardlimit:$LIMIT mb)"
614 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
615 error "set project quota failed"
617 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
618 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
619 change_project -p $TSTPRJID $TESTFILE
622 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
623 "project write failure, but expect success"
624 log "write out of block quota ..."
625 # this time maybe cache write, ignore it's failure
626 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
628 sync; sync_all_data || true
629 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
630 $TSTPRJID "project write success, but expect EDQUOT"
635 USED=$(getquota -p $TSTPRJID global curspace)
636 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
637 "project quota isn't released after deletion"
639 resetquota -p $TSTPRJID
641 run_test 1 "Block hard limit (normal use and out of quota)"
643 # test inode hardlimit
645 local LIMIT=$((1024 * 1024)) # 1M inodes
646 local TESTFILE="$DIR/$tdir/$tfile-0"
648 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
650 local FREE_INODES=$(mdt_free_inodes 0)
651 echo "$FREE_INODES free inodes on master MDT"
652 [ $FREE_INODES -lt $LIMIT ] &&
653 skip "not enough free inodes $FREE_INODES required $LIMIT"
655 setup_quota_test || error "setup quota failed with $?"
656 trap cleanup_quota_test EXIT
659 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
662 log "User quota (inode hardlimit:$LIMIT files)"
663 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
664 error "set user quota failed"
666 # make sure the system is clean
667 local USED=$(getquota -u $TSTUSR global curinodes)
668 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
670 log "Create $LIMIT files ..."
671 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
672 quota_error u $TSTUSR "user create failure, but expect success"
673 log "Create out of file quota ..."
674 $RUNAS touch ${TESTFILE}_xxx &&
675 quota_error u $TSTUSR "user create success, but expect EDQUOT"
678 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
679 rm -f ${TESTFILE}_xxx
680 wait_delete_completed
682 USED=$(getquota -u $TSTUSR global curinodes)
683 [ $USED -ne 0 ] && quota_error u $TSTUSR \
684 "user quota isn't released after deletion"
685 resetquota -u $TSTUSR
688 log "--------------------------------------"
689 log "Group quota (inode hardlimit:$LIMIT files)"
690 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
691 error "set group quota failed"
693 TESTFILE=$DIR/$tdir/$tfile-1
694 # make sure the system is clean
695 USED=$(getquota -g $TSTUSR global curinodes)
696 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
698 log "Create $LIMIT files ..."
699 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
700 quota_error g $TSTUSR "group create failure, but expect success"
701 log "Create out of file quota ..."
702 $RUNAS touch ${TESTFILE}_xxx &&
703 quota_error g $TSTUSR "group create success, but expect EDQUOT"
706 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
707 rm -f ${TESTFILE}_xxx
708 wait_delete_completed
710 USED=$(getquota -g $TSTUSR global curinodes)
711 [ $USED -ne 0 ] && quota_error g $TSTUSR \
712 "user quota isn't released after deletion"
714 resetquota -g $TSTUSR
715 ! is_project_quota_supported && cleanup_quota_test &&
716 echo "Skip project quota is not supported" && return 0
719 log "--------------------------------------"
720 log "Project quota (inode hardlimit:$LIMIT files)"
721 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
722 error "set project quota failed"
724 TESTFILE=$DIR/$tdir/$tfile-1
725 # make sure the system is clean
726 USED=$(getquota -p $TSTPRJID global curinodes)
728 error "Used inodes($USED) for project $TSTPRJID isn't 0"
730 change_project -sp $TSTPRJID $DIR/$tdir
731 log "Create $LIMIT files ..."
732 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
733 $TSTPRJID "project create fail, but expect success"
734 log "Create out of file quota ..."
735 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
736 "project create success, but expect EDQUOT"
737 change_project -C $DIR/$tdir
740 USED=$(getquota -p $TSTPRJID global curinodes)
741 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
742 "project quota isn't released after deletion"
744 resetquota -p $TSTPRJID
747 run_test 2 "File hard limit (normal use and out of quota)"
751 local TIMER=$(($2 * 3 / 2))
757 trap cleanup_quota_test EXIT
759 $LFS setstripe $TESTFILE -c 1 -i 0
760 chown $TSTUSR.$TSTUSR $TESTFILE
761 [ "$qtype" == "p" ] && is_project_quota_supported &&
762 change_project -p $TSTPRJID $TESTFILE
764 echo "Write up to soft limit"
765 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
766 quota_error a $TSTUSR "write failure, but expect success"
767 OFFSET=$((LIMIT * 1024))
770 echo "Write to exceed soft limit"
771 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
772 quota_error a $TSTUSR "write failure, but expect success"
773 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
779 $SHOW_QUOTA_INFO_USER
780 $SHOW_QUOTA_INFO_GROUP
781 $SHOW_QUOTA_INFO_PROJID
783 echo "Write before timer goes off"
784 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
785 quota_error a $TSTUSR "write failure, but expect success"
786 OFFSET=$((OFFSET + 1024))
789 echo "Sleep $TIMER seconds ..."
795 $SHOW_QUOTA_INFO_USER
796 $SHOW_QUOTA_INFO_GROUP
797 $SHOW_QUOTA_INFO_PROJID
799 echo "Write after timer goes off"
800 # maybe cache write, ignore.
801 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
802 OFFSET=$((OFFSET + 1024))
804 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
805 quota_error a $TSTUSR "write success, but expect EDQUOT"
810 $SHOW_QUOTA_INFO_USER
811 $SHOW_QUOTA_INFO_GROUP
812 $SHOW_QUOTA_INFO_PROJID
814 echo "Unlink file to stop timer"
816 wait_delete_completed
817 sync_all_data || true
822 $SHOW_QUOTA_INFO_USER
823 $SHOW_QUOTA_INFO_GROUP
824 $SHOW_QUOTA_INFO_PROJID
826 $LFS setstripe $TESTFILE -c 1 -i 0
827 chown $TSTUSR.$TSTUSR $TESTFILE
828 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
831 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
832 quota_error a $TSTUSR "write failure, but expect success"
841 local TESTFILE=$DIR/$tdir/$tfile-0
843 set_ost_qtype $QTYPE || error "enable ost quota failed"
845 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
846 # make sure the system is clean
847 local USED=$(getquota -u $TSTUSR global curspace)
848 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
850 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
851 $MAX_IQ_TIME $DIR || error "set user grace time failed"
852 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
853 error "set user quota failed"
855 test_block_soft $TESTFILE $GRACE $LIMIT "u"
856 resetquota -u $TSTUSR
858 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
859 TESTFILE=$DIR/$tdir/$tfile-1
860 # make sure the system is clean
861 USED=$(getquota -g $TSTUSR global curspace)
862 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
864 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
865 $MAX_IQ_TIME $DIR || error "set group grace time failed"
866 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
867 error "set group quota failed"
869 test_block_soft $TESTFILE $GRACE $LIMIT "g"
870 resetquota -g $TSTUSR
872 if is_project_quota_supported; then
873 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
874 TESTFILE=$DIR/$tdir/$tfile-2
875 # make sure the system is clean
876 USED=$(getquota -p $TSTPRJID global curspace)
877 [ $USED -ne 0 ] && error \
878 "Used space($USED) for project $TSTPRJID isn't 0."
880 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
882 error "set project grace time failed"
883 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
884 $DIR || error "set project quota failed"
886 test_block_soft $TESTFILE $GRACE $LIMIT "p"
887 resetquota -p $TSTPRJID
888 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
890 error "restore project grace time failed"
894 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
895 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
896 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
897 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
899 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
905 local TIMER=$(($grace * 3 / 2))
908 trap cleanup_quota_test EXIT
909 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
911 echo "Create files to exceed soft limit"
912 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
913 quota_error a $TSTUSR "create failure, but expect success"
914 local trigger_time=$(date +%s)
916 sync_all_data || true
918 local cur_time=$(date +%s)
919 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
920 error "Passed grace time $grace, $trigger_time, $cur_time"
922 echo "Create file before timer goes off"
923 $RUNAS touch ${TESTFILE}_before ||
924 quota_error a $TSTUSR "failed create before timer expired," \
925 "but expect success. $trigger_time, $cur_time"
926 sync_all_data || true
928 echo "Sleep $TIMER seconds ..."
934 $SHOW_QUOTA_INFO_USER
935 $SHOW_QUOTA_INFO_GROUP
936 $SHOW_QUOTA_INFO_PROJID
938 echo "Create file after timer goes off"
939 # There is a window that space is accounted in the quota usage but
940 # hasn't been decreased from the pending write, if we acquire quota
941 # in this window, we'll acquire more than we needed.
942 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
943 sync_all_data || true
944 $RUNAS touch ${TESTFILE}_after_3 &&
945 quota_error a $TSTUSR "create after timer expired," \
947 sync_all_data || true
952 $SHOW_QUOTA_INFO_USER
953 $SHOW_QUOTA_INFO_GROUP
954 $SHOW_QUOTA_INFO_PROJID
956 echo "Unlink files to stop timer"
957 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
958 wait_delete_completed
961 $RUNAS touch ${TESTFILE}_xxx ||
962 quota_error a $TSTUSR "touch after timer stop failure," \
964 sync_all_data || true
972 local LIMIT=10 # inodes
973 local TESTFILE=$DIR/$tdir/$tfile-0
976 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
978 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
979 # make sure the system is clean
980 local USED=$(getquota -u $TSTUSR global curinodes)
981 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
983 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
984 $GRACE $DIR || error "set user grace time failed"
985 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
986 error "set user quota failed"
988 test_file_soft $TESTFILE $LIMIT $GRACE
989 resetquota -u $TSTUSR
991 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
992 # make sure the system is clean
993 USED=$(getquota -g $TSTUSR global curinodes)
994 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
996 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
997 $GRACE $DIR || error "set group grace time failed"
998 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
999 error "set group quota failed"
1000 TESTFILE=$DIR/$tdir/$tfile-1
1002 test_file_soft $TESTFILE $LIMIT $GRACE
1003 resetquota -g $TSTUSR
1005 if is_project_quota_supported; then
1006 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1007 # make sure the system is clean
1008 USED=$(getquota -p $TSTPRJID global curinodes)
1009 [ $USED -ne 0 ] && error \
1010 "Used space($USED) for project $TSTPRJID isn't 0."
1012 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1013 $GRACE $DIR || error "set project grace time failed"
1014 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1015 error "set project quota failed"
1017 TESTFILE=$DIR/$tdir/$tfile-1
1018 # one less than limit, because of parent directory included.
1019 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1020 resetquota -p $TSTPRJID
1021 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1022 $MAX_IQ_TIME $DIR ||
1023 error "restore project grace time failed"
1027 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1028 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1029 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1030 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1032 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1035 local GR_STR1="1w3d"
1036 local GR_STR2="1000s"
1038 local GR_STR4="1w2d3h4m5s"
1040 local GR_STR6="18446744073709551615"
1043 wait_delete_completed
1045 # test of valid grace strings handling
1046 echo "Valid grace strings test"
1047 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1048 $GR_STR2 $DIR || error "set user grace time failed"
1049 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1050 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1051 $GR_STR4 $DIR || error "set group grace time quota failed"
1052 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1054 # test of invalid grace strings handling
1055 echo " Invalid grace strings test"
1056 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1057 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1058 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1062 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1063 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1064 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1065 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1067 run_test 4b "Grace time strings handling"
1069 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1071 local BLIMIT=10 # 10M
1072 local ILIMIT=10 # 10 inodes
1074 setup_quota_test || error "setup quota failed with $?"
1075 trap cleanup_quota_test EXIT
1077 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1078 set_ost_qtype $QTYPE || error "enable ost quota failed"
1080 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1081 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1082 error "set user quota failed"
1083 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1084 if is_project_quota_supported; then
1085 error "set group quota failed"
1086 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1087 -I $ILIMIT $DIR || error "set project quota failed"
1090 # make sure the system is clean
1091 local USED=$(getquota -u $TSTUSR global curinodes)
1092 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1093 USED=$(getquota -g $TSTUSR global curinodes)
1094 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1095 USED=$(getquota -u $TSTUSR global curspace)
1096 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1097 USED=$(getquota -g $TSTUSR global curspace)
1098 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1099 if is_project_quota_supported; then
1100 USED=$(getquota -p $TSTPRJID global curinodes)
1102 error "Used inode($USED) for project $TSTPRJID isn't 0."
1103 USED=$(getquota -p $TSTPRJID global curspace)
1105 error "Used block($USED) for project $TSTPRJID isn't 0."
1108 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1109 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1110 error "create failure, expect success"
1111 if is_project_quota_supported; then
1112 touch $DIR/$tdir/$tfile-0_1
1113 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1115 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1116 error "write failure, expect success"
1118 echo "Chown files to $TSTUSR.$TSTUSR ..."
1119 for i in $(seq 0 $ILIMIT); do
1120 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1121 quota_error a $TSTUSR "chown failure, expect success"
1125 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1126 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1129 resetquota -u $TSTUSR
1130 resetquota -g $TSTUSR
1131 resetquota -p $TSTPRJID
1133 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1135 # test dropping acquire request on master
1139 # Clear dmesg so watchdog is not triggered by previous
1141 do_facet ost1 dmesg -c > /dev/null
1143 setup_quota_test || error "setup quota failed with $?"
1144 trap cleanup_quota_test EXIT
1146 # make sure the system is clean
1147 local USED=$(getquota -u $TSTUSR global curspace)
1148 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1150 # make sure no granted quota on ost
1151 set_ost_qtype $QTYPE || error "enable ost quota failed"
1152 resetquota -u $TSTUSR
1154 # create file for $TSTUSR
1155 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1156 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1157 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1159 # create file for $TSTUSR2
1160 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1161 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1162 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1164 # cache per-ID lock for $TSTUSR on slave
1165 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1166 error "set quota failed"
1167 $RUNAS $DD of=$TESTFILE count=1 ||
1168 error "write $TESTFILE failure, expect success"
1169 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1170 error "write $TESTFILE2 failure, expect success"
1172 sync_all_data || true
1174 #define QUOTA_DQACQ 601
1175 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1176 lustre_fail mds 0x513 601
1178 do_facet ost1 $LCTL set_param \
1179 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1181 # write to un-enforced ID ($TSTUSR2) should succeed
1182 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1183 error "write failure, expect success"
1185 # write to enforced ID ($TSTUSR) in background, exceeding limit
1186 # to make sure DQACQ is sent
1187 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1190 # watchdog timer uses a factor of 2
1191 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1192 sleep $((TIMEOUT * 2 + 1))
1194 # write should be blocked and never finished
1195 if ! ps -p $DDPID > /dev/null 2>&1; then
1197 error "write finished incorrectly!"
1202 # no watchdog is triggered
1203 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1204 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1205 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1206 [ -z "$watchdog" ] || error "$watchdog"
1208 rm -f $TMP/lustre-log-${TESTNAME}.log
1210 # write should continue then fail with EDQUOT
1214 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1215 if [ $count -ge 240 ]; then
1216 quota_error u $TSTUSR "dd not finished in $count secs"
1218 count=$((count + 1))
1219 if [ $((count % 30)) -eq 0 ]; then
1220 c_size=$(stat -c %s $TESTFILE)
1221 echo "Waiting $count secs. $c_size"
1228 resetquota -u $TSTUSR
1230 run_test 6 "Test dropping acquire request on master"
1232 # quota reintegration (global index)
1234 local TESTFILE=$DIR/$tdir/$tfile
1235 local LIMIT=20 # 20M
1237 [ "$SLOW" = "no" ] && LIMIT=5
1239 setup_quota_test || error "setup quota failed with $?"
1240 trap cleanup_quota_test EXIT
1242 # make sure the system is clean
1243 local USED=$(getquota -u $TSTUSR global curspace)
1244 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1246 # make sure no granted quota on ost1
1247 set_ost_qtype $QTYPE || error "enable ost quota failed"
1248 resetquota -u $TSTUSR
1249 set_ost_qtype "none" || error "disable ost quota failed"
1251 local OSTUUID=$(ostuuid_from_index 0)
1252 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1254 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1257 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1258 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1263 echo "Enable quota & set quota limit for $TSTUSR"
1264 set_ost_qtype $QTYPE || error "enable ost quota failed"
1265 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1266 error "set quota failed"
1268 echo "Start ost1..."
1269 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1272 wait_ost_reint $QTYPE || error "reintegration failed"
1274 # hardlimit should have been fetched by slave during global
1275 # reintegration, write will exceed quota
1276 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1277 quota_error u $TSTUSR "write success, but expect EDQUOT"
1280 wait_delete_completed
1281 sync_all_data || true
1287 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1288 error "clear quota failed"
1290 echo "Start ost1..."
1291 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1294 wait_ost_reint $QTYPE || error "reintegration failed"
1296 # hardlimit should be cleared on slave during reintegration
1297 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1298 quota_error u $TSTUSR "write error, but expect success"
1301 resetquota -u $TSTUSR
1303 run_test 7a "Quota reintegration (global index)"
1305 # quota reintegration (slave index)
1308 local TESTFILE=$DIR/$tdir/$tfile
1310 setup_quota_test || error "setup quota failed with $?"
1311 trap cleanup_quota_test EXIT
1313 # make sure the system is clean
1314 local USED=$(getquota -u $TSTUSR global curspace)
1315 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1317 # make sure no granted quota on ost1
1318 set_ost_qtype $QTYPE || error "enable ost quota failed"
1319 resetquota -u $TSTUSR
1320 set_ost_qtype "none" || error "disable ost quota failed"
1322 local OSTUUID=$(ostuuid_from_index 0)
1323 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1325 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1328 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1329 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1331 # consume some space to make sure the granted space will not
1332 # be released during reconciliation
1333 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1334 error "consume space failure, expect success"
1336 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1337 lustre_fail mds 0xa02
1339 set_ost_qtype $QTYPE || error "enable ost quota failed"
1340 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1341 error "set quota failed"
1343 # ignore the write error
1344 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1346 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1350 echo "Restart ost to trigger reintegration..."
1352 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1355 wait_ost_reint $QTYPE || error "reintegration failed"
1357 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1358 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1361 resetquota -u $TSTUSR
1364 run_test 7b "Quota reintegration (slave index)"
1366 # quota reintegration (restart mds during reintegration)
1368 local LIMIT=20 # 20M
1369 local TESTFILE=$DIR/$tdir/$tfile
1371 [ "$SLOW" = "no" ] && LIMIT=5
1373 setup_quota_test || error "setup quota failed with $?"
1374 trap cleanup_quota_test EXIT
1376 # make sure the system is clean
1377 local USED=$(getquota -u $TSTUSR global curspace)
1378 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1380 set_ost_qtype "none" || error "disable ost quota failed"
1381 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1382 error "set quota failed"
1384 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1385 lustre_fail ost 0xa03
1388 set_ost_qtype $QTYPE || error "enable ost quota failed"
1389 # trigger reintegration
1390 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1391 procf=${procf}quota_slave.force_reint
1392 do_facet ost1 $LCTL set_param $procf=1 ||
1393 error "force reintegration failed"
1401 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1404 # wait longer than usual to make sure the reintegration
1405 # is triggered by quota wb thread.
1406 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1408 # hardlimit should have been fetched by slave during global
1409 # reintegration, write will exceed quota
1410 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1411 quota_error u $TSTUSR "write success, but expect EDQUOT"
1414 resetquota -u $TSTUSR
1416 run_test 7c "Quota reintegration (restart mds during reintegration)"
1418 # Quota reintegration (Transfer index in multiple bulks)
1420 local TESTFILE=$DIR/$tdir/$tfile
1421 local TESTFILE1="$DIR/$tdir/$tfile"-1
1424 setup_quota_test || error "setup quota failed with $?"
1425 trap cleanup_quota_test EXIT
1427 set_ost_qtype "none" || error "disable ost quota failed"
1428 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1429 error "set quota for $TSTUSR failed"
1430 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1431 error "set quota for $TSTUSR2 failed"
1433 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1434 lustre_fail mds 0x608 0
1436 # enable quota to tirgger reintegration
1437 set_ost_qtype "u" || error "enable ost quota failed"
1438 wait_ost_reint "u" || error "reintegration failed"
1442 # hardlimit should have been fetched by slave during global
1443 # reintegration, write will exceed quota
1444 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1445 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1447 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1448 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1451 resetquota -u $TSTUSR
1452 resetquota -u $TSTUSR2
1454 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1456 # quota reintegration (inode limits)
1458 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1460 # LU-2435: skip this quota test if underlying zfs version has not
1461 # supported native dnode accounting
1462 [ "$(facet_fstype mds1)" == "zfs" ] && {
1463 local F="feature@userobj_accounting"
1464 local pool=$(zpool_name mds1)
1465 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1467 [[ "$feature" != *" active "* ]] &&
1468 skip "requires zpool with active userobj_accounting"
1471 local ilimit=$((1024 * 2)) # 2k inodes
1472 local TESTFILE=$DIR/${tdir}-1/$tfile
1474 setup_quota_test || error "setup quota failed with $?"
1475 trap cleanup_quota_test EXIT
1477 # make sure the system is clean
1478 local USED=$(getquota -u $TSTUSR global curinodes)
1479 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1481 # make sure no granted quota on mdt1
1482 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1483 resetquota -u $TSTUSR
1484 set_mdt_qtype "none" || error "disable mdt quota failed"
1486 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1487 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1488 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1491 echo "Stop mds${MDSCOUNT}..."
1494 echo "Enable quota & set quota limit for $TSTUSR"
1495 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1496 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1497 error "set quota failed"
1499 echo "Start mds${MDSCOUNT}..."
1500 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1503 wait_mdt_reint $QTYPE || error "reintegration failed"
1505 echo "create remote dir"
1506 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1507 error "create remote dir failed"
1508 chmod 0777 $DIR/${tdir}-1
1510 # hardlimit should have been fetched by slave during global
1511 # reintegration, create will exceed quota
1512 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1513 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1515 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1516 wait_delete_completed
1517 sync_all_data || true
1519 echo "Stop mds${MDSCOUNT}..."
1522 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1523 error "clear quota failed"
1525 echo "Start mds${MDSCOUNT}..."
1526 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1529 wait_mdt_reint $QTYPE || error "reintegration failed"
1531 # hardlimit should be cleared on slave during reintegration
1532 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1533 quota_error u $TSTUSR "create failed, expect success"
1535 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1536 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1539 resetquota -u $TSTUSR
1541 run_test 7e "Quota reintegration (inode limits)"
1543 # run dbench with quota enabled
1545 local BLK_LIMIT="100g" #100G
1546 local FILE_LIMIT=1000000
1548 setup_quota_test || error "setup quota failed with $?"
1549 trap cleanup_quota_test EXIT
1551 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1552 set_ost_qtype $QTYPE || error "enable ost quota failed"
1554 echo "Set enough high limit for user: $TSTUSR"
1555 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1556 error "set user quota failed"
1557 echo "Set enough high limit for group: $TSTUSR"
1558 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1559 error "set group quota failed"
1560 if is_project_quota_supported; then
1561 change_project -sp $TSTPRJID $DIR/$tdir
1562 echo "Set enough high limit for project: $TSTPRJID"
1563 $LFS setquota -p $TSTPRJID -b 0 \
1564 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1565 error "set project quota failed"
1569 [ "$SLOW" = "no" ] && duration=" -t 120"
1570 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1571 quota_error a $TSTUSR "dbench failed!"
1573 is_project_quota_supported && change_project -C $DIR/$tdir
1575 resetquota -u $TSTUSR
1576 resetquota -g $TSTUSR
1577 resetquota -p $TSTPRJID
1579 run_test 8 "Run dbench with quota enabled"
1581 # this check is just for test_9
1582 OST0_MIN=4900000 #4.67G
1584 check_whether_skip () {
1585 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1586 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1587 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1588 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1595 # run for fixing bug10707, it needs a big room. test for 64bit
1597 local filesize=$((1024 * 9 / 2)) # 4.5G
1599 check_whether_skip && return 0
1601 setup_quota_test || error "setup quota failed with $?"
1602 trap cleanup_quota_test EXIT
1604 set_ost_qtype "ug" || error "enable ost quota failed"
1606 local TESTFILE="$DIR/$tdir/$tfile-0"
1607 local BLK_LIMIT=100G #100G
1608 local FILE_LIMIT=1000000
1610 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1612 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1614 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1615 error "set user quota failed"
1617 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1618 "for group: $TSTUSR"
1619 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1620 error "set group quota failed"
1622 quota_show_check a u $TSTUSR
1623 quota_show_check a g $TSTUSR
1625 echo "Create test file"
1626 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1627 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1629 log "Write the big file of 4.5G ..."
1630 $RUNAS $DD of=$TESTFILE count=$filesize ||
1631 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1637 resetquota -u $TSTUSR
1638 resetquota -g $TSTUSR
1643 run_test 9 "Block limit larger than 4GB (b10707)"
1646 local TESTFILE=$DIR/$tdir/$tfile
1648 setup_quota_test || error "setup quota failed with $?"
1649 trap cleanup_quota_test EXIT
1651 # set limit to root user should fail
1652 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1653 error "set limit for root user successfully, expect failure"
1654 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1655 error "set limit for root group successfully, expect failure"
1656 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1657 error "set limit for project 0 successfully, expect failure"
1659 # root user can overrun quota
1660 set_ost_qtype "ug" || error "enable ost quota failed"
1662 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1663 error "set quota failed"
1664 quota_show_check b u $TSTUSR
1666 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1667 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1669 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1670 error "write failure, expect success"
1673 resetquota -u $TSTUSR
1675 run_test 10 "Test quota for root user"
1678 local TESTFILE=$DIR/$tdir/$tfile
1679 setup_quota_test || error "setup quota failed with $?"
1680 trap cleanup_quota_test EXIT
1682 set_mdt_qtype "ug" || error "enable mdt quota failed"
1683 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1684 error "set quota failed"
1686 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1687 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1689 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1690 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1693 local USED=$(getquota -u $TSTUSR global curinodes)
1694 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1697 resetquota -u $TSTUSR
1699 run_test 11 "Chown/chgrp ignores quota"
1702 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1704 local blimit=22 # 22M
1705 local blk_cnt=$((blimit - 5))
1706 local TESTFILE0="$DIR/$tdir/$tfile"-0
1707 local TESTFILE1="$DIR/$tdir/$tfile"-1
1709 setup_quota_test || error "setup quota failed with $?"
1710 trap cleanup_quota_test EXIT
1712 set_ost_qtype "u" || error "enable ost quota failed"
1713 quota_show_check b u $TSTUSR
1715 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1716 error "set quota failed"
1718 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1719 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1720 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1721 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1723 echo "Write to ost0..."
1724 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1725 quota_error a $TSTUSR "dd failed"
1727 echo "Write to ost1..."
1728 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1729 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1731 echo "Free space from ost0..."
1733 wait_delete_completed
1734 sync_all_data || true
1736 echo "Write to ost1 after space freed from ost0..."
1737 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1738 quota_error a $TSTUSR "rebalancing failed"
1741 resetquota -u $TSTUSR
1743 run_test 12a "Block quota rebalancing"
1746 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1748 local ilimit=$((1024 * 2)) # 2k inodes
1749 local TESTFILE0=$DIR/$tdir/$tfile
1750 local TESTFILE1=$DIR/${tdir}-1/$tfile
1752 setup_quota_test || error "setup quota failed with $?"
1753 trap cleanup_quota_test EXIT
1755 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1756 chmod 0777 $DIR/${tdir}-1
1758 set_mdt_qtype "u" || error "enable mdt quota failed"
1759 quota_show_check f u $TSTUSR
1761 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1762 error "set quota failed"
1764 echo "Create $ilimit files on mdt0..."
1765 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1766 quota_error u $TSTUSR "create failed, but expect success"
1768 echo "Create files on mdt1..."
1769 $RUNAS createmany -m $TESTFILE1 1 &&
1770 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1772 echo "Free space from mdt0..."
1773 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1774 wait_delete_completed
1775 sync_all_data || true
1777 echo "Create files on mdt1 after space freed from mdt0..."
1778 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1779 quota_error a $TSTUSR "rebalancing failed"
1781 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1782 error "unlink mdt1 files failed"
1783 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1786 resetquota -u $TSTUSR
1788 run_test 12b "Inode quota rebalancing"
1791 local TESTFILE=$DIR/$tdir/$tfile
1792 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1793 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1795 setup_quota_test || error "setup quota failed with $?"
1796 trap cleanup_quota_test EXIT
1798 set_ost_qtype "u" || error "enable ost quota failed"
1799 quota_show_check b u $TSTUSR
1801 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1802 error "set quota failed"
1803 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1804 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1806 # clear the locks in cache first
1807 do_facet ost1 $LCTL set_param -n $procf=clear
1808 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1809 [ $nlock -eq 0 ] || error "$nlock cached locks"
1811 # write to acquire the per-ID lock
1812 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1813 quota_error a $TSTUSR "dd failed"
1815 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1816 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1818 # clear quota doesn't trigger per-ID lock cancellation
1819 resetquota -u $TSTUSR
1820 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1821 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1823 # clear the per-ID lock
1824 do_facet ost1 $LCTL set_param -n $procf=clear
1825 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1826 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1828 # spare quota should be released
1829 local OSTUUID=$(ostuuid_from_index 0)
1830 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1831 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1832 [ $limit -le $space ] ||
1833 error "spare quota isn't released, limit:$limit, space:$space"
1837 run_test 13 "Cancel per-ID lock in the LRU list"
1840 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1842 wait_delete_completed
1843 sync_all_data || true
1846 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1847 error "set user quota failed"
1848 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1849 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1850 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1851 resetquota -u $TSTUSR
1854 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1855 error "set group quota failed"
1856 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1857 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1858 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1859 resetquota -g $TSTUSR
1861 run_test 15 "Set over 4T block quota"
1865 local BLKS=1 # 1M less than limit
1866 local TESTFILE=$DIR/$tdir/$tfile
1868 setup_quota_test || error "setup quota failed with $?"
1869 trap cleanup_quota_test EXIT
1871 # make sure the system is clean
1872 local USED=$(getquota -u $TSTUSR global curspace)
1873 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1875 set_ost_qtype "ug" || error "enable ost quota failed"
1876 # make sure no granted quota on ost
1877 resetquota -u $TSTUSR
1878 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1879 error "set quota failed"
1881 quota_show_check b u $TSTUSR
1883 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1884 lustre_fail mds 0xa04 $err_code
1886 # write in background
1887 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1891 # write should be blocked and never finished
1892 if ! ps -p $DDPID > /dev/null 2>&1; then
1894 quota_error u $TSTUSR "write finished incorrectly!"
1902 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1904 if [ $count -gt $timeout ]; then
1905 quota_error u $TSTUSR "dd is not finished!"
1910 sync; sync_all_data || true
1912 USED=$(getquota -u $TSTUSR global curspace)
1913 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1914 "Used space(${USED}K) is less than ${BLKS}M"
1917 resetquota -u $TSTUSR
1920 # DQACQ return recoverable error
1922 echo "DQACQ return -ENOLCK"
1924 test_17sub 37 || error "Handle -ENOLCK failed"
1926 echo "DQACQ return -EAGAIN"
1928 test_17sub 11 || error "Handle -EAGAIN failed"
1930 echo "DQACQ return -ETIMEDOUT"
1931 #define ETIMEDOUT 110
1932 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1934 echo "DQACQ return -ENOTCONN"
1935 #define ENOTCONN 107
1936 test_17sub 107 || error "Handle -ENOTCONN failed"
1939 run_test 17 "DQACQ return recoverable error"
1943 local blimit="200m" # 200M
1944 local TESTFILE="$DIR/$tdir/$tfile"
1946 setup_quota_test || error "setup quota failed with $?"
1947 trap cleanup_quota_test EXIT
1949 set_ost_qtype "u" || error "enable ost quota failed"
1950 log "User quota (limit: $blimit)"
1951 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1952 error "set quota failed"
1953 quota_show_check b u $TSTUSR
1955 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1956 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1958 local timeout=$(sysctl -n lustre.timeout)
1960 if [ $io_type = "directio" ]; then
1961 log "Write 100M (directio) ..."
1962 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1964 log "Write 100M (buffered) ..."
1965 $RUNAS $DD of=$TESTFILE count=100 &
1969 replay_barrier $SINGLEMDS
1970 log "Fail mds for $((2 * timeout)) seconds"
1971 fail $SINGLEMDS $((2 * timeout))
1974 if at_is_enabled; then
1975 timeout=$(at_max_get mds)
1977 timeout=$(lctl get_param -n timeout)
1981 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1982 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1983 log "it took $count second"
1988 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1990 cancel_lru_locks mdc
1991 cancel_lru_locks osc
1994 local testfile_size=$(stat -c %s $TESTFILE)
1995 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1996 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1997 "got ${testfile_size}. Verifying file failed!"
2000 resetquota -u $TSTUSR
2003 # test when mds does failover, the ost still could work well
2004 # this test shouldn't trigger watchdog b=14840
2006 # Clear dmesg so watchdog is not triggered by previous
2008 do_facet ost1 dmesg -c > /dev/null
2011 test_18_sub directio
2013 # check if watchdog is triggered
2014 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2015 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2016 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2017 [ -z "$watchdog" ] || error "$watchdog"
2018 rm -f $TMP/lustre-log-${TESTNAME}.log
2020 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2024 local TESTFILE=$DIR/$tdir/$tfile
2026 setup_quota_test || error "setup quota failed with $?"
2027 trap cleanup_quota_test EXIT
2029 set_ost_qtype $QTYPE || error "enable ost quota failed"
2031 # bind file to a single OST
2032 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2033 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2035 echo "Set user quota (limit: ${blimit}M)"
2036 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2037 error "set user quota failed"
2038 quota_show_check b u $TSTUSR
2039 echo "Update quota limits"
2040 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2041 error "set group quota failed"
2042 quota_show_check b u $TSTUSR
2044 # first wirte might be cached
2045 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2046 cancel_lru_locks osc
2048 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2049 quota_error u $TSTUSR "Write success, expect failure"
2053 resetquota -u $TSTUSR
2055 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2057 test_20() { # b15754
2058 local LSTR=(2g 1t 4k 3m) # limits strings
2060 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2063 resetquota -u $TSTUSR
2065 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2066 $MOUNT || error "could not set quota limits"
2067 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2068 --inode-softlimit ${LSTR[2]} \
2069 --inode-hardlimit ${LSTR[3]} \
2070 $MOUNT || error "could not set quota limits"
2072 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2073 error "bsoftlimit was not set properly"
2074 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2075 error "bhardlimit was not set properly"
2076 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2077 error "isoftlimit was not set properly"
2078 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2079 error "ihardlimit was not set properly"
2081 resetquota -u $TSTUSR
2083 run_test 20 "Test if setquota specifiers work properly (b15754)"
2090 local time=$(($(date +%s) + seconds))
2091 while [ $(date +%s) -lt $time ]; do
2092 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2096 # run for fixing bug16053, setquota shouldn't fail when writing and
2097 # deleting are happening
2099 local TESTFILE="$DIR/$tdir/$tfile"
2100 local BLIMIT=10 # 10G
2101 local ILIMIT=1000000
2103 setup_quota_test || error "setup quota failed with $?"
2104 trap cleanup_quota_test EXIT
2106 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2108 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2109 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2110 error "set user quota failed"
2111 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2112 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2113 error "set group quota failed"
2114 if is_project_quota_supported; then
2115 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2116 "project: $TSTPRJID"
2117 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2118 $MOUNT || error "set project quota failed"
2121 # repeat writing on a 1M file
2122 test_21_sub ${TESTFILE}_1 1 30 &
2124 # repeat writing on a 128M file
2125 test_21_sub ${TESTFILE}_2 128 30 &
2128 local time=$(($(date +%s) + 30))
2130 while [ $(date +%s) -lt $time ]; do
2131 log "Set quota for $i times"
2132 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2133 -I $((ILIMIT + i)) $MOUNT ||
2134 error "Set user quota failed"
2135 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2136 -I $((ILIMIT + i)) $MOUNT ||
2137 error "Set group quota failed"
2138 if is_project_quota_supported; then
2139 $LFS setquota -p $TSTPRJID -b 0 -B \
2140 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2141 error "Set project quota failed"
2149 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2151 if [ $count -gt 60 ]; then
2152 quota_error a $TSTUSR "dd should be finished!"
2156 echo "(dd_pid=$DDPID1, time=$count)successful"
2160 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2162 if [ $count -gt 60 ]; then
2163 quota_error a $TSTUSR "dd should be finished!"
2167 echo "(dd_pid=$DDPID2, time=$count)successful"
2170 resetquota -u $TSTUSR
2171 resetquota -g $TSTUSR
2172 resetquota -p $TSTPRJID
2174 run_test 21 "Setquota while writing & deleting (b16053)"
2176 # enable/disable quota enforcement permanently
2178 echo "Set both mdt & ost quota type as ug"
2180 is_project_quota_supported && qtype=$QTYPE
2181 set_mdt_qtype $qtype || error "enable mdt quota failed"
2182 set_ost_qtype $qtype || error "enable ost quota failed"
2185 stopall || error "failed to stopall (1)"
2189 echo "Verify if quota is enabled"
2190 local qtype1=$(mdt_quota_type)
2191 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2192 qtype=$(ost_quota_type)
2193 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2195 echo "Set both mdt & ost quota type as none"
2196 set_mdt_qtype "none" || error "disable mdt quota failed"
2197 set_ost_qtype "none" || error "disable ost quota failed"
2200 stopall || error "failed to stopall (2)"
2205 echo "Verify if quota is disabled"
2206 qtype=$(mdt_quota_type)
2207 [ $qtype != "none" ] && error "mdt quota setting is lost"
2208 qtype=$(ost_quota_type)
2209 [ $qtype != "none" ] && error "ost quota setting is lost"
2213 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2216 local TESTFILE="$DIR/$tdir/$tfile"
2219 setup_quota_test || error "setup quota failed with $?"
2220 trap cleanup_quota_test EXIT
2222 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2225 log "User quota (limit: $LIMIT MB)"
2226 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2227 error "set quota failed"
2228 quota_show_check b u $TSTUSR
2230 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2231 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2233 log "Step1: trigger EDQUOT with O_DIRECT"
2234 log "Write half of file"
2235 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2236 quota_error u $TSTUSR "(1) Write failure, expect success." \
2238 log "Write out of block quota ..."
2239 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2240 oflag=direct conv=notrunc &&
2241 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2245 log "Step2: rewrite should succeed"
2246 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2247 quota_error u $TSTUSR "(3) Write failure, expect success." \
2253 local OST0_UUID=$(ostuuid_from_index 0)
2254 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2255 [ $OST0_QUOTA_USED -ne 0 ] &&
2256 ($SHOW_QUOTA_USER; \
2257 quota_error u $TSTUSR "quota isn't released")
2259 resetquota -u $TSTUSR
2263 [ $(facet_fstype ost1) == "zfs" ] &&
2264 skip "Overwrite in place is not guaranteed to be " \
2265 "space neutral on ZFS"
2267 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2268 check_whether_skip && return 0
2269 log "run for 4MB test file"
2272 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2273 check_whether_skip && return 0
2274 log "run for 40MB test file"
2277 run_test 23 "Quota should be honored with directIO (b16125)"
2281 local TESTFILE="$DIR/$tdir/$tfile"
2283 setup_quota_test || error "setup quota failed with $?"
2284 trap cleanup_quota_test EXIT
2286 set_ost_qtype $QTYPE || error "enable ost quota failed"
2288 # bind file to a single OST
2289 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2290 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2292 echo "Set user quota (limit: ${blimit}M)"
2293 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2294 error "set quota failed"
2296 # overrun quota by root user
2297 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2298 error "write failure, expect success"
2299 cancel_lru_locks osc
2300 sync_all_data || true
2302 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2305 resetquota -u $TSTUSR
2307 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2309 test_27a() { # b19612
2310 $LFS quota $TSTUSR $DIR &&
2311 error "lfs succeeded with no type, but should have failed"
2312 $LFS setquota $TSTUSR $DIR &&
2313 error "lfs succeeded with no type, but should have failed"
2316 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2318 test_27b() { # b20200
2319 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2320 error "lfs setquota failed with uid argument"
2321 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2322 error "lfs stequota failed with gid argument"
2323 if is_project_quota_supported; then
2324 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2325 1000 $DIR || error \
2326 "lfs stequota failed with projid argument"
2328 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2329 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2330 if is_project_quota_supported; then
2331 $SHOW_QUOTA_PROJID ||
2332 error "lfs quota failed with projid argument"
2334 resetquota -u $TSTUSR
2335 resetquota -g $TSTUSR
2336 resetquota -p $TSTPRJID
2339 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2344 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2345 error "lfs setquota failed"
2347 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2348 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2349 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2350 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2352 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2353 error "lfs setquota for $TSTID failed"
2355 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2356 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2357 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2358 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2360 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2361 error "total allocated inode/block limit not printed"
2363 resetquota -u $TSTUSR
2365 run_test 27c "lfs quota should support human-readable output"
2372 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2373 error "set fraction block limit failed"
2374 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2375 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2376 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2377 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2379 resetquota -u $TSTUSR
2381 run_test 27d "lfs setquota should support fraction block limit"
2385 local TESTFILE="$DIR/$tdir/$tfile"
2388 setup_quota_test || error "setup quota failed with $?"
2389 trap cleanup_quota_test EXIT
2391 set_ost_qtype "u" || error "enable ost quota failed"
2393 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2394 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2396 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2397 $MAX_IQ_TIME $DIR || error "set grace time failed"
2398 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2399 error "set quota failed"
2400 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2401 cancel_lru_locks osc
2403 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2404 # over-quota flag has not yet settled since we do not trigger async
2405 # events based on grace time period expiration
2407 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2408 cancel_lru_locks osc
2409 # now over-quota flag should be settled and further writes should fail
2411 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2412 error "grace times were reset"
2415 resetquota -u $TSTUSR
2416 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2417 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2419 run_test 30 "Hard limit updates should not reset grace times"
2421 # basic usage tracking for user & group
2423 local INODES=10 # 10 files
2424 local BLK_CNT=2 # of 2M each
2425 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2427 setup_quota_test || error "setup quota failed with $?"
2428 trap cleanup_quota_test EXIT
2430 # make sure the system is clean
2431 local USED=$(getquota -u $TSTID global curspace)
2433 error "Used space ($USED) for user $TSTID isn't 0."
2434 USED=$(getquota -g $TSTID global curspace)
2436 error "Used space ($USED) for group $TSTID isn't 0."
2437 if is_project_quota_supported; then
2438 USED=$(getquota -p $TSTPRJID global curspace)
2439 [ $USED -ne 0 ] && error \
2440 "Used space ($USED) for project $TSTPRJID isn't 0."
2443 echo "Write files..."
2444 for i in $(seq 0 $INODES); do
2445 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2446 error "write failed"
2447 is_project_quota_supported &&
2448 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2449 echo "Iteration $i/$INODES completed"
2451 cancel_lru_locks osc
2453 echo "Wait for setattr on objects finished..."
2454 wait_delete_completed
2456 sync; sync_all_data || true
2458 echo "Verify disk usage after write"
2459 USED=$(getquota -u $TSTID global curspace)
2460 [ $USED -lt $TOTAL_BLKS ] &&
2461 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2462 USED=$(getquota -g $TSTID global curspace)
2463 [ $USED -lt $TOTAL_BLKS ] &&
2464 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2465 if is_project_quota_supported; then
2466 USED=$(getquota -p $TSTPRJID global curspace)
2467 [ $USED -lt $TOTAL_BLKS ] && error \
2468 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2471 echo "Verify inode usage after write"
2472 USED=$(getquota -u $TSTID global curinodes)
2473 [ $USED -lt $INODES ] &&
2474 error "Used inode for user $TSTID is $USED, expected $INODES"
2475 USED=$(getquota -g $TSTID global curinodes)
2476 [ $USED -lt $INODES ] &&
2477 error "Used inode for group $TSTID is $USED, expected $INODES"
2478 if is_project_quota_supported; then
2479 USED=$(getquota -p $TSTPRJID global curinodes)
2480 [ $USED -lt $INODES ] && error \
2481 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2486 echo "Verify disk usage after delete"
2487 USED=$(getquota -u $TSTID global curspace)
2488 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2489 USED=$(getquota -u $TSTID global curinodes)
2490 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2491 USED=$(getquota -g $TSTID global curspace)
2492 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2493 USED=$(getquota -g $TSTID global curinodes)
2494 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2495 if is_project_quota_supported; then
2496 USED=$(getquota -p $TSTPRJID global curspace)
2498 error "Used space for project $TSTPRJID isn't 0. $USED"
2499 USED=$(getquota -p $TSTPRJID global curinodes)
2501 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2504 run_test 33 "Basic usage tracking for user & group & project"
2506 # usage transfer test for user & group & project
2508 local BLK_CNT=2 # 2MB
2509 local project_supported="no"
2511 is_project_quota_supported && project_supported="yes"
2512 setup_quota_test || error "setup quota failed with $?"
2513 trap cleanup_quota_test EXIT
2515 # make sure the system is clean
2516 local USED=$(getquota -u $TSTID global curspace)
2517 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2518 USED=$(getquota -g $TSTID global curspace)
2519 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2521 local USED=$(getquota -u $TSTID2 global curspace)
2522 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2523 if [ $project_supported == "yes" ]; then
2524 USED=$(getquota -p $TSTPRJID global curspace)
2525 [ $USED -ne 0 ] && error \
2526 "Used space ($USED) for Project $TSTPRJID isn't 0."
2529 echo "Write file..."
2530 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2531 error "write failed"
2532 cancel_lru_locks osc
2533 sync; sync_all_data || true
2535 echo "chown the file to user $TSTID"
2536 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2538 echo "Wait for setattr on objects finished..."
2539 wait_delete_completed
2541 BLK_CNT=$((BLK_CNT * 1024))
2543 echo "Verify disk usage for user $TSTID"
2544 USED=$(getquota -u $TSTID global curspace)
2545 [ $USED -lt $BLK_CNT ] &&
2546 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2547 USED=$(getquota -u $TSTID global curinodes)
2549 error "Used inodes for user $TSTID is $USED, expected 1"
2551 echo "chgrp the file to group $TSTID"
2552 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2554 echo "Wait for setattr on objects finished..."
2555 wait_delete_completed
2557 echo "Verify disk usage for group $TSTID"
2558 USED=$(getquota -g $TSTID global curspace)
2559 [ $USED -ge $BLK_CNT ] ||
2560 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2561 USED=$(getquota -g $TSTID global curinodes)
2563 error "Used inodes for group $TSTID is $USED, expected 1"
2565 # chown won't change the ost object group. LU-4345 */
2566 echo "chown the file to user $TSTID2"
2567 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2569 echo "Wait for setattr on objects finished..."
2570 wait_delete_completed
2572 echo "change_project project id to $TSTPRJID"
2573 [ $project_supported == "yes" ] &&
2574 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2575 echo "Wait for setattr on objects finished..."
2576 wait_delete_completed
2578 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2579 USED=$(getquota -u $TSTID2 global curspace)
2580 [ $USED -lt $BLK_CNT ] &&
2581 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2582 USED=$(getquota -u $TSTID global curspace)
2584 error "Used space for user $TSTID is $USED, expected 0"
2585 USED=$(getquota -g $TSTID global curspace)
2586 [ $USED -lt $BLK_CNT ] &&
2587 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2588 if [ $project_supported == "yes" ]; then
2589 USED=$(getquota -p $TSTPRJID global curspace)
2590 [ $USED -lt $BLK_CNT ] && error \
2591 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2596 run_test 34 "Usage transfer for user & group & project"
2598 # usage is still accessible across restart
2600 local BLK_CNT=2 # 2 MB
2602 setup_quota_test || error "setup quota failed with $?"
2603 trap cleanup_quota_test EXIT
2605 echo "Write file..."
2606 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2607 error "write failed"
2608 is_project_quota_supported &&
2609 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2610 cancel_lru_locks osc
2612 echo "Wait for setattr on objects finished..."
2613 wait_delete_completed
2615 sync; sync_all_data || true
2617 echo "Save disk usage before restart"
2618 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2619 [ $ORIG_USR_SPACE -eq 0 ] &&
2620 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2621 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2622 [ $ORIG_USR_INODES -eq 0 ] &&
2623 error "Used inodes for user $TSTID is 0, expected 1"
2624 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2625 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2626 [ $ORIG_GRP_SPACE -eq 0 ] &&
2627 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2628 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2629 [ $ORIG_GRP_INODES -eq 0 ] &&
2630 error "Used inodes for group $TSTID is 0, expected 1"
2631 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2633 if is_project_quota_supported; then
2634 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2635 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2636 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2637 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2638 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2639 "Used inodes for project $TSTPRJID is 0, expected 1"
2640 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2648 echo "Verify disk usage after restart"
2649 local USED=$(getquota -u $TSTID global curspace)
2650 [ $USED -eq $ORIG_USR_SPACE ] ||
2651 error "Used space for user $TSTID changed from " \
2652 "$ORIG_USR_SPACE to $USED"
2653 USED=$(getquota -u $TSTID global curinodes)
2654 [ $USED -eq $ORIG_USR_INODES ] ||
2655 error "Used inodes for user $TSTID changed from " \
2656 "$ORIG_USR_INODES to $USED"
2657 USED=$(getquota -g $TSTID global curspace)
2658 [ $USED -eq $ORIG_GRP_SPACE ] ||
2659 error "Used space for group $TSTID changed from " \
2660 "$ORIG_GRP_SPACE to $USED"
2661 USED=$(getquota -g $TSTID global curinodes)
2662 [ $USED -eq $ORIG_GRP_INODES ] ||
2663 error "Used inodes for group $TSTID changed from " \
2664 "$ORIG_GRP_INODES to $USED"
2665 if [ $project_supported == "yes" ]; then
2666 USED=$(getquota -p $TSTPRJID global curinodes)
2667 [ $USED -eq $ORIG_PRJ_INODES ] ||
2668 error "Used inodes for project $TSTPRJID " \
2669 "changed from $ORIG_PRJ_INODES to $USED"
2670 USED=$(getquota -p $TSTPRJID global curspace)
2671 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2672 error "Used space for project $TSTPRJID "\
2673 "changed from $ORIG_PRJ_SPACE to $USED"
2676 # check if the vfs_dq_init() is called before writing
2677 echo "Append to the same file..."
2678 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2679 error "write failed"
2680 cancel_lru_locks osc
2681 sync; sync_all_data || true
2683 echo "Verify space usage is increased"
2684 USED=$(getquota -u $TSTID global curspace)
2685 [ $USED -gt $ORIG_USR_SPACE ] ||
2686 error "Used space for user $TSTID isn't increased" \
2687 "orig:$ORIG_USR_SPACE, now:$USED"
2688 USED=$(getquota -g $TSTID global curspace)
2689 [ $USED -gt $ORIG_GRP_SPACE ] ||
2690 error "Used space for group $TSTID isn't increased" \
2691 "orig:$ORIG_GRP_SPACE, now:$USED"
2692 if [ $project_supported == "yes" ]; then
2693 USED=$(getquota -p $TSTPRJID global curspace)
2694 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2695 error "Used space for project $TSTPRJID isn't " \
2696 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2701 run_test 35 "Usage is still accessible across reboot"
2703 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2706 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2707 skip "Old server doesn't have LU-5006 fix."
2709 setup_quota_test || error "setup quota failed with $?"
2710 trap cleanup_quota_test EXIT
2712 # make sure the system is clean
2713 local USED=$(getquota -u $TSTID global curspace)
2715 error "Used space ($USED) for user $TSTID isn't 0."
2717 # create file with MDS_OPEN_DELAY_CREATE flag
2718 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2719 error "Create file failed"
2721 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2722 oflag=sync || error "Write file failed"
2724 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2726 # wait for setattr on objects finished..."
2727 wait_delete_completed
2729 USED=$(getquota -u $TSTID global curspace)
2730 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2734 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2738 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2739 skip "Old server doesn't have LU-8801 fix."
2741 [ "$UID" != 0 ] && skip_env "must run as root" && return
2743 setup_quota_test || error "setup quota failed with $?"
2744 trap cleanup_quota_test EXIT
2746 # make sure the system is clean
2747 local USED=$(getquota -u $TSTID global curspace)
2749 error "Used space ($USED) for user $TSTID isn't 0."
2750 USED=$(getquota -u $TSTID2 global curspace)
2752 error "Used space ($USED) for user $TSTID2 isn't 0."
2754 local TESTFILE="$DIR/$tdir/$tfile"
2755 local file_cnt=10000
2757 # Generate id entries in accounting file
2758 echo "Create $file_cnt files..."
2759 for i in `seq $file_cnt`; do
2761 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2762 error "failed to chown $TESTFILE-$i"
2764 cancel_lru_locks osc
2765 sync; sync_all_data || true
2767 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2768 procf=${procf}.quota_slave.acct_user
2771 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2772 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2773 echo "Found $acct_cnt id entries"
2775 [ $file_cnt -eq $acct_cnt ] || {
2776 do_facet mds1 $LCTL get_param $procf
2777 error "skipped id entries"
2782 run_test 38 "Quota accounting iterator doesn't skip id entries"
2785 local TESTFILE="$DIR/$tdir/project"
2786 ! is_project_quota_supported &&
2787 skip "Project quota is not supported"
2789 setup_quota_test || error "setup quota failed with $?"
2792 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2793 [ $projectid -ne 0 ] &&
2794 error "Project id should be 0 not $projectid"
2795 change_project -p 1024 $TESTFILE
2796 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2797 [ $projectid -ne 1024 ] &&
2798 error "Project id should be 1024 not $projectid"
2800 stopall || error "failed to stopall (1)"
2803 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2804 [ $projectid -ne 1024 ] &&
2805 error "Project id should be 1024 not $projectid"
2809 run_test 39 "Project ID interface works correctly"
2812 ! is_project_quota_supported &&
2813 skip "Project quota is not supported"
2814 local dir1="$DIR/$tdir/dir1"
2815 local dir2="$DIR/$tdir/dir2"
2817 setup_quota_test || error "setup quota failed with $?"
2819 mkdir -p $dir1 $dir2
2820 change_project -sp 1 $dir1 && touch $dir1/1
2821 change_project -sp 2 $dir2
2823 ln $dir1/1 $dir2/1_link &&
2824 error "Hard link across different project quota should fail"
2829 run_test 40a "Hard link across different project ID"
2832 ! is_project_quota_supported &&
2833 skip "Project quota is not supported"
2834 local dir1="$DIR/$tdir/dir1"
2835 local dir2="$DIR/$tdir/dir2"
2837 setup_quota_test || error "setup quota failed with $?"
2838 mkdir -p $dir1 $dir2
2839 change_project -sp 1 $dir1 && touch $dir1/1
2840 change_project -sp 2 $dir2
2842 mv $dir1/1 $dir2/2 || error "mv failed $?"
2843 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2844 if [ "$projid" != "2" ]; then
2845 error "project id expected 2 not $projid"
2850 run_test 40b "Mv across different project ID"
2853 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2854 ! is_project_quota_supported &&
2855 skip "Project quota is not supported"
2857 setup_quota_test || error "setup quota failed with $?"
2858 local dir="$DIR/$tdir/dir"
2860 mkdir -p $dir && change_project -sp 1 $dir
2861 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2862 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2863 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2864 touch $dir/remote_dir/file
2865 #verify inherit works file for remote dir.
2866 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2867 [ "$projid" != "1" ] &&
2868 error "file under remote dir expected 1 not $projid"
2870 #Agent inode should be ignored for project quota
2871 USED=$(getquota -p 1 global curinodes)
2872 [ "$USED" != "3" ] &&
2873 error "file count expected 3 got $USED"
2879 run_test 40c "Remote child Dir inherit project quota properly"
2882 ! is_project_quota_supported &&
2883 skip "Project quota is not supported"
2885 setup_quota_test || error "setup quota failed with $?"
2886 local dir="$DIR/$tdir/dir"
2888 mkdir $dir && change_project -p 1 $dir
2889 count=$($LFS find --projid 1 $DIR | wc -l)
2890 [ "$count" != 1 ] && error "expected 1 but got $count"
2895 run_test 50 "Test if lfs find --projid works"
2898 ! is_project_quota_supported &&
2899 skip "Project quota is not supported"
2900 setup_quota_test || error "setup quota failed with $?"
2901 local dir="$DIR/$tdir/dir"
2903 mkdir $dir && change_project -sp 1 $dir
2904 local used=$(getquota -p 1 global curinodes)
2905 [ $used != "1" ] && error "expected 1 got $used"
2910 used=$(getquota -p 1 global curinodes)
2911 [ $used != "4" ] && error "expected 4 got $used"
2913 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2915 cp $DIR/$tdir/6 $dir/6
2916 used=$(getquota -p 1 global curinodes)
2917 [ $used != "5" ] && error "expected 5 got $used"
2920 mv $DIR/$tdir/6 $dir/7
2921 used=$(getquota -p 1 global curinodes)
2922 [ $used != "6" ] && error "expected 6 got $used"
2927 run_test 51 "Test project accounting with mv/cp"
2930 ! is_project_quota_supported &&
2931 skip "Project quota is not supported"
2932 setup_quota_test || error "setup quota failed with $?"
2933 local dir="$DIR/$tdir/dir"
2934 mkdir $dir && change_project -sp 1 $dir
2936 touch $DIR/$tdir/file
2937 #Try renaming a file into the project. This should fail.
2938 for num in $(seq 1 2000); do
2939 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2940 error "rename should fail"
2945 run_test 52 "Rename across different project ID"
2948 ! is_project_quota_supported &&
2949 skip "Project quota is not supported"
2950 setup_quota_test || error "setup quota failed with $?"
2951 local dir="$DIR/$tdir/dir"
2952 mkdir $dir && change_project -s $dir
2953 lfs project -d $dir | grep P || error "inherit attribute should be set"
2955 change_project -C $dir
2956 lfs project -d $dir | grep P &&
2957 error "inherit attribute should be cleared"
2962 run_test 53 "Project inherit attribute could be cleared"
2965 ! is_project_quota_supported &&
2966 skip "Project quota is not supported"
2967 setup_quota_test || error "setup quota failed with $?"
2968 trap cleanup_quota_test EXIT
2969 local testfile="$DIR/$tdir/$tfile-0"
2971 #set project ID/inherit attribute
2972 change_project -sp $TSTPRJID $DIR/$tdir
2973 $RUNAS createmany -m ${testfile} 100 ||
2974 error "create many files failed"
2976 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2977 # one more count for directory itself */
2981 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2982 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2984 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2985 [ $proj_count1 -eq $proj_count ] ||
2986 error "c2: expected $proj_count got $proj_count1"
2988 #clear project but with kept projid
2989 change_project -rCk $DIR/$tdir
2990 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2991 [ $proj_count1 -eq $proj_count ] ||
2992 error "c3: expected $proj_count got $proj_count1"
2994 #verify projid untouched.
2995 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2997 [ $proj_count1 -eq $proj_count ] ||
2998 error "c4: expected $proj_count got $proj_count1"
3001 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3002 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3003 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3005 #this time clear all
3006 change_project -rC $DIR/$tdir
3007 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3008 [ $proj_count1 -eq 0 ] ||
3009 error "c6: expected 0 got $proj_count1"
3011 unlinkmany ${testfile} 100 ||
3012 error "unlink many files failed"
3016 run_test 54 "basic lfs project interface test"
3019 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3020 skip "Not supported before 2.10.58."
3021 setup_quota_test || error "setup quota failed with $?"
3023 set_ost_qtype $QTYPE || error "enable ost quota failed"
3026 #add second group to TSTUSR
3027 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3030 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3031 error "failed to dd"
3033 cancel_lru_locks osc
3034 sync; sync_all_data || true
3036 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3037 error "failed to setquota on group $TSTUSR2"
3039 $LFS quota -v -g $TSTUSR2 $DIR
3041 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3042 error "chgrp should failed with -EDQUOT"
3044 USED=$(getquota -g $TSTUSR2 global curspace)
3047 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3048 error "failed to setquota on group $TSTUSR2"
3050 $LFS quota -v -g $TSTUSR2 $DIR
3052 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3053 error "chgrp should succeed"
3055 $LFS quota -v -g $TSTUSR2 $DIR
3057 resetquota -g $TSTUSR2
3060 run_test 55 "Chgrp should be affected by group quota"
3063 setup_quota_test || error "setup quota failed with $?"
3065 set_ost_qtype $QTYPE || error "enable ost quota failed"
3068 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3069 erro "failed to set grace time for usr quota"
3070 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3071 awk '{print $4 $8}')
3072 if [ "x$grace_time" != "x10s;10s" ]; then
3073 $LFS quota -t -u $DIR
3074 error "expected grace time: 10s;10s, got:$grace_time"
3079 run_test 56 "lfs quota -t should work well"
3082 setup_quota_test || error "setup quota failed with $?"
3084 local dir="$DIR/$tdir/dir"
3087 #try to change pipe file should not hang and return failure
3088 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3089 awk -F ':' '{ print \\\$2 }'" \
3090 " failed to get xattr for '$dir/pipe'" || return 1
3091 #command can process further if it hit some errors
3092 touch $dir/aaa $dir/bbb
3093 mkdir $dir/subdir -p
3094 touch $dir/subdir/aaa $dir/subdir/bbb
3095 #create one invalid link file
3096 ln -s $dir/not_exist_file $dir/ccc
3097 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3098 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3102 run_test 57 "lfs project could tolerate errors"
3105 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3106 skip "ldiskfs only test"
3107 disable_project_quota
3108 setup_quota_test || error "setup quota failed with $?"
3111 local testfile="$DIR/$tdir/$tfile-0"
3112 #make sure it did not crash kernel
3113 touch $testfile && lfs project -sp 1 $testfile
3115 enable_project_quota
3118 run_test 59 "lfs project dosen't crash kernel with project disabled"
3121 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3122 skip "Needs MDS version 2.11.53 or later."
3123 setup_quota_test || error "setup quota failed with $?"
3124 trap cleanup_quota_test EXIT
3126 local testfile=$DIR/$tdir/$tfile
3129 set_mdt_qtype "ug" || error "enable mdt quota failed"
3131 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3132 error "set quota failed"
3133 quota_show_check a g $TSTUSR
3135 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3136 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3137 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3138 error "create many files failed"
3140 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3142 # root user can overrun quota
3143 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3144 error "root user should succeed"
3147 resetquota -g $TSTUSR
3149 run_test 60 "Test quota for root with setgid"
3151 # test default quota
3152 test_default_quota() {
3153 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3154 skip "Not supported before 2.11.51."
3159 local qprjid=$TSTPRJID
3163 local LIMIT=20480 #20M disk space
3164 local TESTFILE="$DIR/$tdir/$tfile-0"
3166 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3167 echo "Project quota is not supported" && return 0
3169 [ $qtype == "-u" ] && qdtype="-U"
3170 [ $qtype == "-g" ] && qdtype="-G"
3171 [ $qtype == "-p" ] && {
3176 [ $qpool == "meta" ] && {
3177 LIMIT=10240 #10K inodes
3182 setup_quota_test || error "setup quota failed with $?"
3183 trap cleanup_quota_test EXIT
3187 # enable mdt/ost quota
3188 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3189 set_ost_qtype $QTYPE || error "enable ost quota failed"
3191 log "set to use default quota"
3192 $LFS setquota $qtype $qid -d $DIR ||
3193 error "set $qid to use default quota failed"
3195 log "set default quota"
3196 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3197 error "set $qid default quota failed"
3199 log "get default quota"
3200 $LFS quota $qdtype $DIR || error "get default quota failed"
3202 if [ $qpool == "data" ]; then
3203 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3205 [ $SLIMIT -eq $LIMIT ] ||
3206 error "the returned default quota is wrong"
3208 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3210 [ $SLIMIT -eq $LIMIT ] ||
3211 error "the returned default quota is wrong"
3214 # make sure the system is clean
3215 local USED=$(getquota $qtype $qid global curspace)
3216 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3218 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3219 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3221 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3223 log "Test not out of quota"
3224 if [ $qpool == "data" ]; then
3225 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3226 quota_error $qtype $qid "write failed, expect succeed"
3228 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3229 quota_error $qtype $qid "create failed, expect succeed"
3231 unlinkmany $TESTFILE $((LIMIT/2))
3234 log "Test out of quota"
3235 # flush cache, ensure noquota flag is set on client
3236 cancel_lru_locks osc
3237 cancel_lru_locks mdc
3238 sync; sync_all_data || true
3239 if [ $qpool == "data" ]; then
3240 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3241 quota_error $qtype $qid "write succeed, expect EDQUOT"
3243 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3244 quota_error $qtype $qid "create succeed, expect EDQUOT"
3246 unlinkmany $TESTFILE $((LIMIT*2))
3249 log "Increase default quota"
3250 # increase default quota
3251 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3252 error "set default quota failed"
3254 cancel_lru_locks osc
3255 cancel_lru_locks mdc
3256 sync; sync_all_data || true
3257 if [ $qpool == "data" ]; then
3258 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3259 quota_error $qtype $qid "write failed, expect succeed"
3261 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3262 quota_error $qtype $qid "create failed, expect succeed"
3264 unlinkmany $TESTFILE $((LIMIT*2))
3267 log "Set quota to override default quota"
3268 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3269 error "set $qid quota failed"
3271 cancel_lru_locks osc
3272 cancel_lru_locks mdc
3273 sync; sync_all_data || true
3274 if [ $qpool == "data" ]; then
3275 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3276 quota_error $qtype $qid "write succeed, expect EQUOT"
3278 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3279 quota_error $qtype $qid "create succeed, expect EQUOT"
3281 unlinkmany $TESTFILE $((LIMIT*2))
3284 log "Set to use default quota again"
3285 $LFS setquota $qtype $qid -d $DIR ||
3286 error "set $qid to use default quota failed"
3288 cancel_lru_locks osc
3289 cancel_lru_locks mdc
3290 sync; sync_all_data || true
3291 if [ $qpool == "data" ]; then
3292 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3293 quota_error $qtype $qid "write failed, expect succeed"
3295 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3296 quota_error $qtype $qid "create failed, expect succeed"
3298 unlinkmany $TESTFILE $((LIMIT*2))
3303 wait_delete_completed || error "wait_delete_completed failed"
3304 sync_all_data || true
3305 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3306 error "reset default quota failed"
3307 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3308 error "reset quota failed"
3314 test_default_quota "-u" "data"
3315 test_default_quota "-u" "meta"
3316 test_default_quota "-g" "data"
3317 test_default_quota "-g" "meta"
3318 test_default_quota "-p" "data"
3319 test_default_quota "-p" "meta"
3321 run_test 61 "default quota tests"
3324 ! is_project_quota_supported &&
3325 skip "Project quota is not supported"
3326 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3327 skip "chattr did not support project quota"
3328 setup_quota_test || error "setup quota failed with $?"
3329 local testdir=$DIR/$tdir/
3331 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3332 change_project -s $testdir
3333 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3334 error "inherit attribute should be set"
3335 # chattr used FS_IOC_SETFLAGS ioctl
3336 $RUNAS chattr -P $testdir &&
3337 error "regular user clear inherit should fail"
3338 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3339 error "inherit attribute should still be set"
3340 chattr -P $testdir || error "root failed to clear inherit"
3341 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3342 error "inherit attribute should be cleared"
3345 run_test 62 "Project inherit should be only changed by root"
3348 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3349 skip "Not supported before 2.11.55" && return
3353 local dd_failed=false
3354 local tdir_dom=${tdir}_dom
3355 local LIMIT=20480 #20M
3357 [ $qtype == "p" ] && ! is_project_quota_supported &&
3358 echo "Project quota is not supported" && return 0
3360 [ $qtype == "p" ] && qid=$TSTPRJID
3362 setup_quota_test || error "setup quota failed with $?"
3363 trap cleanup_quota_test EXIT
3367 # enable mdt/ost quota
3368 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3369 set_ost_qtype $QTYPE || error "enable ost quota failed"
3371 # make sure the system is clean
3372 local USED=$(getquota -$qtype $qid global curspace)
3373 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3375 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3377 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3378 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3379 error "setstripe $tdir_dom failed"
3380 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3382 [ $qtype == "p" ] && {
3383 change_project -sp $TSTPRJID $DIR/$tdir
3384 change_project -sp $TSTPRJID $DIR/$tdir_dom
3387 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3388 error "set $qid quota failed"
3390 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3391 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3395 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3397 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3398 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3402 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3404 rm -f $DIR/$tdir_dom/*
3406 # flush cache, ensure noquota flag is set on client
3407 cancel_lru_locks osc
3408 cancel_lru_locks mdc
3409 sync; sync_all_data || true
3413 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3414 quota_error $qtype $qid "write failed, expect succeed"
3416 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3417 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3421 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3424 rm -f $DIR/$tdir_dom/*
3426 # flush cache, ensure noquota flag is set on client
3427 cancel_lru_locks osc
3428 cancel_lru_locks mdc
3429 sync; sync_all_data || true
3433 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3434 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3438 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3440 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3441 quota_error $qtype $qid "write succeed, expect EDQUOT"
3444 rm -fr $DIR/$tdir_dom
3446 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3447 error "reset usr quota failed"
3457 run_test 63 "quota on DoM tests"
3461 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3462 if $PQ_CLEANUP; then
3463 disable_project_quota
3466 reset_quota_settings
3471 check_and_cleanup_lustre
3472 export QUOTA_AUTO=$QUOTA_AUTO_OLD