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}
57 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
61 require_dsh_mds || exit 0
62 require_dsh_ost || exit 0
64 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
66 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
68 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
73 check_and_setup_lustre
75 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
76 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
78 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
79 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
80 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
81 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
82 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
83 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
84 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
85 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
87 # control the time of tests
89 [ "$SLOW" = "no" ] && cycle=10
96 # set_blk_tunables(btune_sz)
98 local btune=$(($1 * BLK_SZ))
99 # set btune size on all obdfilters
100 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
101 # set btune size on mds
102 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_btune_sz=$btune"
105 # set_blk_unitsz(bunit_sz)
107 local bunit=$(($1 * BLK_SZ))
108 # set bunit size on all obdfilters
109 do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
110 # set bunit size on mds
111 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_bunit_sz=$bunit"
114 # set_file_tunesz(itune_sz)
117 # set itune size on mds
118 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_itune_sz=$itune"
121 # set_file_unitsz(iunit_sz)
124 # set iunit size on mds
125 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.quota_iunit_sz=$iunit"
131 local fail_val=${3:-0}
133 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
134 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
135 [ $((fail_loc)) -eq 0 ]; then
136 do_facet mds "lctl set_param fail_val=$fail_val"
138 do_facet mds "lctl set_param fail_loc=$fail_loc"
140 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
141 for num in `seq $OSTCOUNT`; do
142 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
143 [ $((fail_loc)) -eq 0 ]; then
144 do_facet ost$num "lctl set_param fail_val=$fail_val"
146 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
151 RUNAS="runas -u $TSTID -g $TSTID"
152 RUNAS2="runas -u $TSTID2 -g $TSTID2"
153 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
154 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
158 run_test_with_stat() {
159 (($# != 2)) && error "the number of arguments is wrong"
161 do_facet mds "lctl set_param lquota.*${FSNAME}-MDT*.stats=0" > /dev/null || true
162 for j in `seq $OSTCOUNT`; do
163 do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null || true
166 if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
167 echo "statistics info begin ***************************************"
168 do_facet mds "lctl get_param lquota.*${FSNAME}-MDT*.stats"
169 for j in `seq $OSTCOUNT`; do
170 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
172 echo "statistics info end ***************************************"
177 # clear quota limits for a user or a group
178 # usage: resetquota -u username
179 # resetquota -g groupname
182 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
183 [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
186 if at_is_enabled; then
187 timeout=$(at_max_get mds)
189 timeout=$(lctl get_param -n timeout)
192 while [ $((count++)) -lt $timeout ]; do
193 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
195 if [ $RC -ne 0 ]; then
196 if [ $RC -eq 240 ]; then # 240 means -EBUSY
197 log "resetquota is blocked for quota master recovery, retry after 1 sec"
201 error "resetquota failed: $RC"
207 [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
214 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
215 log "Files for user ($LOCAL_ID):"
216 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
219 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
220 log "Files for group ($LOCAL_ID):"
221 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
238 # get quota info for a user or a group
239 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
245 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
246 [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
259 *) error "unknown quota parameter $4";;
262 [ "$uuid" = "global" ] && uuid=$DIR
264 $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }'
271 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
273 $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
275 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
276 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
277 if [ -z $USAGE ]; then
278 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
280 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
284 if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
285 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
286 if [ -z $USAGE ]; then
287 quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
289 [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
296 lctl set_param debug="+quota"
297 do_facet mds "lctl set_param debug=+quota"
298 for num in `seq $OSTCOUNT`; do
299 do_facet ost$num "lctl set_param debug=+quota"
302 log "do the quotacheck ..."
303 $LFS quotacheck -ug $DIR
305 resetquota -u $TSTUSR
306 resetquota -g $TSTUSR
308 run_test_with_stat 0 "Set quota ============================="
310 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
314 chmod 0777 $DIR/$tdir
315 TESTFILE="$DIR/$tdir/$tfile-0"
317 wait_delete_completed
320 log " User quota (limit: $LIMIT kbytes)"
321 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
323 quota_show_check b u $TSTUSR
325 $LFS setstripe $TESTFILE -c 1
326 chown $TSTUSR.$TSTUSR $TESTFILE
329 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
331 log " Write out of block quota ..."
332 # this time maybe cache write, ignore it's failure
333 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
334 # flush cache, ensure noquota flag is setted on client
336 $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"
340 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
341 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
342 echo $OST0_QUOTA_USED
343 [ $OST0_QUOTA_USED -ne 0 ] && \
344 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
346 resetquota -u $TSTUSR
349 log "--------------------------------------"
350 log " Group quota (limit: $LIMIT kbytes)"
351 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
353 quota_show_check b g $TSTUSR
354 TESTFILE="$DIR/$tdir/$tfile-1"
356 $LFS setstripe $TESTFILE -c 1
357 chown $TSTUSR.$TSTUSR $TESTFILE
360 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
362 log " Write out of block quota ..."
363 # this time maybe cache write, ignore it's failure
364 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
366 $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"
371 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
372 OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
373 echo $OST0_QUOTA_USED
374 [ $OST0_QUOTA_USED -ne 0 ] && \
375 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
377 resetquota -g $TSTUSR
380 # block hard limit (normal use and out of quota)
382 for i in `seq 1 $cycle`; do
383 # define blk_qunit is between 1M and 4M
384 blk_qunit=$(( $RANDOM % 3072 + 1024 ))
385 blk_qtune=$(( $RANDOM % $blk_qunit ))
386 # other osts and mds will occupy at 1M blk quota
387 b_limit=$(( ($RANDOM - 16384) / 8 + $OSTCOUNT * $blk_qunit * 4 ))
388 set_blk_tunesz $blk_qtune
389 set_blk_unitsz $blk_qunit
390 echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
392 echo "=================================================="
393 set_blk_unitsz $((128 * 1024))
394 set_blk_tunesz $((128 * 1024 / 2))
397 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
399 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
403 chmod 0777 $DIR/$tdir
404 TESTFILE="$DIR/$tdir/$tfile-0"
406 wait_delete_completed
409 log " User quota (limit: $LIMIT files)"
410 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
412 quota_show_check f u $TSTUSR
414 log " Create $LIMIT files ..."
415 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
416 quota_error u $TSTUSR "(usr) create failure, but expect success"
418 log " Create out of file quota ..."
419 $RUNAS touch ${TESTFILE}_xxx && \
420 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
422 unlinkmany ${TESTFILE} $LIMIT
423 rm -f ${TESTFILE}_xxx
427 local dev=$(get_mds_mdt_device_proc_path)
428 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
429 MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
432 [ $MDS_QUOTA_USED -ne 0 ] && \
433 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
435 resetquota -u $TSTUSR
438 log "--------------------------------------"
439 log " Group quota (limit: $LIMIT FILE)"
440 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
442 quota_show_check f g $TSTUSR
443 TESTFILE=$DIR/$tdir/$tfile-1
445 log " Create $LIMIT files ..."
446 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
447 quota_error g $TSTUSR "(grp) create failure, but expect success"
449 log " Create out of file quota ..."
450 $RUNAS touch ${TESTFILE}_xxx && \
451 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
453 unlinkmany ${TESTFILE} $LIMIT
454 rm -f ${TESTFILE}_xxx
457 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
458 MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
461 [ $MDS_QUOTA_USED -ne 0 ] && \
462 ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
464 resetquota -g $TSTUSR
467 # file hard limit (normal use and out of quota)
469 for i in `seq 1 $cycle`; do
470 if [ $i -eq 1 ]; then
475 # define ino_qunit is between 10 and 100
476 ino_qunit=$(( $RANDOM % 90 + 10 ))
477 ino_qtune=$(( $RANDOM % $ino_qunit ))
478 # RANDOM's maxium is 32767
479 i_limit=$(( $RANDOM % 990 + 10 ))
482 set_file_tunesz $ino_qtune
483 set_file_unitsz $ino_qunit
484 echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
486 echo "=================================================="
491 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
495 TIMER=$(($2 * 3 / 2))
498 wait_delete_completed
500 echo " Write to exceed soft limit"
501 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
502 $RUNDD count=$((BUNIT_SZ+1)) || \
503 quota_error a $TSTUSR "write failure, but expect success"
504 OFFSET=$((OFFSET + BUNIT_SZ + 1))
509 $SHOW_QUOTA_INFO_USER
510 $SHOW_QUOTA_INFO_GROUP
512 echo " Write before timer goes off"
513 $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
514 quota_error a $TSTUSR "write failure, but expect success"
515 OFFSET=$((OFFSET + BUNIT_SZ))
519 echo " Sleep $TIMER seconds ..."
524 $SHOW_QUOTA_INFO_USER
525 $SHOW_QUOTA_INFO_GROUP
527 echo " Write after timer goes off"
528 # maybe cache write, ignore.
529 $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
530 OFFSET=$((OFFSET + BUNIT_SZ))
532 $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
533 quota_error a $TSTUSR "write success, but expect EDQUOT"
537 $SHOW_QUOTA_INFO_USER
538 $SHOW_QUOTA_INFO_GROUP
540 echo " Unlink file to stop timer"
547 $SHOW_QUOTA_INFO_USER
548 $SHOW_QUOTA_INFO_GROUP
551 $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
559 # block soft limit (start timer, timer goes off, stop timer)
562 chmod 0777 $DIR/$tdir
564 # 1 bunit on mds and 1 bunit on every ost
565 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
568 echo " User quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
569 TESTFILE=$DIR/$tdir/$tfile-0
571 $LFS setstripe $TESTFILE -c 1
572 chown $TSTUSR.$TSTUSR $TESTFILE
574 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
575 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
577 test_block_soft $TESTFILE $GRACE
578 resetquota -u $TSTUSR
580 echo " Group quota (soft limit: $LIMIT kbytes grace: $GRACE seconds)"
581 TESTFILE=$DIR/$tdir/$tfile-1
583 $LFS setstripe $TESTFILE -c 1
584 chown $TSTUSR.$TSTUSR $TESTFILE
586 $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
587 $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
589 test_block_soft $TESTFILE $GRACE
590 resetquota -g $TSTUSR
592 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
597 TIMER=$(($3 * 3 / 2))
599 wait_delete_completed
601 echo " Create files to exceed soft limit"
602 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
603 quota_error a $TSTUSR "create failure, but expect success"
607 echo " Create file before timer goes off"
608 $RUNAS touch ${TESTFILE}_before || \
609 quota_error a $TSTUSR "failed create before timer expired, but expect success"
613 echo " Sleep $TIMER seconds ..."
618 $SHOW_QUOTA_INFO_USER
619 $SHOW_QUOTA_INFO_GROUP
621 echo " Create file after timer goes off"
622 # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
623 # inode quota left here
624 $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
626 $RUNAS touch ${TESTFILE}_after3 && \
627 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
632 $SHOW_QUOTA_INFO_USER
633 $SHOW_QUOTA_INFO_GROUP
635 echo " Unlink files to stop timer"
636 find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
640 $RUNAS touch ${TESTFILE}_xxx || \
641 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
646 rm -f ${TESTFILE}_xxx
650 # file soft limit (start timer, timer goes off, stop timer)
651 test_4a() { # was test_4
653 chmod 0777 $DIR/$tdir
654 LIMIT=$(($IUNIT_SZ * 10)) # 10 iunits on mds
655 TESTFILE=$DIR/$tdir/$tfile-0
659 echo " User quota (soft limit: $LIMIT files grace: $GRACE seconds)"
660 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
661 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
662 quota_show_check f u $TSTUSR
664 test_file_soft $TESTFILE $LIMIT $GRACE
665 resetquota -u $TSTUSR
667 echo " Group quota (soft limit: $LIMIT files grace: $GRACE seconds)"
668 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
669 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
670 quota_show_check f g $TSTUSR
671 TESTFILE=$DIR/$tdir/$tfile-1
673 test_file_soft $TESTFILE $LIMIT $GRACE
674 resetquota -g $TSTUSR
677 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
678 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
680 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
682 test_4b() { # was test_4a
688 GR_STR6="1111111111111111"
690 wait_delete_completed
692 # test of valid grace strings handling
693 echo " Valid grace strings test"
694 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
695 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
696 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
697 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
699 # test of invalid grace strings handling
700 echo " Invalid grace strings test"
701 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
702 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
705 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
706 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
708 run_test_with_stat 4b "Grace time strings handling ==="
710 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
713 BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
714 ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
716 wait_delete_completed
718 echo " Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
719 $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
720 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
721 quota_show_check a u $TSTUSR
722 quota_show_check a g $TSTUSR
724 echo " Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
725 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
726 error "touch failure, expect success"
727 dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
729 echo " Chown files to $TSTUSR.$TSTUSR ..."
730 for i in `seq 0 $ILIMIT`; do
731 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
732 quota_error a $TSTUSR "chown failure, but expect success"
736 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
739 resetquota -u $TSTUSR
740 resetquota -g $TSTUSR
742 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
744 # block quota acquire & release
746 if [ $OSTCOUNT -lt 2 ]; then
747 skip_env "$OSTCOUNT < 2, too few osts"
751 wait_delete_completed
754 chmod 0777 $DIR/$tdir
756 LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
757 FILEA="$DIR/$tdir/$tfile-0_a"
758 FILEB="$DIR/$tdir/$tfile-0_b"
760 echo " Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
761 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
762 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
763 quota_show_check b u $TSTUSR
764 quota_show_check b g $TSTUSR
766 echo " Create filea on OST0 and fileb on OST1"
767 $LFS setstripe $FILEA -i 0 -c 1
768 $LFS setstripe $FILEB -i 1 -c 1
769 chown $TSTUSR.$TSTUSR $FILEA
770 chown $TSTUSR.$TSTUSR $FILEB
772 echo " Exceed quota limit ..."
773 RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
774 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
775 quota_error a $TSTUSR "write filea failure, but expect success"
780 $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
781 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
783 echo " Write to OST1 return EDQUOT"
784 # this write maybe cache write, ignore it's failure
785 RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
786 $RUNDD count=$(($BUNIT_SZ * 2)) || true
790 $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
791 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
793 echo " Remove filea to let OST0 release quota"
796 if at_is_enabled; then
797 timeout=$(at_max_get mds)
799 timeout=$(lctl get_param -n timeout)
801 count=$((timeout / 5))
802 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
804 while [ $((count--)) -gt 0 ]; do
807 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
808 if [ -z $OST0_QUOTA_HOLD ]; then
809 error "System is error when query quota for block (U:$TSTUSR)."
811 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
817 [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
820 while [ $((count--)) -gt 0 ]; do
823 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
824 if [ -z $OST0_QUOTA_HOLD ]; then
825 error "System is error when query quota for block (G:$TSTUSR)."
827 [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
833 [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
836 echo " Write to OST1"
837 $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
838 quota_error a $TSTUSR "write fileb failure, expect success"
845 resetquota -u $TSTUSR
846 resetquota -g $TSTUSR
849 run_test_with_stat 6 "Block quota acquire & release ========="
851 # quota recovery (block quota only by now)
855 chmod 0777 $DIR/$tdir
857 wait_delete_completed
859 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
860 TESTFILE="$DIR/$tdir/$tfile-0"
862 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
864 $LFS setstripe $TESTFILE -c 1
865 chown $TSTUSR.$TSTUSR $TESTFILE
867 echo " Write to OST0..."
868 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
869 quota_error u $TSTUSR "write failure, but expect success"
871 #define OBD_FAIL_OBD_DQACQ 0x604
872 lustre_fail mds 0x604
873 echo " Remove files on OST0"
877 echo " Trigger recovery..."
878 OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
879 for i in $OSC0_UUID; do
880 $LCTL --device $i activate || error "activate osc failed!"
883 # sleep a while to wait for recovery done
887 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
888 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
889 [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
890 echo " total limits = $TOTAL_LIMIT"
892 OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
893 [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
894 OST0_LIMIT=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
895 [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
896 echo " limits on $OST0_UUID = $OST0_LIMIT"
899 resetquota -u $TSTUSR
901 run_test_with_stat 7 "Quota recovery (only block limit) ======"
903 # run dbench with quota enabled
906 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
909 wait_delete_completed
911 echo " Set enough high limit for user: $TSTUSR"
912 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
913 echo " Set enough high limit for group: $TSTUSR"
914 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
916 chmod 0777 $DIR/$tdir
918 [ "$SLOW" = "no" ] && duration=" -t 120"
919 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
926 run_test_with_stat 8 "Run dbench with quota enabled ==========="
928 # run for fixing bug10707, it needs a big room. test for 64bit
930 GB=$((KB * 1024 * 1024))
931 # Use this as dd bs to decrease time
932 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
933 blksize=$((1 << 21)) # 2Mb
934 size_file=$((GB * 9 / 2))
935 # this check is just for test9 and test10
936 OST0_MIN=4900000 #4.67G
937 check_whether_skip () {
938 OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
939 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
940 if [ $OST0_SIZE -lt $OST0_MIN ]; then
941 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
949 check_whether_skip && return 0
951 wait_delete_completed
957 chmod 0777 $DIR/$tdir
958 TESTFILE="$DIR/$tdir/$tfile-0"
960 BLK_LIMIT=$((100 * KB * KB)) # 100G
962 echo " Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
964 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
965 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
966 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
967 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
969 quota_show_check a u $TSTUSR
970 quota_show_check a g $TSTUSR
973 $LFS setstripe $TESTFILE -c 1
975 chown $TSTUSR.$TSTUSR $TESTFILE
977 log " Write the big file of 4.5G ..."
978 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
979 quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
984 log " delete the big file of 4.5G..."
985 $RUNAS rm -f $TESTFILE
993 set_blk_unitsz $((128 * 1024))
994 set_blk_tunesz $((128 * 1024 / 2))
998 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
1000 # run for fixing bug10707, it need a big room. test for 32bit
1003 chmod 0777 $DIR/$tdir
1004 check_whether_skip && return 0
1006 wait_delete_completed
1011 # make qd_count 32 bit
1012 lustre_fail mds_ost 0xA00
1014 TESTFILE="$DIR/$tdir/$tfile-0"
1016 BLK_LIMIT=$((100 * KB * KB)) # 100G
1019 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1020 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1021 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1022 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1024 quota_show_check a u $TSTUSR
1025 quota_show_check a g $TSTUSR
1028 $LFS setstripe $TESTFILE -c 1
1030 chown $TSTUSR.$TSTUSR $TESTFILE
1032 log " Write the big file of 4.5 G ..."
1033 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$blksize count=$((size_file / blksize)) || \
1034 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1039 log " delete the big file of 4.5 G..."
1040 $RUNAS rm -f $TESTFILE
1041 sync; sleep 3; sync;
1048 # make qd_count 64 bit
1049 lustre_fail mds_ost 0
1051 set_blk_unitsz $((128 * 1024))
1052 set_blk_tunesz $((128 * 1024 / 2))
1056 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1059 wait_delete_completed
1062 block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1064 orig_dbr=`sysctl -n vm.dirty_background_ratio`
1065 orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1066 orig_dr=`sysctl -n vm.dirty_ratio`
1067 orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1068 sysctl -w vm.dirty_background_ratio=1
1069 sysctl -w vm.dirty_expire_centisecs=30
1070 sysctl -w vm.dirty_ratio=1
1071 sysctl -w vm.dirty_writeback_centisecs=50
1072 TESTDIR="$DIR/$tdir"
1078 [ "$SLOW" = no ] && REPS=1
1081 while [ $i -le $REPS ]; do
1082 echo "test: cycle($i of $REPS) start at $(date)"
1083 mkdir -p $TESTDIR && chmod 777 $TESTDIR
1084 echo -n " create a file for uid "
1085 for j in `seq 1 30`; do
1087 # 30MB per dd for a total of 900MB (if space even permits)
1088 runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile bs=$blksize count=15 > /dev/null 2>&1 &
1091 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1093 while [ $PROCS -gt 0 ]; do
1095 SECS=$((SECS + sleep))
1096 PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1097 USED=$(du -s $TESTDIR | awk '{print $1}')
1098 PCT=$(($USED * 100 / $block_limit))
1099 echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS} "
1100 if [ $USED -le $LAST_USED ]; then
1101 kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1108 echo " removing the test files..."
1109 rm -f $TESTDIR/$tfile
1110 echo "cycle $i done at $(date)"
1113 echo "Test took $SECS sec"
1116 sysctl -w vm.dirty_background_ratio=$orig_dbr
1117 sysctl -w vm.dirty_expire_centisecs=$orig_dec
1118 sysctl -w vm.dirty_ratio=$orig_dr
1119 sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1120 if [ $RV -ne 0 ]; then
1121 error "Nothing was written for $SECS sec ... aborting"
1125 run_test_with_stat 11 "run for fixing bug10912 ==========="
1127 # test multiple clients write block quota b=11693
1130 wait_delete_completed
1132 # one OST * 10 + (mds + other OSTs)
1133 LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1134 TESTFILE="$DIR/$tdir/$tfile"
1136 echo " User quota (limit: $LIMIT kbytes)"
1137 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1138 quota_show_check b u $TSTUSR
1140 $LFS setstripe $TESTFILE -i 0 -c 1
1141 chown $TSTUSR.$TSTUSR $TESTFILE
1142 $LFS setstripe $TESTFILE.2 -i 0 -c 1
1143 chown $TSTUSR.$TSTUSR $TESTFILE.2
1145 echo " step1: write out of block quota ..."
1146 # one bunit will give mds
1147 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1149 $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1152 echo " step2: testing ......"
1155 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1157 if [ $count -gt 64 ]; then
1158 quota_error u $TSTUSR "dd should be finished!"
1162 echo "(dd_pid=$DDPID, time=$count)successful"
1166 if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1168 if [ $count -gt 64 ]; then
1169 quota_error u $TSTUSR "dd should be finished!"
1173 echo "(dd_pid=$DDPID1, time=$count)successful"
1175 sync; sleep 5; sync;
1177 echo " step3: checking ......"
1178 fz=`stat -c %s $TESTFILE`
1179 fz2=`stat -c %s $TESTFILE.2`
1181 [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1182 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1184 rm -f $TESTFILE $TESTFILE.2
1185 sync; sleep 3; sync;
1187 resetquota -u $TSTUSR
1189 run_test_with_stat 13 "test multiple clients write block quota ==="
1191 check_if_quota_zero(){
1192 line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1193 for i in `seq 3 $line`; do
1194 if [ $i -eq 3 ]; then
1200 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1201 awk '{print $'"$j"'}'`
1202 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1203 error "quota on $2 isn't clean"
1206 echo "pass check_if_quota_zero"
1209 test_14a() { # was test_14 b=12223 -- setting quota on root
1210 TESTFILE="$DIR/$tdir/$tfile"
1214 cleanup_and_setup_lustre
1219 # out of root's file and block quota
1220 $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1221 createmany -m ${TESTFILE} 20 || \
1222 quota_error u root "unexpected: user(root) create files failly!"
1223 multiop ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1224 quota_error u root "unexpected: user(root) write files failly!"
1226 $RUNAS multiop ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1227 quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1231 for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1232 for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1235 dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1237 #check_if_quota_zero u root
1240 unlinkmany ${TESTFILE} 15
1242 sync; sleep 3; sync;
1244 run_test_with_stat 14a "test setting quota on root ==="
1247 LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1248 PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1250 wait_delete_completed
1252 # force using the latest version in case 14b was omitted
1253 $LFS quotaoff -ug $DIR
1254 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1255 $LFS quotacheck -ug $DIR || error "quotacheck failed"
1258 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1259 TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1260 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1261 echo " (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1262 resetquota -u $TSTUSR
1265 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1266 TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1267 [ $TOTAL_LIMIT -eq $LIMIT ] || error " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1268 echo " (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1270 resetquota -g $TSTUSR
1273 local lustre_version=$(get_lustre_version mds)
1274 if [[ $lustre_version != 1.8* ]]; then
1275 echo mds running $lustre_version, skip quota v1 testing
1279 quota_save_version "ug1"
1281 echo "Testing that >4GB quota limits fail on volume with quota v1"
1282 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1286 run_test_with_stat 15 "set block quota more than 4T ==="
1288 # $1=u/g $2=with qunit adjust or not
1290 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1291 TESTFILE="$DIR/$tdir/$tfile"
1294 wait_delete_completed
1296 echo " User quota (limit: $LIMIT kbytes)"
1297 if [ $1 == "u" ]; then
1298 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1299 quota_show_check b u $TSTUSR
1301 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1302 quota_show_check b g $TSTUSR
1305 $LFS setstripe $TESTFILE -c 1
1306 chown $TSTUSR.$TSTUSR $TESTFILE
1309 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1310 quota_error a $TSTUSR "(usr) write failure, but expect success"
1312 echo " Write out of block quota ..."
1313 # this time maybe cache write, ignore it's failure
1314 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1315 # flush cache, ensure noquota flag is setted on client
1316 cancel_lru_locks osc
1317 if [ $2 -eq 1 ]; then
1318 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1319 quota_error a $TSTUSR "(write failure, but expect success"
1321 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1322 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1326 sync; sleep 3; sync;
1327 resetquota -$1 $TSTUSR
1330 # test without adjusting qunit
1333 # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1334 local lustre_version=$(get_lustre_version mds)
1335 if [[ $lustre_version != 1.8* ]]; then
1336 skip mds running $lustre_version, WITHOUT_CHANGE_QS is not supported
1340 set_blk_tunesz $((BUNIT_SZ * 2))
1341 set_blk_unitsz $((BUNIT_SZ * 4))
1344 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS 0xA01
1345 echo " grp/usr: $i, adjust qunit: $j"
1346 echo "-------------------------------"
1347 [ $j -eq 1 ] && lustre_fail mds_ost 0
1348 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1352 set_blk_unitsz $((128 * 1024))
1353 set_blk_tunesz $((128 * 1024 / 2))
1355 run_test_with_stat 16 "test without adjusting qunit"
1357 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1362 wait_delete_completed
1364 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1365 lustre_fail ost 0x80000A02
1367 TESTFILE="$DIR/$tdir/$tfile-a"
1368 TESTFILE2="$DIR/$tdir/$tfile-b"
1371 BLK_LIMIT=$((100 * 1024)) # 100M
1373 log " Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1374 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1375 log " Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1376 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1378 quota_show_check b u $TSTUSR
1379 quota_show_check b g $TSTUSR
1382 chown $TSTUSR.$TSTUSR $TESTFILE
1384 chown $TSTUSR.$TSTUSR $TESTFILE2
1386 log " Write the test file1 ..."
1387 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
1388 || quota_error a $TSTUSR "write 10M file failure"
1393 log " write the test file2 ..."
1394 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=$(( 10 * 1024 )) \
1395 || quota_error a $TSTUSR "write 10M file failure"
1400 rm -f $TESTFILE $TESTFILE2
1402 sync; sleep 3; sync;
1404 # make qd_count 64 bit
1407 set_blk_unitsz $((128 * 1024))
1408 set_blk_tunesz $((128 * 1024 / 2))
1410 resetquota -u $TSTUSR
1411 resetquota -g $TSTUSR
1415 run_test_with_stat 17 "run for fixing bug14526 ==========="
1417 # test when mds takes a long time to handle a quota req so that
1418 # the ost has dropped it, the ost still could work well b=14840
1420 LIMIT=$((100 * 1024 * 1024)) # 100G
1421 TESTFILE="$DIR/$tdir/$tfile"
1424 wait_delete_completed
1429 log " User quota (limit: $LIMIT kbytes)"
1430 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1431 quota_show_check b u $TSTUSR
1433 $LFS setstripe $TESTFILE -i 0 -c 1
1434 chown $TSTUSR.$TSTUSR $TESTFILE
1436 #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ 0x13c
1437 lustre_fail mds 0x13c
1439 log " step1: write 100M block ..."
1440 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1446 echo " step2: testing ......"
1448 if at_is_enabled; then
1449 timeout=$(at_max_get mds)
1451 timeout=$(lctl get_param -n timeout)
1454 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1456 if [ $count -gt $((4 * $timeout)) ]; then
1457 quota_error u $TSTUSR "count=$count dd should be finished!"
1461 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1463 cancel_lru_locks mdc
1464 cancel_lru_locks osc
1466 testfile_size=$(stat -c %s $TESTFILE)
1467 [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1468 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1473 resetquota -u $TSTUSR
1474 set_blk_unitsz $((128 * 1024))
1475 set_blk_tunesz $((128 * 1024 / 2))
1477 run_test_with_stat 18 "run for fixing bug14840 ==========="
1479 # test when mds drops a quota req, the ost still could work well b=14840
1481 LIMIT=$((100 * 1024 * 1024)) # 100G
1482 TESTFILE="$DIR/$tdir/$tfile-a"
1485 wait_delete_completed
1490 log " User quota (limit: $LIMIT kbytes)"
1491 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1492 quota_show_check b u $TSTUSR
1494 $LFS setstripe $TESTFILE -i 0 -c 1
1495 chown $TSTUSR.$TSTUSR $TESTFILE
1497 #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE 0x8000013d
1498 lustre_fail mds 0x8000013d
1500 log " step1: write 100M block ..."
1501 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1504 echo " step2: testing ......"
1506 if at_is_enabled; then
1507 timeout=$(at_max_get mds)
1509 timeout=$(lctl get_param -n timeout)
1512 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1514 if [ $count -gt $((3 * $timeout)) ]; then
1516 quota_error u $TSTUSR "count=$count dd should be finished!"
1520 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1526 resetquota -u $TSTUSR
1527 set_blk_unitsz $((128 * 1024))
1528 set_blk_tunesz $((128 * 1024 / 2))
1530 run_test_with_stat 18a "run for fixing bug14840 ==========="
1532 # test when mds do failover, the ost still could work well without trigger
1537 LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1538 TESTFILE="$DIR/$tdir/$tfile"
1541 wait_delete_completed
1546 log " User quota (limit: $LIMIT kbytes)"
1547 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1548 quota_show_check b u $TSTUSR
1550 $LFS setstripe $TESTFILE -i 0 -c 1
1551 chown $TSTUSR.$TSTUSR $TESTFILE
1553 timeout=$(sysctl -n lustre.timeout)
1555 if [ $type = "directio" ]; then
1556 log " write 100M block(directio) ..."
1557 $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1559 log " write 100M block(normal) ..."
1560 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1564 do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=ug"
1568 log "failing mds for $((2 * timeout)) seconds"
1569 fail mds $((2 * timeout))
1571 # check if quotaon successful
1572 $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1573 if [ $? -eq 0 ]; then
1575 error "quotaon failed!"
1580 if at_is_enabled; then
1581 timeout=$(at_max_get mds)
1583 timeout=$(lctl get_param -n timeout)
1586 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1587 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1588 log "it took $count second"
1592 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1594 cancel_lru_locks mdc
1595 cancel_lru_locks osc
1598 resetquota -u $TSTUSR
1599 set_blk_unitsz $((128 * 1024))
1600 set_blk_tunesz $((128 * 1024 / 2))
1601 testfile_size=$(stat -c %s $TESTFILE)
1602 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1604 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1609 # test when mds does failover, the ost still could work well
1610 # this test shouldn't trigger watchdog b=14840
1612 test_18bc_sub normal
1613 test_18bc_sub directio
1614 # check if watchdog is triggered
1615 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1616 watchdog=`awk '/test 18b/ {start = 1;}
1617 /Service thread pid/ && /was inactive/{
1621 }' $TMP/lustre-log-${TESTNAME}.log`
1622 [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1623 rm -f $TMP/lustre-log-${TESTNAME}.log
1625 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1627 # test when mds does failover, the ost still could work well
1628 # this test will prevent OST_DISCONNET from happening b=14840
1630 # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1631 lustre_fail ost 0x202
1632 test_18bc_sub normal
1633 test_18bc_sub directio
1636 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1638 run_to_block_limit() {
1639 local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1641 wait_delete_completed
1643 # set 1 Mb quota unit size
1647 # bind file to a single OST
1648 $LFS setstripe -c 1 $TESTFILE
1649 chown $TSTUSR.$TSTUSR $TESTFILE
1651 echo " User quota (limit: $LIMIT kbytes)"
1652 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1653 quota_show_check b u $TSTUSR
1654 echo " Updating quota limits"
1655 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1656 quota_show_check b u $TSTUSR
1658 RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1659 $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1660 # for now page cache of TESTFILE may still be dirty,
1661 # let's push it to the corresponding OST, this will also
1662 # cache NOQUOTA on the client from OST's reply
1663 cancel_lru_locks osc
1664 $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1668 # 1 Mb bunit per each MDS/OSS
1669 local TESTFILE="$DIR/$tdir/$tfile"
1672 run_to_block_limit $TESTFILE
1677 resetquota -u $TSTUSR
1679 set_blk_unitsz $((128 * 1024))
1680 set_blk_tunesz $((128 * 1024 / 2))
1683 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1687 LSTR=(1t 2g 3m 4k) # limits strings
1688 LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1690 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1691 $MOUNT || error "could not set quota limits"
1693 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1694 --inode-softlimit ${LSTR[2]} \
1695 --inode-hardlimit ${LSTR[3]} \
1696 $MOUNT || error "could not set quota limits"
1698 [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1699 [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1700 [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1701 [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1703 resetquota -u $TSTUSR
1705 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1712 time=$(($(date +%s) + seconds))
1713 while [ $(date +%s) -lt $time ]; do
1714 $RUNAS dd if=/dev/zero of=$testfile bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1719 # run for fixing bug16053, setquota shouldn't fail when writing and
1720 # deleting are happening
1725 wait_delete_completed
1727 TESTFILE="$DIR/$tdir/$tfile"
1729 BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1732 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1733 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1734 log " Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1735 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1737 # repeat writing on a 1M file
1738 test_21_sub ${TESTFILE}_1 1024 30 &
1740 # repeat writing on a 128M file
1741 test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1744 time=$(($(date +%s) + 30))
1746 while [ $(date +%s) -lt $time ]; do
1747 log " Set quota for $i times"
1748 $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1749 $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1756 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1758 if [ $count -gt 60 ]; then
1759 quota_error a $TSTUSR "dd should be finished!"
1763 echo "(dd_pid=$DDPID1, time=$count)successful"
1767 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1769 if [ $count -gt 60 ]; then
1770 quota_error a $TSTUSR "dd should be finished!"
1774 echo "(dd_pid=$DDPID2, time=$count)successful"
1776 set_blk_unitsz $((128 * 1024))
1777 set_blk_tunesz $((128 * 1024 / 2))
1778 resetquota -u $TSTUSR
1779 resetquota -g $TSTUSR
1783 run_test_with_stat 21 "run for fixing bug16053 ==========="
1786 local lustre_version=$(get_lustre_version mds)
1787 if [[ $lustre_version != 1.8* ]] ; then
1788 skip mds running $lustre_version, skip quota v1 testing
1791 quota_save_version "ug1"
1797 echo "checking parameters"
1799 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1800 do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1802 run_test 0 "reboot lustre"
1804 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1808 chmod 0777 $DIR/$tdir
1809 TESTFILE="$DIR/$tdir/$tfile-0"
1811 local bs_unit=$((1024*1024))
1814 wait_delete_completed
1817 log " User quota (limit: $LIMIT kbytes)"
1818 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1820 quota_show_check b u $TSTUSR
1822 $LFS setstripe $TESTFILE -c 1
1823 chown $TSTUSR.$TSTUSR $TESTFILE
1825 log " Step1: trigger quota with 0_DIRECT"
1826 log " Write half of file"
1827 $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1828 log " Write out of block quota ..."
1829 $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1832 log " Step2: rewrite should succeed"
1833 $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1837 wait_delete_completed
1838 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1839 OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1840 echo $OST0_QUOTA_USED
1841 [ $OST0_QUOTA_USED -ne 0 ] && \
1842 ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1844 resetquota -u $TSTUSR
1848 log "run for $((OSTCOUNT * 3))MB test file"
1849 test_23_sub $((OSTCOUNT * 3 * 1024))
1852 check_whether_skip && return 0
1853 log "run for $((OSTCOUNT * 30))MB test file"
1854 test_23_sub $((OSTCOUNT * 30 * 1024))
1856 run_test_with_stat 23 "run for fixing bug16125 ==========="
1859 local TESTFILE="$DIR/$tdir/$tfile"
1862 run_to_block_limit $TESTFILE
1863 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1867 resetquota -u $TSTUSR
1869 set_blk_unitsz $((128 * 1024))
1870 set_blk_tunesz $((128 * 1024 / 2))
1872 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1875 if [ $1 = "-u" ]; then
1876 if [ $2 = "$TSTUSR" ]; then
1882 if [ $2 = "$TSTUSR" ]; then
1892 chmod 0777 $DIR/$tdir
1893 TESTFILE="$DIR/$tdir/$tfile-0"
1895 LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1897 wait_delete_completed
1899 # set quota for $TSTUSR
1900 log "setquota for $TSTUSR"
1901 $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1903 if [ "$1" == "-u" ]; then
1904 quota_show_check a u $TSTUSR
1906 quota_show_check a g $TSTUSR
1909 # set quota for $TSTUSR2
1910 log "setquota for $TSTUSR2"
1911 $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1913 if [ "$1" == "-u" ]; then
1914 quota_show_check a u $TSTUSR2
1916 quota_show_check a g $TSTUSR2
1919 # set stripe index to 0
1920 log "setstripe for $DIR/$tdir to 0"
1921 $LFS setstripe $DIR/$tdir -c 1 -i 0
1924 local dev=$(get_mds_mdt_device_proc_path)
1925 MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
1926 OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1928 MDS_QUOTA_USED_OLD=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1929 OST0_QUOTA_USED_OLD=`getquota $1 $TSTUSR $OST0_UUID curspace`
1930 MDS_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1931 OST0_QUOTA_USED2_OLD=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1934 log "$TSTUSR write 4M to $TESTFILE"
1935 $RUNAS dd if=/dev/zero of=$TESTFILE bs=4K count=1K || quota_error a $TSTUSR "dd failed"
1937 show_quota $1 $TSTUSR
1938 show_quota $1 $TSTUSR2
1939 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1940 [ $MDS_QUOTA_USED_NEW -ne $((MDS_QUOTA_USED_OLD + 1)) ] && \
1941 quota_error a $TSTUSR "$TSTUSR inode quota usage error: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1942 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1943 OST0_QUOTA_USED_DELTA=$((OST0_QUOTA_USED_NEW - OST0_QUOTA_USED_OLD))
1944 [ $OST0_QUOTA_USED_DELTA -lt 4096 ] && \
1945 quota_error a $TSTUSR "$TSTUSR block quota usage error: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1947 # chown/chgrp from $TSTUSR to $TSTUSR2
1948 if [ $1 = "-u" ]; then
1949 log "chown from $TSTUSR to $TSTUSR2"
1950 chown $TSTUSR2 $TESTFILE || quota_error u $TSTUSR2 "chown failed"
1952 log "chgrp from $TSTUSR to $TSTUSR2"
1953 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1956 show_quota $1 $TSTUSR
1957 show_quota $1 $TSTUSR2
1958 MDS_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $MDS_UUID curinodes`
1959 [ $MDS_QUOTA_USED2_NEW -ne $((MDS_QUOTA_USED2_OLD + 1)) ] && \
1960 quota_error a $TSTUSR2 "$TSTUSR2 inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED2_OLD|$MDS_QUOTA_USED2_NEW]"
1961 OST0_QUOTA_USED2_NEW=`getquota $1 $TSTUSR2 $OST0_UUID curspace`
1962 # when chown, the quota on ost could be displayed out of quota temporarily. Delete the '*' in this situation. b=20433
1963 OST0_QUOTA_USED2_NEW=${OST0_QUOTA_USED2_NEW%\*}
1964 OST0_QUOTA_USED2_DELTA=$((OST0_QUOTA_USED2_NEW - OST0_QUOTA_USED2_OLD))
1965 [ $OST0_QUOTA_USED2_DELTA -ne $OST0_QUOTA_USED_DELTA ] && \
1966 quota_error a $TSTUSR2 "$TSTUSR2 block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED2_OLD|$OST0_QUOTA_USED2_NEW]"
1967 MDS_QUOTA_USED_NEW=`getquota $1 $TSTUSR $MDS_UUID curinodes`
1968 [ $MDS_QUOTA_USED_NEW -ne $MDS_QUOTA_USED_OLD ] && \
1969 quota_error a $TSTUSR "$TSTUSR inode quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$MDS_QUOTA_USED_OLD|$MDS_QUOTA_USED_NEW]"
1970 OST0_QUOTA_USED_NEW=`getquota $1 $TSTUSR $OST0_UUID curspace`
1971 [ $OST0_QUOTA_USED_NEW -ne $OST0_QUOTA_USED_OLD ] && \
1972 quota_error a $TSTUSR "$TSTUSR block quota usage transfer from $TSTUSR to $TSTUSR2 failed: [$OST0_QUOTA_USED_OLD|$OST0_QUOTA_USED_NEW]"
1975 wait_delete_completed
1976 resetquota $1 $TSTUSR
1977 resetquota $1 $TSTUSR2
1981 log "run for chown case"
1984 log "run for chgrp case"
1987 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1991 chmod 0777 $DIR/$tdir
1992 TESTFILE="$DIR/$tdir/$tfile-0"
1993 TESTFILE2="$DIR/$tdir/$tfile-1"
1997 wait_delete_completed
1999 # every quota slave gets 20MB
2000 b_limit=$((OSTCOUNT * 20 * 1024))
2001 log "limit: ${b_limit}KB"
2002 $LFS setquota -u $TSTUSR -b 0 -B $b_limit -i 0 -I 0 $DIR
2004 quota_show_check b u $TSTUSR
2006 $LFS setstripe $TESTFILE -c 1 -i 0
2007 $LFS setstripe $TESTFILE2 -c 1 -i 0
2008 chown $TSTUSR.$TSTUSR $TESTFILE
2009 chown $TSTUSR.$TSTUSR $TESTFILE2
2011 #define OBD_FAIL_QUOTA_DELAY_REL 0xA03
2012 lustre_fail ost 0xA03
2014 log " Write the first file..."
2015 $RUNAS $DIRECTIO write $TESTFILE 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2016 log " Delete the first file..."
2020 wait_delete_completed
2022 log " Write the second file..."
2023 $RUNAS $DIRECTIO write $TESTFILE2 0 10 $((BLK_SZ * 1024)) || quota_error u $TSTUSR "write failure, but expect success"
2024 log " Delete the second file..."
2028 set_blk_unitsz $((128 * 1024))
2029 set_blk_tunesz $((128 * 1024 / 2))
2030 resetquota -u $TSTUSR
2032 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2035 $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2036 $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed"
2039 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2042 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2043 error "lfs setquota failed with uid argument"
2044 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR || \
2045 error "lfs stequota failed with gid argument"
2046 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2047 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2048 resetquota -u $TSTUSR
2049 resetquota -g $TSTUSR
2052 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2055 BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2056 echo "Step 1: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2057 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2060 echo "Step 2: reset system ..."
2061 cleanup_and_setup_lustre
2064 echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2068 wait_delete_completed
2070 #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2071 lustre_fail ost 0x80000A02
2073 TESTFILE="$DIR/$tdir/$tfile"
2076 BLK_LIMIT=$((100 * 1024)) # 100M
2077 echo "Step 4: set enough high limit for user [$TSTUSR:$BLK_LIMIT]"
2078 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
2082 chown $TSTUSR.$TSTUSR $TESTFILE
2084 echo "Step 5: write the test file1 [10M] ..."
2085 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(( 10 * 1024 )) \
2086 || quota_error a $TSTUSR "write 10M file failure"
2090 sync; sleep 3; sync;
2092 # make qd_count 64 bit
2095 set_blk_unitsz $((128 * 1024))
2096 set_blk_tunesz $((128 * 1024 / 2))
2098 resetquota -u $TSTUSR
2100 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2105 # flush AT history, enforce at_max immediately
2106 do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2114 local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2115 local newtimeo=10 # the default ptlrpc AT value
2119 if at_is_enabled; then
2120 oldtimeo=$(at_max_get client)
2121 at_max_enforce $newtimeo
2123 oldtimeo=$(lctl get_param -n timeout)
2124 lctl set_param timeout=$newtimeo
2127 #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2128 lustre_fail mds 0x12e
2130 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2132 # 1.25 * at_max + 5 + net_latency
2133 echo "sleeping for $((newtimeo * 9 / 4 + 5)) seconds"
2134 sleep $((newtimeo * 9 / 4 + 5))
2135 ps -p $pid && error "lfs hadn't finished by timeout"
2136 wait $pid && error "succeeded, but should have failed"
2140 if at_is_enabled; then
2141 at_max_enforce $oldtimeo
2143 lctl set_param timeout=$oldtimeo
2146 resetquota -u $TSTUSR
2148 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2154 local TESTFILE="$DIR/$tdir/$tfile"
2161 chmod 0777 $DIR/$tdir
2163 $LFS setstripe $TESTFILE -i 0 -c 1
2164 chown $TSTUSR.$TSTUSR $TESTFILE
2166 $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
2167 $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
2168 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1024 count=$((LIMIT * 2)) || true
2169 cancel_lru_locks osc
2171 $LFS setquota -u $TSTUSR -B 0 $DIR
2172 # over-quota flag has not yet settled since we do not trigger async events
2173 # based on grace time period expiration
2175 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 || true
2176 cancel_lru_locks osc
2177 # now over-quota flag should be settled and further writes should fail
2179 $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2181 resetquota -u $TSTUSR
2182 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2184 set_blk_unitsz $((128 * 1024))
2185 set_blk_tunesz $((128 * 1024 / 2))
2187 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2189 # test duplicate quota releases b=18630
2192 chmod 0777 $DIR/$tdir
2194 LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2195 TESTFILE="$DIR/$tdir/$tfile-0"
2196 TESTFILE2="$DIR/$tdir/$tfile-1"
2198 wait_delete_completed
2200 log " User quota (limit: $LIMIT kbytes)"
2201 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2203 $LFS setstripe $TESTFILE -i 0 -c 1
2204 chown $TSTUSR.$TSTUSR $TESTFILE
2205 $LFS setstripe $TESTFILE2 -i 0 -c 1
2206 chown $TSTUSR.$TSTUSR $TESTFILE2
2208 log " step1: write out of block quota ..."
2209 $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=5120
2210 $RUNAS dd if=/dev/zero of=$TESTFILE2 bs=$BLK_SZ count=5120
2212 #define OBD_FAIL_QUOTA_DELAY_SD 0xA04
2213 #define OBD_FAIL_SOME 0x10000000 /* fail N times */
2214 lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2216 log " step2: delete two files so that triggering duplicate quota release ..."
2217 rm -f $TESTFILE $TESTFILE2
2218 sync; sleep 5; sync # OBD_FAIL_QUOTA_DELAY_SD will delay for 5 seconds
2219 wait_delete_completed
2221 log " step3: verify if the ost failed"
2222 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
2223 watchdog=`awk '/test 31/ {start = 1;}
2224 /release quota error/ {
2228 }' $TMP/lustre-log-${TESTNAME}.log`
2229 [ "$watchdog" ] && error "$watchdog"
2230 rm -f $TMP/lustre-log-${TESTNAME}.log
2233 resetquota -u $TSTUSR
2235 run_test_with_stat 31 "test duplicate quota releases ==="
2237 # check hash_cur_bits
2238 check_quota_hash_cur_bits() {
2241 # check quota_hash_cur_bits on all obdfilters
2242 for num in `seq $OSTCOUNT`; do
2243 cb=`do_facet ost$num "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2244 if [ $cb -gt $bits ]; then
2245 echo "hash_lqs_cur_bits of ost$num is too large(cur_bits=$cb)"
2249 # check quota_hash_cur_bits on mds
2250 cb=`do_facet mds "cat /sys/module/lquota/parameters/hash_lqs_cur_bits"`
2251 if [ $cb -gt $bits ]; then
2252 echo "hash_lqs_cur_bits of mds is too large(cur_bits=$cb)"
2260 # check distribution of all obdfilters
2261 for num in `seq $OSTCOUNT`; do
2262 do_facet ost$num "lctl get_param obdfilter.${FSNAME}-OST*.hash_stats | grep LQS_HASH" | while read line; do
2263 rehash_count=`echo $line | awk '{print $9}'`
2264 if [ $rehash_count -eq 0 ]; then
2265 echo -e "ost$num:\n $line"
2266 error "Rehearsh didn't happen"
2270 # check distribution of mds
2271 do_facet mds "lctl get_param mds.${FSNAME}-MDT*.hash_stats | grep LQS_HASH" | while read line; do
2272 rehash_count=`echo $line | awk '{print $9}'`
2273 if [ $rehash_count -eq 0 ]; then
2274 echo -e "mdt:\n $line"
2275 error "Rehearsh didn't happen"
2282 # reset system so that quota_hash_cur_bits==3
2283 echo "Reset system ..."
2284 local LMR_orig=$LOAD_MODULES_REMOTE
2285 LOAD_MODULES_REMOTE=true
2286 cleanup_and_setup_lustre
2287 LOAD_MODULES_REMOTE=$LMR_orig
2289 for user in $SANITY_QUOTA_USERS; do
2290 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" >/dev/null 2>/dev/null || \
2291 missing_users="$missing_users $user"
2293 [ -n "$missing_users" ] && { skip_env "the following users are missing: $missing_users" ; return 0 ; }
2294 check_quota_hash_cur_bits 3 || { skip_env "hash_lqs_cur_bits isn't set properly"; return 0;}
2296 $LFS quotaoff -ug $DIR
2297 $LFS quotacheck -ug $DIR
2299 for user in $SANITY_QUOTA_USERS; do
2300 $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2305 for user in $SANITY_QUOTA_USERS; do
2309 run_test 32 "check lqs hash(bug 21846) =========================================="
2312 # run 98 at the end because of reformatall
2319 local missing_users=""
2321 for user in $SANITY_QUOTA_USERS; do
2322 check_runas_id_ret $user quota_usr "runas -u $user -g quota_usr" || \
2323 missing_users="$missing_users $user"
2325 [ -n "$missing_users" ] && { skip_env "different uid-s on client and servers, or missing users: $missing_users" ; return 0 ; }
2330 quota_set_version 1 # set version before the first quota check
2337 for user in $SANITY_QUOTA_USERS; do
2338 $LFS setquota -u $user --block-hardlimit $((2 * num + 4 * OSTCOUNT)) $DIR || error "first phase setquota failure"
2339 $LFS setstripe -c 1 $DIR/${tfile}${num} || error "single-stripe file creation failed"
2340 chown $user $DIR/${tfile}${num} || error "chown has failed"
2341 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:w$((num * 1024))c || \
2342 error "unexpected error when writing the file for $user"
2346 $LFS quotaoff -ug $DIR
2347 quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2348 $LFS quotaon -ug $DIR
2351 for user in $SANITY_QUOTA_USERS; do
2352 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w$((num * 1024))c || \
2353 error "unexpected error when appending the file for $user"
2354 runas -u $user -g quota_usr multiop $DIR/${tfile}${num} oO_WRONLY:O_DIRECT:O_APPEND:w8192c && \
2355 error "unexpected success when appending the file for $user"
2356 $LFS setquota -u $user --block-hardlimit 0 $DIR || error "second phase setquota failure"
2357 rm -rf $DIR/${tfile}${num}
2361 set_blk_unitsz $((128 * 1024))
2362 set_blk_tunesz $((128 * 1024 / 2))
2364 run_test_with_stat 98 "quotaon autoconversion ==============================="
2370 lctl set_param debug="-quota"
2374 run_test_with_stat 99 "Quota off ==============================="
2377 complete $(basename $0) $SECONDS
2378 check_and_cleanup_lustre