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 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
25 *) error "unsupported kernel" ;;
28 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
29 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
35 TSTID2=${TSTID2:-60001}
36 TSTUSR=${TSTUSR:-"quota_usr"}
37 TSTUSR2=${TSTUSR2:-"quota_2usr"}
39 BUNIT_SZ=${BUNIT_SZ:-1000} # default 1000 quota blocks
40 BTUNE_SZ=${BTUNE_SZ:-500} # default 50% of BUNIT_SZ
41 IUNIT_SZ=${IUNIT_SZ:-10} # default 10 files
42 ITUNE_SZ=${ITUNE_SZ:-5} # default 50% of IUNIT_SZ
47 LUSTRE=${LUSTRE:-`dirname $0`/..}
48 . $LUSTRE/tests/test-framework.sh
50 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
52 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
53 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
55 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11"
57 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
59 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
64 check_and_setup_lustre
66 LOVNAME=`cat $LPROC/llite/*/lov/common_name | tail -n 1`
67 OSTCOUNT=`cat $LPROC/lov/$LOVNAME/numobd`
69 SHOW_QUOTA_USER="$LFS quota -u $TSTUSR $DIR"
70 SHOW_QUOTA_GROUP="$LFS quota -g $TSTUSR $DIR"
71 SHOW_QUOTA_INFO="$LFS quota -t $DIR"
73 # control the time of tests
75 [ "$SLOW" = "no" ] && cycle=10
82 # set_blk_tunables(btune_sz)
84 # set btune size on all obdfilters
85 do_facet ost1 "set -x; for i in /proc/fs/lustre/obdfilter/*/quota_btune_sz; do
86 echo $(($1 * BLK_SZ)) >> \\\$i;
88 # set btune size on mds
89 do_facet $SINGLEMDS "for i in /proc/fs/lustre/mds/${FSNAME}-MDT*/quota_btune_sz; do
90 echo $(($1 * BLK_SZ)) >> \\\$i;
94 # set_blk_unitsz(bunit_sz)
96 do_facet ost1 "for i in /proc/fs/lustre/obdfilter/*/quota_bunit_sz; do
97 echo $(($1 * BLK_SZ)) >> \\\$i;
99 do_facet $SINGLEMDS "for i in /proc/fs/lustre/mds/${FSNAME}-MDT*/quota_bunit_sz; do
100 echo $(($1 * BLK_SZ)) >> \\\$i;
104 # set_file_tunesz(itune_sz)
106 # set iunit and itune size on all obdfilters
107 do_facet ost1 "for i in /proc/fs/lustre/obdfilter/*/quota_itune_sz; do
110 # set iunit and itune size on mds
111 do_facet $SINGLEMDS "for i in /proc/fs/lustre/mds/${FSNAME}-MDT*/quota_itune_sz; do
116 # set_file_unitsz(iunit_sz)
118 do_facet ost1 "for i in /proc/fs/lustre/obdfilter/*/quota_iunit_sz; do
121 do_facet $SINGLEMDS "for i in /proc/fs/lustre/mds/${FSNAME}-MDT*/quota_iunit_sz; do
126 # These are for test on local machine,if run sanity-quota.sh on
127 # real cluster, ltest should have setup the test environment:
129 # - create test user/group on all servers with same id.
130 # - set unit size/tune on all servers size to reasonable value.
132 if [ -z "$NOSETUP" ]; then
134 set_blk_tunesz $BTUNE_SZ
135 set_blk_unitsz $BUNIT_SZ
137 set_file_tunesz $ITUNE_SZ
138 set_file_unitsz $IUNIT_SZ
144 if [ -z "$NOSETUP" ]; then
145 # restore block tunables to default size
146 set_blk_unitsz $((1024 * 100))
147 set_blk_tunesz $((1024 * 50))
148 # restore file tunables to default size
154 RUNAS="runas -u $TSTID"
155 RUNAS2="runas -u $TSTID2"
156 FAIL_ON_ERROR=true check_runas_id $TSTID $RUNAS
157 FAIL_ON_ERROR=true check_runas_id $TSTID2 $RUNAS2
163 $LFS quotaoff -ug $DIR
164 $LFS quotacheck -ug $DIR
166 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
167 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
169 run_test 0 "Set quota ============================="
171 # block hard limit (normal use and out of quota)
174 chmod 0777 $DIR/$tdir
176 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 5)) # 5 bunits each sever
177 TESTFILE=$DIR/$tdir/$tfile-0
179 echo " User quota (limit: $LIMIT kbytes)"
180 $LFS setquota -u $TSTUSR 0 $LIMIT 0 0 $DIR
183 $LFS setstripe $TESTFILE -c 1
184 chown $TSTUSR.$TSTUSR $TESTFILE
187 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || error "(usr) write failure, but expect success"
189 echo " Write out of block quota ..."
190 # this time maybe cache write, ignore it's failure
191 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
192 # flush cache, ensure noquota flag is setted on client
194 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && error "(usr) write success, but expect EDQUOT"
198 echo " Group quota (limit: $LIMIT kbytes)"
199 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR # clear user limit
200 $LFS setquota -g $TSTUSR 0 $LIMIT 0 0 $DIR
202 TESTFILE=$DIR/$tdir/$tfile-1
204 $LFS setstripe $TESTFILE -c 1
205 chown $TSTUSR.$TSTUSR $TESTFILE
208 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || error "(grp) write failure, but expect success"
210 echo " Write out of block quota ..."
211 # this time maybe cache write, ignore it's failure
212 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
214 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$LIMIT && error "(grp) write success, but expect EDQUOT"
218 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
220 run_test 1 "Block hard limit (normal use and out of quota) ==="
222 # file hard limit (normal use and out of quota)
225 chmod 0777 $DIR/$tdir
227 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
228 TESTFILE=$DIR/$tdir/$tfile-0
230 echo " User quota (limit: $LIMIT files)"
231 $LFS setquota -u $TSTUSR 0 0 0 $LIMIT $DIR
234 echo " Create $LIMIT files ..."
235 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
236 error "(usr) create failure, but expect success"
238 echo " Create out of file quota ..."
239 $RUNAS touch ${TESTFILE}_xxx && \
240 error "(usr) touch success, but expect EDQUOT"
242 unlinkmany ${TESTFILE} $LIMIT
245 echo " Group quota (limit: $LIMIT files)"
246 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR # clear user limit
247 $LFS setquota -g $TSTUSR 0 0 0 $LIMIT $DIR
249 TESTFILE=$DIR/$tdir/$tfile-1
251 echo " Create $LIMIT files ..."
252 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
253 error "(grp) create failure, but expect success"
256 echo " Create out of file quota ..."
257 $RUNAS touch ${TESTFILE}_xxx && \
258 error "(grp) touch success, but expect EDQUOT"
260 $RUNAS touch ${TESTFILE}_xxx > /dev/null 2>&1 && error "(grp) touch success, but expect EDQUOT"
263 unlinkmany ${TESTFILE} $LIMIT
266 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
268 run_test 2 "File hard limit (normal use and out of quota) ==="
272 TIMER=$(($2 * 3 / 2))
275 echo " Write to exceed soft limit"
276 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
277 $RUNDD count=$((BUNIT_SZ+1)) || \
278 error "write failure, but expect success"
279 OFFSET=$((OFFSET + BUNIT_SZ + 1))
286 echo " Write before timer goes off"
287 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
288 error "write failure, but expect success"
289 OFFSET=$((OFFSET + BUNIT_SZ))
293 echo " Sleep $TIMER seconds ..."
300 echo " Write after timer goes off"
301 # maybe cache write, ignore.
303 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
304 OFFSET=$((OFFSET + BUNIT_SZ))
306 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
307 error "write success, but expect EDQUOT"
313 echo " Unlink file to stop timer"
322 $RUNDD count=$BUNIT_SZ || error "write failure, but expect success"
329 # block soft limit (start timer, timer goes off, stop timer)
332 chmod 0777 $DIR/$tdir
334 LIMIT=$(( $BUNIT_SZ * 2 )) # 1 bunit on mds and 1 bunit on the ost
337 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
338 TESTFILE=$DIR/$tdir/$tfile-0
340 $LFS setstripe $TESTFILE -c 1
341 chown $TSTUSR.$TSTUSR $TESTFILE
343 $LFS setquota -t -u $GRACE $MAX_IQ_TIME $DIR
344 $LFS setquota -u $TSTUSR $LIMIT 0 0 0 $DIR
346 test_block_soft $TESTFILE $GRACE
347 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
349 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
350 TESTFILE=$DIR/$tdir/$tfile-1
352 $LFS setstripe $TESTFILE -c 1
353 chown $TSTUSR.$TSTUSR $TESTFILE
355 $LFS setquota -t -g $GRACE $MAX_IQ_TIME $DIR
356 $LFS setquota -g $TSTUSR $LIMIT 0 0 0 $DIR
358 test_block_soft $TESTFILE $GRACE
359 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
361 run_test 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
366 TIMER=$(($3 * 3 / 2))
368 echo " Create files to exceed soft limit"
369 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
370 error "create failure, but expect success"
374 echo " Create file before timer goes off"
375 $RUNAS touch ${TESTFILE}_before || \
376 error "failed create before timer expired, but expect success"
380 echo " Sleep $TIMER seconds ..."
387 echo " Create file after timer goes off"
388 $RUNAS createmany -m ${TESTFILE}_after_ $((IUNIT_SZ - 2)) || \
389 error "create ${TESTFILE}_after failure, but expect success"
391 $RUNAS touch ${TESTFILE}_after && \
392 error "create after timer expired, but expect EDQUOT"
399 echo " Unlink files to stop timer"
400 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
404 $RUNAS touch ${TESTFILE}_xxx || \
405 error "touch after timer stop failure, but expect success"
410 rm -f ${TESTFILE}_xxx
413 # file soft limit (start timer, timer goes off, stop timer)
414 test_4a() { # was test_4
416 chmod 0777 $DIR/$tdir
417 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
418 TESTFILE=$DIR/$tdir/$tfile-0
422 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
423 $LFS setquota -t -u $MAX_DQ_TIME $GRACE $DIR
424 $LFS setquota -u $TSTUSR 0 0 $LIMIT 0 $DIR
427 test_file_soft $TESTFILE $LIMIT $GRACE
428 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
430 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
431 $LFS setquota -t -g $MAX_DQ_TIME $GRACE $DIR
432 $LFS setquota -g $TSTUSR 0 0 $LIMIT 0 $DIR
434 TESTFILE=$DIR/$tdir/$tfile-1
436 test_file_soft $TESTFILE $LIMIT $GRACE
437 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
440 $LFS setquota -t -u $MAX_DQ_TIME $MAX_IQ_TIME $DIR
441 $LFS setquota -t -g $MAX_DQ_TIME $MAX_IQ_TIME $DIR
443 run_test 4a "File soft limit (start timer, timer goes off, stop timer) ==="
445 test_4b() { # was test_4a
451 GR_STR6="1111111111111111"
453 # test of valid grace strings handling
454 echo " Valid grace strings test"
455 $LFS setquota -t -u $GR_STR1 $GR_STR2 $DIR
456 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
457 $LFS setquota -t -g $GR_STR3 $GR_STR4 $DIR
458 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
460 # test of invalid grace strings handling
461 echo " Invalid grace strings test"
462 ! $LFS setquota -t -u $GR_STR4 $GR_STR5 $DIR
463 ! $LFS setquota -t -g $GR_STR4 $GR_STR6 $DIR
466 $LFS setquota -t -u $MAX_DQ_TIME $MAX_IQ_TIME $DIR
467 $LFS setquota -t -g $MAX_DQ_TIME $MAX_IQ_TIME $DIR
469 run_test 4b "Grace time strings handling ==="
471 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
474 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
475 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
477 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
478 $LFS setquota -u $TSTUSR 0 $BLIMIT 0 $ILIMIT $DIR
479 $LFS setquota -g $TSTUSR 0 $BLIMIT 0 $ILIMIT $DIR
483 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
484 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
485 error "touch failure, expect success"
486 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
488 echo " Chown files to $TSTUSR.$TSTUSR ..."
489 for i in `seq 0 $ILIMIT`; do
490 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
491 error "chown failure, but expect success"
495 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
497 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
498 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
500 run_test 5 "Chown & chgrp successfully even out of block/file quota ==="
502 # block quota acquire & release
504 if [ $OSTCOUNT -lt 2 ]; then
505 skip "$OSTCOUNT < 2, too few osts"
510 chmod 0777 $DIR/$tdir
512 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
513 FILEA="$DIR/$tdir/$tfile-0_a"
514 FILEB="$DIR/$tdir/$tfile-0_b"
516 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
517 $LFS setquota -u $TSTUSR 0 $LIMIT 0 0 $DIR
518 $LFS setquota -g $TSTUSR 0 $LIMIT 0 0 $DIR
522 echo " Create filea on OST0 and fileb on OST1"
523 $LFS setstripe $FILEA -i 0 -c 1
524 $LFS setstripe $FILEB -i 1 -c 1
525 chown $TSTUSR.$TSTUSR $FILEA
526 chown $TSTUSR.$TSTUSR $FILEB
528 echo " Exceed quota limit ..."
529 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
530 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
531 error "write fileb failure, but expect success"
536 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
537 error "write fileb success, but expect EDQUOT"
539 echo " Write to OST0 return EDQUOT"
540 # this write maybe cache write, ignore it's failure
541 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
542 $RUNDD count=$(($BUNIT_SZ * 2)) || true
546 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
547 error "write filea success, but expect EDQUOT"
549 echo " Remove fileb to let OST1 release quota"
551 sync; sleep 10; sync; # need to allow journal commit for small fs
553 echo " Write to OST0"
554 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
555 error "write filea failure, expect success"
560 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
561 $LFS setquota -g $TSTUSR 0 0 0 0 $DIR
564 run_test 6 "Block quota acquire & release ========="
566 # quota recovery (block quota only by now)
570 chmod 0777 $DIR/$tdir
572 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
573 TESTFILE="$DIR/$tdir/$tfile-0"
575 $LFS setquota -u $TSTUSR 0 $LIMIT 0 0 $DIR
577 $LFS setstripe $TESTFILE -c 1
578 chown $TSTUSR.$TSTUSR $TESTFILE
580 echo " Write to OST0..."
581 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
582 error "write failure, but expect success"
584 #define OBD_FAIL_OBD_DQACQ 0x604
585 echo 0x604 > /proc/sys/lustre/fail_loc
586 echo " Remove files on OST0"
588 echo 0 > /proc/sys/lustre/fail_loc
590 echo " Trigger recovery..."
591 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
592 for i in $OSC0_UUID; do
593 $LCTL --device $i activate || error "activate osc failed!"
596 # sleep a while to wait for recovery done
600 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
601 TOTAL_LIMIT="`$LFS quota -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
602 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
603 echo " total limits = $TOTAL_LIMIT"
605 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
606 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
607 OST0_LIMIT="`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`"
608 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
609 echo " limits on $OST0_UUID = $OST0_LIMIT"
612 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR
614 run_test 7 "Quota recovery (only block limit) ======"
616 # run dbench with quota enabled
619 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
622 wait_delete_completed
624 echo " Set enough high limit for user: $TSTUSR"
625 $LFS setquota -u $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
626 echo " Set enough high limit for group: $TSTUSR"
627 $LFS setquota -g $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
629 chmod 0777 $DIR/$tdir
631 [ "$SLOW" = "no" ] && duration=" -t 120"
632 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || error "dbench failed!"
638 run_test 8 "Run dbench with quota enabled ==========="
640 # run for fixing bug10707, it needs a big room. test for 64bit
642 GB=$((KB * 1024 * 1024))
643 FSIZE=$((OSTCOUNT * 9 / 2))
644 # Use this as dd bs to decrease time
645 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
646 blksize=$((1 << 21)) # 2Mb
649 chmod 0777 $DIR/$tdir
650 lustrefs_size=`(echo 0; df -t lustre -P | awk '{print $4}') | tail -n 1`
651 size_file=$((FSIZE * GB))
652 echo "lustrefs_size:$lustrefs_size size_file:$((size_file / KB))"
653 if [ $((lustrefs_size * KB)) -lt $size_file ]; then
654 skip "less than $size_file bytes free"
658 set_blk_unitsz $((1024 * 100))
659 set_blk_tunesz $((1024 * 50))
661 # set the D_QUOTA flag
663 sysctl -w lnet.debug="+quota"
665 TESTFILE="$DIR/$tdir/$tfile-0"
667 BLK_LIMIT=$((100 * KB * KB)) # 100G
670 echo " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
671 $LFS setquota -u $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
672 echo " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
673 $LFS setquota -g $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
676 [ $OSTCOUNT -ge 2 ] && $LFS setstripe $TESTFILE -c $OSTCOUNT
678 chown $TSTUSR.$TSTUSR $TESTFILE
683 echo " Write the big file of $FSIZE G ..."
684 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
685 error "(usr) write $FSIZE G file failure, but expect success"
690 echo " delete the big file of $FSIZE G..."
691 $RUNAS rm -f $TESTFILE
696 echo " write the big file of 2 G..."
697 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((2 * GB / blksize)) || \
698 error "(usr) write 2 G file failure, but expect seccess"
700 echo " delete the big file of 2 G..."
701 $RUNAS rm -f $TESTFILE
704 set_blk_tunesz $BTUNE_SZ
705 set_blk_unitsz $BUNIT_SZ
708 wait_delete_completed
712 run_test 9 "run for fixing bug10707(64bit) ==========="
714 # run for fixing bug10707, it need a big room. test for 32bit
717 chmod 0777 $DIR/$tdir
718 lustrefs_size=`(echo 0; df -t lustre -P | awk '{print $4}') | tail -n 1`
719 size_file=$((FSIZE * GB))
720 echo "lustrefs_size:$lustrefs_size size_file:$((size_file / KB))"
721 if [ $((lustrefs_size * KB)) -lt $size_file ]; then
722 skip "less than $size_file bytes free"
726 sync; sleep 10; sync;
728 set_blk_unitsz $((1024 * 100))
729 set_blk_tunesz $((1024 * 50))
731 # set the D_QUOTA flag
733 sysctl -w lnet.debug="+quota"
735 # make qd_count 32 bit
736 sysctl -w lustre.fail_loc=0xA00
738 TESTFILE="$DIR/$tdir/$tfile-0"
740 BLK_LIMIT=$((100 * KB * KB)) # 100G
743 echo " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
744 $LFS setquota -u $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
745 echo " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
746 $LFS setquota -g $TSTUSR 0 $BLK_LIMIT 0 $FILE_LIMIT $DIR
749 [ $OSTCOUNT -ge 2 ] && $LFS setstripe $TESTFILE -c $OSTCOUNT
751 chown $TSTUSR.$TSTUSR $TESTFILE
756 echo " Write the big file of $FSIZE G ..."
757 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
758 error "(usr) write $FSIZE G file failure, but expect success"
763 echo " delete the big file of $FSIZE G..."
764 $RUNAS rm -f $TESTFILE
769 echo " write the big file of 2 G..."
770 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((2 * GB / blkzise)) || \
771 error "(usr) write 2 G file failure, but expect success"
773 echo " delete the big file of 2 G..."
774 $RUNAS rm -f $TESTFILE
781 # make qd_count 64 bit
782 sysctl -w lustre.fail_loc=0
784 set_blk_tunesz $BTUNE_SZ
785 set_blk_unitsz $BUNIT_SZ
787 wait_delete_completed
791 run_test 10 "run for fixing bug10707(32bit) ==========="
794 wait_delete_completed
797 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
799 orig_dbr=`cat /proc/sys/vm/dirty_background_ratio`
800 orig_dec=`cat /proc/sys/vm/dirty_expire_centisecs`
801 orig_dr=`cat /proc/sys/vm/dirty_ratio`
802 orig_dwc=`cat /proc/sys/vm/dirty_writeback_centisecs`
803 echo 1 > /proc/sys/vm/dirty_background_ratio
804 echo 30 > /proc/sys/vm/dirty_expire_centisecs
805 echo 1 > /proc/sys/vm/dirty_ratio
806 echo 50 > /proc/sys/vm/dirty_writeback_centisecs
813 [ "$SLOW" = no ] && REPS=1
816 while [ $i -le $REPS ]; do
817 echo "test: cycle($i of $REPS) start at $(date)"
818 mkdir -p $TESTDIR && chmod 777 $TESTDIR
819 echo -n " create a file for uid "
820 for j in `seq 1 30`; do
822 # 30MB per dd for a total of 900MB (if space even permits)
823 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
826 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
828 while [ $PROCS -gt 0 ]; do
830 SECS=$((SECS + sleep))
831 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
832 USED=$(du -s $TESTDIR | awk '{print $1}')
833 PCT=$(($USED * 100 / $block_limit))
834 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
835 if [ $USED -le $LAST_USED ]; then
836 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
843 echo " removing the test files..."
844 rm -f $TESTDIR/$tfile
845 echo "cycle $i done at $(date)"
848 echo "Test took $SECS sec"
851 echo $orig_dbr > /proc/sys/vm/dirty_background_ratio
852 echo $orig_dec > /proc/sys/vm/dirty_expire_centisecs
853 echo $orig_dr > /proc/sys/vm/dirty_ratio
854 echo $orig_dwc > /proc/sys/vm/dirty_writeback_centisecs
855 if [ $RV -ne 0 ]; then
856 error "Nothing was written for $SECS sec ... aborting"
860 run_test 11 "run for fixing bug10912 ==========="
863 # test a deadlock between quota and journal b=11693
866 chmod 0777 $DIR/$tdir
868 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
869 { skip "Need lustre mounted on $MOUNT2 " && retutn 0; }
871 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
872 TESTFILE="$DIR/$tdir/$tfile-0"
873 TESTFILE2="$DIR2/$tdir/$tfile-1"
875 echo " User quota (limit: $LIMIT kbytes)"
876 $LFS setquota -u $TSTUSR 0 $LIMIT 0 0 $DIR
878 $LFS setstripe $TESTFILE -i 0 -c 1
879 chown $TSTUSR.$TSTUSR $TESTFILE
880 $LFS setstripe $TESTFILE2 -i 0 -c 1
881 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
883 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
884 sysctl -w lustre.fail_loc=0x0000021f
886 echo " step1: write out of block quota ..."
887 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
890 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
893 echo " step2: testing ......"
896 if [ -z `ps -ef | awk '$2 == '${DDPID1}' { print $8 }'` ]; then break; fi
898 if [ $count -gt 64 ]; then
899 sysctl -w lustre.fail_loc=0
900 error "dd should be finished!"
904 echo "(dd_pid=$DDPID1, time=$count)successful"
906 #Recover fail_loc and dd will finish soon
907 sysctl -w lustre.fail_loc=0
909 echo " step3: testing ......"
912 if [ -z `ps -ef | awk '$2 == '${DDPID}' { print $8 }'` ]; then break; fi
914 if [ $count -gt 100 ]; then
915 error "dd should be finished!"
919 echo "(dd_pid=$DDPID, time=$count)successful"
921 rm -f $TESTFILE $TESTFILE2
923 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR # clear user limit
925 run_test 12 "test a deadlock between quota and journal ==="
927 # test multiple clients write block quota b=11693
929 # one OST * 10 + (mds + other OSTs)
930 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
931 TESTFILE="$DIR/$tdir/$tfile"
934 echo " User quota (limit: $LIMIT kbytes)"
935 $LFS setquota -u $TSTUSR 0 $LIMIT 0 0 $DIR
938 $LFS setstripe $TESTFILE -i 0 -c 1
939 chown $TSTUSR.$TSTUSR $TESTFILE
940 $LFS setstripe $TESTFILE.2 -i 0 -c 1
941 chown $TSTUSR.$TSTUSR $TESTFILE.2
943 echo " step1: write out of block quota ..."
944 # one bunit will give mds
945 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
947 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
950 echo " step2: testing ......"
953 if [ -z `ps -ef | awk '$2 == '${DDPID}' { print $8 }'` ]; then break; fi
955 if [ $count -gt 64 ]; then
956 error "dd should be finished!"
960 echo "(dd_pid=$DDPID, time=$count)successful"
964 if [ -z `ps -ef | awk '$2 == '${DDPID1}' { print $8 }'` ]; then break; fi
966 if [ $count -gt 64 ]; then
967 error "dd should be finished!"
971 echo "(dd_pid=$DDPID1, time=$count)successful"
975 echo " step3: checking ......"
976 fz=`stat -c %s $TESTFILE`
977 fz2=`stat -c %s $TESTFILE.2`
979 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
980 error "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
982 rm -f $TESTFILE $TESTFILE.2
984 $LFS setquota -u $TSTUSR 0 0 0 0 $DIR # clear user limit
986 run_test 13 "test multiple clients write block quota ==="
988 check_if_quota_zero(){
989 line=`$LFS quota -$1 $2 $DIR | wc -l`
990 for i in `seq 3 $line`; do
991 if [ $i -eq 3 ]; then
997 tmp=`$LFS quota -$1 $2 $DIR | sed -n ${i}p |
998 awk '{print $'"$j"'}'`
999 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -$1 $2 $DIR && \
1000 error "quota on $2 isn't clean"
1003 echo "pass check_if_quota_zero"
1008 cd $T_PWD; sh llmountcleanup.sh || error "llmountcleanup failed"
1011 run_test 0 "reboot lustre"
1016 test_14a() { # was test_14 b=12223 -- setting quota on root
1017 TESTFILE="$DIR/$tdir/$tfile"
1020 # out of root's file and block quota
1021 $LFS setquota -u root 10 10 10 10 $DIR
1022 createmany -m ${TESTFILE} 20 || \
1023 error "unexpected: user(root) create files failly!"
1024 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1025 error "unexpected: user(root) write files failly!"
1027 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1028 error "unexpected: user(quota_usr) write a file successfully!"
1032 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1033 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1036 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1037 $LFS setquota -u root 0 0 0 0 $DIR
1038 #check_if_quota_zero u root
1041 unlinkmany ${TESTFILE} 15
1044 run_test 14a "test setting quota on root ==="
1052 run_test 99 "Quota off ==============================="
1055 log "cleanup: ======================================================"
1058 check_and_cleanup_lustre
1059 echo '=========================== finished ==============================='
1060 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
1061 echo "$0: completed"