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:
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
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 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
990 test_file_soft $TESTFILE $LIMIT $GRACE
991 resetquota -u $TSTUSR
993 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
994 # make sure the system is clean
995 USED=$(getquota -g $TSTUSR global curinodes)
996 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
998 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
999 $GRACE $DIR || error "set group grace time failed"
1000 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1001 error "set group quota failed"
1002 TESTFILE=$DIR/$tdir/$tfile-1
1004 test_file_soft $TESTFILE $LIMIT $GRACE
1005 resetquota -g $TSTUSR
1007 if is_project_quota_supported; then
1008 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1009 # make sure the system is clean
1010 USED=$(getquota -p $TSTPRJID global curinodes)
1011 [ $USED -ne 0 ] && error \
1012 "Used space($USED) for project $TSTPRJID isn't 0."
1014 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1015 $GRACE $DIR || error "set project grace time failed"
1016 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1017 error "set project quota failed"
1019 TESTFILE=$DIR/$tdir/$tfile-1
1020 # one less than limit, because of parent directory included.
1021 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1022 resetquota -p $TSTPRJID
1023 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1024 $MAX_IQ_TIME $DIR ||
1025 error "restore project grace time failed"
1029 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1030 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1031 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1032 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1034 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1037 local GR_STR1="1w3d"
1038 local GR_STR2="1000s"
1040 local GR_STR4="1w2d3h4m5s"
1042 local GR_STR6="18446744073709551615"
1045 wait_delete_completed
1047 # test of valid grace strings handling
1048 echo "Valid grace strings test"
1049 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1050 $GR_STR2 $DIR || error "set user grace time failed"
1051 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1052 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1053 $GR_STR4 $DIR || error "set group grace time quota failed"
1054 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1056 # test of invalid grace strings handling
1057 echo " Invalid grace strings test"
1058 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1059 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1060 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1064 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1065 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1066 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1067 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1069 run_test 4b "Grace time strings handling"
1071 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1073 local BLIMIT=10 # 10M
1074 local ILIMIT=10 # 10 inodes
1076 setup_quota_test || error "setup quota failed with $?"
1077 trap cleanup_quota_test EXIT
1079 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1080 set_ost_qtype $QTYPE || error "enable ost quota failed"
1082 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1083 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1084 error "set user quota failed"
1085 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1086 if is_project_quota_supported; then
1087 error "set group quota failed"
1088 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1089 -I $ILIMIT $DIR || error "set project quota failed"
1092 # make sure the system is clean
1093 local USED=$(getquota -u $TSTUSR global curinodes)
1094 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1095 USED=$(getquota -g $TSTUSR global curinodes)
1096 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1097 USED=$(getquota -u $TSTUSR global curspace)
1098 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1099 USED=$(getquota -g $TSTUSR global curspace)
1100 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1101 if is_project_quota_supported; then
1102 USED=$(getquota -p $TSTPRJID global curinodes)
1104 error "Used inode($USED) for project $TSTPRJID isn't 0."
1105 USED=$(getquota -p $TSTPRJID global curspace)
1107 error "Used block($USED) for project $TSTPRJID isn't 0."
1110 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1111 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1112 error "create failure, expect success"
1113 if is_project_quota_supported; then
1114 touch $DIR/$tdir/$tfile-0_1
1115 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1117 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1118 error "write failure, expect success"
1120 echo "Chown files to $TSTUSR.$TSTUSR ..."
1121 for i in $(seq 0 $ILIMIT); do
1122 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1123 quota_error a $TSTUSR "chown failure, expect success"
1127 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1128 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1131 resetquota -u $TSTUSR
1132 resetquota -g $TSTUSR
1133 resetquota -p $TSTPRJID
1135 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1137 # test dropping acquire request on master
1141 # Clear dmesg so watchdog is not triggered by previous
1143 do_facet ost1 dmesg -c > /dev/null
1145 setup_quota_test || error "setup quota failed with $?"
1146 trap cleanup_quota_test EXIT
1148 # make sure the system is clean
1149 local USED=$(getquota -u $TSTUSR global curspace)
1150 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1152 # make sure no granted quota on ost
1153 set_ost_qtype $QTYPE || error "enable ost quota failed"
1154 resetquota -u $TSTUSR
1156 # create file for $TSTUSR
1157 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1158 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1159 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1161 # create file for $TSTUSR2
1162 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1163 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1164 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1166 # cache per-ID lock for $TSTUSR on slave
1167 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1168 error "set quota failed"
1169 $RUNAS $DD of=$TESTFILE count=1 ||
1170 error "write $TESTFILE failure, expect success"
1171 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1172 error "write $TESTFILE2 failure, expect success"
1174 sync_all_data || true
1176 #define QUOTA_DQACQ 601
1177 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1178 lustre_fail mds 0x513 601
1180 do_facet ost1 $LCTL set_param \
1181 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1183 # write to un-enforced ID ($TSTUSR2) should succeed
1184 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1185 error "write failure, expect success"
1187 # write to enforced ID ($TSTUSR) in background, exceeding limit
1188 # to make sure DQACQ is sent
1189 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1192 # watchdog timer uses a factor of 2
1193 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1194 sleep $((TIMEOUT * 2 + 1))
1196 # write should be blocked and never finished
1197 if ! ps -p $DDPID > /dev/null 2>&1; then
1199 error "write finished incorrectly!"
1204 # no watchdog is triggered
1205 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1206 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1207 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1208 [ -z "$watchdog" ] || error "$watchdog"
1210 rm -f $TMP/lustre-log-${TESTNAME}.log
1212 # write should continue then fail with EDQUOT
1216 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1217 if [ $count -ge 240 ]; then
1218 quota_error u $TSTUSR "dd not finished in $count secs"
1220 count=$((count + 1))
1221 if [ $((count % 30)) -eq 0 ]; then
1222 c_size=$(stat -c %s $TESTFILE)
1223 echo "Waiting $count secs. $c_size"
1230 resetquota -u $TSTUSR
1232 run_test 6 "Test dropping acquire request on master"
1234 # quota reintegration (global index)
1236 local TESTFILE=$DIR/$tdir/$tfile
1237 local LIMIT=20 # 20M
1239 [ "$SLOW" = "no" ] && LIMIT=5
1241 setup_quota_test || error "setup quota failed with $?"
1242 trap cleanup_quota_test EXIT
1244 # make sure the system is clean
1245 local USED=$(getquota -u $TSTUSR global curspace)
1246 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1248 # make sure no granted quota on ost1
1249 set_ost_qtype $QTYPE || error "enable ost quota failed"
1250 resetquota -u $TSTUSR
1251 set_ost_qtype "none" || error "disable ost quota failed"
1253 local OSTUUID=$(ostuuid_from_index 0)
1254 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1256 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1259 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1260 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1265 echo "Enable quota & set quota limit for $TSTUSR"
1266 set_ost_qtype $QTYPE || error "enable ost quota failed"
1267 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1268 error "set quota failed"
1270 echo "Start ost1..."
1271 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1274 wait_ost_reint $QTYPE || error "reintegration failed"
1276 # hardlimit should have been fetched by slave during global
1277 # reintegration, write will exceed quota
1278 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1279 quota_error u $TSTUSR "write success, but expect EDQUOT"
1282 wait_delete_completed
1283 sync_all_data || true
1289 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1290 error "clear quota failed"
1292 echo "Start ost1..."
1293 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1296 wait_ost_reint $QTYPE || error "reintegration failed"
1298 # hardlimit should be cleared on slave during reintegration
1299 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1300 quota_error u $TSTUSR "write error, but expect success"
1303 resetquota -u $TSTUSR
1305 run_test 7a "Quota reintegration (global index)"
1307 # quota reintegration (slave index)
1310 local TESTFILE=$DIR/$tdir/$tfile
1312 setup_quota_test || error "setup quota failed with $?"
1313 trap cleanup_quota_test EXIT
1315 # make sure the system is clean
1316 local USED=$(getquota -u $TSTUSR global curspace)
1317 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1319 # make sure no granted quota on ost1
1320 set_ost_qtype $QTYPE || error "enable ost quota failed"
1321 resetquota -u $TSTUSR
1322 set_ost_qtype "none" || error "disable ost quota failed"
1324 local OSTUUID=$(ostuuid_from_index 0)
1325 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1327 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1330 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1331 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1333 # consume some space to make sure the granted space will not
1334 # be released during reconciliation
1335 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1336 error "consume space failure, expect success"
1338 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1339 lustre_fail mds 0xa02
1341 set_ost_qtype $QTYPE || error "enable ost quota failed"
1342 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1343 error "set quota failed"
1345 # ignore the write error
1346 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1348 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1352 echo "Restart ost to trigger reintegration..."
1354 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1357 wait_ost_reint $QTYPE || error "reintegration failed"
1359 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1360 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1363 resetquota -u $TSTUSR
1366 run_test 7b "Quota reintegration (slave index)"
1368 # quota reintegration (restart mds during reintegration)
1370 local LIMIT=20 # 20M
1371 local TESTFILE=$DIR/$tdir/$tfile
1373 [ "$SLOW" = "no" ] && LIMIT=5
1375 setup_quota_test || error "setup quota failed with $?"
1376 trap cleanup_quota_test EXIT
1378 # make sure the system is clean
1379 local USED=$(getquota -u $TSTUSR global curspace)
1380 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1382 set_ost_qtype "none" || error "disable ost quota failed"
1383 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1384 error "set quota failed"
1386 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1387 lustre_fail ost 0xa03
1390 set_ost_qtype $QTYPE || error "enable ost quota failed"
1391 # trigger reintegration
1392 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1393 procf=${procf}quota_slave.force_reint
1394 do_facet ost1 $LCTL set_param $procf=1 ||
1395 error "force reintegration failed"
1403 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1406 # wait longer than usual to make sure the reintegration
1407 # is triggered by quota wb thread.
1408 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1410 # hardlimit should have been fetched by slave during global
1411 # reintegration, write will exceed quota
1412 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1413 quota_error u $TSTUSR "write success, but expect EDQUOT"
1416 resetquota -u $TSTUSR
1418 run_test 7c "Quota reintegration (restart mds during reintegration)"
1420 # Quota reintegration (Transfer index in multiple bulks)
1422 local TESTFILE=$DIR/$tdir/$tfile
1423 local TESTFILE1="$DIR/$tdir/$tfile"-1
1426 setup_quota_test || error "setup quota failed with $?"
1427 trap cleanup_quota_test EXIT
1429 set_ost_qtype "none" || error "disable ost quota failed"
1430 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1431 error "set quota for $TSTUSR failed"
1432 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1433 error "set quota for $TSTUSR2 failed"
1435 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1436 lustre_fail mds 0x608 0
1438 # enable quota to tirgger reintegration
1439 set_ost_qtype "u" || error "enable ost quota failed"
1440 wait_ost_reint "u" || error "reintegration failed"
1444 # hardlimit should have been fetched by slave during global
1445 # reintegration, write will exceed quota
1446 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1447 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1449 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1450 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1453 resetquota -u $TSTUSR
1454 resetquota -u $TSTUSR2
1456 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1458 # quota reintegration (inode limits)
1460 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1462 # LU-2435: skip this quota test if underlying zfs version has not
1463 # supported native dnode accounting
1464 [ "$(facet_fstype mds1)" == "zfs" ] && {
1465 local F="feature@userobj_accounting"
1466 local pool=$(zpool_name mds1)
1467 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1469 [[ "$feature" != *" active "* ]] &&
1470 skip "requires zpool with active userobj_accounting"
1473 local ilimit=$((1024 * 2)) # 2k inodes
1474 local TESTFILE=$DIR/${tdir}-1/$tfile
1476 setup_quota_test || error "setup quota failed with $?"
1477 trap cleanup_quota_test EXIT
1479 # make sure the system is clean
1480 local USED=$(getquota -u $TSTUSR global curinodes)
1481 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1483 # make sure no granted quota on mdt1
1484 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1485 resetquota -u $TSTUSR
1486 set_mdt_qtype "none" || error "disable mdt quota failed"
1488 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1489 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1490 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1493 echo "Stop mds${MDSCOUNT}..."
1496 echo "Enable quota & set quota limit for $TSTUSR"
1497 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1498 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1499 error "set quota failed"
1501 echo "Start mds${MDSCOUNT}..."
1502 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1505 wait_mdt_reint $QTYPE || error "reintegration failed"
1507 echo "create remote dir"
1508 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1509 error "create remote dir failed"
1510 chmod 0777 $DIR/${tdir}-1
1512 # hardlimit should have been fetched by slave during global
1513 # reintegration, create will exceed quota
1514 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1515 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1517 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1518 wait_delete_completed
1519 sync_all_data || true
1521 echo "Stop mds${MDSCOUNT}..."
1524 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1525 error "clear quota failed"
1527 echo "Start mds${MDSCOUNT}..."
1528 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1531 wait_mdt_reint $QTYPE || error "reintegration failed"
1533 # hardlimit should be cleared on slave during reintegration
1534 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1535 quota_error u $TSTUSR "create failed, expect success"
1537 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1538 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1541 resetquota -u $TSTUSR
1543 run_test 7e "Quota reintegration (inode limits)"
1545 # run dbench with quota enabled
1547 local BLK_LIMIT="100g" #100G
1548 local FILE_LIMIT=1000000
1550 setup_quota_test || error "setup quota failed with $?"
1551 trap cleanup_quota_test EXIT
1553 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1554 set_ost_qtype $QTYPE || error "enable ost quota failed"
1556 echo "Set enough high limit for user: $TSTUSR"
1557 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1558 error "set user quota failed"
1559 echo "Set enough high limit for group: $TSTUSR"
1560 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1561 error "set group quota failed"
1562 if is_project_quota_supported; then
1563 change_project -sp $TSTPRJID $DIR/$tdir
1564 echo "Set enough high limit for project: $TSTPRJID"
1565 $LFS setquota -p $TSTPRJID -b 0 \
1566 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1567 error "set project quota failed"
1571 [ "$SLOW" = "no" ] && duration=" -t 120"
1572 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1573 quota_error a $TSTUSR "dbench failed!"
1575 is_project_quota_supported && change_project -C $DIR/$tdir
1577 resetquota -u $TSTUSR
1578 resetquota -g $TSTUSR
1579 resetquota -p $TSTPRJID
1581 run_test 8 "Run dbench with quota enabled"
1583 # this check is just for test_9
1584 OST0_MIN=4900000 #4.67G
1586 check_whether_skip () {
1587 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1588 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1589 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1590 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1597 # run for fixing bug10707, it needs a big room. test for 64bit
1599 local filesize=$((1024 * 9 / 2)) # 4.5G
1601 check_whether_skip && return 0
1603 setup_quota_test || error "setup quota failed with $?"
1604 trap cleanup_quota_test EXIT
1606 set_ost_qtype "ug" || error "enable ost quota failed"
1608 local TESTFILE="$DIR/$tdir/$tfile-0"
1609 local BLK_LIMIT=100G #100G
1610 local FILE_LIMIT=1000000
1612 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1614 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1616 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1617 error "set user quota failed"
1619 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1620 "for group: $TSTUSR"
1621 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1622 error "set group quota failed"
1624 quota_show_check a u $TSTUSR
1625 quota_show_check a g $TSTUSR
1627 echo "Create test file"
1628 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1629 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1631 log "Write the big file of 4.5G ..."
1632 $RUNAS $DD of=$TESTFILE count=$filesize ||
1633 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1639 resetquota -u $TSTUSR
1640 resetquota -g $TSTUSR
1645 run_test 9 "Block limit larger than 4GB (b10707)"
1648 local TESTFILE=$DIR/$tdir/$tfile
1650 setup_quota_test || error "setup quota failed with $?"
1651 trap cleanup_quota_test EXIT
1653 # set limit to root user should fail
1654 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1655 error "set limit for root user successfully, expect failure"
1656 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1657 error "set limit for root group successfully, expect failure"
1658 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1659 error "set limit for project 0 successfully, expect failure"
1661 # root user can overrun quota
1662 set_ost_qtype "ug" || error "enable ost quota failed"
1664 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1665 error "set quota failed"
1666 quota_show_check b u $TSTUSR
1668 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1669 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1671 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1672 error "write failure, expect success"
1675 resetquota -u $TSTUSR
1677 run_test 10 "Test quota for root user"
1680 local TESTFILE=$DIR/$tdir/$tfile
1681 setup_quota_test || error "setup quota failed with $?"
1682 trap cleanup_quota_test EXIT
1684 set_mdt_qtype "ug" || error "enable mdt quota failed"
1685 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1686 error "set quota failed"
1688 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1689 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1691 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1692 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1695 local USED=$(getquota -u $TSTUSR global curinodes)
1696 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1699 resetquota -u $TSTUSR
1701 run_test 11 "Chown/chgrp ignores quota"
1704 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1706 local blimit=22 # 22M
1707 local blk_cnt=$((blimit - 5))
1708 local TESTFILE0="$DIR/$tdir/$tfile"-0
1709 local TESTFILE1="$DIR/$tdir/$tfile"-1
1711 setup_quota_test || error "setup quota failed with $?"
1712 trap cleanup_quota_test EXIT
1714 set_ost_qtype "u" || error "enable ost quota failed"
1715 quota_show_check b u $TSTUSR
1717 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1718 error "set quota failed"
1720 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1721 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1722 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1723 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1725 echo "Write to ost0..."
1726 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1727 quota_error a $TSTUSR "dd failed"
1729 echo "Write to ost1..."
1730 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1731 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1733 echo "Free space from ost0..."
1735 wait_delete_completed
1736 sync_all_data || true
1738 echo "Write to ost1 after space freed from ost0..."
1739 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1740 quota_error a $TSTUSR "rebalancing failed"
1743 resetquota -u $TSTUSR
1745 run_test 12a "Block quota rebalancing"
1748 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1750 local ilimit=$((1024 * 2)) # 2k inodes
1751 local TESTFILE0=$DIR/$tdir/$tfile
1752 local TESTFILE1=$DIR/${tdir}-1/$tfile
1754 setup_quota_test || error "setup quota failed with $?"
1755 trap cleanup_quota_test EXIT
1757 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1758 chmod 0777 $DIR/${tdir}-1
1760 set_mdt_qtype "u" || error "enable mdt quota failed"
1761 quota_show_check f u $TSTUSR
1763 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1764 error "set quota failed"
1766 echo "Create $ilimit files on mdt0..."
1767 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1768 quota_error u $TSTUSR "create failed, but expect success"
1770 echo "Create files on mdt1..."
1771 $RUNAS createmany -m $TESTFILE1 1 &&
1772 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1774 echo "Free space from mdt0..."
1775 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1776 wait_delete_completed
1777 sync_all_data || true
1779 echo "Create files on mdt1 after space freed from mdt0..."
1780 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1781 quota_error a $TSTUSR "rebalancing failed"
1783 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1784 error "unlink mdt1 files failed"
1785 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1788 resetquota -u $TSTUSR
1790 run_test 12b "Inode quota rebalancing"
1793 local TESTFILE=$DIR/$tdir/$tfile
1794 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1795 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1797 setup_quota_test || error "setup quota failed with $?"
1798 trap cleanup_quota_test EXIT
1800 set_ost_qtype "u" || error "enable ost quota failed"
1801 quota_show_check b u $TSTUSR
1803 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1804 error "set quota failed"
1805 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1806 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1808 # clear the locks in cache first
1809 do_facet ost1 $LCTL set_param -n $procf=clear
1810 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1811 [ $nlock -eq 0 ] || error "$nlock cached locks"
1813 # write to acquire the per-ID lock
1814 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1815 quota_error a $TSTUSR "dd failed"
1817 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1818 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1820 # clear quota doesn't trigger per-ID lock cancellation
1821 resetquota -u $TSTUSR
1822 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1823 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1825 # clear the per-ID lock
1826 do_facet ost1 $LCTL set_param -n $procf=clear
1827 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1828 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1830 # spare quota should be released
1831 local OSTUUID=$(ostuuid_from_index 0)
1832 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1833 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1834 [ $limit -le $space ] ||
1835 error "spare quota isn't released, limit:$limit, space:$space"
1839 run_test 13 "Cancel per-ID lock in the LRU list"
1842 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1844 wait_delete_completed
1845 sync_all_data || true
1848 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1849 error "set user quota failed"
1850 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1851 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1852 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1853 resetquota -u $TSTUSR
1856 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1857 error "set group quota failed"
1858 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1859 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1860 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1861 resetquota -g $TSTUSR
1863 run_test 15 "Set over 4T block quota"
1867 local BLKS=1 # 1M less than limit
1868 local TESTFILE=$DIR/$tdir/$tfile
1870 setup_quota_test || error "setup quota failed with $?"
1871 trap cleanup_quota_test EXIT
1873 # make sure the system is clean
1874 local USED=$(getquota -u $TSTUSR global curspace)
1875 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1877 set_ost_qtype "ug" || error "enable ost quota failed"
1878 # make sure no granted quota on ost
1879 resetquota -u $TSTUSR
1880 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1881 error "set quota failed"
1883 quota_show_check b u $TSTUSR
1885 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1886 lustre_fail mds 0xa04 $err_code
1888 # write in background
1889 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1893 # write should be blocked and never finished
1894 if ! ps -p $DDPID > /dev/null 2>&1; then
1896 quota_error u $TSTUSR "write finished incorrectly!"
1904 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1906 if [ $count -gt $timeout ]; then
1907 quota_error u $TSTUSR "dd is not finished!"
1912 sync; sync_all_data || true
1914 USED=$(getquota -u $TSTUSR global curspace)
1915 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1916 "Used space(${USED}K) is less than ${BLKS}M"
1919 resetquota -u $TSTUSR
1922 # DQACQ return recoverable error
1924 echo "DQACQ return -ENOLCK"
1926 test_17sub 37 || error "Handle -ENOLCK failed"
1928 echo "DQACQ return -EAGAIN"
1930 test_17sub 11 || error "Handle -EAGAIN failed"
1932 echo "DQACQ return -ETIMEDOUT"
1933 #define ETIMEDOUT 110
1934 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1936 echo "DQACQ return -ENOTCONN"
1937 #define ENOTCONN 107
1938 test_17sub 107 || error "Handle -ENOTCONN failed"
1941 run_test 17 "DQACQ return recoverable error"
1945 local blimit="200m" # 200M
1946 local TESTFILE="$DIR/$tdir/$tfile"
1948 setup_quota_test || error "setup quota failed with $?"
1949 trap cleanup_quota_test EXIT
1951 set_ost_qtype "u" || error "enable ost quota failed"
1952 log "User quota (limit: $blimit)"
1953 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1954 error "set quota failed"
1955 quota_show_check b u $TSTUSR
1957 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1958 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1960 local timeout=$(sysctl -n lustre.timeout)
1962 if [ $io_type = "directio" ]; then
1963 log "Write 100M (directio) ..."
1964 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1966 log "Write 100M (buffered) ..."
1967 $RUNAS $DD of=$TESTFILE count=100 &
1971 replay_barrier $SINGLEMDS
1972 log "Fail mds for $((2 * timeout)) seconds"
1973 fail $SINGLEMDS $((2 * timeout))
1976 if at_is_enabled; then
1977 timeout=$(at_max_get mds)
1979 timeout=$(lctl get_param -n timeout)
1983 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1984 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1985 log "it took $count second"
1990 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1992 cancel_lru_locks mdc
1993 cancel_lru_locks osc
1996 local testfile_size=$(stat -c %s $TESTFILE)
1997 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1998 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1999 "got ${testfile_size}. Verifying file failed!"
2002 resetquota -u $TSTUSR
2005 # test when mds does failover, the ost still could work well
2006 # this test shouldn't trigger watchdog b=14840
2008 # Clear dmesg so watchdog is not triggered by previous
2010 do_facet ost1 dmesg -c > /dev/null
2013 test_18_sub directio
2015 # check if watchdog is triggered
2016 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2017 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2018 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2019 [ -z "$watchdog" ] || error "$watchdog"
2020 rm -f $TMP/lustre-log-${TESTNAME}.log
2022 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2026 local TESTFILE=$DIR/$tdir/$tfile
2028 setup_quota_test || error "setup quota failed with $?"
2029 trap cleanup_quota_test EXIT
2031 set_ost_qtype $QTYPE || error "enable ost quota failed"
2033 # bind file to a single OST
2034 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2035 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2037 echo "Set user quota (limit: ${blimit}M)"
2038 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2039 error "set user quota failed"
2040 quota_show_check b u $TSTUSR
2041 echo "Update quota limits"
2042 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2043 error "set group quota failed"
2044 quota_show_check b u $TSTUSR
2046 # first wirte might be cached
2047 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2048 cancel_lru_locks osc
2050 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2051 quota_error u $TSTUSR "Write success, expect failure"
2055 resetquota -u $TSTUSR
2057 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2059 test_20() { # b15754
2060 local LSTR=(2g 1t 4k 3m) # limits strings
2062 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2065 resetquota -u $TSTUSR
2067 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2068 $MOUNT || error "could not set quota limits"
2069 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2070 --inode-softlimit ${LSTR[2]} \
2071 --inode-hardlimit ${LSTR[3]} \
2072 $MOUNT || error "could not set quota limits"
2074 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2075 error "bsoftlimit was not set properly"
2076 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2077 error "bhardlimit was not set properly"
2078 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2079 error "isoftlimit was not set properly"
2080 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2081 error "ihardlimit was not set properly"
2083 resetquota -u $TSTUSR
2085 run_test 20 "Test if setquota specifiers work properly (b15754)"
2092 local time=$(($(date +%s) + seconds))
2093 while [ $(date +%s) -lt $time ]; do
2094 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2098 # run for fixing bug16053, setquota shouldn't fail when writing and
2099 # deleting are happening
2101 local TESTFILE="$DIR/$tdir/$tfile"
2102 local BLIMIT=10 # 10G
2103 local ILIMIT=1000000
2105 setup_quota_test || error "setup quota failed with $?"
2106 trap cleanup_quota_test EXIT
2108 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2110 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2111 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2112 error "set user quota failed"
2113 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2114 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2115 error "set group quota failed"
2116 if is_project_quota_supported; then
2117 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2118 "project: $TSTPRJID"
2119 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2120 $MOUNT || error "set project quota failed"
2123 # repeat writing on a 1M file
2124 test_21_sub ${TESTFILE}_1 1 30 &
2126 # repeat writing on a 128M file
2127 test_21_sub ${TESTFILE}_2 128 30 &
2130 local time=$(($(date +%s) + 30))
2132 while [ $(date +%s) -lt $time ]; do
2133 log "Set quota for $i times"
2134 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2135 -I $((ILIMIT + i)) $MOUNT ||
2136 error "Set user quota failed"
2137 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2138 -I $((ILIMIT + i)) $MOUNT ||
2139 error "Set group quota failed"
2140 if is_project_quota_supported; then
2141 $LFS setquota -p $TSTPRJID -b 0 -B \
2142 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2143 error "Set project quota failed"
2151 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2153 if [ $count -gt 60 ]; then
2154 quota_error a $TSTUSR "dd should be finished!"
2158 echo "(dd_pid=$DDPID1, time=$count)successful"
2162 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2164 if [ $count -gt 60 ]; then
2165 quota_error a $TSTUSR "dd should be finished!"
2169 echo "(dd_pid=$DDPID2, time=$count)successful"
2172 resetquota -u $TSTUSR
2173 resetquota -g $TSTUSR
2174 resetquota -p $TSTPRJID
2176 run_test 21 "Setquota while writing & deleting (b16053)"
2178 # enable/disable quota enforcement permanently
2180 echo "Set both mdt & ost quota type as ug"
2182 is_project_quota_supported && qtype=$QTYPE
2183 set_mdt_qtype $qtype || error "enable mdt quota failed"
2184 set_ost_qtype $qtype || error "enable ost quota failed"
2187 stopall || error "failed to stopall (1)"
2191 echo "Verify if quota is enabled"
2192 local qtype1=$(mdt_quota_type)
2193 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2194 qtype=$(ost_quota_type)
2195 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2197 echo "Set both mdt & ost quota type as none"
2198 set_mdt_qtype "none" || error "disable mdt quota failed"
2199 set_ost_qtype "none" || error "disable ost quota failed"
2202 stopall || error "failed to stopall (2)"
2207 echo "Verify if quota is disabled"
2208 qtype=$(mdt_quota_type)
2209 [ $qtype != "none" ] && error "mdt quota setting is lost"
2210 qtype=$(ost_quota_type)
2211 [ $qtype != "none" ] && error "ost quota setting is lost"
2215 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2218 local TESTFILE="$DIR/$tdir/$tfile"
2221 setup_quota_test || error "setup quota failed with $?"
2222 trap cleanup_quota_test EXIT
2224 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2227 log "User quota (limit: $LIMIT MB)"
2228 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2229 error "set quota failed"
2230 quota_show_check b u $TSTUSR
2232 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2233 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2235 log "Step1: trigger EDQUOT with O_DIRECT"
2236 log "Write half of file"
2237 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2238 quota_error u $TSTUSR "(1) Write failure, expect success." \
2240 log "Write out of block quota ..."
2241 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2242 oflag=direct conv=notrunc &&
2243 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2247 log "Step2: rewrite should succeed"
2248 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2249 quota_error u $TSTUSR "(3) Write failure, expect success." \
2255 local OST0_UUID=$(ostuuid_from_index 0)
2256 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2257 [ $OST0_QUOTA_USED -ne 0 ] &&
2258 ($SHOW_QUOTA_USER; \
2259 quota_error u $TSTUSR "quota isn't released")
2261 resetquota -u $TSTUSR
2265 [ $(facet_fstype ost1) == "zfs" ] &&
2266 skip "Overwrite in place is not guaranteed to be " \
2267 "space neutral on ZFS"
2269 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2270 check_whether_skip && return 0
2271 log "run for 4MB test file"
2274 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2275 check_whether_skip && return 0
2276 log "run for 40MB test file"
2279 run_test 23 "Quota should be honored with directIO (b16125)"
2283 local TESTFILE="$DIR/$tdir/$tfile"
2285 setup_quota_test || error "setup quota failed with $?"
2286 trap cleanup_quota_test EXIT
2288 set_ost_qtype $QTYPE || error "enable ost quota failed"
2290 # bind file to a single OST
2291 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2292 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2294 echo "Set user quota (limit: ${blimit}M)"
2295 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2296 error "set quota failed"
2298 # overrun quota by root user
2299 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2300 error "write failure, expect success"
2301 cancel_lru_locks osc
2302 sync_all_data || true
2304 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2307 resetquota -u $TSTUSR
2309 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2311 test_27a() { # b19612
2312 $LFS quota $TSTUSR $DIR &&
2313 error "lfs succeeded with no type, but should have failed"
2314 $LFS setquota $TSTUSR $DIR &&
2315 error "lfs succeeded with no type, but should have failed"
2318 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2320 test_27b() { # b20200
2321 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2322 error "lfs setquota failed with uid argument"
2323 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2324 error "lfs stequota failed with gid argument"
2325 if is_project_quota_supported; then
2326 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2327 1000 $DIR || error \
2328 "lfs stequota failed with projid argument"
2330 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2331 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2332 if is_project_quota_supported; then
2333 $SHOW_QUOTA_PROJID ||
2334 error "lfs quota failed with projid argument"
2336 resetquota -u $TSTUSR
2337 resetquota -g $TSTUSR
2338 resetquota -p $TSTPRJID
2341 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2346 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2347 error "lfs setquota failed"
2349 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2350 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2351 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2352 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2354 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2355 error "lfs setquota for $TSTID failed"
2357 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2358 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2359 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2360 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2362 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2363 error "total allocated inode/block limit not printed"
2365 resetquota -u $TSTUSR
2367 run_test 27c "lfs quota should support human-readable output"
2374 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2375 error "set fraction block limit failed"
2376 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2377 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2378 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2379 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2381 resetquota -u $TSTUSR
2383 run_test 27d "lfs setquota should support fraction block limit"
2387 local TESTFILE="$DIR/$tdir/$tfile"
2390 setup_quota_test || error "setup quota failed with $?"
2391 trap cleanup_quota_test EXIT
2393 set_ost_qtype "u" || error "enable ost quota failed"
2395 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2396 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2398 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2399 $MAX_IQ_TIME $DIR || error "set grace time failed"
2400 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2401 error "set quota failed"
2402 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2403 cancel_lru_locks osc
2405 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2406 # over-quota flag has not yet settled since we do not trigger async
2407 # events based on grace time period expiration
2409 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2410 cancel_lru_locks osc
2411 # now over-quota flag should be settled and further writes should fail
2413 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2414 error "grace times were reset"
2417 resetquota -u $TSTUSR
2418 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2419 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2421 run_test 30 "Hard limit updates should not reset grace times"
2423 # basic usage tracking for user & group
2425 local INODES=10 # 10 files
2426 local BLK_CNT=2 # of 2M each
2427 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2429 setup_quota_test || error "setup quota failed with $?"
2430 trap cleanup_quota_test EXIT
2432 # make sure the system is clean
2433 local USED=$(getquota -u $TSTID global curspace)
2435 error "Used space ($USED) for user $TSTID isn't 0."
2436 USED=$(getquota -g $TSTID global curspace)
2438 error "Used space ($USED) for group $TSTID isn't 0."
2439 if is_project_quota_supported; then
2440 USED=$(getquota -p $TSTPRJID global curspace)
2441 [ $USED -ne 0 ] && error \
2442 "Used space ($USED) for project $TSTPRJID isn't 0."
2445 echo "Write files..."
2446 for i in $(seq 0 $INODES); do
2447 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2448 error "write failed"
2449 is_project_quota_supported &&
2450 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2451 echo "Iteration $i/$INODES completed"
2453 cancel_lru_locks osc
2455 echo "Wait for setattr on objects finished..."
2456 wait_delete_completed
2458 sync; sync_all_data || true
2460 echo "Verify disk usage after write"
2461 USED=$(getquota -u $TSTID global curspace)
2462 [ $USED -lt $TOTAL_BLKS ] &&
2463 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2464 USED=$(getquota -g $TSTID global curspace)
2465 [ $USED -lt $TOTAL_BLKS ] &&
2466 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2467 if is_project_quota_supported; then
2468 USED=$(getquota -p $TSTPRJID global curspace)
2469 [ $USED -lt $TOTAL_BLKS ] && error \
2470 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2473 echo "Verify inode usage after write"
2474 USED=$(getquota -u $TSTID global curinodes)
2475 [ $USED -lt $INODES ] &&
2476 error "Used inode for user $TSTID is $USED, expected $INODES"
2477 USED=$(getquota -g $TSTID global curinodes)
2478 [ $USED -lt $INODES ] &&
2479 error "Used inode for group $TSTID is $USED, expected $INODES"
2480 if is_project_quota_supported; then
2481 USED=$(getquota -p $TSTPRJID global curinodes)
2482 [ $USED -lt $INODES ] && error \
2483 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2488 echo "Verify disk usage after delete"
2489 USED=$(getquota -u $TSTID global curspace)
2490 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2491 USED=$(getquota -u $TSTID global curinodes)
2492 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2493 USED=$(getquota -g $TSTID global curspace)
2494 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2495 USED=$(getquota -g $TSTID global curinodes)
2496 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2497 if is_project_quota_supported; then
2498 USED=$(getquota -p $TSTPRJID global curspace)
2500 error "Used space for project $TSTPRJID isn't 0. $USED"
2501 USED=$(getquota -p $TSTPRJID global curinodes)
2503 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2506 run_test 33 "Basic usage tracking for user & group & project"
2508 # usage transfer test for user & group & project
2510 local BLK_CNT=2 # 2MB
2511 local project_supported="no"
2513 is_project_quota_supported && project_supported="yes"
2514 setup_quota_test || error "setup quota failed with $?"
2515 trap cleanup_quota_test EXIT
2517 # make sure the system is clean
2518 local USED=$(getquota -u $TSTID global curspace)
2519 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2520 USED=$(getquota -g $TSTID global curspace)
2521 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2523 local USED=$(getquota -u $TSTID2 global curspace)
2524 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2525 if [ $project_supported == "yes" ]; then
2526 USED=$(getquota -p $TSTPRJID global curspace)
2527 [ $USED -ne 0 ] && error \
2528 "Used space ($USED) for Project $TSTPRJID isn't 0."
2531 echo "Write file..."
2532 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2533 error "write failed"
2534 cancel_lru_locks osc
2535 sync; sync_all_data || true
2537 echo "chown the file to user $TSTID"
2538 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2540 echo "Wait for setattr on objects finished..."
2541 wait_delete_completed
2543 BLK_CNT=$((BLK_CNT * 1024))
2545 echo "Verify disk usage for user $TSTID"
2546 USED=$(getquota -u $TSTID global curspace)
2547 [ $USED -lt $BLK_CNT ] &&
2548 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2549 USED=$(getquota -u $TSTID global curinodes)
2551 error "Used inodes for user $TSTID is $USED, expected 1"
2553 echo "chgrp the file to group $TSTID"
2554 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2556 echo "Wait for setattr on objects finished..."
2557 wait_delete_completed
2559 echo "Verify disk usage for group $TSTID"
2560 USED=$(getquota -g $TSTID global curspace)
2561 [ $USED -ge $BLK_CNT ] ||
2562 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2563 USED=$(getquota -g $TSTID global curinodes)
2565 error "Used inodes for group $TSTID is $USED, expected 1"
2567 # chown won't change the ost object group. LU-4345 */
2568 echo "chown the file to user $TSTID2"
2569 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2571 echo "Wait for setattr on objects finished..."
2572 wait_delete_completed
2574 echo "change_project project id to $TSTPRJID"
2575 [ $project_supported == "yes" ] &&
2576 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2577 echo "Wait for setattr on objects finished..."
2578 wait_delete_completed
2580 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2581 USED=$(getquota -u $TSTID2 global curspace)
2582 [ $USED -lt $BLK_CNT ] &&
2583 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2584 USED=$(getquota -u $TSTID global curspace)
2586 error "Used space for user $TSTID is $USED, expected 0"
2587 USED=$(getquota -g $TSTID global curspace)
2588 [ $USED -lt $BLK_CNT ] &&
2589 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2590 if [ $project_supported == "yes" ]; then
2591 USED=$(getquota -p $TSTPRJID global curspace)
2592 [ $USED -lt $BLK_CNT ] && error \
2593 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2598 run_test 34 "Usage transfer for user & group & project"
2600 # usage is still accessible across restart
2602 local BLK_CNT=2 # 2 MB
2604 setup_quota_test || error "setup quota failed with $?"
2605 trap cleanup_quota_test EXIT
2607 echo "Write file..."
2608 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2609 error "write failed"
2610 is_project_quota_supported &&
2611 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2612 cancel_lru_locks osc
2614 echo "Wait for setattr on objects finished..."
2615 wait_delete_completed
2617 sync; sync_all_data || true
2619 echo "Save disk usage before restart"
2620 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2621 [ $ORIG_USR_SPACE -eq 0 ] &&
2622 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2623 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2624 [ $ORIG_USR_INODES -eq 0 ] &&
2625 error "Used inodes for user $TSTID is 0, expected 1"
2626 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2627 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2628 [ $ORIG_GRP_SPACE -eq 0 ] &&
2629 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2630 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2631 [ $ORIG_GRP_INODES -eq 0 ] &&
2632 error "Used inodes for group $TSTID is 0, expected 1"
2633 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2635 if is_project_quota_supported; then
2636 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2637 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2638 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2639 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2640 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2641 "Used inodes for project $TSTPRJID is 0, expected 1"
2642 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2650 echo "Verify disk usage after restart"
2651 local USED=$(getquota -u $TSTID global curspace)
2652 [ $USED -eq $ORIG_USR_SPACE ] ||
2653 error "Used space for user $TSTID changed from " \
2654 "$ORIG_USR_SPACE to $USED"
2655 USED=$(getquota -u $TSTID global curinodes)
2656 [ $USED -eq $ORIG_USR_INODES ] ||
2657 error "Used inodes for user $TSTID changed from " \
2658 "$ORIG_USR_INODES to $USED"
2659 USED=$(getquota -g $TSTID global curspace)
2660 [ $USED -eq $ORIG_GRP_SPACE ] ||
2661 error "Used space for group $TSTID changed from " \
2662 "$ORIG_GRP_SPACE to $USED"
2663 USED=$(getquota -g $TSTID global curinodes)
2664 [ $USED -eq $ORIG_GRP_INODES ] ||
2665 error "Used inodes for group $TSTID changed from " \
2666 "$ORIG_GRP_INODES to $USED"
2667 if [ $project_supported == "yes" ]; then
2668 USED=$(getquota -p $TSTPRJID global curinodes)
2669 [ $USED -eq $ORIG_PRJ_INODES ] ||
2670 error "Used inodes for project $TSTPRJID " \
2671 "changed from $ORIG_PRJ_INODES to $USED"
2672 USED=$(getquota -p $TSTPRJID global curspace)
2673 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2674 error "Used space for project $TSTPRJID "\
2675 "changed from $ORIG_PRJ_SPACE to $USED"
2678 # check if the vfs_dq_init() is called before writing
2679 echo "Append to the same file..."
2680 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2681 error "write failed"
2682 cancel_lru_locks osc
2683 sync; sync_all_data || true
2685 echo "Verify space usage is increased"
2686 USED=$(getquota -u $TSTID global curspace)
2687 [ $USED -gt $ORIG_USR_SPACE ] ||
2688 error "Used space for user $TSTID isn't increased" \
2689 "orig:$ORIG_USR_SPACE, now:$USED"
2690 USED=$(getquota -g $TSTID global curspace)
2691 [ $USED -gt $ORIG_GRP_SPACE ] ||
2692 error "Used space for group $TSTID isn't increased" \
2693 "orig:$ORIG_GRP_SPACE, now:$USED"
2694 if [ $project_supported == "yes" ]; then
2695 USED=$(getquota -p $TSTPRJID global curspace)
2696 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2697 error "Used space for project $TSTPRJID isn't " \
2698 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2703 run_test 35 "Usage is still accessible across reboot"
2705 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2708 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2709 skip "Old server doesn't have LU-5006 fix."
2711 setup_quota_test || error "setup quota failed with $?"
2712 trap cleanup_quota_test EXIT
2714 # make sure the system is clean
2715 local USED=$(getquota -u $TSTID global curspace)
2717 error "Used space ($USED) for user $TSTID isn't 0."
2719 # create file with MDS_OPEN_DELAY_CREATE flag
2720 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2721 error "Create file failed"
2723 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2724 oflag=sync || error "Write file failed"
2726 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2728 # wait for setattr on objects finished..."
2729 wait_delete_completed
2731 USED=$(getquota -u $TSTID global curspace)
2732 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2736 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2740 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2741 skip "Old server doesn't have LU-8801 fix."
2743 [ "$UID" != 0 ] && skip_env "must run as root" && return
2745 setup_quota_test || error "setup quota failed with $?"
2746 trap cleanup_quota_test EXIT
2748 # make sure the system is clean
2749 local USED=$(getquota -u $TSTID global curspace)
2751 error "Used space ($USED) for user $TSTID isn't 0."
2752 USED=$(getquota -u $TSTID2 global curspace)
2754 error "Used space ($USED) for user $TSTID2 isn't 0."
2756 local TESTFILE="$DIR/$tdir/$tfile"
2757 local file_cnt=10000
2759 # Generate id entries in accounting file
2760 echo "Create $file_cnt files..."
2761 for i in `seq $file_cnt`; do
2763 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2764 error "failed to chown $TESTFILE-$i"
2766 cancel_lru_locks osc
2767 sync; sync_all_data || true
2769 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2770 procf=${procf}.quota_slave.acct_user
2773 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2774 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2775 echo "Found $acct_cnt id entries"
2777 [ $file_cnt -eq $acct_cnt ] || {
2778 do_facet mds1 $LCTL get_param $procf
2779 error "skipped id entries"
2784 run_test 38 "Quota accounting iterator doesn't skip id entries"
2787 local TESTFILE="$DIR/$tdir/project"
2788 ! is_project_quota_supported &&
2789 skip "Project quota is not supported"
2791 setup_quota_test || error "setup quota failed with $?"
2794 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2795 [ $projectid -ne 0 ] &&
2796 error "Project id should be 0 not $projectid"
2797 change_project -p 1024 $TESTFILE
2798 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2799 [ $projectid -ne 1024 ] &&
2800 error "Project id should be 1024 not $projectid"
2802 stopall || error "failed to stopall (1)"
2805 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2806 [ $projectid -ne 1024 ] &&
2807 error "Project id should be 1024 not $projectid"
2811 run_test 39 "Project ID interface works correctly"
2814 ! is_project_quota_supported &&
2815 skip "Project quota is not supported"
2816 local dir1="$DIR/$tdir/dir1"
2817 local dir2="$DIR/$tdir/dir2"
2819 setup_quota_test || error "setup quota failed with $?"
2821 mkdir -p $dir1 $dir2
2822 change_project -sp 1 $dir1 && touch $dir1/1
2823 change_project -sp 2 $dir2
2825 ln $dir1/1 $dir2/1_link &&
2826 error "Hard link across different project quota should fail"
2831 run_test 40a "Hard link across different project ID"
2834 ! is_project_quota_supported &&
2835 skip "Project quota is not supported"
2836 local dir1="$DIR/$tdir/dir1"
2837 local dir2="$DIR/$tdir/dir2"
2839 setup_quota_test || error "setup quota failed with $?"
2840 mkdir -p $dir1 $dir2
2841 change_project -sp 1 $dir1 && touch $dir1/1
2842 change_project -sp 2 $dir2
2844 mv $dir1/1 $dir2/2 || error "mv failed $?"
2845 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2846 if [ "$projid" != "2" ]; then
2847 error "project id expected 2 not $projid"
2852 run_test 40b "Mv across different project ID"
2855 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2856 ! is_project_quota_supported &&
2857 skip "Project quota is not supported"
2859 setup_quota_test || error "setup quota failed with $?"
2860 local dir="$DIR/$tdir/dir"
2862 mkdir -p $dir && change_project -sp 1 $dir
2863 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2864 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2865 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2866 touch $dir/remote_dir/file
2867 #verify inherit works file for remote dir.
2868 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2869 [ "$projid" != "1" ] &&
2870 error "file under remote dir expected 1 not $projid"
2872 #Agent inode should be ignored for project quota
2873 USED=$(getquota -p 1 global curinodes)
2874 [ "$USED" != "3" ] &&
2875 error "file count expected 3 got $USED"
2881 run_test 40c "Remote child Dir inherit project quota properly"
2884 ! is_project_quota_supported &&
2885 skip "Project quota is not supported"
2887 setup_quota_test || error "setup quota failed with $?"
2888 local dir1="$DIR/$tdir/dir1"
2889 local dir2="$DIR/$tdir/dir2"
2891 mkdir -p $dir1 && change_project -sp 1 $dir1
2892 mkdir -p $dir2 && change_project -sp 2 $dir2
2893 for num in $(seq 1 10); do
2894 touch $dir1/file_$num $dir2/file_$num
2895 ln -s $dir1/file_$num $dir1/file_$num"_link"
2896 ln -s $dir2/file_$num $dir2/file_$num"_link"
2899 count=$($LFS find --projid 1 $DIR | wc -l)
2900 [ "$count" != 21 ] && error "expected 21 but got $count"
2902 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2903 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2904 [ "$count" != 22 ] && error "expected 22 but got $count"
2909 run_test 50 "Test if lfs find --projid works"
2912 ! is_project_quota_supported &&
2913 skip "Project quota is not supported"
2914 setup_quota_test || error "setup quota failed with $?"
2915 local dir="$DIR/$tdir/dir"
2917 mkdir $dir && change_project -sp 1 $dir
2918 local used=$(getquota -p 1 global curinodes)
2919 [ $used != "1" ] && error "expected 1 got $used"
2924 used=$(getquota -p 1 global curinodes)
2925 [ $used != "4" ] && error "expected 4 got $used"
2927 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2929 cp $DIR/$tdir/6 $dir/6
2930 used=$(getquota -p 1 global curinodes)
2931 [ $used != "5" ] && error "expected 5 got $used"
2934 mv $DIR/$tdir/6 $dir/7
2935 used=$(getquota -p 1 global curinodes)
2936 [ $used != "6" ] && error "expected 6 got $used"
2941 run_test 51 "Test project accounting with mv/cp"
2944 ! is_project_quota_supported &&
2945 skip "Project quota is not supported"
2946 setup_quota_test || error "setup quota failed with $?"
2947 local dir="$DIR/$tdir/dir"
2948 mkdir $dir && change_project -sp 1 $dir
2950 touch $DIR/$tdir/file
2951 #Try renaming a file into the project. This should fail.
2952 for num in $(seq 1 2000); do
2953 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2954 error "rename should fail"
2959 run_test 52 "Rename across different project ID"
2962 ! is_project_quota_supported &&
2963 skip "Project quota is not supported"
2964 setup_quota_test || error "setup quota failed with $?"
2965 local dir="$DIR/$tdir/dir"
2966 mkdir $dir && change_project -s $dir
2967 lfs project -d $dir | grep P || error "inherit attribute should be set"
2969 change_project -C $dir
2970 lfs project -d $dir | grep P &&
2971 error "inherit attribute should be cleared"
2976 run_test 53 "Project inherit attribute could be cleared"
2979 ! is_project_quota_supported &&
2980 skip "Project quota is not supported"
2981 setup_quota_test || error "setup quota failed with $?"
2982 trap cleanup_quota_test EXIT
2983 local testfile="$DIR/$tdir/$tfile-0"
2985 #set project ID/inherit attribute
2986 change_project -sp $TSTPRJID $DIR/$tdir
2987 $RUNAS createmany -m ${testfile} 100 ||
2988 error "create many files failed"
2990 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2991 # one more count for directory itself */
2995 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2996 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2998 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2999 [ $proj_count1 -eq $proj_count ] ||
3000 error "c2: expected $proj_count got $proj_count1"
3002 #clear project but with kept projid
3003 change_project -rCk $DIR/$tdir
3004 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3005 [ $proj_count1 -eq $proj_count ] ||
3006 error "c3: expected $proj_count got $proj_count1"
3008 #verify projid untouched.
3009 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3011 [ $proj_count1 -eq $proj_count ] ||
3012 error "c4: expected $proj_count got $proj_count1"
3015 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3016 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3017 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3019 #this time clear all
3020 change_project -rC $DIR/$tdir
3021 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3022 [ $proj_count1 -eq 0 ] ||
3023 error "c6: expected 0 got $proj_count1"
3025 unlinkmany ${testfile} 100 ||
3026 error "unlink many files failed"
3030 run_test 54 "basic lfs project interface test"
3033 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3034 skip "Not supported before 2.10.58."
3035 setup_quota_test || error "setup quota failed with $?"
3037 set_ost_qtype $QTYPE || error "enable ost quota failed"
3040 #add second group to TSTUSR
3041 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3044 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3045 error "failed to dd"
3047 cancel_lru_locks osc
3048 sync; sync_all_data || true
3050 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3051 error "failed to setquota on group $TSTUSR2"
3053 $LFS quota -v -g $TSTUSR2 $DIR
3055 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3056 error "chgrp should failed with -EDQUOT"
3058 USED=$(getquota -g $TSTUSR2 global curspace)
3061 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3062 error "failed to setquota on group $TSTUSR2"
3064 $LFS quota -v -g $TSTUSR2 $DIR
3066 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3067 error "chgrp should succeed"
3069 $LFS quota -v -g $TSTUSR2 $DIR
3071 resetquota -g $TSTUSR2
3074 run_test 55 "Chgrp should be affected by group quota"
3077 setup_quota_test || error "setup quota failed with $?"
3079 set_ost_qtype $QTYPE || error "enable ost quota failed"
3082 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3083 erro "failed to set grace time for usr quota"
3084 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3085 awk '{print $4 $8}')
3086 if [ "x$grace_time" != "x10s;10s" ]; then
3087 $LFS quota -t -u $DIR
3088 error "expected grace time: 10s;10s, got:$grace_time"
3093 run_test 56 "lfs quota -t should work well"
3096 setup_quota_test || error "setup quota failed with $?"
3098 local dir="$DIR/$tdir/dir"
3101 #try to change pipe file should not hang and return failure
3102 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3103 awk -F ':' '{ print \\\$2 }'" \
3104 " failed to get xattr for '$dir/pipe'" || return 1
3105 #command can process further if it hit some errors
3106 touch $dir/aaa $dir/bbb
3107 mkdir $dir/subdir -p
3108 touch $dir/subdir/aaa $dir/subdir/bbb
3109 #create one invalid link file
3110 ln -s $dir/not_exist_file $dir/ccc
3111 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3112 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3116 run_test 57 "lfs project could tolerate errors"
3119 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3120 skip "ldiskfs only test"
3121 disable_project_quota
3122 setup_quota_test || error "setup quota failed with $?"
3125 local testfile="$DIR/$tdir/$tfile-0"
3126 #make sure it did not crash kernel
3127 touch $testfile && lfs project -sp 1 $testfile
3129 enable_project_quota
3132 run_test 59 "lfs project dosen't crash kernel with project disabled"
3135 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3136 skip "Needs MDS version 2.11.53 or later."
3137 setup_quota_test || error "setup quota failed with $?"
3138 trap cleanup_quota_test EXIT
3140 local testfile=$DIR/$tdir/$tfile
3143 set_mdt_qtype "ug" || error "enable mdt quota failed"
3145 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3146 error "set quota failed"
3147 quota_show_check a g $TSTUSR
3149 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3150 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3151 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3152 error "create many files failed"
3154 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3156 # root user can overrun quota
3157 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3158 error "root user should succeed"
3161 resetquota -g $TSTUSR
3163 run_test 60 "Test quota for root with setgid"
3165 # test default quota
3166 test_default_quota() {
3167 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3168 skip "Not supported before 2.11.51."
3173 local qprjid=$TSTPRJID
3177 local LIMIT=20480 #20M disk space
3178 local TESTFILE="$DIR/$tdir/$tfile-0"
3180 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3181 echo "Project quota is not supported" && return 0
3183 [ $qtype == "-u" ] && qdtype="-U"
3184 [ $qtype == "-g" ] && qdtype="-G"
3185 [ $qtype == "-p" ] && {
3190 [ $qpool == "meta" ] && {
3191 LIMIT=10240 #10K inodes
3196 setup_quota_test || error "setup quota failed with $?"
3197 trap cleanup_quota_test EXIT
3201 # enable mdt/ost quota
3202 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3203 set_ost_qtype $QTYPE || error "enable ost quota failed"
3205 log "set to use default quota"
3206 $LFS setquota $qtype $qid -d $DIR ||
3207 error "set $qid to use default quota failed"
3209 log "set default quota"
3210 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3211 error "set $qid default quota failed"
3213 log "get default quota"
3214 $LFS quota $qdtype $DIR || error "get default quota failed"
3216 if [ $qpool == "data" ]; then
3217 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3219 [ $SLIMIT -eq $LIMIT ] ||
3220 error "the returned default quota is wrong"
3222 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3224 [ $SLIMIT -eq $LIMIT ] ||
3225 error "the returned default quota is wrong"
3228 # make sure the system is clean
3229 local USED=$(getquota $qtype $qid global curspace)
3230 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3232 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3233 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3235 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3237 log "Test not out of quota"
3238 if [ $qpool == "data" ]; then
3239 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3240 quota_error $qtype $qid "write failed, expect succeed"
3242 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3243 quota_error $qtype $qid "create failed, expect succeed"
3245 unlinkmany $TESTFILE $((LIMIT/2))
3248 log "Test out of quota"
3249 # flush cache, ensure noquota flag is set on client
3250 cancel_lru_locks osc
3251 cancel_lru_locks mdc
3252 sync; sync_all_data || true
3253 if [ $qpool == "data" ]; then
3254 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3255 quota_error $qtype $qid "write succeed, expect EDQUOT"
3257 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3258 quota_error $qtype $qid "create succeed, expect EDQUOT"
3260 unlinkmany $TESTFILE $((LIMIT*2))
3263 log "Increase default quota"
3264 # increase default quota
3265 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3266 error "set default quota failed"
3268 cancel_lru_locks osc
3269 cancel_lru_locks mdc
3270 sync; sync_all_data || true
3271 if [ $qpool == "data" ]; then
3272 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3273 quota_error $qtype $qid "write failed, expect succeed"
3275 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3276 quota_error $qtype $qid "create failed, expect succeed"
3278 unlinkmany $TESTFILE $((LIMIT*2))
3281 log "Set quota to override default quota"
3282 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3283 error "set $qid quota failed"
3285 cancel_lru_locks osc
3286 cancel_lru_locks mdc
3287 sync; sync_all_data || true
3288 if [ $qpool == "data" ]; then
3289 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3290 quota_error $qtype $qid "write succeed, expect EQUOT"
3292 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3293 quota_error $qtype $qid "create succeed, expect EQUOT"
3295 unlinkmany $TESTFILE $((LIMIT*2))
3298 log "Set to use default quota again"
3299 $LFS setquota $qtype $qid -d $DIR ||
3300 error "set $qid to use default quota failed"
3302 cancel_lru_locks osc
3303 cancel_lru_locks mdc
3304 sync; sync_all_data || true
3305 if [ $qpool == "data" ]; then
3306 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3307 quota_error $qtype $qid "write failed, expect succeed"
3309 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3310 quota_error $qtype $qid "create failed, expect succeed"
3312 unlinkmany $TESTFILE $((LIMIT*2))
3317 wait_delete_completed || error "wait_delete_completed failed"
3318 sync_all_data || true
3319 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3320 error "reset default quota failed"
3321 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3322 error "reset quota failed"
3328 test_default_quota "-u" "data"
3329 test_default_quota "-u" "meta"
3330 test_default_quota "-g" "data"
3331 test_default_quota "-g" "meta"
3332 test_default_quota "-p" "data"
3333 test_default_quota "-p" "meta"
3335 run_test 61 "default quota tests"
3338 ! is_project_quota_supported &&
3339 skip "Project quota is not supported"
3340 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3341 skip "chattr did not support project quota"
3342 setup_quota_test || error "setup quota failed with $?"
3343 local testdir=$DIR/$tdir/
3345 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3346 change_project -s $testdir
3347 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3348 error "inherit attribute should be set"
3349 # chattr used FS_IOC_SETFLAGS ioctl
3350 $RUNAS chattr -P $testdir &&
3351 error "regular user clear inherit should fail"
3352 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3353 error "inherit attribute should still be set"
3354 chattr -P $testdir || error "root failed to clear inherit"
3355 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3356 error "inherit attribute should be cleared"
3359 run_test 62 "Project inherit should be only changed by root"
3362 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3363 skip "Not supported before 2.11.55" && return
3367 local dd_failed=false
3368 local tdir_dom=${tdir}_dom
3369 local LIMIT=20480 #20M
3371 [ $qtype == "p" ] && ! is_project_quota_supported &&
3372 echo "Project quota is not supported" && return 0
3374 [ $qtype == "p" ] && qid=$TSTPRJID
3376 setup_quota_test || error "setup quota failed with $?"
3377 trap cleanup_quota_test EXIT
3381 # enable mdt/ost quota
3382 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3383 set_ost_qtype $QTYPE || error "enable ost quota failed"
3385 # make sure the system is clean
3386 local USED=$(getquota -$qtype $qid global curspace)
3387 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3389 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3391 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3392 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3393 error "setstripe $tdir_dom failed"
3394 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3396 [ $qtype == "p" ] && {
3397 change_project -sp $TSTPRJID $DIR/$tdir
3398 change_project -sp $TSTPRJID $DIR/$tdir_dom
3401 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3402 error "set $qid quota failed"
3404 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3405 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3409 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3411 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3412 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3416 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3418 rm -f $DIR/$tdir_dom/*
3420 # flush cache, ensure noquota flag is set on client
3421 cancel_lru_locks osc
3422 cancel_lru_locks mdc
3423 sync; sync_all_data || true
3427 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3428 quota_error $qtype $qid "write failed, expect succeed"
3430 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3431 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3435 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3438 rm -f $DIR/$tdir_dom/*
3440 # flush cache, ensure noquota flag is set on client
3441 cancel_lru_locks osc
3442 cancel_lru_locks mdc
3443 sync; sync_all_data || true
3447 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3448 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3452 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3454 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3455 quota_error $qtype $qid "write succeed, expect EDQUOT"
3458 rm -fr $DIR/$tdir_dom
3460 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3461 error "reset usr quota failed"
3471 run_test 63 "quota on DoM tests"
3475 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3476 if $PQ_CLEANUP; then
3477 disable_project_quota
3480 reset_quota_settings
3485 check_and_cleanup_lustre
3486 export QUOTA_AUTO=$QUOTA_AUTO_OLD