Whamcloud - gitweb
LU-1866 osd: ancillary work for initial OI scrub
[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 SRCDIR=`dirname $0`
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
11
12 ONLY=${ONLY:-"$*"}
13 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
17         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
18
19 TMP=${TMP:-/tmp}
20
21 ORIG_PWD=${PWD}
22 TSTID=${TSTID:-60000}
23 TSTID2=${TSTID2:-60001}
24 TSTUSR=${TSTUSR:-"quota_usr"}
25 TSTUSR2=${TSTUSR2:-"quota_2usr"}
26 BLK_SZ=1024
27 MAX_DQ_TIME=604800
28 MAX_IQ_TIME=604800
29
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
32 init_test_env $@
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
34 init_logging
35 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
36
37 require_dsh_mds || exit 0
38 require_dsh_ost || exit 0
39
40 # XXX Once we drop the interoperability with old server (< 2.3.50), the
41 #     sanity-quota-old.sh should be removed.
42 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
43         exec $LUSTRE/tests/sanity-quota-old.sh
44 fi
45
46 # if e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
48         ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
49         skip "e2fsprogs doesn't support quota" && exit 0
50 fi
51
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
53
54 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
55
56 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
57
58 DIR=${DIR:-$MOUNT}
59 DIR2=${DIR2:-$MOUNT2}
60
61 QUOTA_AUTO_OLD=$QUOTA_AUTO
62 export QUOTA_AUTO=0
63
64 check_and_setup_lustre
65
66 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
67 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
68
69 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
70 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
71 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
72 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
73 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
74 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
75 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
76 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
77
78 build_test_filter
79
80 lustre_fail() {
81         local fail_node=$1
82         local fail_loc=$2
83         local fail_val=${3:-0}
84
85         if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
86                 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
87                 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
88         fi
89
90         if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
91                 for num in `seq $OSTCOUNT`; do
92                         do_facet ost$num "lctl set_param fail_val=$fail_val"
93                         do_facet ost$num "lctl set_param fail_loc=$fail_loc"
94                 done
95         fi
96 }
97
98 RUNAS="runas -u $TSTID -g $TSTID"
99 RUNAS2="runas -u $TSTID2 -g $TSTID2"
100 DD="dd if=/dev/zero bs=1M"
101
102 FAIL_ON_ERROR=false
103
104 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
105         error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
106 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
107         error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
108
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 #        resetquota -g groupname
112
113 resetquota() {
114         [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115         [ "$1" != "-u" -a "$1" != "-g" ] &&
116                 error "resetquota: wrong specifier $1 passed"
117
118         $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
119                 error "clear quota for [type:$1 name:$2] failed"
120         # give a chance to slave to release space
121         sleep 1
122 }
123
124 quota_scan() {
125         local LOCAL_UG=$1
126         local LOCAL_ID=$2
127
128         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
129                 $LFS quota -v -u $LOCAL_ID $DIR
130                 log "Files for user ($LOCAL_ID):"
131                 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
132                         xargs stat 2>/dev/null)
133         fi
134
135         if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
136                 $LFS quota -v -u $LOCAL_ID $DIR
137                 log "Files for group ($LOCAL_ID):"
138                 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
139                         xargs stat 2>/dev/null)
140         fi
141 }
142
143 quota_error() {
144         quota_scan $1 $2
145         shift 2
146         error "$*"
147 }
148
149 quota_log() {
150         quota_scan $1 $2
151         shift 2
152         log "$*"
153 }
154
155 # get quota for a user or a group
156 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
157 #                 bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
158 #
159 getquota() {
160         local spec
161         local uuid
162
163         [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
164         [ "$1" != "-u" -a "$1" != "-g" ] &&
165                 error "getquota: wrong u/g specifier $1 passed"
166
167         uuid="$3"
168
169         case "$4" in
170                 curspace)   spec=1;;
171                 bsoftlimit) spec=2;;
172                 bhardlimit) spec=3;;
173                 bgrace)     spec=4;;
174                 curinodes)  spec=5;;
175                 isoftlimit) spec=6;;
176                 ihardlimit) spec=7;;
177                 igrace)     spec=8;;
178                 *)          error "unknown quota parameter $4";;
179         esac
180
181         [ "$uuid" = "global" ] && uuid=$DIR
182
183         $LFS quota -v "$1" "$2" $DIR |
184                 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
185                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
186                 | tr -d "*"
187 }
188
189 # set mdt quota type
190 # usage: set_mdt_qtype ug|u|g|none
191 set_mdt_qtype() {
192         local qtype=$1
193         local varsvc
194         local mdts=$(get_facets MDS)
195         local cmd
196         do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
197         # we have to make sure each MDT received config changes
198         for mdt in ${mdts//,/ }; do
199                 varsvc=${mdt}_svc
200                 cmd="$LCTL get_param -n "
201                 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
202                 cmd=${cmd}.quota_slave.enabled
203
204                 if $(facet_up $mdt); then
205                         wait_update_facet $mdt "$cmd" "$qtype" || return 1
206                 fi
207         done
208         return 0
209 }
210
211 # set ost quota type
212 # usage: set_ost_qtype ug|u|g|none
213 set_ost_qtype() {
214         local qtype=$1
215         local varsvc
216         local osts=$(get_facets OST)
217         local cmd
218         do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
219         # we have to make sure each OST received config changes
220         for ost in ${osts//,/ }; do
221                 varsvc=${ost}_svc
222                 cmd="$LCTL get_param -n "
223                 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
224                 cmd=${cmd}.quota_slave.enabled
225
226                 if $(facet_up $ost); then
227                         wait_update_facet $ost "$cmd" "$qtype" || return 1
228                 fi
229         done
230         return 0
231 }
232
233 wait_reintegration() {
234         local ntype=$1
235         local qtype=$2
236         local max=$3
237         local result="glb[1],slv[1],reint[0]"
238         local varsvc
239         local cmd
240         local tgts
241
242         if [ $ntype == "mdt" ]; then
243                 tgts=$(get_facets MDS)
244         else
245                 tgts=$(get_facets OST)
246         fi
247
248         for tgt in ${tgts//,/ }; do
249                 varsvc=${tgt}_svc
250                 cmd="$LCTL get_param -n "
251                 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
252                 cmd=${cmd}.quota_slave.info
253
254                 if $(facet_up $tgt); then
255                         wait_update_facet $tgt "$cmd |
256                                 grep "$qtype" | awk '{ print \\\$3 }'" \
257                                         "$result" $max || return 1
258                 fi
259         done
260         return 0
261 }
262
263 wait_mdt_reint() {
264         local qtype=$1
265         local max=${2:-90}
266
267         if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
268                 wait_reintegration "mdt" "user" $max || return 1
269         fi
270
271         if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
272                 wait_reintegration "mdt" "group" $max || return 1
273         fi
274         return 0
275 }
276
277 wait_ost_reint() {
278         local qtype=$1
279         local max=${2:-90}
280
281         if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
282                 wait_reintegration "ost" "user" $max || return 1
283         fi
284
285         if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
286                 wait_reintegration "ost" "group" $max || return 1
287         fi
288         return 0
289 }
290
291 setup_quota_test() {
292         rm -rf $DIR/$tdir
293         wait_delete_completed
294         echo "Creating test directory"
295         mkdir -p $DIR/$tdir
296         chmod 0777 $DIR/$tdir
297         # always clear fail_loc in case of fail_loc isn't cleared
298         # properly when previous test failed
299         lustre_fail mds_ost 0
300 }
301
302 cleanup_quota_test() {
303         trap 0
304         echo "Delete files..."
305         rm -rf $DIR/$tdir
306         echo "Wait for unlink objects finished..."
307         wait_delete_completed
308         sync_all_data || true
309 }
310
311 quota_show_check() {
312         local bf=$1
313         local ug=$2
314         local qid=$3
315         local usage
316
317         $LFS quota -v -$ug $qid $DIR
318
319         if [ "$bf" == "a" -o "$bf" == "b" ]; then
320                 usage=$(getquota -$ug $qid global curspace)
321                 if [ -z $usage ]; then
322                         quota_error $ug $qid \
323                                 "Query block quota failed ($ug:$qid)."
324                 else
325                         [ $usage -ne 0 ] && quota_log $ug $qid \
326                                 "Block quota isn't 0 ($ug:$qid:$usage)."
327                 fi
328         fi
329
330         if [ "$bf" == "a" -o "$bf" == "f" ]; then
331                 usage=$(getquota -$ug $qid global curinodes)
332                 if [ -z $usage ]; then
333                         quota_error $ug $qid \
334                                 "Query file quota failed ($ug:$qid)."
335                 else
336                         [ $usage -ne 0 ] && quota_log $ug $qid \
337                                 "File quota isn't 0 ($ug:$qid:$usage)."
338                 fi
339         fi
340 }
341
342 # enable quota debug
343 quota_init() {
344         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
345 }
346 quota_init
347
348 resetquota -u $TSTUSR
349 resetquota -g $TSTUSR
350 resetquota -u $TSTUSR2
351 resetquota -g $TSTUSR2
352
353 test_quota_performance() {
354         local TESTFILE="$DIR/$tdir/$tfile-0"
355         local size=$1 # in MB
356         local stime=$(date +%s)
357         $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
358                 quota_error u $TSTUSR "write failure"
359         local etime=$(date +%s)
360         delta=$((etime - stime))
361         if [ $delta -gt 0 ]; then
362             rate=$((size * 1024 / delta))
363             [ $rate -gt 1024 ] ||
364                 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
365         fi
366         rm -f $TESTFILE
367 }
368
369 # test basic quota performance b=21696
370 test_0() {
371         local MB=100 # 100M
372         [ "$SLOW" = "no" ] && MB=10
373
374         local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
375         [ $free_space -le $((MB * 1024)) ] &&
376                 skip "not enough space ${free_space} KB, " \
377                         "required $((MB * 1024)) KB" && return
378         setup_quota_test
379         trap cleanup_quota_test EXIT
380
381         set_ost_qtype "none" || error "disable ost quota failed"
382         test_quota_performance $MB
383
384         set_ost_qtype "ug" || error "enable ost quota failed"
385         $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
386                 error "set quota failed"
387         test_quota_performance $MB
388
389         cleanup_quota_test
390         resetquota -u $TSTUSR
391 }
392 run_test 0 "Test basic quota performance"
393
394 # test block hardlimit
395 test_1() {
396         local LIMIT=10  # 10M
397         local TESTFILE="$DIR/$tdir/$tfile-0"
398
399         setup_quota_test
400         trap cleanup_quota_test EXIT
401
402         # enable ost quota
403         set_ost_qtype "ug" || "enable ost quota failed"
404
405         # test for user
406         log "User quota (block hardlimit:$LIMIT MB)"
407         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
408                 error "set user quota failed"
409
410         # make sure the system is clean
411         local USED=$(getquota -u $TSTUSR global curspace)
412         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
413
414         $LFS setstripe $TESTFILE -c 1
415         chown $TSTUSR.$TSTUSR $TESTFILE
416
417         log "Write..."
418         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
419                 quota_error u $TSTUSR "user write failure, but expect success"
420         log "Write out of block quota ..."
421         # this time maybe cache write,  ignore it's failure
422         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
423         # flush cache, ensure noquota flag is set on client
424         cancel_lru_locks osc
425         $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
426                 quota_error u $TSTUSR "user write success, but expect EDQUOT"
427
428         rm -f $TESTFILE
429         wait_delete_completed
430         sync_all_data || true
431         USED=$(getquota -u $TSTUSR global curspace)
432         [ $USED -ne 0 ] && quota_error u $TSTUSR \
433                 "user quota isn't released after deletion"
434         resetquota -u $TSTUSR
435
436         # test for group
437         log "--------------------------------------"
438         log "Group quota (block hardlimit:$LIMIT MB)"
439         $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
440                 error "set group quota failed"
441
442         TESTFILE="$DIR/$tdir/$tfile-1"
443         # make sure the system is clean
444         USED=$(getquota -g $TSTUSR global curspace)
445         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
446
447         $LFS setstripe $TESTFILE -c 1
448         chown $TSTUSR.$TSTUSR $TESTFILE
449
450         log "Write ..."
451         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
452                 quota_error g $TSTUSR "group write failure, but expect success"
453         log "Write out of block quota ..."
454         # this time maybe cache write, ignore it's failure
455         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
456         cancel_lru_locks osc
457         $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
458                 quota_error g $TSTUSR "group write success, but expect EDQUOT"
459
460         # cleanup
461         cleanup_quota_test
462
463         USED=$(getquota -g $TSTUSR global curspace)
464         [ $USED -ne 0 ] && quota_error g $TSTUSR \
465                 "group quota isn't released after deletion"
466
467         resetquota -g $TSTUSR
468 }
469 run_test 1 "Block hard limit (normal use and out of quota)"
470
471 # test inode hardlimit
472 test_2() {
473         local LIMIT=$((1024 * 1024)) # 1M inodes
474         local TESTFILE="$DIR/$tdir/$tfile-0"
475
476         [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
477
478         local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
479         [ $FREE_INODES -lt $LIMIT ] &&
480                 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
481                 return
482
483         setup_quota_test
484         trap cleanup_quota_test EXIT
485
486         # enable mdt quota
487         set_mdt_qtype "ug" || "enable mdt quota failed"
488
489         # test for user
490         log "User quota (inode hardlimit:$LIMIT files)"
491         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
492                 error "set user quota failed"
493
494         # make sure the system is clean
495         local USED=$(getquota -u $TSTUSR global curinodes)
496         [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
497
498         log "Create $LIMIT files ..."
499         $RUNAS createmany -m ${TESTFILE} $LIMIT || \
500                 quota_error u $TSTUSR "user create failure, but expect success"
501         log "Create out of file quota ..."
502         $RUNAS touch ${TESTFILE}_xxx && \
503                 quota_error u $TSTUSR "user create success, but expect EDQUOT"
504
505         # cleanup
506         unlinkmany ${TESTFILE} $LIMIT
507         rm -f ${TESTFILE}_xxx
508         wait_delete_completed
509
510         USED=$(getquota -u $TSTUSR global curinodes)
511         [ $USED -ne 0 ] && quota_error u $TSTUSR \
512                 "user quota isn't released after deletion"
513         resetquota -u $TSTUSR
514
515         # test for group
516         log "--------------------------------------"
517         log "Group quota (inode hardlimit:$LIMIT files)"
518         $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
519                 error "set group quota failed"
520
521         TESTFILE=$DIR/$tdir/$tfile-1
522         # make sure the system is clean
523         USED=$(getquota -g $TSTUSR global curinodes)
524         [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
525
526         log "Create $LIMIT files ..."
527         $RUNAS createmany -m ${TESTFILE} $LIMIT ||
528                 quota_error g $TSTUSR "group create failure, but expect success"
529         log "Create out of file quota ..."
530         $RUNAS touch ${TESTFILE}_xxx && \
531                 quota_error g $TSTUSR "group create success, but expect EDQUOT"
532
533         # cleanup
534         unlinkmany ${TESTFILE} $LIMIT
535         rm -f ${TESTFILE}_xxx
536         wait_delete_completed
537
538         USED=$(getquota -g $TSTUSR global curinodes)
539         [ $USED -ne 0 ] && quota_error g $TSTUSR \
540                 "user quota isn't released after deletion"
541
542         cleanup_quota_test
543         resetquota -g $TSTUSR
544 }
545 run_test 2 "File hard limit (normal use and out of quota)"
546
547 test_block_soft() {
548         local TESTFILE=$1
549         local TIMER=$(($2 * 3 / 2))
550         local LIMIT=$3
551         local OFFSET=0
552
553         setup_quota_test
554         trap cleanup_quota_test EXIT
555
556         $LFS setstripe $TESTFILE -c 1 -i 0
557         chown $TSTUSR.$TSTUSR $TESTFILE
558
559         echo "Write up to soft limit"
560         $RUNAS $DD of=$TESTFILE count=$LIMIT ||
561                 quota_error a $TSTUSR "write failure, but expect success"
562         OFFSET=$((LIMIT * 1024))
563         cancel_lru_locks osc
564
565         echo "Write to exceed soft limit"
566         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
567                 quota_error a $TSTUSR "write failure, but expect success"
568         OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
569         cancel_lru_locks osc
570
571         $SHOW_QUOTA_USER
572         $SHOW_QUOTA_GROUP
573         $SHOW_QUOTA_INFO_USER
574         $SHOW_QUOTA_INFO_GROUP
575
576         echo "Write before timer goes off"
577         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
578                 quota_error a $TSTUSR "write failure, but expect success"
579         OFFSET=$((OFFSET + 1024))
580         cancel_lru_locks osc
581
582         echo "Sleep $TIMER seconds ..."
583         sleep $TIMER
584
585         $SHOW_QUOTA_USER
586         $SHOW_QUOTA_GROUP
587         $SHOW_QUOTA_INFO_USER
588         $SHOW_QUOTA_INFO_GROUP
589
590         echo "Write after timer goes off"
591         # maybe cache write, ignore.
592         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
593         OFFSET=$((OFFSET + 1024))
594         cancel_lru_locks osc
595         $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
596                 quota_error a $TSTUSR "write success, but expect EDQUOT"
597
598         $SHOW_QUOTA_USER
599         $SHOW_QUOTA_GROUP
600         $SHOW_QUOTA_INFO_USER
601         $SHOW_QUOTA_INFO_GROUP
602
603         echo "Unlink file to stop timer"
604         rm -f $TESTFILE
605         wait_delete_completed
606         sync_all_data || true
607
608         $SHOW_QUOTA_USER
609         $SHOW_QUOTA_GROUP
610         $SHOW_QUOTA_INFO_USER
611         $SHOW_QUOTA_INFO_GROUP
612
613         $LFS setstripe $TESTFILE -c 1 -i 0
614         chown $TSTUSR.$TSTUSR $TESTFILE
615
616         echo "Write ..."
617         $RUNAS $DD of=$TESTFILE count=$LIMIT ||
618                 quota_error a $TSTUSR "write failure, but expect success"
619         # cleanup
620         cleanup_quota_test
621 }
622
623 # block soft limit
624 test_3() {
625         local LIMIT=1  # 1MB
626         local GRACE=10 # 10s
627         local TESTFILE=$DIR/$tdir/$tfile-0
628
629         set_ost_qtype "ug" || error "enable ost quota failed"
630
631         echo "User quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
632         # make sure the system is clean
633         local USED=$(getquota -u $TSTUSR global curspace)
634         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
635
636         $LFS setquota -t -u --block-grace $GRACE --inode-grace \
637                 $MAX_IQ_TIME $DIR || error "set user grace time failed"
638         $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
639                 error "set user quota failed"
640
641         test_block_soft $TESTFILE $GRACE $LIMIT
642         resetquota -u $TSTUSR
643
644         echo "Group quota (soft limit:$LIMIT MB  grace:$GRACE seconds)"
645         TESTFILE=$DIR/$tdir/$tfile-1
646         # make sure the system is clean
647         USED=$(getquota -g $TSTUSR global curspace)
648         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
649
650         $LFS setquota -t -g --block-grace $GRACE --inode-grace \
651                 $MAX_IQ_TIME $DIR || error "set group grace time failed"
652         $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
653                 error "set group quota failed"
654
655         test_block_soft $TESTFILE $GRACE $LIMIT
656         resetquota -g $TSTUSR
657
658         # cleanup
659         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
660                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
661         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
662                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
663 }
664 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
665
666 test_file_soft() {
667         local TESTFILE=$1
668         local LIMIT=$2
669         local TIMER=$(($3 * 3 / 2))
670
671         setup_quota_test
672         trap cleanup_quota_test EXIT
673
674         echo "Create files to exceed soft limit"
675         $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
676                 quota_error a $TSTUSR "create failure, but expect success"
677         sync; sleep 1; sync
678
679         echo "Create file before timer goes off"
680         $RUNAS touch ${TESTFILE}_before ||
681                 quota_error a $TSTUSR "failed create before timer expired," \
682                         "but expect success"
683         sync; sleep 1; sync
684
685         echo "Sleep $TIMER seconds ..."
686         sleep $TIMER
687
688         $SHOW_QUOTA_USER
689         $SHOW_QUOTA_GROUP
690         $SHOW_QUOTA_INFO_USER
691         $SHOW_QUOTA_INFO_GROUP
692
693         echo "Create file after timer goes off"
694         # There is a window that space is accounted in the quota usage but
695         # hasn't been decreased from the pending write, if we acquire quota
696         # in this window, we'll acquire more than we needed.
697         $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
698         sync; sleep 1; sync
699         $RUNAS touch ${TESTFILE}_after_3 &&
700                 quota_error a $TSTUSR "create after timer expired," \
701                         "but expect EDQUOT"
702         sync; sleep 1; sync
703
704         $SHOW_QUOTA_USER
705         $SHOW_QUOTA_GROUP
706         $SHOW_QUOTA_INFO_USER
707         $SHOW_QUOTA_INFO_GROUP
708
709         echo "Unlink files to stop timer"
710         find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
711         wait_delete_completed
712
713         echo "Create file"
714         $RUNAS touch ${TESTFILE}_xxx ||
715                 quota_error a $TSTUSR "touch after timer stop failure," \
716                         "but expect success"
717         sync; sleep 1; sync
718
719         # cleanup
720         cleanup_quota_test
721 }
722
723 # file soft limit
724 test_4a() {
725         local LIMIT=10 # inodes
726         local TESTFILE=$DIR/$tdir/$tfile-0
727         local GRACE=5
728
729         set_mdt_qtype "ug" || error "enable mdt quota failed"
730
731         echo "User quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
732         # make sure the system is clean
733         local USED=$(getquota -u $TSTUSR global curinodes)
734         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
735
736         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
737                 $GRACE $DIR || error "set user grace time failed"
738         $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
739                 error "set user quota failed"
740
741         test_file_soft $TESTFILE $LIMIT $GRACE
742         resetquota -u $TSTUSR
743
744         echo "Group quota (soft limit:$LIMIT files  grace:$GRACE seconds)"
745         # make sure the system is clean
746         USED=$(getquota -g $TSTUSR global curinodes)
747         [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
748
749         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
750                 $GRACE $DIR || error "set group grace time failed"
751         $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
752                 error "set group quota failed"
753         TESTFILE=$DIR/$tdir/$tfile-1
754
755         test_file_soft $TESTFILE $LIMIT $GRACE
756         resetquota -g $TSTUSR
757
758         # cleanup
759         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
760                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
761         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
762                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
763 }
764 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
765
766 test_4b() {
767         local GR_STR1="1w3d"
768         local GR_STR2="1000s"
769         local GR_STR3="5s"
770         local GR_STR4="1w2d3h4m5s"
771         local GR_STR5="5c"
772         local GR_STR6="1111111111111111"
773
774         wait_delete_completed
775
776         # test of valid grace strings handling
777         echo "Valid grace strings test"
778         $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
779                 $GR_STR2 $DIR || error "set user grace time failed"
780         $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
781         $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
782                 $GR_STR4 $DIR || error "set group grace time quota failed"
783         $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
784
785         # test of invalid grace strings handling
786         echo "  Invalid grace strings test"
787         ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
788         ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
789
790         # cleanup
791         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
792                 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
793         $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
794                 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
795 }
796 run_test 4b "Grace time strings handling"
797
798 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
799 test_5() {
800         local BLIMIT=10 # 10M
801         local ILIMIT=10 # 10 inodes
802
803         setup_quota_test
804         trap cleanup_quota_test EXIT
805
806         set_mdt_qtype "ug" || error "enable mdt quota failed"
807         set_ost_qtype "ug" || error "enable ost quota failed"
808
809         echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
810         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
811                 error "set user quota failed"
812         $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
813                 error "set group quota failed"
814
815         # make sure the system is clean
816         local USED=$(getquota -u $TSTUSR global curinodes)
817         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
818         USED=$(getquota -g $TSTUSR global curinodes)
819         [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
820         USED=$(getquota -u $TSTUSR global curspace)
821         [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
822         USED=$(getquota -g $TSTUSR global curspace)
823         [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
824
825         echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
826         createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
827                 error "create failure, expect success"
828         $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
829                 error "write failure, expect success"
830
831         echo "Chown files to $TSTUSR.$TSTUSR ..."
832         for i in `seq 0 $ILIMIT`; do
833                 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
834                         quota_error a $TSTUSR "chown failure, expect success"
835         done
836
837         # cleanup
838         unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
839         cleanup_quota_test
840
841         resetquota -u $TSTUSR
842         resetquota -g $TSTUSR
843 }
844 run_test 5 "Chown & chgrp successfully even out of block/file quota"
845
846 # test dropping acquire request on master
847 test_6() {
848         local LIMIT=3 # 3M
849
850         setup_quota_test
851         trap cleanup_quota_test EXIT
852
853         # make sure the system is clean
854         local USED=$(getquota -u $TSTUSR global curspace)
855         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
856
857         # make sure no granted quota on ost
858         set_ost_qtype "ug" || error "enable ost quota failed"
859         resetquota -u $TSTUSR
860
861         # create file for $TSTUSR
862         local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
863         $LFS setstripe $TESTFILE -c 1 -i 0
864         chown $TSTUSR.$TSTUSR $TESTFILE
865
866         # create file for $TSTUSR2
867         local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
868         $LFS setstripe $TESTFILE2 -c 1 -i 0
869         chown $TSTUSR2.$TSTUSR2 $TESTFILE2
870
871         # cache per-ID lock for $TSTUSR on slave
872         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
873                 error "set quota failed"
874         $RUNAS $DD of=$TESTFILE count=1 ||
875                 error "write $TESTFILE failure, expect success"
876         $RUNAS2 $DD of=$TESTFILE2 count=1 ||
877                 error "write $TESTFILE2 failure, expect success"
878         sync; sync
879         sync_all_data || true
880
881         #define QUOTA_DQACQ 601
882         #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
883         lustre_fail mds 0x513 601
884
885         # write to un-enforced ID ($TSTUSR2) should succeed
886         $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
887                 error "write failure, expect success"
888
889         # write to enforced ID ($TSTUSR) in background, exceeding limit
890         # to make sure DQACQ is sent
891         $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
892         DDPID=$!
893
894         # watchdog timer uses a factor of 2
895         echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
896         sleep $((TIMEOUT * 2 + 1))
897
898         # write should be blocked and never finished
899         if ! ps -p $DDPID  > /dev/null 2>&1; then
900                 lustre_fail mds 0 0
901                 error "write finished incorrectly!"
902         fi
903
904         lustre_fail mds 0 0
905
906         # no watchdog is triggered
907         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
908         watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
909                        /Service thread pid/ && /was inactive/ {
910                                if (start) {
911                                        print;
912                                }
913                        }' $TMP/lustre-log-${TESTNAME}.log)
914         [ -z "$watchdog" ] || error "$watchdog"
915
916         rm -f $TMP/lustre-log-${TESTNAME}.log
917
918         # write should continue & succeed
919         local count=0
920         while [ true ]; do
921                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
922                 if [ $count -ge 120 ]; then
923                         quota_error u $TSTUSR "dd not finished in $count secs"
924                 fi
925                 count=$((count + 1))
926                 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
927                 sleep 1
928         done
929
930         cleanup_quota_test
931         resetquota -u $TSTUSR
932 }
933 run_test 6 "Test dropping acquire request on master"
934
935 # quota reintegration (global index)
936 test_7a() {
937         local TESTFILE=$DIR/$tdir/$tfile
938         local LIMIT=20 # 20M
939
940         [ "$SLOW" = "no" ] && LIMIT=5
941
942         setup_quota_test
943         trap cleanup_quota_test EXIT
944
945         # make sure the system is clean
946         local USED=$(getquota -u $TSTUSR global curspace)
947         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
948
949         # make sure no granted quota on ost1
950         set_ost_qtype "ug" || error "enable ost quota failed"
951         resetquota -u $TSTUSR
952         set_ost_qtype "none" || error "disable ost quota failed"
953
954         local OSTUUID=$(ostuuid_from_index 0)
955         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
956         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
957                 "$TSTUSR isn't 0."
958
959         # create test file
960         $LFS setstripe $TESTFILE -c 1 -i 0
961         chown $TSTUSR.$TSTUSR $TESTFILE
962
963         echo "Stop ost1..."
964         stop ost1
965
966         echo "Enable quota & set quota limit for $TSTUSR"
967         set_ost_qtype "ug" || error "enable ost quota failed"
968         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
969                 error "set quota failed"
970
971         echo "Start ost1..."
972         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
973         quota_init
974
975         wait_ost_reint "ug" || error "reintegration failed"
976
977         # hardlimit should have been fetched by slave during global
978         # reintegration, write will exceed quota
979         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
980                 quota_error u $TSTUSR "write success, but expect EDQUOT"
981
982         rm -f $TESTFILE
983         wait_delete_completed
984         sync_all_data || true
985         sleep 3
986
987         echo "Stop ost1..."
988         stop ost1
989
990         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
991                 error "clear quota failed"
992
993         echo "Start ost1..."
994         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
995         quota_init
996
997         wait_ost_reint "ug" || error "reintegration failed"
998
999         # hardlimit should be cleared on slave during reintegration
1000         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1001                 quota_error u $TSTUSR "write error, but expect success"
1002
1003         cleanup_quota_test
1004         resetquota -u $TSTUSR
1005 }
1006 run_test 7a "Quota reintegration (global index)"
1007
1008 # quota reintegration (slave index)
1009 test_7b() {
1010         local LIMIT="100G"
1011         local TESTFILE=$DIR/$tdir/$tfile
1012
1013         setup_quota_test
1014         trap cleanup_quota_test EXIT
1015
1016         # make sure the system is clean
1017         local USED=$(getquota -u $TSTUSR global curspace)
1018         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1019
1020         # make sure no granted quota on ost1
1021         set_ost_qtype "ug" || error "enable ost quota failed"
1022         resetquota -u $TSTUSR
1023         set_ost_qtype "none" || error "disable ost quota failed"
1024
1025         local OSTUUID=$(ostuuid_from_index 0)
1026         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1027         [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1028                 "$TSTUSR isn't 0."
1029
1030         # create test file
1031         $LFS setstripe $TESTFILE -c 1 -i 0
1032         chown $TSTUSR.$TSTUSR $TESTFILE
1033
1034         # consume some space to make sure the granted space will not
1035         # be released during reconciliation
1036         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1037                 error "consume space failure, expect success"
1038
1039         # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1040         lustre_fail mds 0xa02
1041
1042         set_ost_qtype "ug" || error "enable ost quota failed"
1043         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1044                 error "set quota failed"
1045
1046         # ignore the write error
1047         $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1048
1049         local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1050
1051         lustre_fail mds 0
1052
1053         echo "Restart ost to trigger reintegration..."
1054         stop ost1
1055         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1056         quota_init
1057
1058         wait_ost_reint "ug" || error "reintegration failed"
1059
1060         USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1061         [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1062
1063         cleanup_quota_test
1064         resetquota -u $TSTUSR
1065         $SHOW_QUOTA_USER
1066 }
1067 run_test 7b "Quota reintegration (slave index)"
1068
1069 # quota reintegration (restart mds during reintegration)
1070 test_7c() {
1071         local LIMIT=20 # 20M
1072         local TESTFILE=$DIR/$tdir/$tfile
1073
1074         [ "$SLOW" = "no" ] && LIMIT=5
1075
1076         setup_quota_test
1077         trap cleanup_quota_test EXIT
1078
1079         # make sure the system is clean
1080         local USED=$(getquota -u $TSTUSR global curspace)
1081         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1082
1083         set_ost_qtype "none" || error "disable ost quota failed"
1084         $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1085                 error "set quota failed"
1086
1087         # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1088         lustre_fail ost 0xa03
1089
1090         # enable ost quota
1091         set_ost_qtype "ug" || error "enable ost quota failed"
1092         # trigger reintegration
1093         local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1094         procf=${procf}quota_slave.force_reint
1095         $LCTL set_param $procf=1 || "force reintegration failed"
1096
1097         echo "Stop mds..."
1098         stop mds1
1099
1100         lustre_fail ost 0
1101
1102         echo "Start mds..."
1103         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1104         quota_init
1105
1106         # wait longer than usual to make sure the reintegration
1107         # is triggered by quota wb thread.
1108         wait_ost_reint "ug" 200 || error "reintegration failed"
1109
1110         # hardlimit should have been fetched by slave during global
1111         # reintegration, write will exceed quota
1112         $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1113                 quota_error u $TSTUSR "write success, but expect EDQUOT"
1114
1115         cleanup_quota_test
1116         resetquota -u $TSTUSR
1117 }
1118 run_test 7c "Quota reintegration (restart mds during reintegration)"
1119
1120 # Quota reintegration (Transfer index in multiple bulks)
1121 test_7d(){
1122         local TESTFILE=$DIR/$tdir/$tfile
1123         local TESTFILE1="$DIR/$tdir/$tfile"-1
1124         local limit=20 #20M
1125
1126         setup_quota_test
1127         trap cleanup_quota_test EXIT
1128
1129         set_ost_qtype "none" || error "disable ost quota failed"
1130         $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1131                 error "set quota for $TSTUSR failed"
1132         $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1133                 error "set quota for $TSTUSR2 failed"
1134
1135         #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1136         lustre_fail mds 0x608 0
1137
1138         # enable quota to tirgger reintegration
1139         set_ost_qtype "u" || error "enable ost quota failed"
1140         wait_ost_reint "u" || error "reintegration failed"
1141
1142         lustre_fail mds 0
1143
1144         # hardlimit should have been fetched by slave during global
1145         # reintegration, write will exceed quota
1146         $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1147                 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1148
1149         $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1150                 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1151
1152         cleanup_quota_test
1153         resetquota -u $TSTUSR
1154         resetquota -u $TSTUSR2
1155 }
1156 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1157
1158 # quota reintegration (inode limits)
1159 test_7e() {
1160         [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1161
1162         local ilimit=$((1024 * 2)) # 2k inodes
1163         local TESTFILE=$DIR/${tdir}-1/$tfile
1164
1165         setup_quota_test
1166         trap cleanup_quota_test EXIT
1167
1168         # make sure the system is clean
1169         local USED=$(getquota -u $TSTUSR global curinodes)
1170         [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1171
1172         # make sure no granted quota on mdt1
1173         set_mdt_qtype "ug" || error "enable mdt quota failed"
1174         resetquota -u $TSTUSR
1175         set_mdt_qtype "none" || error "disable mdt quota failed"
1176
1177         local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1178         USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1179         [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1180                 "$TSTUSR isn't 0."
1181
1182         echo "Stop mds${MDSCOUNT}..."
1183         stop mds${MDSCOUNT}
1184
1185         echo "Enable quota & set quota limit for $TSTUSR"
1186         set_mdt_qtype "ug" || error "enable mdt quota failed"
1187         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit  $DIR ||
1188                 error "set quota failed"
1189
1190         echo "Start mds${MDSCOUNT}..."
1191         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1192         quota_init
1193
1194         wait_mdt_reint "ug" || error "reintegration failed"
1195
1196         echo "create remote dir"
1197         $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1198                 error "create remote dir failed"
1199         chmod 0777 $DIR/${tdir}-1
1200
1201         # hardlimit should have been fetched by slave during global
1202         # reintegration, create will exceed quota
1203         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1204                 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1205
1206         $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1207         wait_delete_completed
1208         sync_all_data || true
1209
1210         echo "Stop mds${MDSCOUNT}..."
1211         stop mds${MDSCOUNT}
1212
1213         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1214                 error "clear quota failed"
1215
1216         echo "Start mds${MDSCOUNT}..."
1217         start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1218         quota_init
1219
1220         wait_mdt_reint "ug" || error "reintegration failed"
1221
1222         # hardlimit should be cleared on slave during reintegration
1223         $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1224                 quota_error -u $TSTUSR "create failed, expect success"
1225
1226         $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1227         $LFS rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1228
1229         cleanup_quota_test
1230         resetquota -u $TSTUSR
1231 }
1232 run_test 7e "Quota reintegration (inode limits)"
1233
1234 # run dbench with quota enabled
1235 test_8() {
1236         local BLK_LIMIT="100g" #100G
1237         local FILE_LIMIT=1000000
1238
1239         setup_quota_test
1240         trap cleanup_quota_test EXIT
1241
1242         set_mdt_qtype "ug" || error "enable mdt quota failed"
1243         set_ost_qtype "ug" || error "enable ost quota failed"
1244
1245         echo "Set enough high limit for user: $TSTUSR"
1246         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1247                 error "set user quota failed"
1248         echo "Set enough high limit for group: $TSTUSR"
1249         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1250                 error "set group quota failed"
1251
1252         local duration=""
1253         [ "$SLOW" = "no" ] && duration=" -t 120"
1254         $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1255                 quota_error a $TSTUSR "dbench failed!"
1256
1257         cleanup_quota_test
1258         resetquota -u $TSTUSR
1259         resetquota -g $TSTUSR
1260 }
1261 run_test 8 "Run dbench with quota enabled"
1262
1263 # this check is just for test_9
1264 OST0_MIN=4900000 #4.67G
1265
1266 check_whether_skip () {
1267         local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1268         log "OST0_SIZE: $OST0_SIZE  required: $OST0_MIN"
1269         if [ $OST0_SIZE -lt $OST0_MIN ]; then
1270                 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1271                 return 0
1272         else
1273                 return 1
1274         fi
1275 }
1276
1277 # run for fixing bug10707, it needs a big room. test for 64bit
1278 test_9() {
1279         local filesize=$((1024 * 9 / 2)) # 4.5G
1280
1281         check_whether_skip && return 0
1282
1283         setup_quota_test
1284         trap cleanup_quota_test EXIT
1285
1286         set_ost_qtype "ug" || error "enable ost quota failed"
1287
1288         local TESTFILE="$DIR/$tdir/$tfile-0"
1289         local BLK_LIMIT=100G #100G
1290         local FILE_LIMIT=1000000
1291
1292         echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1293
1294         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1295                 "for user: $TSTUSR"
1296         $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1297                 error "set user quota failed"
1298
1299         log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1300                 "for group: $TSTUSR"
1301         $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1302                 error "set group quota failed"
1303
1304         quota_show_check a u $TSTUSR
1305         quota_show_check a g $TSTUSR
1306
1307         echo "Create test file"
1308         $LFS setstripe $TESTFILE -c 1 -i 0
1309         chown $TSTUSR.$TSTUSR $TESTFILE
1310
1311         log "Write the big file of 4.5G ..."
1312         $RUNAS $DD of=$TESTFILE count=$filesize ||
1313                 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1314
1315         $SHOW_QUOTA_USER
1316         $SHOW_QUOTA_GROUP
1317
1318         cleanup_quota_test
1319         resetquota -u $TSTUSR
1320         resetquota -g $TSTUSR
1321
1322         $SHOW_QUOTA_USER
1323         $SHOW_QUOTA_GROUP
1324 }
1325 run_test 9 "Block limit larger than 4GB (b10707)"
1326
1327 test_10() {
1328         local TESTFILE=$DIR/$tdir/$tfile
1329
1330         setup_quota_test
1331         trap cleanup_quota_test EXIT
1332
1333         # set limit to root user should fail
1334         $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1335                 error "set limit for root user successfully, expect failure"
1336         $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1337                 error "set limit for root group successfully, expect failure"
1338
1339         # root user can overrun quota
1340         set_ost_qtype "ug" || "enable ost quota failed"
1341
1342         $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1343                 error "set quota failed"
1344         quota_show_check b u $TSTUSR
1345
1346         $LFS setstripe $TESTFILE -c 1
1347         chown $TSTUSR.$TSTUSR $TESTFILE
1348
1349         runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1350                 error "write failure, expect success"
1351
1352         cleanup_quota_test
1353         resetquota -u $TSTUSR
1354 }
1355 run_test 10 "Test quota for root user"
1356
1357 test_11() {
1358         local TESTFILE=$DIR/$tdir/$tfile
1359         setup_quota_test
1360         trap cleanup_quota_test EXIT
1361
1362         set_mdt_qtype "ug" || "enable mdt quota failed"
1363         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1364                 error "set quota failed"
1365
1366         touch "$TESTFILE"-0
1367         touch "$TESTFILE"-1
1368
1369         chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1370         chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1371
1372         $SHOW_QUOTA_USER
1373         local USED=$(getquota -u $TSTUSR global curinodes)
1374         [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1375
1376         cleanup_quota_test
1377         resetquota -u $TSTUSR
1378 }
1379 run_test 11 "Chown/chgrp ignores quota"
1380
1381 test_12a() {
1382         [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1383
1384         local blimit=22 # 22M
1385         local blk_cnt=$((blimit - 5))
1386         local TESTFILE0="$DIR/$tdir/$tfile"-0
1387         local TESTFILE1="$DIR/$tdir/$tfile"-1
1388
1389         setup_quota_test
1390         trap cleanup_quota_test EXIT
1391
1392         set_ost_qtype "u" || "enable ost quota failed"
1393         quota_show_check b u $TSTUSR
1394
1395         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1396                 error "set quota failed"
1397
1398         $LFS setstripe $TESTFILE0 -c 1 -i 0
1399         $LFS setstripe $TESTFILE1 -c 1 -i 1
1400         chown $TSTUSR.$TSTUSR $TESTFILE0
1401         chown $TSTUSR.$TSTUSR $TESTFILE1
1402
1403         echo "Write to ost0..."
1404         $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1405                 quota_error a $TSTUSR "dd failed"
1406
1407         echo "Write to ost1..."
1408         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1409                 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1410
1411         echo "Free space from ost0..."
1412         rm -f $TESTFILE0
1413         wait_delete_completed
1414         sync_all_data || true
1415
1416         echo "Write to ost1 after space freed from ost0..."
1417         $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1418                 quota_error a $TSTUSR "rebalancing failed"
1419
1420         cleanup_quota_test
1421         resetquota -u $TSTUSR
1422 }
1423 run_test 12a "Block quota rebalancing"
1424
1425 test_12b() {
1426         [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1427
1428         local ilimit=$((1024 * 2)) # 2k inodes
1429         local TESTFILE0=$DIR/$tdir/$tfile
1430         local TESTFILE1=$DIR/${tdir}-1/$tfile
1431
1432         setup_quota_test
1433         trap cleanup_quota_test EXIT
1434
1435         $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1436         chmod 0777 $DIR/${tdir}-1
1437
1438         set_mdt_qtype "u" || "enable mdt quota failed"
1439         quota_show_check f u $TSTUSR
1440
1441         $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1442                 error "set quota failed"
1443
1444         echo "Create $ilimit files on mdt0..."
1445         $RUNAS createmany -m $TESTFILE0 $ilimit ||
1446                 quota_error u $TSTUSR "create failed, but expect success"
1447
1448         echo "Create files on mdt1..."
1449         $RUNAS createmany -m $TESTFILE1 1 &&
1450                 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1451
1452         echo "Free space from mdt0..."
1453         $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1454         wait_delete_completed
1455         sync_all_data || true
1456
1457         echo "Create files on mdt1 after space freed from mdt0..."
1458         $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1459                 quota_error a $TSTUSR "rebalancing failed"
1460
1461         $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1462                 error "unlink mdt1 files failed"
1463         $LFS rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1464
1465         cleanup_quota_test
1466         resetquota -u $TSTUSR
1467 }
1468 run_test 12b "Inode quota rebalancing"
1469
1470 test_13(){
1471         local TESTFILE=$DIR/$tdir/$tfile
1472         # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1473         local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1474
1475         setup_quota_test
1476         trap cleanup_quota_test EXIT
1477
1478         set_ost_qtype "u" || "enable ost quota failed"
1479         quota_show_check b u $TSTUSR
1480
1481         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1482                 error "set quota failed"
1483         $LFS setstripe $TESTFILE -c 1 -i 0
1484         chown $TSTUSR.$TSTUSR $TESTFILE
1485
1486         # clear the locks in cache first
1487         do_facet ost1 $LCTL set_param -n $procf=clear
1488         local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1489         [ $nlock -eq 0 ] || error "$nlock cached locks"
1490
1491         # write to acquire the per-ID lock
1492         $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1493                 quota_error a $TSTUSR "dd failed"
1494
1495         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1496         [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1497
1498         # clear quota doesn't trigger per-ID lock cancellation
1499         resetquota -u $TSTUSR
1500         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1501         [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1502
1503         # clear the per-ID lock
1504         do_facet ost1 $LCTL set_param -n $procf=clear
1505         nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1506         [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1507
1508         # spare quota should be released
1509         local OSTUUID=$(ostuuid_from_index 0)
1510         local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1511         local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1512         [ $limit -le $space ] ||
1513                 error "spare quota isn't released, limit:$limit, space:$space"
1514
1515         cleanup_quota_test
1516 }
1517 run_test 13 "Cancel per-ID lock in the LRU list"
1518
1519 test_15(){
1520         local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1521
1522         wait_delete_completed
1523         sync_all_data || true
1524
1525         # test for user
1526         $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1527                 error "set user quota failed"
1528         local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1529         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1530                 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1531         resetquota -u $TSTUSR
1532
1533         # test for group
1534         $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1535                 error "set group quota failed"
1536         TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1537         [ $TOTAL_LIMIT -eq $LIMIT ] ||
1538                 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1539         resetquota -g $TSTUSR
1540 }
1541 run_test 15 "Set over 4T block quota"
1542
1543 test_17sub() {
1544         local err_code=$1
1545         local BLKS=1    # 1M less than limit
1546         local TESTFILE=$DIR/$tdir/$tfile
1547
1548         setup_quota_test
1549         trap cleanup_quota_test EXIT
1550
1551         # make sure the system is clean
1552         local USED=$(getquota -u $TSTUSR global curspace)
1553         [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1554
1555         set_ost_qtype "ug" || error "enable ost quota failed"
1556         # make sure no granted quota on ost
1557         resetquota -u $TSTUSR
1558         $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1559                 error "set quota failed"
1560
1561         quota_show_check b u $TSTUSR
1562
1563         #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1564         lustre_fail mds 0xa04 $err_code
1565
1566         # write in background
1567         $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1568         local DDPID=$!
1569
1570         sleep 2
1571         # write should be blocked and never finished
1572         if ! ps -p $DDPID  > /dev/null 2>&1; then
1573                 lustre_fail mds 0 0
1574                 quota_error u $TSTUSR "write finished incorrectly!"
1575         fi
1576
1577         lustre_fail mds 0 0
1578
1579         local count=0
1580         local timeout=30
1581         while [ true ]; do
1582                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1583                 count=$((count+1))
1584                 if [ $count -gt $timeout ]; then
1585                         quota_error u $TSTUSR "dd is not finished!"
1586                 fi
1587                 sleep 1
1588         done
1589
1590         sync; sync_all_data || true
1591
1592         USED=$(getquota -u $TSTUSR global curspace)
1593         [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1594                 "Used space(${USED}K) is less than ${BLKS}M"
1595
1596         cleanup_quota_test
1597         resetquota -u $TSTUSR
1598 }
1599
1600 # DQACQ return recoverable error
1601 test_17() {
1602         echo "DQACQ return -ENOLCK"
1603         #define ENOLCK  37
1604         test_17sub 37 || error "Handle -ENOLCK failed"
1605
1606         echo "DQACQ return -EAGAIN"
1607         #define EAGAIN  11
1608         test_17sub 11 || error "Handle -EAGAIN failed"
1609
1610         echo "DQACQ return -ETIMEDOUT"
1611         #define ETIMEDOUT 110
1612         test_17sub 110 || error "Handle -ETIMEDOUT failed"
1613
1614         echo "DQACQ return -ENOTCONN"
1615         #define ENOTCONN 107
1616         test_17sub 107 || error "Handle -ENOTCONN failed"
1617 }
1618
1619 run_test 17 "DQACQ return recoverable error"
1620
1621 test_18_sub () {
1622         local io_type=$1
1623         local blimit="200m" # 200M
1624         local TESTFILE="$DIR/$tdir/$tfile"
1625
1626         setup_quota_test
1627         trap cleanup_quota_test EXIT
1628
1629         set_ost_qtype "u" || error "enable ost quota failed"
1630         log "User quota (limit: $blimit)"
1631         $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1632                 error "set quota failed"
1633         quota_show_check b u $TSTUSR
1634
1635         $LFS setstripe $TESTFILE -i 0 -c 1
1636         chown $TSTUSR.$TSTUSR $TESTFILE
1637
1638         local timeout=$(sysctl -n lustre.timeout)
1639
1640         if [ $io_type = "directio" ]; then
1641                 log "Write 100M (directio) ..."
1642                 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1643         else
1644                 log "Write 100M (buffered) ..."
1645                 $RUNAS $DD of=$TESTFILE count=100 &
1646         fi
1647         local DDPID=$!
1648
1649         replay_barrier $SINGLEMDS
1650         log "Fail mds for $((2 * timeout)) seconds"
1651         fail $SINGLEMDS $((2 * timeout))
1652
1653         local count=0
1654         if at_is_enabled; then
1655                 timeout=$(at_max_get mds)
1656         else
1657                 timeout=$(lctl get_param -n timeout)
1658         fi
1659
1660         while [ true ]; do
1661                 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1662                 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1663                         log "it took $count second"
1664                 fi
1665                 sleep 1
1666         done
1667
1668         log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1669         sync
1670         cancel_lru_locks mdc
1671         cancel_lru_locks osc
1672         $SHOW_QUOTA_USER
1673
1674         local testfile_size=$(stat -c %s $TESTFILE)
1675         if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1676                 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1677                         "got ${testfile_size}. Verifying file failed!"
1678         fi
1679         cleanup_quota_test
1680         resetquota -u $TSTUSR
1681 }
1682
1683 # test when mds does failover, the ost still could work well
1684 # this test shouldn't trigger watchdog b=14840
1685 test_18() {
1686         test_18_sub normal
1687         test_18_sub directio
1688
1689         # check if watchdog is triggered
1690         do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1691         local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
1692                        /Service thread pid/ && /was inactive/ {
1693                                if (start) {
1694                                        print;
1695                                }
1696                        }' $TMP/lustre-log-${TESTNAME}.log)
1697         [ -z "$watchdog" ] || error "$watchdog"
1698         rm -f $TMP/lustre-log-${TESTNAME}.log
1699 }
1700 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1701
1702 test_19() {
1703         local blimit=5 # 5M
1704         local TESTFILE=$DIR/$tdir/$tfile
1705
1706         setup_quota_test
1707         trap cleanup_quota_test EXIT
1708
1709         set_ost_qtype "ug" || error "enable ost quota failed"
1710
1711         # bind file to a single OST
1712         $LFS setstripe -c 1 $TESTFILE
1713         chown $TSTUSR.$TSTUSR $TESTFILE
1714
1715         echo "Set user quota (limit: "$blimit"M)"
1716         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1717                 error "set user quota failed"
1718         quota_show_check b u $TSTUSR
1719         echo "Update quota limits"
1720         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1721                 error "set group quota failed"
1722         quota_show_check b u $TSTUSR
1723
1724         # first wirte might be cached
1725         $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1726         cancel_lru_locks osc
1727         $SHOW_QUOTA_USER
1728         $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1729                 quota_error u $TSTUSR "Write success, expect failure"
1730         $SHOW_QUOTA_USER
1731
1732         cleanup_quota_test
1733         resetquota -u $TSTUSR
1734 }
1735 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1736
1737 test_20() { # b15754
1738         local LSTR=(2g 1t 4k 3m) # limits strings
1739         # limits values
1740         local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1741
1742         resetquota -u $TSTUSR
1743
1744         $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1745                 $MOUNT || error "could not set quota limits"
1746         $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1747                                 --inode-softlimit ${LSTR[2]} \
1748                                 --inode-hardlimit ${LSTR[3]} \
1749                                 $MOUNT || error "could not set quota limits"
1750
1751         [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1752                 error "bsoftlimit was not set properly"
1753         [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1754                 error "bhardlimit was not set properly"
1755         [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1756                 error "isoftlimit was not set properly"
1757         [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1758                 error "ihardlimit was not set properly"
1759
1760         resetquota -u $TSTUSR
1761 }
1762 run_test 20 "Test if setquota specifiers work properly (b15754)"
1763
1764 test_21_sub() {
1765         local testfile=$1
1766         local blk_number=$2
1767         local seconds=$3
1768
1769         local time=$(($(date +%s) + seconds))
1770         while [ $(date +%s) -lt $time ]; do
1771                 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1772         done
1773 }
1774
1775 # run for fixing bug16053, setquota shouldn't fail when writing and
1776 # deleting are happening
1777 test_21() {
1778         local TESTFILE="$DIR/$tdir/$tfile"
1779         local BLIMIT=10 # 10G
1780         local ILIMIT=1000000
1781
1782         setup_quota_test
1783         trap cleanup_quota_test EXIT
1784
1785         set_ost_qtype "ug" || error "Enable ost quota failed"
1786
1787         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1788         $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1789                 error "set user quota failed"
1790         log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1791         $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1792                 error "set group quota failed"
1793
1794         # repeat writing on a 1M file
1795         test_21_sub ${TESTFILE}_1 1 30 &
1796         local DDPID1=$!
1797         # repeat writing on a 128M file
1798         test_21_sub ${TESTFILE}_2 128 30 &
1799         local DDPID2=$!
1800
1801         local time=$(($(date +%s) + 30))
1802         local i=1
1803         while [ $(date +%s) -lt $time ]; do
1804                 log "Set quota for $i times"
1805                 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1806                         -I $((ILIMIT + i)) $MOUNT ||
1807                                 error "Set user quota failed"
1808                 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1809                         -I $((ILIMIT + i)) $MOUNT ||
1810                                 error "Set group quota failed"
1811                 i=$((i+1))
1812                 sleep 1
1813         done
1814
1815         local count=0
1816         while [ true ]; do
1817                 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1818                 count=$((count+1))
1819                 if [ $count -gt 60 ]; then
1820                         quota_error a $TSTUSR "dd should be finished!"
1821                 fi
1822                 sleep 1
1823         done
1824         echo "(dd_pid=$DDPID1, time=$count)successful"
1825
1826         count=0
1827         while [ true ]; do
1828                 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1829                 count=$((count+1))
1830                 if [ $count -gt 60 ]; then
1831                         quota_error a $TSTUSR "dd should be finished!"
1832                 fi
1833                 sleep 1
1834         done
1835         echo "(dd_pid=$DDPID2, time=$count)successful"
1836
1837         cleanup_quota_test
1838         resetquota -u $TSTUSR
1839         resetquota -g $TSTUSR
1840 }
1841 run_test 21 "Setquota while writing & deleting (b16053)"
1842
1843 # enable/disable quota enforcement permanently
1844 test_22() {
1845         echo "Set both mdt & ost quota type as ug"
1846         set_mdt_qtype "ug" || error "enable mdt quota failed"
1847         set_ost_qtype "ug" || error "enable ost quota failed"
1848
1849         echo "Restart..."
1850         stopall
1851         mount
1852         setupall
1853
1854         echo "Verify if quota is enabled"
1855         local qtype=$(mdt_quota_type)
1856         [ $qtype != "ug" ] && error "mdt quota setting is lost"
1857         qtype=$(ost_quota_type)
1858         [ $qtype != "ug" ] && error "ost quota setting is lost"
1859
1860         echo "Set both mdt & ost quota type as none"
1861         set_mdt_qtype "none" || error "disable mdt quota failed"
1862         set_ost_qtype "none" || error "disable ost quota failed"
1863
1864         echo "Restart..."
1865         stopall
1866         mount
1867         setupall
1868         quota_init
1869
1870         echo "Verify if quota is disabled"
1871         qtype=$(mdt_quota_type)
1872         [ $qtype != "none" ] && error "mdt quota setting is lost"
1873         qtype=$(ost_quota_type)
1874         [ $qtype != "none" ] && error "ost quota setting is lost"
1875
1876         return 0
1877 }
1878 run_test 22 "enable/disable quota by 'lctl conf_param'"
1879
1880 test_23_sub() {
1881         local TESTFILE="$DIR/$tdir/$tfile"
1882         local LIMIT=$1
1883
1884         setup_quota_test
1885         trap cleanup_quota_test EXIT
1886
1887         set_ost_qtype "ug" || error "Enable ost quota failed"
1888
1889         # test for user
1890         log "User quota (limit: $LIMIT MB)"
1891         $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1892                 error "set quota failed"
1893         quota_show_check b u $TSTUSR
1894
1895         $LFS setstripe $TESTFILE -c 1 -i 0
1896         chown $TSTUSR.$TSTUSR $TESTFILE
1897
1898         log "Step1: trigger EDQUOT with O_DIRECT"
1899         log "Write half of file"
1900         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1901                 quota_error u $TSTUSR "(1) Write failure, expect success." \
1902                         "limit=$LIMIT"
1903         log "Write out of block quota ..."
1904         $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1905                 oflag=direct conv=notrunc &&
1906                 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1907                         "limit=$LIMIT"
1908         log "Step1: done"
1909
1910         log "Step2: rewrite should succeed"
1911         $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1912                 quota_error u $TSTUSR "(3) Write failure, expect success." \
1913                         "limit=$LIMIT"
1914         log "Step2: done"
1915
1916         cleanup_quota_test
1917
1918         local OST0_UUID=$(ostuuid_from_index 0)
1919         local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1920         [ $OST0_QUOTA_USED -ne 0 ] &&
1921                 ($SHOW_QUOTA_USER; \
1922                 quota_error u $TSTUSR "quota isn't released")
1923         $SHOW_QUOTA_USER
1924         resetquota -u $TSTUSR
1925 }
1926
1927 test_23() {
1928         local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1929         check_whether_skip && return 0
1930         log "run for 4MB test file"
1931         test_23_sub 4
1932
1933         OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1934         check_whether_skip && return 0
1935         log "run for 40MB test file"
1936         test_23_sub 40
1937 }
1938 run_test 23 "Quota should be honored with directIO (b16125)"
1939
1940 test_24() {
1941         local blimit=5 # 5M
1942         local TESTFILE="$DIR/$tdir/$tfile"
1943
1944         setup_quota_test
1945         trap cleanup_quota_test EXIT
1946
1947         set_ost_qtype "ug" || error "enable ost quota failed"
1948
1949         # bind file to a single OST
1950         $LFS setstripe -c 1 $TESTFILE
1951         chown $TSTUSR.$TSTUSR $TESTFILE
1952
1953         echo "Set user quota (limit: "$blimit"M)"
1954         $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1955                 error "set quota failed"
1956
1957         # overrun quota by root user
1958         runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1959                 error "write failure, expect success"
1960         cancel_lru_locks osc
1961         sync_all_data || true
1962
1963         $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1964
1965         cleanup_quota_test
1966         resetquota -u $TSTUSR
1967 }
1968 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1969
1970 test_27a() { # b19612
1971         $LFS quota $TSTUSR $DIR &&
1972                 error "lfs succeeded with no type, but should have failed"
1973         $LFS setquota $TSTUSR $DIR &&
1974                 error "lfs succeeded with no type, but should have failed"
1975         return 0
1976 }
1977 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1978
1979 test_27b() { # b20200
1980         $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1981                 error "lfs setquota failed with uid argument"
1982         $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1983                 error "lfs stequota failed with gid argument"
1984         $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1985         $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1986         resetquota -u $TSTUSR
1987         resetquota -g $TSTUSR
1988         return 0
1989 }
1990 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1991
1992 test_30() {
1993         local output
1994         local LIMIT=4 # 4MB
1995         local TESTFILE="$DIR/$tdir/$tfile"
1996         local GRACE=10
1997
1998         setup_quota_test
1999         trap cleanup_quota_test EXIT
2000
2001         set_ost_qtype "u" || error "enable ost quota failed"
2002
2003         $LFS setstripe $TESTFILE -i 0 -c 1
2004         chown $TSTUSR.$TSTUSR $TESTFILE
2005
2006         $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2007                 $MAX_IQ_TIME $DIR || error "set grace time failed"
2008         $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2009                 error "set quota failed"
2010         $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2011         cancel_lru_locks osc
2012         sleep $GRACE
2013         $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2014         # over-quota flag has not yet settled since we do not trigger async
2015         # events based on grace time period expiration
2016         $SHOW_QUOTA_USER
2017         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2018         cancel_lru_locks osc
2019         # now over-quota flag should be settled and further writes should fail
2020         $SHOW_QUOTA_USER
2021         $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2022                 error "grace times were reset"
2023         # cleanup
2024         cleanup_quota_test
2025         resetquota -u $TSTUSR
2026         $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2027                 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2028 }
2029 run_test 30 "Hard limit updates should not reset grace times"
2030
2031 # basic usage tracking for user & group
2032 test_33() {
2033         local INODES=10 # 10 files
2034         local BLK_CNT=2 # of 2M each
2035         local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2036
2037         setup_quota_test
2038         trap cleanup_quota_test EXIT
2039
2040         # make sure the system is clean
2041         local USED=$(getquota -u $TSTID global curspace)
2042         [ $USED -ne 0 ] &&
2043                 error "Used space ($USED) for user $TSTID isn't 0."
2044         USED=$(getquota -g $TSTID global curspace)
2045         [ $USED -ne 0 ] &&
2046                 error "Used space ($USED) for group $TSTID isn't 0."
2047
2048         echo "Write files..."
2049         for i in `seq 0 $INODES`; do
2050                 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2051                         error "write failed"
2052                 echo "Iteration $i/$INODES completed"
2053         done
2054         cancel_lru_locks osc
2055         sync; sync_all_data || true
2056
2057         echo "Verify disk usage after write"
2058         USED=$(getquota -u $TSTID global curspace)
2059         [ $USED -lt $TOTAL_BLKS ] &&
2060                 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2061         USED=$(getquota -g $TSTID global curspace)
2062         [ $USED -lt $TOTAL_BLKS ] &&
2063                 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2064
2065         echo "Verify inode usage after write"
2066         USED=$(getquota -u $TSTID global curinodes)
2067         [ $USED -lt $INODES ] &&
2068                 error "Used inode for user $TSTID is $USED, expected $INODES"
2069         USED=$(getquota -g $TSTID global curinodes)
2070         [ $USED -lt $INODES ] &&
2071                 error "Used inode for group $TSTID is $USED, expected $INODES"
2072
2073         cleanup_quota_test
2074
2075         echo "Verify disk usage after delete"
2076         USED=$(getquota -u $TSTID global curspace)
2077         [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2078         USED=$(getquota -u $TSTID global curinodes)
2079         [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2080         USED=$(getquota -g $TSTID global curspace)
2081         [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2082         USED=$(getquota -g $TSTID global curinodes)
2083         [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2084 }
2085 run_test 33 "Basic usage tracking for user & group"
2086
2087 # usage transfer test for user & group
2088 test_34() {
2089         local BLK_CNT=2 # 2MB
2090
2091         setup_quota_test
2092         trap cleanup_quota_test EXIT
2093
2094         # make sure the system is clean
2095         local USED=$(getquota -u $TSTID global curspace)
2096         [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2097         USED=$(getquota -g $TSTID global curspace)
2098         [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2099
2100         echo "Write file..."
2101         $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2102                 error "write failed"
2103         cancel_lru_locks osc
2104         sync; sync_all_data || true
2105
2106         echo "chown the file to user $TSTID"
2107         chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2108
2109         echo "Wait for setattr on objects finished..."
2110         wait_delete_completed
2111
2112         BLK_CNT=$((BLK_CNT * 1024))
2113
2114         echo "Verify disk usage for user $TSTID"
2115         USED=$(getquota -u $TSTID global curspace)
2116         [ $USED -lt $BLK_CNT ] &&
2117                 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2118         USED=$(getquota -u $TSTID global curinodes)
2119         [ $USED -ne 1 ] &&
2120                 error "Used inodes for user $TSTID is $USED, expected 1"
2121
2122         echo "chgrp the file to group $TSTID"
2123         chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2124
2125         echo "Wait for setattr on objects finished..."
2126         wait_delete_completed
2127
2128         echo "Verify disk usage for group $TSTID"
2129         USED=$(getquota -g $TSTID global curspace)
2130         [ $USED -ge $BLK_CNT ] ||
2131                 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2132         USED=$(getquota -g $TSTID global curinodes)
2133         [ $USED -eq 1 ] ||
2134                 error "Used inodes for group $TSTID is $USED, expected 1"
2135
2136         cleanup_quota_test
2137 }
2138 run_test 34 "Usage transfer for user & group"
2139
2140 # usage is still accessible across restart
2141 test_35() {
2142         local BLK_CNT=2 # 2 MB
2143
2144         setup_quota_test
2145         trap cleanup_quota_test EXIT
2146
2147         echo "Write file..."
2148         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2149                 error "write failed"
2150         cancel_lru_locks osc
2151         sync; sync_all_data || true
2152
2153         echo "Save disk usage before restart"
2154         local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2155         [ $ORIG_USR_SPACE -eq 0 ] &&
2156                 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2157         local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2158         [ $ORIG_USR_INODES -eq 0 ] &&
2159                 error "Used inodes for user $TSTID is 0, expected 1"
2160         echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2161         local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2162         [ $ORIG_GRP_SPACE -eq 0 ] &&
2163                 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2164         local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2165         [ $ORIG_GRP_INODES -eq 0 ] &&
2166                 error "Used inodes for group $TSTID is 0, expected 1"
2167         echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2168
2169         log "Restart..."
2170         local ORIG_REFORMAT=$REFORMAT
2171         REFORMAT=""
2172         cleanup_and_setup_lustre
2173         REFORMAT=$ORIG_REFORMAT
2174         quota_init
2175
2176         echo "Verify disk usage after restart"
2177         local USED=$(getquota -u $TSTID global curspace)
2178         [ $USED -eq $ORIG_USR_SPACE ] ||
2179                 error "Used space for user $TSTID changed from " \
2180                         "$ORIG_USR_SPACE to $USED"
2181         USED=$(getquota -u $TSTID global curinodes)
2182         [ $USED -eq $ORIG_USR_INODES ] ||
2183                 error "Used inodes for user $TSTID changed from " \
2184                         "$ORIG_USR_INODES to $USED"
2185         USED=$(getquota -g $TSTID global curspace)
2186         [ $USED -eq $ORIG_GRP_SPACE ] ||
2187                 error "Used space for group $TSTID changed from " \
2188                         "$ORIG_GRP_SPACE to $USED"
2189         USED=$(getquota -g $TSTID global curinodes)
2190         [ $USED -eq $ORIG_GRP_INODES ] ||
2191                 error "Used inodes for group $TSTID changed from " \
2192                         "$ORIG_GRP_INODES to $USED"
2193
2194         # check if the vfs_dq_init() is called before writing
2195         echo "Append to the same file..."
2196         $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2197                 error "write failed"
2198         cancel_lru_locks osc
2199         sync; sync_all_data || true
2200
2201         echo "Verify space usage is increased"
2202         USED=$(getquota -u $TSTID global curspace)
2203         [ $USED -gt $ORIG_USR_SPACE ] ||
2204                 error "Used space for user $TSTID isn't increased" \
2205                         "orig:$ORIG_USR_SPACE, now:$USED"
2206         USED=$(getquota -g $TSTID global curspace)
2207         [ $USED -gt $ORIG_GRP_SPACE ] ||
2208                 error "Used space for group $TSTID isn't increased" \
2209                         "orig:$ORIG_GRP_SPACE, now:$USED"
2210
2211         cleanup_quota_test
2212 }
2213 run_test 35 "Usage is still accessible across reboot"
2214
2215 # test migrating old amdin quota files (in Linux quota file format v2) into new
2216 # quota global index (in IAM format)
2217 test_36() {
2218         [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2219                 skip "skipping migration test" && return
2220
2221         # get the mdt0 device name
2222         local mdt0_node=$(facet_active_host $SINGLEMDS)
2223         local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2224
2225         echo "Reformat..."
2226         formatall
2227
2228         echo "Copy admin quota files into MDT0..."
2229         local mntpt=$(facet_mntpt $SINGLEMDS)
2230         local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2231         local opt
2232         if ! do_node $mdt0_node test -b $mdt0_fstype; then
2233                 opt="-o loop"
2234         fi
2235         echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2236         do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2237         do_node $mdt0_node mkdir $mntpt/OBJECTS
2238         do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2239         do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2240         do_node $mdt0_node umount -f $mntpt
2241
2242         echo "Setup all..."
2243         setupall
2244
2245         echo "Verify global limits..."
2246         local id_cnt
2247         local limit
2248
2249         local proc="qmt.*.md-0x0.glb-usr"
2250         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2251         [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2252         limit=$(getquota -u 1 global isoftlimit)
2253         [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2254         limit=$(getquota -u 1 global ihardlimit)
2255         [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2256
2257         proc="qmt.*.md-0x0.glb-grp"
2258         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2259         [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2260         limit=$(getquota -g 1 global isoftlimit)
2261         [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2262         limit=$(getquota -g 1 global ihardlimit)
2263         [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2264
2265         proc=" qmt.*.dt-0x0.glb-usr"
2266         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2267         [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2268         limit=$(getquota -u 60001 global bsoftlimit)
2269         [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2270         limit=$(getquota -u 60001 global bhardlimit)
2271         [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2272
2273         proc="qmt.*.dt-0x0.glb-grp"
2274         id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2275         [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2276         limit=$(getquota -g 60001 global bsoftlimit)
2277         [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2278         limit=$(getquota -g 60001 global bhardlimit)
2279         [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2280
2281         echo "Cleanup..."
2282         formatall
2283         setupall
2284 }
2285 run_test 36 "Migrate old admin files into new global indexes"
2286
2287 quota_fini()
2288 {
2289         do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2290 }
2291 quota_fini
2292
2293 cd $ORIG_PWD
2294 complete $SECONDS
2295 check_and_cleanup_lustre
2296 export QUOTA_AUTO=$QUOTA_AUTO_OLD
2297 exit_status