3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
9 #kernel 2.4.x doesn't support quota
10 K_VER=`uname --kernel-release | cut -b 1-3`
11 if [ $K_VER = "2.4" ]; then
12 echo "Kernel 2.4 doesn't support quota"
17 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
20 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
21 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
22 # We have changed the mechanism of quota, test_12 is meanless now.
24 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
25 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
28 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
29 *) error "unsupported kernel" ;;
32 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
33 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
39 TSTID2=${TSTID2:-60001}
40 TSTUSR=${TSTUSR:-"quota_usr"}
41 TSTUSR2=${TSTUSR2:-"quota_2usr"}
43 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
44 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
47 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
48 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
49 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
50 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
51 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
54 LUSTRE=${LUSTRE:-`dirname $0`/..}
55 . $LUSTRE/tests/test-framework.sh
57 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
59 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
61 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
63 require_dsh_mds || exit 0
64 require_dsh_ost || exit 0
66 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
68 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
70 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
75 QUOTA_AUTO_OLD=$QUOTA_AUTO
78 check_and_setup_lustre
80 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
81 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
83 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
84 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
85 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
86 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
87 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
88 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
89 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
90 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
92 # control the time of tests
94 [ "$SLOW" = "no" ] && cycle=10
98 # set_blk_tunables(btune_sz)
100 local btune=$(($1 * BLK_SZ))
101 # set btune size on all obdfilters
102 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
103 # set btune size on mds
104 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
107 # set_blk_unitsz(bunit_sz)
109 local bunit=$(($1 * BLK_SZ))
110 # set bunit size on all obdfilters
111 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
112 # set bunit size on mds
113 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
116 # set_file_tunesz(itune_sz)
119 # set itune size on mds
120 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
123 # set_file_unitsz(iunit_sz)
126 # set iunit size on mds
127 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
133 local fail_val=${3:-0}
135 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
136 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
137 [ $((fail_loc)) -eq 0 ]; then
138 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
140 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
142 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
143 for num in `seq $OSTCOUNT`; do
144 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
145 [ $((fail_loc)) -eq 0 ]; then
146 do_facet ost$num "lctl set_param fail_val=$fail_val"
148 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
153 RUNAS="runas -u $TSTID -g $TSTID"
154 RUNAS2="runas -u $TSTID2 -g $TSTID2"
155 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
156 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
160 run_test_with_stat() {
161 (($# != 2)) && error "the number of arguments is wrong"
163 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
164 for j in `seq $OSTCOUNT`; do
165 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
168 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
169 echo "statistics info begin ***************************************"
170 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
171 for j in `seq $OSTCOUNT`; do
172 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
174 echo "statistics info end ***************************************"
179 # clear quota limits for a user or a group
180 # usage: resetquota -u username
181 # resetquota -g groupname
184 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
185 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
188 if at_is_enabled; then
189 timeout=$(at_max_get mds)
191 timeout=$(lctl get_param -n timeout)
194 while [ $((count++)) -lt $timeout ]; do
196 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
197 if [ $RC -ne 0 ]; then
198 if echo "$OUTPUT" | grep -q busy; then
199 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
203 error "resetquota failed"
209 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
216 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
217 log "Files for user ($LOCAL_ID):"
218 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
221 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
222 log "Files for group ($LOCAL_ID):"
223 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
240 # get quota info for a user or a group
241 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
247 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
248 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
261 *) error "unknown quota parameter $4";;
264 [ "$uuid" = "global" ] && uuid=$DIR
266 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
273 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
275 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
277 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
278 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
279 if [ -z $USAGE ]; then
280 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
282 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
286 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
287 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
288 if [ -z $USAGE ]; then
289 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
291 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
298 $LFS quotacheck -ug $DIR
300 resetquota -u $TSTUSR
301 resetquota -g $TSTUSR
303 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
307 test_quota_performance() {
308 TESTFILE="$DIR/$tdir/$tfile-0"
310 local stime=`date +%s`
311 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
312 local etime=`date +%s`
313 delta=$((etime - stime))
314 if [ $delta -gt 0 ]; then
315 rate=$((size * 1024 / delta))
316 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
321 # test basic quota performance b=21696
324 chmod 0777 $DIR/$tdir
326 [ "$SLOW" = "no" ] && MB=10
328 test_quota_performance $MB
330 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
331 test_quota_performance $MB
333 resetquota -u $TSTUSR
335 run_test_with_stat 0 "Test basic quota performance ==="
337 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
341 chmod 0777 $DIR/$tdir
342 TESTFILE="$DIR/$tdir/$tfile-0"
344 wait_delete_completed
347 log " User quota (limit: $LIMIT kbytes)"
348 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
350 quota_show_check b u $TSTUSR
352 $LFS setstripe $TESTFILE -c 1
353 chown $TSTUSR.$TSTUSR $TESTFILE
356 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
358 log " Write out of block quota ..."
359 # this time maybe cache write, ignore it's failure
360 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
361 # flush cache, ensure noquota flag is setted on client
363 $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"
367 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
368 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
369 echo $OST0_QUOTA_USED
370 [ $OST0_QUOTA_USED -ne 0 ] && \
371 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
373 resetquota -u $TSTUSR
376 log "--------------------------------------"
377 log " Group quota (limit: $LIMIT kbytes)"
378 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
380 quota_show_check b g $TSTUSR
381 TESTFILE="$DIR/$tdir/$tfile-1"
383 $LFS setstripe $TESTFILE -c 1
384 chown $TSTUSR.$TSTUSR $TESTFILE
387 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
389 log " Write out of block quota ..."
390 # this time maybe cache write, ignore it's failure
391 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
393 $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"
398 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
399 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
400 echo $OST0_QUOTA_USED
401 [ $OST0_QUOTA_USED -ne 0 ] && \
402 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
404 resetquota -g $TSTUSR
407 # block hard limit (normal use and out of quota)
409 for i in `seq 1 $cycle`; do
410 # define blk_qunit is between 1M and 4M
411 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
412 blk_qtune=$(( $RANDOM % $blk_qunit ))
413 # other osts and mds will occupy at 1M blk quota
414 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
415 set_blk_tunesz $blk_qtune
416 set_blk_unitsz $blk_qunit
417 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
419 echo "=================================================="
420 set_blk_unitsz $((128 * 1024))
421 set_blk_tunesz $((128 * 1024 / 2))
424 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
426 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
430 chmod 0777 $DIR/$tdir
431 TESTFILE="$DIR/$tdir/$tfile-0"
433 wait_delete_completed
436 log " User quota (limit: $LIMIT files)"
437 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
439 quota_show_check f u $TSTUSR
441 log " Create $LIMIT files ..."
442 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
443 quota_error u $TSTUSR "(usr) create failure, but expect success"
445 log " Create out of file quota ..."
446 $RUNAS touch ${TESTFILE}_xxx && \
447 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
449 unlinkmany ${TESTFILE} $LIMIT
450 rm -f ${TESTFILE}_xxx
453 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
454 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
456 [ $MDS_QUOTA_USED -ne 0 ] && \
457 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
459 resetquota -u $TSTUSR
462 log "--------------------------------------"
463 log " Group quota (limit: $LIMIT FILE)"
464 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
466 quota_show_check f g $TSTUSR
467 TESTFILE=$DIR/$tdir/$tfile-1
469 log " Create $LIMIT files ..."
470 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
471 quota_error g $TSTUSR "(grp) create failure, but expect success"
473 log " Create out of file quota ..."
474 $RUNAS touch ${TESTFILE}_xxx && \
475 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
477 unlinkmany ${TESTFILE} $LIMIT
478 rm -f ${TESTFILE}_xxx
481 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
482 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
484 [ $MDS_QUOTA_USED -ne 0 ] && \
485 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
487 resetquota -g $TSTUSR
490 # file hard limit (normal use and out of quota)
492 for i in `seq 1 $cycle`; do
493 if [ $i -eq 1 ]; then
498 # define ino_qunit is between 10 and 100
499 ino_qunit=$(( $RANDOM % 90 + 10 ))
500 ino_qtune=$(( $RANDOM % $ino_qunit ))
501 # RANDOM's maxium is 32767
502 i_limit=$(( $RANDOM % 990 + 10 ))
505 set_file_tunesz $ino_qtune
506 set_file_unitsz $ino_qunit
507 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
509 echo "=================================================="
514 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
518 TIMER=$(($2 * 3 / 2))
521 wait_delete_completed
523 echo " Write to exceed soft limit"
524 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
525 $RUNDD count=$((BUNIT_SZ+1)) || \
526 quota_error a $TSTUSR "write failure, but expect success"
527 OFFSET=$((OFFSET + BUNIT_SZ + 1))
532 $SHOW_QUOTA_INFO_USER
533 $SHOW_QUOTA_INFO_GROUP
535 echo " Write before timer goes off"
536 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
537 quota_error a $TSTUSR "write failure, but expect success"
538 OFFSET=$((OFFSET + BUNIT_SZ))
542 echo " Sleep $TIMER seconds ..."
547 $SHOW_QUOTA_INFO_USER
548 $SHOW_QUOTA_INFO_GROUP
550 echo " Write after timer goes off"
551 # maybe cache write, ignore.
552 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
553 OFFSET=$((OFFSET + BUNIT_SZ))
555 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
556 quota_error a $TSTUSR "write success, but expect EDQUOT"
560 $SHOW_QUOTA_INFO_USER
561 $SHOW_QUOTA_INFO_GROUP
563 echo " Unlink file to stop timer"
570 $SHOW_QUOTA_INFO_USER
571 $SHOW_QUOTA_INFO_GROUP
574 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
582 # block soft limit (start timer, timer goes off, stop timer)
585 chmod 0777 $DIR/$tdir
587 # 1 bunit on mds and 1 bunit on every ost
588 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
591 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
592 TESTFILE=$DIR/$tdir/$tfile-0
594 $LFS setstripe $TESTFILE -c 1
595 chown $TSTUSR.$TSTUSR $TESTFILE
597 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
598 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
600 test_block_soft $TESTFILE $GRACE
601 resetquota -u $TSTUSR
603 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
604 TESTFILE=$DIR/$tdir/$tfile-1
606 $LFS setstripe $TESTFILE -c 1
607 chown $TSTUSR.$TSTUSR $TESTFILE
609 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
610 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
612 test_block_soft $TESTFILE $GRACE
613 resetquota -g $TSTUSR
615 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
620 TIMER=$(($3 * 3 / 2))
622 wait_delete_completed
624 echo " Create files to exceed soft limit"
625 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
626 quota_error a $TSTUSR "create failure, but expect success"
630 echo " Create file before timer goes off"
631 $RUNAS touch ${TESTFILE}_before || \
632 quota_error a $TSTUSR "failed create before timer expired, but expect success"
636 echo " Sleep $TIMER seconds ..."
641 $SHOW_QUOTA_INFO_USER
642 $SHOW_QUOTA_INFO_GROUP
644 echo " Create file after timer goes off"
645 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
646 # inode quota left here
647 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
649 $RUNAS touch ${TESTFILE}_after3 && \
650 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
655 $SHOW_QUOTA_INFO_USER
656 $SHOW_QUOTA_INFO_GROUP
658 echo " Unlink files to stop timer"
659 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
663 $RUNAS touch ${TESTFILE}_xxx || \
664 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
669 rm -f ${TESTFILE}_xxx
673 # file soft limit (start timer, timer goes off, stop timer)
674 test_4a() { # was test_4
676 chmod 0777 $DIR/$tdir
677 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
678 TESTFILE=$DIR/$tdir/$tfile-0
682 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
683 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
684 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
685 quota_show_check f u $TSTUSR
687 test_file_soft $TESTFILE $LIMIT $GRACE
688 resetquota -u $TSTUSR
690 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
691 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
692 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
693 quota_show_check f g $TSTUSR
694 TESTFILE=$DIR/$tdir/$tfile-1
696 test_file_soft $TESTFILE $LIMIT $GRACE
697 resetquota -g $TSTUSR
700 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
701 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
703 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
705 test_4b() { # was test_4a
711 GR_STR6="1111111111111111"
713 wait_delete_completed
715 # test of valid grace strings handling
716 echo " Valid grace strings test"
717 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
718 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
719 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
720 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
722 # test of invalid grace strings handling
723 echo " Invalid grace strings test"
724 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
725 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
728 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
729 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
731 run_test_with_stat 4b "Grace time strings handling ==="
733 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
736 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
737 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
739 wait_delete_completed
741 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
742 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
743 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
744 quota_show_check a u $TSTUSR
745 quota_show_check a g $TSTUSR
747 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
748 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
749 error "touch failure, expect success"
750 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
752 echo " Chown files to $TSTUSR.$TSTUSR ..."
753 for i in `seq 0 $ILIMIT`; do
754 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
755 quota_error a $TSTUSR "chown failure, but expect success"
759 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
762 resetquota -u $TSTUSR
763 resetquota -g $TSTUSR
765 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
767 # block quota acquire & release
769 if [ $OSTCOUNT -lt 2 ]; then
770 skip_env "$OSTCOUNT < 2, too few osts"
774 wait_delete_completed
777 chmod 0777 $DIR/$tdir
779 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
780 FILEA="$DIR/$tdir/$tfile-0_a"
781 FILEB="$DIR/$tdir/$tfile-0_b"
783 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
784 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
785 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
786 quota_show_check b u $TSTUSR
787 quota_show_check b g $TSTUSR
789 echo " Create filea on OST0 and fileb on OST1"
790 $LFS setstripe $FILEA -i 0 -c 1
791 $LFS setstripe $FILEB -i 1 -c 1
792 chown $TSTUSR.$TSTUSR $FILEA
793 chown $TSTUSR.$TSTUSR $FILEB
795 echo " Exceed quota limit ..."
796 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
797 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
798 quota_error a $TSTUSR "write filea failure, but expect success"
803 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
804 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
806 echo " Write to OST1 return EDQUOT"
807 # this write maybe cache write, ignore it's failure
808 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
809 $RUNDD count=$(($BUNIT_SZ * 2)) || true
813 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
814 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
816 echo " Remove filea to let OST0 release quota"
819 if at_is_enabled; then
820 timeout=$(at_max_get mds)
822 timeout=$(lctl get_param -n timeout)
824 count=$((timeout / 5))
825 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
827 while [ $((count--)) -gt 0 ]; do
830 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
831 if [ -z $OST0_QUOTA_HOLD ]; then
832 error "System is error when query quota for block (U:$TSTUSR)."
834 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
840 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
843 while [ $((count--)) -gt 0 ]; do
846 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
847 if [ -z $OST0_QUOTA_HOLD ]; then
848 error "System is error when query quota for block (G:$TSTUSR)."
850 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
856 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
859 echo " Write to OST1"
860 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
861 quota_error a $TSTUSR "write fileb failure, expect success"
868 resetquota -u $TSTUSR
869 resetquota -g $TSTUSR
872 run_test_with_stat 6 "Block quota acquire & release ========="
874 # quota recovery (block quota only by now)
878 chmod 0777 $DIR/$tdir
880 wait_delete_completed
882 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
883 TESTFILE="$DIR/$tdir/$tfile-0"
885 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
887 $LFS setstripe $TESTFILE -c 1
888 chown $TSTUSR.$TSTUSR $TESTFILE
890 echo " Write to OST0..."
891 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
892 quota_error u $TSTUSR "write failure, but expect success"
894 #define OBD_FAIL_OBD_DQACQ 0x604
895 lustre_fail mds 0x604
896 echo " Remove files on OST0"
900 echo " Trigger recovery..."
901 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
902 for i in $OSC0_UUID; do
903 $LCTL --device $i activate || error "activate osc failed!"
906 # sleep a while to wait for recovery done
910 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
911 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
912 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
913 echo " total limits = $TOTAL_LIMIT"
915 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
916 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
917 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
918 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
919 echo " limits on $OST0_UUID = $OST0_LIMIT"
922 resetquota -u $TSTUSR
924 run_test_with_stat 7 "Quota recovery (only block limit) ======"
926 # run dbench with quota enabled
929 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
932 wait_delete_completed
934 echo " Set enough high limit for user: $TSTUSR"
935 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
936 echo " Set enough high limit for group: $TSTUSR"
937 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
939 chmod 0777 $DIR/$tdir
941 [ "$SLOW" = "no" ] && duration=" -t 120"
942 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
949 run_test_with_stat 8 "Run dbench with quota enabled ==========="
951 # run for fixing bug10707, it needs a big room. test for 64bit
953 GB=$((KB * 1024 * 1024))
954 # Use this as dd bs to decrease time
955 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
956 blksize=$((1 << 21)) # 2Mb
957 size_file=$((GB * 9 / 2))
958 # this check is just for test9 and test10
959 OST0_MIN=4900000 #4.67G
960 check_whether_skip () {
961 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
962 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
963 if [ $OST0_SIZE -lt $OST0_MIN ]; then
964 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
972 check_whether_skip && return 0
974 wait_delete_completed
980 chmod 0777 $DIR/$tdir
981 TESTFILE="$DIR/$tdir/$tfile-0"
983 BLK_LIMIT=$((100 * KB * KB)) # 100G
985 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
987 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
988 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
989 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
990 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
992 quota_show_check a u $TSTUSR
993 quota_show_check a g $TSTUSR
996 $LFS setstripe $TESTFILE -c 1
998 chown $TSTUSR.$TSTUSR $TESTFILE
1000 log " Write the big file of 4.5G ..."
1001 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1002 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1007 log " delete the big file of 4.5G..."
1008 $RUNAS rm -f $TESTFILE
1009 sync; sleep 3; sync;
1016 set_blk_unitsz $((128 * 1024))
1017 set_blk_tunesz $((128 * 1024 / 2))
1021 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1023 # 2.0 version does not support 32 bit qd_count,
1024 # test_10 "run for fixing bug10707(32bit) " is obsolete
1026 # test a deadlock between quota and journal b=11693
1029 chmod 0777 $DIR/$tdir
1031 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1032 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1034 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1035 TESTFILE="$DIR/$tdir/$tfile-0"
1036 TESTFILE2="$DIR2/$tdir/$tfile-1"
1038 wait_delete_completed
1040 echo " User quota (limit: $LIMIT kbytes)"
1041 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1043 $LFS setstripe $TESTFILE -i 0 -c 1
1044 chown $TSTUSR.$TSTUSR $TESTFILE
1045 $LFS setstripe $TESTFILE2 -i 0 -c 1
1046 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1048 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1049 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1050 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1052 echo " step1: write out of block quota ..."
1053 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1055 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1058 echo " step2: testing ......"
1059 local last_size=$(stat -c %s $TESTFILE2)
1061 local start_secs=$SECONDS
1062 while [ -d /proc/${DDPID1} ]; do
1063 local size=$(stat -c %s $TESTFILE2)
1064 if [ $size -eq $last_size ]; then
1065 stall_secs=$[stall_secs+1]
1069 if [ $stall_secs -gt 30 ]; then
1071 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1076 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1078 #Recover fail_loc and dd will finish soon
1081 echo " step3: testing ......"
1084 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1086 if [ $count -gt 150 ]; then
1087 quota_error u $TSTUSR "dd should be finished!"
1091 echo "(dd_pid=$DDPID, time=$count)successful"
1093 rm -f $TESTFILE $TESTFILE2
1094 sync; sleep 3; sync;
1096 resetquota -u $TSTUSR
1098 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1100 # test multiple clients write block quota b=11693
1103 wait_delete_completed
1105 # one OST * 10 + (mds + other OSTs)
1106 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1107 TESTFILE="$DIR/$tdir/$tfile"
1109 echo " User quota (limit: $LIMIT kbytes)"
1110 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1111 quota_show_check b u $TSTUSR
1113 $LFS setstripe $TESTFILE -i 0 -c 1
1114 chown $TSTUSR.$TSTUSR $TESTFILE
1115 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1116 chown $TSTUSR.$TSTUSR $TESTFILE.2
1118 echo " step1: write out of block quota ..."
1119 # one bunit will give mds
1120 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1122 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1125 echo " step2: testing ......"
1128 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1130 if [ $count -gt 64 ]; then
1131 quota_error u $TSTUSR "dd should be finished!"
1135 echo "(dd_pid=$DDPID, time=$count)successful"
1139 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1141 if [ $count -gt 64 ]; then
1142 quota_error u $TSTUSR "dd should be finished!"
1146 echo "(dd_pid=$DDPID1, time=$count)successful"
1148 sync; sleep 5; sync;
1150 echo " step3: checking ......"
1151 fz=`stat -c %s $TESTFILE`
1152 fz2=`stat -c %s $TESTFILE.2`
1154 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1155 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1157 rm -f $TESTFILE $TESTFILE.2
1158 sync; sleep 3; sync;
1160 resetquota -u $TSTUSR
1162 run_test_with_stat 13 "test multiple clients write block quota ==="
1164 check_if_quota_zero(){
1165 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1166 for i in `seq 3 $line`; do
1167 if [ $i -eq 3 ]; then
1173 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1174 awk '{print $'"$j"'}'`
1175 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1176 error "quota on $2 isn't clean"
1179 echo "pass check_if_quota_zero"
1182 test_14a() { # was test_14 b=12223 -- setting quota on root
1183 TESTFILE="$DIR/$tdir/$tfile"
1187 cleanup_and_setup_lustre
1192 # out of root's file and block quota
1193 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1194 createmany -m ${TESTFILE} 20 || \
1195 quota_error u root "unexpected: user(root) create files failly!"
1196 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1197 quota_error u root "unexpected: user(root) write files failly!"
1199 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1200 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1204 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1205 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1208 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1210 #check_if_quota_zero u root
1213 unlinkmany ${TESTFILE} 15
1215 sync; sleep 3; sync;
1217 run_test_with_stat 14a "test setting quota on root ==="
1220 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1221 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1223 wait_delete_completed
1226 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1227 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1228 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1229 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1230 resetquota -u $TSTUSR
1233 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1234 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1235 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1236 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1237 resetquota -g $TSTUSR
1238 $LFS quotaoff -ug $DIR
1239 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1240 error "fail to set version for $SINGLEMDS"
1241 for j in `seq $OSTCOUNT`; do
1242 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1243 error "fail to set version for ost$j"
1246 echo "invalidating quota files"
1247 $LFS quotainv -ug $DIR
1248 $LFS quotainv -ugf $DIR
1249 $LFS quotacheck -ug $DIR
1251 run_test_with_stat 15 "set block quota more than 4T ==="
1253 # 2.0 version does not support WITHOUT_CHANGE_QS,
1254 # test_16 "test without adjusting qunit" is obsolete
1256 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1261 wait_delete_completed
1263 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1264 lustre_fail ost 0x80000A02
1266 TESTFILE="$DIR/$tdir/$tfile-a"
1267 TESTFILE2="$DIR/$tdir/$tfile-b"
1270 BLK_LIMIT=$((100 * 1024)) # 100M
1272 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1273 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1274 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1275 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1277 quota_show_check b u $TSTUSR
1278 quota_show_check b g $TSTUSR
1281 chown $TSTUSR.$TSTUSR $TESTFILE
1283 chown $TSTUSR.$TSTUSR $TESTFILE2
1285 log " Write the test file1 ..."
1286 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1287 || quota_error a $TSTUSR "write 10M file failure"
1292 log " write the test file2 ..."
1293 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1294 || quota_error a $TSTUSR "write 10M file failure"
1299 rm -f $TESTFILE $TESTFILE2
1301 sync; sleep 3; sync;
1303 # make qd_count 64 bit
1306 set_blk_unitsz $((128 * 1024))
1307 set_blk_tunesz $((128 * 1024 / 2))
1309 resetquota -u $TSTUSR
1310 resetquota -g $TSTUSR
1314 run_test_with_stat 17 "run for fixing bug14526 ==========="
1316 # test when mds takes a long time to handle a quota req so that
1317 # the ost has dropped it, the ost still could work well b=14840
1319 LIMIT=$((100 * 1024 * 1024)) # 100G
1320 TESTFILE="$DIR/$tdir/$tfile"
1323 wait_delete_completed
1328 log " User quota (limit: $LIMIT kbytes)"
1329 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1330 quota_show_check b u $TSTUSR
1332 $LFS setstripe $TESTFILE -i 0 -c 1
1333 chown $TSTUSR.$TSTUSR $TESTFILE
1335 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1336 lustre_fail mds 0x13c
1338 log " step1: write 100M block ..."
1339 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1345 echo " step2: testing ......"
1347 if at_is_enabled; then
1348 timeout=$(at_max_get mds)
1350 timeout=$(lctl get_param -n timeout)
1353 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1355 if [ $count -gt $((4 * $timeout)) ]; then
1356 quota_error u $TSTUSR "count=$count dd should be finished!"
1360 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1362 cancel_lru_locks mdc
1363 cancel_lru_locks osc
1365 testfile_size=$(stat -c %s $TESTFILE)
1366 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1367 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1372 resetquota -u $TSTUSR
1373 set_blk_unitsz $((128 * 1024))
1374 set_blk_tunesz $((128 * 1024 / 2))
1376 run_test_with_stat 18 "run for fixing bug14840 ==========="
1378 # test when mds drops a quota req, the ost still could work well b=14840
1380 LIMIT=$((100 * 1024 * 1024)) # 100G
1381 TESTFILE="$DIR/$tdir/$tfile-a"
1384 wait_delete_completed
1389 log " User quota (limit: $LIMIT kbytes)"
1390 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1391 quota_show_check b u $TSTUSR
1393 $LFS setstripe $TESTFILE -i 0 -c 1
1394 chown $TSTUSR.$TSTUSR $TESTFILE
1396 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1397 lustre_fail mds 0x8000013d
1399 log " step1: write 100M block ..."
1400 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1403 echo " step2: testing ......"
1405 if at_is_enabled; then
1406 timeout=$(at_max_get mds)
1408 timeout=$(lctl get_param -n timeout)
1411 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1413 if [ $count -gt $((6 * $timeout)) ]; then
1415 quota_error u $TSTUSR "count=$count dd should be finished!"
1419 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1425 resetquota -u $TSTUSR
1426 set_blk_unitsz $((128 * 1024))
1427 set_blk_tunesz $((128 * 1024 / 2))
1429 run_test_with_stat 18a "run for fixing bug14840 ==========="
1431 # test when mds do failover, the ost still could work well without trigger
1436 LIMIT=$((110 * 1024 )) # 110M
1437 TESTFILE="$DIR/$tdir/$tfile"
1440 wait_delete_completed
1445 log " User quota (limit: $LIMIT kbytes)"
1446 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1447 quota_show_check b u $TSTUSR
1449 $LFS setstripe $TESTFILE -i 0 -c 1
1450 chown $TSTUSR.$TSTUSR $TESTFILE
1452 timeout=$(sysctl -n lustre.timeout)
1454 if [ $type = "directio" ]; then
1455 log " write 100M block(directio) ..."
1456 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1458 log " write 100M block(normal) ..."
1459 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1463 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1465 log "failing mds for $((2 * timeout)) seconds"
1466 fail $SINGLEMDS $((2 * timeout))
1468 # check if quotaon successful
1469 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1470 if [ $? -eq 0 ]; then
1471 error "quotaon failed!"
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
1484 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1485 log "it took $count second"
1489 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1491 cancel_lru_locks mdc
1492 cancel_lru_locks osc
1494 testfile_size=$(stat -c %s $TESTFILE)
1495 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1496 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1501 resetquota -u $TSTUSR
1502 set_blk_unitsz $((128 * 1024))
1503 set_blk_tunesz $((128 * 1024 / 2))
1506 # test when mds does failover, the ost still could work well
1507 # this test shouldn't trigger watchdog b=14840
1509 test_18bc_sub normal
1510 test_18bc_sub directio
1511 # check if watchdog is triggered
1512 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1513 watchdog=`awk '/test 18b/ {start = 1;}
1514 /Service thread pid/ && /was inactive/ {
1518 }' $TMP/lustre-log-${TESTNAME}.log`
1519 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1520 rm -f $TMP/lustre-log-${TESTNAME}.log
1522 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1524 # test when mds does failover, the ost still could work well
1525 # this test will prevent OST_DISCONNET from happening b=14840
1527 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1528 lustre_fail ost 0x202
1529 test_18bc_sub normal
1530 test_18bc_sub directio
1533 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1535 run_to_block_limit() {
1536 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1538 wait_delete_completed
1540 # set 1 Mb quota unit size
1544 # bind file to a single OST
1545 $LFS setstripe -c 1 $TESTFILE
1546 chown $TSTUSR.$TSTUSR $TESTFILE
1548 echo " User quota (limit: $LIMIT kbytes)"
1549 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1550 quota_show_check b u $TSTUSR
1551 echo " Updating quota limits"
1552 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1553 quota_show_check b u $TSTUSR
1555 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1556 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1557 # for now page cache of TESTFILE may still be dirty,
1558 # let's push it to the corresponding OST, this will also
1559 # cache NOQUOTA on the client from OST's reply
1560 cancel_lru_locks osc
1561 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1565 # 1 Mb bunit per each MDS/OSS
1566 local TESTFILE="$DIR/$tdir/$tfile"
1569 run_to_block_limit $TESTFILE
1574 resetquota -u $TSTUSR
1576 set_blk_unitsz $((128 * 1024))
1577 set_blk_tunesz $((128 * 1024 / 2))
1580 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1584 LSTR=(1t 2g 3m 4k) # limits strings
1585 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1587 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1588 $MOUNT || error "could not set quota limits"
1590 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1591 --inode-softlimit ${LSTR[2]} \
1592 --inode-hardlimit ${LSTR[3]} \
1593 $MOUNT || error "could not set quota limits"
1595 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1596 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1597 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1598 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1600 resetquota -u $TSTUSR
1602 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1609 time=$(($(date +%s) + seconds))
1610 while [ $(date +%s) -lt $time ]; do
1611 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1616 # run for fixing bug16053, setquota shouldn't fail when writing and
1617 # deleting are happening
1622 wait_delete_completed
1624 TESTFILE="$DIR/$tdir/$tfile"
1626 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1629 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1630 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1631 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1632 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1634 # repeat writing on a 1M file
1635 test_21_sub ${TESTFILE}_1 1024 30 &
1637 # repeat writing on a 128M file
1638 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1641 time=$(($(date +%s) + 30))
1643 while [ $(date +%s) -lt $time ]; do
1644 log " Set quota for $i times"
1645 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1646 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1653 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1655 if [ $count -gt 60 ]; then
1656 quota_error a $TSTUSR "dd should be finished!"
1660 echo "(dd_pid=$DDPID1, time=$count)successful"
1664 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1666 if [ $count -gt 60 ]; then
1667 quota_error a $TSTUSR "dd should be finished!"
1671 echo "(dd_pid=$DDPID2, time=$count)successful"
1673 set_blk_unitsz $((128 * 1024))
1674 set_blk_tunesz $((128 * 1024 / 2))
1675 resetquota -u $TSTUSR
1676 resetquota -g $TSTUSR
1680 run_test_with_stat 21 "run for fixing bug16053 ==========="
1683 quota_save_version "ug3"
1689 echo "checking parameters"
1691 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1692 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1696 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1700 chmod 0777 $DIR/$tdir
1701 TESTFILE="$DIR/$tdir/$tfile-0"
1703 local bs_unit=$((1024*1024))
1706 wait_delete_completed
1709 log " User quota (limit: $LIMIT kbytes)"
1710 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1712 quota_show_check b u $TSTUSR
1714 $LFS setstripe $TESTFILE -c 1
1715 chown $TSTUSR.$TSTUSR $TESTFILE
1717 log " Step1: trigger quota with 0_DIRECT"
1718 log " Write half of file"
1719 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1720 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1721 log " Write out of block quota ..."
1722 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1723 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1726 log " Step2: rewrite should succeed"
1727 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1728 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1732 wait_delete_completed
1733 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1734 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1735 echo $OST0_QUOTA_USED
1736 [ $OST0_QUOTA_USED -ne 0 ] && \
1737 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1739 resetquota -u $TSTUSR
1743 log "run for $((OSTCOUNT * 4))MB test file"
1744 test_23_sub $((OSTCOUNT * 4 * 1024))
1747 check_whether_skip && return 0
1748 log "run for $((OSTCOUNT * 40))MB test file"
1749 test_23_sub $((OSTCOUNT * 40 * 1024))
1751 run_test_with_stat 23 "run for fixing bug16125 ==========="
1754 local TESTFILE="$DIR/$tdir/$tfile"
1757 run_to_block_limit $TESTFILE
1758 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1762 resetquota -u $TSTUSR
1764 set_blk_unitsz $((128 * 1024))
1765 set_blk_tunesz $((128 * 1024 / 2))
1768 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1771 if [ $1 = "-u" ]; then
1772 if [ $2 = "$TSTUSR" ]; then
1778 if [ $2 = "$TSTUSR" ]; then
1788 chmod 0777 $DIR/$tdir
1789 TESTFILE="$DIR/$tdir/$tfile-0"
1791 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1793 wait_delete_completed
1795 # set quota for $TSTUSR
1796 log "setquota for $TSTUSR"
1797 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1799 if [ "$1" == "-u" ]; then
1800 quota_show_check a u $TSTUSR
1802 quota_show_check a g $TSTUSR
1805 # set quota for $TSTUSR2
1806 log "setquota for $TSTUSR2"
1807 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1809 if [ "$1" == "-u" ]; then
1810 quota_show_check a u $TSTUSR2
1812 quota_show_check a g $TSTUSR2
1815 # set stripe index to 0
1816 log "setstripe for $DIR/$tdir to 0"
1817 $LFS setstripe $DIR/$tdir -c 1 -i 0
1818 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1819 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1820 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1821 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1822 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1823 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1826 log "$TSTUSR write 4M to $TESTFILE"
1827 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1829 show_quota $1 $TSTUSR
1830 show_quota $1 $TSTUSR2
1831 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1832 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1833 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1834 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1835 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1836 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1837 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1839 # chown/chgrp from $TSTUSR to $TSTUSR2
1840 if [ $1 = "-u" ]; then
1841 log "chown from $TSTUSR to $TSTUSR2"
1842 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1844 log "chgrp from $TSTUSR to $TSTUSR2"
1845 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1848 show_quota $1 $TSTUSR
1849 show_quota $1 $TSTUSR2
1850 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1851 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1852 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1853 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1854 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1855 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1856 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1857 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1858 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1859 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1860 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1861 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1862 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1863 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1864 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1867 wait_delete_completed
1868 resetquota $1 $TSTUSR
1869 resetquota $1 $TSTUSR2
1873 log "run for chown case"
1876 log "run for chgrp case"
1879 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1883 chmod 0777 $DIR/$tdir
1884 TESTFILE="$DIR/$tdir/$tfile-0"
1885 TESTFILE2="$DIR/$tdir/$tfile-1"
1889 wait_delete_completed
1891 # every quota slave gets 20MB
1892 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1893 log "limit: ${b_limit}KB"
1894 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1896 quota_show_check b u $TSTUSR
1898 $LFS setstripe $TESTFILE -c 1 -i 0
1899 $LFS setstripe $TESTFILE2 -c 1 -i 0
1900 chown $TSTUSR.$TSTUSR $TESTFILE
1901 chown $TSTUSR.$TSTUSR $TESTFILE2
1903 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1904 lustre_fail ost 0xA03
1906 log " Write the first file..."
1907 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1908 log " Delete the first file..."
1912 wait_delete_completed
1914 log " Write the second file..."
1915 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1916 log " Delete the second file..."
1920 set_blk_unitsz $((128 * 1024))
1921 set_blk_tunesz $((128 * 1024 / 2))
1922 resetquota -u $TSTUSR
1924 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1927 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1928 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1931 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1934 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1935 error "lfs setquota failed with uid argument"
1936 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1937 error "lfs stequota failed with gid argument"
1938 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1939 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1940 resetquota -u $TSTUSR
1941 resetquota -g $TSTUSR
1944 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1947 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1948 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1949 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1952 echo "Step 2: reset system ..."
1953 cleanup_and_setup_lustre
1956 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1960 wait_delete_completed
1962 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1963 lustre_fail ost 0x80000A02
1965 TESTFILE="$DIR/$tdir/$tfile"
1968 BLK_LIMIT=$((100 * 1024)) # 100M
1969 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1970 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1974 chown $TSTUSR.$TSTUSR $TESTFILE
1976 echo "Step 5: write the test file1 [10M] ..."
1977 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1978 || quota_error a $TSTUSR "write 10M file failure"
1982 sync; sleep 3; sync;
1984 # make qd_count 64 bit
1987 set_blk_unitsz $((128 * 1024))
1988 set_blk_tunesz $((128 * 1024 / 2))
1990 resetquota -u $TSTUSR
1992 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
1996 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2000 if at_is_enabled; then
2001 timeout=$(at_max_get client)
2002 at_max_set 10 client
2004 timeout=$(lctl get_param -n timeout)
2005 lctl set_param timeout=10
2008 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2009 lustre_fail mds 0x12e
2011 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2013 echo "sleeping for $((10 * 2)) seconds"
2015 ps -p $pid && error "lfs hadn't finished by timeout"
2016 wait $pid && error "succeeded, but should have failed"
2020 if at_is_enabled; then
2021 at_max_set $timeout client
2023 lctl set_param timeout=$timeout
2026 resetquota -u $TSTUSR
2028 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2034 local TESTFILE="$DIR/$tdir/$tfile"
2041 chmod 0777 $DIR/$tdir
2043 $LFS setstripe $TESTFILE -i 0 -c 1
2044 chown $TSTUSR.$TSTUSR $TESTFILE
2046 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2047 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2048 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2049 cancel_lru_locks osc
2051 $LFS setquota -u $TSTUSR -B 0 $DIR
2052 # over-quota flag has not yet settled since we do not trigger async events
2053 # based on grace time period expiration
2055 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2056 cancel_lru_locks osc
2057 # now over-quota flag should be settled and further writes should fail
2059 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2061 resetquota -u $TSTUSR
2062 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2064 set_blk_unitsz $((128 * 1024))
2065 set_blk_tunesz $((128 * 1024 / 2))
2067 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2069 # test duplicate quota releases b=18630
2072 chmod 0777 $DIR/$tdir
2074 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2075 TESTFILE="$DIR/$tdir/$tfile-0"
2076 TESTFILE2="$DIR/$tdir/$tfile-1"
2078 wait_delete_completed
2080 log " User quota (limit: $LIMIT kbytes)"
2081 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2083 $LFS setstripe $TESTFILE -i 0 -c 1
2084 chown $TSTUSR.$TSTUSR $TESTFILE
2085 $LFS setstripe $TESTFILE2 -i 0 -c 1
2086 chown $TSTUSR.$TSTUSR $TESTFILE2
2088 log " step1: write out of block quota ..."
2089 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2090 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2092 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2093 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2094 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2096 log " step2: delete two files so that triggering duplicate quota release ..."
2097 rm -f $TESTFILE $TESTFILE2
2098 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2099 wait_delete_completed
2101 log " step3: verify if the ost failed"
2102 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2103 watchdog=`awk '/test 31/ {start = 1;}
2104 /release quota error/ {
2108 }' $TMP/lustre-log-${TESTNAME}.log`
2109 [ "$watchdog" ] && error "$watchdog"
2110 rm -f $TMP/lustre-log-${TESTNAME}.log
2113 resetquota -u $TSTUSR
2115 run_test_with_stat 31 "test duplicate quota releases ==="
2117 # check hash_cur_bits
2118 check_quota_hash_cur_bits() {
2121 # check quota_hash_cur_bits on all obdfilters
2122 for num in `seq $OSTCOUNT`; do
2123 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2124 if [ $cb -gt $bits ]; then
2125 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2129 # check quota_hash_cur_bits on mds
2130 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2131 if [ $cb -gt $bits ]; then
2132 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2140 # check distribution of all obdfilters
2141 for num in `seq $OSTCOUNT`; do
2142 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2143 rehash_count=`echo $line | awk '{print $9}'`
2144 if [ $rehash_count -eq 0 ]; then
2145 echo -e "ost$num:\n $line"
2146 error "Rehearsh didn't happen"
2150 # check distribution of mds
2151 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2152 rehash_count=`echo $line | awk '{print $9}'`
2153 if [ $rehash_count -eq 0 ]; then
2154 echo -e "mdt:\n $line"
2155 error "Rehearsh didn't happen"
2162 # reset system so that quota_hash_cur_bits==3
2163 echo "Reset system ..."
2164 local LMR_orig=$LOAD_MODULES_REMOTE
2165 LOAD_MODULES_REMOTE=true
2166 cleanup_and_setup_lustre
2167 LOAD_MODULES_REMOTE=$LMR_orig
2169 for user in $SANITY_QUOTA_USERS; do
2170 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2171 missing_users="$missing_users $user"
2173 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2174 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2176 $LFS quotaoff -ug $DIR
2177 $LFS quotacheck -ug $DIR
2179 for user in $SANITY_QUOTA_USERS; do
2180 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2185 for user in $SANITY_QUOTA_USERS; do
2189 run_test 32 "check lqs hash(bug 21846) =========================================="
2195 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2199 log "cleanup: ======================================================"
2201 check_and_cleanup_lustre
2202 echo '=========================== finished ==============================='
2203 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2204 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2205 echo "$0: completed"