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 DD="dd if=/dev/zero bs=1M"
106 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
107 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
108 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
109 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
111 # clear quota limits for a user or a group
112 # usage: resetquota -u username
113 # resetquota -g groupname
116 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
117 [ "$1" != "-u" -a "$1" != "-g" ] &&
118 error "resetquota: wrong specifier $1 passed"
120 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
121 # The usage should be 0 now, enforce quota to trigger quota
122 # release for each slave, sleep 3 seconds to wait for the release
123 # done, then we can make sure granted quota for each slave is 0.
124 $LFS setquota "$1" "$2" -b 0 -B 1 -i 0 -I 1 $MOUNT
126 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
133 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
134 $LFS quota -v -u $LOCAL_ID $DIR
135 log "Files for user ($LOCAL_ID):"
136 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
140 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
141 $LFS quota -v -u $LOCAL_ID $DIR
142 log "Files for group ($LOCAL_ID):"
143 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
144 xargs stat 2>/dev/null)
160 # get quota for a user or a group
161 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
162 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
168 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
169 [ "$1" != "-u" -a "$1" != "-g" ] &&
170 error "getquota: wrong u/g specifier $1 passed"
183 *) error "unknown quota parameter $4";;
186 [ "$uuid" = "global" ] && uuid=$DIR
188 $LFS quota -v "$1" "$2" $DIR |
189 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
190 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
195 # usage: set_mdt_qtype ug|u|g|none
198 local varsvc=${SINGLEMDS}_svc
199 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
200 if $(facet_up $SINGLEMDS); then
201 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
202 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" "$qtype" ||
209 # usage: set_ost_quota_type ug|u|g|none
213 local osts=$(get_facets OST)
214 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
215 # we have to make sure each OST received config changes
216 for ost in ${osts//,/ }; do
218 if $(facet_up $ost); then
219 wait_update_facet $ost "$LCTL get_param -n \
220 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" \
227 wait_reintegration() {
230 local result="glb[1],slv[1],reint[0]"
233 if [ $ntype == "mdt" ]; then
234 varsvc=${SINGLEMDS}_svc
235 if $(facet_up $SINGLEMDS); then
236 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
237 osd-$FSTYPE.${!varsvc}.quota_slave.info |
238 grep "$qtype" | awk '{ print \\\$3 }'" "$result" ||
242 local osts=$(get_facets OST)
243 for ost in ${osts//,/ }; do
245 if $(facet_up $ost); then
246 wait_update_facet $ost "$LCTL get_param -n \
247 osd-$FSTYPE.${!varsvc}.quota_slave.info |
248 grep "$qtype" | awk '{ print \\\$3 }'" \
249 "$result" || return 1
259 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
260 wait_reintegration "mdt" "user" || return 1
263 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
264 wait_reintegration "mdt" "group" || return 1
272 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
273 wait_reintegration "ost" "user" || return 1
276 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
277 wait_reintegration "ost" "group" || return 1
284 wait_delete_completed
285 echo "Creating test directory"
288 # always clear fail_loc in case of fail_loc isn't cleared
289 # properly when previous test failed
290 lustre_fail mds_ost 0
293 cleanup_quota_test() {
295 echo "Delete files..."
297 echo "Wait for unlink objects finished..."
298 wait_delete_completed
299 sync_all_data || true
308 $LFS quota -v -$ug $qid $DIR
310 if [ "$bf" == "a" -o "$bf" == "b" ]; then
311 usage=$(getquota -$ug $qid global curspace)
312 if [ -z $usage ]; then
313 quota_error $ug $qid \
314 "Query block quota failed ($ug:$qid)."
316 [ $usage -ne 0 ] && quota_log $ug $qid \
317 "Block quota isn't 0 ($ug:$qid:$usage)."
321 if [ "$bf" == "a" -o "$bf" == "f" ]; then
322 usage=$(getquota -$ug $qid global curinodes)
323 if [ -z $usage ]; then
324 quota_error $ug $qid \
325 "Query file quota failed ($ug:$qid)."
327 [ $usage -ne 0 ] && quota_log $ug $qid \
328 "File quota isn't 0 ($ug:$qid:$usage)."
335 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
339 test_quota_performance() {
340 local TESTFILE="$DIR/$tdir/$tfile-0"
341 local size=$1 # in MB
342 local stime=$(date +%s)
343 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
344 quota_error u $TSTUSR "write failure"
345 local etime=$(date +%s)
346 delta=$((etime - stime))
347 if [ $delta -gt 0 ]; then
348 rate=$((size * 1024 / delta))
349 [ $rate -gt 1024 ] ||
350 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
355 # test basic quota performance b=21696
358 [ "$SLOW" = "no" ] && MB=10
360 local free_space=$(lfs df | grep "filesystem summary" | \
362 [ $free_space -le $((MB * 1024)) ] &&
363 skip "not enough space ${free_space} KB, " \
364 "required $((MB * 1024)) KB" && return
366 trap cleanup_quota_test EXIT
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
816 trap cleanup_quota_test EXIT
818 # make sure the system is clean
819 local USED=$(getquota -u $TSTUSR global curspace)
820 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
822 # make sure no granted quota on ost
823 set_ost_qtype "ug" || error "enable ost quota failed"
824 resetquota -u $TSTUSR
826 # create file for $TSTUSR
827 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
828 $LFS setstripe $TESTFILE -c 1 -i 0
829 chown $TSTUSR.$TSTUSR $TESTFILE
831 # create file for $TSTUSR2
832 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
833 $LFS setstripe $TESTFILE2 -c 1 -i 0
834 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
836 # cache per-ID lock for $TSTUSR on slave
837 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
838 $RUNAS $DD of=$TESTFILE count=1 ||
839 error "write $TESTFILE failure, expect success"
840 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
841 error "write $TESTFILE2 failure, expect success"
843 sync_all_data || true
845 #define QUOTA_DQACQ 601
846 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
847 lustre_fail mds 0x513 601
849 # write to un-enforced ID ($TSTUSR2) should succeed
850 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
851 error "write failure, expect success"
853 # write to enforced ID ($TSTUSR) in background, exceeding limit
854 # to make sure DQACQ is sent
855 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
858 echo "Sleep for $TIMEOUT"
861 # write should be blocked and never finished
862 if ! ps -p $DDPID > /dev/null 2>&1; then
864 error "write finished incorrectly!"
869 # no watchdog is triggered
870 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
871 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
872 /Service thread pid/ && /was inactive/ {
876 }' $TMP/lustre-log-${TESTNAME}.log)
877 [ -z "$watchdog" ] || error "$watchdog"
879 rm -f $TMP/lustre-log-${TESTNAME}.log
881 # write should continue & succeed
884 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
885 if [ $count -ge 120 ]; then
886 quota_error u $TSTUSR "dd not finished in $count secs"
889 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
894 resetquota -u $TSTUSR
896 run_test 6 "Test dropping acquire request on master"
898 # quota reintegration (global index)
900 local TESTFILE=$DIR/$tdir/$tfile
903 [ "$SLOW" = "no" ] && LIMIT=5
906 trap cleanup_quota_test EXIT
908 # make sure the system is clean
909 local USED=$(getquota -u $TSTUSR global curspace)
910 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
912 # make sure no granted quota on ost1
913 set_ost_qtype "ug" || error "enable ost quota failed"
914 resetquota -u $TSTUSR
915 set_ost_qtype "none" || error "disable ost quota failed"
917 local OSTUUID=$(ostuuid_from_index 0)
918 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
919 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
923 $LFS setstripe $TESTFILE -c 1 -i 0
924 chown $TSTUSR.$TSTUSR $TESTFILE
929 echo "Enable quota & set quota limit for $TSTUSR"
930 set_ost_qtype "ug" || error "enable ost quota failed"
931 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
934 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
936 wait_ost_reint "ug" || error "reintegration failed"
938 # hardlimit should have been fetched by slave during global
939 # reintegration, write will exceed quota
940 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
941 quota_error u $TSTUSR "write success, but expect EDQUOT"
944 resetquota -u $TSTUSR
946 run_test 7a "Quota reintegration (global index)"
948 # quota reintegration (slave index)
951 local TESTFILE=$DIR/$tdir/$tfile
954 trap cleanup_quota_test EXIT
956 # make sure the system is clean
957 local USED=$(getquota -u $TSTUSR global curspace)
958 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
960 # make sure no granted quota on ost1
961 set_ost_qtype "ug" || error "enable ost quota failed"
962 resetquota -u $TSTUSR
963 set_ost_qtype "none" || error "disable ost quota failed"
965 local OSTUUID=$(ostuuid_from_index 0)
966 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
967 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
971 $LFS setstripe $TESTFILE -c 1 -i 0
972 chown $TSTUSR.$TSTUSR $TESTFILE
974 # consume some space to make sure the granted space will not
975 # be released during reconciliation
976 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
977 error "consume space failure, expect success"
979 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
980 lustre_fail mds 0xa02
982 set_ost_qtype "ug" || error "enable ost quota failed"
983 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
985 # ignore the write error
986 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
988 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
992 echo "Restart ost to trigger reintegration..."
994 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
996 wait_ost_reint "ug" || error "reintegration failed"
998 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
999 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1002 resetquota -u $TSTUSR
1005 run_test 7b "Quota reintegration (slave index)"
1007 # quota reintegration (restart mds during reintegration)
1009 local LIMIT=20 # 20M
1010 local TESTFILE=$DIR/$tdir/$tfile
1012 [ "$SLOW" = "no" ] && LIMIT=5
1015 trap cleanup_quota_test EXIT
1017 # make sure the system is clean
1018 local USED=$(getquota -u $TSTUSR global curspace)
1019 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1021 set_ost_qtype "none" || error "disable ost quota failed"
1022 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
1024 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1025 lustre_fail ost 0xa03
1027 # enable ost quota to trigger reintegration
1028 set_ost_qtype "ug" || error "enable ost quota failed"
1036 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1038 wait_ost_reint "ug" || error "reintegration failed"
1040 # hardlimit should have been fetched by slave during global
1041 # reintegration, write will exceed quota
1042 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1043 quota_error u $TSTUSR "write success, but expect EDQUOT"
1046 resetquota -u $TSTUSR
1048 run_test 7c "Quota reintegration (restart mds during reintegration)"
1050 # run dbench with quota enabled
1052 local BLK_LIMIT="100g" #100G
1053 local FILE_LIMIT=1000000
1056 trap cleanup_quota_test EXIT
1058 set_mdt_qtype "ug" || error "enable mdt quota failed"
1059 set_ost_qtype "ug" || error "enable ost quota failed"
1061 echo "Set enough high limit for user: $TSTUSR"
1062 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1063 echo "Set enough high limit for group: $TSTUSR"
1064 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1067 [ "$SLOW" = "no" ] && duration=" -t 120"
1068 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1069 quota_error a $TSTUSR "dbench failed!"
1072 resetquota -u $TSTUSR
1073 resetquota -g $TSTUSR
1075 run_test 8 "Run dbench with quota enabled"
1077 # this check is just for test_9
1078 OST0_MIN=4900000 #4.67G
1080 check_whether_skip () {
1081 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1082 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1083 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1084 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1091 # run for fixing bug10707, it needs a big room. test for 64bit
1093 local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
1095 check_whether_skip && return 0
1098 trap cleanup_quota_test EXIT
1100 set_ost_qtype "ug" || error "enable ost quota failed"
1102 local TESTFILE="$DIR/$tdir/$tfile-0"
1103 local BLK_LIMIT=100G #100G
1104 local FILE_LIMIT=1000000
1106 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1108 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1110 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1112 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1113 "for group: $TSTUSR"
1114 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1116 quota_show_check a u $TSTUSR
1117 quota_show_check a g $TSTUSR
1119 echo "Create test file"
1120 $LFS setstripe $TESTFILE -c 1 -i 0
1121 chown $TSTUSR.$TSTUSR $TESTFILE
1123 log "Write the big file of 4.5G ..."
1124 $RUNAS $DD of=$TESTFILE count=$filesize ||
1125 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1131 resetquota -u $TSTUSR
1132 resetquota -g $TSTUSR
1137 run_test 9 "Block limit larger than 4GB (b10707)"
1140 local TESTFILE=$DIR/$tdir/$tfile
1143 trap cleanup_quota_test EXIT
1145 # set limit to root user should fail
1146 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1147 error "set limit for root user successfully, expect failure"
1148 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1149 error "set limit for root group successfully, expect failure"
1151 # root user can overrun quota
1152 set_ost_qtype "ug" || "enable ost quota failed"
1154 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
1155 quota_show_check b u $TSTUSR
1157 $LFS setstripe $TESTFILE -c 1
1158 chown $TSTUSR.$TSTUSR $TESTFILE
1160 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1161 error "write failure, expect success"
1164 resetquota -u $TSTUSR
1166 run_test 10 "Test quota for root user"
1169 local TESTFILE=$DIR/$tdir/$tfile
1171 trap cleanup_quota_test EXIT
1173 set_mdt_qtype "ug" || "enable mdt quota failed"
1174 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
1179 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1180 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1183 local USED=$(getquota -u $TSTUSR global curinodes)
1184 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1187 resetquota -u $TSTUSR
1189 run_test 11 "Chown/chgrp ignores quota"
1192 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1194 local blimit=22 # 22M
1195 local blk_cnt=$((blimit - 5))
1196 local TESTFILE0="$DIR/$tdir/$tfile"-0
1197 local TESTFILE1="$DIR/$tdir/$tfile"-1
1200 trap cleanup_quota_test EXIT
1202 set_ost_qtype "u" || "enable ost quota failed"
1203 quota_show_check b u $TSTUSR
1205 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
1207 $LFS setstripe $TESTFILE0 -c 1 -i 0
1208 $LFS setstripe $TESTFILE1 -c 1 -i 1
1209 chown $TSTUSR.$TSTUSR $TESTFILE0
1210 chown $TSTUSR.$TSTUSR $TESTFILE1
1212 echo "Write to ost0..."
1213 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1214 quota_error a $TSTUSR "dd failed"
1216 echo "Write to ost1..."
1217 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1218 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1220 echo "Free space from ost0..."
1222 wait_delete_completed
1223 sync_all_data || true
1225 echo "Write to ost1 after space freed from ost0..."
1226 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1227 quota_error a $TSTUSR "rebalancing failed"
1230 resetquota -u $TSTUSR
1232 run_test 12 "Block quota rebalancing"
1235 local TESTFILE=$DIR/$tdir/$tfile
1236 # the name of osp on ost1 name is MDT0000-osp-OST0000
1237 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1240 trap cleanup_quota_test EXIT
1242 set_ost_qtype "u" || "enable ost quota failed"
1243 quota_show_check b u $TSTUSR
1245 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1246 $LFS setstripe $TESTFILE -c 1 -i 0
1247 chown $TSTUSR.$TSTUSR $TESTFILE
1249 # clear the locks in cache first
1250 do_facet ost1 $LCTL set_param -n $procf=clear
1251 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1252 [ $nlock -eq 0 ] || error "$nlock cached locks"
1254 # write to acquire the per-ID lock
1255 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1256 quota_error a $TSTUSR "dd failed"
1258 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1259 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1261 # clear quota doesn't trigger per-ID lock cancellation
1262 resetquota -u $TSTUSR
1263 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1264 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1266 # clear the per-ID lock
1267 do_facet ost1 $LCTL set_param -n $procf=clear
1268 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1269 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1271 # spare quota should be released
1272 local OSTUUID=$(ostuuid_from_index 0)
1273 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1274 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1275 [ $limit -le $space ] ||
1276 error "spare quota isn't released, limit:$limit, space:$space"
1280 run_test 13 "Cancel per-ID lock in the LRU list"
1283 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1285 wait_delete_completed
1286 sync_all_data || true
1289 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1290 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1291 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1292 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1293 resetquota -u $TSTUSR
1296 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1297 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1298 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1299 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1300 resetquota -g $TSTUSR
1302 run_test 15 "Set over 4T block quota"
1306 local BLKS=1 # 1M less than limit
1307 local TESTFILE=$DIR/$tdir/$tfile
1310 trap cleanup_quota_test EXIT
1312 # make sure the system is clean
1313 local USED=$(getquota -u $TSTUSR global curspace)
1314 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1316 set_ost_qtype "ug" || error "enable ost quota failed"
1317 # make sure no granted quota on ost
1318 resetquota -u $TSTUSR
1319 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1321 quota_show_check b u $TSTUSR
1323 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1324 lustre_fail mds 0xa04 $err_code
1326 # write in background
1327 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1331 # write should be blocked and never finished
1332 if ! ps -p $DDPID > /dev/null 2>&1; then
1334 quota_error u $TSTUSR "write finished incorrectly!"
1342 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1344 if [ $count -gt $timeout ]; then
1345 quota_error u $TSTUSR "dd is not finished!"
1350 sync; sync_all_data || true
1352 USED=$(getquota -u $TSTUSR global curspace)
1353 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1354 "Used space(${USED}K) is less than ${BLKS}M"
1357 resetquota -u $TSTUSR
1360 # DQACQ return recoverable error
1362 echo "DQACQ return -ENOLCK"
1364 test_17sub 37 || error "Handle -ENOLCK failed"
1366 echo "DQACQ return -EAGAIN"
1368 test_17sub 11 || error "Handle -EAGAIN failed"
1370 echo "DQACQ return -ETIMEDOUT"
1371 #define ETIMEDOUT 110
1372 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1374 echo "DQACQ return -ENOTCONN"
1375 #define ENOTCONN 107
1376 test_17sub 107 || error "Handle -ENOTCONN failed"
1379 run_test 17 "DQACQ return recoverable error"
1383 local blimit="200m" # 200M
1384 local TESTFILE="$DIR/$tdir/$tfile"
1387 trap cleanup_quota_test EXIT
1389 set_ost_qtype "u" || error "enable ost quota failed"
1390 log "User quota (limit: $blimit)"
1391 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
1392 quota_show_check b u $TSTUSR
1394 $LFS setstripe $TESTFILE -i 0 -c 1
1395 chown $TSTUSR.$TSTUSR $TESTFILE
1397 local timeout=$(sysctl -n lustre.timeout)
1399 if [ $io_type = "directio" ]; then
1400 log "Write 100M (directio) ..."
1401 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1403 log "Write 100M (buffered) ..."
1404 $RUNAS $DD of=$TESTFILE count=100 &
1408 replay_barrier $SINGLEMDS
1409 log "Fail mds for $((2 * timeout)) seconds"
1410 fail $SINGLEMDS $((2 * timeout))
1413 if at_is_enabled; then
1414 timeout=$(at_max_get mds)
1416 timeout=$(lctl get_param -n timeout)
1420 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1421 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1422 log "it took $count second"
1427 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1429 cancel_lru_locks mdc
1430 cancel_lru_locks osc
1433 local testfile_size=$(stat -c %s $TESTFILE)
1434 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1435 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1436 "got ${testfile_size}. Verifying file failed!"
1439 resetquota -u $TSTUSR
1442 # test when mds does failover, the ost still could work well
1443 # this test shouldn't trigger watchdog b=14840
1446 test_18_sub directio
1448 # check if watchdog is triggered
1449 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1450 local watchdog=$(awk '/test 18b/ {start = 1;}
1451 /Service thread pid/ && /was inactive/ {
1455 }' $TMP/lustre-log-${TESTNAME}.log)
1456 [ -z "$watchdog" ] || error "$watchdog"
1457 rm -f $TMP/lustre-log-${TESTNAME}.log
1459 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1463 local TESTFILE=$DIR/$tdir/$tfile
1466 trap cleanup_quota_test EXIT
1468 set_ost_qtype "ug" || error "enable ost quota failed"
1470 # bind file to a single OST
1471 $LFS setstripe -c 1 $TESTFILE
1472 chown $TSTUSR.$TSTUSR $TESTFILE
1474 echo "Set user quota (limit: "$blimit"M)"
1475 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1476 quota_show_check b u $TSTUSR
1477 echo "Update quota limits"
1478 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1479 quota_show_check b u $TSTUSR
1481 # first wirte might be cached
1482 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1483 cancel_lru_locks osc
1485 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1486 quota_error u $TSTUSR "Write success, expect failure"
1490 resetquota -u $TSTUSR
1492 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1494 test_20() { # b15754
1495 local LSTR=(2g 1t 4k 3m) # limits strings
1497 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1499 resetquota -u $TSTUSR
1501 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1502 $MOUNT || error "could not set quota limits"
1503 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1504 --inode-softlimit ${LSTR[2]} \
1505 --inode-hardlimit ${LSTR[3]} \
1506 $MOUNT || error "could not set quota limits"
1508 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1509 error "bsoftlimit was not set properly"
1510 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1511 error "bhardlimit was not set properly"
1512 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1513 error "isoftlimit was not set properly"
1514 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1515 error "ihardlimit was not set properly"
1517 resetquota -u $TSTUSR
1519 run_test 20 "Test if setquota specifiers work properly (b15754)"
1526 local time=$(($(date +%s) + seconds))
1527 while [ $(date +%s) -lt $time ]; do
1528 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1532 # run for fixing bug16053, setquota shouldn't fail when writing and
1533 # deleting are happening
1535 local TESTFILE="$DIR/$tdir/$tfile"
1536 local BLIMIT=10 # 10G
1537 local ILIMIT=1000000
1540 trap cleanup_quota_test EXIT
1542 set_ost_qtype "ug" || error "Enable ost quota failed"
1544 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1545 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
1546 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1547 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
1549 # repeat writing on a 1M file
1550 test_21_sub ${TESTFILE}_1 1 30 &
1552 # repeat writing on a 128M file
1553 test_21_sub ${TESTFILE}_2 128 30 &
1556 local time=$(($(date +%s) + 30))
1558 while [ $(date +%s) -lt $time ]; do
1559 log "Set quota for $i times"
1560 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1561 -I $((ILIMIT + i)) $MOUNT ||
1562 error "Set user quota failed"
1563 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1564 -I $((ILIMIT + i)) $MOUNT ||
1565 error "Set group quota failed"
1572 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1574 if [ $count -gt 60 ]; then
1575 quota_error a $TSTUSR "dd should be finished!"
1579 echo "(dd_pid=$DDPID1, time=$count)successful"
1583 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1585 if [ $count -gt 60 ]; then
1586 quota_error a $TSTUSR "dd should be finished!"
1590 echo "(dd_pid=$DDPID2, time=$count)successful"
1593 resetquota -u $TSTUSR
1594 resetquota -g $TSTUSR
1596 run_test 21 "Setquota while writing & deleting (b16053)"
1598 # enable/disable quota enforcement permanently
1600 echo "Set both mdt & ost quota type as ug"
1601 set_mdt_qtype "ug" || error "enable mdt quota failed"
1602 set_ost_qtype "ug" || error "enable ost quota failed"
1609 echo "Verify if quota is enabled"
1610 local qtype=$(mdt_quota_type)
1611 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1612 qtype=$(ost_quota_type)
1613 [ $qtype != "ug" ] && error "ost quota setting is lost"
1615 echo "Set both mdt & ost quota type as none"
1616 set_mdt_qtype "none" || error "disable mdt quota failed"
1617 set_ost_qtype "none" || error "disable ost quota failed"
1624 echo "Verify if quota is disabled"
1625 qtype=$(mdt_quota_type)
1626 [ $qtype != "none" ] && error "mdt quota setting is lost"
1627 qtype=$(ost_quota_type)
1628 [ $qtype != "none" ] && error "ost quota setting is lost"
1632 run_test 22 "enable/disable quota by 'lctl conf_param'"
1635 local TESTFILE="$DIR/$tdir/$tfile"
1639 trap cleanup_quota_test EXIT
1641 set_ost_qtype "ug" || error "Enable ost quota failed"
1644 log "User quota (limit: $LIMIT MB)"
1645 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
1646 quota_show_check b u $TSTUSR
1648 $LFS setstripe $TESTFILE -c 1 -i 0
1649 chown $TSTUSR.$TSTUSR $TESTFILE
1651 log "Step1: trigger EDQUOT with O_DIRECT"
1652 log "Write half of file"
1653 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1654 quota_error u $TSTUSR "(1) Write failure, expect success." \
1656 log "Write out of block quota ..."
1657 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1658 oflag=direct conv=notrunc &&
1659 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1663 log "Step2: rewrite should succeed"
1664 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1665 quota_error u $TSTUSR "(3) Write failure, expect success." \
1671 local OST0_UUID=$(ostuuid_from_index 0)
1672 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1673 [ $OST0_QUOTA_USED -ne 0 ] &&
1674 ($SHOW_QUOTA_USER; \
1675 quota_error u $TSTUSR "quota isn't released")
1677 resetquota -u $TSTUSR
1681 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1682 check_whether_skip && return 0
1683 log "run for 4MB test file"
1686 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1687 check_whether_skip && return 0
1688 log "run for 40MB test file"
1691 run_test 23 "Quota should be honored with directIO (b16125)"
1695 local TESTFILE="$DIR/$tdir/$tfile"
1698 trap cleanup_quota_test EXIT
1700 set_ost_qtype "ug" || error "enable ost quota failed"
1702 # bind file to a single OST
1703 $LFS setstripe -c 1 $TESTFILE
1704 chown $TSTUSR.$TSTUSR $TESTFILE
1706 echo "Set user quota (limit: "$blimit"M)"
1707 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1709 # overrun quota by root user
1710 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1711 error "write failure, expect success"
1712 cancel_lru_locks osc
1713 sync_all_data || true
1715 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1718 resetquota -u $TSTUSR
1720 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1722 test_27a() { # b19612
1723 $LFS quota $TSTUSR $DIR &&
1724 error "lfs succeeded with no type, but should have failed"
1725 $LFS setquota $TSTUSR $DIR &&
1726 error "lfs succeeded with no type, but should have failed"
1729 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1731 test_27b() { # b20200
1732 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1733 error "lfs setquota failed with uid argument"
1734 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1735 error "lfs stequota failed with gid argument"
1736 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1737 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1738 resetquota -u $TSTUSR
1739 resetquota -g $TSTUSR
1742 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1747 local TESTFILE="$DIR/$tdir/$tfile"
1751 trap cleanup_quota_test EXIT
1753 set_ost_qtype "u" || error "enable ost quota failed"
1755 $LFS setstripe $TESTFILE -i 0 -c 1
1756 chown $TSTUSR.$TSTUSR $TESTFILE
1758 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
1759 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
1760 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
1761 cancel_lru_locks osc
1763 $LFS setquota -u $TSTUSR -B 0 $DIR
1764 # over-quota flag has not yet settled since we do not trigger async
1765 # events based on grace time period expiration
1767 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
1768 cancel_lru_locks osc
1769 # now over-quota flag should be settled and further writes should fail
1771 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
1772 error "grace times were reset"
1775 resetquota -u $TSTUSR
1776 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1779 run_test 30 "Hard limit updates should not reset grace times"
1781 # basic usage tracking for user & group
1783 local INODES=10 # 10 files
1784 local BLK_CNT=2 # of 2M each
1785 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
1788 trap cleanup_quota_test EXIT
1790 # make sure the system is clean
1791 local USED=$(getquota -u $TSTID global curspace)
1793 error "Used space ($USED) for user $TSTID isn't 0."
1794 USED=$(getquota -g $TSTID global curspace)
1796 error "Used space ($USED) for group $TSTID isn't 0."
1798 echo "Write files..."
1799 for i in `seq 0 $INODES`; do
1800 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
1801 error "write failed"
1802 echo "Iteration $i/$INODES completed"
1804 cancel_lru_locks osc
1805 sync; sync_all_data || true
1807 echo "Verify disk usage after write"
1808 USED=$(getquota -u $TSTID global curspace)
1809 [ $USED -lt $TOTAL_BLKS ] &&
1810 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
1811 USED=$(getquota -g $TSTID global curspace)
1812 [ $USED -lt $TOTAL_BLKS ] &&
1813 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
1815 echo "Verify inode usage after write"
1816 USED=$(getquota -u $TSTID global curinodes)
1817 [ $USED -lt $INODES ] &&
1818 error "Used inode for user $TSTID is $USED, expected $INODES"
1819 USED=$(getquota -g $TSTID global curinodes)
1820 [ $USED -lt $INODES ] &&
1821 error "Used inode for group $TSTID is $USED, expected $INODES"
1825 echo "Verify disk usage after delete"
1826 USED=$(getquota -u $TSTID global curspace)
1827 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
1828 USED=$(getquota -u $TSTID global curinodes)
1829 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
1830 USED=$(getquota -g $TSTID global curspace)
1831 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
1832 USED=$(getquota -g $TSTID global curinodes)
1833 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
1835 run_test 33 "Basic usage tracking for user & group"
1837 # usage transfer test for user & group
1839 local BLK_CNT=2 # 2MB
1842 trap cleanup_quota_test EXIT
1844 # make sure the system is clean
1845 local USED=$(getquota -u $TSTID global curspace)
1846 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
1847 USED=$(getquota -g $TSTID global curspace)
1848 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
1850 echo "Write file..."
1851 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1852 error "write failed"
1853 cancel_lru_locks osc
1854 sync; sync_all_data || true
1856 echo "chown the file to user $TSTID"
1857 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
1859 echo "Wait for setattr on objects finished..."
1860 wait_delete_completed
1862 BLK_CNT=$((BLK_CNT * 1024))
1864 echo "Verify disk usage for user $TSTID"
1865 USED=$(getquota -u $TSTID global curspace)
1866 [ $USED -lt $BLK_CNT ] &&
1867 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
1868 USED=$(getquota -u $TSTID global curinodes)
1870 error "Used inodes for user $TSTID is $USED, expected 1"
1872 echo "chgrp the file to group $TSTID"
1873 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
1875 echo "Wait for setattr on objects finished..."
1876 wait_delete_completed
1878 echo "Verify disk usage for group $TSTID"
1879 USED=$(getquota -g $TSTID global curspace)
1880 [ $USED -ge $BLK_CNT ] ||
1881 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
1882 USED=$(getquota -g $TSTID global curinodes)
1884 error "Used inodes for group $TSTID is $USED, expected 1"
1888 run_test 34 "Usage transfer for user & group"
1890 # usage is still accessible across restart
1892 local BLK_CNT=2 # 2 MB
1895 trap cleanup_quota_test EXIT
1897 echo "Write file..."
1898 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1899 error "write failed"
1900 cancel_lru_locks osc
1901 sync; sync_all_data || true
1903 echo "Save disk usage before restart"
1904 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
1905 [ $ORIG_USR_SPACE -eq 0 ] &&
1906 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
1907 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
1908 [ $ORIG_USR_INODES -eq 0 ] &&
1909 error "Used inodes for user $TSTID is 0, expected 1"
1910 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
1911 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
1912 [ $ORIG_GRP_SPACE -eq 0 ] &&
1913 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
1914 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
1915 [ $ORIG_GRP_INODES -eq 0 ] &&
1916 error "Used inodes for group $TSTID is 0, expected 1"
1917 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
1920 local ORIG_REFORMAT=$REFORMAT
1922 cleanup_and_setup_lustre
1923 REFORMAT=$ORIG_REFORMAT
1926 echo "Verify disk usage after restart"
1927 local USED=$(getquota -u $TSTID global curspace)
1928 [ $USED -eq $ORIG_USR_SPACE ] ||
1929 error "Used space for user $TSTID changed from " \
1930 "$ORIG_USR_SPACE to $USED"
1931 USED=$(getquota -u $TSTID global curinodes)
1932 [ $USED -eq $ORIG_USR_INODES ] ||
1933 error "Used inodes for user $TSTID changed from " \
1934 "$ORIG_USR_INODES to $USED"
1935 USED=$(getquota -g $TSTID global curspace)
1936 [ $USED -eq $ORIG_GRP_SPACE ] ||
1937 error "Used space for group $TSTID changed from " \
1938 "$ORIG_GRP_SPACE to $USED"
1939 USED=$(getquota -g $TSTID global curinodes)
1940 [ $USED -eq $ORIG_GRP_INODES ] ||
1941 error "Used inodes for group $TSTID changed from " \
1942 "$ORIG_GRP_INODES to $USED"
1944 # check if the vfs_dq_init() is called before writing
1945 echo "Append to the same file..."
1946 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
1947 error "write failed"
1948 cancel_lru_locks osc
1949 sync; sync_all_data || true
1951 echo "Verify space usage is increased"
1952 USED=$(getquota -u $TSTID global curspace)
1953 [ $USED -gt $ORIG_USR_SPACE ] ||
1954 error "Used space for user $TSTID isn't increased" \
1955 "orig:$ORIG_USR_SPACE, now:$USED"
1956 USED=$(getquota -g $TSTID global curspace)
1957 [ $USED -gt $ORIG_GRP_SPACE ] ||
1958 error "Used space for group $TSTID isn't increased" \
1959 "orig:$ORIG_GRP_SPACE, now:$USED"
1963 run_test 35 "Usage is still accessible across reboot"
1965 # test migrating old amdin quota files (in Linux quota file format v2) into new
1966 # quota global index (in IAM format)
1968 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
1969 skip "skipping migration test" && return
1971 # get the mdt0 device name
1972 local mdt0_node=$(facet_active_host $SINGLEMDS)
1973 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
1978 echo "Copy admin quota files into MDT0..."
1979 local mntpt=$(facet_mntpt $SINGLEMDS)
1980 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
1982 if ! do_node $mdt0_node test -b $mdt0_fstype; then
1985 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
1986 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
1987 do_node $mdt0_node mkdir $mntpt/OBJECTS
1988 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
1989 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
1990 do_node $mdt0_node umount -f $mntpt
1995 echo "Verify global limits..."
1999 local proc="qmt.*.md-0x0.glb-usr"
2000 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2001 [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
2002 limit=$(getquota -u 1 global isoftlimit)
2003 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2004 limit=$(getquota -u 1 global ihardlimit)
2005 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2007 proc="qmt.*.md-0x0.glb-grp"
2008 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2009 [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
2010 limit=$(getquota -g 1 global isoftlimit)
2011 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2012 limit=$(getquota -g 1 global ihardlimit)
2013 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2015 proc=" qmt.*.dt-0x0.glb-usr"
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 -u 60001 global bsoftlimit)
2019 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2020 limit=$(getquota -u 60001 global bhardlimit)
2021 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2023 proc="qmt.*.dt-0x0.glb-grp"
2024 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2025 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2026 limit=$(getquota -g 60001 global bsoftlimit)
2027 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2028 limit=$(getquota -g 60001 global bhardlimit)
2029 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2035 run_test 36 "Migrate old admin files into new global indexes"
2039 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2045 check_and_cleanup_lustre
2046 export QUOTA_AUTO=$QUOTA_AUTO_OLD