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 ALWAYS_EXCEPT="10 $SANITY_QUOTA_EXCEPT"
23 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
27 *) error "unsupported kernel" ;;
30 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
31 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
37 TSTID2=${TSTID2:-60001}
38 TSTUSR=${TSTUSR:-"quota_usr"}
39 TSTUSR2=${TSTUSR2:-"quota_2usr"}
41 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
42 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
47 LUSTRE=${LUSTRE:-`dirname $0`/..}
48 . $LUSTRE/tests/test-framework.sh
50 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
52 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
54 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
56 require_dsh_mds || exit 0
57 require_dsh_ost || exit 0
59 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
61 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
63 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
68 QUOTA_AUTO_OLD=$QUOTA_AUTO
71 check_and_setup_lustre
73 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
74 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
76 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
77 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
78 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
79 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
80 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
81 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
82 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
83 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
85 # control the time of tests
87 [ "$SLOW" = "no" ] && cycle=10
91 # set_blk_tunables(btune_sz)
93 local btune=$(($1 * BLK_SZ))
94 # set btune size on all obdfilters
95 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
96 # set btune size on mds
97 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
100 # set_blk_unitsz(bunit_sz)
102 local bunit=$(($1 * BLK_SZ))
103 # set bunit size on all obdfilters
104 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
105 # set bunit size on mds
106 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
109 # set_file_tunesz(itune_sz)
112 # set itune size on all obdfilters
113 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_itune_sz=$itune"
114 # set itune size on mds
115 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
118 # set_file_unitsz(iunit_sz)
121 # set iunit size on all obdfilters
122 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_iunit_sz=$iunit"
123 # set iunit size on mds
124 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
130 local fail_val=${3:-0}
132 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
133 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
134 [ $((fail_loc)) -eq 0 ]; then
135 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
137 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
139 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
140 for num in `seq $OSTCOUNT`; do
141 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
142 [ $((fail_loc)) -eq 0 ]; then
143 do_facet ost$num "lctl set_param fail_val=$fail_val"
145 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
150 RUNAS="runas -u $TSTID -g $TSTID"
151 RUNAS2="runas -u $TSTID2 -g $TSTID2"
152 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
153 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
157 run_test_with_stat() {
158 (($# != 2)) && error "the number of arguments is wrong"
160 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
161 for j in `seq $OSTCOUNT`; do
162 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
165 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
166 echo "statistics info begin ***************************************"
167 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
168 for j in `seq $OSTCOUNT`; do
169 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
171 echo "statistics info end ***************************************"
176 # clear quota limits for a user or a group
177 # usage: resetquota -u username
178 # resetquota -g groupname
181 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
182 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
185 if at_is_enabled; then
186 timeout=$(at_max_get mds)
188 timeout=$(lctl get_param -n timeout)
191 while [ $((count++)) -lt $timeout ]; do
193 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
194 if [ $RC -ne 0 ]; then
195 if echo "$OUTPUT" | grep -q busy; then
196 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
200 error "resetquota failed"
206 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
213 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
214 log "Files for user ($LOCAL_ID):"
215 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
218 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
219 log "Files for group ($LOCAL_ID):"
220 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
237 # get quota info for a user or a group
238 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
244 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
245 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
258 *) error "unknown quota parameter $4";;
261 [ "$uuid" = "global" ] && uuid=$DIR
263 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }'
270 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
272 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
274 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
275 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
276 if [ -z $USAGE ]; then
277 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
279 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
283 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
284 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
285 if [ -z $USAGE ]; then
286 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
288 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
295 $LFS quotacheck -ug $DIR
297 resetquota -u $TSTUSR
298 resetquota -g $TSTUSR
300 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
304 test_quota_performance() {
305 TESTFILE="$DIR/$tdir/$tfile-0"
307 local stime=`date +%s`
308 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
309 local etime=`date +%s`
310 delta=$((etime - stime))
311 if [ $delta -gt 0 ]; then
312 rate=$((size * 1024 / delta))
313 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
318 # test basic quota performance b=21696
321 chmod 0777 $DIR/$tdir
323 [ "$SLOW" = "no" ] && MB=10
325 test_quota_performance $MB
327 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
328 test_quota_performance $MB
330 resetquota -u $TSTUSR
332 run_test_with_stat 0 "Test basic quota performance ==="
334 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
338 chmod 0777 $DIR/$tdir
339 TESTFILE="$DIR/$tdir/$tfile-0"
341 wait_delete_completed
344 log " User quota (limit: $LIMIT kbytes)"
345 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
347 quota_show_check b u $TSTUSR
349 $LFS setstripe $TESTFILE -c 1
350 chown $TSTUSR.$TSTUSR $TESTFILE
353 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
355 log " Write out of block quota ..."
356 # this time maybe cache write, ignore it's failure
357 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
358 # flush cache, ensure noquota flag is setted on client
360 $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"
364 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
365 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
366 echo $OST0_QUOTA_USED
367 [ $OST0_QUOTA_USED -ne 0 ] && \
368 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
370 resetquota -u $TSTUSR
373 log "--------------------------------------"
374 log " Group quota (limit: $LIMIT kbytes)"
375 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
377 quota_show_check b g $TSTUSR
378 TESTFILE="$DIR/$tdir/$tfile-1"
380 $LFS setstripe $TESTFILE -c 1
381 chown $TSTUSR.$TSTUSR $TESTFILE
384 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
386 log " Write out of block quota ..."
387 # this time maybe cache write, ignore it's failure
388 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
390 $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"
395 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
396 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
397 echo $OST0_QUOTA_USED
398 [ $OST0_QUOTA_USED -ne 0 ] && \
399 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
401 resetquota -g $TSTUSR
404 # block hard limit (normal use and out of quota)
406 for i in `seq 1 $cycle`; do
407 # define blk_qunit is between 1M and 4M
408 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
409 blk_qtune=$(( $RANDOM % $blk_qunit ))
410 # other osts and mds will occupy at 1M blk quota
411 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
412 set_blk_tunesz $blk_qtune
413 set_blk_unitsz $blk_qunit
414 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
416 echo "=================================================="
417 set_blk_unitsz $((128 * 1024))
418 set_blk_tunesz $((128 * 1024 / 2))
421 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
423 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
427 chmod 0777 $DIR/$tdir
428 TESTFILE="$DIR/$tdir/$tfile-0"
430 wait_delete_completed
433 log " User quota (limit: $LIMIT files)"
434 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
436 quota_show_check f u $TSTUSR
438 log " Create $LIMIT files ..."
439 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
440 quota_error u $TSTUSR "(usr) create failure, but expect success"
442 log " Create out of file quota ..."
443 $RUNAS touch ${TESTFILE}_xxx && \
444 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
446 unlinkmany ${TESTFILE} $LIMIT
447 rm -f ${TESTFILE}_xxx
450 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
451 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
453 [ $MDS_QUOTA_USED -ne 0 ] && \
454 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
456 resetquota -u $TSTUSR
459 log "--------------------------------------"
460 log " Group quota (limit: $LIMIT FILE)"
461 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
463 quota_show_check f g $TSTUSR
464 TESTFILE=$DIR/$tdir/$tfile-1
466 log " Create $LIMIT files ..."
467 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
468 quota_error g $TSTUSR "(grp) create failure, but expect success"
470 log " Create out of file quota ..."
471 $RUNAS touch ${TESTFILE}_xxx && \
472 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
474 unlinkmany ${TESTFILE} $LIMIT
475 rm -f ${TESTFILE}_xxx
478 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
479 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
481 [ $MDS_QUOTA_USED -ne 0 ] && \
482 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
484 resetquota -g $TSTUSR
487 # file hard limit (normal use and out of quota)
489 for i in `seq 1 $cycle`; do
490 if [ $i -eq 1 ]; then
495 # define ino_qunit is between 10 and 100
496 ino_qunit=$(( $RANDOM % 90 + 10 ))
497 ino_qtune=$(( $RANDOM % $ino_qunit ))
498 # RANDOM's maxium is 32767
499 i_limit=$(( $RANDOM % 990 + 10 ))
502 set_file_tunesz $ino_qtune
503 set_file_unitsz $ino_qunit
504 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
506 echo "=================================================="
511 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
515 TIMER=$(($2 * 3 / 2))
518 wait_delete_completed
520 echo " Write to exceed soft limit"
521 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
522 $RUNDD count=$((BUNIT_SZ+1)) || \
523 quota_error a $TSTUSR "write failure, but expect success"
524 OFFSET=$((OFFSET + BUNIT_SZ + 1))
529 $SHOW_QUOTA_INFO_USER
530 $SHOW_QUOTA_INFO_GROUP
532 echo " Write before timer goes off"
533 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
534 quota_error a $TSTUSR "write failure, but expect success"
535 OFFSET=$((OFFSET + BUNIT_SZ))
539 echo " Sleep $TIMER seconds ..."
544 $SHOW_QUOTA_INFO_USER
545 $SHOW_QUOTA_INFO_GROUP
547 echo " Write after timer goes off"
548 # maybe cache write, ignore.
549 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
550 OFFSET=$((OFFSET + BUNIT_SZ))
552 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
553 quota_error a $TSTUSR "write success, but expect EDQUOT"
557 $SHOW_QUOTA_INFO_USER
558 $SHOW_QUOTA_INFO_GROUP
560 echo " Unlink file to stop timer"
567 $SHOW_QUOTA_INFO_USER
568 $SHOW_QUOTA_INFO_GROUP
571 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
579 # block soft limit (start timer, timer goes off, stop timer)
582 chmod 0777 $DIR/$tdir
584 # 1 bunit on mds and 1 bunit on every ost
585 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
588 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
589 TESTFILE=$DIR/$tdir/$tfile-0
591 $LFS setstripe $TESTFILE -c 1
592 chown $TSTUSR.$TSTUSR $TESTFILE
594 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
595 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
597 test_block_soft $TESTFILE $GRACE
598 resetquota -u $TSTUSR
600 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
601 TESTFILE=$DIR/$tdir/$tfile-1
603 $LFS setstripe $TESTFILE -c 1
604 chown $TSTUSR.$TSTUSR $TESTFILE
606 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
607 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
609 test_block_soft $TESTFILE $GRACE
610 resetquota -g $TSTUSR
612 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
617 TIMER=$(($3 * 3 / 2))
619 wait_delete_completed
621 echo " Create files to exceed soft limit"
622 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
623 quota_error a $TSTUSR "create failure, but expect success"
627 echo " Create file before timer goes off"
628 $RUNAS touch ${TESTFILE}_before || \
629 quota_error a $TSTUSR "failed create before timer expired, but expect success"
633 echo " Sleep $TIMER seconds ..."
638 $SHOW_QUOTA_INFO_USER
639 $SHOW_QUOTA_INFO_GROUP
641 echo " Create file after timer goes off"
642 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
643 # inode quota left here
644 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
646 $RUNAS touch ${TESTFILE}_after3 && \
647 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
652 $SHOW_QUOTA_INFO_USER
653 $SHOW_QUOTA_INFO_GROUP
655 echo " Unlink files to stop timer"
656 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
660 $RUNAS touch ${TESTFILE}_xxx || \
661 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
666 rm -f ${TESTFILE}_xxx
670 # file soft limit (start timer, timer goes off, stop timer)
671 test_4a() { # was test_4
673 chmod 0777 $DIR/$tdir
674 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
675 TESTFILE=$DIR/$tdir/$tfile-0
679 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
680 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
681 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
682 quota_show_check f u $TSTUSR
684 test_file_soft $TESTFILE $LIMIT $GRACE
685 resetquota -u $TSTUSR
687 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
688 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
689 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
690 quota_show_check f g $TSTUSR
691 TESTFILE=$DIR/$tdir/$tfile-1
693 test_file_soft $TESTFILE $LIMIT $GRACE
694 resetquota -g $TSTUSR
697 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
698 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
700 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
702 test_4b() { # was test_4a
708 GR_STR6="1111111111111111"
710 wait_delete_completed
712 # test of valid grace strings handling
713 echo " Valid grace strings test"
714 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
715 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
716 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
717 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
719 # test of invalid grace strings handling
720 echo " Invalid grace strings test"
721 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
722 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
725 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
726 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
728 run_test_with_stat 4b "Grace time strings handling ==="
730 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
733 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
734 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
736 wait_delete_completed
738 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
739 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
740 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
741 quota_show_check a u $TSTUSR
742 quota_show_check a g $TSTUSR
744 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
745 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
746 error "touch failure, expect success"
747 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
749 echo " Chown files to $TSTUSR.$TSTUSR ..."
750 for i in `seq 0 $ILIMIT`; do
751 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
752 quota_error a $TSTUSR "chown failure, but expect success"
756 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
759 resetquota -u $TSTUSR
760 resetquota -g $TSTUSR
762 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
764 # block quota acquire & release
766 if [ $OSTCOUNT -lt 2 ]; then
767 skip_env "$OSTCOUNT < 2, too few osts"
771 wait_delete_completed
774 chmod 0777 $DIR/$tdir
776 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
777 FILEA="$DIR/$tdir/$tfile-0_a"
778 FILEB="$DIR/$tdir/$tfile-0_b"
780 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
781 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
782 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
783 quota_show_check b u $TSTUSR
784 quota_show_check b g $TSTUSR
786 echo " Create filea on OST0 and fileb on OST1"
787 $LFS setstripe $FILEA -i 0 -c 1
788 $LFS setstripe $FILEB -i 1 -c 1
789 chown $TSTUSR.$TSTUSR $FILEA
790 chown $TSTUSR.$TSTUSR $FILEB
792 echo " Exceed quota limit ..."
793 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
794 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
795 quota_error a $TSTUSR "write filea failure, but expect success"
800 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
801 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
803 echo " Write to OST1 return EDQUOT"
804 # this write maybe cache write, ignore it's failure
805 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
806 $RUNDD count=$(($BUNIT_SZ * 2)) || true
810 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
811 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
813 echo " Remove filea to let OST0 release quota"
816 if at_is_enabled; then
817 timeout=$(at_max_get mds)
819 timeout=$(lctl get_param -n timeout)
821 count=$((timeout / 5))
822 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
824 while [ $((count--)) -gt 0 ]; do
827 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
828 if [ -z $OST0_QUOTA_HOLD ]; then
829 error "System is error when query quota for block (U:$TSTUSR)."
831 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
837 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
840 while [ $((count--)) -gt 0 ]; do
843 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
844 if [ -z $OST0_QUOTA_HOLD ]; then
845 error "System is error when query quota for block (G:$TSTUSR)."
847 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
853 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
856 echo " Write to OST1"
857 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
858 quota_error a $TSTUSR "write fileb failure, expect success"
865 resetquota -u $TSTUSR
866 resetquota -g $TSTUSR
869 run_test_with_stat 6 "Block quota acquire & release ========="
871 # quota recovery (block quota only by now)
875 chmod 0777 $DIR/$tdir
877 wait_delete_completed
879 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
880 TESTFILE="$DIR/$tdir/$tfile-0"
882 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
884 $LFS setstripe $TESTFILE -c 1
885 chown $TSTUSR.$TSTUSR $TESTFILE
887 echo " Write to OST0..."
888 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
889 quota_error u $TSTUSR "write failure, but expect success"
891 #define OBD_FAIL_OBD_DQACQ 0x604
892 lustre_fail mds 0x604
893 echo " Remove files on OST0"
897 echo " Trigger recovery..."
898 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
899 for i in $OSC0_UUID; do
900 $LCTL --device $i activate || error "activate osc failed!"
903 # sleep a while to wait for recovery done
907 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
908 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
909 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
910 echo " total limits = $TOTAL_LIMIT"
912 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
913 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
914 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
915 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
916 echo " limits on $OST0_UUID = $OST0_LIMIT"
919 resetquota -u $TSTUSR
921 run_test_with_stat 7 "Quota recovery (only block limit) ======"
923 # run dbench with quota enabled
926 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
929 wait_delete_completed
931 echo " Set enough high limit for user: $TSTUSR"
932 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
933 echo " Set enough high limit for group: $TSTUSR"
934 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
936 chmod 0777 $DIR/$tdir
938 [ "$SLOW" = "no" ] && duration=" -t 120"
939 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
946 run_test_with_stat 8 "Run dbench with quota enabled ==========="
948 # run for fixing bug10707, it needs a big room. test for 64bit
950 GB=$((KB * 1024 * 1024))
951 # Use this as dd bs to decrease time
952 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
953 blksize=$((1 << 21)) # 2Mb
954 size_file=$((GB * 9 / 2))
955 # this check is just for test9 and test10
956 OST0_MIN=4900000 #4.67G
957 check_whether_skip () {
958 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
959 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
960 if [ $OST0_SIZE -lt $OST0_MIN ]; then
961 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
969 check_whether_skip && return 0
971 wait_delete_completed
977 chmod 0777 $DIR/$tdir
978 TESTFILE="$DIR/$tdir/$tfile-0"
980 BLK_LIMIT=$((100 * KB * KB)) # 100G
982 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
984 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
985 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
986 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
987 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
989 quota_show_check a u $TSTUSR
990 quota_show_check a g $TSTUSR
993 $LFS setstripe $TESTFILE -c 1
995 chown $TSTUSR.$TSTUSR $TESTFILE
997 log " Write the big file of 4.5G ..."
998 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
999 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1004 log " delete the big file of 4.5G..."
1005 $RUNAS rm -f $TESTFILE
1006 sync; sleep 3; sync;
1013 set_blk_unitsz $((128 * 1024))
1014 set_blk_tunesz $((128 * 1024 / 2))
1018 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1020 # run for fixing bug10707, it need a big room. test for 32bit
1021 # 2.0 version does not support 32 bit qd_count, so such test is obsolete.
1024 chmod 0777 $DIR/$tdir
1025 check_whether_skip && return 0
1027 wait_delete_completed
1032 # make qd_count 32 bit
1033 lustre_fail mds_ost 0xA00
1035 TESTFILE="$DIR/$tdir/$tfile-0"
1037 BLK_LIMIT=$((100 * KB * KB)) # 100G
1040 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1041 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1042 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1043 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1045 quota_show_check a u $TSTUSR
1046 quota_show_check a g $TSTUSR
1049 $LFS setstripe $TESTFILE -c 1
1051 chown $TSTUSR.$TSTUSR $TESTFILE
1053 log " Write the big file of 4.5 G ..."
1054 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1055 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1060 log " delete the big file of 4.5 G..."
1061 $RUNAS rm -f $TESTFILE
1062 sync; sleep 3; sync;
1069 # make qd_count 64 bit
1070 lustre_fail mds_ost 0
1072 set_blk_unitsz $((128 * 1024))
1073 set_blk_tunesz $((128 * 1024 / 2))
1077 #run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1079 # test a deadlock between quota and journal b=11693
1082 chmod 0777 $DIR/$tdir
1084 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1085 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1087 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1088 TESTFILE="$DIR/$tdir/$tfile-0"
1089 TESTFILE2="$DIR2/$tdir/$tfile-1"
1091 wait_delete_completed
1093 echo " User quota (limit: $LIMIT kbytes)"
1094 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1096 $LFS setstripe $TESTFILE -i 0 -c 1
1097 chown $TSTUSR.$TSTUSR $TESTFILE
1098 $LFS setstripe $TESTFILE2 -i 0 -c 1
1099 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1101 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1102 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1103 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1105 echo " step1: write out of block quota ..."
1106 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1108 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1111 echo " step2: testing ......"
1112 local last_size=$(stat -c %s $TESTFILE2)
1114 local start_secs=$SECONDS
1115 while [ -d /proc/${DDPID1} ]; do
1116 local size=$(stat -c %s $TESTFILE2)
1117 if [ $size -eq $last_size ]; then
1118 stall_secs=$[stall_secs+1]
1122 if [ $stall_secs -gt 30 ]; then
1124 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1129 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1131 #Recover fail_loc and dd will finish soon
1134 echo " step3: testing ......"
1137 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1139 if [ $count -gt 150 ]; then
1140 quota_error u $TSTUSR "dd should be finished!"
1144 echo "(dd_pid=$DDPID, time=$count)successful"
1146 rm -f $TESTFILE $TESTFILE2
1147 sync; sleep 3; sync;
1149 resetquota -u $TSTUSR
1151 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1153 # test multiple clients write block quota b=11693
1156 wait_delete_completed
1158 # one OST * 10 + (mds + other OSTs)
1159 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1160 TESTFILE="$DIR/$tdir/$tfile"
1162 echo " User quota (limit: $LIMIT kbytes)"
1163 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1164 quota_show_check b u $TSTUSR
1166 $LFS setstripe $TESTFILE -i 0 -c 1
1167 chown $TSTUSR.$TSTUSR $TESTFILE
1168 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1169 chown $TSTUSR.$TSTUSR $TESTFILE.2
1171 echo " step1: write out of block quota ..."
1172 # one bunit will give mds
1173 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1175 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1178 echo " step2: testing ......"
1181 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1183 if [ $count -gt 64 ]; then
1184 quota_error u $TSTUSR "dd should be finished!"
1188 echo "(dd_pid=$DDPID, time=$count)successful"
1192 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1194 if [ $count -gt 64 ]; then
1195 quota_error u $TSTUSR "dd should be finished!"
1199 echo "(dd_pid=$DDPID1, time=$count)successful"
1201 sync; sleep 5; sync;
1203 echo " step3: checking ......"
1204 fz=`stat -c %s $TESTFILE`
1205 fz2=`stat -c %s $TESTFILE.2`
1207 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1208 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1210 rm -f $TESTFILE $TESTFILE.2
1211 sync; sleep 3; sync;
1213 resetquota -u $TSTUSR
1215 run_test_with_stat 13 "test multiple clients write block quota ==="
1217 check_if_quota_zero(){
1218 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1219 for i in `seq 3 $line`; do
1220 if [ $i -eq 3 ]; then
1226 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1227 awk '{print $'"$j"'}'`
1228 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1229 error "quota on $2 isn't clean"
1232 echo "pass check_if_quota_zero"
1235 test_14a() { # was test_14 b=12223 -- setting quota on root
1236 TESTFILE="$DIR/$tdir/$tfile"
1240 cleanup_and_setup_lustre
1245 # out of root's file and block quota
1246 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1247 createmany -m ${TESTFILE} 20 || \
1248 quota_error u root "unexpected: user(root) create files failly!"
1249 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1250 quota_error u root "unexpected: user(root) write files failly!"
1252 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1253 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1257 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1258 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1261 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1263 #check_if_quota_zero u root
1266 unlinkmany ${TESTFILE} 15
1268 sync; sleep 3; sync;
1270 run_test_with_stat 14a "test setting quota on root ==="
1273 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1274 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1276 wait_delete_completed
1279 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1280 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1281 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1282 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1283 resetquota -u $TSTUSR
1286 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1287 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1288 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1289 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1290 resetquota -g $TSTUSR
1291 $LFS quotaoff -ug $DIR
1292 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1293 error "fail to set version for $SINGLEMDS"
1294 for j in `seq $OSTCOUNT`; do
1295 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1296 error "fail to set version for ost$j"
1299 echo "invalidating quota files"
1300 $LFS quotainv -ug $DIR
1301 $LFS quotainv -ugf $DIR
1302 $LFS quotacheck -ug $DIR
1304 run_test_with_stat 15 "set block quota more than 4T ==="
1306 # $1=u/g $2=with qunit adjust or not
1308 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1309 TESTFILE="$DIR/$tdir/$tfile"
1312 wait_delete_completed
1314 echo " User quota (limit: $LIMIT kbytes)"
1315 if [ $1 == "u" ]; then
1316 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1317 quota_show_check b u $TSTUSR
1319 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1320 quota_show_check b g $TSTUSR
1323 $LFS setstripe $TESTFILE -c 1
1324 chown $TSTUSR.$TSTUSR $TESTFILE
1327 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1328 quota_error a $TSTUSR "(usr) write failure, but expect success"
1330 echo " Write out of block quota ..."
1331 # this time maybe cache write, ignore it's failure
1332 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1333 # flush cache, ensure noquota flag is setted on client
1334 cancel_lru_locks osc
1335 if [ $2 -eq 1 ]; then
1336 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1337 quota_error a $TSTUSR "(write failure, but expect success"
1339 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1340 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1344 sync; sleep 3; sync;
1345 resetquota -$1 $TSTUSR
1348 # test without adjusting qunit
1349 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1351 set_blk_tunesz $((BUNIT_SZ * 2))
1352 set_blk_unitsz $((BUNIT_SZ * 4))
1355 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1356 echo " grp/usr: $i, adjust qunit: $j"
1357 echo "-------------------------------"
1358 [ $j -eq 1 ] && lustre_fail mds_ost 0
1359 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1363 set_blk_unitsz $((128 * 1024))
1364 set_blk_tunesz $((128 * 1024 / 2))
1366 #run_test_with_stat 16 "test without adjusting qunit"
1368 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1373 wait_delete_completed
1375 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1376 lustre_fail ost 0x80000A02
1378 TESTFILE="$DIR/$tdir/$tfile-a"
1379 TESTFILE2="$DIR/$tdir/$tfile-b"
1382 BLK_LIMIT=$((100 * 1024)) # 100M
1384 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1385 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1386 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1387 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1389 quota_show_check b u $TSTUSR
1390 quota_show_check b g $TSTUSR
1393 chown $TSTUSR.$TSTUSR $TESTFILE
1395 chown $TSTUSR.$TSTUSR $TESTFILE2
1397 log " Write the test file1 ..."
1398 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1399 || quota_error a $TSTUSR "write 10M file failure"
1404 log " write the test file2 ..."
1405 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1406 || quota_error a $TSTUSR "write 10M file failure"
1411 rm -f $TESTFILE $TESTFILE2
1413 sync; sleep 3; sync;
1415 # make qd_count 64 bit
1418 set_blk_unitsz $((128 * 1024))
1419 set_blk_tunesz $((128 * 1024 / 2))
1421 resetquota -u $TSTUSR
1422 resetquota -g $TSTUSR
1426 run_test_with_stat 17 "run for fixing bug14526 ==========="
1428 # test when mds takes a long time to handle a quota req so that
1429 # the ost has dropped it, the ost still could work well b=14840
1431 LIMIT=$((100 * 1024 * 1024)) # 100G
1432 TESTFILE="$DIR/$tdir/$tfile"
1435 wait_delete_completed
1440 log " User quota (limit: $LIMIT kbytes)"
1441 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1442 quota_show_check b u $TSTUSR
1444 $LFS setstripe $TESTFILE -i 0 -c 1
1445 chown $TSTUSR.$TSTUSR $TESTFILE
1447 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1448 lustre_fail mds 0x13c
1450 log " step1: write 100M block ..."
1451 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1457 echo " step2: testing ......"
1459 if at_is_enabled; then
1460 timeout=$(at_max_get mds)
1462 timeout=$(lctl get_param -n timeout)
1465 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1467 if [ $count -gt $((4 * $timeout)) ]; then
1468 quota_error u $TSTUSR "count=$count dd should be finished!"
1472 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1474 cancel_lru_locks mdc
1475 cancel_lru_locks osc
1477 testfile_size=$(stat -c %s $TESTFILE)
1478 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1479 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1484 resetquota -u $TSTUSR
1485 set_blk_unitsz $((128 * 1024))
1486 set_blk_tunesz $((128 * 1024 / 2))
1488 run_test_with_stat 18 "run for fixing bug14840 ==========="
1490 # test when mds drops a quota req, the ost still could work well b=14840
1492 LIMIT=$((100 * 1024 * 1024)) # 100G
1493 TESTFILE="$DIR/$tdir/$tfile-a"
1496 wait_delete_completed
1501 log " User quota (limit: $LIMIT kbytes)"
1502 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1503 quota_show_check b u $TSTUSR
1505 $LFS setstripe $TESTFILE -i 0 -c 1
1506 chown $TSTUSR.$TSTUSR $TESTFILE
1508 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1509 lustre_fail mds 0x8000013d
1511 log " step1: write 100M block ..."
1512 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1515 echo " step2: testing ......"
1517 if at_is_enabled; then
1518 timeout=$(at_max_get mds)
1520 timeout=$(lctl get_param -n timeout)
1523 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1525 if [ $count -gt $((6 * $timeout)) ]; then
1527 quota_error u $TSTUSR "count=$count dd should be finished!"
1531 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1537 resetquota -u $TSTUSR
1538 set_blk_unitsz $((128 * 1024))
1539 set_blk_tunesz $((128 * 1024 / 2))
1541 run_test_with_stat 18a "run for fixing bug14840 ==========="
1543 # test when mds do failover, the ost still could work well without trigger
1548 LIMIT=$((110 * 1024 )) # 110M
1549 TESTFILE="$DIR/$tdir/$tfile"
1552 wait_delete_completed
1557 log " User quota (limit: $LIMIT kbytes)"
1558 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1559 quota_show_check b u $TSTUSR
1561 $LFS setstripe $TESTFILE -i 0 -c 1
1562 chown $TSTUSR.$TSTUSR $TESTFILE
1564 timeout=$(sysctl -n lustre.timeout)
1566 if [ $type = "directio" ]; then
1567 log " write 100M block(directio) ..."
1568 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1570 log " write 100M block(normal) ..."
1571 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1575 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1577 log "failing mds for $((2 * timeout)) seconds"
1578 fail $SINGLEMDS $((2 * timeout))
1580 # check if quotaon successful
1581 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1582 if [ $? -eq 0 ]; then
1583 error "quotaon failed!"
1589 if at_is_enabled; then
1590 timeout=$(at_max_get mds)
1592 timeout=$(lctl get_param -n timeout)
1595 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1596 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1597 log "it took $count second"
1601 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1603 cancel_lru_locks mdc
1604 cancel_lru_locks osc
1606 testfile_size=$(stat -c %s $TESTFILE)
1607 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1608 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1613 resetquota -u $TSTUSR
1614 set_blk_unitsz $((128 * 1024))
1615 set_blk_tunesz $((128 * 1024 / 2))
1618 # test when mds does failover, the ost still could work well
1619 # this test shouldn't trigger watchdog b=14840
1621 test_18bc_sub normal
1622 test_18bc_sub directio
1623 # check if watchdog is triggered
1624 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1625 watchdog=`awk '/test 18b/ {start = 1;}
1626 /Service thread pid/ && /was inactive/ {
1630 }' $TMP/lustre-log-${TESTNAME}.log`
1631 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1632 rm -f $TMP/lustre-log-${TESTNAME}.log
1634 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1636 # test when mds does failover, the ost still could work well
1637 # this test will prevent OST_DISCONNET from happening b=14840
1639 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1640 lustre_fail ost 0x202
1641 test_18bc_sub normal
1642 test_18bc_sub directio
1645 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1647 run_to_block_limit() {
1648 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1650 wait_delete_completed
1652 # set 1 Mb quota unit size
1656 # bind file to a single OST
1657 $LFS setstripe -c 1 $TESTFILE
1658 chown $TSTUSR.$TSTUSR $TESTFILE
1660 echo " User quota (limit: $LIMIT kbytes)"
1661 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1662 quota_show_check b u $TSTUSR
1663 echo " Updating quota limits"
1664 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1665 quota_show_check b u $TSTUSR
1667 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1668 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1669 # for now page cache of TESTFILE may still be dirty,
1670 # let's push it to the corresponding OST, this will also
1671 # cache NOQUOTA on the client from OST's reply
1672 cancel_lru_locks osc
1673 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1677 # 1 Mb bunit per each MDS/OSS
1678 local TESTFILE="$DIR/$tdir/$tfile"
1681 run_to_block_limit $TESTFILE
1686 resetquota -u $TSTUSR
1688 set_blk_unitsz $((128 * 1024))
1689 set_blk_tunesz $((128 * 1024 / 2))
1692 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1696 LSTR=(1t 2g 3m 4k) # limits strings
1697 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1699 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1700 $MOUNT || error "could not set quota limits"
1702 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1703 --inode-softlimit ${LSTR[2]} \
1704 --inode-hardlimit ${LSTR[3]} \
1705 $MOUNT || error "could not set quota limits"
1707 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1708 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1709 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1710 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1712 resetquota -u $TSTUSR
1714 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1721 time=$(($(date +%s) + seconds))
1722 while [ $(date +%s) -lt $time ]; do
1723 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1728 # run for fixing bug16053, setquota shouldn't fail when writing and
1729 # deleting are happening
1734 wait_delete_completed
1736 TESTFILE="$DIR/$tdir/$tfile"
1738 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1741 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1742 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1743 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1744 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1746 # repeat writing on a 1M file
1747 test_21_sub ${TESTFILE}_1 1024 30 &
1749 # repeat writing on a 128M file
1750 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1753 time=$(($(date +%s) + 30))
1755 while [ $(date +%s) -lt $time ]; do
1756 log " Set quota for $i times"
1757 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1758 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1765 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1767 if [ $count -gt 60 ]; then
1768 quota_error a $TSTUSR "dd should be finished!"
1772 echo "(dd_pid=$DDPID1, time=$count)successful"
1776 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1778 if [ $count -gt 60 ]; then
1779 quota_error a $TSTUSR "dd should be finished!"
1783 echo "(dd_pid=$DDPID2, time=$count)successful"
1785 set_blk_unitsz $((128 * 1024))
1786 set_blk_tunesz $((128 * 1024 / 2))
1787 resetquota -u $TSTUSR
1788 resetquota -g $TSTUSR
1792 run_test_with_stat 21 "run for fixing bug16053 ==========="
1795 quota_save_version "ug3"
1801 echo "checking parameters"
1803 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1804 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1808 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1812 chmod 0777 $DIR/$tdir
1813 TESTFILE="$DIR/$tdir/$tfile-0"
1815 local bs_unit=$((1024*1024))
1818 wait_delete_completed
1821 log " User quota (limit: $LIMIT kbytes)"
1822 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1824 quota_show_check b u $TSTUSR
1826 $LFS setstripe $TESTFILE -c 1
1827 chown $TSTUSR.$TSTUSR $TESTFILE
1829 log " Step1: trigger quota with 0_DIRECT"
1830 log " Write half of file"
1831 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1832 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1833 log " Write out of block quota ..."
1834 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1835 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1838 log " Step2: rewrite should succeed"
1839 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1840 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1844 wait_delete_completed
1845 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1846 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1847 echo $OST0_QUOTA_USED
1848 [ $OST0_QUOTA_USED -ne 0 ] && \
1849 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1851 resetquota -u $TSTUSR
1855 log "run for $((OSTCOUNT * 4))MB test file"
1856 test_23_sub $((OSTCOUNT * 4 * 1024))
1859 check_whether_skip && return 0
1860 log "run for $((OSTCOUNT * 40))MB test file"
1861 test_23_sub $((OSTCOUNT * 40 * 1024))
1863 run_test_with_stat 23 "run for fixing bug16125 ==========="
1866 local TESTFILE="$DIR/$tdir/$tfile"
1869 run_to_block_limit $TESTFILE
1870 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1874 resetquota -u $TSTUSR
1876 set_blk_unitsz $((128 * 1024))
1877 set_blk_tunesz $((128 * 1024 / 2))
1880 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1883 if [ $1 = "-u" ]; then
1884 if [ $2 = "$TSTUSR" ]; then
1890 if [ $2 = "$TSTUSR" ]; then
1900 chmod 0777 $DIR/$tdir
1901 TESTFILE="$DIR/$tdir/$tfile-0"
1903 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1905 wait_delete_completed
1907 # set quota for $TSTUSR
1908 log "setquota for $TSTUSR"
1909 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1911 if [ "$1" == "-u" ]; then
1912 quota_show_check a u $TSTUSR
1914 quota_show_check a g $TSTUSR
1917 # set quota for $TSTUSR2
1918 log "setquota for $TSTUSR2"
1919 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1921 if [ "$1" == "-u" ]; then
1922 quota_show_check a u $TSTUSR2
1924 quota_show_check a g $TSTUSR2
1927 # set stripe index to 0
1928 log "setstripe for $DIR/$tdir to 0"
1929 $LFS setstripe $DIR/$tdir -c 1 -i 0
1930 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1931 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1932 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1933 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1934 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1935 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1938 log "$TSTUSR write 4M to $TESTFILE"
1939 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1941 show_quota $1 $TSTUSR
1942 show_quota $1 $TSTUSR2
1943 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1944 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1945 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1946 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1947 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1948 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1949 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1951 # chown/chgrp from $TSTUSR to $TSTUSR2
1952 if [ $1 = "-u" ]; then
1953 log "chown from $TSTUSR to $TSTUSR2"
1954 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1956 log "chgrp from $TSTUSR to $TSTUSR2"
1957 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1960 show_quota $1 $TSTUSR
1961 show_quota $1 $TSTUSR2
1962 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1963 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1964 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1965 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1966 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1967 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1968 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1969 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1970 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1971 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1972 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1973 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1974 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1975 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1976 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1979 wait_delete_completed
1980 resetquota $1 $TSTUSR
1981 resetquota $1 $TSTUSR2
1985 log "run for chown case"
1988 log "run for chgrp case"
1991 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1995 chmod 0777 $DIR/$tdir
1996 TESTFILE="$DIR/$tdir/$tfile-0"
1997 TESTFILE2="$DIR/$tdir/$tfile-1"
2001 wait_delete_completed
2003 # every quota slave gets 20MB
2004 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
2005 log "limit: ${b_limit}KB"
2006 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2008 quota_show_check b u $TSTUSR
2010 $LFS setstripe $TESTFILE -c 1 -i 0
2011 $LFS setstripe $TESTFILE2 -c 1 -i 0
2012 chown $TSTUSR.$TSTUSR $TESTFILE
2013 chown $TSTUSR.$TSTUSR $TESTFILE2
2015 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2016 lustre_fail ost 0xA03
2018 log " Write the first file..."
2019 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2020 log " Delete the first file..."
2024 wait_delete_completed
2026 log " Write the second file..."
2027 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2028 log " Delete the second file..."
2032 set_blk_unitsz $((128 * 1024))
2033 set_blk_tunesz $((128 * 1024 / 2))
2034 resetquota -u $TSTUSR
2036 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2039 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2040 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2043 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2046 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2047 error "lfs setquota failed with uid argument"
2048 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2049 error "lfs stequota failed with gid argument"
2050 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2051 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2052 resetquota -u $TSTUSR
2053 resetquota -g $TSTUSR
2056 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2059 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2060 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2061 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2064 echo "Step 2: reset system ..."
2065 cleanup_and_setup_lustre
2068 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2072 wait_delete_completed
2074 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2075 lustre_fail ost 0x80000A02
2077 TESTFILE="$DIR/$tdir/$tfile"
2080 BLK_LIMIT=$((100 * 1024)) # 100M
2081 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2082 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2086 chown $TSTUSR.$TSTUSR $TESTFILE
2088 echo "Step 5: write the test file1 [10M] ..."
2089 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2090 || quota_error a $TSTUSR "write 10M file failure"
2094 sync; sleep 3; sync;
2096 # make qd_count 64 bit
2099 set_blk_unitsz $((128 * 1024))
2100 set_blk_tunesz $((128 * 1024 / 2))
2102 resetquota -u $TSTUSR
2104 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2108 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2112 if at_is_enabled; then
2113 timeout=$(at_max_get client)
2114 at_max_set 10 client
2116 timeout=$(lctl get_param -n timeout)
2117 lctl set_param timeout=10
2120 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2121 lustre_fail mds 0x12e
2123 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2125 echo "sleeping for $((10 * 2)) seconds"
2127 ps -p $pid && error "lfs hadn't finished by timeout"
2128 wait $pid && error "succeeded, but should have failed"
2132 if at_is_enabled; then
2133 at_max_set $timeout client
2135 lctl set_param timeout=$timeout
2138 resetquota -u $TSTUSR
2140 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2146 local TESTFILE="$DIR/$tdir/$tfile"
2153 chmod 0777 $DIR/$tdir
2155 $LFS setstripe $TESTFILE -i 0 -c 1
2156 chown $TSTUSR.$TSTUSR $TESTFILE
2158 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2159 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2160 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2161 cancel_lru_locks osc
2163 $LFS setquota -u $TSTUSR -B 0 $DIR
2164 # over-quota flag has not yet settled since we do not trigger async events
2165 # based on grace time period expiration
2167 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2168 cancel_lru_locks osc
2169 # now over-quota flag should be settled and further writes should fail
2171 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2173 resetquota -u $TSTUSR
2174 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2176 set_blk_unitsz $((128 * 1024))
2177 set_blk_tunesz $((128 * 1024 / 2))
2179 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2181 # test duplicate quota releases b=18630
2184 chmod 0777 $DIR/$tdir
2186 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2187 TESTFILE="$DIR/$tdir/$tfile-0"
2188 TESTFILE2="$DIR/$tdir/$tfile-1"
2190 wait_delete_completed
2192 log " User quota (limit: $LIMIT kbytes)"
2193 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2195 $LFS setstripe $TESTFILE -i 0 -c 1
2196 chown $TSTUSR.$TSTUSR $TESTFILE
2197 $LFS setstripe $TESTFILE2 -i 0 -c 1
2198 chown $TSTUSR.$TSTUSR $TESTFILE2
2200 log " step1: write out of block quota ..."
2201 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2202 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2204 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2205 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2206 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2208 log " step2: delete two files so that triggering duplicate quota release ..."
2209 rm -f $TESTFILE $TESTFILE2
2210 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2211 wait_delete_completed
2213 log " step3: verify if the ost failed"
2214 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2215 watchdog=`awk '/test 31/ {start = 1;}
2216 /release quota error/ {
2220 }' $TMP/lustre-log-${TESTNAME}.log`
2221 [ "$watchdog" ] && error "$watchdog"
2222 rm -f $TMP/lustre-log-${TESTNAME}.log
2225 resetquota -u $TSTUSR
2227 run_test_with_stat 31 "test duplicate quota releases ==="
2233 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2237 log "cleanup: ======================================================"
2239 check_and_cleanup_lustre
2240 echo '=========================== finished ==============================='
2241 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2242 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2243 echo "$0: completed"