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
45 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
46 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
48 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
50 require_dsh_mds || exit 0
51 require_dsh_ost || exit 0
53 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
55 QUOTALOG=${TESTSUITELOG:-$TMP/sanity-quota.log}
57 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
62 QUOTA_AUTO_OLD=$QUOTA_AUTO
65 check_and_setup_lustre
67 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
68 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
70 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
71 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
72 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
73 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
74 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
75 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
79 # control the time of tests
81 [ "$SLOW" = "no" ] && cycle=10
85 # set_blk_tunables(btune_sz)
87 local btune=$(($1 * BLK_SZ))
88 # set btune size on all obdfilters
89 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
90 # set btune size on mds
91 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
94 # set_blk_unitsz(bunit_sz)
96 local bunit=$(($1 * BLK_SZ))
97 # set bunit size on all obdfilters
98 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
99 # set bunit size on mds
100 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
103 # set_file_tunesz(itune_sz)
106 # set itune size on mds
107 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
110 # set_file_unitsz(iunit_sz)
113 # set iunit size on mds
114 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
120 local fail_val=${3:-0}
122 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
123 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
124 [ $((fail_loc)) -eq 0 ]; then
125 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
127 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
129 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
130 for num in `seq $OSTCOUNT`; do
131 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
132 [ $((fail_loc)) -eq 0 ]; then
133 do_facet ost$num "lctl set_param fail_val=$fail_val"
135 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
140 RUNAS="runas -u $TSTID -g $TSTID"
141 RUNAS2="runas -u $TSTID2 -g $TSTID2"
142 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
143 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
147 run_test_with_stat() {
148 (($# != 2)) && error "the number of arguments is wrong"
150 if [ "$USE_OFD" == "yes" ]; then
155 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
156 for j in `seq $OSTCOUNT`; do
157 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
160 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
161 echo "statistics info begin ***************************************"
162 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
163 for j in `seq $OSTCOUNT`; do
164 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
166 echo "statistics info end ***************************************"
171 # clear quota limits for a user or a group
172 # usage: resetquota -u username
173 # resetquota -g groupname
176 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
177 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
180 if at_is_enabled; then
181 timeout=$(at_max_get mds)
183 timeout=$(lctl get_param -n timeout)
186 while [ $((count++)) -lt $timeout ]; do
188 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
189 if [ $RC -ne 0 ]; then
190 if echo "$OUTPUT" | grep -q busy; then
191 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
195 error "resetquota failed"
201 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
208 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
209 log "Files for user ($LOCAL_ID):"
210 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
213 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
214 log "Files for group ($LOCAL_ID):"
215 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
232 # get quota info for a user or a group
233 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
239 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
240 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
253 *) error "unknown quota parameter $4";;
256 [ "$uuid" = "global" ] && uuid=$DIR
258 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
265 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
267 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
269 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
270 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
271 if [ -z $USAGE ]; then
272 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
274 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
278 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
279 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
280 if [ -z $USAGE ]; then
281 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
283 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
290 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
292 log "do the quotacheck ..."
293 $LFS quotacheck -ug $DIR
295 resetquota -u $TSTUSR
296 resetquota -g $TSTUSR
300 test_quota_performance() {
301 TESTFILE="$DIR/$tdir/$tfile-0"
303 local stime=`date +%s`
304 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
305 local etime=`date +%s`
306 delta=$((etime - stime))
307 if [ $delta -gt 0 ]; then
308 rate=$((size * 1024 / delta))
309 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
314 # test basic quota performance b=21696
317 chmod 0777 $DIR/$tdir
319 [ "$SLOW" = "no" ] && MB=10
321 test_quota_performance $MB
323 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
324 test_quota_performance $MB
326 resetquota -u $TSTUSR
328 run_test_with_stat 0 "Test basic quota performance ==="
330 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
334 chmod 0777 $DIR/$tdir
335 TESTFILE="$DIR/$tdir/$tfile-0"
337 wait_delete_completed
340 log " User quota (limit: $LIMIT kbytes)"
341 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
343 quota_show_check b u $TSTUSR
345 $LFS setstripe $TESTFILE -c 1
346 chown $TSTUSR.$TSTUSR $TESTFILE
349 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
351 log " Write out of block quota ..."
352 # this time maybe cache write, ignore it's failure
353 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
354 # flush cache, ensure noquota flag is setted on client
356 $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"
360 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
361 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
362 echo $OST0_QUOTA_USED
363 [ $OST0_QUOTA_USED -ne 0 ] && \
364 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
366 resetquota -u $TSTUSR
369 log "--------------------------------------"
370 log " Group quota (limit: $LIMIT kbytes)"
371 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
373 quota_show_check b g $TSTUSR
374 TESTFILE="$DIR/$tdir/$tfile-1"
376 $LFS setstripe $TESTFILE -c 1
377 chown $TSTUSR.$TSTUSR $TESTFILE
380 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
382 log " Write out of block quota ..."
383 # this time maybe cache write, ignore it's failure
384 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
386 $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"
391 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
392 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
393 echo $OST0_QUOTA_USED
394 [ $OST0_QUOTA_USED -ne 0 ] && \
395 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
397 resetquota -g $TSTUSR
400 # block hard limit (normal use and out of quota)
402 for i in `seq 1 $cycle`; do
403 # define blk_qunit is between 1M and 4M
404 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
405 blk_qtune=$(( $RANDOM % $blk_qunit ))
406 # other osts and mds will occupy at 1M blk quota
407 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
408 set_blk_tunesz $blk_qtune
409 set_blk_unitsz $blk_qunit
410 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
412 echo "=================================================="
413 set_blk_unitsz $((128 * 1024))
414 set_blk_tunesz $((128 * 1024 / 2))
417 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
419 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
423 chmod 0777 $DIR/$tdir
424 TESTFILE="$DIR/$tdir/$tfile-0"
426 wait_delete_completed
429 log " User quota (limit: $LIMIT files)"
430 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
432 quota_show_check f u $TSTUSR
434 log " Create $LIMIT files ..."
435 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
436 quota_error u $TSTUSR "(usr) create failure, but expect success"
438 log " Create out of file quota ..."
439 $RUNAS touch ${TESTFILE}_xxx && \
440 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
442 unlinkmany ${TESTFILE} $LIMIT
443 rm -f ${TESTFILE}_xxx
446 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
447 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
449 [ $MDS_QUOTA_USED -ne 0 ] && \
450 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
452 resetquota -u $TSTUSR
455 log "--------------------------------------"
456 log " Group quota (limit: $LIMIT FILE)"
457 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
459 quota_show_check f g $TSTUSR
460 TESTFILE=$DIR/$tdir/$tfile-1
462 log " Create $LIMIT files ..."
463 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
464 quota_error g $TSTUSR "(grp) create failure, but expect success"
466 log " Create out of file quota ..."
467 $RUNAS touch ${TESTFILE}_xxx && \
468 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
470 unlinkmany ${TESTFILE} $LIMIT
471 rm -f ${TESTFILE}_xxx
474 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
475 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
477 [ $MDS_QUOTA_USED -ne 0 ] && \
478 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
480 resetquota -g $TSTUSR
483 # file hard limit (normal use and out of quota)
485 for i in `seq 1 $cycle`; do
486 if [ $i -eq 1 ]; then
491 # define ino_qunit is between 10 and 100
492 ino_qunit=$(( $RANDOM % 90 + 10 ))
493 ino_qtune=$(( $RANDOM % $ino_qunit ))
494 # RANDOM's maxium is 32767
495 i_limit=$(( $RANDOM % 990 + 10 ))
498 set_file_tunesz $ino_qtune
499 set_file_unitsz $ino_qunit
500 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
502 echo "=================================================="
507 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
511 TIMER=$(($2 * 3 / 2))
514 wait_delete_completed
516 echo " Write to exceed soft limit"
517 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
518 $RUNDD count=$((BUNIT_SZ+1)) || \
519 quota_error a $TSTUSR "write failure, but expect success"
520 OFFSET=$((OFFSET + BUNIT_SZ + 1))
525 $SHOW_QUOTA_INFO_USER
526 $SHOW_QUOTA_INFO_GROUP
528 echo " Write before timer goes off"
529 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
530 quota_error a $TSTUSR "write failure, but expect success"
531 OFFSET=$((OFFSET + BUNIT_SZ))
535 echo " Sleep $TIMER seconds ..."
540 $SHOW_QUOTA_INFO_USER
541 $SHOW_QUOTA_INFO_GROUP
543 echo " Write after timer goes off"
544 # maybe cache write, ignore.
545 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
546 OFFSET=$((OFFSET + BUNIT_SZ))
548 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
549 quota_error a $TSTUSR "write success, but expect EDQUOT"
553 $SHOW_QUOTA_INFO_USER
554 $SHOW_QUOTA_INFO_GROUP
556 echo " Unlink file to stop timer"
563 $SHOW_QUOTA_INFO_USER
564 $SHOW_QUOTA_INFO_GROUP
567 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
575 # block soft limit (start timer, timer goes off, stop timer)
578 chmod 0777 $DIR/$tdir
580 # 1 bunit on mds and 1 bunit on every ost
581 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
584 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
585 TESTFILE=$DIR/$tdir/$tfile-0
587 $LFS setstripe $TESTFILE -c 1
588 chown $TSTUSR.$TSTUSR $TESTFILE
590 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
591 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
593 test_block_soft $TESTFILE $GRACE
594 resetquota -u $TSTUSR
596 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
597 TESTFILE=$DIR/$tdir/$tfile-1
599 $LFS setstripe $TESTFILE -c 1
600 chown $TSTUSR.$TSTUSR $TESTFILE
602 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
603 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
605 test_block_soft $TESTFILE $GRACE
606 resetquota -g $TSTUSR
608 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
613 TIMER=$(($3 * 3 / 2))
615 wait_delete_completed
617 echo " Create files to exceed soft limit"
618 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
619 quota_error a $TSTUSR "create failure, but expect success"
623 echo " Create file before timer goes off"
624 $RUNAS touch ${TESTFILE}_before || \
625 quota_error a $TSTUSR "failed create before timer expired, but expect success"
629 echo " Sleep $TIMER seconds ..."
634 $SHOW_QUOTA_INFO_USER
635 $SHOW_QUOTA_INFO_GROUP
637 echo " Create file after timer goes off"
638 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
639 # inode quota left here
640 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
642 $RUNAS touch ${TESTFILE}_after3 && \
643 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
648 $SHOW_QUOTA_INFO_USER
649 $SHOW_QUOTA_INFO_GROUP
651 echo " Unlink files to stop timer"
652 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
656 $RUNAS touch ${TESTFILE}_xxx || \
657 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
662 rm -f ${TESTFILE}_xxx
666 # file soft limit (start timer, timer goes off, stop timer)
667 test_4a() { # was test_4
669 chmod 0777 $DIR/$tdir
670 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
671 TESTFILE=$DIR/$tdir/$tfile-0
675 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
676 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
677 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
678 quota_show_check f u $TSTUSR
680 test_file_soft $TESTFILE $LIMIT $GRACE
681 resetquota -u $TSTUSR
683 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
684 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
685 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
686 quota_show_check f g $TSTUSR
687 TESTFILE=$DIR/$tdir/$tfile-1
689 test_file_soft $TESTFILE $LIMIT $GRACE
690 resetquota -g $TSTUSR
693 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
694 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
696 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
698 test_4b() { # was test_4a
704 GR_STR6="1111111111111111"
706 wait_delete_completed
708 # test of valid grace strings handling
709 echo " Valid grace strings test"
710 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
711 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
712 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
713 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
715 # test of invalid grace strings handling
716 echo " Invalid grace strings test"
717 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
718 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
721 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
722 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
724 run_test_with_stat 4b "Grace time strings handling ==="
726 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
729 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
730 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
732 wait_delete_completed
734 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
735 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
736 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
737 quota_show_check a u $TSTUSR
738 quota_show_check a g $TSTUSR
740 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
741 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
742 error "touch failure, expect success"
743 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
745 echo " Chown files to $TSTUSR.$TSTUSR ..."
746 for i in `seq 0 $ILIMIT`; do
747 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
748 quota_error a $TSTUSR "chown failure, but expect success"
752 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
755 resetquota -u $TSTUSR
756 resetquota -g $TSTUSR
758 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
760 # block quota acquire & release
762 if [ $OSTCOUNT -lt 2 ]; then
763 skip_env "$OSTCOUNT < 2, too few osts"
767 wait_delete_completed
770 chmod 0777 $DIR/$tdir
772 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
773 FILEA="$DIR/$tdir/$tfile-0_a"
774 FILEB="$DIR/$tdir/$tfile-0_b"
776 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
777 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
778 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
779 quota_show_check b u $TSTUSR
780 quota_show_check b g $TSTUSR
782 echo " Create filea on OST0 and fileb on OST1"
783 $LFS setstripe $FILEA -i 0 -c 1
784 $LFS setstripe $FILEB -i 1 -c 1
785 chown $TSTUSR.$TSTUSR $FILEA
786 chown $TSTUSR.$TSTUSR $FILEB
788 echo " Exceed quota limit ..."
789 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
790 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
791 quota_error a $TSTUSR "write filea failure, but expect success"
796 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
797 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
799 echo " Write to OST1 return EDQUOT"
800 # this write maybe cache write, ignore it's failure
801 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
802 $RUNDD count=$(($BUNIT_SZ * 2)) || true
806 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
807 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
809 echo " Remove filea to let OST0 release quota"
812 if at_is_enabled; then
813 timeout=$(at_max_get mds)
815 timeout=$(lctl get_param -n timeout)
817 count=$((timeout / 5))
818 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
820 while [ $((count--)) -gt 0 ]; do
823 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
824 if [ -z $OST0_QUOTA_HOLD ]; then
825 error "System is error when query quota for block (U:$TSTUSR)."
827 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
833 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
836 while [ $((count--)) -gt 0 ]; do
839 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
840 if [ -z $OST0_QUOTA_HOLD ]; then
841 error "System is error when query quota for block (G:$TSTUSR)."
843 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
849 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
852 echo " Write to OST1"
853 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
854 quota_error a $TSTUSR "write fileb failure, expect success"
861 resetquota -u $TSTUSR
862 resetquota -g $TSTUSR
865 run_test_with_stat 6 "Block quota acquire & release ========="
867 # quota recovery (block quota only by now)
871 chmod 0777 $DIR/$tdir
873 wait_delete_completed
875 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
876 TESTFILE="$DIR/$tdir/$tfile-0"
878 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
880 $LFS setstripe $TESTFILE -c 1
881 chown $TSTUSR.$TSTUSR $TESTFILE
883 echo " Write to OST0..."
884 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
885 quota_error u $TSTUSR "write failure, but expect success"
887 #define OBD_FAIL_OBD_DQACQ 0x604
888 lustre_fail mds 0x604
889 echo " Remove files on OST0"
893 echo " Trigger recovery..."
894 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
895 for i in $OSC0_UUID; do
896 $LCTL --device $i activate || error "activate osc failed!"
899 # sleep a while to wait for recovery done
903 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
904 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
905 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
906 echo " total limits = $TOTAL_LIMIT"
908 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
909 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
910 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
911 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
912 echo " limits on $OST0_UUID = $OST0_LIMIT"
915 resetquota -u $TSTUSR
917 run_test_with_stat 7 "Quota recovery (only block limit) ======"
919 # run dbench with quota enabled
922 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
925 wait_delete_completed
927 echo " Set enough high limit for user: $TSTUSR"
928 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
929 echo " Set enough high limit for group: $TSTUSR"
930 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
932 chmod 0777 $DIR/$tdir
934 [ "$SLOW" = "no" ] && duration=" -t 120"
935 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
942 run_test_with_stat 8 "Run dbench with quota enabled ==========="
944 # run for fixing bug10707, it needs a big room. test for 64bit
946 GB=$((KB * 1024 * 1024))
947 # Use this as dd bs to decrease time
948 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
949 blksize=$((1 << 21)) # 2Mb
950 size_file=$((GB * 9 / 2))
951 # this check is just for test_9
952 OST0_MIN=4900000 #4.67G
953 check_whether_skip () {
954 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
955 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
956 if [ $OST0_SIZE -lt $OST0_MIN ]; then
957 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
965 check_whether_skip && return 0
967 wait_delete_completed
973 chmod 0777 $DIR/$tdir
974 TESTFILE="$DIR/$tdir/$tfile-0"
976 BLK_LIMIT=$((100 * KB * KB)) # 100G
978 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
980 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
981 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
982 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
983 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
985 quota_show_check a u $TSTUSR
986 quota_show_check a g $TSTUSR
989 $LFS setstripe $TESTFILE -c 1 -i 0
991 chown $TSTUSR.$TSTUSR $TESTFILE
993 log " Write the big file of 4.5G ..."
994 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
995 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1000 log " delete the big file of 4.5G..."
1001 $RUNAS rm -f $TESTFILE
1002 sync; sleep 3; sync;
1009 set_blk_unitsz $((128 * 1024))
1010 set_blk_tunesz $((128 * 1024 / 2))
1014 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1016 # 2.0 version does not support 32 bit qd_count,
1017 # test_10 "run for fixing bug10707(32bit) " is obsolete
1019 # test a deadlock between quota and journal b=11693
1022 chmod 0777 $DIR/$tdir
1024 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1025 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1027 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1028 TESTFILE="$DIR/$tdir/$tfile-0"
1029 TESTFILE2="$DIR2/$tdir/$tfile-1"
1031 wait_delete_completed
1033 echo " User quota (limit: $LIMIT kbytes)"
1034 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1036 $LFS setstripe $TESTFILE -i 0 -c 1
1037 chown $TSTUSR.$TSTUSR $TESTFILE
1038 $LFS setstripe $TESTFILE2 -i 0 -c 1
1039 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1041 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1042 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1043 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1045 echo " step1: write out of block quota ..."
1046 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1048 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1051 echo " step2: testing ......"
1052 local last_size=$(stat -c %s $TESTFILE2)
1054 local start_secs=$SECONDS
1055 while [ -d /proc/${DDPID1} ]; do
1056 local size=$(stat -c %s $TESTFILE2)
1057 if [ $size -eq $last_size ]; then
1058 stall_secs=$[stall_secs+1]
1062 if [ $stall_secs -gt 30 ]; then
1064 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1069 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1071 #Recover fail_loc and dd will finish soon
1074 echo " step3: testing ......"
1077 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1079 if [ $count -gt 150 ]; then
1080 quota_error u $TSTUSR "dd should be finished!"
1084 echo "(dd_pid=$DDPID, time=$count)successful"
1086 rm -f $TESTFILE $TESTFILE2
1087 sync; sleep 3; sync;
1089 resetquota -u $TSTUSR
1091 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1093 # test multiple clients write block quota b=11693
1096 wait_delete_completed
1098 # one OST * 10 + (mds + other OSTs)
1099 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1100 TESTFILE="$DIR/$tdir/$tfile"
1102 echo " User quota (limit: $LIMIT kbytes)"
1103 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1104 quota_show_check b u $TSTUSR
1106 $LFS setstripe $TESTFILE -i 0 -c 1
1107 chown $TSTUSR.$TSTUSR $TESTFILE
1108 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1109 chown $TSTUSR.$TSTUSR $TESTFILE.2
1111 echo " step1: write out of block quota ..."
1112 # one bunit will give mds
1113 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1115 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1118 echo " step2: testing ......"
1121 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1123 if [ $count -gt 64 ]; then
1124 quota_error u $TSTUSR "dd should be finished!"
1128 echo "(dd_pid=$DDPID, time=$count)successful"
1132 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1134 if [ $count -gt 64 ]; then
1135 quota_error u $TSTUSR "dd should be finished!"
1139 echo "(dd_pid=$DDPID1, time=$count)successful"
1141 sync; sleep 5; sync;
1143 echo " step3: checking ......"
1144 fz=`stat -c %s $TESTFILE`
1145 fz2=`stat -c %s $TESTFILE.2`
1147 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1148 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1150 rm -f $TESTFILE $TESTFILE.2
1151 sync; sleep 3; sync;
1153 resetquota -u $TSTUSR
1155 run_test_with_stat 13 "test multiple clients write block quota ==="
1157 check_if_quota_zero(){
1158 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1159 for i in `seq 3 $line`; do
1160 if [ $i -eq 3 ]; then
1166 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1167 awk '{print $'"$j"'}'`
1168 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1169 error "quota on $2 isn't clean"
1172 echo "pass check_if_quota_zero"
1175 test_14a() { # was test_14 b=12223 -- setting quota on root
1176 TESTFILE="$DIR/$tdir/$tfile"
1180 cleanup_and_setup_lustre
1185 # out of root's file and block quota
1186 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1187 createmany -m ${TESTFILE} 20 || \
1188 quota_error u root "unexpected: user(root) create files failly!"
1189 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1190 quota_error u root "unexpected: user(root) write files failly!"
1192 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1193 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1197 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1198 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1201 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1203 #check_if_quota_zero u root
1206 unlinkmany ${TESTFILE} 15
1208 sync; sleep 3; sync;
1210 run_test_with_stat 14a "test setting quota on root ==="
1213 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1214 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1216 wait_delete_completed
1219 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1220 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1221 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1222 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1223 resetquota -u $TSTUSR
1226 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1227 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1228 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1229 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1230 resetquota -g $TSTUSR
1231 $LFS quotaoff -ug $DIR
1232 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1233 error "fail to set version for $SINGLEMDS"
1234 for j in `seq $OSTCOUNT`; do
1235 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1236 error "fail to set version for ost$j"
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
2002 if at_is_enabled; then
2003 timeout=$(at_max_get client)
2004 [ $(at_min_get client) -gt $at_max_val ] &&
2005 at_max_val=$(at_min_get client)
2006 at_max_set $at_max_val client
2008 timeout=$(lctl get_param -n timeout)
2009 lctl set_param timeout=$at_max_val
2011 # actually send a RPC to make service at_current confined within at_max
2012 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR ||
2013 error "should succeed"
2015 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2016 lustre_fail mds 0x12e
2018 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2020 deadline=$((2 * (($at_max_val << 1) + ($at_max_val >> 2) + 5)))
2021 echo "wait at most 2 * ($at_max_val * 2.25 + 5) = $deadline seconds," \
2022 "it is server process time add the network latency."
2025 while [ $waited -lt $deadline ]; do
2028 waited=$(($waited + 1))
2029 ps -p $pid > /dev/null || break
2031 echo "waited $waited seconds"
2032 ps -p $pid && error "lfs hadn't finished by $deadline seconds"
2033 wait $pid && error "succeeded, but should have failed"
2037 if at_is_enabled; then
2038 at_max_set $timeout client
2040 lctl set_param timeout=$timeout
2043 resetquota -u $TSTUSR
2045 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2051 local TESTFILE="$DIR/$tdir/$tfile"
2058 chmod 0777 $DIR/$tdir
2060 $LFS setstripe $TESTFILE -i 0 -c 1
2061 chown $TSTUSR.$TSTUSR $TESTFILE
2063 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2064 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2065 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2066 cancel_lru_locks osc
2068 $LFS setquota -u $TSTUSR -B 0 $DIR
2069 # over-quota flag has not yet settled since we do not trigger async events
2070 # based on grace time period expiration
2072 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2073 cancel_lru_locks osc
2074 # now over-quota flag should be settled and further writes should fail
2076 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2078 resetquota -u $TSTUSR
2079 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2081 set_blk_unitsz $((128 * 1024))
2082 set_blk_tunesz $((128 * 1024 / 2))
2084 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2086 # test duplicate quota releases b=18630
2089 chmod 0777 $DIR/$tdir
2091 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2092 TESTFILE="$DIR/$tdir/$tfile-0"
2093 TESTFILE2="$DIR/$tdir/$tfile-1"
2095 wait_delete_completed
2097 log " User quota (limit: $LIMIT kbytes)"
2098 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2100 $LFS setstripe $TESTFILE -i 0 -c 1
2101 chown $TSTUSR.$TSTUSR $TESTFILE
2102 $LFS setstripe $TESTFILE2 -i 0 -c 1
2103 chown $TSTUSR.$TSTUSR $TESTFILE2
2105 log " step1: write out of block quota ..."
2106 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2107 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2109 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2110 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2111 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2113 log " step2: delete two files so that triggering duplicate quota release ..."
2114 rm -f $TESTFILE $TESTFILE2
2115 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2116 wait_delete_completed
2118 log " step3: verify if the ost failed"
2119 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2120 watchdog=`awk '/test 31/ {start = 1;}
2121 /release quota error/ {
2125 }' $TMP/lustre-log-${TESTNAME}.log`
2126 [ "$watchdog" ] && error "$watchdog"
2127 rm -f $TMP/lustre-log-${TESTNAME}.log
2130 resetquota -u $TSTUSR
2132 run_test_with_stat 31 "test duplicate quota releases ==="
2134 # check hash_cur_bits
2135 check_quota_hash_cur_bits() {
2138 # check quota_hash_cur_bits on all obdfilters
2139 for num in `seq $OSTCOUNT`; do
2140 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2141 if [ $cb -gt $bits ]; then
2142 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2146 # check quota_hash_cur_bits on mds
2147 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2148 if [ $cb -gt $bits ]; then
2149 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2157 # check distribution of all obdfilters
2158 for num in `seq $OSTCOUNT`; do
2159 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2160 rehash_count=`echo $line | awk '{print $9}'`
2161 if [ $rehash_count -eq 0 ]; then
2162 echo -e "ost$num:\n $line"
2163 error "Rehearsh didn't happen"
2167 # check distribution of mds
2168 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2169 rehash_count=`echo $line | awk '{print $9}'`
2170 if [ $rehash_count -eq 0 ]; then
2171 echo -e "mdt:\n $line"
2172 error "Rehearsh didn't happen"
2179 # reset system so that quota_hash_cur_bits==3
2180 echo "Reset system ..."
2181 local LMR_orig=$LOAD_MODULES_REMOTE
2182 LOAD_MODULES_REMOTE=true
2183 cleanup_and_setup_lustre
2184 LOAD_MODULES_REMOTE=$LMR_orig
2190 for user in $SANITY_QUOTA_USERS; do
2191 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2192 missing_users="$missing_users $user"
2194 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2195 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2197 $LFS quotaoff -ug $DIR
2198 $LFS quotacheck -ug $DIR
2200 for user in $SANITY_QUOTA_USERS; do
2201 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2206 for user in $SANITY_QUOTA_USERS; do
2210 run_test 32 "check lqs hash(bug 21846) =========================================="
2212 cleanup_quota_test() {
2214 echo "Delete files..."
2218 # basic usage tracking for user & group
2221 chmod 0777 $DIR/$tdir
2224 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2226 trap cleanup_quota_test EXIT
2228 # make sure the system is clean
2229 USED=`getquota -u $TSTID global curspace`
2230 [ $USED -ne 0 ] && \
2231 error "Used space ($USED) for user $TSTID isn't 0."
2232 USED=`getquota -g $TSTID global curspace`
2233 [ $USED -ne 0 ] && \
2234 error "Used space ($USED) for group $TSTID isn't 0."
2236 for i in `seq 0 $INODES`; do
2237 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i conv=fsync \
2238 bs=$((BLK_SZ * BLK_CNT)) count=1 2>/dev/null ||
2239 error "write failed"
2240 echo "Iteration $i/$INODES completed"
2242 sync; sync_all_data;
2244 echo "Verify disk usage after write"
2245 USED=`getquota -u $TSTID global curspace`
2246 [ $USED -lt $TOTAL_BLKS ] && \
2247 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2248 USED=`getquota -u $TSTID global curinodes`
2249 [ $USED -lt $INODES ] && \
2250 error "Used inode for user $TSTID is $USED, expected $INODES"
2252 USED=`getquota -g $TSTID global curspace`
2253 [ $USED -lt $TOTAL_BLKS ] && \
2254 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2255 USED=`getquota -g $TSTID global curinodes`
2256 [ $USED -lt $INODES ] && \
2257 error "Used inode for group $TSTID is $USED, expected $INODES"
2261 echo "Verify disk usage after delete"
2262 wait_delete_completed
2263 sync; sync_all_data;
2265 USED=`getquota -u $TSTID global curspace`
2266 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2267 USED=`getquota -u $TSTID global curinodes`
2268 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2269 USED=`getquota -g $TSTID global curspace`
2270 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2271 USED=`getquota -g $TSTID global curinodes`
2272 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2274 run_test 33 "basic usage tracking for user & group =============================="
2276 # usage transfer test for user & group
2280 chmod 0777 $DIR/$tdir
2282 trap cleanup_quota_test EXIT
2284 # make sure the system is clean
2285 USED=`getquota -u $TSTID global curspace`
2286 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2287 USED=`getquota -g $TSTID global curspace`
2288 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2290 echo "Write file..."
2291 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) count=1 \
2292 conv=fsync 2>/dev/null || error "write failed"
2293 sync; sync_all_data;
2295 echo "chown the file to user $TSTID"
2296 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2298 echo "Wait for setattr on objects finished..."
2299 wait_delete_completed
2301 echo "Verify disk usage for user $TSTID"
2302 USED=`getquota -u $TSTID global curspace`
2303 [ $USED -lt $BLK_CNT ] && \
2304 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2305 USED=`getquota -u $TSTID global curinodes`
2306 [ $USED -ne 1 ] && \
2307 error "Used inodes for user $TSTID is $USED, expected 1"
2309 echo "chgrp the file to group $TSTID"
2310 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2312 echo "Wait for setattr on objects finished..."
2313 wait_delete_completed
2315 echo "Verify disk usage for group $TSTID"
2316 USED=`getquota -g $TSTID global curspace`
2317 [ $USED -ge $BLK_CNT ] || \
2318 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2319 USED=`getquota -g $TSTID global curinodes`
2320 [ $USED -eq 1 ] || \
2321 error "Used inodes for group $TSTID is $USED, expected 1"
2325 run_test 34 "usage transfer for user & group ===================================="
2327 # usage is still accessible across restart
2330 chmod 0777 $DIR/$tdir
2333 trap cleanup_quota_test EXIT
2335 echo "Write file..."
2336 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2337 count=1 conv=fsync 2>/dev/null || error "write failed"
2338 sync; sync_all_data;
2340 echo "Save disk usage before restart"
2341 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2342 [ $ORIG_USR_SPACE -eq 0 ] && \
2343 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2344 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2345 [ $ORIG_USR_INODES -eq 0 ] && \
2346 error "Used inodes for user $TSTID is 0, expected 1"
2347 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2348 [ $ORIG_GRP_SPACE -eq 0 ] && \
2349 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2350 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2351 [ $ORIG_GRP_INODES -eq 0 ] && \
2352 error "Used inodes for group $TSTID is 0, expected 1"
2355 local ORIG_REFORMAT=$REFORMAT
2357 cleanup_and_setup_lustre
2358 REFORMAT=$ORIG_REFORMAT
2361 echo "Verify disk usage after restart"
2362 USED=`getquota -u $TSTID global curspace`
2363 [ $USED -eq $ORIG_USR_SPACE ] || \
2364 error "Used space for user $TSTID changed from " \
2365 "$ORIG_USR_SPACE to $USED"
2366 USED=`getquota -u $TSTID global curinodes`
2367 [ $USED -eq $ORIG_USR_INODES ] || \
2368 error "Used inodes for user $TSTID changed from " \
2369 "$ORIG_USR_INODES to $USED"
2370 USED=`getquota -g $TSTID global curspace`
2371 [ $USED -eq $ORIG_GRP_SPACE ] || \
2372 error "Used space for group $TSTID changed from " \
2373 "$ORIG_GRP_SPACE to $USED"
2374 USED=`getquota -g $TSTID global curinodes`
2375 [ $USED -eq $ORIG_GRP_INODES ] || \
2376 error "Used inodes for group $TSTID changed from " \
2377 "$ORIG_GRP_INODES to $USED"
2379 # check if the vfs_dq_init() is called before writing
2380 echo "Append to the same file..."
2381 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2382 count=1 seek=1 conv=fsync 2>/dev/null || error "write failed"
2383 sync; sync_all_data;
2385 echo "Verify space usage is increased"
2386 USED=`getquota -u $TSTID global curspace`
2387 [ $USED -gt $ORIG_USR_SPACE ] ||
2388 error "Used space for user $TSTID isn't increased" \
2389 "orig:$ORIG_USR_SPACE, now:$USED"
2390 USED=`getquota -g $TSTID global curspace`
2391 [ $USED -gt $ORIG_GRP_SPACE ] ||
2392 error "Used space for group $TSTID isn't increased" \
2393 "orig:$ORIG_GRP_SPACE, now:$USED"
2397 run_test 35 "usage is still accessible across reboot ============================"
2403 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2408 complete sanity-quota.sh $SECONDS
2409 check_and_cleanup_lustre
2410 export QUOTA_AUTO=$QUOTA_AUTO_OLD