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:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
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"}
31 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
32 . $LUSTRE/tests/test-framework.sh
34 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
38 require_dsh_mds || exit 0
39 require_dsh_ost || exit 0
41 # Does e2fsprogs support quota feature?
42 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
43 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
44 grep -q 'quota'"; then
45 skip_env "e2fsprogs doesn't support quota" && exit 0
48 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
49 # bug number for skipped test: LU-2836 LU-6836 LU-2836
50 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6"
51 # bug number for skipped test: LU-5638
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
58 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
60 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
62 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
67 QUOTA_AUTO_OLD=$QUOTA_AUTO
70 check_and_setup_lustre
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
96 RUNAS="runas -u $TSTID -g $TSTID"
97 RUNAS2="runas -u $TSTID2 -g $TSTID2"
98 DD="dd if=/dev/zero bs=1M"
102 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
103 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
104 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
105 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
112 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
113 [ "$1" != "-u" -a "$1" != "-g" ] &&
114 error "resetquota: wrong specifier $1 passed"
116 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
117 error "clear quota for [type:$1 name:$2] failed"
118 # give a chance to slave to release space
126 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
127 $LFS quota -v -u $LOCAL_ID $DIR
128 log "Files for user ($LOCAL_ID):"
129 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
130 xargs stat 2>/dev/null)
133 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
134 $LFS quota -v -g $LOCAL_ID $DIR
135 log "Files for group ($LOCAL_ID):"
136 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
153 # get quota for a user or a group
154 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
155 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
160 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
161 [ "$1" != "-u" -a "$1" != "-g" ] &&
162 error "getquota: wrong u/g specifier $1 passed"
175 *) error "unknown quota parameter $4";;
178 [ "$uuid" = "global" ] && uuid=$DIR
180 $LFS quota -v "$1" "$2" $DIR |
181 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
182 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
187 # usage: set_mdt_qtype ug|u|g|none
191 local mdts=$(get_facets MDS)
193 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
194 # we have to make sure each MDT received config changes
195 for mdt in ${mdts//,/ }; do
197 cmd="$LCTL get_param -n "
198 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
199 cmd=${cmd}.quota_slave.enabled
201 if $(facet_up $mdt); then
202 wait_update_facet $mdt "$cmd" "$qtype" || return 1
209 # usage: set_ost_qtype ug|u|g|none
213 local osts=$(get_facets OST)
215 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
216 # we have to make sure each OST received config changes
217 for ost in ${osts//,/ }; do
219 cmd="$LCTL get_param -n "
220 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
221 cmd=${cmd}.quota_slave.enabled
223 if $(facet_up $ost); then
224 wait_update_facet $ost "$cmd" "$qtype" || return 1
230 wait_reintegration() {
234 local result="glb[1],slv[1],reint[0]"
239 if [ $ntype == "mdt" ]; then
240 tgts=$(get_facets MDS)
242 tgts=$(get_facets OST)
245 for tgt in ${tgts//,/ }; do
247 cmd="$LCTL get_param -n "
248 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
249 cmd=${cmd}.quota_slave.info
251 if $(facet_up $tgt); then
252 wait_update_facet $tgt "$cmd |
253 grep "$qtype" | awk '{ print \\\$3 }'" \
254 "$result" $max || return 1
264 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
265 wait_reintegration "mdt" "user" $max || return 1
268 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
269 wait_reintegration "mdt" "group" $max || return 1
278 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
279 wait_reintegration "ost" "user" $max || return 1
282 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
283 wait_reintegration "ost" "group" $max || return 1
288 enable_project_quota() {
289 stopall || error "failed to stopall (1)"
291 for num in $(seq $MDSCOUNT); do
292 do_facet mds$num $TUNE2FS -O project $(mdsdevname $num) ||
293 error "tune2fs $(mdsdevname $num) failed"
296 for i in $(seq $OSTCOUNT); do
297 do_facet ost$num $TUNE2FS -O project $(ostdevname $num) ||
298 error "tune2fs $(ostdevname $num) failed"
305 disable_project_quota() {
306 stopall || error "failed to stopall (1)"
308 for num in $(seq $MDSCOUNT); do
309 do_facet mds$num $TUNE2FS -Q ^prj $(mdsdevname $num) ||
310 error "tune2fs $(mdsdevname $num) failed"
313 for i in $(seq $OSTCOUNT); do
314 do_facet ost$num $TUNE2FS -Q ^prj $(ostdevname $num) ||
315 error "tune2fs $(ostdevname $num) failed"
323 wait_delete_completed
324 echo "Creating test directory"
325 mkdir $DIR/$tdir || return 1
326 chmod 0777 $DIR/$tdir || return 2
327 # always clear fail_loc in case of fail_loc isn't cleared
328 # properly when previous test failed
329 lustre_fail mds_ost 0
332 cleanup_quota_test() {
334 echo "Delete files..."
336 echo "Wait for unlink objects finished..."
337 wait_delete_completed
338 sync_all_data || true
347 $LFS quota -v -$ug $qid $DIR
349 if [ "$bf" == "a" -o "$bf" == "b" ]; then
350 usage=$(getquota -$ug $qid global curspace)
351 if [ -z $usage ]; then
352 quota_error $ug $qid \
353 "Query block quota failed ($ug:$qid)."
355 [ $usage -ne 0 ] && quota_log $ug $qid \
356 "Block quota isn't 0 ($ug:$qid:$usage)."
360 if [ "$bf" == "a" -o "$bf" == "f" ]; then
361 usage=$(getquota -$ug $qid global curinodes)
362 if [ -z $usage ]; then
363 quota_error $ug $qid \
364 "Query file quota failed ($ug:$qid)."
366 [ $usage -ne 0 ] && quota_log $ug $qid \
367 "File quota isn't 0 ($ug:$qid:$usage)."
374 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
378 resetquota -u $TSTUSR
379 resetquota -g $TSTUSR
380 resetquota -u $TSTUSR2
381 resetquota -g $TSTUSR2
383 test_quota_performance() {
384 local TESTFILE="$DIR/$tdir/$tfile-0"
385 local size=$1 # in MB
386 local stime=$(date +%s)
387 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
388 quota_error u $TSTUSR "write failure"
389 local etime=$(date +%s)
390 delta=$((etime - stime))
391 if [ $delta -gt 0 ]; then
392 rate=$((size * 1024 / delta))
393 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
394 # LU-2872 - see LU-2887 for fix
396 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
398 [ $rate -gt 1024 ] ||
399 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
405 # test basic quota performance b=21696
408 [ "$SLOW" = "no" ] && MB=10
410 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
411 [ $free_space -le $((MB * 1024)) ] &&
412 skip "not enough space ${free_space} KB, " \
413 "required $((MB * 1024)) KB" && return
414 setup_quota_test || error "setup quota failed with $?"
415 trap cleanup_quota_test EXIT
417 set_ost_qtype "none" || error "disable ost quota failed"
418 test_quota_performance $MB
420 set_ost_qtype "ug" || error "enable ost quota failed"
421 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
422 error "set quota failed"
423 test_quota_performance $MB
426 resetquota -u $TSTUSR
428 run_test 0 "Test basic quota performance"
430 # test block hardlimit
433 local TESTFILE="$DIR/$tdir/$tfile-0"
435 setup_quota_test || error "setup quota failed with $?"
436 trap cleanup_quota_test EXIT
439 set_ost_qtype "ug" || error "enable ost quota failed"
442 log "User quota (block hardlimit:$LIMIT MB)"
443 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
444 error "set user quota failed"
446 # make sure the system is clean
447 local USED=$(getquota -u $TSTUSR global curspace)
448 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
450 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
451 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
454 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
455 quota_error u $TSTUSR "user write failure, but expect success"
456 log "Write out of block quota ..."
457 # this time maybe cache write, ignore it's failure
458 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
459 # flush cache, ensure noquota flag is set on client
461 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
462 quota_error u $TSTUSR "user write success, but expect EDQUOT"
465 wait_delete_completed || error "wait_delete_completed failed"
466 sync_all_data || true
467 USED=$(getquota -u $TSTUSR global curspace)
468 [ $USED -ne 0 ] && quota_error u $TSTUSR \
469 "user quota isn't released after deletion"
470 resetquota -u $TSTUSR
473 log "--------------------------------------"
474 log "Group quota (block hardlimit:$LIMIT MB)"
475 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
476 error "set group quota failed"
478 TESTFILE="$DIR/$tdir/$tfile-1"
479 # make sure the system is clean
480 USED=$(getquota -g $TSTUSR global curspace)
481 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
483 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
484 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
487 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
488 quota_error g $TSTUSR "group write failure, but expect success"
489 log "Write out of block quota ..."
490 # this time maybe cache write, ignore it's failure
491 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
493 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
494 quota_error g $TSTUSR "group write success, but expect EDQUOT"
499 USED=$(getquota -g $TSTUSR global curspace)
500 [ $USED -ne 0 ] && quota_error g $TSTUSR \
501 "group quota isn't released after deletion"
503 resetquota -g $TSTUSR
505 run_test 1 "Block hard limit (normal use and out of quota)"
507 # test inode hardlimit
509 local LIMIT=$((1024 * 1024)) # 1M inodes
510 local TESTFILE="$DIR/$tdir/$tfile-0"
512 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
514 local FREE_INODES=$(mdt_free_inodes 0)
515 echo "$FREE_INODES free inodes on master MDT"
516 [ $FREE_INODES -lt $LIMIT ] &&
517 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
520 setup_quota_test || error "setup quota failed with $?"
521 trap cleanup_quota_test EXIT
524 set_mdt_qtype "ug" || error "enable mdt quota failed"
527 log "User quota (inode hardlimit:$LIMIT files)"
528 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
529 error "set user quota failed"
531 # make sure the system is clean
532 local USED=$(getquota -u $TSTUSR global curinodes)
533 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
535 log "Create $LIMIT files ..."
536 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
537 quota_error u $TSTUSR "user create failure, but expect success"
538 log "Create out of file quota ..."
539 $RUNAS touch ${TESTFILE}_xxx &&
540 quota_error u $TSTUSR "user create success, but expect EDQUOT"
543 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
544 rm -f ${TESTFILE}_xxx
545 wait_delete_completed
547 USED=$(getquota -u $TSTUSR global curinodes)
548 [ $USED -ne 0 ] && quota_error u $TSTUSR \
549 "user quota isn't released after deletion"
550 resetquota -u $TSTUSR
553 log "--------------------------------------"
554 log "Group quota (inode hardlimit:$LIMIT files)"
555 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
556 error "set group quota failed"
558 TESTFILE=$DIR/$tdir/$tfile-1
559 # make sure the system is clean
560 USED=$(getquota -g $TSTUSR global curinodes)
561 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
563 log "Create $LIMIT files ..."
564 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
565 quota_error g $TSTUSR "group create failure, but expect success"
566 log "Create out of file quota ..."
567 $RUNAS touch ${TESTFILE}_xxx &&
568 quota_error g $TSTUSR "group create success, but expect EDQUOT"
571 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
572 rm -f ${TESTFILE}_xxx
573 wait_delete_completed
575 USED=$(getquota -g $TSTUSR global curinodes)
576 [ $USED -ne 0 ] && quota_error g $TSTUSR \
577 "user quota isn't released after deletion"
580 resetquota -g $TSTUSR
582 run_test 2 "File hard limit (normal use and out of quota)"
586 local TIMER=$(($2 * 3 / 2))
591 trap cleanup_quota_test EXIT
593 $SETSTRIPE $TESTFILE -c 1 -i 0
594 chown $TSTUSR.$TSTUSR $TESTFILE
596 echo "Write up to soft limit"
597 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
598 quota_error a $TSTUSR "write failure, but expect success"
599 OFFSET=$((LIMIT * 1024))
602 echo "Write to exceed soft limit"
603 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
604 quota_error a $TSTUSR "write failure, but expect success"
605 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
610 $SHOW_QUOTA_INFO_USER
611 $SHOW_QUOTA_INFO_GROUP
613 echo "Write before timer goes off"
614 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
615 quota_error a $TSTUSR "write failure, but expect success"
616 OFFSET=$((OFFSET + 1024))
619 echo "Sleep $TIMER seconds ..."
624 $SHOW_QUOTA_INFO_USER
625 $SHOW_QUOTA_INFO_GROUP
627 echo "Write after timer goes off"
628 # maybe cache write, ignore.
629 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
630 OFFSET=$((OFFSET + 1024))
632 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
633 quota_error a $TSTUSR "write success, but expect EDQUOT"
637 $SHOW_QUOTA_INFO_USER
638 $SHOW_QUOTA_INFO_GROUP
640 echo "Unlink file to stop timer"
642 wait_delete_completed
643 sync_all_data || true
647 $SHOW_QUOTA_INFO_USER
648 $SHOW_QUOTA_INFO_GROUP
650 $SETSTRIPE $TESTFILE -c 1 -i 0
651 chown $TSTUSR.$TSTUSR $TESTFILE
654 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
655 quota_error a $TSTUSR "write failure, but expect success"
664 local TESTFILE=$DIR/$tdir/$tfile-0
666 set_ost_qtype "ug" || error "enable ost quota failed"
668 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
669 # make sure the system is clean
670 local USED=$(getquota -u $TSTUSR global curspace)
671 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
673 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
674 $MAX_IQ_TIME $DIR || error "set user grace time failed"
675 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
676 error "set user quota failed"
678 test_block_soft $TESTFILE $GRACE $LIMIT
679 resetquota -u $TSTUSR
681 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
682 TESTFILE=$DIR/$tdir/$tfile-1
683 # make sure the system is clean
684 USED=$(getquota -g $TSTUSR global curspace)
685 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
687 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
688 $MAX_IQ_TIME $DIR || error "set group grace time failed"
689 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
690 error "set group quota failed"
692 test_block_soft $TESTFILE $GRACE $LIMIT
693 resetquota -g $TSTUSR
696 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
697 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
698 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
699 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
701 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
707 local TIMER=$(($grace * 3 / 2))
710 trap cleanup_quota_test EXIT
712 echo "Create files to exceed soft limit"
713 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
714 quota_error a $TSTUSR "create failure, but expect success"
715 local trigger_time=$(date +%s)
717 sync_all_data || true
719 local cur_time=$(date +%s)
720 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
721 error "Passed grace time $grace, $trigger_time, $cur_time"
723 echo "Create file before timer goes off"
724 $RUNAS touch ${TESTFILE}_before ||
725 quota_error a $TSTUSR "failed create before timer expired," \
726 "but expect success. $trigger_time, $cur_time"
727 sync_all_data || true
729 echo "Sleep $TIMER seconds ..."
734 $SHOW_QUOTA_INFO_USER
735 $SHOW_QUOTA_INFO_GROUP
737 echo "Create file after timer goes off"
738 # There is a window that space is accounted in the quota usage but
739 # hasn't been decreased from the pending write, if we acquire quota
740 # in this window, we'll acquire more than we needed.
741 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
742 sync_all_data || true
743 $RUNAS touch ${TESTFILE}_after_3 &&
744 quota_error a $TSTUSR "create after timer expired," \
746 sync_all_data || true
750 $SHOW_QUOTA_INFO_USER
751 $SHOW_QUOTA_INFO_GROUP
753 echo "Unlink files to stop timer"
754 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
755 wait_delete_completed
758 $RUNAS touch ${TESTFILE}_xxx ||
759 quota_error a $TSTUSR "touch after timer stop failure," \
761 sync_all_data || true
769 local LIMIT=10 # inodes
770 local TESTFILE=$DIR/$tdir/$tfile-0
773 set_mdt_qtype "ug" || error "enable mdt quota failed"
775 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
776 # make sure the system is clean
777 local USED=$(getquota -u $TSTUSR global curinodes)
778 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
780 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
781 $GRACE $DIR || error "set user grace time failed"
782 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
783 error "set user quota failed"
785 test_file_soft $TESTFILE $LIMIT $GRACE
786 resetquota -u $TSTUSR
788 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
789 # make sure the system is clean
790 USED=$(getquota -g $TSTUSR global curinodes)
791 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
793 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
794 $GRACE $DIR || error "set group grace time failed"
795 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
796 error "set group quota failed"
797 TESTFILE=$DIR/$tdir/$tfile-1
799 test_file_soft $TESTFILE $LIMIT $GRACE
800 resetquota -g $TSTUSR
803 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
804 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
805 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
806 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
808 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
812 local GR_STR2="1000s"
814 local GR_STR4="1w2d3h4m5s"
816 local GR_STR6="18446744073709551615"
819 wait_delete_completed
821 # test of valid grace strings handling
822 echo "Valid grace strings test"
823 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
824 $GR_STR2 $DIR || error "set user grace time failed"
825 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
826 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
827 $GR_STR4 $DIR || error "set group grace time quota failed"
828 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
830 # test of invalid grace strings handling
831 echo " Invalid grace strings test"
832 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
833 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
834 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
838 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
839 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
840 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
841 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
843 run_test 4b "Grace time strings handling"
845 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
847 local BLIMIT=10 # 10M
848 local ILIMIT=10 # 10 inodes
850 setup_quota_test || error "setup quota failed with $?"
851 trap cleanup_quota_test EXIT
853 set_mdt_qtype "ug" || error "enable mdt quota failed"
854 set_ost_qtype "ug" || error "enable ost quota failed"
856 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
857 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
858 error "set user quota failed"
859 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
860 error "set group quota failed"
862 # make sure the system is clean
863 local USED=$(getquota -u $TSTUSR global curinodes)
864 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
865 USED=$(getquota -g $TSTUSR global curinodes)
866 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
867 USED=$(getquota -u $TSTUSR global curspace)
868 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
869 USED=$(getquota -g $TSTUSR global curspace)
870 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
872 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
873 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
874 error "create failure, expect success"
875 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
876 error "write failure, expect success"
878 echo "Chown files to $TSTUSR.$TSTUSR ..."
879 for i in $(seq 0 $ILIMIT); do
880 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
881 quota_error a $TSTUSR "chown failure, expect success"
885 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
886 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
889 resetquota -u $TSTUSR
890 resetquota -g $TSTUSR
892 run_test 5 "Chown & chgrp successfully even out of block/file quota"
894 # test dropping acquire request on master
898 # Clear dmesg so watchdog is not triggered by previous
900 do_facet ost1 dmesg -c > /dev/null
902 setup_quota_test || error "setup quota failed with $?"
903 trap cleanup_quota_test EXIT
905 # make sure the system is clean
906 local USED=$(getquota -u $TSTUSR global curspace)
907 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
909 # make sure no granted quota on ost
910 set_ost_qtype "ug" || error "enable ost quota failed"
911 resetquota -u $TSTUSR
913 # create file for $TSTUSR
914 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
915 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
916 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
918 # create file for $TSTUSR2
919 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
920 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
921 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
923 # cache per-ID lock for $TSTUSR on slave
924 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
925 error "set quota failed"
926 $RUNAS $DD of=$TESTFILE count=1 ||
927 error "write $TESTFILE failure, expect success"
928 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
929 error "write $TESTFILE2 failure, expect success"
931 sync_all_data || true
933 #define QUOTA_DQACQ 601
934 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
935 lustre_fail mds 0x513 601
937 # write to un-enforced ID ($TSTUSR2) should succeed
938 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
939 error "write failure, expect success"
941 # write to enforced ID ($TSTUSR) in background, exceeding limit
942 # to make sure DQACQ is sent
943 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
946 # watchdog timer uses a factor of 2
947 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
948 sleep $((TIMEOUT * 2 + 1))
950 # write should be blocked and never finished
951 if ! ps -p $DDPID > /dev/null 2>&1; then
953 error "write finished incorrectly!"
958 # no watchdog is triggered
959 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
960 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
961 { print; }' $TMP/lustre-log-${TESTNAME}.log)
962 [ -z "$watchdog" ] || error "$watchdog"
964 rm -f $TMP/lustre-log-${TESTNAME}.log
966 # write should continue then fail with EDQUOT
970 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
971 if [ $count -ge 240 ]; then
972 quota_error u $TSTUSR "dd not finished in $count secs"
975 if [ $((count % 30)) -eq 0 ]; then
976 c_size=$(stat -c %s $TESTFILE)
977 echo "Waiting $count secs. $c_size"
984 resetquota -u $TSTUSR
986 run_test 6 "Test dropping acquire request on master"
988 # quota reintegration (global index)
990 local TESTFILE=$DIR/$tdir/$tfile
993 [ "$SLOW" = "no" ] && LIMIT=5
995 setup_quota_test || error "setup quota failed with $?"
996 trap cleanup_quota_test EXIT
998 # make sure the system is clean
999 local USED=$(getquota -u $TSTUSR global curspace)
1000 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1002 # make sure no granted quota on ost1
1003 set_ost_qtype "ug" || error "enable ost quota failed"
1004 resetquota -u $TSTUSR
1005 set_ost_qtype "none" || error "disable ost quota failed"
1007 local OSTUUID=$(ostuuid_from_index 0)
1008 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1010 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1013 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1014 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1019 echo "Enable quota & set quota limit for $TSTUSR"
1020 set_ost_qtype "ug" || error "enable ost quota failed"
1021 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1022 error "set quota failed"
1024 echo "Start ost1..."
1025 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1028 wait_ost_reint "ug" || error "reintegration failed"
1030 # hardlimit should have been fetched by slave during global
1031 # reintegration, write will exceed quota
1032 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1033 quota_error u $TSTUSR "write success, but expect EDQUOT"
1036 wait_delete_completed
1037 sync_all_data || true
1043 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1044 error "clear quota failed"
1046 echo "Start ost1..."
1047 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1050 wait_ost_reint "ug" || error "reintegration failed"
1052 # hardlimit should be cleared on slave during reintegration
1053 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1054 quota_error u $TSTUSR "write error, but expect success"
1057 resetquota -u $TSTUSR
1059 run_test 7a "Quota reintegration (global index)"
1061 # quota reintegration (slave index)
1064 local TESTFILE=$DIR/$tdir/$tfile
1066 setup_quota_test || error "setup quota failed with $?"
1067 trap cleanup_quota_test EXIT
1069 # make sure the system is clean
1070 local USED=$(getquota -u $TSTUSR global curspace)
1071 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1073 # make sure no granted quota on ost1
1074 set_ost_qtype "ug" || error "enable ost quota failed"
1075 resetquota -u $TSTUSR
1076 set_ost_qtype "none" || error "disable ost quota failed"
1078 local OSTUUID=$(ostuuid_from_index 0)
1079 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1081 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1084 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1085 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1087 # consume some space to make sure the granted space will not
1088 # be released during reconciliation
1089 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1090 error "consume space failure, expect success"
1092 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1093 lustre_fail mds 0xa02
1095 set_ost_qtype "ug" || error "enable ost quota failed"
1096 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1097 error "set quota failed"
1099 # ignore the write error
1100 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1102 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1106 echo "Restart ost to trigger reintegration..."
1108 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1111 wait_ost_reint "ug" || error "reintegration failed"
1113 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1114 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1117 resetquota -u $TSTUSR
1120 run_test 7b "Quota reintegration (slave index)"
1122 # quota reintegration (restart mds during reintegration)
1124 local LIMIT=20 # 20M
1125 local TESTFILE=$DIR/$tdir/$tfile
1127 [ "$SLOW" = "no" ] && LIMIT=5
1129 setup_quota_test || error "setup quota failed with $?"
1130 trap cleanup_quota_test EXIT
1132 # make sure the system is clean
1133 local USED=$(getquota -u $TSTUSR global curspace)
1134 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1136 set_ost_qtype "none" || error "disable ost quota failed"
1137 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1138 error "set quota failed"
1140 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1141 lustre_fail ost 0xa03
1144 set_ost_qtype "ug" || error "enable ost quota failed"
1145 # trigger reintegration
1146 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1147 procf=${procf}quota_slave.force_reint
1148 do_facet ost1 $LCTL set_param $procf=1 ||
1149 error "force reintegration failed"
1157 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1160 # wait longer than usual to make sure the reintegration
1161 # is triggered by quota wb thread.
1162 wait_ost_reint "ug" 200 || error "reintegration failed"
1164 # hardlimit should have been fetched by slave during global
1165 # reintegration, write will exceed quota
1166 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1167 quota_error u $TSTUSR "write success, but expect EDQUOT"
1170 resetquota -u $TSTUSR
1172 run_test 7c "Quota reintegration (restart mds during reintegration)"
1174 # Quota reintegration (Transfer index in multiple bulks)
1176 local TESTFILE=$DIR/$tdir/$tfile
1177 local TESTFILE1="$DIR/$tdir/$tfile"-1
1180 setup_quota_test || error "setup quota failed with $?"
1181 trap cleanup_quota_test EXIT
1183 set_ost_qtype "none" || error "disable ost quota failed"
1184 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1185 error "set quota for $TSTUSR failed"
1186 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1187 error "set quota for $TSTUSR2 failed"
1189 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1190 lustre_fail mds 0x608 0
1192 # enable quota to tirgger reintegration
1193 set_ost_qtype "u" || error "enable ost quota failed"
1194 wait_ost_reint "u" || error "reintegration failed"
1198 # hardlimit should have been fetched by slave during global
1199 # reintegration, write will exceed quota
1200 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1201 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1203 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1204 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1207 resetquota -u $TSTUSR
1208 resetquota -u $TSTUSR2
1210 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1212 # quota reintegration (inode limits)
1214 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1216 # LU-2435: skip this quota test if underlying zfs version has not
1217 # supported native dnode accounting
1218 [ "$(facet_fstype mds1)" == "zfs" ] && {
1219 local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
1221 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] &&
1222 skip "requires zfs version at least 0.7.0" && return
1225 local ilimit=$((1024 * 2)) # 2k inodes
1226 local TESTFILE=$DIR/${tdir}-1/$tfile
1228 setup_quota_test || error "setup quota failed with $?"
1229 trap cleanup_quota_test EXIT
1231 # make sure the system is clean
1232 local USED=$(getquota -u $TSTUSR global curinodes)
1233 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1235 # make sure no granted quota on mdt1
1236 set_mdt_qtype "ug" || error "enable mdt quota failed"
1237 resetquota -u $TSTUSR
1238 set_mdt_qtype "none" || error "disable mdt quota failed"
1240 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1241 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1242 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1245 echo "Stop mds${MDSCOUNT}..."
1248 echo "Enable quota & set quota limit for $TSTUSR"
1249 set_mdt_qtype "ug" || error "enable mdt quota failed"
1250 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1251 error "set quota failed"
1253 echo "Start mds${MDSCOUNT}..."
1254 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1257 wait_mdt_reint "ug" || error "reintegration failed"
1259 echo "create remote dir"
1260 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1261 error "create remote dir failed"
1262 chmod 0777 $DIR/${tdir}-1
1264 # hardlimit should have been fetched by slave during global
1265 # reintegration, create will exceed quota
1266 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1267 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1269 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1270 wait_delete_completed
1271 sync_all_data || true
1273 echo "Stop mds${MDSCOUNT}..."
1276 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1277 error "clear quota failed"
1279 echo "Start mds${MDSCOUNT}..."
1280 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1283 wait_mdt_reint "ug" || error "reintegration failed"
1285 # hardlimit should be cleared on slave during reintegration
1286 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1287 quota_error -u $TSTUSR "create failed, expect success"
1289 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1290 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1293 resetquota -u $TSTUSR
1295 run_test 7e "Quota reintegration (inode limits)"
1297 # run dbench with quota enabled
1299 local BLK_LIMIT="100g" #100G
1300 local FILE_LIMIT=1000000
1302 setup_quota_test || error "setup quota failed with $?"
1303 trap cleanup_quota_test EXIT
1305 set_mdt_qtype "ug" || error "enable mdt quota failed"
1306 set_ost_qtype "ug" || error "enable ost quota failed"
1308 echo "Set enough high limit for user: $TSTUSR"
1309 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1310 error "set user quota failed"
1311 echo "Set enough high limit for group: $TSTUSR"
1312 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1313 error "set group quota failed"
1316 [ "$SLOW" = "no" ] && duration=" -t 120"
1317 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1318 quota_error a $TSTUSR "dbench failed!"
1321 resetquota -u $TSTUSR
1322 resetquota -g $TSTUSR
1324 run_test 8 "Run dbench with quota enabled"
1326 # this check is just for test_9
1327 OST0_MIN=4900000 #4.67G
1329 check_whether_skip () {
1330 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1331 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1332 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1333 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1340 # run for fixing bug10707, it needs a big room. test for 64bit
1342 local filesize=$((1024 * 9 / 2)) # 4.5G
1344 check_whether_skip && return 0
1346 setup_quota_test || error "setup quota failed with $?"
1347 trap cleanup_quota_test EXIT
1349 set_ost_qtype "ug" || error "enable ost quota failed"
1351 local TESTFILE="$DIR/$tdir/$tfile-0"
1352 local BLK_LIMIT=100G #100G
1353 local FILE_LIMIT=1000000
1355 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1357 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1359 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1360 error "set user quota failed"
1362 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1363 "for group: $TSTUSR"
1364 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1365 error "set group quota failed"
1367 quota_show_check a u $TSTUSR
1368 quota_show_check a g $TSTUSR
1370 echo "Create test file"
1371 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1372 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1374 log "Write the big file of 4.5G ..."
1375 $RUNAS $DD of=$TESTFILE count=$filesize ||
1376 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1382 resetquota -u $TSTUSR
1383 resetquota -g $TSTUSR
1388 run_test 9 "Block limit larger than 4GB (b10707)"
1391 local TESTFILE=$DIR/$tdir/$tfile
1393 setup_quota_test || error "setup quota failed with $?"
1394 trap cleanup_quota_test EXIT
1396 # set limit to root user should fail
1397 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1398 error "set limit for root user successfully, expect failure"
1399 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1400 error "set limit for root group successfully, expect failure"
1402 # root user can overrun quota
1403 set_ost_qtype "ug" || error "enable ost quota failed"
1405 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1406 error "set quota failed"
1407 quota_show_check b u $TSTUSR
1409 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1410 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1412 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1413 error "write failure, expect success"
1416 resetquota -u $TSTUSR
1418 run_test 10 "Test quota for root user"
1421 local TESTFILE=$DIR/$tdir/$tfile
1422 setup_quota_test || error "setup quota failed with $?"
1423 trap cleanup_quota_test EXIT
1425 set_mdt_qtype "ug" || error "enable mdt quota failed"
1426 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1427 error "set quota failed"
1429 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1430 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1432 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1433 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1436 local USED=$(getquota -u $TSTUSR global curinodes)
1437 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1440 resetquota -u $TSTUSR
1442 run_test 11 "Chown/chgrp ignores quota"
1445 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1447 local blimit=22 # 22M
1448 local blk_cnt=$((blimit - 5))
1449 local TESTFILE0="$DIR/$tdir/$tfile"-0
1450 local TESTFILE1="$DIR/$tdir/$tfile"-1
1452 setup_quota_test || error "setup quota failed with $?"
1453 trap cleanup_quota_test EXIT
1455 set_ost_qtype "u" || error "enable ost quota failed"
1456 quota_show_check b u $TSTUSR
1458 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1459 error "set quota failed"
1461 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1462 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1463 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1464 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1466 echo "Write to ost0..."
1467 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1468 quota_error a $TSTUSR "dd failed"
1470 echo "Write to ost1..."
1471 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1472 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1474 echo "Free space from ost0..."
1476 wait_delete_completed
1477 sync_all_data || true
1479 echo "Write to ost1 after space freed from ost0..."
1480 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1481 quota_error a $TSTUSR "rebalancing failed"
1484 resetquota -u $TSTUSR
1486 run_test 12a "Block quota rebalancing"
1489 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1491 local ilimit=$((1024 * 2)) # 2k inodes
1492 local TESTFILE0=$DIR/$tdir/$tfile
1493 local TESTFILE1=$DIR/${tdir}-1/$tfile
1495 setup_quota_test || error "setup quota failed with $?"
1496 trap cleanup_quota_test EXIT
1498 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1499 chmod 0777 $DIR/${tdir}-1
1501 set_mdt_qtype "u" || error "enable mdt quota failed"
1502 quota_show_check f u $TSTUSR
1504 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1505 error "set quota failed"
1507 echo "Create $ilimit files on mdt0..."
1508 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1509 quota_error u $TSTUSR "create failed, but expect success"
1511 echo "Create files on mdt1..."
1512 $RUNAS createmany -m $TESTFILE1 1 &&
1513 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1515 echo "Free space from mdt0..."
1516 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1517 wait_delete_completed
1518 sync_all_data || true
1520 echo "Create files on mdt1 after space freed from mdt0..."
1521 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1522 quota_error a $TSTUSR "rebalancing failed"
1524 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1525 error "unlink mdt1 files failed"
1526 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1529 resetquota -u $TSTUSR
1531 run_test 12b "Inode quota rebalancing"
1534 local TESTFILE=$DIR/$tdir/$tfile
1535 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1536 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1538 setup_quota_test || error "setup quota failed with $?"
1539 trap cleanup_quota_test EXIT
1541 set_ost_qtype "u" || error "enable ost quota failed"
1542 quota_show_check b u $TSTUSR
1544 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1545 error "set quota failed"
1546 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1547 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1549 # clear the locks in cache first
1550 do_facet ost1 $LCTL set_param -n $procf=clear
1551 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1552 [ $nlock -eq 0 ] || error "$nlock cached locks"
1554 # write to acquire the per-ID lock
1555 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1556 quota_error a $TSTUSR "dd failed"
1558 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1559 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1561 # clear quota doesn't trigger per-ID lock cancellation
1562 resetquota -u $TSTUSR
1563 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1564 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1566 # clear the per-ID lock
1567 do_facet ost1 $LCTL set_param -n $procf=clear
1568 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1569 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1571 # spare quota should be released
1572 local OSTUUID=$(ostuuid_from_index 0)
1573 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1574 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1575 [ $limit -le $space ] ||
1576 error "spare quota isn't released, limit:$limit, space:$space"
1580 run_test 13 "Cancel per-ID lock in the LRU list"
1583 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1585 wait_delete_completed
1586 sync_all_data || true
1589 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1590 error "set user quota failed"
1591 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1592 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1593 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1594 resetquota -u $TSTUSR
1597 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1598 error "set group quota failed"
1599 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1600 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1601 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1602 resetquota -g $TSTUSR
1604 run_test 15 "Set over 4T block quota"
1608 local BLKS=1 # 1M less than limit
1609 local TESTFILE=$DIR/$tdir/$tfile
1611 setup_quota_test || error "setup quota failed with $?"
1612 trap cleanup_quota_test EXIT
1614 # make sure the system is clean
1615 local USED=$(getquota -u $TSTUSR global curspace)
1616 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1618 set_ost_qtype "ug" || error "enable ost quota failed"
1619 # make sure no granted quota on ost
1620 resetquota -u $TSTUSR
1621 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1622 error "set quota failed"
1624 quota_show_check b u $TSTUSR
1626 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1627 lustre_fail mds 0xa04 $err_code
1629 # write in background
1630 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1634 # write should be blocked and never finished
1635 if ! ps -p $DDPID > /dev/null 2>&1; then
1637 quota_error u $TSTUSR "write finished incorrectly!"
1645 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1647 if [ $count -gt $timeout ]; then
1648 quota_error u $TSTUSR "dd is not finished!"
1653 sync; sync_all_data || true
1655 USED=$(getquota -u $TSTUSR global curspace)
1656 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1657 "Used space(${USED}K) is less than ${BLKS}M"
1660 resetquota -u $TSTUSR
1663 # DQACQ return recoverable error
1665 echo "DQACQ return -ENOLCK"
1667 test_17sub 37 || error "Handle -ENOLCK failed"
1669 echo "DQACQ return -EAGAIN"
1671 test_17sub 11 || error "Handle -EAGAIN failed"
1673 echo "DQACQ return -ETIMEDOUT"
1674 #define ETIMEDOUT 110
1675 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1677 echo "DQACQ return -ENOTCONN"
1678 #define ENOTCONN 107
1679 test_17sub 107 || error "Handle -ENOTCONN failed"
1682 run_test 17 "DQACQ return recoverable error"
1686 local blimit="200m" # 200M
1687 local TESTFILE="$DIR/$tdir/$tfile"
1689 setup_quota_test || error "setup quota failed with $?"
1690 trap cleanup_quota_test EXIT
1692 set_ost_qtype "u" || error "enable ost quota failed"
1693 log "User quota (limit: $blimit)"
1694 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1695 error "set quota failed"
1696 quota_show_check b u $TSTUSR
1698 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1699 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1701 local timeout=$(sysctl -n lustre.timeout)
1703 if [ $io_type = "directio" ]; then
1704 log "Write 100M (directio) ..."
1705 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1707 log "Write 100M (buffered) ..."
1708 $RUNAS $DD of=$TESTFILE count=100 &
1712 replay_barrier $SINGLEMDS
1713 log "Fail mds for $((2 * timeout)) seconds"
1714 fail $SINGLEMDS $((2 * timeout))
1717 if at_is_enabled; then
1718 timeout=$(at_max_get mds)
1720 timeout=$(lctl get_param -n timeout)
1724 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1725 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1726 log "it took $count second"
1731 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1733 cancel_lru_locks mdc
1734 cancel_lru_locks osc
1737 local testfile_size=$(stat -c %s $TESTFILE)
1738 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1739 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1740 "got ${testfile_size}. Verifying file failed!"
1743 resetquota -u $TSTUSR
1746 # test when mds does failover, the ost still could work well
1747 # this test shouldn't trigger watchdog b=14840
1749 # Clear dmesg so watchdog is not triggered by previous
1751 do_facet ost1 dmesg -c > /dev/null
1754 test_18_sub directio
1756 # check if watchdog is triggered
1757 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1758 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1759 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1760 [ -z "$watchdog" ] || error "$watchdog"
1761 rm -f $TMP/lustre-log-${TESTNAME}.log
1763 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1767 local TESTFILE=$DIR/$tdir/$tfile
1769 setup_quota_test || error "setup quota failed with $?"
1770 trap cleanup_quota_test EXIT
1772 set_ost_qtype "ug" || error "enable ost quota failed"
1774 # bind file to a single OST
1775 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1776 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1778 echo "Set user quota (limit: ${blimit}M)"
1779 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1780 error "set user quota failed"
1781 quota_show_check b u $TSTUSR
1782 echo "Update quota limits"
1783 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1784 error "set group quota failed"
1785 quota_show_check b u $TSTUSR
1787 # first wirte might be cached
1788 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1789 cancel_lru_locks osc
1791 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1792 quota_error u $TSTUSR "Write success, expect failure"
1796 resetquota -u $TSTUSR
1798 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1800 test_20() { # b15754
1801 local LSTR=(2g 1t 4k 3m) # limits strings
1803 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1806 resetquota -u $TSTUSR
1808 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1809 $MOUNT || error "could not set quota limits"
1810 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1811 --inode-softlimit ${LSTR[2]} \
1812 --inode-hardlimit ${LSTR[3]} \
1813 $MOUNT || error "could not set quota limits"
1815 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1816 error "bsoftlimit was not set properly"
1817 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1818 error "bhardlimit was not set properly"
1819 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1820 error "isoftlimit was not set properly"
1821 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1822 error "ihardlimit was not set properly"
1824 resetquota -u $TSTUSR
1826 run_test 20 "Test if setquota specifiers work properly (b15754)"
1833 local time=$(($(date +%s) + seconds))
1834 while [ $(date +%s) -lt $time ]; do
1835 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1839 # run for fixing bug16053, setquota shouldn't fail when writing and
1840 # deleting are happening
1842 local TESTFILE="$DIR/$tdir/$tfile"
1843 local BLIMIT=10 # 10G
1844 local ILIMIT=1000000
1846 setup_quota_test || error "setup quota failed with $?"
1847 trap cleanup_quota_test EXIT
1849 set_ost_qtype "ug" || error "Enable ost quota failed"
1851 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1852 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1853 error "set user quota failed"
1854 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1855 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1856 error "set group quota failed"
1858 # repeat writing on a 1M file
1859 test_21_sub ${TESTFILE}_1 1 30 &
1861 # repeat writing on a 128M file
1862 test_21_sub ${TESTFILE}_2 128 30 &
1865 local time=$(($(date +%s) + 30))
1867 while [ $(date +%s) -lt $time ]; do
1868 log "Set quota for $i times"
1869 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1870 -I $((ILIMIT + i)) $MOUNT ||
1871 error "Set user quota failed"
1872 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1873 -I $((ILIMIT + i)) $MOUNT ||
1874 error "Set group quota failed"
1881 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1883 if [ $count -gt 60 ]; then
1884 quota_error a $TSTUSR "dd should be finished!"
1888 echo "(dd_pid=$DDPID1, time=$count)successful"
1892 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1894 if [ $count -gt 60 ]; then
1895 quota_error a $TSTUSR "dd should be finished!"
1899 echo "(dd_pid=$DDPID2, time=$count)successful"
1902 resetquota -u $TSTUSR
1903 resetquota -g $TSTUSR
1905 run_test 21 "Setquota while writing & deleting (b16053)"
1907 # enable/disable quota enforcement permanently
1909 echo "Set both mdt & ost quota type as ug"
1910 set_mdt_qtype "ug" || error "enable mdt quota failed"
1911 set_ost_qtype "ug" || error "enable ost quota failed"
1914 stopall || error "failed to stopall (1)"
1918 echo "Verify if quota is enabled"
1919 local qtype=$(mdt_quota_type)
1920 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1921 qtype=$(ost_quota_type)
1922 [ $qtype != "ug" ] && error "ost quota setting is lost"
1924 echo "Set both mdt & ost quota type as none"
1925 set_mdt_qtype "none" || error "disable mdt quota failed"
1926 set_ost_qtype "none" || error "disable ost quota failed"
1929 stopall || error "failed to stopall (2)"
1934 echo "Verify if quota is disabled"
1935 qtype=$(mdt_quota_type)
1936 [ $qtype != "none" ] && error "mdt quota setting is lost"
1937 qtype=$(ost_quota_type)
1938 [ $qtype != "none" ] && error "ost quota setting is lost"
1942 run_test 22 "enable/disable quota by 'lctl conf_param'"
1945 local TESTFILE="$DIR/$tdir/$tfile"
1948 setup_quota_test || error "setup quota failed with $?"
1949 trap cleanup_quota_test EXIT
1951 set_ost_qtype "ug" || error "Enable ost quota failed"
1954 log "User quota (limit: $LIMIT MB)"
1955 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1956 error "set quota failed"
1957 quota_show_check b u $TSTUSR
1959 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1960 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1962 log "Step1: trigger EDQUOT with O_DIRECT"
1963 log "Write half of file"
1964 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1965 quota_error u $TSTUSR "(1) Write failure, expect success." \
1967 log "Write out of block quota ..."
1968 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1969 oflag=direct conv=notrunc &&
1970 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1974 log "Step2: rewrite should succeed"
1975 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1976 quota_error u $TSTUSR "(3) Write failure, expect success." \
1982 local OST0_UUID=$(ostuuid_from_index 0)
1983 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1984 [ $OST0_QUOTA_USED -ne 0 ] &&
1985 ($SHOW_QUOTA_USER; \
1986 quota_error u $TSTUSR "quota isn't released")
1988 resetquota -u $TSTUSR
1992 [ $(facet_fstype ost1) == "zfs" ] &&
1993 skip "Overwrite in place is not guaranteed to be " \
1994 "space neutral on ZFS" && return
1996 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1997 check_whether_skip && return 0
1998 log "run for 4MB test file"
2001 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2002 check_whether_skip && return 0
2003 log "run for 40MB test file"
2006 run_test 23 "Quota should be honored with directIO (b16125)"
2010 local TESTFILE="$DIR/$tdir/$tfile"
2012 setup_quota_test || error "setup quota failed with $?"
2013 trap cleanup_quota_test EXIT
2015 set_ost_qtype "ug" || error "enable ost quota failed"
2017 # bind file to a single OST
2018 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2019 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2021 echo "Set user quota (limit: ${blimit}M)"
2022 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2023 error "set quota failed"
2025 # overrun quota by root user
2026 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2027 error "write failure, expect success"
2028 cancel_lru_locks osc
2029 sync_all_data || true
2031 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2034 resetquota -u $TSTUSR
2036 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2038 test_27a() { # b19612
2039 $LFS quota $TSTUSR $DIR &&
2040 error "lfs succeeded with no type, but should have failed"
2041 $LFS setquota $TSTUSR $DIR &&
2042 error "lfs succeeded with no type, but should have failed"
2045 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2047 test_27b() { # b20200
2048 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2049 error "lfs setquota failed with uid argument"
2050 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2051 error "lfs stequota failed with gid argument"
2052 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2053 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2054 resetquota -u $TSTUSR
2055 resetquota -g $TSTUSR
2058 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2063 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2064 error "lfs setquota failed"
2066 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2067 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2068 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2069 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2071 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2072 error "lfs setquota for $TSTID failed"
2074 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2075 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2076 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2077 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2079 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2080 error "total allocated inode/block limit not printed"
2082 resetquota -u $TSTUSR
2084 run_test 27c "lfs quota should support human-readable output"
2091 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2092 error "set fraction block limit failed"
2093 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2094 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2095 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2096 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2098 resetquota -u $TSTUSR
2100 run_test 27d "lfs setquota should support fraction block limit"
2104 local TESTFILE="$DIR/$tdir/$tfile"
2107 setup_quota_test || error "setup quota failed with $?"
2108 trap cleanup_quota_test EXIT
2110 set_ost_qtype "u" || error "enable ost quota failed"
2112 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2113 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2115 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2116 $MAX_IQ_TIME $DIR || error "set grace time failed"
2117 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2118 error "set quota failed"
2119 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2120 cancel_lru_locks osc
2122 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2123 # over-quota flag has not yet settled since we do not trigger async
2124 # events based on grace time period expiration
2126 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2127 cancel_lru_locks osc
2128 # now over-quota flag should be settled and further writes should fail
2130 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2131 error "grace times were reset"
2134 resetquota -u $TSTUSR
2135 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2136 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2138 run_test 30 "Hard limit updates should not reset grace times"
2140 # basic usage tracking for user & group
2142 local INODES=10 # 10 files
2143 local BLK_CNT=2 # of 2M each
2144 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2146 setup_quota_test || error "setup quota failed with $?"
2147 trap cleanup_quota_test EXIT
2149 # make sure the system is clean
2150 local USED=$(getquota -u $TSTID global curspace)
2152 error "Used space ($USED) for user $TSTID isn't 0."
2153 USED=$(getquota -g $TSTID global curspace)
2155 error "Used space ($USED) for group $TSTID isn't 0."
2157 echo "Write files..."
2158 for i in $(seq 0 $INODES); do
2159 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2160 error "write failed"
2161 echo "Iteration $i/$INODES completed"
2163 cancel_lru_locks osc
2164 sync; sync_all_data || true
2166 echo "Verify disk usage after write"
2167 USED=$(getquota -u $TSTID global curspace)
2168 [ $USED -lt $TOTAL_BLKS ] &&
2169 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2170 USED=$(getquota -g $TSTID global curspace)
2171 [ $USED -lt $TOTAL_BLKS ] &&
2172 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2174 echo "Verify inode usage after write"
2175 USED=$(getquota -u $TSTID global curinodes)
2176 [ $USED -lt $INODES ] &&
2177 error "Used inode for user $TSTID is $USED, expected $INODES"
2178 USED=$(getquota -g $TSTID global curinodes)
2179 [ $USED -lt $INODES ] &&
2180 error "Used inode for group $TSTID is $USED, expected $INODES"
2184 echo "Verify disk usage after delete"
2185 USED=$(getquota -u $TSTID global curspace)
2186 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2187 USED=$(getquota -u $TSTID global curinodes)
2188 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2189 USED=$(getquota -g $TSTID global curspace)
2190 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2191 USED=$(getquota -g $TSTID global curinodes)
2192 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2194 run_test 33 "Basic usage tracking for user & group"
2196 # usage transfer test for user & group
2198 local BLK_CNT=2 # 2MB
2200 setup_quota_test || error "setup quota failed with $?"
2201 trap cleanup_quota_test EXIT
2203 # make sure the system is clean
2204 local USED=$(getquota -u $TSTID global curspace)
2205 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2206 USED=$(getquota -g $TSTID global curspace)
2207 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2209 local USED=$(getquota -u $TSTID2 global curspace)
2210 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2212 echo "Write file..."
2213 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2214 error "write failed"
2215 cancel_lru_locks osc
2216 sync; sync_all_data || true
2218 echo "chown the file to user $TSTID"
2219 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2221 echo "Wait for setattr on objects finished..."
2222 wait_delete_completed
2224 BLK_CNT=$((BLK_CNT * 1024))
2226 echo "Verify disk usage for user $TSTID"
2227 USED=$(getquota -u $TSTID global curspace)
2228 [ $USED -lt $BLK_CNT ] &&
2229 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2230 USED=$(getquota -u $TSTID global curinodes)
2232 error "Used inodes for user $TSTID is $USED, expected 1"
2234 echo "chgrp the file to group $TSTID"
2235 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2237 echo "Wait for setattr on objects finished..."
2238 wait_delete_completed
2240 echo "Verify disk usage for group $TSTID"
2241 USED=$(getquota -g $TSTID global curspace)
2242 [ $USED -ge $BLK_CNT ] ||
2243 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2244 USED=$(getquota -g $TSTID global curinodes)
2246 error "Used inodes for group $TSTID is $USED, expected 1"
2248 # chown won't change the ost object group. LU-4345 */
2249 echo "chown the file to user $TSTID2"
2250 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2252 echo "Wait for setattr on objects finished..."
2253 wait_delete_completed
2255 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2256 USED=$(getquota -u $TSTID2 global curspace)
2257 [ $USED -lt $BLK_CNT ] &&
2258 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2259 USED=$(getquota -u $TSTID global curspace)
2261 error "Used space for user $TSTID is $USED, expected 0"
2262 USED=$(getquota -g $TSTID global curspace)
2263 [ $USED -lt $BLK_CNT ] &&
2264 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2268 run_test 34 "Usage transfer for user & group"
2270 # usage is still accessible across restart
2272 local BLK_CNT=2 # 2 MB
2274 setup_quota_test || error "setup quota failed with $?"
2275 trap cleanup_quota_test EXIT
2277 echo "Write file..."
2278 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2279 error "write failed"
2280 cancel_lru_locks osc
2281 sync; sync_all_data || true
2283 echo "Save disk usage before restart"
2284 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2285 [ $ORIG_USR_SPACE -eq 0 ] &&
2286 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2287 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2288 [ $ORIG_USR_INODES -eq 0 ] &&
2289 error "Used inodes for user $TSTID is 0, expected 1"
2290 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2291 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2292 [ $ORIG_GRP_SPACE -eq 0 ] &&
2293 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2294 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2295 [ $ORIG_GRP_INODES -eq 0 ] &&
2296 error "Used inodes for group $TSTID is 0, expected 1"
2297 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2300 local ORIG_REFORMAT=$REFORMAT
2302 cleanup_and_setup_lustre
2303 REFORMAT=$ORIG_REFORMAT
2306 echo "Verify disk usage after restart"
2307 local USED=$(getquota -u $TSTID global curspace)
2308 [ $USED -eq $ORIG_USR_SPACE ] ||
2309 error "Used space for user $TSTID changed from " \
2310 "$ORIG_USR_SPACE to $USED"
2311 USED=$(getquota -u $TSTID global curinodes)
2312 [ $USED -eq $ORIG_USR_INODES ] ||
2313 error "Used inodes for user $TSTID changed from " \
2314 "$ORIG_USR_INODES to $USED"
2315 USED=$(getquota -g $TSTID global curspace)
2316 [ $USED -eq $ORIG_GRP_SPACE ] ||
2317 error "Used space for group $TSTID changed from " \
2318 "$ORIG_GRP_SPACE to $USED"
2319 USED=$(getquota -g $TSTID global curinodes)
2320 [ $USED -eq $ORIG_GRP_INODES ] ||
2321 error "Used inodes for group $TSTID changed from " \
2322 "$ORIG_GRP_INODES to $USED"
2324 # check if the vfs_dq_init() is called before writing
2325 echo "Append to the same file..."
2326 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2327 error "write failed"
2328 cancel_lru_locks osc
2329 sync; sync_all_data || true
2331 echo "Verify space usage is increased"
2332 USED=$(getquota -u $TSTID global curspace)
2333 [ $USED -gt $ORIG_USR_SPACE ] ||
2334 error "Used space for user $TSTID isn't increased" \
2335 "orig:$ORIG_USR_SPACE, now:$USED"
2336 USED=$(getquota -g $TSTID global curspace)
2337 [ $USED -gt $ORIG_GRP_SPACE ] ||
2338 error "Used space for group $TSTID isn't increased" \
2339 "orig:$ORIG_GRP_SPACE, now:$USED"
2343 run_test 35 "Usage is still accessible across reboot"
2345 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2348 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2349 skip "Old server doesn't have LU-5006 fix." && return
2351 setup_quota_test || error "setup quota failed with $?"
2352 trap cleanup_quota_test EXIT
2354 # make sure the system is clean
2355 local USED=$(getquota -u $TSTID global curspace)
2357 error "Used space ($USED) for user $TSTID isn't 0."
2359 # create file with MDS_OPEN_DELAY_CREATE flag
2360 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2361 error "Create file failed"
2363 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2364 oflag=sync || error "Write file failed"
2366 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2368 # wait for setattr on objects finished..."
2369 wait_delete_completed
2371 USED=$(getquota -u $TSTID global curspace)
2372 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2376 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2380 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2381 skip "Old server doesn't have LU-8801 fix." && return
2383 [ "$UID" != 0 ] && skip_env "must run as root" && return
2385 setup_quota_test || error "setup quota failed with $?"
2386 trap cleanup_quota_test EXIT
2388 # make sure the system is clean
2389 local USED=$(getquota -u $TSTID global curspace)
2391 error "Used space ($USED) for user $TSTID isn't 0."
2392 USED=$(getquota -u $TSTID2 global curspace)
2394 error "Used space ($USED) for user $TSTID2 isn't 0."
2396 local TESTFILE="$DIR/$tdir/$tfile"
2397 local file_cnt=10000
2399 # Generate id entries in accounting file
2400 echo "Create $file_cnt files..."
2401 for i in `seq $file_cnt`; do
2403 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2405 cancel_lru_locks osc
2406 sync; sync_all_data || true
2408 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2409 procf=${procf}.quota_slave.acct_user
2412 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2413 echo "Found $acct_cnt id entries"
2415 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2419 run_test 38 "Quota accounting iterator doesn't skip id entries"
2422 [ "$(facet_fstype $singlemds)" != "ldiskfs" ] &&
2423 skip "only for ldiskfs mdt" && return 0
2425 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10) ] &&
2426 skip "Old server doesn't support project quota." && return
2428 man lsattr | grep -i project ||
2429 skip "old e2fsprogs dosen't support project quota" &&
2432 enable_project_quota
2434 local TESTFILE="$DIR/project"
2436 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2437 [ $projectid -ne 0 ] &&
2438 error "Project id should be 0 not $projectid"
2439 chattr -p 1024 $TESTFILE
2440 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2441 [ $projectid -ne 1024 ] &&
2442 error "Project id should be 1024 not $projectid"
2444 stopall || error "failed to stopall (1)"
2447 projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
2448 [ $projectid -ne 1024 ] &&
2449 error "Project id should be 1024 not $projectid"
2451 disable_project_quota
2454 run_test 39 "Project ID interface works correctly"
2458 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2464 check_and_cleanup_lustre
2465 export QUOTA_AUTO=$QUOTA_AUTO_OLD