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
13 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
14 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
15 # We have changed the mechanism of quota, test_12 is meanless now.
17 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
21 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
27 TSTID2=${TSTID2:-60001}
28 TSTUSR=${TSTUSR:-"quota_usr"}
29 TSTUSR2=${TSTUSR2:-"quota_2usr"}
31 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
32 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
35 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
36 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
37 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
38 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
39 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
41 export MULTIOP=${MULTIOP:-multiop}
43 LUSTRE=${LUSTRE:-`dirname $0`/..}
44 . $LUSTRE/tests/test-framework.sh
46 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
48 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
50 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
52 require_dsh_mds || exit 0
53 require_dsh_ost || exit 0
55 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
57 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
59 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
64 QUOTA_AUTO_OLD=$QUOTA_AUTO
67 check_and_setup_lustre
69 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
70 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
75 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
76 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
77 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
81 # control the time of tests
83 [ "$SLOW" = "no" ] && cycle=10
87 # set_blk_tunables(btune_sz)
89 local btune=$(($1 * BLK_SZ))
90 # set btune size on all obdfilters
91 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
92 # set btune size on mds
93 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
96 # set_blk_unitsz(bunit_sz)
98 local bunit=$(($1 * BLK_SZ))
99 # set bunit size on all obdfilters
100 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
101 # set bunit size on mds
102 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
105 # set_file_tunesz(itune_sz)
108 # set itune size on mds
109 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
112 # set_file_unitsz(iunit_sz)
115 # set iunit size on mds
116 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
122 local fail_val=${3:-0}
124 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
125 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
126 [ $((fail_loc)) -eq 0 ]; then
127 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
129 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
131 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
132 for num in `seq $OSTCOUNT`; do
133 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
134 [ $((fail_loc)) -eq 0 ]; then
135 do_facet ost$num "lctl set_param fail_val=$fail_val"
137 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
142 RUNAS="runas -u $TSTID -g $TSTID"
143 RUNAS2="runas -u $TSTID2 -g $TSTID2"
144 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
145 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
149 run_test_with_stat() {
150 (($# != 2)) && error "the number of arguments is wrong"
152 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
153 for j in `seq $OSTCOUNT`; do
154 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
157 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
158 echo "statistics info begin ***************************************"
159 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
160 for j in `seq $OSTCOUNT`; do
161 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
163 echo "statistics info end ***************************************"
168 # clear quota limits for a user or a group
169 # usage: resetquota -u username
170 # resetquota -g groupname
173 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
174 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
177 if at_is_enabled; then
178 timeout=$(at_max_get mds)
180 timeout=$(lctl get_param -n timeout)
183 while [ $((count++)) -lt $timeout ]; do
185 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
186 if [ $RC -ne 0 ]; then
187 if echo "$OUTPUT" | grep -q busy; then
188 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
192 error "resetquota failed"
198 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
205 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
206 log "Files for user ($LOCAL_ID):"
207 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
210 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
211 log "Files for group ($LOCAL_ID):"
212 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
229 # get quota info for a user or a group
230 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
236 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
237 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
250 *) error "unknown quota parameter $4";;
253 [ "$uuid" = "global" ] && uuid=$DIR
255 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
262 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
264 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
266 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
267 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
268 if [ -z $USAGE ]; then
269 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
271 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
275 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
276 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
277 if [ -z $USAGE ]; then
278 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
280 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
287 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
289 log "do the quotacheck ..."
290 $LFS quotacheck -ug $DIR
292 resetquota -u $TSTUSR
293 resetquota -g $TSTUSR
297 test_quota_performance() {
298 TESTFILE="$DIR/$tdir/$tfile-0"
300 local stime=`date +%s`
301 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
302 local etime=`date +%s`
303 delta=$((etime - stime))
304 if [ $delta -gt 0 ]; then
305 rate=$((size * 1024 / delta))
306 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
311 # test basic quota performance b=21696
314 chmod 0777 $DIR/$tdir
316 [ "$SLOW" = "no" ] && MB=10
318 test_quota_performance $MB
320 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
321 test_quota_performance $MB
323 resetquota -u $TSTUSR
325 run_test_with_stat 0 "Test basic quota performance ==="
327 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
331 chmod 0777 $DIR/$tdir
332 TESTFILE="$DIR/$tdir/$tfile-0"
334 wait_delete_completed
337 log " User quota (limit: $LIMIT kbytes)"
338 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
340 quota_show_check b u $TSTUSR
342 $LFS setstripe $TESTFILE -c 1
343 chown $TSTUSR.$TSTUSR $TESTFILE
346 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
348 log " Write out of block quota ..."
349 # this time maybe cache write, ignore it's failure
350 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
351 # flush cache, ensure noquota flag is setted on client
353 $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"
357 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
358 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
359 echo $OST0_QUOTA_USED
360 [ $OST0_QUOTA_USED -ne 0 ] && \
361 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
363 resetquota -u $TSTUSR
366 log "--------------------------------------"
367 log " Group quota (limit: $LIMIT kbytes)"
368 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
370 quota_show_check b g $TSTUSR
371 TESTFILE="$DIR/$tdir/$tfile-1"
373 $LFS setstripe $TESTFILE -c 1
374 chown $TSTUSR.$TSTUSR $TESTFILE
377 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
379 log " Write out of block quota ..."
380 # this time maybe cache write, ignore it's failure
381 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
383 $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"
388 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
389 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
390 echo $OST0_QUOTA_USED
391 [ $OST0_QUOTA_USED -ne 0 ] && \
392 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
394 resetquota -g $TSTUSR
397 # block hard limit (normal use and out of quota)
399 for i in `seq 1 $cycle`; do
400 # define blk_qunit is between 1M and 4M
401 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
402 blk_qtune=$(( $RANDOM % $blk_qunit ))
403 # other osts and mds will occupy at 1M blk quota
404 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
405 set_blk_tunesz $blk_qtune
406 set_blk_unitsz $blk_qunit
407 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
409 echo "=================================================="
410 set_blk_unitsz $((128 * 1024))
411 set_blk_tunesz $((128 * 1024 / 2))
414 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
416 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
420 chmod 0777 $DIR/$tdir
421 TESTFILE="$DIR/$tdir/$tfile-0"
423 wait_delete_completed
426 log " User quota (limit: $LIMIT files)"
427 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
429 quota_show_check f u $TSTUSR
431 log " Create $LIMIT files ..."
432 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
433 quota_error u $TSTUSR "(usr) create failure, but expect success"
435 log " Create out of file quota ..."
436 $RUNAS touch ${TESTFILE}_xxx && \
437 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
439 unlinkmany ${TESTFILE} $LIMIT
440 rm -f ${TESTFILE}_xxx
443 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
444 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
446 [ $MDS_QUOTA_USED -ne 0 ] && \
447 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
449 resetquota -u $TSTUSR
452 log "--------------------------------------"
453 log " Group quota (limit: $LIMIT FILE)"
454 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
456 quota_show_check f g $TSTUSR
457 TESTFILE=$DIR/$tdir/$tfile-1
459 log " Create $LIMIT files ..."
460 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
461 quota_error g $TSTUSR "(grp) create failure, but expect success"
463 log " Create out of file quota ..."
464 $RUNAS touch ${TESTFILE}_xxx && \
465 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
467 unlinkmany ${TESTFILE} $LIMIT
468 rm -f ${TESTFILE}_xxx
471 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
472 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
474 [ $MDS_QUOTA_USED -ne 0 ] && \
475 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
477 resetquota -g $TSTUSR
480 # file hard limit (normal use and out of quota)
482 for i in `seq 1 $cycle`; do
483 if [ $i -eq 1 ]; then
488 # define ino_qunit is between 10 and 100
489 ino_qunit=$(( $RANDOM % 90 + 10 ))
490 ino_qtune=$(( $RANDOM % $ino_qunit ))
491 # RANDOM's maxium is 32767
492 i_limit=$(( $RANDOM % 990 + 10 ))
495 set_file_tunesz $ino_qtune
496 set_file_unitsz $ino_qunit
497 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
499 echo "=================================================="
504 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
508 TIMER=$(($2 * 3 / 2))
511 wait_delete_completed
513 echo " Write to exceed soft limit"
514 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
515 $RUNDD count=$((BUNIT_SZ+1)) || \
516 quota_error a $TSTUSR "write failure, but expect success"
517 OFFSET=$((OFFSET + BUNIT_SZ + 1))
522 $SHOW_QUOTA_INFO_USER
523 $SHOW_QUOTA_INFO_GROUP
525 echo " Write before timer goes off"
526 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
527 quota_error a $TSTUSR "write failure, but expect success"
528 OFFSET=$((OFFSET + BUNIT_SZ))
532 echo " Sleep $TIMER seconds ..."
537 $SHOW_QUOTA_INFO_USER
538 $SHOW_QUOTA_INFO_GROUP
540 echo " Write after timer goes off"
541 # maybe cache write, ignore.
542 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
543 OFFSET=$((OFFSET + BUNIT_SZ))
545 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
546 quota_error a $TSTUSR "write success, but expect EDQUOT"
550 $SHOW_QUOTA_INFO_USER
551 $SHOW_QUOTA_INFO_GROUP
553 echo " Unlink file to stop timer"
560 $SHOW_QUOTA_INFO_USER
561 $SHOW_QUOTA_INFO_GROUP
564 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
572 # block soft limit (start timer, timer goes off, stop timer)
575 chmod 0777 $DIR/$tdir
577 # 1 bunit on mds and 1 bunit on every ost
578 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
581 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
582 TESTFILE=$DIR/$tdir/$tfile-0
584 $LFS setstripe $TESTFILE -c 1
585 chown $TSTUSR.$TSTUSR $TESTFILE
587 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
588 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
590 test_block_soft $TESTFILE $GRACE
591 resetquota -u $TSTUSR
593 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
594 TESTFILE=$DIR/$tdir/$tfile-1
596 $LFS setstripe $TESTFILE -c 1
597 chown $TSTUSR.$TSTUSR $TESTFILE
599 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
600 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
602 test_block_soft $TESTFILE $GRACE
603 resetquota -g $TSTUSR
605 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
610 TIMER=$(($3 * 3 / 2))
612 wait_delete_completed
614 echo " Create files to exceed soft limit"
615 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
616 quota_error a $TSTUSR "create failure, but expect success"
620 echo " Create file before timer goes off"
621 $RUNAS touch ${TESTFILE}_before || \
622 quota_error a $TSTUSR "failed create before timer expired, but expect success"
626 echo " Sleep $TIMER seconds ..."
631 $SHOW_QUOTA_INFO_USER
632 $SHOW_QUOTA_INFO_GROUP
634 echo " Create file after timer goes off"
635 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
636 # inode quota left here
637 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
639 $RUNAS touch ${TESTFILE}_after3 && \
640 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
645 $SHOW_QUOTA_INFO_USER
646 $SHOW_QUOTA_INFO_GROUP
648 echo " Unlink files to stop timer"
649 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
653 $RUNAS touch ${TESTFILE}_xxx || \
654 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
659 rm -f ${TESTFILE}_xxx
663 # file soft limit (start timer, timer goes off, stop timer)
664 test_4a() { # was test_4
666 chmod 0777 $DIR/$tdir
667 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
668 TESTFILE=$DIR/$tdir/$tfile-0
672 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
673 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
674 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
675 quota_show_check f u $TSTUSR
677 test_file_soft $TESTFILE $LIMIT $GRACE
678 resetquota -u $TSTUSR
680 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
681 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
682 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
683 quota_show_check f g $TSTUSR
684 TESTFILE=$DIR/$tdir/$tfile-1
686 test_file_soft $TESTFILE $LIMIT $GRACE
687 resetquota -g $TSTUSR
690 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
691 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
693 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
695 test_4b() { # was test_4a
701 GR_STR6="1111111111111111"
703 wait_delete_completed
705 # test of valid grace strings handling
706 echo " Valid grace strings test"
707 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
708 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
709 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
710 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
712 # test of invalid grace strings handling
713 echo " Invalid grace strings test"
714 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
715 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
718 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
719 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
721 run_test_with_stat 4b "Grace time strings handling ==="
723 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
726 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
727 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
729 wait_delete_completed
731 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
732 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
733 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
734 quota_show_check a u $TSTUSR
735 quota_show_check a g $TSTUSR
737 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
738 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
739 error "touch failure, expect success"
740 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
742 echo " Chown files to $TSTUSR.$TSTUSR ..."
743 for i in `seq 0 $ILIMIT`; do
744 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
745 quota_error a $TSTUSR "chown failure, but expect success"
749 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
752 resetquota -u $TSTUSR
753 resetquota -g $TSTUSR
755 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
757 # block quota acquire & release
759 if [ $OSTCOUNT -lt 2 ]; then
760 skip_env "$OSTCOUNT < 2, too few osts"
764 wait_delete_completed
767 chmod 0777 $DIR/$tdir
769 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
770 FILEA="$DIR/$tdir/$tfile-0_a"
771 FILEB="$DIR/$tdir/$tfile-0_b"
773 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
774 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
775 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
776 quota_show_check b u $TSTUSR
777 quota_show_check b g $TSTUSR
779 echo " Create filea on OST0 and fileb on OST1"
780 $LFS setstripe $FILEA -i 0 -c 1
781 $LFS setstripe $FILEB -i 1 -c 1
782 chown $TSTUSR.$TSTUSR $FILEA
783 chown $TSTUSR.$TSTUSR $FILEB
785 echo " Exceed quota limit ..."
786 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
787 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
788 quota_error a $TSTUSR "write filea failure, but expect success"
793 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
794 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
796 echo " Write to OST1 return EDQUOT"
797 # this write maybe cache write, ignore it's failure
798 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
799 $RUNDD count=$(($BUNIT_SZ * 2)) || true
803 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
804 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
806 echo " Remove filea to let OST0 release quota"
809 if at_is_enabled; then
810 timeout=$(at_max_get mds)
812 timeout=$(lctl get_param -n timeout)
814 count=$((timeout / 5))
815 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
817 while [ $((count--)) -gt 0 ]; do
820 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
821 if [ -z $OST0_QUOTA_HOLD ]; then
822 error "System is error when query quota for block (U:$TSTUSR)."
824 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
830 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
833 while [ $((count--)) -gt 0 ]; do
836 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
837 if [ -z $OST0_QUOTA_HOLD ]; then
838 error "System is error when query quota for block (G:$TSTUSR)."
840 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
846 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
849 echo " Write to OST1"
850 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
851 quota_error a $TSTUSR "write fileb failure, expect success"
858 resetquota -u $TSTUSR
859 resetquota -g $TSTUSR
862 run_test_with_stat 6 "Block quota acquire & release ========="
864 # quota recovery (block quota only by now)
868 chmod 0777 $DIR/$tdir
870 wait_delete_completed
872 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
873 TESTFILE="$DIR/$tdir/$tfile-0"
875 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
877 $LFS setstripe $TESTFILE -c 1
878 chown $TSTUSR.$TSTUSR $TESTFILE
880 echo " Write to OST0..."
881 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
882 quota_error u $TSTUSR "write failure, but expect success"
884 #define OBD_FAIL_OBD_DQACQ 0x604
885 lustre_fail mds 0x604
886 echo " Remove files on OST0"
890 echo " Trigger recovery..."
891 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
892 for i in $OSC0_UUID; do
893 $LCTL --device $i activate || error "activate osc failed!"
896 # sleep a while to wait for recovery done
900 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
901 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
902 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
903 echo " total limits = $TOTAL_LIMIT"
905 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
906 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
907 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
908 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
909 echo " limits on $OST0_UUID = $OST0_LIMIT"
912 resetquota -u $TSTUSR
914 run_test_with_stat 7 "Quota recovery (only block limit) ======"
916 # run dbench with quota enabled
919 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
922 wait_delete_completed
924 echo " Set enough high limit for user: $TSTUSR"
925 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
926 echo " Set enough high limit for group: $TSTUSR"
927 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
929 chmod 0777 $DIR/$tdir
931 [ "$SLOW" = "no" ] && duration=" -t 120"
932 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
939 run_test_with_stat 8 "Run dbench with quota enabled ==========="
941 # run for fixing bug10707, it needs a big room. test for 64bit
943 GB=$((KB * 1024 * 1024))
944 # Use this as dd bs to decrease time
945 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
946 blksize=$((1 << 21)) # 2Mb
947 size_file=$((GB * 9 / 2))
948 # this check is just for test_9
949 OST0_MIN=4900000 #4.67G
950 check_whether_skip () {
951 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
952 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
953 if [ $OST0_SIZE -lt $OST0_MIN ]; then
954 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
962 check_whether_skip && return 0
964 wait_delete_completed
970 chmod 0777 $DIR/$tdir
971 TESTFILE="$DIR/$tdir/$tfile-0"
973 BLK_LIMIT=$((100 * KB * KB)) # 100G
975 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
977 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
978 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
979 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
980 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
982 quota_show_check a u $TSTUSR
983 quota_show_check a g $TSTUSR
986 $LFS setstripe $TESTFILE -c 1 -i 0
988 chown $TSTUSR.$TSTUSR $TESTFILE
990 log " Write the big file of 4.5G ..."
991 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
992 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
997 log " delete the big file of 4.5G..."
998 $RUNAS rm -f $TESTFILE
1006 set_blk_unitsz $((128 * 1024))
1007 set_blk_tunesz $((128 * 1024 / 2))
1011 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1013 # 2.0 version does not support 32 bit qd_count,
1014 # test_10 "run for fixing bug10707(32bit) " is obsolete
1016 # test a deadlock between quota and journal b=11693
1019 chmod 0777 $DIR/$tdir
1021 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1022 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1024 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1025 TESTFILE="$DIR/$tdir/$tfile-0"
1026 TESTFILE2="$DIR2/$tdir/$tfile-1"
1028 wait_delete_completed
1030 echo " User quota (limit: $LIMIT kbytes)"
1031 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1033 $LFS setstripe $TESTFILE -i 0 -c 1
1034 chown $TSTUSR.$TSTUSR $TESTFILE
1035 $LFS setstripe $TESTFILE2 -i 0 -c 1
1036 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1038 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1039 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1040 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1042 echo " step1: write out of block quota ..."
1043 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1045 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1048 echo " step2: testing ......"
1049 local last_size=$(stat -c %s $TESTFILE2)
1051 local start_secs=$SECONDS
1052 while [ -d /proc/${DDPID1} ]; do
1053 local size=$(stat -c %s $TESTFILE2)
1054 if [ $size -eq $last_size ]; then
1055 stall_secs=$[stall_secs+1]
1059 if [ $stall_secs -gt 30 ]; then
1061 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1066 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1068 #Recover fail_loc and dd will finish soon
1071 echo " step3: testing ......"
1074 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1076 if [ $count -gt 150 ]; then
1077 quota_error u $TSTUSR "dd should be finished!"
1081 echo "(dd_pid=$DDPID, time=$count)successful"
1083 rm -f $TESTFILE $TESTFILE2
1084 sync; sleep 3; sync;
1086 resetquota -u $TSTUSR
1088 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1090 # test multiple clients write block quota b=11693
1093 wait_delete_completed
1095 # one OST * 10 + (mds + other OSTs)
1096 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1097 TESTFILE="$DIR/$tdir/$tfile"
1099 echo " User quota (limit: $LIMIT kbytes)"
1100 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1101 quota_show_check b u $TSTUSR
1103 $LFS setstripe $TESTFILE -i 0 -c 1
1104 chown $TSTUSR.$TSTUSR $TESTFILE
1105 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1106 chown $TSTUSR.$TSTUSR $TESTFILE.2
1108 echo " step1: write out of block quota ..."
1109 # one bunit will give mds
1110 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1112 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1115 echo " step2: testing ......"
1118 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1120 if [ $count -gt 64 ]; then
1121 quota_error u $TSTUSR "dd should be finished!"
1125 echo "(dd_pid=$DDPID, time=$count)successful"
1129 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1131 if [ $count -gt 64 ]; then
1132 quota_error u $TSTUSR "dd should be finished!"
1136 echo "(dd_pid=$DDPID1, time=$count)successful"
1138 sync; sleep 5; sync;
1140 echo " step3: checking ......"
1141 fz=`stat -c %s $TESTFILE`
1142 fz2=`stat -c %s $TESTFILE.2`
1144 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1145 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1147 rm -f $TESTFILE $TESTFILE.2
1148 sync; sleep 3; sync;
1150 resetquota -u $TSTUSR
1152 run_test_with_stat 13 "test multiple clients write block quota ==="
1154 check_if_quota_zero(){
1155 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1156 for i in `seq 3 $line`; do
1157 if [ $i -eq 3 ]; then
1163 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1164 awk '{print $'"$j"'}'`
1165 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1166 error "quota on $2 isn't clean"
1169 echo "pass check_if_quota_zero"
1172 test_14a() { # was test_14 b=12223 -- setting quota on root
1173 TESTFILE="$DIR/$tdir/$tfile"
1177 cleanup_and_setup_lustre
1182 # out of root's file and block quota
1183 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1184 createmany -m ${TESTFILE} 20 || \
1185 quota_error u root "unexpected: user(root) create files failly!"
1186 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1187 quota_error u root "unexpected: user(root) write files failly!"
1189 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1190 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1194 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1195 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1198 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1200 #check_if_quota_zero u root
1203 unlinkmany ${TESTFILE} 15
1205 sync; sleep 3; sync;
1207 run_test_with_stat 14a "test setting quota on root ==="
1210 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1211 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1213 wait_delete_completed
1216 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1217 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1218 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1219 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1220 resetquota -u $TSTUSR
1223 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1224 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1225 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1226 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1227 resetquota -g $TSTUSR
1228 $LFS quotaoff -ug $DIR
1229 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1230 error "fail to set version for $SINGLEMDS"
1231 for j in `seq $OSTCOUNT`; do
1232 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1233 error "fail to set version for ost$j"
1236 echo "invalidating quota files"
1237 $LFS quotainv -ug $DIR
1238 $LFS quotainv -ugf $DIR
1239 $LFS quotacheck -ug $DIR
1241 run_test_with_stat 15 "set block quota more than 4T ==="
1243 # 2.0 version does not support WITHOUT_CHANGE_QS,
1244 # test_16 "test without adjusting qunit" is obsolete
1246 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1251 wait_delete_completed
1253 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1254 lustre_fail ost 0x80000A02
1256 TESTFILE="$DIR/$tdir/$tfile-a"
1257 TESTFILE2="$DIR/$tdir/$tfile-b"
1260 BLK_LIMIT=$((100 * 1024)) # 100M
1262 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1263 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1264 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1265 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1267 quota_show_check b u $TSTUSR
1268 quota_show_check b g $TSTUSR
1271 chown $TSTUSR.$TSTUSR $TESTFILE
1273 chown $TSTUSR.$TSTUSR $TESTFILE2
1275 log " Write the test file1 ..."
1276 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1277 || quota_error a $TSTUSR "write 10M file failure"
1282 log " write the test file2 ..."
1283 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1284 || quota_error a $TSTUSR "write 10M file failure"
1289 rm -f $TESTFILE $TESTFILE2
1291 sync; sleep 3; sync;
1293 # make qd_count 64 bit
1296 set_blk_unitsz $((128 * 1024))
1297 set_blk_tunesz $((128 * 1024 / 2))
1299 resetquota -u $TSTUSR
1300 resetquota -g $TSTUSR
1304 run_test_with_stat 17 "run for fixing bug14526 ==========="
1306 # test when mds takes a long time to handle a quota req so that
1307 # the ost has dropped it, the ost still could work well b=14840
1309 LIMIT=$((100 * 1024 * 1024)) # 100G
1310 TESTFILE="$DIR/$tdir/$tfile"
1313 wait_delete_completed
1318 log " User quota (limit: $LIMIT kbytes)"
1319 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1320 quota_show_check b u $TSTUSR
1322 $LFS setstripe $TESTFILE -i 0 -c 1
1323 chown $TSTUSR.$TSTUSR $TESTFILE
1325 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1326 lustre_fail mds 0x13c
1328 log " step1: write 100M block ..."
1329 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1335 echo " step2: testing ......"
1337 if at_is_enabled; then
1338 timeout=$(at_max_get mds)
1340 timeout=$(lctl get_param -n timeout)
1343 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1345 if [ $count -gt $((4 * $timeout)) ]; then
1346 quota_error u $TSTUSR "count=$count dd should be finished!"
1350 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1352 cancel_lru_locks mdc
1353 cancel_lru_locks osc
1355 testfile_size=$(stat -c %s $TESTFILE)
1356 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1357 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1362 resetquota -u $TSTUSR
1363 set_blk_unitsz $((128 * 1024))
1364 set_blk_tunesz $((128 * 1024 / 2))
1366 run_test_with_stat 18 "run for fixing bug14840 ==========="
1368 # test when mds drops a quota req, the ost still could work well b=14840
1370 LIMIT=$((100 * 1024 * 1024)) # 100G
1371 TESTFILE="$DIR/$tdir/$tfile-a"
1374 wait_delete_completed
1379 log " User quota (limit: $LIMIT kbytes)"
1380 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1381 quota_show_check b u $TSTUSR
1383 $LFS setstripe $TESTFILE -i 0 -c 1
1384 chown $TSTUSR.$TSTUSR $TESTFILE
1386 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1387 lustre_fail mds 0x8000013d
1389 log " step1: write 100M block ..."
1390 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1393 echo " step2: testing ......"
1395 if at_is_enabled; then
1396 timeout=$(at_max_get mds)
1398 timeout=$(lctl get_param -n timeout)
1401 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1403 if [ $count -gt $((6 * $timeout)) ]; then
1405 quota_error u $TSTUSR "count=$count dd should be finished!"
1409 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1415 resetquota -u $TSTUSR
1416 set_blk_unitsz $((128 * 1024))
1417 set_blk_tunesz $((128 * 1024 / 2))
1419 run_test_with_stat 18a "run for fixing bug14840 ==========="
1421 # test when mds do failover, the ost still could work well without trigger
1426 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1427 TESTFILE="$DIR/$tdir/$tfile"
1430 wait_delete_completed
1435 log " User quota (limit: $LIMIT kbytes)"
1436 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1437 quota_show_check b u $TSTUSR
1439 $LFS setstripe $TESTFILE -i 0 -c 1
1440 chown $TSTUSR.$TSTUSR $TESTFILE
1442 timeout=$(sysctl -n lustre.timeout)
1444 if [ $type = "directio" ]; then
1445 log " write 100M block(directio) ..."
1446 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1448 log " write 100M block(normal) ..."
1449 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1453 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1455 replay_barrier $SINGLEMDS
1457 log "failing mds for $((2 * timeout)) seconds"
1458 fail $SINGLEMDS $((2 * timeout))
1460 # check if quotaon successful
1461 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1462 if [ $? -eq 0 ]; then
1464 error "quotaon failed!"
1469 if at_is_enabled; then
1470 timeout=$(at_max_get mds)
1472 timeout=$(lctl get_param -n timeout)
1475 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1476 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1477 log "it took $count second"
1481 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1483 cancel_lru_locks mdc
1484 cancel_lru_locks osc
1487 resetquota -u $TSTUSR
1488 set_blk_unitsz $((128 * 1024))
1489 set_blk_tunesz $((128 * 1024 / 2))
1490 testfile_size=$(stat -c %s $TESTFILE)
1491 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1493 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1499 # test when mds does failover, the ost still could work well
1500 # this test shouldn't trigger watchdog b=14840
1502 test_18bc_sub normal
1503 test_18bc_sub directio
1504 # check if watchdog is triggered
1505 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1506 watchdog=`awk '/test 18b/ {start = 1;}
1507 /Service thread pid/ && /was inactive/ {
1511 }' $TMP/lustre-log-${TESTNAME}.log`
1512 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1513 rm -f $TMP/lustre-log-${TESTNAME}.log
1515 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1517 # test when mds does failover, the ost still could work well
1518 # this test will prevent OST_DISCONNET from happening b=14840
1520 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1521 lustre_fail ost 0x202
1522 test_18bc_sub normal
1523 test_18bc_sub directio
1526 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1528 run_to_block_limit() {
1529 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1531 wait_delete_completed
1533 # set 1 Mb quota unit size
1537 # bind file to a single OST
1538 $LFS setstripe -c 1 $TESTFILE
1539 chown $TSTUSR.$TSTUSR $TESTFILE
1541 echo " User quota (limit: $LIMIT kbytes)"
1542 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1543 quota_show_check b u $TSTUSR
1544 echo " Updating quota limits"
1545 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1546 quota_show_check b u $TSTUSR
1548 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1549 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1550 # for now page cache of TESTFILE may still be dirty,
1551 # let's push it to the corresponding OST, this will also
1552 # cache NOQUOTA on the client from OST's reply
1553 cancel_lru_locks osc
1554 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1558 # 1 Mb bunit per each MDS/OSS
1559 local TESTFILE="$DIR/$tdir/$tfile"
1562 run_to_block_limit $TESTFILE
1567 resetquota -u $TSTUSR
1569 set_blk_unitsz $((128 * 1024))
1570 set_blk_tunesz $((128 * 1024 / 2))
1573 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1577 LSTR=(1t 2g 3m 4k) # limits strings
1578 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1580 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1581 $MOUNT || error "could not set quota limits"
1583 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1584 --inode-softlimit ${LSTR[2]} \
1585 --inode-hardlimit ${LSTR[3]} \
1586 $MOUNT || error "could not set quota limits"
1588 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1589 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1590 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1591 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1593 resetquota -u $TSTUSR
1595 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1602 time=$(($(date +%s) + seconds))
1603 while [ $(date +%s) -lt $time ]; do
1604 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1609 # run for fixing bug16053, setquota shouldn't fail when writing and
1610 # deleting are happening
1615 wait_delete_completed
1617 TESTFILE="$DIR/$tdir/$tfile"
1619 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1622 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1623 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1624 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1625 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1627 # repeat writing on a 1M file
1628 test_21_sub ${TESTFILE}_1 1024 30 &
1630 # repeat writing on a 128M file
1631 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1634 time=$(($(date +%s) + 30))
1636 while [ $(date +%s) -lt $time ]; do
1637 log " Set quota for $i times"
1638 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1639 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1646 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1648 if [ $count -gt 60 ]; then
1649 quota_error a $TSTUSR "dd should be finished!"
1653 echo "(dd_pid=$DDPID1, time=$count)successful"
1657 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1659 if [ $count -gt 60 ]; then
1660 quota_error a $TSTUSR "dd should be finished!"
1664 echo "(dd_pid=$DDPID2, time=$count)successful"
1666 set_blk_unitsz $((128 * 1024))
1667 set_blk_tunesz $((128 * 1024 / 2))
1668 resetquota -u $TSTUSR
1669 resetquota -g $TSTUSR
1673 run_test_with_stat 21 "run for fixing bug16053 ==========="
1676 quota_save_version "ug3"
1682 echo "checking parameters"
1684 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1685 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1689 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1693 chmod 0777 $DIR/$tdir
1694 TESTFILE="$DIR/$tdir/$tfile-0"
1696 local bs_unit=$((1024*1024))
1699 wait_delete_completed
1702 log " User quota (limit: $LIMIT kbytes)"
1703 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1705 quota_show_check b u $TSTUSR
1707 $LFS setstripe $TESTFILE -c 1 -i 0
1708 chown $TSTUSR.$TSTUSR $TESTFILE
1710 log " Step1: trigger quota with 0_DIRECT"
1711 log " Write half of file"
1712 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1713 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1714 log " Write out of block quota ..."
1715 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1716 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1719 log " Step2: rewrite should succeed"
1720 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1721 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1725 wait_delete_completed
1726 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1727 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1728 echo $OST0_QUOTA_USED
1729 [ $OST0_QUOTA_USED -ne 0 ] && \
1730 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1732 resetquota -u $TSTUSR
1736 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1738 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1739 check_whether_skip && return 0
1740 log "run for $((4 * $slave_cnt))MB test file"
1741 test_23_sub $((4 * $slave_cnt * 1024))
1743 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1744 check_whether_skip && return 0
1745 log "run for $((40 * $slave_cnt))MB test file"
1746 test_23_sub $((40 * $slave_cnt * 1024))
1748 run_test_with_stat 23 "run for fixing bug16125 ==========="
1751 local TESTFILE="$DIR/$tdir/$tfile"
1754 run_to_block_limit $TESTFILE
1755 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1759 resetquota -u $TSTUSR
1761 set_blk_unitsz $((128 * 1024))
1762 set_blk_tunesz $((128 * 1024 / 2))
1765 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1768 if [ $1 = "-u" ]; then
1769 if [ $2 = "$TSTUSR" ]; then
1775 if [ $2 = "$TSTUSR" ]; then
1785 chmod 0777 $DIR/$tdir
1786 TESTFILE="$DIR/$tdir/$tfile-0"
1788 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1790 wait_delete_completed
1792 # set quota for $TSTUSR
1793 log "setquota for $TSTUSR"
1794 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1796 if [ "$1" == "-u" ]; then
1797 quota_show_check a u $TSTUSR
1799 quota_show_check a g $TSTUSR
1802 # set quota for $TSTUSR2
1803 log "setquota for $TSTUSR2"
1804 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1806 if [ "$1" == "-u" ]; then
1807 quota_show_check a u $TSTUSR2
1809 quota_show_check a g $TSTUSR2
1812 # set stripe index to 0
1813 log "setstripe for $DIR/$tdir to 0"
1814 $LFS setstripe $DIR/$tdir -c 1 -i 0
1815 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1816 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1817 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1818 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1819 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1820 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1823 log "$TSTUSR write 4M to $TESTFILE"
1824 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1826 show_quota $1 $TSTUSR
1827 show_quota $1 $TSTUSR2
1828 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1829 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1830 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1831 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1832 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1833 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1834 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1836 # chown/chgrp from $TSTUSR to $TSTUSR2
1837 if [ $1 = "-u" ]; then
1838 log "chown from $TSTUSR to $TSTUSR2"
1839 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1841 log "chgrp from $TSTUSR to $TSTUSR2"
1842 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1845 show_quota $1 $TSTUSR
1846 show_quota $1 $TSTUSR2
1847 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1848 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1849 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1850 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1851 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1852 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1853 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1854 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1855 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1856 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1857 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1858 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1859 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1860 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1861 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1864 wait_delete_completed
1865 resetquota $1 $TSTUSR
1866 resetquota $1 $TSTUSR2
1870 log "run for chown case"
1873 log "run for chgrp case"
1876 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1880 chmod 0777 $DIR/$tdir
1881 TESTFILE="$DIR/$tdir/$tfile-0"
1882 TESTFILE2="$DIR/$tdir/$tfile-1"
1886 wait_delete_completed
1888 # every quota slave gets 20MB
1889 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1890 log "limit: ${b_limit}KB"
1891 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1893 quota_show_check b u $TSTUSR
1895 $LFS setstripe $TESTFILE -c 1 -i 0
1896 $LFS setstripe $TESTFILE2 -c 1 -i 0
1897 chown $TSTUSR.$TSTUSR $TESTFILE
1898 chown $TSTUSR.$TSTUSR $TESTFILE2
1900 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1901 lustre_fail ost 0xA03
1903 log " Write the first file..."
1904 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1905 log " Delete the first file..."
1909 wait_delete_completed
1911 log " Write the second file..."
1912 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1913 log " Delete the second file..."
1917 set_blk_unitsz $((128 * 1024))
1918 set_blk_tunesz $((128 * 1024 / 2))
1919 resetquota -u $TSTUSR
1921 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1924 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1925 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1928 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1931 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1932 error "lfs setquota failed with uid argument"
1933 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1934 error "lfs stequota failed with gid argument"
1935 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1936 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1937 resetquota -u $TSTUSR
1938 resetquota -g $TSTUSR
1941 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1944 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1945 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1946 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1949 echo "Step 2: reset system ..."
1950 cleanup_and_setup_lustre
1953 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1957 wait_delete_completed
1959 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1960 lustre_fail ost 0x80000A02
1962 TESTFILE="$DIR/$tdir/$tfile"
1965 BLK_LIMIT=$((100 * 1024)) # 100M
1966 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1967 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1971 chown $TSTUSR.$TSTUSR $TESTFILE
1973 echo "Step 5: write the test file1 [10M] ..."
1974 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1975 || quota_error a $TSTUSR "write 10M file failure"
1979 sync; sleep 3; sync;
1981 # make qd_count 64 bit
1984 set_blk_unitsz $((128 * 1024))
1985 set_blk_tunesz $((128 * 1024 / 2))
1987 resetquota -u $TSTUSR
1989 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
1993 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1997 if at_is_enabled; then
1998 timeout=$(at_max_get client)
1999 at_max_set 10 client
2001 timeout=$(lctl get_param -n timeout)
2002 lctl set_param timeout=10
2004 # actually send a RPC to make service at_current confined within at_max
2005 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR || error "should succeed"
2007 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2008 lustre_fail mds 0x12e
2010 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2012 echo "sleeping for 10 * 1.25 + 5 + 10 seconds"
2014 ps -p $pid && error "lfs hadn't finished by timeout"
2015 wait $pid && error "succeeded, but should have failed"
2019 if at_is_enabled; then
2020 at_max_set $timeout client
2022 lctl set_param timeout=$timeout
2025 resetquota -u $TSTUSR
2027 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2033 local TESTFILE="$DIR/$tdir/$tfile"
2040 chmod 0777 $DIR/$tdir
2042 $LFS setstripe $TESTFILE -i 0 -c 1
2043 chown $TSTUSR.$TSTUSR $TESTFILE
2045 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2046 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2047 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2048 cancel_lru_locks osc
2050 $LFS setquota -u $TSTUSR -B 0 $DIR
2051 # over-quota flag has not yet settled since we do not trigger async events
2052 # based on grace time period expiration
2054 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2055 cancel_lru_locks osc
2056 # now over-quota flag should be settled and further writes should fail
2058 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2060 resetquota -u $TSTUSR
2061 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2063 set_blk_unitsz $((128 * 1024))
2064 set_blk_tunesz $((128 * 1024 / 2))
2066 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2068 # test duplicate quota releases b=18630
2071 chmod 0777 $DIR/$tdir
2073 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2074 TESTFILE="$DIR/$tdir/$tfile-0"
2075 TESTFILE2="$DIR/$tdir/$tfile-1"
2077 wait_delete_completed
2079 log " User quota (limit: $LIMIT kbytes)"
2080 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2082 $LFS setstripe $TESTFILE -i 0 -c 1
2083 chown $TSTUSR.$TSTUSR $TESTFILE
2084 $LFS setstripe $TESTFILE2 -i 0 -c 1
2085 chown $TSTUSR.$TSTUSR $TESTFILE2
2087 log " step1: write out of block quota ..."
2088 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2089 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2091 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2092 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2093 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2095 log " step2: delete two files so that triggering duplicate quota release ..."
2096 rm -f $TESTFILE $TESTFILE2
2097 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2098 wait_delete_completed
2100 log " step3: verify if the ost failed"
2101 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2102 watchdog=`awk '/test 31/ {start = 1;}
2103 /release quota error/ {
2107 }' $TMP/lustre-log-${TESTNAME}.log`
2108 [ "$watchdog" ] && error "$watchdog"
2109 rm -f $TMP/lustre-log-${TESTNAME}.log
2112 resetquota -u $TSTUSR
2114 run_test_with_stat 31 "test duplicate quota releases ==="
2116 # check hash_cur_bits
2117 check_quota_hash_cur_bits() {
2120 # check quota_hash_cur_bits on all obdfilters
2121 for num in `seq $OSTCOUNT`; do
2122 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2123 if [ $cb -gt $bits ]; then
2124 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2128 # check quota_hash_cur_bits on mds
2129 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2130 if [ $cb -gt $bits ]; then
2131 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2139 # check distribution of all obdfilters
2140 for num in `seq $OSTCOUNT`; do
2141 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2142 rehash_count=`echo $line | awk '{print $9}'`
2143 if [ $rehash_count -eq 0 ]; then
2144 echo -e "ost$num:\n $line"
2145 error "Rehearsh didn't happen"
2149 # check distribution of mds
2150 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2151 rehash_count=`echo $line | awk '{print $9}'`
2152 if [ $rehash_count -eq 0 ]; then
2153 echo -e "mdt:\n $line"
2154 error "Rehearsh didn't happen"
2161 # reset system so that quota_hash_cur_bits==3
2162 echo "Reset system ..."
2163 local LMR_orig=$LOAD_MODULES_REMOTE
2164 LOAD_MODULES_REMOTE=true
2165 cleanup_and_setup_lustre
2166 LOAD_MODULES_REMOTE=$LMR_orig
2172 for user in $SANITY_QUOTA_USERS; do
2173 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2174 missing_users="$missing_users $user"
2176 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2177 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2179 $LFS quotaoff -ug $DIR
2180 $LFS quotacheck -ug $DIR
2182 for user in $SANITY_QUOTA_USERS; do
2183 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2188 for user in $SANITY_QUOTA_USERS; do
2192 run_test 32 "check lqs hash(bug 21846) =========================================="
2194 cleanup_quota_test() {
2196 echo "Delete files..."
2200 # basic usage tracking for user & group
2203 chmod 0777 $DIR/$tdir
2206 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2208 trap cleanup_quota_test EXIT
2210 # make sure the system is clean
2211 USED=`getquota -u $TSTID global curspace`
2212 [ $USED -ne 0 ] && \
2213 error "Used space ($USED) for user $TSTID isn't 0."
2214 USED=`getquota -g $TSTID global curspace`
2215 [ $USED -ne 0 ] && \
2216 error "Used space ($USED) for group $TSTID isn't 0."
2218 echo "Write files..."
2219 for i in `seq 0 $INODES`; do
2220 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=$BLK_SZ \
2221 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2224 echo "Verify disk usage after write"
2225 USED=`getquota -u $TSTID global curspace`
2226 [ $USED -lt $TOTAL_BLKS ] && \
2227 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2228 USED=`getquota -u $TSTID global curinodes`
2229 [ $USED -lt $INODES ] && \
2230 error "Used inode for user $TSTID is $USED, expected $INODES"
2232 USED=`getquota -g $TSTID global curspace`
2233 [ $USED -lt $TOTAL_BLKS ] && \
2234 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2235 USED=`getquota -g $TSTID global curinodes`
2236 [ $USED -lt $INODES ] && \
2237 error "Used inode for group $TSTID is $USED, expected $INODES"
2241 echo "Verify disk usage after delete"
2242 wait_delete_completed
2243 USED=`getquota -u $TSTID global curspace`
2244 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2245 USED=`getquota -u $TSTID global curinodes`
2246 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2247 USED=`getquota -g $TSTID global curspace`
2248 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2249 USED=`getquota -g $TSTID global curinodes`
2250 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2252 run_test 33 "basic usage tracking for user & group =============================="
2254 # usage transfer test for user & group
2258 chmod 0777 $DIR/$tdir
2260 trap cleanup_quota_test EXIT
2262 # make sure the system is clean
2263 USED=`getquota -u $TSTID global curspace`
2264 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2265 USED=`getquota -g $TSTID global curspace`
2266 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2268 echo "Write file..."
2269 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ count=$BLK_CNT \
2270 oflag=sync 2>/dev/null || error "write failed"
2272 echo "chown the file to user $TSTID"
2273 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2275 echo "Verify disk usage for user $TSTID"
2276 USED=`getquota -u $TSTID global curspace`
2277 [ $USED -lt $BLK_CNT ] && \
2278 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2279 USED=`getquota -u $TSTID global curinodes`
2280 [ $USED -ne 1 ] && \
2281 error "Used inodes for user $TSTID is $USED, expected 1"
2283 echo "chgrp the file to group $TSTID"
2284 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2286 echo "Verify disk usage for group $TSTID"
2287 USED=`getquota -g $TSTID global curspace`
2288 [ $USED -ge $BLK_CNT ] || \
2289 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2290 USED=`getquota -g $TSTID global curinodes`
2291 [ $USED -eq 1 ] || \
2292 error "Used inodes for group $TSTID is $USED, expected 1"
2296 run_test 34 "usage transfer for user & group ===================================="
2298 # usage is still accessible across restart
2301 chmod 0777 $DIR/$tdir
2304 trap cleanup_quota_test EXIT
2306 echo "Write file..."
2307 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ \
2308 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2310 echo "Save disk usage before restart"
2311 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2312 [ $ORIG_USR_SPACE -eq 0 ] && \
2313 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2314 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2315 [ $ORIG_USR_INODES -eq 0 ] && \
2316 error "Used inodes for user $TSTID is 0, expected 1"
2317 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2318 [ $ORIG_GRP_SPACE -eq 0 ] && \
2319 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2320 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2321 [ $ORIG_GRP_INODES -eq 0 ] && \
2322 error "Used inodes for group $TSTID is 0, expected 1"
2325 local ORIG_REFORMAT=$REFORMAT
2327 cleanup_and_setup_lustre
2328 REFORMAT=$ORIG_REFORMAT
2331 echo "Verify disk usage after restart"
2332 USED=`getquota -u $TSTID global curspace`
2333 [ $USED -eq $ORIG_USR_SPACE ] || \
2334 error "Used space for user $TSTID changed from " \
2335 "$ORIG_USR_SPACE to $USED"
2336 USED=`getquota -u $TSTID global curinodes`
2337 [ $USED -eq $ORIG_USR_INODES ] || \
2338 error "Used inodes for user $TSTID changed from " \
2339 "$ORIG_USR_INODES to $USED"
2340 USED=`getquota -g $TSTID global curspace`
2341 [ $USED -eq $ORIG_GRP_SPACE ] || \
2342 error "Used space for group $TSTID changed from " \
2343 "$ORIG_GRP_SPACE to $USED"
2344 USED=`getquota -g $TSTID global curinodes`
2345 [ $USED -eq $ORIG_GRP_INODES ] || \
2346 error "Used inodes for group $TSTID changed from " \
2347 "$ORIG_GRP_INODES to $USED"
2351 run_test 35 "usage is still accessible across reboot ============================"
2358 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2363 complete $(basename $0) $SECONDS
2364 check_and_cleanup_lustre
2365 export QUOTA_AUTO=$QUOTA_AUTO_OLD