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
808 trap cleanup_quota_test EXIT
810 # make sure the system is clean
811 local USED=$(getquota -u $TSTUSR global curspace)
812 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
814 # make sure no granted quota on ost
815 set_ost_qtype "ug" || error "enable ost quota failed"
816 resetquota -u $TSTUSR
818 # create file for $TSTUSR
819 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
820 $LFS setstripe $TESTFILE -c 1 -i 0
821 chown $TSTUSR.$TSTUSR $TESTFILE
823 # create file for $TSTUSR2
824 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
825 $LFS setstripe $TESTFILE2 -c 1 -i 0
826 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
828 # cache per-ID lock for $TSTUSR on slave
829 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
830 $RUNAS $DD of=$TESTFILE count=1 ||
831 error "write $TESTFILE failure, expect success"
832 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
833 error "write $TESTFILE2 failure, expect success"
835 sync_all_data || true
837 #define QUOTA_DQACQ 601
838 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
839 lustre_fail mds 0x513 601
841 # write to un-enforced ID ($TSTUSR2) should succeed
842 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
843 error "write failure, expect success"
845 # write to enforced ID ($TSTUSR) in background, exceeding limit
846 # to make sure DQACQ is sent
847 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
850 echo "Sleep for $TIMEOUT"
853 # write should be blocked and never finished
854 if ! ps -p $DDPID > /dev/null 2>&1; then
856 error "write finished incorrectly!"
861 # no watchdog is triggered
862 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
863 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
864 /Service thread pid/ && /was inactive/ {
868 }' $TMP/lustre-log-${TESTNAME}.log)
869 [ -z "$watchdog" ] || error "$watchdog"
871 rm -f $TMP/lustre-log-${TESTNAME}.log
873 # write should continue & succeed
876 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
877 if [ $count -ge 120 ]; then
878 quota_error u $TSTUSR "dd not finished in $count secs"
881 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
886 resetquota -u $TSTUSR
888 run_test 6 "Test dropping acquire request on master"
890 # quota reintegration (global index)
892 local TESTFILE=$DIR/$tdir/$tfile
895 [ "$SLOW" = "no" ] && LIMIT=5
898 trap cleanup_quota_test EXIT
900 # make sure the system is clean
901 local USED=$(getquota -u $TSTUSR global curspace)
902 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
904 # make sure no granted quota on ost1
905 set_ost_qtype "ug" || error "enable ost quota failed"
906 resetquota -u $TSTUSR
907 set_ost_qtype "none" || error "disable ost quota failed"
909 local OSTUUID=$(ostuuid_from_index 0)
910 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
911 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
915 $LFS setstripe $TESTFILE -c 1 -i 0
916 chown $TSTUSR.$TSTUSR $TESTFILE
921 echo "Enable quota & set quota limit for $TSTUSR"
922 set_ost_qtype "ug" || error "enable ost quota failed"
923 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
926 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
928 wait_ost_reint "ug" || error "reintegration failed"
930 # hardlimit should have been fetched by slave during global
931 # reintegration, write will exceed quota
932 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
933 quota_error u $TSTUSR "write success, but expect EDQUOT"
936 resetquota -u $TSTUSR
938 run_test 7a "Quota reintegration (global index)"
940 # quota reintegration (slave index)
943 local TESTFILE=$DIR/$tdir/$tfile
946 trap cleanup_quota_test EXIT
948 # make sure the system is clean
949 local USED=$(getquota -u $TSTUSR global curspace)
950 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
952 # make sure no granted quota on ost1
953 set_ost_qtype "ug" || error "enable ost quota failed"
954 resetquota -u $TSTUSR
955 set_ost_qtype "none" || error "disable ost quota failed"
957 local OSTUUID=$(ostuuid_from_index 0)
958 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
959 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
963 $LFS setstripe $TESTFILE -c 1 -i 0
964 chown $TSTUSR.$TSTUSR $TESTFILE
966 # consume some space to make sure the granted space will not
967 # be released during reconciliation
968 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
969 error "consume space failure, expect success"
971 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
972 lustre_fail mds 0xa02
974 set_ost_qtype "ug" || error "enable ost quota failed"
975 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
977 # ignore the write error
978 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
980 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
984 echo "Restart ost to trigger reintegration..."
986 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
988 wait_ost_reint "ug" || error "reintegration failed"
990 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
991 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
994 resetquota -u $TSTUSR
997 run_test 7b "Quota reintegration (slave index)"
999 # quota reintegration (restart mds during reintegration)
1001 local LIMIT=20 # 20M
1002 local TESTFILE=$DIR/$tdir/$tfile
1004 [ "$SLOW" = "no" ] && LIMIT=5
1007 trap cleanup_quota_test EXIT
1009 # make sure the system is clean
1010 local USED=$(getquota -u $TSTUSR global curspace)
1011 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1013 set_ost_qtype "none" || error "disable ost quota failed"
1014 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
1016 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1017 lustre_fail ost 0xa03
1019 # enable ost quota to trigger reintegration
1020 set_ost_qtype "ug" || error "enable ost quota failed"
1028 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1030 wait_ost_reint "ug" || error "reintegration failed"
1032 # hardlimit should have been fetched by slave during global
1033 # reintegration, write will exceed quota
1034 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1035 quota_error u $TSTUSR "write success, but expect EDQUOT"
1038 resetquota -u $TSTUSR
1040 run_test 7c "Quota reintegration (restart mds during reintegration)"
1042 # run dbench with quota enabled
1044 local BLK_LIMIT="100g" #100G
1045 local FILE_LIMIT=1000000
1048 trap cleanup_quota_test EXIT
1050 set_mdt_qtype "ug" || error "enable mdt quota failed"
1051 set_ost_qtype "ug" || error "enable ost quota failed"
1053 echo "Set enough high limit for user: $TSTUSR"
1054 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1055 echo "Set enough high limit for group: $TSTUSR"
1056 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1059 [ "$SLOW" = "no" ] && duration=" -t 120"
1060 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1061 quota_error a $TSTUSR "dbench failed!"
1064 resetquota -u $TSTUSR
1065 resetquota -g $TSTUSR
1067 run_test 8 "Run dbench with quota enabled"
1069 # this check is just for test_9
1070 OST0_MIN=4900000 #4.67G
1072 check_whether_skip () {
1073 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1074 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1075 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1076 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1083 # run for fixing bug10707, it needs a big room. test for 64bit
1085 local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
1087 check_whether_skip && return 0
1090 trap cleanup_quota_test EXIT
1092 set_ost_qtype "ug" || error "enable ost quota failed"
1094 local TESTFILE="$DIR/$tdir/$tfile-0"
1095 local BLK_LIMIT=100G #100G
1096 local FILE_LIMIT=1000000
1098 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1100 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1102 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1104 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1105 "for group: $TSTUSR"
1106 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1108 quota_show_check a u $TSTUSR
1109 quota_show_check a g $TSTUSR
1111 echo "Create test file"
1112 $LFS setstripe $TESTFILE -c 1 -i 0
1113 chown $TSTUSR.$TSTUSR $TESTFILE
1115 log "Write the big file of 4.5G ..."
1116 $RUNAS $DD of=$TESTFILE count=$filesize ||
1117 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1123 resetquota -u $TSTUSR
1124 resetquota -g $TSTUSR
1129 run_test 9 "Block limit larger than 4GB (b10707)"
1132 local TESTFILE=$DIR/$tdir/$tfile
1135 trap cleanup_quota_test EXIT
1137 # set limit to root user should fail
1138 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1139 error "set limit for root user successfully, expect failure"
1140 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1141 error "set limit for root group successfully, expect failure"
1143 # root user can overrun quota
1144 set_ost_qtype "ug" || "enable ost quota failed"
1146 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
1147 quota_show_check b u $TSTUSR
1149 $LFS setstripe $TESTFILE -c 1
1150 chown $TSTUSR.$TSTUSR $TESTFILE
1152 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1153 error "write failure, expect success"
1156 resetquota -u $TSTUSR
1158 run_test 10 "Test quota for root user"
1161 local TESTFILE=$DIR/$tdir/$tfile
1163 trap cleanup_quota_test EXIT
1165 set_mdt_qtype "ug" || "enable mdt quota failed"
1166 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
1171 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1172 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1175 local USED=$(getquota -u $TSTUSR global curinodes)
1176 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1179 resetquota -u $TSTUSR
1181 run_test 11 "Chown/chgrp ignores quota"
1184 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1186 local blimit=22 # 22M
1187 local blk_cnt=$((blimit - 5))
1188 local TESTFILE0="$DIR/$tdir/$tfile"-0
1189 local TESTFILE1="$DIR/$tdir/$tfile"-1
1192 trap cleanup_quota_test EXIT
1194 set_ost_qtype "u" || "enable ost quota failed"
1195 quota_show_check b u $TSTUSR
1197 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
1199 $LFS setstripe $TESTFILE0 -c 1 -i 0
1200 $LFS setstripe $TESTFILE1 -c 1 -i 1
1201 chown $TSTUSR.$TSTUSR $TESTFILE0
1202 chown $TSTUSR.$TSTUSR $TESTFILE1
1204 echo "Write to ost0..."
1205 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1206 quota_error a $TSTUSR "dd failed"
1208 echo "Write to ost1..."
1209 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1210 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1212 echo "Free space from ost0..."
1214 wait_delete_completed
1215 sync_all_data || true
1217 echo "Write to ost1 after space freed from ost0..."
1218 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1219 quota_error a $TSTUSR "rebalancing failed"
1222 resetquota -u $TSTUSR
1224 run_test 12 "Block quota rebalancing"
1227 local TESTFILE=$DIR/$tdir/$tfile
1228 # the name of osp on ost1 name is MDT0000-osp-OST0000
1229 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1232 trap cleanup_quota_test EXIT
1234 set_ost_qtype "u" || "enable ost quota failed"
1235 quota_show_check b u $TSTUSR
1237 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1238 $LFS setstripe $TESTFILE -c 1 -i 0
1239 chown $TSTUSR.$TSTUSR $TESTFILE
1241 # clear the locks in cache first
1242 do_facet ost1 $LCTL set_param -n $procf=clear
1243 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1244 [ $nlock -eq 0 ] || error "$nlock cached locks"
1246 # write to acquire the per-ID lock
1247 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1248 quota_error a $TSTUSR "dd failed"
1250 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1251 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1253 # clear quota doesn't trigger per-ID lock cancellation
1254 resetquota -u $TSTUSR
1255 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1256 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1258 # clear the per-ID lock
1259 do_facet ost1 $LCTL set_param -n $procf=clear
1260 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1261 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1263 # spare quota should be released
1264 local OSTUUID=$(ostuuid_from_index 0)
1265 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1266 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1267 [ $limit -le $space ] ||
1268 error "spare quota isn't released, limit:$limit, space:$space"
1272 run_test 13 "Cancel per-ID lock in the LRU list"
1275 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1277 wait_delete_completed
1278 sync_all_data || true
1281 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1282 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1283 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1284 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1285 resetquota -u $TSTUSR
1288 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1289 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1290 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1291 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1292 resetquota -g $TSTUSR
1294 run_test 15 "Set over 4T block quota"
1298 local BLKS=1 # 1M less than limit
1299 local TESTFILE=$DIR/$tdir/$tfile
1302 trap cleanup_quota_test EXIT
1304 # make sure the system is clean
1305 local USED=$(getquota -u $TSTUSR global curspace)
1306 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1308 set_ost_qtype "ug" || error "enable ost quota failed"
1309 # make sure no granted quota on ost
1310 resetquota -u $TSTUSR
1311 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1313 quota_show_check b u $TSTUSR
1315 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1316 lustre_fail mds 0xa04 $err_code
1318 # write in background
1319 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1323 # write should be blocked and never finished
1324 if ! ps -p $DDPID > /dev/null 2>&1; then
1326 quota_error u $TSTUSR "write finished incorrectly!"
1334 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1336 if [ $count -gt $timeout ]; then
1337 quota_error u $TSTUSR "dd is not finished!"
1342 sync; sync_all_data || true
1344 USED=$(getquota -u $TSTUSR global curspace)
1345 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1346 "Used space(${USED}K) is less than ${BLKS}M"
1349 resetquota -u $TSTUSR
1352 # DQACQ return recoverable error
1354 echo "DQACQ return -ENOLCK"
1356 test_17sub 37 || error "Handle -ENOLCK failed"
1358 echo "DQACQ return -EAGAIN"
1360 test_17sub 11 || error "Handle -EAGAIN failed"
1362 echo "DQACQ return -ETIMEDOUT"
1363 #define ETIMEDOUT 110
1364 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1366 echo "DQACQ return -ENOTCONN"
1367 #define ENOTCONN 107
1368 test_17sub 107 || error "Handle -ENOTCONN failed"
1371 run_test 17 "DQACQ return recoverable error"
1375 local blimit="200m" # 200M
1376 local TESTFILE="$DIR/$tdir/$tfile"
1379 trap cleanup_quota_test EXIT
1381 set_ost_qtype "u" || error "enable ost quota failed"
1382 log "User quota (limit: $blimit)"
1383 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
1384 quota_show_check b u $TSTUSR
1386 $LFS setstripe $TESTFILE -i 0 -c 1
1387 chown $TSTUSR.$TSTUSR $TESTFILE
1389 local timeout=$(sysctl -n lustre.timeout)
1391 if [ $io_type = "directio" ]; then
1392 log "Write 100M (directio) ..."
1393 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1395 log "Write 100M (buffered) ..."
1396 $RUNAS $DD of=$TESTFILE count=100 &
1400 replay_barrier $SINGLEMDS
1401 log "Fail mds for $((2 * timeout)) seconds"
1402 fail $SINGLEMDS $((2 * timeout))
1405 if at_is_enabled; then
1406 timeout=$(at_max_get mds)
1408 timeout=$(lctl get_param -n timeout)
1412 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1413 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1414 log "it took $count second"
1419 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1421 cancel_lru_locks mdc
1422 cancel_lru_locks osc
1425 local testfile_size=$(stat -c %s $TESTFILE)
1426 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1427 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1428 "got ${testfile_size}. Verifying file failed!"
1431 resetquota -u $TSTUSR
1434 # test when mds does failover, the ost still could work well
1435 # this test shouldn't trigger watchdog b=14840
1438 test_18_sub directio
1440 # check if watchdog is triggered
1441 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1442 local watchdog=$(awk '/test 18b/ {start = 1;}
1443 /Service thread pid/ && /was inactive/ {
1447 }' $TMP/lustre-log-${TESTNAME}.log)
1448 [ -z "$watchdog" ] || error "$watchdog"
1449 rm -f $TMP/lustre-log-${TESTNAME}.log
1451 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1455 local TESTFILE=$DIR/$tdir/$tfile
1458 trap cleanup_quota_test EXIT
1460 set_ost_qtype "ug" || error "enable ost quota failed"
1462 # bind file to a single OST
1463 $LFS setstripe -c 1 $TESTFILE
1464 chown $TSTUSR.$TSTUSR $TESTFILE
1466 echo "Set user quota (limit: "$blimit"M)"
1467 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1468 quota_show_check b u $TSTUSR
1469 echo "Update quota limits"
1470 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1471 quota_show_check b u $TSTUSR
1473 # first wirte might be cached
1474 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1475 cancel_lru_locks osc
1477 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1478 quota_error u $TSTUSR "Write success, expect failure"
1482 resetquota -u $TSTUSR
1484 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1486 test_20() { # b15754
1487 local LSTR=(2g 1t 4k 3m) # limits strings
1489 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1491 resetquota -u $TSTUSR
1493 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1494 $MOUNT || error "could not set quota limits"
1495 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1496 --inode-softlimit ${LSTR[2]} \
1497 --inode-hardlimit ${LSTR[3]} \
1498 $MOUNT || error "could not set quota limits"
1500 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1501 error "bsoftlimit was not set properly"
1502 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1503 error "bhardlimit was not set properly"
1504 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1505 error "isoftlimit was not set properly"
1506 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1507 error "ihardlimit was not set properly"
1509 resetquota -u $TSTUSR
1511 run_test 20 "Test if setquota specifiers work properly (b15754)"
1518 local time=$(($(date +%s) + seconds))
1519 while [ $(date +%s) -lt $time ]; do
1520 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1524 # run for fixing bug16053, setquota shouldn't fail when writing and
1525 # deleting are happening
1527 local TESTFILE="$DIR/$tdir/$tfile"
1528 local BLIMIT=10 # 10G
1529 local ILIMIT=1000000
1532 trap cleanup_quota_test EXIT
1534 set_ost_qtype "ug" || error "Enable ost quota failed"
1536 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1537 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
1538 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1539 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
1541 # repeat writing on a 1M file
1542 test_21_sub ${TESTFILE}_1 1 30 &
1544 # repeat writing on a 128M file
1545 test_21_sub ${TESTFILE}_2 128 30 &
1548 local time=$(($(date +%s) + 30))
1550 while [ $(date +%s) -lt $time ]; do
1551 log "Set quota for $i times"
1552 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1553 -I $((ILIMIT + i)) $MOUNT ||
1554 error "Set user quota failed"
1555 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1556 -I $((ILIMIT + i)) $MOUNT ||
1557 error "Set group quota failed"
1564 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1566 if [ $count -gt 60 ]; then
1567 quota_error a $TSTUSR "dd should be finished!"
1571 echo "(dd_pid=$DDPID1, time=$count)successful"
1575 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1577 if [ $count -gt 60 ]; then
1578 quota_error a $TSTUSR "dd should be finished!"
1582 echo "(dd_pid=$DDPID2, time=$count)successful"
1585 resetquota -u $TSTUSR
1586 resetquota -g $TSTUSR
1588 run_test 21 "Setquota while writing & deleting (b16053)"
1590 # enable/disable quota enforcement permanently
1592 echo "Set both mdt & ost quota type as ug"
1593 set_mdt_qtype "ug" || error "enable mdt quota failed"
1594 set_ost_qtype "ug" || error "enable ost quota failed"
1601 echo "Verify if quota is enabled"
1602 local qtype=$(mdt_quota_type)
1603 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1604 qtype=$(ost_quota_type)
1605 [ $qtype != "ug" ] && error "ost quota setting is lost"
1607 echo "Set both mdt & ost quota type as none"
1608 set_mdt_qtype "none" || error "disable mdt quota failed"
1609 set_ost_qtype "none" || error "disable ost quota failed"
1616 echo "Verify if quota is disabled"
1617 qtype=$(mdt_quota_type)
1618 [ $qtype != "none" ] && error "mdt quota setting is lost"
1619 qtype=$(ost_quota_type)
1620 [ $qtype != "none" ] && error "ost quota setting is lost"
1624 run_test 22 "enable/disable quota by 'lctl conf_param'"
1627 local TESTFILE="$DIR/$tdir/$tfile"
1631 trap cleanup_quota_test EXIT
1633 set_ost_qtype "ug" || error "Enable ost quota failed"
1636 log "User quota (limit: $LIMIT MB)"
1637 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
1638 quota_show_check b u $TSTUSR
1640 $LFS setstripe $TESTFILE -c 1 -i 0
1641 chown $TSTUSR.$TSTUSR $TESTFILE
1643 log "Step1: trigger EDQUOT with O_DIRECT"
1644 log "Write half of file"
1645 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1646 quota_error u $TSTUSR "(1) Write failure, expect success." \
1648 log "Write out of block quota ..."
1649 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1650 oflag=direct conv=notrunc &&
1651 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1655 log "Step2: rewrite should succeed"
1656 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1657 quota_error u $TSTUSR "(3) Write failure, expect success." \
1663 local OST0_UUID=$(ostuuid_from_index 0)
1664 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1665 [ $OST0_QUOTA_USED -ne 0 ] &&
1666 ($SHOW_QUOTA_USER; \
1667 quota_error u $TSTUSR "quota isn't released")
1669 resetquota -u $TSTUSR
1673 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1674 check_whether_skip && return 0
1675 log "run for 4MB test file"
1678 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1679 check_whether_skip && return 0
1680 log "run for 40MB test file"
1683 run_test 23 "Quota should be honored with directIO (b16125)"
1687 local TESTFILE="$DIR/$tdir/$tfile"
1690 trap cleanup_quota_test EXIT
1692 set_ost_qtype "ug" || error "enable ost quota failed"
1694 # bind file to a single OST
1695 $LFS setstripe -c 1 $TESTFILE
1696 chown $TSTUSR.$TSTUSR $TESTFILE
1698 echo "Set user quota (limit: "$blimit"M)"
1699 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1701 # overrun quota by root user
1702 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1703 error "write failure, expect success"
1704 cancel_lru_locks osc
1705 sync_all_data || true
1707 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1710 resetquota -u $TSTUSR
1712 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1714 test_27a() { # b19612
1715 $LFS quota $TSTUSR $DIR &&
1716 error "lfs succeeded with no type, but should have failed"
1717 $LFS setquota $TSTUSR $DIR &&
1718 error "lfs succeeded with no type, but should have failed"
1721 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1723 test_27b() { # b20200
1724 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1725 error "lfs setquota failed with uid argument"
1726 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1727 error "lfs stequota failed with gid argument"
1728 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1729 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1730 resetquota -u $TSTUSR
1731 resetquota -g $TSTUSR
1734 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1739 local TESTFILE="$DIR/$tdir/$tfile"
1743 trap cleanup_quota_test EXIT
1745 set_ost_qtype "u" || error "enable ost quota failed"
1747 $LFS setstripe $TESTFILE -i 0 -c 1
1748 chown $TSTUSR.$TSTUSR $TESTFILE
1750 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
1751 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
1752 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
1753 cancel_lru_locks osc
1755 $LFS setquota -u $TSTUSR -B 0 $DIR
1756 # over-quota flag has not yet settled since we do not trigger async
1757 # events based on grace time period expiration
1759 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
1760 cancel_lru_locks osc
1761 # now over-quota flag should be settled and further writes should fail
1763 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
1764 error "grace times were reset"
1767 resetquota -u $TSTUSR
1768 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1771 run_test 30 "Hard limit updates should not reset grace times"
1773 # basic usage tracking for user & group
1775 local INODES=10 # 10 files
1776 local BLK_CNT=2 # of 2M each
1777 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
1780 trap cleanup_quota_test EXIT
1782 # make sure the system is clean
1783 local USED=$(getquota -u $TSTID global curspace)
1785 error "Used space ($USED) for user $TSTID isn't 0."
1786 USED=$(getquota -g $TSTID global curspace)
1788 error "Used space ($USED) for group $TSTID isn't 0."
1790 echo "Write files..."
1791 for i in `seq 0 $INODES`; do
1792 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
1793 error "write failed"
1794 echo "Iteration $i/$INODES completed"
1796 cancel_lru_locks osc
1797 sync; sync_all_data || true
1799 echo "Verify disk usage after write"
1800 USED=$(getquota -u $TSTID global curspace)
1801 [ $USED -lt $TOTAL_BLKS ] &&
1802 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
1803 USED=$(getquota -g $TSTID global curspace)
1804 [ $USED -lt $TOTAL_BLKS ] &&
1805 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
1807 echo "Verify inode usage after write"
1808 USED=$(getquota -u $TSTID global curinodes)
1809 [ $USED -lt $INODES ] &&
1810 error "Used inode for user $TSTID is $USED, expected $INODES"
1811 USED=$(getquota -g $TSTID global curinodes)
1812 [ $USED -lt $INODES ] &&
1813 error "Used inode for group $TSTID is $USED, expected $INODES"
1817 echo "Verify disk usage after delete"
1818 USED=$(getquota -u $TSTID global curspace)
1819 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
1820 USED=$(getquota -u $TSTID global curinodes)
1821 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
1822 USED=$(getquota -g $TSTID global curspace)
1823 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
1824 USED=$(getquota -g $TSTID global curinodes)
1825 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
1827 run_test 33 "Basic usage tracking for user & group"
1829 # usage transfer test for user & group
1831 local BLK_CNT=2 # 2MB
1834 trap cleanup_quota_test EXIT
1836 # make sure the system is clean
1837 local USED=$(getquota -u $TSTID global curspace)
1838 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
1839 USED=$(getquota -g $TSTID global curspace)
1840 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
1842 echo "Write file..."
1843 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1844 error "write failed"
1845 cancel_lru_locks osc
1846 sync; sync_all_data || true
1848 echo "chown the file to user $TSTID"
1849 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
1851 echo "Wait for setattr on objects finished..."
1852 wait_delete_completed
1854 BLK_CNT=$((BLK_CNT * 1024))
1856 echo "Verify disk usage for user $TSTID"
1857 USED=$(getquota -u $TSTID global curspace)
1858 [ $USED -lt $BLK_CNT ] &&
1859 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
1860 USED=$(getquota -u $TSTID global curinodes)
1862 error "Used inodes for user $TSTID is $USED, expected 1"
1864 echo "chgrp the file to group $TSTID"
1865 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
1867 echo "Wait for setattr on objects finished..."
1868 wait_delete_completed
1870 echo "Verify disk usage for group $TSTID"
1871 USED=$(getquota -g $TSTID global curspace)
1872 [ $USED -ge $BLK_CNT ] ||
1873 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
1874 USED=$(getquota -g $TSTID global curinodes)
1876 error "Used inodes for group $TSTID is $USED, expected 1"
1880 run_test 34 "Usage transfer for user & group"
1882 # usage is still accessible across restart
1884 local BLK_CNT=2 # 2 MB
1887 trap cleanup_quota_test EXIT
1889 echo "Write file..."
1890 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1891 error "write failed"
1892 cancel_lru_locks osc
1893 sync; sync_all_data || true
1895 echo "Save disk usage before restart"
1896 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
1897 [ $ORIG_USR_SPACE -eq 0 ] &&
1898 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
1899 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
1900 [ $ORIG_USR_INODES -eq 0 ] &&
1901 error "Used inodes for user $TSTID is 0, expected 1"
1902 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
1903 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
1904 [ $ORIG_GRP_SPACE -eq 0 ] &&
1905 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
1906 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
1907 [ $ORIG_GRP_INODES -eq 0 ] &&
1908 error "Used inodes for group $TSTID is 0, expected 1"
1909 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
1912 local ORIG_REFORMAT=$REFORMAT
1914 cleanup_and_setup_lustre
1915 REFORMAT=$ORIG_REFORMAT
1918 echo "Verify disk usage after restart"
1919 local USED=$(getquota -u $TSTID global curspace)
1920 [ $USED -eq $ORIG_USR_SPACE ] ||
1921 error "Used space for user $TSTID changed from " \
1922 "$ORIG_USR_SPACE to $USED"
1923 USED=$(getquota -u $TSTID global curinodes)
1924 [ $USED -eq $ORIG_USR_INODES ] ||
1925 error "Used inodes for user $TSTID changed from " \
1926 "$ORIG_USR_INODES to $USED"
1927 USED=$(getquota -g $TSTID global curspace)
1928 [ $USED -eq $ORIG_GRP_SPACE ] ||
1929 error "Used space for group $TSTID changed from " \
1930 "$ORIG_GRP_SPACE to $USED"
1931 USED=$(getquota -g $TSTID global curinodes)
1932 [ $USED -eq $ORIG_GRP_INODES ] ||
1933 error "Used inodes for group $TSTID changed from " \
1934 "$ORIG_GRP_INODES to $USED"
1936 # check if the vfs_dq_init() is called before writing
1937 echo "Append to the same file..."
1938 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
1939 error "write failed"
1940 cancel_lru_locks osc
1941 sync; sync_all_data || true
1943 echo "Verify space usage is increased"
1944 USED=$(getquota -u $TSTID global curspace)
1945 [ $USED -gt $ORIG_USR_SPACE ] ||
1946 error "Used space for user $TSTID isn't increased" \
1947 "orig:$ORIG_USR_SPACE, now:$USED"
1948 USED=$(getquota -g $TSTID global curspace)
1949 [ $USED -gt $ORIG_GRP_SPACE ] ||
1950 error "Used space for group $TSTID isn't increased" \
1951 "orig:$ORIG_GRP_SPACE, now:$USED"
1955 run_test 35 "Usage is still accessible across reboot"
1957 # test migrating old amdin quota files (in Linux quota file format v2) into new
1958 # quota global index (in IAM format)
1960 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
1961 skip "skipping migration test" && return
1963 # get the mdt0 device name
1964 local mdt0_node=$(facet_active_host $SINGLEMDS)
1965 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
1970 echo "Copy admin quota files into MDT0..."
1971 local mntpt=$(facet_mntpt $SINGLEMDS)
1972 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
1974 if ! do_node $mdt0_node test -b $mdt0_fstype; then
1977 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
1978 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
1979 do_node $mdt0_node mkdir $mntpt/OBJECTS
1980 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
1981 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
1982 do_node $mdt0_node umount -f $mntpt
1987 echo "Verify global limits..."
1991 local proc="qmt.*.md-0x0.glb-usr"
1992 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
1993 [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
1994 limit=$(getquota -u 1 global isoftlimit)
1995 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
1996 limit=$(getquota -u 1 global ihardlimit)
1997 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
1999 proc="qmt.*.md-0x0.glb-grp"
2000 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2001 [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
2002 limit=$(getquota -g 1 global isoftlimit)
2003 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2004 limit=$(getquota -g 1 global ihardlimit)
2005 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2007 proc=" qmt.*.dt-0x0.glb-usr"
2008 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2009 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2010 limit=$(getquota -u 60001 global bsoftlimit)
2011 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2012 limit=$(getquota -u 60001 global bhardlimit)
2013 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2015 proc="qmt.*.dt-0x0.glb-grp"
2016 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2017 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2018 limit=$(getquota -g 60001 global bsoftlimit)
2019 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2020 limit=$(getquota -g 60001 global bhardlimit)
2021 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2027 run_test 36 "Migrate old admin files into new global indexes"
2031 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2037 check_and_cleanup_lustre
2038 export QUOTA_AUTO=$QUOTA_AUTO_OLD