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=$(((100 + $OSTCOUNT * 3) * 1024))
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
1472 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
1495 resetquota -u $TSTUSR
1496 set_blk_unitsz $((128 * 1024))
1497 set_blk_tunesz $((128 * 1024 / 2))
1498 testfile_size=$(stat -c %s $TESTFILE)
1499 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1501 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1507 # test when mds does failover, the ost still could work well
1508 # this test shouldn't trigger watchdog b=14840
1510 test_18bc_sub normal
1511 test_18bc_sub directio
1512 # check if watchdog is triggered
1513 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1514 watchdog=`awk '/test 18b/ {start = 1;}
1515 /Service thread pid/ && /was inactive/ {
1519 }' $TMP/lustre-log-${TESTNAME}.log`
1520 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1521 rm -f $TMP/lustre-log-${TESTNAME}.log
1523 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1525 # test when mds does failover, the ost still could work well
1526 # this test will prevent OST_DISCONNET from happening b=14840
1528 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1529 lustre_fail ost 0x202
1530 test_18bc_sub normal
1531 test_18bc_sub directio
1534 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1536 run_to_block_limit() {
1537 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1539 wait_delete_completed
1541 # set 1 Mb quota unit size
1545 # bind file to a single OST
1546 $LFS setstripe -c 1 $TESTFILE
1547 chown $TSTUSR.$TSTUSR $TESTFILE
1549 echo " User quota (limit: $LIMIT kbytes)"
1550 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1551 quota_show_check b u $TSTUSR
1552 echo " Updating quota limits"
1553 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1554 quota_show_check b u $TSTUSR
1556 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1557 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1558 # for now page cache of TESTFILE may still be dirty,
1559 # let's push it to the corresponding OST, this will also
1560 # cache NOQUOTA on the client from OST's reply
1561 cancel_lru_locks osc
1562 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1566 # 1 Mb bunit per each MDS/OSS
1567 local TESTFILE="$DIR/$tdir/$tfile"
1570 run_to_block_limit $TESTFILE
1575 resetquota -u $TSTUSR
1577 set_blk_unitsz $((128 * 1024))
1578 set_blk_tunesz $((128 * 1024 / 2))
1581 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1585 LSTR=(1t 2g 3m 4k) # limits strings
1586 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1588 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1589 $MOUNT || error "could not set quota limits"
1591 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1592 --inode-softlimit ${LSTR[2]} \
1593 --inode-hardlimit ${LSTR[3]} \
1594 $MOUNT || error "could not set quota limits"
1596 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1597 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1598 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1599 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1601 resetquota -u $TSTUSR
1603 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1610 time=$(($(date +%s) + seconds))
1611 while [ $(date +%s) -lt $time ]; do
1612 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1617 # run for fixing bug16053, setquota shouldn't fail when writing and
1618 # deleting are happening
1623 wait_delete_completed
1625 TESTFILE="$DIR/$tdir/$tfile"
1627 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1630 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1631 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1632 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1633 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1635 # repeat writing on a 1M file
1636 test_21_sub ${TESTFILE}_1 1024 30 &
1638 # repeat writing on a 128M file
1639 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1642 time=$(($(date +%s) + 30))
1644 while [ $(date +%s) -lt $time ]; do
1645 log " Set quota for $i times"
1646 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1647 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1654 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1656 if [ $count -gt 60 ]; then
1657 quota_error a $TSTUSR "dd should be finished!"
1661 echo "(dd_pid=$DDPID1, time=$count)successful"
1665 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1667 if [ $count -gt 60 ]; then
1668 quota_error a $TSTUSR "dd should be finished!"
1672 echo "(dd_pid=$DDPID2, time=$count)successful"
1674 set_blk_unitsz $((128 * 1024))
1675 set_blk_tunesz $((128 * 1024 / 2))
1676 resetquota -u $TSTUSR
1677 resetquota -g $TSTUSR
1681 run_test_with_stat 21 "run for fixing bug16053 ==========="
1684 quota_save_version "ug3"
1690 echo "checking parameters"
1692 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1693 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1697 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1701 chmod 0777 $DIR/$tdir
1702 TESTFILE="$DIR/$tdir/$tfile-0"
1704 local bs_unit=$((1024*1024))
1707 wait_delete_completed
1710 log " User quota (limit: $LIMIT kbytes)"
1711 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1713 quota_show_check b u $TSTUSR
1715 $LFS setstripe $TESTFILE -c 1
1716 chown $TSTUSR.$TSTUSR $TESTFILE
1718 log " Step1: trigger quota with 0_DIRECT"
1719 log " Write half of file"
1720 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1721 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1722 log " Write out of block quota ..."
1723 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1724 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1727 log " Step2: rewrite should succeed"
1728 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1729 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1733 wait_delete_completed
1734 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1735 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1736 echo $OST0_QUOTA_USED
1737 [ $OST0_QUOTA_USED -ne 0 ] && \
1738 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1740 resetquota -u $TSTUSR
1744 log "run for $((OSTCOUNT * 4))MB test file"
1745 test_23_sub $((OSTCOUNT * 4 * 1024))
1748 check_whether_skip && return 0
1749 log "run for $((OSTCOUNT * 40))MB test file"
1750 test_23_sub $((OSTCOUNT * 40 * 1024))
1752 run_test_with_stat 23 "run for fixing bug16125 ==========="
1755 local TESTFILE="$DIR/$tdir/$tfile"
1758 run_to_block_limit $TESTFILE
1759 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1763 resetquota -u $TSTUSR
1765 set_blk_unitsz $((128 * 1024))
1766 set_blk_tunesz $((128 * 1024 / 2))
1769 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1772 if [ $1 = "-u" ]; then
1773 if [ $2 = "$TSTUSR" ]; then
1779 if [ $2 = "$TSTUSR" ]; then
1789 chmod 0777 $DIR/$tdir
1790 TESTFILE="$DIR/$tdir/$tfile-0"
1792 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1794 wait_delete_completed
1796 # set quota for $TSTUSR
1797 log "setquota for $TSTUSR"
1798 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1800 if [ "$1" == "-u" ]; then
1801 quota_show_check a u $TSTUSR
1803 quota_show_check a g $TSTUSR
1806 # set quota for $TSTUSR2
1807 log "setquota for $TSTUSR2"
1808 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1810 if [ "$1" == "-u" ]; then
1811 quota_show_check a u $TSTUSR2
1813 quota_show_check a g $TSTUSR2
1816 # set stripe index to 0
1817 log "setstripe for $DIR/$tdir to 0"
1818 $LFS setstripe $DIR/$tdir -c 1 -i 0
1819 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1820 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1821 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1822 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1823 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1824 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1827 log "$TSTUSR write 4M to $TESTFILE"
1828 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1830 show_quota $1 $TSTUSR
1831 show_quota $1 $TSTUSR2
1832 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1833 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1834 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1835 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1836 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1837 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1838 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1840 # chown/chgrp from $TSTUSR to $TSTUSR2
1841 if [ $1 = "-u" ]; then
1842 log "chown from $TSTUSR to $TSTUSR2"
1843 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1845 log "chgrp from $TSTUSR to $TSTUSR2"
1846 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1849 show_quota $1 $TSTUSR
1850 show_quota $1 $TSTUSR2
1851 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1852 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1853 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1854 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1855 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1856 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1857 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1858 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1859 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1860 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1861 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1862 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1863 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1864 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1865 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1868 wait_delete_completed
1869 resetquota $1 $TSTUSR
1870 resetquota $1 $TSTUSR2
1874 log "run for chown case"
1877 log "run for chgrp case"
1880 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1884 chmod 0777 $DIR/$tdir
1885 TESTFILE="$DIR/$tdir/$tfile-0"
1886 TESTFILE2="$DIR/$tdir/$tfile-1"
1890 wait_delete_completed
1892 # every quota slave gets 20MB
1893 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1894 log "limit: ${b_limit}KB"
1895 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1897 quota_show_check b u $TSTUSR
1899 $LFS setstripe $TESTFILE -c 1 -i 0
1900 $LFS setstripe $TESTFILE2 -c 1 -i 0
1901 chown $TSTUSR.$TSTUSR $TESTFILE
1902 chown $TSTUSR.$TSTUSR $TESTFILE2
1904 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1905 lustre_fail ost 0xA03
1907 log " Write the first file..."
1908 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1909 log " Delete the first file..."
1913 wait_delete_completed
1915 log " Write the second file..."
1916 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1917 log " Delete the second file..."
1921 set_blk_unitsz $((128 * 1024))
1922 set_blk_tunesz $((128 * 1024 / 2))
1923 resetquota -u $TSTUSR
1925 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1928 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1929 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1932 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1935 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1936 error "lfs setquota failed with uid argument"
1937 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1938 error "lfs stequota failed with gid argument"
1939 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1940 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1941 resetquota -u $TSTUSR
1942 resetquota -g $TSTUSR
1945 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1948 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1949 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1950 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1953 echo "Step 2: reset system ..."
1954 cleanup_and_setup_lustre
1957 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1961 wait_delete_completed
1963 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1964 lustre_fail ost 0x80000A02
1966 TESTFILE="$DIR/$tdir/$tfile"
1969 BLK_LIMIT=$((100 * 1024)) # 100M
1970 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1971 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1975 chown $TSTUSR.$TSTUSR $TESTFILE
1977 echo "Step 5: write the test file1 [10M] ..."
1978 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1979 || quota_error a $TSTUSR "write 10M file failure"
1983 sync; sleep 3; sync;
1985 # make qd_count 64 bit
1988 set_blk_unitsz $((128 * 1024))
1989 set_blk_tunesz $((128 * 1024 / 2))
1991 resetquota -u $TSTUSR
1993 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
1997 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2001 if at_is_enabled; then
2002 timeout=$(at_max_get client)
2003 at_max_set 10 client
2005 timeout=$(lctl get_param -n timeout)
2006 lctl set_param timeout=10
2009 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2010 lustre_fail mds 0x12e
2012 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2014 echo "sleeping for $((10 * 2)) seconds"
2016 ps -p $pid && error "lfs hadn't finished by timeout"
2017 wait $pid && error "succeeded, but should have failed"
2021 if at_is_enabled; then
2022 at_max_set $timeout client
2024 lctl set_param timeout=$timeout
2027 resetquota -u $TSTUSR
2029 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2035 local TESTFILE="$DIR/$tdir/$tfile"
2042 chmod 0777 $DIR/$tdir
2044 $LFS setstripe $TESTFILE -i 0 -c 1
2045 chown $TSTUSR.$TSTUSR $TESTFILE
2047 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2048 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2049 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2050 cancel_lru_locks osc
2052 $LFS setquota -u $TSTUSR -B 0 $DIR
2053 # over-quota flag has not yet settled since we do not trigger async events
2054 # based on grace time period expiration
2056 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2057 cancel_lru_locks osc
2058 # now over-quota flag should be settled and further writes should fail
2060 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2062 resetquota -u $TSTUSR
2063 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2065 set_blk_unitsz $((128 * 1024))
2066 set_blk_tunesz $((128 * 1024 / 2))
2068 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2070 # test duplicate quota releases b=18630
2073 chmod 0777 $DIR/$tdir
2075 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2076 TESTFILE="$DIR/$tdir/$tfile-0"
2077 TESTFILE2="$DIR/$tdir/$tfile-1"
2079 wait_delete_completed
2081 log " User quota (limit: $LIMIT kbytes)"
2082 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2084 $LFS setstripe $TESTFILE -i 0 -c 1
2085 chown $TSTUSR.$TSTUSR $TESTFILE
2086 $LFS setstripe $TESTFILE2 -i 0 -c 1
2087 chown $TSTUSR.$TSTUSR $TESTFILE2
2089 log " step1: write out of block quota ..."
2090 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2091 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2093 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2094 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2095 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2097 log " step2: delete two files so that triggering duplicate quota release ..."
2098 rm -f $TESTFILE $TESTFILE2
2099 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2100 wait_delete_completed
2102 log " step3: verify if the ost failed"
2103 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2104 watchdog=`awk '/test 31/ {start = 1;}
2105 /release quota error/ {
2109 }' $TMP/lustre-log-${TESTNAME}.log`
2110 [ "$watchdog" ] && error "$watchdog"
2111 rm -f $TMP/lustre-log-${TESTNAME}.log
2114 resetquota -u $TSTUSR
2116 run_test_with_stat 31 "test duplicate quota releases ==="
2118 # check hash_cur_bits
2119 check_quota_hash_cur_bits() {
2122 # check quota_hash_cur_bits on all obdfilters
2123 for num in `seq $OSTCOUNT`; do
2124 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2125 if [ $cb -gt $bits ]; then
2126 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2130 # check quota_hash_cur_bits on mds
2131 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2132 if [ $cb -gt $bits ]; then
2133 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2141 # check distribution of all obdfilters
2142 for num in `seq $OSTCOUNT`; do
2143 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2144 rehash_count=`echo $line | awk '{print $9}'`
2145 if [ $rehash_count -eq 0 ]; then
2146 echo -e "ost$num:\n $line"
2147 error "Rehearsh didn't happen"
2151 # check distribution of mds
2152 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2153 rehash_count=`echo $line | awk '{print $9}'`
2154 if [ $rehash_count -eq 0 ]; then
2155 echo -e "mdt:\n $line"
2156 error "Rehearsh didn't happen"
2163 # reset system so that quota_hash_cur_bits==3
2164 echo "Reset system ..."
2165 local LMR_orig=$LOAD_MODULES_REMOTE
2166 LOAD_MODULES_REMOTE=true
2167 cleanup_and_setup_lustre
2168 LOAD_MODULES_REMOTE=$LMR_orig
2174 for user in $SANITY_QUOTA_USERS; do
2175 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2176 missing_users="$missing_users $user"
2178 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2179 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2181 $LFS quotaoff -ug $DIR
2182 $LFS quotacheck -ug $DIR
2184 for user in $SANITY_QUOTA_USERS; do
2185 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2190 for user in $SANITY_QUOTA_USERS; do
2194 run_test 32 "check lqs hash(bug 21846) =========================================="
2200 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2204 log "cleanup: ======================================================"
2206 check_and_cleanup_lustre
2207 echo '=========================== finished ==============================='
2208 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2209 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2210 echo "$0: completed"