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_nodes $(comma_list $(osts_nodes)) "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_nodes $(comma_list $(osts_nodes)) "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 mds
117 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_itune_sz=$itune"
120 # set_file_unitsz(iunit_sz)
123 # set iunit size on mds
124 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_iunit_sz=$iunit"
130 local fail_val=${3:-0}
132 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
133 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
134 [ $((fail_loc)) -eq 0 ]; then
135 do_facet mds "lctl set_param fail_val=$fail_val"
137 do_facet mds "lctl set_param fail_loc=$fail_loc"
139 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
140 for num in `seq $OSTCOUNT`; do
141 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
142 [ $((fail_loc)) -eq 0 ]; then
143 do_facet ost$num "lctl set_param fail_val=$fail_val"
145 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
150 RUNAS="runas -u $TSTID -g $TSTID"
151 RUNAS2="runas -u $TSTID2 -g $TSTID2"
152 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
153 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
157 run_test_with_stat() {
158 (($# != 2)) && error "the number of arguments is wrong"
160 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.stats=0" > /dev/null || true
161 for j in `seq $OSTCOUNT`; do
162 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null || true
165 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
166 echo "statistics info begin ***************************************"
167 do_facet mds "lctl get_param lquota.*${FSNAME}-MDT*.stats"
168 for j in `seq $OSTCOUNT`; do
169 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
171 echo "statistics info end ***************************************"
176 # clear quota limits for a user or a group
177 # usage: resetquota -u username
178 # resetquota -g groupname
181 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
182 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
185 if at_is_enabled; then
186 timeout=$(at_max_get mds)
188 timeout=$(lctl get_param -n timeout)
191 while [ $((count++)) -lt $timeout ]; do
192 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
194 if [ $RC -ne 0 ]; then
195 if [ $RC -eq 240 ]; then # 240 means -EBUSY
196 log "resetquota is blocked for quota master recovery, retry after 1 sec"
200 error "resetquota failed: $RC"
206 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
213 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
214 log "Files for user ($LOCAL_ID):"
215 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
218 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
219 log "Files for group ($LOCAL_ID):"
220 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
237 # get quota info for a user or a group
238 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
244 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
245 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
258 *) error "unknown quota parameter $4";;
261 [ "$uuid" = "global" ] && uuid=$DIR
263 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }'
270 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
272 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
274 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
275 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
276 if [ -z $USAGE ]; then
277 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
279 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
283 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
284 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
285 if [ -z $USAGE ]; then
286 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
288 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
295 lctl set_param debug="+quota"
296 do_facet mds "lctl set_param debug=+quota"
297 for num in `seq $OSTCOUNT`; do
298 do_facet ost$num "lctl set_param debug=+quota"
301 log "do the quotacheck ..."
302 $LFS quotacheck -ug $DIR
304 resetquota -u $TSTUSR
305 resetquota -g $TSTUSR
307 run_test_with_stat 0 "Set quota ============================="
309 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
313 chmod 0777 $DIR/$tdir
314 TESTFILE="$DIR/$tdir/$tfile-0"
316 wait_delete_completed
319 log " User quota (limit: $LIMIT kbytes)"
320 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
322 quota_show_check b u $TSTUSR
324 $LFS setstripe $TESTFILE -c 1
325 chown $TSTUSR.$TSTUSR $TESTFILE
328 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
330 log " Write out of block quota ..."
331 # this time maybe cache write, ignore it's failure
332 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
333 # flush cache, ensure noquota flag is setted on client
335 $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"
339 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
340 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
341 echo $OST0_QUOTA_USED
342 [ $OST0_QUOTA_USED -ne 0 ] && \
343 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
345 resetquota -u $TSTUSR
348 log "--------------------------------------"
349 log " Group quota (limit: $LIMIT kbytes)"
350 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
352 quota_show_check b g $TSTUSR
353 TESTFILE="$DIR/$tdir/$tfile-1"
355 $LFS setstripe $TESTFILE -c 1
356 chown $TSTUSR.$TSTUSR $TESTFILE
359 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
361 log " Write out of block quota ..."
362 # this time maybe cache write, ignore it's failure
363 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
365 $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"
370 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
371 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
372 echo $OST0_QUOTA_USED
373 [ $OST0_QUOTA_USED -ne 0 ] && \
374 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
376 resetquota -g $TSTUSR
379 # block hard limit (normal use and out of quota)
381 for i in `seq 1 $cycle`; do
382 # define blk_qunit is between 1M and 4M
383 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
384 blk_qtune=$(( $RANDOM % $blk_qunit ))
385 # other osts and mds will occupy at 1M blk quota
386 b_limit=$(( ($RANDOM - 16384) / 8 + $OSTCOUNT * $blk_qunit * 4 ))
387 set_blk_tunesz $blk_qtune
388 set_blk_unitsz $blk_qunit
389 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
391 echo "=================================================="
392 set_blk_unitsz $((128 * 1024))
393 set_blk_tunesz $((128 * 1024 / 2))
396 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
398 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
402 chmod 0777 $DIR/$tdir
403 TESTFILE="$DIR/$tdir/$tfile-0"
405 wait_delete_completed
408 log " User quota (limit: $LIMIT files)"
409 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
411 quota_show_check f u $TSTUSR
413 log " Create $LIMIT files ..."
414 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
415 quota_error u $TSTUSR "(usr) create failure, but expect success"
417 log " Create out of file quota ..."
418 $RUNAS touch ${TESTFILE}_xxx && \
419 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
421 unlinkmany ${TESTFILE} $LIMIT
422 rm -f ${TESTFILE}_xxx
426 local dev=$(get_mds_mdt_device_proc_path)
427 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
428 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
431 [ $MDS_QUOTA_USED -ne 0 ] && \
432 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
434 resetquota -u $TSTUSR
437 log "--------------------------------------"
438 log " Group quota (limit: $LIMIT FILE)"
439 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
441 quota_show_check f g $TSTUSR
442 TESTFILE=$DIR/$tdir/$tfile-1
444 log " Create $LIMIT files ..."
445 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
446 quota_error g $TSTUSR "(grp) create failure, but expect success"
448 log " Create out of file quota ..."
449 $RUNAS touch ${TESTFILE}_xxx && \
450 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
452 unlinkmany ${TESTFILE} $LIMIT
453 rm -f ${TESTFILE}_xxx
456 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
457 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
460 [ $MDS_QUOTA_USED -ne 0 ] && \
461 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
463 resetquota -g $TSTUSR
466 # file hard limit (normal use and out of quota)
468 for i in `seq 1 $cycle`; do
469 if [ $i -eq 1 ]; then
474 # define ino_qunit is between 10 and 100
475 ino_qunit=$(( $RANDOM % 90 + 10 ))
476 ino_qtune=$(( $RANDOM % $ino_qunit ))
477 # RANDOM's maxium is 32767
478 i_limit=$(( $RANDOM % 990 + 10 ))
481 set_file_tunesz $ino_qtune
482 set_file_unitsz $ino_qunit
483 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
485 echo "=================================================="
490 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
494 TIMER=$(($2 * 3 / 2))
497 wait_delete_completed
499 echo " Write to exceed soft limit"
500 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
501 $RUNDD count=$((BUNIT_SZ+1)) || \
502 quota_error a $TSTUSR "write failure, but expect success"
503 OFFSET=$((OFFSET + BUNIT_SZ + 1))
508 $SHOW_QUOTA_INFO_USER
509 $SHOW_QUOTA_INFO_GROUP
511 echo " Write before timer goes off"
512 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
513 quota_error a $TSTUSR "write failure, but expect success"
514 OFFSET=$((OFFSET + BUNIT_SZ))
518 echo " Sleep $TIMER seconds ..."
523 $SHOW_QUOTA_INFO_USER
524 $SHOW_QUOTA_INFO_GROUP
526 echo " Write after timer goes off"
527 # maybe cache write, ignore.
528 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
529 OFFSET=$((OFFSET + BUNIT_SZ))
531 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
532 quota_error a $TSTUSR "write success, but expect EDQUOT"
536 $SHOW_QUOTA_INFO_USER
537 $SHOW_QUOTA_INFO_GROUP
539 echo " Unlink file to stop timer"
546 $SHOW_QUOTA_INFO_USER
547 $SHOW_QUOTA_INFO_GROUP
550 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
558 # block soft limit (start timer, timer goes off, stop timer)
561 chmod 0777 $DIR/$tdir
563 # 1 bunit on mds and 1 bunit on every ost
564 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
567 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
568 TESTFILE=$DIR/$tdir/$tfile-0
570 $LFS setstripe $TESTFILE -c 1
571 chown $TSTUSR.$TSTUSR $TESTFILE
573 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
574 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
576 test_block_soft $TESTFILE $GRACE
577 resetquota -u $TSTUSR
579 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
580 TESTFILE=$DIR/$tdir/$tfile-1
582 $LFS setstripe $TESTFILE -c 1
583 chown $TSTUSR.$TSTUSR $TESTFILE
585 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
586 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
588 test_block_soft $TESTFILE $GRACE
589 resetquota -g $TSTUSR
591 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
596 TIMER=$(($3 * 3 / 2))
598 wait_delete_completed
600 echo " Create files to exceed soft limit"
601 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
602 quota_error a $TSTUSR "create failure, but expect success"
606 echo " Create file before timer goes off"
607 $RUNAS touch ${TESTFILE}_before || \
608 quota_error a $TSTUSR "failed create before timer expired, but expect success"
612 echo " Sleep $TIMER seconds ..."
617 $SHOW_QUOTA_INFO_USER
618 $SHOW_QUOTA_INFO_GROUP
620 echo " Create file after timer goes off"
621 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
622 # inode quota left here
623 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
625 $RUNAS touch ${TESTFILE}_after3 && \
626 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
631 $SHOW_QUOTA_INFO_USER
632 $SHOW_QUOTA_INFO_GROUP
634 echo " Unlink files to stop timer"
635 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
639 $RUNAS touch ${TESTFILE}_xxx || \
640 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
645 rm -f ${TESTFILE}_xxx
649 # file soft limit (start timer, timer goes off, stop timer)
650 test_4a() { # was test_4
652 chmod 0777 $DIR/$tdir
653 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
654 TESTFILE=$DIR/$tdir/$tfile-0
658 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
659 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
660 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
661 quota_show_check f u $TSTUSR
663 test_file_soft $TESTFILE $LIMIT $GRACE
664 resetquota -u $TSTUSR
666 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
667 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
668 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
669 quota_show_check f g $TSTUSR
670 TESTFILE=$DIR/$tdir/$tfile-1
672 test_file_soft $TESTFILE $LIMIT $GRACE
673 resetquota -g $TSTUSR
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 4a "File soft limit (start timer, timer goes off, stop timer) ==="
681 test_4b() { # was test_4a
687 GR_STR6="1111111111111111"
689 wait_delete_completed
691 # test of valid grace strings handling
692 echo " Valid grace strings test"
693 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
694 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
695 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
696 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
698 # test of invalid grace strings handling
699 echo " Invalid grace strings test"
700 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
701 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
704 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
705 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
707 run_test_with_stat 4b "Grace time strings handling ==="
709 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
712 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
713 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
715 wait_delete_completed
717 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
718 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
719 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
720 quota_show_check a u $TSTUSR
721 quota_show_check a g $TSTUSR
723 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
724 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
725 error "touch failure, expect success"
726 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
728 echo " Chown files to $TSTUSR.$TSTUSR ..."
729 for i in `seq 0 $ILIMIT`; do
730 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
731 quota_error a $TSTUSR "chown failure, but expect success"
735 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
738 resetquota -u $TSTUSR
739 resetquota -g $TSTUSR
741 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
743 # block quota acquire & release
745 if [ $OSTCOUNT -lt 2 ]; then
746 skip_env "$OSTCOUNT < 2, too few osts"
750 wait_delete_completed
753 chmod 0777 $DIR/$tdir
755 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
756 FILEA="$DIR/$tdir/$tfile-0_a"
757 FILEB="$DIR/$tdir/$tfile-0_b"
759 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
760 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
761 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
762 quota_show_check b u $TSTUSR
763 quota_show_check b g $TSTUSR
765 echo " Create filea on OST0 and fileb on OST1"
766 $LFS setstripe $FILEA -i 0 -c 1
767 $LFS setstripe $FILEB -i 1 -c 1
768 chown $TSTUSR.$TSTUSR $FILEA
769 chown $TSTUSR.$TSTUSR $FILEB
771 echo " Exceed quota limit ..."
772 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
773 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
774 quota_error a $TSTUSR "write filea failure, but expect success"
779 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
780 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
782 echo " Write to OST1 return EDQUOT"
783 # this write maybe cache write, ignore it's failure
784 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
785 $RUNDD count=$(($BUNIT_SZ * 2)) || true
789 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
790 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
792 echo " Remove filea to let OST0 release quota"
795 if at_is_enabled; then
796 timeout=$(at_max_get mds)
798 timeout=$(lctl get_param -n timeout)
800 count=$((timeout / 5))
801 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
803 while [ $((count--)) -gt 0 ]; do
806 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
807 if [ -z $OST0_QUOTA_HOLD ]; then
808 error "System is error when query quota for block (U:$TSTUSR)."
810 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
816 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
819 while [ $((count--)) -gt 0 ]; do
822 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
823 if [ -z $OST0_QUOTA_HOLD ]; then
824 error "System is error when query quota for block (G:$TSTUSR)."
826 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
832 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
835 echo " Write to OST1"
836 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
837 quota_error a $TSTUSR "write fileb failure, expect success"
844 resetquota -u $TSTUSR
845 resetquota -g $TSTUSR
848 run_test_with_stat 6 "Block quota acquire & release ========="
850 # quota recovery (block quota only by now)
854 chmod 0777 $DIR/$tdir
856 wait_delete_completed
858 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
859 TESTFILE="$DIR/$tdir/$tfile-0"
861 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
863 $LFS setstripe $TESTFILE -c 1
864 chown $TSTUSR.$TSTUSR $TESTFILE
866 echo " Write to OST0..."
867 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
868 quota_error u $TSTUSR "write failure, but expect success"
870 #define OBD_FAIL_OBD_DQACQ 0x604
871 lustre_fail mds 0x604
872 echo " Remove files on OST0"
876 echo " Trigger recovery..."
877 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
878 for i in $OSC0_UUID; do
879 $LCTL --device $i activate || error "activate osc failed!"
882 # sleep a while to wait for recovery done
886 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
887 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
888 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
889 echo " total limits = $TOTAL_LIMIT"
891 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
892 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
893 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
894 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
895 echo " limits on $OST0_UUID = $OST0_LIMIT"
898 resetquota -u $TSTUSR
900 run_test_with_stat 7 "Quota recovery (only block limit) ======"
902 # run dbench with quota enabled
905 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
908 wait_delete_completed
910 echo " Set enough high limit for user: $TSTUSR"
911 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
912 echo " Set enough high limit for group: $TSTUSR"
913 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
915 chmod 0777 $DIR/$tdir
917 [ "$SLOW" = "no" ] && duration=" -t 120"
918 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
925 run_test_with_stat 8 "Run dbench with quota enabled ==========="
927 # run for fixing bug10707, it needs a big room. test for 64bit
929 GB=$((KB * 1024 * 1024))
930 # Use this as dd bs to decrease time
931 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
932 blksize=$((1 << 21)) # 2Mb
933 size_file=$((GB * 9 / 2))
934 # this check is just for test9 and test10
935 OST0_MIN=4900000 #4.67G
936 check_whether_skip () {
937 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
938 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
939 if [ $OST0_SIZE -lt $OST0_MIN ]; then
940 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
948 check_whether_skip && return 0
950 wait_delete_completed
956 chmod 0777 $DIR/$tdir
957 TESTFILE="$DIR/$tdir/$tfile-0"
959 BLK_LIMIT=$((100 * KB * KB)) # 100G
961 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
963 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
964 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
965 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
966 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
968 quota_show_check a u $TSTUSR
969 quota_show_check a g $TSTUSR
972 $LFS setstripe $TESTFILE -c 1
974 chown $TSTUSR.$TSTUSR $TESTFILE
976 log " Write the big file of 4.5G ..."
977 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
978 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
983 log " delete the big file of 4.5G..."
984 $RUNAS rm -f $TESTFILE
992 set_blk_unitsz $((128 * 1024))
993 set_blk_tunesz $((128 * 1024 / 2))
997 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
999 # run for fixing bug10707, it need a big room. test for 32bit
1002 chmod 0777 $DIR/$tdir
1003 check_whether_skip && return 0
1005 wait_delete_completed
1010 # make qd_count 32 bit
1011 lustre_fail mds_ost 0xA00
1013 TESTFILE="$DIR/$tdir/$tfile-0"
1015 BLK_LIMIT=$((100 * KB * KB)) # 100G
1018 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1019 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1020 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1021 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1023 quota_show_check a u $TSTUSR
1024 quota_show_check a g $TSTUSR
1027 $LFS setstripe $TESTFILE -c 1
1029 chown $TSTUSR.$TSTUSR $TESTFILE
1031 log " Write the big file of 4.5 G ..."
1032 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1033 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1038 log " delete the big file of 4.5 G..."
1039 $RUNAS rm -f $TESTFILE
1040 sync; sleep 3; sync;
1047 # make qd_count 64 bit
1048 lustre_fail mds_ost 0
1050 set_blk_unitsz $((128 * 1024))
1051 set_blk_tunesz $((128 * 1024 / 2))
1055 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1058 wait_delete_completed
1061 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1063 orig_dbr=`sysctl -n vm.dirty_background_ratio`
1064 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1065 orig_dr=`sysctl -n vm.dirty_ratio`
1066 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1067 sysctl -w vm.dirty_background_ratio=1
1068 sysctl -w vm.dirty_expire_centisecs=30
1069 sysctl -w vm.dirty_ratio=1
1070 sysctl -w vm.dirty_writeback_centisecs=50
1071 TESTDIR="$DIR/$tdir"
1077 [ "$SLOW" = no ] && REPS=1
1080 while [ $i -le $REPS ]; do
1081 echo "test: cycle($i of $REPS) start at $(date)"
1082 mkdir -p $TESTDIR && chmod 777 $TESTDIR
1083 echo -n " create a file for uid "
1084 for j in `seq 1 30`; do
1086 # 30MB per dd for a total of 900MB (if space even permits)
1087 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
1090 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1092 while [ $PROCS -gt 0 ]; do
1094 SECS=$((SECS + sleep))
1095 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1096 USED=$(du -s $TESTDIR | awk '{print $1}')
1097 PCT=$(($USED * 100 / $block_limit))
1098 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
1099 if [ $USED -le $LAST_USED ]; then
1100 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1107 echo " removing the test files..."
1108 rm -f $TESTDIR/$tfile
1109 echo "cycle $i done at $(date)"
1112 echo "Test took $SECS sec"
1115 sysctl -w vm.dirty_background_ratio=$orig_dbr
1116 sysctl -w vm.dirty_expire_centisecs=$orig_dec
1117 sysctl -w vm.dirty_ratio=$orig_dr
1118 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1119 if [ $RV -ne 0 ]; then
1120 error "Nothing was written for $SECS sec ... aborting"
1124 run_test_with_stat 11 "run for fixing bug10912 ==========="
1126 # test multiple clients write block quota b=11693
1129 wait_delete_completed
1131 # one OST * 10 + (mds + other OSTs)
1132 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1133 TESTFILE="$DIR/$tdir/$tfile"
1135 echo " User quota (limit: $LIMIT kbytes)"
1136 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1137 quota_show_check b u $TSTUSR
1139 $LFS setstripe $TESTFILE -i 0 -c 1
1140 chown $TSTUSR.$TSTUSR $TESTFILE
1141 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1142 chown $TSTUSR.$TSTUSR $TESTFILE.2
1144 echo " step1: write out of block quota ..."
1145 # one bunit will give mds
1146 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1148 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1151 echo " step2: testing ......"
1154 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1156 if [ $count -gt 64 ]; then
1157 quota_error u $TSTUSR "dd should be finished!"
1161 echo "(dd_pid=$DDPID, time=$count)successful"
1165 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1167 if [ $count -gt 64 ]; then
1168 quota_error u $TSTUSR "dd should be finished!"
1172 echo "(dd_pid=$DDPID1, time=$count)successful"
1174 sync; sleep 5; sync;
1176 echo " step3: checking ......"
1177 fz=`stat -c %s $TESTFILE`
1178 fz2=`stat -c %s $TESTFILE.2`
1180 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1181 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1183 rm -f $TESTFILE $TESTFILE.2
1184 sync; sleep 3; sync;
1186 resetquota -u $TSTUSR
1188 run_test_with_stat 13 "test multiple clients write block quota ==="
1190 check_if_quota_zero(){
1191 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1192 for i in `seq 3 $line`; do
1193 if [ $i -eq 3 ]; then
1199 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1200 awk '{print $'"$j"'}'`
1201 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1202 error "quota on $2 isn't clean"
1205 echo "pass check_if_quota_zero"
1208 test_14a() { # was test_14 b=12223 -- setting quota on root
1209 TESTFILE="$DIR/$tdir/$tfile"
1213 cleanup_and_setup_lustre
1218 # out of root's file and block quota
1219 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1220 createmany -m ${TESTFILE} 20 || \
1221 quota_error u root "unexpected: user(root) create files failly!"
1222 multiop ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1223 quota_error u root "unexpected: user(root) write files failly!"
1225 $RUNAS multiop ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1226 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1230 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1231 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1234 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1236 #check_if_quota_zero u root
1239 unlinkmany ${TESTFILE} 15
1241 sync; sleep 3; sync;
1243 run_test_with_stat 14a "test setting quota on root ==="
1246 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1247 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1249 wait_delete_completed
1251 # force using the latest version in case 14b was omitted
1252 $LFS quotaoff -ug $DIR
1253 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1254 $LFS quotacheck -ug $DIR || error "quotacheck failed"
1257 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1258 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1259 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1260 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1261 resetquota -u $TSTUSR
1264 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1265 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1266 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1267 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1269 resetquota -g $TSTUSR
1272 local lustre_version=$(get_lustre_version mds)
1273 if [[ $lustre_version != 1.8* ]]; then
1274 echo mds running $lustre_version, skip quota v1 testing
1278 quota_save_version "ug1"
1280 echo "Testing that >4GB quota limits fail on volume with quota v1"
1281 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1285 run_test_with_stat 15 "set block quota more than 4T ==="
1287 # $1=u/g $2=with qunit adjust or not
1289 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1290 TESTFILE="$DIR/$tdir/$tfile"
1293 wait_delete_completed
1295 echo " User quota (limit: $LIMIT kbytes)"
1296 if [ $1 == "u" ]; then
1297 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1298 quota_show_check b u $TSTUSR
1300 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1301 quota_show_check b g $TSTUSR
1304 $LFS setstripe $TESTFILE -c 1
1305 chown $TSTUSR.$TSTUSR $TESTFILE
1308 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1309 quota_error a $TSTUSR "(usr) write failure, but expect success"
1311 echo " Write out of block quota ..."
1312 # this time maybe cache write, ignore it's failure
1313 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1314 # flush cache, ensure noquota flag is setted on client
1315 cancel_lru_locks osc
1316 if [ $2 -eq 1 ]; then
1317 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1318 quota_error a $TSTUSR "(write failure, but expect success"
1320 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1321 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1325 sync; sleep 3; sync;
1326 resetquota -$1 $TSTUSR
1329 # test without adjusting qunit
1332 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1333 local lustre_version=$(get_lustre_version mds)
1334 if [[ $lustre_version != 1.8* ]]; then
1335 skip mds running $lustre_version, WITHOUT_CHANGE_QS is not supported
1339 set_blk_tunesz $((BUNIT_SZ * 2))
1340 set_blk_unitsz $((BUNIT_SZ * 4))
1343 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1344 echo " grp/usr: $i, adjust qunit: $j"
1345 echo "-------------------------------"
1346 [ $j -eq 1 ] && lustre_fail mds_ost 0
1347 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1351 set_blk_unitsz $((128 * 1024))
1352 set_blk_tunesz $((128 * 1024 / 2))
1354 run_test_with_stat 16 "test without adjusting qunit"
1356 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1361 wait_delete_completed
1363 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1364 lustre_fail ost 0x80000A02
1366 TESTFILE="$DIR/$tdir/$tfile-a"
1367 TESTFILE2="$DIR/$tdir/$tfile-b"
1370 BLK_LIMIT=$((100 * 1024)) # 100M
1372 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1373 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1374 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1375 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1377 quota_show_check b u $TSTUSR
1378 quota_show_check b g $TSTUSR
1381 chown $TSTUSR.$TSTUSR $TESTFILE
1383 chown $TSTUSR.$TSTUSR $TESTFILE2
1385 log " Write the test file1 ..."
1386 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1387 || quota_error a $TSTUSR "write 10M file failure"
1392 log " write the test file2 ..."
1393 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1394 || quota_error a $TSTUSR "write 10M file failure"
1399 rm -f $TESTFILE $TESTFILE2
1401 sync; sleep 3; sync;
1403 # make qd_count 64 bit
1406 set_blk_unitsz $((128 * 1024))
1407 set_blk_tunesz $((128 * 1024 / 2))
1409 resetquota -u $TSTUSR
1410 resetquota -g $TSTUSR
1414 run_test_with_stat 17 "run for fixing bug14526 ==========="
1416 # test when mds takes a long time to handle a quota req so that
1417 # the ost has dropped it, the ost still could work well b=14840
1419 LIMIT=$((100 * 1024 * 1024)) # 100G
1420 TESTFILE="$DIR/$tdir/$tfile"
1423 wait_delete_completed
1428 log " User quota (limit: $LIMIT kbytes)"
1429 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1430 quota_show_check b u $TSTUSR
1432 $LFS setstripe $TESTFILE -i 0 -c 1
1433 chown $TSTUSR.$TSTUSR $TESTFILE
1435 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1436 lustre_fail mds 0x13c
1438 log " step1: write 100M block ..."
1439 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1445 echo " step2: testing ......"
1447 if at_is_enabled; then
1448 timeout=$(at_max_get mds)
1450 timeout=$(lctl get_param -n timeout)
1453 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1455 if [ $count -gt $((4 * $timeout)) ]; then
1456 quota_error u $TSTUSR "count=$count dd should be finished!"
1460 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1462 cancel_lru_locks mdc
1463 cancel_lru_locks osc
1465 testfile_size=$(stat -c %s $TESTFILE)
1466 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1467 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1472 resetquota -u $TSTUSR
1473 set_blk_unitsz $((128 * 1024))
1474 set_blk_tunesz $((128 * 1024 / 2))
1476 run_test_with_stat 18 "run for fixing bug14840 ==========="
1478 # test when mds drops a quota req, the ost still could work well b=14840
1480 LIMIT=$((100 * 1024 * 1024)) # 100G
1481 TESTFILE="$DIR/$tdir/$tfile-a"
1484 wait_delete_completed
1489 log " User quota (limit: $LIMIT kbytes)"
1490 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1491 quota_show_check b u $TSTUSR
1493 $LFS setstripe $TESTFILE -i 0 -c 1
1494 chown $TSTUSR.$TSTUSR $TESTFILE
1496 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1497 lustre_fail mds 0x8000013d
1499 log " step1: write 100M block ..."
1500 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1503 echo " step2: testing ......"
1505 if at_is_enabled; then
1506 timeout=$(at_max_get mds)
1508 timeout=$(lctl get_param -n timeout)
1511 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1513 if [ $count -gt $((3 * $timeout)) ]; then
1515 quota_error u $TSTUSR "count=$count dd should be finished!"
1519 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1525 resetquota -u $TSTUSR
1526 set_blk_unitsz $((128 * 1024))
1527 set_blk_tunesz $((128 * 1024 / 2))
1529 run_test_with_stat 18a "run for fixing bug14840 ==========="
1531 # test when mds do failover, the ost still could work well without trigger
1536 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1537 TESTFILE="$DIR/$tdir/$tfile"
1540 wait_delete_completed
1545 log " User quota (limit: $LIMIT kbytes)"
1546 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1547 quota_show_check b u $TSTUSR
1549 $LFS setstripe $TESTFILE -i 0 -c 1
1550 chown $TSTUSR.$TSTUSR $TESTFILE
1552 timeout=$(sysctl -n lustre.timeout)
1554 if [ $type = "directio" ]; then
1555 log " write 100M block(directio) ..."
1556 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1558 log " write 100M block(normal) ..."
1559 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1563 do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=ug"
1567 log "failing mds for $((2 * timeout)) seconds"
1568 fail mds $((2 * timeout))
1570 # check if quotaon successful
1571 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1572 if [ $? -eq 0 ]; then
1574 error "quotaon failed!"
1579 if at_is_enabled; then
1580 timeout=$(at_max_get mds)
1582 timeout=$(lctl get_param -n timeout)
1585 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1586 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1587 log "it took $count second"
1591 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1593 cancel_lru_locks mdc
1594 cancel_lru_locks osc
1597 resetquota -u $TSTUSR
1598 set_blk_unitsz $((128 * 1024))
1599 set_blk_tunesz $((128 * 1024 / 2))
1600 testfile_size=$(stat -c %s $TESTFILE)
1601 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1603 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1608 # test when mds does failover, the ost still could work well
1609 # this test shouldn't trigger watchdog b=14840
1611 test_18bc_sub normal
1612 test_18bc_sub directio
1613 # check if watchdog is triggered
1614 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1615 watchdog=`awk '/test 18b/ {start = 1;}
1616 /Service thread pid/ && /was inactive/{
1620 }' $TMP/lustre-log-${TESTNAME}.log`
1621 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1622 rm -f $TMP/lustre-log-${TESTNAME}.log
1624 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1626 # test when mds does failover, the ost still could work well
1627 # this test will prevent OST_DISCONNET from happening b=14840
1629 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1630 lustre_fail ost 0x202
1631 test_18bc_sub normal
1632 test_18bc_sub directio
1635 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1637 run_to_block_limit() {
1638 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1640 wait_delete_completed
1642 # set 1 Mb quota unit size
1646 # bind file to a single OST
1647 $LFS setstripe -c 1 $TESTFILE
1648 chown $TSTUSR.$TSTUSR $TESTFILE
1650 echo " User quota (limit: $LIMIT kbytes)"
1651 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1652 quota_show_check b u $TSTUSR
1653 echo " Updating quota limits"
1654 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1655 quota_show_check b u $TSTUSR
1657 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1658 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1659 # for now page cache of TESTFILE may still be dirty,
1660 # let's push it to the corresponding OST, this will also
1661 # cache NOQUOTA on the client from OST's reply
1662 cancel_lru_locks osc
1663 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1667 # 1 Mb bunit per each MDS/OSS
1668 local TESTFILE="$DIR/$tdir/$tfile"
1671 run_to_block_limit $TESTFILE
1676 resetquota -u $TSTUSR
1678 set_blk_unitsz $((128 * 1024))
1679 set_blk_tunesz $((128 * 1024 / 2))
1682 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1686 LSTR=(1t 2g 3m 4k) # limits strings
1687 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1689 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1690 $MOUNT || error "could not set quota limits"
1692 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1693 --inode-softlimit ${LSTR[2]} \
1694 --inode-hardlimit ${LSTR[3]} \
1695 $MOUNT || error "could not set quota limits"
1697 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1698 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1699 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1700 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1702 resetquota -u $TSTUSR
1704 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1711 time=$(($(date +%s) + seconds))
1712 while [ $(date +%s) -lt $time ]; do
1713 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1718 # run for fixing bug16053, setquota shouldn't fail when writing and
1719 # deleting are happening
1724 wait_delete_completed
1726 TESTFILE="$DIR/$tdir/$tfile"
1728 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1731 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1732 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1733 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1734 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1736 # repeat writing on a 1M file
1737 test_21_sub ${TESTFILE}_1 1024 30 &
1739 # repeat writing on a 128M file
1740 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1743 time=$(($(date +%s) + 30))
1745 while [ $(date +%s) -lt $time ]; do
1746 log " Set quota for $i times"
1747 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1748 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1755 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1757 if [ $count -gt 60 ]; then
1758 quota_error a $TSTUSR "dd should be finished!"
1762 echo "(dd_pid=$DDPID1, time=$count)successful"
1766 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1768 if [ $count -gt 60 ]; then
1769 quota_error a $TSTUSR "dd should be finished!"
1773 echo "(dd_pid=$DDPID2, time=$count)successful"
1775 set_blk_unitsz $((128 * 1024))
1776 set_blk_tunesz $((128 * 1024 / 2))
1777 resetquota -u $TSTUSR
1778 resetquota -g $TSTUSR
1782 run_test_with_stat 21 "run for fixing bug16053 ==========="
1785 local lustre_version=$(get_lustre_version mds)
1786 if [[ $lustre_version != 1.8* ]] ; then
1787 skip mds running $lustre_version, skip quota v1 testing
1790 quota_save_version "ug1"
1796 echo "checking parameters"
1798 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1799 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1801 run_test 0 "reboot lustre"
1803 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1807 chmod 0777 $DIR/$tdir
1808 TESTFILE="$DIR/$tdir/$tfile-0"
1810 local bs_unit=$((1024*1024))
1813 wait_delete_completed
1816 log " User quota (limit: $LIMIT kbytes)"
1817 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1819 quota_show_check b u $TSTUSR
1821 $LFS setstripe $TESTFILE -c 1
1822 chown $TSTUSR.$TSTUSR $TESTFILE
1824 log " Step1: trigger quota with 0_DIRECT"
1825 log " Write half of file"
1826 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1827 log " Write out of block quota ..."
1828 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1831 log " Step2: rewrite should succeed"
1832 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1836 wait_delete_completed
1837 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1838 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1839 echo $OST0_QUOTA_USED
1840 [ $OST0_QUOTA_USED -ne 0 ] && \
1841 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1843 resetquota -u $TSTUSR
1847 log "run for $((OSTCOUNT * 3))MB test file"
1848 test_23_sub $((OSTCOUNT * 3 * 1024))
1851 check_whether_skip && return 0
1852 log "run for $((OSTCOUNT * 30))MB test file"
1853 test_23_sub $((OSTCOUNT * 30 * 1024))
1855 run_test_with_stat 23 "run for fixing bug16125 ==========="
1858 local TESTFILE="$DIR/$tdir/$tfile"
1861 run_to_block_limit $TESTFILE
1862 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1866 resetquota -u $TSTUSR
1868 set_blk_unitsz $((128 * 1024))
1869 set_blk_tunesz $((128 * 1024 / 2))
1872 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1875 if [ $1 = "-u" ]; then
1876 if [ $2 = "$TSTUSR" ]; then
1882 if [ $2 = "$TSTUSR" ]; then
1892 chmod 0777 $DIR/$tdir
1893 TESTFILE="$DIR/$tdir/$tfile-0"
1895 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1897 wait_delete_completed
1899 # set quota for $TSTUSR
1900 log "setquota for $TSTUSR"
1901 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1903 if [ "$1" == "-u" ]; then
1904 quota_show_check a u $TSTUSR
1906 quota_show_check a g $TSTUSR
1909 # set quota for $TSTUSR2
1910 log "setquota for $TSTUSR2"
1911 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1913 if [ "$1" == "-u" ]; then
1914 quota_show_check a u $TSTUSR2
1916 quota_show_check a g $TSTUSR2
1919 # set stripe index to 0
1920 log "setstripe for $DIR/$tdir to 0"
1921 $LFS setstripe $DIR/$tdir -c 1 -i 0
1924 local dev=$(get_mds_mdt_device_proc_path)
1925 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
1926 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1928 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1929 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1930 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1931 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1934 log "$TSTUSR write 4M to $TESTFILE"
1935 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1937 show_quota $1 $TSTUSR
1938 show_quota $1 $TSTUSR2
1939 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1940 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1941 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1942 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1943 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1944 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1945 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1947 # chown/chgrp from $TSTUSR to $TSTUSR2
1948 if [ $1 = "-u" ]; then
1949 log "chown from $TSTUSR to $TSTUSR2"
1950 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1952 log "chgrp from $TSTUSR to $TSTUSR2"
1953 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1956 show_quota $1 $TSTUSR
1957 show_quota $1 $TSTUSR2
1958 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1959 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1960 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1961 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1962 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1963 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1964 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1965 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1966 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1967 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1968 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1969 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1970 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1971 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1972 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1975 wait_delete_completed
1976 resetquota $1 $TSTUSR
1977 resetquota $1 $TSTUSR2
1981 log "run for chown case"
1984 log "run for chgrp case"
1987 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1991 chmod 0777 $DIR/$tdir
1992 TESTFILE="$DIR/$tdir/$tfile-0"
1993 TESTFILE2="$DIR/$tdir/$tfile-1"
1997 wait_delete_completed
1999 # every quota slave gets 20MB
2000 b_limit=$((OSTCOUNT * 20 * 1024))
2001 log "limit: ${b_limit}KB"
2002 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2004 quota_show_check b u $TSTUSR
2006 $LFS setstripe $TESTFILE -c 1 -i 0
2007 $LFS setstripe $TESTFILE2 -c 1 -i 0
2008 chown $TSTUSR.$TSTUSR $TESTFILE
2009 chown $TSTUSR.$TSTUSR $TESTFILE2
2011 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2012 lustre_fail ost 0xA03
2014 log " Write the first file..."
2015 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2016 log " Delete the first file..."
2020 wait_delete_completed
2022 log " Write the second file..."
2023 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2024 log " Delete the second file..."
2028 set_blk_unitsz $((128 * 1024))
2029 set_blk_tunesz $((128 * 1024 / 2))
2030 resetquota -u $TSTUSR
2032 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2035 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2036 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2039 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2042 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2043 error "lfs setquota failed with uid argument"
2044 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2045 error "lfs stequota failed with gid argument"
2046 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2047 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2048 resetquota -u $TSTUSR
2049 resetquota -g $TSTUSR
2052 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2055 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2056 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2057 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2060 echo "Step 2: reset system ..."
2061 cleanup_and_setup_lustre
2064 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2068 wait_delete_completed
2070 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2071 lustre_fail ost 0x80000A02
2073 TESTFILE="$DIR/$tdir/$tfile"
2076 BLK_LIMIT=$((100 * 1024)) # 100M
2077 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2078 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2082 chown $TSTUSR.$TSTUSR $TESTFILE
2084 echo "Step 5: write the test file1 [10M] ..."
2085 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2086 || quota_error a $TSTUSR "write 10M file failure"
2090 sync; sleep 3; sync;
2092 # make qd_count 64 bit
2095 set_blk_unitsz $((128 * 1024))
2096 set_blk_tunesz $((128 * 1024 / 2))
2098 resetquota -u $TSTUSR
2100 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2105 # flush AT history, enforce at_max immediately
2106 do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2114 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2115 local newtimeo=10 # the default ptlrpc AT value
2119 if at_is_enabled; then
2120 oldtimeo=$(at_max_get client)
2121 at_max_enforce $newtimeo
2123 oldtimeo=$(lctl get_param -n timeout)
2124 lctl set_param timeout=$newtimeo
2127 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2128 lustre_fail mds 0x12e
2130 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2132 # 1.25 * at_max + 5 + net_latency
2133 echo "sleeping for $((newtimeo * 9 / 4 + 5)) seconds"
2134 sleep $((newtimeo * 9 / 4 + 5))
2135 ps -p $pid && error "lfs hadn't finished by timeout"
2136 wait $pid && error "succeeded, but should have failed"
2140 if at_is_enabled; then
2141 at_max_enforce $oldtimeo
2143 lctl set_param timeout=$oldtimeo
2146 resetquota -u $TSTUSR
2148 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2154 local TESTFILE="$DIR/$tdir/$tfile"
2161 chmod 0777 $DIR/$tdir
2163 $LFS setstripe $TESTFILE -i 0 -c 1
2164 chown $TSTUSR.$TSTUSR $TESTFILE
2166 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2167 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2168 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2169 cancel_lru_locks osc
2171 $LFS setquota -u $TSTUSR -B 0 $DIR
2172 # over-quota flag has not yet settled since we do not trigger async events
2173 # based on grace time period expiration
2175 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2176 cancel_lru_locks osc
2177 # now over-quota flag should be settled and further writes should fail
2179 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2181 resetquota -u $TSTUSR
2182 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2184 set_blk_unitsz $((128 * 1024))
2185 set_blk_tunesz $((128 * 1024 / 2))
2187 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2189 # test duplicate quota releases b=18630
2192 chmod 0777 $DIR/$tdir
2194 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2195 TESTFILE="$DIR/$tdir/$tfile-0"
2196 TESTFILE2="$DIR/$tdir/$tfile-1"
2198 wait_delete_completed
2200 log " User quota (limit: $LIMIT kbytes)"
2201 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2203 $LFS setstripe $TESTFILE -i 0 -c 1
2204 chown $TSTUSR.$TSTUSR $TESTFILE
2205 $LFS setstripe $TESTFILE2 -i 0 -c 1
2206 chown $TSTUSR.$TSTUSR $TESTFILE2
2208 log " step1: write out of block quota ..."
2209 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2210 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2212 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2213 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2214 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2216 log " step2: delete two files so that triggering duplicate quota release ..."
2217 rm -f $TESTFILE $TESTFILE2
2218 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2219 wait_delete_completed
2221 log " step3: verify if the ost failed"
2222 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2223 watchdog=`awk '/test 31/ {start = 1;}
2224 /release quota error/ {
2228 }' $TMP/lustre-log-${TESTNAME}.log`
2229 [ "$watchdog" ] && error "$watchdog"
2230 rm -f $TMP/lustre-log-${TESTNAME}.log
2233 resetquota -u $TSTUSR
2235 run_test_with_stat 31 "test duplicate quota releases ==="
2237 # check hash_cur_bits
2238 check_quota_hash_cur_bits() {
2241 # check quota_hash_cur_bits on all obdfilters
2242 for num in `seq $OSTCOUNT`; do
2243 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2244 if [ $cb -gt $bits ]; then
2245 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2249 # check quota_hash_cur_bits on mds
2250 cb=`do_facet mds "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2251 if [ $cb -gt $bits ]; then
2252 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2260 # check distribution of all obdfilters
2261 for num in `seq $OSTCOUNT`; do
2262 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2263 rehash_count=`echo $line | awk '{print $9}'`
2264 if [ $rehash_count -eq 0 ]; then
2265 echo -e "ost$num:\n $line"
2266 error "Rehearsh didn't happen"
2270 # check distribution of mds
2271 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2272 rehash_count=`echo $line | awk '{print $9}'`
2273 if [ $rehash_count -eq 0 ]; then
2274 echo -e "mdt:\n $line"
2275 error "Rehearsh didn't happen"
2282 # reset system so that quota_hash_cur_bits==3
2283 echo "Reset system ..."
2284 local LMR_orig=$LOAD_MODULES_REMOTE
2285 LOAD_MODULES_REMOTE=true
2286 cleanup_and_setup_lustre
2287 LOAD_MODULES_REMOTE=$LMR_orig
2289 for user in $SANITY_QUOTA_USERS; do
2290 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2291 missing_users="$missing_users $user"
2293 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2294 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2296 $LFS quotaoff -ug $DIR
2297 $LFS quotacheck -ug $DIR
2299 for user in $SANITY_QUOTA_USERS; do
2300 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2305 for user in $SANITY_QUOTA_USERS; do
2309 run_test 32 "check lqs hash(bug 21846) =========================================="
2312 # run 98 at the end because of reformatall
2319 local missing_users=""
2321 for user in $SANITY_QUOTA_USERS; do
2322 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" || \
2323 missing_users="$missing_users $user"
2325 [ -n "$missing_users" ] && { skip_env "different uid-s on client and servers, or missing users: $missing_users" ; return 0 ; }
2330 quota_set_version 1 # set version before the first quota check
2337 for user in $SANITY_QUOTA_USERS; do
2338 $LFS setquota -u $user --block-hardlimit $((2 * num + 4 * OSTCOUNT)) $DIR || error "first phase setquota failure"
2339 $LFS setstripe -c 1 $DIR/${tfile}${num} || error "single-stripe file creation failed"
2340 chown $user $DIR/${tfile}${num} || error "chown has failed"
2341 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:w$((num * 1024))c || \
2342 error "unexpected error when writing the file for $user"
2346 $LFS quotaoff -ug $DIR
2347 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2348 $LFS quotaon -ug $DIR
2351 for user in $SANITY_QUOTA_USERS; do
2352 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w$((num * 1024))c || \
2353 error "unexpected error when appending the file for $user"
2354 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w8192c && \
2355 error "unexpected success when appending the file for $user"
2356 $LFS setquota -u $user --block-hardlimit 0 $DIR || error "second phase setquota failure"
2357 rm -rf $DIR/${tfile}${num}
2361 set_blk_unitsz $((128 * 1024))
2362 set_blk_tunesz $((128 * 1024 / 2))
2364 run_test_with_stat 98 "quotaon autoconversion ==============================="
2370 lctl set_param debug="-quota"
2374 run_test_with_stat 99 "Quota off ==============================="
2377 complete $(basename $0) $SECONDS
2378 check_and_cleanup_lustre