Whamcloud - gitweb
b=23049 t-f do_node() VERBOSE fix
[fs/lustre-release.git] / lustre / tests / sanity-quota.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # Run test by setting NOSETUP=true when ltest has setup env for us
7 set -e
8
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"
13     exit 0
14 fi
15
16 SRCDIR=`dirname $0`
17 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
18
19 ONLY=${ONLY:-"$*"}
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!
24
25 case `uname -r` in
26 2.6*) FSTYPE=${FSTYPE:-ldiskfs};;
27 *) error "unsupported kernel" ;;
28 esac
29
30 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
31         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
32
33 TMP=${TMP:-/tmp}
34
35 ORIG_PWD=${PWD}
36 TSTID=${TSTID:-60000}
37 TSTID2=${TSTID2:-60001}
38 TSTUSR=${TSTUSR:-"quota_usr"}
39 TSTUSR2=${TSTUSR2:-"quota_2usr"}
40 BLK_SZ=1024
41 BUNIT_SZ=${BUNIT_SZ:-1024}      # min block quota unit(kB)
42 IUNIT_SZ=${IUNIT_SZ:-10}        # min inode quota unit
43 MAX_DQ_TIME=604800
44 MAX_IQ_TIME=604800
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"
50
51 TRACE=${TRACE:-""}
52 LUSTRE=${LUSTRE:-`dirname $0`/..}
53 . $LUSTRE/tests/test-framework.sh
54 init_test_env $@
55 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
56 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
57
58 unset ENABLE_QUOTA
59
60 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
61 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
62
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 10 11 18b 21"
64
65 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
66
67 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
68
69 DIR=${DIR:-$MOUNT}
70 DIR2=${DIR2:-$MOUNT2}
71
72 check_and_setup_lustre
73
74 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
75 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
76
77 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
78 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
79 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
80 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
81 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
82 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
83 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
84 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
85
86 # control the time of tests
87 cycle=30
88 [ "$SLOW" = "no" ] && cycle=10
89
90 build_test_filter
91
92 eval ONLY_0=true
93 eval ONLY_99=true
94
95 # set_blk_tunables(btune_sz)
96 set_blk_tunesz() {
97         local btune=$(($1 * BLK_SZ))
98         # set btune size on all obdfilters
99         do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_btune_sz=$btune"
100         # set btune size on mds
101         do_facet mds  "lctl set_param lquota.*${FSNAME}-MDT*.quota_btune_sz=$btune"
102 }
103
104 # set_blk_unitsz(bunit_sz)
105 set_blk_unitsz() {
106         local bunit=$(($1 * BLK_SZ))
107         # set bunit size on all obdfilters
108         do_nodes $(comma_list $(osts_nodes)) "lctl set_param lquota.${FSNAME}-OST*.quota_bunit_sz=$bunit"
109         # set bunit size on mds
110         do_facet mds  "lctl set_param lquota.*${FSNAME}-MDT*.quota_bunit_sz=$bunit"
111 }
112
113 # set_file_tunesz(itune_sz)
114 set_file_tunesz() {
115         local itune=$1
116         # set itune size on mds
117         do_facet mds  "lctl set_param lquota.*${FSNAME}-MDT*.quota_itune_sz=$itune"
118 }
119
120 # set_file_unitsz(iunit_sz)
121 set_file_unitsz() {
122         local iunit=$1
123         # set iunit size on mds
124         do_facet mds  "lctl set_param lquota.*${FSNAME}-MDT*.quota_iunit_sz=$iunit"
125 }
126
127 lustre_fail() {
128         local fail_node=$1
129         local fail_loc=$2
130         local fail_val=${3:-0}
131
132         if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
133             if [ $((fail_loc & 0x10000000)) -ne 0  -a $fail_val -gt 0 ] || \
134                 [ $((fail_loc)) -eq 0 ]; then
135                 do_facet mds "lctl set_param fail_val=$fail_val"
136             fi
137             do_facet mds "lctl set_param fail_loc=$fail_loc"
138         fi
139         if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
140             for num in `seq $OSTCOUNT`; do
141                 if [ $((fail_loc & 0x10000000)) -ne 0 -a $fail_val -gt 0 ] || \
142                     [ $((fail_loc)) -eq 0 ]; then
143                     do_facet ost$num "lctl set_param fail_val=$fail_val"
144                 fi
145                 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
146             done
147         fi
148 }
149
150 RUNAS="runas -u $TSTID -g $TSTID"
151 RUNAS2="runas -u $TSTID2 -g $TSTID2"
152 FAIL_ON_ERROR=true check_runas_id $TSTID $TSTID $RUNAS
153 FAIL_ON_ERROR=true check_runas_id $TSTID2 $TSTID2 $RUNAS2
154
155 FAIL_ON_ERROR=false
156
157 run_test_with_stat() {
158         (($# != 2)) && error "the number of arguments is wrong"
159
160         do_facet mds  "lctl set_param lquota.*${FSNAME}-MDT*.stats=0" > /dev/null || true
161         for j in `seq $OSTCOUNT`; do
162             do_facet ost$j "lctl set_param lquota.${FSNAME}-OST*.stats=0" > /dev/null || true
163         done
164         run_test "$@"
165         if [ ${STAT:-"yes"} != "no" -a -z "$LAST_SKIPPED" ]; then
166             echo "statistics info begin ***************************************"
167             do_facet mds  "lctl get_param lquota.*${FSNAME}-MDT*.stats"
168             for j in `seq $OSTCOUNT`; do
169                 do_facet ost$j "lctl get_param lquota.${FSNAME}-OST*.stats"
170             done
171             echo "statistics info end   ***************************************"
172         fi
173 }
174
175 #
176 # clear quota limits for a user or a group
177 # usage: resetquota -u username
178 #        resetquota -g groupname
179
180 resetquota() {
181         [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
182         [ "$1" != "-u" -a "$1" != "-g" ] && error "resetquota: wrong specifier $1 passed"
183
184         count=0
185         if at_is_enabled; then
186             timeout=$(at_max_get mds)
187         else
188             timeout=$(lctl get_param -n timeout)
189         fi
190
191         while [ $((count++)) -lt $timeout ]; do
192                 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT
193                 RC=$?
194                 if [ $RC -ne 0 ]; then
195                         if [ $RC -eq 240 ]; then # 240 means -EBUSY
196                                 log "resetquota is blocked for quota master recovery, retry after 1 sec"
197                                 sleep 1
198                                 continue
199                         else
200                                 error "resetquota failed: $RC"
201                         fi
202                 fi
203                 break
204         done
205
206         [ $count -lt $timeout ] || error "resetquota timeout: $timeout"
207 }
208
209 quota_scan() {
210         LOCAL_UG=$1
211         LOCAL_ID=$2
212
213         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
214                 log "Files for user ($LOCAL_ID):"
215                 ($LFS find -user $LOCAL_ID $DIR | xargs stat 2>/dev/null)
216         fi
217
218         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
219                 log "Files for group ($LOCAL_ID):"
220                 ($LFS find -group $LOCAL_ID $DIR | xargs stat 2>/dev/null)
221         fi
222 }
223
224 quota_error() {
225         quota_scan $1 $2
226         shift 2
227         error "$*"
228 }
229
230 quota_log() {
231         quota_scan $1 $2
232         shift 2
233         log "$*"
234 }
235
236 #
237 # get quota info for a user or a group
238 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
239 #
240 getquota() {
241         local spec
242         local uuid
243
244         [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
245         [ "$1" != "-u" -a "$1" != "-g" ] && error "getquota: wrong u/g specifier $1 passed"
246
247         uuid="$3"
248
249         case $4 in
250                 curspace)   spec=1;;
251                 bsoftlimit) spec=2;;
252                 bhardlimit) spec=3;;
253                 bgrace)     spec=4;;
254                 curinodes)  spec=5;;
255                 isoftlimit) spec=6;;
256                 ihardlimit) spec=7;;
257                 igrace)     spec=8;;
258                 *)          error "unknown quota parameter $4";;
259         esac
260
261         [ "$uuid" = "global" ] && uuid=$DIR
262
263         $LFS quota -v "$1" "$2" $DIR | awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") { if (NF == 1) { getline } else { num++ } ; print $num;} }'
264 }
265
266 quota_show_check() {
267         LOCAL_BF=$1
268         LOCAL_UG=$2
269         LOCAL_ID=$3
270         PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
271
272         $LFS quota -v -$LOCAL_UG $LOCAL_ID $DIR
273
274         if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "b" ]; then
275                 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curspace`
276                 if [ -z $USAGE ]; then
277                         quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for block ($LOCAL_UG:$LOCAL_ID)."
278                 else
279                         [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for block ($LOCAL_UG:$LOCAL_ID:$USAGE)."
280                 fi
281         fi
282
283         if [ "$LOCAL_BF" == "a" -o "$LOCAL_BF" == "f" ]; then
284                 USAGE=`getquota -$LOCAL_UG $LOCAL_ID global curinodes`
285                 if [ -z $USAGE ]; then
286                         quota_error $LOCAL_UG $LOCAL_ID "System is error when query quota for file ($LOCAL_UG:$LOCAL_ID)."
287                 else
288                         [ $USAGE -ne 0 ] && quota_log $LOCAL_UG $LOCAL_ID "System is not clean for file ($LOCAL_UG:$LOCAL_ID:$USAGE)."
289                 fi
290         fi
291 }
292
293 # set quota
294 test_0() {
295         lctl set_param debug="+quota"
296         do_facet mds "lctl set_param debug=+quota"
297         for num in `seq $OSTCOUNT`; do
298             do_facet ost$num "lctl set_param debug=+quota"
299         done
300
301         log "do the quotacheck ..."
302         $LFS quotacheck -ug $DIR
303
304         resetquota -u $TSTUSR
305         resetquota -g $TSTUSR
306 }
307 run_test_with_stat 0 "Set quota ============================="
308
309 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
310 test_1_sub() {
311         LIMIT=$1
312         mkdir -p $DIR/$tdir
313         chmod 0777 $DIR/$tdir
314         TESTFILE="$DIR/$tdir/$tfile-0"
315
316         wait_delete_completed
317
318         # test for user
319         log "  User quota (limit: $LIMIT kbytes)"
320         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
321         sleep 3
322         quota_show_check b u $TSTUSR
323
324         $LFS setstripe $TESTFILE -c 1
325         chown $TSTUSR.$TSTUSR $TESTFILE
326
327         log "    Write ..."
328         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error u $TSTUSR "(usr) write failure, but expect success"
329         log "    Done"
330         log "    Write out of block quota ..."
331         # this time maybe cache write,  ignore it's failure
332         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
333         # flush cache, ensure noquota flag is setted on client
334         cancel_lru_locks osc
335         $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"
336
337         rm -f $TESTFILE
338         sync; sleep 1; sync;
339         OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
340         OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
341         echo $OST0_QUOTA_USED
342         [ $OST0_QUOTA_USED -ne 0 ] && \
343             ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
344         $SHOW_QUOTA_USER
345         resetquota -u $TSTUSR
346
347         # test for group
348         log "--------------------------------------"
349         log "  Group quota (limit: $LIMIT kbytes)"
350         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
351         sleep 3
352         quota_show_check b g $TSTUSR
353         TESTFILE="$DIR/$tdir/$tfile-1"
354
355         $LFS setstripe $TESTFILE -c 1
356         chown $TSTUSR.$TSTUSR $TESTFILE
357
358         log "    Write ..."
359         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) || quota_error g $TSTUSR "(grp) write failure, but expect success"
360         log "    Done"
361         log "    Write out of block quota ..."
362         # this time maybe cache write, ignore it's failure
363         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$(($LIMIT/2)) seek=$(($LIMIT/2)) || true
364         cancel_lru_locks osc
365         $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"
366
367         # cleanup
368         rm -f $TESTFILE
369         sync; sleep 1; sync;
370         OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
371         OST0_QUOTA_USED=`getquota -g $TSTUSR $OST0_UUID curspace`
372         echo $OST0_QUOTA_USED
373         [ $OST0_QUOTA_USED -ne 0 ] && \
374             ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
375         $SHOW_QUOTA_GROUP
376         resetquota -g $TSTUSR
377 }
378
379 # block hard limit (normal use and out of quota)
380 test_1() {
381         for i in `seq 1 $cycle`; do
382             # define blk_qunit is between 1M and 4M
383             blk_qunit=$(( $RANDOM % 3072 + 1024 ))
384             blk_qtune=$(( $RANDOM % $blk_qunit ))
385             # other osts and mds will occupy at 1M blk quota
386             b_limit=$(( ($RANDOM - 16384) / 8 +  $OSTCOUNT * $blk_qunit * 4 ))
387             set_blk_tunesz $blk_qtune
388             set_blk_unitsz $blk_qunit
389             echo "cycle: $i(total $cycle) bunit:$blk_qunit, btune:$blk_qtune, blimit:$b_limit"
390             test_1_sub $b_limit
391             echo "=================================================="
392             set_blk_unitsz $((128 * 1024))
393             set_blk_tunesz $((128 * 1024 / 2))
394         done
395 }
396 run_test_with_stat 1 "Block hard limit (normal use and out of quota) ==="
397
398 # test for specific quota limitation, qunit, qtune $1=block_quota_limit
399 test_2_sub() {
400         LIMIT=$1
401         mkdir -p $DIR/$tdir
402         chmod 0777 $DIR/$tdir
403         TESTFILE="$DIR/$tdir/$tfile-0"
404
405         wait_delete_completed
406
407         # test for user
408         log "  User quota (limit: $LIMIT files)"
409         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
410         sleep 3
411         quota_show_check f u $TSTUSR
412
413         log "    Create $LIMIT files ..."
414         $RUNAS createmany -m ${TESTFILE} $LIMIT || \
415                 quota_error u $TSTUSR "(usr) create failure, but expect success"
416         log "    Done"
417         log "    Create out of file quota ..."
418         $RUNAS touch ${TESTFILE}_xxx && \
419                 quota_error u $TSTUSR "(usr) touch success, but expect EDQUOT"
420
421         unlinkmany ${TESTFILE} $LIMIT
422         rm -f ${TESTFILE}_xxx
423         sync; sleep 1; sync;
424
425         # interop 18 <-> 20
426         local dev=$(get_mds_mdt_device_proc_path)
427         MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
428         MDS_QUOTA_USED=`getquota -u $TSTUSR $MDS_UUID curinodes`
429
430         echo $MDS_QUOTA_USED
431         [ $MDS_QUOTA_USED -ne 0 ] && \
432             ($SHOW_QUOTA_USER; quota_error u $TSTUSR "(usr) quota deleted isn't released")
433         $SHOW_QUOTA_USER
434         resetquota -u $TSTUSR
435
436         # test for group
437         log "--------------------------------------"
438         log "  Group quota (limit: $LIMIT FILE)"
439         $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR
440         sleep 3
441         quota_show_check f g $TSTUSR
442         TESTFILE=$DIR/$tdir/$tfile-1
443
444         log "    Create $LIMIT files ..."
445         $RUNAS createmany -m ${TESTFILE} $LIMIT || \
446                 quota_error g $TSTUSR "(grp) create failure, but expect success"
447         log "    Done"
448         log "    Create out of file quota ..."
449         $RUNAS touch ${TESTFILE}_xxx && \
450                 quota_error g $TSTUSR "(grp) touch success, but expect EDQUOT"
451
452         unlinkmany ${TESTFILE} $LIMIT
453         rm -f ${TESTFILE}_xxx
454         sync; sleep 1; sync;
455
456         MDS_UUID=`do_facet mds $LCTL dl | grep -m1 " $dev " | awk '{print $((NF-1))}'`
457         MDS_QUOTA_USED=`getquota -g $TSTUSR $MDS_UUID curinodes`
458
459         echo $MDS_QUOTA_USED
460         [ $MDS_QUOTA_USED -ne 0 ] && \
461             ($SHOW_QUOTA_GROUP; quota_error g $TSTUSR "(grp) quota deleted isn't released")
462         $SHOW_QUOTA_GROUP
463         resetquota -g $TSTUSR
464 }
465
466 # file hard limit (normal use and out of quota)
467 test_2() {
468         for i in `seq 1 $cycle`; do
469             if [ $i -eq 1 ]; then
470                 ino_qunit=52
471                 ino_qtune=41
472                 i_limit=11
473             else
474                 # define ino_qunit is between 10 and 100
475                 ino_qunit=$(( $RANDOM % 90 + 10 ))
476                 ino_qtune=$(( $RANDOM % $ino_qunit ))
477                 # RANDOM's maxium is 32767
478                 i_limit=$(( $RANDOM % 990 + 10 ))
479             fi
480
481             set_file_tunesz $ino_qtune
482             set_file_unitsz $ino_qunit
483             echo "cycle: $i(total $cycle) iunit:$ino_qunit, itune:$ino_qtune, ilimit:$i_limit"
484             test_2_sub $i_limit
485             echo "=================================================="
486             set_file_unitsz 5120
487             set_file_tunesz 2560
488         done
489 }
490 run_test_with_stat 2 "File hard limit (normal use and out of quota) ==="
491
492 test_block_soft() {
493         TESTFILE=$1
494         TIMER=$(($2 * 3 / 2))
495         OFFSET=0
496
497         wait_delete_completed
498
499         echo "    Write to exceed soft limit"
500         RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
501         $RUNDD count=$((BUNIT_SZ+1)) || \
502                 quota_error a $TSTUSR "write failure, but expect success"
503         OFFSET=$((OFFSET + BUNIT_SZ + 1))
504         cancel_lru_locks osc
505
506         $SHOW_QUOTA_USER
507         $SHOW_QUOTA_GROUP
508         $SHOW_QUOTA_INFO_USER
509         $SHOW_QUOTA_INFO_GROUP
510
511         echo "    Write before timer goes off"
512         $RUNDD count=$BUNIT_SZ seek=$OFFSET || \
513                 quota_error a $TSTUSR "write failure, but expect success"
514         OFFSET=$((OFFSET + BUNIT_SZ))
515         cancel_lru_locks osc
516         echo "    Done"
517
518         echo "    Sleep $TIMER seconds ..."
519         sleep $TIMER
520
521         $SHOW_QUOTA_USER
522         $SHOW_QUOTA_GROUP
523         $SHOW_QUOTA_INFO_USER
524         $SHOW_QUOTA_INFO_GROUP
525
526         echo "    Write after timer goes off"
527         # maybe cache write, ignore.
528         $RUNDD count=$BUNIT_SZ seek=$OFFSET || true
529         OFFSET=$((OFFSET + BUNIT_SZ))
530         cancel_lru_locks osc
531         $RUNDD count=$BUNIT_SZ seek=$OFFSET && \
532                 quota_error a $TSTUSR "write success, but expect EDQUOT"
533
534         $SHOW_QUOTA_USER
535         $SHOW_QUOTA_GROUP
536         $SHOW_QUOTA_INFO_USER
537         $SHOW_QUOTA_INFO_GROUP
538
539         echo "    Unlink file to stop timer"
540         rm -f $TESTFILE
541         sync; sleep 1; sync
542         echo "    Done"
543
544         $SHOW_QUOTA_USER
545         $SHOW_QUOTA_GROUP
546         $SHOW_QUOTA_INFO_USER
547         $SHOW_QUOTA_INFO_GROUP
548
549         echo "    Write ..."
550         $RUNDD count=$BUNIT_SZ || quota_error a $TSTUSR "write failure, but expect success"
551         echo "    Done"
552
553         # cleanup
554         rm -f $TESTFILE
555         sync; sleep 3; sync;
556 }
557
558 # block soft limit (start timer, timer goes off, stop timer)
559 test_3() {
560         mkdir -p $DIR/$tdir
561         chmod 0777 $DIR/$tdir
562
563         # 1 bunit on mds and 1 bunit on every ost
564         LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) ))
565         GRACE=10
566
567         echo "  User quota (soft limit: $LIMIT kbytes  grace: $GRACE seconds)"
568         TESTFILE=$DIR/$tdir/$tfile-0
569
570         $LFS setstripe $TESTFILE -c 1
571         chown $TSTUSR.$TSTUSR $TESTFILE
572
573         $LFS setquota -t -u --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
574         $LFS setquota -u $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
575
576         test_block_soft $TESTFILE $GRACE
577         resetquota -u $TSTUSR
578
579         echo "  Group quota (soft limit: $LIMIT kbytes  grace: $GRACE seconds)"
580         TESTFILE=$DIR/$tdir/$tfile-1
581
582         $LFS setstripe $TESTFILE -c 1
583         chown $TSTUSR.$TSTUSR $TESTFILE
584
585         $LFS setquota -t -g --block-grace $GRACE --inode-grace $MAX_IQ_TIME $DIR
586         $LFS setquota -g $TSTUSR -b $LIMIT -B 0 -i 0 -I 0 $DIR
587
588         test_block_soft $TESTFILE $GRACE
589         resetquota -g $TSTUSR
590 }
591 run_test_with_stat 3 "Block soft limit (start timer, timer goes off, stop timer) ==="
592
593 test_file_soft() {
594         TESTFILE=$1
595         LIMIT=$2
596         TIMER=$(($3 * 3 / 2))
597
598         wait_delete_completed
599
600         echo "    Create files to exceed soft limit"
601         $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) || \
602                 quota_error a $TSTUSR "create failure, but expect success"
603         sync; sleep 1; sync
604         echo "    Done"
605
606         echo "    Create file before timer goes off"
607         $RUNAS touch ${TESTFILE}_before || \
608                 quota_error a $TSTUSR "failed create before timer expired, but expect success"
609         sync; sleep 1; sync
610         echo "    Done"
611
612         echo "    Sleep $TIMER seconds ..."
613         sleep $TIMER
614
615         $SHOW_QUOTA_USER
616         $SHOW_QUOTA_GROUP
617         $SHOW_QUOTA_INFO_USER
618         $SHOW_QUOTA_INFO_GROUP
619
620         echo "    Create file after timer goes off"
621         # the least of inode qunit is 2, so there are at most 3(qunit:2+qtune:1)
622         # inode quota left here
623         $RUNAS touch ${TESTFILE}_after ${TESTFILE}_after1 ${TESTFILE}_after2 || true
624         sync; sleep 1; sync
625         $RUNAS touch ${TESTFILE}_after3 && \
626                 quota_error a $TSTUSR "create after timer expired, but expect EDQUOT"
627         sync; sleep 1; sync
628
629         $SHOW_QUOTA_USER
630         $SHOW_QUOTA_GROUP
631         $SHOW_QUOTA_INFO_USER
632         $SHOW_QUOTA_INFO_GROUP
633
634         echo "    Unlink files to stop timer"
635         find `dirname $TESTFILE` -name "`basename ${TESTFILE}`*" | xargs rm -f
636         echo "    Done"
637
638         echo "    Create file"
639         $RUNAS touch ${TESTFILE}_xxx || \
640                 quota_error a $TSTUSR "touch after timer stop failure, but expect success"
641         sync; sleep 1; sync
642         echo "    Done"
643
644         # cleanup
645         rm -f ${TESTFILE}_xxx
646         sync; sleep 3; sync;
647 }
648
649 # file soft limit (start timer, timer goes off, stop timer)
650 test_4a() {        # was test_4
651         mkdir -p $DIR/$tdir
652         chmod 0777 $DIR/$tdir
653         LIMIT=$(($IUNIT_SZ * 10))        # 10 iunits on mds
654         TESTFILE=$DIR/$tdir/$tfile-0
655
656         GRACE=5
657
658         echo "  User quota (soft limit: $LIMIT files  grace: $GRACE seconds)"
659         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
660         $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
661         quota_show_check f u $TSTUSR
662
663         test_file_soft $TESTFILE $LIMIT $GRACE
664         resetquota -u $TSTUSR
665
666         echo "  Group quota (soft limit: $LIMIT files  grace: $GRACE seconds)"
667         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $GRACE $DIR
668         $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR
669         quota_show_check f g $TSTUSR
670         TESTFILE=$DIR/$tdir/$tfile-1
671
672         test_file_soft $TESTFILE $LIMIT $GRACE
673         resetquota -g $TSTUSR
674
675         # cleanup
676         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
677         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
678 }
679 run_test_with_stat 4a "File soft limit (start timer, timer goes off, stop timer) ==="
680
681 test_4b() {        # was test_4a
682         GR_STR1="1w3d"
683         GR_STR2="1000s"
684         GR_STR3="5s"
685         GR_STR4="1w2d3h4m5s"
686         GR_STR5="5c"
687         GR_STR6="1111111111111111"
688
689         wait_delete_completed
690
691         # test of valid grace strings handling
692         echo "  Valid grace strings test"
693         $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace $GR_STR2 $DIR
694         $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
695         $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace $GR_STR4 $DIR
696         $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
697
698         # test of invalid grace strings handling
699         echo "  Invalid grace strings test"
700         ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
701         ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
702
703         # cleanup
704         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
705         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
706 }
707 run_test_with_stat 4b "Grace time strings handling ==="
708
709 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
710 test_5() {
711         mkdir -p $DIR/$tdir
712         BLIMIT=$(( $BUNIT_SZ * $((OSTCOUNT + 1)) * 10)) # 10 bunits on each server
713         ILIMIT=$(( $IUNIT_SZ * 10 )) # 10 iunits on mds
714
715         wait_delete_completed
716
717         echo "  Set quota limit (0 $BLIMIT 0 $ILIMIT) for $TSTUSR.$TSTUSR"
718         $LFS setquota -u $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
719         $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $DIR
720         quota_show_check a u $TSTUSR
721         quota_show_check a g $TSTUSR
722
723         echo "  Create more than $ILIMIT files and more than $BLIMIT kbytes ..."
724         createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) || \
725                 error "touch failure, expect success"
726         dd if=/dev/zero of=$DIR/$tdir/$tfile-0_1 bs=$BLK_SZ count=$((BLIMIT+1)) || error "write failure, expect success"
727
728         echo "  Chown files to $TSTUSR.$TSTUSR ..."
729         for i in `seq 0 $ILIMIT`; do
730         chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i || \
731                         quota_error a $TSTUSR "chown failure, but expect success"
732         done
733
734         # cleanup
735         unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
736         sync; sleep 3; sync;
737
738         resetquota -u $TSTUSR
739         resetquota -g $TSTUSR
740 }
741 run_test_with_stat 5 "Chown & chgrp successfully even out of block/file quota ==="
742
743 # block quota acquire & release
744 test_6() {
745         if [ $OSTCOUNT -lt 2 ]; then
746                 skip_env "$OSTCOUNT < 2, too few osts"
747                 return 0;
748         fi
749
750         wait_delete_completed
751
752         mkdir -p $DIR/$tdir
753         chmod 0777 $DIR/$tdir
754
755         LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1) * 5)) # 5 bunits per server
756         FILEA="$DIR/$tdir/$tfile-0_a"
757         FILEB="$DIR/$tdir/$tfile-0_b"
758
759         echo "  Set block limit $LIMIT kbytes to $TSTUSR.$TSTUSR"
760         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
761         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
762         quota_show_check b u $TSTUSR
763         quota_show_check b g $TSTUSR
764
765         echo "  Create filea on OST0 and fileb on OST1"
766         $LFS setstripe $FILEA -i 0 -c 1
767         $LFS setstripe $FILEB -i 1 -c 1
768         chown $TSTUSR.$TSTUSR $FILEA
769         chown $TSTUSR.$TSTUSR $FILEB
770
771         echo "  Exceed quota limit ..."
772         RUNDD="$RUNAS dd if=/dev/zero of=$FILEA bs=$BLK_SZ"
773         $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
774                 quota_error a $TSTUSR "write filea failure, but expect success"
775
776         cancel_lru_locks osc
777         $SHOW_QUOTA_USER
778         $SHOW_QUOTA_GROUP
779         $RUNDD seek=$LIMIT count=$((BUNIT_SZ * OSTCOUNT)) && \
780                 quota_error a $TSTUSR "write filea success, but expect EDQUOT"
781         cancel_lru_locks osc
782         echo "  Write to OST1 return EDQUOT"
783         # this write maybe cache write, ignore it's failure
784         RUNDD="$RUNAS dd if=/dev/zero of=$FILEB bs=$BLK_SZ"
785         $RUNDD count=$(($BUNIT_SZ * 2)) || true
786         cancel_lru_locks osc
787         $SHOW_QUOTA_USER
788         $SHOW_QUOTA_GROUP
789         $RUNDD count=$((BUNIT_SZ * 2)) seek=$((BUNIT_SZ *2)) && \
790                 quota_error a $TSTUSR "write fileb success, but expect EDQUOT"
791
792         echo "  Remove filea to let OST0 release quota"
793         rm -f $FILEA
794
795         if at_is_enabled; then
796             timeout=$(at_max_get mds)
797         else
798             timeout=$(lctl get_param -n timeout)
799         fi
800         count=$((timeout / 5))
801         OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
802
803         while [ $((count--)) -gt 0 ]; do
804                 sync && sleep 5
805
806                 OST0_QUOTA_HOLD=`getquota -u $TSTUSR $OST0_UUID bhardlimit`
807                 if [ -z $OST0_QUOTA_HOLD ]; then
808                         error "System is error when query quota for block (U:$TSTUSR)."
809                 else
810                         [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
811                 fi
812
813                 break
814         done
815
816         [ ! $count -gt 0 ] && error "Release quota for block timeout (U:$TSTUSR)."
817         $SHOW_QUOTA_USER
818
819         while [ $((count--)) -gt 0 ]; do
820                 sync && sleep 5
821
822                 OST0_QUOTA_HOLD=`getquota -g $TSTUSR $OST0_UUID bhardlimit`
823                 if [ -z $OST0_QUOTA_HOLD ]; then
824                         error "System is error when query quota for block (G:$TSTUSR)."
825                 else
826                         [ $OST0_QUOTA_HOLD -gt $BUNIT_SZ ] && continue
827                 fi
828
829                 break
830         done
831
832         [ ! $count -gt 0 ] && error "Release quota for block timeout (G:$TSTUSR)."
833         $SHOW_QUOTA_GROUP
834
835         echo "  Write to OST1"
836         $RUNDD count=$((LIMIT - BUNIT_SZ * OSTCOUNT)) || \
837                 quota_error a $TSTUSR "write fileb failure, expect success"
838         echo "  Done"
839
840         # cleanup
841         rm -f $FILEB
842         sync; sleep 3; sync;
843
844         resetquota -u $TSTUSR
845         resetquota -g $TSTUSR
846         return 0
847 }
848 run_test_with_stat 6 "Block quota acquire & release ========="
849
850 # quota recovery (block quota only by now)
851 test_7()
852 {
853         mkdir -p $DIR/$tdir
854         chmod 0777 $DIR/$tdir
855
856         wait_delete_completed
857
858         LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) ))
859         TESTFILE="$DIR/$tdir/$tfile-0"
860
861         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
862
863         $LFS setstripe $TESTFILE -c 1
864         chown $TSTUSR.$TSTUSR $TESTFILE
865
866         echo "  Write to OST0..."
867         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ || \
868                 quota_error u $TSTUSR "write failure, but expect success"
869
870         #define OBD_FAIL_OBD_DQACQ               0x604
871         lustre_fail mds  0x604
872         echo "  Remove files on OST0"
873         rm -f $TESTFILE
874         lustre_fail mds  0
875
876         echo "  Trigger recovery..."
877         OSC0_UUID="`$LCTL dl | awk '$3 ~ /osc/ { print $1 }'`"
878         for i in $OSC0_UUID; do
879                 $LCTL --device $i activate || error "activate osc failed!"
880         done
881
882         # sleep a while to wait for recovery done
883         sleep 20
884
885         # check limits
886         PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
887         TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
888         [ $TOTAL_LIMIT -eq $LIMIT ] || error "total limits not recovery!"
889         echo "  total limits = $TOTAL_LIMIT"
890
891         OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
892         [ -z "$OST0_UUID" ] && OST0_UUID=`do_facet ost1 "$LCTL dl | grep -m1 obdfilter" | awk '{print $((NF-1))}'`
893         OST0_LIMIT=`getquota  -u $TSTUSR $OST0_UUID bhardlimit`
894         [ $OST0_LIMIT -eq $BUNIT_SZ ] || error "high limits not released!"
895         echo "  limits on $OST0_UUID = $OST0_LIMIT"
896
897         # cleanup
898         resetquota -u $TSTUSR
899 }
900 run_test_with_stat 7 "Quota recovery (only block limit) ======"
901
902 # run dbench with quota enabled
903 test_8() {
904         mkdir -p $DIR/$tdir
905         BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
906         FILE_LIMIT=1000000
907
908         wait_delete_completed
909
910         echo "  Set enough high limit for user: $TSTUSR"
911         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
912         echo "  Set enough high limit for group: $TSTUSR"
913         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
914
915         chmod 0777 $DIR/$tdir
916         local duration=""
917         [ "$SLOW" = "no" ] && duration=" -t 120"
918         $RUNAS bash rundbench -D $DIR/$tdir 3 $duration || quota_error a $TSTUSR "dbench failed!"
919
920         rm -rf $DIR/$tdir
921         sync; sleep 3; sync;
922
923         return 0
924 }
925 run_test_with_stat 8 "Run dbench with quota enabled ==========="
926
927 # run for fixing bug10707, it needs a big room. test for 64bit
928 KB=1024
929 GB=$((KB * 1024 * 1024))
930 # Use this as dd bs to decrease time
931 # inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
932 blksize=$((1 << 21)) # 2Mb
933 size_file=$((GB * 9 / 2))
934 # this check is just for test9 and test10
935 OST0_MIN=4900000 #4.67G
936 check_whether_skip () {
937     OST0_SIZE=`$LFS df $DIR | awk '/\[OST:0\]/ {print $4}'`
938     log "OST0_SIZE: $OST0_SIZE  required: $OST0_MIN"
939     if [ $OST0_SIZE -lt $OST0_MIN ]; then
940         echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
941         return 0
942     else
943         return 1
944     fi
945 }
946
947 test_9() {
948         check_whether_skip && return 0
949
950         wait_delete_completed
951
952         set_blk_tunesz 512
953         set_blk_unitsz 1024
954
955         mkdir -p $DIR/$tdir
956         chmod 0777 $DIR/$tdir
957         TESTFILE="$DIR/$tdir/$tfile-0"
958
959         BLK_LIMIT=$((100 * KB * KB)) # 100G
960         FILE_LIMIT=1000000
961         echo "  Set block limit $BLK_LIMIT kbytes to $TSTUSR.$TSTUSR"
962
963         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
964         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
965         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
966         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
967
968         quota_show_check a u $TSTUSR
969         quota_show_check a g $TSTUSR
970
971         echo "  Set stripe"
972         $LFS setstripe $TESTFILE -c 1
973         touch $TESTFILE
974         chown $TSTUSR.$TSTUSR $TESTFILE
975
976         log "    Write the big file of 4.5G ..."
977         $RUNAS dd if=/dev/zero of=$TESTFILE  bs=$blksize count=$((size_file / blksize)) || \
978                quota_error a $TSTUSR "(usr) write 4.5G file failure, but expect success"
979
980         $SHOW_QUOTA_USER
981         $SHOW_QUOTA_GROUP
982
983         log "    delete the big file of 4.5G..."
984         $RUNAS rm -f $TESTFILE
985         sync; sleep 3; sync;
986
987         $SHOW_QUOTA_USER
988         $SHOW_QUOTA_GROUP
989
990         RC=$?
991
992         set_blk_unitsz $((128 * 1024))
993         set_blk_tunesz $((128 * 1024 / 2))
994
995         return $RC
996 }
997 run_test_with_stat 9 "run for fixing bug10707(64bit) ==========="
998
999 # run for fixing bug10707, it need a big room. test for 32bit
1000 test_10() {
1001         mkdir -p $DIR/$tdir
1002         chmod 0777 $DIR/$tdir
1003         check_whether_skip && return 0
1004
1005         wait_delete_completed
1006
1007         set_blk_tunesz 512
1008         set_blk_unitsz 1024
1009
1010         # make qd_count 32 bit
1011         lustre_fail mds_ost 0xA00
1012
1013         TESTFILE="$DIR/$tdir/$tfile-0"
1014
1015         BLK_LIMIT=$((100 * KB * KB)) # 100G
1016         FILE_LIMIT=1000000
1017
1018         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1019         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1020         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1021         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR
1022
1023         quota_show_check a u $TSTUSR
1024         quota_show_check a g $TSTUSR
1025
1026         echo "  Set stripe"
1027         $LFS setstripe $TESTFILE -c 1
1028         touch $TESTFILE
1029         chown $TSTUSR.$TSTUSR $TESTFILE
1030
1031         log "    Write the big file of 4.5 G ..."
1032         $RUNAS dd if=/dev/zero of=$TESTFILE  bs=$blksize count=$((size_file / blksize)) || \
1033                 quota_error a $TSTUSR "(usr) write 4.5 G file failure, but expect success"
1034
1035         $SHOW_QUOTA_USER
1036         $SHOW_QUOTA_GROUP
1037
1038         log "    delete the big file of 4.5 G..."
1039         $RUNAS rm -f $TESTFILE
1040         sync; sleep 3; sync;
1041
1042         $SHOW_QUOTA_USER
1043         $SHOW_QUOTA_GROUP
1044
1045         RC=$?
1046
1047         # make qd_count 64 bit
1048         lustre_fail mds_ost 0
1049
1050         set_blk_unitsz $((128 * 1024))
1051         set_blk_tunesz $((128 * 1024 / 2))
1052
1053         return $RC
1054 }
1055 run_test_with_stat 10 "run for fixing bug10707(32bit) ==========="
1056
1057 test_11() {
1058        wait_delete_completed
1059
1060        #prepare the test
1061        block_limit=`(echo 0; df -t lustre -P | awk '{print $(NF - 4)}') | tail -n 1`
1062        echo $block_limit
1063        orig_dbr=`sysctl -n vm.dirty_background_ratio`
1064        orig_dec=`sysctl -n vm.dirty_expire_centisecs`
1065        orig_dr=`sysctl -n vm.dirty_ratio`
1066        orig_dwc=`sysctl -n vm.dirty_writeback_centisecs`
1067        sysctl -w vm.dirty_background_ratio=1
1068        sysctl -w vm.dirty_expire_centisecs=30
1069        sysctl -w vm.dirty_ratio=1
1070        sysctl -w vm.dirty_writeback_centisecs=50
1071        TESTDIR="$DIR/$tdir"
1072        local RV=0
1073
1074        #do the test
1075        local SECS=0
1076        local REPS=3
1077        [ "$SLOW" = no ] && REPS=1
1078        local sleep=20
1079        local i=1
1080        while [ $i -le $REPS ]; do
1081            echo "test: cycle($i of $REPS) start at $(date)"
1082            mkdir -p $TESTDIR && chmod 777 $TESTDIR
1083            echo -n "    create a file for uid "
1084            for j in `seq 1 30`; do
1085                echo -n "$j "
1086                # 30MB per dd for a total of 900MB (if space even permits)
1087                runas -u $j dd if=/dev/zero of=$TESTDIR/$tfile  bs=$blksize count=15 > /dev/null 2>&1 &
1088            done
1089            echo ""
1090            PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1091            LAST_USED=0
1092            while [ $PROCS -gt 0 ]; do 
1093              sleep 20
1094              SECS=$((SECS + sleep))
1095              PROCS=$(ps -ef | grep -v grep | grep "dd if /dev/zero of $TESTDIR" | wc -l)
1096              USED=$(du -s $TESTDIR | awk '{print $1}')
1097              PCT=$(($USED * 100 / $block_limit))
1098              echo "${i}/${REPS} ${PCT}% p${PROCS} t${SECS}  "
1099              if [ $USED -le $LAST_USED ]; then
1100                  kill -9 $(ps -ef | grep "dd if /dev/zero of $TESTDIR" | grep -v grep | awk '{ print $2 }')
1101                  i=$REPS
1102                  RV=2
1103                  break
1104              fi
1105              LAST_USED=$USED
1106            done
1107            echo "    removing the test files..."
1108            rm -f $TESTDIR/$tfile
1109            echo "cycle $i done at $(date)"
1110            i=$[$i+1]
1111        done
1112        echo "Test took $SECS sec"
1113
1114        #clean
1115        sysctl -w vm.dirty_background_ratio=$orig_dbr
1116        sysctl -w vm.dirty_expire_centisecs=$orig_dec
1117        sysctl -w vm.dirty_ratio=$orig_dr
1118        sysctl -w vm.dirty_writeback_centisecs=$orig_dwc
1119        if [ $RV -ne 0 ]; then
1120            error "Nothing was written for $SECS sec ... aborting"
1121        fi
1122        return $RV
1123 }
1124 run_test_with_stat 11 "run for fixing bug10912 ==========="
1125
1126 # test multiple clients write block quota b=11693
1127 test_13() {
1128         mkdir -p $DIR/$tdir
1129         wait_delete_completed
1130
1131         # one OST * 10 + (mds + other OSTs)
1132         LIMIT=$((BUNIT_SZ * 10 + (BUNIT_SZ * OSTCOUNT)))
1133         TESTFILE="$DIR/$tdir/$tfile"
1134
1135         echo "   User quota (limit: $LIMIT kbytes)"
1136         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1137         quota_show_check b u $TSTUSR
1138
1139         $LFS setstripe $TESTFILE -i 0 -c 1
1140         chown $TSTUSR.$TSTUSR $TESTFILE
1141         $LFS setstripe $TESTFILE.2 -i 0 -c 1
1142         chown $TSTUSR.$TSTUSR $TESTFILE.2
1143
1144         echo "   step1: write out of block quota ..."
1145         # one bunit will give mds
1146         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1147         DDPID=$!
1148         $RUNAS dd if=/dev/zero of=$TESTFILE.2 bs=$BLK_SZ count=$[($LIMIT - $BUNIT_SZ) / 2] &
1149         DDPID1=$!
1150
1151         echo  "   step2: testing ......"
1152         count=0
1153         while [ true ]; do
1154             if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1155             count=$[count+1]
1156             if [ $count -gt 64 ]; then
1157                 quota_error u $TSTUSR "dd should be finished!"
1158             fi
1159             sleep 1
1160         done
1161         echo "(dd_pid=$DDPID, time=$count)successful"
1162
1163         count=0
1164         while [ true ]; do
1165             if ! ps -p ${DDPID1} > /dev/null 2>&1 ; then break; fi
1166             count=$[count+1]
1167             if [ $count -gt 64 ]; then
1168                 quota_error u $TSTUSR "dd should be finished!"
1169             fi
1170             sleep 1
1171         done
1172         echo "(dd_pid=$DDPID1, time=$count)successful"
1173
1174         sync; sleep 5; sync;
1175
1176         echo  "   step3: checking ......"
1177         fz=`stat -c %s $TESTFILE`
1178         fz2=`stat -c %s $TESTFILE.2`
1179         $SHOW_QUOTA_USER
1180         [ $((fz + fz2)) -lt $((BUNIT_SZ * BLK_SZ * 10)) ] && \
1181                 quota_error u $TSTUSR "files too small $fz + $fz2 < $((BUNIT_SZ * BLK_SZ * 10))"
1182
1183         rm -f $TESTFILE $TESTFILE.2
1184         sync; sleep 3; sync;
1185
1186         resetquota -u $TSTUSR
1187 }
1188 run_test_with_stat 13 "test multiple clients write block quota ==="
1189
1190 check_if_quota_zero(){
1191         line=`$LFS quota -v -$1 $2 $DIR | wc -l`
1192         for i in `seq 3 $line`; do
1193             if [ $i -eq 3 ]; then
1194                 field="3 4 7 8"
1195             else
1196                 field="3 6"
1197             fi
1198             for j in $field; do
1199                 tmp=`$LFS quota -v -$1 $2 $DIR | sed -n ${i}p |
1200                      awk  '{print $'"$j"'}'`
1201                 [ -n "$tmp" ] && [ $tmp -ne 0 ] && $LFS quota -v -$1 $2 $DIR && \
1202                     error "quota on $2 isn't clean"
1203             done
1204         done
1205         echo "pass check_if_quota_zero"
1206 }
1207
1208 test_14a() {        # was test_14 b=12223 -- setting quota on root
1209         TESTFILE="$DIR/$tdir/$tfile"
1210
1211         # reboot the lustre
1212         sync; sleep 5; sync
1213         cleanup_and_setup_lustre
1214         test_0
1215
1216         mkdir -p $DIR/$tdir
1217
1218         # out of root's file and block quota
1219         $LFS setquota -u root -b 10 -B 10 -i 10 -I 10 $DIR
1220         createmany -m ${TESTFILE} 20 || \
1221             quota_error u root "unexpected: user(root) create files failly!"
1222         multiop ${TESTFILE} oO_CREAT:O_WRONLY:O_DIRECT:w$((4096 * 4096))c || \
1223             quota_error u root "unexpected: user(root) write files failly!"
1224         chmod 666 $TESTFILE
1225         $RUNAS multiop ${TESTFILE} oO_WRONLY:O_APPEND:O_DIRECT:w$((4096 * 4096))c && \
1226             quota_error u root "unexpected: user(quota_usr) write a file successfully!"
1227
1228         # trigger the llog
1229         chmod 777 $DIR
1230         for i in `seq 1 10`; do $RUNAS touch ${TESTFILE}a_$i; done
1231         for i in `seq 1 10`; do $RUNAS rm -f ${TESTFILE}a_$i; done
1232
1233         # do the check
1234         dmesg | tail | grep "\-122" |grep llog_obd_origin_add && error "err -122 not found in dmesg"
1235         resetquota -u root
1236         #check_if_quota_zero u root
1237
1238         # clean
1239         unlinkmany ${TESTFILE} 15
1240         rm -f $TESTFILE
1241         sync; sleep 3; sync;
1242 }
1243 run_test_with_stat 14a "test setting quota on root ==="
1244
1245 test_15(){
1246         LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1247         PATTERN="`echo $DIR | sed 's/\//\\\\\//g'`"
1248
1249         wait_delete_completed
1250
1251         # force using the latest version in case 14b was omitted
1252         $LFS quotaoff -ug $DIR
1253         quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
1254         $LFS quotacheck -ug $DIR || error "quotacheck failed"
1255
1256         # test for user
1257         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1258         TOTAL_LIMIT=`getquota -u $TSTUSR global bhardlimit`
1259         [ $TOTAL_LIMIT -eq $LIMIT ] || error "  (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1260         echo "  (user)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1261         resetquota -u $TSTUSR
1262
1263         # test for group
1264         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1265         TOTAL_LIMIT=`getquota -g $TSTUSR global bhardlimit`
1266         [ $TOTAL_LIMIT -eq $LIMIT ] || error "  (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, failed!"
1267         echo "  (group)total limits = $TOTAL_LIMIT; limit = $LIMIT, successful!"
1268
1269         resetquota -g $TSTUSR
1270
1271         # interop 18 <-> 20
1272         local lustre_version=$(get_lustre_version mds)
1273         if [[ $lustre_version != 1.8* ]]; then
1274                 echo mds running $lustre_version, skip quota v1 testing
1275                 return 0
1276         fi
1277
1278         quota_save_version "ug1"
1279
1280         echo "Testing that >4GB quota limits fail on volume with quota v1"
1281         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR && error "no error from setquota, but should have failed"
1282
1283         return 0
1284 }
1285 run_test_with_stat 15 "set block quota more than 4T ==="
1286
1287 # $1=u/g $2=with qunit adjust or not
1288 test_16_tub() {
1289         LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 4))
1290         TESTFILE="$DIR/$tdir/$tfile"
1291         mkdir -p $DIR/$tdir
1292
1293         wait_delete_completed
1294
1295         echo "  User quota (limit: $LIMIT kbytes)"
1296         if [ $1 == "u" ]; then
1297             $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1298             quota_show_check b u $TSTUSR
1299         else
1300             $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1301             quota_show_check b g $TSTUSR
1302         fi
1303
1304         $LFS setstripe $TESTFILE -c 1
1305         chown $TSTUSR.$TSTUSR $TESTFILE
1306
1307         echo "    Write ..."
1308         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((BUNIT_SZ * 4)) || \
1309             quota_error a $TSTUSR "(usr) write failure, but expect success"
1310         echo "    Done"
1311         echo "    Write out of block quota ..."
1312         # this time maybe cache write,  ignore it's failure
1313         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || true
1314         # flush cache, ensure noquota flag is setted on client
1315         cancel_lru_locks osc
1316         if [ $2 -eq 1 ]; then
1317             $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) || \
1318                 quota_error a $TSTUSR "(write failure, but expect success"
1319         else
1320             $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ * 4)) && \
1321                 quota_error a $TSTUSR "(write success, but expect EDQUOT"
1322         fi
1323
1324         rm -f $TESTFILE
1325         sync; sleep 3; sync;
1326         resetquota -$1 $TSTUSR
1327 }
1328
1329 # test without adjusting qunit
1330 test_16 () {
1331         # interop 18 <-> 20
1332         # 2.0 version does not support WITHOUT_CHANGE_QS, so such test is obsolete
1333         local lustre_version=$(get_lustre_version mds)
1334         if [[ $lustre_version != 1.8* ]]; then
1335                 skip mds running $lustre_version, WITHOUT_CHANGE_QS is not supported
1336                 return 0
1337         fi
1338         
1339         set_blk_tunesz $((BUNIT_SZ * 2))
1340         set_blk_unitsz $((BUNIT_SZ * 4))
1341         for i in u g; do
1342             for j in 0 1; do
1343                 # define OBD_FAIL_QUOTA_WITHOUT_CHANGE_QS    0xA01
1344                 echo " grp/usr: $i, adjust qunit: $j"
1345                 echo "-------------------------------"
1346                 [ $j -eq 1 ] && lustre_fail mds_ost 0
1347                 [ $j -eq 0 ] && lustre_fail mds_ost 0xA01
1348                 test_16_tub $i $j
1349             done
1350         done
1351         set_blk_unitsz $((128 * 1024))
1352         set_blk_tunesz $((128 * 1024 / 2))
1353 }
1354 run_test_with_stat 16 "test without adjusting qunit"
1355
1356 # run for fixing bug14526, failed returned quota reqs shouldn't ruin lustre.
1357 test_17() {
1358         set_blk_tunesz 512
1359         set_blk_unitsz 1024
1360
1361         wait_delete_completed
1362
1363         #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
1364         lustre_fail ost 0x80000A02
1365
1366         TESTFILE="$DIR/$tdir/$tfile-a"
1367         TESTFILE2="$DIR/$tdir/$tfile-b"
1368         mkdir -p $DIR/$tdir
1369
1370         BLK_LIMIT=$((100 * 1024)) # 100M
1371
1372         log "  Set enough high limit(block:$BLK_LIMIT) for user: $TSTUSR"
1373         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1374         log "  Set enough high limit(block:$BLK_LIMIT) for group: $TSTUSR"
1375         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR
1376
1377         quota_show_check b u $TSTUSR
1378         quota_show_check b g $TSTUSR
1379
1380         touch $TESTFILE
1381         chown $TSTUSR.$TSTUSR $TESTFILE
1382         touch $TESTFILE2
1383         chown $TSTUSR.$TSTUSR $TESTFILE2
1384
1385         log "    Write the test file1 ..."
1386         $RUNAS dd if=/dev/zero of=$TESTFILE  bs=$BLK_SZ count=$(( 10 * 1024 )) \
1387             || quota_error a $TSTUSR "write 10M file failure"
1388
1389         $SHOW_QUOTA_USER
1390         $SHOW_QUOTA_GROUP
1391
1392         log "    write the test file2 ..."
1393         $RUNAS dd if=/dev/zero of=$TESTFILE2  bs=$BLK_SZ count=$(( 10 * 1024 )) \
1394             || quota_error a $TSTUSR "write 10M file failure"
1395
1396         $SHOW_QUOTA_USER
1397         $SHOW_QUOTA_GROUP
1398
1399         rm -f $TESTFILE $TESTFILE2
1400         RC=$?
1401         sync; sleep 3; sync;
1402
1403         # make qd_count 64 bit
1404         lustre_fail ost 0
1405
1406         set_blk_unitsz $((128 * 1024))
1407         set_blk_tunesz $((128 * 1024 / 2))
1408
1409         resetquota -u $TSTUSR
1410         resetquota -g $TSTUSR
1411
1412         return $RC
1413 }
1414 run_test_with_stat 17 "run for fixing bug14526 ==========="
1415
1416 # test when mds takes a long time to handle a quota req so that
1417 # the ost has dropped it, the ost still could work well b=14840
1418 test_18() {
1419         LIMIT=$((100 * 1024 * 1024)) # 100G
1420         TESTFILE="$DIR/$tdir/$tfile"
1421         mkdir -p $DIR/$tdir
1422
1423         wait_delete_completed
1424
1425         set_blk_tunesz 512
1426         set_blk_unitsz 1024
1427
1428         log "   User quota (limit: $LIMIT kbytes)"
1429         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1430         quota_show_check b u $TSTUSR
1431
1432         $LFS setstripe $TESTFILE -i 0 -c 1
1433         chown $TSTUSR.$TSTUSR $TESTFILE
1434
1435         #define OBD_FAIL_MDS_BLOCK_QUOTA_REQ      0x13c
1436         lustre_fail mds 0x13c
1437
1438         log "   step1: write 100M block ..."
1439         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1440         DDPID=$!
1441
1442         sleep 5
1443         lustre_fail mds 0
1444
1445         echo  "   step2: testing ......"
1446         count=0
1447         if at_is_enabled; then
1448             timeout=$(at_max_get mds)
1449         else
1450             timeout=$(lctl get_param -n timeout)
1451         fi
1452         while [ true ]; do
1453             if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1454             count=$[count+1]
1455             if [ $count -gt $((4 * $timeout)) ]; then
1456                 quota_error u $TSTUSR "count=$count dd should be finished!"
1457             fi
1458             sleep 1
1459         done
1460         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1461         sync
1462         cancel_lru_locks mdc
1463         cancel_lru_locks osc
1464
1465         testfile_size=$(stat -c %s $TESTFILE)
1466         [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] && \
1467             quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1468         $SHOW_QUOTA_USER
1469         rm -f $TESTFILE
1470         sync
1471
1472         resetquota -u $TSTUSR
1473         set_blk_unitsz $((128 * 1024))
1474         set_blk_tunesz $((128 * 1024 / 2))
1475 }
1476 run_test_with_stat 18 "run for fixing bug14840 ==========="
1477
1478 # test when mds drops a quota req, the ost still could work well b=14840
1479 test_18a() {
1480         LIMIT=$((100 * 1024 * 1024)) # 100G
1481         TESTFILE="$DIR/$tdir/$tfile-a"
1482         mkdir -p $DIR/$tdir
1483
1484         wait_delete_completed
1485
1486         set_blk_tunesz 512
1487         set_blk_unitsz 1024
1488
1489         log "   User quota (limit: $LIMIT kbytes)"
1490         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1491         quota_show_check b u $TSTUSR
1492
1493         $LFS setstripe $TESTFILE -i 0 -c 1
1494         chown $TSTUSR.$TSTUSR $TESTFILE
1495
1496         #define OBD_FAIL_MDS_DROP_QUOTA_REQ | OBD_FAIL_ONCE   0x8000013d
1497         lustre_fail mds 0x8000013d
1498
1499         log "   step1: write 100M block ..."
1500         $RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ count=$((1024 * 100)) &
1501         DDPID=$!
1502
1503         echo  "   step2: testing ......"
1504         count=0
1505         if at_is_enabled; then
1506             timeout=$(at_max_get mds)
1507         else
1508             timeout=$(lctl get_param -n timeout)
1509         fi
1510         while [ true ]; do
1511             if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1512             count=$[count+1]
1513             if [ $count -gt $((3 * $timeout)) ]; then
1514                 lustre_fail mds 0
1515                 quota_error u $TSTUSR "count=$count dd should be finished!"
1516             fi
1517             sleep 1
1518         done
1519         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1520
1521         lustre_fail mds 0
1522         rm -f $TESTFILE
1523         sync
1524
1525         resetquota -u $TSTUSR
1526         set_blk_unitsz $((128 * 1024))
1527         set_blk_tunesz $((128 * 1024 / 2))
1528 }
1529 run_test_with_stat 18a "run for fixing bug14840 ==========="
1530
1531 # test when mds do failover, the ost still could work well without trigger
1532 # watchdog b=14840
1533 test_18bc_sub() {
1534         type=$1
1535
1536         LIMIT=$(((100 + $OSTCOUNT * 3) * 1024))
1537         TESTFILE="$DIR/$tdir/$tfile"
1538         mkdir -p $DIR/$tdir
1539
1540         wait_delete_completed
1541
1542         set_blk_tunesz 512
1543         set_blk_unitsz 1024
1544
1545         log "   User quota (limit: $LIMIT kbytes)"
1546         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1547         quota_show_check b u $TSTUSR
1548
1549         $LFS setstripe $TESTFILE -i 0 -c 1
1550         chown $TSTUSR.$TSTUSR $TESTFILE
1551
1552         timeout=$(sysctl -n lustre.timeout)
1553
1554         if [ $type = "directio" ]; then
1555             log "   write 100M block(directio) ..."
1556             $RUNAS $DIRECTIO write $TESTFILE 0 100 $((BLK_SZ * 1024)) &
1557         else
1558             log "   write 100M block(normal) ..."
1559             $RUNAS dd if=/dev/zero of=$TESTFILE bs=$((BLK_SZ * 1024)) count=100 &
1560         fi
1561
1562         DDPID=$!
1563         do_facet mds "$LCTL conf_param ${FSNAME}-MDT*.$(get_md_name).quota_type=ug"
1564
1565         replay_barrier mds
1566
1567         log "failing mds for $((2 * timeout)) seconds"
1568         fail mds $((2 * timeout))
1569
1570         # check if quotaon successful
1571         $LFS quota -u $TSTUSR $MOUNT 2>&1 | grep -q "quotas are not enabled"
1572         if [ $? -eq 0 ]; then
1573             rm -rf $TESTFILE
1574             error "quotaon failed!"
1575             return
1576         fi
1577
1578         count=0
1579         if at_is_enabled; then
1580             timeout=$(at_max_get mds)
1581         else
1582             timeout=$(lctl get_param -n timeout)
1583         fi
1584         while [ true ]; do
1585             if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1586             if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1587                 log "it took $count second"
1588             fi
1589             sleep 1
1590         done
1591         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1592         sync
1593         cancel_lru_locks mdc
1594         cancel_lru_locks osc
1595         $SHOW_QUOTA_USER
1596
1597         resetquota -u $TSTUSR
1598         set_blk_unitsz $((128 * 1024))
1599         set_blk_tunesz $((128 * 1024 / 2))
1600         testfile_size=$(stat -c %s $TESTFILE)
1601         if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1602             rm -f $TESTFILE
1603             quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)), got ${testfile_size}. Verifying file failed!"
1604         fi
1605         rm -f $TESTFILE
1606 }
1607
1608 # test when mds does failover, the ost still could work well
1609 # this test shouldn't trigger watchdog b=14840
1610 test_18b() {
1611         test_18bc_sub normal
1612         test_18bc_sub directio
1613         # check if watchdog is triggered
1614         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1615         watchdog=`awk '/test 18b/ {start = 1;}
1616                        /Service thread pid/ && /was inactive/{
1617                                if (start) {
1618                                        print;
1619                                }
1620                        }' $TMP/lustre-log-${TESTNAME}.log`
1621         [ `echo "$watchdog" | wc -l` -ge 3 ] && error "$watchdog"
1622         rm -f $TMP/lustre-log-${TESTNAME}.log
1623 }
1624 run_test_with_stat 18b "run for fixing bug14840(mds failover, no watchdog) ==========="
1625
1626 # test when mds does failover, the ost still could work well
1627 # this test will prevent OST_DISCONNET from happening b=14840
1628 test_18c() {
1629         # define OBD_FAIL_OST_DISCONNECT_NET 0x202(disable ost_disconnect for osts)
1630         lustre_fail ost  0x202
1631         test_18bc_sub normal
1632         test_18bc_sub directio
1633         lustre_fail ost  0
1634 }
1635 run_test_with_stat 18c "run for fixing bug14840(mds failover, OST_DISCONNECT is disabled) ==========="
1636
1637 run_to_block_limit() {
1638         local LIMIT=$((($OSTCOUNT + 1) * $BUNIT_SZ))
1639         local TESTFILE=$1
1640         wait_delete_completed
1641
1642         # set 1 Mb quota unit size
1643         set_blk_tunesz 512
1644         set_blk_unitsz 1024
1645
1646         # bind file to a single OST
1647         $LFS setstripe -c 1 $TESTFILE
1648         chown $TSTUSR.$TSTUSR $TESTFILE
1649
1650         echo "  User quota (limit: $LIMIT kbytes)"
1651         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1652         quota_show_check b u $TSTUSR
1653         echo "  Updating quota limits"
1654         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $MOUNT
1655         quota_show_check b u $TSTUSR
1656
1657         RUNDD="$RUNAS dd if=/dev/zero of=$TESTFILE bs=$BLK_SZ"
1658         $RUNDD count=$BUNIT_SZ || quota_error u $TSTUSR "(usr) write failure, but expect success"
1659         # for now page cache of TESTFILE may still be dirty,
1660         # let's push it to the corresponding OST, this will also
1661         # cache NOQUOTA on the client from OST's reply
1662         cancel_lru_locks osc
1663         $RUNDD seek=$BUNIT_SZ && quota_error u $TSTUSR "(usr) write success, should be EDQUOT"
1664 }
1665
1666 test_19() {
1667         # 1 Mb bunit per each MDS/OSS
1668         local TESTFILE="$DIR/$tdir/$tfile"
1669         mkdir -p $DIR/$tdir
1670
1671         run_to_block_limit $TESTFILE
1672         $SHOW_QUOTA_USER
1673
1674         # cleanup
1675         rm -f $TESTFILE
1676         resetquota -u $TSTUSR
1677
1678         set_blk_unitsz $((128 * 1024))
1679         set_blk_tunesz $((128 * 1024 / 2))
1680
1681 }
1682 run_test_with_stat 19 "test if administrative limits updates do not zero operational limits (14790) ==="
1683
1684 test_20()
1685 {
1686         LSTR=(1t 2g 3m 4k) # limits strings
1687         LVAL=($[1*1024*1024*1024] $[2*1024*1024] $[3*1024*1024] $[4*1024]) # limits values
1688
1689         $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1690                                  $MOUNT || error "could not set quota limits"
1691
1692         $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1693                                  --inode-softlimit ${LSTR[2]} \
1694                                  --inode-hardlimit ${LSTR[3]} \
1695                                  $MOUNT || error "could not set quota limits"
1696
1697         [ "`getquota -u $TSTUSR global bsoftlimit`" = "${LVAL[0]}" ] || error "bsoftlimit was not set properly"
1698         [ "`getquota -u $TSTUSR global bhardlimit`" = "${LVAL[1]}" ] || error "bhardlimit was not set properly"
1699         [ "`getquota -u $TSTUSR global isoftlimit`" = "${LVAL[2]}" ] || error "isoftlimit was not set properly"
1700         [ "`getquota -u $TSTUSR global ihardlimit`" = "${LVAL[3]}" ] || error "ihardlimit was not set properly"
1701
1702         resetquota -u $TSTUSR
1703 }
1704 run_test_with_stat 20 "test if setquota specifiers work properly (15754)"
1705
1706 test_21_sub() {
1707         local testfile=$1
1708         local blk_number=$2
1709         local seconds=$3
1710
1711         time=$(($(date +%s) + seconds))
1712         while [ $(date +%s) -lt $time ]; do
1713             $RUNAS dd if=/dev/zero of=$testfile  bs=$BLK_SZ count=$blk_number > /dev/null 2>&1
1714             rm -f $testfile
1715         done
1716 }
1717
1718 # run for fixing bug16053, setquota shouldn't fail when writing and
1719 # deleting are happening
1720 test_21() {
1721         set_blk_tunesz 512
1722         set_blk_unitsz 1024
1723
1724         wait_delete_completed
1725
1726         TESTFILE="$DIR/$tdir/$tfile"
1727
1728         BLK_LIMIT=$((10 * 1024 * 1024)) # 10G
1729         FILE_LIMIT=1000000
1730
1731         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for user: $TSTUSR"
1732         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1733         log "  Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT) for group: $TSTUSR"
1734         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $MOUNT
1735
1736         # repeat writing on a 1M file
1737         test_21_sub ${TESTFILE}_1 1024 30 &
1738         DDPID1=$!
1739         # repeat writing on a 128M file
1740         test_21_sub ${TESTFILE}_2 $((1024 * 128)) 30 &
1741         DDPID2=$!
1742
1743         time=$(($(date +%s) + 30))
1744         i=1
1745         while [ $(date +%s) -lt $time ]; do
1746             log "  Set quota for $i times"
1747             $LFS setquota -u $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1748             $LFS setquota -g $TSTUSR -b 0 -B $((BLK_LIMIT + 1024 * i)) -i 0 -I $((FILE_LIMIT + i)) $MOUNT
1749             i=$((i+1))
1750             sleep 1
1751         done
1752
1753         count=0
1754         while [ true ]; do
1755             if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1756             count=$[count+1]
1757             if [ $count -gt 60 ]; then
1758                 quota_error a $TSTUSR "dd should be finished!"
1759             fi
1760             sleep 1
1761         done
1762         echo "(dd_pid=$DDPID1, time=$count)successful"
1763
1764         count=0
1765         while [ true ]; do
1766             if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1767             count=$[count+1]
1768             if [ $count -gt 60 ]; then
1769                 quota_error a $TSTUSR "dd should be finished!"
1770             fi
1771             sleep 1
1772         done
1773         echo "(dd_pid=$DDPID2, time=$count)successful"
1774
1775         set_blk_unitsz $((128 * 1024))
1776         set_blk_tunesz $((128 * 1024 / 2))
1777         resetquota -u $TSTUSR
1778         resetquota -g $TSTUSR
1779
1780         return $RC
1781 }
1782 run_test_with_stat 21 "run for fixing bug16053 ==========="
1783
1784 test_22() {
1785         local lustre_version=$(get_lustre_version mds)
1786         if [[ $lustre_version != 1.8* ]] ; then
1787                 skip mds running $lustre_version, skip quota v1 testing
1788                 return
1789         fi
1790         quota_save_version "ug1"
1791
1792         stopall
1793         mount
1794         setupall
1795
1796         echo "checking parameters"
1797
1798         do_facet mds "lctl get_param mds.${FSNAME}-MDT*.quota_type" | grep "ug1" || error "admin failure"
1799         do_facet ost1 "lctl get_param obdfilter.*.quota_type" | grep "ug1" || error "op failure"
1800
1801         run_test 0 "reboot lustre"
1802 }
1803 run_test_with_stat 22 "test if quota_type saved as permanent parameter ===="
1804
1805 test_23_sub() {
1806         mkdir -p $DIR/$tdir
1807         chmod 0777 $DIR/$tdir
1808         TESTFILE="$DIR/$tdir/$tfile-0"
1809         rm -f $TESTFILE
1810         local bs_unit=$((1024*1024))
1811         LIMIT=$1
1812
1813         wait_delete_completed
1814
1815         # test for user
1816         log "  User quota (limit: $LIMIT kbytes)"
1817         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
1818         sleep 3
1819         quota_show_check b u $TSTUSR
1820
1821         $LFS setstripe $TESTFILE -c 1
1822         chown $TSTUSR.$TSTUSR $TESTFILE
1823
1824         log "    Step1: trigger quota with 0_DIRECT"
1825         log "      Write half of file"
1826         $RUNAS $DIRECTIO write $TESTFILE 0 $(($LIMIT/1024/2)) $bs_unit || quota_error u $TSTUSR "(1) write failure, but expect success: $LIMIT"
1827         log "      Write out of block quota ..."
1828         $RUNAS $DIRECTIO write $TESTFILE $(($LIMIT/1024/2)) $(($LIMIT/1024/2)) $bs_unit && quota_error u $TSTUSR "(2) write success, but expect EDQUOT: $LIMIT"
1829         log "    Step1: done"
1830
1831         log "    Step2: rewrite should succeed"
1832         $RUNAS $DIRECTIO write $TESTFILE 0 1 $bs_unit || quota_error u $TSTUSR "(3) write failure, but expect success: $LIMIT"
1833         log "    Step2: done"
1834
1835         rm -f $TESTFILE
1836         wait_delete_completed
1837         OST0_UUID=`do_facet ost1 $LCTL dl | grep -m1 obdfilter | awk '{print $((NF-1))}'`
1838         OST0_QUOTA_USED=`getquota -u $TSTUSR $OST0_UUID curspace`
1839         echo $OST0_QUOTA_USED
1840         [ $OST0_QUOTA_USED -ne 0 ] && \
1841             ($SHOW_QUOTA_USER; quota_error u $TSTUSR "quota deleted isn't released")
1842         $SHOW_QUOTA_USER
1843         resetquota -u $TSTUSR
1844 }
1845
1846 test_23() {
1847         log "run for $((OSTCOUNT * 3))MB test file"
1848         test_23_sub $((OSTCOUNT * 3 * 1024))
1849
1850         OST0_MIN=120000
1851         check_whether_skip && return 0
1852         log "run for $((OSTCOUNT * 30))MB test file"
1853         test_23_sub $((OSTCOUNT * 30 * 1024))
1854 }
1855 run_test_with_stat 23 "run for fixing bug16125 ==========="
1856
1857 test_24() {
1858         local TESTFILE="$DIR/$tdir/$tfile"
1859         mkdir -p $DIR/$tdir
1860
1861         run_to_block_limit $TESTFILE
1862         $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1863
1864         # cleanup
1865         rm -f $TESTFILE
1866         resetquota -u $TSTUSR
1867
1868         set_blk_unitsz $((128 * 1024))
1869         set_blk_tunesz $((128 * 1024 / 2))
1870         
1871 }
1872 run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ==========="
1873
1874 show_quota() {
1875         if [ $1 = "-u" ]; then
1876                 if [ $2 = "$TSTUSR" ]; then
1877                         $SHOW_QUOTA_USER
1878                 else
1879                         $SHOW_QUOTA_USER2
1880                 fi
1881         else
1882                 if [ $2 = "$TSTUSR" ]; then
1883                         $SHOW_QUOTA_GROUP
1884                 else
1885                         $SHOW_QUOTA_GROUP2
1886                 fi
1887         fi
1888 }
1889
1890 test_25_sub() {
1891         mkdir -p $DIR/$tdir
1892         chmod 0777 $DIR/$tdir
1893         TESTFILE="$DIR/$tdir/$tfile-0"
1894         rm -f $TESTFILE
1895         LIMIT=$(( $BUNIT_SZ * ($OSTCOUNT + 1) + 4096 ))
1896
1897         wait_delete_completed
1898
1899         # set quota for $TSTUSR
1900         log "setquota for $TSTUSR"
1901         $LFS setquota $1 $TSTUSR -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1902         sleep 3
1903         if [ "$1" == "-u" ]; then
1904                 quota_show_check a u $TSTUSR
1905         else
1906                 quota_show_check a g $TSTUSR
1907         fi
1908
1909         # set quota for $TSTUSR2
1910         log "setquota for $TSTUSR2"
1911         $LFS setquota $1 $TSTUSR2 -b $LIMIT -B $LIMIT -i 10 -I 10 $DIR
1912         sleep 3
1913         if [ "$1" == "-u" ]; then
1914                 quota_show_check a u $TSTUSR2
1915         else
1916                 quota_show_check a g $TSTUSR2
1917         fi
1918
1919         # set stripe index to 0
1920         log "setstripe for $DIR/$tdir to 0"
1921         $LFS setstripe $DIR/$tdir -c 1 -i 0
1922
1923         # interop 18 <-> 20
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))}'`
1927
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`
1932
1933         # TSTUSR write 4M
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"
1936         sync
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]"
1946
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"
1951         else
1952                 log "chgrp from $TSTUSR to $TSTUSR2"
1953                 chgrp $TSTUSR2 $TESTFILE || quota_error g $TSTUSR2 "chgrp failed"
1954         fi
1955         sync
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]"
1973
1974         rm -f $TESTFILE
1975         wait_delete_completed
1976         resetquota $1 $TSTUSR
1977         resetquota $1 $TSTUSR2
1978 }
1979
1980 test_25() {
1981         log "run for chown case"
1982         test_25_sub -u
1983
1984         log "run for chgrp case"
1985         test_25_sub -g
1986 }
1987 run_test_with_stat 25 "test whether quota usage is transfered when chown/chgrp (18081) ==========="
1988
1989 test_26() {
1990         mkdir -p $DIR/$tdir
1991         chmod 0777 $DIR/$tdir
1992         TESTFILE="$DIR/$tdir/$tfile-0"
1993         TESTFILE2="$DIR/$tdir/$tfile-1"
1994         set_blk_tunesz 512
1995         set_blk_unitsz 1024
1996
1997         wait_delete_completed
1998
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
2003         sleep 3
2004         quota_show_check b u $TSTUSR
2005
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
2010
2011         #define OBD_FAIL_QUOTA_DELAY_REL         0xA03
2012         lustre_fail ost 0xA03
2013
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..."
2017         rm -f $TESTFILE
2018
2019
2020         wait_delete_completed
2021
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..."
2025         rm -f $TESTFILE2
2026
2027         lustre_fail ost 0
2028         set_blk_unitsz $((128 * 1024))
2029         set_blk_tunesz $((128 * 1024 / 2))
2030         resetquota -u $TSTUSR
2031 }
2032 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
2033
2034 test_27a() {
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"
2037         return 0
2038 }
2039 run_test_with_stat 27a "lfs quota/setquota should handle wrong arguments (19612) ================="
2040
2041 test_27b() {
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
2050         return 0
2051 }
2052 run_test 27b "lfs quota/setquota should handle user/group ID (20200) ================="
2053
2054 test_28() {
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
2058         $SHOW_QUOTA_USER
2059
2060         echo "Step 2: reset system ..."
2061         cleanup_and_setup_lustre
2062         test_0
2063
2064         echo "Step 3: change qunit for user [$TSTUSR:512:1024]"
2065         set_blk_tunesz 512
2066         set_blk_unitsz 1024
2067
2068         wait_delete_completed
2069
2070         #define OBD_FAIL_QUOTA_RET_QDATA | OBD_FAIL_ONCE
2071         lustre_fail ost 0x80000A02
2072
2073         TESTFILE="$DIR/$tdir/$tfile"
2074         mkdir -p $DIR/$tdir
2075
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
2079         $SHOW_QUOTA_USER
2080
2081         touch $TESTFILE
2082         chown $TSTUSR.$TSTUSR $TESTFILE
2083
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"
2087         $SHOW_QUOTA_USER
2088
2089         rm -f $TESTFILE
2090         sync; sleep 3; sync;
2091
2092         # make qd_count 64 bit
2093         lustre_fail ost 0
2094
2095         set_blk_unitsz $((128 * 1024))
2096         set_blk_tunesz $((128 * 1024 / 2))
2097
2098         resetquota -u $TSTUSR
2099 }
2100 run_test_with_stat 28 "test for consistency for qunit when setquota (18574) ==========="
2101
2102 at_max_enforce()
2103 {
2104         local timeout="$1"
2105         # flush AT history, enforce at_max immediately
2106         do_facet mgs "lctl conf_param $FSNAME.sys.at_max=$timeout"
2107         cleanupall
2108         setupall
2109         test_0
2110 }
2111
2112 test_29()
2113 {
2114         local BLK_LIMIT=$((100 * 1024 * 1024)) # 100G
2115         local newtimeo=10 # the default ptlrpc AT value
2116         local oldtimeo
2117         local pid
2118
2119         if at_is_enabled; then
2120                 oldtimeo=$(at_max_get client)
2121                 at_max_enforce $newtimeo
2122         else
2123                 oldtimeo=$(lctl get_param -n timeout)
2124                 lctl set_param timeout=$newtimeo
2125         fi
2126
2127         #define OBD_FAIL_MDS_QUOTACTL_NET 0x12e
2128         lustre_fail mds 0x12e
2129
2130         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I 0 $DIR & pid=$!
2131
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"
2137
2138         lustre_fail mds 0
2139
2140         if at_is_enabled; then
2141                 at_max_enforce $oldtimeo
2142         else
2143                 lctl set_param timeout=$oldtimeo
2144         fi
2145
2146         resetquota -u $TSTUSR
2147 }
2148 run_test_with_stat 29 "unhandled quotactls must not hang lustre client (19778) ========"
2149
2150 test_30()
2151 {
2152         local output
2153         local LIMIT=1024
2154         local TESTFILE="$DIR/$tdir/$tfile"
2155         local GRACE=10
2156
2157         set_blk_tunesz 512
2158         set_blk_unitsz 1024
2159
2160         mkdir -p $DIR/$tdir
2161         chmod 0777 $DIR/$tdir
2162
2163         $LFS setstripe $TESTFILE -i 0 -c 1
2164         chown $TSTUSR.$TSTUSR $TESTFILE
2165
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
2170         sleep $GRACE
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
2174         $SHOW_QUOTA_USER
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
2178         $SHOW_QUOTA_USER
2179         $RUNAS dd if=/dev/zero of=$TESTFILE conv=notrunc oflag=append bs=1048576 count=1 && error "grace times were reset"
2180         rm -f $TESTFILE
2181         resetquota -u $TSTUSR
2182         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace $MAX_IQ_TIME $DIR
2183
2184         set_blk_unitsz $((128 * 1024))
2185         set_blk_tunesz $((128 * 1024 / 2))
2186 }
2187 run_test_with_stat 30 "hard limit updates should not reset grace times ================"
2188
2189 # test duplicate quota releases b=18630
2190 test_31() {
2191         mkdir -p $DIR/$tdir
2192         chmod 0777 $DIR/$tdir
2193
2194         LIMIT=$(( $BUNIT_SZ * $(($OSTCOUNT + 1)) * 10)) # 10 bunits each sever
2195         TESTFILE="$DIR/$tdir/$tfile-0"
2196         TESTFILE2="$DIR/$tdir/$tfile-1"
2197
2198         wait_delete_completed
2199
2200         log "   User quota (limit: $LIMIT kbytes)"
2201         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR
2202
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
2207
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
2211
2212         #define OBD_FAIL_QUOTA_DELAY_SD      0xA04
2213         #define OBD_FAIL_SOME        0x10000000 /* fail N times */
2214         lustre_fail ost $((0x00000A04 | 0x10000000)) 1
2215
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
2220
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/ {
2225                                if (start) {
2226                                        print;
2227                                }
2228                        }' $TMP/lustre-log-${TESTNAME}.log`
2229         [ "$watchdog" ] && error "$watchdog"
2230         rm -f $TMP/lustre-log-${TESTNAME}.log
2231
2232         lustre_fail ost 0
2233         resetquota -u $TSTUSR
2234 }
2235 run_test_with_stat 31 "test duplicate quota releases ==="
2236
2237 # check hash_cur_bits
2238 check_quota_hash_cur_bits() {
2239         local bits=$1
2240
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)"
2246                 return 1;
2247             fi
2248         done
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)"
2253             return 1;
2254         fi
2255         return 0;
2256 }
2257
2258 # check lqs hash
2259 check_lqs_hash() {
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"
2267                 fi
2268             done
2269         done
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"
2276             fi
2277         done
2278 }
2279
2280 test_32()
2281 {
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
2288
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"
2292         done
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;}
2295
2296         $LFS quotaoff -ug $DIR
2297         $LFS quotacheck -ug $DIR
2298
2299         for user in $SANITY_QUOTA_USERS; do
2300             $LFS setquota -u $user --block-hardlimit 1048576 $DIR
2301         done
2302
2303         check_lqs_hash
2304
2305         for user in $SANITY_QUOTA_USERS; do
2306             resetquota -u $user
2307         done
2308 }
2309 run_test 32 "check lqs hash(bug 21846) =========================================="
2310
2311 #
2312 # run 98 at the end because of reformatall
2313 #
2314
2315 test_98()
2316 {
2317         local num
2318         local user
2319         local missing_users=""
2320
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"
2324         done
2325         [ -n "$missing_users" ] && { skip_env "different uid-s on client and servers, or missing users: $missing_users" ; return 0 ; }
2326
2327         cleanupall
2328         formatall
2329         setupall
2330         quota_set_version 1 # set version before the first quota check
2331         test_0
2332
2333         set_blk_tunesz 2
2334         set_blk_unitsz 4
2335
2336         num=8
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"
2343                 num=$((num + 8))
2344         done
2345
2346         $LFS quotaoff -ug $DIR
2347         quota_set_version 3 2>&1 | grep "Invalid argument" && quota_set_version 2
2348         $LFS quotaon -ug $DIR
2349
2350         num=8
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}
2358                 num=$((num + 8))
2359         done
2360
2361         set_blk_unitsz $((128 * 1024))
2362         set_blk_tunesz $((128 * 1024 / 2))
2363 }
2364 run_test_with_stat 98 "quotaon autoconversion ==============================="
2365
2366 # turn off quota
2367 test_99()
2368 {
2369         $LFS quotaoff $DIR
2370         lctl set_param debug="-quota"
2371
2372         return 0
2373 }
2374 run_test_with_stat 99 "Quota off ==============================="
2375
2376 cd $ORIG_PWD
2377 complete $(basename $0) $SECONDS
2378 check_and_cleanup_lustre
2379 exit_status