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