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
12 if [ "$USE_OFD" = "yes" -a -z "$ONLY" ]; then
13 # only accounting tests are supported with OFD for the time being
18 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
19 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
20 # We have changed the mechanism of quota, test_12 is meanless now.
22 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
23 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
25 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
26 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
32 TSTID2=${TSTID2:-60001}
33 TSTUSR=${TSTUSR:-"quota_usr"}
34 TSTUSR2=${TSTUSR2:-"quota_2usr"}
36 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
37 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
40 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
41 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
42 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
43 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
44 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
46 export MULTIOP=${MULTIOP:-multiop}
48 LUSTRE=${LUSTRE:-`dirname $0`/..}
49 . $LUSTRE/tests/test-framework.sh
51 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
53 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
55 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
57 require_dsh_mds || exit 0
58 require_dsh_ost || exit 0
60 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
62 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
64 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
69 QUOTA_AUTO_OLD=$QUOTA_AUTO
72 check_and_setup_lustre
74 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
75 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
80 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
81 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
82 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
83 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
84 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
86 # control the time of tests
88 [ "$SLOW" = "no" ] && cycle=10
92 if [ "$USE_OFD" = "yes" ]; then
93 for num in `seq $OSTCOUNT`; do
94 if [ $(facet_fstype ost$num) = ldiskfs ]; then
95 # not the most efficient way to enable the quota feature
96 # on ost, but it still allows us to test ofd accounting
98 device=$(ostdevname $num)
100 do_facet ost$num "$TUNE2FS -O quota $device"
101 [ ${PIPESTATUS[0]} -ne 0] && \
102 error "failed to enable quota feature for ost$num"
103 start ost$num $device $OST_MOUNT_OPTS
108 # set_blk_tunables(btune_sz)
110 local btune=$(($1 * BLK_SZ))
111 # set btune size on all obdfilters
112 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
113 # set btune size on mds
114 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
117 # set_blk_unitsz(bunit_sz)
119 local bunit=$(($1 * BLK_SZ))
120 # set bunit size on all obdfilters
121 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
122 # set bunit size on mds
123 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
126 # set_file_tunesz(itune_sz)
129 # set itune size on mds
130 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
133 # set_file_unitsz(iunit_sz)
136 # set iunit size on mds
137 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
143 local fail_val=${3:-0}
145 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
146 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
147 [ $((fail_loc)) -eq 0 ]; then
148 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
150 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
152 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
153 for num in `seq $OSTCOUNT`; do
154 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
155 [ $((fail_loc)) -eq 0 ]; then
156 do_facet ost$num "lctl set_param fail_val=$fail_val"
158 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
163 RUNAS="runas -u $TSTID -g $TSTID"
164 RUNAS2="runas -u $TSTID2 -g $TSTID2"
165 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
166 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
170 run_test_with_stat() {
171 (($# != 2)) && error "the number of arguments is wrong"
173 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
174 for j in `seq $OSTCOUNT`; do
175 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
178 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
179 echo "statistics info begin ***************************************"
180 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
181 for j in `seq $OSTCOUNT`; do
182 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
184 echo "statistics info end ***************************************"
189 # clear quota limits for a user or a group
190 # usage: resetquota -u username
191 # resetquota -g groupname
194 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
195 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
198 if at_is_enabled; then
199 timeout=$(at_max_get mds)
201 timeout=$(lctl get_param -n timeout)
204 while [ $((count++)) -lt $timeout ]; do
206 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
207 if [ $RC -ne 0 ]; then
208 if echo "$OUTPUT" | grep -q busy; then
209 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
213 error "resetquota failed"
219 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
226 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
227 log "Files for user ($LOCAL_ID):"
228 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
231 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
232 log "Files for group ($LOCAL_ID):"
233 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
250 # get quota info for a user or a group
251 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
257 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
258 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
271 *) error "unknown quota parameter $4";;
274 [ "$uuid" = "global" ] && uuid=$DIR
276 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
283 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
285 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
287 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
288 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
289 if [ -z $USAGE ]; then
290 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
292 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
296 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
297 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
298 if [ -z $USAGE ]; then
299 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
301 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
308 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
310 log "do the quotacheck ..."
311 $LFS quotacheck -ug $DIR
313 resetquota -u $TSTUSR
314 resetquota -g $TSTUSR
318 test_quota_performance() {
319 TESTFILE="$DIR/$tdir/$tfile-0"
321 local stime=`date +%s`
322 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
323 local etime=`date +%s`
324 delta=$((etime - stime))
325 if [ $delta -gt 0 ]; then
326 rate=$((size * 1024 / delta))
327 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
332 # test basic quota performance b=21696
335 chmod 0777 $DIR/$tdir
337 [ "$SLOW" = "no" ] && MB=10
339 test_quota_performance $MB
341 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
342 test_quota_performance $MB
344 resetquota -u $TSTUSR
346 run_test_with_stat 0 "Test basic quota performance ==="
348 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
352 chmod 0777 $DIR/$tdir
353 TESTFILE="$DIR/$tdir/$tfile-0"
355 wait_delete_completed
358 log " User quota (limit: $LIMIT kbytes)"
359 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
361 quota_show_check b u $TSTUSR
363 $LFS setstripe $TESTFILE -c 1
364 chown $TSTUSR.$TSTUSR $TESTFILE
367 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
369 log " Write out of block quota ..."
370 # this time maybe cache write, ignore it's failure
371 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
372 # flush cache, ensure noquota flag is setted on client
374 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && quota_error u $TSTUSR "(usr) write success, but expect EDQUOT"
378 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
379 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
380 echo $OST0_QUOTA_USED
381 [ $OST0_QUOTA_USED -ne 0 ] && \
382 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
384 resetquota -u $TSTUSR
387 log "--------------------------------------"
388 log " Group quota (limit: $LIMIT kbytes)"
389 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
391 quota_show_check b g $TSTUSR
392 TESTFILE="$DIR/$tdir/$tfile-1"
394 $LFS setstripe $TESTFILE -c 1
395 chown $TSTUSR.$TSTUSR $TESTFILE
398 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
400 log " Write out of block quota ..."
401 # this time maybe cache write, ignore it's failure
402 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
404 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && quota_error g $TSTUSR "(grp) write success, but expect EDQUOT"
409 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
410 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
411 echo $OST0_QUOTA_USED
412 [ $OST0_QUOTA_USED -ne 0 ] && \
413 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
415 resetquota -g $TSTUSR
418 # block hard limit (normal use and out of quota)
420 for i in `seq 1 $cycle`; do
421 # define blk_qunit is between 1M and 4M
422 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
423 blk_qtune=$(( $RANDOM % $blk_qunit ))
424 # other osts and mds will occupy at 1M blk quota
425 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
426 set_blk_tunesz $blk_qtune
427 set_blk_unitsz $blk_qunit
428 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
430 echo "=================================================="
431 set_blk_unitsz $((128 * 1024))
432 set_blk_tunesz $((128 * 1024 / 2))
435 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
437 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
441 chmod 0777 $DIR/$tdir
442 TESTFILE="$DIR/$tdir/$tfile-0"
444 wait_delete_completed
447 log " User quota (limit: $LIMIT files)"
448 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
450 quota_show_check f u $TSTUSR
452 log " Create $LIMIT files ..."
453 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
454 quota_error u $TSTUSR "(usr) create failure, but expect success"
456 log " Create out of file quota ..."
457 $RUNAS touch ${TESTFILE}_xxx && \
458 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
460 unlinkmany ${TESTFILE} $LIMIT
461 rm -f ${TESTFILE}_xxx
464 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
465 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
467 [ $MDS_QUOTA_USED -ne 0 ] && \
468 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
470 resetquota -u $TSTUSR
473 log "--------------------------------------"
474 log " Group quota (limit: $LIMIT FILE)"
475 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
477 quota_show_check f g $TSTUSR
478 TESTFILE=$DIR/$tdir/$tfile-1
480 log " Create $LIMIT files ..."
481 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
482 quota_error g $TSTUSR "(grp) create failure, but expect success"
484 log " Create out of file quota ..."
485 $RUNAS touch ${TESTFILE}_xxx && \
486 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
488 unlinkmany ${TESTFILE} $LIMIT
489 rm -f ${TESTFILE}_xxx
492 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
493 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
495 [ $MDS_QUOTA_USED -ne 0 ] && \
496 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
498 resetquota -g $TSTUSR
501 # file hard limit (normal use and out of quota)
503 for i in `seq 1 $cycle`; do
504 if [ $i -eq 1 ]; then
509 # define ino_qunit is between 10 and 100
510 ino_qunit=$(( $RANDOM % 90 + 10 ))
511 ino_qtune=$(( $RANDOM % $ino_qunit ))
512 # RANDOM's maxium is 32767
513 i_limit=$(( $RANDOM % 990 + 10 ))
516 set_file_tunesz $ino_qtune
517 set_file_unitsz $ino_qunit
518 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
520 echo "=================================================="
525 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
529 TIMER=$(($2 * 3 / 2))
532 wait_delete_completed
534 echo " Write to exceed soft limit"
535 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
536 $RUNDD count=$((BUNIT_SZ+1)) || \
537 quota_error a $TSTUSR "write failure, but expect success"
538 OFFSET=$((OFFSET + BUNIT_SZ + 1))
543 $SHOW_QUOTA_INFO_USER
544 $SHOW_QUOTA_INFO_GROUP
546 echo " Write before timer goes off"
547 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
548 quota_error a $TSTUSR "write failure, but expect success"
549 OFFSET=$((OFFSET + BUNIT_SZ))
553 echo " Sleep $TIMER seconds ..."
558 $SHOW_QUOTA_INFO_USER
559 $SHOW_QUOTA_INFO_GROUP
561 echo " Write after timer goes off"
562 # maybe cache write, ignore.
563 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
564 OFFSET=$((OFFSET + BUNIT_SZ))
566 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
567 quota_error a $TSTUSR "write success, but expect EDQUOT"
571 $SHOW_QUOTA_INFO_USER
572 $SHOW_QUOTA_INFO_GROUP
574 echo " Unlink file to stop timer"
581 $SHOW_QUOTA_INFO_USER
582 $SHOW_QUOTA_INFO_GROUP
585 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
593 # block soft limit (start timer, timer goes off, stop timer)
596 chmod 0777 $DIR/$tdir
598 # 1 bunit on mds and 1 bunit on every ost
599 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
602 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
603 TESTFILE=$DIR/$tdir/$tfile-0
605 $LFS setstripe $TESTFILE -c 1
606 chown $TSTUSR.$TSTUSR $TESTFILE
608 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
609 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
611 test_block_soft $TESTFILE $GRACE
612 resetquota -u $TSTUSR
614 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
615 TESTFILE=$DIR/$tdir/$tfile-1
617 $LFS setstripe $TESTFILE -c 1
618 chown $TSTUSR.$TSTUSR $TESTFILE
620 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
621 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
623 test_block_soft $TESTFILE $GRACE
624 resetquota -g $TSTUSR
626 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
631 TIMER=$(($3 * 3 / 2))
633 wait_delete_completed
635 echo " Create files to exceed soft limit"
636 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
637 quota_error a $TSTUSR "create failure, but expect success"
641 echo " Create file before timer goes off"
642 $RUNAS touch ${TESTFILE}_before || \
643 quota_error a $TSTUSR "failed create before timer expired, but expect success"
647 echo " Sleep $TIMER seconds ..."
652 $SHOW_QUOTA_INFO_USER
653 $SHOW_QUOTA_INFO_GROUP
655 echo " Create file after timer goes off"
656 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
657 # inode quota left here
658 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
660 $RUNAS touch ${TESTFILE}_after3 && \
661 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
666 $SHOW_QUOTA_INFO_USER
667 $SHOW_QUOTA_INFO_GROUP
669 echo " Unlink files to stop timer"
670 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
674 $RUNAS touch ${TESTFILE}_xxx || \
675 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
680 rm -f ${TESTFILE}_xxx
684 # file soft limit (start timer, timer goes off, stop timer)
685 test_4a() { # was test_4
687 chmod 0777 $DIR/$tdir
688 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
689 TESTFILE=$DIR/$tdir/$tfile-0
693 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
694 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
695 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
696 quota_show_check f u $TSTUSR
698 test_file_soft $TESTFILE $LIMIT $GRACE
699 resetquota -u $TSTUSR
701 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
702 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
703 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
704 quota_show_check f g $TSTUSR
705 TESTFILE=$DIR/$tdir/$tfile-1
707 test_file_soft $TESTFILE $LIMIT $GRACE
708 resetquota -g $TSTUSR
711 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
712 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
714 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
716 test_4b() { # was test_4a
722 GR_STR6="1111111111111111"
724 wait_delete_completed
726 # test of valid grace strings handling
727 echo " Valid grace strings test"
728 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
729 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
730 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
731 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
733 # test of invalid grace strings handling
734 echo " Invalid grace strings test"
735 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
736 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
739 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
740 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
742 run_test_with_stat 4b "Grace time strings handling ==="
744 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
747 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
748 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
750 wait_delete_completed
752 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
753 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
754 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
755 quota_show_check a u $TSTUSR
756 quota_show_check a g $TSTUSR
758 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
759 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
760 error "touch failure, expect success"
761 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
763 echo " Chown files to $TSTUSR.$TSTUSR ..."
764 for i in `seq 0 $ILIMIT`; do
765 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
766 quota_error a $TSTUSR "chown failure, but expect success"
770 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
773 resetquota -u $TSTUSR
774 resetquota -g $TSTUSR
776 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
778 # block quota acquire & release
780 if [ $OSTCOUNT -lt 2 ]; then
781 skip_env "$OSTCOUNT < 2, too few osts"
785 wait_delete_completed
788 chmod 0777 $DIR/$tdir
790 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
791 FILEA="$DIR/$tdir/$tfile-0_a"
792 FILEB="$DIR/$tdir/$tfile-0_b"
794 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
795 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
796 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
797 quota_show_check b u $TSTUSR
798 quota_show_check b g $TSTUSR
800 echo " Create filea on OST0 and fileb on OST1"
801 $LFS setstripe $FILEA -i 0 -c 1
802 $LFS setstripe $FILEB -i 1 -c 1
803 chown $TSTUSR.$TSTUSR $FILEA
804 chown $TSTUSR.$TSTUSR $FILEB
806 echo " Exceed quota limit ..."
807 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
808 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
809 quota_error a $TSTUSR "write filea failure, but expect success"
814 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
815 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
817 echo " Write to OST1 return EDQUOT"
818 # this write maybe cache write, ignore it's failure
819 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
820 $RUNDD count=$(($BUNIT_SZ * 2)) || true
824 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
825 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
827 echo " Remove filea to let OST0 release quota"
830 if at_is_enabled; then
831 timeout=$(at_max_get mds)
833 timeout=$(lctl get_param -n timeout)
835 count=$((timeout / 5))
836 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
838 while [ $((count--)) -gt 0 ]; do
841 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
842 if [ -z $OST0_QUOTA_HOLD ]; then
843 error "System is error when query quota for block (U:$TSTUSR)."
845 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
851 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
854 while [ $((count--)) -gt 0 ]; do
857 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
858 if [ -z $OST0_QUOTA_HOLD ]; then
859 error "System is error when query quota for block (G:$TSTUSR)."
861 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
867 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
870 echo " Write to OST1"
871 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
872 quota_error a $TSTUSR "write fileb failure, expect success"
879 resetquota -u $TSTUSR
880 resetquota -g $TSTUSR
883 run_test_with_stat 6 "Block quota acquire & release ========="
885 # quota recovery (block quota only by now)
889 chmod 0777 $DIR/$tdir
891 wait_delete_completed
893 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
894 TESTFILE="$DIR/$tdir/$tfile-0"
896 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
898 $LFS setstripe $TESTFILE -c 1
899 chown $TSTUSR.$TSTUSR $TESTFILE
901 echo " Write to OST0..."
902 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
903 quota_error u $TSTUSR "write failure, but expect success"
905 #define OBD_FAIL_OBD_DQACQ 0x604
906 lustre_fail mds 0x604
907 echo " Remove files on OST0"
911 echo " Trigger recovery..."
912 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
913 for i in $OSC0_UUID; do
914 $LCTL --device $i activate || error "activate osc failed!"
917 # sleep a while to wait for recovery done
921 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
922 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
923 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
924 echo " total limits = $TOTAL_LIMIT"
926 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
927 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
928 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
929 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
930 echo " limits on $OST0_UUID = $OST0_LIMIT"
933 resetquota -u $TSTUSR
935 run_test_with_stat 7 "Quota recovery (only block limit) ======"
937 # run dbench with quota enabled
940 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
943 wait_delete_completed
945 echo " Set enough high limit for user: $TSTUSR"
946 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
947 echo " Set enough high limit for group: $TSTUSR"
948 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
950 chmod 0777 $DIR/$tdir
952 [ "$SLOW" = "no" ] && duration=" -t 120"
953 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
960 run_test_with_stat 8 "Run dbench with quota enabled ==========="
962 # run for fixing bug10707, it needs a big room. test for 64bit
964 GB=$((KB * 1024 * 1024))
965 # Use this as dd bs to decrease time
966 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
967 blksize=$((1 << 21)) # 2Mb
968 size_file=$((GB * 9 / 2))
969 # this check is just for test_9
970 OST0_MIN=4900000 #4.67G
971 check_whether_skip () {
972 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
973 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
974 if [ $OST0_SIZE -lt $OST0_MIN ]; then
975 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
983 check_whether_skip && return 0
985 wait_delete_completed
991 chmod 0777 $DIR/$tdir
992 TESTFILE="$DIR/$tdir/$tfile-0"
994 BLK_LIMIT=$((100 * KB * KB)) # 100G
996 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
998 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
999 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1000 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1001 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1003 quota_show_check a u $TSTUSR
1004 quota_show_check a g $TSTUSR
1007 $LFS setstripe $TESTFILE -c 1 -i 0
1009 chown $TSTUSR.$TSTUSR $TESTFILE
1011 log " Write the big file of 4.5G ..."
1012 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1013 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1018 log " delete the big file of 4.5G..."
1019 $RUNAS rm -f $TESTFILE
1020 sync; sleep 3; sync;
1027 set_blk_unitsz $((128 * 1024))
1028 set_blk_tunesz $((128 * 1024 / 2))
1032 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1034 # 2.0 version does not support 32 bit qd_count,
1035 # test_10 "run for fixing bug10707(32bit) " is obsolete
1037 # test a deadlock between quota and journal b=11693
1040 chmod 0777 $DIR/$tdir
1042 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1043 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1045 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1046 TESTFILE="$DIR/$tdir/$tfile-0"
1047 TESTFILE2="$DIR2/$tdir/$tfile-1"
1049 wait_delete_completed
1051 echo " User quota (limit: $LIMIT kbytes)"
1052 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1054 $LFS setstripe $TESTFILE -i 0 -c 1
1055 chown $TSTUSR.$TSTUSR $TESTFILE
1056 $LFS setstripe $TESTFILE2 -i 0 -c 1
1057 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1059 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1060 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1061 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1063 echo " step1: write out of block quota ..."
1064 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1066 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1069 echo " step2: testing ......"
1070 local last_size=$(stat -c %s $TESTFILE2)
1072 local start_secs=$SECONDS
1073 while [ -d /proc/${DDPID1} ]; do
1074 local size=$(stat -c %s $TESTFILE2)
1075 if [ $size -eq $last_size ]; then
1076 stall_secs=$[stall_secs+1]
1080 if [ $stall_secs -gt 30 ]; then
1082 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1087 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1089 #Recover fail_loc and dd will finish soon
1092 echo " step3: testing ......"
1095 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1097 if [ $count -gt 150 ]; then
1098 quota_error u $TSTUSR "dd should be finished!"
1102 echo "(dd_pid=$DDPID, time=$count)successful"
1104 rm -f $TESTFILE $TESTFILE2
1105 sync; sleep 3; sync;
1107 resetquota -u $TSTUSR
1109 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1111 # test multiple clients write block quota b=11693
1114 wait_delete_completed
1116 # one OST * 10 + (mds + other OSTs)
1117 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1118 TESTFILE="$DIR/$tdir/$tfile"
1120 echo " User quota (limit: $LIMIT kbytes)"
1121 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1122 quota_show_check b u $TSTUSR
1124 $LFS setstripe $TESTFILE -i 0 -c 1
1125 chown $TSTUSR.$TSTUSR $TESTFILE
1126 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1127 chown $TSTUSR.$TSTUSR $TESTFILE.2
1129 echo " step1: write out of block quota ..."
1130 # one bunit will give mds
1131 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1133 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1136 echo " step2: testing ......"
1139 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1141 if [ $count -gt 64 ]; then
1142 quota_error u $TSTUSR "dd should be finished!"
1146 echo "(dd_pid=$DDPID, time=$count)successful"
1150 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1152 if [ $count -gt 64 ]; then
1153 quota_error u $TSTUSR "dd should be finished!"
1157 echo "(dd_pid=$DDPID1, time=$count)successful"
1159 sync; sleep 5; sync;
1161 echo " step3: checking ......"
1162 fz=`stat -c %s $TESTFILE`
1163 fz2=`stat -c %s $TESTFILE.2`
1165 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1166 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1168 rm -f $TESTFILE $TESTFILE.2
1169 sync; sleep 3; sync;
1171 resetquota -u $TSTUSR
1173 run_test_with_stat 13 "test multiple clients write block quota ==="
1175 check_if_quota_zero(){
1176 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1177 for i in `seq 3 $line`; do
1178 if [ $i -eq 3 ]; then
1184 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1185 awk '{print $'"$j"'}'`
1186 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1187 error "quota on $2 isn't clean"
1190 echo "pass check_if_quota_zero"
1193 test_14a() { # was test_14 b=12223 -- setting quota on root
1194 TESTFILE="$DIR/$tdir/$tfile"
1198 cleanup_and_setup_lustre
1203 # out of root's file and block quota
1204 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1205 createmany -m ${TESTFILE} 20 || \
1206 quota_error u root "unexpected: user(root) create files failly!"
1207 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1208 quota_error u root "unexpected: user(root) write files failly!"
1210 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1211 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1215 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1216 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1219 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1221 #check_if_quota_zero u root
1224 unlinkmany ${TESTFILE} 15
1226 sync; sleep 3; sync;
1228 run_test_with_stat 14a "test setting quota on root ==="
1231 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1232 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1234 wait_delete_completed
1237 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1238 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1239 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1240 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1241 resetquota -u $TSTUSR
1244 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1245 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1246 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1247 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1248 resetquota -g $TSTUSR
1249 $LFS quotaoff -ug $DIR
1250 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1251 error "fail to set version for $SINGLEMDS"
1252 for j in `seq $OSTCOUNT`; do
1253 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1254 error "fail to set version for ost$j"
1257 $LFS quotacheck -ug $DIR
1259 run_test_with_stat 15 "set block quota more than 4T ==="
1261 # 2.0 version does not support WITHOUT_CHANGE_QS,
1262 # test_16 "test without adjusting qunit" is obsolete
1264 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1269 wait_delete_completed
1271 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1272 lustre_fail ost 0x80000A02
1274 TESTFILE="$DIR/$tdir/$tfile-a"
1275 TESTFILE2="$DIR/$tdir/$tfile-b"
1278 BLK_LIMIT=$((100 * 1024)) # 100M
1280 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1281 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1282 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1283 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1285 quota_show_check b u $TSTUSR
1286 quota_show_check b g $TSTUSR
1289 chown $TSTUSR.$TSTUSR $TESTFILE
1291 chown $TSTUSR.$TSTUSR $TESTFILE2
1293 log " Write the test file1 ..."
1294 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1295 || quota_error a $TSTUSR "write 10M file failure"
1300 log " write the test file2 ..."
1301 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1302 || quota_error a $TSTUSR "write 10M file failure"
1307 rm -f $TESTFILE $TESTFILE2
1309 sync; sleep 3; sync;
1311 # make qd_count 64 bit
1314 set_blk_unitsz $((128 * 1024))
1315 set_blk_tunesz $((128 * 1024 / 2))
1317 resetquota -u $TSTUSR
1318 resetquota -g $TSTUSR
1322 run_test_with_stat 17 "run for fixing bug14526 ==========="
1324 # test when mds takes a long time to handle a quota req so that
1325 # the ost has dropped it, the ost still could work well b=14840
1327 LIMIT=$((100 * 1024 * 1024)) # 100G
1328 TESTFILE="$DIR/$tdir/$tfile"
1331 wait_delete_completed
1336 log " User quota (limit: $LIMIT kbytes)"
1337 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1338 quota_show_check b u $TSTUSR
1340 $LFS setstripe $TESTFILE -i 0 -c 1
1341 chown $TSTUSR.$TSTUSR $TESTFILE
1343 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1344 lustre_fail mds 0x13c
1346 log " step1: write 100M block ..."
1347 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1353 echo " step2: testing ......"
1355 if at_is_enabled; then
1356 timeout=$(at_max_get mds)
1358 timeout=$(lctl get_param -n timeout)
1361 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1363 if [ $count -gt $((4 * $timeout)) ]; then
1364 quota_error u $TSTUSR "count=$count dd should be finished!"
1368 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1370 cancel_lru_locks mdc
1371 cancel_lru_locks osc
1373 testfile_size=$(stat -c %s $TESTFILE)
1374 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1375 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1380 resetquota -u $TSTUSR
1381 set_blk_unitsz $((128 * 1024))
1382 set_blk_tunesz $((128 * 1024 / 2))
1384 run_test_with_stat 18 "run for fixing bug14840 ==========="
1386 # test when mds drops a quota req, the ost still could work well b=14840
1388 LIMIT=$((100 * 1024 * 1024)) # 100G
1389 TESTFILE="$DIR/$tdir/$tfile-a"
1392 wait_delete_completed
1397 log " User quota (limit: $LIMIT kbytes)"
1398 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1399 quota_show_check b u $TSTUSR
1401 $LFS setstripe $TESTFILE -i 0 -c 1
1402 chown $TSTUSR.$TSTUSR $TESTFILE
1404 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1405 lustre_fail mds 0x8000013d
1407 log " step1: write 100M block ..."
1408 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1411 echo " step2: testing ......"
1413 if at_is_enabled; then
1414 timeout=$(at_max_get mds)
1416 timeout=$(lctl get_param -n timeout)
1419 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1421 if [ $count -gt $((6 * $timeout)) ]; then
1423 quota_error u $TSTUSR "count=$count dd should be finished!"
1427 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1433 resetquota -u $TSTUSR
1434 set_blk_unitsz $((128 * 1024))
1435 set_blk_tunesz $((128 * 1024 / 2))
1437 run_test_with_stat 18a "run for fixing bug14840 ==========="
1439 # test when mds do failover, the ost still could work well without trigger
1444 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1445 TESTFILE="$DIR/$tdir/$tfile"
1448 wait_delete_completed
1453 log " User quota (limit: $LIMIT kbytes)"
1454 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1455 quota_show_check b u $TSTUSR
1457 $LFS setstripe $TESTFILE -i 0 -c 1
1458 chown $TSTUSR.$TSTUSR $TESTFILE
1460 timeout=$(sysctl -n lustre.timeout)
1462 if [ $type = "directio" ]; then
1463 log " write 100M block(directio) ..."
1464 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1466 log " write 100M block(normal) ..."
1467 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1471 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1473 replay_barrier $SINGLEMDS
1475 log "failing mds for $((2 * timeout)) seconds"
1476 fail $SINGLEMDS $((2 * timeout))
1478 # check if quotaon successful
1479 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1480 if [ $? -eq 0 ]; then
1482 error "quotaon failed!"
1487 if at_is_enabled; then
1488 timeout=$(at_max_get mds)
1490 timeout=$(lctl get_param -n timeout)
1493 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1494 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1495 log "it took $count second"
1499 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1501 cancel_lru_locks mdc
1502 cancel_lru_locks osc
1505 resetquota -u $TSTUSR
1506 set_blk_unitsz $((128 * 1024))
1507 set_blk_tunesz $((128 * 1024 / 2))
1508 testfile_size=$(stat -c %s $TESTFILE)
1509 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1511 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1517 # test when mds does failover, the ost still could work well
1518 # this test shouldn't trigger watchdog b=14840
1520 test_18bc_sub normal
1521 test_18bc_sub directio
1522 # check if watchdog is triggered
1523 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1524 watchdog=`awk '/test 18b/ {start = 1;}
1525 /Service thread pid/ && /was inactive/ {
1529 }' $TMP/lustre-log-${TESTNAME}.log`
1530 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1531 rm -f $TMP/lustre-log-${TESTNAME}.log
1533 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1535 # test when mds does failover, the ost still could work well
1536 # this test will prevent OST_DISCONNET from happening b=14840
1538 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1539 lustre_fail ost 0x202
1540 test_18bc_sub normal
1541 test_18bc_sub directio
1544 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1546 run_to_block_limit() {
1547 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1549 wait_delete_completed
1551 # set 1 Mb quota unit size
1555 # bind file to a single OST
1556 $LFS setstripe -c 1 $TESTFILE
1557 chown $TSTUSR.$TSTUSR $TESTFILE
1559 echo " User quota (limit: $LIMIT kbytes)"
1560 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1561 quota_show_check b u $TSTUSR
1562 echo " Updating quota limits"
1563 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1564 quota_show_check b u $TSTUSR
1566 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1567 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1568 # for now page cache of TESTFILE may still be dirty,
1569 # let's push it to the corresponding OST, this will also
1570 # cache NOQUOTA on the client from OST's reply
1571 cancel_lru_locks osc
1572 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1576 # 1 Mb bunit per each MDS/OSS
1577 local TESTFILE="$DIR/$tdir/$tfile"
1580 run_to_block_limit $TESTFILE
1585 resetquota -u $TSTUSR
1587 set_blk_unitsz $((128 * 1024))
1588 set_blk_tunesz $((128 * 1024 / 2))
1591 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1595 LSTR=(1t 2g 3m 4k) # limits strings
1596 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1598 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1599 $MOUNT || error "could not set quota limits"
1601 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1602 --inode-softlimit ${LSTR[2]} \
1603 --inode-hardlimit ${LSTR[3]} \
1604 $MOUNT || error "could not set quota limits"
1606 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1607 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1608 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1609 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1611 resetquota -u $TSTUSR
1613 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1620 time=$(($(date +%s) + seconds))
1621 while [ $(date +%s) -lt $time ]; do
1622 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1627 # run for fixing bug16053, setquota shouldn't fail when writing and
1628 # deleting are happening
1633 wait_delete_completed
1635 TESTFILE="$DIR/$tdir/$tfile"
1637 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1640 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1641 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1642 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1643 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1645 # repeat writing on a 1M file
1646 test_21_sub ${TESTFILE}_1 1024 30 &
1648 # repeat writing on a 128M file
1649 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1652 time=$(($(date +%s) + 30))
1654 while [ $(date +%s) -lt $time ]; do
1655 log " Set quota for $i times"
1656 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1657 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1664 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1666 if [ $count -gt 60 ]; then
1667 quota_error a $TSTUSR "dd should be finished!"
1671 echo "(dd_pid=$DDPID1, time=$count)successful"
1675 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1677 if [ $count -gt 60 ]; then
1678 quota_error a $TSTUSR "dd should be finished!"
1682 echo "(dd_pid=$DDPID2, time=$count)successful"
1684 set_blk_unitsz $((128 * 1024))
1685 set_blk_tunesz $((128 * 1024 / 2))
1686 resetquota -u $TSTUSR
1687 resetquota -g $TSTUSR
1691 run_test_with_stat 21 "run for fixing bug16053 ==========="
1694 quota_save_version "ug3"
1700 echo "checking parameters"
1702 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1703 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1707 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1711 chmod 0777 $DIR/$tdir
1712 TESTFILE="$DIR/$tdir/$tfile-0"
1714 local bs_unit=$((1024*1024))
1717 wait_delete_completed
1720 log " User quota (limit: $LIMIT kbytes)"
1721 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1723 quota_show_check b u $TSTUSR
1725 $LFS setstripe $TESTFILE -c 1 -i 0
1726 chown $TSTUSR.$TSTUSR $TESTFILE
1728 log " Step1: trigger quota with 0_DIRECT"
1729 log " Write half of file"
1730 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1731 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1732 log " Write out of block quota ..."
1733 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1734 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1737 log " Step2: rewrite should succeed"
1738 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1739 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1743 wait_delete_completed
1744 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1745 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1746 echo $OST0_QUOTA_USED
1747 [ $OST0_QUOTA_USED -ne 0 ] && \
1748 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1750 resetquota -u $TSTUSR
1754 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1756 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1757 check_whether_skip && return 0
1758 log "run for $((4 * $slave_cnt))MB test file"
1759 test_23_sub $((4 * $slave_cnt * 1024))
1761 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1762 check_whether_skip && return 0
1763 log "run for $((40 * $slave_cnt))MB test file"
1764 test_23_sub $((40 * $slave_cnt * 1024))
1766 run_test_with_stat 23 "run for fixing bug16125 ==========="
1769 local TESTFILE="$DIR/$tdir/$tfile"
1772 run_to_block_limit $TESTFILE
1773 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1777 resetquota -u $TSTUSR
1779 set_blk_unitsz $((128 * 1024))
1780 set_blk_tunesz $((128 * 1024 / 2))
1783 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1786 if [ $1 = "-u" ]; then
1787 if [ $2 = "$TSTUSR" ]; then
1793 if [ $2 = "$TSTUSR" ]; then
1803 chmod 0777 $DIR/$tdir
1804 TESTFILE="$DIR/$tdir/$tfile-0"
1806 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1808 wait_delete_completed
1810 # set quota for $TSTUSR
1811 log "setquota for $TSTUSR"
1812 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1814 if [ "$1" == "-u" ]; then
1815 quota_show_check a u $TSTUSR
1817 quota_show_check a g $TSTUSR
1820 # set quota for $TSTUSR2
1821 log "setquota for $TSTUSR2"
1822 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1824 if [ "$1" == "-u" ]; then
1825 quota_show_check a u $TSTUSR2
1827 quota_show_check a g $TSTUSR2
1830 # set stripe index to 0
1831 log "setstripe for $DIR/$tdir to 0"
1832 $LFS setstripe $DIR/$tdir -c 1 -i 0
1833 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1834 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1835 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1836 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1837 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1838 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1841 log "$TSTUSR write 4M to $TESTFILE"
1842 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1844 show_quota $1 $TSTUSR
1845 show_quota $1 $TSTUSR2
1846 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1847 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1848 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1849 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1850 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1851 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1852 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1854 # chown/chgrp from $TSTUSR to $TSTUSR2
1855 if [ $1 = "-u" ]; then
1856 log "chown from $TSTUSR to $TSTUSR2"
1857 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1859 log "chgrp from $TSTUSR to $TSTUSR2"
1860 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1863 show_quota $1 $TSTUSR
1864 show_quota $1 $TSTUSR2
1865 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1866 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1867 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1868 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1869 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1870 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1871 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1872 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1873 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1874 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1875 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1876 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1877 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1878 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1879 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1882 wait_delete_completed
1883 resetquota $1 $TSTUSR
1884 resetquota $1 $TSTUSR2
1888 log "run for chown case"
1891 log "run for chgrp case"
1894 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1898 chmod 0777 $DIR/$tdir
1899 TESTFILE="$DIR/$tdir/$tfile-0"
1900 TESTFILE2="$DIR/$tdir/$tfile-1"
1904 wait_delete_completed
1906 # every quota slave gets 20MB
1907 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1908 log "limit: ${b_limit}KB"
1909 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1911 quota_show_check b u $TSTUSR
1913 $LFS setstripe $TESTFILE -c 1 -i 0
1914 $LFS setstripe $TESTFILE2 -c 1 -i 0
1915 chown $TSTUSR.$TSTUSR $TESTFILE
1916 chown $TSTUSR.$TSTUSR $TESTFILE2
1918 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1919 lustre_fail ost 0xA03
1921 log " Write the first file..."
1922 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1923 log " Delete the first file..."
1927 wait_delete_completed
1929 log " Write the second file..."
1930 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1931 log " Delete the second file..."
1935 set_blk_unitsz $((128 * 1024))
1936 set_blk_tunesz $((128 * 1024 / 2))
1937 resetquota -u $TSTUSR
1939 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1942 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1943 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1946 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1949 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1950 error "lfs setquota failed with uid argument"
1951 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1952 error "lfs stequota failed with gid argument"
1953 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1954 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1955 resetquota -u $TSTUSR
1956 resetquota -g $TSTUSR
1959 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1962 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1963 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1964 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1967 echo "Step 2: reset system ..."
1968 cleanup_and_setup_lustre
1971 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1975 wait_delete_completed
1977 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1978 lustre_fail ost 0x80000A02
1980 TESTFILE="$DIR/$tdir/$tfile"
1983 BLK_LIMIT=$((100 * 1024)) # 100M
1984 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1985 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1989 chown $TSTUSR.$TSTUSR $TESTFILE
1991 echo "Step 5: write the test file1 [10M] ..."
1992 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1993 || quota_error a $TSTUSR "write 10M file failure"
1997 sync; sleep 3; sync;
1999 # make qd_count 64 bit
2002 set_blk_unitsz $((128 * 1024))
2003 set_blk_tunesz $((128 * 1024 / 2))
2005 resetquota -u $TSTUSR
2007 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2011 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2020 if at_is_enabled; then
2021 timeout=$(at_max_get client)
2022 [ $(at_min_get client) -gt $at_max_val ] &&
2023 at_max_val=$(at_min_get client)
2024 at_max_set $at_max_val client
2026 timeout=$(lctl get_param -n timeout)
2027 lctl set_param timeout=$at_max_val
2029 # actually send a RPC to make service at_current confined within at_max
2030 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR ||
2031 error "should succeed"
2033 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2034 lustre_fail mds 0x12e
2036 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2038 deadline=$((2 * (($at_max_val << 1) + ($at_max_val >> 2) + 5)))
2039 echo "wait at most 2 * ($at_max_val * 2.25 + 5) = $deadline seconds," \
2040 "it is server process time add the network latency."
2043 while [ $waited -lt $deadline ]; do
2046 waited=$(($waited + 1))
2047 ps -p $pid > /dev/null || break
2049 echo "waited $waited seconds"
2050 ps -p $pid && error "lfs hadn't finished by $deadline seconds"
2051 wait $pid && error "succeeded, but should have failed"
2055 if at_is_enabled; then
2056 at_max_set $timeout client
2058 lctl set_param timeout=$timeout
2061 resetquota -u $TSTUSR
2063 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2069 local TESTFILE="$DIR/$tdir/$tfile"
2076 chmod 0777 $DIR/$tdir
2078 $LFS setstripe $TESTFILE -i 0 -c 1
2079 chown $TSTUSR.$TSTUSR $TESTFILE
2081 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2082 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2083 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2084 cancel_lru_locks osc
2086 $LFS setquota -u $TSTUSR -B 0 $DIR
2087 # over-quota flag has not yet settled since we do not trigger async events
2088 # based on grace time period expiration
2090 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2091 cancel_lru_locks osc
2092 # now over-quota flag should be settled and further writes should fail
2094 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2096 resetquota -u $TSTUSR
2097 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2099 set_blk_unitsz $((128 * 1024))
2100 set_blk_tunesz $((128 * 1024 / 2))
2102 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2104 # test duplicate quota releases b=18630
2107 chmod 0777 $DIR/$tdir
2109 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2110 TESTFILE="$DIR/$tdir/$tfile-0"
2111 TESTFILE2="$DIR/$tdir/$tfile-1"
2113 wait_delete_completed
2115 log " User quota (limit: $LIMIT kbytes)"
2116 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2118 $LFS setstripe $TESTFILE -i 0 -c 1
2119 chown $TSTUSR.$TSTUSR $TESTFILE
2120 $LFS setstripe $TESTFILE2 -i 0 -c 1
2121 chown $TSTUSR.$TSTUSR $TESTFILE2
2123 log " step1: write out of block quota ..."
2124 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2125 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2127 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2128 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2129 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2131 log " step2: delete two files so that triggering duplicate quota release ..."
2132 rm -f $TESTFILE $TESTFILE2
2133 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2134 wait_delete_completed
2136 log " step3: verify if the ost failed"
2137 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2138 watchdog=`awk '/test 31/ {start = 1;}
2139 /release quota error/ {
2143 }' $TMP/lustre-log-${TESTNAME}.log`
2144 [ "$watchdog" ] && error "$watchdog"
2145 rm -f $TMP/lustre-log-${TESTNAME}.log
2148 resetquota -u $TSTUSR
2150 run_test_with_stat 31 "test duplicate quota releases ==="
2152 # check hash_cur_bits
2153 check_quota_hash_cur_bits() {
2156 # check quota_hash_cur_bits on all obdfilters
2157 for num in `seq $OSTCOUNT`; do
2158 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2159 if [ $cb -gt $bits ]; then
2160 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2164 # check quota_hash_cur_bits on mds
2165 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2166 if [ $cb -gt $bits ]; then
2167 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2175 # check distribution of all obdfilters
2176 for num in `seq $OSTCOUNT`; do
2177 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2178 rehash_count=`echo $line | awk '{print $9}'`
2179 if [ $rehash_count -eq 0 ]; then
2180 echo -e "ost$num:\n $line"
2181 error "Rehearsh didn't happen"
2185 # check distribution of mds
2186 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2187 rehash_count=`echo $line | awk '{print $9}'`
2188 if [ $rehash_count -eq 0 ]; then
2189 echo -e "mdt:\n $line"
2190 error "Rehearsh didn't happen"
2197 # reset system so that quota_hash_cur_bits==3
2198 echo "Reset system ..."
2199 local LMR_orig=$LOAD_MODULES_REMOTE
2200 LOAD_MODULES_REMOTE=true
2201 cleanup_and_setup_lustre
2202 LOAD_MODULES_REMOTE=$LMR_orig
2208 for user in $SANITY_QUOTA_USERS; do
2209 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2210 missing_users="$missing_users $user"
2212 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2213 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2215 $LFS quotaoff -ug $DIR
2216 $LFS quotacheck -ug $DIR
2218 for user in $SANITY_QUOTA_USERS; do
2219 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2224 for user in $SANITY_QUOTA_USERS; do
2228 run_test 32 "check lqs hash(bug 21846) =========================================="
2230 cleanup_quota_test() {
2232 echo "Delete files..."
2236 # basic usage tracking for user & group
2239 chmod 0777 $DIR/$tdir
2242 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2244 trap cleanup_quota_test EXIT
2246 # make sure the system is clean
2247 USED=`getquota -u $TSTID global curspace`
2248 [ $USED -ne 0 ] && \
2249 error "Used space ($USED) for user $TSTID isn't 0."
2250 USED=`getquota -g $TSTID global curspace`
2251 [ $USED -ne 0 ] && \
2252 error "Used space ($USED) for group $TSTID isn't 0."
2254 for i in `seq 0 $INODES`; do
2255 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i conv=fsync \
2256 bs=$((BLK_SZ * BLK_CNT)) count=1 2>/dev/null ||
2257 error "write failed"
2258 echo "Iteration $i/$INODES completed"
2260 sync; sync_all_data;
2262 echo "Verify disk usage after write"
2263 USED=`getquota -u $TSTID global curspace`
2264 [ $USED -lt $TOTAL_BLKS ] && \
2265 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2266 USED=`getquota -u $TSTID global curinodes`
2267 [ $USED -lt $INODES ] && \
2268 error "Used inode for user $TSTID is $USED, expected $INODES"
2270 USED=`getquota -g $TSTID global curspace`
2271 [ $USED -lt $TOTAL_BLKS ] && \
2272 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2273 USED=`getquota -g $TSTID global curinodes`
2274 [ $USED -lt $INODES ] && \
2275 error "Used inode for group $TSTID is $USED, expected $INODES"
2279 echo "Verify disk usage after delete"
2280 wait_delete_completed
2281 USED=`getquota -u $TSTID global curspace`
2282 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2283 USED=`getquota -u $TSTID global curinodes`
2284 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2285 USED=`getquota -g $TSTID global curspace`
2286 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2287 USED=`getquota -g $TSTID global curinodes`
2288 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2290 run_test 33 "basic usage tracking for user & group =============================="
2292 # usage transfer test for user & group
2296 chmod 0777 $DIR/$tdir
2298 trap cleanup_quota_test EXIT
2300 # make sure the system is clean
2301 USED=`getquota -u $TSTID global curspace`
2302 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2303 USED=`getquota -g $TSTID global curspace`
2304 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2306 echo "Write file..."
2307 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) count=1 \
2308 conv=fsync 2>/dev/null || error "write failed"
2309 sync; sync_all_data;
2311 echo "chown the file to user $TSTID"
2312 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2314 echo "Wait for setattr on objects finished..."
2315 wait_delete_completed
2317 echo "Verify disk usage for user $TSTID"
2318 USED=`getquota -u $TSTID global curspace`
2319 [ $USED -lt $BLK_CNT ] && \
2320 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2321 USED=`getquota -u $TSTID global curinodes`
2322 [ $USED -ne 1 ] && \
2323 error "Used inodes for user $TSTID is $USED, expected 1"
2325 echo "chgrp the file to group $TSTID"
2326 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2328 echo "Wait for setattr on objects finished..."
2329 wait_delete_completed
2331 echo "Verify disk usage for group $TSTID"
2332 USED=`getquota -g $TSTID global curspace`
2333 [ $USED -ge $BLK_CNT ] || \
2334 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2335 USED=`getquota -g $TSTID global curinodes`
2336 [ $USED -eq 1 ] || \
2337 error "Used inodes for group $TSTID is $USED, expected 1"
2341 run_test 34 "usage transfer for user & group ===================================="
2343 # usage is still accessible across restart
2346 chmod 0777 $DIR/$tdir
2349 trap cleanup_quota_test EXIT
2351 echo "Write file..."
2352 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2353 count=1 conv=fsync 2>/dev/null || error "write failed"
2354 sync; sync_all_data;
2356 echo "Save disk usage before restart"
2357 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2358 [ $ORIG_USR_SPACE -eq 0 ] && \
2359 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2360 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2361 [ $ORIG_USR_INODES -eq 0 ] && \
2362 error "Used inodes for user $TSTID is 0, expected 1"
2363 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2364 [ $ORIG_GRP_SPACE -eq 0 ] && \
2365 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2366 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2367 [ $ORIG_GRP_INODES -eq 0 ] && \
2368 error "Used inodes for group $TSTID is 0, expected 1"
2371 local ORIG_REFORMAT=$REFORMAT
2373 cleanup_and_setup_lustre
2374 REFORMAT=$ORIG_REFORMAT
2377 echo "Verify disk usage after restart"
2378 USED=`getquota -u $TSTID global curspace`
2379 [ $USED -eq $ORIG_USR_SPACE ] || \
2380 error "Used space for user $TSTID changed from " \
2381 "$ORIG_USR_SPACE to $USED"
2382 USED=`getquota -u $TSTID global curinodes`
2383 [ $USED -eq $ORIG_USR_INODES ] || \
2384 error "Used inodes for user $TSTID changed from " \
2385 "$ORIG_USR_INODES to $USED"
2386 USED=`getquota -g $TSTID global curspace`
2387 [ $USED -eq $ORIG_GRP_SPACE ] || \
2388 error "Used space for group $TSTID changed from " \
2389 "$ORIG_GRP_SPACE to $USED"
2390 USED=`getquota -g $TSTID global curinodes`
2391 [ $USED -eq $ORIG_GRP_INODES ] || \
2392 error "Used inodes for group $TSTID changed from " \
2393 "$ORIG_GRP_INODES to $USED"
2395 # check if the vfs_dq_init() is called before writing
2396 echo "Append to the same file..."
2397 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2398 count=1 seek=1 conv=fsync 2>/dev/null || error "write failed"
2399 sync; sync_all_data;
2401 echo "Verify space usage is increased"
2402 USED=`getquota -u $TSTID global curspace`
2403 [ $USED -gt $ORIG_USR_SPACE ] ||
2404 error "Used space for user $TSTID isn't increased" \
2405 "orig:$ORIG_USR_SPACE, now:$USED"
2406 USED=`getquota -g $TSTID global curspace`
2407 [ $USED -gt $ORIG_GRP_SPACE ] ||
2408 error "Used space for group $TSTID isn't increased" \
2409 "orig:$ORIG_GRP_SPACE, now:$USED"
2413 run_test 35 "usage is still accessible across reboot ============================"
2419 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2424 complete $(basename $0) $SECONDS
2425 check_and_cleanup_lustre
2426 export QUOTA_AUTO=$QUOTA_AUTO_OLD