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}
38 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
40 require_dsh_mds || exit 0
41 require_dsh_ost || exit 0
43 # Does e2fsprogs support quota feature?
44 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
45 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
46 grep -q 'quota'"; then
47 skip_env "e2fsprogs doesn't support quota" && exit 0
50 # Test duration: 30 min
51 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
53 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
54 # bug number for skipped test: LU-6836
55 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4a"
58 # Test duration: 21 9 min"
59 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
75 is_project_quota_supported() {
76 $ENABLE_PROJECT_QUOTAS || return 1
77 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
78 [ $(lustre_version_code $SINGLEMDS) -gt \
79 $(version_code 2.9.55) ] &&
80 lfs --help | grep project >&/dev/null &&
81 egrep -q "7." /etc/redhat-release && return 0
83 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
84 [ $(lustre_version_code $SINGLEMDS) -le \
85 $(version_code 2.10.53) ] && return 1
87 $ZPOOL upgrade -v | grep project_quota && return 0
93 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
94 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
95 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
96 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
97 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
98 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
99 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
100 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
107 local fail_val=${3:-0}
111 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
112 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
113 ost) NODES="$(comma_list $(osts_nodes))";;
116 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
121 echo "lfs project $*"
122 lfs project $* || error "lfs project $* failed"
125 RUNAS="runas -u $TSTID -g $TSTID"
126 RUNAS2="runas -u $TSTID2 -g $TSTID2"
127 DD="dd if=/dev/zero bs=1M"
131 # clear quota limits for a user or a group
132 # usage: resetquota -u username
133 # resetquota -g groupname
134 # resetquota -p projid
137 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
138 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
139 error "resetquota: wrong specifier $1 passed"
141 if [ $1 == "-p" ]; then
142 is_project_quota_supported || return 0
145 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
146 error "clear quota for [type:$1 name:$2] failed"
147 # give a chance to slave to release space
155 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
156 $LFS quota -v -u $local_id $DIR
157 log "Files for user ($local_id):"
158 ($LFS find --user $local_id $DIR | head -n 4 |
159 xargs stat 2>/dev/null)
162 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
163 $LFS quota -v -g $local_id $DIR
164 log "Files for group ($local_id):"
165 ($LFS find --group $local_id $DIR | head -n 4 |
166 xargs stat 2>/dev/null)
169 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
170 $LFS quota -v -p $TSTPRJID $DIR
171 log "Files for project ($TSTPRJID):"
172 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
173 xargs stat 2>/dev/null)
189 # get quota for a user or a group
190 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
191 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
196 sync_all_data > /dev/null 2>&1 || true
198 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
199 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
200 error "getquota: wrong u/g/p specifier $1 passed"
213 *) error "unknown quota parameter $4";;
216 [ "$uuid" = "global" ] && uuid=$DIR
218 $LFS quota -v "$1" "$2" $DIR |
219 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
220 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
225 # usage: set_mdt_qtype ugp|u|g|p|none
229 local mdts=$(get_facets MDS)
231 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
232 qtype=$(tr -d 'p' <<<$qtype)
234 if [[ $PERM_CMD == *"set_param -P"* ]]; then
235 do_facet mgs $PERM_CMD \
236 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
238 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
240 # we have to make sure each MDT received config changes
241 for mdt in ${mdts//,/ }; do
243 cmd="$LCTL get_param -n "
244 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
245 cmd=${cmd}.quota_slave.enabled
247 if $(facet_up $mdt); then
248 wait_update_facet $mdt "$cmd" "$qtype" || return 1
255 # usage: set_ost_qtype ugp|u|g|p|none
259 local osts=$(get_facets OST)
261 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
262 qtype=$(tr -d 'p' <<<$qtype)
264 if [[ $PERM_CMD == *"set_param -P"* ]]; then
265 do_facet mgs $PERM_CMD \
266 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
268 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
270 # we have to make sure each OST received config changes
271 for ost in ${osts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
275 cmd=${cmd}.quota_slave.enabled
277 if $(facet_up $ost); then
278 wait_update_facet $ost "$cmd" "$qtype" || return 1
284 wait_reintegration() {
288 local result="glb[1],slv[1],reint[0]"
293 if [ $ntype == "mdt" ]; then
294 tgts=$(get_facets MDS)
296 tgts=$(get_facets OST)
299 for tgt in ${tgts//,/ }; do
301 cmd="$LCTL get_param -n "
302 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
303 cmd=${cmd}.quota_slave.info
305 if $(facet_up $tgt); then
306 wait_update_facet $tgt "$cmd |
307 grep "$qtype" | awk '{ print \\\$3 }'" \
308 "$result" $max || return 1
318 if [[ "$qtype" =~ "u" ]]; then
319 wait_reintegration "mdt" "user" $max || return 1
322 if [[ "$qtype" =~ "g" ]]; then
323 wait_reintegration "mdt" "group" $max || return 1
326 if [[ "$qtype" =~ "p" ]]; then
327 ! is_project_quota_supported && return 0
328 wait_reintegration "mdt" "project" $max || return 1
337 if [[ "$qtype" =~ "u" ]]; then
338 wait_reintegration "ost" "user" $max || return 1
341 if [[ "$qtype" =~ "g" ]]; then
342 wait_reintegration "ost" "group" $max || return 1
345 if [[ "$qtype" =~ "p" ]]; then
346 ! is_project_quota_supported && return 0
347 wait_reintegration "ost" "project" $max || return 1
352 disable_project_quota() {
353 is_project_quota_supported || return 0
354 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
355 stopall || error "failed to stopall (1)"
357 for num in $(seq $MDSCOUNT); do
358 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
359 error "tune2fs $(mdsdevname $num) failed"
362 for num in $(seq $OSTCOUNT); do
363 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
364 error "tune2fs $(ostdevname $num) failed"
372 wait_delete_completed
373 echo "Creating test directory"
374 mkdir $DIR/$tdir || return 1
375 chmod 0777 $DIR/$tdir || return 2
376 # always clear fail_loc in case of fail_loc isn't cleared
377 # properly when previous test failed
378 lustre_fail mds_ost 0
381 cleanup_quota_test() {
383 echo "Delete files..."
385 echo "Wait for unlink objects finished..."
386 wait_delete_completed
387 sync_all_data || true
396 $LFS quota -v -$ugp $qid $DIR
398 if [ "$bf" == "a" -o "$bf" == "b" ]; then
399 usage=$(getquota -$ugp $qid global curspace)
400 if [ -z $usage ]; then
401 quota_error $ugp $qid \
402 "Query block quota failed ($ugp:$qid)."
404 [ $usage -ne 0 ] && quota_log $ugp $qid \
405 "Block quota isn't 0 ($ugp:$qid:$usage)."
409 if [ "$bf" == "a" -o "$bf" == "f" ]; then
410 usage=$(getquota -$ugp $qid global curinodes)
411 if [ -z $usage ]; then
412 quota_error $ugp $qid \
413 "Query file quota failed ($ugp:$qid)."
415 [ $usage -ne 0 ] && quota_log $ugp $qid \
416 "File quota isn't 0 ($ugp:$qid:$usage)."
421 enable_project_quota() {
422 is_project_quota_supported || return 0
423 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
424 stopall || error "failed to stopall (1)"
426 for num in $(seq $MDSCOUNT); do
427 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
428 error "tune2fs $(mdsdevname $num) failed"
431 for num in $(seq $OSTCOUNT); do
432 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
433 error "tune2fs $(ostdevname $num) failed"
441 reset_quota_settings() {
442 resetquota -u $TSTUSR
443 resetquota -g $TSTUSR
444 resetquota -u $TSTUSR2
445 resetquota -g $TSTUSR2
446 resetquota -p $TSTPRJID
451 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
456 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
457 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
458 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
459 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
461 test_quota_performance() {
462 local TESTFILE="$DIR/$tdir/$tfile-0"
463 local size=$1 # in MB
464 local stime=$(date +%s)
465 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
466 quota_error u $TSTUSR "write failure"
467 local etime=$(date +%s)
468 delta=$((etime - stime))
469 if [ $delta -gt 0 ]; then
470 rate=$((size * 1024 / delta))
471 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
472 # LU-2872 - see LU-2887 for fix
474 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
476 [ $rate -gt 1024 ] ||
477 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
483 # test basic quota performance b=21696
486 [ "$SLOW" = "no" ] && MB=10
488 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
489 [ $free_space -le $((MB * 1024)) ] &&
490 skip "not enough space ${free_space} KB, " \
491 "required $((MB * 1024)) KB"
492 setup_quota_test || error "setup quota failed with $?"
493 trap cleanup_quota_test EXIT
495 set_ost_qtype "none" || error "disable ost quota failed"
496 test_quota_performance $MB
498 set_ost_qtype $QTYPE || error "enable ost quota failed"
499 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
500 error "set quota failed"
501 test_quota_performance $MB
504 resetquota -u $TSTUSR
506 run_test 0 "Test basic quota performance"
508 # test block hardlimit
511 local TESTFILE="$DIR/$tdir/$tfile-0"
513 setup_quota_test || error "setup quota failed with $?"
514 trap cleanup_quota_test EXIT
517 set_ost_qtype $QTYPE || error "enable ost quota failed"
520 log "User quota (block hardlimit:$LIMIT MB)"
521 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
522 error "set user quota failed"
524 # make sure the system is clean
525 local USED=$(getquota -u $TSTUSR global curspace)
526 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
528 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
529 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
532 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
533 quota_error u $TSTUSR "user write failure, but expect success"
534 log "Write out of block quota ..."
535 # this time maybe cache write, ignore it's failure
536 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
537 # flush cache, ensure noquota flag is set on client
539 sync; sync_all_data || true
540 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
541 quota_error u $TSTUSR "user write success, but expect EDQUOT"
544 wait_delete_completed || error "wait_delete_completed failed"
545 sync_all_data || true
546 USED=$(getquota -u $TSTUSR global curspace)
547 [ $USED -ne 0 ] && quota_error u $TSTUSR \
548 "user quota isn't released after deletion"
549 resetquota -u $TSTUSR
552 log "--------------------------------------"
553 log "Group quota (block hardlimit:$LIMIT MB)"
554 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
555 error "set group quota failed"
557 TESTFILE="$DIR/$tdir/$tfile-1"
558 # make sure the system is clean
559 USED=$(getquota -g $TSTUSR global curspace)
560 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
562 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
563 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
566 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
567 quota_error g $TSTUSR "Group write failure, but expect success"
568 log "Write out of block quota ..."
569 # this time maybe cache write, ignore it's failure
570 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
572 sync; sync_all_data || true
573 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
574 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
576 wait_delete_completed || error "wait_delete_completed failed"
577 sync_all_data || true
578 USED=$(getquota -g $TSTUSR global curspace)
579 [ $USED -ne 0 ] && quota_error g $TSTUSR \
580 "Group quota isn't released after deletion"
581 resetquota -g $TSTUSR
583 if ! is_project_quota_supported; then
584 echo "Project quota is not supported"
589 TESTFILE="$DIR/$tdir/$tfile-2"
590 # make sure the system is clean
591 USED=$(getquota -p $TSTPRJID global curspace)
593 error "used space($USED) for project $TSTPRJID isn't 0"
596 log "--------------------------------------"
597 log "Project quota (block hardlimit:$LIMIT mb)"
598 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
599 error "set project quota failed"
601 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
602 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
603 change_project -p $TSTPRJID $TESTFILE
606 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
607 "project write failure, but expect success"
608 log "write out of block quota ..."
609 # this time maybe cache write, ignore it's failure
610 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
612 sync; sync_all_data || true
613 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
614 $TSTPRJID "project write success, but expect EDQUOT"
619 USED=$(getquota -p $TSTPRJID global curspace)
620 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
621 "project quota isn't released after deletion"
623 resetquota -p $TSTPRJID
625 run_test 1 "Block hard limit (normal use and out of quota)"
627 # test inode hardlimit
629 local LIMIT=$((1024 * 1024)) # 1M inodes
630 local TESTFILE="$DIR/$tdir/$tfile-0"
632 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
634 local FREE_INODES=$(mdt_free_inodes 0)
635 echo "$FREE_INODES free inodes on master MDT"
636 [ $FREE_INODES -lt $LIMIT ] &&
637 skip "not enough free inodes $FREE_INODES required $LIMIT"
639 setup_quota_test || error "setup quota failed with $?"
640 trap cleanup_quota_test EXIT
643 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
646 log "User quota (inode hardlimit:$LIMIT files)"
647 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
648 error "set user quota failed"
650 # make sure the system is clean
651 local USED=$(getquota -u $TSTUSR global curinodes)
652 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
654 log "Create $LIMIT files ..."
655 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
656 quota_error u $TSTUSR "user create failure, but expect success"
657 log "Create out of file quota ..."
658 $RUNAS touch ${TESTFILE}_xxx &&
659 quota_error u $TSTUSR "user create success, but expect EDQUOT"
662 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
663 rm -f ${TESTFILE}_xxx
664 wait_delete_completed
666 USED=$(getquota -u $TSTUSR global curinodes)
667 [ $USED -ne 0 ] && quota_error u $TSTUSR \
668 "user quota isn't released after deletion"
669 resetquota -u $TSTUSR
672 log "--------------------------------------"
673 log "Group quota (inode hardlimit:$LIMIT files)"
674 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
675 error "set group quota failed"
677 TESTFILE=$DIR/$tdir/$tfile-1
678 # make sure the system is clean
679 USED=$(getquota -g $TSTUSR global curinodes)
680 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
682 log "Create $LIMIT files ..."
683 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
684 quota_error g $TSTUSR "group create failure, but expect success"
685 log "Create out of file quota ..."
686 $RUNAS touch ${TESTFILE}_xxx &&
687 quota_error g $TSTUSR "group create success, but expect EDQUOT"
690 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
691 rm -f ${TESTFILE}_xxx
692 wait_delete_completed
694 USED=$(getquota -g $TSTUSR global curinodes)
695 [ $USED -ne 0 ] && quota_error g $TSTUSR \
696 "user quota isn't released after deletion"
698 resetquota -g $TSTUSR
699 ! is_project_quota_supported && cleanup_quota_test &&
700 echo "Skip project quota is not supported" && return 0
703 log "--------------------------------------"
704 log "Project quota (inode hardlimit:$LIMIT files)"
705 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
706 error "set project quota failed"
708 TESTFILE=$DIR/$tdir/$tfile-1
709 # make sure the system is clean
710 USED=$(getquota -p $TSTPRJID global curinodes)
712 error "Used inodes($USED) for project $TSTPRJID isn't 0"
714 change_project -sp $TSTPRJID $DIR/$tdir
715 log "Create $LIMIT files ..."
716 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
717 $TSTPRJID "project create fail, but expect success"
718 log "Create out of file quota ..."
719 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
720 "project create success, but expect EDQUOT"
721 change_project -C $DIR/$tdir
724 USED=$(getquota -p $TSTPRJID global curinodes)
725 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
726 "project quota isn't released after deletion"
728 resetquota -p $TSTPRJID
731 run_test 2 "File hard limit (normal use and out of quota)"
735 local TIMER=$(($2 * 3 / 2))
741 trap cleanup_quota_test EXIT
743 $SETSTRIPE $TESTFILE -c 1 -i 0
744 chown $TSTUSR.$TSTUSR $TESTFILE
745 [ "$qtype" == "p" ] && is_project_quota_supported &&
746 change_project -p $TSTPRJID $TESTFILE
748 echo "Write up to soft limit"
749 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
750 quota_error a $TSTUSR "write failure, but expect success"
751 OFFSET=$((LIMIT * 1024))
754 echo "Write to exceed soft limit"
755 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
756 quota_error a $TSTUSR "write failure, but expect success"
757 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
763 $SHOW_QUOTA_INFO_USER
764 $SHOW_QUOTA_INFO_GROUP
765 $SHOW_QUOTA_INFO_PROJID
767 echo "Write before timer goes off"
768 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
769 quota_error a $TSTUSR "write failure, but expect success"
770 OFFSET=$((OFFSET + 1024))
773 echo "Sleep $TIMER seconds ..."
779 $SHOW_QUOTA_INFO_USER
780 $SHOW_QUOTA_INFO_GROUP
781 $SHOW_QUOTA_INFO_PROJID
783 echo "Write after timer goes off"
784 # maybe cache write, ignore.
785 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
786 OFFSET=$((OFFSET + 1024))
788 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
789 quota_error a $TSTUSR "write success, but expect EDQUOT"
794 $SHOW_QUOTA_INFO_USER
795 $SHOW_QUOTA_INFO_GROUP
796 $SHOW_QUOTA_INFO_PROJID
798 echo "Unlink file to stop timer"
800 wait_delete_completed
801 sync_all_data || true
806 $SHOW_QUOTA_INFO_USER
807 $SHOW_QUOTA_INFO_GROUP
808 $SHOW_QUOTA_INFO_PROJID
810 $SETSTRIPE $TESTFILE -c 1 -i 0
811 chown $TSTUSR.$TSTUSR $TESTFILE
812 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
815 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
816 quota_error a $TSTUSR "write failure, but expect success"
825 local TESTFILE=$DIR/$tdir/$tfile-0
827 set_ost_qtype $QTYPE || error "enable ost quota failed"
829 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
830 # make sure the system is clean
831 local USED=$(getquota -u $TSTUSR global curspace)
832 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
834 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
835 $MAX_IQ_TIME $DIR || error "set user grace time failed"
836 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
837 error "set user quota failed"
839 test_block_soft $TESTFILE $GRACE $LIMIT "u"
840 resetquota -u $TSTUSR
842 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
843 TESTFILE=$DIR/$tdir/$tfile-1
844 # make sure the system is clean
845 USED=$(getquota -g $TSTUSR global curspace)
846 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
848 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
849 $MAX_IQ_TIME $DIR || error "set group grace time failed"
850 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
851 error "set group quota failed"
853 test_block_soft $TESTFILE $GRACE $LIMIT "g"
854 resetquota -g $TSTUSR
856 if is_project_quota_supported; then
857 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
858 TESTFILE=$DIR/$tdir/$tfile-2
859 # make sure the system is clean
860 USED=$(getquota -p $TSTPRJID global curspace)
861 [ $USED -ne 0 ] && error \
862 "Used space($USED) for project $TSTPRJID isn't 0."
864 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
866 error "set project grace time failed"
867 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
868 $DIR || error "set project quota failed"
870 test_block_soft $TESTFILE $GRACE $LIMIT "p"
871 resetquota -p $TSTPRJID
872 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
874 error "restore project grace time failed"
878 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
879 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
880 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
881 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
883 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
889 local TIMER=$(($grace * 3 / 2))
892 trap cleanup_quota_test EXIT
893 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
895 echo "Create files to exceed soft limit"
896 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
897 quota_error a $TSTUSR "create failure, but expect success"
898 local trigger_time=$(date +%s)
900 sync_all_data || true
902 local cur_time=$(date +%s)
903 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
904 error "Passed grace time $grace, $trigger_time, $cur_time"
906 echo "Create file before timer goes off"
907 $RUNAS touch ${TESTFILE}_before ||
908 quota_error a $TSTUSR "failed create before timer expired," \
909 "but expect success. $trigger_time, $cur_time"
910 sync_all_data || true
912 echo "Sleep $TIMER seconds ..."
918 $SHOW_QUOTA_INFO_USER
919 $SHOW_QUOTA_INFO_GROUP
920 $SHOW_QUOTA_INFO_PROJID
922 echo "Create file after timer goes off"
923 # There is a window that space is accounted in the quota usage but
924 # hasn't been decreased from the pending write, if we acquire quota
925 # in this window, we'll acquire more than we needed.
926 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
927 sync_all_data || true
928 $RUNAS touch ${TESTFILE}_after_3 &&
929 quota_error a $TSTUSR "create after timer expired," \
931 sync_all_data || true
936 $SHOW_QUOTA_INFO_USER
937 $SHOW_QUOTA_INFO_GROUP
938 $SHOW_QUOTA_INFO_PROJID
940 echo "Unlink files to stop timer"
941 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
942 wait_delete_completed
945 $RUNAS touch ${TESTFILE}_xxx ||
946 quota_error a $TSTUSR "touch after timer stop failure," \
948 sync_all_data || true
956 local LIMIT=10 # inodes
957 local TESTFILE=$DIR/$tdir/$tfile-0
960 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
962 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
963 # make sure the system is clean
964 local USED=$(getquota -u $TSTUSR global curinodes)
965 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
967 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
968 $GRACE $DIR || error "set user grace time failed"
969 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
970 error "set user quota failed"
972 test_file_soft $TESTFILE $LIMIT $GRACE
973 resetquota -u $TSTUSR
975 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
976 # make sure the system is clean
977 USED=$(getquota -g $TSTUSR global curinodes)
978 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
980 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
981 $GRACE $DIR || error "set group grace time failed"
982 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
983 error "set group quota failed"
984 TESTFILE=$DIR/$tdir/$tfile-1
986 test_file_soft $TESTFILE $LIMIT $GRACE
987 resetquota -g $TSTUSR
989 if is_project_quota_supported; then
990 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
991 # make sure the system is clean
992 USED=$(getquota -p $TSTPRJID global curinodes)
993 [ $USED -ne 0 ] && error \
994 "Used space($USED) for project $TSTPRJID isn't 0."
996 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
997 $GRACE $DIR || error "set project grace time failed"
998 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
999 error "set project quota failed"
1001 TESTFILE=$DIR/$tdir/$tfile-1
1002 # one less than limit, because of parent directory included.
1003 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1004 resetquota -p $TSTPRJID
1005 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1006 $MAX_IQ_TIME $DIR ||
1007 error "restore project grace time failed"
1011 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1012 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1013 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1014 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1016 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1019 local GR_STR1="1w3d"
1020 local GR_STR2="1000s"
1022 local GR_STR4="1w2d3h4m5s"
1024 local GR_STR6="18446744073709551615"
1027 wait_delete_completed
1029 # test of valid grace strings handling
1030 echo "Valid grace strings test"
1031 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1032 $GR_STR2 $DIR || error "set user grace time failed"
1033 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1034 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1035 $GR_STR4 $DIR || error "set group grace time quota failed"
1036 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1038 # test of invalid grace strings handling
1039 echo " Invalid grace strings test"
1040 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1041 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1042 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1046 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1047 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1048 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1049 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1051 run_test 4b "Grace time strings handling"
1053 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1055 local BLIMIT=10 # 10M
1056 local ILIMIT=10 # 10 inodes
1058 setup_quota_test || error "setup quota failed with $?"
1059 trap cleanup_quota_test EXIT
1061 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1062 set_ost_qtype $QTYPE || error "enable ost quota failed"
1064 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1065 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1066 error "set user quota failed"
1067 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1068 if is_project_quota_supported; then
1069 error "set group quota failed"
1070 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1071 -I $ILIMIT $DIR || error "set project quota failed"
1074 # make sure the system is clean
1075 local USED=$(getquota -u $TSTUSR global curinodes)
1076 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1077 USED=$(getquota -g $TSTUSR global curinodes)
1078 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1079 USED=$(getquota -u $TSTUSR global curspace)
1080 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1081 USED=$(getquota -g $TSTUSR global curspace)
1082 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1083 if is_project_quota_supported; then
1084 USED=$(getquota -p $TSTPRJID global curinodes)
1086 error "Used inode($USED) for project $TSTPRJID isn't 0."
1087 USED=$(getquota -p $TSTPRJID global curspace)
1089 error "Used block($USED) for project $TSTPRJID isn't 0."
1092 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1093 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1094 error "create failure, expect success"
1095 if is_project_quota_supported; then
1096 touch $DIR/$tdir/$tfile-0_1
1097 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1099 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1100 error "write failure, expect success"
1102 echo "Chown files to $TSTUSR.$TSTUSR ..."
1103 for i in $(seq 0 $ILIMIT); do
1104 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1105 quota_error a $TSTUSR "chown failure, expect success"
1109 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1110 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1113 resetquota -u $TSTUSR
1114 resetquota -g $TSTUSR
1115 resetquota -p $TSTPRJID
1117 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1119 # test dropping acquire request on master
1123 # Clear dmesg so watchdog is not triggered by previous
1125 do_facet ost1 dmesg -c > /dev/null
1127 setup_quota_test || error "setup quota failed with $?"
1128 trap cleanup_quota_test EXIT
1130 # make sure the system is clean
1131 local USED=$(getquota -u $TSTUSR global curspace)
1132 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1134 # make sure no granted quota on ost
1135 set_ost_qtype $QTYPE || error "enable ost quota failed"
1136 resetquota -u $TSTUSR
1138 # create file for $TSTUSR
1139 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1140 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1141 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1143 # create file for $TSTUSR2
1144 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1145 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1146 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1148 # cache per-ID lock for $TSTUSR on slave
1149 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1150 error "set quota failed"
1151 $RUNAS $DD of=$TESTFILE count=1 ||
1152 error "write $TESTFILE failure, expect success"
1153 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1154 error "write $TESTFILE2 failure, expect success"
1156 sync_all_data || true
1158 #define QUOTA_DQACQ 601
1159 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1160 lustre_fail mds 0x513 601
1162 # write to un-enforced ID ($TSTUSR2) should succeed
1163 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1164 error "write failure, expect success"
1166 # write to enforced ID ($TSTUSR) in background, exceeding limit
1167 # to make sure DQACQ is sent
1168 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1171 # watchdog timer uses a factor of 2
1172 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1173 sleep $((TIMEOUT * 2 + 1))
1175 # write should be blocked and never finished
1176 if ! ps -p $DDPID > /dev/null 2>&1; then
1178 error "write finished incorrectly!"
1183 # no watchdog is triggered
1184 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1185 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1186 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1187 [ -z "$watchdog" ] || error "$watchdog"
1189 rm -f $TMP/lustre-log-${TESTNAME}.log
1191 # write should continue then fail with EDQUOT
1195 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1196 if [ $count -ge 240 ]; then
1197 quota_error u $TSTUSR "dd not finished in $count secs"
1199 count=$((count + 1))
1200 if [ $((count % 30)) -eq 0 ]; then
1201 c_size=$(stat -c %s $TESTFILE)
1202 echo "Waiting $count secs. $c_size"
1209 resetquota -u $TSTUSR
1211 run_test 6 "Test dropping acquire request on master"
1213 # quota reintegration (global index)
1215 local TESTFILE=$DIR/$tdir/$tfile
1216 local LIMIT=20 # 20M
1218 [ "$SLOW" = "no" ] && LIMIT=5
1220 setup_quota_test || error "setup quota failed with $?"
1221 trap cleanup_quota_test EXIT
1223 # make sure the system is clean
1224 local USED=$(getquota -u $TSTUSR global curspace)
1225 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1227 # make sure no granted quota on ost1
1228 set_ost_qtype $QTYPE || error "enable ost quota failed"
1229 resetquota -u $TSTUSR
1230 set_ost_qtype "none" || error "disable ost quota failed"
1232 local OSTUUID=$(ostuuid_from_index 0)
1233 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1235 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1238 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1239 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1244 echo "Enable quota & set quota limit for $TSTUSR"
1245 set_ost_qtype $QTYPE || error "enable ost quota failed"
1246 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1247 error "set quota failed"
1249 echo "Start ost1..."
1250 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1253 wait_ost_reint $QTYPE || error "reintegration failed"
1255 # hardlimit should have been fetched by slave during global
1256 # reintegration, write will exceed quota
1257 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1258 quota_error u $TSTUSR "write success, but expect EDQUOT"
1261 wait_delete_completed
1262 sync_all_data || true
1268 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1269 error "clear quota failed"
1271 echo "Start ost1..."
1272 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1275 wait_ost_reint $QTYPE || error "reintegration failed"
1277 # hardlimit should be cleared on slave during reintegration
1278 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1279 quota_error u $TSTUSR "write error, but expect success"
1282 resetquota -u $TSTUSR
1284 run_test 7a "Quota reintegration (global index)"
1286 # quota reintegration (slave index)
1289 local TESTFILE=$DIR/$tdir/$tfile
1291 setup_quota_test || error "setup quota failed with $?"
1292 trap cleanup_quota_test EXIT
1294 # make sure the system is clean
1295 local USED=$(getquota -u $TSTUSR global curspace)
1296 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1298 # make sure no granted quota on ost1
1299 set_ost_qtype $QTYPE || error "enable ost quota failed"
1300 resetquota -u $TSTUSR
1301 set_ost_qtype "none" || error "disable ost quota failed"
1303 local OSTUUID=$(ostuuid_from_index 0)
1304 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1306 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1309 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1310 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1312 # consume some space to make sure the granted space will not
1313 # be released during reconciliation
1314 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1315 error "consume space failure, expect success"
1317 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1318 lustre_fail mds 0xa02
1320 set_ost_qtype $QTYPE || error "enable ost quota failed"
1321 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1322 error "set quota failed"
1324 # ignore the write error
1325 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1327 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1331 echo "Restart ost to trigger reintegration..."
1333 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1336 wait_ost_reint $QTYPE || error "reintegration failed"
1338 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1339 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1342 resetquota -u $TSTUSR
1345 run_test 7b "Quota reintegration (slave index)"
1347 # quota reintegration (restart mds during reintegration)
1349 local LIMIT=20 # 20M
1350 local TESTFILE=$DIR/$tdir/$tfile
1352 [ "$SLOW" = "no" ] && LIMIT=5
1354 setup_quota_test || error "setup quota failed with $?"
1355 trap cleanup_quota_test EXIT
1357 # make sure the system is clean
1358 local USED=$(getquota -u $TSTUSR global curspace)
1359 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1361 set_ost_qtype "none" || error "disable ost quota failed"
1362 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1363 error "set quota failed"
1365 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1366 lustre_fail ost 0xa03
1369 set_ost_qtype $QTYPE || error "enable ost quota failed"
1370 # trigger reintegration
1371 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1372 procf=${procf}quota_slave.force_reint
1373 do_facet ost1 $LCTL set_param $procf=1 ||
1374 error "force reintegration failed"
1382 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1385 # wait longer than usual to make sure the reintegration
1386 # is triggered by quota wb thread.
1387 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1389 # hardlimit should have been fetched by slave during global
1390 # reintegration, write will exceed quota
1391 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1392 quota_error u $TSTUSR "write success, but expect EDQUOT"
1395 resetquota -u $TSTUSR
1397 run_test 7c "Quota reintegration (restart mds during reintegration)"
1399 # Quota reintegration (Transfer index in multiple bulks)
1401 local TESTFILE=$DIR/$tdir/$tfile
1402 local TESTFILE1="$DIR/$tdir/$tfile"-1
1405 setup_quota_test || error "setup quota failed with $?"
1406 trap cleanup_quota_test EXIT
1408 set_ost_qtype "none" || error "disable ost quota failed"
1409 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1410 error "set quota for $TSTUSR failed"
1411 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1412 error "set quota for $TSTUSR2 failed"
1414 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1415 lustre_fail mds 0x608 0
1417 # enable quota to tirgger reintegration
1418 set_ost_qtype "u" || error "enable ost quota failed"
1419 wait_ost_reint "u" || error "reintegration failed"
1423 # hardlimit should have been fetched by slave during global
1424 # reintegration, write will exceed quota
1425 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1426 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1428 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1429 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1432 resetquota -u $TSTUSR
1433 resetquota -u $TSTUSR2
1435 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1437 # quota reintegration (inode limits)
1439 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1441 # LU-2435: skip this quota test if underlying zfs version has not
1442 # supported native dnode accounting
1443 [ "$(facet_fstype mds1)" == "zfs" ] && {
1444 local F="feature@userobj_accounting"
1445 local pool=$(zpool_name mds1)
1446 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1448 [[ "$feature" != *" active "* ]] &&
1449 skip "requires zpool with active userobj_accounting"
1452 local ilimit=$((1024 * 2)) # 2k inodes
1453 local TESTFILE=$DIR/${tdir}-1/$tfile
1455 setup_quota_test || error "setup quota failed with $?"
1456 trap cleanup_quota_test EXIT
1458 # make sure the system is clean
1459 local USED=$(getquota -u $TSTUSR global curinodes)
1460 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1462 # make sure no granted quota on mdt1
1463 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1464 resetquota -u $TSTUSR
1465 set_mdt_qtype "none" || error "disable mdt quota failed"
1467 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1468 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1469 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1472 echo "Stop mds${MDSCOUNT}..."
1475 echo "Enable quota & set quota limit for $TSTUSR"
1476 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1477 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1478 error "set quota failed"
1480 echo "Start mds${MDSCOUNT}..."
1481 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1484 wait_mdt_reint $QTYPE || error "reintegration failed"
1486 echo "create remote dir"
1487 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1488 error "create remote dir failed"
1489 chmod 0777 $DIR/${tdir}-1
1491 # hardlimit should have been fetched by slave during global
1492 # reintegration, create will exceed quota
1493 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1494 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1496 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1497 wait_delete_completed
1498 sync_all_data || true
1500 echo "Stop mds${MDSCOUNT}..."
1503 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1504 error "clear quota failed"
1506 echo "Start mds${MDSCOUNT}..."
1507 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1510 wait_mdt_reint $QTYPE || error "reintegration failed"
1512 # hardlimit should be cleared on slave during reintegration
1513 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1514 quota_error u $TSTUSR "create failed, expect success"
1516 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1517 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1520 resetquota -u $TSTUSR
1522 run_test 7e "Quota reintegration (inode limits)"
1524 # run dbench with quota enabled
1526 local BLK_LIMIT="100g" #100G
1527 local FILE_LIMIT=1000000
1529 setup_quota_test || error "setup quota failed with $?"
1530 trap cleanup_quota_test EXIT
1532 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1533 set_ost_qtype $QTYPE || error "enable ost quota failed"
1535 echo "Set enough high limit for user: $TSTUSR"
1536 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1537 error "set user quota failed"
1538 echo "Set enough high limit for group: $TSTUSR"
1539 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1540 error "set group quota failed"
1541 if is_project_quota_supported; then
1542 change_project -sp $TSTPRJID $DIR/$tdir
1543 echo "Set enough high limit for project: $TSTPRJID"
1544 $LFS setquota -p $TSTPRJID -b 0 \
1545 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1546 error "set project quota failed"
1550 [ "$SLOW" = "no" ] && duration=" -t 120"
1551 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1552 quota_error a $TSTUSR "dbench failed!"
1554 is_project_quota_supported && change_project -C $DIR/$tdir
1556 resetquota -u $TSTUSR
1557 resetquota -g $TSTUSR
1558 resetquota -p $TSTPRJID
1560 run_test 8 "Run dbench with quota enabled"
1562 # this check is just for test_9
1563 OST0_MIN=4900000 #4.67G
1565 check_whether_skip () {
1566 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1567 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1568 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1569 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1576 # run for fixing bug10707, it needs a big room. test for 64bit
1578 local filesize=$((1024 * 9 / 2)) # 4.5G
1580 check_whether_skip && return 0
1582 setup_quota_test || error "setup quota failed with $?"
1583 trap cleanup_quota_test EXIT
1585 set_ost_qtype "ug" || error "enable ost quota failed"
1587 local TESTFILE="$DIR/$tdir/$tfile-0"
1588 local BLK_LIMIT=100G #100G
1589 local FILE_LIMIT=1000000
1591 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1593 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1595 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1596 error "set user quota failed"
1598 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1599 "for group: $TSTUSR"
1600 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set group quota failed"
1603 quota_show_check a u $TSTUSR
1604 quota_show_check a g $TSTUSR
1606 echo "Create test file"
1607 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1608 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1610 log "Write the big file of 4.5G ..."
1611 $RUNAS $DD of=$TESTFILE count=$filesize ||
1612 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1618 resetquota -u $TSTUSR
1619 resetquota -g $TSTUSR
1624 run_test 9 "Block limit larger than 4GB (b10707)"
1627 local TESTFILE=$DIR/$tdir/$tfile
1629 setup_quota_test || error "setup quota failed with $?"
1630 trap cleanup_quota_test EXIT
1632 # set limit to root user should fail
1633 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1634 error "set limit for root user successfully, expect failure"
1635 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1636 error "set limit for root group successfully, expect failure"
1637 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1638 error "set limit for project 0 successfully, expect failure"
1640 # root user can overrun quota
1641 set_ost_qtype "ug" || error "enable ost quota failed"
1643 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1644 error "set quota failed"
1645 quota_show_check b u $TSTUSR
1647 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1648 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1650 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1651 error "write failure, expect success"
1654 resetquota -u $TSTUSR
1656 run_test 10 "Test quota for root user"
1659 local TESTFILE=$DIR/$tdir/$tfile
1660 setup_quota_test || error "setup quota failed with $?"
1661 trap cleanup_quota_test EXIT
1663 set_mdt_qtype "ug" || error "enable mdt quota failed"
1664 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1665 error "set quota failed"
1667 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1668 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1670 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1671 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1674 local USED=$(getquota -u $TSTUSR global curinodes)
1675 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1678 resetquota -u $TSTUSR
1680 run_test 11 "Chown/chgrp ignores quota"
1683 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1685 local blimit=22 # 22M
1686 local blk_cnt=$((blimit - 5))
1687 local TESTFILE0="$DIR/$tdir/$tfile"-0
1688 local TESTFILE1="$DIR/$tdir/$tfile"-1
1690 setup_quota_test || error "setup quota failed with $?"
1691 trap cleanup_quota_test EXIT
1693 set_ost_qtype "u" || error "enable ost quota failed"
1694 quota_show_check b u $TSTUSR
1696 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1697 error "set quota failed"
1699 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1700 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1701 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1702 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1704 echo "Write to ost0..."
1705 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1706 quota_error a $TSTUSR "dd failed"
1708 echo "Write to ost1..."
1709 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1710 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1712 echo "Free space from ost0..."
1714 wait_delete_completed
1715 sync_all_data || true
1717 echo "Write to ost1 after space freed from ost0..."
1718 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1719 quota_error a $TSTUSR "rebalancing failed"
1722 resetquota -u $TSTUSR
1724 run_test 12a "Block quota rebalancing"
1727 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1729 local ilimit=$((1024 * 2)) # 2k inodes
1730 local TESTFILE0=$DIR/$tdir/$tfile
1731 local TESTFILE1=$DIR/${tdir}-1/$tfile
1733 setup_quota_test || error "setup quota failed with $?"
1734 trap cleanup_quota_test EXIT
1736 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1737 chmod 0777 $DIR/${tdir}-1
1739 set_mdt_qtype "u" || error "enable mdt quota failed"
1740 quota_show_check f u $TSTUSR
1742 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1743 error "set quota failed"
1745 echo "Create $ilimit files on mdt0..."
1746 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1747 quota_error u $TSTUSR "create failed, but expect success"
1749 echo "Create files on mdt1..."
1750 $RUNAS createmany -m $TESTFILE1 1 &&
1751 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1753 echo "Free space from mdt0..."
1754 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1755 wait_delete_completed
1756 sync_all_data || true
1758 echo "Create files on mdt1 after space freed from mdt0..."
1759 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1760 quota_error a $TSTUSR "rebalancing failed"
1762 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1763 error "unlink mdt1 files failed"
1764 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1767 resetquota -u $TSTUSR
1769 run_test 12b "Inode quota rebalancing"
1772 local TESTFILE=$DIR/$tdir/$tfile
1773 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1774 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1776 setup_quota_test || error "setup quota failed with $?"
1777 trap cleanup_quota_test EXIT
1779 set_ost_qtype "u" || error "enable ost quota failed"
1780 quota_show_check b u $TSTUSR
1782 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1783 error "set quota failed"
1784 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1785 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1787 # clear the locks in cache first
1788 do_facet ost1 $LCTL set_param -n $procf=clear
1789 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1790 [ $nlock -eq 0 ] || error "$nlock cached locks"
1792 # write to acquire the per-ID lock
1793 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1794 quota_error a $TSTUSR "dd failed"
1796 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1797 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1799 # clear quota doesn't trigger per-ID lock cancellation
1800 resetquota -u $TSTUSR
1801 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1802 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1804 # clear the per-ID lock
1805 do_facet ost1 $LCTL set_param -n $procf=clear
1806 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1807 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1809 # spare quota should be released
1810 local OSTUUID=$(ostuuid_from_index 0)
1811 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1812 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1813 [ $limit -le $space ] ||
1814 error "spare quota isn't released, limit:$limit, space:$space"
1818 run_test 13 "Cancel per-ID lock in the LRU list"
1821 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1823 wait_delete_completed
1824 sync_all_data || true
1827 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1828 error "set user quota failed"
1829 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1830 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1831 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1832 resetquota -u $TSTUSR
1835 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1836 error "set group quota failed"
1837 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1838 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1839 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1840 resetquota -g $TSTUSR
1842 run_test 15 "Set over 4T block quota"
1846 local BLKS=1 # 1M less than limit
1847 local TESTFILE=$DIR/$tdir/$tfile
1849 setup_quota_test || error "setup quota failed with $?"
1850 trap cleanup_quota_test EXIT
1852 # make sure the system is clean
1853 local USED=$(getquota -u $TSTUSR global curspace)
1854 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1856 set_ost_qtype "ug" || error "enable ost quota failed"
1857 # make sure no granted quota on ost
1858 resetquota -u $TSTUSR
1859 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1860 error "set quota failed"
1862 quota_show_check b u $TSTUSR
1864 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1865 lustre_fail mds 0xa04 $err_code
1867 # write in background
1868 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1872 # write should be blocked and never finished
1873 if ! ps -p $DDPID > /dev/null 2>&1; then
1875 quota_error u $TSTUSR "write finished incorrectly!"
1883 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1885 if [ $count -gt $timeout ]; then
1886 quota_error u $TSTUSR "dd is not finished!"
1891 sync; sync_all_data || true
1893 USED=$(getquota -u $TSTUSR global curspace)
1894 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1895 "Used space(${USED}K) is less than ${BLKS}M"
1898 resetquota -u $TSTUSR
1901 # DQACQ return recoverable error
1903 echo "DQACQ return -ENOLCK"
1905 test_17sub 37 || error "Handle -ENOLCK failed"
1907 echo "DQACQ return -EAGAIN"
1909 test_17sub 11 || error "Handle -EAGAIN failed"
1911 echo "DQACQ return -ETIMEDOUT"
1912 #define ETIMEDOUT 110
1913 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1915 echo "DQACQ return -ENOTCONN"
1916 #define ENOTCONN 107
1917 test_17sub 107 || error "Handle -ENOTCONN failed"
1920 run_test 17 "DQACQ return recoverable error"
1924 local blimit="200m" # 200M
1925 local TESTFILE="$DIR/$tdir/$tfile"
1927 setup_quota_test || error "setup quota failed with $?"
1928 trap cleanup_quota_test EXIT
1930 set_ost_qtype "u" || error "enable ost quota failed"
1931 log "User quota (limit: $blimit)"
1932 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1933 error "set quota failed"
1934 quota_show_check b u $TSTUSR
1936 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1937 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1939 local timeout=$(sysctl -n lustre.timeout)
1941 if [ $io_type = "directio" ]; then
1942 log "Write 100M (directio) ..."
1943 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1945 log "Write 100M (buffered) ..."
1946 $RUNAS $DD of=$TESTFILE count=100 &
1950 replay_barrier $SINGLEMDS
1951 log "Fail mds for $((2 * timeout)) seconds"
1952 fail $SINGLEMDS $((2 * timeout))
1955 if at_is_enabled; then
1956 timeout=$(at_max_get mds)
1958 timeout=$(lctl get_param -n timeout)
1962 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1963 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1964 log "it took $count second"
1969 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1971 cancel_lru_locks mdc
1972 cancel_lru_locks osc
1975 local testfile_size=$(stat -c %s $TESTFILE)
1976 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1977 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1978 "got ${testfile_size}. Verifying file failed!"
1981 resetquota -u $TSTUSR
1984 # test when mds does failover, the ost still could work well
1985 # this test shouldn't trigger watchdog b=14840
1987 # Clear dmesg so watchdog is not triggered by previous
1989 do_facet ost1 dmesg -c > /dev/null
1992 test_18_sub directio
1994 # check if watchdog is triggered
1995 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1996 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1997 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1998 [ -z "$watchdog" ] || error "$watchdog"
1999 rm -f $TMP/lustre-log-${TESTNAME}.log
2001 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2005 local TESTFILE=$DIR/$tdir/$tfile
2007 setup_quota_test || error "setup quota failed with $?"
2008 trap cleanup_quota_test EXIT
2010 set_ost_qtype $QTYPE || error "enable ost quota failed"
2012 # bind file to a single OST
2013 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2014 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2016 echo "Set user quota (limit: ${blimit}M)"
2017 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2018 error "set user quota failed"
2019 quota_show_check b u $TSTUSR
2020 echo "Update quota limits"
2021 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2022 error "set group quota failed"
2023 quota_show_check b u $TSTUSR
2025 # first wirte might be cached
2026 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2027 cancel_lru_locks osc
2029 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2030 quota_error u $TSTUSR "Write success, expect failure"
2034 resetquota -u $TSTUSR
2036 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2038 test_20() { # b15754
2039 local LSTR=(2g 1t 4k 3m) # limits strings
2041 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2044 resetquota -u $TSTUSR
2046 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2047 $MOUNT || error "could not set quota limits"
2048 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2049 --inode-softlimit ${LSTR[2]} \
2050 --inode-hardlimit ${LSTR[3]} \
2051 $MOUNT || error "could not set quota limits"
2053 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2054 error "bsoftlimit was not set properly"
2055 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2056 error "bhardlimit was not set properly"
2057 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2058 error "isoftlimit was not set properly"
2059 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2060 error "ihardlimit was not set properly"
2062 resetquota -u $TSTUSR
2064 run_test 20 "Test if setquota specifiers work properly (b15754)"
2071 local time=$(($(date +%s) + seconds))
2072 while [ $(date +%s) -lt $time ]; do
2073 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2077 # run for fixing bug16053, setquota shouldn't fail when writing and
2078 # deleting are happening
2080 local TESTFILE="$DIR/$tdir/$tfile"
2081 local BLIMIT=10 # 10G
2082 local ILIMIT=1000000
2084 setup_quota_test || error "setup quota failed with $?"
2085 trap cleanup_quota_test EXIT
2087 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2089 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2090 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2091 error "set user quota failed"
2092 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2093 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2094 error "set group quota failed"
2095 if is_project_quota_supported; then
2096 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2097 "project: $TSTPRJID"
2098 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2099 $MOUNT || error "set project quota failed"
2102 # repeat writing on a 1M file
2103 test_21_sub ${TESTFILE}_1 1 30 &
2105 # repeat writing on a 128M file
2106 test_21_sub ${TESTFILE}_2 128 30 &
2109 local time=$(($(date +%s) + 30))
2111 while [ $(date +%s) -lt $time ]; do
2112 log "Set quota for $i times"
2113 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2114 -I $((ILIMIT + i)) $MOUNT ||
2115 error "Set user quota failed"
2116 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2117 -I $((ILIMIT + i)) $MOUNT ||
2118 error "Set group quota failed"
2119 if is_project_quota_supported; then
2120 $LFS setquota -p $TSTPRJID -b 0 -B \
2121 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2122 error "Set project quota failed"
2130 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2132 if [ $count -gt 60 ]; then
2133 quota_error a $TSTUSR "dd should be finished!"
2137 echo "(dd_pid=$DDPID1, time=$count)successful"
2141 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2143 if [ $count -gt 60 ]; then
2144 quota_error a $TSTUSR "dd should be finished!"
2148 echo "(dd_pid=$DDPID2, time=$count)successful"
2151 resetquota -u $TSTUSR
2152 resetquota -g $TSTUSR
2153 resetquota -p $TSTPRJID
2155 run_test 21 "Setquota while writing & deleting (b16053)"
2157 # enable/disable quota enforcement permanently
2159 echo "Set both mdt & ost quota type as ug"
2161 is_project_quota_supported && qtype=$QTYPE
2162 set_mdt_qtype $qtype || error "enable mdt quota failed"
2163 set_ost_qtype $qtype || error "enable ost quota failed"
2166 stopall || error "failed to stopall (1)"
2170 echo "Verify if quota is enabled"
2171 local qtype1=$(mdt_quota_type)
2172 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2173 qtype=$(ost_quota_type)
2174 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2176 echo "Set both mdt & ost quota type as none"
2177 set_mdt_qtype "none" || error "disable mdt quota failed"
2178 set_ost_qtype "none" || error "disable ost quota failed"
2181 stopall || error "failed to stopall (2)"
2186 echo "Verify if quota is disabled"
2187 qtype=$(mdt_quota_type)
2188 [ $qtype != "none" ] && error "mdt quota setting is lost"
2189 qtype=$(ost_quota_type)
2190 [ $qtype != "none" ] && error "ost quota setting is lost"
2194 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2197 local TESTFILE="$DIR/$tdir/$tfile"
2200 setup_quota_test || error "setup quota failed with $?"
2201 trap cleanup_quota_test EXIT
2203 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2206 log "User quota (limit: $LIMIT MB)"
2207 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2208 error "set quota failed"
2209 quota_show_check b u $TSTUSR
2211 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2212 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2214 log "Step1: trigger EDQUOT with O_DIRECT"
2215 log "Write half of file"
2216 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2217 quota_error u $TSTUSR "(1) Write failure, expect success." \
2219 log "Write out of block quota ..."
2220 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2221 oflag=direct conv=notrunc &&
2222 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2226 log "Step2: rewrite should succeed"
2227 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2228 quota_error u $TSTUSR "(3) Write failure, expect success." \
2234 local OST0_UUID=$(ostuuid_from_index 0)
2235 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2236 [ $OST0_QUOTA_USED -ne 0 ] &&
2237 ($SHOW_QUOTA_USER; \
2238 quota_error u $TSTUSR "quota isn't released")
2240 resetquota -u $TSTUSR
2244 [ $(facet_fstype ost1) == "zfs" ] &&
2245 skip "Overwrite in place is not guaranteed to be " \
2246 "space neutral on ZFS"
2248 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2249 check_whether_skip && return 0
2250 log "run for 4MB test file"
2253 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2254 check_whether_skip && return 0
2255 log "run for 40MB test file"
2258 run_test 23 "Quota should be honored with directIO (b16125)"
2262 local TESTFILE="$DIR/$tdir/$tfile"
2264 setup_quota_test || error "setup quota failed with $?"
2265 trap cleanup_quota_test EXIT
2267 set_ost_qtype $QTYPE || error "enable ost quota failed"
2269 # bind file to a single OST
2270 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2271 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2273 echo "Set user quota (limit: ${blimit}M)"
2274 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2275 error "set quota failed"
2277 # overrun quota by root user
2278 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2279 error "write failure, expect success"
2280 cancel_lru_locks osc
2281 sync_all_data || true
2283 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2286 resetquota -u $TSTUSR
2288 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2290 test_27a() { # b19612
2291 $LFS quota $TSTUSR $DIR &&
2292 error "lfs succeeded with no type, but should have failed"
2293 $LFS setquota $TSTUSR $DIR &&
2294 error "lfs succeeded with no type, but should have failed"
2297 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2299 test_27b() { # b20200
2300 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2301 error "lfs setquota failed with uid argument"
2302 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2303 error "lfs stequota failed with gid argument"
2304 if is_project_quota_supported; then
2305 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2306 1000 $DIR || error \
2307 "lfs stequota failed with projid argument"
2309 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2310 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2311 if is_project_quota_supported; then
2312 $SHOW_QUOTA_PROJID ||
2313 error "lfs quota failed with projid argument"
2315 resetquota -u $TSTUSR
2316 resetquota -g $TSTUSR
2317 resetquota -p $TSTPRJID
2320 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2325 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2326 error "lfs setquota failed"
2328 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2329 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2330 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2331 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2333 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2334 error "lfs setquota for $TSTID failed"
2336 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2337 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2338 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2339 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2341 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2342 error "total allocated inode/block limit not printed"
2344 resetquota -u $TSTUSR
2346 run_test 27c "lfs quota should support human-readable output"
2353 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2354 error "set fraction block limit failed"
2355 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2356 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2357 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2358 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2360 resetquota -u $TSTUSR
2362 run_test 27d "lfs setquota should support fraction block limit"
2366 local TESTFILE="$DIR/$tdir/$tfile"
2369 setup_quota_test || error "setup quota failed with $?"
2370 trap cleanup_quota_test EXIT
2372 set_ost_qtype "u" || error "enable ost quota failed"
2374 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2375 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2377 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2378 $MAX_IQ_TIME $DIR || error "set grace time failed"
2379 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2380 error "set quota failed"
2381 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2382 cancel_lru_locks osc
2384 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2385 # over-quota flag has not yet settled since we do not trigger async
2386 # events based on grace time period expiration
2388 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2389 cancel_lru_locks osc
2390 # now over-quota flag should be settled and further writes should fail
2392 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2393 error "grace times were reset"
2396 resetquota -u $TSTUSR
2397 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2398 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2400 run_test 30 "Hard limit updates should not reset grace times"
2402 # basic usage tracking for user & group
2404 local INODES=10 # 10 files
2405 local BLK_CNT=2 # of 2M each
2406 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2408 setup_quota_test || error "setup quota failed with $?"
2409 trap cleanup_quota_test EXIT
2411 # make sure the system is clean
2412 local USED=$(getquota -u $TSTID global curspace)
2414 error "Used space ($USED) for user $TSTID isn't 0."
2415 USED=$(getquota -g $TSTID global curspace)
2417 error "Used space ($USED) for group $TSTID isn't 0."
2418 if is_project_quota_supported; then
2419 USED=$(getquota -p $TSTPRJID global curspace)
2420 [ $USED -ne 0 ] && error \
2421 "Used space ($USED) for project $TSTPRJID isn't 0."
2424 echo "Write files..."
2425 for i in $(seq 0 $INODES); do
2426 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2427 error "write failed"
2428 is_project_quota_supported &&
2429 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2430 echo "Iteration $i/$INODES completed"
2432 cancel_lru_locks osc
2434 echo "Wait for setattr on objects finished..."
2435 wait_delete_completed
2437 sync; sync_all_data || true
2439 echo "Verify disk usage after write"
2440 USED=$(getquota -u $TSTID global curspace)
2441 [ $USED -lt $TOTAL_BLKS ] &&
2442 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2443 USED=$(getquota -g $TSTID global curspace)
2444 [ $USED -lt $TOTAL_BLKS ] &&
2445 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2446 if is_project_quota_supported; then
2447 USED=$(getquota -p $TSTPRJID global curspace)
2448 [ $USED -lt $TOTAL_BLKS ] && error \
2449 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2452 echo "Verify inode usage after write"
2453 USED=$(getquota -u $TSTID global curinodes)
2454 [ $USED -lt $INODES ] &&
2455 error "Used inode for user $TSTID is $USED, expected $INODES"
2456 USED=$(getquota -g $TSTID global curinodes)
2457 [ $USED -lt $INODES ] &&
2458 error "Used inode for group $TSTID is $USED, expected $INODES"
2459 if is_project_quota_supported; then
2460 USED=$(getquota -p $TSTPRJID global curinodes)
2461 [ $USED -lt $INODES ] && error \
2462 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2467 echo "Verify disk usage after delete"
2468 USED=$(getquota -u $TSTID global curspace)
2469 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2470 USED=$(getquota -u $TSTID global curinodes)
2471 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2472 USED=$(getquota -g $TSTID global curspace)
2473 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2474 USED=$(getquota -g $TSTID global curinodes)
2475 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2476 if is_project_quota_supported; then
2477 USED=$(getquota -p $TSTPRJID global curspace)
2479 error "Used space for project $TSTPRJID isn't 0. $USED"
2480 USED=$(getquota -p $TSTPRJID global curinodes)
2482 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2485 run_test 33 "Basic usage tracking for user & group & project"
2487 # usage transfer test for user & group & project
2489 local BLK_CNT=2 # 2MB
2490 local project_supported="no"
2492 is_project_quota_supported && project_supported="yes"
2493 setup_quota_test || error "setup quota failed with $?"
2494 trap cleanup_quota_test EXIT
2496 # make sure the system is clean
2497 local USED=$(getquota -u $TSTID global curspace)
2498 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2499 USED=$(getquota -g $TSTID global curspace)
2500 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2502 local USED=$(getquota -u $TSTID2 global curspace)
2503 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2504 if [ $project_supported == "yes" ]; then
2505 USED=$(getquota -p $TSTPRJID global curspace)
2506 [ $USED -ne 0 ] && error \
2507 "Used space ($USED) for Project $TSTPRJID isn't 0."
2510 echo "Write file..."
2511 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2512 error "write failed"
2513 cancel_lru_locks osc
2514 sync; sync_all_data || true
2516 echo "chown the file to user $TSTID"
2517 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2519 echo "Wait for setattr on objects finished..."
2520 wait_delete_completed
2522 BLK_CNT=$((BLK_CNT * 1024))
2524 echo "Verify disk usage for user $TSTID"
2525 USED=$(getquota -u $TSTID global curspace)
2526 [ $USED -lt $BLK_CNT ] &&
2527 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2528 USED=$(getquota -u $TSTID global curinodes)
2530 error "Used inodes for user $TSTID is $USED, expected 1"
2532 echo "chgrp the file to group $TSTID"
2533 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2535 echo "Wait for setattr on objects finished..."
2536 wait_delete_completed
2538 echo "Verify disk usage for group $TSTID"
2539 USED=$(getquota -g $TSTID global curspace)
2540 [ $USED -ge $BLK_CNT ] ||
2541 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2542 USED=$(getquota -g $TSTID global curinodes)
2544 error "Used inodes for group $TSTID is $USED, expected 1"
2546 # chown won't change the ost object group. LU-4345 */
2547 echo "chown the file to user $TSTID2"
2548 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2550 echo "Wait for setattr on objects finished..."
2551 wait_delete_completed
2553 echo "change_project project id to $TSTPRJID"
2554 [ $project_supported == "yes" ] &&
2555 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2556 echo "Wait for setattr on objects finished..."
2557 wait_delete_completed
2559 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2560 USED=$(getquota -u $TSTID2 global curspace)
2561 [ $USED -lt $BLK_CNT ] &&
2562 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2563 USED=$(getquota -u $TSTID global curspace)
2565 error "Used space for user $TSTID is $USED, expected 0"
2566 USED=$(getquota -g $TSTID global curspace)
2567 [ $USED -lt $BLK_CNT ] &&
2568 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2569 if [ $project_supported == "yes" ]; then
2570 USED=$(getquota -p $TSTPRJID global curspace)
2571 [ $USED -lt $BLK_CNT ] && error \
2572 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2577 run_test 34 "Usage transfer for user & group & project"
2579 # usage is still accessible across restart
2581 local BLK_CNT=2 # 2 MB
2583 setup_quota_test || error "setup quota failed with $?"
2584 trap cleanup_quota_test EXIT
2586 echo "Write file..."
2587 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2588 error "write failed"
2589 is_project_quota_supported &&
2590 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2591 cancel_lru_locks osc
2593 echo "Wait for setattr on objects finished..."
2594 wait_delete_completed
2596 sync; sync_all_data || true
2598 echo "Save disk usage before restart"
2599 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2600 [ $ORIG_USR_SPACE -eq 0 ] &&
2601 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2602 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2603 [ $ORIG_USR_INODES -eq 0 ] &&
2604 error "Used inodes for user $TSTID is 0, expected 1"
2605 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2606 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2607 [ $ORIG_GRP_SPACE -eq 0 ] &&
2608 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2609 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2610 [ $ORIG_GRP_INODES -eq 0 ] &&
2611 error "Used inodes for group $TSTID is 0, expected 1"
2612 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2614 if is_project_quota_supported; then
2615 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2616 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2617 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2618 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2619 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2620 "Used inodes for project $TSTPRJID is 0, expected 1"
2621 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2629 echo "Verify disk usage after restart"
2630 local USED=$(getquota -u $TSTID global curspace)
2631 [ $USED -eq $ORIG_USR_SPACE ] ||
2632 error "Used space for user $TSTID changed from " \
2633 "$ORIG_USR_SPACE to $USED"
2634 USED=$(getquota -u $TSTID global curinodes)
2635 [ $USED -eq $ORIG_USR_INODES ] ||
2636 error "Used inodes for user $TSTID changed from " \
2637 "$ORIG_USR_INODES to $USED"
2638 USED=$(getquota -g $TSTID global curspace)
2639 [ $USED -eq $ORIG_GRP_SPACE ] ||
2640 error "Used space for group $TSTID changed from " \
2641 "$ORIG_GRP_SPACE to $USED"
2642 USED=$(getquota -g $TSTID global curinodes)
2643 [ $USED -eq $ORIG_GRP_INODES ] ||
2644 error "Used inodes for group $TSTID changed from " \
2645 "$ORIG_GRP_INODES to $USED"
2646 if [ $project_supported == "yes" ]; then
2647 USED=$(getquota -p $TSTPRJID global curinodes)
2648 [ $USED -eq $ORIG_PRJ_INODES ] ||
2649 error "Used inodes for project $TSTPRJID " \
2650 "changed from $ORIG_PRJ_INODES to $USED"
2651 USED=$(getquota -p $TSTPRJID global curspace)
2652 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2653 error "Used space for project $TSTPRJID "\
2654 "changed from $ORIG_PRJ_SPACE to $USED"
2657 # check if the vfs_dq_init() is called before writing
2658 echo "Append to the same file..."
2659 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2660 error "write failed"
2661 cancel_lru_locks osc
2662 sync; sync_all_data || true
2664 echo "Verify space usage is increased"
2665 USED=$(getquota -u $TSTID global curspace)
2666 [ $USED -gt $ORIG_USR_SPACE ] ||
2667 error "Used space for user $TSTID isn't increased" \
2668 "orig:$ORIG_USR_SPACE, now:$USED"
2669 USED=$(getquota -g $TSTID global curspace)
2670 [ $USED -gt $ORIG_GRP_SPACE ] ||
2671 error "Used space for group $TSTID isn't increased" \
2672 "orig:$ORIG_GRP_SPACE, now:$USED"
2673 if [ $project_supported == "yes" ]; then
2674 USED=$(getquota -p $TSTPRJID global curspace)
2675 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2676 error "Used space for project $TSTPRJID isn't " \
2677 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2682 run_test 35 "Usage is still accessible across reboot"
2684 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2687 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2688 skip "Old server doesn't have LU-5006 fix."
2690 setup_quota_test || error "setup quota failed with $?"
2691 trap cleanup_quota_test EXIT
2693 # make sure the system is clean
2694 local USED=$(getquota -u $TSTID global curspace)
2696 error "Used space ($USED) for user $TSTID isn't 0."
2698 # create file with MDS_OPEN_DELAY_CREATE flag
2699 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2700 error "Create file failed"
2702 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2703 oflag=sync || error "Write file failed"
2705 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2707 # wait for setattr on objects finished..."
2708 wait_delete_completed
2710 USED=$(getquota -u $TSTID global curspace)
2711 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2715 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2719 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2720 skip "Old server doesn't have LU-8801 fix."
2722 [ "$UID" != 0 ] && skip_env "must run as root" && return
2724 setup_quota_test || error "setup quota failed with $?"
2725 trap cleanup_quota_test EXIT
2727 # make sure the system is clean
2728 local USED=$(getquota -u $TSTID global curspace)
2730 error "Used space ($USED) for user $TSTID isn't 0."
2731 USED=$(getquota -u $TSTID2 global curspace)
2733 error "Used space ($USED) for user $TSTID2 isn't 0."
2735 local TESTFILE="$DIR/$tdir/$tfile"
2736 local file_cnt=10000
2738 # Generate id entries in accounting file
2739 echo "Create $file_cnt files..."
2740 for i in `seq $file_cnt`; do
2742 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2743 error "failed to chown $TESTFILE-$i"
2745 cancel_lru_locks osc
2746 sync; sync_all_data || true
2748 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2749 procf=${procf}.quota_slave.acct_user
2752 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2753 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2754 echo "Found $acct_cnt id entries"
2756 [ $file_cnt -eq $acct_cnt ] || {
2757 do_facet mds1 $LCTL get_param $procf
2758 error "skipped id entries"
2763 run_test 38 "Quota accounting iterator doesn't skip id entries"
2766 local TESTFILE="$DIR/$tdir/project"
2767 ! is_project_quota_supported &&
2768 skip "Project quota is not supported"
2770 setup_quota_test || error "setup quota failed with $?"
2773 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2774 [ $projectid -ne 0 ] &&
2775 error "Project id should be 0 not $projectid"
2776 change_project -p 1024 $TESTFILE
2777 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2778 [ $projectid -ne 1024 ] &&
2779 error "Project id should be 1024 not $projectid"
2781 stopall || error "failed to stopall (1)"
2784 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2785 [ $projectid -ne 1024 ] &&
2786 error "Project id should be 1024 not $projectid"
2790 run_test 39 "Project ID interface works correctly"
2793 ! is_project_quota_supported &&
2794 skip "Project quota is not supported"
2795 local dir1="$DIR/$tdir/dir1"
2796 local dir2="$DIR/$tdir/dir2"
2798 setup_quota_test || error "setup quota failed with $?"
2800 mkdir -p $dir1 $dir2
2801 change_project -sp 1 $dir1 && touch $dir1/1
2802 change_project -sp 2 $dir2
2804 ln $dir1/1 $dir2/1_link &&
2805 error "Hard link across different project quota should fail"
2810 run_test 40a "Hard link across different project ID"
2813 ! is_project_quota_supported &&
2814 skip "Project quota is not supported"
2815 local dir1="$DIR/$tdir/dir1"
2816 local dir2="$DIR/$tdir/dir2"
2818 setup_quota_test || error "setup quota failed with $?"
2819 mkdir -p $dir1 $dir2
2820 change_project -sp 1 $dir1 && touch $dir1/1
2821 change_project -sp 2 $dir2
2823 mv $dir1/1 $dir2/2 || error "mv failed $?"
2824 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2825 if [ "$projid" != "2" ]; then
2826 error "project id expected 2 not $projid"
2831 run_test 40b "Mv across different project ID"
2834 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2835 ! is_project_quota_supported &&
2836 skip "Project quota is not supported"
2838 setup_quota_test || error "setup quota failed with $?"
2839 local dir="$DIR/$tdir/dir"
2841 mkdir -p $dir && change_project -sp 1 $dir
2842 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2843 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2844 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2845 touch $dir/remote_dir/file
2846 #verify inherit works file for remote dir.
2847 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2848 [ "$projid" != "1" ] &&
2849 error "file under remote dir expected 1 not $projid"
2851 #Agent inode should be ignored for project quota
2852 USED=$(getquota -p 1 global curinodes)
2853 [ "$USED" != "3" ] &&
2854 error "file count expected 3 got $USED"
2860 run_test 40c "Remote child Dir inherit project quota properly"
2863 ! is_project_quota_supported &&
2864 skip "Project quota is not supported"
2866 setup_quota_test || error "setup quota failed with $?"
2867 local dir="$DIR/$tdir/dir"
2869 mkdir $dir && change_project -p 1 $dir
2870 count=$($LFS find --projid 1 $DIR | wc -l)
2871 [ "$count" != 1 ] && error "expected 1 but got $count"
2876 run_test 50 "Test if lfs find --projid works"
2879 ! is_project_quota_supported &&
2880 skip "Project quota is not supported"
2881 setup_quota_test || error "setup quota failed with $?"
2882 local dir="$DIR/$tdir/dir"
2884 mkdir $dir && change_project -sp 1 $dir
2885 local used=$(getquota -p 1 global curinodes)
2886 [ $used != "1" ] && error "expected 1 got $used"
2891 used=$(getquota -p 1 global curinodes)
2892 [ $used != "4" ] && error "expected 4 got $used"
2894 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2896 cp $DIR/$tdir/6 $dir/6
2897 used=$(getquota -p 1 global curinodes)
2898 [ $used != "5" ] && error "expected 5 got $used"
2901 mv $DIR/$tdir/6 $dir/7
2902 used=$(getquota -p 1 global curinodes)
2903 [ $used != "6" ] && error "expected 6 got $used"
2908 run_test 51 "Test project accounting with mv/cp"
2911 ! is_project_quota_supported &&
2912 skip "Project quota is not supported"
2913 setup_quota_test || error "setup quota failed with $?"
2914 local dir="$DIR/$tdir/dir"
2915 mkdir $dir && change_project -sp 1 $dir
2917 touch $DIR/$tdir/file
2918 #Try renaming a file into the project. This should fail.
2919 for num in $(seq 1 2000); do
2920 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2921 error "rename should fail"
2926 run_test 52 "Rename across different project ID"
2929 ! is_project_quota_supported &&
2930 skip "Project quota is not supported"
2931 setup_quota_test || error "setup quota failed with $?"
2932 local dir="$DIR/$tdir/dir"
2933 mkdir $dir && change_project -s $dir
2934 lfs project -d $dir | grep P || error "inherit attribute should be set"
2936 change_project -C $dir
2937 lfs project -d $dir | grep P &&
2938 error "inherit attribute should be cleared"
2943 run_test 53 "Project inherit attribute could be cleared"
2946 ! is_project_quota_supported &&
2947 skip "Project quota is not supported"
2948 setup_quota_test || error "setup quota failed with $?"
2949 trap cleanup_quota_test EXIT
2950 local testfile="$DIR/$tdir/$tfile-0"
2952 #set project ID/inherit attribute
2953 change_project -sp $TSTPRJID $DIR/$tdir
2954 $RUNAS createmany -m ${testfile} 100 ||
2955 error "create many files failed"
2957 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2958 # one more count for directory itself */
2962 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2963 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2965 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2966 [ $proj_count1 -eq $proj_count ] ||
2967 error "c2: expected $proj_count got $proj_count1"
2969 #clear project but with kept projid
2970 change_project -rCk $DIR/$tdir
2971 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2972 [ $proj_count1 -eq $proj_count ] ||
2973 error "c3: expected $proj_count got $proj_count1"
2975 #verify projid untouched.
2976 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2978 [ $proj_count1 -eq $proj_count ] ||
2979 error "c4: expected $proj_count got $proj_count1"
2982 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2983 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2984 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2986 #this time clear all
2987 change_project -rC $DIR/$tdir
2988 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2989 [ $proj_count1 -eq 0 ] ||
2990 error "c6: expected 0 got $proj_count1"
2992 unlinkmany ${testfile} 100 ||
2993 error "unlink many files failed"
2997 run_test 54 "basic lfs project interface test"
3000 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3001 skip "Not supported before 2.10.58."
3002 setup_quota_test || error "setup quota failed with $?"
3004 set_ost_qtype $QTYPE || error "enable ost quota failed"
3007 #add second group to TSTUSR
3008 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3011 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3012 error "failed to dd"
3014 cancel_lru_locks osc
3015 sync; sync_all_data || true
3017 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3018 error "failed to setquota on group $TSTUSR2"
3020 $LFS quota -v -g $TSTUSR2 $DIR
3022 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3023 error "chgrp should failed with -EDQUOT"
3025 USED=$(getquota -g $TSTUSR2 global curspace)
3028 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3029 error "failed to setquota on group $TSTUSR2"
3031 $LFS quota -v -g $TSTUSR2 $DIR
3033 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3034 error "chgrp should succeed"
3036 $LFS quota -v -g $TSTUSR2 $DIR
3038 resetquota -g $TSTUSR2
3041 run_test 55 "Chgrp should be affected by group quota"
3044 setup_quota_test || error "setup quota failed with $?"
3046 set_ost_qtype $QTYPE || error "enable ost quota failed"
3049 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3050 erro "failed to set grace time for usr quota"
3051 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3052 awk '{print $4 $8}')
3053 if [ "x$grace_time" != "x10s;10s" ]; then
3054 $LFS quota -t -u $DIR
3055 error "expected grace time: 10s;10s, got:$grace_time"
3060 run_test 56 "lfs quota -t should work well"
3063 setup_quota_test || error "setup quota failed with $?"
3065 local dir="$DIR/$tdir/dir"
3068 #try to change pipe file should not hang and return failure
3069 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3070 awk -F ':' '{ print \\\$2 }'" \
3071 " failed to get xattr for '$dir/pipe'" || return 1
3072 #command can process further if it hit some errors
3073 touch $dir/aaa $dir/bbb
3074 #create one invalid link file
3075 ln -s $dir/not_exist_file $dir/ccc
3076 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3077 [ $cnt -eq 2 ] || error "expected 2 got $cnt"
3081 run_test 57 "lfs project could tolerate errors"
3084 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3085 skip "ldiskfs only test"
3086 disable_project_quota
3087 setup_quota_test || error "setup quota failed with $?"
3090 local testfile="$DIR/$tdir/$tfile-0"
3091 #make sure it did not crash kernel
3092 touch $testfile && lfs project -sp 1 $testfile
3094 enable_project_quota
3097 run_test 59 "lfs project dosen't crash kernel with project disabled"
3100 setup_quota_test || error "setup quota failed with $?"
3101 trap cleanup_quota_test EXIT
3102 local testfile=$DIR/$tdir/$tfile
3105 set_mdt_qtype "ug" || error "enable mdt quota failed"
3107 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3108 error "set quota failed"
3109 quota_show_check a g $TSTUSR
3111 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3112 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3113 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3114 error "create many files failed"
3116 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3118 # root user can overrun quota
3119 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3120 error "root user should succeed"
3123 resetquota -g $TSTUSR
3125 run_test 60 "Test quota for root with setgid"
3127 # test default quota
3128 test_default_quota() {
3129 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3130 skip "Not supported before 2.11.51."
3135 local qprjid=$TSTPRJID
3139 local LIMIT=20480 #20M disk space
3140 local TESTFILE="$DIR/$tdir/$tfile-0"
3142 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3143 echo "Project quota is not supported" && return 0
3145 [ $qtype == "-u" ] && qdtype="-U"
3146 [ $qtype == "-g" ] && qdtype="-G"
3147 [ $qtype == "-p" ] && {
3152 [ $qpool == "meta" ] && {
3153 LIMIT=10240 #10K inodes
3158 setup_quota_test || error "setup quota failed with $?"
3159 trap cleanup_quota_test EXIT
3163 # enable mdt/ost quota
3164 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3165 set_ost_qtype $QTYPE || error "enable ost quota failed"
3167 log "set to use default quota"
3168 $LFS setquota $qtype $qid -d $DIR ||
3169 error "set $qid to use default quota failed"
3171 log "set default quota"
3172 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3173 error "set $qid default quota failed"
3175 log "get default quota"
3176 $LFS quota $qdtype $DIR || error "get default quota failed"
3178 if [ $qpool == "data" ]; then
3179 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3181 [ $SLIMIT -eq $LIMIT ] ||
3182 error "the returned default quota is wrong"
3184 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3186 [ $SLIMIT -eq $LIMIT ] ||
3187 error "the returned default quota is wrong"
3190 # make sure the system is clean
3191 local USED=$(getquota $qtype $qid global curspace)
3192 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3194 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3195 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3197 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3199 log "Test not out of quota"
3200 if [ $qpool == "data" ]; then
3201 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3202 quota_error $qtype $qid "write failed, expect succeed"
3204 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3205 quota_error $qtype $qid "create failed, expect succeed"
3207 unlinkmany $TESTFILE $((LIMIT/2))
3210 log "Test out of quota"
3211 # flush cache, ensure noquota flag is set on client
3212 cancel_lru_locks osc
3213 cancel_lru_locks mdc
3214 sync; sync_all_data || true
3215 if [ $qpool == "data" ]; then
3216 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3217 quota_error $qtype $qid "write succeed, expect EDQUOT"
3219 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3220 quota_error $qtype $qid "create succeed, expect EDQUOT"
3222 unlinkmany $TESTFILE $((LIMIT*2))
3225 log "Increase default quota"
3226 # increase default quota
3227 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3228 error "set default quota failed"
3230 cancel_lru_locks osc
3231 cancel_lru_locks mdc
3232 sync; sync_all_data || true
3233 if [ $qpool == "data" ]; then
3234 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3235 quota_error $qtype $qid "write failed, expect succeed"
3237 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3238 quota_error $qtype $qid "create failed, expect succeed"
3240 unlinkmany $TESTFILE $((LIMIT*2))
3243 log "Set quota to override default quota"
3244 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3245 error "set $qid quota failed"
3247 cancel_lru_locks osc
3248 cancel_lru_locks mdc
3249 sync; sync_all_data || true
3250 if [ $qpool == "data" ]; then
3251 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3252 quota_error $qtype $qid "write succeed, expect EQUOT"
3254 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3255 quota_error $qtype $qid "create succeed, expect EQUOT"
3257 unlinkmany $TESTFILE $((LIMIT*2))
3260 log "Set to use default quota again"
3261 $LFS setquota $qtype $qid -d $DIR ||
3262 error "set $qid to use default quota failed"
3264 cancel_lru_locks osc
3265 cancel_lru_locks mdc
3266 sync; sync_all_data || true
3267 if [ $qpool == "data" ]; then
3268 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3269 quota_error $qtype $qid "write failed, expect succeed"
3271 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3272 quota_error $qtype $qid "create failed, expect succeed"
3274 unlinkmany $TESTFILE $((LIMIT*2))
3279 wait_delete_completed || error "wait_delete_completed failed"
3280 sync_all_data || true
3281 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3282 error "reset default quota failed"
3283 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3284 error "reset quota failed"
3290 test_default_quota "-u" "data"
3291 test_default_quota "-u" "meta"
3292 test_default_quota "-g" "data"
3293 test_default_quota "-g" "meta"
3294 test_default_quota "-p" "data"
3295 test_default_quota "-p" "meta"
3297 run_test 61 "default quota tests"
3300 ! is_project_quota_supported &&
3301 skip "Project quota is not supported"
3302 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3303 skip "chattr did not support project quota"
3304 setup_quota_test || error "setup quota failed with $?"
3305 local testdir=$DIR/$tdir/
3307 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3308 change_project -s $testdir
3309 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3310 error "inherit attribute should be set"
3311 # chattr used FS_IOC_SETFLAGS ioctl
3312 $RUNAS chattr -P $testdir &&
3313 error "regular user clear inherit should fail"
3314 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3315 error "inherit attribute should still be set"
3316 chattr -P $testdir || error "root failed to clear inherit"
3317 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3318 error "inherit attribute should be cleared"
3321 run_test 62 "Project inherit should be only changed by root"
3324 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3325 skip "Not supported before 2.11.55" && return
3329 local dd_failed=false
3330 local tdir_dom=${tdir}_dom
3331 local LIMIT=20480 #20M
3333 [ $qtype == "p" ] && ! is_project_quota_supported &&
3334 echo "Project quota is not supported" && return 0
3336 [ $qtype == "p" ] && qid=$TSTPRJID
3338 setup_quota_test || error "setup quota failed with $?"
3339 trap cleanup_quota_test EXIT
3343 # enable mdt/ost quota
3344 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3345 set_ost_qtype $QTYPE || error "enable ost quota failed"
3347 # make sure the system is clean
3348 local USED=$(getquota -$qtype $qid global curspace)
3349 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3351 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3353 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3354 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3355 error "setstripe $tdir_dom failed"
3356 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3358 [ $qtype == "p" ] && {
3359 change_project -sp $TSTPRJID $DIR/$tdir
3360 change_project -sp $TSTPRJID $DIR/$tdir_dom
3363 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3364 error "set $qid quota failed"
3366 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3367 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3371 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3373 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3374 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3378 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3380 rm -f $DIR/$tdir_dom/*
3382 # flush cache, ensure noquota flag is set on client
3383 cancel_lru_locks osc
3384 cancel_lru_locks mdc
3385 sync; sync_all_data || true
3389 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3390 quota_error $qtype $qid "write failed, expect succeed"
3392 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3393 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3397 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3400 rm -f $DIR/$tdir_dom/*
3402 # flush cache, ensure noquota flag is set on client
3403 cancel_lru_locks osc
3404 cancel_lru_locks mdc
3405 sync; sync_all_data || true
3409 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3410 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3414 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3416 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3417 quota_error $qtype $qid "write succeed, expect EDQUOT"
3420 rm -fr $DIR/$tdir_dom
3422 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3423 error "reset usr quota failed"
3433 run_test 63 "quota on DoM tests"
3437 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3438 disable_project_quota
3440 reset_quota_settings
3445 check_and_cleanup_lustre
3446 export QUOTA_AUTO=$QUOTA_AUTO_OLD