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 # give a chance to slave to release space
129 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
130 $LFS quota -v -u $LOCAL_ID $DIR
131 log "Files for user ($LOCAL_ID):"
132 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
133 xargs stat 2>/dev/null)
136 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
137 $LFS quota -v -u $LOCAL_ID $DIR
138 log "Files for group ($LOCAL_ID):"
139 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
140 xargs stat 2>/dev/null)
156 # get quota for a user or a group
157 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
158 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
164 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
165 [ "$1" != "-u" -a "$1" != "-g" ] &&
166 error "getquota: wrong u/g specifier $1 passed"
179 *) error "unknown quota parameter $4";;
182 [ "$uuid" = "global" ] && uuid=$DIR
184 $LFS quota -v "$1" "$2" $DIR |
185 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
186 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
191 # usage: set_mdt_qtype ug|u|g|none
194 local varsvc=${SINGLEMDS}_svc
195 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
196 if $(facet_up $SINGLEMDS); then
197 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
198 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" "$qtype" ||
205 # usage: set_ost_quota_type ug|u|g|none
209 local osts=$(get_facets OST)
210 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
211 # we have to make sure each OST received config changes
212 for ost in ${osts//,/ }; do
214 if $(facet_up $ost); then
215 wait_update_facet $ost "$LCTL get_param -n \
216 osd-$FSTYPE.${!varsvc}.quota_slave.enabled" \
223 wait_reintegration() {
226 local result="glb[1],slv[1],reint[0]"
229 if [ $ntype == "mdt" ]; then
230 varsvc=${SINGLEMDS}_svc
231 if $(facet_up $SINGLEMDS); then
232 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
233 osd-$FSTYPE.${!varsvc}.quota_slave.info |
234 grep "$qtype" | awk '{ print \\\$3 }'" "$result" ||
238 local osts=$(get_facets OST)
239 for ost in ${osts//,/ }; do
241 if $(facet_up $ost); then
242 wait_update_facet $ost "$LCTL get_param -n \
243 osd-$FSTYPE.${!varsvc}.quota_slave.info |
244 grep "$qtype" | awk '{ print \\\$3 }'" \
245 "$result" || return 1
255 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
256 wait_reintegration "mdt" "user" || return 1
259 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
260 wait_reintegration "mdt" "group" || return 1
268 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
269 wait_reintegration "ost" "user" || return 1
272 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
273 wait_reintegration "ost" "group" || return 1
280 wait_delete_completed
281 echo "Creating test directory"
284 # always clear fail_loc in case of fail_loc isn't cleared
285 # properly when previous test failed
286 lustre_fail mds_ost 0
289 cleanup_quota_test() {
291 echo "Delete files..."
293 echo "Wait for unlink objects finished..."
294 wait_delete_completed
295 sync_all_data || true
304 $LFS quota -v -$ug $qid $DIR
306 if [ "$bf" == "a" -o "$bf" == "b" ]; then
307 usage=$(getquota -$ug $qid global curspace)
308 if [ -z $usage ]; then
309 quota_error $ug $qid \
310 "Query block quota failed ($ug:$qid)."
312 [ $usage -ne 0 ] && quota_log $ug $qid \
313 "Block quota isn't 0 ($ug:$qid:$usage)."
317 if [ "$bf" == "a" -o "$bf" == "f" ]; then
318 usage=$(getquota -$ug $qid global curinodes)
319 if [ -z $usage ]; then
320 quota_error $ug $qid \
321 "Query file quota failed ($ug:$qid)."
323 [ $usage -ne 0 ] && quota_log $ug $qid \
324 "File quota isn't 0 ($ug:$qid:$usage)."
331 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
335 test_quota_performance() {
336 local TESTFILE="$DIR/$tdir/$tfile-0"
337 local size=$1 # in MB
338 local stime=$(date +%s)
339 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
340 quota_error u $TSTUSR "write failure"
341 local etime=$(date +%s)
342 delta=$((etime - stime))
343 if [ $delta -gt 0 ]; then
344 rate=$((size * 1024 / delta))
345 [ $rate -gt 1024 ] ||
346 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
351 # test basic quota performance b=21696
354 [ "$SLOW" = "no" ] && MB=10
356 local free_space=$(lfs df | grep "filesystem summary" | \
358 [ $free_space -le $((MB * 1024)) ] &&
359 skip "not enough space ${free_space} KB, " \
360 "required $((MB * 1024)) KB" && return
362 trap cleanup_quota_test EXIT
364 set_ost_qtype "none" || error "disable ost quota failed"
365 test_quota_performance $MB
367 set_ost_qtype "ug" || error "enable ost quota failed"
368 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR
369 test_quota_performance $MB
372 resetquota -u $TSTUSR
374 run_test 0 "Test basic quota performance"
376 # test block hardlimit
379 local TESTFILE="$DIR/$tdir/$tfile-0"
382 trap cleanup_quota_test EXIT
385 set_ost_qtype "ug" || "enable ost quota failed"
388 log "User quota (block hardlimit:$LIMIT MB)"
389 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
391 # make sure the system is clean
392 local USED=$(getquota -u $TSTUSR global curspace)
393 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
395 $LFS setstripe $TESTFILE -c 1
396 chown $TSTUSR.$TSTUSR $TESTFILE
399 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
400 quota_error u $TSTUSR "user write failure, but expect success"
401 log "Write out of block quota ..."
402 # this time maybe cache write, ignore it's failure
403 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
404 # flush cache, ensure noquota flag is set on client
406 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
407 quota_error u $TSTUSR "user write success, but expect EDQUOT"
410 wait_delete_completed
411 sync_all_data || true
412 USED=$(getquota -u $TSTUSR global curspace)
413 [ $USED -ne 0 ] && quota_error u $TSTUSR \
414 "user quota isn't released after deletion"
415 resetquota -u $TSTUSR
418 log "--------------------------------------"
419 log "Group quota (block hardlimit:$LIMIT MB)"
420 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
422 TESTFILE="$DIR/$tdir/$tfile-1"
423 # make sure the system is clean
424 USED=$(getquota -g $TSTUSR global curspace)
425 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
427 $LFS setstripe $TESTFILE -c 1
428 chown $TSTUSR.$TSTUSR $TESTFILE
431 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
432 quota_error g $TSTUSR "group write failure, but expect success"
433 log "Write out of block quota ..."
434 # this time maybe cache write, ignore it's failure
435 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
437 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
438 quota_error g $TSTUSR "group write success, but expect EDQUOT"
443 USED=$(getquota -g $TSTUSR global curspace)
444 [ $USED -ne 0 ] && quota_error g $TSTUSR \
445 "group quota isn't released after deletion"
447 resetquota -g $TSTUSR
449 run_test 1 "Block hard limit (normal use and out of quota)"
451 # test inode hardlimit
453 local LIMIT=$((1024 * 1024)) # 1M inodes
454 local TESTFILE="$DIR/$tdir/$tfile-0"
456 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
459 trap cleanup_quota_test EXIT
462 set_mdt_qtype "ug" || "enable mdt quota failed"
465 log "User quota (inode hardlimit:$LIMIT files)"
466 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
468 # make sure the system is clean
469 local USED=$(getquota -u $TSTUSR global curinodes)
470 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
472 log "Create $LIMIT files ..."
473 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
474 quota_error u $TSTUSR "user create failure, but expect success"
475 log "Create out of file quota ..."
476 $RUNAS touch ${TESTFILE}_xxx && \
477 quota_error u $TSTUSR "user create success, but expect EDQUOT"
480 unlinkmany ${TESTFILE} $LIMIT
481 rm -f ${TESTFILE}_xxx
482 wait_delete_completed
484 USED=$(getquota -u $TSTUSR global curinodes)
485 [ $USED -ne 0 ] && quota_error u $TSTUSR \
486 "user quota isn't released after deletion"
487 resetquota -u $TSTUSR
490 log "--------------------------------------"
491 log "Group quota (inode hardlimit:$LIMIT files)"
492 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
494 TESTFILE=$DIR/$tdir/$tfile-1
495 # make sure the system is clean
496 USED=$(getquota -g $TSTUSR global curinodes)
497 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
499 log "Create $LIMIT files ..."
500 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
501 quota_error g $TSTUSR "group create failure, but expect success"
502 log "Create out of file quota ..."
503 $RUNAS touch ${TESTFILE}_xxx && \
504 quota_error g $TSTUSR "group create success, but expect EDQUOT"
507 unlinkmany ${TESTFILE} $LIMIT
508 rm -f ${TESTFILE}_xxx
509 wait_delete_completed
511 USED=$(getquota -g $TSTUSR global curinodes)
512 [ $USED -ne 0 ] && quota_error g $TSTUSR \
513 "user quota isn't released after deletion"
516 resetquota -g $TSTUSR
518 run_test 2 "File hard limit (normal use and out of quota)"
522 local TIMER=$(($2 * 3 / 2))
527 trap cleanup_quota_test EXIT
529 $LFS setstripe $TESTFILE -c 1 -i 0
530 chown $TSTUSR.$TSTUSR $TESTFILE
532 echo "Write up to soft limit"
533 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
534 quota_error a $TSTUSR "write failure, but expect success"
535 OFFSET=$((LIMIT * 1024))
538 echo "Write to exceed soft limit"
539 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
540 quota_error a $TSTUSR "write failure, but expect success"
541 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
546 $SHOW_QUOTA_INFO_USER
547 $SHOW_QUOTA_INFO_GROUP
549 echo "Write before timer goes off"
550 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
551 quota_error a $TSTUSR "write failure, but expect success"
552 OFFSET=$((OFFSET + 1024))
555 echo "Sleep $TIMER seconds ..."
560 $SHOW_QUOTA_INFO_USER
561 $SHOW_QUOTA_INFO_GROUP
563 echo "Write after timer goes off"
564 # maybe cache write, ignore.
565 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
566 OFFSET=$((OFFSET + 1024))
568 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
569 quota_error a $TSTUSR "write success, but expect EDQUOT"
573 $SHOW_QUOTA_INFO_USER
574 $SHOW_QUOTA_INFO_GROUP
576 echo "Unlink file to stop timer"
578 wait_delete_completed
579 sync_all_data || true
583 $SHOW_QUOTA_INFO_USER
584 $SHOW_QUOTA_INFO_GROUP
586 $LFS setstripe $TESTFILE -c 1 -i 0
587 chown $TSTUSR.$TSTUSR $TESTFILE
590 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
591 quota_error a $TSTUSR "write failure, but expect success"
600 local TESTFILE=$DIR/$tdir/$tfile-0
602 set_ost_qtype "ug" || error "enable ost quota failed"
604 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
605 # make sure the system is clean
606 local USED=$(getquota -u $TSTUSR global curspace)
607 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
609 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
610 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
612 test_block_soft $TESTFILE $GRACE $LIMIT
613 resetquota -u $TSTUSR
615 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
616 TESTFILE=$DIR/$tdir/$tfile-1
617 # make sure the system is clean
618 USED=$(getquota -g $TSTUSR global curspace)
619 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
621 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
622 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
624 test_block_soft $TESTFILE $GRACE $LIMIT
625 resetquota -g $TSTUSR
628 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
630 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
633 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
638 local TIMER=$(($3 * 3 / 2))
641 trap cleanup_quota_test EXIT
643 echo "Create files to exceed soft limit"
644 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
645 quota_error a $TSTUSR "create failure, but expect success"
648 echo "Create file before timer goes off"
649 $RUNAS touch ${TESTFILE}_before ||
650 quota_error a $TSTUSR "failed create before timer expired," \
654 echo "Sleep $TIMER seconds ..."
659 $SHOW_QUOTA_INFO_USER
660 $SHOW_QUOTA_INFO_GROUP
662 echo "Create file after timer goes off"
663 # There is a window that space is accounted in the quota usage but
664 # hasn't been decreased from the pending write, if we acquire quota
665 # in this window, we'll acquire more than we needed.
666 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
668 $RUNAS touch ${TESTFILE}_after_3 &&
669 quota_error a $TSTUSR "create after timer expired," \
675 $SHOW_QUOTA_INFO_USER
676 $SHOW_QUOTA_INFO_GROUP
678 echo "Unlink files to stop timer"
679 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
680 wait_delete_completed
683 $RUNAS touch ${TESTFILE}_xxx ||
684 quota_error a $TSTUSR "touch after timer stop failure," \
694 local LIMIT=10 # inodes
695 local TESTFILE=$DIR/$tdir/$tfile-0
698 set_mdt_qtype "ug" || error "enable mdt quota failed"
700 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
701 # make sure the system is clean
702 local USED=$(getquota -u $TSTUSR global curinodes)
703 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
705 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
706 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
708 test_file_soft $TESTFILE $LIMIT $GRACE
709 resetquota -u $TSTUSR
711 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
712 # make sure the system is clean
713 USED=$(getquota -g $TSTUSR global curinodes)
714 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
716 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
717 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
718 TESTFILE=$DIR/$tdir/$tfile-1
720 test_file_soft $TESTFILE $LIMIT $GRACE
721 resetquota -g $TSTUSR
724 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
726 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
729 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
733 local GR_STR2="1000s"
735 local GR_STR4="1w2d3h4m5s"
737 local GR_STR6="1111111111111111"
739 wait_delete_completed
741 # test of valid grace strings handling
742 echo "Valid grace strings test"
743 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
744 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
745 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
746 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
748 # test of invalid grace strings handling
749 echo " Invalid grace strings test"
750 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
751 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
754 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
756 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
759 run_test 4b "Grace time strings handling"
761 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
763 local BLIMIT=10 # 10M
764 local ILIMIT=10 # 10 inodes
767 trap cleanup_quota_test EXIT
769 set_mdt_qtype "ug" || error "enable mdt quota failed"
770 set_ost_qtype "ug" || error "enable ost quota failed"
772 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
773 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
774 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR
776 # make sure the system is clean
777 local USED=$(getquota -u $TSTUSR global curinodes)
778 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
779 USED=$(getquota -g $TSTUSR global curinodes)
780 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
781 USED=$(getquota -u $TSTUSR global curspace)
782 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
783 USED=$(getquota -g $TSTUSR global curspace)
784 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
786 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
787 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
788 error "create failure, expect success"
789 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
790 error "write failure, expect success"
792 echo "Chown files to $TSTUSR.$TSTUSR ..."
793 for i in `seq 0 $ILIMIT`; do
794 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
795 quota_error a $TSTUSR "chown failure, expect success"
799 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
802 resetquota -u $TSTUSR
803 resetquota -g $TSTUSR
805 run_test 5 "Chown & chgrp successfully even out of block/file quota"
807 # test dropping acquire request on master
812 trap cleanup_quota_test EXIT
814 # make sure the system is clean
815 local USED=$(getquota -u $TSTUSR global curspace)
816 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
818 # make sure no granted quota on ost
819 set_ost_qtype "ug" || error "enable ost quota failed"
820 resetquota -u $TSTUSR
822 # create file for $TSTUSR
823 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
824 $LFS setstripe $TESTFILE -c 1 -i 0
825 chown $TSTUSR.$TSTUSR $TESTFILE
827 # create file for $TSTUSR2
828 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
829 $LFS setstripe $TESTFILE2 -c 1 -i 0
830 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
832 # cache per-ID lock for $TSTUSR on slave
833 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
834 $RUNAS $DD of=$TESTFILE count=1 ||
835 error "write $TESTFILE failure, expect success"
836 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
837 error "write $TESTFILE2 failure, expect success"
839 sync_all_data || true
841 #define QUOTA_DQACQ 601
842 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
843 lustre_fail mds 0x513 601
845 # write to un-enforced ID ($TSTUSR2) should succeed
846 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
847 error "write failure, expect success"
849 # write to enforced ID ($TSTUSR) in background, exceeding limit
850 # to make sure DQACQ is sent
851 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
854 # watchdog timer uses a factor of 2
855 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
856 sleep $((TIMEOUT * 2 + 1))
858 # write should be blocked and never finished
859 if ! ps -p $DDPID > /dev/null 2>&1; then
861 error "write finished incorrectly!"
866 # no watchdog is triggered
867 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
868 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
869 /Service thread pid/ && /was inactive/ {
873 }' $TMP/lustre-log-${TESTNAME}.log)
874 [ -z "$watchdog" ] || error "$watchdog"
876 rm -f $TMP/lustre-log-${TESTNAME}.log
878 # write should continue & succeed
881 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
882 if [ $count -ge 120 ]; then
883 quota_error u $TSTUSR "dd not finished in $count secs"
886 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
891 resetquota -u $TSTUSR
893 run_test 6 "Test dropping acquire request on master"
895 # quota reintegration (global index)
897 local TESTFILE=$DIR/$tdir/$tfile
900 [ "$SLOW" = "no" ] && LIMIT=5
903 trap cleanup_quota_test EXIT
905 # make sure the system is clean
906 local USED=$(getquota -u $TSTUSR global curspace)
907 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
909 # make sure no granted quota on ost1
910 set_ost_qtype "ug" || error "enable ost quota failed"
911 resetquota -u $TSTUSR
912 set_ost_qtype "none" || error "disable ost quota failed"
914 local OSTUUID=$(ostuuid_from_index 0)
915 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
916 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
920 $LFS setstripe $TESTFILE -c 1 -i 0
921 chown $TSTUSR.$TSTUSR $TESTFILE
926 echo "Enable quota & set quota limit for $TSTUSR"
927 set_ost_qtype "ug" || error "enable ost quota failed"
928 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
931 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
933 wait_ost_reint "ug" || error "reintegration failed"
935 # hardlimit should have been fetched by slave during global
936 # reintegration, write will exceed quota
937 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
938 quota_error u $TSTUSR "write success, but expect EDQUOT"
941 resetquota -u $TSTUSR
943 run_test 7a "Quota reintegration (global index)"
945 # quota reintegration (slave index)
948 local TESTFILE=$DIR/$tdir/$tfile
951 trap cleanup_quota_test EXIT
953 # make sure the system is clean
954 local USED=$(getquota -u $TSTUSR global curspace)
955 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
957 # make sure no granted quota on ost1
958 set_ost_qtype "ug" || error "enable ost quota failed"
959 resetquota -u $TSTUSR
960 set_ost_qtype "none" || error "disable ost quota failed"
962 local OSTUUID=$(ostuuid_from_index 0)
963 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
964 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
968 $LFS setstripe $TESTFILE -c 1 -i 0
969 chown $TSTUSR.$TSTUSR $TESTFILE
971 # consume some space to make sure the granted space will not
972 # be released during reconciliation
973 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
974 error "consume space failure, expect success"
976 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
977 lustre_fail mds 0xa02
979 set_ost_qtype "ug" || error "enable ost quota failed"
980 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
982 # ignore the write error
983 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
985 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
989 echo "Restart ost to trigger reintegration..."
991 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
993 wait_ost_reint "ug" || error "reintegration failed"
995 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
996 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
999 resetquota -u $TSTUSR
1002 run_test 7b "Quota reintegration (slave index)"
1004 # quota reintegration (restart mds during reintegration)
1006 local LIMIT=20 # 20M
1007 local TESTFILE=$DIR/$tdir/$tfile
1009 [ "$SLOW" = "no" ] && LIMIT=5
1012 trap cleanup_quota_test EXIT
1014 # make sure the system is clean
1015 local USED=$(getquota -u $TSTUSR global curspace)
1016 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1018 set_ost_qtype "none" || error "disable ost quota failed"
1019 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR
1021 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1022 lustre_fail ost 0xa03
1024 # enable ost quota to trigger reintegration
1025 set_ost_qtype "ug" || error "enable ost quota failed"
1033 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1035 wait_ost_reint "ug" || error "reintegration failed"
1037 # hardlimit should have been fetched by slave during global
1038 # reintegration, write will exceed quota
1039 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1040 quota_error u $TSTUSR "write success, but expect EDQUOT"
1043 resetquota -u $TSTUSR
1045 run_test 7c "Quota reintegration (restart mds during reintegration)"
1047 # run dbench with quota enabled
1049 local BLK_LIMIT="100g" #100G
1050 local FILE_LIMIT=1000000
1053 trap cleanup_quota_test EXIT
1055 set_mdt_qtype "ug" || error "enable mdt quota failed"
1056 set_ost_qtype "ug" || error "enable ost quota failed"
1058 echo "Set enough high limit for user: $TSTUSR"
1059 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1060 echo "Set enough high limit for group: $TSTUSR"
1061 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1064 [ "$SLOW" = "no" ] && duration=" -t 120"
1065 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1066 quota_error a $TSTUSR "dbench failed!"
1069 resetquota -u $TSTUSR
1070 resetquota -g $TSTUSR
1072 run_test 8 "Run dbench with quota enabled"
1074 # this check is just for test_9
1075 OST0_MIN=4900000 #4.67G
1077 check_whether_skip () {
1078 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1079 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1080 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1081 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1088 # run for fixing bug10707, it needs a big room. test for 64bit
1090 local filesize=$((1024 * 1024 * 1024 * 9 / 2)) # 4.5G
1092 check_whether_skip && return 0
1095 trap cleanup_quota_test EXIT
1097 set_ost_qtype "ug" || error "enable ost quota failed"
1099 local TESTFILE="$DIR/$tdir/$tfile-0"
1100 local BLK_LIMIT=100G #100G
1101 local FILE_LIMIT=1000000
1103 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1105 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1107 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1109 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1110 "for group: $TSTUSR"
1111 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1113 quota_show_check a u $TSTUSR
1114 quota_show_check a g $TSTUSR
1116 echo "Create test file"
1117 $LFS setstripe $TESTFILE -c 1 -i 0
1118 chown $TSTUSR.$TSTUSR $TESTFILE
1120 log "Write the big file of 4.5G ..."
1121 $RUNAS $DD of=$TESTFILE count=$filesize ||
1122 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1128 resetquota -u $TSTUSR
1129 resetquota -g $TSTUSR
1134 run_test 9 "Block limit larger than 4GB (b10707)"
1137 local TESTFILE=$DIR/$tdir/$tfile
1140 trap cleanup_quota_test EXIT
1142 # set limit to root user should fail
1143 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1144 error "set limit for root user successfully, expect failure"
1145 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1146 error "set limit for root group successfully, expect failure"
1148 # root user can overrun quota
1149 set_ost_qtype "ug" || "enable ost quota failed"
1151 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR
1152 quota_show_check b u $TSTUSR
1154 $LFS setstripe $TESTFILE -c 1
1155 chown $TSTUSR.$TSTUSR $TESTFILE
1157 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1158 error "write failure, expect success"
1161 resetquota -u $TSTUSR
1163 run_test 10 "Test quota for root user"
1166 local TESTFILE=$DIR/$tdir/$tfile
1168 trap cleanup_quota_test EXIT
1170 set_mdt_qtype "ug" || "enable mdt quota failed"
1171 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR
1176 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1177 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1180 local USED=$(getquota -u $TSTUSR global curinodes)
1181 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1184 resetquota -u $TSTUSR
1186 run_test 11 "Chown/chgrp ignores quota"
1189 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1191 local blimit=22 # 22M
1192 local blk_cnt=$((blimit - 5))
1193 local TESTFILE0="$DIR/$tdir/$tfile"-0
1194 local TESTFILE1="$DIR/$tdir/$tfile"-1
1197 trap cleanup_quota_test EXIT
1199 set_ost_qtype "u" || "enable ost quota failed"
1200 quota_show_check b u $TSTUSR
1202 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR
1204 $LFS setstripe $TESTFILE0 -c 1 -i 0
1205 $LFS setstripe $TESTFILE1 -c 1 -i 1
1206 chown $TSTUSR.$TSTUSR $TESTFILE0
1207 chown $TSTUSR.$TSTUSR $TESTFILE1
1209 echo "Write to ost0..."
1210 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1211 quota_error a $TSTUSR "dd failed"
1213 echo "Write to ost1..."
1214 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1215 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1217 echo "Free space from ost0..."
1219 wait_delete_completed
1220 sync_all_data || true
1222 echo "Write to ost1 after space freed from ost0..."
1223 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1224 quota_error a $TSTUSR "rebalancing failed"
1227 resetquota -u $TSTUSR
1229 run_test 12 "Block quota rebalancing"
1232 local TESTFILE=$DIR/$tdir/$tfile
1233 # the name of osp on ost1 name is MDT0000-osp-OST0000
1234 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1237 trap cleanup_quota_test EXIT
1239 set_ost_qtype "u" || "enable ost quota failed"
1240 quota_show_check b u $TSTUSR
1242 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1243 $LFS setstripe $TESTFILE -c 1 -i 0
1244 chown $TSTUSR.$TSTUSR $TESTFILE
1246 # clear the locks in cache first
1247 do_facet ost1 $LCTL set_param -n $procf=clear
1248 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1249 [ $nlock -eq 0 ] || error "$nlock cached locks"
1251 # write to acquire the per-ID lock
1252 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1253 quota_error a $TSTUSR "dd failed"
1255 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1256 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1258 # clear quota doesn't trigger per-ID lock cancellation
1259 resetquota -u $TSTUSR
1260 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1261 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1263 # clear the per-ID lock
1264 do_facet ost1 $LCTL set_param -n $procf=clear
1265 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1266 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1268 # spare quota should be released
1269 local OSTUUID=$(ostuuid_from_index 0)
1270 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1271 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1272 [ $limit -le $space ] ||
1273 error "spare quota isn't released, limit:$limit, space:$space"
1277 run_test 13 "Cancel per-ID lock in the LRU list"
1280 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1282 wait_delete_completed
1283 sync_all_data || true
1286 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1287 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1288 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1289 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1290 resetquota -u $TSTUSR
1293 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1294 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1295 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1296 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1297 resetquota -g $TSTUSR
1299 run_test 15 "Set over 4T block quota"
1303 local BLKS=1 # 1M less than limit
1304 local TESTFILE=$DIR/$tdir/$tfile
1307 trap cleanup_quota_test EXIT
1309 # make sure the system is clean
1310 local USED=$(getquota -u $TSTUSR global curspace)
1311 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1313 set_ost_qtype "ug" || error "enable ost quota failed"
1314 # make sure no granted quota on ost
1315 resetquota -u $TSTUSR
1316 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR
1318 quota_show_check b u $TSTUSR
1320 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1321 lustre_fail mds 0xa04 $err_code
1323 # write in background
1324 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1328 # write should be blocked and never finished
1329 if ! ps -p $DDPID > /dev/null 2>&1; then
1331 quota_error u $TSTUSR "write finished incorrectly!"
1339 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1341 if [ $count -gt $timeout ]; then
1342 quota_error u $TSTUSR "dd is not finished!"
1347 sync; sync_all_data || true
1349 USED=$(getquota -u $TSTUSR global curspace)
1350 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1351 "Used space(${USED}K) is less than ${BLKS}M"
1354 resetquota -u $TSTUSR
1357 # DQACQ return recoverable error
1359 echo "DQACQ return -ENOLCK"
1361 test_17sub 37 || error "Handle -ENOLCK failed"
1363 echo "DQACQ return -EAGAIN"
1365 test_17sub 11 || error "Handle -EAGAIN failed"
1367 echo "DQACQ return -ETIMEDOUT"
1368 #define ETIMEDOUT 110
1369 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1371 echo "DQACQ return -ENOTCONN"
1372 #define ENOTCONN 107
1373 test_17sub 107 || error "Handle -ENOTCONN failed"
1376 run_test 17 "DQACQ return recoverable error"
1380 local blimit="200m" # 200M
1381 local TESTFILE="$DIR/$tdir/$tfile"
1384 trap cleanup_quota_test EXIT
1386 set_ost_qtype "u" || error "enable ost quota failed"
1387 log "User quota (limit: $blimit)"
1388 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT
1389 quota_show_check b u $TSTUSR
1391 $LFS setstripe $TESTFILE -i 0 -c 1
1392 chown $TSTUSR.$TSTUSR $TESTFILE
1394 local timeout=$(sysctl -n lustre.timeout)
1396 if [ $io_type = "directio" ]; then
1397 log "Write 100M (directio) ..."
1398 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1400 log "Write 100M (buffered) ..."
1401 $RUNAS $DD of=$TESTFILE count=100 &
1405 replay_barrier $SINGLEMDS
1406 log "Fail mds for $((2 * timeout)) seconds"
1407 fail $SINGLEMDS $((2 * timeout))
1410 if at_is_enabled; then
1411 timeout=$(at_max_get mds)
1413 timeout=$(lctl get_param -n timeout)
1417 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1418 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1419 log "it took $count second"
1424 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1426 cancel_lru_locks mdc
1427 cancel_lru_locks osc
1430 local testfile_size=$(stat -c %s $TESTFILE)
1431 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1432 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1433 "got ${testfile_size}. Verifying file failed!"
1436 resetquota -u $TSTUSR
1439 # test when mds does failover, the ost still could work well
1440 # this test shouldn't trigger watchdog b=14840
1443 test_18_sub directio
1445 # check if watchdog is triggered
1446 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1447 local watchdog=$(awk '/test 18b/ {start = 1;}
1448 /Service thread pid/ && /was inactive/ {
1452 }' $TMP/lustre-log-${TESTNAME}.log)
1453 [ -z "$watchdog" ] || error "$watchdog"
1454 rm -f $TMP/lustre-log-${TESTNAME}.log
1456 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1460 local TESTFILE=$DIR/$tdir/$tfile
1463 trap cleanup_quota_test EXIT
1465 set_ost_qtype "ug" || error "enable ost quota failed"
1467 # bind file to a single OST
1468 $LFS setstripe -c 1 $TESTFILE
1469 chown $TSTUSR.$TSTUSR $TESTFILE
1471 echo "Set user quota (limit: "$blimit"M)"
1472 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1473 quota_show_check b u $TSTUSR
1474 echo "Update quota limits"
1475 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1476 quota_show_check b u $TSTUSR
1478 # first wirte might be cached
1479 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1480 cancel_lru_locks osc
1482 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1483 quota_error u $TSTUSR "Write success, expect failure"
1487 resetquota -u $TSTUSR
1489 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1491 test_20() { # b15754
1492 local LSTR=(2g 1t 4k 3m) # limits strings
1494 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1496 resetquota -u $TSTUSR
1498 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1499 $MOUNT || error "could not set quota limits"
1500 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1501 --inode-softlimit ${LSTR[2]} \
1502 --inode-hardlimit ${LSTR[3]} \
1503 $MOUNT || error "could not set quota limits"
1505 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1506 error "bsoftlimit was not set properly"
1507 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1508 error "bhardlimit was not set properly"
1509 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1510 error "isoftlimit was not set properly"
1511 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1512 error "ihardlimit was not set properly"
1514 resetquota -u $TSTUSR
1516 run_test 20 "Test if setquota specifiers work properly (b15754)"
1523 local time=$(($(date +%s) + seconds))
1524 while [ $(date +%s) -lt $time ]; do
1525 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1529 # run for fixing bug16053, setquota shouldn't fail when writing and
1530 # deleting are happening
1532 local TESTFILE="$DIR/$tdir/$tfile"
1533 local BLIMIT=10 # 10G
1534 local ILIMIT=1000000
1537 trap cleanup_quota_test EXIT
1539 set_ost_qtype "ug" || error "Enable ost quota failed"
1541 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1542 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT
1543 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1544 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT
1546 # repeat writing on a 1M file
1547 test_21_sub ${TESTFILE}_1 1 30 &
1549 # repeat writing on a 128M file
1550 test_21_sub ${TESTFILE}_2 128 30 &
1553 local time=$(($(date +%s) + 30))
1555 while [ $(date +%s) -lt $time ]; do
1556 log "Set quota for $i times"
1557 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1558 -I $((ILIMIT + i)) $MOUNT ||
1559 error "Set user quota failed"
1560 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1561 -I $((ILIMIT + i)) $MOUNT ||
1562 error "Set group quota failed"
1569 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1571 if [ $count -gt 60 ]; then
1572 quota_error a $TSTUSR "dd should be finished!"
1576 echo "(dd_pid=$DDPID1, time=$count)successful"
1580 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1582 if [ $count -gt 60 ]; then
1583 quota_error a $TSTUSR "dd should be finished!"
1587 echo "(dd_pid=$DDPID2, time=$count)successful"
1590 resetquota -u $TSTUSR
1591 resetquota -g $TSTUSR
1593 run_test 21 "Setquota while writing & deleting (b16053)"
1595 # enable/disable quota enforcement permanently
1597 echo "Set both mdt & ost quota type as ug"
1598 set_mdt_qtype "ug" || error "enable mdt quota failed"
1599 set_ost_qtype "ug" || error "enable ost quota failed"
1606 echo "Verify if quota is enabled"
1607 local qtype=$(mdt_quota_type)
1608 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1609 qtype=$(ost_quota_type)
1610 [ $qtype != "ug" ] && error "ost quota setting is lost"
1612 echo "Set both mdt & ost quota type as none"
1613 set_mdt_qtype "none" || error "disable mdt quota failed"
1614 set_ost_qtype "none" || error "disable ost quota failed"
1621 echo "Verify if quota is disabled"
1622 qtype=$(mdt_quota_type)
1623 [ $qtype != "none" ] && error "mdt quota setting is lost"
1624 qtype=$(ost_quota_type)
1625 [ $qtype != "none" ] && error "ost quota setting is lost"
1629 run_test 22 "enable/disable quota by 'lctl conf_param'"
1632 local TESTFILE="$DIR/$tdir/$tfile"
1636 trap cleanup_quota_test EXIT
1638 set_ost_qtype "ug" || error "Enable ost quota failed"
1641 log "User quota (limit: $LIMIT MB)"
1642 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR
1643 quota_show_check b u $TSTUSR
1645 $LFS setstripe $TESTFILE -c 1 -i 0
1646 chown $TSTUSR.$TSTUSR $TESTFILE
1648 log "Step1: trigger EDQUOT with O_DIRECT"
1649 log "Write half of file"
1650 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1651 quota_error u $TSTUSR "(1) Write failure, expect success." \
1653 log "Write out of block quota ..."
1654 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1655 oflag=direct conv=notrunc &&
1656 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1660 log "Step2: rewrite should succeed"
1661 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1662 quota_error u $TSTUSR "(3) Write failure, expect success." \
1668 local OST0_UUID=$(ostuuid_from_index 0)
1669 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1670 [ $OST0_QUOTA_USED -ne 0 ] &&
1671 ($SHOW_QUOTA_USER; \
1672 quota_error u $TSTUSR "quota isn't released")
1674 resetquota -u $TSTUSR
1678 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1679 check_whether_skip && return 0
1680 log "run for 4MB test file"
1683 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1684 check_whether_skip && return 0
1685 log "run for 40MB test file"
1688 run_test 23 "Quota should be honored with directIO (b16125)"
1692 local TESTFILE="$DIR/$tdir/$tfile"
1695 trap cleanup_quota_test EXIT
1697 set_ost_qtype "ug" || error "enable ost quota failed"
1699 # bind file to a single OST
1700 $LFS setstripe -c 1 $TESTFILE
1701 chown $TSTUSR.$TSTUSR $TESTFILE
1703 echo "Set user quota (limit: "$blimit"M)"
1704 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT
1706 # overrun quota by root user
1707 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1708 error "write failure, expect success"
1709 cancel_lru_locks osc
1710 sync_all_data || true
1712 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1715 resetquota -u $TSTUSR
1717 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1719 test_27a() { # b19612
1720 $LFS quota $TSTUSR $DIR &&
1721 error "lfs succeeded with no type, but should have failed"
1722 $LFS setquota $TSTUSR $DIR &&
1723 error "lfs succeeded with no type, but should have failed"
1726 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1728 test_27b() { # b20200
1729 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1730 error "lfs setquota failed with uid argument"
1731 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1732 error "lfs stequota failed with gid argument"
1733 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1734 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1735 resetquota -u $TSTUSR
1736 resetquota -g $TSTUSR
1739 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1744 local TESTFILE="$DIR/$tdir/$tfile"
1748 trap cleanup_quota_test EXIT
1750 set_ost_qtype "u" || error "enable ost quota failed"
1752 $LFS setstripe $TESTFILE -i 0 -c 1
1753 chown $TSTUSR.$TSTUSR $TESTFILE
1755 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
1756 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR
1757 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
1758 cancel_lru_locks osc
1760 $LFS setquota -u $TSTUSR -B 0 $DIR
1761 # over-quota flag has not yet settled since we do not trigger async
1762 # events based on grace time period expiration
1764 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
1765 cancel_lru_locks osc
1766 # now over-quota flag should be settled and further writes should fail
1768 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
1769 error "grace times were reset"
1772 resetquota -u $TSTUSR
1773 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1776 run_test 30 "Hard limit updates should not reset grace times"
1778 # basic usage tracking for user & group
1780 local INODES=10 # 10 files
1781 local BLK_CNT=2 # of 2M each
1782 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
1785 trap cleanup_quota_test EXIT
1787 # make sure the system is clean
1788 local USED=$(getquota -u $TSTID global curspace)
1790 error "Used space ($USED) for user $TSTID isn't 0."
1791 USED=$(getquota -g $TSTID global curspace)
1793 error "Used space ($USED) for group $TSTID isn't 0."
1795 echo "Write files..."
1796 for i in `seq 0 $INODES`; do
1797 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
1798 error "write failed"
1799 echo "Iteration $i/$INODES completed"
1801 cancel_lru_locks osc
1802 sync; sync_all_data || true
1804 echo "Verify disk usage after write"
1805 USED=$(getquota -u $TSTID global curspace)
1806 [ $USED -lt $TOTAL_BLKS ] &&
1807 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
1808 USED=$(getquota -g $TSTID global curspace)
1809 [ $USED -lt $TOTAL_BLKS ] &&
1810 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
1812 echo "Verify inode usage after write"
1813 USED=$(getquota -u $TSTID global curinodes)
1814 [ $USED -lt $INODES ] &&
1815 error "Used inode for user $TSTID is $USED, expected $INODES"
1816 USED=$(getquota -g $TSTID global curinodes)
1817 [ $USED -lt $INODES ] &&
1818 error "Used inode for group $TSTID is $USED, expected $INODES"
1822 echo "Verify disk usage after delete"
1823 USED=$(getquota -u $TSTID global curspace)
1824 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
1825 USED=$(getquota -u $TSTID global curinodes)
1826 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
1827 USED=$(getquota -g $TSTID global curspace)
1828 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
1829 USED=$(getquota -g $TSTID global curinodes)
1830 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
1832 run_test 33 "Basic usage tracking for user & group"
1834 # usage transfer test for user & group
1836 local BLK_CNT=2 # 2MB
1839 trap cleanup_quota_test EXIT
1841 # make sure the system is clean
1842 local USED=$(getquota -u $TSTID global curspace)
1843 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
1844 USED=$(getquota -g $TSTID global curspace)
1845 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
1847 echo "Write file..."
1848 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1849 error "write failed"
1850 cancel_lru_locks osc
1851 sync; sync_all_data || true
1853 echo "chown the file to user $TSTID"
1854 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
1856 echo "Wait for setattr on objects finished..."
1857 wait_delete_completed
1859 BLK_CNT=$((BLK_CNT * 1024))
1861 echo "Verify disk usage for user $TSTID"
1862 USED=$(getquota -u $TSTID global curspace)
1863 [ $USED -lt $BLK_CNT ] &&
1864 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
1865 USED=$(getquota -u $TSTID global curinodes)
1867 error "Used inodes for user $TSTID is $USED, expected 1"
1869 echo "chgrp the file to group $TSTID"
1870 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
1872 echo "Wait for setattr on objects finished..."
1873 wait_delete_completed
1875 echo "Verify disk usage for group $TSTID"
1876 USED=$(getquota -g $TSTID global curspace)
1877 [ $USED -ge $BLK_CNT ] ||
1878 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
1879 USED=$(getquota -g $TSTID global curinodes)
1881 error "Used inodes for group $TSTID is $USED, expected 1"
1885 run_test 34 "Usage transfer for user & group"
1887 # usage is still accessible across restart
1889 local BLK_CNT=2 # 2 MB
1892 trap cleanup_quota_test EXIT
1894 echo "Write file..."
1895 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
1896 error "write failed"
1897 cancel_lru_locks osc
1898 sync; sync_all_data || true
1900 echo "Save disk usage before restart"
1901 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
1902 [ $ORIG_USR_SPACE -eq 0 ] &&
1903 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
1904 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
1905 [ $ORIG_USR_INODES -eq 0 ] &&
1906 error "Used inodes for user $TSTID is 0, expected 1"
1907 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
1908 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
1909 [ $ORIG_GRP_SPACE -eq 0 ] &&
1910 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
1911 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
1912 [ $ORIG_GRP_INODES -eq 0 ] &&
1913 error "Used inodes for group $TSTID is 0, expected 1"
1914 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
1917 local ORIG_REFORMAT=$REFORMAT
1919 cleanup_and_setup_lustre
1920 REFORMAT=$ORIG_REFORMAT
1923 echo "Verify disk usage after restart"
1924 local USED=$(getquota -u $TSTID global curspace)
1925 [ $USED -eq $ORIG_USR_SPACE ] ||
1926 error "Used space for user $TSTID changed from " \
1927 "$ORIG_USR_SPACE to $USED"
1928 USED=$(getquota -u $TSTID global curinodes)
1929 [ $USED -eq $ORIG_USR_INODES ] ||
1930 error "Used inodes for user $TSTID changed from " \
1931 "$ORIG_USR_INODES to $USED"
1932 USED=$(getquota -g $TSTID global curspace)
1933 [ $USED -eq $ORIG_GRP_SPACE ] ||
1934 error "Used space for group $TSTID changed from " \
1935 "$ORIG_GRP_SPACE to $USED"
1936 USED=$(getquota -g $TSTID global curinodes)
1937 [ $USED -eq $ORIG_GRP_INODES ] ||
1938 error "Used inodes for group $TSTID changed from " \
1939 "$ORIG_GRP_INODES to $USED"
1941 # check if the vfs_dq_init() is called before writing
1942 echo "Append to the same file..."
1943 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
1944 error "write failed"
1945 cancel_lru_locks osc
1946 sync; sync_all_data || true
1948 echo "Verify space usage is increased"
1949 USED=$(getquota -u $TSTID global curspace)
1950 [ $USED -gt $ORIG_USR_SPACE ] ||
1951 error "Used space for user $TSTID isn't increased" \
1952 "orig:$ORIG_USR_SPACE, now:$USED"
1953 USED=$(getquota -g $TSTID global curspace)
1954 [ $USED -gt $ORIG_GRP_SPACE ] ||
1955 error "Used space for group $TSTID isn't increased" \
1956 "orig:$ORIG_GRP_SPACE, now:$USED"
1960 run_test 35 "Usage is still accessible across reboot"
1962 # test migrating old amdin quota files (in Linux quota file format v2) into new
1963 # quota global index (in IAM format)
1965 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
1966 skip "skipping migration test" && return
1968 # get the mdt0 device name
1969 local mdt0_node=$(facet_active_host $SINGLEMDS)
1970 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
1975 echo "Copy admin quota files into MDT0..."
1976 local mntpt=$(facet_mntpt $SINGLEMDS)
1977 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
1979 if ! do_node $mdt0_node test -b $mdt0_fstype; then
1982 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
1983 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
1984 do_node $mdt0_node mkdir $mntpt/OBJECTS
1985 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
1986 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
1987 do_node $mdt0_node umount -f $mntpt
1992 echo "Verify global limits..."
1996 local proc="qmt.*.md-0x0.glb-usr"
1997 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
1998 [ $id_cnt -eq 401 ] || error "Migrate inode user limit failed: $id_cnt"
1999 limit=$(getquota -u 1 global isoftlimit)
2000 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2001 limit=$(getquota -u 1 global ihardlimit)
2002 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2004 proc="qmt.*.md-0x0.glb-grp"
2005 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2006 [ $id_cnt -eq 401 ] || error "Migrate inode group limit failed: $id_cnt"
2007 limit=$(getquota -g 1 global isoftlimit)
2008 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2009 limit=$(getquota -g 1 global ihardlimit)
2010 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2012 proc=" qmt.*.dt-0x0.glb-usr"
2013 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2014 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2015 limit=$(getquota -u 60001 global bsoftlimit)
2016 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2017 limit=$(getquota -u 60001 global bhardlimit)
2018 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2020 proc="qmt.*.dt-0x0.glb-grp"
2021 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2022 [ $id_cnt -eq 401 ] || error "Migrate block user limit failed: $id_cnt"
2023 limit=$(getquota -g 60001 global bsoftlimit)
2024 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2025 limit=$(getquota -g 60001 global bhardlimit)
2026 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2032 run_test 36 "Migrate old admin files into new global indexes"
2036 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2042 check_and_cleanup_lustre
2043 export QUOTA_AUTO=$QUOTA_AUTO_OLD