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
9 #kernel 2.4.x doesn't support quota
10 K_VER=`uname --kernel-release | cut -b 1-3`
11 if [ $K_VER = "2.4" ]; then
12 echo "Kernel 2.4 doesn't support quota"
17 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
20 # enable test_23 after bug 16542 fixed.
21 ALWAYS_EXCEPT="10 23 $SANITY_QUOTA_EXCEPT"
22 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
25 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
26 *) error "unsupported kernel" ;;
29 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
30 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
36 TSTID2=${TSTID2:-60001}
37 TSTUSR=${TSTUSR:-"quota_usr"}
38 TSTUSR2=${TSTUSR2:-"quota_2usr"}
40 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
41 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
46 LUSTRE=${LUSTRE:-`dirname $0`/..}
47 . $LUSTRE/tests/test-framework.sh
49 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
50 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
52 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
53 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
54 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
56 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 check_and_setup_lustre
67 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
68 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
70 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
71 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
72 SHOW_QUOTA_INFO="$LFS quota -t $DIR"
74 # control the time of tests
76 [ "$SLOW" = "no" ] && cycle=10
83 # set_blk_tunables(btune_sz)
85 local btune=$(($1 * BLK_SZ))
86 # set btune size on all obdfilters
87 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
88 # set btune size on mds
89 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
92 # set_blk_unitsz(bunit_sz)
94 local bunit=$(($1 * BLK_SZ))
95 # set bunit size on all obdfilters
96 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
97 # set bunit size on mds
98 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
101 # set_file_tunesz(itune_sz)
104 # set itune size on all obdfilters
105 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_itune_sz=$itune"
106 # set itune size on mds
107 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
110 # set_file_unitsz(iunit_sz)
113 # set iunit size on all obdfilters
114 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_iunit_sz=$iunit"
115 # set iunit size on mds
116 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
125 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc" ;;
127 for num in `seq $OSTCOUNT`; do
128 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
131 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc" ;
132 for num in `seq $OSTCOUNT`; do
133 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
135 * ) echo "usage: lustre_fail fail_node fail_loc" ;
140 RUNAS="runas -u $TSTID -g $TSTID"
141 RUNAS2="runas -u $TSTID2 -g $TSTID2"
142 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
143 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
147 run_test_with_stat() {
148 (($# != 2)) && error "the number of arguments is wrong"
150 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
151 for j in `seq $OSTCOUNT`; do
152 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
155 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
156 echo "statistics info begin ***************************************"
157 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
158 for j in `seq $OSTCOUNT`; do
159 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
161 echo "statistics info end ***************************************"
166 # clear quota limits for a user or a group
167 # usage: resetquota -u username
168 # resetquota -g groupname
171 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
172 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
173 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT || error "resetquota failed"
178 $LFS quotaoff -ug $DIR
179 $LFS quotacheck -ug $DIR
181 resetquota -u $TSTUSR
182 resetquota -g $TSTUSR
184 lctl set_param debug="+quota"
185 do_facet $SINGLEMDS "lctl set_param debug=+quota"
186 for num in `seq $OSTCOUNT`; do
187 do_facet ost$num "lctl set_param debug=+quota"
190 run_test_with_stat 0 "Set quota ============================="
192 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
196 chmod 0777 $DIR/$tdir
197 TESTFILE="$DIR/$tdir/$tfile-0"
199 wait_delete_completed
202 log " User quota (limit: $LIMIT kbytes)"
203 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
207 $LFS setstripe $TESTFILE -c 1
208 chown $TSTUSR.$TSTUSR $TESTFILE
211 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || error "(usr) write failure, but expect success"
213 log " Write out of block quota ..."
214 # this time maybe cache write, ignore it's failure
215 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
216 # flush cache, ensure noquota flag is setted on client
218 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && error "(usr) write success, but expect EDQUOT"
222 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
223 OST0_QUOTA_USED=`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
224 echo $OST0_QUOTA_USED
225 [ $OST0_QUOTA_USED -ne 0 ] && \
226 ($SHOW_QUOTA_USER; error "quota deleted isn't released")
228 resetquota -u $TSTUSR
231 log "--------------------------------------"
232 log " Group quota (limit: $LIMIT kbytes)"
233 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
236 TESTFILE="$DIR/$tdir/$tfile-1"
238 $LFS setstripe $TESTFILE -c 1
239 chown $TSTUSR.$TSTUSR $TESTFILE
242 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || error "(grp) write failure, but expect success"
244 log " Write out of block quota ..."
245 # this time maybe cache write, ignore it's failure
246 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
248 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && error "(grp) write success, but expect EDQUOT"
253 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
254 OST0_QUOTA_USED=`$LFS quota -o $OST0_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
255 echo $OST0_QUOTA_USED
256 [ $OST0_QUOTA_USED -ne 0 ] && \
257 ($SHOW_QUOTA_USER; error "quota deleted isn't released")
259 resetquota -g $TSTUSR
262 # block hard limit (normal use and out of quota)
264 for i in `seq 1 $cycle`; do
265 # define blk_qunit is between 1M and 4M
266 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
267 blk_qtune=$(( $RANDOM % $blk_qunit ))
268 # other osts and mds will occupy at 1M blk quota
269 b_limit=$(( ($RANDOM - 16384) / 8 + $OSTCOUNT * $blk_qunit * 4 ))
270 set_blk_tunesz $blk_qtune
271 set_blk_unitsz $blk_qunit
272 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
274 echo "=================================================="
275 set_blk_unitsz $((128 * 1024))
276 set_blk_tunesz $((128 * 1024 / 2))
279 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
281 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
285 chmod 0777 $DIR/$tdir
286 TESTFILE="$DIR/$tdir/$tfile-0"
288 wait_delete_completed
291 log " User quota (limit: $LIMIT files)"
292 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
296 log " Create $LIMIT files ..."
297 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
298 error "(usr) create failure, but expect success"
300 log " Create out of file quota ..."
301 $RUNAS touch ${TESTFILE}_xxx && \
302 error "(usr) touch success, but expect EDQUOT"
304 unlinkmany ${TESTFILE} $LIMIT
305 rm -f ${TESTFILE}_xxx
308 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
309 MDS_QUOTA_USED=`$LFS quota -o $MDS_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
311 [ $MDS_QUOTA_USED -ne 0 ] && \
312 ($SHOW_QUOTA_USER; error "quota deleted isn't released")
314 resetquota -u $TSTUSR
317 log "--------------------------------------"
318 log " Group quota (limit: $LIMIT FILE)"
319 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
322 TESTFILE=$DIR/$tdir/$tfile-1
324 log " Create $LIMIT files ..."
325 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
326 error "(usr) create failure, but expect success"
328 log " Create out of file quota ..."
329 $RUNAS touch ${TESTFILE}_xxx && \
330 error "(usr) touch success, but expect EDQUOT"
332 unlinkmany ${TESTFILE} $LIMIT
333 rm -f ${TESTFILE}_xxx
336 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
337 MDS_QUOTA_USED=`$LFS quota -o $MDS_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
339 [ $MDS_QUOTA_USED -ne 0 ] && \
340 ($SHOW_QUOTA_USER; error "quota deleted isn't released")
342 resetquota -g $TSTUSR
345 # file hard limit (normal use and out of quota)
347 for i in `seq 1 $cycle`; do
348 if [ $i -eq 1 ]; then
353 # define ino_qunit is between 10 and 100
354 ino_qunit=$(( $RANDOM % 90 + 10 ))
355 ino_qtune=$(( $RANDOM % $ino_qunit ))
356 # RANDOM's maxium is 32767
357 i_limit=$(( $RANDOM % 990 + 10 ))
360 set_file_tunesz $ino_qtune
361 set_file_unitsz $ino_qunit
362 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
364 echo "=================================================="
369 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
373 TIMER=$(($2 * 3 / 2))
376 wait_delete_completed
378 echo " Write to exceed soft limit"
379 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
380 $RUNDD count=$((BUNIT_SZ+1)) || \
381 error "write failure, but expect success"
382 OFFSET=$((OFFSET + BUNIT_SZ + 1))
389 echo " Write before timer goes off"
390 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
391 error "write failure, but expect success"
392 OFFSET=$((OFFSET + BUNIT_SZ))
396 echo " Sleep $TIMER seconds ..."
403 echo " Write after timer goes off"
404 # maybe cache write, ignore.
405 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
406 OFFSET=$((OFFSET + BUNIT_SZ))
408 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
409 error "write success, but expect EDQUOT"
415 echo " Unlink file to stop timer"
425 $RUNDD count=$BUNIT_SZ || error "write failure, but expect success"
433 # block soft limit (start timer, timer goes off, stop timer)
436 chmod 0777 $DIR/$tdir
438 # 1 bunit on mds and 1 bunit on every ost
439 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
442 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
443 TESTFILE=$DIR/$tdir/$tfile-0
445 $LFS setstripe $TESTFILE -c 1
446 chown $TSTUSR.$TSTUSR $TESTFILE
448 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
449 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
451 test_block_soft $TESTFILE $GRACE
452 resetquota -u $TSTUSR
454 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
455 TESTFILE=$DIR/$tdir/$tfile-1
457 $LFS setstripe $TESTFILE -c 1
458 chown $TSTUSR.$TSTUSR $TESTFILE
460 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
461 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
463 test_block_soft $TESTFILE $GRACE
464 resetquota -g $TSTUSR
466 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
471 TIMER=$(($3 * 3 / 2))
473 wait_delete_completed
475 echo " Create files to exceed soft limit"
476 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
477 error "create failure, but expect success"
481 echo " Create file before timer goes off"
482 $RUNAS touch ${TESTFILE}_before || \
483 error "failed create before timer expired, but expect success"
487 echo " Sleep $TIMER seconds ..."
494 echo " Create file after timer goes off"
495 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
496 # inode quota left here
497 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
499 $RUNAS touch ${TESTFILE}_after3 && \
500 error "create after timer expired, but expect EDQUOT"
507 echo " Unlink files to stop timer"
508 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
512 $RUNAS touch ${TESTFILE}_xxx || \
513 error "touch after timer stop failure, but expect success"
518 rm -f ${TESTFILE}_xxx
522 # file soft limit (start timer, timer goes off, stop timer)
523 test_4a() { # was test_4
525 chmod 0777 $DIR/$tdir
526 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
527 TESTFILE=$DIR/$tdir/$tfile-0
531 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
532 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
533 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
536 test_file_soft $TESTFILE $LIMIT $GRACE
537 resetquota -u $TSTUSR
539 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
540 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
541 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
543 TESTFILE=$DIR/$tdir/$tfile-1
545 test_file_soft $TESTFILE $LIMIT $GRACE
546 resetquota -g $TSTUSR
549 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
550 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
552 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
554 test_4b() { # was test_4a
560 GR_STR6="1111111111111111"
562 wait_delete_completed
564 # test of valid grace strings handling
565 echo " Valid grace strings test"
566 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
567 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
568 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
569 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
571 # test of invalid grace strings handling
572 echo " Invalid grace strings test"
573 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
574 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
577 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
578 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
580 run_test_with_stat 4b "Grace time strings handling ==="
582 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
585 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
586 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
588 wait_delete_completed
590 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
591 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
592 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
596 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
597 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
598 error "touch failure, expect success"
599 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
601 echo " Chown files to $TSTUSR.$TSTUSR ..."
602 for i in `seq 0 $ILIMIT`; do
603 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
604 error "chown failure, but expect success"
608 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
611 resetquota -u $TSTUSR
612 resetquota -g $TSTUSR
614 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
616 # block quota acquire & release
618 if [ $OSTCOUNT -lt 2 ]; then
619 skip "$OSTCOUNT < 2, too few osts"
623 wait_delete_completed
626 chmod 0777 $DIR/$tdir
628 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
629 FILEA="$DIR/$tdir/$tfile-0_a"
630 FILEB="$DIR/$tdir/$tfile-0_b"
632 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
633 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
634 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
638 echo " Create filea on OST0 and fileb on OST1"
639 $LFS setstripe $FILEA -i 0 -c 1
640 $LFS setstripe $FILEB -i 1 -c 1
641 chown $TSTUSR.$TSTUSR $FILEA
642 chown $TSTUSR.$TSTUSR $FILEB
644 echo " Exceed quota limit ..."
645 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
646 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
647 error "write fileb failure, but expect success"
652 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
653 error "write fileb success, but expect EDQUOT"
655 echo " Write to OST0 return EDQUOT"
656 # this write maybe cache write, ignore it's failure
657 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
658 $RUNDD count=$(($BUNIT_SZ * 2)) || true
662 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
663 error "write filea success, but expect EDQUOT"
665 echo " Remove fileb to let OST1 release quota"
667 sync; sleep 10; sync; # need to allow journal commit for small fs
669 echo " Write to OST0"
670 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
671 error "write filea failure, expect success"
678 resetquota -u $TSTUSR
679 resetquota -g $TSTUSR
682 run_test_with_stat 6 "Block quota acquire & release ========="
684 # quota recovery (block quota only by now)
688 chmod 0777 $DIR/$tdir
690 wait_delete_completed
692 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
693 TESTFILE="$DIR/$tdir/$tfile-0"
695 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
697 $LFS setstripe $TESTFILE -c 1
698 chown $TSTUSR.$TSTUSR $TESTFILE
700 echo " Write to OST0..."
701 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
702 error "write failure, but expect success"
704 #define OBD_FAIL_OBD_DQACQ 0x604
705 lustre_fail mds 0x604
706 echo " Remove files on OST0"
710 echo " Trigger recovery..."
711 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
712 for i in $OSC0_UUID; do
713 $LCTL --device $i activate || error "activate osc failed!"
716 # sleep a while to wait for recovery done
720 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
721 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
722 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
723 echo " total limits = $TOTAL_LIMIT"
725 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
726 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
727 OST0_LIMIT="`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $2 }'`"
728 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
729 echo " limits on $OST0_UUID = $OST0_LIMIT"
732 resetquota -u $TSTUSR
734 run_test_with_stat 7 "Quota recovery (only block limit) ======"
736 # run dbench with quota enabled
739 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
742 wait_delete_completed
744 echo " Set enough high limit for user: $TSTUSR"
745 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
746 echo " Set enough high limit for group: $TSTUSR"
747 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
749 chmod 0777 $DIR/$tdir
751 [ "$SLOW" = "no" ] && duration=" -t 120"
752 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || error "dbench failed!"
758 run_test_with_stat 8 "Run dbench with quota enabled ==========="
760 # run for fixing bug10707, it needs a big room. test for 64bit
762 GB=$((KB * 1024 * 1024))
763 # Use this as dd bs to decrease time
764 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
765 blksize=$((1 << 21)) # 2Mb
766 size_file=$((GB * 9 / 2))
767 # this check is just for test9 and test10
768 OST0_MIN=4900000 #4.67G
769 check_whether_skip () {
770 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
771 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
772 if [ $OST0_SIZE -lt $OST0_MIN ]; then
773 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
781 check_whether_skip && return 0
783 wait_delete_completed
789 chmod 0777 $DIR/$tdir
790 TESTFILE="$DIR/$tdir/$tfile-0"
792 BLK_LIMIT=$((100 * KB * KB)) # 100G
794 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
796 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
797 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
798 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
799 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
802 $LFS setstripe $TESTFILE -c 1
804 chown $TSTUSR.$TSTUSR $TESTFILE
809 log " Write the big file of 4.5G ..."
810 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
811 error "(usr) write 4.5G file failure, but expect success"
816 log " delete the big file of 4.5G..."
817 $RUNAS rm -f $TESTFILE
825 set_blk_unitsz $((128 * 1024))
826 set_blk_tunesz $((128 * 1024 / 2))
830 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
832 # run for fixing bug10707, it need a big room. test for 32bit
833 # 2.0 version does not support 32 bit qd_count, so such test is obsolete.
836 chmod 0777 $DIR/$tdir
837 check_whether_skip && return 0
839 wait_delete_completed
844 # make qd_count 32 bit
845 lustre_fail mds_ost 0xA00
847 TESTFILE="$DIR/$tdir/$tfile-0"
849 BLK_LIMIT=$((100 * KB * KB)) # 100G
852 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
853 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
854 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
855 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
858 $LFS setstripe $TESTFILE -c 1
860 chown $TSTUSR.$TSTUSR $TESTFILE
865 log " Write the big file of 4.5 G ..."
866 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
867 error "(usr) write 4.5 G file failure, but expect success"
872 log " delete the big file of 4.5 G..."
873 $RUNAS rm -f $TESTFILE
881 # make qd_count 64 bit
882 lustre_fail mds_ost 0
884 set_blk_unitsz $((128 * 1024))
885 set_blk_tunesz $((128 * 1024 / 2))
889 #run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
892 wait_delete_completed
895 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
897 orig_dbr=`sysctl -n vm.dirty_background_ratio`
898 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
899 orig_dr=`sysctl -n vm.dirty_ratio`
900 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
901 sysctl -w vm.dirty_background_ratio=1
902 sysctl -w vm.dirty_expire_centisecs=30
903 sysctl -w vm.dirty_ratio=1
904 sysctl -w vm.dirty_writeback_centisecs=50
911 [ "$SLOW" = no ] && REPS=1
914 while [ $i -le $REPS ]; do
915 echo "test: cycle($i of $REPS) start at $(date)"
916 mkdir -p $TESTDIR && chmod 777 $TESTDIR
917 echo -n " create a file for uid "
918 for j in `seq 1 30`; do
920 # 30MB per dd for a total of 900MB (if space even permits)
921 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
924 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
926 while [ $PROCS -gt 0 ]; do
928 SECS=$((SECS + sleep))
929 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
930 USED=$(du -s $TESTDIR | awk '{print $1}')
931 PCT=$(($USED * 100 / $block_limit))
932 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
933 if [ $USED -le $LAST_USED ]; then
934 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
941 echo " removing the test files..."
942 rm -f $TESTDIR/$tfile
943 echo "cycle $i done at $(date)"
946 echo "Test took $SECS sec"
949 sysctl -w vm.dirty_background_ratio=$orig_dbr
950 sysctl -w vm.dirty_expire_centisecs=$orig_dec
951 sysctl -w vm.dirty_ratio=$orig_dr
952 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
953 if [ $RV -ne 0 ]; then
954 error "Nothing was written for $SECS sec ... aborting"
958 run_test_with_stat 11 "run for fixing bug10912 ==========="
961 # test a deadlock between quota and journal b=11693
964 chmod 0777 $DIR/$tdir
966 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
967 { skip "Need lustre mounted on $MOUNT2 " && retutn 0; }
969 if [ $OSTCOUNT -lt 2 ]; then
970 skip "$OSTCOUNT < 2, too few osts"
974 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
975 TESTFILE="$DIR/$tdir/$tfile-0"
976 TESTFILE2="$DIR2/$tdir/$tfile-1"
978 wait_delete_completed
980 echo " User quota (limit: $LIMIT kbytes)"
981 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
983 $LFS setstripe $TESTFILE -i 0 -c 1
984 chown $TSTUSR.$TSTUSR $TESTFILE
985 $LFS setstripe $TESTFILE2 -i 1 -c 1
986 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
988 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
989 lustre_fail ost 0x0000021f
991 echo " step1: write out of block quota ..."
992 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
994 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
997 echo " step2: testing ......"
1000 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1002 if [ $count -gt 64 ]; then
1004 error "dd should be finished!"
1008 echo "(dd_pid=$DDPID1, time=$count)successful"
1010 #Recover fail_loc and dd will finish soon
1013 echo " step3: testing ......"
1016 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1018 if [ $count -gt 150 ]; then
1019 error "dd should be finished!"
1023 echo "(dd_pid=$DDPID, time=$count)successful"
1025 rm -f $TESTFILE $TESTFILE2
1026 sync; sleep 3; sync;
1028 resetquota -u $TSTUSR
1030 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1032 # test multiple clients write block quota b=11693
1035 wait_delete_completed
1037 # one OST * 10 + (mds + other OSTs)
1038 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1039 TESTFILE="$DIR/$tdir/$tfile"
1041 echo " User quota (limit: $LIMIT kbytes)"
1042 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1045 $LFS setstripe $TESTFILE -i 0 -c 1
1046 chown $TSTUSR.$TSTUSR $TESTFILE
1047 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1048 chown $TSTUSR.$TSTUSR $TESTFILE.2
1050 echo " step1: write out of block quota ..."
1051 # one bunit will give mds
1052 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1054 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1057 echo " step2: testing ......"
1060 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1062 if [ $count -gt 64 ]; then
1063 error "dd should be finished!"
1067 echo "(dd_pid=$DDPID, time=$count)successful"
1071 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1073 if [ $count -gt 64 ]; then
1074 error "dd should be finished!"
1078 echo "(dd_pid=$DDPID1, time=$count)successful"
1080 sync; sleep 5; sync;
1082 echo " step3: checking ......"
1083 fz=`stat -c %s $TESTFILE`
1084 fz2=`stat -c %s $TESTFILE.2`
1086 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1087 error "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1089 rm -f $TESTFILE $TESTFILE.2
1090 sync; sleep 3; sync;
1092 resetquota -u $TSTUSR
1094 run_test_with_stat 13 "test multiple clients write block quota ==="
1096 check_if_quota_zero(){
1097 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1098 for i in `seq 3 $line`; do
1099 if [ $i -eq 3 ]; then
1105 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1106 awk '{print $'"$j"'}'`
1107 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1108 error "quota on $2 isn't clean"
1111 echo "pass check_if_quota_zero"
1114 test_14a() { # was test_14 b=12223 -- setting quota on root
1115 TESTFILE="$DIR/$tdir/$tfile"
1119 cleanup_and_setup_lustre
1124 # out of root's file and block quota
1125 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1126 createmany -m ${TESTFILE} 20 || \
1127 error "unexpected: user(root) create files failly!"
1128 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1129 error "unexpected: user(root) write files failly!"
1131 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1132 error "unexpected: user(quota_usr) write a file successfully!"
1136 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1137 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1140 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1142 #check_if_quota_zero u root
1145 unlinkmany ${TESTFILE} 15
1147 sync; sleep 3; sync;
1149 run_test_with_stat 14a "test setting quota on root ==="
1151 # save quota version (both administrative and operational quotas)
1152 quota_save_version() {
1153 do_facet mgs "lctl conf_param ${FSNAME}-MDT*.mdd.quota_type=$1"
1154 do_facet mgs "lctl conf_param ${FSNAME}-OST*.ost.quota_type=$1"
1159 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1160 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1162 wait_delete_completed
1165 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1166 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1167 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1168 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1169 resetquota -u $TSTUSR
1172 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1173 TOTAL_LIMIT="`$LFS quota -v -g $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1174 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1175 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1176 resetquota -g $TSTUSR
1177 $LFS quotaoff -ug $DIR
1178 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1179 error "fail to set version for $SINGLEMDS"
1180 for j in `seq $OSTCOUNT`; do
1181 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1182 error "fail to set version for ost$j"
1185 echo "invalidating quota files"
1186 $LFS quotainv -ug $DIR
1187 $LFS quotainv -ugf $DIR
1188 $LFS quotacheck -ug $DIR
1190 run_test_with_stat 15 "set block quota more than 4T ==="
1192 # $1=u/g $2=with qunit adjust or not
1194 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1195 TESTFILE="$DIR/$tdir/$tfile"
1198 wait_delete_completed
1200 echo " User quota (limit: $LIMIT kbytes)"
1201 if [ $1 == "u" ]; then
1202 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1205 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1209 $LFS setstripe $TESTFILE -c 1
1210 chown $TSTUSR.$TSTUSR $TESTFILE
1213 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1214 error "(usr) write failure, but expect success"
1216 echo " Write out of block quota ..."
1217 # this time maybe cache write, ignore it's failure
1218 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1219 # flush cache, ensure noquota flag is setted on client
1220 cancel_lru_locks osc
1221 if [ $2 -eq 1 ]; then
1222 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1223 error "(write failure, but expect success"
1225 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1226 error "(write success, but expect EDQUOT"
1230 sync; sleep 3; sync;
1231 resetquota -$1 $TSTUSR
1234 # test without adjusting qunit
1235 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1237 set_blk_tunesz $((BUNIT_SZ * 2))
1238 set_blk_unitsz $((BUNIT_SZ * 4))
1241 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1242 echo " grp/usr: $i, adjust qunit: $j"
1243 echo "-------------------------------"
1244 [ $j -eq 1 ] && lustre_fail mds_ost 0
1245 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1249 set_blk_unitsz $((128 * 1024))
1250 set_blk_tunesz $((128 * 1024 / 2))
1252 #run_test_with_stat 16 "test without adjusting qunit"
1254 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1259 wait_delete_completed
1261 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1262 lustre_fail ost 0x80000A02
1264 TESTFILE="$DIR/$tdir/$tfile-a"
1265 TESTFILE2="$DIR/$tdir/$tfile-b"
1268 BLK_LIMIT=$((100 * 1024)) # 100M
1270 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1271 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1272 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1273 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1276 chown $TSTUSR.$TSTUSR $TESTFILE
1278 chown $TSTUSR.$TSTUSR $TESTFILE2
1283 log " Write the test file1 ..."
1284 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1285 || echo "write 10M file failure"
1290 log " write the test file2 ..."
1291 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1292 || error "write 10M file failure"
1297 rm -f $TESTFILE $TESTFILE2
1299 sync; sleep 3; sync;
1301 # make qd_count 64 bit
1304 set_blk_unitsz $((128 * 1024))
1305 set_blk_tunesz $((128 * 1024 / 2))
1307 resetquota -u $TSTUSR
1308 resetquota -g $TSTUSR
1312 run_test_with_stat 17 "run for fixing bug14526 ==========="
1314 # test when mds takes a long time to handle a quota req so that
1315 # the ost has dropped it, the ost still could work well b=14840
1317 LIMIT=$((100 * 1024 * 1024)) # 100G
1318 TESTFILE="$DIR/$tdir/$tfile"
1321 wait_delete_completed
1326 log " User quota (limit: $LIMIT kbytes)"
1327 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1330 $LFS setstripe $TESTFILE -i 0 -c 1
1331 chown $TSTUSR.$TSTUSR $TESTFILE
1333 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1334 lustre_fail mds 0x13c
1336 log " step1: write 100M block ..."
1337 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1343 echo " step2: testing ......"
1345 timeout=$(lctl get_param -n timeout)
1347 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1349 if [ $count -gt $((4 * $timeout)) ]; then
1350 error "count=$count dd should be finished!"
1354 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1356 testfile_size=$(stat -c %s $TESTFILE)
1357 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1358 error "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1360 sync; sleep 3; sync;
1362 resetquota -u $TSTUSR
1364 set_blk_unitsz $((128 * 1024))
1365 set_blk_tunesz $((128 * 1024 / 2))
1367 run_test_with_stat 18 "run for fixing bug14840 ==========="
1369 # test when mds drops a quota req, the ost still could work well b=14840
1371 LIMIT=$((100 * 1024 * 1024)) # 100G
1372 TESTFILE="$DIR/$tdir/$tfile-a"
1375 wait_delete_completed
1380 log " User quota (limit: $LIMIT kbytes)"
1381 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1384 $LFS setstripe $TESTFILE -i 0 -c 1
1385 chown $TSTUSR.$TSTUSR $TESTFILE
1387 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1388 lustre_fail mds 0x8000013d
1390 log " step1: write 100M block ..."
1391 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1394 echo " step2: testing ......"
1396 timeout=$(lctl get_param -n timeout)
1398 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1400 if [ $count -gt $((6 * $timeout)) ]; then
1402 error "count=$count dd should be finished!"
1406 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1411 sync; sleep 3; sync;
1413 resetquota -u $TSTUSR
1415 set_blk_unitsz $((128 * 1024))
1416 set_blk_tunesz $((128 * 1024 / 2))
1418 run_test_with_stat 18a "run for fixing bug14840 ==========="
1420 # test when mds do failover, the ost still could work well without trigger
1425 LIMIT=$((110 * 1024 )) # 110M
1426 TESTFILE="$DIR/$tdir/$tfile"
1429 wait_delete_completed
1434 log " User quota (limit: $LIMIT kbytes)"
1435 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1438 $LFS setstripe $TESTFILE -i 0 -c 1
1439 chown $TSTUSR.$TSTUSR $TESTFILE
1441 timeout=$(sysctl -n lustre.timeout)
1443 if [ $type = "directio" ]; then
1444 log " write 100M block(directio) ..."
1445 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1447 log " write 100M block(normal) ..."
1448 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1452 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1454 log "failing mds for $((2 * timeout)) seconds"
1455 fail $SINGLEMDS $((2 * timeout))
1457 # check if quotaon successful
1458 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1459 if [ $? -eq 0 ]; then
1460 error "quotaon failed!"
1467 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1468 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1469 log "it took $count second"
1473 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1476 testfile_size=$(stat -c %s $TESTFILE)
1477 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1478 error "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1480 resetquota -u $TSTUSR
1485 # test when mds does failover, the ost still could work well
1486 # this test shouldn't trigger watchdog b=14840
1488 test_18bc_sub normal
1489 test_18bc_sub directio
1490 # check if watchdog is triggered
1491 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1492 watchdog=`awk '/test 18b/ {start = 1;}
1493 /Watchdog triggered/ {
1497 }' $TMP/lustre-log-${TESTNAME}.log`
1498 if [ -n "$watchdog" ]; then error "$watchdog"; fi
1499 rm -f $TMP/lustre-log-${TESTNAME}.log
1501 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1503 # test when mds does failover, the ost still could work well
1504 # this test will prevent OST_DISCONNET from happening b=14840
1506 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1507 lustre_fail ost 0x202
1508 test_18bc_sub normal
1509 test_18bc_sub directio
1512 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1514 run_to_block_limit() {
1515 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1517 wait_delete_completed
1519 # set 1 Mb quota unit size
1523 # bind file to a single OST
1524 $LFS setstripe -c 1 $TESTFILE
1525 chown $TSTUSR.$TSTUSR $TESTFILE
1527 echo " User quota (limit: $LIMIT kbytes)"
1528 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1530 echo " Updating quota limits"
1531 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1534 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1535 $RUNDD count=$BUNIT_SZ || error "(usr) write failure, but expect success"
1536 # for now page cache of TESTFILE may still be dirty,
1537 # let's push it to the corresponding OST, this will also
1538 # cache NOQUOTA on the client from OST's reply
1539 cancel_lru_locks osc
1540 $RUNDD seek=$BUNIT_SZ && error "(usr) write success, should be EDQUOT"
1544 # 1 Mb bunit per each MDS/OSS
1545 local TESTFILE="$DIR/$tdir/$tfile"
1548 run_to_block_limit $TESTFILE
1553 resetquota -u $TSTUSR
1555 set_blk_unitsz $((128 * 1024))
1556 set_blk_tunesz $((128 * 1024 / 2))
1559 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1563 LSTR=(1t 2g 3m 4k) # limits strings
1564 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1566 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1567 $MOUNT || error "could not set quota limits"
1569 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1570 --inode-softlimit ${LSTR[2]} \
1571 --inode-hardlimit ${LSTR[3]} \
1572 $MOUNT || error "could not set quota limits"
1574 ($LFS quota -v -u $TSTUSR $MOUNT | \
1575 grep -E '^ *'$MOUNT' *[0-9]+\** *'${LVAL[0]}' *'${LVAL[1]}' *[0-9]+\** *'${LVAL[2]}' *'${LVAL[3]}) \
1576 || error "lfs quota output is unexpected"
1578 resetquota -u $TSTUSR
1580 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1587 time=$(($(date +%s) + seconds))
1588 while [ $(date +%s) -lt $time ]; do
1589 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1594 # run for fixing bug16053, setquota shouldn't fail when writing and
1595 # deleting are happening
1600 wait_delete_completed
1602 TESTFILE="$DIR/$tdir/$tfile"
1604 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1607 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1608 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1609 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1610 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1612 # repeat writing on a 1M file
1613 test_21_sub ${TESTFILE}_1 1024 30 &
1615 # repeat writing on a 128M file
1616 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1619 time=$(($(date +%s) + 30))
1621 while [ $(date +%s) -lt $time ]; do
1622 log " Set quota for $i times"
1623 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1624 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1631 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1633 if [ $count -gt 60 ]; then
1634 error "dd should be finished!"
1638 echo "(dd_pid=$DDPID1, time=$count)successful"
1642 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1644 if [ $count -gt 60 ]; then
1645 error "dd should be finished!"
1649 echo "(dd_pid=$DDPID2, time=$count)successful"
1651 set_blk_unitsz $((128 * 1024))
1652 set_blk_tunesz $((128 * 1024 / 2))
1653 resetquota -u $TSTUSR
1654 resetquota -g $TSTUSR
1658 run_test_with_stat 21 "run for fixing bug16053 ==========="
1663 SAVEREFORMAT=$REFORMAT
1664 $LFS quotaoff -ug $DIR || error "could not turn quotas off"
1666 quota_save_version "ug"
1672 REFORMAT=$SAVEREFORMAT
1674 echo "checking parameters"
1676 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug" || error "admin failure"
1677 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug" || error "op failure"
1679 run_test 0 "reboot lustre"
1681 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1685 chmod 0777 $DIR/$tdir
1686 TESTFILE="$DIR/$tdir/$tfile-0"
1688 local bs_unit=$((1024*1024))
1691 wait_delete_completed
1694 log " User quota (limit: $LIMIT kbytes)"
1695 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1699 $LFS setstripe $TESTFILE -c 1
1700 chown $TSTUSR.$TSTUSR $TESTFILE
1702 log " Step1: trigger quota with 0_DIRECT"
1703 log " Write half of file"
1704 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || error "(1) write failure, but expect success: $LIMIT"
1705 log " Write out of block quota ..."
1706 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && error "(2) write success, but expect EDQUOT: $LIMIT"
1709 log " Step2: rewrite should succeed"
1710 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) 1 $bs_unit || error "(3) write failure, but expect success: $LIMIT"
1714 wait_delete_completed
1715 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1716 OST0_QUOTA_USED=`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1717 echo $OST0_QUOTA_USED
1718 [ $OST0_QUOTA_USED -ne 0 ] && \
1719 ($SHOW_QUOTA_USER; error "quota deleted isn't released")
1721 resetquota -u $TSTUSR
1725 log "run for $((OSTCOUNT * 4))MB test file"
1726 test_23_sub $((OSTCOUNT * 4 * 1024))
1729 check_whether_skip && return 0
1730 log "run for $((OSTCOUNT * 40))MB test file"
1731 test_23_sub $((OSTCOUNT * 40 * 1024))
1733 run_test_with_stat 23 "run for fixing bug16125 ==========="
1736 local TESTFILE="$DIR/$tdir/$tfile"
1739 run_to_block_limit $TESTFILE
1740 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1744 resetquota -u $TSTUSR
1746 set_blk_unitsz $((128 * 1024))
1747 set_blk_tunesz $((128 * 1024 / 2))
1750 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1756 lctl set_param debug="-quota"
1760 run_test_with_stat 99 "Quota off ==============================="
1763 log "cleanup: ======================================================"
1765 check_and_cleanup_lustre
1766 echo '=========================== finished ==============================='
1767 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
1768 echo "$0: completed"