3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 # Bug number for skipped test: LU-5152
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT 55"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
27 TSTPRJID=${TSTPRJID:-1000}
33 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
34 . $LUSTRE/tests/test-framework.sh
36 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
41 require_dsh_mds || exit 0
42 require_dsh_ost || exit 0
44 # Does e2fsprogs support quota feature?
45 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
46 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
47 grep -q 'quota'"; then
48 skip_env "e2fsprogs doesn't support quota" && exit 0
51 # Test duration: 30 min
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test:
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
59 # Test duration: 21 9 min"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
76 is_project_quota_supported() {
77 $ENABLE_PROJECT_QUOTAS || return 1
78 [ "$(facet_fstype $SINGLEMDS)" == "ldiskfs" ] &&
79 [ $(lustre_version_code $SINGLEMDS) -gt \
80 $(version_code 2.9.55) ] &&
81 lfs --help | grep project >&/dev/null &&
82 egrep -q "7." /etc/redhat-release && return 0
84 if [ "$(facet_fstype $SINGLEMDS)" == "zfs" ]; then
85 [ $(lustre_version_code $SINGLEMDS) -le \
86 $(version_code 2.10.53) ] && return 1
88 do_facet mds1 $ZPOOL upgrade -v |
89 grep project_quota && return 0
95 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
96 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
97 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
98 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
99 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
100 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
101 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
102 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
109 local fail_val=${3:-0}
113 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
114 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
115 ost) NODES="$(comma_list $(osts_nodes))";;
118 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
123 echo "lfs project $*"
124 lfs project $* || error "lfs project $* failed"
127 RUNAS="runas -u $TSTID -g $TSTID"
128 RUNAS2="runas -u $TSTID2 -g $TSTID2"
129 DD="dd if=/dev/zero bs=1M"
133 # clear quota limits for a user or a group
134 # usage: resetquota -u username
135 # resetquota -g groupname
136 # resetquota -p projid
139 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
140 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
141 error "resetquota: wrong specifier $1 passed"
143 if [ $1 == "-p" ]; then
144 is_project_quota_supported || return 0
147 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
148 error "clear quota for [type:$1 name:$2] failed"
149 # give a chance to slave to release space
157 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
158 $LFS quota -v -u $local_id $DIR
159 log "Files for user ($local_id):"
160 ($LFS find --user $local_id $DIR | head -n 4 |
161 xargs stat 2>/dev/null)
164 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
165 $LFS quota -v -g $local_id $DIR
166 log "Files for group ($local_id):"
167 ($LFS find --group $local_id $DIR | head -n 4 |
168 xargs stat 2>/dev/null)
171 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
172 $LFS quota -v -p $TSTPRJID $DIR
173 log "Files for project ($TSTPRJID):"
174 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
175 xargs stat 2>/dev/null)
191 # get quota for a user or a group
192 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
193 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
198 sync_all_data > /dev/null 2>&1 || true
200 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
201 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
202 error "getquota: wrong u/g/p specifier $1 passed"
215 *) error "unknown quota parameter $4";;
218 [ "$uuid" = "global" ] && uuid=$DIR
220 $LFS quota -v "$1" "$2" $DIR |
221 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
222 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
227 # usage: set_mdt_qtype ugp|u|g|p|none
231 local mdts=$(get_facets MDS)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD == *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
242 # we have to make sure each MDT received config changes
243 for mdt in ${mdts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $mdt); then
250 wait_update_facet $mdt "$cmd" "$qtype" || return 1
257 # usage: set_ost_qtype ugp|u|g|p|none
261 local osts=$(get_facets OST)
263 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
264 qtype=$(tr -d 'p' <<<$qtype)
266 if [[ $PERM_CMD == *"set_param -P"* ]]; then
267 do_facet mgs $PERM_CMD \
268 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
270 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
272 # we have to make sure each OST received config changes
273 for ost in ${osts//,/ }; do
275 cmd="$LCTL get_param -n "
276 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
277 cmd=${cmd}.quota_slave.enabled
279 if $(facet_up $ost); then
280 wait_update_facet $ost "$cmd" "$qtype" || return 1
286 wait_reintegration() {
290 local result="glb[1],slv[1],reint[0]"
295 if [ $ntype == "mdt" ]; then
296 tgts=$(get_facets MDS)
298 tgts=$(get_facets OST)
301 for tgt in ${tgts//,/ }; do
303 cmd="$LCTL get_param -n "
304 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
305 cmd=${cmd}.quota_slave.info
307 if $(facet_up $tgt); then
308 wait_update_facet $tgt "$cmd |
309 grep "$qtype" | awk '{ print \\\$3 }'" \
310 "$result" $max || return 1
320 if [[ "$qtype" =~ "u" ]]; then
321 wait_reintegration "mdt" "user" $max || return 1
324 if [[ "$qtype" =~ "g" ]]; then
325 wait_reintegration "mdt" "group" $max || return 1
328 if [[ "$qtype" =~ "p" ]]; then
329 ! is_project_quota_supported && return 0
330 wait_reintegration "mdt" "project" $max || return 1
339 if [[ "$qtype" =~ "u" ]]; then
340 wait_reintegration "ost" "user" $max || return 1
343 if [[ "$qtype" =~ "g" ]]; then
344 wait_reintegration "ost" "group" $max || return 1
347 if [[ "$qtype" =~ "p" ]]; then
348 ! is_project_quota_supported && return 0
349 wait_reintegration "ost" "project" $max || return 1
354 disable_project_quota() {
355 is_project_quota_supported || return 0
356 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
357 stopall || error "failed to stopall (1)"
359 for num in $(seq $MDSCOUNT); do
360 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
361 error "tune2fs $(mdsdevname $num) failed"
364 for num in $(seq $OSTCOUNT); do
365 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
366 error "tune2fs $(ostdevname $num) failed"
374 wait_delete_completed
375 echo "Creating test directory"
376 mkdir $DIR/$tdir || return 1
377 chmod 0777 $DIR/$tdir || return 2
378 # always clear fail_loc in case of fail_loc isn't cleared
379 # properly when previous test failed
380 lustre_fail mds_ost 0
383 cleanup_quota_test() {
385 echo "Delete files..."
387 echo "Wait for unlink objects finished..."
388 wait_delete_completed
389 sync_all_data || true
399 $LFS quota -v -$ugp $qid $DIR
401 if [ "$bf" == "a" -o "$bf" == "b" ]; then
402 usage=$(getquota -$ugp $qid global curspace)
403 if [ -z $usage ]; then
404 quota_error $ugp $qid \
405 "Query block quota failed ($ugp:$qid)."
407 [ $usage -ne 0 ] && quota_log $ugp $qid \
408 "Block quota isn't 0 ($ugp:$qid:$usage)."
412 if [ "$bf" == "a" -o "$bf" == "f" ]; then
413 usage=$(getquota -$ugp $qid global curinodes)
414 if [ -z $usage ]; then
415 quota_error $ugp $qid \
416 "Query file quota failed ($ugp:$qid)."
418 [ $usage -ne 0 ] && quota_log $ugp $qid \
419 "File quota isn't 0 ($ugp:$qid:$usage)."
424 enable_project_quota() {
425 is_project_quota_supported || return 0
426 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] && return 0
427 stopall || error "failed to stopall (1)"
429 for num in $(seq $MDSCOUNT); do
430 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
431 error "tune2fs $(mdsdevname $num) failed"
434 for num in $(seq $OSTCOUNT); do
435 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
436 error "tune2fs $(ostdevname $num) failed"
443 project_quota_enabled () {
445 for num in $(seq $MDSCOUNT); do
446 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
447 grep -q project || rc=1
449 for num in $(seq $OSTCOUNT); do
450 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
451 grep -q project || rc=1
453 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
457 project_quota_enabled || enable_project_quota
459 reset_quota_settings() {
460 resetquota -u $TSTUSR
461 resetquota -g $TSTUSR
462 resetquota -u $TSTUSR2
463 resetquota -g $TSTUSR2
464 resetquota -p $TSTPRJID
469 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
474 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
475 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
476 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
477 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
479 test_quota_performance() {
480 local TESTFILE="$DIR/$tdir/$tfile-0"
481 local size=$1 # in MB
482 local stime=$(date +%s)
483 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
484 quota_error u $TSTUSR "write failure"
485 local etime=$(date +%s)
486 delta=$((etime - stime))
487 if [ $delta -gt 0 ]; then
488 rate=$((size * 1024 / delta))
489 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
490 # LU-2872 - see LU-2887 for fix
492 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
494 [ $rate -gt 1024 ] ||
495 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
501 # test basic quota performance b=21696
504 [ "$SLOW" = "no" ] && MB=10
506 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
507 [ $free_space -le $((MB * 1024)) ] &&
508 skip "not enough space ${free_space} KB, " \
509 "required $((MB * 1024)) KB"
510 setup_quota_test || error "setup quota failed with $?"
511 trap cleanup_quota_test EXIT
513 set_ost_qtype "none" || error "disable ost quota failed"
514 test_quota_performance $MB
516 set_ost_qtype $QTYPE || error "enable ost quota failed"
517 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
518 error "set quota failed"
519 test_quota_performance $MB
523 run_test 0 "Test basic quota performance"
525 # test block hardlimit
528 local TESTFILE="$DIR/$tdir/$tfile-0"
530 setup_quota_test || error "setup quota failed with $?"
531 trap cleanup_quota_test EXIT
534 set_ost_qtype $QTYPE || error "enable ost quota failed"
537 log "User quota (block hardlimit:$LIMIT MB)"
538 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
539 error "set user quota failed"
541 # make sure the system is clean
542 local USED=$(getquota -u $TSTUSR global curspace)
543 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
545 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
546 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
549 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
550 quota_error u $TSTUSR "user write failure, but expect success"
551 log "Write out of block quota ..."
552 # this time maybe cache write, ignore it's failure
553 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
554 # flush cache, ensure noquota flag is set on client
556 sync; sync_all_data || true
557 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
558 quota_error u $TSTUSR "user write success, but expect EDQUOT"
561 wait_delete_completed || error "wait_delete_completed failed"
562 sync_all_data || true
563 USED=$(getquota -u $TSTUSR global curspace)
564 [ $USED -ne 0 ] && quota_error u $TSTUSR \
565 "user quota isn't released after deletion"
566 resetquota -u $TSTUSR
569 log "--------------------------------------"
570 log "Group quota (block hardlimit:$LIMIT MB)"
571 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
572 error "set group quota failed"
574 TESTFILE="$DIR/$tdir/$tfile-1"
575 # make sure the system is clean
576 USED=$(getquota -g $TSTUSR global curspace)
577 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
579 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
580 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
583 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
584 quota_error g $TSTUSR "Group write failure, but expect success"
585 log "Write out of block quota ..."
586 # this time maybe cache write, ignore it's failure
587 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
589 sync; sync_all_data || true
590 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
591 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
593 wait_delete_completed || error "wait_delete_completed failed"
594 sync_all_data || true
595 USED=$(getquota -g $TSTUSR global curspace)
596 [ $USED -ne 0 ] && quota_error g $TSTUSR \
597 "Group quota isn't released after deletion"
598 resetquota -g $TSTUSR
600 if ! is_project_quota_supported; then
601 echo "Project quota is not supported"
606 TESTFILE="$DIR/$tdir/$tfile-2"
607 # make sure the system is clean
608 USED=$(getquota -p $TSTPRJID global curspace)
610 error "used space($USED) for project $TSTPRJID isn't 0"
613 log "--------------------------------------"
614 log "Project quota (block hardlimit:$LIMIT mb)"
615 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
616 error "set project quota failed"
618 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
619 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
620 change_project -p $TSTPRJID $TESTFILE
623 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
624 "project write failure, but expect success"
625 log "write out of block quota ..."
626 # this time maybe cache write, ignore it's failure
627 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
629 sync; sync_all_data || true
630 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
631 $TSTPRJID "project write success, but expect EDQUOT"
636 USED=$(getquota -p $TSTPRJID global curspace)
637 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
638 "project quota isn't released after deletion"
640 run_test 1 "Block hard limit (normal use and out of quota)"
642 # test inode hardlimit
644 local LIMIT=$((1024 * 1024)) # 1M inodes
645 local TESTFILE="$DIR/$tdir/$tfile-0"
647 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
649 local FREE_INODES=$(mdt_free_inodes 0)
650 echo "$FREE_INODES free inodes on master MDT"
651 [ $FREE_INODES -lt $LIMIT ] &&
652 skip "not enough free inodes $FREE_INODES required $LIMIT"
654 setup_quota_test || error "setup quota failed with $?"
655 trap cleanup_quota_test EXIT
658 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
661 log "User quota (inode hardlimit:$LIMIT files)"
662 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
663 error "set user quota failed"
665 # make sure the system is clean
666 local USED=$(getquota -u $TSTUSR global curinodes)
667 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
669 log "Create $LIMIT files ..."
670 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
671 quota_error u $TSTUSR "user create failure, but expect success"
672 log "Create out of file quota ..."
673 $RUNAS touch ${TESTFILE}_xxx &&
674 quota_error u $TSTUSR "user create success, but expect EDQUOT"
677 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
678 rm -f ${TESTFILE}_xxx
679 wait_delete_completed
681 USED=$(getquota -u $TSTUSR global curinodes)
682 [ $USED -ne 0 ] && quota_error u $TSTUSR \
683 "user quota isn't released after deletion"
684 resetquota -u $TSTUSR
687 log "--------------------------------------"
688 log "Group quota (inode hardlimit:$LIMIT files)"
689 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
690 error "set group quota failed"
692 TESTFILE=$DIR/$tdir/$tfile-1
693 # make sure the system is clean
694 USED=$(getquota -g $TSTUSR global curinodes)
695 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
697 log "Create $LIMIT files ..."
698 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
699 quota_error g $TSTUSR "group create failure, but expect success"
700 log "Create out of file quota ..."
701 $RUNAS touch ${TESTFILE}_xxx &&
702 quota_error g $TSTUSR "group create success, but expect EDQUOT"
705 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
706 rm -f ${TESTFILE}_xxx
707 wait_delete_completed
709 USED=$(getquota -g $TSTUSR global curinodes)
710 [ $USED -ne 0 ] && quota_error g $TSTUSR \
711 "user quota isn't released after deletion"
713 resetquota -g $TSTUSR
714 ! is_project_quota_supported && cleanup_quota_test &&
715 echo "Skip project quota is not supported" && return 0
718 log "--------------------------------------"
719 log "Project quota (inode hardlimit:$LIMIT files)"
720 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
721 error "set project quota failed"
723 TESTFILE=$DIR/$tdir/$tfile-1
724 # make sure the system is clean
725 USED=$(getquota -p $TSTPRJID global curinodes)
727 error "Used inodes($USED) for project $TSTPRJID isn't 0"
729 change_project -sp $TSTPRJID $DIR/$tdir
730 log "Create $LIMIT files ..."
731 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
732 $TSTPRJID "project create fail, but expect success"
733 log "Create out of file quota ..."
734 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
735 "project create success, but expect EDQUOT"
736 change_project -C $DIR/$tdir
739 USED=$(getquota -p $TSTPRJID global curinodes)
740 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
741 "project quota isn't released after deletion"
744 run_test 2 "File hard limit (normal use and out of quota)"
748 local TIMER=$(($2 * 3 / 2))
754 trap cleanup_quota_test EXIT
756 $LFS setstripe $TESTFILE -c 1 -i 0
757 chown $TSTUSR.$TSTUSR $TESTFILE
758 [ "$qtype" == "p" ] && is_project_quota_supported &&
759 change_project -p $TSTPRJID $TESTFILE
761 echo "Write up to soft limit"
762 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
763 quota_error a $TSTUSR "write failure, but expect success"
764 OFFSET=$((LIMIT * 1024))
767 echo "Write to exceed soft limit"
768 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
769 quota_error a $TSTUSR "write failure, but expect success"
770 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
776 $SHOW_QUOTA_INFO_USER
777 $SHOW_QUOTA_INFO_GROUP
778 $SHOW_QUOTA_INFO_PROJID
780 echo "Write before timer goes off"
781 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
782 quota_error a $TSTUSR "write failure, but expect success"
783 OFFSET=$((OFFSET + 1024))
786 echo "Sleep $TIMER seconds ..."
792 $SHOW_QUOTA_INFO_USER
793 $SHOW_QUOTA_INFO_GROUP
794 $SHOW_QUOTA_INFO_PROJID
796 echo "Write after timer goes off"
797 # maybe cache write, ignore.
798 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
799 OFFSET=$((OFFSET + 1024))
801 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
802 quota_error a $TSTUSR "write success, but expect EDQUOT"
807 $SHOW_QUOTA_INFO_USER
808 $SHOW_QUOTA_INFO_GROUP
809 $SHOW_QUOTA_INFO_PROJID
811 echo "Unlink file to stop timer"
813 wait_delete_completed
814 sync_all_data || true
819 $SHOW_QUOTA_INFO_USER
820 $SHOW_QUOTA_INFO_GROUP
821 $SHOW_QUOTA_INFO_PROJID
823 $LFS setstripe $TESTFILE -c 1 -i 0
824 chown $TSTUSR.$TSTUSR $TESTFILE
825 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
828 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
829 quota_error a $TSTUSR "write failure, but expect success"
838 local TESTFILE=$DIR/$tdir/$tfile-0
840 set_ost_qtype $QTYPE || error "enable ost quota failed"
842 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
843 # make sure the system is clean
844 local USED=$(getquota -u $TSTUSR global curspace)
845 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
847 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
848 $MAX_IQ_TIME $DIR || error "set user grace time failed"
849 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
850 error "set user quota failed"
852 test_block_soft $TESTFILE $GRACE $LIMIT "u"
854 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
855 TESTFILE=$DIR/$tdir/$tfile-1
856 # make sure the system is clean
857 USED=$(getquota -g $TSTUSR global curspace)
858 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
860 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
861 $MAX_IQ_TIME $DIR || error "set group grace time failed"
862 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
863 error "set group quota failed"
865 test_block_soft $TESTFILE $GRACE $LIMIT "g"
867 if is_project_quota_supported; then
868 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
869 TESTFILE=$DIR/$tdir/$tfile-2
870 # make sure the system is clean
871 USED=$(getquota -p $TSTPRJID global curspace)
872 [ $USED -ne 0 ] && error \
873 "Used space($USED) for project $TSTPRJID isn't 0."
875 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
877 error "set project grace time failed"
878 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
879 $DIR || error "set project quota failed"
881 test_block_soft $TESTFILE $GRACE $LIMIT "p"
882 resetquota -p $TSTPRJID
883 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
885 error "restore project grace time failed"
889 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
890 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
891 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
892 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
894 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
900 local TIMER=$(($grace * 3 / 2))
903 trap cleanup_quota_test EXIT
904 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
906 echo "Create files to exceed soft limit"
907 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
908 quota_error a $TSTUSR "create failure, but expect success"
909 local trigger_time=$(date +%s)
911 sync_all_data || true
913 local cur_time=$(date +%s)
914 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
915 error "Passed grace time $grace, $trigger_time, $cur_time"
917 echo "Create file before timer goes off"
918 $RUNAS touch ${TESTFILE}_before ||
919 quota_error a $TSTUSR "failed create before timer expired," \
920 "but expect success. $trigger_time, $cur_time"
921 sync_all_data || true
923 echo "Sleep $TIMER seconds ..."
929 $SHOW_QUOTA_INFO_USER
930 $SHOW_QUOTA_INFO_GROUP
931 $SHOW_QUOTA_INFO_PROJID
933 echo "Create file after timer goes off"
934 # There is a window that space is accounted in the quota usage but
935 # hasn't been decreased from the pending write, if we acquire quota
936 # in this window, we'll acquire more than we needed.
937 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
938 sync_all_data || true
939 $RUNAS touch ${TESTFILE}_after_3 &&
940 quota_error a $TSTUSR "create after timer expired," \
942 sync_all_data || true
947 $SHOW_QUOTA_INFO_USER
948 $SHOW_QUOTA_INFO_GROUP
949 $SHOW_QUOTA_INFO_PROJID
951 echo "Unlink files to stop timer"
952 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
953 wait_delete_completed
956 $RUNAS touch ${TESTFILE}_xxx ||
957 quota_error a $TSTUSR "touch after timer stop failure," \
959 sync_all_data || true
967 local LIMIT=10 # inodes
968 local TESTFILE=$DIR/$tdir/$tfile-0
971 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
973 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
974 # make sure the system is clean
975 local USED=$(getquota -u $TSTUSR global curinodes)
976 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
978 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
979 $GRACE $DIR || error "set user grace time failed"
980 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
981 error "set user quota failed"
983 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && GRACE=20
985 test_file_soft $TESTFILE $LIMIT $GRACE
987 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
988 # make sure the system is clean
989 USED=$(getquota -g $TSTUSR global curinodes)
990 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
992 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
993 $GRACE $DIR || error "set group grace time failed"
994 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
995 error "set group quota failed"
996 TESTFILE=$DIR/$tdir/$tfile-1
998 test_file_soft $TESTFILE $LIMIT $GRACE
1000 if is_project_quota_supported; then
1001 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
1002 # make sure the system is clean
1003 USED=$(getquota -p $TSTPRJID global curinodes)
1004 [ $USED -ne 0 ] && error \
1005 "Used space($USED) for project $TSTPRJID isn't 0."
1007 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1008 $GRACE $DIR || error "set project grace time failed"
1009 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1010 error "set project quota failed"
1012 TESTFILE=$DIR/$tdir/$tfile-1
1013 # one less than limit, because of parent directory included.
1014 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE
1015 resetquota -p $TSTPRJID
1016 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1017 $MAX_IQ_TIME $DIR ||
1018 error "restore project grace time failed"
1022 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1023 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1024 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1025 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1027 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1030 local GR_STR1="1w3d"
1031 local GR_STR2="1000s"
1033 local GR_STR4="1w2d3h4m5s"
1035 local GR_STR6="18446744073709551615"
1038 wait_delete_completed
1040 # test of valid grace strings handling
1041 echo "Valid grace strings test"
1042 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1043 $GR_STR2 $DIR || error "set user grace time failed"
1044 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1045 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1046 $GR_STR4 $DIR || error "set group grace time quota failed"
1047 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1049 # test of invalid grace strings handling
1050 echo " Invalid grace strings test"
1051 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1052 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1053 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1057 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1058 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1059 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1060 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1062 run_test 4b "Grace time strings handling"
1064 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1066 local BLIMIT=10 # 10M
1067 local ILIMIT=10 # 10 inodes
1069 setup_quota_test || error "setup quota failed with $?"
1070 trap cleanup_quota_test EXIT
1072 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1073 set_ost_qtype $QTYPE || error "enable ost quota failed"
1075 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1076 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1077 error "set user quota failed"
1078 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1079 if is_project_quota_supported; then
1080 error "set group quota failed"
1081 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1082 -I $ILIMIT $DIR || error "set project quota failed"
1085 # make sure the system is clean
1086 local USED=$(getquota -u $TSTUSR global curinodes)
1087 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1088 USED=$(getquota -g $TSTUSR global curinodes)
1089 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1090 USED=$(getquota -u $TSTUSR global curspace)
1091 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1092 USED=$(getquota -g $TSTUSR global curspace)
1093 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1094 if is_project_quota_supported; then
1095 USED=$(getquota -p $TSTPRJID global curinodes)
1097 error "Used inode($USED) for project $TSTPRJID isn't 0."
1098 USED=$(getquota -p $TSTPRJID global curspace)
1100 error "Used block($USED) for project $TSTPRJID isn't 0."
1103 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1104 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1105 error "create failure, expect success"
1106 if is_project_quota_supported; then
1107 touch $DIR/$tdir/$tfile-0_1
1108 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1110 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1111 error "write failure, expect success"
1113 echo "Chown files to $TSTUSR.$TSTUSR ..."
1114 for i in $(seq 0 $ILIMIT); do
1115 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1116 quota_error a $TSTUSR "chown failure, expect success"
1120 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1121 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1124 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1126 # test dropping acquire request on master
1130 # Clear dmesg so watchdog is not triggered by previous
1132 do_facet ost1 dmesg -c > /dev/null
1134 setup_quota_test || error "setup quota failed with $?"
1135 trap cleanup_quota_test EXIT
1137 # make sure the system is clean
1138 local USED=$(getquota -u $TSTUSR global curspace)
1139 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1141 # make sure no granted quota on ost
1142 set_ost_qtype $QTYPE || error "enable ost quota failed"
1143 resetquota -u $TSTUSR
1145 # create file for $TSTUSR
1146 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1147 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1148 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1150 # create file for $TSTUSR2
1151 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1152 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1153 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1155 # cache per-ID lock for $TSTUSR on slave
1156 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1157 error "set quota failed"
1158 $RUNAS $DD of=$TESTFILE count=1 ||
1159 error "write $TESTFILE failure, expect success"
1160 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1161 error "write $TESTFILE2 failure, expect success"
1163 sync_all_data || true
1165 #define QUOTA_DQACQ 601
1166 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1167 lustre_fail mds 0x513 601
1169 do_facet ost1 $LCTL set_param \
1170 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1172 # write to un-enforced ID ($TSTUSR2) should succeed
1173 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1174 error "write failure, expect success"
1176 # write to enforced ID ($TSTUSR) in background, exceeding limit
1177 # to make sure DQACQ is sent
1178 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1181 # watchdog timer uses a factor of 2
1182 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1183 sleep $((TIMEOUT * 2 + 1))
1185 # write should be blocked and never finished
1186 if ! ps -p $DDPID > /dev/null 2>&1; then
1188 error "write finished incorrectly!"
1193 # no watchdog is triggered
1194 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1195 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1196 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1197 [ -z "$watchdog" ] || error "$watchdog"
1199 rm -f $TMP/lustre-log-${TESTNAME}.log
1201 # write should continue then fail with EDQUOT
1205 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1206 if [ $count -ge 240 ]; then
1207 quota_error u $TSTUSR "dd not finished in $count secs"
1209 count=$((count + 1))
1210 if [ $((count % 30)) -eq 0 ]; then
1211 c_size=$(stat -c %s $TESTFILE)
1212 echo "Waiting $count secs. $c_size"
1220 run_test 6 "Test dropping acquire request on master"
1222 # quota reintegration (global index)
1224 local TESTFILE=$DIR/$tdir/$tfile
1225 local LIMIT=20 # 20M
1227 [ "$SLOW" = "no" ] && LIMIT=5
1229 setup_quota_test || error "setup quota failed with $?"
1230 trap cleanup_quota_test EXIT
1232 # make sure the system is clean
1233 local USED=$(getquota -u $TSTUSR global curspace)
1234 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1236 # make sure no granted quota on ost1
1237 set_ost_qtype $QTYPE || error "enable ost quota failed"
1238 resetquota -u $TSTUSR
1239 set_ost_qtype "none" || error "disable ost quota failed"
1241 local OSTUUID=$(ostuuid_from_index 0)
1242 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1244 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1247 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1248 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1253 echo "Enable quota & set quota limit for $TSTUSR"
1254 set_ost_qtype $QTYPE || error "enable ost quota failed"
1255 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1256 error "set quota failed"
1258 echo "Start ost1..."
1259 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1262 wait_ost_reint $QTYPE || error "reintegration failed"
1264 # hardlimit should have been fetched by slave during global
1265 # reintegration, write will exceed quota
1266 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1267 quota_error u $TSTUSR "write success, but expect EDQUOT"
1270 wait_delete_completed
1271 sync_all_data || true
1277 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1278 error "clear quota failed"
1280 echo "Start ost1..."
1281 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1284 wait_ost_reint $QTYPE || error "reintegration failed"
1286 # hardlimit should be cleared on slave during reintegration
1287 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1288 quota_error u $TSTUSR "write error, but expect success"
1292 run_test 7a "Quota reintegration (global index)"
1294 # quota reintegration (slave index)
1297 local TESTFILE=$DIR/$tdir/$tfile
1299 setup_quota_test || error "setup quota failed with $?"
1300 trap cleanup_quota_test EXIT
1302 # make sure the system is clean
1303 local USED=$(getquota -u $TSTUSR global curspace)
1304 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1306 # make sure no granted quota on ost1
1307 set_ost_qtype $QTYPE || error "enable ost quota failed"
1308 resetquota -u $TSTUSR
1309 set_ost_qtype "none" || error "disable ost quota failed"
1311 local OSTUUID=$(ostuuid_from_index 0)
1312 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1314 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1317 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1318 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1320 # consume some space to make sure the granted space will not
1321 # be released during reconciliation
1322 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1323 error "consume space failure, expect success"
1325 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1326 lustre_fail mds 0xa02
1328 set_ost_qtype $QTYPE || error "enable ost quota failed"
1329 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1330 error "set quota failed"
1332 # ignore the write error
1333 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1335 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1339 echo "Restart ost to trigger reintegration..."
1341 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1344 wait_ost_reint $QTYPE || error "reintegration failed"
1346 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1347 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1352 run_test 7b "Quota reintegration (slave index)"
1354 # quota reintegration (restart mds during reintegration)
1356 local LIMIT=20 # 20M
1357 local TESTFILE=$DIR/$tdir/$tfile
1359 [ "$SLOW" = "no" ] && LIMIT=5
1361 setup_quota_test || error "setup quota failed with $?"
1362 trap cleanup_quota_test EXIT
1364 # make sure the system is clean
1365 local USED=$(getquota -u $TSTUSR global curspace)
1366 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1368 set_ost_qtype "none" || error "disable ost quota failed"
1369 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1370 error "set quota failed"
1372 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1373 lustre_fail ost 0xa03
1376 set_ost_qtype $QTYPE || error "enable ost quota failed"
1377 # trigger reintegration
1378 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1379 procf=${procf}quota_slave.force_reint
1380 do_facet ost1 $LCTL set_param $procf=1 ||
1381 error "force reintegration failed"
1389 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1392 # wait longer than usual to make sure the reintegration
1393 # is triggered by quota wb thread.
1394 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1396 # hardlimit should have been fetched by slave during global
1397 # reintegration, write will exceed quota
1398 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1399 quota_error u $TSTUSR "write success, but expect EDQUOT"
1403 run_test 7c "Quota reintegration (restart mds during reintegration)"
1405 # Quota reintegration (Transfer index in multiple bulks)
1407 local TESTFILE=$DIR/$tdir/$tfile
1408 local TESTFILE1="$DIR/$tdir/$tfile"-1
1411 setup_quota_test || error "setup quota failed with $?"
1412 trap cleanup_quota_test EXIT
1414 set_ost_qtype "none" || error "disable ost quota failed"
1415 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1416 error "set quota for $TSTUSR failed"
1417 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1418 error "set quota for $TSTUSR2 failed"
1420 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1421 lustre_fail mds 0x608 0
1423 # enable quota to tirgger reintegration
1424 set_ost_qtype "u" || error "enable ost quota failed"
1425 wait_ost_reint "u" || error "reintegration failed"
1429 # hardlimit should have been fetched by slave during global
1430 # reintegration, write will exceed quota
1431 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1432 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1434 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1435 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1439 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1441 # quota reintegration (inode limits)
1443 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1445 # LU-2435: skip this quota test if underlying zfs version has not
1446 # supported native dnode accounting
1447 [ "$(facet_fstype mds1)" == "zfs" ] && {
1448 local F="feature@userobj_accounting"
1449 local pool=$(zpool_name mds1)
1450 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1452 [[ "$feature" != *" active "* ]] &&
1453 skip "requires zpool with active userobj_accounting"
1456 local ilimit=$((1024 * 2)) # 2k inodes
1457 local TESTFILE=$DIR/${tdir}-1/$tfile
1459 setup_quota_test || error "setup quota failed with $?"
1460 trap cleanup_quota_test EXIT
1462 # make sure the system is clean
1463 local USED=$(getquota -u $TSTUSR global curinodes)
1464 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1466 # make sure no granted quota on mdt1
1467 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1468 resetquota -u $TSTUSR
1469 set_mdt_qtype "none" || error "disable mdt quota failed"
1471 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1472 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1473 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1476 echo "Stop mds${MDSCOUNT}..."
1479 echo "Enable quota & set quota limit for $TSTUSR"
1480 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1481 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1482 error "set quota failed"
1484 echo "Start mds${MDSCOUNT}..."
1485 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1488 wait_mdt_reint $QTYPE || error "reintegration failed"
1490 echo "create remote dir"
1491 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1492 error "create remote dir failed"
1493 chmod 0777 $DIR/${tdir}-1
1495 # hardlimit should have been fetched by slave during global
1496 # reintegration, create will exceed quota
1497 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1498 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1500 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1501 wait_delete_completed
1502 sync_all_data || true
1504 echo "Stop mds${MDSCOUNT}..."
1507 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1508 error "clear quota failed"
1510 echo "Start mds${MDSCOUNT}..."
1511 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1514 wait_mdt_reint $QTYPE || error "reintegration failed"
1516 # hardlimit should be cleared on slave during reintegration
1517 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1518 quota_error u $TSTUSR "create failed, expect success"
1520 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1521 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1525 run_test 7e "Quota reintegration (inode limits)"
1527 # run dbench with quota enabled
1529 local BLK_LIMIT="100g" #100G
1530 local FILE_LIMIT=1000000
1532 setup_quota_test || error "setup quota failed with $?"
1533 trap cleanup_quota_test EXIT
1535 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1536 set_ost_qtype $QTYPE || error "enable ost quota failed"
1538 echo "Set enough high limit for user: $TSTUSR"
1539 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1540 error "set user quota failed"
1541 echo "Set enough high limit for group: $TSTUSR"
1542 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1543 error "set group quota failed"
1544 if is_project_quota_supported; then
1545 change_project -sp $TSTPRJID $DIR/$tdir
1546 echo "Set enough high limit for project: $TSTPRJID"
1547 $LFS setquota -p $TSTPRJID -b 0 \
1548 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1549 error "set project quota failed"
1553 [ "$SLOW" = "no" ] && duration=" -t 120"
1554 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1555 quota_error a $TSTUSR "dbench failed!"
1557 is_project_quota_supported && change_project -C $DIR/$tdir
1560 run_test 8 "Run dbench with quota enabled"
1562 # this check is just for test_9
1563 OST0_MIN=4900000 #4.67G
1565 check_whether_skip () {
1566 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1567 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1568 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1569 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1576 # run for fixing bug10707, it needs a big room. test for 64bit
1578 local filesize=$((1024 * 9 / 2)) # 4.5G
1580 check_whether_skip && return 0
1582 setup_quota_test || error "setup quota failed with $?"
1583 trap cleanup_quota_test EXIT
1585 set_ost_qtype "ug" || error "enable ost quota failed"
1587 local TESTFILE="$DIR/$tdir/$tfile-0"
1588 local BLK_LIMIT=100G #100G
1589 local FILE_LIMIT=1000000
1591 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1593 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1595 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1596 error "set user quota failed"
1598 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1599 "for group: $TSTUSR"
1600 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set group quota failed"
1603 quota_show_check a u $TSTUSR
1604 quota_show_check a g $TSTUSR
1606 echo "Create test file"
1607 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1608 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1610 log "Write the big file of 4.5G ..."
1611 $RUNAS $DD of=$TESTFILE count=$filesize ||
1612 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1622 run_test 9 "Block limit larger than 4GB (b10707)"
1625 local TESTFILE=$DIR/$tdir/$tfile
1627 setup_quota_test || error "setup quota failed with $?"
1628 trap cleanup_quota_test EXIT
1630 # set limit to root user should fail
1631 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1632 error "set limit for root user successfully, expect failure"
1633 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1634 error "set limit for root group successfully, expect failure"
1635 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1636 error "set limit for project 0 successfully, expect failure"
1638 # root user can overrun quota
1639 set_ost_qtype "ug" || error "enable ost quota failed"
1641 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1642 error "set quota failed"
1643 quota_show_check b u $TSTUSR
1645 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1646 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1648 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1649 error "write failure, expect success"
1653 run_test 10 "Test quota for root user"
1656 local TESTFILE=$DIR/$tdir/$tfile
1657 setup_quota_test || error "setup quota failed with $?"
1658 trap cleanup_quota_test EXIT
1660 set_mdt_qtype "ug" || error "enable mdt quota failed"
1661 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1662 error "set quota failed"
1664 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1665 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1667 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1668 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1671 local USED=$(getquota -u $TSTUSR global curinodes)
1672 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1676 run_test 11 "Chown/chgrp ignores quota"
1679 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1681 local blimit=22 # 22M
1682 local blk_cnt=$((blimit - 5))
1683 local TESTFILE0="$DIR/$tdir/$tfile"-0
1684 local TESTFILE1="$DIR/$tdir/$tfile"-1
1686 setup_quota_test || error "setup quota failed with $?"
1687 trap cleanup_quota_test EXIT
1689 set_ost_qtype "u" || error "enable ost quota failed"
1690 quota_show_check b u $TSTUSR
1692 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1693 error "set quota failed"
1695 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1696 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1697 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1698 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1700 echo "Write to ost0..."
1701 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1702 quota_error a $TSTUSR "dd failed"
1704 echo "Write to ost1..."
1705 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1706 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1708 echo "Free space from ost0..."
1710 wait_delete_completed
1711 sync_all_data || true
1713 echo "Write to ost1 after space freed from ost0..."
1714 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1715 quota_error a $TSTUSR "rebalancing failed"
1719 run_test 12a "Block quota rebalancing"
1722 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1724 local ilimit=$((1024 * 2)) # 2k inodes
1725 local TESTFILE0=$DIR/$tdir/$tfile
1726 local TESTFILE1=$DIR/${tdir}-1/$tfile
1728 setup_quota_test || error "setup quota failed with $?"
1729 trap cleanup_quota_test EXIT
1731 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1732 chmod 0777 $DIR/${tdir}-1
1734 set_mdt_qtype "u" || error "enable mdt quota failed"
1735 quota_show_check f u $TSTUSR
1737 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1738 error "set quota failed"
1740 echo "Create $ilimit files on mdt0..."
1741 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1742 quota_error u $TSTUSR "create failed, but expect success"
1744 echo "Create files on mdt1..."
1745 $RUNAS createmany -m $TESTFILE1 1 &&
1746 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1748 echo "Free space from mdt0..."
1749 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1750 wait_delete_completed
1751 sync_all_data || true
1753 echo "Create files on mdt1 after space freed from mdt0..."
1754 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1755 quota_error a $TSTUSR "rebalancing failed"
1757 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1758 error "unlink mdt1 files failed"
1759 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1763 run_test 12b "Inode quota rebalancing"
1766 local TESTFILE=$DIR/$tdir/$tfile
1767 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1768 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1770 setup_quota_test || error "setup quota failed with $?"
1771 trap cleanup_quota_test EXIT
1773 set_ost_qtype "u" || error "enable ost quota failed"
1774 quota_show_check b u $TSTUSR
1776 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1777 error "set quota failed"
1778 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1779 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1781 # clear the locks in cache first
1782 do_facet ost1 $LCTL set_param -n $procf=clear
1783 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1784 [ $nlock -eq 0 ] || error "$nlock cached locks"
1786 # write to acquire the per-ID lock
1787 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1788 quota_error a $TSTUSR "dd failed"
1790 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1791 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1793 # clear quota doesn't trigger per-ID lock cancellation
1794 resetquota -u $TSTUSR
1795 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1796 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1798 # clear the per-ID lock
1799 do_facet ost1 $LCTL set_param -n $procf=clear
1800 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1801 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1803 # spare quota should be released
1804 local OSTUUID=$(ostuuid_from_index 0)
1805 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1806 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1807 [ $limit -le $space ] ||
1808 error "spare quota isn't released, limit:$limit, space:$space"
1812 run_test 13 "Cancel per-ID lock in the LRU list"
1815 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1817 wait_delete_completed
1818 sync_all_data || true
1821 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1822 error "set user quota failed"
1823 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1824 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1825 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1826 resetquota -u $TSTUSR
1829 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1830 error "set group quota failed"
1831 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1832 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1833 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1834 resetquota -g $TSTUSR
1836 run_test 15 "Set over 4T block quota"
1840 local BLKS=1 # 1M less than limit
1841 local TESTFILE=$DIR/$tdir/$tfile
1843 setup_quota_test || error "setup quota failed with $?"
1844 trap cleanup_quota_test EXIT
1846 # make sure the system is clean
1847 local USED=$(getquota -u $TSTUSR global curspace)
1848 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1850 set_ost_qtype "ug" || error "enable ost quota failed"
1851 # make sure no granted quota on ost
1852 resetquota -u $TSTUSR
1853 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1854 error "set quota failed"
1856 quota_show_check b u $TSTUSR
1858 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1859 lustre_fail mds 0xa04 $err_code
1861 # write in background
1862 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1866 # write should be blocked and never finished
1867 if ! ps -p $DDPID > /dev/null 2>&1; then
1869 quota_error u $TSTUSR "write finished incorrectly!"
1877 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1879 if [ $count -gt $timeout ]; then
1880 quota_error u $TSTUSR "dd is not finished!"
1885 sync; sync_all_data || true
1887 USED=$(getquota -u $TSTUSR global curspace)
1888 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1889 "Used space(${USED}K) is less than ${BLKS}M"
1894 # DQACQ return recoverable error
1896 echo "DQACQ return -ENOLCK"
1898 test_17sub 37 || error "Handle -ENOLCK failed"
1900 echo "DQACQ return -EAGAIN"
1902 test_17sub 11 || error "Handle -EAGAIN failed"
1904 echo "DQACQ return -ETIMEDOUT"
1905 #define ETIMEDOUT 110
1906 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1908 echo "DQACQ return -ENOTCONN"
1909 #define ENOTCONN 107
1910 test_17sub 107 || error "Handle -ENOTCONN failed"
1913 run_test 17 "DQACQ return recoverable error"
1917 local blimit="200m" # 200M
1918 local TESTFILE="$DIR/$tdir/$tfile"
1920 setup_quota_test || error "setup quota failed with $?"
1921 trap cleanup_quota_test EXIT
1923 set_ost_qtype "u" || error "enable ost quota failed"
1924 log "User quota (limit: $blimit)"
1925 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1926 error "set quota failed"
1927 quota_show_check b u $TSTUSR
1929 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1930 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1932 local timeout=$(sysctl -n lustre.timeout)
1934 if [ $io_type = "directio" ]; then
1935 log "Write 100M (directio) ..."
1936 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1938 log "Write 100M (buffered) ..."
1939 $RUNAS $DD of=$TESTFILE count=100 &
1943 replay_barrier $SINGLEMDS
1944 log "Fail mds for $((2 * timeout)) seconds"
1945 fail $SINGLEMDS $((2 * timeout))
1948 if at_is_enabled; then
1949 timeout=$(at_max_get mds)
1951 timeout=$(lctl get_param -n timeout)
1955 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1956 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1957 log "it took $count second"
1962 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1964 cancel_lru_locks mdc
1965 cancel_lru_locks osc
1968 local testfile_size=$(stat -c %s $TESTFILE)
1969 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1970 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1971 "got ${testfile_size}. Verifying file failed!"
1976 # test when mds does failover, the ost still could work well
1977 # this test shouldn't trigger watchdog b=14840
1979 # Clear dmesg so watchdog is not triggered by previous
1981 do_facet ost1 dmesg -c > /dev/null
1984 test_18_sub directio
1986 # check if watchdog is triggered
1987 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1988 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1989 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1990 [ -z "$watchdog" ] || error "$watchdog"
1991 rm -f $TMP/lustre-log-${TESTNAME}.log
1993 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1997 local TESTFILE=$DIR/$tdir/$tfile
1999 setup_quota_test || error "setup quota failed with $?"
2000 trap cleanup_quota_test EXIT
2002 set_ost_qtype $QTYPE || error "enable ost quota failed"
2004 # bind file to a single OST
2005 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2006 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2008 echo "Set user quota (limit: ${blimit}M)"
2009 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2010 error "set user quota failed"
2011 quota_show_check b u $TSTUSR
2012 echo "Update quota limits"
2013 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2014 error "set group quota failed"
2015 quota_show_check b u $TSTUSR
2017 # first wirte might be cached
2018 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2019 cancel_lru_locks osc
2021 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2022 quota_error u $TSTUSR "Write success, expect failure"
2027 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2029 test_20() { # b15754
2030 local LSTR=(2g 1t 4k 3m) # limits strings
2032 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2035 resetquota -u $TSTUSR
2037 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2038 $MOUNT || error "could not set quota limits"
2039 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2040 --inode-softlimit ${LSTR[2]} \
2041 --inode-hardlimit ${LSTR[3]} \
2042 $MOUNT || error "could not set quota limits"
2044 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2045 error "bsoftlimit was not set properly"
2046 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2047 error "bhardlimit was not set properly"
2048 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2049 error "isoftlimit was not set properly"
2050 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2051 error "ihardlimit was not set properly"
2053 resetquota -u $TSTUSR
2055 run_test 20 "Test if setquota specifiers work properly (b15754)"
2062 local time=$(($(date +%s) + seconds))
2063 while [ $(date +%s) -lt $time ]; do
2064 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2068 # run for fixing bug16053, setquota shouldn't fail when writing and
2069 # deleting are happening
2071 local TESTFILE="$DIR/$tdir/$tfile"
2072 local BLIMIT=10 # 10G
2073 local ILIMIT=1000000
2075 setup_quota_test || error "setup quota failed with $?"
2076 trap cleanup_quota_test EXIT
2078 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2080 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2081 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2082 error "set user quota failed"
2083 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2084 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2085 error "set group quota failed"
2086 if is_project_quota_supported; then
2087 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2088 "project: $TSTPRJID"
2089 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2090 $MOUNT || error "set project quota failed"
2093 # repeat writing on a 1M file
2094 test_21_sub ${TESTFILE}_1 1 30 &
2096 # repeat writing on a 128M file
2097 test_21_sub ${TESTFILE}_2 128 30 &
2100 local time=$(($(date +%s) + 30))
2102 while [ $(date +%s) -lt $time ]; do
2103 log "Set quota for $i times"
2104 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2105 -I $((ILIMIT + i)) $MOUNT ||
2106 error "Set user quota failed"
2107 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2108 -I $((ILIMIT + i)) $MOUNT ||
2109 error "Set group quota failed"
2110 if is_project_quota_supported; then
2111 $LFS setquota -p $TSTPRJID -b 0 -B \
2112 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2113 error "Set project quota failed"
2121 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2123 if [ $count -gt 60 ]; then
2124 quota_error a $TSTUSR "dd should be finished!"
2128 echo "(dd_pid=$DDPID1, time=$count)successful"
2132 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2134 if [ $count -gt 60 ]; then
2135 quota_error a $TSTUSR "dd should be finished!"
2139 echo "(dd_pid=$DDPID2, time=$count)successful"
2143 run_test 21 "Setquota while writing & deleting (b16053)"
2145 # enable/disable quota enforcement permanently
2147 echo "Set both mdt & ost quota type as ug"
2149 is_project_quota_supported && qtype=$QTYPE
2150 set_mdt_qtype $qtype || error "enable mdt quota failed"
2151 set_ost_qtype $qtype || error "enable ost quota failed"
2154 stopall || error "failed to stopall (1)"
2158 echo "Verify if quota is enabled"
2159 local qtype1=$(mdt_quota_type)
2160 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2161 qtype=$(ost_quota_type)
2162 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2164 echo "Set both mdt & ost quota type as none"
2165 set_mdt_qtype "none" || error "disable mdt quota failed"
2166 set_ost_qtype "none" || error "disable ost quota failed"
2169 stopall || error "failed to stopall (2)"
2174 echo "Verify if quota is disabled"
2175 qtype=$(mdt_quota_type)
2176 [ $qtype != "none" ] && error "mdt quota setting is lost"
2177 qtype=$(ost_quota_type)
2178 [ $qtype != "none" ] && error "ost quota setting is lost"
2182 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2185 local TESTFILE="$DIR/$tdir/$tfile"
2188 setup_quota_test || error "setup quota failed with $?"
2189 trap cleanup_quota_test EXIT
2191 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2194 log "User quota (limit: $LIMIT MB)"
2195 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2196 error "set quota failed"
2197 quota_show_check b u $TSTUSR
2199 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2200 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2202 log "Step1: trigger EDQUOT with O_DIRECT"
2203 log "Write half of file"
2204 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2205 quota_error u $TSTUSR "(1) Write failure, expect success." \
2207 log "Write out of block quota ..."
2208 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2209 oflag=direct conv=notrunc &&
2210 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2214 log "Step2: rewrite should succeed"
2215 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2216 quota_error u $TSTUSR "(3) Write failure, expect success." \
2222 local OST0_UUID=$(ostuuid_from_index 0)
2223 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2224 [ $OST0_QUOTA_USED -ne 0 ] &&
2225 ($SHOW_QUOTA_USER; \
2226 quota_error u $TSTUSR "quota isn't released")
2231 [ $(facet_fstype ost1) == "zfs" ] &&
2232 skip "Overwrite in place is not guaranteed to be " \
2233 "space neutral on ZFS"
2235 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2236 check_whether_skip && return 0
2237 log "run for 4MB test file"
2240 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2241 check_whether_skip && return 0
2242 log "run for 40MB test file"
2245 run_test 23 "Quota should be honored with directIO (b16125)"
2249 local TESTFILE="$DIR/$tdir/$tfile"
2251 setup_quota_test || error "setup quota failed with $?"
2252 trap cleanup_quota_test EXIT
2254 set_ost_qtype $QTYPE || error "enable ost quota failed"
2256 # bind file to a single OST
2257 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2258 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2260 echo "Set user quota (limit: ${blimit}M)"
2261 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2262 error "set quota failed"
2264 # overrun quota by root user
2265 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2266 error "write failure, expect success"
2267 cancel_lru_locks osc
2268 sync_all_data || true
2270 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2274 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2276 test_27a() { # b19612
2277 $LFS quota $TSTUSR $DIR &&
2278 error "lfs succeeded with no type, but should have failed"
2279 $LFS setquota $TSTUSR $DIR &&
2280 error "lfs succeeded with no type, but should have failed"
2283 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2285 test_27b() { # b20200
2286 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2287 error "lfs setquota failed with uid argument"
2288 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2289 error "lfs stequota failed with gid argument"
2290 if is_project_quota_supported; then
2291 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2292 1000 $DIR || error \
2293 "lfs stequota failed with projid argument"
2295 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2296 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2297 if is_project_quota_supported; then
2298 $SHOW_QUOTA_PROJID ||
2299 error "lfs quota failed with projid argument"
2301 resetquota -u $TSTUSR
2302 resetquota -g $TSTUSR
2303 resetquota -p $TSTPRJID
2306 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2311 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2312 error "lfs setquota failed"
2314 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2315 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2316 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2317 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2319 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2320 error "lfs setquota for $TSTID failed"
2322 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2323 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2324 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2325 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2327 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2328 error "total allocated inode/block limit not printed"
2330 resetquota -u $TSTUSR
2332 run_test 27c "lfs quota should support human-readable output"
2339 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2340 error "set fraction block limit failed"
2341 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2342 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2343 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2344 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2346 resetquota -u $TSTUSR
2348 run_test 27d "lfs setquota should support fraction block limit"
2352 local TESTFILE="$DIR/$tdir/$tfile"
2355 setup_quota_test || error "setup quota failed with $?"
2356 trap cleanup_quota_test EXIT
2358 set_ost_qtype "u" || error "enable ost quota failed"
2360 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2361 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2363 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2364 $MAX_IQ_TIME $DIR || error "set grace time failed"
2365 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2366 error "set quota failed"
2367 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2368 cancel_lru_locks osc
2370 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2371 # over-quota flag has not yet settled since we do not trigger async
2372 # events based on grace time period expiration
2374 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2375 cancel_lru_locks osc
2376 # now over-quota flag should be settled and further writes should fail
2378 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2379 error "grace times were reset"
2382 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2383 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2385 run_test 30 "Hard limit updates should not reset grace times"
2387 # basic usage tracking for user & group
2389 local INODES=10 # 10 files
2390 local BLK_CNT=2 # of 2M each
2391 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2393 setup_quota_test || error "setup quota failed with $?"
2394 trap cleanup_quota_test EXIT
2396 # make sure the system is clean
2397 local USED=$(getquota -u $TSTID global curspace)
2399 error "Used space ($USED) for user $TSTID isn't 0."
2400 USED=$(getquota -g $TSTID global curspace)
2402 error "Used space ($USED) for group $TSTID isn't 0."
2403 if is_project_quota_supported; then
2404 USED=$(getquota -p $TSTPRJID global curspace)
2405 [ $USED -ne 0 ] && error \
2406 "Used space ($USED) for project $TSTPRJID isn't 0."
2409 echo "Write files..."
2410 for i in $(seq 0 $INODES); do
2411 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2412 error "write failed"
2413 is_project_quota_supported &&
2414 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2415 echo "Iteration $i/$INODES completed"
2417 cancel_lru_locks osc
2419 echo "Wait for setattr on objects finished..."
2420 wait_delete_completed
2422 sync; sync_all_data || true
2424 echo "Verify disk usage after write"
2425 USED=$(getquota -u $TSTID global curspace)
2426 [ $USED -lt $TOTAL_BLKS ] &&
2427 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2428 USED=$(getquota -g $TSTID global curspace)
2429 [ $USED -lt $TOTAL_BLKS ] &&
2430 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2431 if is_project_quota_supported; then
2432 USED=$(getquota -p $TSTPRJID global curspace)
2433 [ $USED -lt $TOTAL_BLKS ] && error \
2434 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2437 echo "Verify inode usage after write"
2438 USED=$(getquota -u $TSTID global curinodes)
2439 [ $USED -lt $INODES ] &&
2440 error "Used inode for user $TSTID is $USED, expected $INODES"
2441 USED=$(getquota -g $TSTID global curinodes)
2442 [ $USED -lt $INODES ] &&
2443 error "Used inode for group $TSTID is $USED, expected $INODES"
2444 if is_project_quota_supported; then
2445 USED=$(getquota -p $TSTPRJID global curinodes)
2446 [ $USED -lt $INODES ] && error \
2447 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2452 echo "Verify disk usage after delete"
2453 USED=$(getquota -u $TSTID global curspace)
2454 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2455 USED=$(getquota -u $TSTID global curinodes)
2456 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2457 USED=$(getquota -g $TSTID global curspace)
2458 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2459 USED=$(getquota -g $TSTID global curinodes)
2460 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2461 if is_project_quota_supported; then
2462 USED=$(getquota -p $TSTPRJID global curspace)
2464 error "Used space for project $TSTPRJID isn't 0. $USED"
2465 USED=$(getquota -p $TSTPRJID global curinodes)
2467 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2470 run_test 33 "Basic usage tracking for user & group & project"
2472 # usage transfer test for user & group & project
2474 local BLK_CNT=2 # 2MB
2475 local project_supported="no"
2477 is_project_quota_supported && project_supported="yes"
2478 setup_quota_test || error "setup quota failed with $?"
2479 trap cleanup_quota_test EXIT
2481 # make sure the system is clean
2482 local USED=$(getquota -u $TSTID global curspace)
2483 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2484 USED=$(getquota -g $TSTID global curspace)
2485 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2487 local USED=$(getquota -u $TSTID2 global curspace)
2488 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2489 if [ $project_supported == "yes" ]; then
2490 USED=$(getquota -p $TSTPRJID global curspace)
2491 [ $USED -ne 0 ] && error \
2492 "Used space ($USED) for Project $TSTPRJID isn't 0."
2495 echo "Write file..."
2496 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2497 error "write failed"
2498 cancel_lru_locks osc
2499 sync; sync_all_data || true
2501 echo "chown the file to user $TSTID"
2502 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2504 echo "Wait for setattr on objects finished..."
2505 wait_delete_completed
2507 BLK_CNT=$((BLK_CNT * 1024))
2509 echo "Verify disk usage for user $TSTID"
2510 USED=$(getquota -u $TSTID global curspace)
2511 [ $USED -lt $BLK_CNT ] &&
2512 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2513 USED=$(getquota -u $TSTID global curinodes)
2515 error "Used inodes for user $TSTID is $USED, expected 1"
2517 echo "chgrp the file to group $TSTID"
2518 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2520 echo "Wait for setattr on objects finished..."
2521 wait_delete_completed
2523 echo "Verify disk usage for group $TSTID"
2524 USED=$(getquota -g $TSTID global curspace)
2525 [ $USED -ge $BLK_CNT ] ||
2526 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2527 USED=$(getquota -g $TSTID global curinodes)
2529 error "Used inodes for group $TSTID is $USED, expected 1"
2531 # chown won't change the ost object group. LU-4345 */
2532 echo "chown the file to user $TSTID2"
2533 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2535 echo "Wait for setattr on objects finished..."
2536 wait_delete_completed
2538 echo "change_project project id to $TSTPRJID"
2539 [ $project_supported == "yes" ] &&
2540 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2541 echo "Wait for setattr on objects finished..."
2542 wait_delete_completed
2544 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2545 USED=$(getquota -u $TSTID2 global curspace)
2546 [ $USED -lt $BLK_CNT ] &&
2547 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2548 USED=$(getquota -u $TSTID global curspace)
2550 error "Used space for user $TSTID is $USED, expected 0"
2551 USED=$(getquota -g $TSTID global curspace)
2552 [ $USED -lt $BLK_CNT ] &&
2553 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2554 if [ $project_supported == "yes" ]; then
2555 USED=$(getquota -p $TSTPRJID global curspace)
2556 [ $USED -lt $BLK_CNT ] && error \
2557 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2562 run_test 34 "Usage transfer for user & group & project"
2564 # usage is still accessible across restart
2566 local BLK_CNT=2 # 2 MB
2568 setup_quota_test || error "setup quota failed with $?"
2569 trap cleanup_quota_test EXIT
2571 echo "Write file..."
2572 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2573 error "write failed"
2574 is_project_quota_supported &&
2575 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2576 cancel_lru_locks osc
2578 echo "Wait for setattr on objects finished..."
2579 wait_delete_completed
2581 sync; sync_all_data || true
2583 echo "Save disk usage before restart"
2584 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2585 [ $ORIG_USR_SPACE -eq 0 ] &&
2586 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2587 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2588 [ $ORIG_USR_INODES -eq 0 ] &&
2589 error "Used inodes for user $TSTID is 0, expected 1"
2590 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2591 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2592 [ $ORIG_GRP_SPACE -eq 0 ] &&
2593 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2594 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2595 [ $ORIG_GRP_INODES -eq 0 ] &&
2596 error "Used inodes for group $TSTID is 0, expected 1"
2597 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2599 if is_project_quota_supported; then
2600 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2601 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2602 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2603 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2604 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2605 "Used inodes for project $TSTPRJID is 0, expected 1"
2606 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2614 echo "Verify disk usage after restart"
2615 local USED=$(getquota -u $TSTID global curspace)
2616 [ $USED -eq $ORIG_USR_SPACE ] ||
2617 error "Used space for user $TSTID changed from " \
2618 "$ORIG_USR_SPACE to $USED"
2619 USED=$(getquota -u $TSTID global curinodes)
2620 [ $USED -eq $ORIG_USR_INODES ] ||
2621 error "Used inodes for user $TSTID changed from " \
2622 "$ORIG_USR_INODES to $USED"
2623 USED=$(getquota -g $TSTID global curspace)
2624 [ $USED -eq $ORIG_GRP_SPACE ] ||
2625 error "Used space for group $TSTID changed from " \
2626 "$ORIG_GRP_SPACE to $USED"
2627 USED=$(getquota -g $TSTID global curinodes)
2628 [ $USED -eq $ORIG_GRP_INODES ] ||
2629 error "Used inodes for group $TSTID changed from " \
2630 "$ORIG_GRP_INODES to $USED"
2631 if [ $project_supported == "yes" ]; then
2632 USED=$(getquota -p $TSTPRJID global curinodes)
2633 [ $USED -eq $ORIG_PRJ_INODES ] ||
2634 error "Used inodes for project $TSTPRJID " \
2635 "changed from $ORIG_PRJ_INODES to $USED"
2636 USED=$(getquota -p $TSTPRJID global curspace)
2637 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2638 error "Used space for project $TSTPRJID "\
2639 "changed from $ORIG_PRJ_SPACE to $USED"
2642 # check if the vfs_dq_init() is called before writing
2643 echo "Append to the same file..."
2644 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2645 error "write failed"
2646 cancel_lru_locks osc
2647 sync; sync_all_data || true
2649 echo "Verify space usage is increased"
2650 USED=$(getquota -u $TSTID global curspace)
2651 [ $USED -gt $ORIG_USR_SPACE ] ||
2652 error "Used space for user $TSTID isn't increased" \
2653 "orig:$ORIG_USR_SPACE, now:$USED"
2654 USED=$(getquota -g $TSTID global curspace)
2655 [ $USED -gt $ORIG_GRP_SPACE ] ||
2656 error "Used space for group $TSTID isn't increased" \
2657 "orig:$ORIG_GRP_SPACE, now:$USED"
2658 if [ $project_supported == "yes" ]; then
2659 USED=$(getquota -p $TSTPRJID global curspace)
2660 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2661 error "Used space for project $TSTPRJID isn't " \
2662 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2667 run_test 35 "Usage is still accessible across reboot"
2669 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2672 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2673 skip "Old server doesn't have LU-5006 fix."
2675 setup_quota_test || error "setup quota failed with $?"
2676 trap cleanup_quota_test EXIT
2678 # make sure the system is clean
2679 local USED=$(getquota -u $TSTID global curspace)
2681 error "Used space ($USED) for user $TSTID isn't 0."
2683 # create file with MDS_OPEN_DELAY_CREATE flag
2684 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2685 error "Create file failed"
2687 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2688 oflag=sync || error "Write file failed"
2690 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2692 # wait for setattr on objects finished..."
2693 wait_delete_completed
2695 USED=$(getquota -u $TSTID global curspace)
2696 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2700 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2704 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2705 skip "Old server doesn't have LU-8801 fix."
2707 [ "$UID" != 0 ] && skip_env "must run as root" && return
2709 setup_quota_test || error "setup quota failed with $?"
2710 trap cleanup_quota_test EXIT
2712 # make sure the system is clean
2713 local USED=$(getquota -u $TSTID global curspace)
2715 error "Used space ($USED) for user $TSTID isn't 0."
2716 USED=$(getquota -u $TSTID2 global curspace)
2718 error "Used space ($USED) for user $TSTID2 isn't 0."
2720 local TESTFILE="$DIR/$tdir/$tfile"
2721 local file_cnt=10000
2723 # Generate id entries in accounting file
2724 echo "Create $file_cnt files..."
2725 for i in `seq $file_cnt`; do
2727 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2728 error "failed to chown $TESTFILE-$i"
2730 cancel_lru_locks osc
2731 sync; sync_all_data || true
2733 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2734 procf=${procf}.quota_slave.acct_user
2737 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2738 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2739 echo "Found $acct_cnt id entries"
2741 [ $file_cnt -eq $acct_cnt ] || {
2742 do_facet mds1 $LCTL get_param $procf
2743 error "skipped id entries"
2748 run_test 38 "Quota accounting iterator doesn't skip id entries"
2751 local TESTFILE="$DIR/$tdir/project"
2752 ! is_project_quota_supported &&
2753 skip "Project quota is not supported"
2755 setup_quota_test || error "setup quota failed with $?"
2758 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2759 [ $projectid -ne 0 ] &&
2760 error "Project id should be 0 not $projectid"
2761 change_project -p 1024 $TESTFILE
2762 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2763 [ $projectid -ne 1024 ] &&
2764 error "Project id should be 1024 not $projectid"
2766 stopall || error "failed to stopall (1)"
2769 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2770 [ $projectid -ne 1024 ] &&
2771 error "Project id should be 1024 not $projectid"
2775 run_test 39 "Project ID interface works correctly"
2778 ! is_project_quota_supported &&
2779 skip "Project quota is not supported"
2780 local dir1="$DIR/$tdir/dir1"
2781 local dir2="$DIR/$tdir/dir2"
2783 setup_quota_test || error "setup quota failed with $?"
2785 mkdir -p $dir1 $dir2
2786 change_project -sp 1 $dir1 && touch $dir1/1
2787 change_project -sp 2 $dir2
2789 ln $dir1/1 $dir2/1_link &&
2790 error "Hard link across different project quota should fail"
2795 run_test 40a "Hard link across different project ID"
2798 ! is_project_quota_supported &&
2799 skip "Project quota is not supported"
2800 local dir1="$DIR/$tdir/dir1"
2801 local dir2="$DIR/$tdir/dir2"
2803 setup_quota_test || error "setup quota failed with $?"
2804 mkdir -p $dir1 $dir2
2805 change_project -sp 1 $dir1 && touch $dir1/1
2806 change_project -sp 2 $dir2
2808 mv $dir1/1 $dir2/2 || error "mv failed $?"
2809 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2810 if [ "$projid" != "2" ]; then
2811 error "project id expected 2 not $projid"
2816 run_test 40b "Mv across different project ID"
2819 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2820 ! is_project_quota_supported &&
2821 skip "Project quota is not supported"
2823 setup_quota_test || error "setup quota failed with $?"
2824 local dir="$DIR/$tdir/dir"
2826 mkdir -p $dir && change_project -sp 1 $dir
2827 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2828 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2829 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2830 touch $dir/remote_dir/file
2831 #verify inherit works file for remote dir.
2832 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2833 [ "$projid" != "1" ] &&
2834 error "file under remote dir expected 1 not $projid"
2836 #Agent inode should be ignored for project quota
2837 USED=$(getquota -p 1 global curinodes)
2838 [ "$USED" != "3" ] &&
2839 error "file count expected 3 got $USED"
2845 run_test 40c "Remote child Dir inherit project quota properly"
2848 ! is_project_quota_supported &&
2849 skip "Project quota is not supported"
2851 setup_quota_test || error "setup quota failed with $?"
2852 local dir1="$DIR/$tdir/dir1"
2853 local dir2="$DIR/$tdir/dir2"
2855 mkdir -p $dir1 && change_project -sp 1 $dir1
2856 mkdir -p $dir2 && change_project -sp 2 $dir2
2857 for num in $(seq 1 10); do
2858 touch $dir1/file_$num $dir2/file_$num
2859 ln -s $dir1/file_$num $dir1/file_$num"_link"
2860 ln -s $dir2/file_$num $dir2/file_$num"_link"
2863 count=$($LFS find --projid 1 $DIR | wc -l)
2864 [ "$count" != 21 ] && error "expected 21 but got $count"
2866 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2867 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2868 [ "$count" != 22 ] && error "expected 22 but got $count"
2873 run_test 50 "Test if lfs find --projid works"
2876 ! is_project_quota_supported &&
2877 skip "Project quota is not supported"
2878 setup_quota_test || error "setup quota failed with $?"
2879 local dir="$DIR/$tdir/dir"
2881 mkdir $dir && change_project -sp 1 $dir
2882 local used=$(getquota -p 1 global curinodes)
2883 [ $used != "1" ] && error "expected 1 got $used"
2888 used=$(getquota -p 1 global curinodes)
2889 [ $used != "4" ] && error "expected 4 got $used"
2891 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2893 cp $DIR/$tdir/6 $dir/6
2894 used=$(getquota -p 1 global curinodes)
2895 [ $used != "5" ] && error "expected 5 got $used"
2898 mv $DIR/$tdir/6 $dir/7
2899 used=$(getquota -p 1 global curinodes)
2900 [ $used != "6" ] && error "expected 6 got $used"
2905 run_test 51 "Test project accounting with mv/cp"
2908 ! is_project_quota_supported &&
2909 skip "Project quota is not supported"
2910 setup_quota_test || error "setup quota failed with $?"
2911 local dir="$DIR/$tdir/dir"
2912 mkdir $dir && change_project -sp 1 $dir
2914 touch $DIR/$tdir/file
2915 #Try renaming a file into the project. This should fail.
2916 for num in $(seq 1 2000); do
2917 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2918 error "rename should fail"
2923 run_test 52 "Rename across different project ID"
2926 ! is_project_quota_supported &&
2927 skip "Project quota is not supported"
2928 setup_quota_test || error "setup quota failed with $?"
2929 local dir="$DIR/$tdir/dir"
2930 mkdir $dir && change_project -s $dir
2931 lfs project -d $dir | grep P || error "inherit attribute should be set"
2933 change_project -C $dir
2934 lfs project -d $dir | grep P &&
2935 error "inherit attribute should be cleared"
2940 run_test 53 "Project inherit attribute could be cleared"
2943 ! is_project_quota_supported &&
2944 skip "Project quota is not supported"
2945 setup_quota_test || error "setup quota failed with $?"
2946 trap cleanup_quota_test EXIT
2947 local testfile="$DIR/$tdir/$tfile-0"
2949 #set project ID/inherit attribute
2950 change_project -sp $TSTPRJID $DIR/$tdir
2951 $RUNAS createmany -m ${testfile} 100 ||
2952 error "create many files failed"
2954 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2955 # one more count for directory itself */
2959 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2960 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2962 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2963 [ $proj_count1 -eq $proj_count ] ||
2964 error "c2: expected $proj_count got $proj_count1"
2966 #clear project but with kept projid
2967 change_project -rCk $DIR/$tdir
2968 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2969 [ $proj_count1 -eq $proj_count ] ||
2970 error "c3: expected $proj_count got $proj_count1"
2972 #verify projid untouched.
2973 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2975 [ $proj_count1 -eq $proj_count ] ||
2976 error "c4: expected $proj_count got $proj_count1"
2979 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2980 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2981 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2983 #this time clear all
2984 change_project -rC $DIR/$tdir
2985 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2986 [ $proj_count1 -eq 0 ] ||
2987 error "c6: expected 0 got $proj_count1"
2989 unlinkmany ${testfile} 100 ||
2990 error "unlink many files failed"
2994 run_test 54 "basic lfs project interface test"
2997 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
2998 skip "Not supported before 2.10.58."
2999 setup_quota_test || error "setup quota failed with $?"
3001 set_ost_qtype $QTYPE || error "enable ost quota failed"
3004 #add second group to TSTUSR
3005 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3008 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3009 error "failed to dd"
3011 cancel_lru_locks osc
3012 sync; sync_all_data || true
3014 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3015 error "failed to setquota on group $TSTUSR2"
3017 $LFS quota -v -g $TSTUSR2 $DIR
3019 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3020 error "chgrp should failed with -EDQUOT"
3022 USED=$(getquota -g $TSTUSR2 global curspace)
3025 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3026 error "failed to setquota on group $TSTUSR2"
3028 $LFS quota -v -g $TSTUSR2 $DIR
3030 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3031 error "chgrp should succeed"
3033 $LFS quota -v -g $TSTUSR2 $DIR
3037 run_test 55 "Chgrp should be affected by group quota"
3040 setup_quota_test || error "setup quota failed with $?"
3042 set_ost_qtype $QTYPE || error "enable ost quota failed"
3045 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3046 erro "failed to set grace time for usr quota"
3047 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3048 awk '{print $4 $8}')
3049 if [ "x$grace_time" != "x10s;10s" ]; then
3050 $LFS quota -t -u $DIR
3051 error "expected grace time: 10s;10s, got:$grace_time"
3056 run_test 56 "lfs quota -t should work well"
3059 setup_quota_test || error "setup quota failed with $?"
3061 local dir="$DIR/$tdir/dir"
3064 #try to change pipe file should not hang and return failure
3065 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3066 awk -F ':' '{ print \\\$2 }'" \
3067 " failed to get xattr for '$dir/pipe'" || return 1
3068 #command can process further if it hit some errors
3069 touch $dir/aaa $dir/bbb
3070 mkdir $dir/subdir -p
3071 touch $dir/subdir/aaa $dir/subdir/bbb
3072 #create one invalid link file
3073 ln -s $dir/not_exist_file $dir/ccc
3074 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3075 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3079 run_test 57 "lfs project could tolerate errors"
3082 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3083 skip "ldiskfs only test"
3084 disable_project_quota
3085 setup_quota_test || error "setup quota failed with $?"
3088 local testfile="$DIR/$tdir/$tfile-0"
3089 #make sure it did not crash kernel
3090 touch $testfile && lfs project -sp 1 $testfile
3092 enable_project_quota
3095 run_test 59 "lfs project dosen't crash kernel with project disabled"
3098 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3099 skip "Needs MDS version 2.11.53 or later."
3100 setup_quota_test || error "setup quota failed with $?"
3101 trap cleanup_quota_test EXIT
3103 local testfile=$DIR/$tdir/$tfile
3106 set_mdt_qtype "ug" || error "enable mdt quota failed"
3108 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3109 error "set quota failed"
3110 quota_show_check a g $TSTUSR
3112 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3113 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3114 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3115 error "create many files failed"
3117 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3119 # root user can overrun quota
3120 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3121 error "root user should succeed"
3125 run_test 60 "Test quota for root with setgid"
3127 # test default quota
3128 test_default_quota() {
3129 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3130 skip "Not supported before 2.11.51."
3135 local qprjid=$TSTPRJID
3139 local LIMIT=20480 #20M disk space
3140 local TESTFILE="$DIR/$tdir/$tfile-0"
3142 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3143 echo "Project quota is not supported" && return 0
3145 [ $qtype == "-u" ] && qdtype="-U"
3146 [ $qtype == "-g" ] && qdtype="-G"
3147 [ $qtype == "-p" ] && {
3152 [ $qpool == "meta" ] && {
3153 LIMIT=10240 #10K inodes
3158 setup_quota_test || error "setup quota failed with $?"
3159 trap cleanup_quota_test EXIT
3163 # enable mdt/ost quota
3164 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3165 set_ost_qtype $QTYPE || error "enable ost quota failed"
3167 log "set to use default quota"
3168 $LFS setquota $qtype $qid -d $DIR ||
3169 error "set $qid to use default quota failed"
3171 log "set default quota"
3172 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3173 error "set $qid default quota failed"
3175 log "get default quota"
3176 $LFS quota $qdtype $DIR || error "get default quota failed"
3178 if [ $qpool == "data" ]; then
3179 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3181 [ $SLIMIT -eq $LIMIT ] ||
3182 error "the returned default quota is wrong"
3184 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3186 [ $SLIMIT -eq $LIMIT ] ||
3187 error "the returned default quota is wrong"
3190 # make sure the system is clean
3191 local USED=$(getquota $qtype $qid global curspace)
3192 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3194 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3195 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3197 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3199 log "Test not out of quota"
3200 if [ $qpool == "data" ]; then
3201 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3202 quota_error $qtype $qid "write failed, expect succeed"
3204 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3205 quota_error $qtype $qid "create failed, expect succeed"
3207 unlinkmany $TESTFILE $((LIMIT/2))
3210 log "Test out of quota"
3211 # flush cache, ensure noquota flag is set on client
3212 cancel_lru_locks osc
3213 cancel_lru_locks mdc
3214 sync; sync_all_data || true
3215 if [ $qpool == "data" ]; then
3216 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3217 quota_error $qtype $qid "write succeed, expect EDQUOT"
3219 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3220 quota_error $qtype $qid "create succeed, expect EDQUOT"
3222 unlinkmany $TESTFILE $((LIMIT*2))
3225 log "Increase default quota"
3226 # increase default quota
3227 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3228 error "set default quota failed"
3230 cancel_lru_locks osc
3231 cancel_lru_locks mdc
3232 sync; sync_all_data || true
3233 if [ $qpool == "data" ]; then
3234 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3235 quota_error $qtype $qid "write failed, expect succeed"
3237 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3238 quota_error $qtype $qid "create failed, expect succeed"
3240 unlinkmany $TESTFILE $((LIMIT*2))
3243 log "Set quota to override default quota"
3244 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3245 error "set $qid quota failed"
3247 cancel_lru_locks osc
3248 cancel_lru_locks mdc
3249 sync; sync_all_data || true
3250 if [ $qpool == "data" ]; then
3251 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3252 quota_error $qtype $qid "write succeed, expect EQUOT"
3254 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3255 quota_error $qtype $qid "create succeed, expect EQUOT"
3257 unlinkmany $TESTFILE $((LIMIT*2))
3260 log "Set to use default quota again"
3261 $LFS setquota $qtype $qid -d $DIR ||
3262 error "set $qid to use default quota failed"
3264 cancel_lru_locks osc
3265 cancel_lru_locks mdc
3266 sync; sync_all_data || true
3267 if [ $qpool == "data" ]; then
3268 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3269 quota_error $qtype $qid "write failed, expect succeed"
3271 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3272 quota_error $qtype $qid "create failed, expect succeed"
3274 unlinkmany $TESTFILE $((LIMIT*2))
3279 wait_delete_completed || error "wait_delete_completed failed"
3280 sync_all_data || true
3281 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3282 error "reset default quota failed"
3283 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3284 error "reset quota failed"
3290 test_default_quota "-u" "data"
3291 test_default_quota "-u" "meta"
3292 test_default_quota "-g" "data"
3293 test_default_quota "-g" "meta"
3294 test_default_quota "-p" "data"
3295 test_default_quota "-p" "meta"
3297 run_test 61 "default quota tests"
3300 ! is_project_quota_supported &&
3301 skip "Project quota is not supported"
3302 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3303 skip "chattr did not support project quota"
3304 setup_quota_test || error "setup quota failed with $?"
3305 local testdir=$DIR/$tdir/
3307 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3308 change_project -s $testdir
3309 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3310 error "inherit attribute should be set"
3311 # chattr used FS_IOC_SETFLAGS ioctl
3312 $RUNAS chattr -P $testdir &&
3313 error "regular user clear inherit should fail"
3314 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3315 error "inherit attribute should still be set"
3316 chattr -P $testdir || error "root failed to clear inherit"
3317 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3318 error "inherit attribute should be cleared"
3321 run_test 62 "Project inherit should be only changed by root"
3324 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3325 skip "Not supported before 2.11.55" && return
3329 local dd_failed=false
3330 local tdir_dom=${tdir}_dom
3331 local LIMIT=20480 #20M
3333 [ $qtype == "p" ] && ! is_project_quota_supported &&
3334 echo "Project quota is not supported" && return 0
3336 [ $qtype == "p" ] && qid=$TSTPRJID
3338 setup_quota_test || error "setup quota failed with $?"
3339 trap cleanup_quota_test EXIT
3343 # enable mdt/ost quota
3344 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3345 set_ost_qtype $QTYPE || error "enable ost quota failed"
3347 # make sure the system is clean
3348 local USED=$(getquota -$qtype $qid global curspace)
3349 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3351 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3353 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3354 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3355 error "setstripe $tdir_dom failed"
3356 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3358 [ $qtype == "p" ] && {
3359 change_project -sp $TSTPRJID $DIR/$tdir
3360 change_project -sp $TSTPRJID $DIR/$tdir_dom
3363 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3364 error "set $qid quota failed"
3366 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3367 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3371 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3373 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3374 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3378 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3380 rm -f $DIR/$tdir_dom/*
3382 # flush cache, ensure noquota flag is set on client
3383 cancel_lru_locks osc
3384 cancel_lru_locks mdc
3385 sync; sync_all_data || true
3389 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3390 quota_error $qtype $qid "write failed, expect succeed"
3392 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3393 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3397 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3400 rm -f $DIR/$tdir_dom/*
3402 # flush cache, ensure noquota flag is set on client
3403 cancel_lru_locks osc
3404 cancel_lru_locks mdc
3405 sync; sync_all_data || true
3409 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3410 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3414 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3416 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3417 quota_error $qtype $qid "write succeed, expect EDQUOT"
3420 rm -fr $DIR/$tdir_dom
3422 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3423 error "reset usr quota failed"
3433 run_test 63 "quota on DoM tests"
3437 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3438 if $PQ_CLEANUP; then
3439 disable_project_quota
3442 reset_quota_settings
3447 check_and_cleanup_lustre
3448 export QUOTA_AUTO=$QUOTA_AUTO_OLD