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 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
151 for j in `seq $OSTCOUNT`; do
152 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
155 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
156 echo "statistics info begin ***************************************"
157 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
158 for j in `seq $OSTCOUNT`; do
159 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
161 echo "statistics info end ***************************************"
166 # clear quota limits for a user or a group
167 # usage: resetquota -u username
168 # resetquota -g groupname
171 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
172 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
175 if at_is_enabled; then
176 timeout=$(at_max_get mds)
178 timeout=$(lctl get_param -n timeout)
181 while [ $((count++)) -lt $timeout ]; do
183 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
184 if [ $RC -ne 0 ]; then
185 if echo "$OUTPUT" | grep -q busy; then
186 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
190 error "resetquota failed"
196 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
203 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
204 log "Files for user ($LOCAL_ID):"
205 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
208 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
209 log "Files for group ($LOCAL_ID):"
210 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
227 # get quota info for a user or a group
228 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
234 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
235 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
248 *) error "unknown quota parameter $4";;
251 [ "$uuid" = "global" ] && uuid=$DIR
253 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
260 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
262 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
264 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
265 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
266 if [ -z $USAGE ]; then
267 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
269 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
273 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
274 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
275 if [ -z $USAGE ]; then
276 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
278 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
285 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
287 log "do the quotacheck ..."
288 $LFS quotacheck -ug $DIR
290 resetquota -u $TSTUSR
291 resetquota -g $TSTUSR
295 test_quota_performance() {
296 TESTFILE="$DIR/$tdir/$tfile-0"
298 local stime=`date +%s`
299 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
300 local etime=`date +%s`
301 delta=$((etime - stime))
302 if [ $delta -gt 0 ]; then
303 rate=$((size * 1024 / delta))
304 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
309 # test basic quota performance b=21696
312 chmod 0777 $DIR/$tdir
314 [ "$SLOW" = "no" ] && MB=10
316 test_quota_performance $MB
318 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
319 test_quota_performance $MB
321 resetquota -u $TSTUSR
323 run_test_with_stat 0 "Test basic quota performance ==="
325 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
329 chmod 0777 $DIR/$tdir
330 TESTFILE="$DIR/$tdir/$tfile-0"
332 wait_delete_completed
335 log " User quota (limit: $LIMIT kbytes)"
336 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
338 quota_show_check b u $TSTUSR
340 $LFS setstripe $TESTFILE -c 1
341 chown $TSTUSR.$TSTUSR $TESTFILE
344 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
346 log " Write out of block quota ..."
347 # this time maybe cache write, ignore it's failure
348 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
349 # flush cache, ensure noquota flag is setted on client
351 $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"
355 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
356 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
357 echo $OST0_QUOTA_USED
358 [ $OST0_QUOTA_USED -ne 0 ] && \
359 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
361 resetquota -u $TSTUSR
364 log "--------------------------------------"
365 log " Group quota (limit: $LIMIT kbytes)"
366 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
368 quota_show_check b g $TSTUSR
369 TESTFILE="$DIR/$tdir/$tfile-1"
371 $LFS setstripe $TESTFILE -c 1
372 chown $TSTUSR.$TSTUSR $TESTFILE
375 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
377 log " Write out of block quota ..."
378 # this time maybe cache write, ignore it's failure
379 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
381 $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"
386 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
387 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
388 echo $OST0_QUOTA_USED
389 [ $OST0_QUOTA_USED -ne 0 ] && \
390 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
392 resetquota -g $TSTUSR
395 # block hard limit (normal use and out of quota)
397 for i in `seq 1 $cycle`; do
398 # define blk_qunit is between 1M and 4M
399 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
400 blk_qtune=$(( $RANDOM % $blk_qunit ))
401 # other osts and mds will occupy at 1M blk quota
402 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
403 set_blk_tunesz $blk_qtune
404 set_blk_unitsz $blk_qunit
405 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
407 echo "=================================================="
408 set_blk_unitsz $((128 * 1024))
409 set_blk_tunesz $((128 * 1024 / 2))
412 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
414 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
418 chmod 0777 $DIR/$tdir
419 TESTFILE="$DIR/$tdir/$tfile-0"
421 wait_delete_completed
424 log " User quota (limit: $LIMIT files)"
425 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
427 quota_show_check f u $TSTUSR
429 log " Create $LIMIT files ..."
430 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
431 quota_error u $TSTUSR "(usr) create failure, but expect success"
433 log " Create out of file quota ..."
434 $RUNAS touch ${TESTFILE}_xxx && \
435 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
437 unlinkmany ${TESTFILE} $LIMIT
438 rm -f ${TESTFILE}_xxx
441 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
442 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
444 [ $MDS_QUOTA_USED -ne 0 ] && \
445 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
447 resetquota -u $TSTUSR
450 log "--------------------------------------"
451 log " Group quota (limit: $LIMIT FILE)"
452 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
454 quota_show_check f g $TSTUSR
455 TESTFILE=$DIR/$tdir/$tfile-1
457 log " Create $LIMIT files ..."
458 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
459 quota_error g $TSTUSR "(grp) create failure, but expect success"
461 log " Create out of file quota ..."
462 $RUNAS touch ${TESTFILE}_xxx && \
463 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
465 unlinkmany ${TESTFILE} $LIMIT
466 rm -f ${TESTFILE}_xxx
469 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
470 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
472 [ $MDS_QUOTA_USED -ne 0 ] && \
473 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
475 resetquota -g $TSTUSR
478 # file hard limit (normal use and out of quota)
480 for i in `seq 1 $cycle`; do
481 if [ $i -eq 1 ]; then
486 # define ino_qunit is between 10 and 100
487 ino_qunit=$(( $RANDOM % 90 + 10 ))
488 ino_qtune=$(( $RANDOM % $ino_qunit ))
489 # RANDOM's maxium is 32767
490 i_limit=$(( $RANDOM % 990 + 10 ))
493 set_file_tunesz $ino_qtune
494 set_file_unitsz $ino_qunit
495 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
497 echo "=================================================="
502 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
506 TIMER=$(($2 * 3 / 2))
509 wait_delete_completed
511 echo " Write to exceed soft limit"
512 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
513 $RUNDD count=$((BUNIT_SZ+1)) || \
514 quota_error a $TSTUSR "write failure, but expect success"
515 OFFSET=$((OFFSET + BUNIT_SZ + 1))
520 $SHOW_QUOTA_INFO_USER
521 $SHOW_QUOTA_INFO_GROUP
523 echo " Write before timer goes off"
524 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
525 quota_error a $TSTUSR "write failure, but expect success"
526 OFFSET=$((OFFSET + BUNIT_SZ))
530 echo " Sleep $TIMER seconds ..."
535 $SHOW_QUOTA_INFO_USER
536 $SHOW_QUOTA_INFO_GROUP
538 echo " Write after timer goes off"
539 # maybe cache write, ignore.
540 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
541 OFFSET=$((OFFSET + BUNIT_SZ))
543 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
544 quota_error a $TSTUSR "write success, but expect EDQUOT"
548 $SHOW_QUOTA_INFO_USER
549 $SHOW_QUOTA_INFO_GROUP
551 echo " Unlink file to stop timer"
558 $SHOW_QUOTA_INFO_USER
559 $SHOW_QUOTA_INFO_GROUP
562 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
570 # block soft limit (start timer, timer goes off, stop timer)
573 chmod 0777 $DIR/$tdir
575 # 1 bunit on mds and 1 bunit on every ost
576 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
579 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
580 TESTFILE=$DIR/$tdir/$tfile-0
582 $LFS setstripe $TESTFILE -c 1
583 chown $TSTUSR.$TSTUSR $TESTFILE
585 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
586 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
588 test_block_soft $TESTFILE $GRACE
589 resetquota -u $TSTUSR
591 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
592 TESTFILE=$DIR/$tdir/$tfile-1
594 $LFS setstripe $TESTFILE -c 1
595 chown $TSTUSR.$TSTUSR $TESTFILE
597 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
598 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
600 test_block_soft $TESTFILE $GRACE
601 resetquota -g $TSTUSR
603 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
608 TIMER=$(($3 * 3 / 2))
610 wait_delete_completed
612 echo " Create files to exceed soft limit"
613 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
614 quota_error a $TSTUSR "create failure, but expect success"
618 echo " Create file before timer goes off"
619 $RUNAS touch ${TESTFILE}_before || \
620 quota_error a $TSTUSR "failed create before timer expired, but expect success"
624 echo " Sleep $TIMER seconds ..."
629 $SHOW_QUOTA_INFO_USER
630 $SHOW_QUOTA_INFO_GROUP
632 echo " Create file after timer goes off"
633 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
634 # inode quota left here
635 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
637 $RUNAS touch ${TESTFILE}_after3 && \
638 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
643 $SHOW_QUOTA_INFO_USER
644 $SHOW_QUOTA_INFO_GROUP
646 echo " Unlink files to stop timer"
647 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
651 $RUNAS touch ${TESTFILE}_xxx || \
652 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
657 rm -f ${TESTFILE}_xxx
661 # file soft limit (start timer, timer goes off, stop timer)
662 test_4a() { # was test_4
664 chmod 0777 $DIR/$tdir
665 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
666 TESTFILE=$DIR/$tdir/$tfile-0
670 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
671 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
672 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
673 quota_show_check f u $TSTUSR
675 test_file_soft $TESTFILE $LIMIT $GRACE
676 resetquota -u $TSTUSR
678 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
679 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
680 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
681 quota_show_check f g $TSTUSR
682 TESTFILE=$DIR/$tdir/$tfile-1
684 test_file_soft $TESTFILE $LIMIT $GRACE
685 resetquota -g $TSTUSR
688 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
689 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
691 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
693 test_4b() { # was test_4a
699 GR_STR6="1111111111111111"
701 wait_delete_completed
703 # test of valid grace strings handling
704 echo " Valid grace strings test"
705 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
706 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
707 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
708 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
710 # test of invalid grace strings handling
711 echo " Invalid grace strings test"
712 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
713 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
716 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
717 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
719 run_test_with_stat 4b "Grace time strings handling ==="
721 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
724 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
725 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
727 wait_delete_completed
729 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
730 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
731 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
732 quota_show_check a u $TSTUSR
733 quota_show_check a g $TSTUSR
735 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
736 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
737 error "touch failure, expect success"
738 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
740 echo " Chown files to $TSTUSR.$TSTUSR ..."
741 for i in `seq 0 $ILIMIT`; do
742 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
743 quota_error a $TSTUSR "chown failure, but expect success"
747 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
750 resetquota -u $TSTUSR
751 resetquota -g $TSTUSR
753 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
755 # block quota acquire & release
757 if [ $OSTCOUNT -lt 2 ]; then
758 skip_env "$OSTCOUNT < 2, too few osts"
762 wait_delete_completed
765 chmod 0777 $DIR/$tdir
767 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
768 FILEA="$DIR/$tdir/$tfile-0_a"
769 FILEB="$DIR/$tdir/$tfile-0_b"
771 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
772 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
773 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
774 quota_show_check b u $TSTUSR
775 quota_show_check b g $TSTUSR
777 echo " Create filea on OST0 and fileb on OST1"
778 $LFS setstripe $FILEA -i 0 -c 1
779 $LFS setstripe $FILEB -i 1 -c 1
780 chown $TSTUSR.$TSTUSR $FILEA
781 chown $TSTUSR.$TSTUSR $FILEB
783 echo " Exceed quota limit ..."
784 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
785 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
786 quota_error a $TSTUSR "write filea failure, but expect success"
791 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
792 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
794 echo " Write to OST1 return EDQUOT"
795 # this write maybe cache write, ignore it's failure
796 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
797 $RUNDD count=$(($BUNIT_SZ * 2)) || true
801 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
802 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
804 echo " Remove filea to let OST0 release quota"
807 if at_is_enabled; then
808 timeout=$(at_max_get mds)
810 timeout=$(lctl get_param -n timeout)
812 count=$((timeout / 5))
813 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
815 while [ $((count--)) -gt 0 ]; do
818 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
819 if [ -z $OST0_QUOTA_HOLD ]; then
820 error "System is error when query quota for block (U:$TSTUSR)."
822 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
828 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
831 while [ $((count--)) -gt 0 ]; do
834 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
835 if [ -z $OST0_QUOTA_HOLD ]; then
836 error "System is error when query quota for block (G:$TSTUSR)."
838 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
844 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
847 echo " Write to OST1"
848 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
849 quota_error a $TSTUSR "write fileb failure, expect success"
856 resetquota -u $TSTUSR
857 resetquota -g $TSTUSR
860 run_test_with_stat 6 "Block quota acquire & release ========="
862 # quota recovery (block quota only by now)
866 chmod 0777 $DIR/$tdir
868 wait_delete_completed
870 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
871 TESTFILE="$DIR/$tdir/$tfile-0"
873 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
875 $LFS setstripe $TESTFILE -c 1
876 chown $TSTUSR.$TSTUSR $TESTFILE
878 echo " Write to OST0..."
879 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
880 quota_error u $TSTUSR "write failure, but expect success"
882 #define OBD_FAIL_OBD_DQACQ 0x604
883 lustre_fail mds 0x604
884 echo " Remove files on OST0"
888 echo " Trigger recovery..."
889 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
890 for i in $OSC0_UUID; do
891 $LCTL --device $i activate || error "activate osc failed!"
894 # sleep a while to wait for recovery done
898 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
899 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
900 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
901 echo " total limits = $TOTAL_LIMIT"
903 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
904 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
905 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
906 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
907 echo " limits on $OST0_UUID = $OST0_LIMIT"
910 resetquota -u $TSTUSR
912 run_test_with_stat 7 "Quota recovery (only block limit) ======"
914 # run dbench with quota enabled
917 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
920 wait_delete_completed
922 echo " Set enough high limit for user: $TSTUSR"
923 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
924 echo " Set enough high limit for group: $TSTUSR"
925 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
927 chmod 0777 $DIR/$tdir
929 [ "$SLOW" = "no" ] && duration=" -t 120"
930 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
937 run_test_with_stat 8 "Run dbench with quota enabled ==========="
939 # run for fixing bug10707, it needs a big room. test for 64bit
941 GB=$((KB * 1024 * 1024))
942 # Use this as dd bs to decrease time
943 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
944 blksize=$((1 << 21)) # 2Mb
945 size_file=$((GB * 9 / 2))
946 # this check is just for test_9
947 OST0_MIN=4900000 #4.67G
948 check_whether_skip () {
949 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
950 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
951 if [ $OST0_SIZE -lt $OST0_MIN ]; then
952 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
960 check_whether_skip && return 0
962 wait_delete_completed
968 chmod 0777 $DIR/$tdir
969 TESTFILE="$DIR/$tdir/$tfile-0"
971 BLK_LIMIT=$((100 * KB * KB)) # 100G
973 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
975 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
976 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
977 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
978 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
980 quota_show_check a u $TSTUSR
981 quota_show_check a g $TSTUSR
984 $LFS setstripe $TESTFILE -c 1 -i 0
986 chown $TSTUSR.$TSTUSR $TESTFILE
988 log " Write the big file of 4.5G ..."
989 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
990 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
995 log " delete the big file of 4.5G..."
996 $RUNAS rm -f $TESTFILE
1004 set_blk_unitsz $((128 * 1024))
1005 set_blk_tunesz $((128 * 1024 / 2))
1009 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1011 # 2.0 version does not support 32 bit qd_count,
1012 # test_10 "run for fixing bug10707(32bit) " is obsolete
1014 # test a deadlock between quota and journal b=11693
1017 chmod 0777 $DIR/$tdir
1019 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1020 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1022 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1023 TESTFILE="$DIR/$tdir/$tfile-0"
1024 TESTFILE2="$DIR2/$tdir/$tfile-1"
1026 wait_delete_completed
1028 echo " User quota (limit: $LIMIT kbytes)"
1029 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1031 $LFS setstripe $TESTFILE -i 0 -c 1
1032 chown $TSTUSR.$TSTUSR $TESTFILE
1033 $LFS setstripe $TESTFILE2 -i 0 -c 1
1034 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1036 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1037 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1038 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1040 echo " step1: write out of block quota ..."
1041 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1043 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1046 echo " step2: testing ......"
1047 local last_size=$(stat -c %s $TESTFILE2)
1049 local start_secs=$SECONDS
1050 while [ -d /proc/${DDPID1} ]; do
1051 local size=$(stat -c %s $TESTFILE2)
1052 if [ $size -eq $last_size ]; then
1053 stall_secs=$[stall_secs+1]
1057 if [ $stall_secs -gt 30 ]; then
1059 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1064 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1066 #Recover fail_loc and dd will finish soon
1069 echo " step3: testing ......"
1072 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1074 if [ $count -gt 150 ]; then
1075 quota_error u $TSTUSR "dd should be finished!"
1079 echo "(dd_pid=$DDPID, time=$count)successful"
1081 rm -f $TESTFILE $TESTFILE2
1082 sync; sleep 3; sync;
1084 resetquota -u $TSTUSR
1086 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1088 # test multiple clients write block quota b=11693
1091 wait_delete_completed
1093 # one OST * 10 + (mds + other OSTs)
1094 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1095 TESTFILE="$DIR/$tdir/$tfile"
1097 echo " User quota (limit: $LIMIT kbytes)"
1098 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1099 quota_show_check b u $TSTUSR
1101 $LFS setstripe $TESTFILE -i 0 -c 1
1102 chown $TSTUSR.$TSTUSR $TESTFILE
1103 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1104 chown $TSTUSR.$TSTUSR $TESTFILE.2
1106 echo " step1: write out of block quota ..."
1107 # one bunit will give mds
1108 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1110 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1113 echo " step2: testing ......"
1116 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1118 if [ $count -gt 64 ]; then
1119 quota_error u $TSTUSR "dd should be finished!"
1123 echo "(dd_pid=$DDPID, time=$count)successful"
1127 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1129 if [ $count -gt 64 ]; then
1130 quota_error u $TSTUSR "dd should be finished!"
1134 echo "(dd_pid=$DDPID1, time=$count)successful"
1136 sync; sleep 5; sync;
1138 echo " step3: checking ......"
1139 fz=`stat -c %s $TESTFILE`
1140 fz2=`stat -c %s $TESTFILE.2`
1142 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1143 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1145 rm -f $TESTFILE $TESTFILE.2
1146 sync; sleep 3; sync;
1148 resetquota -u $TSTUSR
1150 run_test_with_stat 13 "test multiple clients write block quota ==="
1152 check_if_quota_zero(){
1153 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1154 for i in `seq 3 $line`; do
1155 if [ $i -eq 3 ]; then
1161 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1162 awk '{print $'"$j"'}'`
1163 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1164 error "quota on $2 isn't clean"
1167 echo "pass check_if_quota_zero"
1170 test_14a() { # was test_14 b=12223 -- setting quota on root
1171 TESTFILE="$DIR/$tdir/$tfile"
1175 cleanup_and_setup_lustre
1180 # out of root's file and block quota
1181 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1182 createmany -m ${TESTFILE} 20 || \
1183 quota_error u root "unexpected: user(root) create files failly!"
1184 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1185 quota_error u root "unexpected: user(root) write files failly!"
1187 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1188 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1192 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1193 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1196 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1198 #check_if_quota_zero u root
1201 unlinkmany ${TESTFILE} 15
1203 sync; sleep 3; sync;
1205 run_test_with_stat 14a "test setting quota on root ==="
1208 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1209 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1211 wait_delete_completed
1214 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1215 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1216 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1217 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1218 resetquota -u $TSTUSR
1221 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1222 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1223 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1224 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1225 resetquota -g $TSTUSR
1226 $LFS quotaoff -ug $DIR
1227 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1228 error "fail to set version for $SINGLEMDS"
1229 for j in `seq $OSTCOUNT`; do
1230 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1231 error "fail to set version for ost$j"
1234 $LFS quotacheck -ug $DIR
1236 run_test_with_stat 15 "set block quota more than 4T ==="
1238 # 2.0 version does not support WITHOUT_CHANGE_QS,
1239 # test_16 "test without adjusting qunit" is obsolete
1241 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1246 wait_delete_completed
1248 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1249 lustre_fail ost 0x80000A02
1251 TESTFILE="$DIR/$tdir/$tfile-a"
1252 TESTFILE2="$DIR/$tdir/$tfile-b"
1255 BLK_LIMIT=$((100 * 1024)) # 100M
1257 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1258 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1259 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1260 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1262 quota_show_check b u $TSTUSR
1263 quota_show_check b g $TSTUSR
1266 chown $TSTUSR.$TSTUSR $TESTFILE
1268 chown $TSTUSR.$TSTUSR $TESTFILE2
1270 log " Write the test file1 ..."
1271 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1272 || quota_error a $TSTUSR "write 10M file failure"
1277 log " write the test file2 ..."
1278 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1279 || quota_error a $TSTUSR "write 10M file failure"
1284 rm -f $TESTFILE $TESTFILE2
1286 sync; sleep 3; sync;
1288 # make qd_count 64 bit
1291 set_blk_unitsz $((128 * 1024))
1292 set_blk_tunesz $((128 * 1024 / 2))
1294 resetquota -u $TSTUSR
1295 resetquota -g $TSTUSR
1299 run_test_with_stat 17 "run for fixing bug14526 ==========="
1301 # test when mds takes a long time to handle a quota req so that
1302 # the ost has dropped it, the ost still could work well b=14840
1304 LIMIT=$((100 * 1024 * 1024)) # 100G
1305 TESTFILE="$DIR/$tdir/$tfile"
1308 wait_delete_completed
1313 log " User quota (limit: $LIMIT kbytes)"
1314 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1315 quota_show_check b u $TSTUSR
1317 $LFS setstripe $TESTFILE -i 0 -c 1
1318 chown $TSTUSR.$TSTUSR $TESTFILE
1320 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1321 lustre_fail mds 0x13c
1323 log " step1: write 100M block ..."
1324 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1330 echo " step2: testing ......"
1332 if at_is_enabled; then
1333 timeout=$(at_max_get mds)
1335 timeout=$(lctl get_param -n timeout)
1338 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1340 if [ $count -gt $((4 * $timeout)) ]; then
1341 quota_error u $TSTUSR "count=$count dd should be finished!"
1345 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1347 cancel_lru_locks mdc
1348 cancel_lru_locks osc
1350 testfile_size=$(stat -c %s $TESTFILE)
1351 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1352 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1357 resetquota -u $TSTUSR
1358 set_blk_unitsz $((128 * 1024))
1359 set_blk_tunesz $((128 * 1024 / 2))
1361 run_test_with_stat 18 "run for fixing bug14840 ==========="
1363 # test when mds drops a quota req, the ost still could work well b=14840
1365 LIMIT=$((100 * 1024 * 1024)) # 100G
1366 TESTFILE="$DIR/$tdir/$tfile-a"
1369 wait_delete_completed
1374 log " User quota (limit: $LIMIT kbytes)"
1375 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1376 quota_show_check b u $TSTUSR
1378 $LFS setstripe $TESTFILE -i 0 -c 1
1379 chown $TSTUSR.$TSTUSR $TESTFILE
1381 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1382 lustre_fail mds 0x8000013d
1384 log " step1: write 100M block ..."
1385 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1388 echo " step2: testing ......"
1390 if at_is_enabled; then
1391 timeout=$(at_max_get mds)
1393 timeout=$(lctl get_param -n timeout)
1396 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1398 if [ $count -gt $((6 * $timeout)) ]; then
1400 quota_error u $TSTUSR "count=$count dd should be finished!"
1404 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1410 resetquota -u $TSTUSR
1411 set_blk_unitsz $((128 * 1024))
1412 set_blk_tunesz $((128 * 1024 / 2))
1414 run_test_with_stat 18a "run for fixing bug14840 ==========="
1416 # test when mds do failover, the ost still could work well without trigger
1421 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1422 TESTFILE="$DIR/$tdir/$tfile"
1425 wait_delete_completed
1430 log " User quota (limit: $LIMIT kbytes)"
1431 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1432 quota_show_check b u $TSTUSR
1434 $LFS setstripe $TESTFILE -i 0 -c 1
1435 chown $TSTUSR.$TSTUSR $TESTFILE
1437 timeout=$(sysctl -n lustre.timeout)
1439 if [ $type = "directio" ]; then
1440 log " write 100M block(directio) ..."
1441 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1443 log " write 100M block(normal) ..."
1444 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1448 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1450 replay_barrier $SINGLEMDS
1452 log "failing mds for $((2 * timeout)) seconds"
1453 fail $SINGLEMDS $((2 * timeout))
1455 # check if quotaon successful
1456 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1457 if [ $? -eq 0 ]; then
1459 error "quotaon failed!"
1464 if at_is_enabled; then
1465 timeout=$(at_max_get mds)
1467 timeout=$(lctl get_param -n timeout)
1470 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1471 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1472 log "it took $count second"
1476 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1478 cancel_lru_locks mdc
1479 cancel_lru_locks osc
1482 resetquota -u $TSTUSR
1483 set_blk_unitsz $((128 * 1024))
1484 set_blk_tunesz $((128 * 1024 / 2))
1485 testfile_size=$(stat -c %s $TESTFILE)
1486 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1488 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1494 # test when mds does failover, the ost still could work well
1495 # this test shouldn't trigger watchdog b=14840
1497 test_18bc_sub normal
1498 test_18bc_sub directio
1499 # check if watchdog is triggered
1500 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1501 watchdog=`awk '/test 18b/ {start = 1;}
1502 /Service thread pid/ && /was inactive/ {
1506 }' $TMP/lustre-log-${TESTNAME}.log`
1507 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1508 rm -f $TMP/lustre-log-${TESTNAME}.log
1510 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1512 # test when mds does failover, the ost still could work well
1513 # this test will prevent OST_DISCONNET from happening b=14840
1515 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1516 lustre_fail ost 0x202
1517 test_18bc_sub normal
1518 test_18bc_sub directio
1521 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1523 run_to_block_limit() {
1524 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1526 wait_delete_completed
1528 # set 1 Mb quota unit size
1532 # bind file to a single OST
1533 $LFS setstripe -c 1 $TESTFILE
1534 chown $TSTUSR.$TSTUSR $TESTFILE
1536 echo " User quota (limit: $LIMIT kbytes)"
1537 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1538 quota_show_check b u $TSTUSR
1539 echo " Updating quota limits"
1540 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1541 quota_show_check b u $TSTUSR
1543 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1544 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1545 # for now page cache of TESTFILE may still be dirty,
1546 # let's push it to the corresponding OST, this will also
1547 # cache NOQUOTA on the client from OST's reply
1548 cancel_lru_locks osc
1549 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1553 # 1 Mb bunit per each MDS/OSS
1554 local TESTFILE="$DIR/$tdir/$tfile"
1557 run_to_block_limit $TESTFILE
1562 resetquota -u $TSTUSR
1564 set_blk_unitsz $((128 * 1024))
1565 set_blk_tunesz $((128 * 1024 / 2))
1568 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1572 LSTR=(1t 2g 3m 4k) # limits strings
1573 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1575 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1576 $MOUNT || error "could not set quota limits"
1578 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1579 --inode-softlimit ${LSTR[2]} \
1580 --inode-hardlimit ${LSTR[3]} \
1581 $MOUNT || error "could not set quota limits"
1583 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1584 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1585 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1586 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1588 resetquota -u $TSTUSR
1590 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1597 time=$(($(date +%s) + seconds))
1598 while [ $(date +%s) -lt $time ]; do
1599 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1604 # run for fixing bug16053, setquota shouldn't fail when writing and
1605 # deleting are happening
1610 wait_delete_completed
1612 TESTFILE="$DIR/$tdir/$tfile"
1614 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1617 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1618 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1619 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1620 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1622 # repeat writing on a 1M file
1623 test_21_sub ${TESTFILE}_1 1024 30 &
1625 # repeat writing on a 128M file
1626 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1629 time=$(($(date +%s) + 30))
1631 while [ $(date +%s) -lt $time ]; do
1632 log " Set quota for $i times"
1633 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1634 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1641 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1643 if [ $count -gt 60 ]; then
1644 quota_error a $TSTUSR "dd should be finished!"
1648 echo "(dd_pid=$DDPID1, time=$count)successful"
1652 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1654 if [ $count -gt 60 ]; then
1655 quota_error a $TSTUSR "dd should be finished!"
1659 echo "(dd_pid=$DDPID2, time=$count)successful"
1661 set_blk_unitsz $((128 * 1024))
1662 set_blk_tunesz $((128 * 1024 / 2))
1663 resetquota -u $TSTUSR
1664 resetquota -g $TSTUSR
1668 run_test_with_stat 21 "run for fixing bug16053 ==========="
1671 quota_save_version "ug3"
1677 echo "checking parameters"
1679 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1680 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1684 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1688 chmod 0777 $DIR/$tdir
1689 TESTFILE="$DIR/$tdir/$tfile-0"
1691 local bs_unit=$((1024*1024))
1694 wait_delete_completed
1697 log " User quota (limit: $LIMIT kbytes)"
1698 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1700 quota_show_check b u $TSTUSR
1702 $LFS setstripe $TESTFILE -c 1 -i 0
1703 chown $TSTUSR.$TSTUSR $TESTFILE
1705 log " Step1: trigger quota with 0_DIRECT"
1706 log " Write half of file"
1707 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1708 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1709 log " Write out of block quota ..."
1710 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1711 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1714 log " Step2: rewrite should succeed"
1715 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1716 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1720 wait_delete_completed
1721 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1722 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1723 echo $OST0_QUOTA_USED
1724 [ $OST0_QUOTA_USED -ne 0 ] && \
1725 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1727 resetquota -u $TSTUSR
1731 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1733 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1734 check_whether_skip && return 0
1735 log "run for $((4 * $slave_cnt))MB test file"
1736 test_23_sub $((4 * $slave_cnt * 1024))
1738 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1739 check_whether_skip && return 0
1740 log "run for $((40 * $slave_cnt))MB test file"
1741 test_23_sub $((40 * $slave_cnt * 1024))
1743 run_test_with_stat 23 "run for fixing bug16125 ==========="
1746 local TESTFILE="$DIR/$tdir/$tfile"
1749 run_to_block_limit $TESTFILE
1750 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1754 resetquota -u $TSTUSR
1756 set_blk_unitsz $((128 * 1024))
1757 set_blk_tunesz $((128 * 1024 / 2))
1760 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1763 if [ $1 = "-u" ]; then
1764 if [ $2 = "$TSTUSR" ]; then
1770 if [ $2 = "$TSTUSR" ]; then
1780 chmod 0777 $DIR/$tdir
1781 TESTFILE="$DIR/$tdir/$tfile-0"
1783 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1785 wait_delete_completed
1787 # set quota for $TSTUSR
1788 log "setquota for $TSTUSR"
1789 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1791 if [ "$1" == "-u" ]; then
1792 quota_show_check a u $TSTUSR
1794 quota_show_check a g $TSTUSR
1797 # set quota for $TSTUSR2
1798 log "setquota for $TSTUSR2"
1799 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1801 if [ "$1" == "-u" ]; then
1802 quota_show_check a u $TSTUSR2
1804 quota_show_check a g $TSTUSR2
1807 # set stripe index to 0
1808 log "setstripe for $DIR/$tdir to 0"
1809 $LFS setstripe $DIR/$tdir -c 1 -i 0
1810 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1811 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1812 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1813 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1814 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1815 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1818 log "$TSTUSR write 4M to $TESTFILE"
1819 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1821 show_quota $1 $TSTUSR
1822 show_quota $1 $TSTUSR2
1823 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1824 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1825 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1826 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1827 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1828 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1829 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1831 # chown/chgrp from $TSTUSR to $TSTUSR2
1832 if [ $1 = "-u" ]; then
1833 log "chown from $TSTUSR to $TSTUSR2"
1834 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1836 log "chgrp from $TSTUSR to $TSTUSR2"
1837 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1840 show_quota $1 $TSTUSR
1841 show_quota $1 $TSTUSR2
1842 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1843 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1844 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1845 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1846 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1847 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1848 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1849 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1850 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1851 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1852 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1853 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1854 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1855 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1856 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1859 wait_delete_completed
1860 resetquota $1 $TSTUSR
1861 resetquota $1 $TSTUSR2
1865 log "run for chown case"
1868 log "run for chgrp case"
1871 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1875 chmod 0777 $DIR/$tdir
1876 TESTFILE="$DIR/$tdir/$tfile-0"
1877 TESTFILE2="$DIR/$tdir/$tfile-1"
1881 wait_delete_completed
1883 # every quota slave gets 20MB
1884 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1885 log "limit: ${b_limit}KB"
1886 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1888 quota_show_check b u $TSTUSR
1890 $LFS setstripe $TESTFILE -c 1 -i 0
1891 $LFS setstripe $TESTFILE2 -c 1 -i 0
1892 chown $TSTUSR.$TSTUSR $TESTFILE
1893 chown $TSTUSR.$TSTUSR $TESTFILE2
1895 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1896 lustre_fail ost 0xA03
1898 log " Write the first file..."
1899 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1900 log " Delete the first file..."
1904 wait_delete_completed
1906 log " Write the second file..."
1907 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1908 log " Delete the second file..."
1912 set_blk_unitsz $((128 * 1024))
1913 set_blk_tunesz $((128 * 1024 / 2))
1914 resetquota -u $TSTUSR
1916 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1919 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1920 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1923 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1926 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1927 error "lfs setquota failed with uid argument"
1928 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1929 error "lfs stequota failed with gid argument"
1930 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1931 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1932 resetquota -u $TSTUSR
1933 resetquota -g $TSTUSR
1936 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1939 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1940 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1941 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1944 echo "Step 2: reset system ..."
1945 cleanup_and_setup_lustre
1948 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1952 wait_delete_completed
1954 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1955 lustre_fail ost 0x80000A02
1957 TESTFILE="$DIR/$tdir/$tfile"
1960 BLK_LIMIT=$((100 * 1024)) # 100M
1961 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1962 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1966 chown $TSTUSR.$TSTUSR $TESTFILE
1968 echo "Step 5: write the test file1 [10M] ..."
1969 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1970 || quota_error a $TSTUSR "write 10M file failure"
1974 sync; sleep 3; sync;
1976 # make qd_count 64 bit
1979 set_blk_unitsz $((128 * 1024))
1980 set_blk_tunesz $((128 * 1024 / 2))
1982 resetquota -u $TSTUSR
1984 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
1988 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1997 if at_is_enabled; then
1998 timeout=$(at_max_get client)
1999 [ $(at_min_get client) -gt $at_max_val ] &&
2000 at_max_val=$(at_min_get client)
2001 at_max_set $at_max_val client
2003 timeout=$(lctl get_param -n timeout)
2004 lctl set_param timeout=$at_max_val
2006 # actually send a RPC to make service at_current confined within at_max
2007 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR ||
2008 error "should succeed"
2010 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2011 lustre_fail mds 0x12e
2013 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2015 deadline=$((2 * (($at_max_val << 1) + ($at_max_val >> 2) + 5)))
2016 echo "wait at most 2 * ($at_max_val * 2.25 + 5) = $deadline seconds," \
2017 "it is server process time add the network latency."
2020 while [ $waited -lt $deadline ]; do
2023 waited=$(($waited + 1))
2024 ps -p $pid > /dev/null || break
2026 echo "waited $waited seconds"
2027 ps -p $pid && error "lfs hadn't finished by $deadline seconds"
2028 wait $pid && error "succeeded, but should have failed"
2032 if at_is_enabled; then
2033 at_max_set $timeout client
2035 lctl set_param timeout=$timeout
2038 resetquota -u $TSTUSR
2040 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2046 local TESTFILE="$DIR/$tdir/$tfile"
2053 chmod 0777 $DIR/$tdir
2055 $LFS setstripe $TESTFILE -i 0 -c 1
2056 chown $TSTUSR.$TSTUSR $TESTFILE
2058 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2059 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2060 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2061 cancel_lru_locks osc
2063 $LFS setquota -u $TSTUSR -B 0 $DIR
2064 # over-quota flag has not yet settled since we do not trigger async events
2065 # based on grace time period expiration
2067 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2068 cancel_lru_locks osc
2069 # now over-quota flag should be settled and further writes should fail
2071 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2073 resetquota -u $TSTUSR
2074 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2076 set_blk_unitsz $((128 * 1024))
2077 set_blk_tunesz $((128 * 1024 / 2))
2079 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2081 # test duplicate quota releases b=18630
2084 chmod 0777 $DIR/$tdir
2086 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2087 TESTFILE="$DIR/$tdir/$tfile-0"
2088 TESTFILE2="$DIR/$tdir/$tfile-1"
2090 wait_delete_completed
2092 log " User quota (limit: $LIMIT kbytes)"
2093 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2095 $LFS setstripe $TESTFILE -i 0 -c 1
2096 chown $TSTUSR.$TSTUSR $TESTFILE
2097 $LFS setstripe $TESTFILE2 -i 0 -c 1
2098 chown $TSTUSR.$TSTUSR $TESTFILE2
2100 log " step1: write out of block quota ..."
2101 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2102 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2104 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2105 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2106 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2108 log " step2: delete two files so that triggering duplicate quota release ..."
2109 rm -f $TESTFILE $TESTFILE2
2110 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2111 wait_delete_completed
2113 log " step3: verify if the ost failed"
2114 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2115 watchdog=`awk '/test 31/ {start = 1;}
2116 /release quota error/ {
2120 }' $TMP/lustre-log-${TESTNAME}.log`
2121 [ "$watchdog" ] && error "$watchdog"
2122 rm -f $TMP/lustre-log-${TESTNAME}.log
2125 resetquota -u $TSTUSR
2127 run_test_with_stat 31 "test duplicate quota releases ==="
2129 # check hash_cur_bits
2130 check_quota_hash_cur_bits() {
2133 # check quota_hash_cur_bits on all obdfilters
2134 for num in `seq $OSTCOUNT`; do
2135 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2136 if [ $cb -gt $bits ]; then
2137 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2141 # check quota_hash_cur_bits on mds
2142 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2143 if [ $cb -gt $bits ]; then
2144 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2152 # check distribution of all obdfilters
2153 for num in `seq $OSTCOUNT`; do
2154 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2155 rehash_count=`echo $line | awk '{print $9}'`
2156 if [ $rehash_count -eq 0 ]; then
2157 echo -e "ost$num:\n $line"
2158 error "Rehearsh didn't happen"
2162 # check distribution of mds
2163 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2164 rehash_count=`echo $line | awk '{print $9}'`
2165 if [ $rehash_count -eq 0 ]; then
2166 echo -e "mdt:\n $line"
2167 error "Rehearsh didn't happen"
2174 # reset system so that quota_hash_cur_bits==3
2175 echo "Reset system ..."
2176 local LMR_orig=$LOAD_MODULES_REMOTE
2177 LOAD_MODULES_REMOTE=true
2178 cleanup_and_setup_lustre
2179 LOAD_MODULES_REMOTE=$LMR_orig
2185 for user in $SANITY_QUOTA_USERS; do
2186 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2187 missing_users="$missing_users $user"
2189 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2190 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2192 $LFS quotaoff -ug $DIR
2193 $LFS quotacheck -ug $DIR
2195 for user in $SANITY_QUOTA_USERS; do
2196 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2201 for user in $SANITY_QUOTA_USERS; do
2205 run_test 32 "check lqs hash(bug 21846) =========================================="
2207 cleanup_quota_test() {
2209 echo "Delete files..."
2213 # basic usage tracking for user & group
2216 chmod 0777 $DIR/$tdir
2219 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2221 trap cleanup_quota_test EXIT
2223 # make sure the system is clean
2224 USED=`getquota -u $TSTID global curspace`
2225 [ $USED -ne 0 ] && \
2226 error "Used space ($USED) for user $TSTID isn't 0."
2227 USED=`getquota -g $TSTID global curspace`
2228 [ $USED -ne 0 ] && \
2229 error "Used space ($USED) for group $TSTID isn't 0."
2231 for i in `seq 0 $INODES`; do
2232 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i conv=fsync \
2233 bs=$((BLK_SZ * BLK_CNT)) count=1 2>/dev/null ||
2234 error "write failed"
2235 echo "Iteration $i/$INODES completed"
2237 sync; sync_all_data;
2239 echo "Verify disk usage after write"
2240 USED=`getquota -u $TSTID global curspace`
2241 [ $USED -lt $TOTAL_BLKS ] && \
2242 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2243 USED=`getquota -u $TSTID global curinodes`
2244 [ $USED -lt $INODES ] && \
2245 error "Used inode for user $TSTID is $USED, expected $INODES"
2247 USED=`getquota -g $TSTID global curspace`
2248 [ $USED -lt $TOTAL_BLKS ] && \
2249 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2250 USED=`getquota -g $TSTID global curinodes`
2251 [ $USED -lt $INODES ] && \
2252 error "Used inode for group $TSTID is $USED, expected $INODES"
2256 echo "Verify disk usage after delete"
2257 wait_delete_completed
2258 sync; sync_all_data;
2260 USED=`getquota -u $TSTID global curspace`
2261 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2262 USED=`getquota -u $TSTID global curinodes`
2263 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2264 USED=`getquota -g $TSTID global curspace`
2265 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2266 USED=`getquota -g $TSTID global curinodes`
2267 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2269 run_test 33 "basic usage tracking for user & group =============================="
2271 # usage transfer test for user & group
2275 chmod 0777 $DIR/$tdir
2277 trap cleanup_quota_test EXIT
2279 # make sure the system is clean
2280 USED=`getquota -u $TSTID global curspace`
2281 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2282 USED=`getquota -g $TSTID global curspace`
2283 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2285 echo "Write file..."
2286 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) count=1 \
2287 conv=fsync 2>/dev/null || error "write failed"
2288 sync; sync_all_data;
2290 echo "chown the file to user $TSTID"
2291 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2293 echo "Wait for setattr on objects finished..."
2294 wait_delete_completed
2296 echo "Verify disk usage for user $TSTID"
2297 USED=`getquota -u $TSTID global curspace`
2298 [ $USED -lt $BLK_CNT ] && \
2299 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2300 USED=`getquota -u $TSTID global curinodes`
2301 [ $USED -ne 1 ] && \
2302 error "Used inodes for user $TSTID is $USED, expected 1"
2304 echo "chgrp the file to group $TSTID"
2305 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2307 echo "Wait for setattr on objects finished..."
2308 wait_delete_completed
2310 echo "Verify disk usage for group $TSTID"
2311 USED=`getquota -g $TSTID global curspace`
2312 [ $USED -ge $BLK_CNT ] || \
2313 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2314 USED=`getquota -g $TSTID global curinodes`
2315 [ $USED -eq 1 ] || \
2316 error "Used inodes for group $TSTID is $USED, expected 1"
2320 run_test 34 "usage transfer for user & group ===================================="
2322 # usage is still accessible across restart
2325 chmod 0777 $DIR/$tdir
2328 trap cleanup_quota_test EXIT
2330 echo "Write file..."
2331 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2332 count=1 conv=fsync 2>/dev/null || error "write failed"
2333 sync; sync_all_data;
2335 echo "Save disk usage before restart"
2336 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2337 [ $ORIG_USR_SPACE -eq 0 ] && \
2338 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2339 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2340 [ $ORIG_USR_INODES -eq 0 ] && \
2341 error "Used inodes for user $TSTID is 0, expected 1"
2342 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2343 [ $ORIG_GRP_SPACE -eq 0 ] && \
2344 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2345 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2346 [ $ORIG_GRP_INODES -eq 0 ] && \
2347 error "Used inodes for group $TSTID is 0, expected 1"
2350 local ORIG_REFORMAT=$REFORMAT
2352 cleanup_and_setup_lustre
2353 REFORMAT=$ORIG_REFORMAT
2356 echo "Verify disk usage after restart"
2357 USED=`getquota -u $TSTID global curspace`
2358 [ $USED -eq $ORIG_USR_SPACE ] || \
2359 error "Used space for user $TSTID changed from " \
2360 "$ORIG_USR_SPACE to $USED"
2361 USED=`getquota -u $TSTID global curinodes`
2362 [ $USED -eq $ORIG_USR_INODES ] || \
2363 error "Used inodes for user $TSTID changed from " \
2364 "$ORIG_USR_INODES to $USED"
2365 USED=`getquota -g $TSTID global curspace`
2366 [ $USED -eq $ORIG_GRP_SPACE ] || \
2367 error "Used space for group $TSTID changed from " \
2368 "$ORIG_GRP_SPACE to $USED"
2369 USED=`getquota -g $TSTID global curinodes`
2370 [ $USED -eq $ORIG_GRP_INODES ] || \
2371 error "Used inodes for group $TSTID changed from " \
2372 "$ORIG_GRP_INODES to $USED"
2374 # check if the vfs_dq_init() is called before writing
2375 echo "Append to the same file..."
2376 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$((BLK_SZ * BLK_CNT)) \
2377 count=1 seek=1 conv=fsync 2>/dev/null || error "write failed"
2378 sync; sync_all_data;
2380 echo "Verify space usage is increased"
2381 USED=`getquota -u $TSTID global curspace`
2382 [ $USED -gt $ORIG_USR_SPACE ] ||
2383 error "Used space for user $TSTID isn't increased" \
2384 "orig:$ORIG_USR_SPACE, now:$USED"
2385 USED=`getquota -g $TSTID global curspace`
2386 [ $USED -gt $ORIG_GRP_SPACE ] ||
2387 error "Used space for group $TSTID isn't increased" \
2388 "orig:$ORIG_GRP_SPACE, now:$USED"
2392 run_test 35 "usage is still accessible across reboot ============================"
2398 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2404 # override TESTSUITE so Maloo keeps only one set of sanity-quota results
2405 TESTSUITE=sanity-quota.sh
2407 check_and_cleanup_lustre
2408 export QUOTA_AUTO=$QUOTA_AUTO_OLD