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 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
39 require_dsh_mds || exit 0
40 require_dsh_ost || exit 0
42 # XXX Once we drop the interoperability with old server (< 2.3.50), the
43 # sanity-quota-old.sh should be removed.
44 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
45 exec $LUSTRE/tests/sanity-quota-old.sh
48 # if e2fsprogs support quota feature?
49 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
50 ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
51 skip "e2fsprogs doesn't support quota" && exit 0
54 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
56 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
58 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
63 QUOTA_AUTO_OLD=$QUOTA_AUTO
66 check_and_setup_lustre
68 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
69 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
71 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
72 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
73 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
77 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
78 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
85 local fail_val=${3:-0}
87 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
88 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
89 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
92 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
93 for num in `seq $OSTCOUNT`; do
94 do_facet ost$num "lctl set_param fail_val=$fail_val"
95 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
100 RUNAS="runas -u $TSTID -g $TSTID"
101 RUNAS2="runas -u $TSTID2 -g $TSTID2"
102 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
103 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
104 DD="dd if=/dev/zero bs=1M"
108 # clear quota limits for a user or a group
109 # usage: resetquota -u username
110 # resetquota -g groupname
113 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
114 [ "$1" != "-u" -a "$1" != "-g" ] &&
115 error "resetquota: wrong specifier $1 passed"
117 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
118 # The usage should be 0 now, enforce quota to trigger quota
119 # release for each slave, sleep 3 seconds to wait for the release
120 # done, then we can make sure granted quota for each slave is 0.
121 $LFS setquota "$1" "$2" -b 0 -B 1 -i 0 -I 1 $MOUNT
123 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
130 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
131 $LFS quota -v -u $LOCAL_ID $DIR
132 log "Files for user ($LOCAL_ID):"
133 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
134 xargs stat 2>/dev/null)
137 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
138 $LFS quota -v -u $LOCAL_ID $DIR
139 log "Files for group ($LOCAL_ID):"
140 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
141 xargs stat 2>/dev/null)
157 # get quota for a user or a group
158 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
159 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
165 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
166 [ "$1" != "-u" -a "$1" != "-g" ] &&
167 error "getquota: wrong u/g specifier $1 passed"
180 *) error "unknown quota parameter $4";;
183 [ "$uuid" = "global" ] && uuid=$DIR
185 $LFS quota -v "$1" "$2" $DIR |
186 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
187 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
192 # usage: set_mdt_qtype ug|u|g|none
195 local varsvc=${SINGLEMDS}_svc
196 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
197 if $(facet_up $SINGLEMDS); then
198 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
199 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" "$qtype" ||
206 # usage: set_ost_quota_type ug|u|g|none
210 local osts=$(get_facets OST)
211 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
212 # we have to make sure each OST received config changes
213 for ost in ${osts//,/ }; do
215 if $(facet_up $ost); then
216 wait_update_facet $ost "$LCTL get_param -n \
217 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" \
224 wait_reintegration() {
227 local result="glb[1],slv[1],reint[0]"
230 if [ $ntype == "mdt" ]; then
231 varsvc=${SINGLEMDS}_svc
232 if $(facet_up $SINGLEMDS); then
233 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
234 osd-$FSTYPE.${!varsvc}.quota_slave.info |
235 grep "$qtype" | awk '{ print \\\$3 }'" "$result" ||
239 local osts=$(get_facets OST)
240 for ost in ${osts//,/ }; do
242 if $(facet_up $ost); then
243 wait_update_facet $ost "$LCTL get_param -n \
244 osd-$FSTYPE.${!varsvc}.quota_slave.info |
245 grep "$qtype" | awk '{ print \\\$3 }'" \
246 "$result" || return 1
256 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
257 wait_reintegration "mdt" "user" || return 1
260 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
261 wait_reintegration "mdt" "group" || return 1
269 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
270 wait_reintegration "ost" "user" || return 1
273 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
274 wait_reintegration "ost" "group" || return 1
281 wait_delete_completed
282 echo "Creating test directory"
285 # always clear fail_loc in case of fail_loc isn't cleared
286 # properly when previous test failed
287 lustre_fail mds_ost 0
290 cleanup_quota_test() {
292 echo "Delete files..."
294 echo "Wait for unlink objects finished..."
295 wait_delete_completed
296 sync_all_data || true
305 $LFS quota -v -$ug $qid $DIR
307 if [ "$bf" == "a" -o "$bf" == "b" ]; then
308 usage=$(getquota -$ug $qid global curspace)
309 if [ -z $usage ]; then
310 quota_error $ug $qid \
311 "Query block quota failed ($ug:$qid)."
313 [ $usage -ne 0 ] && quota_log $ug $qid \
314 "Block quota isn't 0 ($ug:$qid:$usage)."
318 if [ "$bf" == "a" -o "$bf" == "f" ]; then
319 usage=$(getquota -$ug $qid global curinodes)
320 if [ -z $usage ]; then
321 quota_error $ug $qid \
322 "Query file quota failed ($ug:$qid)."
324 [ $usage -ne 0 ] && quota_log $ug $qid \
325 "File quota isn't 0 ($ug:$qid:$usage)."
332 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
336 test_quota_performance() {
337 local TESTFILE="$DIR/$tdir/$tfile-0"
338 local size=$1 # in MB
339 local stime=$(date +%s)
340 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
341 quota_error u $TSTUSR "write failure"
342 local etime=$(date +%s)
343 delta=$((etime - stime))
344 if [ $delta -gt 0 ]; then
345 rate=$((size * 1024 / delta))
346 [ $rate -gt 1024 ] ||
347 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
352 # test basic quota performance b=21696
355 trap cleanup_quota_test EXIT
358 [ "$SLOW" = "no" ] && MB=10
360 set_ost_qtype "none" || error "disable ost quota failed"
361 test_quota_performance $MB
363 set_ost_qtype "ug" || error "enable ost quota failed"
364 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR
365 test_quota_performance $MB
368 resetquota -u $TSTUSR
370 run_test 0 "Test basic quota performance"
372 # test block hardlimit
375 local TESTFILE="$DIR/$tdir/$tfile-0"
378 trap cleanup_quota_test EXIT
381 set_ost_qtype "ug" || "enable ost quota failed"
384 log "User quota (block hardlimit:$LIMIT MB)"
385 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
387 # make sure the system is clean
388 local USED=$(getquota -u $TSTUSR global curspace)
389 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
391 $LFS setstripe $TESTFILE -c 1
392 chown $TSTUSR.$TSTUSR $TESTFILE
395 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
396 quota_error u $TSTUSR "user write failure, but expect success"
397 log "Write out of block quota ..."
398 # this time maybe cache write, ignore it's failure
399 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
400 # flush cache, ensure noquota flag is set on client
402 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
403 quota_error u $TSTUSR "user write success, but expect EDQUOT"
406 wait_delete_completed
407 sync_all_data || true
408 USED=$(getquota -u $TSTUSR global curspace)
409 [ $USED -ne 0 ] && quota_error u $TSTUSR \
410 "user quota isn't released after deletion"
411 resetquota -u $TSTUSR
414 log "--------------------------------------"
415 log "Group quota (block hardlimit:$LIMIT MB)"
416 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
418 TESTFILE="$DIR/$tdir/$tfile-1"
419 # make sure the system is clean
420 USED=$(getquota -g $TSTUSR global curspace)
421 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
423 $LFS setstripe $TESTFILE -c 1
424 chown $TSTUSR.$TSTUSR $TESTFILE
427 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
428 quota_error g $TSTUSR "group write failure, but expect success"
429 log "Write out of block quota ..."
430 # this time maybe cache write, ignore it's failure
431 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
433 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
434 quota_error g $TSTUSR "group write success, but expect EDQUOT"
439 USED=$(getquota -g $TSTUSR global curspace)
440 [ $USED -ne 0 ] && quota_error g $TSTUSR \
441 "group quota isn't released after deletion"
443 resetquota -g $TSTUSR
445 run_test 1 "Block hard limit (normal use and out of quota)"
447 # test inode hardlimit
449 local LIMIT=$((1024 * 1024)) # 1M inodes
450 local TESTFILE="$DIR/$tdir/$tfile-0"
452 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
455 trap cleanup_quota_test EXIT
458 set_mdt_qtype "ug" || "enable mdt quota failed"
461 log "User quota (inode hardlimit:$LIMIT files)"
462 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
464 # make sure the system is clean
465 local USED=$(getquota -u $TSTUSR global curinodes)
466 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
468 log "Create $LIMIT files ..."
469 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
470 quota_error u $TSTUSR "user create failure, but expect success"
471 log "Create out of file quota ..."
472 $RUNAS touch ${TESTFILE}_xxx && \
473 quota_error u $TSTUSR "user create success, but expect EDQUOT"
476 unlinkmany ${TESTFILE} $LIMIT
477 rm -f ${TESTFILE}_xxx
478 wait_delete_completed
480 USED=$(getquota -u $TSTUSR global curinodes)
481 [ $USED -ne 0 ] && quota_error u $TSTUSR \
482 "user quota isn't released after deletion"
483 resetquota -u $TSTUSR
486 log "--------------------------------------"
487 log "Group quota (inode hardlimit:$LIMIT files)"
488 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
490 TESTFILE=$DIR/$tdir/$tfile-1
491 # make sure the system is clean
492 USED=$(getquota -g $TSTUSR global curinodes)
493 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
495 log "Create $LIMIT files ..."
496 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
497 quota_error g $TSTUSR "group create failure, but expect success"
498 log "Create out of file quota ..."
499 $RUNAS touch ${TESTFILE}_xxx && \
500 quota_error g $TSTUSR "group create success, but expect EDQUOT"
503 unlinkmany ${TESTFILE} $LIMIT
504 rm -f ${TESTFILE}_xxx
505 wait_delete_completed
507 USED=$(getquota -g $TSTUSR global curinodes)
508 [ $USED -ne 0 ] && quota_error g $TSTUSR \
509 "user quota isn't released after deletion"
512 resetquota -g $TSTUSR
514 run_test 2 "File hard limit (normal use and out of quota)"
518 local TIMER=$(($2 * 3 / 2))
523 trap cleanup_quota_test EXIT
525 $LFS setstripe $TESTFILE -c 1 -i 0
526 chown $TSTUSR.$TSTUSR $TESTFILE
528 echo "Write up to soft limit"
529 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
530 quota_error a $TSTUSR "write failure, but expect success"
531 OFFSET=$((LIMIT * 1024))
534 echo "Write to exceed soft limit"
535 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
536 quota_error a $TSTUSR "write failure, but expect success"
537 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
542 $SHOW_QUOTA_INFO_USER
543 $SHOW_QUOTA_INFO_GROUP
545 echo "Write before timer goes off"
546 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
547 quota_error a $TSTUSR "write failure, but expect success"
548 OFFSET=$((OFFSET + 1024))
551 echo "Sleep $TIMER seconds ..."
556 $SHOW_QUOTA_INFO_USER
557 $SHOW_QUOTA_INFO_GROUP
559 echo "Write after timer goes off"
560 # maybe cache write, ignore.
561 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
562 OFFSET=$((OFFSET + 1024))
564 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
565 quota_error a $TSTUSR "write success, but expect EDQUOT"
569 $SHOW_QUOTA_INFO_USER
570 $SHOW_QUOTA_INFO_GROUP
572 echo "Unlink file to stop timer"
574 wait_delete_completed
575 sync_all_data || true
579 $SHOW_QUOTA_INFO_USER
580 $SHOW_QUOTA_INFO_GROUP
582 $LFS setstripe $TESTFILE -c 1 -i 0
583 chown $TSTUSR.$TSTUSR $TESTFILE
586 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
587 quota_error a $TSTUSR "write failure, but expect success"
596 local TESTFILE=$DIR/$tdir/$tfile-0
598 set_ost_qtype "ug" || error "enable ost quota failed"
600 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
601 # make sure the system is clean
602 local USED=$(getquota -u $TSTUSR global curspace)
603 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
605 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
606 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
608 test_block_soft $TESTFILE $GRACE $LIMIT
609 resetquota -u $TSTUSR
611 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
612 TESTFILE=$DIR/$tdir/$tfile-1
613 # make sure the system is clean
614 USED=$(getquota -g $TSTUSR global curspace)
615 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
617 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
618 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
620 test_block_soft $TESTFILE $GRACE $LIMIT
621 resetquota -g $TSTUSR
624 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
626 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
629 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
634 local TIMER=$(($3 * 3 / 2))
637 trap cleanup_quota_test EXIT
639 echo "Create files to exceed soft limit"
640 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
641 quota_error a $TSTUSR "create failure, but expect success"
644 echo "Create file before timer goes off"
645 $RUNAS touch ${TESTFILE}_before ||
646 quota_error a $TSTUSR "failed create before timer expired," \
650 echo "Sleep $TIMER seconds ..."
655 $SHOW_QUOTA_INFO_USER
656 $SHOW_QUOTA_INFO_GROUP
658 echo "Create file after timer goes off"
659 # There is a window that space is accounted in the quota usage but
660 # hasn't been decreased from the pending write, if we acquire quota
661 # in this window, we'll acquire more than we needed.
662 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
664 $RUNAS touch ${TESTFILE}_after_3 &&
665 quota_error a $TSTUSR "create after timer expired," \
671 $SHOW_QUOTA_INFO_USER
672 $SHOW_QUOTA_INFO_GROUP
674 echo "Unlink files to stop timer"
675 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
676 wait_delete_completed
679 $RUNAS touch ${TESTFILE}_xxx ||
680 quota_error a $TSTUSR "touch after timer stop failure," \
690 local LIMIT=10 # inodes
691 local TESTFILE=$DIR/$tdir/$tfile-0
694 set_mdt_qtype "ug" || error "enable mdt quota failed"
696 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
697 # make sure the system is clean
698 local USED=$(getquota -u $TSTUSR global curinodes)
699 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
701 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
702 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
704 test_file_soft $TESTFILE $LIMIT $GRACE
705 resetquota -u $TSTUSR
707 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
708 # make sure the system is clean
709 USED=$(getquota -g $TSTUSR global curinodes)
710 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
712 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
713 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
714 TESTFILE=$DIR/$tdir/$tfile-1
716 test_file_soft $TESTFILE $LIMIT $GRACE
717 resetquota -g $TSTUSR
720 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
722 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
725 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
729 local GR_STR2="1000s"
731 local GR_STR4="1w2d3h4m5s"
733 local GR_STR6="1111111111111111"
735 wait_delete_completed
737 # test of valid grace strings handling
738 echo "Valid grace strings test"
739 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
740 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
741 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
742 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
744 # test of invalid grace strings handling
745 echo " Invalid grace strings test"
746 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
747 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
750 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
752 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
755 run_test 4b "Grace time strings handling"
757 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
759 local BLIMIT=10 # 10M
760 local ILIMIT=10 # 10 inodes
763 trap cleanup_quota_test EXIT
765 set_mdt_qtype "ug" || error "enable mdt quota failed"
766 set_ost_qtype "ug" || error "enable ost quota failed"
768 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
769 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
770 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
772 # make sure the system is clean
773 local USED=$(getquota -u $TSTUSR global curinodes)
774 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
775 USED=$(getquota -g $TSTUSR global curinodes)
776 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
777 USED=$(getquota -u $TSTUSR global curspace)
778 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
779 USED=$(getquota -g $TSTUSR global curspace)
780 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
782 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
783 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
784 error "create failure, expect success"
785 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
786 error "write failure, expect success"
788 echo "Chown files to $TSTUSR.$TSTUSR ..."
789 for i in `seq 0 $ILIMIT`; do
790 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
791 quota_error a $TSTUSR "chown failure, expect success"
795 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
798 resetquota -u $TSTUSR
799 resetquota -g $TSTUSR
801 run_test 5 "Chown & chgrp successfully even out of block/file quota"
803 # test dropping acquire request on master
806 trap cleanup_quota_test EXIT
808 # make sure the system is clean
809 local USED=$(getquota -u $TSTUSR global curspace)
810 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
812 # make sure no granted quota on ost
813 set_ost_qtype "ug" || error "enable ost quota failed"
814 resetquota -u $TSTUSR
816 # create file for $TSTUSR
817 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
818 $LFS setstripe $TESTFILE -c 1 -i 0
819 chown $TSTUSR.$TSTUSR $TESTFILE
821 # create file for $TSTUSR2
822 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
823 $LFS setstripe $TESTFILE2 -c 1 -i 0
824 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
826 # cache per-ID lock for $TSTUSR on slave
827 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
828 $RUNAS $DD of=$TESTFILE count=1 ||
829 error "write $TESTFILE failure, expect success"
830 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
831 error "write $TESTFILE2 failure, expect success"
833 sync_all_data || true
835 #define QUOTA_DQACQ 601
836 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
837 lustre_fail mds 0x513 601
839 # write to un-enforced ID ($TSTUSR2) should succeed
840 $RUNAS2 $DD of=$TESTFILE2 count=1 seek=1 oflag=sync conv=notrunc ||
841 error "write failure, expect success"
843 # write to enforced ID ($TSTUSR) in background, exceeding limit
844 # to make sure DQACQ is sent
845 $RUNAS $DD of=$TESTFILE count=2 seek=1 oflag=sync conv=notrunc &
848 echo "Sleep for $TIMEOUT"
851 # write should be blocked and never finished
852 if ! ps -p $DDPID > /dev/null 2>&1; then
854 error "write finished incorrectly!"
859 # no watchdog is triggered
860 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
861 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
862 /Service thread pid/ && /was inactive/ {
866 }' $TMP/lustre-log-${TESTNAME}.log)
867 [ -z "$watchdog" ] || error "$watchdog"
869 rm -f $TMP/lustre-log-${TESTNAME}.log
871 # write should continue & succeed
874 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
875 if [ $count -ge 120 ]; then
876 quota_error u $TSTUSR "dd not finished in $count secs"
879 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
884 resetquota -u $TSTUSR
886 run_test 6 "Test dropping acquire request on master"
888 # quota reintegration (global index)
890 local TESTFILE=$DIR/$tdir/$tfile
893 [ "$SLOW" = "no" ] && LIMIT=5
896 trap cleanup_quota_test EXIT
898 # make sure the system is clean
899 local USED=$(getquota -u $TSTUSR global curspace)
900 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
902 # make sure no granted quota on ost1
903 set_ost_qtype "ug" || error "enable ost quota failed"
904 resetquota -u $TSTUSR
905 set_ost_qtype "none" || error "disable ost quota failed"
907 local OSTUUID=$(ostuuid_from_index 0)
908 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
909 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
913 $LFS setstripe $TESTFILE -c 1 -i 0
914 chown $TSTUSR.$TSTUSR $TESTFILE
919 echo "Enable quota & set quota limit for $TSTUSR"
920 set_ost_qtype "ug" || error "enable ost quota failed"
921 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
924 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
926 wait_ost_reint "ug" || error "reintegration failed"
928 # hardlimit should have been fetched by slave during global
929 # reintegration, write will exceed quota
930 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
931 quota_error u $TSTUSR "write success, but expect EDQUOT"
934 resetquota -u $TSTUSR
936 run_test 7a "Quota reintegration (global index)"
938 # quota reintegration (slave index)
941 local TESTFILE=$DIR/$tdir/$tfile
944 trap cleanup_quota_test EXIT
946 # make sure the system is clean
947 local USED=$(getquota -u $TSTUSR global curspace)
948 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
950 # make sure no granted quota on ost1
951 set_ost_qtype "ug" || error "enable ost quota failed"
952 resetquota -u $TSTUSR
953 set_ost_qtype "none" || error "disable ost quota failed"
955 local OSTUUID=$(ostuuid_from_index 0)
956 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
957 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
961 $LFS setstripe $TESTFILE -c 1 -i 0
962 chown $TSTUSR.$TSTUSR $TESTFILE
964 # consume some space to make sure the granted space will not
965 # be released during reconciliation
966 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
967 error "consume space failure, expect success"
969 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
970 lustre_fail mds 0xa02
972 set_ost_qtype "ug" || error "enable ost quota failed"
973 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
975 # ignore the write error
976 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
978 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
982 echo "Restart ost to trigger reintegration..."
984 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
986 wait_ost_reint "ug" || error "reintegration failed"
988 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
989 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
992 resetquota -u $TSTUSR
995 run_test 7b "Quota reintegration (slave index)"
997 # quota reintegration (restart mds during reintegration)
1000 local TESTFILE=$DIR/$tdir/$tfile
1002 [ "$SLOW" = "no" ] && LIMIT=5
1005 trap cleanup_quota_test EXIT
1007 # make sure the system is clean
1008 local USED=$(getquota -u $TSTUSR global curspace)
1009 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1011 set_ost_qtype "none" || error "disable ost quota failed"
1012 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
1014 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1015 lustre_fail ost 0xa03
1017 # enable ost quota to trigger reintegration
1018 set_ost_qtype "ug" || error "enable ost quota failed"
1026 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1028 wait_ost_reint "ug" || error "reintegration failed"
1030 # hardlimit should have been fetched by slave during global
1031 # reintegration, write will exceed quota
1032 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1033 quota_error u $TSTUSR "write success, but expect EDQUOT"
1036 resetquota -u $TSTUSR
1038 run_test 7c "Quota reintegration (restart mds during reintegration)"
1040 # run dbench with quota enabled
1042 local BLK_LIMIT="100g" #100G
1043 local FILE_LIMIT=1000000
1046 trap cleanup_quota_test EXIT
1048 set_mdt_qtype "ug" || error "enable mdt quota failed"
1049 set_ost_qtype "ug" || error "enable ost quota failed"
1051 echo "Set enough high limit for user: $TSTUSR"
1052 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1053 echo "Set enough high limit for group: $TSTUSR"
1054 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1057 [ "$SLOW" = "no" ] && duration=" -t 120"
1058 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1059 quota_error a $TSTUSR "dbench failed!"
1062 resetquota -u $TSTUSR
1063 resetquota -g $TSTUSR
1065 run_test 8 "Run dbench with quota enabled"
1067 # this check is just for test_9
1068 OST0_MIN=4900000 #4.67G
1070 check_whether_skip () {
1071 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1072 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1073 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1074 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1081 # run for fixing bug10707, it needs a big room. test for 64bit
1083 local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
1085 check_whether_skip && return 0
1088 trap cleanup_quota_test EXIT
1090 set_ost_qtype "ug" || error "enable ost quota failed"
1092 local TESTFILE="$DIR/$tdir/$tfile-0"
1093 local BLK_LIMIT=100G #100G
1094 local FILE_LIMIT=1000000
1096 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1098 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1100 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1102 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1103 "for group: $TSTUSR"
1104 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1106 quota_show_check a u $TSTUSR
1107 quota_show_check a g $TSTUSR
1109 echo "Create test file"
1110 $LFS setstripe $TESTFILE -c 1 -i 0
1111 chown $TSTUSR.$TSTUSR $TESTFILE
1113 log "Write the big file of 4.5G ..."
1114 $RUNAS $DD of=$TESTFILE count=$filesize ||
1115 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1121 resetquota -u $TSTUSR
1122 resetquota -g $TSTUSR
1127 run_test 9 "Block limit larger than 4GB (b10707)"
1130 local TESTFILE=$DIR/$tdir/$tfile
1133 trap cleanup_quota_test EXIT
1135 # set limit to root user should fail
1136 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1137 error "set limit for root user successfully, expect failure"
1138 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1139 error "set limit for root group successfully, expect failure"
1141 # root user can overrun quota
1142 set_ost_qtype "ug" || "enable ost quota failed"
1144 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
1145 quota_show_check b u $TSTUSR
1147 $LFS setstripe $TESTFILE -c 1
1148 chown $TSTUSR.$TSTUSR $TESTFILE
1150 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1151 error "write failure, expect success"
1154 resetquota -u $TSTUSR
1156 run_test 10 "Test quota for root user"
1159 local TESTFILE=$DIR/$tdir/$tfile
1161 trap cleanup_quota_test EXIT
1163 set_mdt_qtype "ug" || "enable mdt quota failed"
1164 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
1169 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1170 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1173 local USED=$(getquota -u $TSTUSR global curinodes)
1174 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1177 resetquota -u $TSTUSR
1179 run_test 11 "Chown/chgrp ignores quota"
1182 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1184 local blimit=22 # 22M
1185 local blk_cnt=$((blimit - 5))
1186 local TESTFILE0="$DIR/$tdir/$tfile"-0
1187 local TESTFILE1="$DIR/$tdir/$tfile"-1
1190 trap cleanup_quota_test EXIT
1192 set_ost_qtype "u" || "enable ost quota failed"
1193 quota_show_check b u $TSTUSR
1195 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
1197 $LFS setstripe $TESTFILE0 -c 1 -i 0
1198 $LFS setstripe $TESTFILE1 -c 1 -i 1
1199 chown $TSTUSR.$TSTUSR $TESTFILE0
1200 chown $TSTUSR.$TSTUSR $TESTFILE1
1202 echo "Write to ost0..."
1203 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1204 quota_error a $TSTUSR "dd failed"
1206 echo "Write to ost1..."
1207 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1208 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1210 echo "Free space from ost0..."
1212 wait_delete_completed
1213 sync_all_data || true
1215 echo "Write to ost1 after space freed from ost0..."
1216 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1217 quota_error a $TSTUSR "rebalancing failed"
1220 resetquota -u $TSTUSR
1222 run_test 12 "Block quota rebalancing"
1225 local TESTFILE=$DIR/$tdir/$tfile
1226 # the name of osp on ost1 name is MDT0000-osp-OST0000
1227 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1230 trap cleanup_quota_test EXIT
1232 set_ost_qtype "u" || "enable ost quota failed"
1233 quota_show_check b u $TSTUSR
1235 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1236 $LFS setstripe $TESTFILE -c 1 -i 0
1237 chown $TSTUSR.$TSTUSR $TESTFILE
1239 # clear the locks in cache first
1240 do_facet ost1 $LCTL set_param -n $procf=clear
1241 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1242 [ $nlock -eq 0 ] || error "$nlock cached locks"
1244 # write to acquire the per-ID lock
1245 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1246 quota_error a $TSTUSR "dd failed"
1248 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1249 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1251 # clear quota doesn't trigger per-ID lock cancellation
1252 resetquota -u $TSTUSR
1253 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1254 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1256 # clear the per-ID lock
1257 do_facet ost1 $LCTL set_param -n $procf=clear
1258 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1259 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1261 # spare quota should be released
1262 local OSTUUID=$(ostuuid_from_index 0)
1263 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1264 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1265 [ $limit -le $space ] ||
1266 error "spare quota isn't released, limit:$limit, space:$space"
1270 run_test 13 "Cancel per-ID lock in the LRU list"
1273 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1275 wait_delete_completed
1276 sync_all_data || true
1279 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1280 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1281 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1282 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1283 resetquota -u $TSTUSR
1286 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1287 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1288 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1289 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1290 resetquota -g $TSTUSR
1292 run_test 15 "Set over 4T block quota"
1296 local BLKS=1 # 1M less than limit
1297 local TESTFILE=$DIR/$tdir/$tfile
1300 trap cleanup_quota_test EXIT
1302 # make sure the system is clean
1303 local USED=$(getquota -u $TSTUSR global curspace)
1304 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1306 set_ost_qtype "ug" || error "enable ost quota failed"
1307 # make sure no granted quota on ost
1308 resetquota -u $TSTUSR
1309 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1311 quota_show_check b u $TSTUSR
1313 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1314 lustre_fail mds 0xa04 $err_code
1316 # write in background
1317 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1321 # write should be blocked and never finished
1322 if ! ps -p $DDPID > /dev/null 2>&1; then
1324 quota_error u $TSTUSR "write finished incorrectly!"
1332 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1334 if [ $count -gt $timeout ]; then
1335 quota_error u $TSTUSR "dd is not finished!"
1340 sync; sync_all_data || true
1342 USED=$(getquota -u $TSTUSR global curspace)
1343 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1344 "Used space(${USED}K) is less than ${BLKS}M"
1347 resetquota -u $TSTUSR
1350 # DQACQ return recoverable error
1352 echo "DQACQ return -ENOLCK"
1354 test_17sub 37 || error "Handle -ENOLCK failed"
1356 echo "DQACQ return -EAGAIN"
1358 test_17sub 11 || error "Handle -EAGAIN failed"
1360 echo "DQACQ return -ETIMEDOUT"
1361 #define ETIMEDOUT 110
1362 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1364 echo "DQACQ return -ENOTCONN"
1365 #define ENOTCONN 107
1366 test_17sub 107 || error "Handle -ENOTCONN failed"
1369 run_test 17 "DQACQ return recoverable error"
1373 local blimit="200m" # 200M
1374 local TESTFILE="$DIR/$tdir/$tfile"
1377 trap cleanup_quota_test EXIT
1379 set_ost_qtype "u" || error "enable ost quota failed"
1380 log "User quota (limit: $blimit)"
1381 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
1382 quota_show_check b u $TSTUSR
1384 $LFS setstripe $TESTFILE -i 0 -c 1
1385 chown $TSTUSR.$TSTUSR $TESTFILE
1387 local timeout=$(sysctl -n lustre.timeout)
1389 if [ $io_type = "directio" ]; then
1390 log "Write 100M (directio) ..."
1391 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1393 log "Write 100M (buffered) ..."
1394 $RUNAS $DD of=$TESTFILE count=100 &
1398 replay_barrier $SINGLEMDS
1399 log "Fail mds for $((2 * timeout)) seconds"
1400 fail $SINGLEMDS $((2 * timeout))
1403 if at_is_enabled; then
1404 timeout=$(at_max_get mds)
1406 timeout=$(lctl get_param -n timeout)
1410 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1411 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1412 log "it took $count second"
1417 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1419 cancel_lru_locks mdc
1420 cancel_lru_locks osc
1423 local testfile_size=$(stat -c %s $TESTFILE)
1424 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1425 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1426 "got ${testfile_size}. Verifying file failed!"
1429 resetquota -u $TSTUSR
1432 # test when mds does failover, the ost still could work well
1433 # this test shouldn't trigger watchdog b=14840
1436 test_18_sub directio
1438 # check if watchdog is triggered
1439 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1440 local watchdog=$(awk '/test 18b/ {start = 1;}
1441 /Service thread pid/ && /was inactive/ {
1445 }' $TMP/lustre-log-${TESTNAME}.log)
1446 [ -z "$watchdog" ] || error "$watchdog"
1447 rm -f $TMP/lustre-log-${TESTNAME}.log
1449 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1453 local TESTFILE=$DIR/$tdir/$tfile
1456 trap cleanup_quota_test EXIT
1458 set_ost_qtype "ug" || error "enable ost quota failed"
1460 # bind file to a single OST
1461 $LFS setstripe -c 1 $TESTFILE
1462 chown $TSTUSR.$TSTUSR $TESTFILE
1464 echo "Set user quota (limit: "$blimit"M)"
1465 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1466 quota_show_check b u $TSTUSR
1467 echo "Update quota limits"
1468 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1469 quota_show_check b u $TSTUSR
1471 # first wirte might be cached
1472 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1473 cancel_lru_locks osc
1475 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1476 quota_error u $TSTUSR "Write success, expect failure"
1480 resetquota -u $TSTUSR
1482 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1484 test_20() { # b15754
1485 local LSTR=(2g 1t 4k 3m) # limits strings
1487 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1489 resetquota -u $TSTUSR
1491 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1492 $MOUNT || error "could not set quota limits"
1493 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1494 --inode-softlimit ${LSTR[2]} \
1495 --inode-hardlimit ${LSTR[3]} \
1496 $MOUNT || error "could not set quota limits"
1498 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1499 error "bsoftlimit was not set properly"
1500 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1501 error "bhardlimit was not set properly"
1502 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1503 error "isoftlimit was not set properly"
1504 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1505 error "ihardlimit was not set properly"
1507 resetquota -u $TSTUSR
1509 run_test 20 "Test if setquota specifiers work properly (b15754)"
1516 local time=$(($(date +%s) + seconds))
1517 while [ $(date +%s) -lt $time ]; do
1518 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1522 # run for fixing bug16053, setquota shouldn't fail when writing and
1523 # deleting are happening
1525 local TESTFILE="$DIR/$tdir/$tfile"
1526 local BLIMIT=10 # 10G
1527 local ILIMIT=1000000
1530 trap cleanup_quota_test EXIT
1532 set_ost_qtype "ug" || error "Enable ost quota failed"
1534 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1535 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
1536 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1537 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
1539 # repeat writing on a 1M file
1540 test_21_sub ${TESTFILE}_1 1 30 &
1542 # repeat writing on a 128M file
1543 test_21_sub ${TESTFILE}_2 128 30 &
1546 local time=$(($(date +%s) + 30))
1548 while [ $(date +%s) -lt $time ]; do
1549 log "Set quota for $i times"
1550 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1551 -I $((ILIMIT + i)) $MOUNT ||
1552 error "Set user quota failed"
1553 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1554 -I $((ILIMIT + i)) $MOUNT ||
1555 error "Set group quota failed"
1562 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1564 if [ $count -gt 60 ]; then
1565 quota_error a $TSTUSR "dd should be finished!"
1569 echo "(dd_pid=$DDPID1, time=$count)successful"
1573 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1575 if [ $count -gt 60 ]; then
1576 quota_error a $TSTUSR "dd should be finished!"
1580 echo "(dd_pid=$DDPID2, time=$count)successful"
1583 resetquota -u $TSTUSR
1584 resetquota -g $TSTUSR
1586 run_test 21 "Setquota while writing & deleting (b16053)"
1588 # enable/disable quota enforcement permanently
1590 echo "Set both mdt & ost quota type as ug"
1591 set_mdt_qtype "ug" || error "enable mdt quota failed"
1592 set_ost_qtype "ug" || error "enable ost quota failed"
1599 echo "Verify if quota is enabled"
1600 local qtype=$(mdt_quota_type)
1601 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1602 qtype=$(ost_quota_type)
1603 [ $qtype != "ug" ] && error "ost quota setting is lost"
1605 echo "Set both mdt & ost quota type as none"
1606 set_mdt_qtype "none" || error "disable mdt quota failed"
1607 set_ost_qtype "none" || error "disable ost quota failed"
1614 echo "Verify if quota is disabled"
1615 qtype=$(mdt_quota_type)
1616 [ $qtype != "none" ] && error "mdt quota setting is lost"
1617 qtype=$(ost_quota_type)
1618 [ $qtype != "none" ] && error "ost quota setting is lost"
1622 run_test 22 "enable/disable quota by 'lctl conf_param'"
1625 local TESTFILE="$DIR/$tdir/$tfile"
1629 trap cleanup_quota_test EXIT
1631 set_ost_qtype "ug" || error "Enable ost quota failed"
1634 log "User quota (limit: $LIMIT MB)"
1635 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
1636 quota_show_check b u $TSTUSR
1638 $LFS setstripe $TESTFILE -c 1 -i 0
1639 chown $TSTUSR.$TSTUSR $TESTFILE
1641 log "Step1: trigger EDQUOT with O_DIRECT"
1642 log "Write half of file"
1643 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1644 quota_error u $TSTUSR "(1) Write failure, expect success." \
1646 log "Write out of block quota ..."
1647 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1648 oflag=direct conv=notrunc &&
1649 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1653 log "Step2: rewrite should succeed"
1654 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1655 quota_error u $TSTUSR "(3) Write failure, expect success." \
1661 local OST0_UUID=$(ostuuid_from_index 0)
1662 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1663 [ $OST0_QUOTA_USED -ne 0 ] &&
1664 ($SHOW_QUOTA_USER; \
1665 quota_error u $TSTUSR "quota isn't released")
1667 resetquota -u $TSTUSR
1671 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1672 check_whether_skip && return 0
1673 log "run for 4MB test file"
1676 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1677 check_whether_skip && return 0
1678 log "run for 40MB test file"
1681 run_test 23 "Quota should be honored with directIO (b16125)"
1685 local TESTFILE="$DIR/$tdir/$tfile"
1688 trap cleanup_quota_test EXIT
1690 set_ost_qtype "ug" || error "enable ost quota failed"
1692 # bind file to a single OST
1693 $LFS setstripe -c 1 $TESTFILE
1694 chown $TSTUSR.$TSTUSR $TESTFILE
1696 echo "Set user quota (limit: "$blimit"M)"
1697 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1699 # overrun quota by root user
1700 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1701 error "write failure, expect success"
1702 cancel_lru_locks osc
1703 sync_all_data || true
1705 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1708 resetquota -u $TSTUSR
1710 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1712 test_27a() { # b19612
1713 $LFS quota $TSTUSR $DIR &&
1714 error "lfs succeeded with no type, but should have failed"
1715 $LFS setquota $TSTUSR $DIR &&
1716 error "lfs succeeded with no type, but should have failed"
1719 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1721 test_27b() { # b20200
1722 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1723 error "lfs setquota failed with uid argument"
1724 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1725 error "lfs stequota failed with gid argument"
1726 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1727 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1728 resetquota -u $TSTUSR
1729 resetquota -g $TSTUSR
1732 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1737 local TESTFILE="$DIR/$tdir/$tfile"
1741 trap cleanup_quota_test EXIT
1743 set_ost_qtype "u" || error "enable ost quota failed"
1745 $LFS setstripe $TESTFILE -i 0 -c 1
1746 chown $TSTUSR.$TSTUSR $TESTFILE
1748 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
1749 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
1750 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
1751 cancel_lru_locks osc
1753 $LFS setquota -u $TSTUSR -B 0 $DIR
1754 # over-quota flag has not yet settled since we do not trigger async
1755 # events based on grace time period expiration
1757 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
1758 cancel_lru_locks osc
1759 # now over-quota flag should be settled and further writes should fail
1761 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
1762 error "grace times were reset"
1765 resetquota -u $TSTUSR
1766 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1769 run_test 30 "Hard limit updates should not reset grace times"
1771 # basic usage tracking for user & group
1773 local INODES=10 # 10 files
1774 local BLK_CNT=2 # of 2M each
1775 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
1778 trap cleanup_quota_test EXIT
1780 # make sure the system is clean
1781 local USED=$(getquota -u $TSTID global curspace)
1783 error "Used space ($USED) for user $TSTID isn't 0."
1784 USED=$(getquota -g $TSTID global curspace)
1786 error "Used space ($USED) for group $TSTID isn't 0."
1788 echo "Write files..."
1789 for i in `seq 0 $INODES`; do
1790 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
1791 error "write failed"
1792 echo "Iteration $i/$INODES completed"
1794 cancel_lru_locks osc
1795 sync; sync_all_data || true
1797 echo "Verify disk usage after write"
1798 USED=$(getquota -u $TSTID global curspace)
1799 [ $USED -lt $TOTAL_BLKS ] &&
1800 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
1801 USED=$(getquota -g $TSTID global curspace)
1802 [ $USED -lt $TOTAL_BLKS ] &&
1803 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
1805 echo "Verify inode usage after write"
1806 USED=$(getquota -u $TSTID global curinodes)
1807 [ $USED -lt $INODES ] &&
1808 error "Used inode for user $TSTID is $USED, expected $INODES"
1809 USED=$(getquota -g $TSTID global curinodes)
1810 [ $USED -lt $INODES ] &&
1811 error "Used inode for group $TSTID is $USED, expected $INODES"
1815 echo "Verify disk usage after delete"
1816 USED=$(getquota -u $TSTID global curspace)
1817 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
1818 USED=$(getquota -u $TSTID global curinodes)
1819 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
1820 USED=$(getquota -g $TSTID global curspace)
1821 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
1822 USED=$(getquota -g $TSTID global curinodes)
1823 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
1825 run_test 33 "Basic usage tracking for user & group"
1827 # usage transfer test for user & group
1829 local BLK_CNT=2 # 2MB
1832 trap cleanup_quota_test EXIT
1834 # make sure the system is clean
1835 local USED=$(getquota -u $TSTID global curspace)
1836 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
1837 USED=$(getquota -g $TSTID global curspace)
1838 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
1840 echo "Write file..."
1841 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1842 error "write failed"
1843 cancel_lru_locks osc
1844 sync; sync_all_data || true
1846 echo "chown the file to user $TSTID"
1847 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
1849 echo "Wait for setattr on objects finished..."
1850 wait_delete_completed
1852 BLK_CNT=$((BLK_CNT * 1024))
1854 echo "Verify disk usage for user $TSTID"
1855 USED=$(getquota -u $TSTID global curspace)
1856 [ $USED -lt $BLK_CNT ] &&
1857 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
1858 USED=$(getquota -u $TSTID global curinodes)
1860 error "Used inodes for user $TSTID is $USED, expected 1"
1862 echo "chgrp the file to group $TSTID"
1863 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
1865 echo "Wait for setattr on objects finished..."
1866 wait_delete_completed
1868 echo "Verify disk usage for group $TSTID"
1869 USED=$(getquota -g $TSTID global curspace)
1870 [ $USED -ge $BLK_CNT ] ||
1871 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
1872 USED=$(getquota -g $TSTID global curinodes)
1874 error "Used inodes for group $TSTID is $USED, expected 1"
1878 run_test 34 "Usage transfer for user & group"
1880 # usage is still accessible across restart
1882 local BLK_CNT=2 # 2 MB
1885 trap cleanup_quota_test EXIT
1887 echo "Write file..."
1888 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1889 error "write failed"
1890 cancel_lru_locks osc
1891 sync; sync_all_data || true
1893 echo "Save disk usage before restart"
1894 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
1895 [ $ORIG_USR_SPACE -eq 0 ] &&
1896 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
1897 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
1898 [ $ORIG_USR_INODES -eq 0 ] &&
1899 error "Used inodes for user $TSTID is 0, expected 1"
1900 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
1901 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
1902 [ $ORIG_GRP_SPACE -eq 0 ] &&
1903 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
1904 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
1905 [ $ORIG_GRP_INODES -eq 0 ] &&
1906 error "Used inodes for group $TSTID is 0, expected 1"
1907 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
1910 local ORIG_REFORMAT=$REFORMAT
1912 cleanup_and_setup_lustre
1913 REFORMAT=$ORIG_REFORMAT
1916 echo "Verify disk usage after restart"
1917 local USED=$(getquota -u $TSTID global curspace)
1918 [ $USED -eq $ORIG_USR_SPACE ] ||
1919 error "Used space for user $TSTID changed from " \
1920 "$ORIG_USR_SPACE to $USED"
1921 USED=$(getquota -u $TSTID global curinodes)
1922 [ $USED -eq $ORIG_USR_INODES ] ||
1923 error "Used inodes for user $TSTID changed from " \
1924 "$ORIG_USR_INODES to $USED"
1925 USED=$(getquota -g $TSTID global curspace)
1926 [ $USED -eq $ORIG_GRP_SPACE ] ||
1927 error "Used space for group $TSTID changed from " \
1928 "$ORIG_GRP_SPACE to $USED"
1929 USED=$(getquota -g $TSTID global curinodes)
1930 [ $USED -eq $ORIG_GRP_INODES ] ||
1931 error "Used inodes for group $TSTID changed from " \
1932 "$ORIG_GRP_INODES to $USED"
1934 # check if the vfs_dq_init() is called before writing
1935 echo "Append to the same file..."
1936 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
1937 error "write failed"
1938 cancel_lru_locks osc
1939 sync; sync_all_data || true
1941 echo "Verify space usage is increased"
1942 USED=$(getquota -u $TSTID global curspace)
1943 [ $USED -gt $ORIG_USR_SPACE ] ||
1944 error "Used space for user $TSTID isn't increased" \
1945 "orig:$ORIG_USR_SPACE, now:$USED"
1946 USED=$(getquota -g $TSTID global curspace)
1947 [ $USED -gt $ORIG_GRP_SPACE ] ||
1948 error "Used space for group $TSTID isn't increased" \
1949 "orig:$ORIG_GRP_SPACE, now:$USED"
1953 run_test 35 "Usage is still accessible across reboot"
1955 # test migrating old amdin quota files (in Linux quota file format v2) into new
1956 # quota global index (in IAM format)
1958 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
1959 skip "skipping migration test" && return
1961 # get the mdt0 device name
1962 local mdt0_node=$(facet_active_host $SINGLEMDS)
1963 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
1968 echo "Copy admin quota files into MDT0..."
1969 local mntpt=$(facet_mntpt $SINGLEMDS)
1970 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
1972 if ! do_node $mdt0_node test -b $mdt0_fstype; then
1975 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
1976 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
1977 do_node $mdt0_node mkdir $mntpt/OBJECTS
1978 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
1979 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
1980 do_node $mdt0_node umount -f $mntpt
1985 echo "Verify global limits..."
1989 local proc="qmt.*.md-0x0.glb-usr"
1990 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
1991 [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
1992 limit=$(getquota -u 1 global isoftlimit)
1993 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
1994 limit=$(getquota -u 1 global ihardlimit)
1995 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
1997 proc="qmt.*.md-0x0.glb-grp"
1998 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
1999 [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
2000 limit=$(getquota -g 1 global isoftlimit)
2001 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2002 limit=$(getquota -g 1 global ihardlimit)
2003 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2005 proc=" qmt.*.dt-0x0.glb-usr"
2006 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2007 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2008 limit=$(getquota -u 60001 global bsoftlimit)
2009 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2010 limit=$(getquota -u 60001 global bhardlimit)
2011 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2013 proc="qmt.*.dt-0x0.glb-grp"
2014 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2015 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2016 limit=$(getquota -g 60001 global bsoftlimit)
2017 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2018 limit=$(getquota -g 60001 global bhardlimit)
2019 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2025 run_test 36 "Migrate old admin files into new global indexes"
2029 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2034 complete $(basename $0) $SECONDS
2035 check_and_cleanup_lustre
2036 export QUOTA_AUTO=$QUOTA_AUTO_OLD