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"
54 LUSTRE=${LUSTRE:-`dirname $0`/..}
55 . $LUSTRE/tests/test-framework.sh
57 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
59 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
61 [ $MDSCOUNT -gt 1 ] && skip "CMD case" && exit 0
63 require_dsh_mds || exit 0
64 require_dsh_ost || exit 0
66 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
68 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
70 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
75 QUOTA_AUTO_OLD=$QUOTA_AUTO
78 check_and_setup_lustre
80 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
81 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
83 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
84 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
85 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
86 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
87 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
88 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
89 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
90 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
92 # control the time of tests
94 [ "$SLOW" = "no" ] && cycle=10
98 # set_blk_tunables(btune_sz)
100 local btune=$(($1 * BLK_SZ))
101 # set btune size on all obdfilters
102 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
103 # set btune size on mds
104 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_btune_sz=$btune"
107 # set_blk_unitsz(bunit_sz)
109 local bunit=$(($1 * BLK_SZ))
110 # set bunit size on all obdfilters
111 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
112 # set bunit size on mds
113 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_bunit_sz=$bunit"
116 # set_file_tunesz(itune_sz)
119 # set itune size on mds
120 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_itune_sz=$itune"
123 # set_file_unitsz(iunit_sz)
126 # set iunit size on mds
127 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_iunit_sz=$iunit"
133 local fail_val=${3:-0}
135 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
136 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
137 [ $((fail_loc)) -eq 0 ]; then
138 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
140 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
142 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
143 for num in `seq $OSTCOUNT`; do
144 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
145 [ $((fail_loc)) -eq 0 ]; then
146 do_facet ost$num "lctl set_param fail_val=$fail_val"
148 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
153 RUNAS="runas -u $TSTID -g $TSTID"
154 RUNAS2="runas -u $TSTID2 -g $TSTID2"
155 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
156 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
160 run_test_with_stat() {
161 (($# != 2)) && error "the number of arguments is wrong"
163 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.stats=0" > /dev/null
164 for j in `seq $OSTCOUNT`; do
165 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null
168 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
169 echo "statistics info begin ***************************************"
170 do_facet $SINGLEMDS "lctl get_param lquota.mdd_obd-${FSNAME}-MDT*.stats"
171 for j in `seq $OSTCOUNT`; do
172 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
174 echo "statistics info end ***************************************"
179 # clear quota limits for a user or a group
180 # usage: resetquota -u username
181 # resetquota -g groupname
184 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
185 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
188 if at_is_enabled; then
189 timeout=$(at_max_get mds)
191 timeout=$(lctl get_param -n timeout)
194 while [ $((count++)) -lt $timeout ]; do
196 OUTPUT=`$LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT 2>&1` || RC=${PIPESTATUS[0]}
197 if [ $RC -ne 0 ]; then
198 if echo "$OUTPUT" | grep -q busy; then
199 log "resetquota is blocked for quota master recovery, retry after $((count * 3)) sec"
203 error "resetquota failed"
209 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
216 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
217 log "Files for user ($LOCAL_ID):"
218 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
221 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
222 log "Files for group ($LOCAL_ID):"
223 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
240 # get quota info for a user or a group
241 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
247 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
248 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
261 *) error "unknown quota parameter $4";;
264 [ "$uuid" = "global" ] && uuid=$DIR
266 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }' | tr -d "*"
273 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
275 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
277 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
278 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
279 if [ -z $USAGE ]; then
280 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
282 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
286 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
287 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
288 if [ -z $USAGE ]; then
289 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
291 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
298 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
300 log "do the quotacheck ..."
301 $LFS quotacheck -ug $DIR
303 resetquota -u $TSTUSR
304 resetquota -g $TSTUSR
308 test_quota_performance() {
309 TESTFILE="$DIR/$tdir/$tfile-0"
311 local stime=`date +%s`
312 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1M count=$size || quota_error u $TSTUSR "write failure"
313 local etime=`date +%s`
314 delta=$((etime - stime))
315 if [ $delta -gt 0 ]; then
316 rate=$((size * 1024 / delta))
317 [ $rate -gt 1024 ] || error "SLOW IO for $TSTUSR (user): $rate KB/sec"
322 # test basic quota performance b=21696
325 chmod 0777 $DIR/$tdir
327 [ "$SLOW" = "no" ] && MB=10
329 test_quota_performance $MB
331 $LFS setquota -u $TSTUSR -b 0 -B $((1024*1024)) -i 0 -I 0 $DIR
332 test_quota_performance $MB
334 resetquota -u $TSTUSR
336 run_test_with_stat 0 "Test basic quota performance ==="
338 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
342 chmod 0777 $DIR/$tdir
343 TESTFILE="$DIR/$tdir/$tfile-0"
345 wait_delete_completed
348 log " User quota (limit: $LIMIT kbytes)"
349 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
351 quota_show_check b u $TSTUSR
353 $LFS setstripe $TESTFILE -c 1
354 chown $TSTUSR.$TSTUSR $TESTFILE
357 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
359 log " Write out of block quota ..."
360 # this time maybe cache write, ignore it's failure
361 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
362 # flush cache, ensure noquota flag is setted on client
364 $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"
368 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
369 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
370 echo $OST0_QUOTA_USED
371 [ $OST0_QUOTA_USED -ne 0 ] && \
372 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
374 resetquota -u $TSTUSR
377 log "--------------------------------------"
378 log " Group quota (limit: $LIMIT kbytes)"
379 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
381 quota_show_check b g $TSTUSR
382 TESTFILE="$DIR/$tdir/$tfile-1"
384 $LFS setstripe $TESTFILE -c 1
385 chown $TSTUSR.$TSTUSR $TESTFILE
388 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
390 log " Write out of block quota ..."
391 # this time maybe cache write, ignore it's failure
392 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
394 $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"
399 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
400 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
401 echo $OST0_QUOTA_USED
402 [ $OST0_QUOTA_USED -ne 0 ] && \
403 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
405 resetquota -g $TSTUSR
408 # block hard limit (normal use and out of quota)
410 for i in `seq 1 $cycle`; do
411 # define blk_qunit is between 1M and 4M
412 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
413 blk_qtune=$(( $RANDOM % $blk_qunit ))
414 # other osts and mds will occupy at 1M blk quota
415 b_limit=$(( ($RANDOM - 16384) / 8 + ($OSTCOUNT + 1) * $blk_qunit * 4 ))
416 set_blk_tunesz $blk_qtune
417 set_blk_unitsz $blk_qunit
418 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
420 echo "=================================================="
421 set_blk_unitsz $((128 * 1024))
422 set_blk_tunesz $((128 * 1024 / 2))
425 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
427 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
431 chmod 0777 $DIR/$tdir
432 TESTFILE="$DIR/$tdir/$tfile-0"
434 wait_delete_completed
437 log " User quota (limit: $LIMIT files)"
438 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
440 quota_show_check f u $TSTUSR
442 log " Create $LIMIT files ..."
443 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
444 quota_error u $TSTUSR "(usr) create failure, but expect success"
446 log " Create out of file quota ..."
447 $RUNAS touch ${TESTFILE}_xxx && \
448 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
450 unlinkmany ${TESTFILE} $LIMIT
451 rm -f ${TESTFILE}_xxx
454 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
455 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
457 [ $MDS_QUOTA_USED -ne 0 ] && \
458 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
460 resetquota -u $TSTUSR
463 log "--------------------------------------"
464 log " Group quota (limit: $LIMIT FILE)"
465 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
467 quota_show_check f g $TSTUSR
468 TESTFILE=$DIR/$tdir/$tfile-1
470 log " Create $LIMIT files ..."
471 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
472 quota_error g $TSTUSR "(grp) create failure, but expect success"
474 log " Create out of file quota ..."
475 $RUNAS touch ${TESTFILE}_xxx && \
476 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
478 unlinkmany ${TESTFILE} $LIMIT
479 rm -f ${TESTFILE}_xxx
482 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
483 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
485 [ $MDS_QUOTA_USED -ne 0 ] && \
486 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
488 resetquota -g $TSTUSR
491 # file hard limit (normal use and out of quota)
493 for i in `seq 1 $cycle`; do
494 if [ $i -eq 1 ]; then
499 # define ino_qunit is between 10 and 100
500 ino_qunit=$(( $RANDOM % 90 + 10 ))
501 ino_qtune=$(( $RANDOM % $ino_qunit ))
502 # RANDOM's maxium is 32767
503 i_limit=$(( $RANDOM % 990 + 10 ))
506 set_file_tunesz $ino_qtune
507 set_file_unitsz $ino_qunit
508 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
510 echo "=================================================="
515 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
519 TIMER=$(($2 * 3 / 2))
522 wait_delete_completed
524 echo " Write to exceed soft limit"
525 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
526 $RUNDD count=$((BUNIT_SZ+1)) || \
527 quota_error a $TSTUSR "write failure, but expect success"
528 OFFSET=$((OFFSET + BUNIT_SZ + 1))
533 $SHOW_QUOTA_INFO_USER
534 $SHOW_QUOTA_INFO_GROUP
536 echo " Write before timer goes off"
537 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
538 quota_error a $TSTUSR "write failure, but expect success"
539 OFFSET=$((OFFSET + BUNIT_SZ))
543 echo " Sleep $TIMER seconds ..."
548 $SHOW_QUOTA_INFO_USER
549 $SHOW_QUOTA_INFO_GROUP
551 echo " Write after timer goes off"
552 # maybe cache write, ignore.
553 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
554 OFFSET=$((OFFSET + BUNIT_SZ))
556 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
557 quota_error a $TSTUSR "write success, but expect EDQUOT"
561 $SHOW_QUOTA_INFO_USER
562 $SHOW_QUOTA_INFO_GROUP
564 echo " Unlink file to stop timer"
571 $SHOW_QUOTA_INFO_USER
572 $SHOW_QUOTA_INFO_GROUP
575 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
583 # block soft limit (start timer, timer goes off, stop timer)
586 chmod 0777 $DIR/$tdir
588 # 1 bunit on mds and 1 bunit on every ost
589 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
592 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
593 TESTFILE=$DIR/$tdir/$tfile-0
595 $LFS setstripe $TESTFILE -c 1
596 chown $TSTUSR.$TSTUSR $TESTFILE
598 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
599 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
601 test_block_soft $TESTFILE $GRACE
602 resetquota -u $TSTUSR
604 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
605 TESTFILE=$DIR/$tdir/$tfile-1
607 $LFS setstripe $TESTFILE -c 1
608 chown $TSTUSR.$TSTUSR $TESTFILE
610 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
611 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
613 test_block_soft $TESTFILE $GRACE
614 resetquota -g $TSTUSR
616 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
621 TIMER=$(($3 * 3 / 2))
623 wait_delete_completed
625 echo " Create files to exceed soft limit"
626 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
627 quota_error a $TSTUSR "create failure, but expect success"
631 echo " Create file before timer goes off"
632 $RUNAS touch ${TESTFILE}_before || \
633 quota_error a $TSTUSR "failed create before timer expired, but expect success"
637 echo " Sleep $TIMER seconds ..."
642 $SHOW_QUOTA_INFO_USER
643 $SHOW_QUOTA_INFO_GROUP
645 echo " Create file after timer goes off"
646 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
647 # inode quota left here
648 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
650 $RUNAS touch ${TESTFILE}_after3 && \
651 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
656 $SHOW_QUOTA_INFO_USER
657 $SHOW_QUOTA_INFO_GROUP
659 echo " Unlink files to stop timer"
660 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
664 $RUNAS touch ${TESTFILE}_xxx || \
665 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
670 rm -f ${TESTFILE}_xxx
674 # file soft limit (start timer, timer goes off, stop timer)
675 test_4a() { # was test_4
677 chmod 0777 $DIR/$tdir
678 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
679 TESTFILE=$DIR/$tdir/$tfile-0
683 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
684 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
685 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
686 quota_show_check f u $TSTUSR
688 test_file_soft $TESTFILE $LIMIT $GRACE
689 resetquota -u $TSTUSR
691 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
692 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
693 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
694 quota_show_check f g $TSTUSR
695 TESTFILE=$DIR/$tdir/$tfile-1
697 test_file_soft $TESTFILE $LIMIT $GRACE
698 resetquota -g $TSTUSR
701 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
702 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
704 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
706 test_4b() { # was test_4a
712 GR_STR6="1111111111111111"
714 wait_delete_completed
716 # test of valid grace strings handling
717 echo " Valid grace strings test"
718 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
719 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
720 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
721 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
723 # test of invalid grace strings handling
724 echo " Invalid grace strings test"
725 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
726 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
729 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
730 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
732 run_test_with_stat 4b "Grace time strings handling ==="
734 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
737 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
738 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
740 wait_delete_completed
742 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
743 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
744 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
745 quota_show_check a u $TSTUSR
746 quota_show_check a g $TSTUSR
748 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
749 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
750 error "touch failure, expect success"
751 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
753 echo " Chown files to $TSTUSR.$TSTUSR ..."
754 for i in `seq 0 $ILIMIT`; do
755 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
756 quota_error a $TSTUSR "chown failure, but expect success"
760 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
763 resetquota -u $TSTUSR
764 resetquota -g $TSTUSR
766 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
768 # block quota acquire & release
770 if [ $OSTCOUNT -lt 2 ]; then
771 skip_env "$OSTCOUNT < 2, too few osts"
775 wait_delete_completed
778 chmod 0777 $DIR/$tdir
780 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
781 FILEA="$DIR/$tdir/$tfile-0_a"
782 FILEB="$DIR/$tdir/$tfile-0_b"
784 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
785 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
786 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
787 quota_show_check b u $TSTUSR
788 quota_show_check b g $TSTUSR
790 echo " Create filea on OST0 and fileb on OST1"
791 $LFS setstripe $FILEA -i 0 -c 1
792 $LFS setstripe $FILEB -i 1 -c 1
793 chown $TSTUSR.$TSTUSR $FILEA
794 chown $TSTUSR.$TSTUSR $FILEB
796 echo " Exceed quota limit ..."
797 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
798 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
799 quota_error a $TSTUSR "write filea failure, but expect success"
804 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
805 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
807 echo " Write to OST1 return EDQUOT"
808 # this write maybe cache write, ignore it's failure
809 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
810 $RUNDD count=$(($BUNIT_SZ * 2)) || true
814 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
815 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
817 echo " Remove filea to let OST0 release quota"
820 if at_is_enabled; then
821 timeout=$(at_max_get mds)
823 timeout=$(lctl get_param -n timeout)
825 count=$((timeout / 5))
826 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
828 while [ $((count--)) -gt 0 ]; do
831 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
832 if [ -z $OST0_QUOTA_HOLD ]; then
833 error "System is error when query quota for block (U:$TSTUSR)."
835 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
841 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
844 while [ $((count--)) -gt 0 ]; do
847 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
848 if [ -z $OST0_QUOTA_HOLD ]; then
849 error "System is error when query quota for block (G:$TSTUSR)."
851 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
857 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
860 echo " Write to OST1"
861 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
862 quota_error a $TSTUSR "write fileb failure, expect success"
869 resetquota -u $TSTUSR
870 resetquota -g $TSTUSR
873 run_test_with_stat 6 "Block quota acquire & release ========="
875 # quota recovery (block quota only by now)
879 chmod 0777 $DIR/$tdir
881 wait_delete_completed
883 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
884 TESTFILE="$DIR/$tdir/$tfile-0"
886 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
888 $LFS setstripe $TESTFILE -c 1
889 chown $TSTUSR.$TSTUSR $TESTFILE
891 echo " Write to OST0..."
892 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
893 quota_error u $TSTUSR "write failure, but expect success"
895 #define OBD_FAIL_OBD_DQACQ 0x604
896 lustre_fail mds 0x604
897 echo " Remove files on OST0"
901 echo " Trigger recovery..."
902 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
903 for i in $OSC0_UUID; do
904 $LCTL --device $i activate || error "activate osc failed!"
907 # sleep a while to wait for recovery done
911 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
912 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
913 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
914 echo " total limits = $TOTAL_LIMIT"
916 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
917 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
918 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
919 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
920 echo " limits on $OST0_UUID = $OST0_LIMIT"
923 resetquota -u $TSTUSR
925 run_test_with_stat 7 "Quota recovery (only block limit) ======"
927 # run dbench with quota enabled
930 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
933 wait_delete_completed
935 echo " Set enough high limit for user: $TSTUSR"
936 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
937 echo " Set enough high limit for group: $TSTUSR"
938 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
940 chmod 0777 $DIR/$tdir
942 [ "$SLOW" = "no" ] && duration=" -t 120"
943 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
950 run_test_with_stat 8 "Run dbench with quota enabled ==========="
952 # run for fixing bug10707, it needs a big room. test for 64bit
954 GB=$((KB * 1024 * 1024))
955 # Use this as dd bs to decrease time
956 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
957 blksize=$((1 << 21)) # 2Mb
958 size_file=$((GB * 9 / 2))
959 # this check is just for test_9
960 OST0_MIN=4900000 #4.67G
961 check_whether_skip () {
962 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
963 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
964 if [ $OST0_SIZE -lt $OST0_MIN ]; then
965 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
973 check_whether_skip && return 0
975 wait_delete_completed
981 chmod 0777 $DIR/$tdir
982 TESTFILE="$DIR/$tdir/$tfile-0"
984 BLK_LIMIT=$((100 * KB * KB)) # 100G
986 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
988 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
989 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
990 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
991 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
993 quota_show_check a u $TSTUSR
994 quota_show_check a g $TSTUSR
997 $LFS setstripe $TESTFILE -c 1 -i 0
999 chown $TSTUSR.$TSTUSR $TESTFILE
1001 log " Write the big file of 4.5G ..."
1002 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1003 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
1008 log " delete the big file of 4.5G..."
1009 $RUNAS rm -f $TESTFILE
1010 sync; sleep 3; sync;
1017 set_blk_unitsz $((128 * 1024))
1018 set_blk_tunesz $((128 * 1024 / 2))
1022 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1024 # 2.0 version does not support 32 bit qd_count,
1025 # test_10 "run for fixing bug10707(32bit) " is obsolete
1027 # test a deadlock between quota and journal b=11693
1030 chmod 0777 $DIR/$tdir
1032 [ "$(grep $DIR2 /proc/mounts)" ] || mount_client $DIR2 || \
1033 { skip_env "Need lustre mounted on $MOUNT2 " && retutn 0; }
1035 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
1036 TESTFILE="$DIR/$tdir/$tfile-0"
1037 TESTFILE2="$DIR2/$tdir/$tfile-1"
1039 wait_delete_completed
1041 echo " User quota (limit: $LIMIT kbytes)"
1042 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1044 $LFS setstripe $TESTFILE -i 0 -c 1
1045 chown $TSTUSR.$TSTUSR $TESTFILE
1046 $LFS setstripe $TESTFILE2 -i 0 -c 1
1047 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
1049 #define OBD_FAIL_OST_HOLD_WRITE_RPC 0x21f
1050 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
1051 lustre_fail ost $((0x0000021f | 0x10000000)) 1
1053 echo " step1: write out of block quota ..."
1054 $RUNAS2 dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=102400 &
1056 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT*2)) &
1059 echo " step2: testing ......"
1060 local last_size=$(stat -c %s $TESTFILE2)
1062 local start_secs=$SECONDS
1063 while [ -d /proc/${DDPID1} ]; do
1064 local size=$(stat -c %s $TESTFILE2)
1065 if [ $size -eq $last_size ]; then
1066 stall_secs=$[stall_secs+1]
1070 if [ $stall_secs -gt 30 ]; then
1072 quota_error u $TSTUSR2 "giving up: dd stalled (i.e. made no progress) for 30 seconds!"
1077 echo "(dd_pid=$DDPID1, time=$((SECONDS-start_secs)))successful"
1079 #Recover fail_loc and dd will finish soon
1082 echo " step3: testing ......"
1085 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1087 if [ $count -gt 150 ]; then
1088 quota_error u $TSTUSR "dd should be finished!"
1092 echo "(dd_pid=$DDPID, time=$count)successful"
1094 rm -f $TESTFILE $TESTFILE2
1095 sync; sleep 3; sync;
1097 resetquota -u $TSTUSR
1099 run_test_with_stat 12 "test a deadlock between quota and journal ==="
1101 # test multiple clients write block quota b=11693
1104 wait_delete_completed
1106 # one OST * 10 + (mds + other OSTs)
1107 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1108 TESTFILE="$DIR/$tdir/$tfile"
1110 echo " User quota (limit: $LIMIT kbytes)"
1111 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1112 quota_show_check b u $TSTUSR
1114 $LFS setstripe $TESTFILE -i 0 -c 1
1115 chown $TSTUSR.$TSTUSR $TESTFILE
1116 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1117 chown $TSTUSR.$TSTUSR $TESTFILE.2
1119 echo " step1: write out of block quota ..."
1120 # one bunit will give mds
1121 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1123 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1126 echo " step2: testing ......"
1129 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1131 if [ $count -gt 64 ]; then
1132 quota_error u $TSTUSR "dd should be finished!"
1136 echo "(dd_pid=$DDPID, time=$count)successful"
1140 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1142 if [ $count -gt 64 ]; then
1143 quota_error u $TSTUSR "dd should be finished!"
1147 echo "(dd_pid=$DDPID1, time=$count)successful"
1149 sync; sleep 5; sync;
1151 echo " step3: checking ......"
1152 fz=`stat -c %s $TESTFILE`
1153 fz2=`stat -c %s $TESTFILE.2`
1155 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1156 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1158 rm -f $TESTFILE $TESTFILE.2
1159 sync; sleep 3; sync;
1161 resetquota -u $TSTUSR
1163 run_test_with_stat 13 "test multiple clients write block quota ==="
1165 check_if_quota_zero(){
1166 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1167 for i in `seq 3 $line`; do
1168 if [ $i -eq 3 ]; then
1174 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1175 awk '{print $'"$j"'}'`
1176 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1177 error "quota on $2 isn't clean"
1180 echo "pass check_if_quota_zero"
1183 test_14a() { # was test_14 b=12223 -- setting quota on root
1184 TESTFILE="$DIR/$tdir/$tfile"
1188 cleanup_and_setup_lustre
1193 # out of root's file and block quota
1194 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1195 createmany -m ${TESTFILE} 20 || \
1196 quota_error u root "unexpected: user(root) create files failly!"
1197 multiop ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1198 quota_error u root "unexpected: user(root) write files failly!"
1200 $RUNAS multiop ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1201 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1205 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1206 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1209 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1211 #check_if_quota_zero u root
1214 unlinkmany ${TESTFILE} 15
1216 sync; sleep 3; sync;
1218 run_test_with_stat 14a "test setting quota on root ==="
1221 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1222 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1224 wait_delete_completed
1227 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1228 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1229 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1230 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1231 resetquota -u $TSTUSR
1234 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1235 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1236 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1237 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1238 resetquota -g $TSTUSR
1239 $LFS quotaoff -ug $DIR
1240 do_facet $SINGLEMDS "lctl set_param lquota.mdd_obd-${FSNAME}-MDT*.quota_type=ug" | grep "error writing" && \
1241 error "fail to set version for $SINGLEMDS"
1242 for j in `seq $OSTCOUNT`; do
1243 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.quota_type=ug" | grep "error writing" && \
1244 error "fail to set version for ost$j"
1247 echo "invalidating quota files"
1248 $LFS quotainv -ug $DIR
1249 $LFS quotainv -ugf $DIR
1250 $LFS quotacheck -ug $DIR
1252 run_test_with_stat 15 "set block quota more than 4T ==="
1254 # 2.0 version does not support WITHOUT_CHANGE_QS,
1255 # test_16 "test without adjusting qunit" is obsolete
1257 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1262 wait_delete_completed
1264 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1265 lustre_fail ost 0x80000A02
1267 TESTFILE="$DIR/$tdir/$tfile-a"
1268 TESTFILE2="$DIR/$tdir/$tfile-b"
1271 BLK_LIMIT=$((100 * 1024)) # 100M
1273 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1274 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1275 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1276 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1278 quota_show_check b u $TSTUSR
1279 quota_show_check b g $TSTUSR
1282 chown $TSTUSR.$TSTUSR $TESTFILE
1284 chown $TSTUSR.$TSTUSR $TESTFILE2
1286 log " Write the test file1 ..."
1287 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1288 || quota_error a $TSTUSR "write 10M file failure"
1293 log " write the test file2 ..."
1294 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1295 || quota_error a $TSTUSR "write 10M file failure"
1300 rm -f $TESTFILE $TESTFILE2
1302 sync; sleep 3; sync;
1304 # make qd_count 64 bit
1307 set_blk_unitsz $((128 * 1024))
1308 set_blk_tunesz $((128 * 1024 / 2))
1310 resetquota -u $TSTUSR
1311 resetquota -g $TSTUSR
1315 run_test_with_stat 17 "run for fixing bug14526 ==========="
1317 # test when mds takes a long time to handle a quota req so that
1318 # the ost has dropped it, the ost still could work well b=14840
1320 LIMIT=$((100 * 1024 * 1024)) # 100G
1321 TESTFILE="$DIR/$tdir/$tfile"
1324 wait_delete_completed
1329 log " User quota (limit: $LIMIT kbytes)"
1330 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1331 quota_show_check b u $TSTUSR
1333 $LFS setstripe $TESTFILE -i 0 -c 1
1334 chown $TSTUSR.$TSTUSR $TESTFILE
1336 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1337 lustre_fail mds 0x13c
1339 log " step1: write 100M block ..."
1340 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1346 echo " step2: testing ......"
1348 if at_is_enabled; then
1349 timeout=$(at_max_get mds)
1351 timeout=$(lctl get_param -n timeout)
1354 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1356 if [ $count -gt $((4 * $timeout)) ]; then
1357 quota_error u $TSTUSR "count=$count dd should be finished!"
1361 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1363 cancel_lru_locks mdc
1364 cancel_lru_locks osc
1366 testfile_size=$(stat -c %s $TESTFILE)
1367 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1368 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1373 resetquota -u $TSTUSR
1374 set_blk_unitsz $((128 * 1024))
1375 set_blk_tunesz $((128 * 1024 / 2))
1377 run_test_with_stat 18 "run for fixing bug14840 ==========="
1379 # test when mds drops a quota req, the ost still could work well b=14840
1381 LIMIT=$((100 * 1024 * 1024)) # 100G
1382 TESTFILE="$DIR/$tdir/$tfile-a"
1385 wait_delete_completed
1390 log " User quota (limit: $LIMIT kbytes)"
1391 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1392 quota_show_check b u $TSTUSR
1394 $LFS setstripe $TESTFILE -i 0 -c 1
1395 chown $TSTUSR.$TSTUSR $TESTFILE
1397 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1398 lustre_fail mds 0x8000013d
1400 log " step1: write 100M block ..."
1401 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1404 echo " step2: testing ......"
1406 if at_is_enabled; then
1407 timeout=$(at_max_get mds)
1409 timeout=$(lctl get_param -n timeout)
1412 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1414 if [ $count -gt $((6 * $timeout)) ]; then
1416 quota_error u $TSTUSR "count=$count dd should be finished!"
1420 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1426 resetquota -u $TSTUSR
1427 set_blk_unitsz $((128 * 1024))
1428 set_blk_tunesz $((128 * 1024 / 2))
1430 run_test_with_stat 18a "run for fixing bug14840 ==========="
1432 # test when mds do failover, the ost still could work well without trigger
1437 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1438 TESTFILE="$DIR/$tdir/$tfile"
1441 wait_delete_completed
1446 log " User quota (limit: $LIMIT kbytes)"
1447 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1448 quota_show_check b u $TSTUSR
1450 $LFS setstripe $TESTFILE -i 0 -c 1
1451 chown $TSTUSR.$TSTUSR $TESTFILE
1453 timeout=$(sysctl -n lustre.timeout)
1455 if [ $type = "directio" ]; then
1456 log " write 100M block(directio) ..."
1457 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1459 log " write 100M block(normal) ..."
1460 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1464 do_facet $SINGLEMDS "$LCTL conf_param ${FSNAME}-MDT*.mdd.quota_type=ug"
1466 replay_barrier $SINGLEMDS
1468 log "failing mds for $((2 * timeout)) seconds"
1469 fail $SINGLEMDS $((2 * timeout))
1471 # check if quotaon successful
1472 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1473 if [ $? -eq 0 ]; then
1475 error "quotaon failed!"
1480 if at_is_enabled; then
1481 timeout=$(at_max_get mds)
1483 timeout=$(lctl get_param -n timeout)
1486 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1487 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1488 log "it took $count second"
1492 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1494 cancel_lru_locks mdc
1495 cancel_lru_locks osc
1498 resetquota -u $TSTUSR
1499 set_blk_unitsz $((128 * 1024))
1500 set_blk_tunesz $((128 * 1024 / 2))
1501 testfile_size=$(stat -c %s $TESTFILE)
1502 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1504 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1510 # test when mds does failover, the ost still could work well
1511 # this test shouldn't trigger watchdog b=14840
1513 test_18bc_sub normal
1514 test_18bc_sub directio
1515 # check if watchdog is triggered
1516 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1517 watchdog=`awk '/test 18b/ {start = 1;}
1518 /Service thread pid/ && /was inactive/ {
1522 }' $TMP/lustre-log-${TESTNAME}.log`
1523 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1524 rm -f $TMP/lustre-log-${TESTNAME}.log
1526 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1528 # test when mds does failover, the ost still could work well
1529 # this test will prevent OST_DISCONNET from happening b=14840
1531 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1532 lustre_fail ost 0x202
1533 test_18bc_sub normal
1534 test_18bc_sub directio
1537 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1539 run_to_block_limit() {
1540 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1542 wait_delete_completed
1544 # set 1 Mb quota unit size
1548 # bind file to a single OST
1549 $LFS setstripe -c 1 $TESTFILE
1550 chown $TSTUSR.$TSTUSR $TESTFILE
1552 echo " User quota (limit: $LIMIT kbytes)"
1553 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1554 quota_show_check b u $TSTUSR
1555 echo " Updating quota limits"
1556 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1557 quota_show_check b u $TSTUSR
1559 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1560 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1561 # for now page cache of TESTFILE may still be dirty,
1562 # let's push it to the corresponding OST, this will also
1563 # cache NOQUOTA on the client from OST's reply
1564 cancel_lru_locks osc
1565 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1569 # 1 Mb bunit per each MDS/OSS
1570 local TESTFILE="$DIR/$tdir/$tfile"
1573 run_to_block_limit $TESTFILE
1578 resetquota -u $TSTUSR
1580 set_blk_unitsz $((128 * 1024))
1581 set_blk_tunesz $((128 * 1024 / 2))
1584 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1588 LSTR=(1t 2g 3m 4k) # limits strings
1589 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1591 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1592 $MOUNT || error "could not set quota limits"
1594 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1595 --inode-softlimit ${LSTR[2]} \
1596 --inode-hardlimit ${LSTR[3]} \
1597 $MOUNT || error "could not set quota limits"
1599 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1600 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1601 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1602 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1604 resetquota -u $TSTUSR
1606 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1613 time=$(($(date +%s) + seconds))
1614 while [ $(date +%s) -lt $time ]; do
1615 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1620 # run for fixing bug16053, setquota shouldn't fail when writing and
1621 # deleting are happening
1626 wait_delete_completed
1628 TESTFILE="$DIR/$tdir/$tfile"
1630 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1633 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1634 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1635 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1636 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1638 # repeat writing on a 1M file
1639 test_21_sub ${TESTFILE}_1 1024 30 &
1641 # repeat writing on a 128M file
1642 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1645 time=$(($(date +%s) + 30))
1647 while [ $(date +%s) -lt $time ]; do
1648 log " Set quota for $i times"
1649 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1650 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1657 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1659 if [ $count -gt 60 ]; then
1660 quota_error a $TSTUSR "dd should be finished!"
1664 echo "(dd_pid=$DDPID1, time=$count)successful"
1668 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1670 if [ $count -gt 60 ]; then
1671 quota_error a $TSTUSR "dd should be finished!"
1675 echo "(dd_pid=$DDPID2, time=$count)successful"
1677 set_blk_unitsz $((128 * 1024))
1678 set_blk_tunesz $((128 * 1024 / 2))
1679 resetquota -u $TSTUSR
1680 resetquota -g $TSTUSR
1684 run_test_with_stat 21 "run for fixing bug16053 ==========="
1687 quota_save_version "ug3"
1693 echo "checking parameters"
1695 do_facet $SINGLEMDS "lctl get_param mdd.${FSNAME}-MDT*.quota_type" | grep "ug3" || error "admin failure"
1696 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug3" || error "op failure"
1700 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1704 chmod 0777 $DIR/$tdir
1705 TESTFILE="$DIR/$tdir/$tfile-0"
1707 local bs_unit=$((1024*1024))
1710 wait_delete_completed
1713 log " User quota (limit: $LIMIT kbytes)"
1714 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1716 quota_show_check b u $TSTUSR
1718 $LFS setstripe $TESTFILE -c 1 -i 0
1719 chown $TSTUSR.$TSTUSR $TESTFILE
1721 log " Step1: trigger quota with 0_DIRECT"
1722 log " Write half of file"
1723 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || \
1724 quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1725 log " Write out of block quota ..."
1726 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && \
1727 quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1730 log " Step2: rewrite should succeed"
1731 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || \
1732 quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1736 wait_delete_completed
1737 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1738 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1739 echo $OST0_QUOTA_USED
1740 [ $OST0_QUOTA_USED -ne 0 ] && \
1741 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1743 resetquota -u $TSTUSR
1747 local slave_cnt=$((OSTCOUNT + 1)) # 1 mds, n osts
1749 OST0_MIN=$((6 * $slave_cnt * 1024)) # extra space for meta blocks.
1750 check_whether_skip && return 0
1751 log "run for $((4 * $slave_cnt))MB test file"
1752 test_23_sub $((4 * $slave_cnt * 1024))
1754 OST0_MIN=$((60 * $slave_cnt * 1024)) # extra space for meta blocks.
1755 check_whether_skip && return 0
1756 log "run for $((40 * $slave_cnt))MB test file"
1757 test_23_sub $((40 * $slave_cnt * 1024))
1759 run_test_with_stat 23 "run for fixing bug16125 ==========="
1762 local TESTFILE="$DIR/$tdir/$tfile"
1765 run_to_block_limit $TESTFILE
1766 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1770 resetquota -u $TSTUSR
1772 set_blk_unitsz $((128 * 1024))
1773 set_blk_tunesz $((128 * 1024 / 2))
1776 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1779 if [ $1 = "-u" ]; then
1780 if [ $2 = "$TSTUSR" ]; then
1786 if [ $2 = "$TSTUSR" ]; then
1796 chmod 0777 $DIR/$tdir
1797 TESTFILE="$DIR/$tdir/$tfile-0"
1799 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1801 wait_delete_completed
1803 # set quota for $TSTUSR
1804 log "setquota for $TSTUSR"
1805 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1807 if [ "$1" == "-u" ]; then
1808 quota_show_check a u $TSTUSR
1810 quota_show_check a g $TSTUSR
1813 # set quota for $TSTUSR2
1814 log "setquota for $TSTUSR2"
1815 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1817 if [ "$1" == "-u" ]; then
1818 quota_show_check a u $TSTUSR2
1820 quota_show_check a g $TSTUSR2
1823 # set stripe index to 0
1824 log "setstripe for $DIR/$tdir to 0"
1825 $LFS setstripe $DIR/$tdir -c 1 -i 0
1826 MDS_UUID=`do_facet $SINGLEMDS $LCTL dl | grep -m1 " mdt " | awk '{print $((NF-1))}'`
1827 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1828 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1829 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1830 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1831 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1834 log "$TSTUSR write 4M to $TESTFILE"
1835 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1837 show_quota $1 $TSTUSR
1838 show_quota $1 $TSTUSR2
1839 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1840 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1841 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1842 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1843 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1844 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1845 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1847 # chown/chgrp from $TSTUSR to $TSTUSR2
1848 if [ $1 = "-u" ]; then
1849 log "chown from $TSTUSR to $TSTUSR2"
1850 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1852 log "chgrp from $TSTUSR to $TSTUSR2"
1853 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1856 show_quota $1 $TSTUSR
1857 show_quota $1 $TSTUSR2
1858 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1859 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1860 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1861 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1862 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1863 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1864 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1865 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1866 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1867 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1868 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1869 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1870 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1871 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1872 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1875 wait_delete_completed
1876 resetquota $1 $TSTUSR
1877 resetquota $1 $TSTUSR2
1881 log "run for chown case"
1884 log "run for chgrp case"
1887 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1891 chmod 0777 $DIR/$tdir
1892 TESTFILE="$DIR/$tdir/$tfile-0"
1893 TESTFILE2="$DIR/$tdir/$tfile-1"
1897 wait_delete_completed
1899 # every quota slave gets 20MB
1900 b_limit=$(((OSTCOUNT + 1) * 20 * 1024))
1901 log "limit: ${b_limit}KB"
1902 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
1904 quota_show_check b u $TSTUSR
1906 $LFS setstripe $TESTFILE -c 1 -i 0
1907 $LFS setstripe $TESTFILE2 -c 1 -i 0
1908 chown $TSTUSR.$TSTUSR $TESTFILE
1909 chown $TSTUSR.$TSTUSR $TESTFILE2
1911 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
1912 lustre_fail ost 0xA03
1914 log " Write the first file..."
1915 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1916 log " Delete the first file..."
1920 wait_delete_completed
1922 log " Write the second file..."
1923 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
1924 log " Delete the second file..."
1928 set_blk_unitsz $((128 * 1024))
1929 set_blk_tunesz $((128 * 1024 / 2))
1930 resetquota -u $TSTUSR
1932 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
1935 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1936 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
1939 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
1942 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1943 error "lfs setquota failed with uid argument"
1944 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
1945 error "lfs stequota failed with gid argument"
1946 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1947 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1948 resetquota -u $TSTUSR
1949 resetquota -g $TSTUSR
1952 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
1955 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
1956 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1957 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1960 echo "Step 2: reset system ..."
1961 cleanup_and_setup_lustre
1964 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
1968 wait_delete_completed
1970 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1971 lustre_fail ost 0x80000A02
1973 TESTFILE="$DIR/$tdir/$tfile"
1976 BLK_LIMIT=$((100 * 1024)) # 100M
1977 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
1978 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1982 chown $TSTUSR.$TSTUSR $TESTFILE
1984 echo "Step 5: write the test file1 [10M] ..."
1985 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1986 || quota_error a $TSTUSR "write 10M file failure"
1990 sync; sleep 3; sync;
1992 # make qd_count 64 bit
1995 set_blk_unitsz $((128 * 1024))
1996 set_blk_tunesz $((128 * 1024 / 2))
1998 resetquota -u $TSTUSR
2000 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2004 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2008 if at_is_enabled; then
2009 timeout=$(at_max_get client)
2010 at_max_set 10 client
2012 timeout=$(lctl get_param -n timeout)
2013 lctl set_param timeout=10
2015 # actually send a RPC to make service at_current confined within at_max
2016 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR || error "should succeed"
2018 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2019 lustre_fail mds 0x12e
2021 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2023 echo "sleeping for 10 * 1.25 + 5 + 10 seconds"
2025 ps -p $pid && error "lfs hadn't finished by timeout"
2026 wait $pid && error "succeeded, but should have failed"
2030 if at_is_enabled; then
2031 at_max_set $timeout client
2033 lctl set_param timeout=$timeout
2036 resetquota -u $TSTUSR
2038 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2044 local TESTFILE="$DIR/$tdir/$tfile"
2051 chmod 0777 $DIR/$tdir
2053 $LFS setstripe $TESTFILE -i 0 -c 1
2054 chown $TSTUSR.$TSTUSR $TESTFILE
2056 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2057 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2058 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2059 cancel_lru_locks osc
2061 $LFS setquota -u $TSTUSR -B 0 $DIR
2062 # over-quota flag has not yet settled since we do not trigger async events
2063 # based on grace time period expiration
2065 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2066 cancel_lru_locks osc
2067 # now over-quota flag should be settled and further writes should fail
2069 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2071 resetquota -u $TSTUSR
2072 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2074 set_blk_unitsz $((128 * 1024))
2075 set_blk_tunesz $((128 * 1024 / 2))
2077 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2079 # test duplicate quota releases b=18630
2082 chmod 0777 $DIR/$tdir
2084 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2085 TESTFILE="$DIR/$tdir/$tfile-0"
2086 TESTFILE2="$DIR/$tdir/$tfile-1"
2088 wait_delete_completed
2090 log " User quota (limit: $LIMIT kbytes)"
2091 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2093 $LFS setstripe $TESTFILE -i 0 -c 1
2094 chown $TSTUSR.$TSTUSR $TESTFILE
2095 $LFS setstripe $TESTFILE2 -i 0 -c 1
2096 chown $TSTUSR.$TSTUSR $TESTFILE2
2098 log " step1: write out of block quota ..."
2099 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2100 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2102 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2103 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2104 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2106 log " step2: delete two files so that triggering duplicate quota release ..."
2107 rm -f $TESTFILE $TESTFILE2
2108 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2109 wait_delete_completed
2111 log " step3: verify if the ost failed"
2112 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2113 watchdog=`awk '/test 31/ {start = 1;}
2114 /release quota error/ {
2118 }' $TMP/lustre-log-${TESTNAME}.log`
2119 [ "$watchdog" ] && error "$watchdog"
2120 rm -f $TMP/lustre-log-${TESTNAME}.log
2123 resetquota -u $TSTUSR
2125 run_test_with_stat 31 "test duplicate quota releases ==="
2127 # check hash_cur_bits
2128 check_quota_hash_cur_bits() {
2131 # check quota_hash_cur_bits on all obdfilters
2132 for num in `seq $OSTCOUNT`; do
2133 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2134 if [ $cb -gt $bits ]; then
2135 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2139 # check quota_hash_cur_bits on mds
2140 cb=`do_facet $SINGLEMDS "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2141 if [ $cb -gt $bits ]; then
2142 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2150 # check distribution of all obdfilters
2151 for num in `seq $OSTCOUNT`; do
2152 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2153 rehash_count=`echo $line | awk '{print $9}'`
2154 if [ $rehash_count -eq 0 ]; then
2155 echo -e "ost$num:\n $line"
2156 error "Rehearsh didn't happen"
2160 # check distribution of mds
2161 do_facet $SINGLEMDS "lctl get_param mdt.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2162 rehash_count=`echo $line | awk '{print $9}'`
2163 if [ $rehash_count -eq 0 ]; then
2164 echo -e "mdt:\n $line"
2165 error "Rehearsh didn't happen"
2172 # reset system so that quota_hash_cur_bits==3
2173 echo "Reset system ..."
2174 local LMR_orig=$LOAD_MODULES_REMOTE
2175 LOAD_MODULES_REMOTE=true
2176 cleanup_and_setup_lustre
2177 LOAD_MODULES_REMOTE=$LMR_orig
2183 for user in $SANITY_QUOTA_USERS; do
2184 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2185 missing_users="$missing_users $user"
2187 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2188 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2190 $LFS quotaoff -ug $DIR
2191 $LFS quotacheck -ug $DIR
2193 for user in $SANITY_QUOTA_USERS; do
2194 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2199 for user in $SANITY_QUOTA_USERS; do
2203 run_test 32 "check lqs hash(bug 21846) =========================================="
2205 cleanup_quota_test() {
2207 echo "Delete files..."
2211 # basic usage tracking for user & group
2214 chmod 0777 $DIR/$tdir
2217 TOTAL_BLKS=$(($INODES * $BLK_CNT))
2219 trap cleanup_quota_test EXIT
2221 # make sure the system is clean
2222 USED=`getquota -u $TSTID global curspace`
2223 [ $USED -ne 0 ] && \
2224 error "Used space ($USED) for user $TSTID isn't 0."
2225 USED=`getquota -g $TSTID global curspace`
2226 [ $USED -ne 0 ] && \
2227 error "Used space ($USED) for group $TSTID isn't 0."
2229 echo "Write files..."
2230 for i in `seq 0 $INODES`; do
2231 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile-$i bs=$BLK_SZ \
2232 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2235 echo "Verify disk usage after write"
2236 USED=`getquota -u $TSTID global curspace`
2237 [ $USED -lt $TOTAL_BLKS ] && \
2238 error "Used space for user $TSTID is $USED, expected $TOTAL_BLKS"
2239 USED=`getquota -u $TSTID global curinodes`
2240 [ $USED -lt $INODES ] && \
2241 error "Used inode for user $TSTID is $USED, expected $INODES"
2243 USED=`getquota -g $TSTID global curspace`
2244 [ $USED -lt $TOTAL_BLKS ] && \
2245 error "Used space for group $TSTID is $USED, expected $TOTAL_BLKS"
2246 USED=`getquota -g $TSTID global curinodes`
2247 [ $USED -lt $INODES ] && \
2248 error "Used inode for group $TSTID is $USED, expected $INODES"
2252 echo "Verify disk usage after delete"
2253 wait_delete_completed
2254 USED=`getquota -u $TSTID global curspace`
2255 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2256 USED=`getquota -u $TSTID global curinodes`
2257 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2258 USED=`getquota -g $TSTID global curspace`
2259 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2260 USED=`getquota -g $TSTID global curinodes`
2261 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2263 run_test 33 "basic usage tracking for user & group =============================="
2265 # usage transfer test for user & group
2269 chmod 0777 $DIR/$tdir
2271 trap cleanup_quota_test EXIT
2273 # make sure the system is clean
2274 USED=`getquota -u $TSTID global curspace`
2275 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2276 USED=`getquota -g $TSTID global curspace`
2277 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2279 echo "Write file..."
2280 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ count=$BLK_CNT \
2281 oflag=sync 2>/dev/null || error "write failed"
2283 echo "chown the file to user $TSTID"
2284 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2286 echo "Verify disk usage for user $TSTID"
2287 USED=`getquota -u $TSTID global curspace`
2288 [ $USED -lt $BLK_CNT ] && \
2289 error "Used space for user $TSTID is $USED, expected $BLK_CNT"
2290 USED=`getquota -u $TSTID global curinodes`
2291 [ $USED -ne 1 ] && \
2292 error "Used inodes for user $TSTID is $USED, expected 1"
2294 echo "chgrp the file to group $TSTID"
2295 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2297 echo "Verify disk usage for group $TSTID"
2298 USED=`getquota -g $TSTID global curspace`
2299 [ $USED -ge $BLK_CNT ] || \
2300 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2301 USED=`getquota -g $TSTID global curinodes`
2302 [ $USED -eq 1 ] || \
2303 error "Used inodes for group $TSTID is $USED, expected 1"
2307 run_test 34 "usage transfer for user & group ===================================="
2309 # usage is still accessible across restart
2312 chmod 0777 $DIR/$tdir
2315 trap cleanup_quota_test EXIT
2317 echo "Write file..."
2318 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=$BLK_SZ \
2319 count=$BLK_CNT oflag=sync 2>/dev/null || error "write failed"
2321 echo "Save disk usage before restart"
2322 ORIG_USR_SPACE=`getquota -u $TSTID global curspace`
2323 [ $ORIG_USR_SPACE -eq 0 ] && \
2324 error "Used space for user $TSTID is 0, expected $BLK_CNT"
2325 ORIG_USR_INODES=`getquota -u $TSTID global curinodes`
2326 [ $ORIG_USR_INODES -eq 0 ] && \
2327 error "Used inodes for user $TSTID is 0, expected 1"
2328 ORIG_GRP_SPACE=`getquota -g $TSTID global curspace`
2329 [ $ORIG_GRP_SPACE -eq 0 ] && \
2330 error "Used space for group $TSTID is 0, expected $BLK_CNT"
2331 ORIG_GRP_INODES=`getquota -g $TSTID global curinodes`
2332 [ $ORIG_GRP_INODES -eq 0 ] && \
2333 error "Used inodes for group $TSTID is 0, expected 1"
2336 local ORIG_REFORMAT=$REFORMAT
2338 cleanup_and_setup_lustre
2339 REFORMAT=$ORIG_REFORMAT
2342 echo "Verify disk usage after restart"
2343 USED=`getquota -u $TSTID global curspace`
2344 [ $USED -eq $ORIG_USR_SPACE ] || \
2345 error "Used space for user $TSTID changed from " \
2346 "$ORIG_USR_SPACE to $USED"
2347 USED=`getquota -u $TSTID global curinodes`
2348 [ $USED -eq $ORIG_USR_INODES ] || \
2349 error "Used inodes for user $TSTID changed from " \
2350 "$ORIG_USR_INODES to $USED"
2351 USED=`getquota -g $TSTID global curspace`
2352 [ $USED -eq $ORIG_GRP_SPACE ] || \
2353 error "Used space for group $TSTID changed from " \
2354 "$ORIG_GRP_SPACE to $USED"
2355 USED=`getquota -g $TSTID global curinodes`
2356 [ $USED -eq $ORIG_GRP_INODES ] || \
2357 error "Used inodes for group $TSTID changed from " \
2358 "$ORIG_GRP_INODES to $USED"
2362 run_test 35 "usage is still accessible across reboot ============================"
2369 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2374 complete $(basename $0) $SECONDS
2375 check_and_cleanup_lustre
2376 export QUOTA_AUTO=$QUOTA_AUTO_OLD