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
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
12 # only accounting tests are supported for the time being
16 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
17 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
18 # We have changed the mechanism of quota, test_12 is meanless now.
20 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
23 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
24 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
30 TSTID2=${TSTID2:-60001}
31 TSTUSR=${TSTUSR:-"quota_usr"}
32 TSTUSR2=${TSTUSR2:-"quota_2usr"}
34 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
35 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
38 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
39 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
40 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
41 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
42 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
44 export MULTIOP=${MULTIOP:-multiop}
46 LUSTRE=${LUSTRE:-`dirname $0`/..}
47 . $LUSTRE/tests/test-framework.sh
49 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
51 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
53 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
55 require_dsh_mds || exit 0
56 require_dsh_ost || exit 0
58 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
60 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
62 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
67 QUOTA_AUTO_OLD=$QUOTA_AUTO
70 check_and_setup_lustre
72 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
73 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
75 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
76 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
77 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
78 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
79 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
80 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
81 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
82 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84 # control the time of tests
86 [ "$SLOW" = "no" ] && cycle=10
90 # Use OFD for all quota testing
91 USE_OFD_OLD="$USE_OFD"
92 LOAD_MODULES_REMOTE_OLD="$LOAD_MODULES_REMOTE"
94 export LOAD_MODULES_REMOTE="true"
95 cleanup_and_setup_lustre
97 # set_blk_tunables(btune_sz)
99 local btune=$(($1 * BLK_SZ))
100 # set btune size on all obdfilters
101 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
102 # set btune size on mds
103 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
106 # set_blk_unitsz(bunit_sz)
108 local bunit=$(($1 * BLK_SZ))
109 # set bunit size on all obdfilters
110 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
111 # set bunit size on mds
112 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
115 # set_file_tunesz(itune_sz)
118 # set itune size on mds
119 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
122 # set_file_unitsz(iunit_sz)
125 # set iunit size on mds
126 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
132 local fail_val=${3:-0}
134 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
135 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
136 [ $((fail_loc)) -eq 0 ]; then
137 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
139 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
141 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
142 for num in `seq $OSTCOUNT`; do
143 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
144 [ $((fail_loc)) -eq 0 ]; then
145 do_facet ost$num "lctl set_param fail_val=$fail_val"
147 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
152 RUNAS="runas -u $TSTID -g $TSTID"
153 RUNAS2="runas -u $TSTID2 -g $TSTID2"
154 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
155 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
159 run_test_with_stat() {
160 (($# != 2)) && error "the number of arguments is wrong"
162 if [ "$USE_OFD" == "yes" ]; then
167 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
168 for j in `seq $OSTCOUNT`; do
169 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
172 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
173 echo "statistics info begin ***************************************"
174 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
175 for j in `seq $OSTCOUNT`; do
176 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
178 echo "statistics info end ***************************************"
183 # clear quota limits for a user or a group
184 # usage: resetquota -u username
185 # resetquota -g groupname
188 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
189 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
192 if at_is_enabled; then
193 timeout=$(at_max_get mds)
195 timeout=$(lctl get_param -n timeout)
198 while [ $((count++)) -lt $timeout ]; do
200 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
201 if [ $RC -ne 0 ]; then
202 if echo "$OUTPUT" | grep -q busy; then
203 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
207 error "resetquota failed"
213 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
220 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
221 log "Files for user ($LOCAL_ID):"
222 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
225 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
226 log "Files for group ($LOCAL_ID):"
227 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
244 # get quota info for a user or a group
245 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
251 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
252 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
265 *) error "unknown quota parameter $4";;
268 [ "$uuid" = "global" ] && uuid=$DIR
270 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
277 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
279 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
281 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
282 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
283 if [ -z $USAGE ]; then
284 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
286 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
290 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
291 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
292 if [ -z $USAGE ]; then
293 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
295 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
302 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
304 # log "do the quotacheck ..."
305 # $LFS quotacheck -ug $DIR
307 # resetquota -u $TSTUSR
308 # resetquota -g $TSTUSR
312 test_quota_performance() {
313 TESTFILE="$DIR/$tdir/$tfile-0"
315 local stime=`date +%s`
316 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
317 local etime=`date +%s`
318 delta=$((etime - stime))
319 if [ $delta -gt 0 ]; then
320 rate=$((size * 1024 / delta))
321 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
326 # test basic quota performance b=21696
329 chmod 0777 $DIR/$tdir
331 [ "$SLOW" = "no" ] && MB=10
333 test_quota_performance $MB
335 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
336 test_quota_performance $MB
338 resetquota -u $TSTUSR
340 run_test_with_stat 0 "Test basic quota performance ==="
342 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
346 chmod 0777 $DIR/$tdir
347 TESTFILE="$DIR/$tdir/$tfile-0"
349 wait_delete_completed
352 log " User quota (limit: $LIMIT kbytes)"
353 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
355 quota_show_check b u $TSTUSR
357 $LFS setstripe $TESTFILE -c 1
358 chown $TSTUSR.$TSTUSR $TESTFILE
361 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
363 log " Write out of block quota ..."
364 # this time maybe cache write, ignore it's failure
365 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
366 # flush cache, ensure noquota flag is setted on client
368 $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"
372 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
373 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
374 echo $OST0_QUOTA_USED
375 [ $OST0_QUOTA_USED -ne 0 ] && \
376 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
378 resetquota -u $TSTUSR
381 log "--------------------------------------"
382 log " Group quota (limit: $LIMIT kbytes)"
383 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
385 quota_show_check b g $TSTUSR
386 TESTFILE="$DIR/$tdir/$tfile-1"
388 $LFS setstripe $TESTFILE -c 1
389 chown $TSTUSR.$TSTUSR $TESTFILE
392 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
394 log " Write out of block quota ..."
395 # this time maybe cache write, ignore it's failure
396 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
398 $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"
403 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
404 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
405 echo $OST0_QUOTA_USED
406 [ $OST0_QUOTA_USED -ne 0 ] && \
407 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
409 resetquota -g $TSTUSR
412 # block hard limit (normal use and out of quota)
414 for i in `seq 1 $cycle`; do
415 # define blk_qunit is between 1M and 4M
416 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
417 blk_qtune=$(( $RANDOM % $blk_qunit ))
418 # other osts and mds will occupy at 1M blk quota
419 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
420 set_blk_tunesz $blk_qtune
421 set_blk_unitsz $blk_qunit
422 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
424 echo "=================================================="
425 set_blk_unitsz $((128 * 1024))
426 set_blk_tunesz $((128 * 1024 / 2))
429 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
431 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
435 chmod 0777 $DIR/$tdir
436 TESTFILE="$DIR/$tdir/$tfile-0"
438 wait_delete_completed
441 log " User quota (limit: $LIMIT files)"
442 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
444 quota_show_check f u $TSTUSR
446 log " Create $LIMIT files ..."
447 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
448 quota_error u $TSTUSR "(usr) create failure, but expect success"
450 log " Create out of file quota ..."
451 $RUNAS touch ${TESTFILE}_xxx && \
452 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
454 unlinkmany ${TESTFILE} $LIMIT
455 rm -f ${TESTFILE}_xxx
458 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
459 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
461 [ $MDS_QUOTA_USED -ne 0 ] && \
462 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
464 resetquota -u $TSTUSR
467 log "--------------------------------------"
468 log " Group quota (limit: $LIMIT FILE)"
469 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
471 quota_show_check f g $TSTUSR
472 TESTFILE=$DIR/$tdir/$tfile-1
474 log " Create $LIMIT files ..."
475 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
476 quota_error g $TSTUSR "(grp) create failure, but expect success"
478 log " Create out of file quota ..."
479 $RUNAS touch ${TESTFILE}_xxx && \
480 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
482 unlinkmany ${TESTFILE} $LIMIT
483 rm -f ${TESTFILE}_xxx
486 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
487 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
489 [ $MDS_QUOTA_USED -ne 0 ] && \
490 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
492 resetquota -g $TSTUSR
495 # file hard limit (normal use and out of quota)
497 for i in `seq 1 $cycle`; do
498 if [ $i -eq 1 ]; then
503 # define ino_qunit is between 10 and 100
504 ino_qunit=$(( $RANDOM % 90 + 10 ))
505 ino_qtune=$(( $RANDOM % $ino_qunit ))
506 # RANDOM's maxium is 32767
507 i_limit=$(( $RANDOM % 990 + 10 ))
510 set_file_tunesz $ino_qtune
511 set_file_unitsz $ino_qunit
512 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
514 echo "=================================================="
519 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
523 TIMER=$(($2 * 3 / 2))
526 wait_delete_completed
528 echo " Write to exceed soft limit"
529 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
530 $RUNDD count=$((BUNIT_SZ+1)) || \
531 quota_error a $TSTUSR "write failure, but expect success"
532 OFFSET=$((OFFSET + BUNIT_SZ + 1))
537 $SHOW_QUOTA_INFO_USER
538 $SHOW_QUOTA_INFO_GROUP
540 echo " Write before timer goes off"
541 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
542 quota_error a $TSTUSR "write failure, but expect success"
543 OFFSET=$((OFFSET + BUNIT_SZ))
547 echo " Sleep $TIMER seconds ..."
552 $SHOW_QUOTA_INFO_USER
553 $SHOW_QUOTA_INFO_GROUP
555 echo " Write after timer goes off"
556 # maybe cache write, ignore.
557 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
558 OFFSET=$((OFFSET + BUNIT_SZ))
560 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
561 quota_error a $TSTUSR "write success, but expect EDQUOT"
565 $SHOW_QUOTA_INFO_USER
566 $SHOW_QUOTA_INFO_GROUP
568 echo " Unlink file to stop timer"
575 $SHOW_QUOTA_INFO_USER
576 $SHOW_QUOTA_INFO_GROUP
579 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
587 # block soft limit (start timer, timer goes off, stop timer)
590 chmod 0777 $DIR/$tdir
592 # 1 bunit on mds and 1 bunit on every ost
593 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
596 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
597 TESTFILE=$DIR/$tdir/$tfile-0
599 $LFS setstripe $TESTFILE -c 1
600 chown $TSTUSR.$TSTUSR $TESTFILE
602 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
603 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
605 test_block_soft $TESTFILE $GRACE
606 resetquota -u $TSTUSR
608 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
609 TESTFILE=$DIR/$tdir/$tfile-1
611 $LFS setstripe $TESTFILE -c 1
612 chown $TSTUSR.$TSTUSR $TESTFILE
614 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
615 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
617 test_block_soft $TESTFILE $GRACE
618 resetquota -g $TSTUSR
620 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
625 TIMER=$(($3 * 3 / 2))
627 wait_delete_completed
629 echo " Create files to exceed soft limit"
630 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
631 quota_error a $TSTUSR "create failure, but expect success"
635 echo " Create file before timer goes off"
636 $RUNAS touch ${TESTFILE}_before || \
637 quota_error a $TSTUSR "failed create before timer expired, but expect success"
641 echo " Sleep $TIMER seconds ..."
646 $SHOW_QUOTA_INFO_USER
647 $SHOW_QUOTA_INFO_GROUP
649 echo " Create file after timer goes off"
650 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
651 # inode quota left here
652 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
654 $RUNAS touch ${TESTFILE}_after3 && \
655 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
660 $SHOW_QUOTA_INFO_USER
661 $SHOW_QUOTA_INFO_GROUP
663 echo " Unlink files to stop timer"
664 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
668 $RUNAS touch ${TESTFILE}_xxx || \
669 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
674 rm -f ${TESTFILE}_xxx
678 # file soft limit (start timer, timer goes off, stop timer)
679 test_4a() { # was test_4
681 chmod 0777 $DIR/$tdir
682 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
683 TESTFILE=$DIR/$tdir/$tfile-0
687 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
688 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
689 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
690 quota_show_check f u $TSTUSR
692 test_file_soft $TESTFILE $LIMIT $GRACE
693 resetquota -u $TSTUSR
695 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
696 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
697 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
698 quota_show_check f g $TSTUSR
699 TESTFILE=$DIR/$tdir/$tfile-1
701 test_file_soft $TESTFILE $LIMIT $GRACE
702 resetquota -g $TSTUSR
705 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
706 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
708 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
710 test_4b() { # was test_4a
716 GR_STR6="1111111111111111"
718 wait_delete_completed
720 # test of valid grace strings handling
721 echo " Valid grace strings test"
722 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
723 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
724 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
725 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
727 # test of invalid grace strings handling
728 echo " Invalid grace strings test"
729 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
730 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
733 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
734 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
736 run_test_with_stat 4b "Grace time strings handling ==="
738 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
741 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
742 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
744 wait_delete_completed
746 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
747 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
748 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
749 quota_show_check a u $TSTUSR
750 quota_show_check a g $TSTUSR
752 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
753 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
754 error "touch failure, expect success"
755 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
757 echo " Chown files to $TSTUSR.$TSTUSR ..."
758 for i in `seq 0 $ILIMIT`; do
759 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
760 quota_error a $TSTUSR "chown failure, but expect success"
764 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
767 resetquota -u $TSTUSR
768 resetquota -g $TSTUSR
770 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
772 # block quota acquire & release
774 if [ $OSTCOUNT -lt 2 ]; then
775 skip_env "$OSTCOUNT < 2, too few osts"
779 wait_delete_completed
782 chmod 0777 $DIR/$tdir
784 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
785 FILEA="$DIR/$tdir/$tfile-0_a"
786 FILEB="$DIR/$tdir/$tfile-0_b"
788 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
789 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
790 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
791 quota_show_check b u $TSTUSR
792 quota_show_check b g $TSTUSR
794 echo " Create filea on OST0 and fileb on OST1"
795 $LFS setstripe $FILEA -i 0 -c 1
796 $LFS setstripe $FILEB -i 1 -c 1
797 chown $TSTUSR.$TSTUSR $FILEA
798 chown $TSTUSR.$TSTUSR $FILEB
800 echo " Exceed quota limit ..."
801 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
802 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
803 quota_error a $TSTUSR "write filea failure, but expect success"
808 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
809 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
811 echo " Write to OST1 return EDQUOT"
812 # this write maybe cache write, ignore it's failure
813 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
814 $RUNDD count=$(($BUNIT_SZ * 2)) || true
818 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
819 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
821 echo " Remove filea to let OST0 release quota"
824 if at_is_enabled; then
825 timeout=$(at_max_get mds)
827 timeout=$(lctl get_param -n timeout)
829 count=$((timeout / 5))
830 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
832 while [ $((count--)) -gt 0 ]; do
835 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
836 if [ -z $OST0_QUOTA_HOLD ]; then
837 error "System is error when query quota for block (U:$TSTUSR)."
839 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
845 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
848 while [ $((count--)) -gt 0 ]; do
851 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
852 if [ -z $OST0_QUOTA_HOLD ]; then
853 error "System is error when query quota for block (G:$TSTUSR)."
855 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
861 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
864 echo " Write to OST1"
865 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
866 quota_error a $TSTUSR "write fileb failure, expect success"
873 resetquota -u $TSTUSR
874 resetquota -g $TSTUSR
877 run_test_with_stat 6 "Block quota acquire & release ========="
879 # quota recovery (block quota only by now)
883 chmod 0777 $DIR/$tdir
885 wait_delete_completed
887 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
888 TESTFILE="$DIR/$tdir/$tfile-0"
890 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
892 $LFS setstripe $TESTFILE -c 1
893 chown $TSTUSR.$TSTUSR $TESTFILE
895 echo " Write to OST0..."
896 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
897 quota_error u $TSTUSR "write failure, but expect success"
899 #define OBD_FAIL_OBD_DQACQ 0x604
900 lustre_fail mds 0x604
901 echo " Remove files on OST0"
905 echo " Trigger recovery..."
906 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
907 for i in $OSC0_UUID; do
908 $LCTL --device $i activate || error "activate osc failed!"
911 # sleep a while to wait for recovery done
915 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
916 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
917 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
918 echo " total limits = $TOTAL_LIMIT"
920 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
921 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
922 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
923 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
924 echo " limits on $OST0_UUID = $OST0_LIMIT"
927 resetquota -u $TSTUSR
929 run_test_with_stat 7 "Quota recovery (only block limit) ======"
931 # run dbench with quota enabled
934 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
937 wait_delete_completed
939 echo " Set enough high limit for user: $TSTUSR"
940 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
941 echo " Set enough high limit for group: $TSTUSR"
942 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
944 chmod 0777 $DIR/$tdir
946 [ "$SLOW" = "no" ] && duration=" -t 120"
947 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
954 run_test_with_stat 8 "Run dbench with quota enabled ==========="
956 # run for fixing bug10707, it needs a big room. test for 64bit
958 GB=$((KB * 1024 * 1024))
959 # Use this as dd bs to decrease time
960 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
961 blksize=$((1 << 21)) # 2Mb
962 size_file=$((GB * 9 / 2))
963 # this check is just for test_9
964 OST0_MIN=4900000 #4.67G
965 check_whether_skip () {
966 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
967 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
968 if [ $OST0_SIZE -lt $OST0_MIN ]; then
969 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
977 check_whether_skip && return 0
979 wait_delete_completed
985 chmod 0777 $DIR/$tdir
986 TESTFILE="$DIR/$tdir/$tfile-0"
988 BLK_LIMIT=$((100 * KB * KB)) # 100G
990 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
992 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
993 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
994 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
995 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
997 quota_show_check a u $TSTUSR
998 quota_show_check a g $TSTUSR
1001 $LFS setstripe $TESTFILE -c 1 -i 0
1003 chown $TSTUSR.$TSTUSR $TESTFILE
1005 log " Write the big file of 4.5G ..."
1006 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1007 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1012 log " delete the big file of 4.5G..."
1013 $RUNAS rm -f $TESTFILE
1014 sync; sleep 3; sync;
1021 set_blk_unitsz $((128 * 1024))
1022 set_blk_tunesz $((128 * 1024 / 2))
1026 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1028 # 2.0 version does not support 32 bit qd_count,
1029 # test_10 "run for fixing bug10707(32bit) " is obsolete
1031 # test a deadlock between quota and journal b=11693
1034 chmod 0777 $DIR/$tdir
1036 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1037 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1039 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1040 TESTFILE="$DIR/$tdir/$tfile-0"
1041 TESTFILE2="$DIR2/$tdir/$tfile-1"
1043 wait_delete_completed
1045 echo " User quota (limit: $LIMIT kbytes)"
1046 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1048 $LFS setstripe $TESTFILE -i 0 -c 1
1049 chown $TSTUSR.$TSTUSR $TESTFILE
1050 $LFS setstripe $TESTFILE2 -i 0 -c 1
1051 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1053 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1054 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1055 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1057 echo " step1: write out of block quota ..."
1058 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1060 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1063 echo " step2: testing ......"
1064 local last_size=$(stat -c %s $TESTFILE2)
1066 local start_secs=$SECONDS
1067 while [ -d /proc/${DDPID1} ]; do
1068 local size=$(stat -c %s $TESTFILE2)
1069 if [ $size -eq $last_size ]; then
1070 stall_secs=$[stall_secs+1]
1074 if [ $stall_secs -gt 30 ]; then
1076 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1081 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1083 #Recover fail_loc and dd will finish soon
1086 echo " step3: testing ......"
1089 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1091 if [ $count -gt 150 ]; then
1092 quota_error u $TSTUSR "dd should be finished!"
1096 echo "(dd_pid=$DDPID, time=$count)successful"
1098 rm -f $TESTFILE $TESTFILE2
1099 sync; sleep 3; sync;
1101 resetquota -u $TSTUSR
1103 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1105 # test multiple clients write block quota b=11693
1108 wait_delete_completed
1110 # one OST * 10 + (mds + other OSTs)
1111 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1112 TESTFILE="$DIR/$tdir/$tfile"
1114 echo " User quota (limit: $LIMIT kbytes)"
1115 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1116 quota_show_check b u $TSTUSR
1118 $LFS setstripe $TESTFILE -i 0 -c 1
1119 chown $TSTUSR.$TSTUSR $TESTFILE
1120 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1121 chown $TSTUSR.$TSTUSR $TESTFILE.2
1123 echo " step1: write out of block quota ..."
1124 # one bunit will give mds
1125 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1127 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1130 echo " step2: testing ......"
1133 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1135 if [ $count -gt 64 ]; then
1136 quota_error u $TSTUSR "dd should be finished!"
1140 echo "(dd_pid=$DDPID, time=$count)successful"
1144 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1146 if [ $count -gt 64 ]; then
1147 quota_error u $TSTUSR "dd should be finished!"
1151 echo "(dd_pid=$DDPID1, time=$count)successful"
1153 sync; sleep 5; sync;
1155 echo " step3: checking ......"
1156 fz=`stat -c %s $TESTFILE`
1157 fz2=`stat -c %s $TESTFILE.2`
1159 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1160 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1162 rm -f $TESTFILE $TESTFILE.2
1163 sync; sleep 3; sync;
1165 resetquota -u $TSTUSR
1167 run_test_with_stat 13 "test multiple clients write block quota ==="
1169 check_if_quota_zero(){
1170 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1171 for i in `seq 3 $line`; do
1172 if [ $i -eq 3 ]; then
1178 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1179 awk '{print $'"$j"'}'`
1180 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1181 error "quota on $2 isn't clean"
1184 echo "pass check_if_quota_zero"
1187 test_14a() { # was test_14 b=12223 -- setting quota on root
1188 TESTFILE="$DIR/$tdir/$tfile"
1192 cleanup_and_setup_lustre
1197 # out of root's file and block quota
1198 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1199 createmany -m ${TESTFILE} 20 || \
1200 quota_error u root "unexpected: user(root) create files failly!"
1201 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1202 quota_error u root "unexpected: user(root) write files failly!"
1204 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1205 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1209 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1210 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1213 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1215 #check_if_quota_zero u root
1218 unlinkmany ${TESTFILE} 15
1220 sync; sleep 3; sync;
1222 run_test_with_stat 14a "test setting quota on root ==="
1225 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1226 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1228 wait_delete_completed
1231 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1232 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1233 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1234 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1235 resetquota -u $TSTUSR
1238 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1239 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1240 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1241 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1242 resetquota -g $TSTUSR
1243 $LFS quotaoff -ug $DIR
1244 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1245 error "fail to set version for $SINGLEMDS"
1246 for j in `seq $OSTCOUNT`; do
1247 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1248 error "fail to set version for ost$j"
1251 $LFS quotacheck -ug $DIR
1253 run_test_with_stat 15 "set block quota more than 4T ==="
1255 # 2.0 version does not support WITHOUT_CHANGE_QS,
1256 # test_16 "test without adjusting qunit" is obsolete
1258 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1263 wait_delete_completed
1265 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1266 lustre_fail ost 0x80000A02
1268 TESTFILE="$DIR/$tdir/$tfile-a"
1269 TESTFILE2="$DIR/$tdir/$tfile-b"
1272 BLK_LIMIT=$((100 * 1024)) # 100M
1274 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1275 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1276 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1277 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1279 quota_show_check b u $TSTUSR
1280 quota_show_check b g $TSTUSR
1283 chown $TSTUSR.$TSTUSR $TESTFILE
1285 chown $TSTUSR.$TSTUSR $TESTFILE2
1287 log " Write the test file1 ..."
1288 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1289 || quota_error a $TSTUSR "write 10M file failure"
1294 log " write the test file2 ..."
1295 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1296 || quota_error a $TSTUSR "write 10M file failure"
1301 rm -f $TESTFILE $TESTFILE2
1303 sync; sleep 3; sync;
1305 # make qd_count 64 bit
1308 set_blk_unitsz $((128 * 1024))
1309 set_blk_tunesz $((128 * 1024 / 2))
1311 resetquota -u $TSTUSR
1312 resetquota -g $TSTUSR
1316 run_test_with_stat 17 "run for fixing bug14526 ==========="
1318 # test when mds takes a long time to handle a quota req so that
1319 # the ost has dropped it, the ost still could work well b=14840
1321 LIMIT=$((100 * 1024 * 1024)) # 100G
1322 TESTFILE="$DIR/$tdir/$tfile"
1325 wait_delete_completed
1330 log " User quota (limit: $LIMIT kbytes)"
1331 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1332 quota_show_check b u $TSTUSR
1334 $LFS setstripe $TESTFILE -i 0 -c 1
1335 chown $TSTUSR.$TSTUSR $TESTFILE
1337 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1338 lustre_fail mds 0x13c
1340 log " step1: write 100M block ..."
1341 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1347 echo " step2: testing ......"
1349 if at_is_enabled; then
1350 timeout=$(at_max_get mds)
1352 timeout=$(lctl get_param -n timeout)
1355 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1357 if [ $count -gt $((4 * $timeout)) ]; then
1358 quota_error u $TSTUSR "count=$count dd should be finished!"
1362 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1364 cancel_lru_locks mdc
1365 cancel_lru_locks osc
1367 testfile_size=$(stat -c %s $TESTFILE)
1368 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1369 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1374 resetquota -u $TSTUSR
1375 set_blk_unitsz $((128 * 1024))
1376 set_blk_tunesz $((128 * 1024 / 2))
1378 run_test_with_stat 18 "run for fixing bug14840 ==========="
1380 # test when mds drops a quota req, the ost still could work well b=14840
1382 LIMIT=$((100 * 1024 * 1024)) # 100G
1383 TESTFILE="$DIR/$tdir/$tfile-a"
1386 wait_delete_completed
1391 log " User quota (limit: $LIMIT kbytes)"
1392 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1393 quota_show_check b u $TSTUSR
1395 $LFS setstripe $TESTFILE -i 0 -c 1
1396 chown $TSTUSR.$TSTUSR $TESTFILE
1398 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1399 lustre_fail mds 0x8000013d
1401 log " step1: write 100M block ..."
1402 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1405 echo " step2: testing ......"
1407 if at_is_enabled; then
1408 timeout=$(at_max_get mds)
1410 timeout=$(lctl get_param -n timeout)
1413 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1415 if [ $count -gt $((6 * $timeout)) ]; then
1417 quota_error u $TSTUSR "count=$count dd should be finished!"
1421 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1427 resetquota -u $TSTUSR
1428 set_blk_unitsz $((128 * 1024))
1429 set_blk_tunesz $((128 * 1024 / 2))
1431 run_test_with_stat 18a "run for fixing bug14840 ==========="
1433 # test when mds do failover, the ost still could work well without trigger
1438 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1439 TESTFILE="$DIR/$tdir/$tfile"
1442 wait_delete_completed
1447 log " User quota (limit: $LIMIT kbytes)"
1448 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1449 quota_show_check b u $TSTUSR
1451 $LFS setstripe $TESTFILE -i 0 -c 1
1452 chown $TSTUSR.$TSTUSR $TESTFILE
1454 timeout=$(sysctl -n lustre.timeout)
1456 if [ $type = "directio" ]; then
1457 log " write 100M block(directio) ..."
1458 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1460 log " write 100M block(normal) ..."
1461 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1465 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1467 replay_barrier $SINGLEMDS
1469 log "failing mds for $((2 * timeout)) seconds"
1470 fail $SINGLEMDS $((2 * timeout))
1472 # check if quotaon successful
1473 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1474 if [ $? -eq 0 ]; then
1476 error "quotaon failed!"
1481 if at_is_enabled; then
1482 timeout=$(at_max_get mds)
1484 timeout=$(lctl get_param -n timeout)
1487 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1488 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1489 log "it took $count second"
1493 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1495 cancel_lru_locks mdc
1496 cancel_lru_locks osc
1499 resetquota -u $TSTUSR
1500 set_blk_unitsz $((128 * 1024))
1501 set_blk_tunesz $((128 * 1024 / 2))
1502 testfile_size=$(stat -c %s $TESTFILE)
1503 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1505 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1511 # test when mds does failover, the ost still could work well
1512 # this test shouldn't trigger watchdog b=14840
1514 test_18bc_sub normal
1515 test_18bc_sub directio
1516 # check if watchdog is triggered
1517 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1518 watchdog=`awk '/test 18b/ {start = 1;}
1519 /Service thread pid/ && /was inactive/ {
1523 }' $TMP/lustre-log-${TESTNAME}.log`
1524 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1525 rm -f $TMP/lustre-log-${TESTNAME}.log
1527 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1529 # test when mds does failover, the ost still could work well
1530 # this test will prevent OST_DISCONNET from happening b=14840
1532 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1533 lustre_fail ost 0x202
1534 test_18bc_sub normal
1535 test_18bc_sub directio
1538 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1540 run_to_block_limit() {
1541 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1543 wait_delete_completed
1545 # set 1 Mb quota unit size
1549 # bind file to a single OST
1550 $LFS setstripe -c 1 $TESTFILE
1551 chown $TSTUSR.$TSTUSR $TESTFILE
1553 echo " User quota (limit: $LIMIT kbytes)"
1554 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1555 quota_show_check b u $TSTUSR
1556 echo " Updating quota limits"
1557 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1558 quota_show_check b u $TSTUSR
1560 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1561 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1562 # for now page cache of TESTFILE may still be dirty,
1563 # let's push it to the corresponding OST, this will also
1564 # cache NOQUOTA on the client from OST's reply
1565 cancel_lru_locks osc
1566 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1570 # 1 Mb bunit per each MDS/OSS
1571 local TESTFILE="$DIR/$tdir/$tfile"
1574 run_to_block_limit $TESTFILE
1579 resetquota -u $TSTUSR
1581 set_blk_unitsz $((128 * 1024))
1582 set_blk_tunesz $((128 * 1024 / 2))
1585 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1589 LSTR=(1t 2g 3m 4k) # limits strings
1590 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1592 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1593 $MOUNT || error "could not set quota limits"
1595 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1596 --inode-softlimit ${LSTR[2]} \
1597 --inode-hardlimit ${LSTR[3]} \
1598 $MOUNT || error "could not set quota limits"
1600 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1601 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1602 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1603 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1605 resetquota -u $TSTUSR
1607 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1614 time=$(($(date +%s) + seconds))
1615 while [ $(date +%s) -lt $time ]; do
1616 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1621 # run for fixing bug16053, setquota shouldn't fail when writing and
1622 # deleting are happening
1627 wait_delete_completed
1629 TESTFILE="$DIR/$tdir/$tfile"
1631 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1634 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1635 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1636 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1637 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1639 # repeat writing on a 1M file
1640 test_21_sub ${TESTFILE}_1 1024 30 &
1642 # repeat writing on a 128M file
1643 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1646 time=$(($(date +%s) + 30))
1648 while [ $(date +%s) -lt $time ]; do
1649 log " Set quota for $i times"
1650 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1651 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1658 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1660 if [ $count -gt 60 ]; then
1661 quota_error a $TSTUSR "dd should be finished!"
1665 echo "(dd_pid=$DDPID1, time=$count)successful"
1669 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1671 if [ $count -gt 60 ]; then
1672 quota_error a $TSTUSR "dd should be finished!"
1676 echo "(dd_pid=$DDPID2, time=$count)successful"
1678 set_blk_unitsz $((128 * 1024))
1679 set_blk_tunesz $((128 * 1024 / 2))
1680 resetquota -u $TSTUSR
1681 resetquota -g $TSTUSR
1685 run_test_with_stat 21 "run for fixing bug16053 ==========="
1688 quota_save_version "ug3"
1694 echo "checking parameters"
1696 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1697 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1701 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1705 chmod 0777 $DIR/$tdir
1706 TESTFILE="$DIR/$tdir/$tfile-0"
1708 local bs_unit=$((1024*1024))
1711 wait_delete_completed
1714 log " User quota (limit: $LIMIT kbytes)"
1715 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1717 quota_show_check b u $TSTUSR
1719 $LFS setstripe $TESTFILE -c 1 -i 0
1720 chown $TSTUSR.$TSTUSR $TESTFILE
1722 log " Step1: trigger quota with 0_DIRECT"
1723 log " Write half of file"
1724 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1725 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1726 log " Write out of block quota ..."
1727 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1728 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1731 log " Step2: rewrite should succeed"
1732 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1733 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1737 wait_delete_completed
1738 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1739 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1740 echo $OST0_QUOTA_USED
1741 [ $OST0_QUOTA_USED -ne 0 ] && \
1742 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1744 resetquota -u $TSTUSR
1748 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1750 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1751 check_whether_skip && return 0
1752 log "run for $((4 * $slave_cnt))MB test file"
1753 test_23_sub $((4 * $slave_cnt * 1024))
1755 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1756 check_whether_skip && return 0
1757 log "run for $((40 * $slave_cnt))MB test file"
1758 test_23_sub $((40 * $slave_cnt * 1024))
1760 run_test_with_stat 23 "run for fixing bug16125 ==========="
1763 local TESTFILE="$DIR/$tdir/$tfile"
1766 run_to_block_limit $TESTFILE
1767 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1771 resetquota -u $TSTUSR
1773 set_blk_unitsz $((128 * 1024))
1774 set_blk_tunesz $((128 * 1024 / 2))
1777 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1780 if [ $1 = "-u" ]; then
1781 if [ $2 = "$TSTUSR" ]; then
1787 if [ $2 = "$TSTUSR" ]; then
1797 chmod 0777 $DIR/$tdir
1798 TESTFILE="$DIR/$tdir/$tfile-0"
1800 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1802 wait_delete_completed
1804 # set quota for $TSTUSR
1805 log "setquota for $TSTUSR"
1806 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1808 if [ "$1" == "-u" ]; then
1809 quota_show_check a u $TSTUSR
1811 quota_show_check a g $TSTUSR
1814 # set quota for $TSTUSR2
1815 log "setquota for $TSTUSR2"
1816 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1818 if [ "$1" == "-u" ]; then
1819 quota_show_check a u $TSTUSR2
1821 quota_show_check a g $TSTUSR2
1824 # set stripe index to 0
1825 log "setstripe for $DIR/$tdir to 0"
1826 $LFS setstripe $DIR/$tdir -c 1 -i 0
1827 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1828 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1829 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1830 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1831 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1832 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1835 log "$TSTUSR write 4M to $TESTFILE"
1836 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1838 show_quota $1 $TSTUSR
1839 show_quota $1 $TSTUSR2
1840 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1841 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1842 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1843 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1844 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1845 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1846 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1848 # chown/chgrp from $TSTUSR to $TSTUSR2
1849 if [ $1 = "-u" ]; then
1850 log "chown from $TSTUSR to $TSTUSR2"
1851 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1853 log "chgrp from $TSTUSR to $TSTUSR2"
1854 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1857 show_quota $1 $TSTUSR
1858 show_quota $1 $TSTUSR2
1859 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1860 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1861 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1862 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1863 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1864 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1865 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1866 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1867 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1868 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1869 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1870 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1871 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1872 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1873 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1876 wait_delete_completed
1877 resetquota $1 $TSTUSR
1878 resetquota $1 $TSTUSR2
1882 log "run for chown case"
1885 log "run for chgrp case"
1888 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1892 chmod 0777 $DIR/$tdir
1893 TESTFILE="$DIR/$tdir/$tfile-0"
1894 TESTFILE2="$DIR/$tdir/$tfile-1"
1898 wait_delete_completed
1900 # every quota slave gets 20MB
1901 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1902 log "limit: ${b_limit}KB"
1903 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1905 quota_show_check b u $TSTUSR
1907 $LFS setstripe $TESTFILE -c 1 -i 0
1908 $LFS setstripe $TESTFILE2 -c 1 -i 0
1909 chown $TSTUSR.$TSTUSR $TESTFILE
1910 chown $TSTUSR.$TSTUSR $TESTFILE2
1912 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1913 lustre_fail ost 0xA03
1915 log " Write the first file..."
1916 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1917 log " Delete the first file..."
1921 wait_delete_completed
1923 log " Write the second file..."
1924 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1925 log " Delete the second file..."
1929 set_blk_unitsz $((128 * 1024))
1930 set_blk_tunesz $((128 * 1024 / 2))
1931 resetquota -u $TSTUSR
1933 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1936 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1937 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1940 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1943 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1944 error "lfs setquota failed with uid argument"
1945 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1946 error "lfs stequota failed with gid argument"
1947 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1948 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1949 resetquota -u $TSTUSR
1950 resetquota -g $TSTUSR
1953 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1956 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1957 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1958 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1961 echo "Step 2: reset system ..."
1962 cleanup_and_setup_lustre
1965 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1969 wait_delete_completed
1971 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1972 lustre_fail ost 0x80000A02
1974 TESTFILE="$DIR/$tdir/$tfile"
1977 BLK_LIMIT=$((100 * 1024)) # 100M
1978 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1979 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1983 chown $TSTUSR.$TSTUSR $TESTFILE
1985 echo "Step 5: write the test file1 [10M] ..."
1986 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1987 || quota_error a $TSTUSR "write 10M file failure"
1991 sync; sleep 3; sync;
1993 # make qd_count 64 bit
1996 set_blk_unitsz $((128 * 1024))
1997 set_blk_tunesz $((128 * 1024 / 2))
1999 resetquota -u $TSTUSR
2001 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2005 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2014 if at_is_enabled; then
2015 timeout=$(at_max_get client)
2016 [ $(at_min_get client) -gt $at_max_val ] &&
2017 at_max_val=$(at_min_get client)
2018 at_max_set $at_max_val client
2020 timeout=$(lctl get_param -n timeout)
2021 lctl set_param timeout=$at_max_val
2023 # actually send a RPC to make service at_current confined within at_max
2024 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR ||
2025 error "should succeed"
2027 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2028 lustre_fail mds 0x12e
2030 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2032 deadline=$((2 * (($at_max_val << 1) + ($at_max_val >> 2) + 5)))
2033 echo "wait at most 2 * ($at_max_val * 2.25 + 5) = $deadline seconds," \
2034 "it is server process time add the network latency."
2037 while [ $waited -lt $deadline ]; do
2040 waited=$(($waited + 1))
2041 ps -p $pid > /dev/null || break
2043 echo "waited $waited seconds"
2044 ps -p $pid && error "lfs hadn't finished by $deadline seconds"
2045 wait $pid && error "succeeded, but should have failed"
2049 if at_is_enabled; then
2050 at_max_set $timeout client
2052 lctl set_param timeout=$timeout
2055 resetquota -u $TSTUSR
2057 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2063 local TESTFILE="$DIR/$tdir/$tfile"
2070 chmod 0777 $DIR/$tdir
2072 $LFS setstripe $TESTFILE -i 0 -c 1
2073 chown $TSTUSR.$TSTUSR $TESTFILE
2075 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2076 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2077 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2078 cancel_lru_locks osc
2080 $LFS setquota -u $TSTUSR -B 0 $DIR
2081 # over-quota flag has not yet settled since we do not trigger async events
2082 # based on grace time period expiration
2084 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2085 cancel_lru_locks osc
2086 # now over-quota flag should be settled and further writes should fail
2088 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2090 resetquota -u $TSTUSR
2091 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2093 set_blk_unitsz $((128 * 1024))
2094 set_blk_tunesz $((128 * 1024 / 2))
2096 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2098 # test duplicate quota releases b=18630
2101 chmod 0777 $DIR/$tdir
2103 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2104 TESTFILE="$DIR/$tdir/$tfile-0"
2105 TESTFILE2="$DIR/$tdir/$tfile-1"
2107 wait_delete_completed
2109 log " User quota (limit: $LIMIT kbytes)"
2110 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2112 $LFS setstripe $TESTFILE -i 0 -c 1
2113 chown $TSTUSR.$TSTUSR $TESTFILE
2114 $LFS setstripe $TESTFILE2 -i 0 -c 1
2115 chown $TSTUSR.$TSTUSR $TESTFILE2
2117 log " step1: write out of block quota ..."
2118 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2119 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2121 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2122 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2123 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2125 log " step2: delete two files so that triggering duplicate quota release ..."
2126 rm -f $TESTFILE $TESTFILE2
2127 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2128 wait_delete_completed
2130 log " step3: verify if the ost failed"
2131 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2132 watchdog=`awk '/test 31/ {start = 1;}
2133 /release quota error/ {
2137 }' $TMP/lustre-log-${TESTNAME}.log`
2138 [ "$watchdog" ] && error "$watchdog"
2139 rm -f $TMP/lustre-log-${TESTNAME}.log
2142 resetquota -u $TSTUSR
2144 run_test_with_stat 31 "test duplicate quota releases ==="
2146 # check hash_cur_bits
2147 check_quota_hash_cur_bits() {
2150 # check quota_hash_cur_bits on all obdfilters
2151 for num in `seq $OSTCOUNT`; do
2152 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2153 if [ $cb -gt $bits ]; then
2154 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2158 # check quota_hash_cur_bits on mds
2159 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2160 if [ $cb -gt $bits ]; then
2161 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2169 # check distribution of all obdfilters
2170 for num in `seq $OSTCOUNT`; do
2171 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2172 rehash_count=`echo $line | awk '{print $9}'`
2173 if [ $rehash_count -eq 0 ]; then
2174 echo -e "ost$num:\n $line"
2175 error "Rehearsh didn't happen"
2179 # check distribution of mds
2180 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2181 rehash_count=`echo $line | awk '{print $9}'`
2182 if [ $rehash_count -eq 0 ]; then
2183 echo -e "mdt:\n $line"
2184 error "Rehearsh didn't happen"
2191 # reset system so that quota_hash_cur_bits==3
2192 echo "Reset system ..."
2193 local LMR_orig=$LOAD_MODULES_REMOTE
2194 LOAD_MODULES_REMOTE=true
2195 cleanup_and_setup_lustre
2196 LOAD_MODULES_REMOTE=$LMR_orig
2202 for user in $SANITY_QUOTA_USERS; do
2203 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2204 missing_users="$missing_users $user"
2206 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2207 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2209 $LFS quotaoff -ug $DIR
2210 $LFS quotacheck -ug $DIR
2212 for user in $SANITY_QUOTA_USERS; do
2213 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2218 for user in $SANITY_QUOTA_USERS; do
2222 run_test 32 "check lqs hash(bug 21846) =========================================="
2224 cleanup_quota_test() {
2226 echo "Delete files..."
2230 # basic usage tracking for user & group
2233 chmod 0777 $DIR/$tdir
2236 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2238 trap cleanup_quota_test EXIT
2240 # make sure the system is clean
2241 USED=`getquota -u $TSTID global curspace`
2242 [ $USED -ne 0 ] && \
2243 error "Used space ($USED) for user $TSTID isn't 0."
2244 USED=`getquota -g $TSTID global curspace`
2245 [ $USED -ne 0 ] && \
2246 error "Used space ($USED) for group $TSTID isn't 0."
2248 for i in `seq 0 $INODES`; do
2249 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i conv=fsync \
2250 bs=$((BLK_SZ * BLK_CNT)) count=1 2>/dev/null ||
2251 error "write failed"
2252 echo "Iteration $i/$INODES completed"
2254 sync; sync_all_data;
2256 echo "Verify disk usage after write"
2257 USED=`getquota -u $TSTID global curspace`
2258 [ $USED -lt $TOTAL_BLKS ] && \
2259 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2260 USED=`getquota -u $TSTID global curinodes`
2261 [ $USED -lt $INODES ] && \
2262 error "Used inode for user $TSTID is $USED, expected $INODES"
2264 USED=`getquota -g $TSTID global curspace`
2265 [ $USED -lt $TOTAL_BLKS ] && \
2266 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2267 USED=`getquota -g $TSTID global curinodes`
2268 [ $USED -lt $INODES ] && \
2269 error "Used inode for group $TSTID is $USED, expected $INODES"
2273 echo "Verify disk usage after delete"
2274 wait_delete_completed
2275 USED=`getquota -u $TSTID global curspace`
2276 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2277 USED=`getquota -u $TSTID global curinodes`
2278 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2279 USED=`getquota -g $TSTID global curspace`
2280 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2281 USED=`getquota -g $TSTID global curinodes`
2282 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2284 run_test 33 "basic usage tracking for user & group =============================="
2286 # usage transfer test for user & group
2290 chmod 0777 $DIR/$tdir
2292 trap cleanup_quota_test EXIT
2294 # make sure the system is clean
2295 USED=`getquota -u $TSTID global curspace`
2296 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2297 USED=`getquota -g $TSTID global curspace`
2298 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2300 echo "Write file..."
2301 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) count=1 \
2302 conv=fsync 2>/dev/null || error "write failed"
2303 sync; sync_all_data;
2305 echo "chown the file to user $TSTID"
2306 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2308 echo "Wait for setattr on objects finished..."
2309 wait_delete_completed
2311 echo "Verify disk usage for user $TSTID"
2312 USED=`getquota -u $TSTID global curspace`
2313 [ $USED -lt $BLK_CNT ] && \
2314 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2315 USED=`getquota -u $TSTID global curinodes`
2316 [ $USED -ne 1 ] && \
2317 error "Used inodes for user $TSTID is $USED, expected 1"
2319 echo "chgrp the file to group $TSTID"
2320 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2322 echo "Wait for setattr on objects finished..."
2323 wait_delete_completed
2325 echo "Verify disk usage for group $TSTID"
2326 USED=`getquota -g $TSTID global curspace`
2327 [ $USED -ge $BLK_CNT ] || \
2328 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2329 USED=`getquota -g $TSTID global curinodes`
2330 [ $USED -eq 1 ] || \
2331 error "Used inodes for group $TSTID is $USED, expected 1"
2335 run_test 34 "usage transfer for user & group ===================================="
2337 # usage is still accessible across restart
2340 chmod 0777 $DIR/$tdir
2343 trap cleanup_quota_test EXIT
2345 echo "Write file..."
2346 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2347 count=1 conv=fsync 2>/dev/null || error "write failed"
2348 sync; sync_all_data;
2350 echo "Save disk usage before restart"
2351 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2352 [ $ORIG_USR_SPACE -eq 0 ] && \
2353 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2354 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2355 [ $ORIG_USR_INODES -eq 0 ] && \
2356 error "Used inodes for user $TSTID is 0, expected 1"
2357 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2358 [ $ORIG_GRP_SPACE -eq 0 ] && \
2359 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2360 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2361 [ $ORIG_GRP_INODES -eq 0 ] && \
2362 error "Used inodes for group $TSTID is 0, expected 1"
2365 local ORIG_REFORMAT=$REFORMAT
2367 cleanup_and_setup_lustre
2368 REFORMAT=$ORIG_REFORMAT
2371 echo "Verify disk usage after restart"
2372 USED=`getquota -u $TSTID global curspace`
2373 [ $USED -eq $ORIG_USR_SPACE ] || \
2374 error "Used space for user $TSTID changed from " \
2375 "$ORIG_USR_SPACE to $USED"
2376 USED=`getquota -u $TSTID global curinodes`
2377 [ $USED -eq $ORIG_USR_INODES ] || \
2378 error "Used inodes for user $TSTID changed from " \
2379 "$ORIG_USR_INODES to $USED"
2380 USED=`getquota -g $TSTID global curspace`
2381 [ $USED -eq $ORIG_GRP_SPACE ] || \
2382 error "Used space for group $TSTID changed from " \
2383 "$ORIG_GRP_SPACE to $USED"
2384 USED=`getquota -g $TSTID global curinodes`
2385 [ $USED -eq $ORIG_GRP_INODES ] || \
2386 error "Used inodes for group $TSTID changed from " \
2387 "$ORIG_GRP_INODES to $USED"
2389 # check if the vfs_dq_init() is called before writing
2390 echo "Append to the same file..."
2391 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2392 count=1 seek=1 conv=fsync 2>/dev/null || error "write failed"
2393 sync; sync_all_data;
2395 echo "Verify space usage is increased"
2396 USED=`getquota -u $TSTID global curspace`
2397 [ $USED -gt $ORIG_USR_SPACE ] ||
2398 error "Used space for user $TSTID isn't increased" \
2399 "orig:$ORIG_USR_SPACE, now:$USED"
2400 USED=`getquota -g $TSTID global curspace`
2401 [ $USED -gt $ORIG_GRP_SPACE ] ||
2402 error "Used space for group $TSTID isn't increased" \
2403 "orig:$ORIG_GRP_SPACE, now:$USED"
2407 run_test 35 "usage is still accessible across reboot ============================"
2413 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2418 complete $(basename $0) $SECONDS
2419 export USE_OFD="$USE_OFD_OLD"
2420 export LOAD_MODULES_REMOTE="$LOAD_MODULES_REMOTE_OLD"
2421 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2422 cleanup_and_setup_lustre