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 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
21 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
22 # We have changed the mechanism of quota, test_12 is meanless now.
24 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
25 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
28 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
29 *) error "unsupported kernel" ;;
32 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
33 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
39 TSTID2=${TSTID2:-60001}
40 TSTUSR=${TSTUSR:-"quota_usr"}
41 TSTUSR2=${TSTUSR2:-"quota_2usr"}
43 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
44 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
49 LUSTRE=${LUSTRE:-`dirname $0`/..}
50 . $LUSTRE/tests/test-framework.sh
52 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
54 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
56 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
58 require_dsh_mds || exit 0
59 require_dsh_ost || exit 0
61 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
63 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
65 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
70 QUOTA_AUTO_OLD=$QUOTA_AUTO
73 check_and_setup_lustre
75 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
76 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
78 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
79 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
80 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
81 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
82 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
83 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
84 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
85 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
87 # control the time of tests
89 [ "$SLOW" = "no" ] && cycle=10
93 # set_blk_tunables(btune_sz)
95 local btune=$(($1 * BLK_SZ))
96 # set btune size on all obdfilters
97 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
98 # set btune size on mds
99 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
102 # set_blk_unitsz(bunit_sz)
104 local bunit=$(($1 * BLK_SZ))
105 # set bunit size on all obdfilters
106 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
107 # set bunit size on mds
108 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
111 # set_file_tunesz(itune_sz)
114 # set itune size on all obdfilters
115 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_itune_sz=$itune"
116 # set itune size on mds
117 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
120 # set_file_unitsz(iunit_sz)
123 # set iunit size on all obdfilters
124 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_iunit_sz=$iunit"
125 # set iunit size on mds
126 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
132 local fail_val=${3:-0}
134 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
135 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
136 [ $((fail_loc)) -eq 0 ]; then
137 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
139 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
141 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
142 for num in `seq $OSTCOUNT`; do
143 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
144 [ $((fail_loc)) -eq 0 ]; then
145 do_facet ost$num "lctl set_param fail_val=$fail_val"
147 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
152 RUNAS="runas -u $TSTID -g $TSTID"
153 RUNAS2="runas -u $TSTID2 -g $TSTID2"
154 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
155 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
159 run_test_with_stat() {
160 (($# != 2)) && error "the number of arguments is wrong"
162 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
163 for j in `seq $OSTCOUNT`; do
164 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
167 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
168 echo "statistics info begin ***************************************"
169 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
170 for j in `seq $OSTCOUNT`; do
171 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
173 echo "statistics info end ***************************************"
178 # clear quota limits for a user or a group
179 # usage: resetquota -u username
180 # resetquota -g groupname
183 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
184 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
187 if at_is_enabled; then
188 timeout=$(at_max_get mds)
190 timeout=$(lctl get_param -n timeout)
193 while [ $((count++)) -lt $timeout ]; do
195 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
196 if [ $RC -ne 0 ]; then
197 if echo "$OUTPUT" | grep -q busy; then
198 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
202 error "resetquota failed"
208 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
215 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
216 log "Files for user ($LOCAL_ID):"
217 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
220 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
221 log "Files for group ($LOCAL_ID):"
222 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
239 # get quota info for a user or a group
240 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
246 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
247 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
260 *) error "unknown quota parameter $4";;
263 [ "$uuid" = "global" ] && uuid=$DIR
265 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }'
272 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
274 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
276 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
277 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
278 if [ -z $USAGE ]; then
279 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
281 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
285 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
286 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
287 if [ -z $USAGE ]; then
288 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
290 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
297 $LFS quotacheck -ug $DIR
299 resetquota -u $TSTUSR
300 resetquota -g $TSTUSR
302 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
306 test_quota_performance() {
307 TESTFILE="$DIR/$tdir/$tfile-0"
309 local stime=`date +%s`
310 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
311 local etime=`date +%s`
312 delta=$((etime - stime))
313 if [ $delta -gt 0 ]; then
314 rate=$((size * 1024 / delta))
315 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
320 # test basic quota performance b=21696
323 chmod 0777 $DIR/$tdir
325 [ "$SLOW" = "no" ] && MB=10
327 test_quota_performance $MB
329 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
330 test_quota_performance $MB
332 resetquota -u $TSTUSR
334 run_test_with_stat 0 "Test basic quota performance ==="
336 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
340 chmod 0777 $DIR/$tdir
341 TESTFILE="$DIR/$tdir/$tfile-0"
343 wait_delete_completed
346 log " User quota (limit: $LIMIT kbytes)"
347 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
349 quota_show_check b u $TSTUSR
351 $LFS setstripe $TESTFILE -c 1
352 chown $TSTUSR.$TSTUSR $TESTFILE
355 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
357 log " Write out of block quota ..."
358 # this time maybe cache write, ignore it's failure
359 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
360 # flush cache, ensure noquota flag is setted on client
362 $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"
366 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
367 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
368 echo $OST0_QUOTA_USED
369 [ $OST0_QUOTA_USED -ne 0 ] && \
370 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
372 resetquota -u $TSTUSR
375 log "--------------------------------------"
376 log " Group quota (limit: $LIMIT kbytes)"
377 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
379 quota_show_check b g $TSTUSR
380 TESTFILE="$DIR/$tdir/$tfile-1"
382 $LFS setstripe $TESTFILE -c 1
383 chown $TSTUSR.$TSTUSR $TESTFILE
386 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
388 log " Write out of block quota ..."
389 # this time maybe cache write, ignore it's failure
390 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
392 $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"
397 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
398 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
399 echo $OST0_QUOTA_USED
400 [ $OST0_QUOTA_USED -ne 0 ] && \
401 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
403 resetquota -g $TSTUSR
406 # block hard limit (normal use and out of quota)
408 for i in `seq 1 $cycle`; do
409 # define blk_qunit is between 1M and 4M
410 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
411 blk_qtune=$(( $RANDOM % $blk_qunit ))
412 # other osts and mds will occupy at 1M blk quota
413 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
414 set_blk_tunesz $blk_qtune
415 set_blk_unitsz $blk_qunit
416 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
418 echo "=================================================="
419 set_blk_unitsz $((128 * 1024))
420 set_blk_tunesz $((128 * 1024 / 2))
423 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
425 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
429 chmod 0777 $DIR/$tdir
430 TESTFILE="$DIR/$tdir/$tfile-0"
432 wait_delete_completed
435 log " User quota (limit: $LIMIT files)"
436 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
438 quota_show_check f u $TSTUSR
440 log " Create $LIMIT files ..."
441 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
442 quota_error u $TSTUSR "(usr) create failure, but expect success"
444 log " Create out of file quota ..."
445 $RUNAS touch ${TESTFILE}_xxx && \
446 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
448 unlinkmany ${TESTFILE} $LIMIT
449 rm -f ${TESTFILE}_xxx
452 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
453 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
455 [ $MDS_QUOTA_USED -ne 0 ] && \
456 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
458 resetquota -u $TSTUSR
461 log "--------------------------------------"
462 log " Group quota (limit: $LIMIT FILE)"
463 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
465 quota_show_check f g $TSTUSR
466 TESTFILE=$DIR/$tdir/$tfile-1
468 log " Create $LIMIT files ..."
469 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
470 quota_error g $TSTUSR "(grp) create failure, but expect success"
472 log " Create out of file quota ..."
473 $RUNAS touch ${TESTFILE}_xxx && \
474 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
476 unlinkmany ${TESTFILE} $LIMIT
477 rm -f ${TESTFILE}_xxx
480 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
481 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
483 [ $MDS_QUOTA_USED -ne 0 ] && \
484 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
486 resetquota -g $TSTUSR
489 # file hard limit (normal use and out of quota)
491 for i in `seq 1 $cycle`; do
492 if [ $i -eq 1 ]; then
497 # define ino_qunit is between 10 and 100
498 ino_qunit=$(( $RANDOM % 90 + 10 ))
499 ino_qtune=$(( $RANDOM % $ino_qunit ))
500 # RANDOM's maxium is 32767
501 i_limit=$(( $RANDOM % 990 + 10 ))
504 set_file_tunesz $ino_qtune
505 set_file_unitsz $ino_qunit
506 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
508 echo "=================================================="
513 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
517 TIMER=$(($2 * 3 / 2))
520 wait_delete_completed
522 echo " Write to exceed soft limit"
523 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
524 $RUNDD count=$((BUNIT_SZ+1)) || \
525 quota_error a $TSTUSR "write failure, but expect success"
526 OFFSET=$((OFFSET + BUNIT_SZ + 1))
531 $SHOW_QUOTA_INFO_USER
532 $SHOW_QUOTA_INFO_GROUP
534 echo " Write before timer goes off"
535 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
536 quota_error a $TSTUSR "write failure, but expect success"
537 OFFSET=$((OFFSET + BUNIT_SZ))
541 echo " Sleep $TIMER seconds ..."
546 $SHOW_QUOTA_INFO_USER
547 $SHOW_QUOTA_INFO_GROUP
549 echo " Write after timer goes off"
550 # maybe cache write, ignore.
551 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
552 OFFSET=$((OFFSET + BUNIT_SZ))
554 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
555 quota_error a $TSTUSR "write success, but expect EDQUOT"
559 $SHOW_QUOTA_INFO_USER
560 $SHOW_QUOTA_INFO_GROUP
562 echo " Unlink file to stop timer"
569 $SHOW_QUOTA_INFO_USER
570 $SHOW_QUOTA_INFO_GROUP
573 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
581 # block soft limit (start timer, timer goes off, stop timer)
584 chmod 0777 $DIR/$tdir
586 # 1 bunit on mds and 1 bunit on every ost
587 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
590 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
591 TESTFILE=$DIR/$tdir/$tfile-0
593 $LFS setstripe $TESTFILE -c 1
594 chown $TSTUSR.$TSTUSR $TESTFILE
596 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
597 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
599 test_block_soft $TESTFILE $GRACE
600 resetquota -u $TSTUSR
602 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
603 TESTFILE=$DIR/$tdir/$tfile-1
605 $LFS setstripe $TESTFILE -c 1
606 chown $TSTUSR.$TSTUSR $TESTFILE
608 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
609 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
611 test_block_soft $TESTFILE $GRACE
612 resetquota -g $TSTUSR
614 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
619 TIMER=$(($3 * 3 / 2))
621 wait_delete_completed
623 echo " Create files to exceed soft limit"
624 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
625 quota_error a $TSTUSR "create failure, but expect success"
629 echo " Create file before timer goes off"
630 $RUNAS touch ${TESTFILE}_before || \
631 quota_error a $TSTUSR "failed create before timer expired, but expect success"
635 echo " Sleep $TIMER seconds ..."
640 $SHOW_QUOTA_INFO_USER
641 $SHOW_QUOTA_INFO_GROUP
643 echo " Create file after timer goes off"
644 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
645 # inode quota left here
646 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
648 $RUNAS touch ${TESTFILE}_after3 && \
649 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
654 $SHOW_QUOTA_INFO_USER
655 $SHOW_QUOTA_INFO_GROUP
657 echo " Unlink files to stop timer"
658 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
662 $RUNAS touch ${TESTFILE}_xxx || \
663 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
668 rm -f ${TESTFILE}_xxx
672 # file soft limit (start timer, timer goes off, stop timer)
673 test_4a() { # was test_4
675 chmod 0777 $DIR/$tdir
676 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
677 TESTFILE=$DIR/$tdir/$tfile-0
681 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
682 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
683 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
684 quota_show_check f u $TSTUSR
686 test_file_soft $TESTFILE $LIMIT $GRACE
687 resetquota -u $TSTUSR
689 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
690 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
691 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
692 quota_show_check f g $TSTUSR
693 TESTFILE=$DIR/$tdir/$tfile-1
695 test_file_soft $TESTFILE $LIMIT $GRACE
696 resetquota -g $TSTUSR
699 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
700 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
702 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
704 test_4b() { # was test_4a
710 GR_STR6="1111111111111111"
712 wait_delete_completed
714 # test of valid grace strings handling
715 echo " Valid grace strings test"
716 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
717 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
718 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
719 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
721 # test of invalid grace strings handling
722 echo " Invalid grace strings test"
723 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
724 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
727 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
728 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
730 run_test_with_stat 4b "Grace time strings handling ==="
732 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
735 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
736 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
738 wait_delete_completed
740 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
741 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
742 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
743 quota_show_check a u $TSTUSR
744 quota_show_check a g $TSTUSR
746 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
747 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
748 error "touch failure, expect success"
749 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
751 echo " Chown files to $TSTUSR.$TSTUSR ..."
752 for i in `seq 0 $ILIMIT`; do
753 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
754 quota_error a $TSTUSR "chown failure, but expect success"
758 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
761 resetquota -u $TSTUSR
762 resetquota -g $TSTUSR
764 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
766 # block quota acquire & release
768 if [ $OSTCOUNT -lt 2 ]; then
769 skip_env "$OSTCOUNT < 2, too few osts"
773 wait_delete_completed
776 chmod 0777 $DIR/$tdir
778 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
779 FILEA="$DIR/$tdir/$tfile-0_a"
780 FILEB="$DIR/$tdir/$tfile-0_b"
782 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
783 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
784 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
785 quota_show_check b u $TSTUSR
786 quota_show_check b g $TSTUSR
788 echo " Create filea on OST0 and fileb on OST1"
789 $LFS setstripe $FILEA -i 0 -c 1
790 $LFS setstripe $FILEB -i 1 -c 1
791 chown $TSTUSR.$TSTUSR $FILEA
792 chown $TSTUSR.$TSTUSR $FILEB
794 echo " Exceed quota limit ..."
795 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
796 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
797 quota_error a $TSTUSR "write filea failure, but expect success"
802 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
803 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
805 echo " Write to OST1 return EDQUOT"
806 # this write maybe cache write, ignore it's failure
807 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
808 $RUNDD count=$(($BUNIT_SZ * 2)) || true
812 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
813 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
815 echo " Remove filea to let OST0 release quota"
818 if at_is_enabled; then
819 timeout=$(at_max_get mds)
821 timeout=$(lctl get_param -n timeout)
823 count=$((timeout / 5))
824 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
826 while [ $((count--)) -gt 0 ]; do
829 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
830 if [ -z $OST0_QUOTA_HOLD ]; then
831 error "System is error when query quota for block (U:$TSTUSR)."
833 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
839 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
842 while [ $((count--)) -gt 0 ]; do
845 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
846 if [ -z $OST0_QUOTA_HOLD ]; then
847 error "System is error when query quota for block (G:$TSTUSR)."
849 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
855 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
858 echo " Write to OST1"
859 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
860 quota_error a $TSTUSR "write fileb failure, expect success"
867 resetquota -u $TSTUSR
868 resetquota -g $TSTUSR
871 run_test_with_stat 6 "Block quota acquire & release ========="
873 # quota recovery (block quota only by now)
877 chmod 0777 $DIR/$tdir
879 wait_delete_completed
881 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
882 TESTFILE="$DIR/$tdir/$tfile-0"
884 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
886 $LFS setstripe $TESTFILE -c 1
887 chown $TSTUSR.$TSTUSR $TESTFILE
889 echo " Write to OST0..."
890 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
891 quota_error u $TSTUSR "write failure, but expect success"
893 #define OBD_FAIL_OBD_DQACQ 0x604
894 lustre_fail mds 0x604
895 echo " Remove files on OST0"
899 echo " Trigger recovery..."
900 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
901 for i in $OSC0_UUID; do
902 $LCTL --device $i activate || error "activate osc failed!"
905 # sleep a while to wait for recovery done
909 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
910 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
911 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
912 echo " total limits = $TOTAL_LIMIT"
914 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
915 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
916 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
917 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
918 echo " limits on $OST0_UUID = $OST0_LIMIT"
921 resetquota -u $TSTUSR
923 run_test_with_stat 7 "Quota recovery (only block limit) ======"
925 # run dbench with quota enabled
928 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
931 wait_delete_completed
933 echo " Set enough high limit for user: $TSTUSR"
934 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
935 echo " Set enough high limit for group: $TSTUSR"
936 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
938 chmod 0777 $DIR/$tdir
940 [ "$SLOW" = "no" ] && duration=" -t 120"
941 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
948 run_test_with_stat 8 "Run dbench with quota enabled ==========="
950 # run for fixing bug10707, it needs a big room. test for 64bit
952 GB=$((KB * 1024 * 1024))
953 # Use this as dd bs to decrease time
954 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
955 blksize=$((1 << 21)) # 2Mb
956 size_file=$((GB * 9 / 2))
957 # this check is just for test9 and test10
958 OST0_MIN=4900000 #4.67G
959 check_whether_skip () {
960 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
961 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
962 if [ $OST0_SIZE -lt $OST0_MIN ]; then
963 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
971 check_whether_skip && return 0
973 wait_delete_completed
979 chmod 0777 $DIR/$tdir
980 TESTFILE="$DIR/$tdir/$tfile-0"
982 BLK_LIMIT=$((100 * KB * KB)) # 100G
984 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
986 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
987 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
988 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
989 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
991 quota_show_check a u $TSTUSR
992 quota_show_check a g $TSTUSR
995 $LFS setstripe $TESTFILE -c 1
997 chown $TSTUSR.$TSTUSR $TESTFILE
999 log " Write the big file of 4.5G ..."
1000 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1001 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1006 log " delete the big file of 4.5G..."
1007 $RUNAS rm -f $TESTFILE
1008 sync; sleep 3; sync;
1015 set_blk_unitsz $((128 * 1024))
1016 set_blk_tunesz $((128 * 1024 / 2))
1020 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1022 # run for fixing bug10707, it need a big room. test for 32bit
1023 # 2.0 version does not support 32 bit qd_count, so such test is obsolete.
1026 chmod 0777 $DIR/$tdir
1027 check_whether_skip && return 0
1029 wait_delete_completed
1034 # make qd_count 32 bit
1035 lustre_fail mds_ost 0xA00
1037 TESTFILE="$DIR/$tdir/$tfile-0"
1039 BLK_LIMIT=$((100 * KB * KB)) # 100G
1042 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1043 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1044 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1045 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1047 quota_show_check a u $TSTUSR
1048 quota_show_check a g $TSTUSR
1051 $LFS setstripe $TESTFILE -c 1
1053 chown $TSTUSR.$TSTUSR $TESTFILE
1055 log " Write the big file of 4.5 G ..."
1056 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1057 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1062 log " delete the big file of 4.5 G..."
1063 $RUNAS rm -f $TESTFILE
1064 sync; sleep 3; sync;
1071 # make qd_count 64 bit
1072 lustre_fail mds_ost 0
1074 set_blk_unitsz $((128 * 1024))
1075 set_blk_tunesz $((128 * 1024 / 2))
1079 #run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1081 # test a deadlock between quota and journal b=11693
1084 chmod 0777 $DIR/$tdir
1086 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1087 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1089 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1090 TESTFILE="$DIR/$tdir/$tfile-0"
1091 TESTFILE2="$DIR2/$tdir/$tfile-1"
1093 wait_delete_completed
1095 echo " User quota (limit: $LIMIT kbytes)"
1096 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1098 $LFS setstripe $TESTFILE -i 0 -c 1
1099 chown $TSTUSR.$TSTUSR $TESTFILE
1100 $LFS setstripe $TESTFILE2 -i 0 -c 1
1101 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1103 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1104 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1105 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1107 echo " step1: write out of block quota ..."
1108 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1110 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1113 echo " step2: testing ......"
1114 local last_size=$(stat -c %s $TESTFILE2)
1116 local start_secs=$SECONDS
1117 while [ -d /proc/${DDPID1} ]; do
1118 local size=$(stat -c %s $TESTFILE2)
1119 if [ $size -eq $last_size ]; then
1120 stall_secs=$[stall_secs+1]
1124 if [ $stall_secs -gt 30 ]; then
1126 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1131 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1133 #Recover fail_loc and dd will finish soon
1136 echo " step3: testing ......"
1139 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1141 if [ $count -gt 150 ]; then
1142 quota_error u $TSTUSR "dd should be finished!"
1146 echo "(dd_pid=$DDPID, time=$count)successful"
1148 rm -f $TESTFILE $TESTFILE2
1149 sync; sleep 3; sync;
1151 resetquota -u $TSTUSR
1153 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1155 # test multiple clients write block quota b=11693
1158 wait_delete_completed
1160 # one OST * 10 + (mds + other OSTs)
1161 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1162 TESTFILE="$DIR/$tdir/$tfile"
1164 echo " User quota (limit: $LIMIT kbytes)"
1165 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1166 quota_show_check b u $TSTUSR
1168 $LFS setstripe $TESTFILE -i 0 -c 1
1169 chown $TSTUSR.$TSTUSR $TESTFILE
1170 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1171 chown $TSTUSR.$TSTUSR $TESTFILE.2
1173 echo " step1: write out of block quota ..."
1174 # one bunit will give mds
1175 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1177 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1180 echo " step2: testing ......"
1183 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1185 if [ $count -gt 64 ]; then
1186 quota_error u $TSTUSR "dd should be finished!"
1190 echo "(dd_pid=$DDPID, time=$count)successful"
1194 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1196 if [ $count -gt 64 ]; then
1197 quota_error u $TSTUSR "dd should be finished!"
1201 echo "(dd_pid=$DDPID1, time=$count)successful"
1203 sync; sleep 5; sync;
1205 echo " step3: checking ......"
1206 fz=`stat -c %s $TESTFILE`
1207 fz2=`stat -c %s $TESTFILE.2`
1209 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1210 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1212 rm -f $TESTFILE $TESTFILE.2
1213 sync; sleep 3; sync;
1215 resetquota -u $TSTUSR
1217 run_test_with_stat 13 "test multiple clients write block quota ==="
1219 check_if_quota_zero(){
1220 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1221 for i in `seq 3 $line`; do
1222 if [ $i -eq 3 ]; then
1228 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1229 awk '{print $'"$j"'}'`
1230 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1231 error "quota on $2 isn't clean"
1234 echo "pass check_if_quota_zero"
1237 test_14a() { # was test_14 b=12223 -- setting quota on root
1238 TESTFILE="$DIR/$tdir/$tfile"
1242 cleanup_and_setup_lustre
1247 # out of root's file and block quota
1248 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1249 createmany -m ${TESTFILE} 20 || \
1250 quota_error u root "unexpected: user(root) create files failly!"
1251 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1252 quota_error u root "unexpected: user(root) write files failly!"
1254 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1255 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1259 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1260 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1263 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1265 #check_if_quota_zero u root
1268 unlinkmany ${TESTFILE} 15
1270 sync; sleep 3; sync;
1272 run_test_with_stat 14a "test setting quota on root ==="
1275 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1276 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1278 wait_delete_completed
1281 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1282 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1283 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1284 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1285 resetquota -u $TSTUSR
1288 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1289 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1290 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1291 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1292 resetquota -g $TSTUSR
1293 $LFS quotaoff -ug $DIR
1294 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1295 error "fail to set version for $SINGLEMDS"
1296 for j in `seq $OSTCOUNT`; do
1297 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1298 error "fail to set version for ost$j"
1301 echo "invalidating quota files"
1302 $LFS quotainv -ug $DIR
1303 $LFS quotainv -ugf $DIR
1304 $LFS quotacheck -ug $DIR
1306 run_test_with_stat 15 "set block quota more than 4T ==="
1308 # $1=u/g $2=with qunit adjust or not
1310 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1311 TESTFILE="$DIR/$tdir/$tfile"
1314 wait_delete_completed
1316 echo " User quota (limit: $LIMIT kbytes)"
1317 if [ $1 == "u" ]; then
1318 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1319 quota_show_check b u $TSTUSR
1321 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1322 quota_show_check b g $TSTUSR
1325 $LFS setstripe $TESTFILE -c 1
1326 chown $TSTUSR.$TSTUSR $TESTFILE
1329 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1330 quota_error a $TSTUSR "(usr) write failure, but expect success"
1332 echo " Write out of block quota ..."
1333 # this time maybe cache write, ignore it's failure
1334 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1335 # flush cache, ensure noquota flag is setted on client
1336 cancel_lru_locks osc
1337 if [ $2 -eq 1 ]; then
1338 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1339 quota_error a $TSTUSR "(write failure, but expect success"
1341 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1342 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1346 sync; sleep 3; sync;
1347 resetquota -$1 $TSTUSR
1350 # test without adjusting qunit
1351 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1353 set_blk_tunesz $((BUNIT_SZ * 2))
1354 set_blk_unitsz $((BUNIT_SZ * 4))
1357 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1358 echo " grp/usr: $i, adjust qunit: $j"
1359 echo "-------------------------------"
1360 [ $j -eq 1 ] && lustre_fail mds_ost 0
1361 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1365 set_blk_unitsz $((128 * 1024))
1366 set_blk_tunesz $((128 * 1024 / 2))
1368 #run_test_with_stat 16 "test without adjusting qunit"
1370 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1375 wait_delete_completed
1377 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1378 lustre_fail ost 0x80000A02
1380 TESTFILE="$DIR/$tdir/$tfile-a"
1381 TESTFILE2="$DIR/$tdir/$tfile-b"
1384 BLK_LIMIT=$((100 * 1024)) # 100M
1386 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1387 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1388 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1389 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1391 quota_show_check b u $TSTUSR
1392 quota_show_check b g $TSTUSR
1395 chown $TSTUSR.$TSTUSR $TESTFILE
1397 chown $TSTUSR.$TSTUSR $TESTFILE2
1399 log " Write the test file1 ..."
1400 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1401 || quota_error a $TSTUSR "write 10M file failure"
1406 log " write the test file2 ..."
1407 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1408 || quota_error a $TSTUSR "write 10M file failure"
1413 rm -f $TESTFILE $TESTFILE2
1415 sync; sleep 3; sync;
1417 # make qd_count 64 bit
1420 set_blk_unitsz $((128 * 1024))
1421 set_blk_tunesz $((128 * 1024 / 2))
1423 resetquota -u $TSTUSR
1424 resetquota -g $TSTUSR
1428 run_test_with_stat 17 "run for fixing bug14526 ==========="
1430 # test when mds takes a long time to handle a quota req so that
1431 # the ost has dropped it, the ost still could work well b=14840
1433 LIMIT=$((100 * 1024 * 1024)) # 100G
1434 TESTFILE="$DIR/$tdir/$tfile"
1437 wait_delete_completed
1442 log " User quota (limit: $LIMIT kbytes)"
1443 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1444 quota_show_check b u $TSTUSR
1446 $LFS setstripe $TESTFILE -i 0 -c 1
1447 chown $TSTUSR.$TSTUSR $TESTFILE
1449 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1450 lustre_fail mds 0x13c
1452 log " step1: write 100M block ..."
1453 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1459 echo " step2: testing ......"
1461 if at_is_enabled; then
1462 timeout=$(at_max_get mds)
1464 timeout=$(lctl get_param -n timeout)
1467 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1469 if [ $count -gt $((4 * $timeout)) ]; then
1470 quota_error u $TSTUSR "count=$count dd should be finished!"
1474 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1476 cancel_lru_locks mdc
1477 cancel_lru_locks osc
1479 testfile_size=$(stat -c %s $TESTFILE)
1480 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1481 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1486 resetquota -u $TSTUSR
1487 set_blk_unitsz $((128 * 1024))
1488 set_blk_tunesz $((128 * 1024 / 2))
1490 run_test_with_stat 18 "run for fixing bug14840 ==========="
1492 # test when mds drops a quota req, the ost still could work well b=14840
1494 LIMIT=$((100 * 1024 * 1024)) # 100G
1495 TESTFILE="$DIR/$tdir/$tfile-a"
1498 wait_delete_completed
1503 log " User quota (limit: $LIMIT kbytes)"
1504 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1505 quota_show_check b u $TSTUSR
1507 $LFS setstripe $TESTFILE -i 0 -c 1
1508 chown $TSTUSR.$TSTUSR $TESTFILE
1510 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1511 lustre_fail mds 0x8000013d
1513 log " step1: write 100M block ..."
1514 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1517 echo " step2: testing ......"
1519 if at_is_enabled; then
1520 timeout=$(at_max_get mds)
1522 timeout=$(lctl get_param -n timeout)
1525 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1527 if [ $count -gt $((6 * $timeout)) ]; then
1529 quota_error u $TSTUSR "count=$count dd should be finished!"
1533 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1539 resetquota -u $TSTUSR
1540 set_blk_unitsz $((128 * 1024))
1541 set_blk_tunesz $((128 * 1024 / 2))
1543 run_test_with_stat 18a "run for fixing bug14840 ==========="
1545 # test when mds do failover, the ost still could work well without trigger
1550 LIMIT=$((110 * 1024 )) # 110M
1551 TESTFILE="$DIR/$tdir/$tfile"
1554 wait_delete_completed
1559 log " User quota (limit: $LIMIT kbytes)"
1560 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1561 quota_show_check b u $TSTUSR
1563 $LFS setstripe $TESTFILE -i 0 -c 1
1564 chown $TSTUSR.$TSTUSR $TESTFILE
1566 timeout=$(sysctl -n lustre.timeout)
1568 if [ $type = "directio" ]; then
1569 log " write 100M block(directio) ..."
1570 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1572 log " write 100M block(normal) ..."
1573 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1577 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1579 log "failing mds for $((2 * timeout)) seconds"
1580 fail $SINGLEMDS $((2 * timeout))
1582 # check if quotaon successful
1583 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1584 if [ $? -eq 0 ]; then
1585 error "quotaon failed!"
1591 if at_is_enabled; then
1592 timeout=$(at_max_get mds)
1594 timeout=$(lctl get_param -n timeout)
1597 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1598 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1599 log "it took $count second"
1603 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1605 cancel_lru_locks mdc
1606 cancel_lru_locks osc
1608 testfile_size=$(stat -c %s $TESTFILE)
1609 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1610 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1615 resetquota -u $TSTUSR
1616 set_blk_unitsz $((128 * 1024))
1617 set_blk_tunesz $((128 * 1024 / 2))
1620 # test when mds does failover, the ost still could work well
1621 # this test shouldn't trigger watchdog b=14840
1623 test_18bc_sub normal
1624 test_18bc_sub directio
1625 # check if watchdog is triggered
1626 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1627 watchdog=`awk '/test 18b/ {start = 1;}
1628 /Service thread pid/ && /was inactive/ {
1632 }' $TMP/lustre-log-${TESTNAME}.log`
1633 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1634 rm -f $TMP/lustre-log-${TESTNAME}.log
1636 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1638 # test when mds does failover, the ost still could work well
1639 # this test will prevent OST_DISCONNET from happening b=14840
1641 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1642 lustre_fail ost 0x202
1643 test_18bc_sub normal
1644 test_18bc_sub directio
1647 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1649 run_to_block_limit() {
1650 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1652 wait_delete_completed
1654 # set 1 Mb quota unit size
1658 # bind file to a single OST
1659 $LFS setstripe -c 1 $TESTFILE
1660 chown $TSTUSR.$TSTUSR $TESTFILE
1662 echo " User quota (limit: $LIMIT kbytes)"
1663 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1664 quota_show_check b u $TSTUSR
1665 echo " Updating quota limits"
1666 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1667 quota_show_check b u $TSTUSR
1669 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1670 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1671 # for now page cache of TESTFILE may still be dirty,
1672 # let's push it to the corresponding OST, this will also
1673 # cache NOQUOTA on the client from OST's reply
1674 cancel_lru_locks osc
1675 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1679 # 1 Mb bunit per each MDS/OSS
1680 local TESTFILE="$DIR/$tdir/$tfile"
1683 run_to_block_limit $TESTFILE
1688 resetquota -u $TSTUSR
1690 set_blk_unitsz $((128 * 1024))
1691 set_blk_tunesz $((128 * 1024 / 2))
1694 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1698 LSTR=(1t 2g 3m 4k) # limits strings
1699 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1701 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1702 $MOUNT || error "could not set quota limits"
1704 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1705 --inode-softlimit ${LSTR[2]} \
1706 --inode-hardlimit ${LSTR[3]} \
1707 $MOUNT || error "could not set quota limits"
1709 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1710 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1711 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1712 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1714 resetquota -u $TSTUSR
1716 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1723 time=$(($(date +%s) + seconds))
1724 while [ $(date +%s) -lt $time ]; do
1725 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1730 # run for fixing bug16053, setquota shouldn't fail when writing and
1731 # deleting are happening
1736 wait_delete_completed
1738 TESTFILE="$DIR/$tdir/$tfile"
1740 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1743 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1744 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1745 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1746 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1748 # repeat writing on a 1M file
1749 test_21_sub ${TESTFILE}_1 1024 30 &
1751 # repeat writing on a 128M file
1752 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1755 time=$(($(date +%s) + 30))
1757 while [ $(date +%s) -lt $time ]; do
1758 log " Set quota for $i times"
1759 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1760 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1767 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1769 if [ $count -gt 60 ]; then
1770 quota_error a $TSTUSR "dd should be finished!"
1774 echo "(dd_pid=$DDPID1, time=$count)successful"
1778 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1780 if [ $count -gt 60 ]; then
1781 quota_error a $TSTUSR "dd should be finished!"
1785 echo "(dd_pid=$DDPID2, time=$count)successful"
1787 set_blk_unitsz $((128 * 1024))
1788 set_blk_tunesz $((128 * 1024 / 2))
1789 resetquota -u $TSTUSR
1790 resetquota -g $TSTUSR
1794 run_test_with_stat 21 "run for fixing bug16053 ==========="
1797 quota_save_version "ug3"
1803 echo "checking parameters"
1805 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1806 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1810 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1814 chmod 0777 $DIR/$tdir
1815 TESTFILE="$DIR/$tdir/$tfile-0"
1817 local bs_unit=$((1024*1024))
1820 wait_delete_completed
1823 log " User quota (limit: $LIMIT kbytes)"
1824 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1826 quota_show_check b u $TSTUSR
1828 $LFS setstripe $TESTFILE -c 1
1829 chown $TSTUSR.$TSTUSR $TESTFILE
1831 log " Step1: trigger quota with 0_DIRECT"
1832 log " Write half of file"
1833 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1834 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1835 log " Write out of block quota ..."
1836 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1837 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1840 log " Step2: rewrite should succeed"
1841 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1842 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1846 wait_delete_completed
1847 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1848 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1849 echo $OST0_QUOTA_USED
1850 [ $OST0_QUOTA_USED -ne 0 ] && \
1851 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1853 resetquota -u $TSTUSR
1857 log "run for $((OSTCOUNT * 4))MB test file"
1858 test_23_sub $((OSTCOUNT * 4 * 1024))
1861 check_whether_skip && return 0
1862 log "run for $((OSTCOUNT * 40))MB test file"
1863 test_23_sub $((OSTCOUNT * 40 * 1024))
1865 run_test_with_stat 23 "run for fixing bug16125 ==========="
1868 local TESTFILE="$DIR/$tdir/$tfile"
1871 run_to_block_limit $TESTFILE
1872 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1876 resetquota -u $TSTUSR
1878 set_blk_unitsz $((128 * 1024))
1879 set_blk_tunesz $((128 * 1024 / 2))
1882 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1885 if [ $1 = "-u" ]; then
1886 if [ $2 = "$TSTUSR" ]; then
1892 if [ $2 = "$TSTUSR" ]; then
1902 chmod 0777 $DIR/$tdir
1903 TESTFILE="$DIR/$tdir/$tfile-0"
1905 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1907 wait_delete_completed
1909 # set quota for $TSTUSR
1910 log "setquota for $TSTUSR"
1911 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1913 if [ "$1" == "-u" ]; then
1914 quota_show_check a u $TSTUSR
1916 quota_show_check a g $TSTUSR
1919 # set quota for $TSTUSR2
1920 log "setquota for $TSTUSR2"
1921 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1923 if [ "$1" == "-u" ]; then
1924 quota_show_check a u $TSTUSR2
1926 quota_show_check a g $TSTUSR2
1929 # set stripe index to 0
1930 log "setstripe for $DIR/$tdir to 0"
1931 $LFS setstripe $DIR/$tdir -c 1 -i 0
1932 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1933 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1934 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1935 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1936 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1937 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1940 log "$TSTUSR write 4M to $TESTFILE"
1941 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1943 show_quota $1 $TSTUSR
1944 show_quota $1 $TSTUSR2
1945 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1946 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1947 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1948 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1949 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1950 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1951 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1953 # chown/chgrp from $TSTUSR to $TSTUSR2
1954 if [ $1 = "-u" ]; then
1955 log "chown from $TSTUSR to $TSTUSR2"
1956 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1958 log "chgrp from $TSTUSR to $TSTUSR2"
1959 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1962 show_quota $1 $TSTUSR
1963 show_quota $1 $TSTUSR2
1964 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1965 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1966 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1967 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1968 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1969 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1970 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1971 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1972 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1973 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1974 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1975 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1976 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1977 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1978 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1981 wait_delete_completed
1982 resetquota $1 $TSTUSR
1983 resetquota $1 $TSTUSR2
1987 log "run for chown case"
1990 log "run for chgrp case"
1993 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1997 chmod 0777 $DIR/$tdir
1998 TESTFILE="$DIR/$tdir/$tfile-0"
1999 TESTFILE2="$DIR/$tdir/$tfile-1"
2003 wait_delete_completed
2005 # every quota slave gets 20MB
2006 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
2007 log "limit: ${b_limit}KB"
2008 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2010 quota_show_check b u $TSTUSR
2012 $LFS setstripe $TESTFILE -c 1 -i 0
2013 $LFS setstripe $TESTFILE2 -c 1 -i 0
2014 chown $TSTUSR.$TSTUSR $TESTFILE
2015 chown $TSTUSR.$TSTUSR $TESTFILE2
2017 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2018 lustre_fail ost 0xA03
2020 log " Write the first file..."
2021 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2022 log " Delete the first file..."
2026 wait_delete_completed
2028 log " Write the second file..."
2029 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2030 log " Delete the second file..."
2034 set_blk_unitsz $((128 * 1024))
2035 set_blk_tunesz $((128 * 1024 / 2))
2036 resetquota -u $TSTUSR
2038 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2041 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2042 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2045 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2048 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2049 error "lfs setquota failed with uid argument"
2050 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2051 error "lfs stequota failed with gid argument"
2052 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2053 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2054 resetquota -u $TSTUSR
2055 resetquota -g $TSTUSR
2058 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2061 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2062 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2063 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2066 echo "Step 2: reset system ..."
2067 cleanup_and_setup_lustre
2070 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2074 wait_delete_completed
2076 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2077 lustre_fail ost 0x80000A02
2079 TESTFILE="$DIR/$tdir/$tfile"
2082 BLK_LIMIT=$((100 * 1024)) # 100M
2083 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2084 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2088 chown $TSTUSR.$TSTUSR $TESTFILE
2090 echo "Step 5: write the test file1 [10M] ..."
2091 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2092 || quota_error a $TSTUSR "write 10M file failure"
2096 sync; sleep 3; sync;
2098 # make qd_count 64 bit
2101 set_blk_unitsz $((128 * 1024))
2102 set_blk_tunesz $((128 * 1024 / 2))
2104 resetquota -u $TSTUSR
2106 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2110 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2114 if at_is_enabled; then
2115 timeout=$(at_max_get client)
2116 at_max_set 10 client
2118 timeout=$(lctl get_param -n timeout)
2119 lctl set_param timeout=10
2122 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2123 lustre_fail mds 0x12e
2125 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2127 echo "sleeping for $((10 * 2)) seconds"
2129 ps -p $pid && error "lfs hadn't finished by timeout"
2130 wait $pid && error "succeeded, but should have failed"
2134 if at_is_enabled; then
2135 at_max_set $timeout client
2137 lctl set_param timeout=$timeout
2140 resetquota -u $TSTUSR
2142 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2148 local TESTFILE="$DIR/$tdir/$tfile"
2155 chmod 0777 $DIR/$tdir
2157 $LFS setstripe $TESTFILE -i 0 -c 1
2158 chown $TSTUSR.$TSTUSR $TESTFILE
2160 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2161 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2162 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2163 cancel_lru_locks osc
2165 $LFS setquota -u $TSTUSR -B 0 $DIR
2166 # over-quota flag has not yet settled since we do not trigger async events
2167 # based on grace time period expiration
2169 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2170 cancel_lru_locks osc
2171 # now over-quota flag should be settled and further writes should fail
2173 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2175 resetquota -u $TSTUSR
2176 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2178 set_blk_unitsz $((128 * 1024))
2179 set_blk_tunesz $((128 * 1024 / 2))
2181 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2183 # test duplicate quota releases b=18630
2186 chmod 0777 $DIR/$tdir
2188 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2189 TESTFILE="$DIR/$tdir/$tfile-0"
2190 TESTFILE2="$DIR/$tdir/$tfile-1"
2192 wait_delete_completed
2194 log " User quota (limit: $LIMIT kbytes)"
2195 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2197 $LFS setstripe $TESTFILE -i 0 -c 1
2198 chown $TSTUSR.$TSTUSR $TESTFILE
2199 $LFS setstripe $TESTFILE2 -i 0 -c 1
2200 chown $TSTUSR.$TSTUSR $TESTFILE2
2202 log " step1: write out of block quota ..."
2203 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2204 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2206 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2207 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2208 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2210 log " step2: delete two files so that triggering duplicate quota release ..."
2211 rm -f $TESTFILE $TESTFILE2
2212 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2213 wait_delete_completed
2215 log " step3: verify if the ost failed"
2216 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2217 watchdog=`awk '/test 31/ {start = 1;}
2218 /release quota error/ {
2222 }' $TMP/lustre-log-${TESTNAME}.log`
2223 [ "$watchdog" ] && error "$watchdog"
2224 rm -f $TMP/lustre-log-${TESTNAME}.log
2227 resetquota -u $TSTUSR
2229 run_test_with_stat 31 "test duplicate quota releases ==="
2235 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2239 log "cleanup: ======================================================"
2241 check_and_cleanup_lustre
2242 echo '=========================== finished ==============================='
2243 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2244 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2245 echo "$0: completed"