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