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 29"
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
165 for j in `seq $OSTCOUNT`; do
166 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
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 $5 }'`"
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 -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { 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 -o $OST0_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { 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
399 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 mds | awk '{print $((NF-1))}'`
400 MDS_QUOTA_USED=`$LFS quota -o $MDS_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
402 [ $MDS_QUOTA_USED -ne 0 ] && \
403 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
405 resetquota -u $TSTUSR
408 log "--------------------------------------"
409 log " Group quota (limit: $LIMIT FILE)"
410 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
412 quota_show_check f g $TSTUSR
413 TESTFILE=$DIR/$tdir/$tfile-1
415 log " Create $LIMIT files ..."
416 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
417 quota_error g $TSTUSR "(grp) create failure, but expect success"
419 log " Create out of file quota ..."
420 $RUNAS touch ${TESTFILE}_xxx && \
421 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
423 unlinkmany ${TESTFILE} $LIMIT
424 rm -f ${TESTFILE}_xxx
427 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 mds | awk '{print $((NF-1))}'`
428 MDS_QUOTA_USED=`$LFS quota -o $MDS_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
430 [ $MDS_QUOTA_USED -ne 0 ] && \
431 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
433 resetquota -g $TSTUSR
436 # file hard limit (normal use and out of quota)
438 for i in `seq 1 $cycle`; do
439 if [ $i -eq 1 ]; then
444 # define ino_qunit is between 10 and 100
445 ino_qunit=$(( $RANDOM % 90 + 10 ))
446 ino_qtune=$(( $RANDOM % $ino_qunit ))
447 # RANDOM's maxium is 32767
448 i_limit=$(( $RANDOM % 990 + 10 ))
451 set_file_tunesz $ino_qtune
452 set_file_unitsz $ino_qunit
453 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
455 echo "=================================================="
460 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
464 TIMER=$(($2 * 3 / 2))
467 wait_delete_completed
469 echo " Write to exceed soft limit"
470 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
471 $RUNDD count=$((BUNIT_SZ+1)) || \
472 quota_error a $TSTUSR "write failure, but expect success"
473 OFFSET=$((OFFSET + BUNIT_SZ + 1))
478 $SHOW_QUOTA_INFO_USER
479 $SHOW_QUOTA_INFO_GROUP
481 echo " Write before timer goes off"
482 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
483 quota_error a $TSTUSR "write failure, but expect success"
484 OFFSET=$((OFFSET + BUNIT_SZ))
488 echo " Sleep $TIMER seconds ..."
493 $SHOW_QUOTA_INFO_USER
494 $SHOW_QUOTA_INFO_GROUP
496 echo " Write after timer goes off"
497 # maybe cache write, ignore.
498 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
499 OFFSET=$((OFFSET + BUNIT_SZ))
501 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
502 quota_error a $TSTUSR "write success, but expect EDQUOT"
506 $SHOW_QUOTA_INFO_USER
507 $SHOW_QUOTA_INFO_GROUP
509 echo " Unlink file to stop timer"
516 $SHOW_QUOTA_INFO_USER
517 $SHOW_QUOTA_INFO_GROUP
520 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
528 # block soft limit (start timer, timer goes off, stop timer)
531 chmod 0777 $DIR/$tdir
533 # 1 bunit on mds and 1 bunit on every ost
534 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
537 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
538 TESTFILE=$DIR/$tdir/$tfile-0
540 $LFS setstripe $TESTFILE -c 1
541 chown $TSTUSR.$TSTUSR $TESTFILE
543 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
544 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
546 test_block_soft $TESTFILE $GRACE
547 resetquota -u $TSTUSR
549 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
550 TESTFILE=$DIR/$tdir/$tfile-1
552 $LFS setstripe $TESTFILE -c 1
553 chown $TSTUSR.$TSTUSR $TESTFILE
555 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
556 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
558 test_block_soft $TESTFILE $GRACE
559 resetquota -g $TSTUSR
561 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
566 TIMER=$(($3 * 3 / 2))
568 wait_delete_completed
570 echo " Create files to exceed soft limit"
571 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
572 quota_error a $TSTUSR "create failure, but expect success"
576 echo " Create file before timer goes off"
577 $RUNAS touch ${TESTFILE}_before || \
578 quota_error a $TSTUSR "failed create before timer expired, but expect success"
582 echo " Sleep $TIMER seconds ..."
587 $SHOW_QUOTA_INFO_USER
588 $SHOW_QUOTA_INFO_GROUP
590 echo " Create file after timer goes off"
591 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
592 # inode quota left here
593 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
595 $RUNAS touch ${TESTFILE}_after3 && \
596 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
601 $SHOW_QUOTA_INFO_USER
602 $SHOW_QUOTA_INFO_GROUP
604 echo " Unlink files to stop timer"
605 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
609 $RUNAS touch ${TESTFILE}_xxx || \
610 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
615 rm -f ${TESTFILE}_xxx
619 # file soft limit (start timer, timer goes off, stop timer)
620 test_4a() { # was test_4
622 chmod 0777 $DIR/$tdir
623 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
624 TESTFILE=$DIR/$tdir/$tfile-0
628 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
629 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
630 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
631 quota_show_check f u $TSTUSR
633 test_file_soft $TESTFILE $LIMIT $GRACE
634 resetquota -u $TSTUSR
636 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
637 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
638 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
639 quota_show_check f g $TSTUSR
640 TESTFILE=$DIR/$tdir/$tfile-1
642 test_file_soft $TESTFILE $LIMIT $GRACE
643 resetquota -g $TSTUSR
646 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
647 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
649 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
651 test_4b() { # was test_4a
657 GR_STR6="1111111111111111"
659 wait_delete_completed
661 # test of valid grace strings handling
662 echo " Valid grace strings test"
663 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
664 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
665 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
666 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
668 # test of invalid grace strings handling
669 echo " Invalid grace strings test"
670 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
671 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
674 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
675 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
677 run_test_with_stat 4b "Grace time strings handling ==="
679 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
682 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
683 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
685 wait_delete_completed
687 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
688 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
689 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
690 quota_show_check a u $TSTUSR
691 quota_show_check a g $TSTUSR
693 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
694 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
695 error "touch failure, expect success"
696 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
698 echo " Chown files to $TSTUSR.$TSTUSR ..."
699 for i in `seq 0 $ILIMIT`; do
700 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
701 quota_error a $TSTUSR "chown failure, but expect success"
705 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
708 resetquota -u $TSTUSR
709 resetquota -g $TSTUSR
711 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
713 # block quota acquire & release
715 if [ $OSTCOUNT -lt 2 ]; then
716 skip_env "$OSTCOUNT < 2, too few osts"
720 wait_delete_completed
723 chmod 0777 $DIR/$tdir
725 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
726 FILEA="$DIR/$tdir/$tfile-0_a"
727 FILEB="$DIR/$tdir/$tfile-0_b"
729 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
730 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
731 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
732 quota_show_check b u $TSTUSR
733 quota_show_check b g $TSTUSR
735 echo " Create filea on OST0 and fileb on OST1"
736 $LFS setstripe $FILEA -i 0 -c 1
737 $LFS setstripe $FILEB -i 1 -c 1
738 chown $TSTUSR.$TSTUSR $FILEA
739 chown $TSTUSR.$TSTUSR $FILEB
741 echo " Exceed quota limit ..."
742 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
743 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
744 quota_error a $TSTUSR "write filea failure, but expect success"
749 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
750 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
752 echo " Write to OST1 return EDQUOT"
753 # this write maybe cache write, ignore it's failure
754 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
755 $RUNDD count=$(($BUNIT_SZ * 2)) || true
759 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
760 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
762 echo " Remove filea to let OST0 release quota"
765 if at_is_enabled; then
766 timeout=$(at_max_get mds)
768 timeout=$(lctl get_param -n timeout)
770 count=$((timeout / 5))
771 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
773 while [ $((count--)) -gt 0 ]; do
776 OST0_QUOTA_HOLD=`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`
777 if [ -z $OST0_QUOTA_HOLD ]; then
778 error "System is error when query quota for block (U:$TSTUSR)."
780 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
786 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
789 while [ $((count--)) -gt 0 ]; do
792 OST0_QUOTA_HOLD=`$LFS quota -o $OST0_UUID -g $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`
793 if [ -z $OST0_QUOTA_HOLD ]; then
794 error "System is error when query quota for block (G:$TSTUSR)."
796 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
802 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
805 echo " Write to OST1"
806 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
807 quota_error a $TSTUSR "write fileb failure, expect success"
814 resetquota -u $TSTUSR
815 resetquota -g $TSTUSR
818 run_test_with_stat 6 "Block quota acquire & release ========="
820 # quota recovery (block quota only by now)
824 chmod 0777 $DIR/$tdir
826 wait_delete_completed
828 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
829 TESTFILE="$DIR/$tdir/$tfile-0"
831 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
833 $LFS setstripe $TESTFILE -c 1
834 chown $TSTUSR.$TSTUSR $TESTFILE
836 echo " Write to OST0..."
837 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
838 quota_error u $TSTUSR "write failure, but expect success"
840 #define OBD_FAIL_OBD_DQACQ 0x604
841 lustre_fail mds 0x604
842 echo " Remove files on OST0"
846 echo " Trigger recovery..."
847 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
848 for i in $OSC0_UUID; do
849 $LCTL --device $i activate || error "activate osc failed!"
852 # sleep a while to wait for recovery done
856 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
857 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
858 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
859 echo " total limits = $TOTAL_LIMIT"
861 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
862 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
863 OST0_LIMIT="`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $3 }'`"
864 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
865 echo " limits on $OST0_UUID = $OST0_LIMIT"
868 resetquota -u $TSTUSR
870 run_test_with_stat 7 "Quota recovery (only block limit) ======"
872 # run dbench with quota enabled
875 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
878 wait_delete_completed
880 echo " Set enough high limit for user: $TSTUSR"
881 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
882 echo " Set enough high limit for group: $TSTUSR"
883 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
885 chmod 0777 $DIR/$tdir
887 [ "$SLOW" = "no" ] && duration=" -t 120"
888 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
895 run_test_with_stat 8 "Run dbench with quota enabled ==========="
897 # run for fixing bug10707, it needs a big room. test for 64bit
899 GB=$((KB * 1024 * 1024))
900 # Use this as dd bs to decrease time
901 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
902 blksize=$((1 << 21)) # 2Mb
903 size_file=$((GB * 9 / 2))
904 # this check is just for test9 and test10
905 OST0_MIN=4900000 #4.67G
906 check_whether_skip () {
907 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
908 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
909 if [ $OST0_SIZE -lt $OST0_MIN ]; then
910 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
918 check_whether_skip && return 0
920 wait_delete_completed
926 chmod 0777 $DIR/$tdir
927 TESTFILE="$DIR/$tdir/$tfile-0"
929 BLK_LIMIT=$((100 * KB * KB)) # 100G
931 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
933 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
934 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
935 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
936 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
938 quota_show_check a u $TSTUSR
939 quota_show_check a g $TSTUSR
942 $LFS setstripe $TESTFILE -c 1
944 chown $TSTUSR.$TSTUSR $TESTFILE
946 log " Write the big file of 4.5G ..."
947 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
948 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
953 log " delete the big file of 4.5G..."
954 $RUNAS rm -f $TESTFILE
962 set_blk_unitsz $((128 * 1024))
963 set_blk_tunesz $((128 * 1024 / 2))
967 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
969 # run for fixing bug10707, it need a big room. test for 32bit
972 chmod 0777 $DIR/$tdir
973 check_whether_skip && return 0
975 wait_delete_completed
980 # make qd_count 32 bit
981 lustre_fail mds_ost 0xA00
983 TESTFILE="$DIR/$tdir/$tfile-0"
985 BLK_LIMIT=$((100 * KB * KB)) # 100G
988 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
989 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
990 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
991 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
993 quota_show_check a u $TSTUSR
994 quota_show_check a g $TSTUSR
997 $LFS setstripe $TESTFILE -c 1
999 chown $TSTUSR.$TSTUSR $TESTFILE
1001 log " Write the big file of 4.5 G ..."
1002 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1003 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1008 log " delete the big file of 4.5 G..."
1009 $RUNAS rm -f $TESTFILE
1010 sync; sleep 3; sync;
1017 # make qd_count 64 bit
1018 lustre_fail mds_ost 0
1020 set_blk_unitsz $((128 * 1024))
1021 set_blk_tunesz $((128 * 1024 / 2))
1025 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1028 wait_delete_completed
1031 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1033 orig_dbr=`sysctl -n vm.dirty_background_ratio`
1034 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1035 orig_dr=`sysctl -n vm.dirty_ratio`
1036 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1037 sysctl -w vm.dirty_background_ratio=1
1038 sysctl -w vm.dirty_expire_centisecs=30
1039 sysctl -w vm.dirty_ratio=1
1040 sysctl -w vm.dirty_writeback_centisecs=50
1041 TESTDIR="$DIR/$tdir"
1047 [ "$SLOW" = no ] && REPS=1
1050 while [ $i -le $REPS ]; do
1051 echo "test: cycle($i of $REPS) start at $(date)"
1052 mkdir -p $TESTDIR && chmod 777 $TESTDIR
1053 echo -n " create a file for uid "
1054 for j in `seq 1 30`; do
1056 # 30MB per dd for a total of 900MB (if space even permits)
1057 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
1060 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1062 while [ $PROCS -gt 0 ]; do
1064 SECS=$((SECS + sleep))
1065 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1066 USED=$(du -s $TESTDIR | awk '{print $1}')
1067 PCT=$(($USED * 100 / $block_limit))
1068 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
1069 if [ $USED -le $LAST_USED ]; then
1070 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1077 echo " removing the test files..."
1078 rm -f $TESTDIR/$tfile
1079 echo "cycle $i done at $(date)"
1082 echo "Test took $SECS sec"
1085 sysctl -w vm.dirty_background_ratio=$orig_dbr
1086 sysctl -w vm.dirty_expire_centisecs=$orig_dec
1087 sysctl -w vm.dirty_ratio=$orig_dr
1088 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1089 if [ $RV -ne 0 ]; then
1090 error "Nothing was written for $SECS sec ... aborting"
1094 run_test_with_stat 11 "run for fixing bug10912 ==========="
1097 # test a deadlock between quota and journal b=11693
1100 chmod 0777 $DIR/$tdir
1102 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1103 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1105 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1106 TESTFILE="$DIR/$tdir/$tfile-0"
1107 TESTFILE2="$DIR2/$tdir/$tfile-1"
1109 wait_delete_completed
1111 echo " User quota (limit: $LIMIT kbytes)"
1112 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1114 $LFS setstripe $TESTFILE -i 0 -c 1
1115 chown $TSTUSR.$TSTUSR $TESTFILE
1116 $LFS setstripe $TESTFILE2 -i 0 -c 1
1117 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1119 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1120 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1121 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1123 echo " step1: write out of block quota ..."
1124 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1126 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1129 echo " step2: testing ......"
1130 local last_size=$(stat -c %s $TESTFILE2)
1132 local start_secs=$SECONDS
1133 while [ -d /proc/${DDPID1} ]; do
1134 local size=$(stat -c %s $TESTFILE2)
1135 if [ $size -eq $last_size ]; then
1136 stall_secs=$[stall_secs+1]
1140 if [ $stall_secs -gt 30 ]; then
1142 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1147 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1149 #Recover fail_loc and dd will finish soon
1152 echo " step3: testing ......"
1155 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1157 if [ $count -gt 150 ]; then
1158 quota_error u $TSTUSR "dd should be finished!"
1162 echo "(dd_pid=$DDPID, time=$count)successful"
1164 rm -f $TESTFILE $TESTFILE2
1165 sync; sleep 3; sync;
1167 resetquota -u $TSTUSR
1169 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1171 # test multiple clients write block quota b=11693
1174 wait_delete_completed
1176 # one OST * 10 + (mds + other OSTs)
1177 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1178 TESTFILE="$DIR/$tdir/$tfile"
1180 echo " User quota (limit: $LIMIT kbytes)"
1181 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1182 quota_show_check b u $TSTUSR
1184 $LFS setstripe $TESTFILE -i 0 -c 1
1185 chown $TSTUSR.$TSTUSR $TESTFILE
1186 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1187 chown $TSTUSR.$TSTUSR $TESTFILE.2
1189 echo " step1: write out of block quota ..."
1190 # one bunit will give mds
1191 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1193 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1196 echo " step2: testing ......"
1199 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1201 if [ $count -gt 64 ]; then
1202 quota_error u $TSTUSR "dd should be finished!"
1206 echo "(dd_pid=$DDPID, time=$count)successful"
1210 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1212 if [ $count -gt 64 ]; then
1213 quota_error u $TSTUSR "dd should be finished!"
1217 echo "(dd_pid=$DDPID1, time=$count)successful"
1219 sync; sleep 5; sync;
1221 echo " step3: checking ......"
1222 fz=`stat -c %s $TESTFILE`
1223 fz2=`stat -c %s $TESTFILE.2`
1225 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1226 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1228 rm -f $TESTFILE $TESTFILE.2
1229 sync; sleep 3; sync;
1231 resetquota -u $TSTUSR
1233 run_test_with_stat 13 "test multiple clients write block quota ==="
1235 check_if_quota_zero(){
1236 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1237 for i in `seq 3 $line`; do
1238 if [ $i -eq 3 ]; then
1244 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1245 awk '{print $'"$j"'}'`
1246 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1247 error "quota on $2 isn't clean"
1250 echo "pass check_if_quota_zero"
1253 test_14a() { # was test_14 b=12223 -- setting quota on root
1254 TESTFILE="$DIR/$tdir/$tfile"
1258 cleanup_and_setup_lustre
1263 # out of root's file and block quota
1264 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1265 createmany -m ${TESTFILE} 20 || \
1266 quota_error u root "unexpected: user(root) create files failly!"
1267 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1268 quota_error u root "unexpected: user(root) write files failly!"
1270 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1271 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1275 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1276 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1279 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1281 #check_if_quota_zero u root
1284 unlinkmany ${TESTFILE} 15
1286 sync; sleep 3; sync;
1288 run_test_with_stat 14a "test setting quota on root ==="
1291 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1292 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1294 wait_delete_completed
1296 # force using the latest version in case 14b was omitted
1297 $LFS quotaoff -ug $DIR
1298 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1299 $LFS quotacheck -ug $DIR || error "quotacheck failed"
1302 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1303 TOTAL_LIMIT="`$LFS quota -v -u $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1304 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1305 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1306 resetquota -u $TSTUSR
1309 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1310 TOTAL_LIMIT="`$LFS quota -v -g $TSTUSR $DIR | awk '/^.*'$PATTERN'.*[[:digit:]+][[:space:]+]/ { print $4 }'`"
1311 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1312 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1314 resetquota -g $TSTUSR
1316 quota_save_version "ug1"
1318 echo "Testing that >4GB quota limits fail on volume with quota v1"
1319 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1323 run_test_with_stat 15 "set block quota more than 4T ==="
1325 # $1=u/g $2=with qunit adjust or not
1327 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1328 TESTFILE="$DIR/$tdir/$tfile"
1331 wait_delete_completed
1333 echo " User quota (limit: $LIMIT kbytes)"
1334 if [ $1 == "u" ]; then
1335 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1336 quota_show_check b u $TSTUSR
1338 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1339 quota_show_check b g $TSTUSR
1342 $LFS setstripe $TESTFILE -c 1
1343 chown $TSTUSR.$TSTUSR $TESTFILE
1346 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1347 quota_error a $TSTUSR "(usr) write failure, but expect success"
1349 echo " Write out of block quota ..."
1350 # this time maybe cache write, ignore it's failure
1351 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1352 # flush cache, ensure noquota flag is setted on client
1353 cancel_lru_locks osc
1354 if [ $2 -eq 1 ]; then
1355 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1356 quota_error a $TSTUSR "(write failure, but expect success"
1358 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1359 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1363 sync; sleep 3; sync;
1364 resetquota -$1 $TSTUSR
1367 # test without adjusting qunit
1369 set_blk_tunesz $((BUNIT_SZ * 2))
1370 set_blk_unitsz $((BUNIT_SZ * 4))
1373 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1374 echo " grp/usr: $i, adjust qunit: $j"
1375 echo "-------------------------------"
1376 [ $j -eq 1 ] && lustre_fail mds_ost 0
1377 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1381 set_blk_unitsz $((128 * 1024))
1382 set_blk_tunesz $((128 * 1024 / 2))
1384 run_test_with_stat 16 "test without adjusting qunit"
1386 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1391 wait_delete_completed
1393 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1394 lustre_fail ost 0x80000A02
1396 TESTFILE="$DIR/$tdir/$tfile-a"
1397 TESTFILE2="$DIR/$tdir/$tfile-b"
1400 BLK_LIMIT=$((100 * 1024)) # 100M
1402 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1403 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1404 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1405 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1407 quota_show_check b u $TSTUSR
1408 quota_show_check b g $TSTUSR
1411 chown $TSTUSR.$TSTUSR $TESTFILE
1413 chown $TSTUSR.$TSTUSR $TESTFILE2
1415 log " Write the test file1 ..."
1416 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1417 || quota_error a $TSTUSR "write 10M file failure"
1422 log " write the test file2 ..."
1423 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1424 || quota_error a $TSTUSR "write 10M file failure"
1429 rm -f $TESTFILE $TESTFILE2
1431 sync; sleep 3; sync;
1433 # make qd_count 64 bit
1436 set_blk_unitsz $((128 * 1024))
1437 set_blk_tunesz $((128 * 1024 / 2))
1439 resetquota -u $TSTUSR
1440 resetquota -g $TSTUSR
1444 run_test_with_stat 17 "run for fixing bug14526 ==========="
1446 # test when mds takes a long time to handle a quota req so that
1447 # the ost has dropped it, the ost still could work well b=14840
1449 LIMIT=$((100 * 1024 * 1024)) # 100G
1450 TESTFILE="$DIR/$tdir/$tfile"
1453 wait_delete_completed
1458 log " User quota (limit: $LIMIT kbytes)"
1459 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1460 quota_show_check b u $TSTUSR
1462 $LFS setstripe $TESTFILE -i 0 -c 1
1463 chown $TSTUSR.$TSTUSR $TESTFILE
1465 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1466 lustre_fail mds 0x13c
1468 log " step1: write 100M block ..."
1469 $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 $((4 * $timeout)) ]; then
1486 quota_error u $TSTUSR "count=$count dd should be finished!"
1490 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1492 cancel_lru_locks mdc
1493 cancel_lru_locks osc
1495 testfile_size=$(stat -c %s $TESTFILE)
1496 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1497 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1502 resetquota -u $TSTUSR
1503 set_blk_unitsz $((128 * 1024))
1504 set_blk_tunesz $((128 * 1024 / 2))
1506 run_test_with_stat 18 "run for fixing bug14840 ==========="
1508 # test when mds drops a quota req, the ost still could work well b=14840
1510 LIMIT=$((100 * 1024 * 1024)) # 100G
1511 TESTFILE="$DIR/$tdir/$tfile-a"
1514 wait_delete_completed
1519 log " User quota (limit: $LIMIT kbytes)"
1520 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1521 quota_show_check b u $TSTUSR
1523 $LFS setstripe $TESTFILE -i 0 -c 1
1524 chown $TSTUSR.$TSTUSR $TESTFILE
1526 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1527 lustre_fail mds 0x8000013d
1529 log " step1: write 100M block ..."
1530 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1533 echo " step2: testing ......"
1535 if at_is_enabled; then
1536 timeout=$(at_max_get mds)
1538 timeout=$(lctl get_param -n timeout)
1541 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1543 if [ $count -gt $((3 * $timeout)) ]; then
1545 quota_error u $TSTUSR "count=$count dd should be finished!"
1549 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1555 resetquota -u $TSTUSR
1556 set_blk_unitsz $((128 * 1024))
1557 set_blk_tunesz $((128 * 1024 / 2))
1559 run_test_with_stat 18a "run for fixing bug14840 ==========="
1561 # test when mds do failover, the ost still could work well without trigger
1566 LIMIT=$((110 * 1024 )) # 110M
1567 TESTFILE="$DIR/$tdir/$tfile"
1570 wait_delete_completed
1575 log " User quota (limit: $LIMIT kbytes)"
1576 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1577 quota_show_check b u $TSTUSR
1579 $LFS setstripe $TESTFILE -i 0 -c 1
1580 chown $TSTUSR.$TSTUSR $TESTFILE
1582 timeout=$(sysctl -n lustre.timeout)
1584 if [ $type = "directio" ]; then
1585 log " write 100M block(directio) ..."
1586 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1588 log " write 100M block(normal) ..."
1589 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1593 do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.mdt.quota_type=ug"
1595 log "failing mds for $((2 * timeout)) seconds"
1596 fail mds $((2 * timeout))
1598 # check if quotaon successful
1599 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1600 if [ $? -eq 0 ]; then
1601 error "quotaon failed!"
1607 if at_is_enabled; then
1608 timeout=$(at_max_get mds)
1610 timeout=$(lctl get_param -n timeout)
1613 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1614 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1615 log "it took $count second"
1619 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1621 cancel_lru_locks mdc
1622 cancel_lru_locks osc
1624 testfile_size=$(stat -c %s $TESTFILE)
1625 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1626 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1631 resetquota -u $TSTUSR
1632 set_blk_unitsz $((128 * 1024))
1633 set_blk_tunesz $((128 * 1024 / 2))
1636 # test when mds does failover, the ost still could work well
1637 # this test shouldn't trigger watchdog b=14840
1639 test_18bc_sub normal
1640 test_18bc_sub directio
1641 # check if watchdog is triggered
1642 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1643 watchdog=`awk '/test 18b/ {start = 1;}
1644 /Watchdog triggered/ {
1648 }' $TMP/lustre-log-${TESTNAME}.log`
1649 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1650 rm -f $TMP/lustre-log-${TESTNAME}.log
1652 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1654 # test when mds does failover, the ost still could work well
1655 # this test will prevent OST_DISCONNET from happening b=14840
1657 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1658 lustre_fail ost 0x202
1659 test_18bc_sub normal
1660 test_18bc_sub directio
1663 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1665 run_to_block_limit() {
1666 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1668 wait_delete_completed
1670 # set 1 Mb quota unit size
1674 # bind file to a single OST
1675 $LFS setstripe -c 1 $TESTFILE
1676 chown $TSTUSR.$TSTUSR $TESTFILE
1678 echo " User quota (limit: $LIMIT kbytes)"
1679 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1680 quota_show_check b u $TSTUSR
1681 echo " Updating quota limits"
1682 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1683 quota_show_check b u $TSTUSR
1685 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1686 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1687 # for now page cache of TESTFILE may still be dirty,
1688 # let's push it to the corresponding OST, this will also
1689 # cache NOQUOTA on the client from OST's reply
1690 cancel_lru_locks osc
1691 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1695 # 1 Mb bunit per each MDS/OSS
1696 local TESTFILE="$DIR/$tdir/$tfile"
1699 run_to_block_limit $TESTFILE
1704 resetquota -u $TSTUSR
1706 set_blk_unitsz $((128 * 1024))
1707 set_blk_tunesz $((128 * 1024 / 2))
1710 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1714 LSTR=(1t 2g 3m 4k) # limits strings
1715 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1717 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1718 $MOUNT || error "could not set quota limits"
1720 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1721 --inode-softlimit ${LSTR[2]} \
1722 --inode-hardlimit ${LSTR[3]} \
1723 $MOUNT || error "could not set quota limits"
1725 ($LFS quota -v -u $TSTUSR $MOUNT | \
1726 grep -E '^ *'$MOUNT' *[0-9]+\** *'${LVAL[0]}' *'${LVAL[1]}' *[0-9]+\** *'${LVAL[2]}' *'${LVAL[3]}) \
1727 || error "lfs quota output is unexpected"
1729 resetquota -u $TSTUSR
1731 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1738 time=$(($(date +%s) + seconds))
1739 while [ $(date +%s) -lt $time ]; do
1740 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1745 # run for fixing bug16053, setquota shouldn't fail when writing and
1746 # deleting are happening
1751 wait_delete_completed
1753 TESTFILE="$DIR/$tdir/$tfile"
1755 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1758 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1759 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1760 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1761 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1763 # repeat writing on a 1M file
1764 test_21_sub ${TESTFILE}_1 1024 30 &
1766 # repeat writing on a 128M file
1767 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1770 time=$(($(date +%s) + 30))
1772 while [ $(date +%s) -lt $time ]; do
1773 log " Set quota for $i times"
1774 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1775 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1782 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1784 if [ $count -gt 60 ]; then
1785 quota_error a $TSTUSR "dd should be finished!"
1789 echo "(dd_pid=$DDPID1, time=$count)successful"
1793 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1795 if [ $count -gt 60 ]; then
1796 quota_error a $TSTUSR "dd should be finished!"
1800 echo "(dd_pid=$DDPID2, time=$count)successful"
1802 set_blk_unitsz $((128 * 1024))
1803 set_blk_tunesz $((128 * 1024 / 2))
1804 resetquota -u $TSTUSR
1805 resetquota -g $TSTUSR
1809 run_test_with_stat 21 "run for fixing bug16053 ==========="
1812 quota_save_version "ug1"
1818 echo "checking parameters"
1820 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1821 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1823 run_test 0 "reboot lustre"
1825 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1829 chmod 0777 $DIR/$tdir
1830 TESTFILE="$DIR/$tdir/$tfile-0"
1832 local bs_unit=$((1024*1024))
1835 wait_delete_completed
1838 log " User quota (limit: $LIMIT kbytes)"
1839 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1841 quota_show_check b u $TSTUSR
1843 $LFS setstripe $TESTFILE -c 1
1844 chown $TSTUSR.$TSTUSR $TESTFILE
1846 log " Step1: trigger quota with 0_DIRECT"
1847 log " Write half of file"
1848 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1849 log " Write out of block quota ..."
1850 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1853 log " Step2: rewrite should succeed"
1854 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1858 wait_delete_completed
1859 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1860 OST0_QUOTA_USED=`$LFS quota -o $OST0_UUID -u $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1861 echo $OST0_QUOTA_USED
1862 [ $OST0_QUOTA_USED -ne 0 ] && \
1863 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1865 resetquota -u $TSTUSR
1869 log "run for $((OSTCOUNT * 3))MB test file"
1870 test_23_sub $((OSTCOUNT * 3 * 1024))
1873 check_whether_skip && return 0
1874 log "run for $((OSTCOUNT * 30))MB test file"
1875 test_23_sub $((OSTCOUNT * 30 * 1024))
1877 run_test_with_stat 23 "run for fixing bug16125 ==========="
1880 local TESTFILE="$DIR/$tdir/$tfile"
1883 run_to_block_limit $TESTFILE
1884 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1888 resetquota -u $TSTUSR
1890 set_blk_unitsz $((128 * 1024))
1891 set_blk_tunesz $((128 * 1024 / 2))
1894 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1897 if [ $1 = "-u" ]; then
1898 if [ $2 = "$TSTUSR" ]; then
1904 if [ $2 = "$TSTUSR" ]; then
1914 chmod 0777 $DIR/$tdir
1915 TESTFILE="$DIR/$tdir/$tfile-0"
1917 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1919 wait_delete_completed
1921 # set quota for $TSTUSR
1922 log "setquota for $TSTUSR"
1923 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1925 if [ "$1" == "-u" ]; then
1926 quota_show_check a u $TSTUSR
1928 quota_show_check a g $TSTUSR
1931 # set quota for $TSTUSR2
1932 log "setquota for $TSTUSR2"
1933 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1935 if [ "$1" == "-u" ]; then
1936 quota_show_check a u $TSTUSR2
1938 quota_show_check a g $TSTUSR2
1941 # set stripe index to 0
1942 log "setstripe for $DIR/$tdir to 0"
1943 $LFS setstripe $DIR/$tdir -c 1 -i 0
1944 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 mds | awk '{print $((NF-1))}'`
1945 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1946 MDS_QUOTA_USED_OLD=`$LFS quota -o $MDS_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
1947 OST0_QUOTA_USED_OLD=`$LFS quota -o $OST0_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1948 MDS_QUOTA_USED2_OLD=`$LFS quota -o $MDS_UUID $1 $TSTUSR2 $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
1949 OST0_QUOTA_USED2_OLD=`$LFS quota -o $OST0_UUID $1 $TSTUSR2 $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1952 log "$TSTUSR write 4M to $TESTFILE"
1953 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1955 show_quota $1 $TSTUSR
1956 show_quota $1 $TSTUSR2
1957 MDS_QUOTA_USED_NEW=`$LFS quota -o $MDS_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
1958 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1959 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1960 OST0_QUOTA_USED_NEW=`$LFS quota -o $OST0_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1961 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1962 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1963 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1965 # chown/chgrp from $TSTUSR to $TSTUSR2
1966 if [ $1 = "-u" ]; then
1967 log "chown from $TSTUSR to $TSTUSR2"
1968 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1970 log "chgrp from $TSTUSR to $TSTUSR2"
1971 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1974 show_quota $1 $TSTUSR
1975 show_quota $1 $TSTUSR2
1976 MDS_QUOTA_USED2_NEW=`$LFS quota -o $MDS_UUID $1 $TSTUSR2 $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
1977 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1978 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1979 OST0_QUOTA_USED2_NEW=`$LFS quota -o $OST0_UUID $1 $TSTUSR2 $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1980 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1981 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1982 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1983 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1984 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1985 MDS_QUOTA_USED_NEW=`$LFS quota -o $MDS_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $4 }'`
1986 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1987 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1988 OST0_QUOTA_USED_NEW=`$LFS quota -o $OST0_UUID $1 $TSTUSR $DIR | awk '/^.*[[:digit:]+][[:space:]+]/ { print $1 }'`
1989 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1990 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1993 wait_delete_completed
1994 resetquota $1 $TSTUSR
1995 resetquota $1 $TSTUSR2
1999 log "run for chown case"
2002 log "run for chgrp case"
2005 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
2009 chmod 0777 $DIR/$tdir
2010 TESTFILE="$DIR/$tdir/$tfile-0"
2011 TESTFILE2="$DIR/$tdir/$tfile-1"
2015 wait_delete_completed
2017 # every quota slave gets 20MB
2018 b_limit=$((OSTCOUNT * 20 * 1024))
2019 log "limit: ${b_limit}KB"
2020 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2022 quota_show_check b u $TSTUSR
2024 $LFS setstripe $TESTFILE -c 1 -i 0
2025 $LFS setstripe $TESTFILE2 -c 1 -i 0
2026 chown $TSTUSR.$TSTUSR $TESTFILE
2027 chown $TSTUSR.$TSTUSR $TESTFILE2
2029 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2030 lustre_fail ost 0xA03
2032 log " Write the first file..."
2033 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2034 log " Delete the first file..."
2038 wait_delete_completed
2040 log " Write the second file..."
2041 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2042 log " Delete the second file..."
2046 set_blk_unitsz $((128 * 1024))
2047 set_blk_tunesz $((128 * 1024 / 2))
2048 resetquota -u $TSTUSR
2050 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2053 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2054 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2057 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2060 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2061 error "lfs setquota failed with uid argument"
2062 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2063 error "lfs stequota failed with gid argument"
2064 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2065 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2066 resetquota -u $TSTUSR
2067 resetquota -g $TSTUSR
2070 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2073 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2074 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2075 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2078 echo "Step 2: reset system ..."
2079 cleanup_and_setup_lustre
2082 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2086 wait_delete_completed
2088 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2089 lustre_fail ost 0x80000A02
2091 TESTFILE="$DIR/$tdir/$tfile"
2094 BLK_LIMIT=$((100 * 1024)) # 100M
2095 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2096 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2100 chown $TSTUSR.$TSTUSR $TESTFILE
2102 echo "Step 5: write the test file1 [10M] ..."
2103 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2104 || quota_error a $TSTUSR "write 10M file failure"
2108 sync; sleep 3; sync;
2110 # make qd_count 64 bit
2113 set_blk_unitsz $((128 * 1024))
2114 set_blk_tunesz $((128 * 1024 / 2))
2116 resetquota -u $TSTUSR
2118 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2123 # flush AT history, enforce at_max immediately
2124 do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2132 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2133 local newtimeo=10 # the default ptlrpc AT value
2138 if at_is_enabled; then
2139 oldtimeo=$(at_max_get client)
2140 at_max_enforce $newtimeo
2142 oldtimeo=$(lctl get_param -n timeout)
2143 lctl set_param timeout=$newtimeo
2146 resends=$(lctl get_param -n mdc.${FSNAME}-*.quota_resend_count | head -1)
2148 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2149 lustre_fail mds 0x12e
2151 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2153 # 1.25 * at_max + 5 + net_latency
2154 echo "sleeping for $(((newtimeo * 9 / 4 + 5) * resends)) seconds"
2155 sleep $(((newtimeo * 9 / 4 + 5) * resends))
2156 ps -p $pid && error "lfs hadn't finished by timeout"
2157 wait $pid && error "succeeded, but should have failed"
2161 if at_is_enabled; then
2162 at_max_enforce $oldtimeo
2164 lctl set_param timeout=$oldtimeo
2167 resetquota -u $TSTUSR
2169 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2175 local TESTFILE="$DIR/$tdir/$tfile"
2179 chmod 0777 $DIR/$tdir
2181 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2182 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2183 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2184 cancel_lru_locks osc
2186 $LFS setquota -u $TSTUSR -B 0 $DIR
2188 output=`$SHOW_QUOTA_USER | grep $MOUNT | awk '{ print $5 }' | tr -d s`
2189 [ "$output" -le "$((GRACE - 5))" ] || error "grace times were reset or unexpectedly high latency"
2191 resetquota -u $TSTUSR
2192 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2194 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2197 # run 98 at the end because of reformatall
2204 local missing_users=""
2206 for user in $SANITY_QUOTA_USERS; do
2207 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2208 missing_users="$missing_users $user"
2210 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2215 quota_set_version 1 # set version before the first quota check
2222 for user in $SANITY_QUOTA_USERS; do
2223 $LFS setquota -u $user --block-hardlimit $((2 * num + 4 * OSTCOUNT)) $DIR || error "first phase setquota failure"
2224 $LFS setstripe -c 1 $DIR/${tfile}${num} || error "single-stripe file creation failed"
2225 chown $user $DIR/${tfile}${num} || error "chown has failed"
2226 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:w$((num * 1024))c || \
2227 error "unexpected error when writing the file for $user"
2231 $LFS quotaoff -ug $DIR
2232 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2233 $LFS quotaon -ug $DIR
2236 for user in $SANITY_QUOTA_USERS; do
2237 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w$((num * 1024))c || \
2238 error "unexpected error when appending the file for $user"
2239 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w8192c && \
2240 error "unexpected success when appending the file for $user"
2241 $LFS setquota -u $user --block-hardlimit 0 $DIR || error "second phase setquota failure"
2242 rm -rf $DIR/${tfile}${num}
2246 set_blk_unitsz $((128 * 1024))
2247 set_blk_tunesz $((128 * 1024 / 2))
2249 run_test_with_stat 98 "quotaon autoconversion ==============================="
2255 lctl set_param debug="-quota"
2259 run_test_with_stat 99 "Quota off ==============================="
2262 log "cleanup: ======================================================"
2264 check_and_cleanup_lustre
2265 echo '=========================== finished ==============================='
2266 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2267 echo "$0: completed"