3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test: LU-6836
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4a"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 do_facet mds1 $ZPOOL upgrade -v |
89 grep project_quota && return 0
95 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
96 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
97 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
98 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
99 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
100 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
101 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
102 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
109 local fail_val=${3:-0}
113 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
114 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
115 ost) NODES="$(comma_list $(osts_nodes))";;
118 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
123 echo "lfs project $*"
124 lfs project $* || error "lfs project $* failed"
127 RUNAS="runas -u $TSTID -g $TSTID"
128 RUNAS2="runas -u $TSTID2 -g $TSTID2"
129 DD="dd if=/dev/zero bs=1M"
133 # clear quota limits for a user or a group
134 # usage: resetquota -u username
135 # resetquota -g groupname
136 # resetquota -p projid
139 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
140 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
141 error "resetquota: wrong specifier $1 passed"
143 if [ $1 == "-p" ]; then
144 is_project_quota_supported || return 0
147 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
148 error "clear quota for [type:$1 name:$2] failed"
149 # give a chance to slave to release space
157 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
158 $LFS quota -v -u $local_id $DIR
159 log "Files for user ($local_id):"
160 ($LFS find --user $local_id $DIR | head -n 4 |
161 xargs stat 2>/dev/null)
164 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
165 $LFS quota -v -g $local_id $DIR
166 log "Files for group ($local_id):"
167 ($LFS find --group $local_id $DIR | head -n 4 |
168 xargs stat 2>/dev/null)
171 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
172 $LFS quota -v -p $TSTPRJID $DIR
173 log "Files for project ($TSTPRJID):"
174 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
175 xargs stat 2>/dev/null)
191 # get quota for a user or a group
192 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
193 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
198 sync_all_data > /dev/null 2>&1 || true
200 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
201 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
202 error "getquota: wrong u/g/p specifier $1 passed"
215 *) error "unknown quota parameter $4";;
218 [ "$uuid" = "global" ] && uuid=$DIR
220 $LFS quota -v "$1" "$2" $DIR |
221 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
222 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
227 # usage: set_mdt_qtype ugp|u|g|p|none
231 local mdts=$(get_facets MDS)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD = *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
242 # we have to make sure each MDT received config changes
243 for mdt in ${mdts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $mdt); then
250 wait_update_facet $mdt "$cmd" "$qtype" || return 1
257 # usage: set_ost_qtype ugp|u|g|p|none
261 local osts=$(get_facets OST)
263 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
264 qtype=$(tr -d 'p' <<<$qtype)
266 if [[ $PERM_CMD = *"set_param -P"* ]]; then
267 do_facet mgs $PERM_CMD \
268 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
270 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
272 # we have to make sure each OST received config changes
273 for ost in ${osts//,/ }; do
275 cmd="$LCTL get_param -n "
276 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
277 cmd=${cmd}.quota_slave.enabled
279 if $(facet_up $ost); then
280 wait_update_facet $ost "$cmd" "$qtype" || return 1
286 wait_reintegration() {
290 local result="glb[1],slv[1],reint[0]"
295 if [ $ntype == "mdt" ]; then
296 tgts=$(get_facets MDS)
298 tgts=$(get_facets OST)
301 for tgt in ${tgts//,/ }; do
303 cmd="$LCTL get_param -n "
304 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
305 cmd=${cmd}.quota_slave.info
307 if $(facet_up $tgt); then
308 wait_update_facet $tgt "$cmd |
309 grep "$qtype" | awk '{ print \\\$3 }'" \
310 "$result" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "mdt" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "mdt" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "mdt" "project" $max || return 1
339 if [[ "$qtype" =~ "u" ]]; then
340 wait_reintegration "ost" "user" $max || return 1
343 if [[ "$qtype" =~ "g" ]]; then
344 wait_reintegration "ost" "group" $max || return 1
347 if [[ "$qtype" =~ "p" ]]; then
348 ! is_project_quota_supported && return 0
349 wait_reintegration "ost" "project" $max || return 1
354 disable_project_quota() {
355 is_project_quota_supported || return 0
356 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
357 stopall || error "failed to stopall (1)"
359 for num in $(seq $MDSCOUNT); do
360 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
361 error "tune2fs $(mdsdevname $num) failed"
364 for num in $(seq $OSTCOUNT); do
365 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
366 error "tune2fs $(ostdevname $num) failed"
374 wait_delete_completed
375 echo "Creating test directory"
376 mkdir $DIR/$tdir || return 1
377 chmod 0777 $DIR/$tdir || return 2
378 # always clear fail_loc in case of fail_loc isn't cleared
379 # properly when previous test failed
380 lustre_fail mds_ost 0
383 cleanup_quota_test() {
385 echo "Delete files..."
387 echo "Wait for unlink objects finished..."
388 wait_delete_completed
389 sync_all_data || true
398 $LFS quota -v -$ugp $qid $DIR
400 if [ "$bf" == "a" -o "$bf" == "b" ]; then
401 usage=$(getquota -$ugp $qid global curspace)
402 if [ -z $usage ]; then
403 quota_error $ugp $qid \
404 "Query block quota failed ($ugp:$qid)."
406 [ $usage -ne 0 ] && quota_log $ugp $qid \
407 "Block quota isn't 0 ($ugp:$qid:$usage)."
411 if [ "$bf" == "a" -o "$bf" == "f" ]; then
412 usage=$(getquota -$ugp $qid global curinodes)
413 if [ -z $usage ]; then
414 quota_error $ugp $qid \
415 "Query file quota failed ($ugp:$qid)."
417 [ $usage -ne 0 ] && quota_log $ugp $qid \
418 "File quota isn't 0 ($ugp:$qid:$usage)."
423 enable_project_quota() {
424 is_project_quota_supported || return 0
425 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
426 stopall || error "failed to stopall (1)"
428 for num in $(seq $MDSCOUNT); do
429 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
430 error "tune2fs $(mdsdevname $num) failed"
433 for num in $(seq $OSTCOUNT); do
434 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
435 error "tune2fs $(ostdevname $num) failed"
443 reset_quota_settings() {
444 resetquota -u $TSTUSR
445 resetquota -g $TSTUSR
446 resetquota -u $TSTUSR2
447 resetquota -g $TSTUSR2
448 resetquota -p $TSTPRJID
453 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
458 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
459 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
460 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
461 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
463 test_quota_performance() {
464 local TESTFILE="$DIR/$tdir/$tfile-0"
465 local size=$1 # in MB
466 local stime=$(date +%s)
467 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
468 quota_error u $TSTUSR "write failure"
469 local etime=$(date +%s)
470 delta=$((etime - stime))
471 if [ $delta -gt 0 ]; then
472 rate=$((size * 1024 / delta))
473 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
474 # LU-2872 - see LU-2887 for fix
476 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
478 [ $rate -gt 1024 ] ||
479 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
485 # test basic quota performance b=21696
488 [ "$SLOW" = "no" ] && MB=10
490 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
491 [ $free_space -le $((MB * 1024)) ] &&
492 skip "not enough space ${free_space} KB, " \
493 "required $((MB * 1024)) KB"
494 setup_quota_test || error "setup quota failed with $?"
495 trap cleanup_quota_test EXIT
497 set_ost_qtype "none" || error "disable ost quota failed"
498 test_quota_performance $MB
500 set_ost_qtype $QTYPE || error "enable ost quota failed"
501 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
502 error "set quota failed"
503 test_quota_performance $MB
506 resetquota -u $TSTUSR
508 run_test 0 "Test basic quota performance"
510 # test block hardlimit
513 local TESTFILE="$DIR/$tdir/$tfile-0"
515 setup_quota_test || error "setup quota failed with $?"
516 trap cleanup_quota_test EXIT
519 set_ost_qtype $QTYPE || error "enable ost quota failed"
522 log "User quota (block hardlimit:$LIMIT MB)"
523 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
524 error "set user quota failed"
526 # make sure the system is clean
527 local USED=$(getquota -u $TSTUSR global curspace)
528 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
530 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
531 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
534 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
535 quota_error u $TSTUSR "user write failure, but expect success"
536 log "Write out of block quota ..."
537 # this time maybe cache write, ignore it's failure
538 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
539 # flush cache, ensure noquota flag is set on client
541 sync; sync_all_data || true
542 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
543 quota_error u $TSTUSR "user write success, but expect EDQUOT"
546 wait_delete_completed || error "wait_delete_completed failed"
547 sync_all_data || true
548 USED=$(getquota -u $TSTUSR global curspace)
549 [ $USED -ne 0 ] && quota_error u $TSTUSR \
550 "user quota isn't released after deletion"
551 resetquota -u $TSTUSR
554 log "--------------------------------------"
555 log "Group quota (block hardlimit:$LIMIT MB)"
556 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
557 error "set group quota failed"
559 TESTFILE="$DIR/$tdir/$tfile-1"
560 # make sure the system is clean
561 USED=$(getquota -g $TSTUSR global curspace)
562 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
564 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
565 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
568 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
569 quota_error g $TSTUSR "Group write failure, but expect success"
570 log "Write out of block quota ..."
571 # this time maybe cache write, ignore it's failure
572 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
574 sync; sync_all_data || true
575 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
576 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
578 wait_delete_completed || error "wait_delete_completed failed"
579 sync_all_data || true
580 USED=$(getquota -g $TSTUSR global curspace)
581 [ $USED -ne 0 ] && quota_error g $TSTUSR \
582 "Group quota isn't released after deletion"
583 resetquota -g $TSTUSR
585 if ! is_project_quota_supported; then
586 echo "Project quota is not supported"
591 TESTFILE="$DIR/$tdir/$tfile-2"
592 # make sure the system is clean
593 USED=$(getquota -p $TSTPRJID global curspace)
595 error "used space($USED) for project $TSTPRJID isn't 0"
598 log "--------------------------------------"
599 log "Project quota (block hardlimit:$LIMIT mb)"
600 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
601 error "set project quota failed"
603 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
604 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
605 change_project -p $TSTPRJID $TESTFILE
608 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
609 "project write failure, but expect success"
610 log "write out of block quota ..."
611 # this time maybe cache write, ignore it's failure
612 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
614 sync; sync_all_data || true
615 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
616 $TSTPRJID "project write success, but expect EDQUOT"
621 USED=$(getquota -p $TSTPRJID global curspace)
622 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
623 "project quota isn't released after deletion"
625 resetquota -p $TSTPRJID
627 run_test 1 "Block hard limit (normal use and out of quota)"
629 # test inode hardlimit
631 local LIMIT=$((1024 * 1024)) # 1M inodes
632 local TESTFILE="$DIR/$tdir/$tfile-0"
634 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
636 local FREE_INODES=$(mdt_free_inodes 0)
637 echo "$FREE_INODES free inodes on master MDT"
638 [ $FREE_INODES -lt $LIMIT ] &&
639 skip "not enough free inodes $FREE_INODES required $LIMIT"
641 setup_quota_test || error "setup quota failed with $?"
642 trap cleanup_quota_test EXIT
645 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
648 log "User quota (inode hardlimit:$LIMIT files)"
649 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
650 error "set user quota failed"
652 # make sure the system is clean
653 local USED=$(getquota -u $TSTUSR global curinodes)
654 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
656 log "Create $LIMIT files ..."
657 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
658 quota_error u $TSTUSR "user create failure, but expect success"
659 log "Create out of file quota ..."
660 $RUNAS touch ${TESTFILE}_xxx &&
661 quota_error u $TSTUSR "user create success, but expect EDQUOT"
664 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
665 rm -f ${TESTFILE}_xxx
666 wait_delete_completed
668 USED=$(getquota -u $TSTUSR global curinodes)
669 [ $USED -ne 0 ] && quota_error u $TSTUSR \
670 "user quota isn't released after deletion"
671 resetquota -u $TSTUSR
674 log "--------------------------------------"
675 log "Group quota (inode hardlimit:$LIMIT files)"
676 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
677 error "set group quota failed"
679 TESTFILE=$DIR/$tdir/$tfile-1
680 # make sure the system is clean
681 USED=$(getquota -g $TSTUSR global curinodes)
682 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
684 log "Create $LIMIT files ..."
685 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
686 quota_error g $TSTUSR "group create failure, but expect success"
687 log "Create out of file quota ..."
688 $RUNAS touch ${TESTFILE}_xxx &&
689 quota_error g $TSTUSR "group create success, but expect EDQUOT"
692 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
693 rm -f ${TESTFILE}_xxx
694 wait_delete_completed
696 USED=$(getquota -g $TSTUSR global curinodes)
697 [ $USED -ne 0 ] && quota_error g $TSTUSR \
698 "user quota isn't released after deletion"
700 resetquota -g $TSTUSR
701 ! is_project_quota_supported && cleanup_quota_test &&
702 echo "Skip project quota is not supported" && return 0
705 log "--------------------------------------"
706 log "Project quota (inode hardlimit:$LIMIT files)"
707 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
708 error "set project quota failed"
710 TESTFILE=$DIR/$tdir/$tfile-1
711 # make sure the system is clean
712 USED=$(getquota -p $TSTPRJID global curinodes)
714 error "Used inodes($USED) for project $TSTPRJID isn't 0"
716 change_project -sp $TSTPRJID $DIR/$tdir
717 log "Create $LIMIT files ..."
718 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
719 $TSTPRJID "project create fail, but expect success"
720 log "Create out of file quota ..."
721 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
722 "project create success, but expect EDQUOT"
723 change_project -C $DIR/$tdir
726 USED=$(getquota -p $TSTPRJID global curinodes)
727 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
728 "project quota isn't released after deletion"
730 resetquota -p $TSTPRJID
733 run_test 2 "File hard limit (normal use and out of quota)"
737 local TIMER=$(($2 * 3 / 2))
743 trap cleanup_quota_test EXIT
745 $SETSTRIPE $TESTFILE -c 1 -i 0
746 chown $TSTUSR.$TSTUSR $TESTFILE
747 [ "$qtype" == "p" ] && is_project_quota_supported &&
748 change_project -p $TSTPRJID $TESTFILE
750 echo "Write up to soft limit"
751 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
752 quota_error a $TSTUSR "write failure, but expect success"
753 OFFSET=$((LIMIT * 1024))
756 echo "Write to exceed soft limit"
757 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
758 quota_error a $TSTUSR "write failure, but expect success"
759 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
765 $SHOW_QUOTA_INFO_USER
766 $SHOW_QUOTA_INFO_GROUP
767 $SHOW_QUOTA_INFO_PROJID
769 echo "Write before timer goes off"
770 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
771 quota_error a $TSTUSR "write failure, but expect success"
772 OFFSET=$((OFFSET + 1024))
775 echo "Sleep $TIMER seconds ..."
781 $SHOW_QUOTA_INFO_USER
782 $SHOW_QUOTA_INFO_GROUP
783 $SHOW_QUOTA_INFO_PROJID
785 echo "Write after timer goes off"
786 # maybe cache write, ignore.
787 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
788 OFFSET=$((OFFSET + 1024))
790 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
791 quota_error a $TSTUSR "write success, but expect EDQUOT"
796 $SHOW_QUOTA_INFO_USER
797 $SHOW_QUOTA_INFO_GROUP
798 $SHOW_QUOTA_INFO_PROJID
800 echo "Unlink file to stop timer"
802 wait_delete_completed
803 sync_all_data || true
808 $SHOW_QUOTA_INFO_USER
809 $SHOW_QUOTA_INFO_GROUP
810 $SHOW_QUOTA_INFO_PROJID
812 $SETSTRIPE $TESTFILE -c 1 -i 0
813 chown $TSTUSR.$TSTUSR $TESTFILE
814 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
817 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
818 quota_error a $TSTUSR "write failure, but expect success"
827 local TESTFILE=$DIR/$tdir/$tfile-0
829 set_ost_qtype $QTYPE || error "enable ost quota failed"
831 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
832 # make sure the system is clean
833 local USED=$(getquota -u $TSTUSR global curspace)
834 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
836 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
837 $MAX_IQ_TIME $DIR || error "set user grace time failed"
838 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
839 error "set user quota failed"
841 test_block_soft $TESTFILE $GRACE $LIMIT "u"
842 resetquota -u $TSTUSR
844 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
845 TESTFILE=$DIR/$tdir/$tfile-1
846 # make sure the system is clean
847 USED=$(getquota -g $TSTUSR global curspace)
848 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
850 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
851 $MAX_IQ_TIME $DIR || error "set group grace time failed"
852 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
853 error "set group quota failed"
855 test_block_soft $TESTFILE $GRACE $LIMIT "g"
856 resetquota -g $TSTUSR
858 if is_project_quota_supported; then
859 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
860 TESTFILE=$DIR/$tdir/$tfile-2
861 # make sure the system is clean
862 USED=$(getquota -p $TSTPRJID global curspace)
863 [ $USED -ne 0 ] && error \
864 "Used space($USED) for project $TSTPRJID isn't 0."
866 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
868 error "set project grace time failed"
869 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
870 $DIR || error "set project quota failed"
872 test_block_soft $TESTFILE $GRACE $LIMIT "p"
873 resetquota -p $TSTPRJID
874 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
876 error "restore project grace time failed"
880 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
881 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
882 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
883 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
885 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
891 local TIMER=$(($grace * 3 / 2))
894 trap cleanup_quota_test EXIT
895 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
897 echo "Create files to exceed soft limit"
898 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
899 quota_error a $TSTUSR "create failure, but expect success"
900 local trigger_time=$(date +%s)
902 sync_all_data || true
904 local cur_time=$(date +%s)
905 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
906 error "Passed grace time $grace, $trigger_time, $cur_time"
908 echo "Create file before timer goes off"
909 $RUNAS touch ${TESTFILE}_before ||
910 quota_error a $TSTUSR "failed create before timer expired," \
911 "but expect success. $trigger_time, $cur_time"
912 sync_all_data || true
914 echo "Sleep $TIMER seconds ..."
920 $SHOW_QUOTA_INFO_USER
921 $SHOW_QUOTA_INFO_GROUP
922 $SHOW_QUOTA_INFO_PROJID
924 echo "Create file after timer goes off"
925 # There is a window that space is accounted in the quota usage but
926 # hasn't been decreased from the pending write, if we acquire quota
927 # in this window, we'll acquire more than we needed.
928 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
929 sync_all_data || true
930 $RUNAS touch ${TESTFILE}_after_3 &&
931 quota_error a $TSTUSR "create after timer expired," \
933 sync_all_data || true
938 $SHOW_QUOTA_INFO_USER
939 $SHOW_QUOTA_INFO_GROUP
940 $SHOW_QUOTA_INFO_PROJID
942 echo "Unlink files to stop timer"
943 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
944 wait_delete_completed
947 $RUNAS touch ${TESTFILE}_xxx ||
948 quota_error a $TSTUSR "touch after timer stop failure," \
950 sync_all_data || true
958 local LIMIT=10 # inodes
959 local TESTFILE=$DIR/$tdir/$tfile-0
962 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
964 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
965 # make sure the system is clean
966 local USED=$(getquota -u $TSTUSR global curinodes)
967 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
969 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
970 $GRACE $DIR || error "set user grace time failed"
971 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
972 error "set user quota failed"
974 test_file_soft $TESTFILE $LIMIT $GRACE
975 resetquota -u $TSTUSR
977 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
978 # make sure the system is clean
979 USED=$(getquota -g $TSTUSR global curinodes)
980 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
982 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
983 $GRACE $DIR || error "set group grace time failed"
984 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
985 error "set group quota failed"
986 TESTFILE=$DIR/$tdir/$tfile-1
988 test_file_soft $TESTFILE $LIMIT $GRACE
989 resetquota -g $TSTUSR
991 if is_project_quota_supported; then
992 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
993 # make sure the system is clean
994 USED=$(getquota -p $TSTPRJID global curinodes)
995 [ $USED -ne 0 ] && error \
996 "Used space($USED) for project $TSTPRJID isn't 0."
998 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
999 $GRACE $DIR || error "set project grace time failed"
1000 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1001 error "set project quota failed"
1003 TESTFILE=$DIR/$tdir/$tfile-1
1004 # one less than limit, because of parent directory included.
1005 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1006 resetquota -p $TSTPRJID
1007 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1008 $MAX_IQ_TIME $DIR ||
1009 error "restore project grace time failed"
1013 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1014 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1015 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1016 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1018 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1021 local GR_STR1="1w3d"
1022 local GR_STR2="1000s"
1024 local GR_STR4="1w2d3h4m5s"
1026 local GR_STR6="18446744073709551615"
1029 wait_delete_completed
1031 # test of valid grace strings handling
1032 echo "Valid grace strings test"
1033 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1034 $GR_STR2 $DIR || error "set user grace time failed"
1035 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1036 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1037 $GR_STR4 $DIR || error "set group grace time quota failed"
1038 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1040 # test of invalid grace strings handling
1041 echo " Invalid grace strings test"
1042 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1043 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1044 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1048 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1049 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1050 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1051 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1053 run_test 4b "Grace time strings handling"
1055 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1057 local BLIMIT=10 # 10M
1058 local ILIMIT=10 # 10 inodes
1060 setup_quota_test || error "setup quota failed with $?"
1061 trap cleanup_quota_test EXIT
1063 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1064 set_ost_qtype $QTYPE || error "enable ost quota failed"
1066 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1067 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1068 error "set user quota failed"
1069 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1070 if is_project_quota_supported; then
1071 error "set group quota failed"
1072 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1073 -I $ILIMIT $DIR || error "set project quota failed"
1076 # make sure the system is clean
1077 local USED=$(getquota -u $TSTUSR global curinodes)
1078 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1079 USED=$(getquota -g $TSTUSR global curinodes)
1080 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1081 USED=$(getquota -u $TSTUSR global curspace)
1082 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1083 USED=$(getquota -g $TSTUSR global curspace)
1084 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1085 if is_project_quota_supported; then
1086 USED=$(getquota -p $TSTPRJID global curinodes)
1088 error "Used inode($USED) for project $TSTPRJID isn't 0."
1089 USED=$(getquota -p $TSTPRJID global curspace)
1091 error "Used block($USED) for project $TSTPRJID isn't 0."
1094 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1095 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1096 error "create failure, expect success"
1097 if is_project_quota_supported; then
1098 touch $DIR/$tdir/$tfile-0_1
1099 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1101 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1102 error "write failure, expect success"
1104 echo "Chown files to $TSTUSR.$TSTUSR ..."
1105 for i in $(seq 0 $ILIMIT); do
1106 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1107 quota_error a $TSTUSR "chown failure, expect success"
1111 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1112 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1115 resetquota -u $TSTUSR
1116 resetquota -g $TSTUSR
1117 resetquota -p $TSTPRJID
1119 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1121 # test dropping acquire request on master
1125 # Clear dmesg so watchdog is not triggered by previous
1127 do_facet ost1 dmesg -c > /dev/null
1129 setup_quota_test || error "setup quota failed with $?"
1130 trap cleanup_quota_test EXIT
1132 # make sure the system is clean
1133 local USED=$(getquota -u $TSTUSR global curspace)
1134 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1136 # make sure no granted quota on ost
1137 set_ost_qtype $QTYPE || error "enable ost quota failed"
1138 resetquota -u $TSTUSR
1140 # create file for $TSTUSR
1141 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1142 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1143 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1145 # create file for $TSTUSR2
1146 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1147 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1148 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1150 # cache per-ID lock for $TSTUSR on slave
1151 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1152 error "set quota failed"
1153 $RUNAS $DD of=$TESTFILE count=1 ||
1154 error "write $TESTFILE failure, expect success"
1155 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1156 error "write $TESTFILE2 failure, expect success"
1158 sync_all_data || true
1160 #define QUOTA_DQACQ 601
1161 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1162 lustre_fail mds 0x513 601
1164 do_facet ost1 $LCTL set_param \
1165 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1167 # write to un-enforced ID ($TSTUSR2) should succeed
1168 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1169 error "write failure, expect success"
1171 # write to enforced ID ($TSTUSR) in background, exceeding limit
1172 # to make sure DQACQ is sent
1173 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1176 # watchdog timer uses a factor of 2
1177 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1178 sleep $((TIMEOUT * 2 + 1))
1180 # write should be blocked and never finished
1181 if ! ps -p $DDPID > /dev/null 2>&1; then
1183 error "write finished incorrectly!"
1188 # no watchdog is triggered
1189 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1190 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1191 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1192 [ -z "$watchdog" ] || error "$watchdog"
1194 rm -f $TMP/lustre-log-${TESTNAME}.log
1196 # write should continue then fail with EDQUOT
1200 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1201 if [ $count -ge 240 ]; then
1202 quota_error u $TSTUSR "dd not finished in $count secs"
1204 count=$((count + 1))
1205 if [ $((count % 30)) -eq 0 ]; then
1206 c_size=$(stat -c %s $TESTFILE)
1207 echo "Waiting $count secs. $c_size"
1214 resetquota -u $TSTUSR
1216 run_test 6 "Test dropping acquire request on master"
1218 # quota reintegration (global index)
1220 local TESTFILE=$DIR/$tdir/$tfile
1221 local LIMIT=20 # 20M
1223 [ "$SLOW" = "no" ] && LIMIT=5
1225 setup_quota_test || error "setup quota failed with $?"
1226 trap cleanup_quota_test EXIT
1228 # make sure the system is clean
1229 local USED=$(getquota -u $TSTUSR global curspace)
1230 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1232 # make sure no granted quota on ost1
1233 set_ost_qtype $QTYPE || error "enable ost quota failed"
1234 resetquota -u $TSTUSR
1235 set_ost_qtype "none" || error "disable ost quota failed"
1237 local OSTUUID=$(ostuuid_from_index 0)
1238 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1240 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1243 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1244 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1249 echo "Enable quota & set quota limit for $TSTUSR"
1250 set_ost_qtype $QTYPE || error "enable ost quota failed"
1251 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1252 error "set quota failed"
1254 echo "Start ost1..."
1255 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1258 wait_ost_reint $QTYPE || error "reintegration failed"
1260 # hardlimit should have been fetched by slave during global
1261 # reintegration, write will exceed quota
1262 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1263 quota_error u $TSTUSR "write success, but expect EDQUOT"
1266 wait_delete_completed
1267 sync_all_data || true
1273 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1274 error "clear quota failed"
1276 echo "Start ost1..."
1277 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1280 wait_ost_reint $QTYPE || error "reintegration failed"
1282 # hardlimit should be cleared on slave during reintegration
1283 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1284 quota_error u $TSTUSR "write error, but expect success"
1287 resetquota -u $TSTUSR
1289 run_test 7a "Quota reintegration (global index)"
1291 # quota reintegration (slave index)
1294 local TESTFILE=$DIR/$tdir/$tfile
1296 setup_quota_test || error "setup quota failed with $?"
1297 trap cleanup_quota_test EXIT
1299 # make sure the system is clean
1300 local USED=$(getquota -u $TSTUSR global curspace)
1301 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1303 # make sure no granted quota on ost1
1304 set_ost_qtype $QTYPE || error "enable ost quota failed"
1305 resetquota -u $TSTUSR
1306 set_ost_qtype "none" || error "disable ost quota failed"
1308 local OSTUUID=$(ostuuid_from_index 0)
1309 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1311 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1314 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1315 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1317 # consume some space to make sure the granted space will not
1318 # be released during reconciliation
1319 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1320 error "consume space failure, expect success"
1322 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1323 lustre_fail mds 0xa02
1325 set_ost_qtype $QTYPE || error "enable ost quota failed"
1326 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1327 error "set quota failed"
1329 # ignore the write error
1330 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1332 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1336 echo "Restart ost to trigger reintegration..."
1338 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1341 wait_ost_reint $QTYPE || error "reintegration failed"
1343 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1344 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1347 resetquota -u $TSTUSR
1350 run_test 7b "Quota reintegration (slave index)"
1352 # quota reintegration (restart mds during reintegration)
1354 local LIMIT=20 # 20M
1355 local TESTFILE=$DIR/$tdir/$tfile
1357 [ "$SLOW" = "no" ] && LIMIT=5
1359 setup_quota_test || error "setup quota failed with $?"
1360 trap cleanup_quota_test EXIT
1362 # make sure the system is clean
1363 local USED=$(getquota -u $TSTUSR global curspace)
1364 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1366 set_ost_qtype "none" || error "disable ost quota failed"
1367 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1368 error "set quota failed"
1370 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1371 lustre_fail ost 0xa03
1374 set_ost_qtype $QTYPE || error "enable ost quota failed"
1375 # trigger reintegration
1376 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1377 procf=${procf}quota_slave.force_reint
1378 do_facet ost1 $LCTL set_param $procf=1 ||
1379 error "force reintegration failed"
1387 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1390 # wait longer than usual to make sure the reintegration
1391 # is triggered by quota wb thread.
1392 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1394 # hardlimit should have been fetched by slave during global
1395 # reintegration, write will exceed quota
1396 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1397 quota_error u $TSTUSR "write success, but expect EDQUOT"
1400 resetquota -u $TSTUSR
1402 run_test 7c "Quota reintegration (restart mds during reintegration)"
1404 # Quota reintegration (Transfer index in multiple bulks)
1406 local TESTFILE=$DIR/$tdir/$tfile
1407 local TESTFILE1="$DIR/$tdir/$tfile"-1
1410 setup_quota_test || error "setup quota failed with $?"
1411 trap cleanup_quota_test EXIT
1413 set_ost_qtype "none" || error "disable ost quota failed"
1414 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1415 error "set quota for $TSTUSR failed"
1416 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1417 error "set quota for $TSTUSR2 failed"
1419 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1420 lustre_fail mds 0x608 0
1422 # enable quota to tirgger reintegration
1423 set_ost_qtype "u" || error "enable ost quota failed"
1424 wait_ost_reint "u" || error "reintegration failed"
1428 # hardlimit should have been fetched by slave during global
1429 # reintegration, write will exceed quota
1430 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1431 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1433 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1434 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1437 resetquota -u $TSTUSR
1438 resetquota -u $TSTUSR2
1440 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1442 # quota reintegration (inode limits)
1444 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1446 # LU-2435: skip this quota test if underlying zfs version has not
1447 # supported native dnode accounting
1448 [ "$(facet_fstype mds1)" == "zfs" ] && {
1449 local F="feature@userobj_accounting"
1450 local pool=$(zpool_name mds1)
1451 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1453 [[ "$feature" != *" active "* ]] &&
1454 skip "requires zpool with active userobj_accounting"
1457 local ilimit=$((1024 * 2)) # 2k inodes
1458 local TESTFILE=$DIR/${tdir}-1/$tfile
1460 setup_quota_test || error "setup quota failed with $?"
1461 trap cleanup_quota_test EXIT
1463 # make sure the system is clean
1464 local USED=$(getquota -u $TSTUSR global curinodes)
1465 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1467 # make sure no granted quota on mdt1
1468 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1469 resetquota -u $TSTUSR
1470 set_mdt_qtype "none" || error "disable mdt quota failed"
1472 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1473 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1474 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1477 echo "Stop mds${MDSCOUNT}..."
1480 echo "Enable quota & set quota limit for $TSTUSR"
1481 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1482 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1483 error "set quota failed"
1485 echo "Start mds${MDSCOUNT}..."
1486 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1489 wait_mdt_reint $QTYPE || error "reintegration failed"
1491 echo "create remote dir"
1492 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1493 error "create remote dir failed"
1494 chmod 0777 $DIR/${tdir}-1
1496 # hardlimit should have been fetched by slave during global
1497 # reintegration, create will exceed quota
1498 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1499 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1501 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1502 wait_delete_completed
1503 sync_all_data || true
1505 echo "Stop mds${MDSCOUNT}..."
1508 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1509 error "clear quota failed"
1511 echo "Start mds${MDSCOUNT}..."
1512 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1515 wait_mdt_reint $QTYPE || error "reintegration failed"
1517 # hardlimit should be cleared on slave during reintegration
1518 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1519 quota_error u $TSTUSR "create failed, expect success"
1521 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1522 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1525 resetquota -u $TSTUSR
1527 run_test 7e "Quota reintegration (inode limits)"
1529 # run dbench with quota enabled
1531 local BLK_LIMIT="100g" #100G
1532 local FILE_LIMIT=1000000
1534 setup_quota_test || error "setup quota failed with $?"
1535 trap cleanup_quota_test EXIT
1537 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1538 set_ost_qtype $QTYPE || error "enable ost quota failed"
1540 echo "Set enough high limit for user: $TSTUSR"
1541 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1542 error "set user quota failed"
1543 echo "Set enough high limit for group: $TSTUSR"
1544 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1545 error "set group quota failed"
1546 if is_project_quota_supported; then
1547 change_project -sp $TSTPRJID $DIR/$tdir
1548 echo "Set enough high limit for project: $TSTPRJID"
1549 $LFS setquota -p $TSTPRJID -b 0 \
1550 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1551 error "set project quota failed"
1555 [ "$SLOW" = "no" ] && duration=" -t 120"
1556 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1557 quota_error a $TSTUSR "dbench failed!"
1559 is_project_quota_supported && change_project -C $DIR/$tdir
1561 resetquota -u $TSTUSR
1562 resetquota -g $TSTUSR
1563 resetquota -p $TSTPRJID
1565 run_test 8 "Run dbench with quota enabled"
1567 # this check is just for test_9
1568 OST0_MIN=4900000 #4.67G
1570 check_whether_skip () {
1571 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1572 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1573 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1574 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1581 # run for fixing bug10707, it needs a big room. test for 64bit
1583 local filesize=$((1024 * 9 / 2)) # 4.5G
1585 check_whether_skip && return 0
1587 setup_quota_test || error "setup quota failed with $?"
1588 trap cleanup_quota_test EXIT
1590 set_ost_qtype "ug" || error "enable ost quota failed"
1592 local TESTFILE="$DIR/$tdir/$tfile-0"
1593 local BLK_LIMIT=100G #100G
1594 local FILE_LIMIT=1000000
1596 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1598 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1600 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set user quota failed"
1603 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1604 "for group: $TSTUSR"
1605 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1606 error "set group quota failed"
1608 quota_show_check a u $TSTUSR
1609 quota_show_check a g $TSTUSR
1611 echo "Create test file"
1612 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1613 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1615 log "Write the big file of 4.5G ..."
1616 $RUNAS $DD of=$TESTFILE count=$filesize ||
1617 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1623 resetquota -u $TSTUSR
1624 resetquota -g $TSTUSR
1629 run_test 9 "Block limit larger than 4GB (b10707)"
1632 local TESTFILE=$DIR/$tdir/$tfile
1634 setup_quota_test || error "setup quota failed with $?"
1635 trap cleanup_quota_test EXIT
1637 # set limit to root user should fail
1638 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1639 error "set limit for root user successfully, expect failure"
1640 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1641 error "set limit for root group successfully, expect failure"
1642 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1643 error "set limit for project 0 successfully, expect failure"
1645 # root user can overrun quota
1646 set_ost_qtype "ug" || error "enable ost quota failed"
1648 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1649 error "set quota failed"
1650 quota_show_check b u $TSTUSR
1652 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1653 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1655 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1656 error "write failure, expect success"
1659 resetquota -u $TSTUSR
1661 run_test 10 "Test quota for root user"
1664 local TESTFILE=$DIR/$tdir/$tfile
1665 setup_quota_test || error "setup quota failed with $?"
1666 trap cleanup_quota_test EXIT
1668 set_mdt_qtype "ug" || error "enable mdt quota failed"
1669 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1670 error "set quota failed"
1672 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1673 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1675 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1676 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1679 local USED=$(getquota -u $TSTUSR global curinodes)
1680 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1683 resetquota -u $TSTUSR
1685 run_test 11 "Chown/chgrp ignores quota"
1688 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1690 local blimit=22 # 22M
1691 local blk_cnt=$((blimit - 5))
1692 local TESTFILE0="$DIR/$tdir/$tfile"-0
1693 local TESTFILE1="$DIR/$tdir/$tfile"-1
1695 setup_quota_test || error "setup quota failed with $?"
1696 trap cleanup_quota_test EXIT
1698 set_ost_qtype "u" || error "enable ost quota failed"
1699 quota_show_check b u $TSTUSR
1701 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1702 error "set quota failed"
1704 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1705 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1706 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1707 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1709 echo "Write to ost0..."
1710 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1711 quota_error a $TSTUSR "dd failed"
1713 echo "Write to ost1..."
1714 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1715 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1717 echo "Free space from ost0..."
1719 wait_delete_completed
1720 sync_all_data || true
1722 echo "Write to ost1 after space freed from ost0..."
1723 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1724 quota_error a $TSTUSR "rebalancing failed"
1727 resetquota -u $TSTUSR
1729 run_test 12a "Block quota rebalancing"
1732 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1734 local ilimit=$((1024 * 2)) # 2k inodes
1735 local TESTFILE0=$DIR/$tdir/$tfile
1736 local TESTFILE1=$DIR/${tdir}-1/$tfile
1738 setup_quota_test || error "setup quota failed with $?"
1739 trap cleanup_quota_test EXIT
1741 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1742 chmod 0777 $DIR/${tdir}-1
1744 set_mdt_qtype "u" || error "enable mdt quota failed"
1745 quota_show_check f u $TSTUSR
1747 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1748 error "set quota failed"
1750 echo "Create $ilimit files on mdt0..."
1751 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1752 quota_error u $TSTUSR "create failed, but expect success"
1754 echo "Create files on mdt1..."
1755 $RUNAS createmany -m $TESTFILE1 1 &&
1756 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1758 echo "Free space from mdt0..."
1759 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1760 wait_delete_completed
1761 sync_all_data || true
1763 echo "Create files on mdt1 after space freed from mdt0..."
1764 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1765 quota_error a $TSTUSR "rebalancing failed"
1767 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1768 error "unlink mdt1 files failed"
1769 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1772 resetquota -u $TSTUSR
1774 run_test 12b "Inode quota rebalancing"
1777 local TESTFILE=$DIR/$tdir/$tfile
1778 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1779 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1781 setup_quota_test || error "setup quota failed with $?"
1782 trap cleanup_quota_test EXIT
1784 set_ost_qtype "u" || error "enable ost quota failed"
1785 quota_show_check b u $TSTUSR
1787 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1788 error "set quota failed"
1789 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1790 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1792 # clear the locks in cache first
1793 do_facet ost1 $LCTL set_param -n $procf=clear
1794 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1795 [ $nlock -eq 0 ] || error "$nlock cached locks"
1797 # write to acquire the per-ID lock
1798 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1799 quota_error a $TSTUSR "dd failed"
1801 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1802 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1804 # clear quota doesn't trigger per-ID lock cancellation
1805 resetquota -u $TSTUSR
1806 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1807 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1809 # clear the per-ID lock
1810 do_facet ost1 $LCTL set_param -n $procf=clear
1811 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1812 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1814 # spare quota should be released
1815 local OSTUUID=$(ostuuid_from_index 0)
1816 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1817 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1818 [ $limit -le $space ] ||
1819 error "spare quota isn't released, limit:$limit, space:$space"
1823 run_test 13 "Cancel per-ID lock in the LRU list"
1826 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1828 wait_delete_completed
1829 sync_all_data || true
1832 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1833 error "set user quota failed"
1834 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1835 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1836 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1837 resetquota -u $TSTUSR
1840 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1841 error "set group quota failed"
1842 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1843 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1844 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1845 resetquota -g $TSTUSR
1847 run_test 15 "Set over 4T block quota"
1851 local BLKS=1 # 1M less than limit
1852 local TESTFILE=$DIR/$tdir/$tfile
1854 setup_quota_test || error "setup quota failed with $?"
1855 trap cleanup_quota_test EXIT
1857 # make sure the system is clean
1858 local USED=$(getquota -u $TSTUSR global curspace)
1859 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1861 set_ost_qtype "ug" || error "enable ost quota failed"
1862 # make sure no granted quota on ost
1863 resetquota -u $TSTUSR
1864 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1865 error "set quota failed"
1867 quota_show_check b u $TSTUSR
1869 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1870 lustre_fail mds 0xa04 $err_code
1872 # write in background
1873 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1877 # write should be blocked and never finished
1878 if ! ps -p $DDPID > /dev/null 2>&1; then
1880 quota_error u $TSTUSR "write finished incorrectly!"
1888 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1890 if [ $count -gt $timeout ]; then
1891 quota_error u $TSTUSR "dd is not finished!"
1896 sync; sync_all_data || true
1898 USED=$(getquota -u $TSTUSR global curspace)
1899 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1900 "Used space(${USED}K) is less than ${BLKS}M"
1903 resetquota -u $TSTUSR
1906 # DQACQ return recoverable error
1908 echo "DQACQ return -ENOLCK"
1910 test_17sub 37 || error "Handle -ENOLCK failed"
1912 echo "DQACQ return -EAGAIN"
1914 test_17sub 11 || error "Handle -EAGAIN failed"
1916 echo "DQACQ return -ETIMEDOUT"
1917 #define ETIMEDOUT 110
1918 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1920 echo "DQACQ return -ENOTCONN"
1921 #define ENOTCONN 107
1922 test_17sub 107 || error "Handle -ENOTCONN failed"
1925 run_test 17 "DQACQ return recoverable error"
1929 local blimit="200m" # 200M
1930 local TESTFILE="$DIR/$tdir/$tfile"
1932 setup_quota_test || error "setup quota failed with $?"
1933 trap cleanup_quota_test EXIT
1935 set_ost_qtype "u" || error "enable ost quota failed"
1936 log "User quota (limit: $blimit)"
1937 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1938 error "set quota failed"
1939 quota_show_check b u $TSTUSR
1941 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1942 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1944 local timeout=$(sysctl -n lustre.timeout)
1946 if [ $io_type = "directio" ]; then
1947 log "Write 100M (directio) ..."
1948 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1950 log "Write 100M (buffered) ..."
1951 $RUNAS $DD of=$TESTFILE count=100 &
1955 replay_barrier $SINGLEMDS
1956 log "Fail mds for $((2 * timeout)) seconds"
1957 fail $SINGLEMDS $((2 * timeout))
1960 if at_is_enabled; then
1961 timeout=$(at_max_get mds)
1963 timeout=$(lctl get_param -n timeout)
1967 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1968 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1969 log "it took $count second"
1974 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1976 cancel_lru_locks mdc
1977 cancel_lru_locks osc
1980 local testfile_size=$(stat -c %s $TESTFILE)
1981 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1982 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1983 "got ${testfile_size}. Verifying file failed!"
1986 resetquota -u $TSTUSR
1989 # test when mds does failover, the ost still could work well
1990 # this test shouldn't trigger watchdog b=14840
1992 # Clear dmesg so watchdog is not triggered by previous
1994 do_facet ost1 dmesg -c > /dev/null
1997 test_18_sub directio
1999 # check if watchdog is triggered
2000 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2001 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2002 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2003 [ -z "$watchdog" ] || error "$watchdog"
2004 rm -f $TMP/lustre-log-${TESTNAME}.log
2006 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2010 local TESTFILE=$DIR/$tdir/$tfile
2012 setup_quota_test || error "setup quota failed with $?"
2013 trap cleanup_quota_test EXIT
2015 set_ost_qtype $QTYPE || error "enable ost quota failed"
2017 # bind file to a single OST
2018 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2019 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2021 echo "Set user quota (limit: ${blimit}M)"
2022 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2023 error "set user quota failed"
2024 quota_show_check b u $TSTUSR
2025 echo "Update quota limits"
2026 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2027 error "set group quota failed"
2028 quota_show_check b u $TSTUSR
2030 # first wirte might be cached
2031 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2032 cancel_lru_locks osc
2034 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2035 quota_error u $TSTUSR "Write success, expect failure"
2039 resetquota -u $TSTUSR
2041 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2043 test_20() { # b15754
2044 local LSTR=(2g 1t 4k 3m) # limits strings
2046 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2049 resetquota -u $TSTUSR
2051 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2052 $MOUNT || error "could not set quota limits"
2053 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2054 --inode-softlimit ${LSTR[2]} \
2055 --inode-hardlimit ${LSTR[3]} \
2056 $MOUNT || error "could not set quota limits"
2058 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2059 error "bsoftlimit was not set properly"
2060 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2061 error "bhardlimit was not set properly"
2062 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2063 error "isoftlimit was not set properly"
2064 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2065 error "ihardlimit was not set properly"
2067 resetquota -u $TSTUSR
2069 run_test 20 "Test if setquota specifiers work properly (b15754)"
2076 local time=$(($(date +%s) + seconds))
2077 while [ $(date +%s) -lt $time ]; do
2078 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2082 # run for fixing bug16053, setquota shouldn't fail when writing and
2083 # deleting are happening
2085 local TESTFILE="$DIR/$tdir/$tfile"
2086 local BLIMIT=10 # 10G
2087 local ILIMIT=1000000
2089 setup_quota_test || error "setup quota failed with $?"
2090 trap cleanup_quota_test EXIT
2092 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2094 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2095 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2096 error "set user quota failed"
2097 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2098 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2099 error "set group quota failed"
2100 if is_project_quota_supported; then
2101 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2102 "project: $TSTPRJID"
2103 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2104 $MOUNT || error "set project quota failed"
2107 # repeat writing on a 1M file
2108 test_21_sub ${TESTFILE}_1 1 30 &
2110 # repeat writing on a 128M file
2111 test_21_sub ${TESTFILE}_2 128 30 &
2114 local time=$(($(date +%s) + 30))
2116 while [ $(date +%s) -lt $time ]; do
2117 log "Set quota for $i times"
2118 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2119 -I $((ILIMIT + i)) $MOUNT ||
2120 error "Set user quota failed"
2121 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2122 -I $((ILIMIT + i)) $MOUNT ||
2123 error "Set group quota failed"
2124 if is_project_quota_supported; then
2125 $LFS setquota -p $TSTPRJID -b 0 -B \
2126 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2127 error "Set project quota failed"
2135 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2137 if [ $count -gt 60 ]; then
2138 quota_error a $TSTUSR "dd should be finished!"
2142 echo "(dd_pid=$DDPID1, time=$count)successful"
2146 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2148 if [ $count -gt 60 ]; then
2149 quota_error a $TSTUSR "dd should be finished!"
2153 echo "(dd_pid=$DDPID2, time=$count)successful"
2156 resetquota -u $TSTUSR
2157 resetquota -g $TSTUSR
2158 resetquota -p $TSTPRJID
2160 run_test 21 "Setquota while writing & deleting (b16053)"
2162 # enable/disable quota enforcement permanently
2164 echo "Set both mdt & ost quota type as ug"
2166 is_project_quota_supported && qtype=$QTYPE
2167 set_mdt_qtype $qtype || error "enable mdt quota failed"
2168 set_ost_qtype $qtype || error "enable ost quota failed"
2171 stopall || error "failed to stopall (1)"
2175 echo "Verify if quota is enabled"
2176 local qtype1=$(mdt_quota_type)
2177 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2178 qtype=$(ost_quota_type)
2179 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2181 echo "Set both mdt & ost quota type as none"
2182 set_mdt_qtype "none" || error "disable mdt quota failed"
2183 set_ost_qtype "none" || error "disable ost quota failed"
2186 stopall || error "failed to stopall (2)"
2191 echo "Verify if quota is disabled"
2192 qtype=$(mdt_quota_type)
2193 [ $qtype != "none" ] && error "mdt quota setting is lost"
2194 qtype=$(ost_quota_type)
2195 [ $qtype != "none" ] && error "ost quota setting is lost"
2199 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2202 local TESTFILE="$DIR/$tdir/$tfile"
2205 setup_quota_test || error "setup quota failed with $?"
2206 trap cleanup_quota_test EXIT
2208 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2211 log "User quota (limit: $LIMIT MB)"
2212 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2213 error "set quota failed"
2214 quota_show_check b u $TSTUSR
2216 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2217 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2219 log "Step1: trigger EDQUOT with O_DIRECT"
2220 log "Write half of file"
2221 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2222 quota_error u $TSTUSR "(1) Write failure, expect success." \
2224 log "Write out of block quota ..."
2225 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2226 oflag=direct conv=notrunc &&
2227 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2231 log "Step2: rewrite should succeed"
2232 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2233 quota_error u $TSTUSR "(3) Write failure, expect success." \
2239 local OST0_UUID=$(ostuuid_from_index 0)
2240 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2241 [ $OST0_QUOTA_USED -ne 0 ] &&
2242 ($SHOW_QUOTA_USER; \
2243 quota_error u $TSTUSR "quota isn't released")
2245 resetquota -u $TSTUSR
2249 [ $(facet_fstype ost1) == "zfs" ] &&
2250 skip "Overwrite in place is not guaranteed to be " \
2251 "space neutral on ZFS"
2253 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2254 check_whether_skip && return 0
2255 log "run for 4MB test file"
2258 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2259 check_whether_skip && return 0
2260 log "run for 40MB test file"
2263 run_test 23 "Quota should be honored with directIO (b16125)"
2267 local TESTFILE="$DIR/$tdir/$tfile"
2269 setup_quota_test || error "setup quota failed with $?"
2270 trap cleanup_quota_test EXIT
2272 set_ost_qtype $QTYPE || error "enable ost quota failed"
2274 # bind file to a single OST
2275 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2276 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2278 echo "Set user quota (limit: ${blimit}M)"
2279 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2280 error "set quota failed"
2282 # overrun quota by root user
2283 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2284 error "write failure, expect success"
2285 cancel_lru_locks osc
2286 sync_all_data || true
2288 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2291 resetquota -u $TSTUSR
2293 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2295 test_27a() { # b19612
2296 $LFS quota $TSTUSR $DIR &&
2297 error "lfs succeeded with no type, but should have failed"
2298 $LFS setquota $TSTUSR $DIR &&
2299 error "lfs succeeded with no type, but should have failed"
2302 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2304 test_27b() { # b20200
2305 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2306 error "lfs setquota failed with uid argument"
2307 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2308 error "lfs stequota failed with gid argument"
2309 if is_project_quota_supported; then
2310 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2311 1000 $DIR || error \
2312 "lfs stequota failed with projid argument"
2314 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2315 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2316 if is_project_quota_supported; then
2317 $SHOW_QUOTA_PROJID ||
2318 error "lfs quota failed with projid argument"
2320 resetquota -u $TSTUSR
2321 resetquota -g $TSTUSR
2322 resetquota -p $TSTPRJID
2325 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2330 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2331 error "lfs setquota failed"
2333 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2334 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2335 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2336 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2338 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2339 error "lfs setquota for $TSTID failed"
2341 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2342 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2343 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2344 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2346 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2347 error "total allocated inode/block limit not printed"
2349 resetquota -u $TSTUSR
2351 run_test 27c "lfs quota should support human-readable output"
2358 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2359 error "set fraction block limit failed"
2360 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2361 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2362 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2363 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2365 resetquota -u $TSTUSR
2367 run_test 27d "lfs setquota should support fraction block limit"
2371 local TESTFILE="$DIR/$tdir/$tfile"
2374 setup_quota_test || error "setup quota failed with $?"
2375 trap cleanup_quota_test EXIT
2377 set_ost_qtype "u" || error "enable ost quota failed"
2379 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2380 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2382 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2383 $MAX_IQ_TIME $DIR || error "set grace time failed"
2384 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2385 error "set quota failed"
2386 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2387 cancel_lru_locks osc
2389 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2390 # over-quota flag has not yet settled since we do not trigger async
2391 # events based on grace time period expiration
2393 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2394 cancel_lru_locks osc
2395 # now over-quota flag should be settled and further writes should fail
2397 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2398 error "grace times were reset"
2401 resetquota -u $TSTUSR
2402 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2403 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2405 run_test 30 "Hard limit updates should not reset grace times"
2407 # basic usage tracking for user & group
2409 local INODES=10 # 10 files
2410 local BLK_CNT=2 # of 2M each
2411 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2413 setup_quota_test || error "setup quota failed with $?"
2414 trap cleanup_quota_test EXIT
2416 # make sure the system is clean
2417 local USED=$(getquota -u $TSTID global curspace)
2419 error "Used space ($USED) for user $TSTID isn't 0."
2420 USED=$(getquota -g $TSTID global curspace)
2422 error "Used space ($USED) for group $TSTID isn't 0."
2423 if is_project_quota_supported; then
2424 USED=$(getquota -p $TSTPRJID global curspace)
2425 [ $USED -ne 0 ] && error \
2426 "Used space ($USED) for project $TSTPRJID isn't 0."
2429 echo "Write files..."
2430 for i in $(seq 0 $INODES); do
2431 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2432 error "write failed"
2433 is_project_quota_supported &&
2434 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2435 echo "Iteration $i/$INODES completed"
2437 cancel_lru_locks osc
2439 echo "Wait for setattr on objects finished..."
2440 wait_delete_completed
2442 sync; sync_all_data || true
2444 echo "Verify disk usage after write"
2445 USED=$(getquota -u $TSTID global curspace)
2446 [ $USED -lt $TOTAL_BLKS ] &&
2447 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2448 USED=$(getquota -g $TSTID global curspace)
2449 [ $USED -lt $TOTAL_BLKS ] &&
2450 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2451 if is_project_quota_supported; then
2452 USED=$(getquota -p $TSTPRJID global curspace)
2453 [ $USED -lt $TOTAL_BLKS ] && error \
2454 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2457 echo "Verify inode usage after write"
2458 USED=$(getquota -u $TSTID global curinodes)
2459 [ $USED -lt $INODES ] &&
2460 error "Used inode for user $TSTID is $USED, expected $INODES"
2461 USED=$(getquota -g $TSTID global curinodes)
2462 [ $USED -lt $INODES ] &&
2463 error "Used inode for group $TSTID is $USED, expected $INODES"
2464 if is_project_quota_supported; then
2465 USED=$(getquota -p $TSTPRJID global curinodes)
2466 [ $USED -lt $INODES ] && error \
2467 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2472 echo "Verify disk usage after delete"
2473 USED=$(getquota -u $TSTID global curspace)
2474 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2475 USED=$(getquota -u $TSTID global curinodes)
2476 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2477 USED=$(getquota -g $TSTID global curspace)
2478 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2479 USED=$(getquota -g $TSTID global curinodes)
2480 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2481 if is_project_quota_supported; then
2482 USED=$(getquota -p $TSTPRJID global curspace)
2484 error "Used space for project $TSTPRJID isn't 0. $USED"
2485 USED=$(getquota -p $TSTPRJID global curinodes)
2487 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2490 run_test 33 "Basic usage tracking for user & group & project"
2492 # usage transfer test for user & group & project
2494 local BLK_CNT=2 # 2MB
2495 local project_supported="no"
2497 is_project_quota_supported && project_supported="yes"
2498 setup_quota_test || error "setup quota failed with $?"
2499 trap cleanup_quota_test EXIT
2501 # make sure the system is clean
2502 local USED=$(getquota -u $TSTID global curspace)
2503 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2504 USED=$(getquota -g $TSTID global curspace)
2505 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2507 local USED=$(getquota -u $TSTID2 global curspace)
2508 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2509 if [ $project_supported == "yes" ]; then
2510 USED=$(getquota -p $TSTPRJID global curspace)
2511 [ $USED -ne 0 ] && error \
2512 "Used space ($USED) for Project $TSTPRJID isn't 0."
2515 echo "Write file..."
2516 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2517 error "write failed"
2518 cancel_lru_locks osc
2519 sync; sync_all_data || true
2521 echo "chown the file to user $TSTID"
2522 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2524 echo "Wait for setattr on objects finished..."
2525 wait_delete_completed
2527 BLK_CNT=$((BLK_CNT * 1024))
2529 echo "Verify disk usage for user $TSTID"
2530 USED=$(getquota -u $TSTID global curspace)
2531 [ $USED -lt $BLK_CNT ] &&
2532 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2533 USED=$(getquota -u $TSTID global curinodes)
2535 error "Used inodes for user $TSTID is $USED, expected 1"
2537 echo "chgrp the file to group $TSTID"
2538 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2540 echo "Wait for setattr on objects finished..."
2541 wait_delete_completed
2543 echo "Verify disk usage for group $TSTID"
2544 USED=$(getquota -g $TSTID global curspace)
2545 [ $USED -ge $BLK_CNT ] ||
2546 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2547 USED=$(getquota -g $TSTID global curinodes)
2549 error "Used inodes for group $TSTID is $USED, expected 1"
2551 # chown won't change the ost object group. LU-4345 */
2552 echo "chown the file to user $TSTID2"
2553 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2555 echo "Wait for setattr on objects finished..."
2556 wait_delete_completed
2558 echo "change_project project id to $TSTPRJID"
2559 [ $project_supported == "yes" ] &&
2560 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2561 echo "Wait for setattr on objects finished..."
2562 wait_delete_completed
2564 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2565 USED=$(getquota -u $TSTID2 global curspace)
2566 [ $USED -lt $BLK_CNT ] &&
2567 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2568 USED=$(getquota -u $TSTID global curspace)
2570 error "Used space for user $TSTID is $USED, expected 0"
2571 USED=$(getquota -g $TSTID global curspace)
2572 [ $USED -lt $BLK_CNT ] &&
2573 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2574 if [ $project_supported == "yes" ]; then
2575 USED=$(getquota -p $TSTPRJID global curspace)
2576 [ $USED -lt $BLK_CNT ] && error \
2577 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2582 run_test 34 "Usage transfer for user & group & project"
2584 # usage is still accessible across restart
2586 local BLK_CNT=2 # 2 MB
2588 setup_quota_test || error "setup quota failed with $?"
2589 trap cleanup_quota_test EXIT
2591 echo "Write file..."
2592 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2593 error "write failed"
2594 is_project_quota_supported &&
2595 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2596 cancel_lru_locks osc
2598 echo "Wait for setattr on objects finished..."
2599 wait_delete_completed
2601 sync; sync_all_data || true
2603 echo "Save disk usage before restart"
2604 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2605 [ $ORIG_USR_SPACE -eq 0 ] &&
2606 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2607 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2608 [ $ORIG_USR_INODES -eq 0 ] &&
2609 error "Used inodes for user $TSTID is 0, expected 1"
2610 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2611 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2612 [ $ORIG_GRP_SPACE -eq 0 ] &&
2613 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2614 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2615 [ $ORIG_GRP_INODES -eq 0 ] &&
2616 error "Used inodes for group $TSTID is 0, expected 1"
2617 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2619 if is_project_quota_supported; then
2620 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2621 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2622 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2623 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2624 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2625 "Used inodes for project $TSTPRJID is 0, expected 1"
2626 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2634 echo "Verify disk usage after restart"
2635 local USED=$(getquota -u $TSTID global curspace)
2636 [ $USED -eq $ORIG_USR_SPACE ] ||
2637 error "Used space for user $TSTID changed from " \
2638 "$ORIG_USR_SPACE to $USED"
2639 USED=$(getquota -u $TSTID global curinodes)
2640 [ $USED -eq $ORIG_USR_INODES ] ||
2641 error "Used inodes for user $TSTID changed from " \
2642 "$ORIG_USR_INODES to $USED"
2643 USED=$(getquota -g $TSTID global curspace)
2644 [ $USED -eq $ORIG_GRP_SPACE ] ||
2645 error "Used space for group $TSTID changed from " \
2646 "$ORIG_GRP_SPACE to $USED"
2647 USED=$(getquota -g $TSTID global curinodes)
2648 [ $USED -eq $ORIG_GRP_INODES ] ||
2649 error "Used inodes for group $TSTID changed from " \
2650 "$ORIG_GRP_INODES to $USED"
2651 if [ $project_supported == "yes" ]; then
2652 USED=$(getquota -p $TSTPRJID global curinodes)
2653 [ $USED -eq $ORIG_PRJ_INODES ] ||
2654 error "Used inodes for project $TSTPRJID " \
2655 "changed from $ORIG_PRJ_INODES to $USED"
2656 USED=$(getquota -p $TSTPRJID global curspace)
2657 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2658 error "Used space for project $TSTPRJID "\
2659 "changed from $ORIG_PRJ_SPACE to $USED"
2662 # check if the vfs_dq_init() is called before writing
2663 echo "Append to the same file..."
2664 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2665 error "write failed"
2666 cancel_lru_locks osc
2667 sync; sync_all_data || true
2669 echo "Verify space usage is increased"
2670 USED=$(getquota -u $TSTID global curspace)
2671 [ $USED -gt $ORIG_USR_SPACE ] ||
2672 error "Used space for user $TSTID isn't increased" \
2673 "orig:$ORIG_USR_SPACE, now:$USED"
2674 USED=$(getquota -g $TSTID global curspace)
2675 [ $USED -gt $ORIG_GRP_SPACE ] ||
2676 error "Used space for group $TSTID isn't increased" \
2677 "orig:$ORIG_GRP_SPACE, now:$USED"
2678 if [ $project_supported == "yes" ]; then
2679 USED=$(getquota -p $TSTPRJID global curspace)
2680 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2681 error "Used space for project $TSTPRJID isn't " \
2682 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2687 run_test 35 "Usage is still accessible across reboot"
2689 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2692 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2693 skip "Old server doesn't have LU-5006 fix."
2695 setup_quota_test || error "setup quota failed with $?"
2696 trap cleanup_quota_test EXIT
2698 # make sure the system is clean
2699 local USED=$(getquota -u $TSTID global curspace)
2701 error "Used space ($USED) for user $TSTID isn't 0."
2703 # create file with MDS_OPEN_DELAY_CREATE flag
2704 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2705 error "Create file failed"
2707 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2708 oflag=sync || error "Write file failed"
2710 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2712 # wait for setattr on objects finished..."
2713 wait_delete_completed
2715 USED=$(getquota -u $TSTID global curspace)
2716 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2720 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2724 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2725 skip "Old server doesn't have LU-8801 fix."
2727 [ "$UID" != 0 ] && skip_env "must run as root" && return
2729 setup_quota_test || error "setup quota failed with $?"
2730 trap cleanup_quota_test EXIT
2732 # make sure the system is clean
2733 local USED=$(getquota -u $TSTID global curspace)
2735 error "Used space ($USED) for user $TSTID isn't 0."
2736 USED=$(getquota -u $TSTID2 global curspace)
2738 error "Used space ($USED) for user $TSTID2 isn't 0."
2740 local TESTFILE="$DIR/$tdir/$tfile"
2741 local file_cnt=10000
2743 # Generate id entries in accounting file
2744 echo "Create $file_cnt files..."
2745 for i in `seq $file_cnt`; do
2747 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2748 error "failed to chown $TESTFILE-$i"
2750 cancel_lru_locks osc
2751 sync; sync_all_data || true
2753 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2754 procf=${procf}.quota_slave.acct_user
2757 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2758 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2759 echo "Found $acct_cnt id entries"
2761 [ $file_cnt -eq $acct_cnt ] || {
2762 do_facet mds1 $LCTL get_param $procf
2763 error "skipped id entries"
2768 run_test 38 "Quota accounting iterator doesn't skip id entries"
2771 local TESTFILE="$DIR/$tdir/project"
2772 ! is_project_quota_supported &&
2773 skip "Project quota is not supported"
2775 setup_quota_test || error "setup quota failed with $?"
2778 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2779 [ $projectid -ne 0 ] &&
2780 error "Project id should be 0 not $projectid"
2781 change_project -p 1024 $TESTFILE
2782 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2783 [ $projectid -ne 1024 ] &&
2784 error "Project id should be 1024 not $projectid"
2786 stopall || error "failed to stopall (1)"
2789 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2790 [ $projectid -ne 1024 ] &&
2791 error "Project id should be 1024 not $projectid"
2795 run_test 39 "Project ID interface works correctly"
2798 ! is_project_quota_supported &&
2799 skip "Project quota is not supported"
2800 local dir1="$DIR/$tdir/dir1"
2801 local dir2="$DIR/$tdir/dir2"
2803 setup_quota_test || error "setup quota failed with $?"
2805 mkdir -p $dir1 $dir2
2806 change_project -sp 1 $dir1 && touch $dir1/1
2807 change_project -sp 2 $dir2
2809 ln $dir1/1 $dir2/1_link &&
2810 error "Hard link across different project quota should fail"
2815 run_test 40a "Hard link across different project ID"
2818 ! is_project_quota_supported &&
2819 skip "Project quota is not supported"
2820 local dir1="$DIR/$tdir/dir1"
2821 local dir2="$DIR/$tdir/dir2"
2823 setup_quota_test || error "setup quota failed with $?"
2824 mkdir -p $dir1 $dir2
2825 change_project -sp 1 $dir1 && touch $dir1/1
2826 change_project -sp 2 $dir2
2828 mv $dir1/1 $dir2/2 || error "mv failed $?"
2829 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2830 if [ "$projid" != "2" ]; then
2831 error "project id expected 2 not $projid"
2836 run_test 40b "Mv across different project ID"
2839 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2840 ! is_project_quota_supported &&
2841 skip "Project quota is not supported"
2843 setup_quota_test || error "setup quota failed with $?"
2844 local dir="$DIR/$tdir/dir"
2846 mkdir -p $dir && change_project -sp 1 $dir
2847 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2848 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2849 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2850 touch $dir/remote_dir/file
2851 #verify inherit works file for remote dir.
2852 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2853 [ "$projid" != "1" ] &&
2854 error "file under remote dir expected 1 not $projid"
2856 #Agent inode should be ignored for project quota
2857 USED=$(getquota -p 1 global curinodes)
2858 [ "$USED" != "3" ] &&
2859 error "file count expected 3 got $USED"
2865 run_test 40c "Remote child Dir inherit project quota properly"
2868 ! is_project_quota_supported &&
2869 skip "Project quota is not supported"
2871 setup_quota_test || error "setup quota failed with $?"
2872 local dir1="$DIR/$tdir/dir1"
2873 local dir2="$DIR/$tdir/dir2"
2875 mkdir -p $dir1 && change_project -sp 1 $dir1
2876 mkdir -p $dir2 && change_project -sp 2 $dir2
2877 for num in $(seq 1 10); do
2878 touch $dir1/file_$num $dir2/file_$num
2879 ln -s $dir1/file_$num $dir1/file_$num"_link"
2880 ln -s $dir2/file_$num $dir2/file_$num"_link"
2883 count=$($LFS find --projid 1 $DIR | wc -l)
2884 [ "$count" != 21 ] && error "expected 21 but got $count"
2886 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2887 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2888 [ "$count" != 22 ] && error "expected 22 but got $count"
2893 run_test 50 "Test if lfs find --projid works"
2896 ! is_project_quota_supported &&
2897 skip "Project quota is not supported"
2898 setup_quota_test || error "setup quota failed with $?"
2899 local dir="$DIR/$tdir/dir"
2901 mkdir $dir && change_project -sp 1 $dir
2902 local used=$(getquota -p 1 global curinodes)
2903 [ $used != "1" ] && error "expected 1 got $used"
2908 used=$(getquota -p 1 global curinodes)
2909 [ $used != "4" ] && error "expected 4 got $used"
2911 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2913 cp $DIR/$tdir/6 $dir/6
2914 used=$(getquota -p 1 global curinodes)
2915 [ $used != "5" ] && error "expected 5 got $used"
2918 mv $DIR/$tdir/6 $dir/7
2919 used=$(getquota -p 1 global curinodes)
2920 [ $used != "6" ] && error "expected 6 got $used"
2925 run_test 51 "Test project accounting with mv/cp"
2928 ! is_project_quota_supported &&
2929 skip "Project quota is not supported"
2930 setup_quota_test || error "setup quota failed with $?"
2931 local dir="$DIR/$tdir/dir"
2932 mkdir $dir && change_project -sp 1 $dir
2934 touch $DIR/$tdir/file
2935 #Try renaming a file into the project. This should fail.
2936 for num in $(seq 1 2000); do
2937 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2938 error "rename should fail"
2943 run_test 52 "Rename across different project ID"
2946 ! is_project_quota_supported &&
2947 skip "Project quota is not supported"
2948 setup_quota_test || error "setup quota failed with $?"
2949 local dir="$DIR/$tdir/dir"
2950 mkdir $dir && change_project -s $dir
2951 lfs project -d $dir | grep P || error "inherit attribute should be set"
2953 change_project -C $dir
2954 lfs project -d $dir | grep P &&
2955 error "inherit attribute should be cleared"
2960 run_test 53 "Project inherit attribute could be cleared"
2963 ! is_project_quota_supported &&
2964 skip "Project quota is not supported"
2965 setup_quota_test || error "setup quota failed with $?"
2966 trap cleanup_quota_test EXIT
2967 local testfile="$DIR/$tdir/$tfile-0"
2969 #set project ID/inherit attribute
2970 change_project -sp $TSTPRJID $DIR/$tdir
2971 $RUNAS createmany -m ${testfile} 100 ||
2972 error "create many files failed"
2974 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2975 # one more count for directory itself */
2979 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2980 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2982 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2983 [ $proj_count1 -eq $proj_count ] ||
2984 error "c2: expected $proj_count got $proj_count1"
2986 #clear project but with kept projid
2987 change_project -rCk $DIR/$tdir
2988 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2989 [ $proj_count1 -eq $proj_count ] ||
2990 error "c3: expected $proj_count got $proj_count1"
2992 #verify projid untouched.
2993 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2995 [ $proj_count1 -eq $proj_count ] ||
2996 error "c4: expected $proj_count got $proj_count1"
2999 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
3000 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3001 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3003 #this time clear all
3004 change_project -rC $DIR/$tdir
3005 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3006 [ $proj_count1 -eq 0 ] ||
3007 error "c6: expected 0 got $proj_count1"
3009 unlinkmany ${testfile} 100 ||
3010 error "unlink many files failed"
3014 run_test 54 "basic lfs project interface test"
3017 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3018 skip "Not supported before 2.10.58."
3019 setup_quota_test || error "setup quota failed with $?"
3021 set_ost_qtype $QTYPE || error "enable ost quota failed"
3024 #add second group to TSTUSR
3025 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3028 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3029 error "failed to dd"
3031 cancel_lru_locks osc
3032 sync; sync_all_data || true
3034 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3035 error "failed to setquota on group $TSTUSR2"
3037 $LFS quota -v -g $TSTUSR2 $DIR
3039 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3040 error "chgrp should failed with -EDQUOT"
3042 USED=$(getquota -g $TSTUSR2 global curspace)
3045 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3046 error "failed to setquota on group $TSTUSR2"
3048 $LFS quota -v -g $TSTUSR2 $DIR
3050 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3051 error "chgrp should succeed"
3053 $LFS quota -v -g $TSTUSR2 $DIR
3055 resetquota -g $TSTUSR2
3058 run_test 55 "Chgrp should be affected by group quota"
3061 setup_quota_test || error "setup quota failed with $?"
3063 set_ost_qtype $QTYPE || error "enable ost quota failed"
3066 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3067 erro "failed to set grace time for usr quota"
3068 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3069 awk '{print $4 $8}')
3070 if [ "x$grace_time" != "x10s;10s" ]; then
3071 $LFS quota -t -u $DIR
3072 error "expected grace time: 10s;10s, got:$grace_time"
3077 run_test 56 "lfs quota -t should work well"
3080 setup_quota_test || error "setup quota failed with $?"
3082 local dir="$DIR/$tdir/dir"
3085 #try to change pipe file should not hang and return failure
3086 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3087 awk -F ':' '{ print \\\$2 }'" \
3088 " unable to get xattr for fifo '$dir/pipe'" || return 1
3089 #command can process further if it hit some errors
3090 touch $dir/aaa $dir/bbb
3091 mkdir $dir/subdir -p
3092 touch $dir/subdir/aaa $dir/subdir/bbb
3093 #create one invalid link file
3094 ln -s $dir/not_exist_file $dir/ccc
3095 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3096 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3100 run_test 57 "lfs project could tolerate errors"
3103 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3104 skip "ldiskfs only test"
3105 disable_project_quota
3106 setup_quota_test || error "setup quota failed with $?"
3109 local testfile="$DIR/$tdir/$tfile-0"
3110 #make sure it did not crash kernel
3111 touch $testfile && lfs project -sp 1 $testfile
3113 enable_project_quota
3116 run_test 59 "lfs project dosen't crash kernel with project disabled"
3119 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3120 skip "Needs MDS version 2.11.53 or later."
3121 setup_quota_test || error "setup quota failed with $?"
3122 trap cleanup_quota_test EXIT
3124 local testfile=$DIR/$tdir/$tfile
3127 set_mdt_qtype "ug" || error "enable mdt quota failed"
3129 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3130 error "set quota failed"
3131 quota_show_check a g $TSTUSR
3133 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3134 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3135 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3136 error "create many files failed"
3138 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3140 # root user can overrun quota
3141 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3142 error "root user should succeed"
3145 resetquota -g $TSTUSR
3147 run_test 60 "Test quota for root with setgid"
3149 # test default quota
3150 test_default_quota() {
3151 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3152 skip "Not supported before 2.11.51."
3157 local qprjid=$TSTPRJID
3161 local LIMIT=20480 #20M disk space
3162 local TESTFILE="$DIR/$tdir/$tfile-0"
3164 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3165 echo "Project quota is not supported" && return 0
3167 [ $qtype == "-u" ] && qdtype="-U"
3168 [ $qtype == "-g" ] && qdtype="-G"
3169 [ $qtype == "-p" ] && {
3174 [ $qpool == "meta" ] && {
3175 LIMIT=10240 #10K inodes
3180 setup_quota_test || error "setup quota failed with $?"
3181 trap cleanup_quota_test EXIT
3185 # enable mdt/ost quota
3186 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3187 set_ost_qtype $QTYPE || error "enable ost quota failed"
3189 log "set to use default quota"
3190 $LFS setquota $qtype $qid -d $DIR ||
3191 error "set $qid to use default quota failed"
3193 log "set default quota"
3194 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3195 error "set $qid default quota failed"
3197 log "get default quota"
3198 $LFS quota $qdtype $DIR || error "get default quota failed"
3200 if [ $qpool == "data" ]; then
3201 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3203 [ $SLIMIT -eq $LIMIT ] ||
3204 error "the returned default quota is wrong"
3206 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3208 [ $SLIMIT -eq $LIMIT ] ||
3209 error "the returned default quota is wrong"
3212 # make sure the system is clean
3213 local USED=$(getquota $qtype $qid global curspace)
3214 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3216 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3217 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3219 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3221 log "Test not out of quota"
3222 if [ $qpool == "data" ]; then
3223 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3224 quota_error $qtype $qid "write failed, expect succeed"
3226 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3227 quota_error $qtype $qid "create failed, expect succeed"
3229 unlinkmany $TESTFILE $((LIMIT/2))
3232 log "Test out of quota"
3233 # flush cache, ensure noquota flag is set on client
3234 cancel_lru_locks osc
3235 cancel_lru_locks mdc
3236 sync; sync_all_data || true
3237 if [ $qpool == "data" ]; then
3238 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3239 quota_error $qtype $qid "write succeed, expect EDQUOT"
3241 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3242 quota_error $qtype $qid "create succeed, expect EDQUOT"
3244 unlinkmany $TESTFILE $((LIMIT*2))
3247 log "Increase default quota"
3248 # increase default quota
3249 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3250 error "set default quota failed"
3252 cancel_lru_locks osc
3253 cancel_lru_locks mdc
3254 sync; sync_all_data || true
3255 if [ $qpool == "data" ]; then
3256 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3257 quota_error $qtype $qid "write failed, expect succeed"
3259 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3260 quota_error $qtype $qid "create failed, expect succeed"
3262 unlinkmany $TESTFILE $((LIMIT*2))
3265 log "Set quota to override default quota"
3266 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3267 error "set $qid quota failed"
3269 cancel_lru_locks osc
3270 cancel_lru_locks mdc
3271 sync; sync_all_data || true
3272 if [ $qpool == "data" ]; then
3273 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3274 quota_error $qtype $qid "write succeed, expect EQUOT"
3276 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3277 quota_error $qtype $qid "create succeed, expect EQUOT"
3279 unlinkmany $TESTFILE $((LIMIT*2))
3282 log "Set to use default quota again"
3283 $LFS setquota $qtype $qid -d $DIR ||
3284 error "set $qid to use default quota failed"
3286 cancel_lru_locks osc
3287 cancel_lru_locks mdc
3288 sync; sync_all_data || true
3289 if [ $qpool == "data" ]; then
3290 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3291 quota_error $qtype $qid "write failed, expect succeed"
3293 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3294 quota_error $qtype $qid "create failed, expect succeed"
3296 unlinkmany $TESTFILE $((LIMIT*2))
3301 wait_delete_completed || error "wait_delete_completed failed"
3302 sync_all_data || true
3303 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3304 error "reset default quota failed"
3305 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3306 error "reset quota failed"
3312 test_default_quota "-u" "data"
3313 test_default_quota "-u" "meta"
3314 test_default_quota "-g" "data"
3315 test_default_quota "-g" "meta"
3316 test_default_quota "-p" "data"
3317 test_default_quota "-p" "meta"
3319 run_test 61 "default quota tests"
3322 ! is_project_quota_supported &&
3323 skip "Project quota is not supported"
3324 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3325 skip "chattr did not support project quota"
3326 setup_quota_test || error "setup quota failed with $?"
3327 local testdir=$DIR/$tdir/
3329 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3330 change_project -s $testdir
3331 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3332 error "inherit attribute should be set"
3333 # chattr used FS_IOC_SETFLAGS ioctl
3334 $RUNAS chattr -P $testdir &&
3335 error "regular user clear inherit should fail"
3336 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3337 error "inherit attribute should still be set"
3338 chattr -P $testdir || error "root failed to clear inherit"
3339 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3340 error "inherit attribute should be cleared"
3343 run_test 62 "Project inherit should be only changed by root"
3346 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3347 skip "Not supported before 2.11.55" && return
3351 local dd_failed=false
3352 local tdir_dom=${tdir}_dom
3353 local LIMIT=20480 #20M
3355 [ $qtype == "p" ] && ! is_project_quota_supported &&
3356 echo "Project quota is not supported" && return 0
3358 [ $qtype == "p" ] && qid=$TSTPRJID
3360 setup_quota_test || error "setup quota failed with $?"
3361 trap cleanup_quota_test EXIT
3365 # enable mdt/ost quota
3366 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3367 set_ost_qtype $QTYPE || error "enable ost quota failed"
3369 # make sure the system is clean
3370 local USED=$(getquota -$qtype $qid global curspace)
3371 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3373 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3375 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3376 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3377 error "setstripe $tdir_dom failed"
3378 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3380 [ $qtype == "p" ] && {
3381 change_project -sp $TSTPRJID $DIR/$tdir
3382 change_project -sp $TSTPRJID $DIR/$tdir_dom
3385 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3386 error "set $qid quota failed"
3388 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3389 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3393 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3395 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3396 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3400 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3402 rm -f $DIR/$tdir_dom/*
3404 # flush cache, ensure noquota flag is set on client
3405 cancel_lru_locks osc
3406 cancel_lru_locks mdc
3407 sync; sync_all_data || true
3411 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3412 quota_error $qtype $qid "write failed, expect succeed"
3414 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3415 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3419 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3422 rm -f $DIR/$tdir_dom/*
3424 # flush cache, ensure noquota flag is set on client
3425 cancel_lru_locks osc
3426 cancel_lru_locks mdc
3427 sync; sync_all_data || true
3431 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3432 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3436 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3438 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3439 quota_error $qtype $qid "write succeed, expect EDQUOT"
3442 rm -fr $DIR/$tdir_dom
3444 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3445 error "reset usr quota failed"
3455 run_test 63 "quota on DoM tests"
3458 ! is_project_quota_supported &&
3459 skip "Project quota is not supported"
3460 setup_quota_test || error "setup quota failed with $?"
3461 local dir1="$DIR/$tdir/"
3464 ln -s $dir1/file $dir1/file_link
3466 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3467 error "set symlink file's project should fail"
3469 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3470 error "get symlink file's project should fail"
3474 run_test 64 "lfs project on symlink files should fail"
3478 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3479 disable_project_quota
3481 reset_quota_settings
3486 check_and_cleanup_lustre
3487 export QUOTA_AUTO=$QUOTA_AUTO_OLD