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 # Does e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip "e2fsprogs doesn't support quota" && exit 0
53 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
54 # bug number for skipped test: LU-2872 LU-2836 LU-2836 LU-2059
55 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 1 3 6 7d"
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
75 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
80 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
81 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
82 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
83 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
84 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
91 local fail_val=${3:-0}
93 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
94 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
95 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
98 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
99 for num in `seq $OSTCOUNT`; do
100 do_facet ost$num "lctl set_param fail_val=$fail_val"
101 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
106 RUNAS="runas -u $TSTID -g $TSTID"
107 RUNAS2="runas -u $TSTID2 -g $TSTID2"
108 DD="dd if=/dev/zero bs=1M"
112 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
113 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
114 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
115 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
117 # clear quota limits for a user or a group
118 # usage: resetquota -u username
119 # resetquota -g groupname
122 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
123 [ "$1" != "-u" -a "$1" != "-g" ] &&
124 error "resetquota: wrong specifier $1 passed"
126 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
127 error "clear quota for [type:$1 name:$2] failed"
128 # give a chance to slave to release space
136 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
137 $LFS quota -v -u $LOCAL_ID $DIR
138 log "Files for user ($LOCAL_ID):"
139 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
140 xargs stat 2>/dev/null)
143 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
144 $LFS quota -v -u $LOCAL_ID $DIR
145 log "Files for group ($LOCAL_ID):"
146 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
147 xargs stat 2>/dev/null)
163 # get quota for a user or a group
164 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
165 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
171 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
172 [ "$1" != "-u" -a "$1" != "-g" ] &&
173 error "getquota: wrong u/g specifier $1 passed"
186 *) error "unknown quota parameter $4";;
189 [ "$uuid" = "global" ] && uuid=$DIR
191 $LFS quota -v "$1" "$2" $DIR |
192 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
193 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
198 # usage: set_mdt_qtype ug|u|g|none
202 local mdts=$(get_facets MDS)
204 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
205 # we have to make sure each MDT received config changes
206 for mdt in ${mdts//,/ }; do
208 cmd="$LCTL get_param -n "
209 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
210 cmd=${cmd}.quota_slave.enabled
212 if $(facet_up $mdt); then
213 wait_update_facet $mdt "$cmd" "$qtype" || return 1
220 # usage: set_ost_qtype ug|u|g|none
224 local osts=$(get_facets OST)
226 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
227 # we have to make sure each OST received config changes
228 for ost in ${osts//,/ }; do
230 cmd="$LCTL get_param -n "
231 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
232 cmd=${cmd}.quota_slave.enabled
234 if $(facet_up $ost); then
235 wait_update_facet $ost "$cmd" "$qtype" || return 1
241 wait_reintegration() {
245 local result="glb[1],slv[1],reint[0]"
250 if [ $ntype == "mdt" ]; then
251 tgts=$(get_facets MDS)
253 tgts=$(get_facets OST)
256 for tgt in ${tgts//,/ }; do
258 cmd="$LCTL get_param -n "
259 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
260 cmd=${cmd}.quota_slave.info
262 if $(facet_up $tgt); then
263 wait_update_facet $tgt "$cmd |
264 grep "$qtype" | awk '{ print \\\$3 }'" \
265 "$result" $max || return 1
275 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
276 wait_reintegration "mdt" "user" $max || return 1
279 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
280 wait_reintegration "mdt" "group" $max || return 1
289 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
290 wait_reintegration "ost" "user" $max || return 1
293 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
294 wait_reintegration "ost" "group" $max || return 1
301 wait_delete_completed
302 echo "Creating test directory"
304 chmod 0777 $DIR/$tdir
305 # always clear fail_loc in case of fail_loc isn't cleared
306 # properly when previous test failed
307 lustre_fail mds_ost 0
310 cleanup_quota_test() {
312 echo "Delete files..."
314 echo "Wait for unlink objects finished..."
315 wait_delete_completed
316 sync_all_data || true
325 $LFS quota -v -$ug $qid $DIR
327 if [ "$bf" == "a" -o "$bf" == "b" ]; then
328 usage=$(getquota -$ug $qid global curspace)
329 if [ -z $usage ]; then
330 quota_error $ug $qid \
331 "Query block quota failed ($ug:$qid)."
333 [ $usage -ne 0 ] && quota_log $ug $qid \
334 "Block quota isn't 0 ($ug:$qid:$usage)."
338 if [ "$bf" == "a" -o "$bf" == "f" ]; then
339 usage=$(getquota -$ug $qid global curinodes)
340 if [ -z $usage ]; then
341 quota_error $ug $qid \
342 "Query file quota failed ($ug:$qid)."
344 [ $usage -ne 0 ] && quota_log $ug $qid \
345 "File quota isn't 0 ($ug:$qid:$usage)."
352 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
356 resetquota -u $TSTUSR
357 resetquota -g $TSTUSR
358 resetquota -u $TSTUSR2
359 resetquota -g $TSTUSR2
361 test_quota_performance() {
362 local TESTFILE="$DIR/$tdir/$tfile-0"
363 local size=$1 # in MB
364 local stime=$(date +%s)
365 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
366 quota_error u $TSTUSR "write failure"
367 local etime=$(date +%s)
368 delta=$((etime - stime))
369 if [ $delta -gt 0 ]; then
370 rate=$((size * 1024 / delta))
371 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
372 # LU-2872 - see LU-2887 for fix
374 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
376 [ $rate -gt 1024 ] ||
377 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
383 # test basic quota performance b=21696
386 [ "$SLOW" = "no" ] && MB=10
388 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
389 [ $free_space -le $((MB * 1024)) ] &&
390 skip "not enough space ${free_space} KB, " \
391 "required $((MB * 1024)) KB" && return
393 trap cleanup_quota_test EXIT
395 set_ost_qtype "none" || error "disable ost quota failed"
396 test_quota_performance $MB
398 set_ost_qtype "ug" || error "enable ost quota failed"
399 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
400 error "set quota failed"
401 test_quota_performance $MB
404 resetquota -u $TSTUSR
406 run_test 0 "Test basic quota performance"
408 # test block hardlimit
411 local TESTFILE="$DIR/$tdir/$tfile-0"
414 trap cleanup_quota_test EXIT
417 set_ost_qtype "ug" || "enable ost quota failed"
420 log "User quota (block hardlimit:$LIMIT MB)"
421 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
422 error "set user quota failed"
424 # make sure the system is clean
425 local USED=$(getquota -u $TSTUSR global curspace)
426 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
428 $LFS setstripe $TESTFILE -c 1
429 chown $TSTUSR.$TSTUSR $TESTFILE
432 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
433 quota_error u $TSTUSR "user write failure, but expect success"
434 log "Write out of block quota ..."
435 # this time maybe cache write, ignore it's failure
436 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
437 # flush cache, ensure noquota flag is set on client
439 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
440 quota_error u $TSTUSR "user write success, but expect EDQUOT"
443 wait_delete_completed
444 sync_all_data || true
445 USED=$(getquota -u $TSTUSR global curspace)
446 [ $USED -ne 0 ] && quota_error u $TSTUSR \
447 "user quota isn't released after deletion"
448 resetquota -u $TSTUSR
451 log "--------------------------------------"
452 log "Group quota (block hardlimit:$LIMIT MB)"
453 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
454 error "set group quota failed"
456 TESTFILE="$DIR/$tdir/$tfile-1"
457 # make sure the system is clean
458 USED=$(getquota -g $TSTUSR global curspace)
459 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
461 $LFS setstripe $TESTFILE -c 1
462 chown $TSTUSR.$TSTUSR $TESTFILE
465 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
466 quota_error g $TSTUSR "group write failure, but expect success"
467 log "Write out of block quota ..."
468 # this time maybe cache write, ignore it's failure
469 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
471 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
472 quota_error g $TSTUSR "group write success, but expect EDQUOT"
477 USED=$(getquota -g $TSTUSR global curspace)
478 [ $USED -ne 0 ] && quota_error g $TSTUSR \
479 "group quota isn't released after deletion"
481 resetquota -g $TSTUSR
483 run_test 1 "Block hard limit (normal use and out of quota)"
485 # test inode hardlimit
487 local LIMIT=$((1024 * 1024)) # 1M inodes
488 local TESTFILE="$DIR/$tdir/$tfile-0"
490 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
492 local FREE_INODES=$(mdt_free_inodes 0)
493 echo "$FREE_INODES free inodes on master MDT"
494 [ $FREE_INODES -lt $LIMIT ] &&
495 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
499 trap cleanup_quota_test EXIT
502 set_mdt_qtype "ug" || "enable mdt quota failed"
505 log "User quota (inode hardlimit:$LIMIT files)"
506 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
507 error "set user quota failed"
509 # make sure the system is clean
510 local USED=$(getquota -u $TSTUSR global curinodes)
511 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
513 log "Create $LIMIT files ..."
514 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
515 quota_error u $TSTUSR "user create failure, but expect success"
516 log "Create out of file quota ..."
517 $RUNAS touch ${TESTFILE}_xxx && \
518 quota_error u $TSTUSR "user create success, but expect EDQUOT"
521 unlinkmany ${TESTFILE} $LIMIT
522 rm -f ${TESTFILE}_xxx
523 wait_delete_completed
525 USED=$(getquota -u $TSTUSR global curinodes)
526 [ $USED -ne 0 ] && quota_error u $TSTUSR \
527 "user quota isn't released after deletion"
528 resetquota -u $TSTUSR
531 log "--------------------------------------"
532 log "Group quota (inode hardlimit:$LIMIT files)"
533 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
534 error "set group quota failed"
536 TESTFILE=$DIR/$tdir/$tfile-1
537 # make sure the system is clean
538 USED=$(getquota -g $TSTUSR global curinodes)
539 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
541 log "Create $LIMIT files ..."
542 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
543 quota_error g $TSTUSR "group create failure, but expect success"
544 log "Create out of file quota ..."
545 $RUNAS touch ${TESTFILE}_xxx && \
546 quota_error g $TSTUSR "group create success, but expect EDQUOT"
549 unlinkmany ${TESTFILE} $LIMIT
550 rm -f ${TESTFILE}_xxx
551 wait_delete_completed
553 USED=$(getquota -g $TSTUSR global curinodes)
554 [ $USED -ne 0 ] && quota_error g $TSTUSR \
555 "user quota isn't released after deletion"
558 resetquota -g $TSTUSR
560 run_test 2 "File hard limit (normal use and out of quota)"
564 local TIMER=$(($2 * 3 / 2))
569 trap cleanup_quota_test EXIT
571 $LFS setstripe $TESTFILE -c 1 -i 0
572 chown $TSTUSR.$TSTUSR $TESTFILE
574 echo "Write up to soft limit"
575 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
576 quota_error a $TSTUSR "write failure, but expect success"
577 OFFSET=$((LIMIT * 1024))
580 echo "Write to exceed soft limit"
581 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
582 quota_error a $TSTUSR "write failure, but expect success"
583 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
588 $SHOW_QUOTA_INFO_USER
589 $SHOW_QUOTA_INFO_GROUP
591 echo "Write before timer goes off"
592 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
593 quota_error a $TSTUSR "write failure, but expect success"
594 OFFSET=$((OFFSET + 1024))
597 echo "Sleep $TIMER seconds ..."
602 $SHOW_QUOTA_INFO_USER
603 $SHOW_QUOTA_INFO_GROUP
605 echo "Write after timer goes off"
606 # maybe cache write, ignore.
607 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
608 OFFSET=$((OFFSET + 1024))
610 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
611 quota_error a $TSTUSR "write success, but expect EDQUOT"
615 $SHOW_QUOTA_INFO_USER
616 $SHOW_QUOTA_INFO_GROUP
618 echo "Unlink file to stop timer"
620 wait_delete_completed
621 sync_all_data || true
625 $SHOW_QUOTA_INFO_USER
626 $SHOW_QUOTA_INFO_GROUP
628 $LFS setstripe $TESTFILE -c 1 -i 0
629 chown $TSTUSR.$TSTUSR $TESTFILE
632 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
633 quota_error a $TSTUSR "write failure, but expect success"
642 local TESTFILE=$DIR/$tdir/$tfile-0
644 set_ost_qtype "ug" || error "enable ost quota failed"
646 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
647 # make sure the system is clean
648 local USED=$(getquota -u $TSTUSR global curspace)
649 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
651 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
652 $MAX_IQ_TIME $DIR || error "set user grace time failed"
653 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
654 error "set user quota failed"
656 test_block_soft $TESTFILE $GRACE $LIMIT
657 resetquota -u $TSTUSR
659 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
660 TESTFILE=$DIR/$tdir/$tfile-1
661 # make sure the system is clean
662 USED=$(getquota -g $TSTUSR global curspace)
663 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
665 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
666 $MAX_IQ_TIME $DIR || error "set group grace time failed"
667 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
668 error "set group quota failed"
670 test_block_soft $TESTFILE $GRACE $LIMIT
671 resetquota -g $TSTUSR
674 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
675 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
676 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
677 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
679 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
684 local TIMER=$(($3 * 3 / 2))
687 trap cleanup_quota_test EXIT
689 echo "Create files to exceed soft limit"
690 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
691 quota_error a $TSTUSR "create failure, but expect success"
694 echo "Create file before timer goes off"
695 $RUNAS touch ${TESTFILE}_before ||
696 quota_error a $TSTUSR "failed create before timer expired," \
700 echo "Sleep $TIMER seconds ..."
705 $SHOW_QUOTA_INFO_USER
706 $SHOW_QUOTA_INFO_GROUP
708 echo "Create file after timer goes off"
709 # There is a window that space is accounted in the quota usage but
710 # hasn't been decreased from the pending write, if we acquire quota
711 # in this window, we'll acquire more than we needed.
712 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
714 $RUNAS touch ${TESTFILE}_after_3 &&
715 quota_error a $TSTUSR "create after timer expired," \
721 $SHOW_QUOTA_INFO_USER
722 $SHOW_QUOTA_INFO_GROUP
724 echo "Unlink files to stop timer"
725 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
726 wait_delete_completed
729 $RUNAS touch ${TESTFILE}_xxx ||
730 quota_error a $TSTUSR "touch after timer stop failure," \
740 local LIMIT=10 # inodes
741 local TESTFILE=$DIR/$tdir/$tfile-0
744 set_mdt_qtype "ug" || error "enable mdt quota failed"
746 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
747 # make sure the system is clean
748 local USED=$(getquota -u $TSTUSR global curinodes)
749 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
751 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
752 $GRACE $DIR || error "set user grace time failed"
753 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
754 error "set user quota failed"
756 test_file_soft $TESTFILE $LIMIT $GRACE
757 resetquota -u $TSTUSR
759 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
760 # make sure the system is clean
761 USED=$(getquota -g $TSTUSR global curinodes)
762 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
764 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
765 $GRACE $DIR || error "set group grace time failed"
766 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
767 error "set group quota failed"
768 TESTFILE=$DIR/$tdir/$tfile-1
770 test_file_soft $TESTFILE $LIMIT $GRACE
771 resetquota -g $TSTUSR
774 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
775 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
776 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
777 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
779 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
783 local GR_STR2="1000s"
785 local GR_STR4="1w2d3h4m5s"
787 local GR_STR6="1111111111111111"
789 wait_delete_completed
791 # test of valid grace strings handling
792 echo "Valid grace strings test"
793 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
794 $GR_STR2 $DIR || error "set user grace time failed"
795 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
796 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
797 $GR_STR4 $DIR || error "set group grace time quota failed"
798 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
800 # test of invalid grace strings handling
801 echo " Invalid grace strings test"
802 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
803 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
806 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
807 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
808 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
809 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
811 run_test 4b "Grace time strings handling"
813 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
815 local BLIMIT=10 # 10M
816 local ILIMIT=10 # 10 inodes
819 trap cleanup_quota_test EXIT
821 set_mdt_qtype "ug" || error "enable mdt quota failed"
822 set_ost_qtype "ug" || error "enable ost quota failed"
824 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
825 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
826 error "set user quota failed"
827 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
828 error "set group quota failed"
830 # make sure the system is clean
831 local USED=$(getquota -u $TSTUSR global curinodes)
832 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
833 USED=$(getquota -g $TSTUSR global curinodes)
834 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
835 USED=$(getquota -u $TSTUSR global curspace)
836 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
837 USED=$(getquota -g $TSTUSR global curspace)
838 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
840 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
841 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
842 error "create failure, expect success"
843 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
844 error "write failure, expect success"
846 echo "Chown files to $TSTUSR.$TSTUSR ..."
847 for i in `seq 0 $ILIMIT`; do
848 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
849 quota_error a $TSTUSR "chown failure, expect success"
853 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
856 resetquota -u $TSTUSR
857 resetquota -g $TSTUSR
859 run_test 5 "Chown & chgrp successfully even out of block/file quota"
861 # test dropping acquire request on master
865 # Clear dmesg so watchdog is not triggered by previous
867 do_facet ost1 dmesg -c > /dev/null
870 trap cleanup_quota_test EXIT
872 # make sure the system is clean
873 local USED=$(getquota -u $TSTUSR global curspace)
874 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
876 # make sure no granted quota on ost
877 set_ost_qtype "ug" || error "enable ost quota failed"
878 resetquota -u $TSTUSR
880 # create file for $TSTUSR
881 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
882 $LFS setstripe $TESTFILE -c 1 -i 0
883 chown $TSTUSR.$TSTUSR $TESTFILE
885 # create file for $TSTUSR2
886 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
887 $LFS setstripe $TESTFILE2 -c 1 -i 0
888 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
890 # cache per-ID lock for $TSTUSR on slave
891 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
892 error "set quota failed"
893 $RUNAS $DD of=$TESTFILE count=1 ||
894 error "write $TESTFILE failure, expect success"
895 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
896 error "write $TESTFILE2 failure, expect success"
898 sync_all_data || true
900 #define QUOTA_DQACQ 601
901 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
902 lustre_fail mds 0x513 601
904 # write to un-enforced ID ($TSTUSR2) should succeed
905 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
906 error "write failure, expect success"
908 # write to enforced ID ($TSTUSR) in background, exceeding limit
909 # to make sure DQACQ is sent
910 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
913 # watchdog timer uses a factor of 2
914 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
915 sleep $((TIMEOUT * 2 + 1))
917 # write should be blocked and never finished
918 if ! ps -p $DDPID > /dev/null 2>&1; then
920 error "write finished incorrectly!"
925 # no watchdog is triggered
926 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
927 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
928 { print; }' $TMP/lustre-log-${TESTNAME}.log)
929 [ -z "$watchdog" ] || error "$watchdog"
931 rm -f $TMP/lustre-log-${TESTNAME}.log
933 # write should continue & succeed
935 local o_size=$(stat -c %s $TESTFILE)
938 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
939 if [ $count -ge 240 ]; then
940 quota_error u $TSTUSR "dd not finished in $count secs"
943 if [ $((count % 30)) -eq 0 ]; then
944 c_size=$(stat -c %s $TESTFILE)
945 if [ $c_size -eq $o_size ]; then
946 quota_error u $TSTUSR "file not growed" \
947 "in 30 seconds $o_size/$c_size"
949 echo "Waiting $count secs. $o_size/$c_size"
957 resetquota -u $TSTUSR
959 run_test 6 "Test dropping acquire request on master"
961 # quota reintegration (global index)
963 local TESTFILE=$DIR/$tdir/$tfile
966 [ "$SLOW" = "no" ] && LIMIT=5
969 trap cleanup_quota_test EXIT
971 # make sure the system is clean
972 local USED=$(getquota -u $TSTUSR global curspace)
973 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
975 # make sure no granted quota on ost1
976 set_ost_qtype "ug" || error "enable ost quota failed"
977 resetquota -u $TSTUSR
978 set_ost_qtype "none" || error "disable ost quota failed"
980 local OSTUUID=$(ostuuid_from_index 0)
981 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
982 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
986 $LFS setstripe $TESTFILE -c 1 -i 0
987 chown $TSTUSR.$TSTUSR $TESTFILE
992 echo "Enable quota & set quota limit for $TSTUSR"
993 set_ost_qtype "ug" || error "enable ost quota failed"
994 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
995 error "set quota failed"
998 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1001 wait_ost_reint "ug" || error "reintegration failed"
1003 # hardlimit should have been fetched by slave during global
1004 # reintegration, write will exceed quota
1005 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1006 quota_error u $TSTUSR "write success, but expect EDQUOT"
1009 wait_delete_completed
1010 sync_all_data || true
1016 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1017 error "clear quota failed"
1019 echo "Start ost1..."
1020 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1023 wait_ost_reint "ug" || error "reintegration failed"
1025 # hardlimit should be cleared on slave during reintegration
1026 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1027 quota_error u $TSTUSR "write error, but expect success"
1030 resetquota -u $TSTUSR
1032 run_test 7a "Quota reintegration (global index)"
1034 # quota reintegration (slave index)
1037 local TESTFILE=$DIR/$tdir/$tfile
1040 trap cleanup_quota_test EXIT
1042 # make sure the system is clean
1043 local USED=$(getquota -u $TSTUSR global curspace)
1044 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1046 # make sure no granted quota on ost1
1047 set_ost_qtype "ug" || error "enable ost quota failed"
1048 resetquota -u $TSTUSR
1049 set_ost_qtype "none" || error "disable ost quota failed"
1051 local OSTUUID=$(ostuuid_from_index 0)
1052 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1053 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1057 $LFS setstripe $TESTFILE -c 1 -i 0
1058 chown $TSTUSR.$TSTUSR $TESTFILE
1060 # consume some space to make sure the granted space will not
1061 # be released during reconciliation
1062 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1063 error "consume space failure, expect success"
1065 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1066 lustre_fail mds 0xa02
1068 set_ost_qtype "ug" || error "enable ost quota failed"
1069 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1070 error "set quota failed"
1072 # ignore the write error
1073 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1075 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1079 echo "Restart ost to trigger reintegration..."
1081 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1084 wait_ost_reint "ug" || error "reintegration failed"
1086 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1087 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1090 resetquota -u $TSTUSR
1093 run_test 7b "Quota reintegration (slave index)"
1095 # quota reintegration (restart mds during reintegration)
1097 local LIMIT=20 # 20M
1098 local TESTFILE=$DIR/$tdir/$tfile
1100 [ "$SLOW" = "no" ] && LIMIT=5
1103 trap cleanup_quota_test EXIT
1105 # make sure the system is clean
1106 local USED=$(getquota -u $TSTUSR global curspace)
1107 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1109 set_ost_qtype "none" || error "disable ost quota failed"
1110 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1111 error "set quota failed"
1113 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1114 lustre_fail ost 0xa03
1117 set_ost_qtype "ug" || error "enable ost quota failed"
1118 # trigger reintegration
1119 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1120 procf=${procf}quota_slave.force_reint
1121 do_facet ost1 $LCTL set_param $procf=1 ||
1122 error "force reintegration failed"
1130 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1133 # wait longer than usual to make sure the reintegration
1134 # is triggered by quota wb thread.
1135 wait_ost_reint "ug" 200 || error "reintegration failed"
1137 # hardlimit should have been fetched by slave during global
1138 # reintegration, write will exceed quota
1139 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1140 quota_error u $TSTUSR "write success, but expect EDQUOT"
1143 resetquota -u $TSTUSR
1145 run_test 7c "Quota reintegration (restart mds during reintegration)"
1147 # Quota reintegration (Transfer index in multiple bulks)
1149 local TESTFILE=$DIR/$tdir/$tfile
1150 local TESTFILE1="$DIR/$tdir/$tfile"-1
1154 trap cleanup_quota_test EXIT
1156 set_ost_qtype "none" || error "disable ost quota failed"
1157 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1158 error "set quota for $TSTUSR failed"
1159 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1160 error "set quota for $TSTUSR2 failed"
1162 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1163 lustre_fail mds 0x608 0
1165 # enable quota to tirgger reintegration
1166 set_ost_qtype "u" || error "enable ost quota failed"
1167 wait_ost_reint "u" || error "reintegration failed"
1171 # hardlimit should have been fetched by slave during global
1172 # reintegration, write will exceed quota
1173 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1174 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1176 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1177 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1180 resetquota -u $TSTUSR
1181 resetquota -u $TSTUSR2
1183 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1185 # quota reintegration (inode limits)
1187 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1189 local ilimit=$((1024 * 2)) # 2k inodes
1190 local TESTFILE=$DIR/${tdir}-1/$tfile
1193 trap cleanup_quota_test EXIT
1195 # make sure the system is clean
1196 local USED=$(getquota -u $TSTUSR global curinodes)
1197 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1199 # make sure no granted quota on mdt1
1200 set_mdt_qtype "ug" || error "enable mdt quota failed"
1201 resetquota -u $TSTUSR
1202 set_mdt_qtype "none" || error "disable mdt quota failed"
1204 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1205 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1206 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1209 echo "Stop mds${MDSCOUNT}..."
1212 echo "Enable quota & set quota limit for $TSTUSR"
1213 set_mdt_qtype "ug" || error "enable mdt quota failed"
1214 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1215 error "set quota failed"
1217 echo "Start mds${MDSCOUNT}..."
1218 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1221 wait_mdt_reint "ug" || error "reintegration failed"
1223 echo "create remote dir"
1224 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1225 error "create remote dir failed"
1226 chmod 0777 $DIR/${tdir}-1
1228 # hardlimit should have been fetched by slave during global
1229 # reintegration, create will exceed quota
1230 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1231 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1233 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1234 wait_delete_completed
1235 sync_all_data || true
1237 echo "Stop mds${MDSCOUNT}..."
1240 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1241 error "clear quota failed"
1243 echo "Start mds${MDSCOUNT}..."
1244 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1247 wait_mdt_reint "ug" || error "reintegration failed"
1249 # hardlimit should be cleared on slave during reintegration
1250 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1251 quota_error -u $TSTUSR "create failed, expect success"
1253 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1254 rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1257 resetquota -u $TSTUSR
1259 run_test 7e "Quota reintegration (inode limits)"
1261 # run dbench with quota enabled
1263 local BLK_LIMIT="100g" #100G
1264 local FILE_LIMIT=1000000
1267 trap cleanup_quota_test EXIT
1269 set_mdt_qtype "ug" || error "enable mdt quota failed"
1270 set_ost_qtype "ug" || error "enable ost quota failed"
1272 echo "Set enough high limit for user: $TSTUSR"
1273 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1274 error "set user quota failed"
1275 echo "Set enough high limit for group: $TSTUSR"
1276 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1277 error "set group quota failed"
1280 [ "$SLOW" = "no" ] && duration=" -t 120"
1281 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1282 quota_error a $TSTUSR "dbench failed!"
1285 resetquota -u $TSTUSR
1286 resetquota -g $TSTUSR
1288 run_test 8 "Run dbench with quota enabled"
1290 # this check is just for test_9
1291 OST0_MIN=4900000 #4.67G
1293 check_whether_skip () {
1294 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1295 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1296 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1297 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1304 # run for fixing bug10707, it needs a big room. test for 64bit
1306 local filesize=$((1024 * 9 / 2)) # 4.5G
1308 check_whether_skip && return 0
1311 trap cleanup_quota_test EXIT
1313 set_ost_qtype "ug" || error "enable ost quota failed"
1315 local TESTFILE="$DIR/$tdir/$tfile-0"
1316 local BLK_LIMIT=100G #100G
1317 local FILE_LIMIT=1000000
1319 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1321 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1323 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1324 error "set user quota failed"
1326 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1327 "for group: $TSTUSR"
1328 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1329 error "set group quota failed"
1331 quota_show_check a u $TSTUSR
1332 quota_show_check a g $TSTUSR
1334 echo "Create test file"
1335 $LFS setstripe $TESTFILE -c 1 -i 0
1336 chown $TSTUSR.$TSTUSR $TESTFILE
1338 log "Write the big file of 4.5G ..."
1339 $RUNAS $DD of=$TESTFILE count=$filesize ||
1340 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1346 resetquota -u $TSTUSR
1347 resetquota -g $TSTUSR
1352 run_test 9 "Block limit larger than 4GB (b10707)"
1355 local TESTFILE=$DIR/$tdir/$tfile
1358 trap cleanup_quota_test EXIT
1360 # set limit to root user should fail
1361 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1362 error "set limit for root user successfully, expect failure"
1363 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1364 error "set limit for root group successfully, expect failure"
1366 # root user can overrun quota
1367 set_ost_qtype "ug" || "enable ost quota failed"
1369 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1370 error "set quota failed"
1371 quota_show_check b u $TSTUSR
1373 $LFS setstripe $TESTFILE -c 1
1374 chown $TSTUSR.$TSTUSR $TESTFILE
1376 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1377 error "write failure, expect success"
1380 resetquota -u $TSTUSR
1382 run_test 10 "Test quota for root user"
1385 local TESTFILE=$DIR/$tdir/$tfile
1387 trap cleanup_quota_test EXIT
1389 set_mdt_qtype "ug" || "enable mdt quota failed"
1390 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1391 error "set quota failed"
1396 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1397 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1400 local USED=$(getquota -u $TSTUSR global curinodes)
1401 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1404 resetquota -u $TSTUSR
1406 run_test 11 "Chown/chgrp ignores quota"
1409 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1411 local blimit=22 # 22M
1412 local blk_cnt=$((blimit - 5))
1413 local TESTFILE0="$DIR/$tdir/$tfile"-0
1414 local TESTFILE1="$DIR/$tdir/$tfile"-1
1417 trap cleanup_quota_test EXIT
1419 set_ost_qtype "u" || "enable ost quota failed"
1420 quota_show_check b u $TSTUSR
1422 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1423 error "set quota failed"
1425 $LFS setstripe $TESTFILE0 -c 1 -i 0
1426 $LFS setstripe $TESTFILE1 -c 1 -i 1
1427 chown $TSTUSR.$TSTUSR $TESTFILE0
1428 chown $TSTUSR.$TSTUSR $TESTFILE1
1430 echo "Write to ost0..."
1431 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1432 quota_error a $TSTUSR "dd failed"
1434 echo "Write to ost1..."
1435 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1436 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1438 echo "Free space from ost0..."
1440 wait_delete_completed
1441 sync_all_data || true
1443 echo "Write to ost1 after space freed from ost0..."
1444 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1445 quota_error a $TSTUSR "rebalancing failed"
1448 resetquota -u $TSTUSR
1450 run_test 12a "Block quota rebalancing"
1453 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1455 local ilimit=$((1024 * 2)) # 2k inodes
1456 local TESTFILE0=$DIR/$tdir/$tfile
1457 local TESTFILE1=$DIR/${tdir}-1/$tfile
1460 trap cleanup_quota_test EXIT
1462 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1463 chmod 0777 $DIR/${tdir}-1
1465 set_mdt_qtype "u" || "enable mdt quota failed"
1466 quota_show_check f u $TSTUSR
1468 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1469 error "set quota failed"
1471 echo "Create $ilimit files on mdt0..."
1472 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1473 quota_error u $TSTUSR "create failed, but expect success"
1475 echo "Create files on mdt1..."
1476 $RUNAS createmany -m $TESTFILE1 1 &&
1477 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1479 echo "Free space from mdt0..."
1480 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1481 wait_delete_completed
1482 sync_all_data || true
1484 echo "Create files on mdt1 after space freed from mdt0..."
1485 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1486 quota_error a $TSTUSR "rebalancing failed"
1488 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1489 error "unlink mdt1 files failed"
1490 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1493 resetquota -u $TSTUSR
1495 run_test 12b "Inode quota rebalancing"
1498 local TESTFILE=$DIR/$tdir/$tfile
1499 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1500 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1503 trap cleanup_quota_test EXIT
1505 set_ost_qtype "u" || "enable ost quota failed"
1506 quota_show_check b u $TSTUSR
1508 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1509 error "set quota failed"
1510 $LFS setstripe $TESTFILE -c 1 -i 0
1511 chown $TSTUSR.$TSTUSR $TESTFILE
1513 # clear the locks in cache first
1514 do_facet ost1 $LCTL set_param -n $procf=clear
1515 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1516 [ $nlock -eq 0 ] || error "$nlock cached locks"
1518 # write to acquire the per-ID lock
1519 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1520 quota_error a $TSTUSR "dd failed"
1522 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1523 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1525 # clear quota doesn't trigger per-ID lock cancellation
1526 resetquota -u $TSTUSR
1527 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1528 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1530 # clear the per-ID lock
1531 do_facet ost1 $LCTL set_param -n $procf=clear
1532 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1533 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1535 # spare quota should be released
1536 local OSTUUID=$(ostuuid_from_index 0)
1537 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1538 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1539 [ $limit -le $space ] ||
1540 error "spare quota isn't released, limit:$limit, space:$space"
1544 run_test 13 "Cancel per-ID lock in the LRU list"
1547 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1549 wait_delete_completed
1550 sync_all_data || true
1553 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1554 error "set user quota failed"
1555 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1556 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1557 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1558 resetquota -u $TSTUSR
1561 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1562 error "set group quota failed"
1563 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1564 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1565 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1566 resetquota -g $TSTUSR
1568 run_test 15 "Set over 4T block quota"
1572 local BLKS=1 # 1M less than limit
1573 local TESTFILE=$DIR/$tdir/$tfile
1576 trap cleanup_quota_test EXIT
1578 # make sure the system is clean
1579 local USED=$(getquota -u $TSTUSR global curspace)
1580 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1582 set_ost_qtype "ug" || error "enable ost quota failed"
1583 # make sure no granted quota on ost
1584 resetquota -u $TSTUSR
1585 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1586 error "set quota failed"
1588 quota_show_check b u $TSTUSR
1590 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1591 lustre_fail mds 0xa04 $err_code
1593 # write in background
1594 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1598 # write should be blocked and never finished
1599 if ! ps -p $DDPID > /dev/null 2>&1; then
1601 quota_error u $TSTUSR "write finished incorrectly!"
1609 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1611 if [ $count -gt $timeout ]; then
1612 quota_error u $TSTUSR "dd is not finished!"
1617 sync; sync_all_data || true
1619 USED=$(getquota -u $TSTUSR global curspace)
1620 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1621 "Used space(${USED}K) is less than ${BLKS}M"
1624 resetquota -u $TSTUSR
1627 # DQACQ return recoverable error
1629 echo "DQACQ return -ENOLCK"
1631 test_17sub 37 || error "Handle -ENOLCK failed"
1633 echo "DQACQ return -EAGAIN"
1635 test_17sub 11 || error "Handle -EAGAIN failed"
1637 echo "DQACQ return -ETIMEDOUT"
1638 #define ETIMEDOUT 110
1639 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1641 echo "DQACQ return -ENOTCONN"
1642 #define ENOTCONN 107
1643 test_17sub 107 || error "Handle -ENOTCONN failed"
1646 run_test 17 "DQACQ return recoverable error"
1650 local blimit="200m" # 200M
1651 local TESTFILE="$DIR/$tdir/$tfile"
1654 trap cleanup_quota_test EXIT
1656 set_ost_qtype "u" || error "enable ost quota failed"
1657 log "User quota (limit: $blimit)"
1658 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1659 error "set quota failed"
1660 quota_show_check b u $TSTUSR
1662 $LFS setstripe $TESTFILE -i 0 -c 1
1663 chown $TSTUSR.$TSTUSR $TESTFILE
1665 local timeout=$(sysctl -n lustre.timeout)
1667 if [ $io_type = "directio" ]; then
1668 log "Write 100M (directio) ..."
1669 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1671 log "Write 100M (buffered) ..."
1672 $RUNAS $DD of=$TESTFILE count=100 &
1676 replay_barrier $SINGLEMDS
1677 log "Fail mds for $((2 * timeout)) seconds"
1678 fail $SINGLEMDS $((2 * timeout))
1681 if at_is_enabled; then
1682 timeout=$(at_max_get mds)
1684 timeout=$(lctl get_param -n timeout)
1688 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1689 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1690 log "it took $count second"
1695 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1697 cancel_lru_locks mdc
1698 cancel_lru_locks osc
1701 local testfile_size=$(stat -c %s $TESTFILE)
1702 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1703 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1704 "got ${testfile_size}. Verifying file failed!"
1707 resetquota -u $TSTUSR
1710 # test when mds does failover, the ost still could work well
1711 # this test shouldn't trigger watchdog b=14840
1713 # Clear dmesg so watchdog is not triggered by previous
1715 do_facet ost1 dmesg -c > /dev/null
1718 test_18_sub directio
1720 # check if watchdog is triggered
1721 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1722 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1723 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1724 [ -z "$watchdog" ] || error "$watchdog"
1725 rm -f $TMP/lustre-log-${TESTNAME}.log
1727 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1731 local TESTFILE=$DIR/$tdir/$tfile
1734 trap cleanup_quota_test EXIT
1736 set_ost_qtype "ug" || error "enable ost quota failed"
1738 # bind file to a single OST
1739 $LFS setstripe -c 1 $TESTFILE
1740 chown $TSTUSR.$TSTUSR $TESTFILE
1742 echo "Set user quota (limit: "$blimit"M)"
1743 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1744 error "set user quota failed"
1745 quota_show_check b u $TSTUSR
1746 echo "Update quota limits"
1747 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1748 error "set group quota failed"
1749 quota_show_check b u $TSTUSR
1751 # first wirte might be cached
1752 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1753 cancel_lru_locks osc
1755 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1756 quota_error u $TSTUSR "Write success, expect failure"
1760 resetquota -u $TSTUSR
1762 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1764 test_20() { # b15754
1765 local LSTR=(2g 1t 4k 3m) # limits strings
1767 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1769 resetquota -u $TSTUSR
1771 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1772 $MOUNT || error "could not set quota limits"
1773 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1774 --inode-softlimit ${LSTR[2]} \
1775 --inode-hardlimit ${LSTR[3]} \
1776 $MOUNT || error "could not set quota limits"
1778 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1779 error "bsoftlimit was not set properly"
1780 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1781 error "bhardlimit was not set properly"
1782 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1783 error "isoftlimit was not set properly"
1784 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1785 error "ihardlimit was not set properly"
1787 resetquota -u $TSTUSR
1789 run_test 20 "Test if setquota specifiers work properly (b15754)"
1796 local time=$(($(date +%s) + seconds))
1797 while [ $(date +%s) -lt $time ]; do
1798 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1802 # run for fixing bug16053, setquota shouldn't fail when writing and
1803 # deleting are happening
1805 local TESTFILE="$DIR/$tdir/$tfile"
1806 local BLIMIT=10 # 10G
1807 local ILIMIT=1000000
1810 trap cleanup_quota_test EXIT
1812 set_ost_qtype "ug" || error "Enable ost quota failed"
1814 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1815 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1816 error "set user quota failed"
1817 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1818 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1819 error "set group quota failed"
1821 # repeat writing on a 1M file
1822 test_21_sub ${TESTFILE}_1 1 30 &
1824 # repeat writing on a 128M file
1825 test_21_sub ${TESTFILE}_2 128 30 &
1828 local time=$(($(date +%s) + 30))
1830 while [ $(date +%s) -lt $time ]; do
1831 log "Set quota for $i times"
1832 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1833 -I $((ILIMIT + i)) $MOUNT ||
1834 error "Set user quota failed"
1835 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1836 -I $((ILIMIT + i)) $MOUNT ||
1837 error "Set group quota failed"
1844 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1846 if [ $count -gt 60 ]; then
1847 quota_error a $TSTUSR "dd should be finished!"
1851 echo "(dd_pid=$DDPID1, time=$count)successful"
1855 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1857 if [ $count -gt 60 ]; then
1858 quota_error a $TSTUSR "dd should be finished!"
1862 echo "(dd_pid=$DDPID2, time=$count)successful"
1865 resetquota -u $TSTUSR
1866 resetquota -g $TSTUSR
1868 run_test 21 "Setquota while writing & deleting (b16053)"
1870 # enable/disable quota enforcement permanently
1872 echo "Set both mdt & ost quota type as ug"
1873 set_mdt_qtype "ug" || error "enable mdt quota failed"
1874 set_ost_qtype "ug" || error "enable ost quota failed"
1881 echo "Verify if quota is enabled"
1882 local qtype=$(mdt_quota_type)
1883 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1884 qtype=$(ost_quota_type)
1885 [ $qtype != "ug" ] && error "ost quota setting is lost"
1887 echo "Set both mdt & ost quota type as none"
1888 set_mdt_qtype "none" || error "disable mdt quota failed"
1889 set_ost_qtype "none" || error "disable ost quota failed"
1897 echo "Verify if quota is disabled"
1898 qtype=$(mdt_quota_type)
1899 [ $qtype != "none" ] && error "mdt quota setting is lost"
1900 qtype=$(ost_quota_type)
1901 [ $qtype != "none" ] && error "ost quota setting is lost"
1905 run_test 22 "enable/disable quota by 'lctl conf_param'"
1908 local TESTFILE="$DIR/$tdir/$tfile"
1912 trap cleanup_quota_test EXIT
1914 set_ost_qtype "ug" || error "Enable ost quota failed"
1917 log "User quota (limit: $LIMIT MB)"
1918 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1919 error "set quota failed"
1920 quota_show_check b u $TSTUSR
1922 $LFS setstripe $TESTFILE -c 1 -i 0
1923 chown $TSTUSR.$TSTUSR $TESTFILE
1925 log "Step1: trigger EDQUOT with O_DIRECT"
1926 log "Write half of file"
1927 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1928 quota_error u $TSTUSR "(1) Write failure, expect success." \
1930 log "Write out of block quota ..."
1931 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1932 oflag=direct conv=notrunc &&
1933 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1937 log "Step2: rewrite should succeed"
1938 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1939 quota_error u $TSTUSR "(3) Write failure, expect success." \
1945 local OST0_UUID=$(ostuuid_from_index 0)
1946 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1947 [ $OST0_QUOTA_USED -ne 0 ] &&
1948 ($SHOW_QUOTA_USER; \
1949 quota_error u $TSTUSR "quota isn't released")
1951 resetquota -u $TSTUSR
1955 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1956 check_whether_skip && return 0
1957 log "run for 4MB test file"
1960 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1961 check_whether_skip && return 0
1962 log "run for 40MB test file"
1965 run_test 23 "Quota should be honored with directIO (b16125)"
1969 local TESTFILE="$DIR/$tdir/$tfile"
1972 trap cleanup_quota_test EXIT
1974 set_ost_qtype "ug" || error "enable ost quota failed"
1976 # bind file to a single OST
1977 $LFS setstripe -c 1 $TESTFILE
1978 chown $TSTUSR.$TSTUSR $TESTFILE
1980 echo "Set user quota (limit: "$blimit"M)"
1981 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1982 error "set quota failed"
1984 # overrun quota by root user
1985 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1986 error "write failure, expect success"
1987 cancel_lru_locks osc
1988 sync_all_data || true
1990 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1993 resetquota -u $TSTUSR
1995 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1997 test_27a() { # b19612
1998 $LFS quota $TSTUSR $DIR &&
1999 error "lfs succeeded with no type, but should have failed"
2000 $LFS setquota $TSTUSR $DIR &&
2001 error "lfs succeeded with no type, but should have failed"
2004 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2006 test_27b() { # b20200
2007 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2008 error "lfs setquota failed with uid argument"
2009 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2010 error "lfs stequota failed with gid argument"
2011 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2012 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2013 resetquota -u $TSTUSR
2014 resetquota -g $TSTUSR
2017 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2022 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2023 error "lfs setquota failed"
2025 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2026 [ $limit != "30M" ] && error "softlimit isn't human-readable"
2027 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2028 [ $limit != "3T" ] && error "hardlimit isn't human-readable"
2030 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2031 error "total allocated inode/block limit not printed"
2033 resetquota -u $TSTUSR
2035 run_test 27c "lfs quota should support human-readable output"
2040 local TESTFILE="$DIR/$tdir/$tfile"
2044 trap cleanup_quota_test EXIT
2046 set_ost_qtype "u" || error "enable ost quota failed"
2048 $LFS setstripe $TESTFILE -i 0 -c 1
2049 chown $TSTUSR.$TSTUSR $TESTFILE
2051 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2052 $MAX_IQ_TIME $DIR || error "set grace time failed"
2053 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2054 error "set quota failed"
2055 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2056 cancel_lru_locks osc
2058 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2059 # over-quota flag has not yet settled since we do not trigger async
2060 # events based on grace time period expiration
2062 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2063 cancel_lru_locks osc
2064 # now over-quota flag should be settled and further writes should fail
2066 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2067 error "grace times were reset"
2070 resetquota -u $TSTUSR
2071 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2072 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2074 run_test 30 "Hard limit updates should not reset grace times"
2076 # basic usage tracking for user & group
2078 local INODES=10 # 10 files
2079 local BLK_CNT=2 # of 2M each
2080 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2083 trap cleanup_quota_test EXIT
2085 # make sure the system is clean
2086 local USED=$(getquota -u $TSTID global curspace)
2088 error "Used space ($USED) for user $TSTID isn't 0."
2089 USED=$(getquota -g $TSTID global curspace)
2091 error "Used space ($USED) for group $TSTID isn't 0."
2093 echo "Write files..."
2094 for i in `seq 0 $INODES`; do
2095 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2096 error "write failed"
2097 echo "Iteration $i/$INODES completed"
2099 cancel_lru_locks osc
2100 sync; sync_all_data || true
2102 echo "Verify disk usage after write"
2103 USED=$(getquota -u $TSTID global curspace)
2104 [ $USED -lt $TOTAL_BLKS ] &&
2105 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2106 USED=$(getquota -g $TSTID global curspace)
2107 [ $USED -lt $TOTAL_BLKS ] &&
2108 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2110 echo "Verify inode usage after write"
2111 USED=$(getquota -u $TSTID global curinodes)
2112 [ $USED -lt $INODES ] &&
2113 error "Used inode for user $TSTID is $USED, expected $INODES"
2114 USED=$(getquota -g $TSTID global curinodes)
2115 [ $USED -lt $INODES ] &&
2116 error "Used inode for group $TSTID is $USED, expected $INODES"
2120 echo "Verify disk usage after delete"
2121 USED=$(getquota -u $TSTID global curspace)
2122 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2123 USED=$(getquota -u $TSTID global curinodes)
2124 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2125 USED=$(getquota -g $TSTID global curspace)
2126 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2127 USED=$(getquota -g $TSTID global curinodes)
2128 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2130 run_test 33 "Basic usage tracking for user & group"
2132 # usage transfer test for user & group
2134 local BLK_CNT=2 # 2MB
2137 trap cleanup_quota_test EXIT
2139 # make sure the system is clean
2140 local USED=$(getquota -u $TSTID global curspace)
2141 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2142 USED=$(getquota -g $TSTID global curspace)
2143 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2145 echo "Write file..."
2146 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2147 error "write failed"
2148 cancel_lru_locks osc
2149 sync; sync_all_data || true
2151 echo "chown the file to user $TSTID"
2152 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2154 echo "Wait for setattr on objects finished..."
2155 wait_delete_completed
2157 BLK_CNT=$((BLK_CNT * 1024))
2159 echo "Verify disk usage for user $TSTID"
2160 USED=$(getquota -u $TSTID global curspace)
2161 [ $USED -lt $BLK_CNT ] &&
2162 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2163 USED=$(getquota -u $TSTID global curinodes)
2165 error "Used inodes for user $TSTID is $USED, expected 1"
2167 echo "chgrp the file to group $TSTID"
2168 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2170 echo "Wait for setattr on objects finished..."
2171 wait_delete_completed
2173 echo "Verify disk usage for group $TSTID"
2174 USED=$(getquota -g $TSTID global curspace)
2175 [ $USED -ge $BLK_CNT ] ||
2176 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2177 USED=$(getquota -g $TSTID global curinodes)
2179 error "Used inodes for group $TSTID is $USED, expected 1"
2183 run_test 34 "Usage transfer for user & group"
2185 # usage is still accessible across restart
2187 local BLK_CNT=2 # 2 MB
2190 trap cleanup_quota_test EXIT
2192 echo "Write file..."
2193 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2194 error "write failed"
2195 cancel_lru_locks osc
2196 sync; sync_all_data || true
2198 echo "Save disk usage before restart"
2199 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2200 [ $ORIG_USR_SPACE -eq 0 ] &&
2201 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2202 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2203 [ $ORIG_USR_INODES -eq 0 ] &&
2204 error "Used inodes for user $TSTID is 0, expected 1"
2205 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2206 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2207 [ $ORIG_GRP_SPACE -eq 0 ] &&
2208 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2209 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2210 [ $ORIG_GRP_INODES -eq 0 ] &&
2211 error "Used inodes for group $TSTID is 0, expected 1"
2212 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2215 local ORIG_REFORMAT=$REFORMAT
2217 cleanup_and_setup_lustre
2218 REFORMAT=$ORIG_REFORMAT
2221 echo "Verify disk usage after restart"
2222 local USED=$(getquota -u $TSTID global curspace)
2223 [ $USED -eq $ORIG_USR_SPACE ] ||
2224 error "Used space for user $TSTID changed from " \
2225 "$ORIG_USR_SPACE to $USED"
2226 USED=$(getquota -u $TSTID global curinodes)
2227 [ $USED -eq $ORIG_USR_INODES ] ||
2228 error "Used inodes for user $TSTID changed from " \
2229 "$ORIG_USR_INODES to $USED"
2230 USED=$(getquota -g $TSTID global curspace)
2231 [ $USED -eq $ORIG_GRP_SPACE ] ||
2232 error "Used space for group $TSTID changed from " \
2233 "$ORIG_GRP_SPACE to $USED"
2234 USED=$(getquota -g $TSTID global curinodes)
2235 [ $USED -eq $ORIG_GRP_INODES ] ||
2236 error "Used inodes for group $TSTID changed from " \
2237 "$ORIG_GRP_INODES to $USED"
2239 # check if the vfs_dq_init() is called before writing
2240 echo "Append to the same file..."
2241 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2242 error "write failed"
2243 cancel_lru_locks osc
2244 sync; sync_all_data || true
2246 echo "Verify space usage is increased"
2247 USED=$(getquota -u $TSTID global curspace)
2248 [ $USED -gt $ORIG_USR_SPACE ] ||
2249 error "Used space for user $TSTID isn't increased" \
2250 "orig:$ORIG_USR_SPACE, now:$USED"
2251 USED=$(getquota -g $TSTID global curspace)
2252 [ $USED -gt $ORIG_GRP_SPACE ] ||
2253 error "Used space for group $TSTID isn't increased" \
2254 "orig:$ORIG_GRP_SPACE, now:$USED"
2258 run_test 35 "Usage is still accessible across reboot"
2260 # test migrating old amdin quota files (in Linux quota file format v2) into new
2261 # quota global index (in IAM format)
2263 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2264 skip "skipping migration test" && return
2266 # get the mdt0 device name
2267 local mdt0_node=$(facet_active_host $SINGLEMDS)
2268 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2273 echo "Copy admin quota files into MDT0..."
2274 local mntpt=$(facet_mntpt $SINGLEMDS)
2275 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2277 if ! do_node $mdt0_node test -b $mdt0_fstype; then
2280 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2281 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2282 do_node $mdt0_node mkdir $mntpt/OBJECTS
2283 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2284 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2285 do_node $mdt0_node umount -d -f $mntpt
2290 echo "Verify global limits..."
2294 local proc="qmt.*.md-0x0.glb-usr"
2295 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2296 [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2297 limit=$(getquota -u 1 global isoftlimit)
2298 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2299 limit=$(getquota -u 1 global ihardlimit)
2300 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2302 proc="qmt.*.md-0x0.glb-grp"
2303 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2304 [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2305 limit=$(getquota -g 1 global isoftlimit)
2306 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2307 limit=$(getquota -g 1 global ihardlimit)
2308 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2310 proc=" qmt.*.dt-0x0.glb-usr"
2311 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2312 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2313 limit=$(getquota -u 60001 global bsoftlimit)
2314 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2315 limit=$(getquota -u 60001 global bhardlimit)
2316 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2318 proc="qmt.*.dt-0x0.glb-grp"
2319 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2320 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2321 limit=$(getquota -g 60001 global bsoftlimit)
2322 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2323 limit=$(getquota -g 60001 global bhardlimit)
2324 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2330 run_test 36 "Migrate old admin files into new global indexes"
2334 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2340 check_and_cleanup_lustre
2341 export QUOTA_AUTO=$QUOTA_AUTO_OLD