3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test: LU-6836
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4a"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 $ZPOOL upgrade -v | grep project_quota && return 0
94 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
95 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
96 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
97 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
98 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
99 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
100 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
101 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
108 local fail_val=${3:-0}
112 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
113 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
114 ost) NODES="$(comma_list $(osts_nodes))";;
117 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
122 echo "lfs project $*"
123 lfs project $* || error "lfs project $* failed"
126 RUNAS="runas -u $TSTID -g $TSTID"
127 RUNAS2="runas -u $TSTID2 -g $TSTID2"
128 DD="dd if=/dev/zero bs=1M"
132 # clear quota limits for a user or a group
133 # usage: resetquota -u username
134 # resetquota -g groupname
135 # resetquota -p projid
138 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
139 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
140 error "resetquota: wrong specifier $1 passed"
142 if [ $1 == "-p" ]; then
143 is_project_quota_supported || return 0
146 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
147 error "clear quota for [type:$1 name:$2] failed"
148 # give a chance to slave to release space
156 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
157 $LFS quota -v -u $local_id $DIR
158 log "Files for user ($local_id):"
159 ($LFS find --user $local_id $DIR | head -n 4 |
160 xargs stat 2>/dev/null)
163 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
164 $LFS quota -v -g $local_id $DIR
165 log "Files for group ($local_id):"
166 ($LFS find --group $local_id $DIR | head -n 4 |
167 xargs stat 2>/dev/null)
170 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
171 $LFS quota -v -p $TSTPRJID $DIR
172 log "Files for project ($TSTPRJID):"
173 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
174 xargs stat 2>/dev/null)
190 # get quota for a user or a group
191 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
192 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
197 sync_all_data > /dev/null 2>&1 || true
199 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
200 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
201 error "getquota: wrong u/g/p specifier $1 passed"
214 *) error "unknown quota parameter $4";;
217 [ "$uuid" = "global" ] && uuid=$DIR
219 $LFS quota -v "$1" "$2" $DIR |
220 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
221 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
226 # usage: set_mdt_qtype ugp|u|g|p|none
230 local mdts=$(get_facets MDS)
232 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
233 qtype=$(tr -d 'p' <<<$qtype)
235 if [[ $PERM_CMD = *"set_param -P"* ]]; then
236 do_facet mgs $PERM_CMD \
237 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
239 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
241 # we have to make sure each MDT received config changes
242 for mdt in ${mdts//,/ }; do
244 cmd="$LCTL get_param -n "
245 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
246 cmd=${cmd}.quota_slave.enabled
248 if $(facet_up $mdt); then
249 wait_update_facet $mdt "$cmd" "$qtype" || return 1
256 # usage: set_ost_qtype ugp|u|g|p|none
260 local osts=$(get_facets OST)
262 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
263 qtype=$(tr -d 'p' <<<$qtype)
265 if [[ $PERM_CMD = *"set_param -P"* ]]; then
266 do_facet mgs $PERM_CMD \
267 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
269 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
271 # we have to make sure each OST received config changes
272 for ost in ${osts//,/ }; do
274 cmd="$LCTL get_param -n "
275 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
276 cmd=${cmd}.quota_slave.enabled
278 if $(facet_up $ost); then
279 wait_update_facet $ost "$cmd" "$qtype" || return 1
285 wait_reintegration() {
289 local result="glb[1],slv[1],reint[0]"
294 if [ $ntype == "mdt" ]; then
295 tgts=$(get_facets MDS)
297 tgts=$(get_facets OST)
300 for tgt in ${tgts//,/ }; do
302 cmd="$LCTL get_param -n "
303 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
304 cmd=${cmd}.quota_slave.info
306 if $(facet_up $tgt); then
307 wait_update_facet $tgt "$cmd |
308 grep "$qtype" | awk '{ print \\\$3 }'" \
309 "$result" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "mdt" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "mdt" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "mdt" "project" $max || return 1
338 if [[ "$qtype" =~ "u" ]]; then
339 wait_reintegration "ost" "user" $max || return 1
342 if [[ "$qtype" =~ "g" ]]; then
343 wait_reintegration "ost" "group" $max || return 1
346 if [[ "$qtype" =~ "p" ]]; then
347 ! is_project_quota_supported && return 0
348 wait_reintegration "ost" "project" $max || return 1
353 disable_project_quota() {
354 is_project_quota_supported || return 0
355 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
356 stopall || error "failed to stopall (1)"
358 for num in $(seq $MDSCOUNT); do
359 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
360 error "tune2fs $(mdsdevname $num) failed"
363 for num in $(seq $OSTCOUNT); do
364 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
365 error "tune2fs $(ostdevname $num) failed"
373 wait_delete_completed
374 echo "Creating test directory"
375 mkdir $DIR/$tdir || return 1
376 chmod 0777 $DIR/$tdir || return 2
377 # always clear fail_loc in case of fail_loc isn't cleared
378 # properly when previous test failed
379 lustre_fail mds_ost 0
382 cleanup_quota_test() {
384 echo "Delete files..."
386 echo "Wait for unlink objects finished..."
387 wait_delete_completed
388 sync_all_data || true
397 $LFS quota -v -$ugp $qid $DIR
399 if [ "$bf" == "a" -o "$bf" == "b" ]; then
400 usage=$(getquota -$ugp $qid global curspace)
401 if [ -z $usage ]; then
402 quota_error $ugp $qid \
403 "Query block quota failed ($ugp:$qid)."
405 [ $usage -ne 0 ] && quota_log $ugp $qid \
406 "Block quota isn't 0 ($ugp:$qid:$usage)."
410 if [ "$bf" == "a" -o "$bf" == "f" ]; then
411 usage=$(getquota -$ugp $qid global curinodes)
412 if [ -z $usage ]; then
413 quota_error $ugp $qid \
414 "Query file quota failed ($ugp:$qid)."
416 [ $usage -ne 0 ] && quota_log $ugp $qid \
417 "File quota isn't 0 ($ugp:$qid:$usage)."
422 enable_project_quota() {
423 is_project_quota_supported || return 0
424 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
425 stopall || error "failed to stopall (1)"
427 for num in $(seq $MDSCOUNT); do
428 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
429 error "tune2fs $(mdsdevname $num) failed"
432 for num in $(seq $OSTCOUNT); do
433 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
434 error "tune2fs $(ostdevname $num) failed"
442 reset_quota_settings() {
443 resetquota -u $TSTUSR
444 resetquota -g $TSTUSR
445 resetquota -u $TSTUSR2
446 resetquota -g $TSTUSR2
447 resetquota -p $TSTPRJID
452 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
457 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
458 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
459 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
460 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
462 test_quota_performance() {
463 local TESTFILE="$DIR/$tdir/$tfile-0"
464 local size=$1 # in MB
465 local stime=$(date +%s)
466 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
467 quota_error u $TSTUSR "write failure"
468 local etime=$(date +%s)
469 delta=$((etime - stime))
470 if [ $delta -gt 0 ]; then
471 rate=$((size * 1024 / delta))
472 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
473 # LU-2872 - see LU-2887 for fix
475 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
477 [ $rate -gt 1024 ] ||
478 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
484 # test basic quota performance b=21696
487 [ "$SLOW" = "no" ] && MB=10
489 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
490 [ $free_space -le $((MB * 1024)) ] &&
491 skip "not enough space ${free_space} KB, " \
492 "required $((MB * 1024)) KB"
493 setup_quota_test || error "setup quota failed with $?"
494 trap cleanup_quota_test EXIT
496 set_ost_qtype "none" || error "disable ost quota failed"
497 test_quota_performance $MB
499 set_ost_qtype $QTYPE || error "enable ost quota failed"
500 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
501 error "set quota failed"
502 test_quota_performance $MB
505 resetquota -u $TSTUSR
507 run_test 0 "Test basic quota performance"
509 # test block hardlimit
512 local TESTFILE="$DIR/$tdir/$tfile-0"
514 setup_quota_test || error "setup quota failed with $?"
515 trap cleanup_quota_test EXIT
518 set_ost_qtype $QTYPE || error "enable ost quota failed"
521 log "User quota (block hardlimit:$LIMIT MB)"
522 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
523 error "set user quota failed"
525 # make sure the system is clean
526 local USED=$(getquota -u $TSTUSR global curspace)
527 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
529 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
530 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
533 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
534 quota_error u $TSTUSR "user write failure, but expect success"
535 log "Write out of block quota ..."
536 # this time maybe cache write, ignore it's failure
537 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
538 # flush cache, ensure noquota flag is set on client
540 sync; sync_all_data || true
541 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
542 quota_error u $TSTUSR "user write success, but expect EDQUOT"
545 wait_delete_completed || error "wait_delete_completed failed"
546 sync_all_data || true
547 USED=$(getquota -u $TSTUSR global curspace)
548 [ $USED -ne 0 ] && quota_error u $TSTUSR \
549 "user quota isn't released after deletion"
550 resetquota -u $TSTUSR
553 log "--------------------------------------"
554 log "Group quota (block hardlimit:$LIMIT MB)"
555 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
556 error "set group quota failed"
558 TESTFILE="$DIR/$tdir/$tfile-1"
559 # make sure the system is clean
560 USED=$(getquota -g $TSTUSR global curspace)
561 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
563 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
564 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
567 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
568 quota_error g $TSTUSR "Group write failure, but expect success"
569 log "Write out of block quota ..."
570 # this time maybe cache write, ignore it's failure
571 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
573 sync; sync_all_data || true
574 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
575 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
577 wait_delete_completed || error "wait_delete_completed failed"
578 sync_all_data || true
579 USED=$(getquota -g $TSTUSR global curspace)
580 [ $USED -ne 0 ] && quota_error g $TSTUSR \
581 "Group quota isn't released after deletion"
582 resetquota -g $TSTUSR
584 if ! is_project_quota_supported; then
585 echo "Project quota is not supported"
590 TESTFILE="$DIR/$tdir/$tfile-2"
591 # make sure the system is clean
592 USED=$(getquota -p $TSTPRJID global curspace)
594 error "used space($USED) for project $TSTPRJID isn't 0"
597 log "--------------------------------------"
598 log "Project quota (block hardlimit:$LIMIT mb)"
599 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
600 error "set project quota failed"
602 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
603 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
604 change_project -p $TSTPRJID $TESTFILE
607 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
608 "project write failure, but expect success"
609 log "write out of block quota ..."
610 # this time maybe cache write, ignore it's failure
611 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
613 sync; sync_all_data || true
614 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
615 $TSTPRJID "project write success, but expect EDQUOT"
620 USED=$(getquota -p $TSTPRJID global curspace)
621 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
622 "project quota isn't released after deletion"
624 resetquota -p $TSTPRJID
626 run_test 1 "Block hard limit (normal use and out of quota)"
628 # test inode hardlimit
630 local LIMIT=$((1024 * 1024)) # 1M inodes
631 local TESTFILE="$DIR/$tdir/$tfile-0"
633 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
635 local FREE_INODES=$(mdt_free_inodes 0)
636 echo "$FREE_INODES free inodes on master MDT"
637 [ $FREE_INODES -lt $LIMIT ] &&
638 skip "not enough free inodes $FREE_INODES required $LIMIT"
640 setup_quota_test || error "setup quota failed with $?"
641 trap cleanup_quota_test EXIT
644 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
647 log "User quota (inode hardlimit:$LIMIT files)"
648 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
649 error "set user quota failed"
651 # make sure the system is clean
652 local USED=$(getquota -u $TSTUSR global curinodes)
653 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
655 log "Create $LIMIT files ..."
656 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
657 quota_error u $TSTUSR "user create failure, but expect success"
658 log "Create out of file quota ..."
659 $RUNAS touch ${TESTFILE}_xxx &&
660 quota_error u $TSTUSR "user create success, but expect EDQUOT"
663 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
664 rm -f ${TESTFILE}_xxx
665 wait_delete_completed
667 USED=$(getquota -u $TSTUSR global curinodes)
668 [ $USED -ne 0 ] && quota_error u $TSTUSR \
669 "user quota isn't released after deletion"
670 resetquota -u $TSTUSR
673 log "--------------------------------------"
674 log "Group quota (inode hardlimit:$LIMIT files)"
675 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
676 error "set group quota failed"
678 TESTFILE=$DIR/$tdir/$tfile-1
679 # make sure the system is clean
680 USED=$(getquota -g $TSTUSR global curinodes)
681 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
683 log "Create $LIMIT files ..."
684 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
685 quota_error g $TSTUSR "group create failure, but expect success"
686 log "Create out of file quota ..."
687 $RUNAS touch ${TESTFILE}_xxx &&
688 quota_error g $TSTUSR "group create success, but expect EDQUOT"
691 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
692 rm -f ${TESTFILE}_xxx
693 wait_delete_completed
695 USED=$(getquota -g $TSTUSR global curinodes)
696 [ $USED -ne 0 ] && quota_error g $TSTUSR \
697 "user quota isn't released after deletion"
699 resetquota -g $TSTUSR
700 ! is_project_quota_supported && cleanup_quota_test &&
701 echo "Skip project quota is not supported" && return 0
704 log "--------------------------------------"
705 log "Project quota (inode hardlimit:$LIMIT files)"
706 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
707 error "set project quota failed"
709 TESTFILE=$DIR/$tdir/$tfile-1
710 # make sure the system is clean
711 USED=$(getquota -p $TSTPRJID global curinodes)
713 error "Used inodes($USED) for project $TSTPRJID isn't 0"
715 change_project -sp $TSTPRJID $DIR/$tdir
716 log "Create $LIMIT files ..."
717 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
718 $TSTPRJID "project create fail, but expect success"
719 log "Create out of file quota ..."
720 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
721 "project create success, but expect EDQUOT"
722 change_project -C $DIR/$tdir
725 USED=$(getquota -p $TSTPRJID global curinodes)
726 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
727 "project quota isn't released after deletion"
729 resetquota -p $TSTPRJID
732 run_test 2 "File hard limit (normal use and out of quota)"
736 local TIMER=$(($2 * 3 / 2))
742 trap cleanup_quota_test EXIT
744 $SETSTRIPE $TESTFILE -c 1 -i 0
745 chown $TSTUSR.$TSTUSR $TESTFILE
746 [ "$qtype" == "p" ] && is_project_quota_supported &&
747 change_project -p $TSTPRJID $TESTFILE
749 echo "Write up to soft limit"
750 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
751 quota_error a $TSTUSR "write failure, but expect success"
752 OFFSET=$((LIMIT * 1024))
755 echo "Write to exceed soft limit"
756 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
757 quota_error a $TSTUSR "write failure, but expect success"
758 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
764 $SHOW_QUOTA_INFO_USER
765 $SHOW_QUOTA_INFO_GROUP
766 $SHOW_QUOTA_INFO_PROJID
768 echo "Write before timer goes off"
769 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
770 quota_error a $TSTUSR "write failure, but expect success"
771 OFFSET=$((OFFSET + 1024))
774 echo "Sleep $TIMER seconds ..."
780 $SHOW_QUOTA_INFO_USER
781 $SHOW_QUOTA_INFO_GROUP
782 $SHOW_QUOTA_INFO_PROJID
784 echo "Write after timer goes off"
785 # maybe cache write, ignore.
786 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
787 OFFSET=$((OFFSET + 1024))
789 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
790 quota_error a $TSTUSR "write success, but expect EDQUOT"
795 $SHOW_QUOTA_INFO_USER
796 $SHOW_QUOTA_INFO_GROUP
797 $SHOW_QUOTA_INFO_PROJID
799 echo "Unlink file to stop timer"
801 wait_delete_completed
802 sync_all_data || true
807 $SHOW_QUOTA_INFO_USER
808 $SHOW_QUOTA_INFO_GROUP
809 $SHOW_QUOTA_INFO_PROJID
811 $SETSTRIPE $TESTFILE -c 1 -i 0
812 chown $TSTUSR.$TSTUSR $TESTFILE
813 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
816 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
817 quota_error a $TSTUSR "write failure, but expect success"
826 local TESTFILE=$DIR/$tdir/$tfile-0
828 set_ost_qtype $QTYPE || error "enable ost quota failed"
830 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
831 # make sure the system is clean
832 local USED=$(getquota -u $TSTUSR global curspace)
833 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
835 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
836 $MAX_IQ_TIME $DIR || error "set user grace time failed"
837 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
838 error "set user quota failed"
840 test_block_soft $TESTFILE $GRACE $LIMIT "u"
841 resetquota -u $TSTUSR
843 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
844 TESTFILE=$DIR/$tdir/$tfile-1
845 # make sure the system is clean
846 USED=$(getquota -g $TSTUSR global curspace)
847 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
849 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
850 $MAX_IQ_TIME $DIR || error "set group grace time failed"
851 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
852 error "set group quota failed"
854 test_block_soft $TESTFILE $GRACE $LIMIT "g"
855 resetquota -g $TSTUSR
857 if is_project_quota_supported; then
858 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
859 TESTFILE=$DIR/$tdir/$tfile-2
860 # make sure the system is clean
861 USED=$(getquota -p $TSTPRJID global curspace)
862 [ $USED -ne 0 ] && error \
863 "Used space($USED) for project $TSTPRJID isn't 0."
865 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
867 error "set project grace time failed"
868 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
869 $DIR || error "set project quota failed"
871 test_block_soft $TESTFILE $GRACE $LIMIT "p"
872 resetquota -p $TSTPRJID
873 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
875 error "restore project grace time failed"
879 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
880 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
881 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
882 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
884 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
890 local TIMER=$(($grace * 3 / 2))
893 trap cleanup_quota_test EXIT
894 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
896 echo "Create files to exceed soft limit"
897 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
898 quota_error a $TSTUSR "create failure, but expect success"
899 local trigger_time=$(date +%s)
901 sync_all_data || true
903 local cur_time=$(date +%s)
904 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
905 error "Passed grace time $grace, $trigger_time, $cur_time"
907 echo "Create file before timer goes off"
908 $RUNAS touch ${TESTFILE}_before ||
909 quota_error a $TSTUSR "failed create before timer expired," \
910 "but expect success. $trigger_time, $cur_time"
911 sync_all_data || true
913 echo "Sleep $TIMER seconds ..."
919 $SHOW_QUOTA_INFO_USER
920 $SHOW_QUOTA_INFO_GROUP
921 $SHOW_QUOTA_INFO_PROJID
923 echo "Create file after timer goes off"
924 # There is a window that space is accounted in the quota usage but
925 # hasn't been decreased from the pending write, if we acquire quota
926 # in this window, we'll acquire more than we needed.
927 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
928 sync_all_data || true
929 $RUNAS touch ${TESTFILE}_after_3 &&
930 quota_error a $TSTUSR "create after timer expired," \
932 sync_all_data || true
937 $SHOW_QUOTA_INFO_USER
938 $SHOW_QUOTA_INFO_GROUP
939 $SHOW_QUOTA_INFO_PROJID
941 echo "Unlink files to stop timer"
942 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
943 wait_delete_completed
946 $RUNAS touch ${TESTFILE}_xxx ||
947 quota_error a $TSTUSR "touch after timer stop failure," \
949 sync_all_data || true
957 local LIMIT=10 # inodes
958 local TESTFILE=$DIR/$tdir/$tfile-0
961 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
963 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
964 # make sure the system is clean
965 local USED=$(getquota -u $TSTUSR global curinodes)
966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
968 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
969 $GRACE $DIR || error "set user grace time failed"
970 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
971 error "set user quota failed"
973 test_file_soft $TESTFILE $LIMIT $GRACE
974 resetquota -u $TSTUSR
976 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
977 # make sure the system is clean
978 USED=$(getquota -g $TSTUSR global curinodes)
979 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
981 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
982 $GRACE $DIR || error "set group grace time failed"
983 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
984 error "set group quota failed"
985 TESTFILE=$DIR/$tdir/$tfile-1
987 test_file_soft $TESTFILE $LIMIT $GRACE
988 resetquota -g $TSTUSR
990 if is_project_quota_supported; then
991 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
992 # make sure the system is clean
993 USED=$(getquota -p $TSTPRJID global curinodes)
994 [ $USED -ne 0 ] && error \
995 "Used space($USED) for project $TSTPRJID isn't 0."
997 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
998 $GRACE $DIR || error "set project grace time failed"
999 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1000 error "set project quota failed"
1002 TESTFILE=$DIR/$tdir/$tfile-1
1003 # one less than limit, because of parent directory included.
1004 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1005 resetquota -p $TSTPRJID
1006 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1007 $MAX_IQ_TIME $DIR ||
1008 error "restore project grace time failed"
1012 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1013 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1014 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1015 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1017 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1020 local GR_STR1="1w3d"
1021 local GR_STR2="1000s"
1023 local GR_STR4="1w2d3h4m5s"
1025 local GR_STR6="18446744073709551615"
1028 wait_delete_completed
1030 # test of valid grace strings handling
1031 echo "Valid grace strings test"
1032 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1033 $GR_STR2 $DIR || error "set user grace time failed"
1034 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1035 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1036 $GR_STR4 $DIR || error "set group grace time quota failed"
1037 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1039 # test of invalid grace strings handling
1040 echo " Invalid grace strings test"
1041 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1042 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1043 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1047 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1048 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1049 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1050 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1052 run_test 4b "Grace time strings handling"
1054 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1056 local BLIMIT=10 # 10M
1057 local ILIMIT=10 # 10 inodes
1059 setup_quota_test || error "setup quota failed with $?"
1060 trap cleanup_quota_test EXIT
1062 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1063 set_ost_qtype $QTYPE || error "enable ost quota failed"
1065 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1066 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1067 error "set user quota failed"
1068 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1069 if is_project_quota_supported; then
1070 error "set group quota failed"
1071 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1072 -I $ILIMIT $DIR || error "set project quota failed"
1075 # make sure the system is clean
1076 local USED=$(getquota -u $TSTUSR global curinodes)
1077 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1078 USED=$(getquota -g $TSTUSR global curinodes)
1079 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1080 USED=$(getquota -u $TSTUSR global curspace)
1081 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1082 USED=$(getquota -g $TSTUSR global curspace)
1083 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1084 if is_project_quota_supported; then
1085 USED=$(getquota -p $TSTPRJID global curinodes)
1087 error "Used inode($USED) for project $TSTPRJID isn't 0."
1088 USED=$(getquota -p $TSTPRJID global curspace)
1090 error "Used block($USED) for project $TSTPRJID isn't 0."
1093 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1094 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1095 error "create failure, expect success"
1096 if is_project_quota_supported; then
1097 touch $DIR/$tdir/$tfile-0_1
1098 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1100 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1101 error "write failure, expect success"
1103 echo "Chown files to $TSTUSR.$TSTUSR ..."
1104 for i in $(seq 0 $ILIMIT); do
1105 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1106 quota_error a $TSTUSR "chown failure, expect success"
1110 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1111 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1114 resetquota -u $TSTUSR
1115 resetquota -g $TSTUSR
1116 resetquota -p $TSTPRJID
1118 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1120 # test dropping acquire request on master
1124 # Clear dmesg so watchdog is not triggered by previous
1126 do_facet ost1 dmesg -c > /dev/null
1128 setup_quota_test || error "setup quota failed with $?"
1129 trap cleanup_quota_test EXIT
1131 # make sure the system is clean
1132 local USED=$(getquota -u $TSTUSR global curspace)
1133 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1135 # make sure no granted quota on ost
1136 set_ost_qtype $QTYPE || error "enable ost quota failed"
1137 resetquota -u $TSTUSR
1139 # create file for $TSTUSR
1140 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1141 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1142 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1144 # create file for $TSTUSR2
1145 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1146 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1147 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1149 # cache per-ID lock for $TSTUSR on slave
1150 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1151 error "set quota failed"
1152 $RUNAS $DD of=$TESTFILE count=1 ||
1153 error "write $TESTFILE failure, expect success"
1154 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1155 error "write $TESTFILE2 failure, expect success"
1157 sync_all_data || true
1159 #define QUOTA_DQACQ 601
1160 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1161 lustre_fail mds 0x513 601
1163 # write to un-enforced ID ($TSTUSR2) should succeed
1164 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1165 error "write failure, expect success"
1167 # write to enforced ID ($TSTUSR) in background, exceeding limit
1168 # to make sure DQACQ is sent
1169 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1172 # watchdog timer uses a factor of 2
1173 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1174 sleep $((TIMEOUT * 2 + 1))
1176 # write should be blocked and never finished
1177 if ! ps -p $DDPID > /dev/null 2>&1; then
1179 error "write finished incorrectly!"
1184 # no watchdog is triggered
1185 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1186 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1187 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1188 [ -z "$watchdog" ] || error "$watchdog"
1190 rm -f $TMP/lustre-log-${TESTNAME}.log
1192 # write should continue then fail with EDQUOT
1196 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1197 if [ $count -ge 240 ]; then
1198 quota_error u $TSTUSR "dd not finished in $count secs"
1200 count=$((count + 1))
1201 if [ $((count % 30)) -eq 0 ]; then
1202 c_size=$(stat -c %s $TESTFILE)
1203 echo "Waiting $count secs. $c_size"
1210 resetquota -u $TSTUSR
1212 run_test 6 "Test dropping acquire request on master"
1214 # quota reintegration (global index)
1216 local TESTFILE=$DIR/$tdir/$tfile
1217 local LIMIT=20 # 20M
1219 [ "$SLOW" = "no" ] && LIMIT=5
1221 setup_quota_test || error "setup quota failed with $?"
1222 trap cleanup_quota_test EXIT
1224 # make sure the system is clean
1225 local USED=$(getquota -u $TSTUSR global curspace)
1226 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1228 # make sure no granted quota on ost1
1229 set_ost_qtype $QTYPE || error "enable ost quota failed"
1230 resetquota -u $TSTUSR
1231 set_ost_qtype "none" || error "disable ost quota failed"
1233 local OSTUUID=$(ostuuid_from_index 0)
1234 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1236 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1239 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1240 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1245 echo "Enable quota & set quota limit for $TSTUSR"
1246 set_ost_qtype $QTYPE || error "enable ost quota failed"
1247 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1248 error "set quota failed"
1250 echo "Start ost1..."
1251 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1254 wait_ost_reint $QTYPE || error "reintegration failed"
1256 # hardlimit should have been fetched by slave during global
1257 # reintegration, write will exceed quota
1258 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1259 quota_error u $TSTUSR "write success, but expect EDQUOT"
1262 wait_delete_completed
1263 sync_all_data || true
1269 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1270 error "clear quota failed"
1272 echo "Start ost1..."
1273 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1276 wait_ost_reint $QTYPE || error "reintegration failed"
1278 # hardlimit should be cleared on slave during reintegration
1279 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1280 quota_error u $TSTUSR "write error, but expect success"
1283 resetquota -u $TSTUSR
1285 run_test 7a "Quota reintegration (global index)"
1287 # quota reintegration (slave index)
1290 local TESTFILE=$DIR/$tdir/$tfile
1292 setup_quota_test || error "setup quota failed with $?"
1293 trap cleanup_quota_test EXIT
1295 # make sure the system is clean
1296 local USED=$(getquota -u $TSTUSR global curspace)
1297 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1299 # make sure no granted quota on ost1
1300 set_ost_qtype $QTYPE || error "enable ost quota failed"
1301 resetquota -u $TSTUSR
1302 set_ost_qtype "none" || error "disable ost quota failed"
1304 local OSTUUID=$(ostuuid_from_index 0)
1305 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1307 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1310 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1311 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1313 # consume some space to make sure the granted space will not
1314 # be released during reconciliation
1315 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1316 error "consume space failure, expect success"
1318 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1319 lustre_fail mds 0xa02
1321 set_ost_qtype $QTYPE || error "enable ost quota failed"
1322 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1323 error "set quota failed"
1325 # ignore the write error
1326 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1328 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1332 echo "Restart ost to trigger reintegration..."
1334 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1337 wait_ost_reint $QTYPE || error "reintegration failed"
1339 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1340 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1343 resetquota -u $TSTUSR
1346 run_test 7b "Quota reintegration (slave index)"
1348 # quota reintegration (restart mds during reintegration)
1350 local LIMIT=20 # 20M
1351 local TESTFILE=$DIR/$tdir/$tfile
1353 [ "$SLOW" = "no" ] && LIMIT=5
1355 setup_quota_test || error "setup quota failed with $?"
1356 trap cleanup_quota_test EXIT
1358 # make sure the system is clean
1359 local USED=$(getquota -u $TSTUSR global curspace)
1360 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1362 set_ost_qtype "none" || error "disable ost quota failed"
1363 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1364 error "set quota failed"
1366 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1367 lustre_fail ost 0xa03
1370 set_ost_qtype $QTYPE || error "enable ost quota failed"
1371 # trigger reintegration
1372 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1373 procf=${procf}quota_slave.force_reint
1374 do_facet ost1 $LCTL set_param $procf=1 ||
1375 error "force reintegration failed"
1383 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1386 # wait longer than usual to make sure the reintegration
1387 # is triggered by quota wb thread.
1388 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1390 # hardlimit should have been fetched by slave during global
1391 # reintegration, write will exceed quota
1392 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1393 quota_error u $TSTUSR "write success, but expect EDQUOT"
1396 resetquota -u $TSTUSR
1398 run_test 7c "Quota reintegration (restart mds during reintegration)"
1400 # Quota reintegration (Transfer index in multiple bulks)
1402 local TESTFILE=$DIR/$tdir/$tfile
1403 local TESTFILE1="$DIR/$tdir/$tfile"-1
1406 setup_quota_test || error "setup quota failed with $?"
1407 trap cleanup_quota_test EXIT
1409 set_ost_qtype "none" || error "disable ost quota failed"
1410 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1411 error "set quota for $TSTUSR failed"
1412 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1413 error "set quota for $TSTUSR2 failed"
1415 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1416 lustre_fail mds 0x608 0
1418 # enable quota to tirgger reintegration
1419 set_ost_qtype "u" || error "enable ost quota failed"
1420 wait_ost_reint "u" || error "reintegration failed"
1424 # hardlimit should have been fetched by slave during global
1425 # reintegration, write will exceed quota
1426 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1427 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1429 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1430 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1433 resetquota -u $TSTUSR
1434 resetquota -u $TSTUSR2
1436 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1438 # quota reintegration (inode limits)
1440 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1442 # LU-2435: skip this quota test if underlying zfs version has not
1443 # supported native dnode accounting
1444 [ "$(facet_fstype mds1)" == "zfs" ] && {
1445 local F="feature@userobj_accounting"
1446 local pool=$(zpool_name mds1)
1447 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1449 [[ "$feature" != *" active "* ]] &&
1450 skip "requires zpool with active userobj_accounting"
1453 local ilimit=$((1024 * 2)) # 2k inodes
1454 local TESTFILE=$DIR/${tdir}-1/$tfile
1456 setup_quota_test || error "setup quota failed with $?"
1457 trap cleanup_quota_test EXIT
1459 # make sure the system is clean
1460 local USED=$(getquota -u $TSTUSR global curinodes)
1461 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1463 # make sure no granted quota on mdt1
1464 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1465 resetquota -u $TSTUSR
1466 set_mdt_qtype "none" || error "disable mdt quota failed"
1468 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1469 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1470 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1473 echo "Stop mds${MDSCOUNT}..."
1476 echo "Enable quota & set quota limit for $TSTUSR"
1477 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1478 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1479 error "set quota failed"
1481 echo "Start mds${MDSCOUNT}..."
1482 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1485 wait_mdt_reint $QTYPE || error "reintegration failed"
1487 echo "create remote dir"
1488 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1489 error "create remote dir failed"
1490 chmod 0777 $DIR/${tdir}-1
1492 # hardlimit should have been fetched by slave during global
1493 # reintegration, create will exceed quota
1494 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1495 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1497 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1498 wait_delete_completed
1499 sync_all_data || true
1501 echo "Stop mds${MDSCOUNT}..."
1504 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1505 error "clear quota failed"
1507 echo "Start mds${MDSCOUNT}..."
1508 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1511 wait_mdt_reint $QTYPE || error "reintegration failed"
1513 # hardlimit should be cleared on slave during reintegration
1514 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1515 quota_error u $TSTUSR "create failed, expect success"
1517 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1518 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1521 resetquota -u $TSTUSR
1523 run_test 7e "Quota reintegration (inode limits)"
1525 # run dbench with quota enabled
1527 local BLK_LIMIT="100g" #100G
1528 local FILE_LIMIT=1000000
1530 setup_quota_test || error "setup quota failed with $?"
1531 trap cleanup_quota_test EXIT
1533 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1534 set_ost_qtype $QTYPE || error "enable ost quota failed"
1536 echo "Set enough high limit for user: $TSTUSR"
1537 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1538 error "set user quota failed"
1539 echo "Set enough high limit for group: $TSTUSR"
1540 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1541 error "set group quota failed"
1542 if is_project_quota_supported; then
1543 change_project -sp $TSTPRJID $DIR/$tdir
1544 echo "Set enough high limit for project: $TSTPRJID"
1545 $LFS setquota -p $TSTPRJID -b 0 \
1546 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1547 error "set project quota failed"
1551 [ "$SLOW" = "no" ] && duration=" -t 120"
1552 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1553 quota_error a $TSTUSR "dbench failed!"
1555 is_project_quota_supported && change_project -C $DIR/$tdir
1557 resetquota -u $TSTUSR
1558 resetquota -g $TSTUSR
1559 resetquota -p $TSTPRJID
1561 run_test 8 "Run dbench with quota enabled"
1563 # this check is just for test_9
1564 OST0_MIN=4900000 #4.67G
1566 check_whether_skip () {
1567 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1568 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1569 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1570 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1577 # run for fixing bug10707, it needs a big room. test for 64bit
1579 local filesize=$((1024 * 9 / 2)) # 4.5G
1581 check_whether_skip && return 0
1583 setup_quota_test || error "setup quota failed with $?"
1584 trap cleanup_quota_test EXIT
1586 set_ost_qtype "ug" || error "enable ost quota failed"
1588 local TESTFILE="$DIR/$tdir/$tfile-0"
1589 local BLK_LIMIT=100G #100G
1590 local FILE_LIMIT=1000000
1592 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1594 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1596 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1597 error "set user quota failed"
1599 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1600 "for group: $TSTUSR"
1601 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1602 error "set group quota failed"
1604 quota_show_check a u $TSTUSR
1605 quota_show_check a g $TSTUSR
1607 echo "Create test file"
1608 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1609 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1611 log "Write the big file of 4.5G ..."
1612 $RUNAS $DD of=$TESTFILE count=$filesize ||
1613 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1619 resetquota -u $TSTUSR
1620 resetquota -g $TSTUSR
1625 run_test 9 "Block limit larger than 4GB (b10707)"
1628 local TESTFILE=$DIR/$tdir/$tfile
1630 setup_quota_test || error "setup quota failed with $?"
1631 trap cleanup_quota_test EXIT
1633 # set limit to root user should fail
1634 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1635 error "set limit for root user successfully, expect failure"
1636 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1637 error "set limit for root group successfully, expect failure"
1638 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1639 error "set limit for project 0 successfully, expect failure"
1641 # root user can overrun quota
1642 set_ost_qtype "ug" || error "enable ost quota failed"
1644 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1645 error "set quota failed"
1646 quota_show_check b u $TSTUSR
1648 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1649 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1651 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1652 error "write failure, expect success"
1655 resetquota -u $TSTUSR
1657 run_test 10 "Test quota for root user"
1660 local TESTFILE=$DIR/$tdir/$tfile
1661 setup_quota_test || error "setup quota failed with $?"
1662 trap cleanup_quota_test EXIT
1664 set_mdt_qtype "ug" || error "enable mdt quota failed"
1665 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1666 error "set quota failed"
1668 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1669 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1671 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1672 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1675 local USED=$(getquota -u $TSTUSR global curinodes)
1676 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1679 resetquota -u $TSTUSR
1681 run_test 11 "Chown/chgrp ignores quota"
1684 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1686 local blimit=22 # 22M
1687 local blk_cnt=$((blimit - 5))
1688 local TESTFILE0="$DIR/$tdir/$tfile"-0
1689 local TESTFILE1="$DIR/$tdir/$tfile"-1
1691 setup_quota_test || error "setup quota failed with $?"
1692 trap cleanup_quota_test EXIT
1694 set_ost_qtype "u" || error "enable ost quota failed"
1695 quota_show_check b u $TSTUSR
1697 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1698 error "set quota failed"
1700 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1701 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1702 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1703 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1705 echo "Write to ost0..."
1706 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1707 quota_error a $TSTUSR "dd failed"
1709 echo "Write to ost1..."
1710 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1711 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1713 echo "Free space from ost0..."
1715 wait_delete_completed
1716 sync_all_data || true
1718 echo "Write to ost1 after space freed from ost0..."
1719 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1720 quota_error a $TSTUSR "rebalancing failed"
1723 resetquota -u $TSTUSR
1725 run_test 12a "Block quota rebalancing"
1728 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1730 local ilimit=$((1024 * 2)) # 2k inodes
1731 local TESTFILE0=$DIR/$tdir/$tfile
1732 local TESTFILE1=$DIR/${tdir}-1/$tfile
1734 setup_quota_test || error "setup quota failed with $?"
1735 trap cleanup_quota_test EXIT
1737 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1738 chmod 0777 $DIR/${tdir}-1
1740 set_mdt_qtype "u" || error "enable mdt quota failed"
1741 quota_show_check f u $TSTUSR
1743 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1744 error "set quota failed"
1746 echo "Create $ilimit files on mdt0..."
1747 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1748 quota_error u $TSTUSR "create failed, but expect success"
1750 echo "Create files on mdt1..."
1751 $RUNAS createmany -m $TESTFILE1 1 &&
1752 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1754 echo "Free space from mdt0..."
1755 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1756 wait_delete_completed
1757 sync_all_data || true
1759 echo "Create files on mdt1 after space freed from mdt0..."
1760 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1761 quota_error a $TSTUSR "rebalancing failed"
1763 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1764 error "unlink mdt1 files failed"
1765 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1768 resetquota -u $TSTUSR
1770 run_test 12b "Inode quota rebalancing"
1773 local TESTFILE=$DIR/$tdir/$tfile
1774 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1775 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1777 setup_quota_test || error "setup quota failed with $?"
1778 trap cleanup_quota_test EXIT
1780 set_ost_qtype "u" || error "enable ost quota failed"
1781 quota_show_check b u $TSTUSR
1783 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1784 error "set quota failed"
1785 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1786 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1788 # clear the locks in cache first
1789 do_facet ost1 $LCTL set_param -n $procf=clear
1790 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1791 [ $nlock -eq 0 ] || error "$nlock cached locks"
1793 # write to acquire the per-ID lock
1794 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1795 quota_error a $TSTUSR "dd failed"
1797 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1798 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1800 # clear quota doesn't trigger per-ID lock cancellation
1801 resetquota -u $TSTUSR
1802 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1803 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1805 # clear the per-ID lock
1806 do_facet ost1 $LCTL set_param -n $procf=clear
1807 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1808 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1810 # spare quota should be released
1811 local OSTUUID=$(ostuuid_from_index 0)
1812 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1813 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1814 [ $limit -le $space ] ||
1815 error "spare quota isn't released, limit:$limit, space:$space"
1819 run_test 13 "Cancel per-ID lock in the LRU list"
1822 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1824 wait_delete_completed
1825 sync_all_data || true
1828 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1829 error "set user quota failed"
1830 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1831 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1832 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1833 resetquota -u $TSTUSR
1836 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1837 error "set group quota failed"
1838 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1839 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1840 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1841 resetquota -g $TSTUSR
1843 run_test 15 "Set over 4T block quota"
1847 local BLKS=1 # 1M less than limit
1848 local TESTFILE=$DIR/$tdir/$tfile
1850 setup_quota_test || error "setup quota failed with $?"
1851 trap cleanup_quota_test EXIT
1853 # make sure the system is clean
1854 local USED=$(getquota -u $TSTUSR global curspace)
1855 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1857 set_ost_qtype "ug" || error "enable ost quota failed"
1858 # make sure no granted quota on ost
1859 resetquota -u $TSTUSR
1860 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1861 error "set quota failed"
1863 quota_show_check b u $TSTUSR
1865 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1866 lustre_fail mds 0xa04 $err_code
1868 # write in background
1869 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1873 # write should be blocked and never finished
1874 if ! ps -p $DDPID > /dev/null 2>&1; then
1876 quota_error u $TSTUSR "write finished incorrectly!"
1884 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1886 if [ $count -gt $timeout ]; then
1887 quota_error u $TSTUSR "dd is not finished!"
1892 sync; sync_all_data || true
1894 USED=$(getquota -u $TSTUSR global curspace)
1895 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1896 "Used space(${USED}K) is less than ${BLKS}M"
1899 resetquota -u $TSTUSR
1902 # DQACQ return recoverable error
1904 echo "DQACQ return -ENOLCK"
1906 test_17sub 37 || error "Handle -ENOLCK failed"
1908 echo "DQACQ return -EAGAIN"
1910 test_17sub 11 || error "Handle -EAGAIN failed"
1912 echo "DQACQ return -ETIMEDOUT"
1913 #define ETIMEDOUT 110
1914 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1916 echo "DQACQ return -ENOTCONN"
1917 #define ENOTCONN 107
1918 test_17sub 107 || error "Handle -ENOTCONN failed"
1921 run_test 17 "DQACQ return recoverable error"
1925 local blimit="200m" # 200M
1926 local TESTFILE="$DIR/$tdir/$tfile"
1928 setup_quota_test || error "setup quota failed with $?"
1929 trap cleanup_quota_test EXIT
1931 set_ost_qtype "u" || error "enable ost quota failed"
1932 log "User quota (limit: $blimit)"
1933 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1934 error "set quota failed"
1935 quota_show_check b u $TSTUSR
1937 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1938 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1940 local timeout=$(sysctl -n lustre.timeout)
1942 if [ $io_type = "directio" ]; then
1943 log "Write 100M (directio) ..."
1944 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1946 log "Write 100M (buffered) ..."
1947 $RUNAS $DD of=$TESTFILE count=100 &
1951 replay_barrier $SINGLEMDS
1952 log "Fail mds for $((2 * timeout)) seconds"
1953 fail $SINGLEMDS $((2 * timeout))
1956 if at_is_enabled; then
1957 timeout=$(at_max_get mds)
1959 timeout=$(lctl get_param -n timeout)
1963 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1964 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1965 log "it took $count second"
1970 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1972 cancel_lru_locks mdc
1973 cancel_lru_locks osc
1976 local testfile_size=$(stat -c %s $TESTFILE)
1977 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1978 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1979 "got ${testfile_size}. Verifying file failed!"
1982 resetquota -u $TSTUSR
1985 # test when mds does failover, the ost still could work well
1986 # this test shouldn't trigger watchdog b=14840
1988 # Clear dmesg so watchdog is not triggered by previous
1990 do_facet ost1 dmesg -c > /dev/null
1993 test_18_sub directio
1995 # check if watchdog is triggered
1996 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1997 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1998 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1999 [ -z "$watchdog" ] || error "$watchdog"
2000 rm -f $TMP/lustre-log-${TESTNAME}.log
2002 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2006 local TESTFILE=$DIR/$tdir/$tfile
2008 setup_quota_test || error "setup quota failed with $?"
2009 trap cleanup_quota_test EXIT
2011 set_ost_qtype $QTYPE || error "enable ost quota failed"
2013 # bind file to a single OST
2014 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2015 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2017 echo "Set user quota (limit: ${blimit}M)"
2018 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2019 error "set user quota failed"
2020 quota_show_check b u $TSTUSR
2021 echo "Update quota limits"
2022 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2023 error "set group quota failed"
2024 quota_show_check b u $TSTUSR
2026 # first wirte might be cached
2027 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2028 cancel_lru_locks osc
2030 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2031 quota_error u $TSTUSR "Write success, expect failure"
2035 resetquota -u $TSTUSR
2037 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2039 test_20() { # b15754
2040 local LSTR=(2g 1t 4k 3m) # limits strings
2042 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2045 resetquota -u $TSTUSR
2047 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2048 $MOUNT || error "could not set quota limits"
2049 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2050 --inode-softlimit ${LSTR[2]} \
2051 --inode-hardlimit ${LSTR[3]} \
2052 $MOUNT || error "could not set quota limits"
2054 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2055 error "bsoftlimit was not set properly"
2056 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2057 error "bhardlimit was not set properly"
2058 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2059 error "isoftlimit was not set properly"
2060 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2061 error "ihardlimit was not set properly"
2063 resetquota -u $TSTUSR
2065 run_test 20 "Test if setquota specifiers work properly (b15754)"
2072 local time=$(($(date +%s) + seconds))
2073 while [ $(date +%s) -lt $time ]; do
2074 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2078 # run for fixing bug16053, setquota shouldn't fail when writing and
2079 # deleting are happening
2081 local TESTFILE="$DIR/$tdir/$tfile"
2082 local BLIMIT=10 # 10G
2083 local ILIMIT=1000000
2085 setup_quota_test || error "setup quota failed with $?"
2086 trap cleanup_quota_test EXIT
2088 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2090 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2091 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2092 error "set user quota failed"
2093 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2094 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2095 error "set group quota failed"
2096 if is_project_quota_supported; then
2097 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2098 "project: $TSTPRJID"
2099 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2100 $MOUNT || error "set project quota failed"
2103 # repeat writing on a 1M file
2104 test_21_sub ${TESTFILE}_1 1 30 &
2106 # repeat writing on a 128M file
2107 test_21_sub ${TESTFILE}_2 128 30 &
2110 local time=$(($(date +%s) + 30))
2112 while [ $(date +%s) -lt $time ]; do
2113 log "Set quota for $i times"
2114 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2115 -I $((ILIMIT + i)) $MOUNT ||
2116 error "Set user quota failed"
2117 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2118 -I $((ILIMIT + i)) $MOUNT ||
2119 error "Set group quota failed"
2120 if is_project_quota_supported; then
2121 $LFS setquota -p $TSTPRJID -b 0 -B \
2122 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2123 error "Set project quota failed"
2131 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2133 if [ $count -gt 60 ]; then
2134 quota_error a $TSTUSR "dd should be finished!"
2138 echo "(dd_pid=$DDPID1, time=$count)successful"
2142 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2144 if [ $count -gt 60 ]; then
2145 quota_error a $TSTUSR "dd should be finished!"
2149 echo "(dd_pid=$DDPID2, time=$count)successful"
2152 resetquota -u $TSTUSR
2153 resetquota -g $TSTUSR
2154 resetquota -p $TSTPRJID
2156 run_test 21 "Setquota while writing & deleting (b16053)"
2158 # enable/disable quota enforcement permanently
2160 echo "Set both mdt & ost quota type as ug"
2162 is_project_quota_supported && qtype=$QTYPE
2163 set_mdt_qtype $qtype || error "enable mdt quota failed"
2164 set_ost_qtype $qtype || error "enable ost quota failed"
2167 stopall || error "failed to stopall (1)"
2171 echo "Verify if quota is enabled"
2172 local qtype1=$(mdt_quota_type)
2173 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2174 qtype=$(ost_quota_type)
2175 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2177 echo "Set both mdt & ost quota type as none"
2178 set_mdt_qtype "none" || error "disable mdt quota failed"
2179 set_ost_qtype "none" || error "disable ost quota failed"
2182 stopall || error "failed to stopall (2)"
2187 echo "Verify if quota is disabled"
2188 qtype=$(mdt_quota_type)
2189 [ $qtype != "none" ] && error "mdt quota setting is lost"
2190 qtype=$(ost_quota_type)
2191 [ $qtype != "none" ] && error "ost quota setting is lost"
2195 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2198 local TESTFILE="$DIR/$tdir/$tfile"
2201 setup_quota_test || error "setup quota failed with $?"
2202 trap cleanup_quota_test EXIT
2204 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2207 log "User quota (limit: $LIMIT MB)"
2208 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2209 error "set quota failed"
2210 quota_show_check b u $TSTUSR
2212 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2213 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2215 log "Step1: trigger EDQUOT with O_DIRECT"
2216 log "Write half of file"
2217 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2218 quota_error u $TSTUSR "(1) Write failure, expect success." \
2220 log "Write out of block quota ..."
2221 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2222 oflag=direct conv=notrunc &&
2223 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2227 log "Step2: rewrite should succeed"
2228 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2229 quota_error u $TSTUSR "(3) Write failure, expect success." \
2235 local OST0_UUID=$(ostuuid_from_index 0)
2236 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2237 [ $OST0_QUOTA_USED -ne 0 ] &&
2238 ($SHOW_QUOTA_USER; \
2239 quota_error u $TSTUSR "quota isn't released")
2241 resetquota -u $TSTUSR
2245 [ $(facet_fstype ost1) == "zfs" ] &&
2246 skip "Overwrite in place is not guaranteed to be " \
2247 "space neutral on ZFS"
2249 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2250 check_whether_skip && return 0
2251 log "run for 4MB test file"
2254 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2255 check_whether_skip && return 0
2256 log "run for 40MB test file"
2259 run_test 23 "Quota should be honored with directIO (b16125)"
2263 local TESTFILE="$DIR/$tdir/$tfile"
2265 setup_quota_test || error "setup quota failed with $?"
2266 trap cleanup_quota_test EXIT
2268 set_ost_qtype $QTYPE || error "enable ost quota failed"
2270 # bind file to a single OST
2271 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2272 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2274 echo "Set user quota (limit: ${blimit}M)"
2275 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2276 error "set quota failed"
2278 # overrun quota by root user
2279 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2280 error "write failure, expect success"
2281 cancel_lru_locks osc
2282 sync_all_data || true
2284 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2287 resetquota -u $TSTUSR
2289 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2291 test_27a() { # b19612
2292 $LFS quota $TSTUSR $DIR &&
2293 error "lfs succeeded with no type, but should have failed"
2294 $LFS setquota $TSTUSR $DIR &&
2295 error "lfs succeeded with no type, but should have failed"
2298 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2300 test_27b() { # b20200
2301 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2302 error "lfs setquota failed with uid argument"
2303 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2304 error "lfs stequota failed with gid argument"
2305 if is_project_quota_supported; then
2306 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2307 1000 $DIR || error \
2308 "lfs stequota failed with projid argument"
2310 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2311 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2312 if is_project_quota_supported; then
2313 $SHOW_QUOTA_PROJID ||
2314 error "lfs quota failed with projid argument"
2316 resetquota -u $TSTUSR
2317 resetquota -g $TSTUSR
2318 resetquota -p $TSTPRJID
2321 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2326 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2327 error "lfs setquota failed"
2329 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2330 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2331 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2332 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2334 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2335 error "lfs setquota for $TSTID failed"
2337 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2338 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2339 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2340 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2342 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2343 error "total allocated inode/block limit not printed"
2345 resetquota -u $TSTUSR
2347 run_test 27c "lfs quota should support human-readable output"
2354 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2355 error "set fraction block limit failed"
2356 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2357 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2358 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2359 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2361 resetquota -u $TSTUSR
2363 run_test 27d "lfs setquota should support fraction block limit"
2367 local TESTFILE="$DIR/$tdir/$tfile"
2370 setup_quota_test || error "setup quota failed with $?"
2371 trap cleanup_quota_test EXIT
2373 set_ost_qtype "u" || error "enable ost quota failed"
2375 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2376 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2378 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2379 $MAX_IQ_TIME $DIR || error "set grace time failed"
2380 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2381 error "set quota failed"
2382 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2383 cancel_lru_locks osc
2385 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2386 # over-quota flag has not yet settled since we do not trigger async
2387 # events based on grace time period expiration
2389 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2390 cancel_lru_locks osc
2391 # now over-quota flag should be settled and further writes should fail
2393 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2394 error "grace times were reset"
2397 resetquota -u $TSTUSR
2398 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2399 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2401 run_test 30 "Hard limit updates should not reset grace times"
2403 # basic usage tracking for user & group
2405 local INODES=10 # 10 files
2406 local BLK_CNT=2 # of 2M each
2407 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2409 setup_quota_test || error "setup quota failed with $?"
2410 trap cleanup_quota_test EXIT
2412 # make sure the system is clean
2413 local USED=$(getquota -u $TSTID global curspace)
2415 error "Used space ($USED) for user $TSTID isn't 0."
2416 USED=$(getquota -g $TSTID global curspace)
2418 error "Used space ($USED) for group $TSTID isn't 0."
2419 if is_project_quota_supported; then
2420 USED=$(getquota -p $TSTPRJID global curspace)
2421 [ $USED -ne 0 ] && error \
2422 "Used space ($USED) for project $TSTPRJID isn't 0."
2425 echo "Write files..."
2426 for i in $(seq 0 $INODES); do
2427 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2428 error "write failed"
2429 is_project_quota_supported &&
2430 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2431 echo "Iteration $i/$INODES completed"
2433 cancel_lru_locks osc
2435 echo "Wait for setattr on objects finished..."
2436 wait_delete_completed
2438 sync; sync_all_data || true
2440 echo "Verify disk usage after write"
2441 USED=$(getquota -u $TSTID global curspace)
2442 [ $USED -lt $TOTAL_BLKS ] &&
2443 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2444 USED=$(getquota -g $TSTID global curspace)
2445 [ $USED -lt $TOTAL_BLKS ] &&
2446 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2447 if is_project_quota_supported; then
2448 USED=$(getquota -p $TSTPRJID global curspace)
2449 [ $USED -lt $TOTAL_BLKS ] && error \
2450 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2453 echo "Verify inode usage after write"
2454 USED=$(getquota -u $TSTID global curinodes)
2455 [ $USED -lt $INODES ] &&
2456 error "Used inode for user $TSTID is $USED, expected $INODES"
2457 USED=$(getquota -g $TSTID global curinodes)
2458 [ $USED -lt $INODES ] &&
2459 error "Used inode for group $TSTID is $USED, expected $INODES"
2460 if is_project_quota_supported; then
2461 USED=$(getquota -p $TSTPRJID global curinodes)
2462 [ $USED -lt $INODES ] && error \
2463 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2468 echo "Verify disk usage after delete"
2469 USED=$(getquota -u $TSTID global curspace)
2470 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2471 USED=$(getquota -u $TSTID global curinodes)
2472 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2473 USED=$(getquota -g $TSTID global curspace)
2474 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2475 USED=$(getquota -g $TSTID global curinodes)
2476 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2477 if is_project_quota_supported; then
2478 USED=$(getquota -p $TSTPRJID global curspace)
2480 error "Used space for project $TSTPRJID isn't 0. $USED"
2481 USED=$(getquota -p $TSTPRJID global curinodes)
2483 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2486 run_test 33 "Basic usage tracking for user & group & project"
2488 # usage transfer test for user & group & project
2490 local BLK_CNT=2 # 2MB
2491 local project_supported="no"
2493 is_project_quota_supported && project_supported="yes"
2494 setup_quota_test || error "setup quota failed with $?"
2495 trap cleanup_quota_test EXIT
2497 # make sure the system is clean
2498 local USED=$(getquota -u $TSTID global curspace)
2499 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2500 USED=$(getquota -g $TSTID global curspace)
2501 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2503 local USED=$(getquota -u $TSTID2 global curspace)
2504 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2505 if [ $project_supported == "yes" ]; then
2506 USED=$(getquota -p $TSTPRJID global curspace)
2507 [ $USED -ne 0 ] && error \
2508 "Used space ($USED) for Project $TSTPRJID isn't 0."
2511 echo "Write file..."
2512 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2513 error "write failed"
2514 cancel_lru_locks osc
2515 sync; sync_all_data || true
2517 echo "chown the file to user $TSTID"
2518 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2520 echo "Wait for setattr on objects finished..."
2521 wait_delete_completed
2523 BLK_CNT=$((BLK_CNT * 1024))
2525 echo "Verify disk usage for user $TSTID"
2526 USED=$(getquota -u $TSTID global curspace)
2527 [ $USED -lt $BLK_CNT ] &&
2528 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2529 USED=$(getquota -u $TSTID global curinodes)
2531 error "Used inodes for user $TSTID is $USED, expected 1"
2533 echo "chgrp the file to group $TSTID"
2534 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2536 echo "Wait for setattr on objects finished..."
2537 wait_delete_completed
2539 echo "Verify disk usage for group $TSTID"
2540 USED=$(getquota -g $TSTID global curspace)
2541 [ $USED -ge $BLK_CNT ] ||
2542 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2543 USED=$(getquota -g $TSTID global curinodes)
2545 error "Used inodes for group $TSTID is $USED, expected 1"
2547 # chown won't change the ost object group. LU-4345 */
2548 echo "chown the file to user $TSTID2"
2549 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2551 echo "Wait for setattr on objects finished..."
2552 wait_delete_completed
2554 echo "change_project project id to $TSTPRJID"
2555 [ $project_supported == "yes" ] &&
2556 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2557 echo "Wait for setattr on objects finished..."
2558 wait_delete_completed
2560 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2561 USED=$(getquota -u $TSTID2 global curspace)
2562 [ $USED -lt $BLK_CNT ] &&
2563 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2564 USED=$(getquota -u $TSTID global curspace)
2566 error "Used space for user $TSTID is $USED, expected 0"
2567 USED=$(getquota -g $TSTID global curspace)
2568 [ $USED -lt $BLK_CNT ] &&
2569 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2570 if [ $project_supported == "yes" ]; then
2571 USED=$(getquota -p $TSTPRJID global curspace)
2572 [ $USED -lt $BLK_CNT ] && error \
2573 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2578 run_test 34 "Usage transfer for user & group & project"
2580 # usage is still accessible across restart
2582 local BLK_CNT=2 # 2 MB
2584 setup_quota_test || error "setup quota failed with $?"
2585 trap cleanup_quota_test EXIT
2587 echo "Write file..."
2588 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2589 error "write failed"
2590 is_project_quota_supported &&
2591 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2592 cancel_lru_locks osc
2594 echo "Wait for setattr on objects finished..."
2595 wait_delete_completed
2597 sync; sync_all_data || true
2599 echo "Save disk usage before restart"
2600 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2601 [ $ORIG_USR_SPACE -eq 0 ] &&
2602 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2603 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2604 [ $ORIG_USR_INODES -eq 0 ] &&
2605 error "Used inodes for user $TSTID is 0, expected 1"
2606 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2607 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2608 [ $ORIG_GRP_SPACE -eq 0 ] &&
2609 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2610 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2611 [ $ORIG_GRP_INODES -eq 0 ] &&
2612 error "Used inodes for group $TSTID is 0, expected 1"
2613 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2615 if is_project_quota_supported; then
2616 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2617 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2618 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2619 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2620 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2621 "Used inodes for project $TSTPRJID is 0, expected 1"
2622 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2630 echo "Verify disk usage after restart"
2631 local USED=$(getquota -u $TSTID global curspace)
2632 [ $USED -eq $ORIG_USR_SPACE ] ||
2633 error "Used space for user $TSTID changed from " \
2634 "$ORIG_USR_SPACE to $USED"
2635 USED=$(getquota -u $TSTID global curinodes)
2636 [ $USED -eq $ORIG_USR_INODES ] ||
2637 error "Used inodes for user $TSTID changed from " \
2638 "$ORIG_USR_INODES to $USED"
2639 USED=$(getquota -g $TSTID global curspace)
2640 [ $USED -eq $ORIG_GRP_SPACE ] ||
2641 error "Used space for group $TSTID changed from " \
2642 "$ORIG_GRP_SPACE to $USED"
2643 USED=$(getquota -g $TSTID global curinodes)
2644 [ $USED -eq $ORIG_GRP_INODES ] ||
2645 error "Used inodes for group $TSTID changed from " \
2646 "$ORIG_GRP_INODES to $USED"
2647 if [ $project_supported == "yes" ]; then
2648 USED=$(getquota -p $TSTPRJID global curinodes)
2649 [ $USED -eq $ORIG_PRJ_INODES ] ||
2650 error "Used inodes for project $TSTPRJID " \
2651 "changed from $ORIG_PRJ_INODES to $USED"
2652 USED=$(getquota -p $TSTPRJID global curspace)
2653 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2654 error "Used space for project $TSTPRJID "\
2655 "changed from $ORIG_PRJ_SPACE to $USED"
2658 # check if the vfs_dq_init() is called before writing
2659 echo "Append to the same file..."
2660 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2661 error "write failed"
2662 cancel_lru_locks osc
2663 sync; sync_all_data || true
2665 echo "Verify space usage is increased"
2666 USED=$(getquota -u $TSTID global curspace)
2667 [ $USED -gt $ORIG_USR_SPACE ] ||
2668 error "Used space for user $TSTID isn't increased" \
2669 "orig:$ORIG_USR_SPACE, now:$USED"
2670 USED=$(getquota -g $TSTID global curspace)
2671 [ $USED -gt $ORIG_GRP_SPACE ] ||
2672 error "Used space for group $TSTID isn't increased" \
2673 "orig:$ORIG_GRP_SPACE, now:$USED"
2674 if [ $project_supported == "yes" ]; then
2675 USED=$(getquota -p $TSTPRJID global curspace)
2676 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2677 error "Used space for project $TSTPRJID isn't " \
2678 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2683 run_test 35 "Usage is still accessible across reboot"
2685 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2688 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2689 skip "Old server doesn't have LU-5006 fix."
2691 setup_quota_test || error "setup quota failed with $?"
2692 trap cleanup_quota_test EXIT
2694 # make sure the system is clean
2695 local USED=$(getquota -u $TSTID global curspace)
2697 error "Used space ($USED) for user $TSTID isn't 0."
2699 # create file with MDS_OPEN_DELAY_CREATE flag
2700 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2701 error "Create file failed"
2703 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2704 oflag=sync || error "Write file failed"
2706 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2708 # wait for setattr on objects finished..."
2709 wait_delete_completed
2711 USED=$(getquota -u $TSTID global curspace)
2712 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2716 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2720 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2721 skip "Old server doesn't have LU-8801 fix."
2723 [ "$UID" != 0 ] && skip_env "must run as root" && return
2725 setup_quota_test || error "setup quota failed with $?"
2726 trap cleanup_quota_test EXIT
2728 # make sure the system is clean
2729 local USED=$(getquota -u $TSTID global curspace)
2731 error "Used space ($USED) for user $TSTID isn't 0."
2732 USED=$(getquota -u $TSTID2 global curspace)
2734 error "Used space ($USED) for user $TSTID2 isn't 0."
2736 local TESTFILE="$DIR/$tdir/$tfile"
2737 local file_cnt=10000
2739 # Generate id entries in accounting file
2740 echo "Create $file_cnt files..."
2741 for i in `seq $file_cnt`; do
2743 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2744 error "failed to chown $TESTFILE-$i"
2746 cancel_lru_locks osc
2747 sync; sync_all_data || true
2749 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2750 procf=${procf}.quota_slave.acct_user
2753 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2754 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2755 echo "Found $acct_cnt id entries"
2757 [ $file_cnt -eq $acct_cnt ] || {
2758 do_facet mds1 $LCTL get_param $procf
2759 error "skipped id entries"
2764 run_test 38 "Quota accounting iterator doesn't skip id entries"
2767 local TESTFILE="$DIR/$tdir/project"
2768 ! is_project_quota_supported &&
2769 skip "Project quota is not supported"
2771 setup_quota_test || error "setup quota failed with $?"
2774 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2775 [ $projectid -ne 0 ] &&
2776 error "Project id should be 0 not $projectid"
2777 change_project -p 1024 $TESTFILE
2778 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2779 [ $projectid -ne 1024 ] &&
2780 error "Project id should be 1024 not $projectid"
2782 stopall || error "failed to stopall (1)"
2785 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2786 [ $projectid -ne 1024 ] &&
2787 error "Project id should be 1024 not $projectid"
2791 run_test 39 "Project ID interface works correctly"
2794 ! is_project_quota_supported &&
2795 skip "Project quota is not supported"
2796 local dir1="$DIR/$tdir/dir1"
2797 local dir2="$DIR/$tdir/dir2"
2799 setup_quota_test || error "setup quota failed with $?"
2801 mkdir -p $dir1 $dir2
2802 change_project -sp 1 $dir1 && touch $dir1/1
2803 change_project -sp 2 $dir2
2805 ln $dir1/1 $dir2/1_link &&
2806 error "Hard link across different project quota should fail"
2811 run_test 40a "Hard link across different project ID"
2814 ! is_project_quota_supported &&
2815 skip "Project quota is not supported"
2816 local dir1="$DIR/$tdir/dir1"
2817 local dir2="$DIR/$tdir/dir2"
2819 setup_quota_test || error "setup quota failed with $?"
2820 mkdir -p $dir1 $dir2
2821 change_project -sp 1 $dir1 && touch $dir1/1
2822 change_project -sp 2 $dir2
2824 mv $dir1/1 $dir2/2 || error "mv failed $?"
2825 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2826 if [ "$projid" != "2" ]; then
2827 error "project id expected 2 not $projid"
2832 run_test 40b "Mv across different project ID"
2835 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2836 ! is_project_quota_supported &&
2837 skip "Project quota is not supported"
2839 setup_quota_test || error "setup quota failed with $?"
2840 local dir="$DIR/$tdir/dir"
2842 mkdir -p $dir && change_project -sp 1 $dir
2843 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2844 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2845 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2846 touch $dir/remote_dir/file
2847 #verify inherit works file for remote dir.
2848 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2849 [ "$projid" != "1" ] &&
2850 error "file under remote dir expected 1 not $projid"
2852 #Agent inode should be ignored for project quota
2853 USED=$(getquota -p 1 global curinodes)
2854 [ "$USED" != "3" ] &&
2855 error "file count expected 3 got $USED"
2861 run_test 40c "Remote child Dir inherit project quota properly"
2864 ! is_project_quota_supported &&
2865 skip "Project quota is not supported"
2867 setup_quota_test || error "setup quota failed with $?"
2868 local dir="$DIR/$tdir/dir"
2870 mkdir $dir && change_project -p 1 $dir
2871 count=$($LFS find --projid 1 $DIR | wc -l)
2872 [ "$count" != 1 ] && error "expected 1 but got $count"
2877 run_test 50 "Test if lfs find --projid works"
2880 ! is_project_quota_supported &&
2881 skip "Project quota is not supported"
2882 setup_quota_test || error "setup quota failed with $?"
2883 local dir="$DIR/$tdir/dir"
2885 mkdir $dir && change_project -sp 1 $dir
2886 local used=$(getquota -p 1 global curinodes)
2887 [ $used != "1" ] && error "expected 1 got $used"
2892 used=$(getquota -p 1 global curinodes)
2893 [ $used != "4" ] && error "expected 4 got $used"
2895 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2897 cp $DIR/$tdir/6 $dir/6
2898 used=$(getquota -p 1 global curinodes)
2899 [ $used != "5" ] && error "expected 5 got $used"
2902 mv $DIR/$tdir/6 $dir/7
2903 used=$(getquota -p 1 global curinodes)
2904 [ $used != "6" ] && error "expected 6 got $used"
2909 run_test 51 "Test project accounting with mv/cp"
2912 ! is_project_quota_supported &&
2913 skip "Project quota is not supported"
2914 setup_quota_test || error "setup quota failed with $?"
2915 local dir="$DIR/$tdir/dir"
2916 mkdir $dir && change_project -sp 1 $dir
2918 touch $DIR/$tdir/file
2919 #Try renaming a file into the project. This should fail.
2920 for num in $(seq 1 2000); do
2921 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2922 error "rename should fail"
2927 run_test 52 "Rename across different project ID"
2930 ! is_project_quota_supported &&
2931 skip "Project quota is not supported"
2932 setup_quota_test || error "setup quota failed with $?"
2933 local dir="$DIR/$tdir/dir"
2934 mkdir $dir && change_project -s $dir
2935 lfs project -d $dir | grep P || error "inherit attribute should be set"
2937 change_project -C $dir
2938 lfs project -d $dir | grep P &&
2939 error "inherit attribute should be cleared"
2944 run_test 53 "Project inherit attribute could be cleared"
2947 ! is_project_quota_supported &&
2948 skip "Project quota is not supported"
2949 setup_quota_test || error "setup quota failed with $?"
2950 trap cleanup_quota_test EXIT
2951 local testfile="$DIR/$tdir/$tfile-0"
2953 #set project ID/inherit attribute
2954 change_project -sp $TSTPRJID $DIR/$tdir
2955 $RUNAS createmany -m ${testfile} 100 ||
2956 error "create many files failed"
2958 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2959 # one more count for directory itself */
2963 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2964 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2966 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2967 [ $proj_count1 -eq $proj_count ] ||
2968 error "c2: expected $proj_count got $proj_count1"
2970 #clear project but with kept projid
2971 change_project -rCk $DIR/$tdir
2972 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2973 [ $proj_count1 -eq $proj_count ] ||
2974 error "c3: expected $proj_count got $proj_count1"
2976 #verify projid untouched.
2977 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2979 [ $proj_count1 -eq $proj_count ] ||
2980 error "c4: expected $proj_count got $proj_count1"
2983 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2984 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2985 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2987 #this time clear all
2988 change_project -rC $DIR/$tdir
2989 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2990 [ $proj_count1 -eq 0 ] ||
2991 error "c6: expected 0 got $proj_count1"
2993 unlinkmany ${testfile} 100 ||
2994 error "unlink many files failed"
2998 run_test 54 "basic lfs project interface test"
3001 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3002 skip "Not supported before 2.10.58."
3003 setup_quota_test || error "setup quota failed with $?"
3005 set_ost_qtype $QTYPE || error "enable ost quota failed"
3008 #add second group to TSTUSR
3009 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3012 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3013 error "failed to dd"
3015 cancel_lru_locks osc
3016 sync; sync_all_data || true
3018 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3019 error "failed to setquota on group $TSTUSR2"
3021 $LFS quota -v -g $TSTUSR2 $DIR
3023 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3024 error "chgrp should failed with -EDQUOT"
3026 USED=$(getquota -g $TSTUSR2 global curspace)
3029 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3030 error "failed to setquota on group $TSTUSR2"
3032 $LFS quota -v -g $TSTUSR2 $DIR
3034 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3035 error "chgrp should succeed"
3037 $LFS quota -v -g $TSTUSR2 $DIR
3039 resetquota -g $TSTUSR2
3042 run_test 55 "Chgrp should be affected by group quota"
3045 setup_quota_test || error "setup quota failed with $?"
3047 set_ost_qtype $QTYPE || error "enable ost quota failed"
3050 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3051 erro "failed to set grace time for usr quota"
3052 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3053 awk '{print $4 $8}')
3054 if [ "x$grace_time" != "x10s;10s" ]; then
3055 $LFS quota -t -u $DIR
3056 error "expected grace time: 10s;10s, got:$grace_time"
3061 run_test 56 "lfs quota -t should work well"
3064 setup_quota_test || error "setup quota failed with $?"
3066 local dir="$DIR/$tdir/dir"
3069 #try to change pipe file should not hang and return failure
3070 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3071 awk -F ':' '{ print \\\$2 }'" \
3072 " failed to get xattr for '$dir/pipe'" || return 1
3073 #command can process further if it hit some errors
3074 touch $dir/aaa $dir/bbb
3075 mkdir $dir/subdir -p
3076 touch $dir/subdir/aaa $dir/subdir/bbb
3077 #create one invalid link file
3078 ln -s $dir/not_exist_file $dir/ccc
3079 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3080 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3084 run_test 57 "lfs project could tolerate errors"
3087 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3088 skip "ldiskfs only test"
3089 disable_project_quota
3090 setup_quota_test || error "setup quota failed with $?"
3093 local testfile="$DIR/$tdir/$tfile-0"
3094 #make sure it did not crash kernel
3095 touch $testfile && lfs project -sp 1 $testfile
3097 enable_project_quota
3100 run_test 59 "lfs project dosen't crash kernel with project disabled"
3103 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3104 skip "Needs MDS version 2.11.53 or later."
3105 setup_quota_test || error "setup quota failed with $?"
3106 trap cleanup_quota_test EXIT
3108 local testfile=$DIR/$tdir/$tfile
3111 set_mdt_qtype "ug" || error "enable mdt quota failed"
3113 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3114 error "set quota failed"
3115 quota_show_check a g $TSTUSR
3117 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3118 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3119 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3120 error "create many files failed"
3122 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3124 # root user can overrun quota
3125 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3126 error "root user should succeed"
3129 resetquota -g $TSTUSR
3131 run_test 60 "Test quota for root with setgid"
3133 # test default quota
3134 test_default_quota() {
3135 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3136 skip "Not supported before 2.11.51."
3141 local qprjid=$TSTPRJID
3145 local LIMIT=20480 #20M disk space
3146 local TESTFILE="$DIR/$tdir/$tfile-0"
3148 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3149 echo "Project quota is not supported" && return 0
3151 [ $qtype == "-u" ] && qdtype="-U"
3152 [ $qtype == "-g" ] && qdtype="-G"
3153 [ $qtype == "-p" ] && {
3158 [ $qpool == "meta" ] && {
3159 LIMIT=10240 #10K inodes
3164 setup_quota_test || error "setup quota failed with $?"
3165 trap cleanup_quota_test EXIT
3169 # enable mdt/ost quota
3170 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3171 set_ost_qtype $QTYPE || error "enable ost quota failed"
3173 log "set to use default quota"
3174 $LFS setquota $qtype $qid -d $DIR ||
3175 error "set $qid to use default quota failed"
3177 log "set default quota"
3178 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3179 error "set $qid default quota failed"
3181 log "get default quota"
3182 $LFS quota $qdtype $DIR || error "get default quota failed"
3184 if [ $qpool == "data" ]; then
3185 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3187 [ $SLIMIT -eq $LIMIT ] ||
3188 error "the returned default quota is wrong"
3190 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3192 [ $SLIMIT -eq $LIMIT ] ||
3193 error "the returned default quota is wrong"
3196 # make sure the system is clean
3197 local USED=$(getquota $qtype $qid global curspace)
3198 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3200 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3201 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3203 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3205 log "Test not out of quota"
3206 if [ $qpool == "data" ]; then
3207 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3208 quota_error $qtype $qid "write failed, expect succeed"
3210 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3211 quota_error $qtype $qid "create failed, expect succeed"
3213 unlinkmany $TESTFILE $((LIMIT/2))
3216 log "Test out of quota"
3217 # flush cache, ensure noquota flag is set on client
3218 cancel_lru_locks osc
3219 cancel_lru_locks mdc
3220 sync; sync_all_data || true
3221 if [ $qpool == "data" ]; then
3222 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3223 quota_error $qtype $qid "write succeed, expect EDQUOT"
3225 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3226 quota_error $qtype $qid "create succeed, expect EDQUOT"
3228 unlinkmany $TESTFILE $((LIMIT*2))
3231 log "Increase default quota"
3232 # increase default quota
3233 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3234 error "set default quota failed"
3236 cancel_lru_locks osc
3237 cancel_lru_locks mdc
3238 sync; sync_all_data || true
3239 if [ $qpool == "data" ]; then
3240 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3241 quota_error $qtype $qid "write failed, expect succeed"
3243 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3244 quota_error $qtype $qid "create failed, expect succeed"
3246 unlinkmany $TESTFILE $((LIMIT*2))
3249 log "Set quota to override default quota"
3250 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3251 error "set $qid quota failed"
3253 cancel_lru_locks osc
3254 cancel_lru_locks mdc
3255 sync; sync_all_data || true
3256 if [ $qpool == "data" ]; then
3257 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3258 quota_error $qtype $qid "write succeed, expect EQUOT"
3260 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3261 quota_error $qtype $qid "create succeed, expect EQUOT"
3263 unlinkmany $TESTFILE $((LIMIT*2))
3266 log "Set to use default quota again"
3267 $LFS setquota $qtype $qid -d $DIR ||
3268 error "set $qid to use default quota failed"
3270 cancel_lru_locks osc
3271 cancel_lru_locks mdc
3272 sync; sync_all_data || true
3273 if [ $qpool == "data" ]; then
3274 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3275 quota_error $qtype $qid "write failed, expect succeed"
3277 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3278 quota_error $qtype $qid "create failed, expect succeed"
3280 unlinkmany $TESTFILE $((LIMIT*2))
3285 wait_delete_completed || error "wait_delete_completed failed"
3286 sync_all_data || true
3287 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3288 error "reset default quota failed"
3289 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3290 error "reset quota failed"
3296 test_default_quota "-u" "data"
3297 test_default_quota "-u" "meta"
3298 test_default_quota "-g" "data"
3299 test_default_quota "-g" "meta"
3300 test_default_quota "-p" "data"
3301 test_default_quota "-p" "meta"
3303 run_test 61 "default quota tests"
3306 ! is_project_quota_supported &&
3307 skip "Project quota is not supported"
3308 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3309 skip "chattr did not support project quota"
3310 setup_quota_test || error "setup quota failed with $?"
3311 local testdir=$DIR/$tdir/
3313 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3314 change_project -s $testdir
3315 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3316 error "inherit attribute should be set"
3317 # chattr used FS_IOC_SETFLAGS ioctl
3318 $RUNAS chattr -P $testdir &&
3319 error "regular user clear inherit should fail"
3320 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3321 error "inherit attribute should still be set"
3322 chattr -P $testdir || error "root failed to clear inherit"
3323 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3324 error "inherit attribute should be cleared"
3327 run_test 62 "Project inherit should be only changed by root"
3330 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3331 skip "Not supported before 2.11.55" && return
3335 local dd_failed=false
3336 local tdir_dom=${tdir}_dom
3337 local LIMIT=20480 #20M
3339 [ $qtype == "p" ] && ! is_project_quota_supported &&
3340 echo "Project quota is not supported" && return 0
3342 [ $qtype == "p" ] && qid=$TSTPRJID
3344 setup_quota_test || error "setup quota failed with $?"
3345 trap cleanup_quota_test EXIT
3349 # enable mdt/ost quota
3350 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3351 set_ost_qtype $QTYPE || error "enable ost quota failed"
3353 # make sure the system is clean
3354 local USED=$(getquota -$qtype $qid global curspace)
3355 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3357 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3359 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3360 $SETSTRIPE -E 1M -L mdt $DIR/$tdir_dom ||
3361 error "setstripe $tdir_dom failed"
3362 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3364 [ $qtype == "p" ] && {
3365 change_project -sp $TSTPRJID $DIR/$tdir
3366 change_project -sp $TSTPRJID $DIR/$tdir_dom
3369 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3370 error "set $qid quota failed"
3372 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3373 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3377 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3379 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3380 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3384 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3386 rm -f $DIR/$tdir_dom/*
3388 # flush cache, ensure noquota flag is set on client
3389 cancel_lru_locks osc
3390 cancel_lru_locks mdc
3391 sync; sync_all_data || true
3395 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3396 quota_error $qtype $qid "write failed, expect succeed"
3398 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3399 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3403 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3406 rm -f $DIR/$tdir_dom/*
3408 # flush cache, ensure noquota flag is set on client
3409 cancel_lru_locks osc
3410 cancel_lru_locks mdc
3411 sync; sync_all_data || true
3415 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3416 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3420 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3422 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3423 quota_error $qtype $qid "write succeed, expect EDQUOT"
3426 rm -fr $DIR/$tdir_dom
3428 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3429 error "reset usr quota failed"
3439 run_test 63 "quota on DoM tests"
3443 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3444 disable_project_quota
3446 reset_quota_settings
3451 check_and_cleanup_lustre
3452 export QUOTA_AUTO=$QUOTA_AUTO_OLD