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