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