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 echo "invalidating quota files"
1258 $LFS quotainv -ug $DIR
1259 $LFS quotainv -ugf $DIR
1260 $LFS quotacheck -ug $DIR
1262 run_test_with_stat 15 "set block quota more than 4T ==="
1264 # 2.0 version does not support WITHOUT_CHANGE_QS,
1265 # test_16 "test without adjusting qunit" is obsolete
1267 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1272 wait_delete_completed
1274 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1275 lustre_fail ost 0x80000A02
1277 TESTFILE="$DIR/$tdir/$tfile-a"
1278 TESTFILE2="$DIR/$tdir/$tfile-b"
1281 BLK_LIMIT=$((100 * 1024)) # 100M
1283 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1284 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1285 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1286 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1288 quota_show_check b u $TSTUSR
1289 quota_show_check b g $TSTUSR
1292 chown $TSTUSR.$TSTUSR $TESTFILE
1294 chown $TSTUSR.$TSTUSR $TESTFILE2
1296 log " Write the test file1 ..."
1297 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1298 || quota_error a $TSTUSR "write 10M file failure"
1303 log " write the test file2 ..."
1304 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1305 || quota_error a $TSTUSR "write 10M file failure"
1310 rm -f $TESTFILE $TESTFILE2
1312 sync; sleep 3; sync;
1314 # make qd_count 64 bit
1317 set_blk_unitsz $((128 * 1024))
1318 set_blk_tunesz $((128 * 1024 / 2))
1320 resetquota -u $TSTUSR
1321 resetquota -g $TSTUSR
1325 run_test_with_stat 17 "run for fixing bug14526 ==========="
1327 # test when mds takes a long time to handle a quota req so that
1328 # the ost has dropped it, the ost still could work well b=14840
1330 LIMIT=$((100 * 1024 * 1024)) # 100G
1331 TESTFILE="$DIR/$tdir/$tfile"
1334 wait_delete_completed
1339 log " User quota (limit: $LIMIT kbytes)"
1340 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1341 quota_show_check b u $TSTUSR
1343 $LFS setstripe $TESTFILE -i 0 -c 1
1344 chown $TSTUSR.$TSTUSR $TESTFILE
1346 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1347 lustre_fail mds 0x13c
1349 log " step1: write 100M block ..."
1350 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1356 echo " step2: testing ......"
1358 if at_is_enabled; then
1359 timeout=$(at_max_get mds)
1361 timeout=$(lctl get_param -n timeout)
1364 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1366 if [ $count -gt $((4 * $timeout)) ]; then
1367 quota_error u $TSTUSR "count=$count dd should be finished!"
1371 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1373 cancel_lru_locks mdc
1374 cancel_lru_locks osc
1376 testfile_size=$(stat -c %s $TESTFILE)
1377 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1378 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1383 resetquota -u $TSTUSR
1384 set_blk_unitsz $((128 * 1024))
1385 set_blk_tunesz $((128 * 1024 / 2))
1387 run_test_with_stat 18 "run for fixing bug14840 ==========="
1389 # test when mds drops a quota req, the ost still could work well b=14840
1391 LIMIT=$((100 * 1024 * 1024)) # 100G
1392 TESTFILE="$DIR/$tdir/$tfile-a"
1395 wait_delete_completed
1400 log " User quota (limit: $LIMIT kbytes)"
1401 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1402 quota_show_check b u $TSTUSR
1404 $LFS setstripe $TESTFILE -i 0 -c 1
1405 chown $TSTUSR.$TSTUSR $TESTFILE
1407 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1408 lustre_fail mds 0x8000013d
1410 log " step1: write 100M block ..."
1411 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1414 echo " step2: testing ......"
1416 if at_is_enabled; then
1417 timeout=$(at_max_get mds)
1419 timeout=$(lctl get_param -n timeout)
1422 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1424 if [ $count -gt $((6 * $timeout)) ]; then
1426 quota_error u $TSTUSR "count=$count dd should be finished!"
1430 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1436 resetquota -u $TSTUSR
1437 set_blk_unitsz $((128 * 1024))
1438 set_blk_tunesz $((128 * 1024 / 2))
1440 run_test_with_stat 18a "run for fixing bug14840 ==========="
1442 # test when mds do failover, the ost still could work well without trigger
1447 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1448 TESTFILE="$DIR/$tdir/$tfile"
1451 wait_delete_completed
1456 log " User quota (limit: $LIMIT kbytes)"
1457 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1458 quota_show_check b u $TSTUSR
1460 $LFS setstripe $TESTFILE -i 0 -c 1
1461 chown $TSTUSR.$TSTUSR $TESTFILE
1463 timeout=$(sysctl -n lustre.timeout)
1465 if [ $type = "directio" ]; then
1466 log " write 100M block(directio) ..."
1467 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1469 log " write 100M block(normal) ..."
1470 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1474 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1476 replay_barrier $SINGLEMDS
1478 log "failing mds for $((2 * timeout)) seconds"
1479 fail $SINGLEMDS $((2 * timeout))
1481 # check if quotaon successful
1482 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1483 if [ $? -eq 0 ]; then
1485 error "quotaon failed!"
1490 if at_is_enabled; then
1491 timeout=$(at_max_get mds)
1493 timeout=$(lctl get_param -n timeout)
1496 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1497 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1498 log "it took $count second"
1502 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1504 cancel_lru_locks mdc
1505 cancel_lru_locks osc
1508 resetquota -u $TSTUSR
1509 set_blk_unitsz $((128 * 1024))
1510 set_blk_tunesz $((128 * 1024 / 2))
1511 testfile_size=$(stat -c %s $TESTFILE)
1512 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1514 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1520 # test when mds does failover, the ost still could work well
1521 # this test shouldn't trigger watchdog b=14840
1523 test_18bc_sub normal
1524 test_18bc_sub directio
1525 # check if watchdog is triggered
1526 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1527 watchdog=`awk '/test 18b/ {start = 1;}
1528 /Service thread pid/ && /was inactive/ {
1532 }' $TMP/lustre-log-${TESTNAME}.log`
1533 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1534 rm -f $TMP/lustre-log-${TESTNAME}.log
1536 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1538 # test when mds does failover, the ost still could work well
1539 # this test will prevent OST_DISCONNET from happening b=14840
1541 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1542 lustre_fail ost 0x202
1543 test_18bc_sub normal
1544 test_18bc_sub directio
1547 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1549 run_to_block_limit() {
1550 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1552 wait_delete_completed
1554 # set 1 Mb quota unit size
1558 # bind file to a single OST
1559 $LFS setstripe -c 1 $TESTFILE
1560 chown $TSTUSR.$TSTUSR $TESTFILE
1562 echo " User quota (limit: $LIMIT kbytes)"
1563 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1564 quota_show_check b u $TSTUSR
1565 echo " Updating quota limits"
1566 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1567 quota_show_check b u $TSTUSR
1569 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1570 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1571 # for now page cache of TESTFILE may still be dirty,
1572 # let's push it to the corresponding OST, this will also
1573 # cache NOQUOTA on the client from OST's reply
1574 cancel_lru_locks osc
1575 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1579 # 1 Mb bunit per each MDS/OSS
1580 local TESTFILE="$DIR/$tdir/$tfile"
1583 run_to_block_limit $TESTFILE
1588 resetquota -u $TSTUSR
1590 set_blk_unitsz $((128 * 1024))
1591 set_blk_tunesz $((128 * 1024 / 2))
1594 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1598 LSTR=(1t 2g 3m 4k) # limits strings
1599 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1601 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1602 $MOUNT || error "could not set quota limits"
1604 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1605 --inode-softlimit ${LSTR[2]} \
1606 --inode-hardlimit ${LSTR[3]} \
1607 $MOUNT || error "could not set quota limits"
1609 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1610 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1611 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1612 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1614 resetquota -u $TSTUSR
1616 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1623 time=$(($(date +%s) + seconds))
1624 while [ $(date +%s) -lt $time ]; do
1625 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1630 # run for fixing bug16053, setquota shouldn't fail when writing and
1631 # deleting are happening
1636 wait_delete_completed
1638 TESTFILE="$DIR/$tdir/$tfile"
1640 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1643 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1644 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1645 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1646 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1648 # repeat writing on a 1M file
1649 test_21_sub ${TESTFILE}_1 1024 30 &
1651 # repeat writing on a 128M file
1652 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1655 time=$(($(date +%s) + 30))
1657 while [ $(date +%s) -lt $time ]; do
1658 log " Set quota for $i times"
1659 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1660 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1667 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1669 if [ $count -gt 60 ]; then
1670 quota_error a $TSTUSR "dd should be finished!"
1674 echo "(dd_pid=$DDPID1, time=$count)successful"
1678 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1680 if [ $count -gt 60 ]; then
1681 quota_error a $TSTUSR "dd should be finished!"
1685 echo "(dd_pid=$DDPID2, time=$count)successful"
1687 set_blk_unitsz $((128 * 1024))
1688 set_blk_tunesz $((128 * 1024 / 2))
1689 resetquota -u $TSTUSR
1690 resetquota -g $TSTUSR
1694 run_test_with_stat 21 "run for fixing bug16053 ==========="
1697 quota_save_version "ug3"
1703 echo "checking parameters"
1705 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1706 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1710 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1714 chmod 0777 $DIR/$tdir
1715 TESTFILE="$DIR/$tdir/$tfile-0"
1717 local bs_unit=$((1024*1024))
1720 wait_delete_completed
1723 log " User quota (limit: $LIMIT kbytes)"
1724 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1726 quota_show_check b u $TSTUSR
1728 $LFS setstripe $TESTFILE -c 1 -i 0
1729 chown $TSTUSR.$TSTUSR $TESTFILE
1731 log " Step1: trigger quota with 0_DIRECT"
1732 log " Write half of file"
1733 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1734 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1735 log " Write out of block quota ..."
1736 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1737 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1740 log " Step2: rewrite should succeed"
1741 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1742 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1746 wait_delete_completed
1747 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1748 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1749 echo $OST0_QUOTA_USED
1750 [ $OST0_QUOTA_USED -ne 0 ] && \
1751 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1753 resetquota -u $TSTUSR
1757 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1759 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1760 check_whether_skip && return 0
1761 log "run for $((4 * $slave_cnt))MB test file"
1762 test_23_sub $((4 * $slave_cnt * 1024))
1764 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1765 check_whether_skip && return 0
1766 log "run for $((40 * $slave_cnt))MB test file"
1767 test_23_sub $((40 * $slave_cnt * 1024))
1769 run_test_with_stat 23 "run for fixing bug16125 ==========="
1772 local TESTFILE="$DIR/$tdir/$tfile"
1775 run_to_block_limit $TESTFILE
1776 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1780 resetquota -u $TSTUSR
1782 set_blk_unitsz $((128 * 1024))
1783 set_blk_tunesz $((128 * 1024 / 2))
1786 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1789 if [ $1 = "-u" ]; then
1790 if [ $2 = "$TSTUSR" ]; then
1796 if [ $2 = "$TSTUSR" ]; then
1806 chmod 0777 $DIR/$tdir
1807 TESTFILE="$DIR/$tdir/$tfile-0"
1809 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1811 wait_delete_completed
1813 # set quota for $TSTUSR
1814 log "setquota for $TSTUSR"
1815 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1817 if [ "$1" == "-u" ]; then
1818 quota_show_check a u $TSTUSR
1820 quota_show_check a g $TSTUSR
1823 # set quota for $TSTUSR2
1824 log "setquota for $TSTUSR2"
1825 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1827 if [ "$1" == "-u" ]; then
1828 quota_show_check a u $TSTUSR2
1830 quota_show_check a g $TSTUSR2
1833 # set stripe index to 0
1834 log "setstripe for $DIR/$tdir to 0"
1835 $LFS setstripe $DIR/$tdir -c 1 -i 0
1836 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1837 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1838 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1839 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1840 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1841 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1844 log "$TSTUSR write 4M to $TESTFILE"
1845 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1847 show_quota $1 $TSTUSR
1848 show_quota $1 $TSTUSR2
1849 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1850 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1851 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1852 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1853 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1854 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1855 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1857 # chown/chgrp from $TSTUSR to $TSTUSR2
1858 if [ $1 = "-u" ]; then
1859 log "chown from $TSTUSR to $TSTUSR2"
1860 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1862 log "chgrp from $TSTUSR to $TSTUSR2"
1863 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1866 show_quota $1 $TSTUSR
1867 show_quota $1 $TSTUSR2
1868 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1869 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1870 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1871 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1872 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1873 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1874 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1875 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1876 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1877 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1878 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1879 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1880 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1881 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1882 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1885 wait_delete_completed
1886 resetquota $1 $TSTUSR
1887 resetquota $1 $TSTUSR2
1891 log "run for chown case"
1894 log "run for chgrp case"
1897 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1901 chmod 0777 $DIR/$tdir
1902 TESTFILE="$DIR/$tdir/$tfile-0"
1903 TESTFILE2="$DIR/$tdir/$tfile-1"
1907 wait_delete_completed
1909 # every quota slave gets 20MB
1910 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1911 log "limit: ${b_limit}KB"
1912 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1914 quota_show_check b u $TSTUSR
1916 $LFS setstripe $TESTFILE -c 1 -i 0
1917 $LFS setstripe $TESTFILE2 -c 1 -i 0
1918 chown $TSTUSR.$TSTUSR $TESTFILE
1919 chown $TSTUSR.$TSTUSR $TESTFILE2
1921 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1922 lustre_fail ost 0xA03
1924 log " Write the first file..."
1925 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1926 log " Delete the first file..."
1930 wait_delete_completed
1932 log " Write the second file..."
1933 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1934 log " Delete the second file..."
1938 set_blk_unitsz $((128 * 1024))
1939 set_blk_tunesz $((128 * 1024 / 2))
1940 resetquota -u $TSTUSR
1942 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1945 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1946 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1949 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1952 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1953 error "lfs setquota failed with uid argument"
1954 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1955 error "lfs stequota failed with gid argument"
1956 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1957 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1958 resetquota -u $TSTUSR
1959 resetquota -g $TSTUSR
1962 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1965 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1966 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1967 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1970 echo "Step 2: reset system ..."
1971 cleanup_and_setup_lustre
1974 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1978 wait_delete_completed
1980 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1981 lustre_fail ost 0x80000A02
1983 TESTFILE="$DIR/$tdir/$tfile"
1986 BLK_LIMIT=$((100 * 1024)) # 100M
1987 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1988 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1992 chown $TSTUSR.$TSTUSR $TESTFILE
1994 echo "Step 5: write the test file1 [10M] ..."
1995 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1996 || quota_error a $TSTUSR "write 10M file failure"
2000 sync; sleep 3; sync;
2002 # make qd_count 64 bit
2005 set_blk_unitsz $((128 * 1024))
2006 set_blk_tunesz $((128 * 1024 / 2))
2008 resetquota -u $TSTUSR
2010 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2014 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2018 if at_is_enabled; then
2019 timeout=$(at_max_get client)
2020 at_max_set 10 client
2022 timeout=$(lctl get_param -n timeout)
2023 lctl set_param timeout=10
2025 # actually send a RPC to make service at_current confined within at_max
2026 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR || error "should succeed"
2028 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2029 lustre_fail mds 0x12e
2031 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2033 echo "sleeping for 10 * 1.25 + 5 + 10 seconds"
2035 ps -p $pid && error "lfs hadn't finished by timeout"
2036 wait $pid && error "succeeded, but should have failed"
2040 if at_is_enabled; then
2041 at_max_set $timeout client
2043 lctl set_param timeout=$timeout
2046 resetquota -u $TSTUSR
2048 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2054 local TESTFILE="$DIR/$tdir/$tfile"
2061 chmod 0777 $DIR/$tdir
2063 $LFS setstripe $TESTFILE -i 0 -c 1
2064 chown $TSTUSR.$TSTUSR $TESTFILE
2066 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2067 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2068 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2069 cancel_lru_locks osc
2071 $LFS setquota -u $TSTUSR -B 0 $DIR
2072 # over-quota flag has not yet settled since we do not trigger async events
2073 # based on grace time period expiration
2075 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2076 cancel_lru_locks osc
2077 # now over-quota flag should be settled and further writes should fail
2079 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2081 resetquota -u $TSTUSR
2082 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2084 set_blk_unitsz $((128 * 1024))
2085 set_blk_tunesz $((128 * 1024 / 2))
2087 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2089 # test duplicate quota releases b=18630
2092 chmod 0777 $DIR/$tdir
2094 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2095 TESTFILE="$DIR/$tdir/$tfile-0"
2096 TESTFILE2="$DIR/$tdir/$tfile-1"
2098 wait_delete_completed
2100 log " User quota (limit: $LIMIT kbytes)"
2101 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2103 $LFS setstripe $TESTFILE -i 0 -c 1
2104 chown $TSTUSR.$TSTUSR $TESTFILE
2105 $LFS setstripe $TESTFILE2 -i 0 -c 1
2106 chown $TSTUSR.$TSTUSR $TESTFILE2
2108 log " step1: write out of block quota ..."
2109 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2110 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2112 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2113 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2114 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2116 log " step2: delete two files so that triggering duplicate quota release ..."
2117 rm -f $TESTFILE $TESTFILE2
2118 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2119 wait_delete_completed
2121 log " step3: verify if the ost failed"
2122 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2123 watchdog=`awk '/test 31/ {start = 1;}
2124 /release quota error/ {
2128 }' $TMP/lustre-log-${TESTNAME}.log`
2129 [ "$watchdog" ] && error "$watchdog"
2130 rm -f $TMP/lustre-log-${TESTNAME}.log
2133 resetquota -u $TSTUSR
2135 run_test_with_stat 31 "test duplicate quota releases ==="
2137 # check hash_cur_bits
2138 check_quota_hash_cur_bits() {
2141 # check quota_hash_cur_bits on all obdfilters
2142 for num in `seq $OSTCOUNT`; do
2143 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2144 if [ $cb -gt $bits ]; then
2145 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2149 # check quota_hash_cur_bits on mds
2150 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2151 if [ $cb -gt $bits ]; then
2152 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2160 # check distribution of all obdfilters
2161 for num in `seq $OSTCOUNT`; do
2162 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2163 rehash_count=`echo $line | awk '{print $9}'`
2164 if [ $rehash_count -eq 0 ]; then
2165 echo -e "ost$num:\n $line"
2166 error "Rehearsh didn't happen"
2170 # check distribution of mds
2171 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2172 rehash_count=`echo $line | awk '{print $9}'`
2173 if [ $rehash_count -eq 0 ]; then
2174 echo -e "mdt:\n $line"
2175 error "Rehearsh didn't happen"
2182 # reset system so that quota_hash_cur_bits==3
2183 echo "Reset system ..."
2184 local LMR_orig=$LOAD_MODULES_REMOTE
2185 LOAD_MODULES_REMOTE=true
2186 cleanup_and_setup_lustre
2187 LOAD_MODULES_REMOTE=$LMR_orig
2193 for user in $SANITY_QUOTA_USERS; do
2194 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2195 missing_users="$missing_users $user"
2197 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2198 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2200 $LFS quotaoff -ug $DIR
2201 $LFS quotacheck -ug $DIR
2203 for user in $SANITY_QUOTA_USERS; do
2204 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2209 for user in $SANITY_QUOTA_USERS; do
2213 run_test 32 "check lqs hash(bug 21846) =========================================="
2215 cleanup_quota_test() {
2217 echo "Delete files..."
2221 # basic usage tracking for user & group
2224 chmod 0777 $DIR/$tdir
2227 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2229 trap cleanup_quota_test EXIT
2231 # make sure the system is clean
2232 USED=`getquota -u $TSTID global curspace`
2233 [ $USED -ne 0 ] && \
2234 error "Used space ($USED) for user $TSTID isn't 0."
2235 USED=`getquota -g $TSTID global curspace`
2236 [ $USED -ne 0 ] && \
2237 error "Used space ($USED) for group $TSTID isn't 0."
2239 for i in `seq 0 $INODES`; do
2240 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i conv=fsync \
2241 bs=$((BLK_SZ * BLK_CNT)) count=1 2>/dev/null ||
2242 error "write failed"
2243 echo "Iteration $i/$INODES completed"
2245 sync; sync_all_data;
2247 echo "Verify disk usage after write"
2248 USED=`getquota -u $TSTID global curspace`
2249 [ $USED -lt $TOTAL_BLKS ] && \
2250 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2251 USED=`getquota -u $TSTID global curinodes`
2252 [ $USED -lt $INODES ] && \
2253 error "Used inode for user $TSTID is $USED, expected $INODES"
2255 USED=`getquota -g $TSTID global curspace`
2256 [ $USED -lt $TOTAL_BLKS ] && \
2257 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2258 USED=`getquota -g $TSTID global curinodes`
2259 [ $USED -lt $INODES ] && \
2260 error "Used inode for group $TSTID is $USED, expected $INODES"
2264 echo "Verify disk usage after delete"
2265 wait_delete_completed
2266 USED=`getquota -u $TSTID global curspace`
2267 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2268 USED=`getquota -u $TSTID global curinodes`
2269 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2270 USED=`getquota -g $TSTID global curspace`
2271 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2272 USED=`getquota -g $TSTID global curinodes`
2273 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2275 run_test 33 "basic usage tracking for user & group =============================="
2277 # usage transfer test for user & group
2281 chmod 0777 $DIR/$tdir
2283 trap cleanup_quota_test EXIT
2285 # make sure the system is clean
2286 USED=`getquota -u $TSTID global curspace`
2287 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2288 USED=`getquota -g $TSTID global curspace`
2289 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2291 echo "Write file..."
2292 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) count=1 \
2293 conv=fsync 2>/dev/null || error "write failed"
2294 sync; sync_all_data;
2296 echo "chown the file to user $TSTID"
2297 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2299 echo "Wait for setattr on objects finished..."
2300 wait_delete_completed
2302 echo "Verify disk usage for user $TSTID"
2303 USED=`getquota -u $TSTID global curspace`
2304 [ $USED -lt $BLK_CNT ] && \
2305 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2306 USED=`getquota -u $TSTID global curinodes`
2307 [ $USED -ne 1 ] && \
2308 error "Used inodes for user $TSTID is $USED, expected 1"
2310 echo "chgrp the file to group $TSTID"
2311 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2313 echo "Wait for setattr on objects finished..."
2314 wait_delete_completed
2316 echo "Verify disk usage for group $TSTID"
2317 USED=`getquota -g $TSTID global curspace`
2318 [ $USED -ge $BLK_CNT ] || \
2319 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2320 USED=`getquota -g $TSTID global curinodes`
2321 [ $USED -eq 1 ] || \
2322 error "Used inodes for group $TSTID is $USED, expected 1"
2326 run_test 34 "usage transfer for user & group ===================================="
2328 # usage is still accessible across restart
2331 chmod 0777 $DIR/$tdir
2334 trap cleanup_quota_test EXIT
2336 echo "Write file..."
2337 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2338 count=1 conv=fsync 2>/dev/null || error "write failed"
2339 sync; sync_all_data;
2341 echo "Save disk usage before restart"
2342 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2343 [ $ORIG_USR_SPACE -eq 0 ] && \
2344 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2345 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2346 [ $ORIG_USR_INODES -eq 0 ] && \
2347 error "Used inodes for user $TSTID is 0, expected 1"
2348 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2349 [ $ORIG_GRP_SPACE -eq 0 ] && \
2350 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2351 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2352 [ $ORIG_GRP_INODES -eq 0 ] && \
2353 error "Used inodes for group $TSTID is 0, expected 1"
2356 local ORIG_REFORMAT=$REFORMAT
2358 cleanup_and_setup_lustre
2359 REFORMAT=$ORIG_REFORMAT
2362 echo "Verify disk usage after restart"
2363 USED=`getquota -u $TSTID global curspace`
2364 [ $USED -eq $ORIG_USR_SPACE ] || \
2365 error "Used space for user $TSTID changed from " \
2366 "$ORIG_USR_SPACE to $USED"
2367 USED=`getquota -u $TSTID global curinodes`
2368 [ $USED -eq $ORIG_USR_INODES ] || \
2369 error "Used inodes for user $TSTID changed from " \
2370 "$ORIG_USR_INODES to $USED"
2371 USED=`getquota -g $TSTID global curspace`
2372 [ $USED -eq $ORIG_GRP_SPACE ] || \
2373 error "Used space for group $TSTID changed from " \
2374 "$ORIG_GRP_SPACE to $USED"
2375 USED=`getquota -g $TSTID global curinodes`
2376 [ $USED -eq $ORIG_GRP_INODES ] || \
2377 error "Used inodes for group $TSTID changed from " \
2378 "$ORIG_GRP_INODES to $USED"
2382 run_test 35 "usage is still accessible across reboot ============================"
2388 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2393 complete $(basename $0) $SECONDS
2394 check_and_cleanup_lustre
2395 export QUOTA_AUTO=$QUOTA_AUTO_OLD