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"
82 # Use OFD for all quota testing
84 USE_OFD_OLD="$USE_OFD"
85 LOAD_MODULES_REMOTE_OLD="$LOAD_MODULES_REMOTE"
87 export LOAD_MODULES_REMOTE="true"
93 local fail_val=${3:-0}
95 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
96 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
97 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
100 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
101 for num in `seq $OSTCOUNT`; do
102 do_facet ost$num "lctl set_param fail_val=$fail_val"
103 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
108 RUNAS="runas -u $TSTID -g $TSTID"
109 RUNAS2="runas -u $TSTID2 -g $TSTID2"
110 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
111 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
112 DD="dd if=/dev/zero bs=1M"
116 # clear quota limits for a user or a group
117 # usage: resetquota -u username
118 # resetquota -g groupname
121 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
122 [ "$1" != "-u" -a "$1" != "-g" ] &&
123 error "resetquota: wrong specifier $1 passed"
125 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
126 # The usage should be 0 now, enforce quota to trigger quota
127 # release for each slave, sleep 3 seconds to wait for the release
128 # done, then we can make sure granted quota for each slave is 0.
129 $LFS setquota "$1" "$2" -b 0 -B 1 -i 0 -I 1 $MOUNT
131 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
138 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
139 $LFS quota -v -u $LOCAL_ID $DIR
140 log "Files for user ($LOCAL_ID):"
141 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
142 xargs stat 2>/dev/null)
145 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
146 $LFS quota -v -u $LOCAL_ID $DIR
147 log "Files for group ($LOCAL_ID):"
148 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
149 xargs stat 2>/dev/null)
165 # get quota for a user or a group
166 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
167 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
173 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
174 [ "$1" != "-u" -a "$1" != "-g" ] &&
175 error "getquota: wrong u/g specifier $1 passed"
188 *) error "unknown quota parameter $4";;
191 [ "$uuid" = "global" ] && uuid=$DIR
193 $LFS quota -v "$1" "$2" $DIR |
194 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
195 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
200 # usage: set_mdt_qtype ug|u|g|none
203 local varsvc=${SINGLEMDS}_svc
204 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
205 if $(facet_up $SINGLEMDS); then
206 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
207 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" "$qtype" ||
214 # usage: set_ost_quota_type ug|u|g|none
218 local osts=$(get_facets OST)
219 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
220 # we have to make sure each OST received config changes
221 for ost in ${osts//,/ }; do
223 if $(facet_up $ost); then
224 wait_update_facet $ost "$LCTL get_param -n \
225 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" \
232 wait_reintegration() {
235 local result="glb[1],slv[1],reint[0]"
238 if [ $ntype == "mdt" ]; then
239 varsvc=${SINGLEMDS}_svc
240 if $(facet_up $SINGLEMDS); then
241 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
242 osd-$FSTYPE.${!varsvc}.quota_slave.info |
243 grep "$qtype" | awk '{ print \\\$3 }'" "$result" ||
247 local osts=$(get_facets OST)
248 for ost in ${osts//,/ }; do
250 if $(facet_up $ost); then
251 wait_update_facet $ost "$LCTL get_param -n \
252 osd-$FSTYPE.${!varsvc}.quota_slave.info |
253 grep "$qtype" | awk '{ print \\\$3 }'" \
254 "$result" || return 1
264 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
265 wait_reintegration "mdt" "user" || return 1
268 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
269 wait_reintegration "mdt" "group" || return 1
277 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
278 wait_reintegration "ost" "user" || return 1
281 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
282 wait_reintegration "ost" "group" || return 1
289 wait_delete_completed
290 echo "Creating test directory"
293 # always clear fail_loc in case of fail_loc isn't cleared
294 # properly when previous test failed
295 lustre_fail mds_ost 0
298 cleanup_quota_test() {
300 echo "Delete files..."
302 echo "Wait for unlink objects finished..."
303 wait_delete_completed
304 sync_all_data || true
313 $LFS quota -v -$ug $qid $DIR
315 if [ "$bf" == "a" -o "$bf" == "b" ]; then
316 usage=$(getquota -$ug $qid global curspace)
317 if [ -z $usage ]; then
318 quota_error $ug $qid \
319 "Query block quota failed ($ug:$qid)."
321 [ $usage -ne 0 ] && quota_log $ug $qid \
322 "Block quota isn't 0 ($ug:$qid:$usage)."
326 if [ "$bf" == "a" -o "$bf" == "f" ]; then
327 usage=$(getquota -$ug $qid global curinodes)
328 if [ -z $usage ]; then
329 quota_error $ug $qid \
330 "Query file quota failed ($ug:$qid)."
332 [ $usage -ne 0 ] && quota_log $ug $qid \
333 "File quota isn't 0 ($ug:$qid:$usage)."
340 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
344 test_quota_performance() {
345 local TESTFILE="$DIR/$tdir/$tfile-0"
346 local size=$1 # in MB
347 local stime=$(date +%s)
348 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
349 quota_error u $TSTUSR "write failure"
350 local etime=$(date +%s)
351 delta=$((etime - stime))
352 if [ $delta -gt 0 ]; then
353 rate=$((size * 1024 / delta))
354 [ $rate -gt 1024 ] ||
355 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
360 # test basic quota performance b=21696
363 trap cleanup_quota_test EXIT
366 [ "$SLOW" = "no" ] && MB=10
368 set_ost_qtype "none" || error "disable ost quota failed"
369 test_quota_performance $MB
371 set_ost_qtype "ug" || error "enable ost quota failed"
372 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR
373 test_quota_performance $MB
376 resetquota -u $TSTUSR
378 run_test 0 "Test basic quota performance"
380 # test block hardlimit
383 local TESTFILE="$DIR/$tdir/$tfile-0"
386 trap cleanup_quota_test EXIT
389 set_ost_qtype "ug" || "enable ost quota failed"
392 log "User quota (block hardlimit:$LIMIT MB)"
393 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
395 # make sure the system is clean
396 local USED=$(getquota -u $TSTUSR global curspace)
397 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
399 $LFS setstripe $TESTFILE -c 1
400 chown $TSTUSR.$TSTUSR $TESTFILE
403 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
404 quota_error u $TSTUSR "user write failure, but expect success"
405 log "Write out of block quota ..."
406 # this time maybe cache write, ignore it's failure
407 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
408 # flush cache, ensure noquota flag is set on client
410 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
411 quota_error u $TSTUSR "user write success, but expect EDQUOT"
414 wait_delete_completed
415 sync_all_data || true
416 USED=$(getquota -u $TSTUSR global curspace)
417 [ $USED -ne 0 ] && quota_error u $TSTUSR \
418 "user quota isn't released after deletion"
419 resetquota -u $TSTUSR
422 log "--------------------------------------"
423 log "Group quota (block hardlimit:$LIMIT MB)"
424 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
426 TESTFILE="$DIR/$tdir/$tfile-1"
427 # make sure the system is clean
428 USED=$(getquota -g $TSTUSR global curspace)
429 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
431 $LFS setstripe $TESTFILE -c 1
432 chown $TSTUSR.$TSTUSR $TESTFILE
435 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
436 quota_error g $TSTUSR "group write failure, but expect success"
437 log "Write out of block quota ..."
438 # this time maybe cache write, ignore it's failure
439 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
441 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
442 quota_error g $TSTUSR "group write success, but expect EDQUOT"
447 USED=$(getquota -g $TSTUSR global curspace)
448 [ $USED -ne 0 ] && quota_error g $TSTUSR \
449 "group quota isn't released after deletion"
451 resetquota -g $TSTUSR
453 run_test 1 "Block hard limit (normal use and out of quota)"
455 # test inode hardlimit
457 local LIMIT=$((1024 * 1024)) # 1M inodes
458 local TESTFILE="$DIR/$tdir/$tfile-0"
460 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
463 trap cleanup_quota_test EXIT
466 set_mdt_qtype "ug" || "enable mdt quota failed"
469 log "User quota (inode hardlimit:$LIMIT files)"
470 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
472 # make sure the system is clean
473 local USED=$(getquota -u $TSTUSR global curinodes)
474 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
476 log "Create $LIMIT files ..."
477 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
478 quota_error u $TSTUSR "user create failure, but expect success"
479 log "Create out of file quota ..."
480 $RUNAS touch ${TESTFILE}_xxx && \
481 quota_error u $TSTUSR "user create success, but expect EDQUOT"
484 unlinkmany ${TESTFILE} $LIMIT
485 rm -f ${TESTFILE}_xxx
486 wait_delete_completed
488 USED=$(getquota -u $TSTUSR global curinodes)
489 [ $USED -ne 0 ] && quota_error u $TSTUSR \
490 "user quota isn't released after deletion"
491 resetquota -u $TSTUSR
494 log "--------------------------------------"
495 log "Group quota (inode hardlimit:$LIMIT files)"
496 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
498 TESTFILE=$DIR/$tdir/$tfile-1
499 # make sure the system is clean
500 USED=$(getquota -g $TSTUSR global curinodes)
501 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
503 log "Create $LIMIT files ..."
504 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
505 quota_error g $TSTUSR "group create failure, but expect success"
506 log "Create out of file quota ..."
507 $RUNAS touch ${TESTFILE}_xxx && \
508 quota_error g $TSTUSR "group create success, but expect EDQUOT"
511 unlinkmany ${TESTFILE} $LIMIT
512 rm -f ${TESTFILE}_xxx
513 wait_delete_completed
515 USED=$(getquota -g $TSTUSR global curinodes)
516 [ $USED -ne 0 ] && quota_error g $TSTUSR \
517 "user quota isn't released after deletion"
520 resetquota -g $TSTUSR
522 run_test 2 "File hard limit (normal use and out of quota)"
526 local TIMER=$(($2 * 3 / 2))
531 trap cleanup_quota_test EXIT
533 $LFS setstripe $TESTFILE -c 1 -i 0
534 chown $TSTUSR.$TSTUSR $TESTFILE
536 echo "Write up to soft limit"
537 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
538 quota_error a $TSTUSR "write failure, but expect success"
539 OFFSET=$((LIMIT * 1024))
542 echo "Write to exceed soft limit"
543 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
544 quota_error a $TSTUSR "write failure, but expect success"
545 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
550 $SHOW_QUOTA_INFO_USER
551 $SHOW_QUOTA_INFO_GROUP
553 echo "Write before timer goes off"
554 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
555 quota_error a $TSTUSR "write failure, but expect success"
556 OFFSET=$((OFFSET + 1024))
559 echo "Sleep $TIMER seconds ..."
564 $SHOW_QUOTA_INFO_USER
565 $SHOW_QUOTA_INFO_GROUP
567 echo "Write after timer goes off"
568 # maybe cache write, ignore.
569 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
570 OFFSET=$((OFFSET + 1024))
572 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
573 quota_error a $TSTUSR "write success, but expect EDQUOT"
577 $SHOW_QUOTA_INFO_USER
578 $SHOW_QUOTA_INFO_GROUP
580 echo "Unlink file to stop timer"
582 wait_delete_completed
583 sync_all_data || true
587 $SHOW_QUOTA_INFO_USER
588 $SHOW_QUOTA_INFO_GROUP
590 $LFS setstripe $TESTFILE -c 1 -i 0
591 chown $TSTUSR.$TSTUSR $TESTFILE
594 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
595 quota_error a $TSTUSR "write failure, but expect success"
604 local TESTFILE=$DIR/$tdir/$tfile-0
606 set_ost_qtype "ug" || error "enable ost quota failed"
608 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
609 # make sure the system is clean
610 local USED=$(getquota -u $TSTUSR global curspace)
611 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
613 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
614 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
616 test_block_soft $TESTFILE $GRACE $LIMIT
617 resetquota -u $TSTUSR
619 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
620 TESTFILE=$DIR/$tdir/$tfile-1
621 # make sure the system is clean
622 USED=$(getquota -g $TSTUSR global curspace)
623 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
625 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
626 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
628 test_block_soft $TESTFILE $GRACE $LIMIT
629 resetquota -g $TSTUSR
632 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
634 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
637 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
642 local TIMER=$(($3 * 3 / 2))
645 trap cleanup_quota_test EXIT
647 echo "Create files to exceed soft limit"
648 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
649 quota_error a $TSTUSR "create failure, but expect success"
652 echo "Create file before timer goes off"
653 $RUNAS touch ${TESTFILE}_before ||
654 quota_error a $TSTUSR "failed create before timer expired," \
658 echo "Sleep $TIMER seconds ..."
663 $SHOW_QUOTA_INFO_USER
664 $SHOW_QUOTA_INFO_GROUP
666 echo "Create file after timer goes off"
667 # There is a window that space is accounted in the quota usage but
668 # hasn't been decreased from the pending write, if we acquire quota
669 # in this window, we'll acquire more than we needed.
670 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
672 $RUNAS touch ${TESTFILE}_after_3 &&
673 quota_error a $TSTUSR "create after timer expired," \
679 $SHOW_QUOTA_INFO_USER
680 $SHOW_QUOTA_INFO_GROUP
682 echo "Unlink files to stop timer"
683 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
684 wait_delete_completed
687 $RUNAS touch ${TESTFILE}_xxx ||
688 quota_error a $TSTUSR "touch after timer stop failure," \
698 local LIMIT=10 # inodes
699 local TESTFILE=$DIR/$tdir/$tfile-0
702 set_mdt_qtype "ug" || error "enable mdt quota failed"
704 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
705 # make sure the system is clean
706 local USED=$(getquota -u $TSTUSR global curinodes)
707 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
709 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
710 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
712 test_file_soft $TESTFILE $LIMIT $GRACE
713 resetquota -u $TSTUSR
715 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
716 # make sure the system is clean
717 USED=$(getquota -g $TSTUSR global curinodes)
718 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
720 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
721 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
722 TESTFILE=$DIR/$tdir/$tfile-1
724 test_file_soft $TESTFILE $LIMIT $GRACE
725 resetquota -g $TSTUSR
728 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
730 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
733 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
737 local GR_STR2="1000s"
739 local GR_STR4="1w2d3h4m5s"
741 local GR_STR6="1111111111111111"
743 wait_delete_completed
745 # test of valid grace strings handling
746 echo "Valid grace strings test"
747 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
748 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
749 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
750 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
752 # test of invalid grace strings handling
753 echo " Invalid grace strings test"
754 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
755 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
758 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
760 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
763 run_test 4b "Grace time strings handling"
765 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
767 local BLIMIT=10 # 10M
768 local ILIMIT=10 # 10 inodes
771 trap cleanup_quota_test EXIT
773 set_mdt_qtype "ug" || error "enable mdt quota failed"
774 set_ost_qtype "ug" || error "enable ost quota failed"
776 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
777 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
778 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
780 # make sure the system is clean
781 local USED=$(getquota -u $TSTUSR global curinodes)
782 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
783 USED=$(getquota -g $TSTUSR global curinodes)
784 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
785 USED=$(getquota -u $TSTUSR global curspace)
786 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
787 USED=$(getquota -g $TSTUSR global curspace)
788 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
790 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
791 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
792 error "create failure, expect success"
793 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
794 error "write failure, expect success"
796 echo "Chown files to $TSTUSR.$TSTUSR ..."
797 for i in `seq 0 $ILIMIT`; do
798 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
799 quota_error a $TSTUSR "chown failure, expect success"
803 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
806 resetquota -u $TSTUSR
807 resetquota -g $TSTUSR
809 run_test 5 "Chown & chgrp successfully even out of block/file quota"
811 # test dropping acquire request on master
814 trap cleanup_quota_test EXIT
816 # make sure the system is clean
817 local USED=$(getquota -u $TSTUSR global curspace)
818 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
820 # make sure no granted quota on ost
821 set_ost_qtype "ug" || error "enable ost quota failed"
822 resetquota -u $TSTUSR
824 # create file for $TSTUSR
825 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
826 $LFS setstripe $TESTFILE -c 1 -i 0
827 chown $TSTUSR.$TSTUSR $TESTFILE
829 # create file for $TSTUSR2
830 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
831 $LFS setstripe $TESTFILE2 -c 1 -i 0
832 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
834 # cache per-ID lock for $TSTUSR on slave
835 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
836 $RUNAS $DD of=$TESTFILE count=1 ||
837 error "write $TESTFILE failure, expect success"
838 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
839 error "write $TESTFILE2 failure, expect success"
841 sync_all_data || true
843 #define QUOTA_DQACQ 601
844 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
845 lustre_fail mds 0x513 601
847 # write to un-enforced ID ($TSTUSR2) should succeed
848 $RUNAS2 $DD of=$TESTFILE2 count=1 seek=1 oflag=sync conv=notrunc ||
849 error "write failure, expect success"
851 # write to enforced ID ($TSTUSR) in background, exceeding limit
852 # to make sure DQACQ is sent
853 $RUNAS $DD of=$TESTFILE count=2 seek=1 oflag=sync conv=notrunc &
856 echo "Sleep for $TIMEOUT"
859 # write should be blocked and never finished
860 if ! ps -p $DDPID > /dev/null 2>&1; then
862 error "write finished incorrectly!"
867 # no watchdog is triggered
868 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
869 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
870 /Service thread pid/ && /was inactive/ {
874 }' $TMP/lustre-log-${TESTNAME}.log)
875 [ -z "$watchdog" ] || error "$watchdog"
877 rm -f $TMP/lustre-log-${TESTNAME}.log
879 # write should continue & succeed
882 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
883 if [ $count -ge 120 ]; then
884 quota_error u $TSTUSR "dd not finished in $count secs"
887 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
892 resetquota -u $TSTUSR
894 run_test 6 "Test dropping acquire request on master"
896 # quota reintegration (global index)
898 local TESTFILE=$DIR/$tdir/$tfile
901 [ "$SLOW" = "no" ] && LIMIT=5
904 trap cleanup_quota_test EXIT
906 # make sure the system is clean
907 local USED=$(getquota -u $TSTUSR global curspace)
908 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
910 # make sure no granted quota on ost1
911 set_ost_qtype "ug" || error "enable ost quota failed"
912 resetquota -u $TSTUSR
913 set_ost_qtype "none" || error "disable ost quota failed"
915 local OSTUUID=$(ostuuid_from_index 0)
916 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
917 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
921 $LFS setstripe $TESTFILE -c 1 -i 0
922 chown $TSTUSR.$TSTUSR $TESTFILE
927 echo "Enable quota & set quota limit for $TSTUSR"
928 set_ost_qtype "ug" || error "enable ost quota failed"
929 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
932 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
934 wait_ost_reint "ug" || error "reintegration failed"
936 # hardlimit should have been fetched by slave during global
937 # reintegration, write will exceed quota
938 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
939 quota_error u $TSTUSR "write success, but expect EDQUOT"
942 resetquota -u $TSTUSR
944 run_test 7a "Quota reintegration (global index)"
946 # quota reintegration (slave index)
949 local TESTFILE=$DIR/$tdir/$tfile
952 trap cleanup_quota_test EXIT
954 # make sure the system is clean
955 local USED=$(getquota -u $TSTUSR global curspace)
956 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
958 # make sure no granted quota on ost1
959 set_ost_qtype "ug" || error "enable ost quota failed"
960 resetquota -u $TSTUSR
961 set_ost_qtype "none" || error "disable ost quota failed"
963 local OSTUUID=$(ostuuid_from_index 0)
964 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
965 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
969 $LFS setstripe $TESTFILE -c 1 -i 0
970 chown $TSTUSR.$TSTUSR $TESTFILE
972 # consume some space to make sure the granted space will not
973 # be released during reconciliation
974 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
975 error "consume space failure, expect success"
977 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
978 lustre_fail mds 0xa02
980 set_ost_qtype "ug" || error "enable ost quota failed"
981 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
983 # ignore the write error
984 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
986 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
990 echo "Restart ost to trigger reintegration..."
992 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
994 wait_ost_reint "ug" || error "reintegration failed"
996 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
997 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1000 resetquota -u $TSTUSR
1003 run_test 7b "Quota reintegration (slave index)"
1005 # quota reintegration (restart mds during reintegration)
1007 local LIMIT=20 # 20M
1008 local TESTFILE=$DIR/$tdir/$tfile
1010 [ "$SLOW" = "no" ] && LIMIT=5
1013 trap cleanup_quota_test EXIT
1015 # make sure the system is clean
1016 local USED=$(getquota -u $TSTUSR global curspace)
1017 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1019 set_ost_qtype "none" || error "disable ost quota failed"
1020 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
1022 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1023 lustre_fail ost 0xa03
1025 # enable ost quota to trigger reintegration
1026 set_ost_qtype "ug" || error "enable ost quota failed"
1034 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1036 wait_ost_reint "ug" || error "reintegration failed"
1038 # hardlimit should have been fetched by slave during global
1039 # reintegration, write will exceed quota
1040 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1041 quota_error u $TSTUSR "write success, but expect EDQUOT"
1044 resetquota -u $TSTUSR
1046 run_test 7c "Quota reintegration (restart mds during reintegration)"
1048 # run dbench with quota enabled
1050 local BLK_LIMIT="100g" #100G
1051 local FILE_LIMIT=1000000
1054 trap cleanup_quota_test EXIT
1056 set_mdt_qtype "ug" || error "enable mdt quota failed"
1057 set_ost_qtype "ug" || error "enable ost quota failed"
1059 echo "Set enough high limit for user: $TSTUSR"
1060 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1061 echo "Set enough high limit for group: $TSTUSR"
1062 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1065 [ "$SLOW" = "no" ] && duration=" -t 120"
1066 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1067 quota_error a $TSTUSR "dbench failed!"
1070 resetquota -u $TSTUSR
1071 resetquota -g $TSTUSR
1073 run_test 8 "Run dbench with quota enabled"
1075 # this check is just for test_9
1076 OST0_MIN=4900000 #4.67G
1078 check_whether_skip () {
1079 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1080 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1081 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1082 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1089 # run for fixing bug10707, it needs a big room. test for 64bit
1091 local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
1093 check_whether_skip && return 0
1096 trap cleanup_quota_test EXIT
1098 set_ost_qtype "ug" || error "enable ost quota failed"
1100 local TESTFILE="$DIR/$tdir/$tfile-0"
1101 local BLK_LIMIT=100G #100G
1102 local FILE_LIMIT=1000000
1104 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1106 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1108 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1110 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1111 "for group: $TSTUSR"
1112 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1114 quota_show_check a u $TSTUSR
1115 quota_show_check a g $TSTUSR
1117 echo "Create test file"
1118 $LFS setstripe $TESTFILE -c 1 -i 0
1119 chown $TSTUSR.$TSTUSR $TESTFILE
1121 log "Write the big file of 4.5G ..."
1122 $RUNAS $DD of=$TESTFILE count=$filesize ||
1123 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1129 resetquota -u $TSTUSR
1130 resetquota -g $TSTUSR
1135 run_test 9 "Block limit larger than 4GB (b10707)"
1138 local TESTFILE=$DIR/$tdir/$tfile
1141 trap cleanup_quota_test EXIT
1143 # set limit to root user should fail
1144 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1145 error "set limit for root user successfully, expect failure"
1146 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1147 error "set limit for root group successfully, expect failure"
1149 # root user can overrun quota
1150 set_ost_qtype "ug" || "enable ost quota failed"
1152 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
1153 quota_show_check b u $TSTUSR
1155 $LFS setstripe $TESTFILE -c 1
1156 chown $TSTUSR.$TSTUSR $TESTFILE
1158 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1159 error "write failure, expect success"
1162 resetquota -u $TSTUSR
1164 run_test 10 "Test quota for root user"
1167 local TESTFILE=$DIR/$tdir/$tfile
1169 trap cleanup_quota_test EXIT
1171 set_mdt_qtype "ug" || "enable mdt quota failed"
1172 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
1177 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1178 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1181 local USED=$(getquota -u $TSTUSR global curinodes)
1182 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1185 resetquota -u $TSTUSR
1187 run_test 11 "Chown/chgrp ignores quota"
1190 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1192 local blimit=22 # 22M
1193 local blk_cnt=$((blimit - 5))
1194 local TESTFILE0="$DIR/$tdir/$tfile"-0
1195 local TESTFILE1="$DIR/$tdir/$tfile"-1
1198 trap cleanup_quota_test EXIT
1200 set_ost_qtype "u" || "enable ost quota failed"
1201 quota_show_check b u $TSTUSR
1203 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
1205 $LFS setstripe $TESTFILE0 -c 1 -i 0
1206 $LFS setstripe $TESTFILE1 -c 1 -i 1
1207 chown $TSTUSR.$TSTUSR $TESTFILE0
1208 chown $TSTUSR.$TSTUSR $TESTFILE1
1210 echo "Write to ost0..."
1211 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1212 quota_error a $TSTUSR "dd failed"
1214 echo "Write to ost1..."
1215 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1216 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1218 echo "Free space from ost0..."
1220 wait_delete_completed
1221 sync_all_data || true
1223 echo "Write to ost1 after space freed from ost0..."
1224 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1225 quota_error a $TSTUSR "rebalancing failed"
1228 resetquota -u $TSTUSR
1230 run_test 12 "Block quota rebalancing"
1233 local TESTFILE=$DIR/$tdir/$tfile
1234 # the name of osp on ost1 name is MDT0000-osp-OST0000
1235 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1238 trap cleanup_quota_test EXIT
1240 set_ost_qtype "u" || "enable ost quota failed"
1241 quota_show_check b u $TSTUSR
1243 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1244 $LFS setstripe $TESTFILE -c 1 -i 0
1245 chown $TSTUSR.$TSTUSR $TESTFILE
1247 # clear the locks in cache first
1248 do_facet ost1 $LCTL set_param -n $procf=clear
1249 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1250 [ $nlock -eq 0 ] || error "$nlock cached locks"
1252 # write to acquire the per-ID lock
1253 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1254 quota_error a $TSTUSR "dd failed"
1256 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1257 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1259 # clear quota doesn't trigger per-ID lock cancellation
1260 resetquota -u $TSTUSR
1261 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1262 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1264 # clear the per-ID lock
1265 do_facet ost1 $LCTL set_param -n $procf=clear
1266 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1267 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1269 # spare quota should be released
1270 local OSTUUID=$(ostuuid_from_index 0)
1271 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1272 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1273 [ $limit -le $space ] ||
1274 error "spare quota isn't released, limit:$limit, space:$space"
1278 run_test 13 "Cancel per-ID lock in the LRU list"
1281 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1283 wait_delete_completed
1284 sync_all_data || true
1287 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1288 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1289 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1290 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1291 resetquota -u $TSTUSR
1294 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1295 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1296 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1297 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1298 resetquota -g $TSTUSR
1300 run_test 15 "Set over 4T block quota"
1304 local BLKS=1 # 1M less than limit
1305 local TESTFILE=$DIR/$tdir/$tfile
1308 trap cleanup_quota_test EXIT
1310 # make sure the system is clean
1311 local USED=$(getquota -u $TSTUSR global curspace)
1312 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1314 set_ost_qtype "ug" || error "enable ost quota failed"
1315 # make sure no granted quota on ost
1316 resetquota -u $TSTUSR
1317 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1319 quota_show_check b u $TSTUSR
1321 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1322 lustre_fail mds 0xa04 $err_code
1324 # write in background
1325 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1329 # write should be blocked and never finished
1330 if ! ps -p $DDPID > /dev/null 2>&1; then
1332 quota_error u $TSTUSR "write finished incorrectly!"
1340 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1342 if [ $count -gt $timeout ]; then
1343 quota_error u $TSTUSR "dd is not finished!"
1348 sync; sync_all_data || true
1350 USED=$(getquota -u $TSTUSR global curspace)
1351 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1352 "Used space(${USED}K) is less than ${BLKS}M"
1355 resetquota -u $TSTUSR
1358 # DQACQ return recoverable error
1360 echo "DQACQ return -ENOLCK"
1362 test_17sub 37 || error "Handle -ENOLCK failed"
1364 echo "DQACQ return -EAGAIN"
1366 test_17sub 11 || error "Handle -EAGAIN failed"
1368 echo "DQACQ return -ETIMEDOUT"
1369 #define ETIMEDOUT 110
1370 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1372 echo "DQACQ return -ENOTCONN"
1373 #define ENOTCONN 107
1374 test_17sub 107 || error "Handle -ENOTCONN failed"
1377 run_test 17 "DQACQ return recoverable error"
1381 local blimit="200m" # 200M
1382 local TESTFILE="$DIR/$tdir/$tfile"
1385 trap cleanup_quota_test EXIT
1387 set_ost_qtype "u" || error "enable ost quota failed"
1388 log "User quota (limit: $blimit)"
1389 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
1390 quota_show_check b u $TSTUSR
1392 $LFS setstripe $TESTFILE -i 0 -c 1
1393 chown $TSTUSR.$TSTUSR $TESTFILE
1395 local timeout=$(sysctl -n lustre.timeout)
1397 if [ $io_type = "directio" ]; then
1398 log "Write 100M (directio) ..."
1399 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1401 log "Write 100M (buffered) ..."
1402 $RUNAS $DD of=$TESTFILE count=100 &
1406 replay_barrier $SINGLEMDS
1407 log "Fail mds for $((2 * timeout)) seconds"
1408 fail $SINGLEMDS $((2 * timeout))
1411 if at_is_enabled; then
1412 timeout=$(at_max_get mds)
1414 timeout=$(lctl get_param -n timeout)
1418 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1419 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1420 log "it took $count second"
1425 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1427 cancel_lru_locks mdc
1428 cancel_lru_locks osc
1431 local testfile_size=$(stat -c %s $TESTFILE)
1432 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1433 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1434 "got ${testfile_size}. Verifying file failed!"
1437 resetquota -u $TSTUSR
1440 # test when mds does failover, the ost still could work well
1441 # this test shouldn't trigger watchdog b=14840
1444 test_18_sub directio
1446 # check if watchdog is triggered
1447 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1448 local watchdog=$(awk '/test 18b/ {start = 1;}
1449 /Service thread pid/ && /was inactive/ {
1453 }' $TMP/lustre-log-${TESTNAME}.log)
1454 [ -z "$watchdog" ] || error "$watchdog"
1455 rm -f $TMP/lustre-log-${TESTNAME}.log
1457 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1461 local TESTFILE=$DIR/$tdir/$tfile
1464 trap cleanup_quota_test EXIT
1466 set_ost_qtype "ug" || error "enable ost quota failed"
1468 # bind file to a single OST
1469 $LFS setstripe -c 1 $TESTFILE
1470 chown $TSTUSR.$TSTUSR $TESTFILE
1472 echo "Set user quota (limit: "$blimit"M)"
1473 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1474 quota_show_check b u $TSTUSR
1475 echo "Update quota limits"
1476 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1477 quota_show_check b u $TSTUSR
1479 # first wirte might be cached
1480 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1481 cancel_lru_locks osc
1483 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1484 quota_error u $TSTUSR "Write success, expect failure"
1488 resetquota -u $TSTUSR
1490 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1492 test_20() { # b15754
1493 local LSTR=(2g 1t 4k 3m) # limits strings
1495 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1497 resetquota -u $TSTUSR
1499 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1500 $MOUNT || error "could not set quota limits"
1501 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1502 --inode-softlimit ${LSTR[2]} \
1503 --inode-hardlimit ${LSTR[3]} \
1504 $MOUNT || error "could not set quota limits"
1506 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1507 error "bsoftlimit was not set properly"
1508 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1509 error "bhardlimit was not set properly"
1510 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1511 error "isoftlimit was not set properly"
1512 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1513 error "ihardlimit was not set properly"
1515 resetquota -u $TSTUSR
1517 run_test 20 "Test if setquota specifiers work properly (b15754)"
1524 local time=$(($(date +%s) + seconds))
1525 while [ $(date +%s) -lt $time ]; do
1526 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1530 # run for fixing bug16053, setquota shouldn't fail when writing and
1531 # deleting are happening
1533 local TESTFILE="$DIR/$tdir/$tfile"
1534 local BLIMIT=10 # 10G
1535 local ILIMIT=1000000
1538 trap cleanup_quota_test EXIT
1540 set_ost_qtype "ug" || error "Enable ost quota failed"
1542 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1543 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
1544 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1545 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
1547 # repeat writing on a 1M file
1548 test_21_sub ${TESTFILE}_1 1 30 &
1550 # repeat writing on a 128M file
1551 test_21_sub ${TESTFILE}_2 128 30 &
1554 local time=$(($(date +%s) + 30))
1556 while [ $(date +%s) -lt $time ]; do
1557 log "Set quota for $i times"
1558 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1559 -I $((ILIMIT + i)) $MOUNT ||
1560 error "Set user quota failed"
1561 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1562 -I $((ILIMIT + i)) $MOUNT ||
1563 error "Set group quota failed"
1570 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1572 if [ $count -gt 60 ]; then
1573 quota_error a $TSTUSR "dd should be finished!"
1577 echo "(dd_pid=$DDPID1, time=$count)successful"
1581 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1583 if [ $count -gt 60 ]; then
1584 quota_error a $TSTUSR "dd should be finished!"
1588 echo "(dd_pid=$DDPID2, time=$count)successful"
1591 resetquota -u $TSTUSR
1592 resetquota -g $TSTUSR
1594 run_test 21 "Setquota while writing & deleting (b16053)"
1596 # enable/disable quota enforcement permanently
1598 echo "Set both mdt & ost quota type as ug"
1599 set_mdt_qtype "ug" || error "enable mdt quota failed"
1600 set_ost_qtype "ug" || error "enable ost quota failed"
1607 echo "Verify if quota is enabled"
1608 local qtype=$(mdt_quota_type)
1609 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1610 qtype=$(ost_quota_type)
1611 [ $qtype != "ug" ] && error "ost quota setting is lost"
1613 echo "Set both mdt & ost quota type as none"
1614 set_mdt_qtype "none" || error "disable mdt quota failed"
1615 set_ost_qtype "none" || error "disable ost quota failed"
1622 echo "Verify if quota is disabled"
1623 qtype=$(mdt_quota_type)
1624 [ $qtype != "none" ] && error "mdt quota setting is lost"
1625 qtype=$(ost_quota_type)
1626 [ $qtype != "none" ] && error "ost quota setting is lost"
1630 run_test 22 "enable/disable quota by 'lctl conf_param'"
1633 local TESTFILE="$DIR/$tdir/$tfile"
1637 trap cleanup_quota_test EXIT
1639 set_ost_qtype "ug" || error "Enable ost quota failed"
1642 log "User quota (limit: $LIMIT MB)"
1643 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
1644 quota_show_check b u $TSTUSR
1646 $LFS setstripe $TESTFILE -c 1 -i 0
1647 chown $TSTUSR.$TSTUSR $TESTFILE
1649 log "Step1: trigger EDQUOT with O_DIRECT"
1650 log "Write half of file"
1651 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1652 quota_error u $TSTUSR "(1) Write failure, expect success." \
1654 log "Write out of block quota ..."
1655 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1656 oflag=direct conv=notrunc &&
1657 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1661 log "Step2: rewrite should succeed"
1662 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1663 quota_error u $TSTUSR "(3) Write failure, expect success." \
1669 local OST0_UUID=$(ostuuid_from_index 0)
1670 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1671 [ $OST0_QUOTA_USED -ne 0 ] &&
1672 ($SHOW_QUOTA_USER; \
1673 quota_error u $TSTUSR "quota isn't released")
1675 resetquota -u $TSTUSR
1679 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1680 check_whether_skip && return 0
1681 log "run for 4MB test file"
1684 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1685 check_whether_skip && return 0
1686 log "run for 40MB test file"
1689 run_test 23 "Quota should be honored with directIO (b16125)"
1693 local TESTFILE="$DIR/$tdir/$tfile"
1696 trap cleanup_quota_test EXIT
1698 set_ost_qtype "ug" || error "enable ost quota failed"
1700 # bind file to a single OST
1701 $LFS setstripe -c 1 $TESTFILE
1702 chown $TSTUSR.$TSTUSR $TESTFILE
1704 echo "Set user quota (limit: "$blimit"M)"
1705 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1707 # overrun quota by root user
1708 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1709 error "write failure, expect success"
1710 cancel_lru_locks osc
1711 sync_all_data || true
1713 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1716 resetquota -u $TSTUSR
1718 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1720 test_27a() { # b19612
1721 $LFS quota $TSTUSR $DIR &&
1722 error "lfs succeeded with no type, but should have failed"
1723 $LFS setquota $TSTUSR $DIR &&
1724 error "lfs succeeded with no type, but should have failed"
1727 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1729 test_27b() { # b20200
1730 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1731 error "lfs setquota failed with uid argument"
1732 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1733 error "lfs stequota failed with gid argument"
1734 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1735 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1736 resetquota -u $TSTUSR
1737 resetquota -g $TSTUSR
1740 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1745 local TESTFILE="$DIR/$tdir/$tfile"
1749 trap cleanup_quota_test EXIT
1751 set_ost_qtype "u" || error "enable ost quota failed"
1753 $LFS setstripe $TESTFILE -i 0 -c 1
1754 chown $TSTUSR.$TSTUSR $TESTFILE
1756 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
1757 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
1758 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
1759 cancel_lru_locks osc
1761 $LFS setquota -u $TSTUSR -B 0 $DIR
1762 # over-quota flag has not yet settled since we do not trigger async
1763 # events based on grace time period expiration
1765 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
1766 cancel_lru_locks osc
1767 # now over-quota flag should be settled and further writes should fail
1769 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
1770 error "grace times were reset"
1773 resetquota -u $TSTUSR
1774 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1777 run_test 30 "Hard limit updates should not reset grace times"
1779 # basic usage tracking for user & group
1781 local INODES=10 # 10 files
1782 local BLK_CNT=2 # of 2M each
1783 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
1786 trap cleanup_quota_test EXIT
1788 # make sure the system is clean
1789 local USED=$(getquota -u $TSTID global curspace)
1791 error "Used space ($USED) for user $TSTID isn't 0."
1792 USED=$(getquota -g $TSTID global curspace)
1794 error "Used space ($USED) for group $TSTID isn't 0."
1796 echo "Write files..."
1797 for i in `seq 0 $INODES`; do
1798 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
1799 error "write failed"
1800 echo "Iteration $i/$INODES completed"
1802 cancel_lru_locks osc
1803 sync; sync_all_data || true
1805 echo "Verify disk usage after write"
1806 USED=$(getquota -u $TSTID global curspace)
1807 [ $USED -lt $TOTAL_BLKS ] &&
1808 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
1809 USED=$(getquota -g $TSTID global curspace)
1810 [ $USED -lt $TOTAL_BLKS ] &&
1811 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
1813 echo "Verify inode usage after write"
1814 USED=$(getquota -u $TSTID global curinodes)
1815 [ $USED -lt $INODES ] &&
1816 error "Used inode for user $TSTID is $USED, expected $INODES"
1817 USED=$(getquota -g $TSTID global curinodes)
1818 [ $USED -lt $INODES ] &&
1819 error "Used inode for group $TSTID is $USED, expected $INODES"
1823 echo "Verify disk usage after delete"
1824 USED=$(getquota -u $TSTID global curspace)
1825 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
1826 USED=$(getquota -u $TSTID global curinodes)
1827 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
1828 USED=$(getquota -g $TSTID global curspace)
1829 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
1830 USED=$(getquota -g $TSTID global curinodes)
1831 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
1833 run_test 33 "Basic usage tracking for user & group"
1835 # usage transfer test for user & group
1837 local BLK_CNT=2 # 2MB
1840 trap cleanup_quota_test EXIT
1842 # make sure the system is clean
1843 local USED=$(getquota -u $TSTID global curspace)
1844 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
1845 USED=$(getquota -g $TSTID global curspace)
1846 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
1848 echo "Write file..."
1849 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1850 error "write failed"
1851 cancel_lru_locks osc
1852 sync; sync_all_data || true
1854 echo "chown the file to user $TSTID"
1855 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
1857 echo "Wait for setattr on objects finished..."
1858 wait_delete_completed
1860 BLK_CNT=$((BLK_CNT * 1024))
1862 echo "Verify disk usage for user $TSTID"
1863 USED=$(getquota -u $TSTID global curspace)
1864 [ $USED -lt $BLK_CNT ] &&
1865 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
1866 USED=$(getquota -u $TSTID global curinodes)
1868 error "Used inodes for user $TSTID is $USED, expected 1"
1870 echo "chgrp the file to group $TSTID"
1871 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
1873 echo "Wait for setattr on objects finished..."
1874 wait_delete_completed
1876 echo "Verify disk usage for group $TSTID"
1877 USED=$(getquota -g $TSTID global curspace)
1878 [ $USED -ge $BLK_CNT ] ||
1879 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
1880 USED=$(getquota -g $TSTID global curinodes)
1882 error "Used inodes for group $TSTID is $USED, expected 1"
1886 run_test 34 "Usage transfer for user & group"
1888 # usage is still accessible across restart
1890 local BLK_CNT=2 # 2 MB
1893 trap cleanup_quota_test EXIT
1895 echo "Write file..."
1896 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1897 error "write failed"
1898 cancel_lru_locks osc
1899 sync; sync_all_data || true
1901 echo "Save disk usage before restart"
1902 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
1903 [ $ORIG_USR_SPACE -eq 0 ] &&
1904 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
1905 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
1906 [ $ORIG_USR_INODES -eq 0 ] &&
1907 error "Used inodes for user $TSTID is 0, expected 1"
1908 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
1909 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
1910 [ $ORIG_GRP_SPACE -eq 0 ] &&
1911 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
1912 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
1913 [ $ORIG_GRP_INODES -eq 0 ] &&
1914 error "Used inodes for group $TSTID is 0, expected 1"
1915 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
1918 local ORIG_REFORMAT=$REFORMAT
1920 cleanup_and_setup_lustre
1921 REFORMAT=$ORIG_REFORMAT
1924 echo "Verify disk usage after restart"
1925 local USED=$(getquota -u $TSTID global curspace)
1926 [ $USED -eq $ORIG_USR_SPACE ] ||
1927 error "Used space for user $TSTID changed from " \
1928 "$ORIG_USR_SPACE to $USED"
1929 USED=$(getquota -u $TSTID global curinodes)
1930 [ $USED -eq $ORIG_USR_INODES ] ||
1931 error "Used inodes for user $TSTID changed from " \
1932 "$ORIG_USR_INODES to $USED"
1933 USED=$(getquota -g $TSTID global curspace)
1934 [ $USED -eq $ORIG_GRP_SPACE ] ||
1935 error "Used space for group $TSTID changed from " \
1936 "$ORIG_GRP_SPACE to $USED"
1937 USED=$(getquota -g $TSTID global curinodes)
1938 [ $USED -eq $ORIG_GRP_INODES ] ||
1939 error "Used inodes for group $TSTID changed from " \
1940 "$ORIG_GRP_INODES to $USED"
1942 # check if the vfs_dq_init() is called before writing
1943 echo "Append to the same file..."
1944 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
1945 error "write failed"
1946 cancel_lru_locks osc
1947 sync; sync_all_data || true
1949 echo "Verify space usage is increased"
1950 USED=$(getquota -u $TSTID global curspace)
1951 [ $USED -gt $ORIG_USR_SPACE ] ||
1952 error "Used space for user $TSTID isn't increased" \
1953 "orig:$ORIG_USR_SPACE, now:$USED"
1954 USED=$(getquota -g $TSTID global curspace)
1955 [ $USED -gt $ORIG_GRP_SPACE ] ||
1956 error "Used space for group $TSTID isn't increased" \
1957 "orig:$ORIG_GRP_SPACE, now:$USED"
1961 run_test 35 "Usage is still accessible across reboot"
1963 # test migrating old amdin quota files (in Linux quota file format v2) into new
1964 # quota global index (in IAM format)
1966 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
1967 skip "skipping migration test" && return
1969 # get the mdt0 device name
1970 local mdt0_node=$(facet_active_host $SINGLEMDS)
1971 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
1976 echo "Copy admin quota files into MDT0..."
1977 local mntpt=$(facet_mntpt $SINGLEMDS)
1978 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
1980 if ! do_node $mdt0_node test -b $mdt0_fstype; then
1983 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
1984 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
1985 do_node $mdt0_node mkdir $mntpt/OBJECTS
1986 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
1987 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
1988 do_node $mdt0_node umount -f $mntpt
1993 echo "Verify global limits..."
1997 local proc="qmt.*.md-0x0.glb-usr"
1998 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
1999 [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
2000 limit=$(getquota -u 1 global isoftlimit)
2001 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2002 limit=$(getquota -u 1 global ihardlimit)
2003 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2005 proc="qmt.*.md-0x0.glb-grp"
2006 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2007 [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
2008 limit=$(getquota -g 1 global isoftlimit)
2009 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2010 limit=$(getquota -g 1 global ihardlimit)
2011 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2013 proc=" qmt.*.dt-0x0.glb-usr"
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 -u 60001 global bsoftlimit)
2017 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2018 limit=$(getquota -u 60001 global bhardlimit)
2019 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2021 proc="qmt.*.dt-0x0.glb-grp"
2022 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2023 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2024 limit=$(getquota -g 60001 global bsoftlimit)
2025 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2026 limit=$(getquota -g 60001 global bhardlimit)
2027 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2033 run_test 36 "Migrate old admin files into new global indexes"
2037 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2042 complete $(basename $0) $SECONDS
2043 check_and_cleanup_lustre
2044 export USE_OFD="$USE_OFD_OLD"
2045 export LOAD_MODULES_REMOTE="$LOAD_MODULES_REMOTE_OLD"
2046 export QUOTA_AUTO=$QUOTA_AUTO_OLD