3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
9 #kernel 2.4.x doesn't support quota
10 K_VER=`uname --kernel-release | cut -b 1-3`
11 if [ $K_VER = "2.4" ]; then
12 echo "Kernel 2.4 doesn't support quota"
17 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
20 # test_11 has been used to protect a kernel bug(bz10912), now it isn't
21 # useful any more. Then add it to ALWAYS_EXCEPT. b=19835
22 # We have changed the mechanism of quota, test_12 is meanless now.
24 ALWAYS_EXCEPT="10 12 $SANITY_QUOTA_EXCEPT"
25 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
28 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
29 *) error "unsupported kernel" ;;
32 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
33 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
39 TSTID2=${TSTID2:-60001}
40 TSTUSR=${TSTUSR:-"quota_usr"}
41 TSTUSR2=${TSTUSR2:-"quota_2usr"}
43 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
44 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
47 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
48 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
49 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
50 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
51 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
53 export MULTIOP=${MULTIOP:-multiop}
55 LUSTRE=${LUSTRE:-`dirname $0`/..}
56 . $LUSTRE/tests/test-framework.sh
58 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
60 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
62 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
64 require_dsh_mds || exit 0
65 require_dsh_ost || exit 0
67 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
69 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
71 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
76 QUOTA_AUTO_OLD=$QUOTA_AUTO
79 check_and_setup_lustre
81 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
82 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
84 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
85 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
86 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
87 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
88 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
89 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
90 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
91 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
93 # control the time of tests
95 [ "$SLOW" = "no" ] && cycle=10
99 # set_blk_tunables(btune_sz)
101 local btune=$(($1 * BLK_SZ))
102 # set btune size on all obdfilters
103 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
104 # set btune size on mds
105 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
108 # set_blk_unitsz(bunit_sz)
110 local bunit=$(($1 * BLK_SZ))
111 # set bunit size on all obdfilters
112 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
113 # set bunit size on mds
114 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
117 # set_file_tunesz(itune_sz)
120 # set itune size on mds
121 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
124 # set_file_unitsz(iunit_sz)
127 # set iunit size on mds
128 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
134 local fail_val=${3:-0}
136 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
137 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
138 [ $((fail_loc)) -eq 0 ]; then
139 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
141 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
143 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
144 for num in `seq $OSTCOUNT`; do
145 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
146 [ $((fail_loc)) -eq 0 ]; then
147 do_facet ost$num "lctl set_param fail_val=$fail_val"
149 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
154 RUNAS="runas -u $TSTID -g $TSTID"
155 RUNAS2="runas -u $TSTID2 -g $TSTID2"
156 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
157 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
161 run_test_with_stat() {
162 (($# != 2)) && error "the number of arguments is wrong"
164 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
165 for j in `seq $OSTCOUNT`; do
166 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
169 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
170 echo "statistics info begin ***************************************"
171 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
172 for j in `seq $OSTCOUNT`; do
173 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
175 echo "statistics info end ***************************************"
180 # clear quota limits for a user or a group
181 # usage: resetquota -u username
182 # resetquota -g groupname
185 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
186 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
189 if at_is_enabled; then
190 timeout=$(at_max_get mds)
192 timeout=$(lctl get_param -n timeout)
195 while [ $((count++)) -lt $timeout ]; do
197 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
198 if [ $RC -ne 0 ]; then
199 if echo "$OUTPUT" | grep -q busy; then
200 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
204 error "resetquota failed"
210 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
217 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
218 log "Files for user ($LOCAL_ID):"
219 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
222 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
223 log "Files for group ($LOCAL_ID):"
224 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
241 # get quota info for a user or a group
242 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
248 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
249 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
262 *) error "unknown quota parameter $4";;
265 [ "$uuid" = "global" ] && uuid=$DIR
267 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
274 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
276 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
278 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
279 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
280 if [ -z $USAGE ]; then
281 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
283 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
287 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
288 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
289 if [ -z $USAGE ]; then
290 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
292 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
299 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
301 log "do the quotacheck ..."
302 $LFS quotacheck -ug $DIR
304 resetquota -u $TSTUSR
305 resetquota -g $TSTUSR
309 test_quota_performance() {
310 TESTFILE="$DIR/$tdir/$tfile-0"
312 local stime=`date +%s`
313 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
314 local etime=`date +%s`
315 delta=$((etime - stime))
316 if [ $delta -gt 0 ]; then
317 rate=$((size * 1024 / delta))
318 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
323 # test basic quota performance b=21696
326 chmod 0777 $DIR/$tdir
328 [ "$SLOW" = "no" ] && MB=10
330 test_quota_performance $MB
332 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
333 test_quota_performance $MB
335 resetquota -u $TSTUSR
337 run_test_with_stat 0 "Test basic quota performance ==="
339 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
343 chmod 0777 $DIR/$tdir
344 TESTFILE="$DIR/$tdir/$tfile-0"
346 wait_delete_completed
349 log " User quota (limit: $LIMIT kbytes)"
350 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
352 quota_show_check b u $TSTUSR
354 $LFS setstripe $TESTFILE -c 1
355 chown $TSTUSR.$TSTUSR $TESTFILE
358 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
360 log " Write out of block quota ..."
361 # this time maybe cache write, ignore it's failure
362 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
363 # flush cache, ensure noquota flag is setted on client
365 $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"
369 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
370 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
371 echo $OST0_QUOTA_USED
372 [ $OST0_QUOTA_USED -ne 0 ] && \
373 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
375 resetquota -u $TSTUSR
378 log "--------------------------------------"
379 log " Group quota (limit: $LIMIT kbytes)"
380 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
382 quota_show_check b g $TSTUSR
383 TESTFILE="$DIR/$tdir/$tfile-1"
385 $LFS setstripe $TESTFILE -c 1
386 chown $TSTUSR.$TSTUSR $TESTFILE
389 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
391 log " Write out of block quota ..."
392 # this time maybe cache write, ignore it's failure
393 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
395 $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"
400 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
401 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
402 echo $OST0_QUOTA_USED
403 [ $OST0_QUOTA_USED -ne 0 ] && \
404 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
406 resetquota -g $TSTUSR
409 # block hard limit (normal use and out of quota)
411 for i in `seq 1 $cycle`; do
412 # define blk_qunit is between 1M and 4M
413 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
414 blk_qtune=$(( $RANDOM % $blk_qunit ))
415 # other osts and mds will occupy at 1M blk quota
416 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
417 set_blk_tunesz $blk_qtune
418 set_blk_unitsz $blk_qunit
419 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
421 echo "=================================================="
422 set_blk_unitsz $((128 * 1024))
423 set_blk_tunesz $((128 * 1024 / 2))
426 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
428 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
432 chmod 0777 $DIR/$tdir
433 TESTFILE="$DIR/$tdir/$tfile-0"
435 wait_delete_completed
438 log " User quota (limit: $LIMIT files)"
439 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
441 quota_show_check f u $TSTUSR
443 log " Create $LIMIT files ..."
444 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
445 quota_error u $TSTUSR "(usr) create failure, but expect success"
447 log " Create out of file quota ..."
448 $RUNAS touch ${TESTFILE}_xxx && \
449 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
451 unlinkmany ${TESTFILE} $LIMIT
452 rm -f ${TESTFILE}_xxx
455 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
456 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
458 [ $MDS_QUOTA_USED -ne 0 ] && \
459 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
461 resetquota -u $TSTUSR
464 log "--------------------------------------"
465 log " Group quota (limit: $LIMIT FILE)"
466 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
468 quota_show_check f g $TSTUSR
469 TESTFILE=$DIR/$tdir/$tfile-1
471 log " Create $LIMIT files ..."
472 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
473 quota_error g $TSTUSR "(grp) create failure, but expect success"
475 log " Create out of file quota ..."
476 $RUNAS touch ${TESTFILE}_xxx && \
477 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
479 unlinkmany ${TESTFILE} $LIMIT
480 rm -f ${TESTFILE}_xxx
483 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
484 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
486 [ $MDS_QUOTA_USED -ne 0 ] && \
487 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
489 resetquota -g $TSTUSR
492 # file hard limit (normal use and out of quota)
494 for i in `seq 1 $cycle`; do
495 if [ $i -eq 1 ]; then
500 # define ino_qunit is between 10 and 100
501 ino_qunit=$(( $RANDOM % 90 + 10 ))
502 ino_qtune=$(( $RANDOM % $ino_qunit ))
503 # RANDOM's maxium is 32767
504 i_limit=$(( $RANDOM % 990 + 10 ))
507 set_file_tunesz $ino_qtune
508 set_file_unitsz $ino_qunit
509 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
511 echo "=================================================="
516 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
520 TIMER=$(($2 * 3 / 2))
523 wait_delete_completed
525 echo " Write to exceed soft limit"
526 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
527 $RUNDD count=$((BUNIT_SZ+1)) || \
528 quota_error a $TSTUSR "write failure, but expect success"
529 OFFSET=$((OFFSET + BUNIT_SZ + 1))
534 $SHOW_QUOTA_INFO_USER
535 $SHOW_QUOTA_INFO_GROUP
537 echo " Write before timer goes off"
538 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
539 quota_error a $TSTUSR "write failure, but expect success"
540 OFFSET=$((OFFSET + BUNIT_SZ))
544 echo " Sleep $TIMER seconds ..."
549 $SHOW_QUOTA_INFO_USER
550 $SHOW_QUOTA_INFO_GROUP
552 echo " Write after timer goes off"
553 # maybe cache write, ignore.
554 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
555 OFFSET=$((OFFSET + BUNIT_SZ))
557 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
558 quota_error a $TSTUSR "write success, but expect EDQUOT"
562 $SHOW_QUOTA_INFO_USER
563 $SHOW_QUOTA_INFO_GROUP
565 echo " Unlink file to stop timer"
572 $SHOW_QUOTA_INFO_USER
573 $SHOW_QUOTA_INFO_GROUP
576 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
584 # block soft limit (start timer, timer goes off, stop timer)
587 chmod 0777 $DIR/$tdir
589 # 1 bunit on mds and 1 bunit on every ost
590 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
593 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
594 TESTFILE=$DIR/$tdir/$tfile-0
596 $LFS setstripe $TESTFILE -c 1
597 chown $TSTUSR.$TSTUSR $TESTFILE
599 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
600 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
602 test_block_soft $TESTFILE $GRACE
603 resetquota -u $TSTUSR
605 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
606 TESTFILE=$DIR/$tdir/$tfile-1
608 $LFS setstripe $TESTFILE -c 1
609 chown $TSTUSR.$TSTUSR $TESTFILE
611 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
612 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
614 test_block_soft $TESTFILE $GRACE
615 resetquota -g $TSTUSR
617 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
622 TIMER=$(($3 * 3 / 2))
624 wait_delete_completed
626 echo " Create files to exceed soft limit"
627 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
628 quota_error a $TSTUSR "create failure, but expect success"
632 echo " Create file before timer goes off"
633 $RUNAS touch ${TESTFILE}_before || \
634 quota_error a $TSTUSR "failed create before timer expired, but expect success"
638 echo " Sleep $TIMER seconds ..."
643 $SHOW_QUOTA_INFO_USER
644 $SHOW_QUOTA_INFO_GROUP
646 echo " Create file after timer goes off"
647 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
648 # inode quota left here
649 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
651 $RUNAS touch ${TESTFILE}_after3 && \
652 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
657 $SHOW_QUOTA_INFO_USER
658 $SHOW_QUOTA_INFO_GROUP
660 echo " Unlink files to stop timer"
661 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
665 $RUNAS touch ${TESTFILE}_xxx || \
666 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
671 rm -f ${TESTFILE}_xxx
675 # file soft limit (start timer, timer goes off, stop timer)
676 test_4a() { # was test_4
678 chmod 0777 $DIR/$tdir
679 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
680 TESTFILE=$DIR/$tdir/$tfile-0
684 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
685 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
686 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
687 quota_show_check f u $TSTUSR
689 test_file_soft $TESTFILE $LIMIT $GRACE
690 resetquota -u $TSTUSR
692 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
693 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
694 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
695 quota_show_check f g $TSTUSR
696 TESTFILE=$DIR/$tdir/$tfile-1
698 test_file_soft $TESTFILE $LIMIT $GRACE
699 resetquota -g $TSTUSR
702 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
703 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
705 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
707 test_4b() { # was test_4a
713 GR_STR6="1111111111111111"
715 wait_delete_completed
717 # test of valid grace strings handling
718 echo " Valid grace strings test"
719 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
720 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
721 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
722 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
724 # test of invalid grace strings handling
725 echo " Invalid grace strings test"
726 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
727 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
730 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
731 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
733 run_test_with_stat 4b "Grace time strings handling ==="
735 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
738 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
739 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
741 wait_delete_completed
743 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
744 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
745 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
746 quota_show_check a u $TSTUSR
747 quota_show_check a g $TSTUSR
749 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
750 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
751 error "touch failure, expect success"
752 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
754 echo " Chown files to $TSTUSR.$TSTUSR ..."
755 for i in `seq 0 $ILIMIT`; do
756 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
757 quota_error a $TSTUSR "chown failure, but expect success"
761 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
764 resetquota -u $TSTUSR
765 resetquota -g $TSTUSR
767 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
769 # block quota acquire & release
771 if [ $OSTCOUNT -lt 2 ]; then
772 skip_env "$OSTCOUNT < 2, too few osts"
776 wait_delete_completed
779 chmod 0777 $DIR/$tdir
781 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
782 FILEA="$DIR/$tdir/$tfile-0_a"
783 FILEB="$DIR/$tdir/$tfile-0_b"
785 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
786 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
787 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
788 quota_show_check b u $TSTUSR
789 quota_show_check b g $TSTUSR
791 echo " Create filea on OST0 and fileb on OST1"
792 $LFS setstripe $FILEA -i 0 -c 1
793 $LFS setstripe $FILEB -i 1 -c 1
794 chown $TSTUSR.$TSTUSR $FILEA
795 chown $TSTUSR.$TSTUSR $FILEB
797 echo " Exceed quota limit ..."
798 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
799 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
800 quota_error a $TSTUSR "write filea failure, but expect success"
805 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
806 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
808 echo " Write to OST1 return EDQUOT"
809 # this write maybe cache write, ignore it's failure
810 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
811 $RUNDD count=$(($BUNIT_SZ * 2)) || true
815 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
816 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
818 echo " Remove filea to let OST0 release quota"
821 if at_is_enabled; then
822 timeout=$(at_max_get mds)
824 timeout=$(lctl get_param -n timeout)
826 count=$((timeout / 5))
827 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
829 while [ $((count--)) -gt 0 ]; do
832 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
833 if [ -z $OST0_QUOTA_HOLD ]; then
834 error "System is error when query quota for block (U:$TSTUSR)."
836 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
842 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
845 while [ $((count--)) -gt 0 ]; do
848 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
849 if [ -z $OST0_QUOTA_HOLD ]; then
850 error "System is error when query quota for block (G:$TSTUSR)."
852 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
858 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
861 echo " Write to OST1"
862 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
863 quota_error a $TSTUSR "write fileb failure, expect success"
870 resetquota -u $TSTUSR
871 resetquota -g $TSTUSR
874 run_test_with_stat 6 "Block quota acquire & release ========="
876 # quota recovery (block quota only by now)
880 chmod 0777 $DIR/$tdir
882 wait_delete_completed
884 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
885 TESTFILE="$DIR/$tdir/$tfile-0"
887 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
889 $LFS setstripe $TESTFILE -c 1
890 chown $TSTUSR.$TSTUSR $TESTFILE
892 echo " Write to OST0..."
893 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
894 quota_error u $TSTUSR "write failure, but expect success"
896 #define OBD_FAIL_OBD_DQACQ 0x604
897 lustre_fail mds 0x604
898 echo " Remove files on OST0"
902 echo " Trigger recovery..."
903 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
904 for i in $OSC0_UUID; do
905 $LCTL --device $i activate || error "activate osc failed!"
908 # sleep a while to wait for recovery done
912 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
913 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
914 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
915 echo " total limits = $TOTAL_LIMIT"
917 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
918 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
919 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
920 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
921 echo " limits on $OST0_UUID = $OST0_LIMIT"
924 resetquota -u $TSTUSR
926 run_test_with_stat 7 "Quota recovery (only block limit) ======"
928 # run dbench with quota enabled
931 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
934 wait_delete_completed
936 echo " Set enough high limit for user: $TSTUSR"
937 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
938 echo " Set enough high limit for group: $TSTUSR"
939 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
941 chmod 0777 $DIR/$tdir
943 [ "$SLOW" = "no" ] && duration=" -t 120"
944 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
951 run_test_with_stat 8 "Run dbench with quota enabled ==========="
953 # run for fixing bug10707, it needs a big room. test for 64bit
955 GB=$((KB * 1024 * 1024))
956 # Use this as dd bs to decrease time
957 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
958 blksize=$((1 << 21)) # 2Mb
959 size_file=$((GB * 9 / 2))
960 # this check is just for test_9
961 OST0_MIN=4900000 #4.67G
962 check_whether_skip () {
963 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
964 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
965 if [ $OST0_SIZE -lt $OST0_MIN ]; then
966 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
974 check_whether_skip && return 0
976 wait_delete_completed
982 chmod 0777 $DIR/$tdir
983 TESTFILE="$DIR/$tdir/$tfile-0"
985 BLK_LIMIT=$((100 * KB * KB)) # 100G
987 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
989 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
990 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
991 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
992 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
994 quota_show_check a u $TSTUSR
995 quota_show_check a g $TSTUSR
998 $LFS setstripe $TESTFILE -c 1 -i 0
1000 chown $TSTUSR.$TSTUSR $TESTFILE
1002 log " Write the big file of 4.5G ..."
1003 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1004 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1009 log " delete the big file of 4.5G..."
1010 $RUNAS rm -f $TESTFILE
1011 sync; sleep 3; sync;
1018 set_blk_unitsz $((128 * 1024))
1019 set_blk_tunesz $((128 * 1024 / 2))
1023 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1025 # 2.0 version does not support 32 bit qd_count,
1026 # test_10 "run for fixing bug10707(32bit) " is obsolete
1028 # test a deadlock between quota and journal b=11693
1031 chmod 0777 $DIR/$tdir
1033 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1034 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1036 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1037 TESTFILE="$DIR/$tdir/$tfile-0"
1038 TESTFILE2="$DIR2/$tdir/$tfile-1"
1040 wait_delete_completed
1042 echo " User quota (limit: $LIMIT kbytes)"
1043 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1045 $LFS setstripe $TESTFILE -i 0 -c 1
1046 chown $TSTUSR.$TSTUSR $TESTFILE
1047 $LFS setstripe $TESTFILE2 -i 0 -c 1
1048 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1050 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1051 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1052 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1054 echo " step1: write out of block quota ..."
1055 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1057 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1060 echo " step2: testing ......"
1061 local last_size=$(stat -c %s $TESTFILE2)
1063 local start_secs=$SECONDS
1064 while [ -d /proc/${DDPID1} ]; do
1065 local size=$(stat -c %s $TESTFILE2)
1066 if [ $size -eq $last_size ]; then
1067 stall_secs=$[stall_secs+1]
1071 if [ $stall_secs -gt 30 ]; then
1073 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1078 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1080 #Recover fail_loc and dd will finish soon
1083 echo " step3: testing ......"
1086 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1088 if [ $count -gt 150 ]; then
1089 quota_error u $TSTUSR "dd should be finished!"
1093 echo "(dd_pid=$DDPID, time=$count)successful"
1095 rm -f $TESTFILE $TESTFILE2
1096 sync; sleep 3; sync;
1098 resetquota -u $TSTUSR
1100 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1102 # test multiple clients write block quota b=11693
1105 wait_delete_completed
1107 # one OST * 10 + (mds + other OSTs)
1108 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1109 TESTFILE="$DIR/$tdir/$tfile"
1111 echo " User quota (limit: $LIMIT kbytes)"
1112 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1113 quota_show_check b u $TSTUSR
1115 $LFS setstripe $TESTFILE -i 0 -c 1
1116 chown $TSTUSR.$TSTUSR $TESTFILE
1117 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1118 chown $TSTUSR.$TSTUSR $TESTFILE.2
1120 echo " step1: write out of block quota ..."
1121 # one bunit will give mds
1122 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1124 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1127 echo " step2: testing ......"
1130 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1132 if [ $count -gt 64 ]; then
1133 quota_error u $TSTUSR "dd should be finished!"
1137 echo "(dd_pid=$DDPID, time=$count)successful"
1141 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1143 if [ $count -gt 64 ]; then
1144 quota_error u $TSTUSR "dd should be finished!"
1148 echo "(dd_pid=$DDPID1, time=$count)successful"
1150 sync; sleep 5; sync;
1152 echo " step3: checking ......"
1153 fz=`stat -c %s $TESTFILE`
1154 fz2=`stat -c %s $TESTFILE.2`
1156 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1157 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1159 rm -f $TESTFILE $TESTFILE.2
1160 sync; sleep 3; sync;
1162 resetquota -u $TSTUSR
1164 run_test_with_stat 13 "test multiple clients write block quota ==="
1166 check_if_quota_zero(){
1167 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1168 for i in `seq 3 $line`; do
1169 if [ $i -eq 3 ]; then
1175 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1176 awk '{print $'"$j"'}'`
1177 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1178 error "quota on $2 isn't clean"
1181 echo "pass check_if_quota_zero"
1184 test_14a() { # was test_14 b=12223 -- setting quota on root
1185 TESTFILE="$DIR/$tdir/$tfile"
1189 cleanup_and_setup_lustre
1194 # out of root's file and block quota
1195 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1196 createmany -m ${TESTFILE} 20 || \
1197 quota_error u root "unexpected: user(root) create files failly!"
1198 $MULTIOP ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1199 quota_error u root "unexpected: user(root) write files failly!"
1201 $RUNAS $MULTIOP ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1202 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1206 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1207 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1210 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1212 #check_if_quota_zero u root
1215 unlinkmany ${TESTFILE} 15
1217 sync; sleep 3; sync;
1219 run_test_with_stat 14a "test setting quota on root ==="
1222 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1223 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1225 wait_delete_completed
1228 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1229 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1230 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1231 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1232 resetquota -u $TSTUSR
1235 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1236 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1237 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1238 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1239 resetquota -g $TSTUSR
1240 $LFS quotaoff -ug $DIR
1241 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1242 error "fail to set version for $SINGLEMDS"
1243 for j in `seq $OSTCOUNT`; do
1244 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1245 error "fail to set version for ost$j"
1248 echo "invalidating quota files"
1249 $LFS quotainv -ug $DIR
1250 $LFS quotainv -ugf $DIR
1251 $LFS quotacheck -ug $DIR
1253 run_test_with_stat 15 "set block quota more than 4T ==="
1255 # 2.0 version does not support WITHOUT_CHANGE_QS,
1256 # test_16 "test without adjusting qunit" is obsolete
1258 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1263 wait_delete_completed
1265 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1266 lustre_fail ost 0x80000A02
1268 TESTFILE="$DIR/$tdir/$tfile-a"
1269 TESTFILE2="$DIR/$tdir/$tfile-b"
1272 BLK_LIMIT=$((100 * 1024)) # 100M
1274 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1275 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1276 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1277 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1279 quota_show_check b u $TSTUSR
1280 quota_show_check b g $TSTUSR
1283 chown $TSTUSR.$TSTUSR $TESTFILE
1285 chown $TSTUSR.$TSTUSR $TESTFILE2
1287 log " Write the test file1 ..."
1288 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1289 || quota_error a $TSTUSR "write 10M file failure"
1294 log " write the test file2 ..."
1295 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1296 || quota_error a $TSTUSR "write 10M file failure"
1301 rm -f $TESTFILE $TESTFILE2
1303 sync; sleep 3; sync;
1305 # make qd_count 64 bit
1308 set_blk_unitsz $((128 * 1024))
1309 set_blk_tunesz $((128 * 1024 / 2))
1311 resetquota -u $TSTUSR
1312 resetquota -g $TSTUSR
1316 run_test_with_stat 17 "run for fixing bug14526 ==========="
1318 # test when mds takes a long time to handle a quota req so that
1319 # the ost has dropped it, the ost still could work well b=14840
1321 LIMIT=$((100 * 1024 * 1024)) # 100G
1322 TESTFILE="$DIR/$tdir/$tfile"
1325 wait_delete_completed
1330 log " User quota (limit: $LIMIT kbytes)"
1331 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1332 quota_show_check b u $TSTUSR
1334 $LFS setstripe $TESTFILE -i 0 -c 1
1335 chown $TSTUSR.$TSTUSR $TESTFILE
1337 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1338 lustre_fail mds 0x13c
1340 log " step1: write 100M block ..."
1341 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1347 echo " step2: testing ......"
1349 if at_is_enabled; then
1350 timeout=$(at_max_get mds)
1352 timeout=$(lctl get_param -n timeout)
1355 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1357 if [ $count -gt $((4 * $timeout)) ]; then
1358 quota_error u $TSTUSR "count=$count dd should be finished!"
1362 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1364 cancel_lru_locks mdc
1365 cancel_lru_locks osc
1367 testfile_size=$(stat -c %s $TESTFILE)
1368 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1369 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1374 resetquota -u $TSTUSR
1375 set_blk_unitsz $((128 * 1024))
1376 set_blk_tunesz $((128 * 1024 / 2))
1378 run_test_with_stat 18 "run for fixing bug14840 ==========="
1380 # test when mds drops a quota req, the ost still could work well b=14840
1382 LIMIT=$((100 * 1024 * 1024)) # 100G
1383 TESTFILE="$DIR/$tdir/$tfile-a"
1386 wait_delete_completed
1391 log " User quota (limit: $LIMIT kbytes)"
1392 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1393 quota_show_check b u $TSTUSR
1395 $LFS setstripe $TESTFILE -i 0 -c 1
1396 chown $TSTUSR.$TSTUSR $TESTFILE
1398 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1399 lustre_fail mds 0x8000013d
1401 log " step1: write 100M block ..."
1402 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1405 echo " step2: testing ......"
1407 if at_is_enabled; then
1408 timeout=$(at_max_get mds)
1410 timeout=$(lctl get_param -n timeout)
1413 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1415 if [ $count -gt $((6 * $timeout)) ]; then
1417 quota_error u $TSTUSR "count=$count dd should be finished!"
1421 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1427 resetquota -u $TSTUSR
1428 set_blk_unitsz $((128 * 1024))
1429 set_blk_tunesz $((128 * 1024 / 2))
1431 run_test_with_stat 18a "run for fixing bug14840 ==========="
1433 # test when mds do failover, the ost still could work well without trigger
1438 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1439 TESTFILE="$DIR/$tdir/$tfile"
1442 wait_delete_completed
1447 log " User quota (limit: $LIMIT kbytes)"
1448 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1449 quota_show_check b u $TSTUSR
1451 $LFS setstripe $TESTFILE -i 0 -c 1
1452 chown $TSTUSR.$TSTUSR $TESTFILE
1454 timeout=$(sysctl -n lustre.timeout)
1456 if [ $type = "directio" ]; then
1457 log " write 100M block(directio) ..."
1458 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1460 log " write 100M block(normal) ..."
1461 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1465 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1467 replay_barrier $SINGLEMDS
1469 log "failing mds for $((2 * timeout)) seconds"
1470 fail $SINGLEMDS $((2 * timeout))
1472 # check if quotaon successful
1473 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1474 if [ $? -eq 0 ]; then
1476 error "quotaon failed!"
1481 if at_is_enabled; then
1482 timeout=$(at_max_get mds)
1484 timeout=$(lctl get_param -n timeout)
1487 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1488 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1489 log "it took $count second"
1493 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1495 cancel_lru_locks mdc
1496 cancel_lru_locks osc
1499 resetquota -u $TSTUSR
1500 set_blk_unitsz $((128 * 1024))
1501 set_blk_tunesz $((128 * 1024 / 2))
1502 testfile_size=$(stat -c %s $TESTFILE)
1503 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1505 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1511 # test when mds does failover, the ost still could work well
1512 # this test shouldn't trigger watchdog b=14840
1514 test_18bc_sub normal
1515 test_18bc_sub directio
1516 # check if watchdog is triggered
1517 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1518 watchdog=`awk '/test 18b/ {start = 1;}
1519 /Service thread pid/ && /was inactive/ {
1523 }' $TMP/lustre-log-${TESTNAME}.log`
1524 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1525 rm -f $TMP/lustre-log-${TESTNAME}.log
1527 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1529 # test when mds does failover, the ost still could work well
1530 # this test will prevent OST_DISCONNET from happening b=14840
1532 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1533 lustre_fail ost 0x202
1534 test_18bc_sub normal
1535 test_18bc_sub directio
1538 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1540 run_to_block_limit() {
1541 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1543 wait_delete_completed
1545 # set 1 Mb quota unit size
1549 # bind file to a single OST
1550 $LFS setstripe -c 1 $TESTFILE
1551 chown $TSTUSR.$TSTUSR $TESTFILE
1553 echo " User quota (limit: $LIMIT kbytes)"
1554 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1555 quota_show_check b u $TSTUSR
1556 echo " Updating quota limits"
1557 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1558 quota_show_check b u $TSTUSR
1560 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1561 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1562 # for now page cache of TESTFILE may still be dirty,
1563 # let's push it to the corresponding OST, this will also
1564 # cache NOQUOTA on the client from OST's reply
1565 cancel_lru_locks osc
1566 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1570 # 1 Mb bunit per each MDS/OSS
1571 local TESTFILE="$DIR/$tdir/$tfile"
1574 run_to_block_limit $TESTFILE
1579 resetquota -u $TSTUSR
1581 set_blk_unitsz $((128 * 1024))
1582 set_blk_tunesz $((128 * 1024 / 2))
1585 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1589 LSTR=(1t 2g 3m 4k) # limits strings
1590 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1592 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1593 $MOUNT || error "could not set quota limits"
1595 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1596 --inode-softlimit ${LSTR[2]} \
1597 --inode-hardlimit ${LSTR[3]} \
1598 $MOUNT || error "could not set quota limits"
1600 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1601 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1602 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1603 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1605 resetquota -u $TSTUSR
1607 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1614 time=$(($(date +%s) + seconds))
1615 while [ $(date +%s) -lt $time ]; do
1616 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1621 # run for fixing bug16053, setquota shouldn't fail when writing and
1622 # deleting are happening
1627 wait_delete_completed
1629 TESTFILE="$DIR/$tdir/$tfile"
1631 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1634 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1635 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1636 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1637 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1639 # repeat writing on a 1M file
1640 test_21_sub ${TESTFILE}_1 1024 30 &
1642 # repeat writing on a 128M file
1643 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1646 time=$(($(date +%s) + 30))
1648 while [ $(date +%s) -lt $time ]; do
1649 log " Set quota for $i times"
1650 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1651 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1658 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1660 if [ $count -gt 60 ]; then
1661 quota_error a $TSTUSR "dd should be finished!"
1665 echo "(dd_pid=$DDPID1, time=$count)successful"
1669 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1671 if [ $count -gt 60 ]; then
1672 quota_error a $TSTUSR "dd should be finished!"
1676 echo "(dd_pid=$DDPID2, time=$count)successful"
1678 set_blk_unitsz $((128 * 1024))
1679 set_blk_tunesz $((128 * 1024 / 2))
1680 resetquota -u $TSTUSR
1681 resetquota -g $TSTUSR
1685 run_test_with_stat 21 "run for fixing bug16053 ==========="
1688 quota_save_version "ug3"
1694 echo "checking parameters"
1696 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1697 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1701 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1705 chmod 0777 $DIR/$tdir
1706 TESTFILE="$DIR/$tdir/$tfile-0"
1708 local bs_unit=$((1024*1024))
1711 wait_delete_completed
1714 log " User quota (limit: $LIMIT kbytes)"
1715 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1717 quota_show_check b u $TSTUSR
1719 $LFS setstripe $TESTFILE -c 1 -i 0
1720 chown $TSTUSR.$TSTUSR $TESTFILE
1722 log " Step1: trigger quota with 0_DIRECT"
1723 log " Write half of file"
1724 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1725 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1726 log " Write out of block quota ..."
1727 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1728 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1731 log " Step2: rewrite should succeed"
1732 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1733 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1737 wait_delete_completed
1738 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1739 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1740 echo $OST0_QUOTA_USED
1741 [ $OST0_QUOTA_USED -ne 0 ] && \
1742 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1744 resetquota -u $TSTUSR
1748 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1750 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1751 check_whether_skip && return 0
1752 log "run for $((4 * $slave_cnt))MB test file"
1753 test_23_sub $((4 * $slave_cnt * 1024))
1755 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1756 check_whether_skip && return 0
1757 log "run for $((40 * $slave_cnt))MB test file"
1758 test_23_sub $((40 * $slave_cnt * 1024))
1760 run_test_with_stat 23 "run for fixing bug16125 ==========="
1763 local TESTFILE="$DIR/$tdir/$tfile"
1766 run_to_block_limit $TESTFILE
1767 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1771 resetquota -u $TSTUSR
1773 set_blk_unitsz $((128 * 1024))
1774 set_blk_tunesz $((128 * 1024 / 2))
1777 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1780 if [ $1 = "-u" ]; then
1781 if [ $2 = "$TSTUSR" ]; then
1787 if [ $2 = "$TSTUSR" ]; then
1797 chmod 0777 $DIR/$tdir
1798 TESTFILE="$DIR/$tdir/$tfile-0"
1800 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1802 wait_delete_completed
1804 # set quota for $TSTUSR
1805 log "setquota for $TSTUSR"
1806 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1808 if [ "$1" == "-u" ]; then
1809 quota_show_check a u $TSTUSR
1811 quota_show_check a g $TSTUSR
1814 # set quota for $TSTUSR2
1815 log "setquota for $TSTUSR2"
1816 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1818 if [ "$1" == "-u" ]; then
1819 quota_show_check a u $TSTUSR2
1821 quota_show_check a g $TSTUSR2
1824 # set stripe index to 0
1825 log "setstripe for $DIR/$tdir to 0"
1826 $LFS setstripe $DIR/$tdir -c 1 -i 0
1827 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1828 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1829 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1830 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1831 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1832 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1835 log "$TSTUSR write 4M to $TESTFILE"
1836 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1838 show_quota $1 $TSTUSR
1839 show_quota $1 $TSTUSR2
1840 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1841 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1842 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1843 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1844 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1845 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1846 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1848 # chown/chgrp from $TSTUSR to $TSTUSR2
1849 if [ $1 = "-u" ]; then
1850 log "chown from $TSTUSR to $TSTUSR2"
1851 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1853 log "chgrp from $TSTUSR to $TSTUSR2"
1854 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1857 show_quota $1 $TSTUSR
1858 show_quota $1 $TSTUSR2
1859 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1860 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1861 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1862 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1863 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1864 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1865 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1866 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1867 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1868 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1869 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1870 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1871 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1872 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1873 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1876 wait_delete_completed
1877 resetquota $1 $TSTUSR
1878 resetquota $1 $TSTUSR2
1882 log "run for chown case"
1885 log "run for chgrp case"
1888 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1892 chmod 0777 $DIR/$tdir
1893 TESTFILE="$DIR/$tdir/$tfile-0"
1894 TESTFILE2="$DIR/$tdir/$tfile-1"
1898 wait_delete_completed
1900 # every quota slave gets 20MB
1901 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1902 log "limit: ${b_limit}KB"
1903 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1905 quota_show_check b u $TSTUSR
1907 $LFS setstripe $TESTFILE -c 1 -i 0
1908 $LFS setstripe $TESTFILE2 -c 1 -i 0
1909 chown $TSTUSR.$TSTUSR $TESTFILE
1910 chown $TSTUSR.$TSTUSR $TESTFILE2
1912 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1913 lustre_fail ost 0xA03
1915 log " Write the first file..."
1916 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1917 log " Delete the first file..."
1921 wait_delete_completed
1923 log " Write the second file..."
1924 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1925 log " Delete the second file..."
1929 set_blk_unitsz $((128 * 1024))
1930 set_blk_tunesz $((128 * 1024 / 2))
1931 resetquota -u $TSTUSR
1933 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1936 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1937 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1940 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1943 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1944 error "lfs setquota failed with uid argument"
1945 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1946 error "lfs stequota failed with gid argument"
1947 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1948 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1949 resetquota -u $TSTUSR
1950 resetquota -g $TSTUSR
1953 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1956 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1957 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1958 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1961 echo "Step 2: reset system ..."
1962 cleanup_and_setup_lustre
1965 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1969 wait_delete_completed
1971 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1972 lustre_fail ost 0x80000A02
1974 TESTFILE="$DIR/$tdir/$tfile"
1977 BLK_LIMIT=$((100 * 1024)) # 100M
1978 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1979 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1983 chown $TSTUSR.$TSTUSR $TESTFILE
1985 echo "Step 5: write the test file1 [10M] ..."
1986 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1987 || quota_error a $TSTUSR "write 10M file failure"
1991 sync; sleep 3; sync;
1993 # make qd_count 64 bit
1996 set_blk_unitsz $((128 * 1024))
1997 set_blk_tunesz $((128 * 1024 / 2))
1999 resetquota -u $TSTUSR
2001 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2005 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2009 if at_is_enabled; then
2010 timeout=$(at_max_get client)
2011 at_max_set 10 client
2013 timeout=$(lctl get_param -n timeout)
2014 lctl set_param timeout=10
2016 # actually send a RPC to make service at_current confined within at_max
2017 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR || error "should succeed"
2019 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2020 lustre_fail mds 0x12e
2022 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2024 echo "sleeping for 10 * 1.25 + 5 + 10 seconds"
2026 ps -p $pid && error "lfs hadn't finished by timeout"
2027 wait $pid && error "succeeded, but should have failed"
2031 if at_is_enabled; then
2032 at_max_set $timeout client
2034 lctl set_param timeout=$timeout
2037 resetquota -u $TSTUSR
2039 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2045 local TESTFILE="$DIR/$tdir/$tfile"
2052 chmod 0777 $DIR/$tdir
2054 $LFS setstripe $TESTFILE -i 0 -c 1
2055 chown $TSTUSR.$TSTUSR $TESTFILE
2057 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2058 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2059 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2060 cancel_lru_locks osc
2062 $LFS setquota -u $TSTUSR -B 0 $DIR
2063 # over-quota flag has not yet settled since we do not trigger async events
2064 # based on grace time period expiration
2066 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2067 cancel_lru_locks osc
2068 # now over-quota flag should be settled and further writes should fail
2070 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2072 resetquota -u $TSTUSR
2073 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2075 set_blk_unitsz $((128 * 1024))
2076 set_blk_tunesz $((128 * 1024 / 2))
2078 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2080 # test duplicate quota releases b=18630
2083 chmod 0777 $DIR/$tdir
2085 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2086 TESTFILE="$DIR/$tdir/$tfile-0"
2087 TESTFILE2="$DIR/$tdir/$tfile-1"
2089 wait_delete_completed
2091 log " User quota (limit: $LIMIT kbytes)"
2092 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2094 $LFS setstripe $TESTFILE -i 0 -c 1
2095 chown $TSTUSR.$TSTUSR $TESTFILE
2096 $LFS setstripe $TESTFILE2 -i 0 -c 1
2097 chown $TSTUSR.$TSTUSR $TESTFILE2
2099 log " step1: write out of block quota ..."
2100 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2101 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2103 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2104 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2105 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2107 log " step2: delete two files so that triggering duplicate quota release ..."
2108 rm -f $TESTFILE $TESTFILE2
2109 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2110 wait_delete_completed
2112 log " step3: verify if the ost failed"
2113 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2114 watchdog=`awk '/test 31/ {start = 1;}
2115 /release quota error/ {
2119 }' $TMP/lustre-log-${TESTNAME}.log`
2120 [ "$watchdog" ] && error "$watchdog"
2121 rm -f $TMP/lustre-log-${TESTNAME}.log
2124 resetquota -u $TSTUSR
2126 run_test_with_stat 31 "test duplicate quota releases ==="
2128 # check hash_cur_bits
2129 check_quota_hash_cur_bits() {
2132 # check quota_hash_cur_bits on all obdfilters
2133 for num in `seq $OSTCOUNT`; do
2134 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2135 if [ $cb -gt $bits ]; then
2136 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2140 # check quota_hash_cur_bits on mds
2141 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2142 if [ $cb -gt $bits ]; then
2143 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2151 # check distribution of all obdfilters
2152 for num in `seq $OSTCOUNT`; do
2153 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2154 rehash_count=`echo $line | awk '{print $9}'`
2155 if [ $rehash_count -eq 0 ]; then
2156 echo -e "ost$num:\n $line"
2157 error "Rehearsh didn't happen"
2161 # check distribution of mds
2162 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2163 rehash_count=`echo $line | awk '{print $9}'`
2164 if [ $rehash_count -eq 0 ]; then
2165 echo -e "mdt:\n $line"
2166 error "Rehearsh didn't happen"
2173 # reset system so that quota_hash_cur_bits==3
2174 echo "Reset system ..."
2175 local LMR_orig=$LOAD_MODULES_REMOTE
2176 LOAD_MODULES_REMOTE=true
2177 cleanup_and_setup_lustre
2178 LOAD_MODULES_REMOTE=$LMR_orig
2184 for user in $SANITY_QUOTA_USERS; do
2185 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2186 missing_users="$missing_users $user"
2188 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2189 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2191 $LFS quotaoff -ug $DIR
2192 $LFS quotacheck -ug $DIR
2194 for user in $SANITY_QUOTA_USERS; do
2195 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2200 for user in $SANITY_QUOTA_USERS; do
2204 run_test 32 "check lqs hash(bug 21846) =========================================="
2206 cleanup_quota_test() {
2208 echo "Delete files..."
2212 # basic usage tracking for user & group
2215 chmod 0777 $DIR/$tdir
2218 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2220 trap cleanup_quota_test EXIT
2222 # make sure the system is clean
2223 USED=`getquota -u $TSTID global curspace`
2224 [ $USED -ne 0 ] && \
2225 error "Used space ($USED) for user $TSTID isn't 0."
2226 USED=`getquota -g $TSTID global curspace`
2227 [ $USED -ne 0 ] && \
2228 error "Used space ($USED) for group $TSTID isn't 0."
2230 echo "Write files..."
2231 for i in `seq 0 $INODES`; do
2232 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=$BLK_SZ \
2233 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2236 echo "Verify disk usage after write"
2237 USED=`getquota -u $TSTID global curspace`
2238 [ $USED -lt $TOTAL_BLKS ] && \
2239 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2240 USED=`getquota -u $TSTID global curinodes`
2241 [ $USED -lt $INODES ] && \
2242 error "Used inode for user $TSTID is $USED, expected $INODES"
2244 USED=`getquota -g $TSTID global curspace`
2245 [ $USED -lt $TOTAL_BLKS ] && \
2246 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2247 USED=`getquota -g $TSTID global curinodes`
2248 [ $USED -lt $INODES ] && \
2249 error "Used inode for group $TSTID is $USED, expected $INODES"
2253 echo "Verify disk usage after delete"
2254 wait_delete_completed
2255 USED=`getquota -u $TSTID global curspace`
2256 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2257 USED=`getquota -u $TSTID global curinodes`
2258 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2259 USED=`getquota -g $TSTID global curspace`
2260 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2261 USED=`getquota -g $TSTID global curinodes`
2262 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2264 run_test 33 "basic usage tracking for user & group =============================="
2266 # usage transfer test for user & group
2270 chmod 0777 $DIR/$tdir
2272 trap cleanup_quota_test EXIT
2274 # make sure the system is clean
2275 USED=`getquota -u $TSTID global curspace`
2276 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2277 USED=`getquota -g $TSTID global curspace`
2278 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2280 echo "Write file..."
2281 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ count=$BLK_CNT \
2282 oflag=sync 2>/dev/null || error "write failed"
2284 echo "chown the file to user $TSTID"
2285 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2287 echo "Verify disk usage for user $TSTID"
2288 USED=`getquota -u $TSTID global curspace`
2289 [ $USED -lt $BLK_CNT ] && \
2290 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2291 USED=`getquota -u $TSTID global curinodes`
2292 [ $USED -ne 1 ] && \
2293 error "Used inodes for user $TSTID is $USED, expected 1"
2295 echo "chgrp the file to group $TSTID"
2296 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2298 echo "Verify disk usage for group $TSTID"
2299 USED=`getquota -g $TSTID global curspace`
2300 [ $USED -ge $BLK_CNT ] || \
2301 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2302 USED=`getquota -g $TSTID global curinodes`
2303 [ $USED -eq 1 ] || \
2304 error "Used inodes for group $TSTID is $USED, expected 1"
2308 run_test 34 "usage transfer for user & group ===================================="
2310 # usage is still accessible across restart
2313 chmod 0777 $DIR/$tdir
2316 trap cleanup_quota_test EXIT
2318 echo "Write file..."
2319 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ \
2320 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2322 echo "Save disk usage before restart"
2323 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2324 [ $ORIG_USR_SPACE -eq 0 ] && \
2325 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2326 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2327 [ $ORIG_USR_INODES -eq 0 ] && \
2328 error "Used inodes for user $TSTID is 0, expected 1"
2329 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2330 [ $ORIG_GRP_SPACE -eq 0 ] && \
2331 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2332 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2333 [ $ORIG_GRP_INODES -eq 0 ] && \
2334 error "Used inodes for group $TSTID is 0, expected 1"
2337 local ORIG_REFORMAT=$REFORMAT
2339 cleanup_and_setup_lustre
2340 REFORMAT=$ORIG_REFORMAT
2343 echo "Verify disk usage after restart"
2344 USED=`getquota -u $TSTID global curspace`
2345 [ $USED -eq $ORIG_USR_SPACE ] || \
2346 error "Used space for user $TSTID changed from " \
2347 "$ORIG_USR_SPACE to $USED"
2348 USED=`getquota -u $TSTID global curinodes`
2349 [ $USED -eq $ORIG_USR_INODES ] || \
2350 error "Used inodes for user $TSTID changed from " \
2351 "$ORIG_USR_INODES to $USED"
2352 USED=`getquota -g $TSTID global curspace`
2353 [ $USED -eq $ORIG_GRP_SPACE ] || \
2354 error "Used space for group $TSTID changed from " \
2355 "$ORIG_GRP_SPACE to $USED"
2356 USED=`getquota -g $TSTID global curinodes`
2357 [ $USED -eq $ORIG_GRP_INODES ] || \
2358 error "Used inodes for group $TSTID changed from " \
2359 "$ORIG_GRP_INODES to $USED"
2363 run_test 35 "usage is still accessible across reboot ============================"
2370 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2375 complete $(basename $0) $SECONDS
2376 check_and_cleanup_lustre
2377 export QUOTA_AUTO=$QUOTA_AUTO_OLD