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 ALWAYS_EXCEPT="10 11 $SANITY_QUOTA_EXCEPT"
23 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
27 *) error "unsupported kernel" ;;
30 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
31 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
37 TSTID2=${TSTID2:-60001}
38 TSTUSR=${TSTUSR:-"quota_usr"}
39 TSTUSR2=${TSTUSR2:-"quota_2usr"}
41 BUNIT_SZ=${BUNIT_SZ:-1024} # min block quota unit(kB)
42 IUNIT_SZ=${IUNIT_SZ:-10} # min inode quota unit
45 SANITY_QUOTA_USERS="quota15_1 quota15_2 quota15_3 quota15_4 quota15_5 quota15_6 \
46 quota15_7 quota15_8 quota15_9 quota15_10 quota15_11 quota15_12 \
47 quota15_13 quota15_14 quota15_15 quota15_16 quota15_17 quota15_18 \
48 quota15_19 quota15_20 quota15_21 quota15_22 quota15_23 quota15_24 \
49 quota15_25 quota15_26 quota15_27 quota15_28 quota15_29 quota15_30"
52 LUSTRE=${LUSTRE:-`dirname $0`/..}
53 . $LUSTRE/tests/test-framework.sh
55 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
56 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
60 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
61 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
65 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
67 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
72 check_and_setup_lustre
74 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
75 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
80 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
81 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
82 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
83 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
84 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
86 # control the time of tests
88 [ "$SLOW" = "no" ] && cycle=10
95 # set_blk_tunables(btune_sz)
97 local btune=$(($1 * BLK_SZ))
98 # set btune size on all obdfilters
99 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
100 # set btune size on mds
101 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_btune_sz=$btune"
104 # set_blk_unitsz(bunit_sz)
106 local bunit=$(($1 * BLK_SZ))
107 # set bunit size on all obdfilters
108 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
109 # set bunit size on mds
110 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_bunit_sz=$bunit"
113 # set_file_tunesz(itune_sz)
116 # set itune size on all obdfilters
117 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_itune_sz=$itune"
118 # set itune size on mds
119 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_itune_sz=$itune"
122 # set_file_unitsz(iunit_sz)
125 # set iunit size on all obdfilters
126 do_facet ost1 "lctl set_param lquota.${FSNAME}-OST*.quota_iunit_sz=$iunit"
127 # set iunit size on mds
128 do_facet mds "lctl set_param lquota.*${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 mds "lctl set_param fail_val=$fail_val"
141 do_facet mds "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 mds "lctl set_param lquota.*${FSNAME}-MDT*.stats=0" > /dev/null || true
165 for j in `seq $OSTCOUNT`; do
166 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null || true
169 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
170 echo "statistics info begin ***************************************"
171 do_facet mds "lctl get_param lquota.*${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
196 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
198 if [ $RC -ne 0 ]; then
199 if [ $RC -eq 240 ]; then # 240 means -EBUSY
200 log "resetquota is blocked for quota master recovery, retry after 1 sec"
204 error "resetquota failed: $RC"
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;} }'
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 $LFS quotaoff -ug $DIR
300 $LFS quotacheck -ug $DIR
302 resetquota -u $TSTUSR
303 resetquota -g $TSTUSR
305 lctl set_param debug="+quota"
306 do_facet mds "lctl set_param debug=+quota"
307 for num in `seq $OSTCOUNT`; do
308 do_facet ost$num "lctl set_param debug=+quota"
311 run_test_with_stat 0 "Set quota ============================="
313 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
317 chmod 0777 $DIR/$tdir
318 TESTFILE="$DIR/$tdir/$tfile-0"
320 wait_delete_completed
323 log " User quota (limit: $LIMIT kbytes)"
324 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
326 quota_show_check b u $TSTUSR
328 $LFS setstripe $TESTFILE -c 1
329 chown $TSTUSR.$TSTUSR $TESTFILE
332 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
334 log " Write out of block quota ..."
335 # this time maybe cache write, ignore it's failure
336 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
337 # flush cache, ensure noquota flag is setted on client
339 $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"
343 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
344 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
345 echo $OST0_QUOTA_USED
346 [ $OST0_QUOTA_USED -ne 0 ] && \
347 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
349 resetquota -u $TSTUSR
352 log "--------------------------------------"
353 log " Group quota (limit: $LIMIT kbytes)"
354 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
356 quota_show_check b g $TSTUSR
357 TESTFILE="$DIR/$tdir/$tfile-1"
359 $LFS setstripe $TESTFILE -c 1
360 chown $TSTUSR.$TSTUSR $TESTFILE
363 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
365 log " Write out of block quota ..."
366 # this time maybe cache write, ignore it's failure
367 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
369 $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"
374 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
375 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
376 echo $OST0_QUOTA_USED
377 [ $OST0_QUOTA_USED -ne 0 ] && \
378 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
380 resetquota -g $TSTUSR
383 # block hard limit (normal use and out of quota)
385 for i in `seq 1 $cycle`; do
386 # define blk_qunit is between 1M and 4M
387 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
388 blk_qtune=$(( $RANDOM % $blk_qunit ))
389 # other osts and mds will occupy at 1M blk quota
390 b_limit=$(( ($RANDOM - 16384) / 8 + $OSTCOUNT * $blk_qunit * 4 ))
391 set_blk_tunesz $blk_qtune
392 set_blk_unitsz $blk_qunit
393 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
395 echo "=================================================="
396 set_blk_unitsz $((128 * 1024))
397 set_blk_tunesz $((128 * 1024 / 2))
400 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
402 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
406 chmod 0777 $DIR/$tdir
407 TESTFILE="$DIR/$tdir/$tfile-0"
409 wait_delete_completed
412 log " User quota (limit: $LIMIT files)"
413 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
415 quota_show_check f u $TSTUSR
417 log " Create $LIMIT files ..."
418 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
419 quota_error u $TSTUSR "(usr) create failure, but expect success"
421 log " Create out of file quota ..."
422 $RUNAS touch ${TESTFILE}_xxx && \
423 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
425 unlinkmany ${TESTFILE} $LIMIT
426 rm -f ${TESTFILE}_xxx
430 local dev=$(get_mds_mdt_device_proc_path)
431 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
432 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
435 [ $MDS_QUOTA_USED -ne 0 ] && \
436 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
438 resetquota -u $TSTUSR
441 log "--------------------------------------"
442 log " Group quota (limit: $LIMIT FILE)"
443 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
445 quota_show_check f g $TSTUSR
446 TESTFILE=$DIR/$tdir/$tfile-1
448 log " Create $LIMIT files ..."
449 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
450 quota_error g $TSTUSR "(grp) create failure, but expect success"
452 log " Create out of file quota ..."
453 $RUNAS touch ${TESTFILE}_xxx && \
454 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
456 unlinkmany ${TESTFILE} $LIMIT
457 rm -f ${TESTFILE}_xxx
460 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
461 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
464 [ $MDS_QUOTA_USED -ne 0 ] && \
465 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
467 resetquota -g $TSTUSR
470 # file hard limit (normal use and out of quota)
472 for i in `seq 1 $cycle`; do
473 if [ $i -eq 1 ]; then
478 # define ino_qunit is between 10 and 100
479 ino_qunit=$(( $RANDOM % 90 + 10 ))
480 ino_qtune=$(( $RANDOM % $ino_qunit ))
481 # RANDOM's maxium is 32767
482 i_limit=$(( $RANDOM % 990 + 10 ))
485 set_file_tunesz $ino_qtune
486 set_file_unitsz $ino_qunit
487 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
489 echo "=================================================="
494 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
498 TIMER=$(($2 * 3 / 2))
501 wait_delete_completed
503 echo " Write to exceed soft limit"
504 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
505 $RUNDD count=$((BUNIT_SZ+1)) || \
506 quota_error a $TSTUSR "write failure, but expect success"
507 OFFSET=$((OFFSET + BUNIT_SZ + 1))
512 $SHOW_QUOTA_INFO_USER
513 $SHOW_QUOTA_INFO_GROUP
515 echo " Write before timer goes off"
516 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
517 quota_error a $TSTUSR "write failure, but expect success"
518 OFFSET=$((OFFSET + BUNIT_SZ))
522 echo " Sleep $TIMER seconds ..."
527 $SHOW_QUOTA_INFO_USER
528 $SHOW_QUOTA_INFO_GROUP
530 echo " Write after timer goes off"
531 # maybe cache write, ignore.
532 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
533 OFFSET=$((OFFSET + BUNIT_SZ))
535 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
536 quota_error a $TSTUSR "write success, but expect EDQUOT"
540 $SHOW_QUOTA_INFO_USER
541 $SHOW_QUOTA_INFO_GROUP
543 echo " Unlink file to stop timer"
550 $SHOW_QUOTA_INFO_USER
551 $SHOW_QUOTA_INFO_GROUP
554 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
562 # block soft limit (start timer, timer goes off, stop timer)
565 chmod 0777 $DIR/$tdir
567 # 1 bunit on mds and 1 bunit on every ost
568 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
571 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
572 TESTFILE=$DIR/$tdir/$tfile-0
574 $LFS setstripe $TESTFILE -c 1
575 chown $TSTUSR.$TSTUSR $TESTFILE
577 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
578 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
580 test_block_soft $TESTFILE $GRACE
581 resetquota -u $TSTUSR
583 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
584 TESTFILE=$DIR/$tdir/$tfile-1
586 $LFS setstripe $TESTFILE -c 1
587 chown $TSTUSR.$TSTUSR $TESTFILE
589 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
590 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
592 test_block_soft $TESTFILE $GRACE
593 resetquota -g $TSTUSR
595 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
600 TIMER=$(($3 * 3 / 2))
602 wait_delete_completed
604 echo " Create files to exceed soft limit"
605 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
606 quota_error a $TSTUSR "create failure, but expect success"
610 echo " Create file before timer goes off"
611 $RUNAS touch ${TESTFILE}_before || \
612 quota_error a $TSTUSR "failed create before timer expired, but expect success"
616 echo " Sleep $TIMER seconds ..."
621 $SHOW_QUOTA_INFO_USER
622 $SHOW_QUOTA_INFO_GROUP
624 echo " Create file after timer goes off"
625 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
626 # inode quota left here
627 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
629 $RUNAS touch ${TESTFILE}_after3 && \
630 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
635 $SHOW_QUOTA_INFO_USER
636 $SHOW_QUOTA_INFO_GROUP
638 echo " Unlink files to stop timer"
639 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
643 $RUNAS touch ${TESTFILE}_xxx || \
644 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
649 rm -f ${TESTFILE}_xxx
653 # file soft limit (start timer, timer goes off, stop timer)
654 test_4a() { # was test_4
656 chmod 0777 $DIR/$tdir
657 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
658 TESTFILE=$DIR/$tdir/$tfile-0
662 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
663 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
664 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
665 quota_show_check f u $TSTUSR
667 test_file_soft $TESTFILE $LIMIT $GRACE
668 resetquota -u $TSTUSR
670 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
671 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
672 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
673 quota_show_check f g $TSTUSR
674 TESTFILE=$DIR/$tdir/$tfile-1
676 test_file_soft $TESTFILE $LIMIT $GRACE
677 resetquota -g $TSTUSR
680 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
681 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
683 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
685 test_4b() { # was test_4a
691 GR_STR6="1111111111111111"
693 wait_delete_completed
695 # test of valid grace strings handling
696 echo " Valid grace strings test"
697 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
698 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
699 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
700 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
702 # test of invalid grace strings handling
703 echo " Invalid grace strings test"
704 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
705 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
708 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
709 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
711 run_test_with_stat 4b "Grace time strings handling ==="
713 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
716 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
717 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
719 wait_delete_completed
721 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
722 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
723 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
724 quota_show_check a u $TSTUSR
725 quota_show_check a g $TSTUSR
727 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
728 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
729 error "touch failure, expect success"
730 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
732 echo " Chown files to $TSTUSR.$TSTUSR ..."
733 for i in `seq 0 $ILIMIT`; do
734 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
735 quota_error a $TSTUSR "chown failure, but expect success"
739 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
742 resetquota -u $TSTUSR
743 resetquota -g $TSTUSR
745 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
747 # block quota acquire & release
749 if [ $OSTCOUNT -lt 2 ]; then
750 skip_env "$OSTCOUNT < 2, too few osts"
754 wait_delete_completed
757 chmod 0777 $DIR/$tdir
759 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
760 FILEA="$DIR/$tdir/$tfile-0_a"
761 FILEB="$DIR/$tdir/$tfile-0_b"
763 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
764 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
765 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
766 quota_show_check b u $TSTUSR
767 quota_show_check b g $TSTUSR
769 echo " Create filea on OST0 and fileb on OST1"
770 $LFS setstripe $FILEA -i 0 -c 1
771 $LFS setstripe $FILEB -i 1 -c 1
772 chown $TSTUSR.$TSTUSR $FILEA
773 chown $TSTUSR.$TSTUSR $FILEB
775 echo " Exceed quota limit ..."
776 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
777 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
778 quota_error a $TSTUSR "write filea failure, but expect success"
783 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
784 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
786 echo " Write to OST1 return EDQUOT"
787 # this write maybe cache write, ignore it's failure
788 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
789 $RUNDD count=$(($BUNIT_SZ * 2)) || true
793 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
794 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
796 echo " Remove filea to let OST0 release quota"
799 if at_is_enabled; then
800 timeout=$(at_max_get mds)
802 timeout=$(lctl get_param -n timeout)
804 count=$((timeout / 5))
805 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
807 while [ $((count--)) -gt 0 ]; do
810 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
811 if [ -z $OST0_QUOTA_HOLD ]; then
812 error "System is error when query quota for block (U:$TSTUSR)."
814 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
820 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
823 while [ $((count--)) -gt 0 ]; do
826 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
827 if [ -z $OST0_QUOTA_HOLD ]; then
828 error "System is error when query quota for block (G:$TSTUSR)."
830 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
836 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
839 echo " Write to OST1"
840 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
841 quota_error a $TSTUSR "write fileb failure, expect success"
848 resetquota -u $TSTUSR
849 resetquota -g $TSTUSR
852 run_test_with_stat 6 "Block quota acquire & release ========="
854 # quota recovery (block quota only by now)
858 chmod 0777 $DIR/$tdir
860 wait_delete_completed
862 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
863 TESTFILE="$DIR/$tdir/$tfile-0"
865 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
867 $LFS setstripe $TESTFILE -c 1
868 chown $TSTUSR.$TSTUSR $TESTFILE
870 echo " Write to OST0..."
871 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
872 quota_error u $TSTUSR "write failure, but expect success"
874 #define OBD_FAIL_OBD_DQACQ 0x604
875 lustre_fail mds 0x604
876 echo " Remove files on OST0"
880 echo " Trigger recovery..."
881 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
882 for i in $OSC0_UUID; do
883 $LCTL --device $i activate || error "activate osc failed!"
886 # sleep a while to wait for recovery done
890 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
891 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
892 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
893 echo " total limits = $TOTAL_LIMIT"
895 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
896 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
897 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
898 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
899 echo " limits on $OST0_UUID = $OST0_LIMIT"
902 resetquota -u $TSTUSR
904 run_test_with_stat 7 "Quota recovery (only block limit) ======"
906 # run dbench with quota enabled
909 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
912 wait_delete_completed
914 echo " Set enough high limit for user: $TSTUSR"
915 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
916 echo " Set enough high limit for group: $TSTUSR"
917 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
919 chmod 0777 $DIR/$tdir
921 [ "$SLOW" = "no" ] && duration=" -t 120"
922 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
929 run_test_with_stat 8 "Run dbench with quota enabled ==========="
931 # run for fixing bug10707, it needs a big room. test for 64bit
933 GB=$((KB * 1024 * 1024))
934 # Use this as dd bs to decrease time
935 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
936 blksize=$((1 << 21)) # 2Mb
937 size_file=$((GB * 9 / 2))
938 # this check is just for test9 and test10
939 OST0_MIN=4900000 #4.67G
940 check_whether_skip () {
941 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
942 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
943 if [ $OST0_SIZE -lt $OST0_MIN ]; then
944 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
952 check_whether_skip && return 0
954 wait_delete_completed
960 chmod 0777 $DIR/$tdir
961 TESTFILE="$DIR/$tdir/$tfile-0"
963 BLK_LIMIT=$((100 * KB * KB)) # 100G
965 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
967 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
968 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
969 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
970 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
972 quota_show_check a u $TSTUSR
973 quota_show_check a g $TSTUSR
976 $LFS setstripe $TESTFILE -c 1
978 chown $TSTUSR.$TSTUSR $TESTFILE
980 log " Write the big file of 4.5G ..."
981 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
982 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
987 log " delete the big file of 4.5G..."
988 $RUNAS rm -f $TESTFILE
996 set_blk_unitsz $((128 * 1024))
997 set_blk_tunesz $((128 * 1024 / 2))
1001 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1003 # run for fixing bug10707, it need a big room. test for 32bit
1006 chmod 0777 $DIR/$tdir
1007 check_whether_skip && return 0
1009 wait_delete_completed
1014 # make qd_count 32 bit
1015 lustre_fail mds_ost 0xA00
1017 TESTFILE="$DIR/$tdir/$tfile-0"
1019 BLK_LIMIT=$((100 * KB * KB)) # 100G
1022 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1023 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1024 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1025 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1027 quota_show_check a u $TSTUSR
1028 quota_show_check a g $TSTUSR
1031 $LFS setstripe $TESTFILE -c 1
1033 chown $TSTUSR.$TSTUSR $TESTFILE
1035 log " Write the big file of 4.5 G ..."
1036 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1037 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1042 log " delete the big file of 4.5 G..."
1043 $RUNAS rm -f $TESTFILE
1044 sync; sleep 3; sync;
1051 # make qd_count 64 bit
1052 lustre_fail mds_ost 0
1054 set_blk_unitsz $((128 * 1024))
1055 set_blk_tunesz $((128 * 1024 / 2))
1059 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1062 wait_delete_completed
1065 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1067 orig_dbr=`sysctl -n vm.dirty_background_ratio`
1068 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1069 orig_dr=`sysctl -n vm.dirty_ratio`
1070 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1071 sysctl -w vm.dirty_background_ratio=1
1072 sysctl -w vm.dirty_expire_centisecs=30
1073 sysctl -w vm.dirty_ratio=1
1074 sysctl -w vm.dirty_writeback_centisecs=50
1075 TESTDIR="$DIR/$tdir"
1081 [ "$SLOW" = no ] && REPS=1
1084 while [ $i -le $REPS ]; do
1085 echo "test: cycle($i of $REPS) start at $(date)"
1086 mkdir -p $TESTDIR && chmod 777 $TESTDIR
1087 echo -n " create a file for uid "
1088 for j in `seq 1 30`; do
1090 # 30MB per dd for a total of 900MB (if space even permits)
1091 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
1094 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1096 while [ $PROCS -gt 0 ]; do
1098 SECS=$((SECS + sleep))
1099 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1100 USED=$(du -s $TESTDIR | awk '{print $1}')
1101 PCT=$(($USED * 100 / $block_limit))
1102 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
1103 if [ $USED -le $LAST_USED ]; then
1104 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1111 echo " removing the test files..."
1112 rm -f $TESTDIR/$tfile
1113 echo "cycle $i done at $(date)"
1116 echo "Test took $SECS sec"
1119 sysctl -w vm.dirty_background_ratio=$orig_dbr
1120 sysctl -w vm.dirty_expire_centisecs=$orig_dec
1121 sysctl -w vm.dirty_ratio=$orig_dr
1122 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1123 if [ $RV -ne 0 ]; then
1124 error "Nothing was written for $SECS sec ... aborting"
1128 run_test_with_stat 11 "run for fixing bug10912 ==========="
1130 # test multiple clients write block quota b=11693
1133 wait_delete_completed
1135 # one OST * 10 + (mds + other OSTs)
1136 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1137 TESTFILE="$DIR/$tdir/$tfile"
1139 echo " User quota (limit: $LIMIT kbytes)"
1140 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1141 quota_show_check b u $TSTUSR
1143 $LFS setstripe $TESTFILE -i 0 -c 1
1144 chown $TSTUSR.$TSTUSR $TESTFILE
1145 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1146 chown $TSTUSR.$TSTUSR $TESTFILE.2
1148 echo " step1: write out of block quota ..."
1149 # one bunit will give mds
1150 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1152 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1155 echo " step2: testing ......"
1158 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1160 if [ $count -gt 64 ]; then
1161 quota_error u $TSTUSR "dd should be finished!"
1165 echo "(dd_pid=$DDPID, time=$count)successful"
1169 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1171 if [ $count -gt 64 ]; then
1172 quota_error u $TSTUSR "dd should be finished!"
1176 echo "(dd_pid=$DDPID1, time=$count)successful"
1178 sync; sleep 5; sync;
1180 echo " step3: checking ......"
1181 fz=`stat -c %s $TESTFILE`
1182 fz2=`stat -c %s $TESTFILE.2`
1184 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1185 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1187 rm -f $TESTFILE $TESTFILE.2
1188 sync; sleep 3; sync;
1190 resetquota -u $TSTUSR
1192 run_test_with_stat 13 "test multiple clients write block quota ==="
1194 check_if_quota_zero(){
1195 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1196 for i in `seq 3 $line`; do
1197 if [ $i -eq 3 ]; then
1203 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1204 awk '{print $'"$j"'}'`
1205 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1206 error "quota on $2 isn't clean"
1209 echo "pass check_if_quota_zero"
1212 test_14a() { # was test_14 b=12223 -- setting quota on root
1213 TESTFILE="$DIR/$tdir/$tfile"
1217 cleanup_and_setup_lustre
1222 # out of root's file and block quota
1223 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1224 createmany -m ${TESTFILE} 20 || \
1225 quota_error u root "unexpected: user(root) create files failly!"
1226 dd if=/dev/zero of=$TESTFILE bs=4k count=4096 || \
1227 quota_error u root "unexpected: user(root) write files failly!"
1229 $RUNAS dd if=/dev/zero of=${TESTFILE} seek=4096 bs=4k count=4096 && \
1230 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1234 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1235 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1238 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1240 #check_if_quota_zero u root
1243 unlinkmany ${TESTFILE} 15
1245 sync; sleep 3; sync;
1247 run_test_with_stat 14a "test setting quota on root ==="
1250 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1251 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1253 wait_delete_completed
1255 # force using the latest version in case 14b was omitted
1256 $LFS quotaoff -ug $DIR
1257 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1258 $LFS quotacheck -ug $DIR || error "quotacheck failed"
1261 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1262 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1263 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1264 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1265 resetquota -u $TSTUSR
1268 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1269 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1270 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1271 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1273 resetquota -g $TSTUSR
1276 local lustre_version=$(get_lustre_version mds)
1277 if [[ $lustre_version != 1.8* ]]; then
1278 echo mds running $lustre_version, skip quota v1 testing
1282 quota_save_version "ug1"
1284 echo "Testing that >4GB quota limits fail on volume with quota v1"
1285 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1289 run_test_with_stat 15 "set block quota more than 4T ==="
1291 # $1=u/g $2=with qunit adjust or not
1293 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1294 TESTFILE="$DIR/$tdir/$tfile"
1297 wait_delete_completed
1299 echo " User quota (limit: $LIMIT kbytes)"
1300 if [ $1 == "u" ]; then
1301 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1302 quota_show_check b u $TSTUSR
1304 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1305 quota_show_check b g $TSTUSR
1308 $LFS setstripe $TESTFILE -c 1
1309 chown $TSTUSR.$TSTUSR $TESTFILE
1312 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1313 quota_error a $TSTUSR "(usr) write failure, but expect success"
1315 echo " Write out of block quota ..."
1316 # this time maybe cache write, ignore it's failure
1317 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1318 # flush cache, ensure noquota flag is setted on client
1319 cancel_lru_locks osc
1320 if [ $2 -eq 1 ]; then
1321 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1322 quota_error a $TSTUSR "(write failure, but expect success"
1324 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1325 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1329 sync; sleep 3; sync;
1330 resetquota -$1 $TSTUSR
1333 # test without adjusting qunit
1336 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1337 local lustre_version=$(get_lustre_version mds)
1338 if [[ $lustre_version != 1.8* ]]; then
1339 skip mds running $lustre_version, WITHOUT_CHANGE_QS is not supported
1343 set_blk_tunesz $((BUNIT_SZ * 2))
1344 set_blk_unitsz $((BUNIT_SZ * 4))
1347 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1348 echo " grp/usr: $i, adjust qunit: $j"
1349 echo "-------------------------------"
1350 [ $j -eq 1 ] && lustre_fail mds_ost 0
1351 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1355 set_blk_unitsz $((128 * 1024))
1356 set_blk_tunesz $((128 * 1024 / 2))
1358 run_test_with_stat 16 "test without adjusting qunit"
1360 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1365 wait_delete_completed
1367 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1368 lustre_fail ost 0x80000A02
1370 TESTFILE="$DIR/$tdir/$tfile-a"
1371 TESTFILE2="$DIR/$tdir/$tfile-b"
1374 BLK_LIMIT=$((100 * 1024)) # 100M
1376 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1377 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1378 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1379 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1381 quota_show_check b u $TSTUSR
1382 quota_show_check b g $TSTUSR
1385 chown $TSTUSR.$TSTUSR $TESTFILE
1387 chown $TSTUSR.$TSTUSR $TESTFILE2
1389 log " Write the test file1 ..."
1390 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1391 || quota_error a $TSTUSR "write 10M file failure"
1396 log " write the test file2 ..."
1397 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1398 || quota_error a $TSTUSR "write 10M file failure"
1403 rm -f $TESTFILE $TESTFILE2
1405 sync; sleep 3; sync;
1407 # make qd_count 64 bit
1410 set_blk_unitsz $((128 * 1024))
1411 set_blk_tunesz $((128 * 1024 / 2))
1413 resetquota -u $TSTUSR
1414 resetquota -g $TSTUSR
1418 run_test_with_stat 17 "run for fixing bug14526 ==========="
1420 # test when mds takes a long time to handle a quota req so that
1421 # the ost has dropped it, the ost still could work well b=14840
1423 LIMIT=$((100 * 1024 * 1024)) # 100G
1424 TESTFILE="$DIR/$tdir/$tfile"
1427 wait_delete_completed
1432 log " User quota (limit: $LIMIT kbytes)"
1433 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1434 quota_show_check b u $TSTUSR
1436 $LFS setstripe $TESTFILE -i 0 -c 1
1437 chown $TSTUSR.$TSTUSR $TESTFILE
1439 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1440 lustre_fail mds 0x13c
1442 log " step1: write 100M block ..."
1443 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1449 echo " step2: testing ......"
1451 if at_is_enabled; then
1452 timeout=$(at_max_get mds)
1454 timeout=$(lctl get_param -n timeout)
1457 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1459 if [ $count -gt $((4 * $timeout)) ]; then
1460 quota_error u $TSTUSR "count=$count dd should be finished!"
1464 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1466 cancel_lru_locks mdc
1467 cancel_lru_locks osc
1469 testfile_size=$(stat -c %s $TESTFILE)
1470 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1471 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1476 resetquota -u $TSTUSR
1477 set_blk_unitsz $((128 * 1024))
1478 set_blk_tunesz $((128 * 1024 / 2))
1480 run_test_with_stat 18 "run for fixing bug14840 ==========="
1482 # test when mds drops a quota req, the ost still could work well b=14840
1484 LIMIT=$((100 * 1024 * 1024)) # 100G
1485 TESTFILE="$DIR/$tdir/$tfile-a"
1488 wait_delete_completed
1493 log " User quota (limit: $LIMIT kbytes)"
1494 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1495 quota_show_check b u $TSTUSR
1497 $LFS setstripe $TESTFILE -i 0 -c 1
1498 chown $TSTUSR.$TSTUSR $TESTFILE
1500 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1501 lustre_fail mds 0x8000013d
1503 log " step1: write 100M block ..."
1504 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1507 echo " step2: testing ......"
1509 if at_is_enabled; then
1510 timeout=$(at_max_get mds)
1512 timeout=$(lctl get_param -n timeout)
1515 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1517 if [ $count -gt $((3 * $timeout)) ]; then
1519 quota_error u $TSTUSR "count=$count dd should be finished!"
1523 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1529 resetquota -u $TSTUSR
1530 set_blk_unitsz $((128 * 1024))
1531 set_blk_tunesz $((128 * 1024 / 2))
1533 run_test_with_stat 18a "run for fixing bug14840 ==========="
1535 # test when mds do failover, the ost still could work well without trigger
1540 LIMIT=$((110 * 1024 )) # 110M
1541 TESTFILE="$DIR/$tdir/$tfile"
1544 wait_delete_completed
1549 log " User quota (limit: $LIMIT kbytes)"
1550 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1551 quota_show_check b u $TSTUSR
1553 $LFS setstripe $TESTFILE -i 0 -c 1
1554 chown $TSTUSR.$TSTUSR $TESTFILE
1556 timeout=$(sysctl -n lustre.timeout)
1558 if [ $type = "directio" ]; then
1559 log " write 100M block(directio) ..."
1560 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1562 log " write 100M block(normal) ..."
1563 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1567 do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=ug"
1569 log "failing mds for $((2 * timeout)) seconds"
1570 fail mds $((2 * timeout))
1572 # check if quotaon successful
1573 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1574 if [ $? -eq 0 ]; then
1575 error "quotaon failed!"
1581 if at_is_enabled; then
1582 timeout=$(at_max_get mds)
1584 timeout=$(lctl get_param -n timeout)
1587 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1588 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1589 log "it took $count second"
1593 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1595 cancel_lru_locks mdc
1596 cancel_lru_locks osc
1598 testfile_size=$(stat -c %s $TESTFILE)
1599 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1600 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1605 resetquota -u $TSTUSR
1606 set_blk_unitsz $((128 * 1024))
1607 set_blk_tunesz $((128 * 1024 / 2))
1610 # test when mds does failover, the ost still could work well
1611 # this test shouldn't trigger watchdog b=14840
1613 test_18bc_sub normal
1614 test_18bc_sub directio
1615 # check if watchdog is triggered
1616 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1617 watchdog=`awk '/test 18b/ {start = 1;}
1618 /Service thread pid/ && /was inactive/{
1622 }' $TMP/lustre-log-${TESTNAME}.log`
1623 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1624 rm -f $TMP/lustre-log-${TESTNAME}.log
1626 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1628 # test when mds does failover, the ost still could work well
1629 # this test will prevent OST_DISCONNET from happening b=14840
1631 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1632 lustre_fail ost 0x202
1633 test_18bc_sub normal
1634 test_18bc_sub directio
1637 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1639 run_to_block_limit() {
1640 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1642 wait_delete_completed
1644 # set 1 Mb quota unit size
1648 # bind file to a single OST
1649 $LFS setstripe -c 1 $TESTFILE
1650 chown $TSTUSR.$TSTUSR $TESTFILE
1652 echo " User quota (limit: $LIMIT kbytes)"
1653 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1654 quota_show_check b u $TSTUSR
1655 echo " Updating quota limits"
1656 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1657 quota_show_check b u $TSTUSR
1659 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1660 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1661 # for now page cache of TESTFILE may still be dirty,
1662 # let's push it to the corresponding OST, this will also
1663 # cache NOQUOTA on the client from OST's reply
1664 cancel_lru_locks osc
1665 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1669 # 1 Mb bunit per each MDS/OSS
1670 local TESTFILE="$DIR/$tdir/$tfile"
1673 run_to_block_limit $TESTFILE
1678 resetquota -u $TSTUSR
1680 set_blk_unitsz $((128 * 1024))
1681 set_blk_tunesz $((128 * 1024 / 2))
1684 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1688 LSTR=(1t 2g 3m 4k) # limits strings
1689 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1691 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1692 $MOUNT || error "could not set quota limits"
1694 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1695 --inode-softlimit ${LSTR[2]} \
1696 --inode-hardlimit ${LSTR[3]} \
1697 $MOUNT || error "could not set quota limits"
1699 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1700 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1701 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1702 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1704 resetquota -u $TSTUSR
1706 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1713 time=$(($(date +%s) + seconds))
1714 while [ $(date +%s) -lt $time ]; do
1715 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1720 # run for fixing bug16053, setquota shouldn't fail when writing and
1721 # deleting are happening
1726 wait_delete_completed
1728 TESTFILE="$DIR/$tdir/$tfile"
1730 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1733 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1734 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1735 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1736 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1738 # repeat writing on a 1M file
1739 test_21_sub ${TESTFILE}_1 1024 30 &
1741 # repeat writing on a 128M file
1742 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1745 time=$(($(date +%s) + 30))
1747 while [ $(date +%s) -lt $time ]; do
1748 log " Set quota for $i times"
1749 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1750 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1757 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1759 if [ $count -gt 60 ]; then
1760 quota_error a $TSTUSR "dd should be finished!"
1764 echo "(dd_pid=$DDPID1, time=$count)successful"
1768 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1770 if [ $count -gt 60 ]; then
1771 quota_error a $TSTUSR "dd should be finished!"
1775 echo "(dd_pid=$DDPID2, time=$count)successful"
1777 set_blk_unitsz $((128 * 1024))
1778 set_blk_tunesz $((128 * 1024 / 2))
1779 resetquota -u $TSTUSR
1780 resetquota -g $TSTUSR
1784 run_test_with_stat 21 "run for fixing bug16053 ==========="
1787 local lustre_version=$(get_lustre_version mds)
1788 if [[ $lustre_version != 1.8* ]] ; then
1789 skip mds running $lustre_version, skip quota v1 testing
1792 quota_save_version "ug1"
1798 echo "checking parameters"
1800 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1801 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1803 run_test 0 "reboot lustre"
1805 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1809 chmod 0777 $DIR/$tdir
1810 TESTFILE="$DIR/$tdir/$tfile-0"
1812 local bs_unit=$((1024*1024))
1815 wait_delete_completed
1818 log " User quota (limit: $LIMIT kbytes)"
1819 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1821 quota_show_check b u $TSTUSR
1823 $LFS setstripe $TESTFILE -c 1
1824 chown $TSTUSR.$TSTUSR $TESTFILE
1826 log " Step1: trigger quota with 0_DIRECT"
1827 log " Write half of file"
1828 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1829 log " Write out of block quota ..."
1830 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1833 log " Step2: rewrite should succeed"
1834 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1838 wait_delete_completed
1839 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1840 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1841 echo $OST0_QUOTA_USED
1842 [ $OST0_QUOTA_USED -ne 0 ] && \
1843 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1845 resetquota -u $TSTUSR
1849 log "run for $((OSTCOUNT * 3))MB test file"
1850 test_23_sub $((OSTCOUNT * 3 * 1024))
1853 check_whether_skip && return 0
1854 log "run for $((OSTCOUNT * 30))MB test file"
1855 test_23_sub $((OSTCOUNT * 30 * 1024))
1857 run_test_with_stat 23 "run for fixing bug16125 ==========="
1860 local TESTFILE="$DIR/$tdir/$tfile"
1863 run_to_block_limit $TESTFILE
1864 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1868 resetquota -u $TSTUSR
1870 set_blk_unitsz $((128 * 1024))
1871 set_blk_tunesz $((128 * 1024 / 2))
1874 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1877 if [ $1 = "-u" ]; then
1878 if [ $2 = "$TSTUSR" ]; then
1884 if [ $2 = "$TSTUSR" ]; then
1894 chmod 0777 $DIR/$tdir
1895 TESTFILE="$DIR/$tdir/$tfile-0"
1897 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1899 wait_delete_completed
1901 # set quota for $TSTUSR
1902 log "setquota for $TSTUSR"
1903 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1905 if [ "$1" == "-u" ]; then
1906 quota_show_check a u $TSTUSR
1908 quota_show_check a g $TSTUSR
1911 # set quota for $TSTUSR2
1912 log "setquota for $TSTUSR2"
1913 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1915 if [ "$1" == "-u" ]; then
1916 quota_show_check a u $TSTUSR2
1918 quota_show_check a g $TSTUSR2
1921 # set stripe index to 0
1922 log "setstripe for $DIR/$tdir to 0"
1923 $LFS setstripe $DIR/$tdir -c 1 -i 0
1926 local dev=$(get_mds_mdt_device_proc_path)
1927 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
1928 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1930 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1931 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1932 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1933 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1936 log "$TSTUSR write 4M to $TESTFILE"
1937 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1939 show_quota $1 $TSTUSR
1940 show_quota $1 $TSTUSR2
1941 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1942 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1943 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1944 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1945 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1946 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1947 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1949 # chown/chgrp from $TSTUSR to $TSTUSR2
1950 if [ $1 = "-u" ]; then
1951 log "chown from $TSTUSR to $TSTUSR2"
1952 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1954 log "chgrp from $TSTUSR to $TSTUSR2"
1955 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1958 show_quota $1 $TSTUSR
1959 show_quota $1 $TSTUSR2
1960 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1961 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1962 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1963 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1964 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1965 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1966 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1967 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1968 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1969 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1970 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1971 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1972 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1973 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1974 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1977 wait_delete_completed
1978 resetquota $1 $TSTUSR
1979 resetquota $1 $TSTUSR2
1983 log "run for chown case"
1986 log "run for chgrp case"
1989 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1993 chmod 0777 $DIR/$tdir
1994 TESTFILE="$DIR/$tdir/$tfile-0"
1995 TESTFILE2="$DIR/$tdir/$tfile-1"
1999 wait_delete_completed
2001 # every quota slave gets 20MB
2002 b_limit=$((OSTCOUNT * 20 * 1024))
2003 log "limit: ${b_limit}KB"
2004 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2006 quota_show_check b u $TSTUSR
2008 $LFS setstripe $TESTFILE -c 1 -i 0
2009 $LFS setstripe $TESTFILE2 -c 1 -i 0
2010 chown $TSTUSR.$TSTUSR $TESTFILE
2011 chown $TSTUSR.$TSTUSR $TESTFILE2
2013 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2014 lustre_fail ost 0xA03
2016 log " Write the first file..."
2017 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2018 log " Delete the first file..."
2022 wait_delete_completed
2024 log " Write the second file..."
2025 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2026 log " Delete the second file..."
2030 set_blk_unitsz $((128 * 1024))
2031 set_blk_tunesz $((128 * 1024 / 2))
2032 resetquota -u $TSTUSR
2034 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2037 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2038 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2041 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2044 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2045 error "lfs setquota failed with uid argument"
2046 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2047 error "lfs stequota failed with gid argument"
2048 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2049 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2050 resetquota -u $TSTUSR
2051 resetquota -g $TSTUSR
2054 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2057 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2058 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2059 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2062 echo "Step 2: reset system ..."
2063 cleanup_and_setup_lustre
2066 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2070 wait_delete_completed
2072 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2073 lustre_fail ost 0x80000A02
2075 TESTFILE="$DIR/$tdir/$tfile"
2078 BLK_LIMIT=$((100 * 1024)) # 100M
2079 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2080 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2084 chown $TSTUSR.$TSTUSR $TESTFILE
2086 echo "Step 5: write the test file1 [10M] ..."
2087 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2088 || quota_error a $TSTUSR "write 10M file failure"
2092 sync; sleep 3; sync;
2094 # make qd_count 64 bit
2097 set_blk_unitsz $((128 * 1024))
2098 set_blk_tunesz $((128 * 1024 / 2))
2100 resetquota -u $TSTUSR
2102 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2107 # flush AT history, enforce at_max immediately
2108 do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2116 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2117 local newtimeo=10 # the default ptlrpc AT value
2121 if at_is_enabled; then
2122 oldtimeo=$(at_max_get client)
2123 at_max_enforce $newtimeo
2125 oldtimeo=$(lctl get_param -n timeout)
2126 lctl set_param timeout=$newtimeo
2129 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2130 lustre_fail mds 0x12e
2132 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2134 # 1.25 * at_max + 5 + net_latency
2135 echo "sleeping for $((newtimeo * 9 / 4 + 5)) seconds"
2136 sleep $((newtimeo * 9 / 4 + 5))
2137 ps -p $pid && error "lfs hadn't finished by timeout"
2138 wait $pid && error "succeeded, but should have failed"
2142 if at_is_enabled; then
2143 at_max_enforce $oldtimeo
2145 lctl set_param timeout=$oldtimeo
2148 resetquota -u $TSTUSR
2150 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2156 local TESTFILE="$DIR/$tdir/$tfile"
2163 chmod 0777 $DIR/$tdir
2165 $LFS setstripe $TESTFILE -i 0 -c 1
2166 chown $TSTUSR.$TSTUSR $TESTFILE
2168 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2169 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2170 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2171 cancel_lru_locks osc
2173 $LFS setquota -u $TSTUSR -B 0 $DIR
2174 # over-quota flag has not yet settled since we do not trigger async events
2175 # based on grace time period expiration
2177 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2178 cancel_lru_locks osc
2179 # now over-quota flag should be settled and further writes should fail
2181 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2183 resetquota -u $TSTUSR
2184 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2186 set_blk_unitsz $((128 * 1024))
2187 set_blk_tunesz $((128 * 1024 / 2))
2189 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2191 # test duplicate quota releases b=18630
2194 chmod 0777 $DIR/$tdir
2196 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2197 TESTFILE="$DIR/$tdir/$tfile-0"
2198 TESTFILE2="$DIR/$tdir/$tfile-1"
2200 wait_delete_completed
2202 log " User quota (limit: $LIMIT kbytes)"
2203 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2205 $LFS setstripe $TESTFILE -i 0 -c 1
2206 chown $TSTUSR.$TSTUSR $TESTFILE
2207 $LFS setstripe $TESTFILE2 -i 0 -c 1
2208 chown $TSTUSR.$TSTUSR $TESTFILE2
2210 log " step1: write out of block quota ..."
2211 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2212 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2214 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2215 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2216 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2218 log " step2: delete two files so that triggering duplicate quota release ..."
2219 rm -f $TESTFILE $TESTFILE2
2220 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2221 wait_delete_completed
2223 log " step3: verify if the ost failed"
2224 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2225 watchdog=`awk '/test 31/ {start = 1;}
2226 /release quota error/ {
2230 }' $TMP/lustre-log-${TESTNAME}.log`
2231 [ "$watchdog" ] && error "$watchdog"
2232 rm -f $TMP/lustre-log-${TESTNAME}.log
2235 resetquota -u $TSTUSR
2237 run_test_with_stat 31 "test duplicate quota releases ==="
2239 # check hash_cur_bits
2240 check_quota_hash_cur_bits() {
2243 # check quota_hash_cur_bits on all obdfilters
2244 for num in `seq $OSTCOUNT`; do
2245 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2246 if [ $cb -gt $bits ]; then
2247 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2251 # check quota_hash_cur_bits on mds
2252 cb=`do_facet mds "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2253 if [ $cb -gt $bits ]; then
2254 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2262 # check distribution of all obdfilters
2263 for num in `seq $OSTCOUNT`; do
2264 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2265 rehash_count=`echo $line | awk '{print $9}'`
2266 if [ $rehash_count -eq 0 ]; then
2267 echo -e "ost$num:\n $line"
2268 error "Rehearsh didn't happen"
2272 # check distribution of mds
2273 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2274 rehash_count=`echo $line | awk '{print $9}'`
2275 if [ $rehash_count -eq 0 ]; then
2276 echo -e "mdt:\n $line"
2277 error "Rehearsh didn't happen"
2284 # reset system so that quota_hash_cur_bits==3
2285 echo "Reset system ..."
2286 local LMR_orig=$LOAD_MODULES_REMOTE
2287 LOAD_MODULES_REMOTE=true
2288 cleanup_and_setup_lustre
2289 LOAD_MODULES_REMOTE=$LMR_orig
2291 for user in $SANITY_QUOTA_USERS; do
2292 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2293 missing_users="$missing_users $user"
2295 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2296 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2298 $LFS quotaoff -ug $DIR
2299 $LFS quotacheck -ug $DIR
2301 for user in $SANITY_QUOTA_USERS; do
2302 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2307 for user in $SANITY_QUOTA_USERS; do
2311 run_test 32 "check lqs hash(bug 21846) =========================================="
2314 # run 98 at the end because of reformatall
2321 local missing_users=""
2323 for user in $SANITY_QUOTA_USERS; do
2324 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" || \
2325 missing_users="$missing_users $user"
2327 [ -n "$missing_users" ] && { skip_env "different uid-s on client and servers, or missing users: $missing_users" ; return 0 ; }
2332 quota_set_version 1 # set version before the first quota check
2339 for user in $SANITY_QUOTA_USERS; do
2340 $LFS setquota -u $user --block-hardlimit $((2 * num + 4 * OSTCOUNT)) $DIR || error "first phase setquota failure"
2341 $LFS setstripe -c 1 $DIR/${tfile}${num} || error "single-stripe file creation failed"
2342 chown $user $DIR/${tfile}${num} || error "chown has failed"
2343 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:w$((num * 1024))c || \
2344 error "unexpected error when writing the file for $user"
2348 $LFS quotaoff -ug $DIR
2349 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2350 $LFS quotaon -ug $DIR
2353 for user in $SANITY_QUOTA_USERS; do
2354 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w$((num * 1024))c || \
2355 error "unexpected error when appending the file for $user"
2356 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w8192c && \
2357 error "unexpected success when appending the file for $user"
2358 $LFS setquota -u $user --block-hardlimit 0 $DIR || error "second phase setquota failure"
2359 rm -rf $DIR/${tfile}${num}
2363 set_blk_unitsz $((128 * 1024))
2364 set_blk_tunesz $((128 * 1024 / 2))
2366 run_test_with_stat 98 "quotaon autoconversion ==============================="
2372 lctl set_param debug="-quota"
2376 run_test_with_stat 99 "Quota off ==============================="
2379 log "cleanup: ======================================================"
2381 check_and_cleanup_lustre
2382 echo '=========================== finished ==============================='
2383 [ -f "$QUOTALOG" ] && cat $QUOTALOG && grep -q FAIL $QUOTALOG && exit 1 || true
2384 echo "$0: completed"