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 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
17 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
23 TSTID2=${TSTID2:-60001}
24 TSTUSR=${TSTUSR:-"quota_usr"}
25 TSTUSR2=${TSTUSR2:-"quota_2usr"}
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
37 require_dsh_mds || exit 0
38 require_dsh_ost || exit 0
40 # XXX Once we drop the interoperability with old server (< 2.3.50), the
41 # sanity-quota-old.sh should be removed.
42 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
43 exec $LUSTRE/tests/sanity-quota-old.sh
46 # if e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
48 ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
49 skip "e2fsprogs doesn't support quota" && exit 0
52 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
53 # bug number for skipped test: LU-2836 LU-2836 LU-2059
54 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 6 7d"
59 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
61 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
63 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
68 QUOTA_AUTO_OLD=$QUOTA_AUTO
71 check_and_setup_lustre
73 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
74 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
76 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
77 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
78 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
79 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
80 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
81 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
82 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
83 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
90 local fail_val=${3:-0}
92 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
93 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
94 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
97 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
98 for num in `seq $OSTCOUNT`; do
99 do_facet ost$num "lctl set_param fail_val=$fail_val"
100 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
105 RUNAS="runas -u $TSTID -g $TSTID"
106 RUNAS2="runas -u $TSTID2 -g $TSTID2"
107 DD="dd if=/dev/zero bs=1M"
111 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
112 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
113 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
114 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
116 # clear quota limits for a user or a group
117 # usage: resetquota -u username
118 # resetquota -g groupname
121 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
122 [ "$1" != "-u" -a "$1" != "-g" ] &&
123 error "resetquota: wrong specifier $1 passed"
125 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
126 error "clear quota for [type:$1 name:$2] failed"
127 # give a chance to slave to release space
135 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
136 $LFS quota -v -u $LOCAL_ID $DIR
137 log "Files for user ($LOCAL_ID):"
138 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
139 xargs stat 2>/dev/null)
142 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
143 $LFS quota -v -u $LOCAL_ID $DIR
144 log "Files for group ($LOCAL_ID):"
145 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
146 xargs stat 2>/dev/null)
162 # get quota for a user or a group
163 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
164 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
170 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
171 [ "$1" != "-u" -a "$1" != "-g" ] &&
172 error "getquota: wrong u/g specifier $1 passed"
185 *) error "unknown quota parameter $4";;
188 [ "$uuid" = "global" ] && uuid=$DIR
190 $LFS quota -v "$1" "$2" $DIR |
191 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
192 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
197 # usage: set_mdt_qtype ug|u|g|none
201 local mdts=$(get_facets MDS)
203 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
204 # we have to make sure each MDT received config changes
205 for mdt in ${mdts//,/ }; do
207 cmd="$LCTL get_param -n "
208 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
209 cmd=${cmd}.quota_slave.enabled
211 if $(facet_up $mdt); then
212 wait_update_facet $mdt "$cmd" "$qtype" || return 1
219 # usage: set_ost_qtype ug|u|g|none
223 local osts=$(get_facets OST)
225 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
226 # we have to make sure each OST received config changes
227 for ost in ${osts//,/ }; do
229 cmd="$LCTL get_param -n "
230 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
231 cmd=${cmd}.quota_slave.enabled
233 if $(facet_up $ost); then
234 wait_update_facet $ost "$cmd" "$qtype" || return 1
240 wait_reintegration() {
244 local result="glb[1],slv[1],reint[0]"
249 if [ $ntype == "mdt" ]; then
250 tgts=$(get_facets MDS)
252 tgts=$(get_facets OST)
255 for tgt in ${tgts//,/ }; do
257 cmd="$LCTL get_param -n "
258 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
259 cmd=${cmd}.quota_slave.info
261 if $(facet_up $tgt); then
262 wait_update_facet $tgt "$cmd |
263 grep "$qtype" | awk '{ print \\\$3 }'" \
264 "$result" $max || return 1
274 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
275 wait_reintegration "mdt" "user" $max || return 1
278 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
279 wait_reintegration "mdt" "group" $max || return 1
288 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
289 wait_reintegration "ost" "user" $max || return 1
292 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
293 wait_reintegration "ost" "group" $max || return 1
300 wait_delete_completed
301 echo "Creating test directory"
303 chmod 0777 $DIR/$tdir
304 # always clear fail_loc in case of fail_loc isn't cleared
305 # properly when previous test failed
306 lustre_fail mds_ost 0
309 cleanup_quota_test() {
311 echo "Delete files..."
313 echo "Wait for unlink objects finished..."
314 wait_delete_completed
315 sync_all_data || true
324 $LFS quota -v -$ug $qid $DIR
326 if [ "$bf" == "a" -o "$bf" == "b" ]; then
327 usage=$(getquota -$ug $qid global curspace)
328 if [ -z $usage ]; then
329 quota_error $ug $qid \
330 "Query block quota failed ($ug:$qid)."
332 [ $usage -ne 0 ] && quota_log $ug $qid \
333 "Block quota isn't 0 ($ug:$qid:$usage)."
337 if [ "$bf" == "a" -o "$bf" == "f" ]; then
338 usage=$(getquota -$ug $qid global curinodes)
339 if [ -z $usage ]; then
340 quota_error $ug $qid \
341 "Query file quota failed ($ug:$qid)."
343 [ $usage -ne 0 ] && quota_log $ug $qid \
344 "File quota isn't 0 ($ug:$qid:$usage)."
351 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
355 resetquota -u $TSTUSR
356 resetquota -g $TSTUSR
357 resetquota -u $TSTUSR2
358 resetquota -g $TSTUSR2
360 test_quota_performance() {
361 local TESTFILE="$DIR/$tdir/$tfile-0"
362 local size=$1 # in MB
363 local stime=$(date +%s)
364 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
365 quota_error u $TSTUSR "write failure"
366 local etime=$(date +%s)
367 delta=$((etime - stime))
368 if [ $delta -gt 0 ]; then
369 rate=$((size * 1024 / delta))
370 [ $rate -gt 1024 ] ||
371 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
376 # test basic quota performance b=21696
379 [ "$SLOW" = "no" ] && MB=10
381 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
382 [ $free_space -le $((MB * 1024)) ] &&
383 skip "not enough space ${free_space} KB, " \
384 "required $((MB * 1024)) KB" && return
386 trap cleanup_quota_test EXIT
388 set_ost_qtype "none" || error "disable ost quota failed"
389 test_quota_performance $MB
391 set_ost_qtype "ug" || error "enable ost quota failed"
392 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
393 error "set quota failed"
394 test_quota_performance $MB
397 resetquota -u $TSTUSR
399 run_test 0 "Test basic quota performance"
401 # test block hardlimit
404 local TESTFILE="$DIR/$tdir/$tfile-0"
407 trap cleanup_quota_test EXIT
410 set_ost_qtype "ug" || "enable ost quota failed"
413 log "User quota (block hardlimit:$LIMIT MB)"
414 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
415 error "set user quota failed"
417 # make sure the system is clean
418 local USED=$(getquota -u $TSTUSR global curspace)
419 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
421 $LFS setstripe $TESTFILE -c 1
422 chown $TSTUSR.$TSTUSR $TESTFILE
425 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
426 quota_error u $TSTUSR "user write failure, but expect success"
427 log "Write out of block quota ..."
428 # this time maybe cache write, ignore it's failure
429 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
430 # flush cache, ensure noquota flag is set on client
432 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
433 quota_error u $TSTUSR "user write success, but expect EDQUOT"
436 wait_delete_completed
437 sync_all_data || true
438 USED=$(getquota -u $TSTUSR global curspace)
439 [ $USED -ne 0 ] && quota_error u $TSTUSR \
440 "user quota isn't released after deletion"
441 resetquota -u $TSTUSR
444 log "--------------------------------------"
445 log "Group quota (block hardlimit:$LIMIT MB)"
446 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
447 error "set group quota failed"
449 TESTFILE="$DIR/$tdir/$tfile-1"
450 # make sure the system is clean
451 USED=$(getquota -g $TSTUSR global curspace)
452 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
454 $LFS setstripe $TESTFILE -c 1
455 chown $TSTUSR.$TSTUSR $TESTFILE
458 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
459 quota_error g $TSTUSR "group write failure, but expect success"
460 log "Write out of block quota ..."
461 # this time maybe cache write, ignore it's failure
462 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
464 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
465 quota_error g $TSTUSR "group write success, but expect EDQUOT"
470 USED=$(getquota -g $TSTUSR global curspace)
471 [ $USED -ne 0 ] && quota_error g $TSTUSR \
472 "group quota isn't released after deletion"
474 resetquota -g $TSTUSR
476 run_test 1 "Block hard limit (normal use and out of quota)"
478 # test inode hardlimit
480 local LIMIT=$((1024 * 1024)) # 1M inodes
481 local TESTFILE="$DIR/$tdir/$tfile-0"
483 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
485 local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
486 [ $FREE_INODES -lt $LIMIT ] &&
487 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
491 trap cleanup_quota_test EXIT
494 set_mdt_qtype "ug" || "enable mdt quota failed"
497 log "User quota (inode hardlimit:$LIMIT files)"
498 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
499 error "set user quota failed"
501 # make sure the system is clean
502 local USED=$(getquota -u $TSTUSR global curinodes)
503 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
505 log "Create $LIMIT files ..."
506 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
507 quota_error u $TSTUSR "user create failure, but expect success"
508 log "Create out of file quota ..."
509 $RUNAS touch ${TESTFILE}_xxx && \
510 quota_error u $TSTUSR "user create success, but expect EDQUOT"
513 unlinkmany ${TESTFILE} $LIMIT
514 rm -f ${TESTFILE}_xxx
515 wait_delete_completed
517 USED=$(getquota -u $TSTUSR global curinodes)
518 [ $USED -ne 0 ] && quota_error u $TSTUSR \
519 "user quota isn't released after deletion"
520 resetquota -u $TSTUSR
523 log "--------------------------------------"
524 log "Group quota (inode hardlimit:$LIMIT files)"
525 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
526 error "set group quota failed"
528 TESTFILE=$DIR/$tdir/$tfile-1
529 # make sure the system is clean
530 USED=$(getquota -g $TSTUSR global curinodes)
531 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
533 log "Create $LIMIT files ..."
534 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
535 quota_error g $TSTUSR "group create failure, but expect success"
536 log "Create out of file quota ..."
537 $RUNAS touch ${TESTFILE}_xxx && \
538 quota_error g $TSTUSR "group create success, but expect EDQUOT"
541 unlinkmany ${TESTFILE} $LIMIT
542 rm -f ${TESTFILE}_xxx
543 wait_delete_completed
545 USED=$(getquota -g $TSTUSR global curinodes)
546 [ $USED -ne 0 ] && quota_error g $TSTUSR \
547 "user quota isn't released after deletion"
550 resetquota -g $TSTUSR
552 run_test 2 "File hard limit (normal use and out of quota)"
556 local TIMER=$(($2 * 3 / 2))
561 trap cleanup_quota_test EXIT
563 $LFS setstripe $TESTFILE -c 1 -i 0
564 chown $TSTUSR.$TSTUSR $TESTFILE
566 echo "Write up to soft limit"
567 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
568 quota_error a $TSTUSR "write failure, but expect success"
569 OFFSET=$((LIMIT * 1024))
572 echo "Write to exceed soft limit"
573 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
574 quota_error a $TSTUSR "write failure, but expect success"
575 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
580 $SHOW_QUOTA_INFO_USER
581 $SHOW_QUOTA_INFO_GROUP
583 echo "Write before timer goes off"
584 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
585 quota_error a $TSTUSR "write failure, but expect success"
586 OFFSET=$((OFFSET + 1024))
589 echo "Sleep $TIMER seconds ..."
594 $SHOW_QUOTA_INFO_USER
595 $SHOW_QUOTA_INFO_GROUP
597 echo "Write after timer goes off"
598 # maybe cache write, ignore.
599 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
600 OFFSET=$((OFFSET + 1024))
602 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
603 quota_error a $TSTUSR "write success, but expect EDQUOT"
607 $SHOW_QUOTA_INFO_USER
608 $SHOW_QUOTA_INFO_GROUP
610 echo "Unlink file to stop timer"
612 wait_delete_completed
613 sync_all_data || true
617 $SHOW_QUOTA_INFO_USER
618 $SHOW_QUOTA_INFO_GROUP
620 $LFS setstripe $TESTFILE -c 1 -i 0
621 chown $TSTUSR.$TSTUSR $TESTFILE
624 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
625 quota_error a $TSTUSR "write failure, but expect success"
634 local TESTFILE=$DIR/$tdir/$tfile-0
636 set_ost_qtype "ug" || error "enable ost quota failed"
638 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
639 # make sure the system is clean
640 local USED=$(getquota -u $TSTUSR global curspace)
641 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
643 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
644 $MAX_IQ_TIME $DIR || error "set user grace time failed"
645 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
646 error "set user quota failed"
648 test_block_soft $TESTFILE $GRACE $LIMIT
649 resetquota -u $TSTUSR
651 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
652 TESTFILE=$DIR/$tdir/$tfile-1
653 # make sure the system is clean
654 USED=$(getquota -g $TSTUSR global curspace)
655 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
657 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
658 $MAX_IQ_TIME $DIR || error "set group grace time failed"
659 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
660 error "set group quota failed"
662 test_block_soft $TESTFILE $GRACE $LIMIT
663 resetquota -g $TSTUSR
666 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
667 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
668 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
669 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
671 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
676 local TIMER=$(($3 * 3 / 2))
679 trap cleanup_quota_test EXIT
681 echo "Create files to exceed soft limit"
682 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
683 quota_error a $TSTUSR "create failure, but expect success"
686 echo "Create file before timer goes off"
687 $RUNAS touch ${TESTFILE}_before ||
688 quota_error a $TSTUSR "failed create before timer expired," \
692 echo "Sleep $TIMER seconds ..."
697 $SHOW_QUOTA_INFO_USER
698 $SHOW_QUOTA_INFO_GROUP
700 echo "Create file after timer goes off"
701 # There is a window that space is accounted in the quota usage but
702 # hasn't been decreased from the pending write, if we acquire quota
703 # in this window, we'll acquire more than we needed.
704 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
706 $RUNAS touch ${TESTFILE}_after_3 &&
707 quota_error a $TSTUSR "create after timer expired," \
713 $SHOW_QUOTA_INFO_USER
714 $SHOW_QUOTA_INFO_GROUP
716 echo "Unlink files to stop timer"
717 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
718 wait_delete_completed
721 $RUNAS touch ${TESTFILE}_xxx ||
722 quota_error a $TSTUSR "touch after timer stop failure," \
732 local LIMIT=10 # inodes
733 local TESTFILE=$DIR/$tdir/$tfile-0
736 set_mdt_qtype "ug" || error "enable mdt quota failed"
738 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
739 # make sure the system is clean
740 local USED=$(getquota -u $TSTUSR global curinodes)
741 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
743 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
744 $GRACE $DIR || error "set user grace time failed"
745 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
746 error "set user quota failed"
748 test_file_soft $TESTFILE $LIMIT $GRACE
749 resetquota -u $TSTUSR
751 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
752 # make sure the system is clean
753 USED=$(getquota -g $TSTUSR global curinodes)
754 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
756 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
757 $GRACE $DIR || error "set group grace time failed"
758 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
759 error "set group quota failed"
760 TESTFILE=$DIR/$tdir/$tfile-1
762 test_file_soft $TESTFILE $LIMIT $GRACE
763 resetquota -g $TSTUSR
766 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
767 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
768 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
769 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
771 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
775 local GR_STR2="1000s"
777 local GR_STR4="1w2d3h4m5s"
779 local GR_STR6="1111111111111111"
781 wait_delete_completed
783 # test of valid grace strings handling
784 echo "Valid grace strings test"
785 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
786 $GR_STR2 $DIR || error "set user grace time failed"
787 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
788 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
789 $GR_STR4 $DIR || error "set group grace time quota failed"
790 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
792 # test of invalid grace strings handling
793 echo " Invalid grace strings test"
794 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
795 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
798 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
799 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
800 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
801 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
803 run_test 4b "Grace time strings handling"
805 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
807 local BLIMIT=10 # 10M
808 local ILIMIT=10 # 10 inodes
811 trap cleanup_quota_test EXIT
813 set_mdt_qtype "ug" || error "enable mdt quota failed"
814 set_ost_qtype "ug" || error "enable ost quota failed"
816 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
817 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
818 error "set user quota failed"
819 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
820 error "set group quota failed"
822 # make sure the system is clean
823 local USED=$(getquota -u $TSTUSR global curinodes)
824 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
825 USED=$(getquota -g $TSTUSR global curinodes)
826 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
827 USED=$(getquota -u $TSTUSR global curspace)
828 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
829 USED=$(getquota -g $TSTUSR global curspace)
830 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
832 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
833 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
834 error "create failure, expect success"
835 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
836 error "write failure, expect success"
838 echo "Chown files to $TSTUSR.$TSTUSR ..."
839 for i in `seq 0 $ILIMIT`; do
840 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
841 quota_error a $TSTUSR "chown failure, expect success"
845 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
848 resetquota -u $TSTUSR
849 resetquota -g $TSTUSR
851 run_test 5 "Chown & chgrp successfully even out of block/file quota"
853 # test dropping acquire request on master
858 trap cleanup_quota_test EXIT
860 # make sure the system is clean
861 local USED=$(getquota -u $TSTUSR global curspace)
862 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
864 # make sure no granted quota on ost
865 set_ost_qtype "ug" || error "enable ost quota failed"
866 resetquota -u $TSTUSR
868 # create file for $TSTUSR
869 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
870 $LFS setstripe $TESTFILE -c 1 -i 0
871 chown $TSTUSR.$TSTUSR $TESTFILE
873 # create file for $TSTUSR2
874 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
875 $LFS setstripe $TESTFILE2 -c 1 -i 0
876 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
878 # cache per-ID lock for $TSTUSR on slave
879 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
880 error "set quota failed"
881 $RUNAS $DD of=$TESTFILE count=1 ||
882 error "write $TESTFILE failure, expect success"
883 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
884 error "write $TESTFILE2 failure, expect success"
886 sync_all_data || true
888 #define QUOTA_DQACQ 601
889 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
890 lustre_fail mds 0x513 601
892 # write to un-enforced ID ($TSTUSR2) should succeed
893 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
894 error "write failure, expect success"
896 # write to enforced ID ($TSTUSR) in background, exceeding limit
897 # to make sure DQACQ is sent
898 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
901 # watchdog timer uses a factor of 2
902 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
903 sleep $((TIMEOUT * 2 + 1))
905 # write should be blocked and never finished
906 if ! ps -p $DDPID > /dev/null 2>&1; then
908 error "write finished incorrectly!"
913 # no watchdog is triggered
914 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
915 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
916 /Service thread pid/ && /was inactive/ {
920 }' $TMP/lustre-log-${TESTNAME}.log)
921 [ -z "$watchdog" ] || error "$watchdog"
923 rm -f $TMP/lustre-log-${TESTNAME}.log
925 # write should continue & succeed
928 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
929 if [ $count -ge 120 ]; then
930 quota_error u $TSTUSR "dd not finished in $count secs"
933 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
938 resetquota -u $TSTUSR
940 run_test 6 "Test dropping acquire request on master"
942 # quota reintegration (global index)
944 local TESTFILE=$DIR/$tdir/$tfile
947 [ "$SLOW" = "no" ] && LIMIT=5
950 trap cleanup_quota_test EXIT
952 # make sure the system is clean
953 local USED=$(getquota -u $TSTUSR global curspace)
954 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
956 # make sure no granted quota on ost1
957 set_ost_qtype "ug" || error "enable ost quota failed"
958 resetquota -u $TSTUSR
959 set_ost_qtype "none" || error "disable ost quota failed"
961 local OSTUUID=$(ostuuid_from_index 0)
962 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
963 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
967 $LFS setstripe $TESTFILE -c 1 -i 0
968 chown $TSTUSR.$TSTUSR $TESTFILE
973 echo "Enable quota & set quota limit for $TSTUSR"
974 set_ost_qtype "ug" || error "enable ost quota failed"
975 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
976 error "set quota failed"
979 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
982 wait_ost_reint "ug" || error "reintegration failed"
984 # hardlimit should have been fetched by slave during global
985 # reintegration, write will exceed quota
986 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
987 quota_error u $TSTUSR "write success, but expect EDQUOT"
990 wait_delete_completed
991 sync_all_data || true
997 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
998 error "clear quota failed"
1000 echo "Start ost1..."
1001 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1004 wait_ost_reint "ug" || error "reintegration failed"
1006 # hardlimit should be cleared on slave during reintegration
1007 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1008 quota_error u $TSTUSR "write error, but expect success"
1011 resetquota -u $TSTUSR
1013 run_test 7a "Quota reintegration (global index)"
1015 # quota reintegration (slave index)
1018 local TESTFILE=$DIR/$tdir/$tfile
1021 trap cleanup_quota_test EXIT
1023 # make sure the system is clean
1024 local USED=$(getquota -u $TSTUSR global curspace)
1025 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1027 # make sure no granted quota on ost1
1028 set_ost_qtype "ug" || error "enable ost quota failed"
1029 resetquota -u $TSTUSR
1030 set_ost_qtype "none" || error "disable ost quota failed"
1032 local OSTUUID=$(ostuuid_from_index 0)
1033 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1034 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1038 $LFS setstripe $TESTFILE -c 1 -i 0
1039 chown $TSTUSR.$TSTUSR $TESTFILE
1041 # consume some space to make sure the granted space will not
1042 # be released during reconciliation
1043 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1044 error "consume space failure, expect success"
1046 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1047 lustre_fail mds 0xa02
1049 set_ost_qtype "ug" || error "enable ost quota failed"
1050 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1051 error "set quota failed"
1053 # ignore the write error
1054 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1056 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1060 echo "Restart ost to trigger reintegration..."
1062 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1065 wait_ost_reint "ug" || error "reintegration failed"
1067 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1068 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1071 resetquota -u $TSTUSR
1074 run_test 7b "Quota reintegration (slave index)"
1076 # quota reintegration (restart mds during reintegration)
1078 local LIMIT=20 # 20M
1079 local TESTFILE=$DIR/$tdir/$tfile
1081 [ "$SLOW" = "no" ] && LIMIT=5
1084 trap cleanup_quota_test EXIT
1086 # make sure the system is clean
1087 local USED=$(getquota -u $TSTUSR global curspace)
1088 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1090 set_ost_qtype "none" || error "disable ost quota failed"
1091 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1092 error "set quota failed"
1094 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1095 lustre_fail ost 0xa03
1098 set_ost_qtype "ug" || error "enable ost quota failed"
1099 # trigger reintegration
1100 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1101 procf=${procf}quota_slave.force_reint
1102 $LCTL set_param $procf=1 || "force reintegration failed"
1110 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1113 # wait longer than usual to make sure the reintegration
1114 # is triggered by quota wb thread.
1115 wait_ost_reint "ug" 200 || error "reintegration failed"
1117 # hardlimit should have been fetched by slave during global
1118 # reintegration, write will exceed quota
1119 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1120 quota_error u $TSTUSR "write success, but expect EDQUOT"
1123 resetquota -u $TSTUSR
1125 run_test 7c "Quota reintegration (restart mds during reintegration)"
1127 # Quota reintegration (Transfer index in multiple bulks)
1129 local TESTFILE=$DIR/$tdir/$tfile
1130 local TESTFILE1="$DIR/$tdir/$tfile"-1
1134 trap cleanup_quota_test EXIT
1136 set_ost_qtype "none" || error "disable ost quota failed"
1137 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1138 error "set quota for $TSTUSR failed"
1139 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1140 error "set quota for $TSTUSR2 failed"
1142 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1143 lustre_fail mds 0x608 0
1145 # enable quota to tirgger reintegration
1146 set_ost_qtype "u" || error "enable ost quota failed"
1147 wait_ost_reint "u" || error "reintegration failed"
1151 # hardlimit should have been fetched by slave during global
1152 # reintegration, write will exceed quota
1153 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1154 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1156 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1157 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1160 resetquota -u $TSTUSR
1161 resetquota -u $TSTUSR2
1163 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1165 # quota reintegration (inode limits)
1167 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1169 local ilimit=$((1024 * 2)) # 2k inodes
1170 local TESTFILE=$DIR/${tdir}-1/$tfile
1173 trap cleanup_quota_test EXIT
1175 # make sure the system is clean
1176 local USED=$(getquota -u $TSTUSR global curinodes)
1177 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1179 # make sure no granted quota on mdt1
1180 set_mdt_qtype "ug" || error "enable mdt quota failed"
1181 resetquota -u $TSTUSR
1182 set_mdt_qtype "none" || error "disable mdt quota failed"
1184 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1185 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1186 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1189 echo "Stop mds${MDSCOUNT}..."
1192 echo "Enable quota & set quota limit for $TSTUSR"
1193 set_mdt_qtype "ug" || error "enable mdt quota failed"
1194 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1195 error "set quota failed"
1197 echo "Start mds${MDSCOUNT}..."
1198 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1201 wait_mdt_reint "ug" || error "reintegration failed"
1203 echo "create remote dir"
1204 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1205 error "create remote dir failed"
1206 chmod 0777 $DIR/${tdir}-1
1208 # hardlimit should have been fetched by slave during global
1209 # reintegration, create will exceed quota
1210 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1211 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1213 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1214 wait_delete_completed
1215 sync_all_data || true
1217 echo "Stop mds${MDSCOUNT}..."
1220 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1221 error "clear quota failed"
1223 echo "Start mds${MDSCOUNT}..."
1224 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1227 wait_mdt_reint "ug" || error "reintegration failed"
1229 # hardlimit should be cleared on slave during reintegration
1230 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1231 quota_error -u $TSTUSR "create failed, expect success"
1233 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1234 $LFS rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1237 resetquota -u $TSTUSR
1239 run_test 7e "Quota reintegration (inode limits)"
1241 # run dbench with quota enabled
1243 local BLK_LIMIT="100g" #100G
1244 local FILE_LIMIT=1000000
1247 trap cleanup_quota_test EXIT
1249 set_mdt_qtype "ug" || error "enable mdt quota failed"
1250 set_ost_qtype "ug" || error "enable ost quota failed"
1252 echo "Set enough high limit for user: $TSTUSR"
1253 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1254 error "set user quota failed"
1255 echo "Set enough high limit for group: $TSTUSR"
1256 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1257 error "set group quota failed"
1260 [ "$SLOW" = "no" ] && duration=" -t 120"
1261 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1262 quota_error a $TSTUSR "dbench failed!"
1265 resetquota -u $TSTUSR
1266 resetquota -g $TSTUSR
1268 run_test 8 "Run dbench with quota enabled"
1270 # this check is just for test_9
1271 OST0_MIN=4900000 #4.67G
1273 check_whether_skip () {
1274 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1275 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1276 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1277 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1284 # run for fixing bug10707, it needs a big room. test for 64bit
1286 local filesize=$((1024 * 9 / 2)) # 4.5G
1288 check_whether_skip && return 0
1291 trap cleanup_quota_test EXIT
1293 set_ost_qtype "ug" || error "enable ost quota failed"
1295 local TESTFILE="$DIR/$tdir/$tfile-0"
1296 local BLK_LIMIT=100G #100G
1297 local FILE_LIMIT=1000000
1299 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1301 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1303 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1304 error "set user quota failed"
1306 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1307 "for group: $TSTUSR"
1308 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1309 error "set group quota failed"
1311 quota_show_check a u $TSTUSR
1312 quota_show_check a g $TSTUSR
1314 echo "Create test file"
1315 $LFS setstripe $TESTFILE -c 1 -i 0
1316 chown $TSTUSR.$TSTUSR $TESTFILE
1318 log "Write the big file of 4.5G ..."
1319 $RUNAS $DD of=$TESTFILE count=$filesize ||
1320 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1326 resetquota -u $TSTUSR
1327 resetquota -g $TSTUSR
1332 run_test 9 "Block limit larger than 4GB (b10707)"
1335 local TESTFILE=$DIR/$tdir/$tfile
1338 trap cleanup_quota_test EXIT
1340 # set limit to root user should fail
1341 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1342 error "set limit for root user successfully, expect failure"
1343 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1344 error "set limit for root group successfully, expect failure"
1346 # root user can overrun quota
1347 set_ost_qtype "ug" || "enable ost quota failed"
1349 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1350 error "set quota failed"
1351 quota_show_check b u $TSTUSR
1353 $LFS setstripe $TESTFILE -c 1
1354 chown $TSTUSR.$TSTUSR $TESTFILE
1356 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1357 error "write failure, expect success"
1360 resetquota -u $TSTUSR
1362 run_test 10 "Test quota for root user"
1365 local TESTFILE=$DIR/$tdir/$tfile
1367 trap cleanup_quota_test EXIT
1369 set_mdt_qtype "ug" || "enable mdt quota failed"
1370 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1371 error "set quota failed"
1376 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1377 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1380 local USED=$(getquota -u $TSTUSR global curinodes)
1381 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1384 resetquota -u $TSTUSR
1386 run_test 11 "Chown/chgrp ignores quota"
1389 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1391 local blimit=22 # 22M
1392 local blk_cnt=$((blimit - 5))
1393 local TESTFILE0="$DIR/$tdir/$tfile"-0
1394 local TESTFILE1="$DIR/$tdir/$tfile"-1
1397 trap cleanup_quota_test EXIT
1399 set_ost_qtype "u" || "enable ost quota failed"
1400 quota_show_check b u $TSTUSR
1402 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1403 error "set quota failed"
1405 $LFS setstripe $TESTFILE0 -c 1 -i 0
1406 $LFS setstripe $TESTFILE1 -c 1 -i 1
1407 chown $TSTUSR.$TSTUSR $TESTFILE0
1408 chown $TSTUSR.$TSTUSR $TESTFILE1
1410 echo "Write to ost0..."
1411 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1412 quota_error a $TSTUSR "dd failed"
1414 echo "Write to ost1..."
1415 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1416 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1418 echo "Free space from ost0..."
1420 wait_delete_completed
1421 sync_all_data || true
1423 echo "Write to ost1 after space freed from ost0..."
1424 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1425 quota_error a $TSTUSR "rebalancing failed"
1428 resetquota -u $TSTUSR
1430 run_test 12a "Block quota rebalancing"
1433 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1435 local ilimit=$((1024 * 2)) # 2k inodes
1436 local TESTFILE0=$DIR/$tdir/$tfile
1437 local TESTFILE1=$DIR/${tdir}-1/$tfile
1440 trap cleanup_quota_test EXIT
1442 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1443 chmod 0777 $DIR/${tdir}-1
1445 set_mdt_qtype "u" || "enable mdt quota failed"
1446 quota_show_check f u $TSTUSR
1448 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1449 error "set quota failed"
1451 echo "Create $ilimit files on mdt0..."
1452 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1453 quota_error u $TSTUSR "create failed, but expect success"
1455 echo "Create files on mdt1..."
1456 $RUNAS createmany -m $TESTFILE1 1 &&
1457 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1459 echo "Free space from mdt0..."
1460 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1461 wait_delete_completed
1462 sync_all_data || true
1464 echo "Create files on mdt1 after space freed from mdt0..."
1465 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1466 quota_error a $TSTUSR "rebalancing failed"
1468 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1469 error "unlink mdt1 files failed"
1470 $LFS rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1473 resetquota -u $TSTUSR
1475 run_test 12b "Inode quota rebalancing"
1478 local TESTFILE=$DIR/$tdir/$tfile
1479 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1480 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1483 trap cleanup_quota_test EXIT
1485 set_ost_qtype "u" || "enable ost quota failed"
1486 quota_show_check b u $TSTUSR
1488 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1489 error "set quota failed"
1490 $LFS setstripe $TESTFILE -c 1 -i 0
1491 chown $TSTUSR.$TSTUSR $TESTFILE
1493 # clear the locks in cache first
1494 do_facet ost1 $LCTL set_param -n $procf=clear
1495 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1496 [ $nlock -eq 0 ] || error "$nlock cached locks"
1498 # write to acquire the per-ID lock
1499 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1500 quota_error a $TSTUSR "dd failed"
1502 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1503 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1505 # clear quota doesn't trigger per-ID lock cancellation
1506 resetquota -u $TSTUSR
1507 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1508 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1510 # clear the per-ID lock
1511 do_facet ost1 $LCTL set_param -n $procf=clear
1512 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1513 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1515 # spare quota should be released
1516 local OSTUUID=$(ostuuid_from_index 0)
1517 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1518 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1519 [ $limit -le $space ] ||
1520 error "spare quota isn't released, limit:$limit, space:$space"
1524 run_test 13 "Cancel per-ID lock in the LRU list"
1527 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1529 wait_delete_completed
1530 sync_all_data || true
1533 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1534 error "set user quota failed"
1535 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1536 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1537 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1538 resetquota -u $TSTUSR
1541 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1542 error "set group quota failed"
1543 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1544 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1545 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1546 resetquota -g $TSTUSR
1548 run_test 15 "Set over 4T block quota"
1552 local BLKS=1 # 1M less than limit
1553 local TESTFILE=$DIR/$tdir/$tfile
1556 trap cleanup_quota_test EXIT
1558 # make sure the system is clean
1559 local USED=$(getquota -u $TSTUSR global curspace)
1560 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1562 set_ost_qtype "ug" || error "enable ost quota failed"
1563 # make sure no granted quota on ost
1564 resetquota -u $TSTUSR
1565 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1566 error "set quota failed"
1568 quota_show_check b u $TSTUSR
1570 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1571 lustre_fail mds 0xa04 $err_code
1573 # write in background
1574 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1578 # write should be blocked and never finished
1579 if ! ps -p $DDPID > /dev/null 2>&1; then
1581 quota_error u $TSTUSR "write finished incorrectly!"
1589 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1591 if [ $count -gt $timeout ]; then
1592 quota_error u $TSTUSR "dd is not finished!"
1597 sync; sync_all_data || true
1599 USED=$(getquota -u $TSTUSR global curspace)
1600 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1601 "Used space(${USED}K) is less than ${BLKS}M"
1604 resetquota -u $TSTUSR
1607 # DQACQ return recoverable error
1609 echo "DQACQ return -ENOLCK"
1611 test_17sub 37 || error "Handle -ENOLCK failed"
1613 echo "DQACQ return -EAGAIN"
1615 test_17sub 11 || error "Handle -EAGAIN failed"
1617 echo "DQACQ return -ETIMEDOUT"
1618 #define ETIMEDOUT 110
1619 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1621 echo "DQACQ return -ENOTCONN"
1622 #define ENOTCONN 107
1623 test_17sub 107 || error "Handle -ENOTCONN failed"
1626 run_test 17 "DQACQ return recoverable error"
1630 local blimit="200m" # 200M
1631 local TESTFILE="$DIR/$tdir/$tfile"
1634 trap cleanup_quota_test EXIT
1636 set_ost_qtype "u" || error "enable ost quota failed"
1637 log "User quota (limit: $blimit)"
1638 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1639 error "set quota failed"
1640 quota_show_check b u $TSTUSR
1642 $LFS setstripe $TESTFILE -i 0 -c 1
1643 chown $TSTUSR.$TSTUSR $TESTFILE
1645 local timeout=$(sysctl -n lustre.timeout)
1647 if [ $io_type = "directio" ]; then
1648 log "Write 100M (directio) ..."
1649 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1651 log "Write 100M (buffered) ..."
1652 $RUNAS $DD of=$TESTFILE count=100 &
1656 replay_barrier $SINGLEMDS
1657 log "Fail mds for $((2 * timeout)) seconds"
1658 fail $SINGLEMDS $((2 * timeout))
1661 if at_is_enabled; then
1662 timeout=$(at_max_get mds)
1664 timeout=$(lctl get_param -n timeout)
1668 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1669 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1670 log "it took $count second"
1675 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1677 cancel_lru_locks mdc
1678 cancel_lru_locks osc
1681 local testfile_size=$(stat -c %s $TESTFILE)
1682 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1683 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1684 "got ${testfile_size}. Verifying file failed!"
1687 resetquota -u $TSTUSR
1690 # test when mds does failover, the ost still could work well
1691 # this test shouldn't trigger watchdog b=14840
1694 test_18_sub directio
1696 # check if watchdog is triggered
1697 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1698 local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
1699 /Service thread pid/ && /was inactive/ {
1703 }' $TMP/lustre-log-${TESTNAME}.log)
1704 [ -z "$watchdog" ] || error "$watchdog"
1705 rm -f $TMP/lustre-log-${TESTNAME}.log
1707 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1711 local TESTFILE=$DIR/$tdir/$tfile
1714 trap cleanup_quota_test EXIT
1716 set_ost_qtype "ug" || error "enable ost quota failed"
1718 # bind file to a single OST
1719 $LFS setstripe -c 1 $TESTFILE
1720 chown $TSTUSR.$TSTUSR $TESTFILE
1722 echo "Set user quota (limit: "$blimit"M)"
1723 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1724 error "set user quota failed"
1725 quota_show_check b u $TSTUSR
1726 echo "Update quota limits"
1727 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1728 error "set group quota failed"
1729 quota_show_check b u $TSTUSR
1731 # first wirte might be cached
1732 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1733 cancel_lru_locks osc
1735 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1736 quota_error u $TSTUSR "Write success, expect failure"
1740 resetquota -u $TSTUSR
1742 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1744 test_20() { # b15754
1745 local LSTR=(2g 1t 4k 3m) # limits strings
1747 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1749 resetquota -u $TSTUSR
1751 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1752 $MOUNT || error "could not set quota limits"
1753 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1754 --inode-softlimit ${LSTR[2]} \
1755 --inode-hardlimit ${LSTR[3]} \
1756 $MOUNT || error "could not set quota limits"
1758 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1759 error "bsoftlimit was not set properly"
1760 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1761 error "bhardlimit was not set properly"
1762 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1763 error "isoftlimit was not set properly"
1764 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1765 error "ihardlimit was not set properly"
1767 resetquota -u $TSTUSR
1769 run_test 20 "Test if setquota specifiers work properly (b15754)"
1776 local time=$(($(date +%s) + seconds))
1777 while [ $(date +%s) -lt $time ]; do
1778 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1782 # run for fixing bug16053, setquota shouldn't fail when writing and
1783 # deleting are happening
1785 local TESTFILE="$DIR/$tdir/$tfile"
1786 local BLIMIT=10 # 10G
1787 local ILIMIT=1000000
1790 trap cleanup_quota_test EXIT
1792 set_ost_qtype "ug" || error "Enable ost quota failed"
1794 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1795 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1796 error "set user quota failed"
1797 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1798 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1799 error "set group quota failed"
1801 # repeat writing on a 1M file
1802 test_21_sub ${TESTFILE}_1 1 30 &
1804 # repeat writing on a 128M file
1805 test_21_sub ${TESTFILE}_2 128 30 &
1808 local time=$(($(date +%s) + 30))
1810 while [ $(date +%s) -lt $time ]; do
1811 log "Set quota for $i times"
1812 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1813 -I $((ILIMIT + i)) $MOUNT ||
1814 error "Set user quota failed"
1815 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1816 -I $((ILIMIT + i)) $MOUNT ||
1817 error "Set group quota failed"
1824 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1826 if [ $count -gt 60 ]; then
1827 quota_error a $TSTUSR "dd should be finished!"
1831 echo "(dd_pid=$DDPID1, time=$count)successful"
1835 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1837 if [ $count -gt 60 ]; then
1838 quota_error a $TSTUSR "dd should be finished!"
1842 echo "(dd_pid=$DDPID2, time=$count)successful"
1845 resetquota -u $TSTUSR
1846 resetquota -g $TSTUSR
1848 run_test 21 "Setquota while writing & deleting (b16053)"
1850 # enable/disable quota enforcement permanently
1852 echo "Set both mdt & ost quota type as ug"
1853 set_mdt_qtype "ug" || error "enable mdt quota failed"
1854 set_ost_qtype "ug" || error "enable ost quota failed"
1861 echo "Verify if quota is enabled"
1862 local qtype=$(mdt_quota_type)
1863 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1864 qtype=$(ost_quota_type)
1865 [ $qtype != "ug" ] && error "ost quota setting is lost"
1867 echo "Set both mdt & ost quota type as none"
1868 set_mdt_qtype "none" || error "disable mdt quota failed"
1869 set_ost_qtype "none" || error "disable ost quota failed"
1877 echo "Verify if quota is disabled"
1878 qtype=$(mdt_quota_type)
1879 [ $qtype != "none" ] && error "mdt quota setting is lost"
1880 qtype=$(ost_quota_type)
1881 [ $qtype != "none" ] && error "ost quota setting is lost"
1885 run_test 22 "enable/disable quota by 'lctl conf_param'"
1888 local TESTFILE="$DIR/$tdir/$tfile"
1892 trap cleanup_quota_test EXIT
1894 set_ost_qtype "ug" || error "Enable ost quota failed"
1897 log "User quota (limit: $LIMIT MB)"
1898 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1899 error "set quota failed"
1900 quota_show_check b u $TSTUSR
1902 $LFS setstripe $TESTFILE -c 1 -i 0
1903 chown $TSTUSR.$TSTUSR $TESTFILE
1905 log "Step1: trigger EDQUOT with O_DIRECT"
1906 log "Write half of file"
1907 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1908 quota_error u $TSTUSR "(1) Write failure, expect success." \
1910 log "Write out of block quota ..."
1911 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1912 oflag=direct conv=notrunc &&
1913 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1917 log "Step2: rewrite should succeed"
1918 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1919 quota_error u $TSTUSR "(3) Write failure, expect success." \
1925 local OST0_UUID=$(ostuuid_from_index 0)
1926 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1927 [ $OST0_QUOTA_USED -ne 0 ] &&
1928 ($SHOW_QUOTA_USER; \
1929 quota_error u $TSTUSR "quota isn't released")
1931 resetquota -u $TSTUSR
1935 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1936 check_whether_skip && return 0
1937 log "run for 4MB test file"
1940 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1941 check_whether_skip && return 0
1942 log "run for 40MB test file"
1945 run_test 23 "Quota should be honored with directIO (b16125)"
1949 local TESTFILE="$DIR/$tdir/$tfile"
1952 trap cleanup_quota_test EXIT
1954 set_ost_qtype "ug" || error "enable ost quota failed"
1956 # bind file to a single OST
1957 $LFS setstripe -c 1 $TESTFILE
1958 chown $TSTUSR.$TSTUSR $TESTFILE
1960 echo "Set user quota (limit: "$blimit"M)"
1961 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1962 error "set quota failed"
1964 # overrun quota by root user
1965 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1966 error "write failure, expect success"
1967 cancel_lru_locks osc
1968 sync_all_data || true
1970 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1973 resetquota -u $TSTUSR
1975 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1977 test_27a() { # b19612
1978 $LFS quota $TSTUSR $DIR &&
1979 error "lfs succeeded with no type, but should have failed"
1980 $LFS setquota $TSTUSR $DIR &&
1981 error "lfs succeeded with no type, but should have failed"
1984 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1986 test_27b() { # b20200
1987 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1988 error "lfs setquota failed with uid argument"
1989 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1990 error "lfs stequota failed with gid argument"
1991 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1992 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1993 resetquota -u $TSTUSR
1994 resetquota -g $TSTUSR
1997 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2002 local TESTFILE="$DIR/$tdir/$tfile"
2006 trap cleanup_quota_test EXIT
2008 set_ost_qtype "u" || error "enable ost quota failed"
2010 $LFS setstripe $TESTFILE -i 0 -c 1
2011 chown $TSTUSR.$TSTUSR $TESTFILE
2013 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2014 $MAX_IQ_TIME $DIR || error "set grace time failed"
2015 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2016 error "set quota failed"
2017 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2018 cancel_lru_locks osc
2020 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2021 # over-quota flag has not yet settled since we do not trigger async
2022 # events based on grace time period expiration
2024 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2025 cancel_lru_locks osc
2026 # now over-quota flag should be settled and further writes should fail
2028 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2029 error "grace times were reset"
2032 resetquota -u $TSTUSR
2033 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2034 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2036 run_test 30 "Hard limit updates should not reset grace times"
2038 # basic usage tracking for user & group
2040 local INODES=10 # 10 files
2041 local BLK_CNT=2 # of 2M each
2042 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2045 trap cleanup_quota_test EXIT
2047 # make sure the system is clean
2048 local USED=$(getquota -u $TSTID global curspace)
2050 error "Used space ($USED) for user $TSTID isn't 0."
2051 USED=$(getquota -g $TSTID global curspace)
2053 error "Used space ($USED) for group $TSTID isn't 0."
2055 echo "Write files..."
2056 for i in `seq 0 $INODES`; do
2057 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2058 error "write failed"
2059 echo "Iteration $i/$INODES completed"
2061 cancel_lru_locks osc
2062 sync; sync_all_data || true
2064 echo "Verify disk usage after write"
2065 USED=$(getquota -u $TSTID global curspace)
2066 [ $USED -lt $TOTAL_BLKS ] &&
2067 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2068 USED=$(getquota -g $TSTID global curspace)
2069 [ $USED -lt $TOTAL_BLKS ] &&
2070 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2072 echo "Verify inode usage after write"
2073 USED=$(getquota -u $TSTID global curinodes)
2074 [ $USED -lt $INODES ] &&
2075 error "Used inode for user $TSTID is $USED, expected $INODES"
2076 USED=$(getquota -g $TSTID global curinodes)
2077 [ $USED -lt $INODES ] &&
2078 error "Used inode for group $TSTID is $USED, expected $INODES"
2082 echo "Verify disk usage after delete"
2083 USED=$(getquota -u $TSTID global curspace)
2084 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2085 USED=$(getquota -u $TSTID global curinodes)
2086 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2087 USED=$(getquota -g $TSTID global curspace)
2088 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2089 USED=$(getquota -g $TSTID global curinodes)
2090 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2092 run_test 33 "Basic usage tracking for user & group"
2094 # usage transfer test for user & group
2096 local BLK_CNT=2 # 2MB
2099 trap cleanup_quota_test EXIT
2101 # make sure the system is clean
2102 local USED=$(getquota -u $TSTID global curspace)
2103 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2104 USED=$(getquota -g $TSTID global curspace)
2105 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2107 echo "Write file..."
2108 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2109 error "write failed"
2110 cancel_lru_locks osc
2111 sync; sync_all_data || true
2113 echo "chown the file to user $TSTID"
2114 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2116 echo "Wait for setattr on objects finished..."
2117 wait_delete_completed
2119 BLK_CNT=$((BLK_CNT * 1024))
2121 echo "Verify disk usage for user $TSTID"
2122 USED=$(getquota -u $TSTID global curspace)
2123 [ $USED -lt $BLK_CNT ] &&
2124 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2125 USED=$(getquota -u $TSTID global curinodes)
2127 error "Used inodes for user $TSTID is $USED, expected 1"
2129 echo "chgrp the file to group $TSTID"
2130 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2132 echo "Wait for setattr on objects finished..."
2133 wait_delete_completed
2135 echo "Verify disk usage for group $TSTID"
2136 USED=$(getquota -g $TSTID global curspace)
2137 [ $USED -ge $BLK_CNT ] ||
2138 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2139 USED=$(getquota -g $TSTID global curinodes)
2141 error "Used inodes for group $TSTID is $USED, expected 1"
2145 run_test 34 "Usage transfer for user & group"
2147 # usage is still accessible across restart
2149 local BLK_CNT=2 # 2 MB
2152 trap cleanup_quota_test EXIT
2154 echo "Write file..."
2155 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2156 error "write failed"
2157 cancel_lru_locks osc
2158 sync; sync_all_data || true
2160 echo "Save disk usage before restart"
2161 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2162 [ $ORIG_USR_SPACE -eq 0 ] &&
2163 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2164 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2165 [ $ORIG_USR_INODES -eq 0 ] &&
2166 error "Used inodes for user $TSTID is 0, expected 1"
2167 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2168 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2169 [ $ORIG_GRP_SPACE -eq 0 ] &&
2170 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2171 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2172 [ $ORIG_GRP_INODES -eq 0 ] &&
2173 error "Used inodes for group $TSTID is 0, expected 1"
2174 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2177 local ORIG_REFORMAT=$REFORMAT
2179 cleanup_and_setup_lustre
2180 REFORMAT=$ORIG_REFORMAT
2183 echo "Verify disk usage after restart"
2184 local USED=$(getquota -u $TSTID global curspace)
2185 [ $USED -eq $ORIG_USR_SPACE ] ||
2186 error "Used space for user $TSTID changed from " \
2187 "$ORIG_USR_SPACE to $USED"
2188 USED=$(getquota -u $TSTID global curinodes)
2189 [ $USED -eq $ORIG_USR_INODES ] ||
2190 error "Used inodes for user $TSTID changed from " \
2191 "$ORIG_USR_INODES to $USED"
2192 USED=$(getquota -g $TSTID global curspace)
2193 [ $USED -eq $ORIG_GRP_SPACE ] ||
2194 error "Used space for group $TSTID changed from " \
2195 "$ORIG_GRP_SPACE to $USED"
2196 USED=$(getquota -g $TSTID global curinodes)
2197 [ $USED -eq $ORIG_GRP_INODES ] ||
2198 error "Used inodes for group $TSTID changed from " \
2199 "$ORIG_GRP_INODES to $USED"
2201 # check if the vfs_dq_init() is called before writing
2202 echo "Append to the same file..."
2203 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2204 error "write failed"
2205 cancel_lru_locks osc
2206 sync; sync_all_data || true
2208 echo "Verify space usage is increased"
2209 USED=$(getquota -u $TSTID global curspace)
2210 [ $USED -gt $ORIG_USR_SPACE ] ||
2211 error "Used space for user $TSTID isn't increased" \
2212 "orig:$ORIG_USR_SPACE, now:$USED"
2213 USED=$(getquota -g $TSTID global curspace)
2214 [ $USED -gt $ORIG_GRP_SPACE ] ||
2215 error "Used space for group $TSTID isn't increased" \
2216 "orig:$ORIG_GRP_SPACE, now:$USED"
2220 run_test 35 "Usage is still accessible across reboot"
2222 # test migrating old amdin quota files (in Linux quota file format v2) into new
2223 # quota global index (in IAM format)
2225 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2226 skip "skipping migration test" && return
2228 # get the mdt0 device name
2229 local mdt0_node=$(facet_active_host $SINGLEMDS)
2230 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2235 echo "Copy admin quota files into MDT0..."
2236 local mntpt=$(facet_mntpt $SINGLEMDS)
2237 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2239 if ! do_node $mdt0_node test -b $mdt0_fstype; then
2242 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2243 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2244 do_node $mdt0_node mkdir $mntpt/OBJECTS
2245 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2246 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2247 do_node $mdt0_node umount -f $mntpt
2252 echo "Verify global limits..."
2256 local proc="qmt.*.md-0x0.glb-usr"
2257 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2258 [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2259 limit=$(getquota -u 1 global isoftlimit)
2260 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2261 limit=$(getquota -u 1 global ihardlimit)
2262 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2264 proc="qmt.*.md-0x0.glb-grp"
2265 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2266 [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2267 limit=$(getquota -g 1 global isoftlimit)
2268 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2269 limit=$(getquota -g 1 global ihardlimit)
2270 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2272 proc=" qmt.*.dt-0x0.glb-usr"
2273 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2274 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2275 limit=$(getquota -u 60001 global bsoftlimit)
2276 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2277 limit=$(getquota -u 60001 global bhardlimit)
2278 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2280 proc="qmt.*.dt-0x0.glb-grp"
2281 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2282 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2283 limit=$(getquota -g 60001 global bsoftlimit)
2284 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2285 limit=$(getquota -g 60001 global bhardlimit)
2286 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2292 run_test 36 "Migrate old admin files into new global indexes"
2296 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2302 check_and_cleanup_lustre
2303 export QUOTA_AUTO=$QUOTA_AUTO_OLD