3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test: LU-6836
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 4a"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 $ZPOOL upgrade -v | grep project_quota && return 0
94 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
95 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
96 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
97 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
98 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
99 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
100 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
101 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
108 local fail_val=${3:-0}
112 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
113 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
114 ost) NODES="$(comma_list $(osts_nodes))";;
117 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
122 echo "lfs project $*"
123 lfs project $* || error "lfs project $* failed"
126 RUNAS="runas -u $TSTID -g $TSTID"
127 RUNAS2="runas -u $TSTID2 -g $TSTID2"
128 DD="dd if=/dev/zero bs=1M"
132 # clear quota limits for a user or a group
133 # usage: resetquota -u username
134 # resetquota -g groupname
135 # resetquota -p projid
138 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
139 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
140 error "resetquota: wrong specifier $1 passed"
142 if [ $1 == "-p" ]; then
143 is_project_quota_supported || return 0
146 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
147 error "clear quota for [type:$1 name:$2] failed"
148 # give a chance to slave to release space
156 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
157 $LFS quota -v -u $local_id $DIR
158 log "Files for user ($local_id):"
159 ($LFS find --user $local_id $DIR | head -n 4 |
160 xargs stat 2>/dev/null)
163 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
164 $LFS quota -v -g $local_id $DIR
165 log "Files for group ($local_id):"
166 ($LFS find --group $local_id $DIR | head -n 4 |
167 xargs stat 2>/dev/null)
170 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
171 $LFS quota -v -p $TSTPRJID $DIR
172 log "Files for project ($TSTPRJID):"
173 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
174 xargs stat 2>/dev/null)
190 # get quota for a user or a group
191 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
192 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
197 sync_all_data > /dev/null 2>&1 || true
199 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
200 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
201 error "getquota: wrong u/g/p specifier $1 passed"
214 *) error "unknown quota parameter $4";;
217 [ "$uuid" = "global" ] && uuid=$DIR
219 $LFS quota -v "$1" "$2" $DIR |
220 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
221 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
226 # usage: set_mdt_qtype ugp|u|g|p|none
230 local mdts=$(get_facets MDS)
232 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
233 qtype=$(tr -d 'p' <<<$qtype)
235 if [[ $PERM_CMD == *"set_param -P"* ]]; then
236 do_facet mgs $PERM_CMD \
237 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
239 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
241 # we have to make sure each MDT received config changes
242 for mdt in ${mdts//,/ }; do
244 cmd="$LCTL get_param -n "
245 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
246 cmd=${cmd}.quota_slave.enabled
248 if $(facet_up $mdt); then
249 wait_update_facet $mdt "$cmd" "$qtype" || return 1
256 # usage: set_ost_qtype ugp|u|g|p|none
260 local osts=$(get_facets OST)
262 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
263 qtype=$(tr -d 'p' <<<$qtype)
265 if [[ $PERM_CMD == *"set_param -P"* ]]; then
266 do_facet mgs $PERM_CMD \
267 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
269 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
271 # we have to make sure each OST received config changes
272 for ost in ${osts//,/ }; do
274 cmd="$LCTL get_param -n "
275 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
276 cmd=${cmd}.quota_slave.enabled
278 if $(facet_up $ost); then
279 wait_update_facet $ost "$cmd" "$qtype" || return 1
285 wait_reintegration() {
289 local result="glb[1],slv[1],reint[0]"
294 if [ $ntype == "mdt" ]; then
295 tgts=$(get_facets MDS)
297 tgts=$(get_facets OST)
300 for tgt in ${tgts//,/ }; do
302 cmd="$LCTL get_param -n "
303 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
304 cmd=${cmd}.quota_slave.info
306 if $(facet_up $tgt); then
307 wait_update_facet $tgt "$cmd |
308 grep "$qtype" | awk '{ print \\\$3 }'" \
309 "$result" $max || return 1
319 if [[ "$qtype" =~ "u" ]]; then
320 wait_reintegration "mdt" "user" $max || return 1
323 if [[ "$qtype" =~ "g" ]]; then
324 wait_reintegration "mdt" "group" $max || return 1
327 if [[ "$qtype" =~ "p" ]]; then
328 ! is_project_quota_supported && return 0
329 wait_reintegration "mdt" "project" $max || return 1
338 if [[ "$qtype" =~ "u" ]]; then
339 wait_reintegration "ost" "user" $max || return 1
342 if [[ "$qtype" =~ "g" ]]; then
343 wait_reintegration "ost" "group" $max || return 1
346 if [[ "$qtype" =~ "p" ]]; then
347 ! is_project_quota_supported && return 0
348 wait_reintegration "ost" "project" $max || return 1
353 disable_project_quota() {
354 is_project_quota_supported || return 0
355 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
356 stopall || error "failed to stopall (1)"
358 for num in $(seq $MDSCOUNT); do
359 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
360 error "tune2fs $(mdsdevname $num) failed"
363 for num in $(seq $OSTCOUNT); do
364 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
365 error "tune2fs $(ostdevname $num) failed"
373 wait_delete_completed
374 echo "Creating test directory"
375 mkdir $DIR/$tdir || return 1
376 chmod 0777 $DIR/$tdir || return 2
377 # always clear fail_loc in case of fail_loc isn't cleared
378 # properly when previous test failed
379 lustre_fail mds_ost 0
382 cleanup_quota_test() {
384 echo "Delete files..."
386 echo "Wait for unlink objects finished..."
387 wait_delete_completed
388 sync_all_data || true
397 $LFS quota -v -$ugp $qid $DIR
399 if [ "$bf" == "a" -o "$bf" == "b" ]; then
400 usage=$(getquota -$ugp $qid global curspace)
401 if [ -z $usage ]; then
402 quota_error $ugp $qid \
403 "Query block quota failed ($ugp:$qid)."
405 [ $usage -ne 0 ] && quota_log $ugp $qid \
406 "Block quota isn't 0 ($ugp:$qid:$usage)."
410 if [ "$bf" == "a" -o "$bf" == "f" ]; then
411 usage=$(getquota -$ugp $qid global curinodes)
412 if [ -z $usage ]; then
413 quota_error $ugp $qid \
414 "Query file quota failed ($ugp:$qid)."
416 [ $usage -ne 0 ] && quota_log $ugp $qid \
417 "File quota isn't 0 ($ugp:$qid:$usage)."
422 enable_project_quota() {
423 is_project_quota_supported || return 0
424 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
425 stopall || error "failed to stopall (1)"
427 for num in $(seq $MDSCOUNT); do
428 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
429 error "tune2fs $(mdsdevname $num) failed"
432 for num in $(seq $OSTCOUNT); do
433 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
434 error "tune2fs $(ostdevname $num) failed"
441 project_quota_enabled () {
443 for num in $(seq $MDSCOUNT); do
444 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
445 grep -q project || rc=1
447 for num in $(seq $OSTCOUNT); do
448 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
449 grep -q project || rc=1
451 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
455 project_quota_enabled || enable_project_quota
457 reset_quota_settings() {
458 resetquota -u $TSTUSR
459 resetquota -g $TSTUSR
460 resetquota -u $TSTUSR2
461 resetquota -g $TSTUSR2
462 resetquota -p $TSTPRJID
467 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
472 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
473 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
474 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
475 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
477 test_quota_performance() {
478 local TESTFILE="$DIR/$tdir/$tfile-0"
479 local size=$1 # in MB
480 local stime=$(date +%s)
481 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
482 quota_error u $TSTUSR "write failure"
483 local etime=$(date +%s)
484 delta=$((etime - stime))
485 if [ $delta -gt 0 ]; then
486 rate=$((size * 1024 / delta))
487 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
488 # LU-2872 - see LU-2887 for fix
490 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
492 [ $rate -gt 1024 ] ||
493 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
499 # test basic quota performance b=21696
502 [ "$SLOW" = "no" ] && MB=10
504 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
505 [ $free_space -le $((MB * 1024)) ] &&
506 skip "not enough space ${free_space} KB, " \
507 "required $((MB * 1024)) KB"
508 setup_quota_test || error "setup quota failed with $?"
509 trap cleanup_quota_test EXIT
511 set_ost_qtype "none" || error "disable ost quota failed"
512 test_quota_performance $MB
514 set_ost_qtype $QTYPE || error "enable ost quota failed"
515 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
516 error "set quota failed"
517 test_quota_performance $MB
520 resetquota -u $TSTUSR
522 run_test 0 "Test basic quota performance"
524 # test block hardlimit
527 local TESTFILE="$DIR/$tdir/$tfile-0"
529 setup_quota_test || error "setup quota failed with $?"
530 trap cleanup_quota_test EXIT
533 set_ost_qtype $QTYPE || error "enable ost quota failed"
536 log "User quota (block hardlimit:$LIMIT MB)"
537 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
538 error "set user quota failed"
540 # make sure the system is clean
541 local USED=$(getquota -u $TSTUSR global curspace)
542 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
544 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
545 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
548 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
549 quota_error u $TSTUSR "user write failure, but expect success"
550 log "Write out of block quota ..."
551 # this time maybe cache write, ignore it's failure
552 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
553 # flush cache, ensure noquota flag is set on client
555 sync; sync_all_data || true
556 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
557 quota_error u $TSTUSR "user write success, but expect EDQUOT"
560 wait_delete_completed || error "wait_delete_completed failed"
561 sync_all_data || true
562 USED=$(getquota -u $TSTUSR global curspace)
563 [ $USED -ne 0 ] && quota_error u $TSTUSR \
564 "user quota isn't released after deletion"
565 resetquota -u $TSTUSR
568 log "--------------------------------------"
569 log "Group quota (block hardlimit:$LIMIT MB)"
570 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
571 error "set group quota failed"
573 TESTFILE="$DIR/$tdir/$tfile-1"
574 # make sure the system is clean
575 USED=$(getquota -g $TSTUSR global curspace)
576 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
578 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
579 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
582 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
583 quota_error g $TSTUSR "Group write failure, but expect success"
584 log "Write out of block quota ..."
585 # this time maybe cache write, ignore it's failure
586 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
588 sync; sync_all_data || true
589 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
590 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
592 wait_delete_completed || error "wait_delete_completed failed"
593 sync_all_data || true
594 USED=$(getquota -g $TSTUSR global curspace)
595 [ $USED -ne 0 ] && quota_error g $TSTUSR \
596 "Group quota isn't released after deletion"
597 resetquota -g $TSTUSR
599 if ! is_project_quota_supported; then
600 echo "Project quota is not supported"
605 TESTFILE="$DIR/$tdir/$tfile-2"
606 # make sure the system is clean
607 USED=$(getquota -p $TSTPRJID global curspace)
609 error "used space($USED) for project $TSTPRJID isn't 0"
612 log "--------------------------------------"
613 log "Project quota (block hardlimit:$LIMIT mb)"
614 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
615 error "set project quota failed"
617 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
618 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
619 change_project -p $TSTPRJID $TESTFILE
622 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
623 "project write failure, but expect success"
624 log "write out of block quota ..."
625 # this time maybe cache write, ignore it's failure
626 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
628 sync; sync_all_data || true
629 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
630 $TSTPRJID "project write success, but expect EDQUOT"
635 USED=$(getquota -p $TSTPRJID global curspace)
636 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
637 "project quota isn't released after deletion"
639 resetquota -p $TSTPRJID
641 run_test 1 "Block hard limit (normal use and out of quota)"
643 # test inode hardlimit
645 local LIMIT=$((1024 * 1024)) # 1M inodes
646 local TESTFILE="$DIR/$tdir/$tfile-0"
648 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
650 local FREE_INODES=$(mdt_free_inodes 0)
651 echo "$FREE_INODES free inodes on master MDT"
652 [ $FREE_INODES -lt $LIMIT ] &&
653 skip "not enough free inodes $FREE_INODES required $LIMIT"
655 setup_quota_test || error "setup quota failed with $?"
656 trap cleanup_quota_test EXIT
659 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
662 log "User quota (inode hardlimit:$LIMIT files)"
663 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
664 error "set user quota failed"
666 # make sure the system is clean
667 local USED=$(getquota -u $TSTUSR global curinodes)
668 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
670 log "Create $LIMIT files ..."
671 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
672 quota_error u $TSTUSR "user create failure, but expect success"
673 log "Create out of file quota ..."
674 $RUNAS touch ${TESTFILE}_xxx &&
675 quota_error u $TSTUSR "user create success, but expect EDQUOT"
678 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
679 rm -f ${TESTFILE}_xxx
680 wait_delete_completed
682 USED=$(getquota -u $TSTUSR global curinodes)
683 [ $USED -ne 0 ] && quota_error u $TSTUSR \
684 "user quota isn't released after deletion"
685 resetquota -u $TSTUSR
688 log "--------------------------------------"
689 log "Group quota (inode hardlimit:$LIMIT files)"
690 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
691 error "set group quota failed"
693 TESTFILE=$DIR/$tdir/$tfile-1
694 # make sure the system is clean
695 USED=$(getquota -g $TSTUSR global curinodes)
696 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
698 log "Create $LIMIT files ..."
699 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
700 quota_error g $TSTUSR "group create failure, but expect success"
701 log "Create out of file quota ..."
702 $RUNAS touch ${TESTFILE}_xxx &&
703 quota_error g $TSTUSR "group create success, but expect EDQUOT"
706 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
707 rm -f ${TESTFILE}_xxx
708 wait_delete_completed
710 USED=$(getquota -g $TSTUSR global curinodes)
711 [ $USED -ne 0 ] && quota_error g $TSTUSR \
712 "user quota isn't released after deletion"
714 resetquota -g $TSTUSR
715 ! is_project_quota_supported && cleanup_quota_test &&
716 echo "Skip project quota is not supported" && return 0
719 log "--------------------------------------"
720 log "Project quota (inode hardlimit:$LIMIT files)"
721 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
722 error "set project quota failed"
724 TESTFILE=$DIR/$tdir/$tfile-1
725 # make sure the system is clean
726 USED=$(getquota -p $TSTPRJID global curinodes)
728 error "Used inodes($USED) for project $TSTPRJID isn't 0"
730 change_project -sp $TSTPRJID $DIR/$tdir
731 log "Create $LIMIT files ..."
732 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
733 $TSTPRJID "project create fail, but expect success"
734 log "Create out of file quota ..."
735 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
736 "project create success, but expect EDQUOT"
737 change_project -C $DIR/$tdir
740 USED=$(getquota -p $TSTPRJID global curinodes)
741 [ $USED -ne 0 ] && quota_error p $TSTPRJID \
742 "project quota isn't released after deletion"
744 resetquota -p $TSTPRJID
747 run_test 2 "File hard limit (normal use and out of quota)"
751 local TIMER=$(($2 * 3 / 2))
757 trap cleanup_quota_test EXIT
759 $LFS setstripe $TESTFILE -c 1 -i 0
760 chown $TSTUSR.$TSTUSR $TESTFILE
761 [ "$qtype" == "p" ] && is_project_quota_supported &&
762 change_project -p $TSTPRJID $TESTFILE
764 echo "Write up to soft limit"
765 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
766 quota_error a $TSTUSR "write failure, but expect success"
767 OFFSET=$((LIMIT * 1024))
770 echo "Write to exceed soft limit"
771 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
772 quota_error a $TSTUSR "write failure, but expect success"
773 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
779 $SHOW_QUOTA_INFO_USER
780 $SHOW_QUOTA_INFO_GROUP
781 $SHOW_QUOTA_INFO_PROJID
783 echo "Write before timer goes off"
784 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
785 quota_error a $TSTUSR "write failure, but expect success"
786 OFFSET=$((OFFSET + 1024))
789 echo "Sleep $TIMER seconds ..."
795 $SHOW_QUOTA_INFO_USER
796 $SHOW_QUOTA_INFO_GROUP
797 $SHOW_QUOTA_INFO_PROJID
799 echo "Write after timer goes off"
800 # maybe cache write, ignore.
801 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
802 OFFSET=$((OFFSET + 1024))
804 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
805 quota_error a $TSTUSR "write success, but expect EDQUOT"
810 $SHOW_QUOTA_INFO_USER
811 $SHOW_QUOTA_INFO_GROUP
812 $SHOW_QUOTA_INFO_PROJID
814 echo "Unlink file to stop timer"
816 wait_delete_completed
817 sync_all_data || true
822 $SHOW_QUOTA_INFO_USER
823 $SHOW_QUOTA_INFO_GROUP
824 $SHOW_QUOTA_INFO_PROJID
826 $LFS setstripe $TESTFILE -c 1 -i 0
827 chown $TSTUSR.$TSTUSR $TESTFILE
828 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
831 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
832 quota_error a $TSTUSR "write failure, but expect success"
841 local TESTFILE=$DIR/$tdir/$tfile-0
843 set_ost_qtype $QTYPE || error "enable ost quota failed"
845 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
846 # make sure the system is clean
847 local USED=$(getquota -u $TSTUSR global curspace)
848 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
850 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
851 $MAX_IQ_TIME $DIR || error "set user grace time failed"
852 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
853 error "set user quota failed"
855 test_block_soft $TESTFILE $GRACE $LIMIT "u"
856 resetquota -u $TSTUSR
858 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
859 TESTFILE=$DIR/$tdir/$tfile-1
860 # make sure the system is clean
861 USED=$(getquota -g $TSTUSR global curspace)
862 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
864 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
865 $MAX_IQ_TIME $DIR || error "set group grace time failed"
866 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
867 error "set group quota failed"
869 test_block_soft $TESTFILE $GRACE $LIMIT "g"
870 resetquota -g $TSTUSR
872 if is_project_quota_supported; then
873 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
874 TESTFILE=$DIR/$tdir/$tfile-2
875 # make sure the system is clean
876 USED=$(getquota -p $TSTPRJID global curspace)
877 [ $USED -ne 0 ] && error \
878 "Used space($USED) for project $TSTPRJID isn't 0."
880 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
882 error "set project grace time failed"
883 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
884 $DIR || error "set project quota failed"
886 test_block_soft $TESTFILE $GRACE $LIMIT "p"
887 resetquota -p $TSTPRJID
888 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
890 error "restore project grace time failed"
894 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
895 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
896 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
897 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
899 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
905 local TIMER=$(($grace * 3 / 2))
908 trap cleanup_quota_test EXIT
909 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
911 echo "Create files to exceed soft limit"
912 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
913 quota_error a $TSTUSR "create failure, but expect success"
914 local trigger_time=$(date +%s)
916 sync_all_data || true
918 local cur_time=$(date +%s)
919 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
920 error "Passed grace time $grace, $trigger_time, $cur_time"
922 echo "Create file before timer goes off"
923 $RUNAS touch ${TESTFILE}_before ||
924 quota_error a $TSTUSR "failed create before timer expired," \
925 "but expect success. $trigger_time, $cur_time"
926 sync_all_data || true
928 echo "Sleep $TIMER seconds ..."
934 $SHOW_QUOTA_INFO_USER
935 $SHOW_QUOTA_INFO_GROUP
936 $SHOW_QUOTA_INFO_PROJID
938 echo "Create file after timer goes off"
939 # There is a window that space is accounted in the quota usage but
940 # hasn't been decreased from the pending write, if we acquire quota
941 # in this window, we'll acquire more than we needed.
942 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
943 sync_all_data || true
944 $RUNAS touch ${TESTFILE}_after_3 &&
945 quota_error a $TSTUSR "create after timer expired," \
947 sync_all_data || true
952 $SHOW_QUOTA_INFO_USER
953 $SHOW_QUOTA_INFO_GROUP
954 $SHOW_QUOTA_INFO_PROJID
956 echo "Unlink files to stop timer"
957 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
958 wait_delete_completed
961 $RUNAS touch ${TESTFILE}_xxx ||
962 quota_error a $TSTUSR "touch after timer stop failure," \
964 sync_all_data || true
972 local LIMIT=10 # inodes
973 local TESTFILE=$DIR/$tdir/$tfile-0
976 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
978 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
979 # make sure the system is clean
980 local USED=$(getquota -u $TSTUSR global curinodes)
981 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
983 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
984 $GRACE $DIR || error "set user grace time failed"
985 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
986 error "set user quota failed"
988 test_file_soft $TESTFILE $LIMIT $GRACE
989 resetquota -u $TSTUSR
991 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
992 # make sure the system is clean
993 USED=$(getquota -g $TSTUSR global curinodes)
994 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
996 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
997 $GRACE $DIR || error "set group grace time failed"
998 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
999 error "set group quota failed"
1000 TESTFILE=$DIR/$tdir/$tfile-1
1002 test_file_soft $TESTFILE $LIMIT $GRACE
1003 resetquota -g $TSTUSR
1005 if is_project_quota_supported; then
1006 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1007 # make sure the system is clean
1008 USED=$(getquota -p $TSTPRJID global curinodes)
1009 [ $USED -ne 0 ] && error \
1010 "Used space($USED) for project $TSTPRJID isn't 0."
1012 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1013 $GRACE $DIR || error "set project grace time failed"
1014 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1015 error "set project quota failed"
1017 TESTFILE=$DIR/$tdir/$tfile-1
1018 # one less than limit, because of parent directory included.
1019 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1020 resetquota -p $TSTPRJID
1021 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1022 $MAX_IQ_TIME $DIR ||
1023 error "restore project grace time failed"
1027 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1028 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1029 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1030 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1032 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1035 local GR_STR1="1w3d"
1036 local GR_STR2="1000s"
1038 local GR_STR4="1w2d3h4m5s"
1040 local GR_STR6="18446744073709551615"
1043 wait_delete_completed
1045 # test of valid grace strings handling
1046 echo "Valid grace strings test"
1047 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1048 $GR_STR2 $DIR || error "set user grace time failed"
1049 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1050 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1051 $GR_STR4 $DIR || error "set group grace time quota failed"
1052 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1054 # test of invalid grace strings handling
1055 echo " Invalid grace strings test"
1056 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1057 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1058 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1062 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1063 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1064 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1065 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1067 run_test 4b "Grace time strings handling"
1069 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1071 local BLIMIT=10 # 10M
1072 local ILIMIT=10 # 10 inodes
1074 setup_quota_test || error "setup quota failed with $?"
1075 trap cleanup_quota_test EXIT
1077 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1078 set_ost_qtype $QTYPE || error "enable ost quota failed"
1080 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1081 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1082 error "set user quota failed"
1083 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1084 if is_project_quota_supported; then
1085 error "set group quota failed"
1086 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1087 -I $ILIMIT $DIR || error "set project quota failed"
1090 # make sure the system is clean
1091 local USED=$(getquota -u $TSTUSR global curinodes)
1092 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1093 USED=$(getquota -g $TSTUSR global curinodes)
1094 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1095 USED=$(getquota -u $TSTUSR global curspace)
1096 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1097 USED=$(getquota -g $TSTUSR global curspace)
1098 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1099 if is_project_quota_supported; then
1100 USED=$(getquota -p $TSTPRJID global curinodes)
1102 error "Used inode($USED) for project $TSTPRJID isn't 0."
1103 USED=$(getquota -p $TSTPRJID global curspace)
1105 error "Used block($USED) for project $TSTPRJID isn't 0."
1108 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1109 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1110 error "create failure, expect success"
1111 if is_project_quota_supported; then
1112 touch $DIR/$tdir/$tfile-0_1
1113 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1115 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1116 error "write failure, expect success"
1118 echo "Chown files to $TSTUSR.$TSTUSR ..."
1119 for i in $(seq 0 $ILIMIT); do
1120 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1121 quota_error a $TSTUSR "chown failure, expect success"
1125 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1126 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1129 resetquota -u $TSTUSR
1130 resetquota -g $TSTUSR
1131 resetquota -p $TSTPRJID
1133 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1135 # test dropping acquire request on master
1139 # Clear dmesg so watchdog is not triggered by previous
1141 do_facet ost1 dmesg -c > /dev/null
1143 setup_quota_test || error "setup quota failed with $?"
1144 trap cleanup_quota_test EXIT
1146 # make sure the system is clean
1147 local USED=$(getquota -u $TSTUSR global curspace)
1148 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1150 # make sure no granted quota on ost
1151 set_ost_qtype $QTYPE || error "enable ost quota failed"
1152 resetquota -u $TSTUSR
1154 # create file for $TSTUSR
1155 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1156 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1157 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1159 # create file for $TSTUSR2
1160 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1161 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1162 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1164 # cache per-ID lock for $TSTUSR on slave
1165 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1166 error "set quota failed"
1167 $RUNAS $DD of=$TESTFILE count=1 ||
1168 error "write $TESTFILE failure, expect success"
1169 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1170 error "write $TESTFILE2 failure, expect success"
1172 sync_all_data || true
1174 #define QUOTA_DQACQ 601
1175 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1176 lustre_fail mds 0x513 601
1178 # write to un-enforced ID ($TSTUSR2) should succeed
1179 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1180 error "write failure, expect success"
1182 # write to enforced ID ($TSTUSR) in background, exceeding limit
1183 # to make sure DQACQ is sent
1184 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1187 # watchdog timer uses a factor of 2
1188 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1189 sleep $((TIMEOUT * 2 + 1))
1191 # write should be blocked and never finished
1192 if ! ps -p $DDPID > /dev/null 2>&1; then
1194 error "write finished incorrectly!"
1199 # no watchdog is triggered
1200 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1201 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1202 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1203 [ -z "$watchdog" ] || error "$watchdog"
1205 rm -f $TMP/lustre-log-${TESTNAME}.log
1207 # write should continue then fail with EDQUOT
1211 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1212 if [ $count -ge 240 ]; then
1213 quota_error u $TSTUSR "dd not finished in $count secs"
1215 count=$((count + 1))
1216 if [ $((count % 30)) -eq 0 ]; then
1217 c_size=$(stat -c %s $TESTFILE)
1218 echo "Waiting $count secs. $c_size"
1225 resetquota -u $TSTUSR
1227 run_test 6 "Test dropping acquire request on master"
1229 # quota reintegration (global index)
1231 local TESTFILE=$DIR/$tdir/$tfile
1232 local LIMIT=20 # 20M
1234 [ "$SLOW" = "no" ] && LIMIT=5
1236 setup_quota_test || error "setup quota failed with $?"
1237 trap cleanup_quota_test EXIT
1239 # make sure the system is clean
1240 local USED=$(getquota -u $TSTUSR global curspace)
1241 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1243 # make sure no granted quota on ost1
1244 set_ost_qtype $QTYPE || error "enable ost quota failed"
1245 resetquota -u $TSTUSR
1246 set_ost_qtype "none" || error "disable ost quota failed"
1248 local OSTUUID=$(ostuuid_from_index 0)
1249 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1251 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1254 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1255 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1260 echo "Enable quota & set quota limit for $TSTUSR"
1261 set_ost_qtype $QTYPE || error "enable ost quota failed"
1262 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1263 error "set quota failed"
1265 echo "Start ost1..."
1266 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1269 wait_ost_reint $QTYPE || error "reintegration failed"
1271 # hardlimit should have been fetched by slave during global
1272 # reintegration, write will exceed quota
1273 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1274 quota_error u $TSTUSR "write success, but expect EDQUOT"
1277 wait_delete_completed
1278 sync_all_data || true
1284 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1285 error "clear quota failed"
1287 echo "Start ost1..."
1288 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1291 wait_ost_reint $QTYPE || error "reintegration failed"
1293 # hardlimit should be cleared on slave during reintegration
1294 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1295 quota_error u $TSTUSR "write error, but expect success"
1298 resetquota -u $TSTUSR
1300 run_test 7a "Quota reintegration (global index)"
1302 # quota reintegration (slave index)
1305 local TESTFILE=$DIR/$tdir/$tfile
1307 setup_quota_test || error "setup quota failed with $?"
1308 trap cleanup_quota_test EXIT
1310 # make sure the system is clean
1311 local USED=$(getquota -u $TSTUSR global curspace)
1312 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1314 # make sure no granted quota on ost1
1315 set_ost_qtype $QTYPE || error "enable ost quota failed"
1316 resetquota -u $TSTUSR
1317 set_ost_qtype "none" || error "disable ost quota failed"
1319 local OSTUUID=$(ostuuid_from_index 0)
1320 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1322 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1325 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1326 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1328 # consume some space to make sure the granted space will not
1329 # be released during reconciliation
1330 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1331 error "consume space failure, expect success"
1333 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1334 lustre_fail mds 0xa02
1336 set_ost_qtype $QTYPE || error "enable ost quota failed"
1337 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1338 error "set quota failed"
1340 # ignore the write error
1341 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1343 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1347 echo "Restart ost to trigger reintegration..."
1349 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1352 wait_ost_reint $QTYPE || error "reintegration failed"
1354 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1355 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1358 resetquota -u $TSTUSR
1361 run_test 7b "Quota reintegration (slave index)"
1363 # quota reintegration (restart mds during reintegration)
1365 local LIMIT=20 # 20M
1366 local TESTFILE=$DIR/$tdir/$tfile
1368 [ "$SLOW" = "no" ] && LIMIT=5
1370 setup_quota_test || error "setup quota failed with $?"
1371 trap cleanup_quota_test EXIT
1373 # make sure the system is clean
1374 local USED=$(getquota -u $TSTUSR global curspace)
1375 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1377 set_ost_qtype "none" || error "disable ost quota failed"
1378 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1379 error "set quota failed"
1381 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1382 lustre_fail ost 0xa03
1385 set_ost_qtype $QTYPE || error "enable ost quota failed"
1386 # trigger reintegration
1387 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1388 procf=${procf}quota_slave.force_reint
1389 do_facet ost1 $LCTL set_param $procf=1 ||
1390 error "force reintegration failed"
1398 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1401 # wait longer than usual to make sure the reintegration
1402 # is triggered by quota wb thread.
1403 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1405 # hardlimit should have been fetched by slave during global
1406 # reintegration, write will exceed quota
1407 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1408 quota_error u $TSTUSR "write success, but expect EDQUOT"
1411 resetquota -u $TSTUSR
1413 run_test 7c "Quota reintegration (restart mds during reintegration)"
1415 # Quota reintegration (Transfer index in multiple bulks)
1417 local TESTFILE=$DIR/$tdir/$tfile
1418 local TESTFILE1="$DIR/$tdir/$tfile"-1
1421 setup_quota_test || error "setup quota failed with $?"
1422 trap cleanup_quota_test EXIT
1424 set_ost_qtype "none" || error "disable ost quota failed"
1425 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1426 error "set quota for $TSTUSR failed"
1427 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1428 error "set quota for $TSTUSR2 failed"
1430 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1431 lustre_fail mds 0x608 0
1433 # enable quota to tirgger reintegration
1434 set_ost_qtype "u" || error "enable ost quota failed"
1435 wait_ost_reint "u" || error "reintegration failed"
1439 # hardlimit should have been fetched by slave during global
1440 # reintegration, write will exceed quota
1441 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1442 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1444 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1445 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1448 resetquota -u $TSTUSR
1449 resetquota -u $TSTUSR2
1451 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1453 # quota reintegration (inode limits)
1455 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1457 # LU-2435: skip this quota test if underlying zfs version has not
1458 # supported native dnode accounting
1459 [ "$(facet_fstype mds1)" == "zfs" ] && {
1460 local F="feature@userobj_accounting"
1461 local pool=$(zpool_name mds1)
1462 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1464 [[ "$feature" != *" active "* ]] &&
1465 skip "requires zpool with active userobj_accounting"
1468 local ilimit=$((1024 * 2)) # 2k inodes
1469 local TESTFILE=$DIR/${tdir}-1/$tfile
1471 setup_quota_test || error "setup quota failed with $?"
1472 trap cleanup_quota_test EXIT
1474 # make sure the system is clean
1475 local USED=$(getquota -u $TSTUSR global curinodes)
1476 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1478 # make sure no granted quota on mdt1
1479 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1480 resetquota -u $TSTUSR
1481 set_mdt_qtype "none" || error "disable mdt quota failed"
1483 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1484 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1485 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1488 echo "Stop mds${MDSCOUNT}..."
1491 echo "Enable quota & set quota limit for $TSTUSR"
1492 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1493 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1494 error "set quota failed"
1496 echo "Start mds${MDSCOUNT}..."
1497 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1500 wait_mdt_reint $QTYPE || error "reintegration failed"
1502 echo "create remote dir"
1503 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1504 error "create remote dir failed"
1505 chmod 0777 $DIR/${tdir}-1
1507 # hardlimit should have been fetched by slave during global
1508 # reintegration, create will exceed quota
1509 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1510 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1512 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1513 wait_delete_completed
1514 sync_all_data || true
1516 echo "Stop mds${MDSCOUNT}..."
1519 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1520 error "clear quota failed"
1522 echo "Start mds${MDSCOUNT}..."
1523 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1526 wait_mdt_reint $QTYPE || error "reintegration failed"
1528 # hardlimit should be cleared on slave during reintegration
1529 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1530 quota_error u $TSTUSR "create failed, expect success"
1532 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1533 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1536 resetquota -u $TSTUSR
1538 run_test 7e "Quota reintegration (inode limits)"
1540 # run dbench with quota enabled
1542 local BLK_LIMIT="100g" #100G
1543 local FILE_LIMIT=1000000
1545 setup_quota_test || error "setup quota failed with $?"
1546 trap cleanup_quota_test EXIT
1548 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1549 set_ost_qtype $QTYPE || error "enable ost quota failed"
1551 echo "Set enough high limit for user: $TSTUSR"
1552 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1553 error "set user quota failed"
1554 echo "Set enough high limit for group: $TSTUSR"
1555 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1556 error "set group quota failed"
1557 if is_project_quota_supported; then
1558 change_project -sp $TSTPRJID $DIR/$tdir
1559 echo "Set enough high limit for project: $TSTPRJID"
1560 $LFS setquota -p $TSTPRJID -b 0 \
1561 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1562 error "set project quota failed"
1566 [ "$SLOW" = "no" ] && duration=" -t 120"
1567 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1568 quota_error a $TSTUSR "dbench failed!"
1570 is_project_quota_supported && change_project -C $DIR/$tdir
1572 resetquota -u $TSTUSR
1573 resetquota -g $TSTUSR
1574 resetquota -p $TSTPRJID
1576 run_test 8 "Run dbench with quota enabled"
1578 # this check is just for test_9
1579 OST0_MIN=4900000 #4.67G
1581 check_whether_skip () {
1582 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1583 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1584 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1585 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1592 # run for fixing bug10707, it needs a big room. test for 64bit
1594 local filesize=$((1024 * 9 / 2)) # 4.5G
1596 check_whether_skip && return 0
1598 setup_quota_test || error "setup quota failed with $?"
1599 trap cleanup_quota_test EXIT
1601 set_ost_qtype "ug" || error "enable ost quota failed"
1603 local TESTFILE="$DIR/$tdir/$tfile-0"
1604 local BLK_LIMIT=100G #100G
1605 local FILE_LIMIT=1000000
1607 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1609 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1611 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1612 error "set user quota failed"
1614 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1615 "for group: $TSTUSR"
1616 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1617 error "set group quota failed"
1619 quota_show_check a u $TSTUSR
1620 quota_show_check a g $TSTUSR
1622 echo "Create test file"
1623 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1624 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1626 log "Write the big file of 4.5G ..."
1627 $RUNAS $DD of=$TESTFILE count=$filesize ||
1628 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1634 resetquota -u $TSTUSR
1635 resetquota -g $TSTUSR
1640 run_test 9 "Block limit larger than 4GB (b10707)"
1643 local TESTFILE=$DIR/$tdir/$tfile
1645 setup_quota_test || error "setup quota failed with $?"
1646 trap cleanup_quota_test EXIT
1648 # set limit to root user should fail
1649 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1650 error "set limit for root user successfully, expect failure"
1651 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1652 error "set limit for root group successfully, expect failure"
1653 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1654 error "set limit for project 0 successfully, expect failure"
1656 # root user can overrun quota
1657 set_ost_qtype "ug" || error "enable ost quota failed"
1659 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1660 error "set quota failed"
1661 quota_show_check b u $TSTUSR
1663 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1664 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1666 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1667 error "write failure, expect success"
1670 resetquota -u $TSTUSR
1672 run_test 10 "Test quota for root user"
1675 local TESTFILE=$DIR/$tdir/$tfile
1676 setup_quota_test || error "setup quota failed with $?"
1677 trap cleanup_quota_test EXIT
1679 set_mdt_qtype "ug" || error "enable mdt quota failed"
1680 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1681 error "set quota failed"
1683 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1684 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1686 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1687 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1690 local USED=$(getquota -u $TSTUSR global curinodes)
1691 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1694 resetquota -u $TSTUSR
1696 run_test 11 "Chown/chgrp ignores quota"
1699 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1701 local blimit=22 # 22M
1702 local blk_cnt=$((blimit - 5))
1703 local TESTFILE0="$DIR/$tdir/$tfile"-0
1704 local TESTFILE1="$DIR/$tdir/$tfile"-1
1706 setup_quota_test || error "setup quota failed with $?"
1707 trap cleanup_quota_test EXIT
1709 set_ost_qtype "u" || error "enable ost quota failed"
1710 quota_show_check b u $TSTUSR
1712 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1713 error "set quota failed"
1715 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1716 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1717 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1718 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1720 echo "Write to ost0..."
1721 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1722 quota_error a $TSTUSR "dd failed"
1724 echo "Write to ost1..."
1725 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1726 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1728 echo "Free space from ost0..."
1730 wait_delete_completed
1731 sync_all_data || true
1733 echo "Write to ost1 after space freed from ost0..."
1734 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1735 quota_error a $TSTUSR "rebalancing failed"
1738 resetquota -u $TSTUSR
1740 run_test 12a "Block quota rebalancing"
1743 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1745 local ilimit=$((1024 * 2)) # 2k inodes
1746 local TESTFILE0=$DIR/$tdir/$tfile
1747 local TESTFILE1=$DIR/${tdir}-1/$tfile
1749 setup_quota_test || error "setup quota failed with $?"
1750 trap cleanup_quota_test EXIT
1752 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1753 chmod 0777 $DIR/${tdir}-1
1755 set_mdt_qtype "u" || error "enable mdt quota failed"
1756 quota_show_check f u $TSTUSR
1758 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1759 error "set quota failed"
1761 echo "Create $ilimit files on mdt0..."
1762 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1763 quota_error u $TSTUSR "create failed, but expect success"
1765 echo "Create files on mdt1..."
1766 $RUNAS createmany -m $TESTFILE1 1 &&
1767 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1769 echo "Free space from mdt0..."
1770 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1771 wait_delete_completed
1772 sync_all_data || true
1774 echo "Create files on mdt1 after space freed from mdt0..."
1775 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1776 quota_error a $TSTUSR "rebalancing failed"
1778 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1779 error "unlink mdt1 files failed"
1780 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1783 resetquota -u $TSTUSR
1785 run_test 12b "Inode quota rebalancing"
1788 local TESTFILE=$DIR/$tdir/$tfile
1789 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1790 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1792 setup_quota_test || error "setup quota failed with $?"
1793 trap cleanup_quota_test EXIT
1795 set_ost_qtype "u" || error "enable ost quota failed"
1796 quota_show_check b u $TSTUSR
1798 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1799 error "set quota failed"
1800 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1801 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1803 # clear the locks in cache first
1804 do_facet ost1 $LCTL set_param -n $procf=clear
1805 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1806 [ $nlock -eq 0 ] || error "$nlock cached locks"
1808 # write to acquire the per-ID lock
1809 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1810 quota_error a $TSTUSR "dd failed"
1812 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1813 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1815 # clear quota doesn't trigger per-ID lock cancellation
1816 resetquota -u $TSTUSR
1817 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1818 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1820 # clear the per-ID lock
1821 do_facet ost1 $LCTL set_param -n $procf=clear
1822 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1823 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1825 # spare quota should be released
1826 local OSTUUID=$(ostuuid_from_index 0)
1827 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1828 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1829 [ $limit -le $space ] ||
1830 error "spare quota isn't released, limit:$limit, space:$space"
1834 run_test 13 "Cancel per-ID lock in the LRU list"
1837 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1839 wait_delete_completed
1840 sync_all_data || true
1843 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1844 error "set user quota failed"
1845 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1846 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1847 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1848 resetquota -u $TSTUSR
1851 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1852 error "set group quota failed"
1853 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1854 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1855 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1856 resetquota -g $TSTUSR
1858 run_test 15 "Set over 4T block quota"
1862 local BLKS=1 # 1M less than limit
1863 local TESTFILE=$DIR/$tdir/$tfile
1865 setup_quota_test || error "setup quota failed with $?"
1866 trap cleanup_quota_test EXIT
1868 # make sure the system is clean
1869 local USED=$(getquota -u $TSTUSR global curspace)
1870 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1872 set_ost_qtype "ug" || error "enable ost quota failed"
1873 # make sure no granted quota on ost
1874 resetquota -u $TSTUSR
1875 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1876 error "set quota failed"
1878 quota_show_check b u $TSTUSR
1880 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1881 lustre_fail mds 0xa04 $err_code
1883 # write in background
1884 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1888 # write should be blocked and never finished
1889 if ! ps -p $DDPID > /dev/null 2>&1; then
1891 quota_error u $TSTUSR "write finished incorrectly!"
1899 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1901 if [ $count -gt $timeout ]; then
1902 quota_error u $TSTUSR "dd is not finished!"
1907 sync; sync_all_data || true
1909 USED=$(getquota -u $TSTUSR global curspace)
1910 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1911 "Used space(${USED}K) is less than ${BLKS}M"
1914 resetquota -u $TSTUSR
1917 # DQACQ return recoverable error
1919 echo "DQACQ return -ENOLCK"
1921 test_17sub 37 || error "Handle -ENOLCK failed"
1923 echo "DQACQ return -EAGAIN"
1925 test_17sub 11 || error "Handle -EAGAIN failed"
1927 echo "DQACQ return -ETIMEDOUT"
1928 #define ETIMEDOUT 110
1929 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1931 echo "DQACQ return -ENOTCONN"
1932 #define ENOTCONN 107
1933 test_17sub 107 || error "Handle -ENOTCONN failed"
1936 run_test 17 "DQACQ return recoverable error"
1940 local blimit="200m" # 200M
1941 local TESTFILE="$DIR/$tdir/$tfile"
1943 setup_quota_test || error "setup quota failed with $?"
1944 trap cleanup_quota_test EXIT
1946 set_ost_qtype "u" || error "enable ost quota failed"
1947 log "User quota (limit: $blimit)"
1948 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1949 error "set quota failed"
1950 quota_show_check b u $TSTUSR
1952 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1953 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1955 local timeout=$(sysctl -n lustre.timeout)
1957 if [ $io_type = "directio" ]; then
1958 log "Write 100M (directio) ..."
1959 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1961 log "Write 100M (buffered) ..."
1962 $RUNAS $DD of=$TESTFILE count=100 &
1966 replay_barrier $SINGLEMDS
1967 log "Fail mds for $((2 * timeout)) seconds"
1968 fail $SINGLEMDS $((2 * timeout))
1971 if at_is_enabled; then
1972 timeout=$(at_max_get mds)
1974 timeout=$(lctl get_param -n timeout)
1978 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1979 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1980 log "it took $count second"
1985 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1987 cancel_lru_locks mdc
1988 cancel_lru_locks osc
1991 local testfile_size=$(stat -c %s $TESTFILE)
1992 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1993 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1994 "got ${testfile_size}. Verifying file failed!"
1997 resetquota -u $TSTUSR
2000 # test when mds does failover, the ost still could work well
2001 # this test shouldn't trigger watchdog b=14840
2003 # Clear dmesg so watchdog is not triggered by previous
2005 do_facet ost1 dmesg -c > /dev/null
2008 test_18_sub directio
2010 # check if watchdog is triggered
2011 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2012 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
2013 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2014 [ -z "$watchdog" ] || error "$watchdog"
2015 rm -f $TMP/lustre-log-${TESTNAME}.log
2017 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2021 local TESTFILE=$DIR/$tdir/$tfile
2023 setup_quota_test || error "setup quota failed with $?"
2024 trap cleanup_quota_test EXIT
2026 set_ost_qtype $QTYPE || error "enable ost quota failed"
2028 # bind file to a single OST
2029 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2030 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2032 echo "Set user quota (limit: ${blimit}M)"
2033 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2034 error "set user quota failed"
2035 quota_show_check b u $TSTUSR
2036 echo "Update quota limits"
2037 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2038 error "set group quota failed"
2039 quota_show_check b u $TSTUSR
2041 # first wirte might be cached
2042 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2043 cancel_lru_locks osc
2045 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2046 quota_error u $TSTUSR "Write success, expect failure"
2050 resetquota -u $TSTUSR
2052 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2054 test_20() { # b15754
2055 local LSTR=(2g 1t 4k 3m) # limits strings
2057 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2060 resetquota -u $TSTUSR
2062 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2063 $MOUNT || error "could not set quota limits"
2064 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2065 --inode-softlimit ${LSTR[2]} \
2066 --inode-hardlimit ${LSTR[3]} \
2067 $MOUNT || error "could not set quota limits"
2069 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2070 error "bsoftlimit was not set properly"
2071 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2072 error "bhardlimit was not set properly"
2073 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2074 error "isoftlimit was not set properly"
2075 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2076 error "ihardlimit was not set properly"
2078 resetquota -u $TSTUSR
2080 run_test 20 "Test if setquota specifiers work properly (b15754)"
2087 local time=$(($(date +%s) + seconds))
2088 while [ $(date +%s) -lt $time ]; do
2089 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2093 # run for fixing bug16053, setquota shouldn't fail when writing and
2094 # deleting are happening
2096 local TESTFILE="$DIR/$tdir/$tfile"
2097 local BLIMIT=10 # 10G
2098 local ILIMIT=1000000
2100 setup_quota_test || error "setup quota failed with $?"
2101 trap cleanup_quota_test EXIT
2103 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2105 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2106 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2107 error "set user quota failed"
2108 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2109 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2110 error "set group quota failed"
2111 if is_project_quota_supported; then
2112 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2113 "project: $TSTPRJID"
2114 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2115 $MOUNT || error "set project quota failed"
2118 # repeat writing on a 1M file
2119 test_21_sub ${TESTFILE}_1 1 30 &
2121 # repeat writing on a 128M file
2122 test_21_sub ${TESTFILE}_2 128 30 &
2125 local time=$(($(date +%s) + 30))
2127 while [ $(date +%s) -lt $time ]; do
2128 log "Set quota for $i times"
2129 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2130 -I $((ILIMIT + i)) $MOUNT ||
2131 error "Set user quota failed"
2132 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2133 -I $((ILIMIT + i)) $MOUNT ||
2134 error "Set group quota failed"
2135 if is_project_quota_supported; then
2136 $LFS setquota -p $TSTPRJID -b 0 -B \
2137 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2138 error "Set project quota failed"
2146 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2148 if [ $count -gt 60 ]; then
2149 quota_error a $TSTUSR "dd should be finished!"
2153 echo "(dd_pid=$DDPID1, time=$count)successful"
2157 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2159 if [ $count -gt 60 ]; then
2160 quota_error a $TSTUSR "dd should be finished!"
2164 echo "(dd_pid=$DDPID2, time=$count)successful"
2167 resetquota -u $TSTUSR
2168 resetquota -g $TSTUSR
2169 resetquota -p $TSTPRJID
2171 run_test 21 "Setquota while writing & deleting (b16053)"
2173 # enable/disable quota enforcement permanently
2175 echo "Set both mdt & ost quota type as ug"
2177 is_project_quota_supported && qtype=$QTYPE
2178 set_mdt_qtype $qtype || error "enable mdt quota failed"
2179 set_ost_qtype $qtype || error "enable ost quota failed"
2182 stopall || error "failed to stopall (1)"
2186 echo "Verify if quota is enabled"
2187 local qtype1=$(mdt_quota_type)
2188 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2189 qtype=$(ost_quota_type)
2190 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2192 echo "Set both mdt & ost quota type as none"
2193 set_mdt_qtype "none" || error "disable mdt quota failed"
2194 set_ost_qtype "none" || error "disable ost quota failed"
2197 stopall || error "failed to stopall (2)"
2202 echo "Verify if quota is disabled"
2203 qtype=$(mdt_quota_type)
2204 [ $qtype != "none" ] && error "mdt quota setting is lost"
2205 qtype=$(ost_quota_type)
2206 [ $qtype != "none" ] && error "ost quota setting is lost"
2210 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2213 local TESTFILE="$DIR/$tdir/$tfile"
2216 setup_quota_test || error "setup quota failed with $?"
2217 trap cleanup_quota_test EXIT
2219 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2222 log "User quota (limit: $LIMIT MB)"
2223 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2224 error "set quota failed"
2225 quota_show_check b u $TSTUSR
2227 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2228 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2230 log "Step1: trigger EDQUOT with O_DIRECT"
2231 log "Write half of file"
2232 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2233 quota_error u $TSTUSR "(1) Write failure, expect success." \
2235 log "Write out of block quota ..."
2236 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2237 oflag=direct conv=notrunc &&
2238 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2242 log "Step2: rewrite should succeed"
2243 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2244 quota_error u $TSTUSR "(3) Write failure, expect success." \
2250 local OST0_UUID=$(ostuuid_from_index 0)
2251 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2252 [ $OST0_QUOTA_USED -ne 0 ] &&
2253 ($SHOW_QUOTA_USER; \
2254 quota_error u $TSTUSR "quota isn't released")
2256 resetquota -u $TSTUSR
2260 [ $(facet_fstype ost1) == "zfs" ] &&
2261 skip "Overwrite in place is not guaranteed to be " \
2262 "space neutral on ZFS"
2264 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2265 check_whether_skip && return 0
2266 log "run for 4MB test file"
2269 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2270 check_whether_skip && return 0
2271 log "run for 40MB test file"
2274 run_test 23 "Quota should be honored with directIO (b16125)"
2278 local TESTFILE="$DIR/$tdir/$tfile"
2280 setup_quota_test || error "setup quota failed with $?"
2281 trap cleanup_quota_test EXIT
2283 set_ost_qtype $QTYPE || error "enable ost quota failed"
2285 # bind file to a single OST
2286 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2287 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2289 echo "Set user quota (limit: ${blimit}M)"
2290 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2291 error "set quota failed"
2293 # overrun quota by root user
2294 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2295 error "write failure, expect success"
2296 cancel_lru_locks osc
2297 sync_all_data || true
2299 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2302 resetquota -u $TSTUSR
2304 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2306 test_27a() { # b19612
2307 $LFS quota $TSTUSR $DIR &&
2308 error "lfs succeeded with no type, but should have failed"
2309 $LFS setquota $TSTUSR $DIR &&
2310 error "lfs succeeded with no type, but should have failed"
2313 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2315 test_27b() { # b20200
2316 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2317 error "lfs setquota failed with uid argument"
2318 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2319 error "lfs stequota failed with gid argument"
2320 if is_project_quota_supported; then
2321 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2322 1000 $DIR || error \
2323 "lfs stequota failed with projid argument"
2325 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2326 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2327 if is_project_quota_supported; then
2328 $SHOW_QUOTA_PROJID ||
2329 error "lfs quota failed with projid argument"
2331 resetquota -u $TSTUSR
2332 resetquota -g $TSTUSR
2333 resetquota -p $TSTPRJID
2336 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2341 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2342 error "lfs setquota failed"
2344 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2345 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2346 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2347 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2349 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2350 error "lfs setquota for $TSTID failed"
2352 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2353 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2354 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2355 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2357 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2358 error "total allocated inode/block limit not printed"
2360 resetquota -u $TSTUSR
2362 run_test 27c "lfs quota should support human-readable output"
2369 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2370 error "set fraction block limit failed"
2371 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2372 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2373 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2374 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2376 resetquota -u $TSTUSR
2378 run_test 27d "lfs setquota should support fraction block limit"
2382 local TESTFILE="$DIR/$tdir/$tfile"
2385 setup_quota_test || error "setup quota failed with $?"
2386 trap cleanup_quota_test EXIT
2388 set_ost_qtype "u" || error "enable ost quota failed"
2390 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2391 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2393 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2394 $MAX_IQ_TIME $DIR || error "set grace time failed"
2395 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2396 error "set quota failed"
2397 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2398 cancel_lru_locks osc
2400 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2401 # over-quota flag has not yet settled since we do not trigger async
2402 # events based on grace time period expiration
2404 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2405 cancel_lru_locks osc
2406 # now over-quota flag should be settled and further writes should fail
2408 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2409 error "grace times were reset"
2412 resetquota -u $TSTUSR
2413 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2414 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2416 run_test 30 "Hard limit updates should not reset grace times"
2418 # basic usage tracking for user & group
2420 local INODES=10 # 10 files
2421 local BLK_CNT=2 # of 2M each
2422 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2424 setup_quota_test || error "setup quota failed with $?"
2425 trap cleanup_quota_test EXIT
2427 # make sure the system is clean
2428 local USED=$(getquota -u $TSTID global curspace)
2430 error "Used space ($USED) for user $TSTID isn't 0."
2431 USED=$(getquota -g $TSTID global curspace)
2433 error "Used space ($USED) for group $TSTID isn't 0."
2434 if is_project_quota_supported; then
2435 USED=$(getquota -p $TSTPRJID global curspace)
2436 [ $USED -ne 0 ] && error \
2437 "Used space ($USED) for project $TSTPRJID isn't 0."
2440 echo "Write files..."
2441 for i in $(seq 0 $INODES); do
2442 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2443 error "write failed"
2444 is_project_quota_supported &&
2445 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2446 echo "Iteration $i/$INODES completed"
2448 cancel_lru_locks osc
2450 echo "Wait for setattr on objects finished..."
2451 wait_delete_completed
2453 sync; sync_all_data || true
2455 echo "Verify disk usage after write"
2456 USED=$(getquota -u $TSTID global curspace)
2457 [ $USED -lt $TOTAL_BLKS ] &&
2458 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2459 USED=$(getquota -g $TSTID global curspace)
2460 [ $USED -lt $TOTAL_BLKS ] &&
2461 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2462 if is_project_quota_supported; then
2463 USED=$(getquota -p $TSTPRJID global curspace)
2464 [ $USED -lt $TOTAL_BLKS ] && error \
2465 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2468 echo "Verify inode usage after write"
2469 USED=$(getquota -u $TSTID global curinodes)
2470 [ $USED -lt $INODES ] &&
2471 error "Used inode for user $TSTID is $USED, expected $INODES"
2472 USED=$(getquota -g $TSTID global curinodes)
2473 [ $USED -lt $INODES ] &&
2474 error "Used inode for group $TSTID is $USED, expected $INODES"
2475 if is_project_quota_supported; then
2476 USED=$(getquota -p $TSTPRJID global curinodes)
2477 [ $USED -lt $INODES ] && error \
2478 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2483 echo "Verify disk usage after delete"
2484 USED=$(getquota -u $TSTID global curspace)
2485 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2486 USED=$(getquota -u $TSTID global curinodes)
2487 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2488 USED=$(getquota -g $TSTID global curspace)
2489 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2490 USED=$(getquota -g $TSTID global curinodes)
2491 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2492 if is_project_quota_supported; then
2493 USED=$(getquota -p $TSTPRJID global curspace)
2495 error "Used space for project $TSTPRJID isn't 0. $USED"
2496 USED=$(getquota -p $TSTPRJID global curinodes)
2498 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2501 run_test 33 "Basic usage tracking for user & group & project"
2503 # usage transfer test for user & group & project
2505 local BLK_CNT=2 # 2MB
2506 local project_supported="no"
2508 is_project_quota_supported && project_supported="yes"
2509 setup_quota_test || error "setup quota failed with $?"
2510 trap cleanup_quota_test EXIT
2512 # make sure the system is clean
2513 local USED=$(getquota -u $TSTID global curspace)
2514 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2515 USED=$(getquota -g $TSTID global curspace)
2516 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2518 local USED=$(getquota -u $TSTID2 global curspace)
2519 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2520 if [ $project_supported == "yes" ]; then
2521 USED=$(getquota -p $TSTPRJID global curspace)
2522 [ $USED -ne 0 ] && error \
2523 "Used space ($USED) for Project $TSTPRJID isn't 0."
2526 echo "Write file..."
2527 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2528 error "write failed"
2529 cancel_lru_locks osc
2530 sync; sync_all_data || true
2532 echo "chown the file to user $TSTID"
2533 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2535 echo "Wait for setattr on objects finished..."
2536 wait_delete_completed
2538 BLK_CNT=$((BLK_CNT * 1024))
2540 echo "Verify disk usage for user $TSTID"
2541 USED=$(getquota -u $TSTID global curspace)
2542 [ $USED -lt $BLK_CNT ] &&
2543 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2544 USED=$(getquota -u $TSTID global curinodes)
2546 error "Used inodes for user $TSTID is $USED, expected 1"
2548 echo "chgrp the file to group $TSTID"
2549 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2551 echo "Wait for setattr on objects finished..."
2552 wait_delete_completed
2554 echo "Verify disk usage for group $TSTID"
2555 USED=$(getquota -g $TSTID global curspace)
2556 [ $USED -ge $BLK_CNT ] ||
2557 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2558 USED=$(getquota -g $TSTID global curinodes)
2560 error "Used inodes for group $TSTID is $USED, expected 1"
2562 # chown won't change the ost object group. LU-4345 */
2563 echo "chown the file to user $TSTID2"
2564 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2566 echo "Wait for setattr on objects finished..."
2567 wait_delete_completed
2569 echo "change_project project id to $TSTPRJID"
2570 [ $project_supported == "yes" ] &&
2571 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2572 echo "Wait for setattr on objects finished..."
2573 wait_delete_completed
2575 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2576 USED=$(getquota -u $TSTID2 global curspace)
2577 [ $USED -lt $BLK_CNT ] &&
2578 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2579 USED=$(getquota -u $TSTID global curspace)
2581 error "Used space for user $TSTID is $USED, expected 0"
2582 USED=$(getquota -g $TSTID global curspace)
2583 [ $USED -lt $BLK_CNT ] &&
2584 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2585 if [ $project_supported == "yes" ]; then
2586 USED=$(getquota -p $TSTPRJID global curspace)
2587 [ $USED -lt $BLK_CNT ] && error \
2588 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2593 run_test 34 "Usage transfer for user & group & project"
2595 # usage is still accessible across restart
2597 local BLK_CNT=2 # 2 MB
2599 setup_quota_test || error "setup quota failed with $?"
2600 trap cleanup_quota_test EXIT
2602 echo "Write file..."
2603 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2604 error "write failed"
2605 is_project_quota_supported &&
2606 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2607 cancel_lru_locks osc
2609 echo "Wait for setattr on objects finished..."
2610 wait_delete_completed
2612 sync; sync_all_data || true
2614 echo "Save disk usage before restart"
2615 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2616 [ $ORIG_USR_SPACE -eq 0 ] &&
2617 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2618 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2619 [ $ORIG_USR_INODES -eq 0 ] &&
2620 error "Used inodes for user $TSTID is 0, expected 1"
2621 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2622 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2623 [ $ORIG_GRP_SPACE -eq 0 ] &&
2624 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2625 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2626 [ $ORIG_GRP_INODES -eq 0 ] &&
2627 error "Used inodes for group $TSTID is 0, expected 1"
2628 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2630 if is_project_quota_supported; then
2631 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2632 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2633 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2634 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2635 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2636 "Used inodes for project $TSTPRJID is 0, expected 1"
2637 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2645 echo "Verify disk usage after restart"
2646 local USED=$(getquota -u $TSTID global curspace)
2647 [ $USED -eq $ORIG_USR_SPACE ] ||
2648 error "Used space for user $TSTID changed from " \
2649 "$ORIG_USR_SPACE to $USED"
2650 USED=$(getquota -u $TSTID global curinodes)
2651 [ $USED -eq $ORIG_USR_INODES ] ||
2652 error "Used inodes for user $TSTID changed from " \
2653 "$ORIG_USR_INODES to $USED"
2654 USED=$(getquota -g $TSTID global curspace)
2655 [ $USED -eq $ORIG_GRP_SPACE ] ||
2656 error "Used space for group $TSTID changed from " \
2657 "$ORIG_GRP_SPACE to $USED"
2658 USED=$(getquota -g $TSTID global curinodes)
2659 [ $USED -eq $ORIG_GRP_INODES ] ||
2660 error "Used inodes for group $TSTID changed from " \
2661 "$ORIG_GRP_INODES to $USED"
2662 if [ $project_supported == "yes" ]; then
2663 USED=$(getquota -p $TSTPRJID global curinodes)
2664 [ $USED -eq $ORIG_PRJ_INODES ] ||
2665 error "Used inodes for project $TSTPRJID " \
2666 "changed from $ORIG_PRJ_INODES to $USED"
2667 USED=$(getquota -p $TSTPRJID global curspace)
2668 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2669 error "Used space for project $TSTPRJID "\
2670 "changed from $ORIG_PRJ_SPACE to $USED"
2673 # check if the vfs_dq_init() is called before writing
2674 echo "Append to the same file..."
2675 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2676 error "write failed"
2677 cancel_lru_locks osc
2678 sync; sync_all_data || true
2680 echo "Verify space usage is increased"
2681 USED=$(getquota -u $TSTID global curspace)
2682 [ $USED -gt $ORIG_USR_SPACE ] ||
2683 error "Used space for user $TSTID isn't increased" \
2684 "orig:$ORIG_USR_SPACE, now:$USED"
2685 USED=$(getquota -g $TSTID global curspace)
2686 [ $USED -gt $ORIG_GRP_SPACE ] ||
2687 error "Used space for group $TSTID isn't increased" \
2688 "orig:$ORIG_GRP_SPACE, now:$USED"
2689 if [ $project_supported == "yes" ]; then
2690 USED=$(getquota -p $TSTPRJID global curspace)
2691 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2692 error "Used space for project $TSTPRJID isn't " \
2693 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2698 run_test 35 "Usage is still accessible across reboot"
2700 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2703 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2704 skip "Old server doesn't have LU-5006 fix."
2706 setup_quota_test || error "setup quota failed with $?"
2707 trap cleanup_quota_test EXIT
2709 # make sure the system is clean
2710 local USED=$(getquota -u $TSTID global curspace)
2712 error "Used space ($USED) for user $TSTID isn't 0."
2714 # create file with MDS_OPEN_DELAY_CREATE flag
2715 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2716 error "Create file failed"
2718 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2719 oflag=sync || error "Write file failed"
2721 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2723 # wait for setattr on objects finished..."
2724 wait_delete_completed
2726 USED=$(getquota -u $TSTID global curspace)
2727 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2731 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2735 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2736 skip "Old server doesn't have LU-8801 fix."
2738 [ "$UID" != 0 ] && skip_env "must run as root" && return
2740 setup_quota_test || error "setup quota failed with $?"
2741 trap cleanup_quota_test EXIT
2743 # make sure the system is clean
2744 local USED=$(getquota -u $TSTID global curspace)
2746 error "Used space ($USED) for user $TSTID isn't 0."
2747 USED=$(getquota -u $TSTID2 global curspace)
2749 error "Used space ($USED) for user $TSTID2 isn't 0."
2751 local TESTFILE="$DIR/$tdir/$tfile"
2752 local file_cnt=10000
2754 # Generate id entries in accounting file
2755 echo "Create $file_cnt files..."
2756 for i in `seq $file_cnt`; do
2758 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2759 error "failed to chown $TESTFILE-$i"
2761 cancel_lru_locks osc
2762 sync; sync_all_data || true
2764 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2765 procf=${procf}.quota_slave.acct_user
2768 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2769 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2770 echo "Found $acct_cnt id entries"
2772 [ $file_cnt -eq $acct_cnt ] || {
2773 do_facet mds1 $LCTL get_param $procf
2774 error "skipped id entries"
2779 run_test 38 "Quota accounting iterator doesn't skip id entries"
2782 local TESTFILE="$DIR/$tdir/project"
2783 ! is_project_quota_supported &&
2784 skip "Project quota is not supported"
2786 setup_quota_test || error "setup quota failed with $?"
2789 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2790 [ $projectid -ne 0 ] &&
2791 error "Project id should be 0 not $projectid"
2792 change_project -p 1024 $TESTFILE
2793 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2794 [ $projectid -ne 1024 ] &&
2795 error "Project id should be 1024 not $projectid"
2797 stopall || error "failed to stopall (1)"
2800 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2801 [ $projectid -ne 1024 ] &&
2802 error "Project id should be 1024 not $projectid"
2806 run_test 39 "Project ID interface works correctly"
2809 ! is_project_quota_supported &&
2810 skip "Project quota is not supported"
2811 local dir1="$DIR/$tdir/dir1"
2812 local dir2="$DIR/$tdir/dir2"
2814 setup_quota_test || error "setup quota failed with $?"
2816 mkdir -p $dir1 $dir2
2817 change_project -sp 1 $dir1 && touch $dir1/1
2818 change_project -sp 2 $dir2
2820 ln $dir1/1 $dir2/1_link &&
2821 error "Hard link across different project quota should fail"
2826 run_test 40a "Hard link across different project ID"
2829 ! is_project_quota_supported &&
2830 skip "Project quota is not supported"
2831 local dir1="$DIR/$tdir/dir1"
2832 local dir2="$DIR/$tdir/dir2"
2834 setup_quota_test || error "setup quota failed with $?"
2835 mkdir -p $dir1 $dir2
2836 change_project -sp 1 $dir1 && touch $dir1/1
2837 change_project -sp 2 $dir2
2839 mv $dir1/1 $dir2/2 || error "mv failed $?"
2840 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2841 if [ "$projid" != "2" ]; then
2842 error "project id expected 2 not $projid"
2847 run_test 40b "Mv across different project ID"
2850 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2851 ! is_project_quota_supported &&
2852 skip "Project quota is not supported"
2854 setup_quota_test || error "setup quota failed with $?"
2855 local dir="$DIR/$tdir/dir"
2857 mkdir -p $dir && change_project -sp 1 $dir
2858 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2859 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2860 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2861 touch $dir/remote_dir/file
2862 #verify inherit works file for remote dir.
2863 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2864 [ "$projid" != "1" ] &&
2865 error "file under remote dir expected 1 not $projid"
2867 #Agent inode should be ignored for project quota
2868 USED=$(getquota -p 1 global curinodes)
2869 [ "$USED" != "3" ] &&
2870 error "file count expected 3 got $USED"
2876 run_test 40c "Remote child Dir inherit project quota properly"
2879 ! is_project_quota_supported &&
2880 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 -p 1 $dir
2886 count=$($LFS find --projid 1 $DIR | wc -l)
2887 [ "$count" != 1 ] && error "expected 1 but got $count"
2892 run_test 50 "Test if lfs find --projid works"
2895 ! is_project_quota_supported &&
2896 skip "Project quota is not supported"
2897 setup_quota_test || error "setup quota failed with $?"
2898 local dir="$DIR/$tdir/dir"
2900 mkdir $dir && change_project -sp 1 $dir
2901 local used=$(getquota -p 1 global curinodes)
2902 [ $used != "1" ] && error "expected 1 got $used"
2907 used=$(getquota -p 1 global curinodes)
2908 [ $used != "4" ] && error "expected 4 got $used"
2910 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2912 cp $DIR/$tdir/6 $dir/6
2913 used=$(getquota -p 1 global curinodes)
2914 [ $used != "5" ] && error "expected 5 got $used"
2917 mv $DIR/$tdir/6 $dir/7
2918 used=$(getquota -p 1 global curinodes)
2919 [ $used != "6" ] && error "expected 6 got $used"
2924 run_test 51 "Test project accounting with mv/cp"
2927 ! is_project_quota_supported &&
2928 skip "Project quota is not supported"
2929 setup_quota_test || error "setup quota failed with $?"
2930 local dir="$DIR/$tdir/dir"
2931 mkdir $dir && change_project -sp 1 $dir
2933 touch $DIR/$tdir/file
2934 #Try renaming a file into the project. This should fail.
2935 for num in $(seq 1 2000); do
2936 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2937 error "rename should fail"
2942 run_test 52 "Rename across different project ID"
2945 ! is_project_quota_supported &&
2946 skip "Project quota is not supported"
2947 setup_quota_test || error "setup quota failed with $?"
2948 local dir="$DIR/$tdir/dir"
2949 mkdir $dir && change_project -s $dir
2950 lfs project -d $dir | grep P || error "inherit attribute should be set"
2952 change_project -C $dir
2953 lfs project -d $dir | grep P &&
2954 error "inherit attribute should be cleared"
2959 run_test 53 "Project inherit attribute could be cleared"
2962 ! is_project_quota_supported &&
2963 skip "Project quota is not supported"
2964 setup_quota_test || error "setup quota failed with $?"
2965 trap cleanup_quota_test EXIT
2966 local testfile="$DIR/$tdir/$tfile-0"
2968 #set project ID/inherit attribute
2969 change_project -sp $TSTPRJID $DIR/$tdir
2970 $RUNAS createmany -m ${testfile} 100 ||
2971 error "create many files failed"
2973 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2974 # one more count for directory itself */
2978 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2979 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2981 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2982 [ $proj_count1 -eq $proj_count ] ||
2983 error "c2: expected $proj_count got $proj_count1"
2985 #clear project but with kept projid
2986 change_project -rCk $DIR/$tdir
2987 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2988 [ $proj_count1 -eq $proj_count ] ||
2989 error "c3: expected $proj_count got $proj_count1"
2991 #verify projid untouched.
2992 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2994 [ $proj_count1 -eq $proj_count ] ||
2995 error "c4: expected $proj_count got $proj_count1"
2998 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2999 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
3000 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
3002 #this time clear all
3003 change_project -rC $DIR/$tdir
3004 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
3005 [ $proj_count1 -eq 0 ] ||
3006 error "c6: expected 0 got $proj_count1"
3008 unlinkmany ${testfile} 100 ||
3009 error "unlink many files failed"
3013 run_test 54 "basic lfs project interface test"
3016 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
3017 skip "Not supported before 2.10.58."
3018 setup_quota_test || error "setup quota failed with $?"
3020 set_ost_qtype $QTYPE || error "enable ost quota failed"
3023 #add second group to TSTUSR
3024 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3027 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3028 error "failed to dd"
3030 cancel_lru_locks osc
3031 sync; sync_all_data || true
3033 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3034 error "failed to setquota on group $TSTUSR2"
3036 $LFS quota -v -g $TSTUSR2 $DIR
3038 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3039 error "chgrp should failed with -EDQUOT"
3041 USED=$(getquota -g $TSTUSR2 global curspace)
3044 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3045 error "failed to setquota on group $TSTUSR2"
3047 $LFS quota -v -g $TSTUSR2 $DIR
3049 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3050 error "chgrp should succeed"
3052 $LFS quota -v -g $TSTUSR2 $DIR
3054 resetquota -g $TSTUSR2
3057 run_test 55 "Chgrp should be affected by group quota"
3060 setup_quota_test || error "setup quota failed with $?"
3062 set_ost_qtype $QTYPE || error "enable ost quota failed"
3065 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3066 erro "failed to set grace time for usr quota"
3067 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3068 awk '{print $4 $8}')
3069 if [ "x$grace_time" != "x10s;10s" ]; then
3070 $LFS quota -t -u $DIR
3071 error "expected grace time: 10s;10s, got:$grace_time"
3076 run_test 56 "lfs quota -t should work well"
3079 setup_quota_test || error "setup quota failed with $?"
3081 local dir="$DIR/$tdir/dir"
3084 #try to change pipe file should not hang and return failure
3085 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3086 awk -F ':' '{ print \\\$2 }'" \
3087 " failed to get xattr for '$dir/pipe'" || return 1
3088 #command can process further if it hit some errors
3089 touch $dir/aaa $dir/bbb
3090 mkdir $dir/subdir -p
3091 touch $dir/subdir/aaa $dir/subdir/bbb
3092 #create one invalid link file
3093 ln -s $dir/not_exist_file $dir/ccc
3094 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3095 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3099 run_test 57 "lfs project could tolerate errors"
3102 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3103 skip "ldiskfs only test"
3104 disable_project_quota
3105 setup_quota_test || error "setup quota failed with $?"
3108 local testfile="$DIR/$tdir/$tfile-0"
3109 #make sure it did not crash kernel
3110 touch $testfile && lfs project -sp 1 $testfile
3112 enable_project_quota
3115 run_test 59 "lfs project dosen't crash kernel with project disabled"
3118 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3119 skip "Needs MDS version 2.11.53 or later."
3120 setup_quota_test || error "setup quota failed with $?"
3121 trap cleanup_quota_test EXIT
3123 local testfile=$DIR/$tdir/$tfile
3126 set_mdt_qtype "ug" || error "enable mdt quota failed"
3128 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3129 error "set quota failed"
3130 quota_show_check a g $TSTUSR
3132 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3133 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3134 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3135 error "create many files failed"
3137 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3139 # root user can overrun quota
3140 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3141 error "root user should succeed"
3144 resetquota -g $TSTUSR
3146 run_test 60 "Test quota for root with setgid"
3148 # test default quota
3149 test_default_quota() {
3150 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3151 skip "Not supported before 2.11.51."
3156 local qprjid=$TSTPRJID
3160 local LIMIT=20480 #20M disk space
3161 local TESTFILE="$DIR/$tdir/$tfile-0"
3163 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3164 echo "Project quota is not supported" && return 0
3166 [ $qtype == "-u" ] && qdtype="-U"
3167 [ $qtype == "-g" ] && qdtype="-G"
3168 [ $qtype == "-p" ] && {
3173 [ $qpool == "meta" ] && {
3174 LIMIT=10240 #10K inodes
3179 setup_quota_test || error "setup quota failed with $?"
3180 trap cleanup_quota_test EXIT
3184 # enable mdt/ost quota
3185 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3186 set_ost_qtype $QTYPE || error "enable ost quota failed"
3188 log "set to use default quota"
3189 $LFS setquota $qtype $qid -d $DIR ||
3190 error "set $qid to use default quota failed"
3192 log "set default quota"
3193 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3194 error "set $qid default quota failed"
3196 log "get default quota"
3197 $LFS quota $qdtype $DIR || error "get default quota failed"
3199 if [ $qpool == "data" ]; then
3200 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3202 [ $SLIMIT -eq $LIMIT ] ||
3203 error "the returned default quota is wrong"
3205 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3207 [ $SLIMIT -eq $LIMIT ] ||
3208 error "the returned default quota is wrong"
3211 # make sure the system is clean
3212 local USED=$(getquota $qtype $qid global curspace)
3213 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3215 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3216 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3218 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3220 log "Test not out of quota"
3221 if [ $qpool == "data" ]; then
3222 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3223 quota_error $qtype $qid "write failed, expect succeed"
3225 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3226 quota_error $qtype $qid "create failed, expect succeed"
3228 unlinkmany $TESTFILE $((LIMIT/2))
3231 log "Test out of quota"
3232 # flush cache, ensure noquota flag is set on client
3233 cancel_lru_locks osc
3234 cancel_lru_locks mdc
3235 sync; sync_all_data || true
3236 if [ $qpool == "data" ]; then
3237 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3238 quota_error $qtype $qid "write succeed, expect EDQUOT"
3240 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3241 quota_error $qtype $qid "create succeed, expect EDQUOT"
3243 unlinkmany $TESTFILE $((LIMIT*2))
3246 log "Increase default quota"
3247 # increase default quota
3248 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3249 error "set default quota failed"
3251 cancel_lru_locks osc
3252 cancel_lru_locks mdc
3253 sync; sync_all_data || true
3254 if [ $qpool == "data" ]; then
3255 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3256 quota_error $qtype $qid "write failed, expect succeed"
3258 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3259 quota_error $qtype $qid "create failed, expect succeed"
3261 unlinkmany $TESTFILE $((LIMIT*2))
3264 log "Set quota to override default quota"
3265 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3266 error "set $qid quota failed"
3268 cancel_lru_locks osc
3269 cancel_lru_locks mdc
3270 sync; sync_all_data || true
3271 if [ $qpool == "data" ]; then
3272 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3273 quota_error $qtype $qid "write succeed, expect EQUOT"
3275 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3276 quota_error $qtype $qid "create succeed, expect EQUOT"
3278 unlinkmany $TESTFILE $((LIMIT*2))
3281 log "Set to use default quota again"
3282 $LFS setquota $qtype $qid -d $DIR ||
3283 error "set $qid to use default quota failed"
3285 cancel_lru_locks osc
3286 cancel_lru_locks mdc
3287 sync; sync_all_data || true
3288 if [ $qpool == "data" ]; then
3289 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3290 quota_error $qtype $qid "write failed, expect succeed"
3292 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3293 quota_error $qtype $qid "create failed, expect succeed"
3295 unlinkmany $TESTFILE $((LIMIT*2))
3300 wait_delete_completed || error "wait_delete_completed failed"
3301 sync_all_data || true
3302 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3303 error "reset default quota failed"
3304 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3305 error "reset quota failed"
3311 test_default_quota "-u" "data"
3312 test_default_quota "-u" "meta"
3313 test_default_quota "-g" "data"
3314 test_default_quota "-g" "meta"
3315 test_default_quota "-p" "data"
3316 test_default_quota "-p" "meta"
3318 run_test 61 "default quota tests"
3321 ! is_project_quota_supported &&
3322 skip "Project quota is not supported"
3323 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3324 skip "chattr did not support project quota"
3325 setup_quota_test || error "setup quota failed with $?"
3326 local testdir=$DIR/$tdir/
3328 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3329 change_project -s $testdir
3330 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3331 error "inherit attribute should be set"
3332 # chattr used FS_IOC_SETFLAGS ioctl
3333 $RUNAS chattr -P $testdir &&
3334 error "regular user clear inherit should fail"
3335 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3336 error "inherit attribute should still be set"
3337 chattr -P $testdir || error "root failed to clear inherit"
3338 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3339 error "inherit attribute should be cleared"
3342 run_test 62 "Project inherit should be only changed by root"
3345 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3346 skip "Not supported before 2.11.55" && return
3350 local dd_failed=false
3351 local tdir_dom=${tdir}_dom
3352 local LIMIT=20480 #20M
3354 [ $qtype == "p" ] && ! is_project_quota_supported &&
3355 echo "Project quota is not supported" && return 0
3357 [ $qtype == "p" ] && qid=$TSTPRJID
3359 setup_quota_test || error "setup quota failed with $?"
3360 trap cleanup_quota_test EXIT
3364 # enable mdt/ost quota
3365 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3366 set_ost_qtype $QTYPE || error "enable ost quota failed"
3368 # make sure the system is clean
3369 local USED=$(getquota -$qtype $qid global curspace)
3370 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3372 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3374 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3375 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3376 error "setstripe $tdir_dom failed"
3377 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3379 [ $qtype == "p" ] && {
3380 change_project -sp $TSTPRJID $DIR/$tdir
3381 change_project -sp $TSTPRJID $DIR/$tdir_dom
3384 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3385 error "set $qid quota failed"
3387 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3388 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3392 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3394 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3395 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3399 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3401 rm -f $DIR/$tdir_dom/*
3403 # flush cache, ensure noquota flag is set on client
3404 cancel_lru_locks osc
3405 cancel_lru_locks mdc
3406 sync; sync_all_data || true
3410 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3411 quota_error $qtype $qid "write failed, expect succeed"
3413 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3414 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3418 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3421 rm -f $DIR/$tdir_dom/*
3423 # flush cache, ensure noquota flag is set on client
3424 cancel_lru_locks osc
3425 cancel_lru_locks mdc
3426 sync; sync_all_data || true
3430 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3431 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3435 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3437 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3438 quota_error $qtype $qid "write succeed, expect EDQUOT"
3441 rm -fr $DIR/$tdir_dom
3443 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3444 error "reset usr quota failed"
3454 run_test 63 "quota on DoM tests"
3458 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3459 if $PQ_CLEANUP; then
3460 disable_project_quota
3463 reset_quota_settings
3468 check_and_cleanup_lustre
3469 export QUOTA_AUTO=$QUOTA_AUTO_OLD