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 11 $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
45 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
46 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
47 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
48 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
49 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
52 LUSTRE=${LUSTRE:-`dirname $0`/..}
53 . $LUSTRE/tests/test-framework.sh
55 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
56 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
60 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
61 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
65 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
67 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
72 check_and_setup_lustre
74 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
75 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
80 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
81 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
82 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
83 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
84 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
86 # control the time of tests
88 [ "$SLOW" = "no" ] && cycle=10
95 # set_blk_tunables(btune_sz)
97 local btune=$(($1 * BLK_SZ))
98 # set btune size on all obdfilters
99 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
100 # set btune size on mds
101 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_btune_sz=$btune"
104 # set_blk_unitsz(bunit_sz)
106 local bunit=$(($1 * BLK_SZ))
107 # set bunit size on all obdfilters
108 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
109 # set bunit size on mds
110 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_bunit_sz=$bunit"
113 # set_file_tunesz(itune_sz)
116 # set itune size on all obdfilters
117 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_itune_sz=$itune"
118 # set itune size on mds
119 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_itune_sz=$itune"
122 # set_file_unitsz(iunit_sz)
125 # set iunit size on all obdfilters
126 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_iunit_sz=$iunit"
127 # set iunit size on mds
128 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_iunit_sz=$iunit"
134 local fail_val=${3:-0}
136 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
137 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
138 [ $((fail_loc)) -eq 0 ]; then
139 do_facet mds "lctl set_param fail_val=$fail_val"
141 do_facet mds "lctl set_param fail_loc=$fail_loc"
143 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
144 for num in `seq $OSTCOUNT`; do
145 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
146 [ $((fail_loc)) -eq 0 ]; then
147 do_facet ost$num "lctl set_param fail_val=$fail_val"
149 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
154 RUNAS="runas -u $TSTID -g $TSTID"
155 RUNAS2="runas -u $TSTID2 -g $TSTID2"
156 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
157 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
161 run_test_with_stat() {
162 (($# != 2)) && error "the number of arguments is wrong"
164 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.stats=0" > /dev/null || true
165 for j in `seq $OSTCOUNT`; do
166 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null || true
169 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
170 echo "statistics info begin ***************************************"
171 do_facet mds "lctl get_param lquota.*${FSNAME}-MDT*.stats"
172 for j in `seq $OSTCOUNT`; do
173 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
175 echo "statistics info end ***************************************"
180 # clear quota limits for a user or a group
181 # usage: resetquota -u username
182 # resetquota -g groupname
185 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
186 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
189 if at_is_enabled; then
190 timeout=$(at_max_get mds)
192 timeout=$(lctl get_param -n timeout)
195 while [ $((count++)) -lt $timeout ]; do
196 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
198 if [ $RC -ne 0 ]; then
199 if [ $RC -eq 240 ]; then # 240 means -EBUSY
200 log "resetquota is blocked for quota master recovery, retry after 1 sec"
204 error "resetquota failed: $RC"
210 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
217 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
218 log "Files for user ($LOCAL_ID):"
219 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
222 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
223 log "Files for group ($LOCAL_ID):"
224 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
244 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
246 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
248 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
249 USAGE="`$LFS quota -$LOCAL_UG $LOCAL_ID $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $2 }'`"
250 if [ -z $USAGE ]; then
251 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
253 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
257 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
258 USAGE="`$LFS quota -$LOCAL_UG $LOCAL_ID $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $6 }'`"
259 if [ -z $USAGE ]; then
260 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
262 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
269 $LFS quotaoff -ug $DIR
270 $LFS quotacheck -ug $DIR
272 resetquota -u $TSTUSR
273 resetquota -g $TSTUSR
275 lctl set_param debug="+quota"
276 do_facet mds "lctl set_param debug=+quota"
277 for num in `seq $OSTCOUNT`; do
278 do_facet ost$num "lctl set_param debug=+quota"
281 run_test_with_stat 0 "Set quota ============================="
283 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
287 chmod 0777 $DIR/$tdir
288 TESTFILE="$DIR/$tdir/$tfile-0"
290 wait_delete_completed
293 log " User quota (limit: $LIMIT kbytes)"
294 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
296 quota_show_check b u $TSTUSR
298 $LFS setstripe $TESTFILE -c 1
299 chown $TSTUSR.$TSTUSR $TESTFILE
302 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
304 log " Write out of block quota ..."
305 # this time maybe cache write, ignore it's failure
306 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
307 # flush cache, ensure noquota flag is setted on client
309 $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"
313 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
314 OST0_QUOTA_USED=`$LFS quota -q -o $OST0_UUID -u $TSTUSR $DIR | awk '{ print $1 }'`
315 echo $OST0_QUOTA_USED
316 [ $OST0_QUOTA_USED -ne 0 ] && \
317 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
319 resetquota -u $TSTUSR
322 log "--------------------------------------"
323 log " Group quota (limit: $LIMIT kbytes)"
324 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
326 quota_show_check b g $TSTUSR
327 TESTFILE="$DIR/$tdir/$tfile-1"
329 $LFS setstripe $TESTFILE -c 1
330 chown $TSTUSR.$TSTUSR $TESTFILE
333 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
335 log " Write out of block quota ..."
336 # this time maybe cache write, ignore it's failure
337 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
339 $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"
344 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
345 OST0_QUOTA_USED=`$LFS quota -q -o $OST0_UUID -g $TSTUSR $DIR | awk '{ print $1 }'`
346 echo $OST0_QUOTA_USED
347 [ $OST0_QUOTA_USED -ne 0 ] && \
348 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
350 resetquota -g $TSTUSR
353 # block hard limit (normal use and out of quota)
355 for i in `seq 1 $cycle`; do
356 # define blk_qunit is between 1M and 4M
357 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
358 blk_qtune=$(( $RANDOM % $blk_qunit ))
359 # other osts and mds will occupy at 1M blk quota
360 b_limit=$(( ($RANDOM - 16384) / 8 + $OSTCOUNT * $blk_qunit * 4 ))
361 set_blk_tunesz $blk_qtune
362 set_blk_unitsz $blk_qunit
363 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
365 echo "=================================================="
366 set_blk_unitsz $((128 * 1024))
367 set_blk_tunesz $((128 * 1024 / 2))
370 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
372 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
376 chmod 0777 $DIR/$tdir
377 TESTFILE="$DIR/$tdir/$tfile-0"
379 wait_delete_completed
382 log " User quota (limit: $LIMIT files)"
383 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
385 quota_show_check f u $TSTUSR
387 log " Create $LIMIT files ..."
388 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
389 quota_error u $TSTUSR "(usr) create failure, but expect success"
391 log " Create out of file quota ..."
392 $RUNAS touch ${TESTFILE}_xxx && \
393 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
395 unlinkmany ${TESTFILE} $LIMIT
396 rm -f ${TESTFILE}_xxx
400 local dev=$(get_mds_mdt_device_proc_path)
401 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
402 MDS_QUOTA_USED=`$LFS quota -q -o $MDS_UUID -u $TSTUSR $DIR | awk '{ print $5 }'`
404 [ $MDS_QUOTA_USED -ne 0 ] && \
405 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
407 resetquota -u $TSTUSR
410 log "--------------------------------------"
411 log " Group quota (limit: $LIMIT FILE)"
412 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
414 quota_show_check f g $TSTUSR
415 TESTFILE=$DIR/$tdir/$tfile-1
417 log " Create $LIMIT files ..."
418 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
419 quota_error g $TSTUSR "(grp) create failure, but expect success"
421 log " Create out of file quota ..."
422 $RUNAS touch ${TESTFILE}_xxx && \
423 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
425 unlinkmany ${TESTFILE} $LIMIT
426 rm -f ${TESTFILE}_xxx
429 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
430 MDS_QUOTA_USED=`$LFS quota -q -o $MDS_UUID -g $TSTUSR $DIR | awk '{ print $5 }'`
432 [ $MDS_QUOTA_USED -ne 0 ] && \
433 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
435 resetquota -g $TSTUSR
438 # file hard limit (normal use and out of quota)
440 for i in `seq 1 $cycle`; do
441 if [ $i -eq 1 ]; then
446 # define ino_qunit is between 10 and 100
447 ino_qunit=$(( $RANDOM % 90 + 10 ))
448 ino_qtune=$(( $RANDOM % $ino_qunit ))
449 # RANDOM's maxium is 32767
450 i_limit=$(( $RANDOM % 990 + 10 ))
453 set_file_tunesz $ino_qtune
454 set_file_unitsz $ino_qunit
455 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
457 echo "=================================================="
462 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
466 TIMER=$(($2 * 3 / 2))
469 wait_delete_completed
471 echo " Write to exceed soft limit"
472 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
473 $RUNDD count=$((BUNIT_SZ+1)) || \
474 quota_error a $TSTUSR "write failure, but expect success"
475 OFFSET=$((OFFSET + BUNIT_SZ + 1))
480 $SHOW_QUOTA_INFO_USER
481 $SHOW_QUOTA_INFO_GROUP
483 echo " Write before timer goes off"
484 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
485 quota_error a $TSTUSR "write failure, but expect success"
486 OFFSET=$((OFFSET + BUNIT_SZ))
490 echo " Sleep $TIMER seconds ..."
495 $SHOW_QUOTA_INFO_USER
496 $SHOW_QUOTA_INFO_GROUP
498 echo " Write after timer goes off"
499 # maybe cache write, ignore.
500 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
501 OFFSET=$((OFFSET + BUNIT_SZ))
503 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
504 quota_error a $TSTUSR "write success, but expect EDQUOT"
508 $SHOW_QUOTA_INFO_USER
509 $SHOW_QUOTA_INFO_GROUP
511 echo " Unlink file to stop timer"
518 $SHOW_QUOTA_INFO_USER
519 $SHOW_QUOTA_INFO_GROUP
522 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
530 # block soft limit (start timer, timer goes off, stop timer)
533 chmod 0777 $DIR/$tdir
535 # 1 bunit on mds and 1 bunit on every ost
536 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
539 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
540 TESTFILE=$DIR/$tdir/$tfile-0
542 $LFS setstripe $TESTFILE -c 1
543 chown $TSTUSR.$TSTUSR $TESTFILE
545 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
546 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
548 test_block_soft $TESTFILE $GRACE
549 resetquota -u $TSTUSR
551 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
552 TESTFILE=$DIR/$tdir/$tfile-1
554 $LFS setstripe $TESTFILE -c 1
555 chown $TSTUSR.$TSTUSR $TESTFILE
557 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
558 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
560 test_block_soft $TESTFILE $GRACE
561 resetquota -g $TSTUSR
563 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
568 TIMER=$(($3 * 3 / 2))
570 wait_delete_completed
572 echo " Create files to exceed soft limit"
573 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
574 quota_error a $TSTUSR "create failure, but expect success"
578 echo " Create file before timer goes off"
579 $RUNAS touch ${TESTFILE}_before || \
580 quota_error a $TSTUSR "failed create before timer expired, but expect success"
584 echo " Sleep $TIMER seconds ..."
589 $SHOW_QUOTA_INFO_USER
590 $SHOW_QUOTA_INFO_GROUP
592 echo " Create file after timer goes off"
593 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
594 # inode quota left here
595 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
597 $RUNAS touch ${TESTFILE}_after3 && \
598 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
603 $SHOW_QUOTA_INFO_USER
604 $SHOW_QUOTA_INFO_GROUP
606 echo " Unlink files to stop timer"
607 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
611 $RUNAS touch ${TESTFILE}_xxx || \
612 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
617 rm -f ${TESTFILE}_xxx
621 # file soft limit (start timer, timer goes off, stop timer)
622 test_4a() { # was test_4
624 chmod 0777 $DIR/$tdir
625 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
626 TESTFILE=$DIR/$tdir/$tfile-0
630 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
631 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
632 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
633 quota_show_check f u $TSTUSR
635 test_file_soft $TESTFILE $LIMIT $GRACE
636 resetquota -u $TSTUSR
638 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
639 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
640 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
641 quota_show_check f g $TSTUSR
642 TESTFILE=$DIR/$tdir/$tfile-1
644 test_file_soft $TESTFILE $LIMIT $GRACE
645 resetquota -g $TSTUSR
648 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
649 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
651 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
653 test_4b() { # was test_4a
659 GR_STR6="1111111111111111"
661 wait_delete_completed
663 # test of valid grace strings handling
664 echo " Valid grace strings test"
665 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
666 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
667 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
668 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
670 # test of invalid grace strings handling
671 echo " Invalid grace strings test"
672 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
673 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
676 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
677 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
679 run_test_with_stat 4b "Grace time strings handling ==="
681 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
684 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
685 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
687 wait_delete_completed
689 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
690 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
691 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
692 quota_show_check a u $TSTUSR
693 quota_show_check a g $TSTUSR
695 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
696 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
697 error "touch failure, expect success"
698 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
700 echo " Chown files to $TSTUSR.$TSTUSR ..."
701 for i in `seq 0 $ILIMIT`; do
702 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
703 quota_error a $TSTUSR "chown failure, but expect success"
707 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
710 resetquota -u $TSTUSR
711 resetquota -g $TSTUSR
713 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
715 # block quota acquire & release
717 if [ $OSTCOUNT -lt 2 ]; then
718 skip_env "$OSTCOUNT < 2, too few osts"
722 wait_delete_completed
725 chmod 0777 $DIR/$tdir
727 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
728 FILEA="$DIR/$tdir/$tfile-0_a"
729 FILEB="$DIR/$tdir/$tfile-0_b"
731 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
732 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
733 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
734 quota_show_check b u $TSTUSR
735 quota_show_check b g $TSTUSR
737 echo " Create filea on OST0 and fileb on OST1"
738 $LFS setstripe $FILEA -i 0 -c 1
739 $LFS setstripe $FILEB -i 1 -c 1
740 chown $TSTUSR.$TSTUSR $FILEA
741 chown $TSTUSR.$TSTUSR $FILEB
743 echo " Exceed quota limit ..."
744 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
745 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
746 quota_error a $TSTUSR "write filea failure, but expect success"
751 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
752 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
754 echo " Write to OST1 return EDQUOT"
755 # this write maybe cache write, ignore it's failure
756 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
757 $RUNDD count=$(($BUNIT_SZ * 2)) || true
761 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
762 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
764 echo " Remove filea to let OST0 release quota"
767 if at_is_enabled; then
768 timeout=$(at_max_get mds)
770 timeout=$(lctl get_param -n timeout)
772 count=$((timeout / 5))
773 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
775 while [ $((count--)) -gt 0 ]; do
778 OST0_QUOTA_HOLD=`$LFS quota -q -o $OST0_UUID -u $TSTUSR $DIR | awk '{ print $3 }'`
779 if [ -z $OST0_QUOTA_HOLD ]; then
780 error "System is error when query quota for block (U:$TSTUSR)."
782 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
788 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
791 while [ $((count--)) -gt 0 ]; do
794 OST0_QUOTA_HOLD=`$LFS quota -q -o $OST0_UUID -g $TSTUSR $DIR | awk '{ print $3 }'`
795 if [ -z $OST0_QUOTA_HOLD ]; then
796 error "System is error when query quota for block (G:$TSTUSR)."
798 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
804 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
807 echo " Write to OST1"
808 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
809 quota_error a $TSTUSR "write fileb failure, expect success"
816 resetquota -u $TSTUSR
817 resetquota -g $TSTUSR
820 run_test_with_stat 6 "Block quota acquire & release ========="
822 # quota recovery (block quota only by now)
826 chmod 0777 $DIR/$tdir
828 wait_delete_completed
830 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
831 TESTFILE="$DIR/$tdir/$tfile-0"
833 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
835 $LFS setstripe $TESTFILE -c 1
836 chown $TSTUSR.$TSTUSR $TESTFILE
838 echo " Write to OST0..."
839 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
840 quota_error u $TSTUSR "write failure, but expect success"
842 #define OBD_FAIL_OBD_DQACQ 0x604
843 lustre_fail mds 0x604
844 echo " Remove files on OST0"
848 echo " Trigger recovery..."
849 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
850 for i in $OSC0_UUID; do
851 $LCTL --device $i activate || error "activate osc failed!"
854 # sleep a while to wait for recovery done
858 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
859 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
860 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
861 echo " total limits = $TOTAL_LIMIT"
863 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
864 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
865 OST0_LIMIT="`$LFS quota -q -o $OST0_UUID -u $TSTUSR $DIR | awk '{ print $3 }'`"
866 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
867 echo " limits on $OST0_UUID = $OST0_LIMIT"
870 resetquota -u $TSTUSR
872 run_test_with_stat 7 "Quota recovery (only block limit) ======"
874 # run dbench with quota enabled
877 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
880 wait_delete_completed
882 echo " Set enough high limit for user: $TSTUSR"
883 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
884 echo " Set enough high limit for group: $TSTUSR"
885 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
887 chmod 0777 $DIR/$tdir
889 [ "$SLOW" = "no" ] && duration=" -t 120"
890 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
897 run_test_with_stat 8 "Run dbench with quota enabled ==========="
899 # run for fixing bug10707, it needs a big room. test for 64bit
901 GB=$((KB * 1024 * 1024))
902 # Use this as dd bs to decrease time
903 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
904 blksize=$((1 << 21)) # 2Mb
905 size_file=$((GB * 9 / 2))
906 # this check is just for test9 and test10
907 OST0_MIN=4900000 #4.67G
908 check_whether_skip () {
909 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
910 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
911 if [ $OST0_SIZE -lt $OST0_MIN ]; then
912 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
920 check_whether_skip && return 0
922 wait_delete_completed
928 chmod 0777 $DIR/$tdir
929 TESTFILE="$DIR/$tdir/$tfile-0"
931 BLK_LIMIT=$((100 * KB * KB)) # 100G
933 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
935 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
936 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
937 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
938 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
940 quota_show_check a u $TSTUSR
941 quota_show_check a g $TSTUSR
944 $LFS setstripe $TESTFILE -c 1
946 chown $TSTUSR.$TSTUSR $TESTFILE
948 log " Write the big file of 4.5G ..."
949 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
950 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
955 log " delete the big file of 4.5G..."
956 $RUNAS rm -f $TESTFILE
964 set_blk_unitsz $((128 * 1024))
965 set_blk_tunesz $((128 * 1024 / 2))
969 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
971 # run for fixing bug10707, it need a big room. test for 32bit
974 chmod 0777 $DIR/$tdir
975 check_whether_skip && return 0
977 wait_delete_completed
982 # make qd_count 32 bit
983 lustre_fail mds_ost 0xA00
985 TESTFILE="$DIR/$tdir/$tfile-0"
987 BLK_LIMIT=$((100 * KB * KB)) # 100G
990 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
991 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
992 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
993 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
995 quota_show_check a u $TSTUSR
996 quota_show_check a g $TSTUSR
999 $LFS setstripe $TESTFILE -c 1
1001 chown $TSTUSR.$TSTUSR $TESTFILE
1003 log " Write the big file of 4.5 G ..."
1004 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1005 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1010 log " delete the big file of 4.5 G..."
1011 $RUNAS rm -f $TESTFILE
1012 sync; sleep 3; sync;
1019 # make qd_count 64 bit
1020 lustre_fail mds_ost 0
1022 set_blk_unitsz $((128 * 1024))
1023 set_blk_tunesz $((128 * 1024 / 2))
1027 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1030 wait_delete_completed
1033 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1035 orig_dbr=`sysctl -n vm.dirty_background_ratio`
1036 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1037 orig_dr=`sysctl -n vm.dirty_ratio`
1038 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1039 sysctl -w vm.dirty_background_ratio=1
1040 sysctl -w vm.dirty_expire_centisecs=30
1041 sysctl -w vm.dirty_ratio=1
1042 sysctl -w vm.dirty_writeback_centisecs=50
1043 TESTDIR="$DIR/$tdir"
1049 [ "$SLOW" = no ] && REPS=1
1052 while [ $i -le $REPS ]; do
1053 echo "test: cycle($i of $REPS) start at $(date)"
1054 mkdir -p $TESTDIR && chmod 777 $TESTDIR
1055 echo -n " create a file for uid "
1056 for j in `seq 1 30`; do
1058 # 30MB per dd for a total of 900MB (if space even permits)
1059 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
1062 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1064 while [ $PROCS -gt 0 ]; do
1066 SECS=$((SECS + sleep))
1067 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1068 USED=$(du -s $TESTDIR | awk '{print $1}')
1069 PCT=$(($USED * 100 / $block_limit))
1070 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
1071 if [ $USED -le $LAST_USED ]; then
1072 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1079 echo " removing the test files..."
1080 rm -f $TESTDIR/$tfile
1081 echo "cycle $i done at $(date)"
1084 echo "Test took $SECS sec"
1087 sysctl -w vm.dirty_background_ratio=$orig_dbr
1088 sysctl -w vm.dirty_expire_centisecs=$orig_dec
1089 sysctl -w vm.dirty_ratio=$orig_dr
1090 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1091 if [ $RV -ne 0 ]; then
1092 error "Nothing was written for $SECS sec ... aborting"
1096 run_test_with_stat 11 "run for fixing bug10912 ==========="
1098 # test multiple clients write block quota b=11693
1101 wait_delete_completed
1103 # one OST * 10 + (mds + other OSTs)
1104 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1105 TESTFILE="$DIR/$tdir/$tfile"
1107 echo " User quota (limit: $LIMIT kbytes)"
1108 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1109 quota_show_check b u $TSTUSR
1111 $LFS setstripe $TESTFILE -i 0 -c 1
1112 chown $TSTUSR.$TSTUSR $TESTFILE
1113 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1114 chown $TSTUSR.$TSTUSR $TESTFILE.2
1116 echo " step1: write out of block quota ..."
1117 # one bunit will give mds
1118 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1120 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1123 echo " step2: testing ......"
1126 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1128 if [ $count -gt 64 ]; then
1129 quota_error u $TSTUSR "dd should be finished!"
1133 echo "(dd_pid=$DDPID, time=$count)successful"
1137 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1139 if [ $count -gt 64 ]; then
1140 quota_error u $TSTUSR "dd should be finished!"
1144 echo "(dd_pid=$DDPID1, time=$count)successful"
1146 sync; sleep 5; sync;
1148 echo " step3: checking ......"
1149 fz=`stat -c %s $TESTFILE`
1150 fz2=`stat -c %s $TESTFILE.2`
1152 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1153 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1155 rm -f $TESTFILE $TESTFILE.2
1156 sync; sleep 3; sync;
1158 resetquota -u $TSTUSR
1160 run_test_with_stat 13 "test multiple clients write block quota ==="
1162 check_if_quota_zero(){
1163 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1164 for i in `seq 3 $line`; do
1165 if [ $i -eq 3 ]; then
1171 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1172 awk '{print $'"$j"'}'`
1173 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1174 error "quota on $2 isn't clean"
1177 echo "pass check_if_quota_zero"
1180 test_14a() { # was test_14 b=12223 -- setting quota on root
1181 TESTFILE="$DIR/$tdir/$tfile"
1185 cleanup_and_setup_lustre
1190 # out of root's file and block quota
1191 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1192 createmany -m ${TESTFILE} 20 || \
1193 quota_error u root "unexpected: user(root) create files failly!"
1194 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1195 quota_error u root "unexpected: user(root) write files failly!"
1197 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1198 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1202 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1203 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1206 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1208 #check_if_quota_zero u root
1211 unlinkmany ${TESTFILE} 15
1213 sync; sleep 3; sync;
1215 run_test_with_stat 14a "test setting quota on root ==="
1218 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1219 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1221 wait_delete_completed
1223 # force using the latest version in case 14b was omitted
1224 $LFS quotaoff -ug $DIR
1225 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1226 $LFS quotacheck -ug $DIR || error "quotacheck failed"
1229 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1230 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1231 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1232 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1233 resetquota -u $TSTUSR
1236 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1237 TOTAL_LIMIT="`$LFS quota -v -g $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1238 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1239 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1241 resetquota -g $TSTUSR
1244 local lustre_version=$(get_lustre_version mds)
1245 if [[ $lustre_version != 1.8* ]]; then
1246 echo mds running $lustre_version, skip quota v1 testing
1250 quota_save_version "ug1"
1252 echo "Testing that >4GB quota limits fail on volume with quota v1"
1253 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1257 run_test_with_stat 15 "set block quota more than 4T ==="
1259 # $1=u/g $2=with qunit adjust or not
1261 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1262 TESTFILE="$DIR/$tdir/$tfile"
1265 wait_delete_completed
1267 echo " User quota (limit: $LIMIT kbytes)"
1268 if [ $1 == "u" ]; then
1269 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1270 quota_show_check b u $TSTUSR
1272 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1273 quota_show_check b g $TSTUSR
1276 $LFS setstripe $TESTFILE -c 1
1277 chown $TSTUSR.$TSTUSR $TESTFILE
1280 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1281 quota_error a $TSTUSR "(usr) write failure, but expect success"
1283 echo " Write out of block quota ..."
1284 # this time maybe cache write, ignore it's failure
1285 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1286 # flush cache, ensure noquota flag is setted on client
1287 cancel_lru_locks osc
1288 if [ $2 -eq 1 ]; then
1289 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1290 quota_error a $TSTUSR "(write failure, but expect success"
1292 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1293 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1297 sync; sleep 3; sync;
1298 resetquota -$1 $TSTUSR
1301 # test without adjusting qunit
1304 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1305 local lustre_version=$(get_lustre_version mds)
1306 if [[ $lustre_version != 1.8* ]]; then
1307 skip mds running $lustre_version, WITHOUT_CHANGE_QS is not supported
1311 set_blk_tunesz $((BUNIT_SZ * 2))
1312 set_blk_unitsz $((BUNIT_SZ * 4))
1315 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1316 echo " grp/usr: $i, adjust qunit: $j"
1317 echo "-------------------------------"
1318 [ $j -eq 1 ] && lustre_fail mds_ost 0
1319 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1323 set_blk_unitsz $((128 * 1024))
1324 set_blk_tunesz $((128 * 1024 / 2))
1326 run_test_with_stat 16 "test without adjusting qunit"
1328 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1333 wait_delete_completed
1335 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1336 lustre_fail ost 0x80000A02
1338 TESTFILE="$DIR/$tdir/$tfile-a"
1339 TESTFILE2="$DIR/$tdir/$tfile-b"
1342 BLK_LIMIT=$((100 * 1024)) # 100M
1344 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1345 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1346 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1347 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1349 quota_show_check b u $TSTUSR
1350 quota_show_check b g $TSTUSR
1353 chown $TSTUSR.$TSTUSR $TESTFILE
1355 chown $TSTUSR.$TSTUSR $TESTFILE2
1357 log " Write the test file1 ..."
1358 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1359 || quota_error a $TSTUSR "write 10M file failure"
1364 log " write the test file2 ..."
1365 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1366 || quota_error a $TSTUSR "write 10M file failure"
1371 rm -f $TESTFILE $TESTFILE2
1373 sync; sleep 3; sync;
1375 # make qd_count 64 bit
1378 set_blk_unitsz $((128 * 1024))
1379 set_blk_tunesz $((128 * 1024 / 2))
1381 resetquota -u $TSTUSR
1382 resetquota -g $TSTUSR
1386 run_test_with_stat 17 "run for fixing bug14526 ==========="
1388 # test when mds takes a long time to handle a quota req so that
1389 # the ost has dropped it, the ost still could work well b=14840
1391 LIMIT=$((100 * 1024 * 1024)) # 100G
1392 TESTFILE="$DIR/$tdir/$tfile"
1395 wait_delete_completed
1400 log " User quota (limit: $LIMIT kbytes)"
1401 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1402 quota_show_check b u $TSTUSR
1404 $LFS setstripe $TESTFILE -i 0 -c 1
1405 chown $TSTUSR.$TSTUSR $TESTFILE
1407 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1408 lustre_fail mds 0x13c
1410 log " step1: write 100M block ..."
1411 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1417 echo " step2: testing ......"
1419 if at_is_enabled; then
1420 timeout=$(at_max_get mds)
1422 timeout=$(lctl get_param -n timeout)
1425 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1427 if [ $count -gt $((4 * $timeout)) ]; then
1428 quota_error u $TSTUSR "count=$count dd should be finished!"
1432 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1434 cancel_lru_locks mdc
1435 cancel_lru_locks osc
1437 testfile_size=$(stat -c %s $TESTFILE)
1438 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1439 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1444 resetquota -u $TSTUSR
1445 set_blk_unitsz $((128 * 1024))
1446 set_blk_tunesz $((128 * 1024 / 2))
1448 run_test_with_stat 18 "run for fixing bug14840 ==========="
1450 # test when mds drops a quota req, the ost still could work well b=14840
1452 LIMIT=$((100 * 1024 * 1024)) # 100G
1453 TESTFILE="$DIR/$tdir/$tfile-a"
1456 wait_delete_completed
1461 log " User quota (limit: $LIMIT kbytes)"
1462 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1463 quota_show_check b u $TSTUSR
1465 $LFS setstripe $TESTFILE -i 0 -c 1
1466 chown $TSTUSR.$TSTUSR $TESTFILE
1468 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1469 lustre_fail mds 0x8000013d
1471 log " step1: write 100M block ..."
1472 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1475 echo " step2: testing ......"
1477 if at_is_enabled; then
1478 timeout=$(at_max_get mds)
1480 timeout=$(lctl get_param -n timeout)
1483 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1485 if [ $count -gt $((3 * $timeout)) ]; then
1487 quota_error u $TSTUSR "count=$count dd should be finished!"
1491 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1497 resetquota -u $TSTUSR
1498 set_blk_unitsz $((128 * 1024))
1499 set_blk_tunesz $((128 * 1024 / 2))
1501 run_test_with_stat 18a "run for fixing bug14840 ==========="
1503 # test when mds do failover, the ost still could work well without trigger
1508 LIMIT=$((110 * 1024 )) # 110M
1509 TESTFILE="$DIR/$tdir/$tfile"
1512 wait_delete_completed
1517 log " User quota (limit: $LIMIT kbytes)"
1518 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1519 quota_show_check b u $TSTUSR
1521 $LFS setstripe $TESTFILE -i 0 -c 1
1522 chown $TSTUSR.$TSTUSR $TESTFILE
1524 timeout=$(sysctl -n lustre.timeout)
1526 if [ $type = "directio" ]; then
1527 log " write 100M block(directio) ..."
1528 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1530 log " write 100M block(normal) ..."
1531 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1535 do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.mdt.quota_type=ug"
1537 log "failing mds for $((2 * timeout)) seconds"
1538 fail mds $((2 * timeout))
1540 # check if quotaon successful
1541 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1542 if [ $? -eq 0 ]; then
1543 error "quotaon failed!"
1549 if at_is_enabled; then
1550 timeout=$(at_max_get mds)
1552 timeout=$(lctl get_param -n timeout)
1555 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1556 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1557 log "it took $count second"
1561 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1563 cancel_lru_locks mdc
1564 cancel_lru_locks osc
1566 testfile_size=$(stat -c %s $TESTFILE)
1567 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1568 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1573 resetquota -u $TSTUSR
1574 set_blk_unitsz $((128 * 1024))
1575 set_blk_tunesz $((128 * 1024 / 2))
1578 # test when mds does failover, the ost still could work well
1579 # this test shouldn't trigger watchdog b=14840
1581 test_18bc_sub normal
1582 test_18bc_sub directio
1583 # check if watchdog is triggered
1584 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1585 watchdog=`awk '/test 18b/ {start = 1;}
1586 /Service thread pid/ && /was inactive/{
1590 }' $TMP/lustre-log-${TESTNAME}.log`
1591 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1592 rm -f $TMP/lustre-log-${TESTNAME}.log
1594 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1596 # test when mds does failover, the ost still could work well
1597 # this test will prevent OST_DISCONNET from happening b=14840
1599 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1600 lustre_fail ost 0x202
1601 test_18bc_sub normal
1602 test_18bc_sub directio
1605 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1607 run_to_block_limit() {
1608 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1610 wait_delete_completed
1612 # set 1 Mb quota unit size
1616 # bind file to a single OST
1617 $LFS setstripe -c 1 $TESTFILE
1618 chown $TSTUSR.$TSTUSR $TESTFILE
1620 echo " User quota (limit: $LIMIT kbytes)"
1621 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1622 quota_show_check b u $TSTUSR
1623 echo " Updating quota limits"
1624 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1625 quota_show_check b u $TSTUSR
1627 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1628 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1629 # for now page cache of TESTFILE may still be dirty,
1630 # let's push it to the corresponding OST, this will also
1631 # cache NOQUOTA on the client from OST's reply
1632 cancel_lru_locks osc
1633 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1637 # 1 Mb bunit per each MDS/OSS
1638 local TESTFILE="$DIR/$tdir/$tfile"
1641 run_to_block_limit $TESTFILE
1646 resetquota -u $TSTUSR
1648 set_blk_unitsz $((128 * 1024))
1649 set_blk_tunesz $((128 * 1024 / 2))
1652 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1656 LSTR=(1t 2g 3m 4k) # limits strings
1657 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1659 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1660 $MOUNT || error "could not set quota limits"
1662 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1663 --inode-softlimit ${LSTR[2]} \
1664 --inode-hardlimit ${LSTR[3]} \
1665 $MOUNT || error "could not set quota limits"
1667 ($LFS quota -v -u $TSTUSR $MOUNT | \
1668 grep -E '^ *'$MOUNT' *[0-9]+\** *'${LVAL[0]}' *'${LVAL[1]}' *- *[0-9]+\** *'${LVAL[2]}' *'${LVAL[3]}) \
1669 || error "lfs quota output is unexpected"
1671 resetquota -u $TSTUSR
1673 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1680 time=$(($(date +%s) + seconds))
1681 while [ $(date +%s) -lt $time ]; do
1682 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1687 # run for fixing bug16053, setquota shouldn't fail when writing and
1688 # deleting are happening
1693 wait_delete_completed
1695 TESTFILE="$DIR/$tdir/$tfile"
1697 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1700 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1701 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1702 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1703 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1705 # repeat writing on a 1M file
1706 test_21_sub ${TESTFILE}_1 1024 30 &
1708 # repeat writing on a 128M file
1709 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1712 time=$(($(date +%s) + 30))
1714 while [ $(date +%s) -lt $time ]; do
1715 log " Set quota for $i times"
1716 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1717 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1724 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1726 if [ $count -gt 60 ]; then
1727 quota_error a $TSTUSR "dd should be finished!"
1731 echo "(dd_pid=$DDPID1, time=$count)successful"
1735 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1737 if [ $count -gt 60 ]; then
1738 quota_error a $TSTUSR "dd should be finished!"
1742 echo "(dd_pid=$DDPID2, time=$count)successful"
1744 set_blk_unitsz $((128 * 1024))
1745 set_blk_tunesz $((128 * 1024 / 2))
1746 resetquota -u $TSTUSR
1747 resetquota -g $TSTUSR
1751 run_test_with_stat 21 "run for fixing bug16053 ==========="
1754 local lustre_version=$(get_lustre_version mds)
1755 if [[ $lustre_version != 1.8* ]] ; then
1756 skip mds running $lustre_version, skip quota v1 testing
1759 quota_save_version "ug1"
1765 echo "checking parameters"
1767 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1768 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1770 run_test 0 "reboot lustre"
1772 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1776 chmod 0777 $DIR/$tdir
1777 TESTFILE="$DIR/$tdir/$tfile-0"
1779 local bs_unit=$((1024*1024))
1782 wait_delete_completed
1785 log " User quota (limit: $LIMIT kbytes)"
1786 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1788 quota_show_check b u $TSTUSR
1790 $LFS setstripe $TESTFILE -c 1
1791 chown $TSTUSR.$TSTUSR $TESTFILE
1793 log " Step1: trigger quota with 0_DIRECT"
1794 log " Write half of file"
1795 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1796 log " Write out of block quota ..."
1797 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1800 log " Step2: rewrite should succeed"
1801 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1805 wait_delete_completed
1806 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1807 OST0_QUOTA_USED=`$LFS quota -q -o $OST0_UUID -u $TSTUSR $DIR | awk '{ print $1 }'`
1808 echo $OST0_QUOTA_USED
1809 [ $OST0_QUOTA_USED -ne 0 ] && \
1810 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1812 resetquota -u $TSTUSR
1816 log "run for $((OSTCOUNT * 3))MB test file"
1817 test_23_sub $((OSTCOUNT * 3 * 1024))
1820 check_whether_skip && return 0
1821 log "run for $((OSTCOUNT * 30))MB test file"
1822 test_23_sub $((OSTCOUNT * 30 * 1024))
1824 run_test_with_stat 23 "run for fixing bug16125 ==========="
1827 local TESTFILE="$DIR/$tdir/$tfile"
1830 run_to_block_limit $TESTFILE
1831 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1835 resetquota -u $TSTUSR
1837 set_blk_unitsz $((128 * 1024))
1838 set_blk_tunesz $((128 * 1024 / 2))
1841 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1844 if [ $1 = "-u" ]; then
1845 if [ $2 = "$TSTUSR" ]; then
1851 if [ $2 = "$TSTUSR" ]; then
1861 chmod 0777 $DIR/$tdir
1862 TESTFILE="$DIR/$tdir/$tfile-0"
1864 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1866 wait_delete_completed
1868 # set quota for $TSTUSR
1869 log "setquota for $TSTUSR"
1870 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1872 if [ "$1" == "-u" ]; then
1873 quota_show_check a u $TSTUSR
1875 quota_show_check a g $TSTUSR
1878 # set quota for $TSTUSR2
1879 log "setquota for $TSTUSR2"
1880 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1882 if [ "$1" == "-u" ]; then
1883 quota_show_check a u $TSTUSR2
1885 quota_show_check a g $TSTUSR2
1888 # set stripe index to 0
1889 log "setstripe for $DIR/$tdir to 0"
1890 $LFS setstripe $DIR/$tdir -c 1 -i 0
1893 local dev=$(get_mds_mdt_device_proc_path)
1894 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
1895 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1896 MDS_QUOTA_USED_OLD=`$LFS quota -q -o $MDS_UUID $1 $TSTUSR $DIR | awk '{ print $5 }'`
1897 OST0_QUOTA_USED_OLD=`$LFS quota -q -o $OST0_UUID $1 $TSTUSR $DIR | awk '{ print $1 }'`
1898 MDS_QUOTA_USED2_OLD=`$LFS quota -q -o $MDS_UUID $1 $TSTUSR2 $DIR | awk '{ print $5 }'`
1899 OST0_QUOTA_USED2_OLD=`$LFS quota -q -o $OST0_UUID $1 $TSTUSR2 $DIR | awk '{ print $1 }'`
1902 log "$TSTUSR write 4M to $TESTFILE"
1903 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1905 show_quota $1 $TSTUSR
1906 show_quota $1 $TSTUSR2
1907 MDS_QUOTA_USED_NEW=`$LFS quota -q -o $MDS_UUID $1 $TSTUSR $DIR | awk '{ print $5 }'`
1908 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1909 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1910 OST0_QUOTA_USED_NEW=`$LFS quota -q -o $OST0_UUID $1 $TSTUSR $DIR | awk '{ print $1 }'`
1911 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1912 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1913 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1915 # chown/chgrp from $TSTUSR to $TSTUSR2
1916 if [ $1 = "-u" ]; then
1917 log "chown from $TSTUSR to $TSTUSR2"
1918 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1920 log "chgrp from $TSTUSR to $TSTUSR2"
1921 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1924 show_quota $1 $TSTUSR
1925 show_quota $1 $TSTUSR2
1926 MDS_QUOTA_USED2_NEW=`$LFS quota -q -o $MDS_UUID $1 $TSTUSR2 $DIR | awk '{ print $5 }'`
1927 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1928 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1929 OST0_QUOTA_USED2_NEW=`$LFS quota -q -o $OST0_UUID $1 $TSTUSR2 $DIR | awk '{ print $1 }'`
1930 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1931 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1932 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1933 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1934 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1935 MDS_QUOTA_USED_NEW=`$LFS quota -q -o $MDS_UUID $1 $TSTUSR $DIR | awk '{ print $5 }'`
1936 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1937 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1938 OST0_QUOTA_USED_NEW=`$LFS quota -q -o $OST0_UUID $1 $TSTUSR $DIR | awk '{ print $1 }'`
1939 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1940 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1943 wait_delete_completed
1944 resetquota $1 $TSTUSR
1945 resetquota $1 $TSTUSR2
1949 log "run for chown case"
1952 log "run for chgrp case"
1955 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1959 chmod 0777 $DIR/$tdir
1960 TESTFILE="$DIR/$tdir/$tfile-0"
1961 TESTFILE2="$DIR/$tdir/$tfile-1"
1965 wait_delete_completed
1967 # every quota slave gets 20MB
1968 b_limit=$((OSTCOUNT * 20 * 1024))
1969 log "limit: ${b_limit}KB"
1970 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1972 quota_show_check b u $TSTUSR
1974 $LFS setstripe $TESTFILE -c 1 -i 0
1975 $LFS setstripe $TESTFILE2 -c 1 -i 0
1976 chown $TSTUSR.$TSTUSR $TESTFILE
1977 chown $TSTUSR.$TSTUSR $TESTFILE2
1979 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1980 lustre_fail ost 0xA03
1982 log " Write the first file..."
1983 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1984 log " Delete the first file..."
1988 wait_delete_completed
1990 log " Write the second file..."
1991 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1992 log " Delete the second file..."
1996 set_blk_unitsz $((128 * 1024))
1997 set_blk_tunesz $((128 * 1024 / 2))
1998 resetquota -u $TSTUSR
2000 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2003 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2004 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2007 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2010 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2011 error "lfs setquota failed with uid argument"
2012 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2013 error "lfs stequota failed with gid argument"
2014 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2015 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2016 resetquota -u $TSTUSR
2017 resetquota -g $TSTUSR
2020 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2023 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2024 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2025 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2028 echo "Step 2: reset system ..."
2029 cleanup_and_setup_lustre
2032 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2036 wait_delete_completed
2038 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2039 lustre_fail ost 0x80000A02
2041 TESTFILE="$DIR/$tdir/$tfile"
2044 BLK_LIMIT=$((100 * 1024)) # 100M
2045 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2046 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2050 chown $TSTUSR.$TSTUSR $TESTFILE
2052 echo "Step 5: write the test file1 [10M] ..."
2053 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2054 || quota_error a $TSTUSR "write 10M file failure"
2058 sync; sleep 3; sync;
2060 # make qd_count 64 bit
2063 set_blk_unitsz $((128 * 1024))
2064 set_blk_tunesz $((128 * 1024 / 2))
2066 resetquota -u $TSTUSR
2068 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2073 # flush AT history, enforce at_max immediately
2074 do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2082 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2083 local newtimeo=10 # the default ptlrpc AT value
2087 if at_is_enabled; then
2088 oldtimeo=$(at_max_get client)
2089 at_max_enforce $newtimeo
2091 oldtimeo=$(lctl get_param -n timeout)
2092 lctl set_param timeout=$newtimeo
2095 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2096 lustre_fail mds 0x12e
2098 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2100 # 1.25 * at_max + 5 + net_latency
2101 echo "sleeping for $((newtimeo * 9 / 4 + 5)) seconds"
2102 sleep $((newtimeo * 9 / 4 + 5))
2103 ps -p $pid && error "lfs hadn't finished by timeout"
2104 wait $pid && error "succeeded, but should have failed"
2108 if at_is_enabled; then
2109 at_max_enforce $oldtimeo
2111 lctl set_param timeout=$oldtimeo
2114 resetquota -u $TSTUSR
2116 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2122 local TESTFILE="$DIR/$tdir/$tfile"
2129 chmod 0777 $DIR/$tdir
2131 $LFS setstripe $TESTFILE -i 0 -c 1
2132 chown $TSTUSR.$TSTUSR $TESTFILE
2134 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2135 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2136 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2137 cancel_lru_locks osc
2139 $LFS setquota -u $TSTUSR -B 0 $DIR
2140 # over-quota flag has not yet settled since we do not trigger async events
2141 # based on grace time period expiration
2143 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2144 cancel_lru_locks osc
2145 # now over-quota flag should be settled and further writes should fail
2147 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2149 resetquota -u $TSTUSR
2150 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2152 set_blk_unitsz $((128 * 1024))
2153 set_blk_tunesz $((128 * 1024 / 2))
2155 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2157 # test duplicate quota releases b=18630
2160 chmod 0777 $DIR/$tdir
2162 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2163 TESTFILE="$DIR/$tdir/$tfile-0"
2164 TESTFILE2="$DIR/$tdir/$tfile-1"
2166 wait_delete_completed
2168 log " User quota (limit: $LIMIT kbytes)"
2169 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2171 $LFS setstripe $TESTFILE -i 0 -c 1
2172 chown $TSTUSR.$TSTUSR $TESTFILE
2173 $LFS setstripe $TESTFILE2 -i 0 -c 1
2174 chown $TSTUSR.$TSTUSR $TESTFILE2
2176 log " step1: write out of block quota ..."
2177 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2178 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2180 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2181 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2182 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2184 log " step2: delete two files so that triggering duplicate quota release ..."
2185 rm -f $TESTFILE $TESTFILE2
2186 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2187 wait_delete_completed
2189 log " step3: verify if the ost failed"
2190 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2191 watchdog=`awk '/test 31/ {start = 1;}
2192 /release quota error/ {
2196 }' $TMP/lustre-log-${TESTNAME}.log`
2197 [ "$watchdog" ] && error "$watchdog"
2198 rm -f $TMP/lustre-log-${TESTNAME}.log
2201 resetquota -u $TSTUSR
2203 run_test_with_stat 31 "test duplicate quota releases ==="
2206 # run 98 at the end because of reformatall
2213 local missing_users=""
2215 for user in $SANITY_QUOTA_USERS; do
2216 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" || \
2217 missing_users="$missing_users $user"
2219 [ -n "$missing_users" ] && { skip_env "different uid-s on client and servers, or missing users: $missing_users" ; return 0 ; }
2224 quota_set_version 1 # set version before the first quota check
2231 for user in $SANITY_QUOTA_USERS; do
2232 $LFS setquota -u $user --block-hardlimit $((2 * num + 4 * OSTCOUNT)) $DIR || error "first phase setquota failure"
2233 $LFS setstripe -c 1 $DIR/${tfile}${num} || error "single-stripe file creation failed"
2234 chown $user $DIR/${tfile}${num} || error "chown has failed"
2235 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:w$((num * 1024))c || \
2236 error "unexpected error when writing the file for $user"
2240 $LFS quotaoff -ug $DIR
2241 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2242 $LFS quotaon -ug $DIR
2245 for user in $SANITY_QUOTA_USERS; do
2246 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w$((num * 1024))c || \
2247 error "unexpected error when appending the file for $user"
2248 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w8192c && \
2249 error "unexpected success when appending the file for $user"
2250 $LFS setquota -u $user --block-hardlimit 0 $DIR || error "second phase setquota failure"
2251 rm -rf $DIR/${tfile}${num}
2255 set_blk_unitsz $((128 * 1024))
2256 set_blk_tunesz $((128 * 1024 / 2))
2258 run_test_with_stat 98 "quotaon autoconversion ==============================="
2264 lctl set_param debug="-quota"
2268 run_test_with_stat 99 "Quota off ==============================="
2271 log "cleanup: ======================================================"
2273 check_and_cleanup_lustre
2274 echo '=========================== finished ==============================='
2275 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2276 echo "$0: completed"