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