3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
17 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
23 TSTID2=${TSTID2:-60001}
24 TSTUSR=${TSTUSR:-"quota_usr"}
25 TSTUSR2=${TSTUSR2:-"quota_2usr"}
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
37 require_dsh_mds || exit 0
38 require_dsh_ost || exit 0
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
46 # if e2fsprogs support quota feature?
47 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] && \
48 ! $DEBUGFS -c -R supported_features | grep -q 'quota'; then
49 skip "e2fsprogs doesn't support quota" && exit 0
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
54 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
56 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
61 QUOTA_AUTO_OLD=$QUOTA_AUTO
64 check_and_setup_lustre
66 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
67 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
69 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
70 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
71 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
72 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
73 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
74 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
75 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
76 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
83 local fail_val=${3:-0}
85 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
86 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
87 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
90 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
91 for num in `seq $OSTCOUNT`; do
92 do_facet ost$num "lctl set_param fail_val=$fail_val"
93 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
98 RUNAS="runas -u $TSTID -g $TSTID"
99 RUNAS2="runas -u $TSTID2 -g $TSTID2"
100 DD="dd if=/dev/zero bs=1M"
104 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
105 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
106 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
107 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
119 error "clear quota for [type:$1 name:$2] failed"
120 # give a chance to slave to release space
128 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
129 $LFS quota -v -u $LOCAL_ID $DIR
130 log "Files for user ($LOCAL_ID):"
131 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
132 xargs stat 2>/dev/null)
135 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
136 $LFS quota -v -u $LOCAL_ID $DIR
137 log "Files for group ($LOCAL_ID):"
138 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
139 xargs stat 2>/dev/null)
155 # get quota for a user or a group
156 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
157 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
163 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
164 [ "$1" != "-u" -a "$1" != "-g" ] &&
165 error "getquota: wrong u/g specifier $1 passed"
178 *) error "unknown quota parameter $4";;
181 [ "$uuid" = "global" ] && uuid=$DIR
183 $LFS quota -v "$1" "$2" $DIR |
184 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
185 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
190 # usage: set_mdt_qtype ug|u|g|none
194 local mdts=$(get_facets MDS)
196 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
197 # we have to make sure each MDT received config changes
198 for mdt in ${mdts//,/ }; do
200 cmd="$LCTL get_param -n "
201 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
202 cmd=${cmd}.quota_slave.enabled
204 if $(facet_up $mdt); then
205 wait_update_facet $mdt "$cmd" "$qtype" || return 1
212 # usage: set_ost_qtype ug|u|g|none
216 local osts=$(get_facets OST)
218 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
219 # we have to make sure each OST received config changes
220 for ost in ${osts//,/ }; do
222 cmd="$LCTL get_param -n "
223 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
224 cmd=${cmd}.quota_slave.enabled
226 if $(facet_up $ost); then
227 wait_update_facet $ost "$cmd" "$qtype" || return 1
233 wait_reintegration() {
237 local result="glb[1],slv[1],reint[0]"
242 if [ $ntype == "mdt" ]; then
243 tgts=$(get_facets MDS)
245 tgts=$(get_facets OST)
248 for tgt in ${tgts//,/ }; do
250 cmd="$LCTL get_param -n "
251 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
252 cmd=${cmd}.quota_slave.info
254 if $(facet_up $tgt); then
255 wait_update_facet $tgt "$cmd |
256 grep "$qtype" | awk '{ print \\\$3 }'" \
257 "$result" $max || return 1
267 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
268 wait_reintegration "mdt" "user" $max || return 1
271 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
272 wait_reintegration "mdt" "group" $max || return 1
281 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
282 wait_reintegration "ost" "user" $max || return 1
285 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
286 wait_reintegration "ost" "group" $max || return 1
293 wait_delete_completed
294 echo "Creating test directory"
296 chmod 0777 $DIR/$tdir
297 # always clear fail_loc in case of fail_loc isn't cleared
298 # properly when previous test failed
299 lustre_fail mds_ost 0
302 cleanup_quota_test() {
304 echo "Delete files..."
306 echo "Wait for unlink objects finished..."
307 wait_delete_completed
308 sync_all_data || true
317 $LFS quota -v -$ug $qid $DIR
319 if [ "$bf" == "a" -o "$bf" == "b" ]; then
320 usage=$(getquota -$ug $qid global curspace)
321 if [ -z $usage ]; then
322 quota_error $ug $qid \
323 "Query block quota failed ($ug:$qid)."
325 [ $usage -ne 0 ] && quota_log $ug $qid \
326 "Block quota isn't 0 ($ug:$qid:$usage)."
330 if [ "$bf" == "a" -o "$bf" == "f" ]; then
331 usage=$(getquota -$ug $qid global curinodes)
332 if [ -z $usage ]; then
333 quota_error $ug $qid \
334 "Query file quota failed ($ug:$qid)."
336 [ $usage -ne 0 ] && quota_log $ug $qid \
337 "File quota isn't 0 ($ug:$qid:$usage)."
344 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
348 resetquota -u $TSTUSR
349 resetquota -g $TSTUSR
350 resetquota -u $TSTUSR2
351 resetquota -g $TSTUSR2
353 test_quota_performance() {
354 local TESTFILE="$DIR/$tdir/$tfile-0"
355 local size=$1 # in MB
356 local stime=$(date +%s)
357 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
358 quota_error u $TSTUSR "write failure"
359 local etime=$(date +%s)
360 delta=$((etime - stime))
361 if [ $delta -gt 0 ]; then
362 rate=$((size * 1024 / delta))
363 [ $rate -gt 1024 ] ||
364 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
369 # test basic quota performance b=21696
372 [ "$SLOW" = "no" ] && MB=10
374 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
375 [ $free_space -le $((MB * 1024)) ] &&
376 skip "not enough space ${free_space} KB, " \
377 "required $((MB * 1024)) KB" && return
379 trap cleanup_quota_test EXIT
381 set_ost_qtype "none" || error "disable ost quota failed"
382 test_quota_performance $MB
384 set_ost_qtype "ug" || error "enable ost quota failed"
385 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
386 error "set quota failed"
387 test_quota_performance $MB
390 resetquota -u $TSTUSR
392 run_test 0 "Test basic quota performance"
394 # test block hardlimit
397 local TESTFILE="$DIR/$tdir/$tfile-0"
400 trap cleanup_quota_test EXIT
403 set_ost_qtype "ug" || "enable ost quota failed"
406 log "User quota (block hardlimit:$LIMIT MB)"
407 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
408 error "set user quota failed"
410 # make sure the system is clean
411 local USED=$(getquota -u $TSTUSR global curspace)
412 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
414 $LFS setstripe $TESTFILE -c 1
415 chown $TSTUSR.$TSTUSR $TESTFILE
418 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
419 quota_error u $TSTUSR "user write failure, but expect success"
420 log "Write out of block quota ..."
421 # this time maybe cache write, ignore it's failure
422 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
423 # flush cache, ensure noquota flag is set on client
425 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
426 quota_error u $TSTUSR "user write success, but expect EDQUOT"
429 wait_delete_completed
430 sync_all_data || true
431 USED=$(getquota -u $TSTUSR global curspace)
432 [ $USED -ne 0 ] && quota_error u $TSTUSR \
433 "user quota isn't released after deletion"
434 resetquota -u $TSTUSR
437 log "--------------------------------------"
438 log "Group quota (block hardlimit:$LIMIT MB)"
439 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
440 error "set group quota failed"
442 TESTFILE="$DIR/$tdir/$tfile-1"
443 # make sure the system is clean
444 USED=$(getquota -g $TSTUSR global curspace)
445 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
447 $LFS setstripe $TESTFILE -c 1
448 chown $TSTUSR.$TSTUSR $TESTFILE
451 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
452 quota_error g $TSTUSR "group write failure, but expect success"
453 log "Write out of block quota ..."
454 # this time maybe cache write, ignore it's failure
455 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
457 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
458 quota_error g $TSTUSR "group write success, but expect EDQUOT"
463 USED=$(getquota -g $TSTUSR global curspace)
464 [ $USED -ne 0 ] && quota_error g $TSTUSR \
465 "group quota isn't released after deletion"
467 resetquota -g $TSTUSR
469 run_test 1 "Block hard limit (normal use and out of quota)"
471 # test inode hardlimit
473 local LIMIT=$((1024 * 1024)) # 1M inodes
474 local TESTFILE="$DIR/$tdir/$tfile-0"
476 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
478 local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
479 [ $FREE_INODES -lt $LIMIT ] &&
480 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
484 trap cleanup_quota_test EXIT
487 set_mdt_qtype "ug" || "enable mdt quota failed"
490 log "User quota (inode hardlimit:$LIMIT files)"
491 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
492 error "set user quota failed"
494 # make sure the system is clean
495 local USED=$(getquota -u $TSTUSR global curinodes)
496 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
498 log "Create $LIMIT files ..."
499 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
500 quota_error u $TSTUSR "user create failure, but expect success"
501 log "Create out of file quota ..."
502 $RUNAS touch ${TESTFILE}_xxx && \
503 quota_error u $TSTUSR "user create success, but expect EDQUOT"
506 unlinkmany ${TESTFILE} $LIMIT
507 rm -f ${TESTFILE}_xxx
508 wait_delete_completed
510 USED=$(getquota -u $TSTUSR global curinodes)
511 [ $USED -ne 0 ] && quota_error u $TSTUSR \
512 "user quota isn't released after deletion"
513 resetquota -u $TSTUSR
516 log "--------------------------------------"
517 log "Group quota (inode hardlimit:$LIMIT files)"
518 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
519 error "set group quota failed"
521 TESTFILE=$DIR/$tdir/$tfile-1
522 # make sure the system is clean
523 USED=$(getquota -g $TSTUSR global curinodes)
524 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
526 log "Create $LIMIT files ..."
527 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
528 quota_error g $TSTUSR "group create failure, but expect success"
529 log "Create out of file quota ..."
530 $RUNAS touch ${TESTFILE}_xxx && \
531 quota_error g $TSTUSR "group create success, but expect EDQUOT"
534 unlinkmany ${TESTFILE} $LIMIT
535 rm -f ${TESTFILE}_xxx
536 wait_delete_completed
538 USED=$(getquota -g $TSTUSR global curinodes)
539 [ $USED -ne 0 ] && quota_error g $TSTUSR \
540 "user quota isn't released after deletion"
543 resetquota -g $TSTUSR
545 run_test 2 "File hard limit (normal use and out of quota)"
549 local TIMER=$(($2 * 3 / 2))
554 trap cleanup_quota_test EXIT
556 $LFS setstripe $TESTFILE -c 1 -i 0
557 chown $TSTUSR.$TSTUSR $TESTFILE
559 echo "Write up to soft limit"
560 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
561 quota_error a $TSTUSR "write failure, but expect success"
562 OFFSET=$((LIMIT * 1024))
565 echo "Write to exceed soft limit"
566 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
567 quota_error a $TSTUSR "write failure, but expect success"
568 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
573 $SHOW_QUOTA_INFO_USER
574 $SHOW_QUOTA_INFO_GROUP
576 echo "Write before timer goes off"
577 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
578 quota_error a $TSTUSR "write failure, but expect success"
579 OFFSET=$((OFFSET + 1024))
582 echo "Sleep $TIMER seconds ..."
587 $SHOW_QUOTA_INFO_USER
588 $SHOW_QUOTA_INFO_GROUP
590 echo "Write after timer goes off"
591 # maybe cache write, ignore.
592 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
593 OFFSET=$((OFFSET + 1024))
595 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
596 quota_error a $TSTUSR "write success, but expect EDQUOT"
600 $SHOW_QUOTA_INFO_USER
601 $SHOW_QUOTA_INFO_GROUP
603 echo "Unlink file to stop timer"
605 wait_delete_completed
606 sync_all_data || true
610 $SHOW_QUOTA_INFO_USER
611 $SHOW_QUOTA_INFO_GROUP
613 $LFS setstripe $TESTFILE -c 1 -i 0
614 chown $TSTUSR.$TSTUSR $TESTFILE
617 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
618 quota_error a $TSTUSR "write failure, but expect success"
627 local TESTFILE=$DIR/$tdir/$tfile-0
629 set_ost_qtype "ug" || error "enable ost quota failed"
631 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
632 # make sure the system is clean
633 local USED=$(getquota -u $TSTUSR global curspace)
634 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
636 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
637 $MAX_IQ_TIME $DIR || error "set user grace time failed"
638 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
639 error "set user quota failed"
641 test_block_soft $TESTFILE $GRACE $LIMIT
642 resetquota -u $TSTUSR
644 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
645 TESTFILE=$DIR/$tdir/$tfile-1
646 # make sure the system is clean
647 USED=$(getquota -g $TSTUSR global curspace)
648 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
650 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
651 $MAX_IQ_TIME $DIR || error "set group grace time failed"
652 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
653 error "set group quota failed"
655 test_block_soft $TESTFILE $GRACE $LIMIT
656 resetquota -g $TSTUSR
659 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
660 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
661 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
662 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
664 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
669 local TIMER=$(($3 * 3 / 2))
672 trap cleanup_quota_test EXIT
674 echo "Create files to exceed soft limit"
675 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
676 quota_error a $TSTUSR "create failure, but expect success"
679 echo "Create file before timer goes off"
680 $RUNAS touch ${TESTFILE}_before ||
681 quota_error a $TSTUSR "failed create before timer expired," \
685 echo "Sleep $TIMER seconds ..."
690 $SHOW_QUOTA_INFO_USER
691 $SHOW_QUOTA_INFO_GROUP
693 echo "Create file after timer goes off"
694 # There is a window that space is accounted in the quota usage but
695 # hasn't been decreased from the pending write, if we acquire quota
696 # in this window, we'll acquire more than we needed.
697 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
699 $RUNAS touch ${TESTFILE}_after_3 &&
700 quota_error a $TSTUSR "create after timer expired," \
706 $SHOW_QUOTA_INFO_USER
707 $SHOW_QUOTA_INFO_GROUP
709 echo "Unlink files to stop timer"
710 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
711 wait_delete_completed
714 $RUNAS touch ${TESTFILE}_xxx ||
715 quota_error a $TSTUSR "touch after timer stop failure," \
725 local LIMIT=10 # inodes
726 local TESTFILE=$DIR/$tdir/$tfile-0
729 set_mdt_qtype "ug" || error "enable mdt quota failed"
731 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
732 # make sure the system is clean
733 local USED=$(getquota -u $TSTUSR global curinodes)
734 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
736 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
737 $GRACE $DIR || error "set user grace time failed"
738 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
739 error "set user quota failed"
741 test_file_soft $TESTFILE $LIMIT $GRACE
742 resetquota -u $TSTUSR
744 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
745 # make sure the system is clean
746 USED=$(getquota -g $TSTUSR global curinodes)
747 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
749 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
750 $GRACE $DIR || error "set group grace time failed"
751 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
752 error "set group quota failed"
753 TESTFILE=$DIR/$tdir/$tfile-1
755 test_file_soft $TESTFILE $LIMIT $GRACE
756 resetquota -g $TSTUSR
759 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
760 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
761 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
762 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
764 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
768 local GR_STR2="1000s"
770 local GR_STR4="1w2d3h4m5s"
772 local GR_STR6="1111111111111111"
774 wait_delete_completed
776 # test of valid grace strings handling
777 echo "Valid grace strings test"
778 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
779 $GR_STR2 $DIR || error "set user grace time failed"
780 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
781 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
782 $GR_STR4 $DIR || error "set group grace time quota failed"
783 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
785 # test of invalid grace strings handling
786 echo " Invalid grace strings test"
787 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
788 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
791 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
792 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
793 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
794 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
796 run_test 4b "Grace time strings handling"
798 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
800 local BLIMIT=10 # 10M
801 local ILIMIT=10 # 10 inodes
804 trap cleanup_quota_test EXIT
806 set_mdt_qtype "ug" || error "enable mdt quota failed"
807 set_ost_qtype "ug" || error "enable ost quota failed"
809 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
810 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
811 error "set user quota failed"
812 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
813 error "set group quota failed"
815 # make sure the system is clean
816 local USED=$(getquota -u $TSTUSR global curinodes)
817 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
818 USED=$(getquota -g $TSTUSR global curinodes)
819 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
820 USED=$(getquota -u $TSTUSR global curspace)
821 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
822 USED=$(getquota -g $TSTUSR global curspace)
823 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
825 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
826 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
827 error "create failure, expect success"
828 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
829 error "write failure, expect success"
831 echo "Chown files to $TSTUSR.$TSTUSR ..."
832 for i in `seq 0 $ILIMIT`; do
833 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
834 quota_error a $TSTUSR "chown failure, expect success"
838 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
841 resetquota -u $TSTUSR
842 resetquota -g $TSTUSR
844 run_test 5 "Chown & chgrp successfully even out of block/file quota"
846 # test dropping acquire request on master
851 trap cleanup_quota_test EXIT
853 # make sure the system is clean
854 local USED=$(getquota -u $TSTUSR global curspace)
855 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
857 # make sure no granted quota on ost
858 set_ost_qtype "ug" || error "enable ost quota failed"
859 resetquota -u $TSTUSR
861 # create file for $TSTUSR
862 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
863 $LFS setstripe $TESTFILE -c 1 -i 0
864 chown $TSTUSR.$TSTUSR $TESTFILE
866 # create file for $TSTUSR2
867 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
868 $LFS setstripe $TESTFILE2 -c 1 -i 0
869 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
871 # cache per-ID lock for $TSTUSR on slave
872 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
873 error "set quota failed"
874 $RUNAS $DD of=$TESTFILE count=1 ||
875 error "write $TESTFILE failure, expect success"
876 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
877 error "write $TESTFILE2 failure, expect success"
879 sync_all_data || true
881 #define QUOTA_DQACQ 601
882 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
883 lustre_fail mds 0x513 601
885 # write to un-enforced ID ($TSTUSR2) should succeed
886 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
887 error "write failure, expect success"
889 # write to enforced ID ($TSTUSR) in background, exceeding limit
890 # to make sure DQACQ is sent
891 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
894 # watchdog timer uses a factor of 2
895 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
896 sleep $((TIMEOUT * 2 + 1))
898 # write should be blocked and never finished
899 if ! ps -p $DDPID > /dev/null 2>&1; then
901 error "write finished incorrectly!"
906 # no watchdog is triggered
907 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
908 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
909 /Service thread pid/ && /was inactive/ {
913 }' $TMP/lustre-log-${TESTNAME}.log)
914 [ -z "$watchdog" ] || error "$watchdog"
916 rm -f $TMP/lustre-log-${TESTNAME}.log
918 # write should continue & succeed
921 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
922 if [ $count -ge 120 ]; then
923 quota_error u $TSTUSR "dd not finished in $count secs"
926 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
931 resetquota -u $TSTUSR
933 run_test 6 "Test dropping acquire request on master"
935 # quota reintegration (global index)
937 local TESTFILE=$DIR/$tdir/$tfile
940 [ "$SLOW" = "no" ] && LIMIT=5
943 trap cleanup_quota_test EXIT
945 # make sure the system is clean
946 local USED=$(getquota -u $TSTUSR global curspace)
947 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
949 # make sure no granted quota on ost1
950 set_ost_qtype "ug" || error "enable ost quota failed"
951 resetquota -u $TSTUSR
952 set_ost_qtype "none" || error "disable ost quota failed"
954 local OSTUUID=$(ostuuid_from_index 0)
955 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
956 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
960 $LFS setstripe $TESTFILE -c 1 -i 0
961 chown $TSTUSR.$TSTUSR $TESTFILE
966 echo "Enable quota & set quota limit for $TSTUSR"
967 set_ost_qtype "ug" || error "enable ost quota failed"
968 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
969 error "set quota failed"
972 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
975 wait_ost_reint "ug" || error "reintegration failed"
977 # hardlimit should have been fetched by slave during global
978 # reintegration, write will exceed quota
979 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
980 quota_error u $TSTUSR "write success, but expect EDQUOT"
983 wait_delete_completed
984 sync_all_data || true
990 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
991 error "clear quota failed"
994 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
997 wait_ost_reint "ug" || error "reintegration failed"
999 # hardlimit should be cleared on slave during reintegration
1000 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1001 quota_error u $TSTUSR "write error, but expect success"
1004 resetquota -u $TSTUSR
1006 run_test 7a "Quota reintegration (global index)"
1008 # quota reintegration (slave index)
1011 local TESTFILE=$DIR/$tdir/$tfile
1014 trap cleanup_quota_test EXIT
1016 # make sure the system is clean
1017 local USED=$(getquota -u $TSTUSR global curspace)
1018 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1020 # make sure no granted quota on ost1
1021 set_ost_qtype "ug" || error "enable ost quota failed"
1022 resetquota -u $TSTUSR
1023 set_ost_qtype "none" || error "disable ost quota failed"
1025 local OSTUUID=$(ostuuid_from_index 0)
1026 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1027 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1031 $LFS setstripe $TESTFILE -c 1 -i 0
1032 chown $TSTUSR.$TSTUSR $TESTFILE
1034 # consume some space to make sure the granted space will not
1035 # be released during reconciliation
1036 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1037 error "consume space failure, expect success"
1039 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1040 lustre_fail mds 0xa02
1042 set_ost_qtype "ug" || error "enable ost quota failed"
1043 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1044 error "set quota failed"
1046 # ignore the write error
1047 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1049 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1053 echo "Restart ost to trigger reintegration..."
1055 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1058 wait_ost_reint "ug" || error "reintegration failed"
1060 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1061 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1064 resetquota -u $TSTUSR
1067 run_test 7b "Quota reintegration (slave index)"
1069 # quota reintegration (restart mds during reintegration)
1071 local LIMIT=20 # 20M
1072 local TESTFILE=$DIR/$tdir/$tfile
1074 [ "$SLOW" = "no" ] && LIMIT=5
1077 trap cleanup_quota_test EXIT
1079 # make sure the system is clean
1080 local USED=$(getquota -u $TSTUSR global curspace)
1081 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1083 set_ost_qtype "none" || error "disable ost quota failed"
1084 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1085 error "set quota failed"
1087 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1088 lustre_fail ost 0xa03
1091 set_ost_qtype "ug" || error "enable ost quota failed"
1092 # trigger reintegration
1093 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1094 procf=${procf}quota_slave.force_reint
1095 $LCTL set_param $procf=1 || "force reintegration failed"
1103 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1106 # wait longer than usual to make sure the reintegration
1107 # is triggered by quota wb thread.
1108 wait_ost_reint "ug" 200 || error "reintegration failed"
1110 # hardlimit should have been fetched by slave during global
1111 # reintegration, write will exceed quota
1112 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1113 quota_error u $TSTUSR "write success, but expect EDQUOT"
1116 resetquota -u $TSTUSR
1118 run_test 7c "Quota reintegration (restart mds during reintegration)"
1120 # Quota reintegration (Transfer index in multiple bulks)
1122 local TESTFILE=$DIR/$tdir/$tfile
1123 local TESTFILE1="$DIR/$tdir/$tfile"-1
1127 trap cleanup_quota_test EXIT
1129 set_ost_qtype "none" || error "disable ost quota failed"
1130 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1131 error "set quota for $TSTUSR failed"
1132 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1133 error "set quota for $TSTUSR2 failed"
1135 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1136 lustre_fail mds 0x608 0
1138 # enable quota to tirgger reintegration
1139 set_ost_qtype "u" || error "enable ost quota failed"
1140 wait_ost_reint "u" || error "reintegration failed"
1144 # hardlimit should have been fetched by slave during global
1145 # reintegration, write will exceed quota
1146 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1147 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1149 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1150 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1153 resetquota -u $TSTUSR
1154 resetquota -u $TSTUSR2
1156 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1158 # quota reintegration (inode limits)
1160 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1162 local ilimit=$((1024 * 2)) # 2k inodes
1163 local TESTFILE=$DIR/${tdir}-1/$tfile
1166 trap cleanup_quota_test EXIT
1168 # make sure the system is clean
1169 local USED=$(getquota -u $TSTUSR global curinodes)
1170 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1172 # make sure no granted quota on mdt1
1173 set_mdt_qtype "ug" || error "enable mdt quota failed"
1174 resetquota -u $TSTUSR
1175 set_mdt_qtype "none" || error "disable mdt quota failed"
1177 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1178 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1179 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1182 echo "Stop mds${MDSCOUNT}..."
1185 echo "Enable quota & set quota limit for $TSTUSR"
1186 set_mdt_qtype "ug" || error "enable mdt quota failed"
1187 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1188 error "set quota failed"
1190 echo "Start mds${MDSCOUNT}..."
1191 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1194 wait_mdt_reint "ug" || error "reintegration failed"
1196 echo "create remote dir"
1197 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1198 error "create remote dir failed"
1199 chmod 0777 $DIR/${tdir}-1
1201 # hardlimit should have been fetched by slave during global
1202 # reintegration, create will exceed quota
1203 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1204 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1206 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1207 wait_delete_completed
1208 sync_all_data || true
1210 echo "Stop mds${MDSCOUNT}..."
1213 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1214 error "clear quota failed"
1216 echo "Start mds${MDSCOUNT}..."
1217 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1220 wait_mdt_reint "ug" || error "reintegration failed"
1222 # hardlimit should be cleared on slave during reintegration
1223 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1224 quota_error -u $TSTUSR "create failed, expect success"
1226 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1227 $LFS rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1230 resetquota -u $TSTUSR
1232 run_test 7e "Quota reintegration (inode limits)"
1234 # run dbench with quota enabled
1236 local BLK_LIMIT="100g" #100G
1237 local FILE_LIMIT=1000000
1240 trap cleanup_quota_test EXIT
1242 set_mdt_qtype "ug" || error "enable mdt quota failed"
1243 set_ost_qtype "ug" || error "enable ost quota failed"
1245 echo "Set enough high limit for user: $TSTUSR"
1246 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1247 error "set user quota failed"
1248 echo "Set enough high limit for group: $TSTUSR"
1249 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1250 error "set group quota failed"
1253 [ "$SLOW" = "no" ] && duration=" -t 120"
1254 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1255 quota_error a $TSTUSR "dbench failed!"
1258 resetquota -u $TSTUSR
1259 resetquota -g $TSTUSR
1261 run_test 8 "Run dbench with quota enabled"
1263 # this check is just for test_9
1264 OST0_MIN=4900000 #4.67G
1266 check_whether_skip () {
1267 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1268 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1269 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1270 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1277 # run for fixing bug10707, it needs a big room. test for 64bit
1279 local filesize=$((1024 * 9 / 2)) # 4.5G
1281 check_whether_skip && return 0
1284 trap cleanup_quota_test EXIT
1286 set_ost_qtype "ug" || error "enable ost quota failed"
1288 local TESTFILE="$DIR/$tdir/$tfile-0"
1289 local BLK_LIMIT=100G #100G
1290 local FILE_LIMIT=1000000
1292 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1294 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1296 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1297 error "set user quota failed"
1299 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1300 "for group: $TSTUSR"
1301 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1302 error "set group quota failed"
1304 quota_show_check a u $TSTUSR
1305 quota_show_check a g $TSTUSR
1307 echo "Create test file"
1308 $LFS setstripe $TESTFILE -c 1 -i 0
1309 chown $TSTUSR.$TSTUSR $TESTFILE
1311 log "Write the big file of 4.5G ..."
1312 $RUNAS $DD of=$TESTFILE count=$filesize ||
1313 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1319 resetquota -u $TSTUSR
1320 resetquota -g $TSTUSR
1325 run_test 9 "Block limit larger than 4GB (b10707)"
1328 local TESTFILE=$DIR/$tdir/$tfile
1331 trap cleanup_quota_test EXIT
1333 # set limit to root user should fail
1334 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1335 error "set limit for root user successfully, expect failure"
1336 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1337 error "set limit for root group successfully, expect failure"
1339 # root user can overrun quota
1340 set_ost_qtype "ug" || "enable ost quota failed"
1342 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1343 error "set quota failed"
1344 quota_show_check b u $TSTUSR
1346 $LFS setstripe $TESTFILE -c 1
1347 chown $TSTUSR.$TSTUSR $TESTFILE
1349 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1350 error "write failure, expect success"
1353 resetquota -u $TSTUSR
1355 run_test 10 "Test quota for root user"
1358 local TESTFILE=$DIR/$tdir/$tfile
1360 trap cleanup_quota_test EXIT
1362 set_mdt_qtype "ug" || "enable mdt quota failed"
1363 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1364 error "set quota failed"
1369 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1370 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1373 local USED=$(getquota -u $TSTUSR global curinodes)
1374 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1377 resetquota -u $TSTUSR
1379 run_test 11 "Chown/chgrp ignores quota"
1382 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1384 local blimit=22 # 22M
1385 local blk_cnt=$((blimit - 5))
1386 local TESTFILE0="$DIR/$tdir/$tfile"-0
1387 local TESTFILE1="$DIR/$tdir/$tfile"-1
1390 trap cleanup_quota_test EXIT
1392 set_ost_qtype "u" || "enable ost quota failed"
1393 quota_show_check b u $TSTUSR
1395 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1396 error "set quota failed"
1398 $LFS setstripe $TESTFILE0 -c 1 -i 0
1399 $LFS setstripe $TESTFILE1 -c 1 -i 1
1400 chown $TSTUSR.$TSTUSR $TESTFILE0
1401 chown $TSTUSR.$TSTUSR $TESTFILE1
1403 echo "Write to ost0..."
1404 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1405 quota_error a $TSTUSR "dd failed"
1407 echo "Write to ost1..."
1408 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1409 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1411 echo "Free space from ost0..."
1413 wait_delete_completed
1414 sync_all_data || true
1416 echo "Write to ost1 after space freed from ost0..."
1417 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1418 quota_error a $TSTUSR "rebalancing failed"
1421 resetquota -u $TSTUSR
1423 run_test 12a "Block quota rebalancing"
1426 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1428 local ilimit=$((1024 * 2)) # 2k inodes
1429 local TESTFILE0=$DIR/$tdir/$tfile
1430 local TESTFILE1=$DIR/${tdir}-1/$tfile
1433 trap cleanup_quota_test EXIT
1435 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1436 chmod 0777 $DIR/${tdir}-1
1438 set_mdt_qtype "u" || "enable mdt quota failed"
1439 quota_show_check f u $TSTUSR
1441 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1442 error "set quota failed"
1444 echo "Create $ilimit files on mdt0..."
1445 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1446 quota_error u $TSTUSR "create failed, but expect success"
1448 echo "Create files on mdt1..."
1449 $RUNAS createmany -m $TESTFILE1 1 &&
1450 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1452 echo "Free space from mdt0..."
1453 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1454 wait_delete_completed
1455 sync_all_data || true
1457 echo "Create files on mdt1 after space freed from mdt0..."
1458 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1459 quota_error a $TSTUSR "rebalancing failed"
1461 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1462 error "unlink mdt1 files failed"
1463 $LFS rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1466 resetquota -u $TSTUSR
1468 run_test 12b "Inode quota rebalancing"
1471 local TESTFILE=$DIR/$tdir/$tfile
1472 # the name of osp on ost1 name is MDT0000-osp-OST0000
1473 local procf="ldlm.namespaces.*MDT0000-osp-OST0000.lru_size"
1476 trap cleanup_quota_test EXIT
1478 set_ost_qtype "u" || "enable ost quota failed"
1479 quota_show_check b u $TSTUSR
1481 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1482 error "set quota failed"
1483 $LFS setstripe $TESTFILE -c 1 -i 0
1484 chown $TSTUSR.$TSTUSR $TESTFILE
1486 # clear the locks in cache first
1487 do_facet ost1 $LCTL set_param -n $procf=clear
1488 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1489 [ $nlock -eq 0 ] || error "$nlock cached locks"
1491 # write to acquire the per-ID lock
1492 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1493 quota_error a $TSTUSR "dd failed"
1495 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1496 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1498 # clear quota doesn't trigger per-ID lock cancellation
1499 resetquota -u $TSTUSR
1500 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1501 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1503 # clear the per-ID lock
1504 do_facet ost1 $LCTL set_param -n $procf=clear
1505 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1506 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1508 # spare quota should be released
1509 local OSTUUID=$(ostuuid_from_index 0)
1510 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1511 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1512 [ $limit -le $space ] ||
1513 error "spare quota isn't released, limit:$limit, space:$space"
1517 run_test 13 "Cancel per-ID lock in the LRU list"
1520 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1522 wait_delete_completed
1523 sync_all_data || true
1526 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1527 error "set user quota failed"
1528 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1529 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1530 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1531 resetquota -u $TSTUSR
1534 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1535 error "set group quota failed"
1536 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1537 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1538 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1539 resetquota -g $TSTUSR
1541 run_test 15 "Set over 4T block quota"
1545 local BLKS=1 # 1M less than limit
1546 local TESTFILE=$DIR/$tdir/$tfile
1549 trap cleanup_quota_test EXIT
1551 # make sure the system is clean
1552 local USED=$(getquota -u $TSTUSR global curspace)
1553 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1555 set_ost_qtype "ug" || error "enable ost quota failed"
1556 # make sure no granted quota on ost
1557 resetquota -u $TSTUSR
1558 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1559 error "set quota failed"
1561 quota_show_check b u $TSTUSR
1563 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1564 lustre_fail mds 0xa04 $err_code
1566 # write in background
1567 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1571 # write should be blocked and never finished
1572 if ! ps -p $DDPID > /dev/null 2>&1; then
1574 quota_error u $TSTUSR "write finished incorrectly!"
1582 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1584 if [ $count -gt $timeout ]; then
1585 quota_error u $TSTUSR "dd is not finished!"
1590 sync; sync_all_data || true
1592 USED=$(getquota -u $TSTUSR global curspace)
1593 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1594 "Used space(${USED}K) is less than ${BLKS}M"
1597 resetquota -u $TSTUSR
1600 # DQACQ return recoverable error
1602 echo "DQACQ return -ENOLCK"
1604 test_17sub 37 || error "Handle -ENOLCK failed"
1606 echo "DQACQ return -EAGAIN"
1608 test_17sub 11 || error "Handle -EAGAIN failed"
1610 echo "DQACQ return -ETIMEDOUT"
1611 #define ETIMEDOUT 110
1612 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1614 echo "DQACQ return -ENOTCONN"
1615 #define ENOTCONN 107
1616 test_17sub 107 || error "Handle -ENOTCONN failed"
1619 run_test 17 "DQACQ return recoverable error"
1623 local blimit="200m" # 200M
1624 local TESTFILE="$DIR/$tdir/$tfile"
1627 trap cleanup_quota_test EXIT
1629 set_ost_qtype "u" || error "enable ost quota failed"
1630 log "User quota (limit: $blimit)"
1631 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1632 error "set quota failed"
1633 quota_show_check b u $TSTUSR
1635 $LFS setstripe $TESTFILE -i 0 -c 1
1636 chown $TSTUSR.$TSTUSR $TESTFILE
1638 local timeout=$(sysctl -n lustre.timeout)
1640 if [ $io_type = "directio" ]; then
1641 log "Write 100M (directio) ..."
1642 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1644 log "Write 100M (buffered) ..."
1645 $RUNAS $DD of=$TESTFILE count=100 &
1649 replay_barrier $SINGLEMDS
1650 log "Fail mds for $((2 * timeout)) seconds"
1651 fail $SINGLEMDS $((2 * timeout))
1654 if at_is_enabled; then
1655 timeout=$(at_max_get mds)
1657 timeout=$(lctl get_param -n timeout)
1661 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1662 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1663 log "it took $count second"
1668 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1670 cancel_lru_locks mdc
1671 cancel_lru_locks osc
1674 local testfile_size=$(stat -c %s $TESTFILE)
1675 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1676 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1677 "got ${testfile_size}. Verifying file failed!"
1680 resetquota -u $TSTUSR
1683 # test when mds does failover, the ost still could work well
1684 # this test shouldn't trigger watchdog b=14840
1687 test_18_sub directio
1689 # check if watchdog is triggered
1690 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1691 local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
1692 /Service thread pid/ && /was inactive/ {
1696 }' $TMP/lustre-log-${TESTNAME}.log)
1697 [ -z "$watchdog" ] || error "$watchdog"
1698 rm -f $TMP/lustre-log-${TESTNAME}.log
1700 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1704 local TESTFILE=$DIR/$tdir/$tfile
1707 trap cleanup_quota_test EXIT
1709 set_ost_qtype "ug" || error "enable ost quota failed"
1711 # bind file to a single OST
1712 $LFS setstripe -c 1 $TESTFILE
1713 chown $TSTUSR.$TSTUSR $TESTFILE
1715 echo "Set user quota (limit: "$blimit"M)"
1716 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1717 error "set user quota failed"
1718 quota_show_check b u $TSTUSR
1719 echo "Update quota limits"
1720 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1721 error "set group quota failed"
1722 quota_show_check b u $TSTUSR
1724 # first wirte might be cached
1725 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1726 cancel_lru_locks osc
1728 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1729 quota_error u $TSTUSR "Write success, expect failure"
1733 resetquota -u $TSTUSR
1735 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1737 test_20() { # b15754
1738 local LSTR=(2g 1t 4k 3m) # limits strings
1740 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1742 resetquota -u $TSTUSR
1744 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1745 $MOUNT || error "could not set quota limits"
1746 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1747 --inode-softlimit ${LSTR[2]} \
1748 --inode-hardlimit ${LSTR[3]} \
1749 $MOUNT || error "could not set quota limits"
1751 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1752 error "bsoftlimit was not set properly"
1753 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1754 error "bhardlimit was not set properly"
1755 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1756 error "isoftlimit was not set properly"
1757 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1758 error "ihardlimit was not set properly"
1760 resetquota -u $TSTUSR
1762 run_test 20 "Test if setquota specifiers work properly (b15754)"
1769 local time=$(($(date +%s) + seconds))
1770 while [ $(date +%s) -lt $time ]; do
1771 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1775 # run for fixing bug16053, setquota shouldn't fail when writing and
1776 # deleting are happening
1778 local TESTFILE="$DIR/$tdir/$tfile"
1779 local BLIMIT=10 # 10G
1780 local ILIMIT=1000000
1783 trap cleanup_quota_test EXIT
1785 set_ost_qtype "ug" || error "Enable ost quota failed"
1787 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1788 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1789 error "set user quota failed"
1790 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1791 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1792 error "set group quota failed"
1794 # repeat writing on a 1M file
1795 test_21_sub ${TESTFILE}_1 1 30 &
1797 # repeat writing on a 128M file
1798 test_21_sub ${TESTFILE}_2 128 30 &
1801 local time=$(($(date +%s) + 30))
1803 while [ $(date +%s) -lt $time ]; do
1804 log "Set quota for $i times"
1805 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1806 -I $((ILIMIT + i)) $MOUNT ||
1807 error "Set user quota failed"
1808 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1809 -I $((ILIMIT + i)) $MOUNT ||
1810 error "Set group quota failed"
1817 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1819 if [ $count -gt 60 ]; then
1820 quota_error a $TSTUSR "dd should be finished!"
1824 echo "(dd_pid=$DDPID1, time=$count)successful"
1828 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1830 if [ $count -gt 60 ]; then
1831 quota_error a $TSTUSR "dd should be finished!"
1835 echo "(dd_pid=$DDPID2, time=$count)successful"
1838 resetquota -u $TSTUSR
1839 resetquota -g $TSTUSR
1841 run_test 21 "Setquota while writing & deleting (b16053)"
1843 # enable/disable quota enforcement permanently
1845 echo "Set both mdt & ost quota type as ug"
1846 set_mdt_qtype "ug" || error "enable mdt quota failed"
1847 set_ost_qtype "ug" || error "enable ost quota failed"
1854 echo "Verify if quota is enabled"
1855 local qtype=$(mdt_quota_type)
1856 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1857 qtype=$(ost_quota_type)
1858 [ $qtype != "ug" ] && error "ost quota setting is lost"
1860 echo "Set both mdt & ost quota type as none"
1861 set_mdt_qtype "none" || error "disable mdt quota failed"
1862 set_ost_qtype "none" || error "disable ost quota failed"
1870 echo "Verify if quota is disabled"
1871 qtype=$(mdt_quota_type)
1872 [ $qtype != "none" ] && error "mdt quota setting is lost"
1873 qtype=$(ost_quota_type)
1874 [ $qtype != "none" ] && error "ost quota setting is lost"
1878 run_test 22 "enable/disable quota by 'lctl conf_param'"
1881 local TESTFILE="$DIR/$tdir/$tfile"
1885 trap cleanup_quota_test EXIT
1887 set_ost_qtype "ug" || error "Enable ost quota failed"
1890 log "User quota (limit: $LIMIT MB)"
1891 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1892 error "set quota failed"
1893 quota_show_check b u $TSTUSR
1895 $LFS setstripe $TESTFILE -c 1 -i 0
1896 chown $TSTUSR.$TSTUSR $TESTFILE
1898 log "Step1: trigger EDQUOT with O_DIRECT"
1899 log "Write half of file"
1900 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1901 quota_error u $TSTUSR "(1) Write failure, expect success." \
1903 log "Write out of block quota ..."
1904 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1905 oflag=direct conv=notrunc &&
1906 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1910 log "Step2: rewrite should succeed"
1911 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1912 quota_error u $TSTUSR "(3) Write failure, expect success." \
1918 local OST0_UUID=$(ostuuid_from_index 0)
1919 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1920 [ $OST0_QUOTA_USED -ne 0 ] &&
1921 ($SHOW_QUOTA_USER; \
1922 quota_error u $TSTUSR "quota isn't released")
1924 resetquota -u $TSTUSR
1928 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1929 check_whether_skip && return 0
1930 log "run for 4MB test file"
1933 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1934 check_whether_skip && return 0
1935 log "run for 40MB test file"
1938 run_test 23 "Quota should be honored with directIO (b16125)"
1942 local TESTFILE="$DIR/$tdir/$tfile"
1945 trap cleanup_quota_test EXIT
1947 set_ost_qtype "ug" || error "enable ost quota failed"
1949 # bind file to a single OST
1950 $LFS setstripe -c 1 $TESTFILE
1951 chown $TSTUSR.$TSTUSR $TESTFILE
1953 echo "Set user quota (limit: "$blimit"M)"
1954 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1955 error "set quota failed"
1957 # overrun quota by root user
1958 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1959 error "write failure, expect success"
1960 cancel_lru_locks osc
1961 sync_all_data || true
1963 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1966 resetquota -u $TSTUSR
1968 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1970 test_27a() { # b19612
1971 $LFS quota $TSTUSR $DIR &&
1972 error "lfs succeeded with no type, but should have failed"
1973 $LFS setquota $TSTUSR $DIR &&
1974 error "lfs succeeded with no type, but should have failed"
1977 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1979 test_27b() { # b20200
1980 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1981 error "lfs setquota failed with uid argument"
1982 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1983 error "lfs stequota failed with gid argument"
1984 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1985 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1986 resetquota -u $TSTUSR
1987 resetquota -g $TSTUSR
1990 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1995 local TESTFILE="$DIR/$tdir/$tfile"
1999 trap cleanup_quota_test EXIT
2001 set_ost_qtype "u" || error "enable ost quota failed"
2003 $LFS setstripe $TESTFILE -i 0 -c 1
2004 chown $TSTUSR.$TSTUSR $TESTFILE
2006 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2007 $MAX_IQ_TIME $DIR || error "set grace time failed"
2008 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2009 error "set quota failed"
2010 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2011 cancel_lru_locks osc
2013 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2014 # over-quota flag has not yet settled since we do not trigger async
2015 # events based on grace time period expiration
2017 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2018 cancel_lru_locks osc
2019 # now over-quota flag should be settled and further writes should fail
2021 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2022 error "grace times were reset"
2025 resetquota -u $TSTUSR
2026 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2027 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2029 run_test 30 "Hard limit updates should not reset grace times"
2031 # basic usage tracking for user & group
2033 local INODES=10 # 10 files
2034 local BLK_CNT=2 # of 2M each
2035 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2038 trap cleanup_quota_test EXIT
2040 # make sure the system is clean
2041 local USED=$(getquota -u $TSTID global curspace)
2043 error "Used space ($USED) for user $TSTID isn't 0."
2044 USED=$(getquota -g $TSTID global curspace)
2046 error "Used space ($USED) for group $TSTID isn't 0."
2048 echo "Write files..."
2049 for i in `seq 0 $INODES`; do
2050 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2051 error "write failed"
2052 echo "Iteration $i/$INODES completed"
2054 cancel_lru_locks osc
2055 sync; sync_all_data || true
2057 echo "Verify disk usage after write"
2058 USED=$(getquota -u $TSTID global curspace)
2059 [ $USED -lt $TOTAL_BLKS ] &&
2060 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2061 USED=$(getquota -g $TSTID global curspace)
2062 [ $USED -lt $TOTAL_BLKS ] &&
2063 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2065 echo "Verify inode usage after write"
2066 USED=$(getquota -u $TSTID global curinodes)
2067 [ $USED -lt $INODES ] &&
2068 error "Used inode for user $TSTID is $USED, expected $INODES"
2069 USED=$(getquota -g $TSTID global curinodes)
2070 [ $USED -lt $INODES ] &&
2071 error "Used inode for group $TSTID is $USED, expected $INODES"
2075 echo "Verify disk usage after delete"
2076 USED=$(getquota -u $TSTID global curspace)
2077 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2078 USED=$(getquota -u $TSTID global curinodes)
2079 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2080 USED=$(getquota -g $TSTID global curspace)
2081 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2082 USED=$(getquota -g $TSTID global curinodes)
2083 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2085 run_test 33 "Basic usage tracking for user & group"
2087 # usage transfer test for user & group
2089 local BLK_CNT=2 # 2MB
2092 trap cleanup_quota_test EXIT
2094 # make sure the system is clean
2095 local USED=$(getquota -u $TSTID global curspace)
2096 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2097 USED=$(getquota -g $TSTID global curspace)
2098 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2100 echo "Write file..."
2101 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2102 error "write failed"
2103 cancel_lru_locks osc
2104 sync; sync_all_data || true
2106 echo "chown the file to user $TSTID"
2107 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2109 echo "Wait for setattr on objects finished..."
2110 wait_delete_completed
2112 BLK_CNT=$((BLK_CNT * 1024))
2114 echo "Verify disk usage for user $TSTID"
2115 USED=$(getquota -u $TSTID global curspace)
2116 [ $USED -lt $BLK_CNT ] &&
2117 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2118 USED=$(getquota -u $TSTID global curinodes)
2120 error "Used inodes for user $TSTID is $USED, expected 1"
2122 echo "chgrp the file to group $TSTID"
2123 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2125 echo "Wait for setattr on objects finished..."
2126 wait_delete_completed
2128 echo "Verify disk usage for group $TSTID"
2129 USED=$(getquota -g $TSTID global curspace)
2130 [ $USED -ge $BLK_CNT ] ||
2131 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2132 USED=$(getquota -g $TSTID global curinodes)
2134 error "Used inodes for group $TSTID is $USED, expected 1"
2138 run_test 34 "Usage transfer for user & group"
2140 # usage is still accessible across restart
2142 local BLK_CNT=2 # 2 MB
2145 trap cleanup_quota_test EXIT
2147 echo "Write file..."
2148 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2149 error "write failed"
2150 cancel_lru_locks osc
2151 sync; sync_all_data || true
2153 echo "Save disk usage before restart"
2154 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2155 [ $ORIG_USR_SPACE -eq 0 ] &&
2156 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2157 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2158 [ $ORIG_USR_INODES -eq 0 ] &&
2159 error "Used inodes for user $TSTID is 0, expected 1"
2160 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2161 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2162 [ $ORIG_GRP_SPACE -eq 0 ] &&
2163 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2164 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2165 [ $ORIG_GRP_INODES -eq 0 ] &&
2166 error "Used inodes for group $TSTID is 0, expected 1"
2167 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2170 local ORIG_REFORMAT=$REFORMAT
2172 cleanup_and_setup_lustre
2173 REFORMAT=$ORIG_REFORMAT
2176 echo "Verify disk usage after restart"
2177 local USED=$(getquota -u $TSTID global curspace)
2178 [ $USED -eq $ORIG_USR_SPACE ] ||
2179 error "Used space for user $TSTID changed from " \
2180 "$ORIG_USR_SPACE to $USED"
2181 USED=$(getquota -u $TSTID global curinodes)
2182 [ $USED -eq $ORIG_USR_INODES ] ||
2183 error "Used inodes for user $TSTID changed from " \
2184 "$ORIG_USR_INODES to $USED"
2185 USED=$(getquota -g $TSTID global curspace)
2186 [ $USED -eq $ORIG_GRP_SPACE ] ||
2187 error "Used space for group $TSTID changed from " \
2188 "$ORIG_GRP_SPACE to $USED"
2189 USED=$(getquota -g $TSTID global curinodes)
2190 [ $USED -eq $ORIG_GRP_INODES ] ||
2191 error "Used inodes for group $TSTID changed from " \
2192 "$ORIG_GRP_INODES to $USED"
2194 # check if the vfs_dq_init() is called before writing
2195 echo "Append to the same file..."
2196 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2197 error "write failed"
2198 cancel_lru_locks osc
2199 sync; sync_all_data || true
2201 echo "Verify space usage is increased"
2202 USED=$(getquota -u $TSTID global curspace)
2203 [ $USED -gt $ORIG_USR_SPACE ] ||
2204 error "Used space for user $TSTID isn't increased" \
2205 "orig:$ORIG_USR_SPACE, now:$USED"
2206 USED=$(getquota -g $TSTID global curspace)
2207 [ $USED -gt $ORIG_GRP_SPACE ] ||
2208 error "Used space for group $TSTID isn't increased" \
2209 "orig:$ORIG_GRP_SPACE, now:$USED"
2213 run_test 35 "Usage is still accessible across reboot"
2215 # test migrating old amdin quota files (in Linux quota file format v2) into new
2216 # quota global index (in IAM format)
2218 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2219 skip "skipping migration test" && return
2221 # get the mdt0 device name
2222 local mdt0_node=$(facet_active_host $SINGLEMDS)
2223 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2228 echo "Copy admin quota files into MDT0..."
2229 local mntpt=$(facet_mntpt $SINGLEMDS)
2230 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2232 if ! do_node $mdt0_node test -b $mdt0_fstype; then
2235 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2236 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2237 do_node $mdt0_node mkdir $mntpt/OBJECTS
2238 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2239 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2240 do_node $mdt0_node umount -f $mntpt
2245 echo "Verify global limits..."
2249 local proc="qmt.*.md-0x0.glb-usr"
2250 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2251 [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2252 limit=$(getquota -u 1 global isoftlimit)
2253 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2254 limit=$(getquota -u 1 global ihardlimit)
2255 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2257 proc="qmt.*.md-0x0.glb-grp"
2258 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2259 [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2260 limit=$(getquota -g 1 global isoftlimit)
2261 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2262 limit=$(getquota -g 1 global ihardlimit)
2263 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2265 proc=" qmt.*.dt-0x0.glb-usr"
2266 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2267 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2268 limit=$(getquota -u 60001 global bsoftlimit)
2269 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2270 limit=$(getquota -u 60001 global bhardlimit)
2271 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2273 proc="qmt.*.dt-0x0.glb-grp"
2274 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2275 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2276 limit=$(getquota -g 60001 global bsoftlimit)
2277 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2278 limit=$(getquota -g 60001 global bhardlimit)
2279 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2285 run_test 36 "Migrate old admin files into new global indexes"
2289 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2295 check_and_cleanup_lustre
2296 export QUOTA_AUTO=$QUOTA_AUTO_OLD