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 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
53 # bug number for skipped test: LU-2836 LU-2837 LU-2059
54 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 6 7d"
56 [ "$SLOW" = "no" ] && EXCEPT_SLOW="9 18 21"
58 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
60 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
65 QUOTA_AUTO_OLD=$QUOTA_AUTO
68 check_and_setup_lustre
70 LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
71 OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
73 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
74 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
75 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
76 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
77 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
78 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $DIR"
79 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
80 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
87 local fail_val=${3:-0}
89 if [ $fail_node == "mds" ] || [ $fail_node == "mds_ost" ]; then
90 do_facet $SINGLEMDS "lctl set_param fail_val=$fail_val"
91 do_facet $SINGLEMDS "lctl set_param fail_loc=$fail_loc"
94 if [ $fail_node == "ost" ] || [ $fail_node == "mds_ost" ]; then
95 for num in `seq $OSTCOUNT`; do
96 do_facet ost$num "lctl set_param fail_val=$fail_val"
97 do_facet ost$num "lctl set_param fail_loc=$fail_loc"
102 RUNAS="runas -u $TSTID -g $TSTID"
103 RUNAS2="runas -u $TSTID2 -g $TSTID2"
104 DD="dd if=/dev/zero bs=1M"
108 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
109 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
110 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
111 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
113 # clear quota limits for a user or a group
114 # usage: resetquota -u username
115 # resetquota -g groupname
118 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
119 [ "$1" != "-u" -a "$1" != "-g" ] &&
120 error "resetquota: wrong specifier $1 passed"
122 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
123 error "clear quota for [type:$1 name:$2] failed"
124 # give a chance to slave to release space
132 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
133 $LFS quota -v -u $LOCAL_ID $DIR
134 log "Files for user ($LOCAL_ID):"
135 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
136 xargs stat 2>/dev/null)
139 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
140 $LFS quota -v -u $LOCAL_ID $DIR
141 log "Files for group ($LOCAL_ID):"
142 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
143 xargs stat 2>/dev/null)
159 # get quota for a user or a group
160 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
161 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
167 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
168 [ "$1" != "-u" -a "$1" != "-g" ] &&
169 error "getquota: wrong u/g specifier $1 passed"
182 *) error "unknown quota parameter $4";;
185 [ "$uuid" = "global" ] && uuid=$DIR
187 $LFS quota -v "$1" "$2" $DIR |
188 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
189 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
194 # usage: set_mdt_qtype ug|u|g|none
198 local mdts=$(get_facets MDS)
200 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
201 # we have to make sure each MDT received config changes
202 for mdt in ${mdts//,/ }; do
204 cmd="$LCTL get_param -n "
205 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
206 cmd=${cmd}.quota_slave.enabled
208 if $(facet_up $mdt); then
209 wait_update_facet $mdt "$cmd" "$qtype" || return 1
216 # usage: set_ost_qtype ug|u|g|none
220 local osts=$(get_facets OST)
222 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
223 # we have to make sure each OST received config changes
224 for ost in ${osts//,/ }; do
226 cmd="$LCTL get_param -n "
227 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
228 cmd=${cmd}.quota_slave.enabled
230 if $(facet_up $ost); then
231 wait_update_facet $ost "$cmd" "$qtype" || return 1
237 wait_reintegration() {
241 local result="glb[1],slv[1],reint[0]"
246 if [ $ntype == "mdt" ]; then
247 tgts=$(get_facets MDS)
249 tgts=$(get_facets OST)
252 for tgt in ${tgts//,/ }; do
254 cmd="$LCTL get_param -n "
255 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
256 cmd=${cmd}.quota_slave.info
258 if $(facet_up $tgt); then
259 wait_update_facet $tgt "$cmd |
260 grep "$qtype" | awk '{ print \\\$3 }'" \
261 "$result" $max || return 1
271 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
272 wait_reintegration "mdt" "user" $max || return 1
275 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
276 wait_reintegration "mdt" "group" $max || return 1
285 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
286 wait_reintegration "ost" "user" $max || return 1
289 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
290 wait_reintegration "ost" "group" $max || return 1
297 wait_delete_completed
298 echo "Creating test directory"
300 chmod 0777 $DIR/$tdir
301 # always clear fail_loc in case of fail_loc isn't cleared
302 # properly when previous test failed
303 lustre_fail mds_ost 0
306 cleanup_quota_test() {
308 echo "Delete files..."
310 echo "Wait for unlink objects finished..."
311 wait_delete_completed
312 sync_all_data || true
321 $LFS quota -v -$ug $qid $DIR
323 if [ "$bf" == "a" -o "$bf" == "b" ]; then
324 usage=$(getquota -$ug $qid global curspace)
325 if [ -z $usage ]; then
326 quota_error $ug $qid \
327 "Query block quota failed ($ug:$qid)."
329 [ $usage -ne 0 ] && quota_log $ug $qid \
330 "Block quota isn't 0 ($ug:$qid:$usage)."
334 if [ "$bf" == "a" -o "$bf" == "f" ]; then
335 usage=$(getquota -$ug $qid global curinodes)
336 if [ -z $usage ]; then
337 quota_error $ug $qid \
338 "Query file quota failed ($ug:$qid)."
340 [ $usage -ne 0 ] && quota_log $ug $qid \
341 "File quota isn't 0 ($ug:$qid:$usage)."
348 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
352 resetquota -u $TSTUSR
353 resetquota -g $TSTUSR
354 resetquota -u $TSTUSR2
355 resetquota -g $TSTUSR2
357 test_quota_performance() {
358 local TESTFILE="$DIR/$tdir/$tfile-0"
359 local size=$1 # in MB
360 local stime=$(date +%s)
361 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
362 quota_error u $TSTUSR "write failure"
363 local etime=$(date +%s)
364 delta=$((etime - stime))
365 if [ $delta -gt 0 ]; then
366 rate=$((size * 1024 / delta))
367 [ $rate -gt 1024 ] ||
368 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
373 # test basic quota performance b=21696
376 [ "$SLOW" = "no" ] && MB=10
378 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
379 [ $free_space -le $((MB * 1024)) ] &&
380 skip "not enough space ${free_space} KB, " \
381 "required $((MB * 1024)) KB" && return
383 trap cleanup_quota_test EXIT
385 set_ost_qtype "none" || error "disable ost quota failed"
386 test_quota_performance $MB
388 set_ost_qtype "ug" || error "enable ost quota failed"
389 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
390 error "set quota failed"
391 test_quota_performance $MB
394 resetquota -u $TSTUSR
396 run_test 0 "Test basic quota performance"
398 # test block hardlimit
401 local TESTFILE="$DIR/$tdir/$tfile-0"
404 trap cleanup_quota_test EXIT
407 set_ost_qtype "ug" || "enable ost quota failed"
410 log "User quota (block hardlimit:$LIMIT MB)"
411 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
412 error "set user quota failed"
414 # make sure the system is clean
415 local USED=$(getquota -u $TSTUSR global curspace)
416 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
418 $LFS setstripe $TESTFILE -c 1
419 chown $TSTUSR.$TSTUSR $TESTFILE
422 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
423 quota_error u $TSTUSR "user write failure, but expect success"
424 log "Write out of block quota ..."
425 # this time maybe cache write, ignore it's failure
426 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
427 # flush cache, ensure noquota flag is set on client
429 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
430 quota_error u $TSTUSR "user write success, but expect EDQUOT"
433 wait_delete_completed
434 sync_all_data || true
435 USED=$(getquota -u $TSTUSR global curspace)
436 [ $USED -ne 0 ] && quota_error u $TSTUSR \
437 "user quota isn't released after deletion"
438 resetquota -u $TSTUSR
441 log "--------------------------------------"
442 log "Group quota (block hardlimit:$LIMIT MB)"
443 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
444 error "set group quota failed"
446 TESTFILE="$DIR/$tdir/$tfile-1"
447 # make sure the system is clean
448 USED=$(getquota -g $TSTUSR global curspace)
449 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
451 $LFS setstripe $TESTFILE -c 1
452 chown $TSTUSR.$TSTUSR $TESTFILE
455 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
456 quota_error g $TSTUSR "group write failure, but expect success"
457 log "Write out of block quota ..."
458 # this time maybe cache write, ignore it's failure
459 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
461 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
462 quota_error g $TSTUSR "group write success, but expect EDQUOT"
467 USED=$(getquota -g $TSTUSR global curspace)
468 [ $USED -ne 0 ] && quota_error g $TSTUSR \
469 "group quota isn't released after deletion"
471 resetquota -g $TSTUSR
473 run_test 1 "Block hard limit (normal use and out of quota)"
475 # test inode hardlimit
477 local LIMIT=$((1024 * 1024)) # 1M inodes
478 local TESTFILE="$DIR/$tdir/$tfile-0"
480 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
482 local FREE_INODES=$(lfs_df -i | grep "summary" | awk '{print $4}')
483 [ $FREE_INODES -lt $LIMIT ] &&
484 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
488 trap cleanup_quota_test EXIT
491 set_mdt_qtype "ug" || "enable mdt quota failed"
494 log "User quota (inode hardlimit:$LIMIT files)"
495 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
496 error "set user quota failed"
498 # make sure the system is clean
499 local USED=$(getquota -u $TSTUSR global curinodes)
500 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
502 log "Create $LIMIT files ..."
503 $RUNAS createmany -m ${TESTFILE} $LIMIT || \
504 quota_error u $TSTUSR "user create failure, but expect success"
505 log "Create out of file quota ..."
506 $RUNAS touch ${TESTFILE}_xxx && \
507 quota_error u $TSTUSR "user create success, but expect EDQUOT"
510 unlinkmany ${TESTFILE} $LIMIT
511 rm -f ${TESTFILE}_xxx
512 wait_delete_completed
514 USED=$(getquota -u $TSTUSR global curinodes)
515 [ $USED -ne 0 ] && quota_error u $TSTUSR \
516 "user quota isn't released after deletion"
517 resetquota -u $TSTUSR
520 log "--------------------------------------"
521 log "Group quota (inode hardlimit:$LIMIT files)"
522 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
523 error "set group quota failed"
525 TESTFILE=$DIR/$tdir/$tfile-1
526 # make sure the system is clean
527 USED=$(getquota -g $TSTUSR global curinodes)
528 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
530 log "Create $LIMIT files ..."
531 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
532 quota_error g $TSTUSR "group create failure, but expect success"
533 log "Create out of file quota ..."
534 $RUNAS touch ${TESTFILE}_xxx && \
535 quota_error g $TSTUSR "group create success, but expect EDQUOT"
538 unlinkmany ${TESTFILE} $LIMIT
539 rm -f ${TESTFILE}_xxx
540 wait_delete_completed
542 USED=$(getquota -g $TSTUSR global curinodes)
543 [ $USED -ne 0 ] && quota_error g $TSTUSR \
544 "user quota isn't released after deletion"
547 resetquota -g $TSTUSR
549 run_test 2 "File hard limit (normal use and out of quota)"
553 local TIMER=$(($2 * 3 / 2))
558 trap cleanup_quota_test EXIT
560 $LFS setstripe $TESTFILE -c 1 -i 0
561 chown $TSTUSR.$TSTUSR $TESTFILE
563 echo "Write up to soft limit"
564 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
565 quota_error a $TSTUSR "write failure, but expect success"
566 OFFSET=$((LIMIT * 1024))
569 echo "Write to exceed soft limit"
570 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
571 quota_error a $TSTUSR "write failure, but expect success"
572 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
577 $SHOW_QUOTA_INFO_USER
578 $SHOW_QUOTA_INFO_GROUP
580 echo "Write before timer goes off"
581 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
582 quota_error a $TSTUSR "write failure, but expect success"
583 OFFSET=$((OFFSET + 1024))
586 echo "Sleep $TIMER seconds ..."
591 $SHOW_QUOTA_INFO_USER
592 $SHOW_QUOTA_INFO_GROUP
594 echo "Write after timer goes off"
595 # maybe cache write, ignore.
596 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
597 OFFSET=$((OFFSET + 1024))
599 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
600 quota_error a $TSTUSR "write success, but expect EDQUOT"
604 $SHOW_QUOTA_INFO_USER
605 $SHOW_QUOTA_INFO_GROUP
607 echo "Unlink file to stop timer"
609 wait_delete_completed
610 sync_all_data || true
614 $SHOW_QUOTA_INFO_USER
615 $SHOW_QUOTA_INFO_GROUP
617 $LFS setstripe $TESTFILE -c 1 -i 0
618 chown $TSTUSR.$TSTUSR $TESTFILE
621 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
622 quota_error a $TSTUSR "write failure, but expect success"
631 local TESTFILE=$DIR/$tdir/$tfile-0
633 set_ost_qtype "ug" || error "enable ost quota failed"
635 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
636 # make sure the system is clean
637 local USED=$(getquota -u $TSTUSR global curspace)
638 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
640 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
641 $MAX_IQ_TIME $DIR || error "set user grace time failed"
642 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
643 error "set user quota failed"
645 test_block_soft $TESTFILE $GRACE $LIMIT
646 resetquota -u $TSTUSR
648 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
649 TESTFILE=$DIR/$tdir/$tfile-1
650 # make sure the system is clean
651 USED=$(getquota -g $TSTUSR global curspace)
652 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
654 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
655 $MAX_IQ_TIME $DIR || error "set group grace time failed"
656 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
657 error "set group quota failed"
659 test_block_soft $TESTFILE $GRACE $LIMIT
660 resetquota -g $TSTUSR
663 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
664 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
665 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
666 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
668 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
673 local TIMER=$(($3 * 3 / 2))
676 trap cleanup_quota_test EXIT
678 echo "Create files to exceed soft limit"
679 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
680 quota_error a $TSTUSR "create failure, but expect success"
683 echo "Create file before timer goes off"
684 $RUNAS touch ${TESTFILE}_before ||
685 quota_error a $TSTUSR "failed create before timer expired," \
689 echo "Sleep $TIMER seconds ..."
694 $SHOW_QUOTA_INFO_USER
695 $SHOW_QUOTA_INFO_GROUP
697 echo "Create file after timer goes off"
698 # There is a window that space is accounted in the quota usage but
699 # hasn't been decreased from the pending write, if we acquire quota
700 # in this window, we'll acquire more than we needed.
701 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
703 $RUNAS touch ${TESTFILE}_after_3 &&
704 quota_error a $TSTUSR "create after timer expired," \
710 $SHOW_QUOTA_INFO_USER
711 $SHOW_QUOTA_INFO_GROUP
713 echo "Unlink files to stop timer"
714 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
715 wait_delete_completed
718 $RUNAS touch ${TESTFILE}_xxx ||
719 quota_error a $TSTUSR "touch after timer stop failure," \
729 local LIMIT=10 # inodes
730 local TESTFILE=$DIR/$tdir/$tfile-0
733 set_mdt_qtype "ug" || error "enable mdt quota failed"
735 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
736 # make sure the system is clean
737 local USED=$(getquota -u $TSTUSR global curinodes)
738 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
740 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
741 $GRACE $DIR || error "set user grace time failed"
742 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
743 error "set user quota failed"
745 test_file_soft $TESTFILE $LIMIT $GRACE
746 resetquota -u $TSTUSR
748 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
749 # make sure the system is clean
750 USED=$(getquota -g $TSTUSR global curinodes)
751 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
753 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
754 $GRACE $DIR || error "set group grace time failed"
755 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
756 error "set group quota failed"
757 TESTFILE=$DIR/$tdir/$tfile-1
759 test_file_soft $TESTFILE $LIMIT $GRACE
760 resetquota -g $TSTUSR
763 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
764 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
765 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
766 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
768 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
772 local GR_STR2="1000s"
774 local GR_STR4="1w2d3h4m5s"
776 local GR_STR6="1111111111111111"
778 wait_delete_completed
780 # test of valid grace strings handling
781 echo "Valid grace strings test"
782 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
783 $GR_STR2 $DIR || error "set user grace time failed"
784 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
785 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
786 $GR_STR4 $DIR || error "set group grace time quota failed"
787 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
789 # test of invalid grace strings handling
790 echo " Invalid grace strings test"
791 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
792 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
795 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
796 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
797 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
798 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
800 run_test 4b "Grace time strings handling"
802 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
804 local BLIMIT=10 # 10M
805 local ILIMIT=10 # 10 inodes
808 trap cleanup_quota_test EXIT
810 set_mdt_qtype "ug" || error "enable mdt quota failed"
811 set_ost_qtype "ug" || error "enable ost quota failed"
813 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
814 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
815 error "set user quota failed"
816 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
817 error "set group quota failed"
819 # make sure the system is clean
820 local USED=$(getquota -u $TSTUSR global curinodes)
821 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
822 USED=$(getquota -g $TSTUSR global curinodes)
823 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
824 USED=$(getquota -u $TSTUSR global curspace)
825 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
826 USED=$(getquota -g $TSTUSR global curspace)
827 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
829 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
830 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
831 error "create failure, expect success"
832 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
833 error "write failure, expect success"
835 echo "Chown files to $TSTUSR.$TSTUSR ..."
836 for i in `seq 0 $ILIMIT`; do
837 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
838 quota_error a $TSTUSR "chown failure, expect success"
842 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1))
845 resetquota -u $TSTUSR
846 resetquota -g $TSTUSR
848 run_test 5 "Chown & chgrp successfully even out of block/file quota"
850 # test dropping acquire request on master
855 trap cleanup_quota_test EXIT
857 # make sure the system is clean
858 local USED=$(getquota -u $TSTUSR global curspace)
859 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
861 # make sure no granted quota on ost
862 set_ost_qtype "ug" || error "enable ost quota failed"
863 resetquota -u $TSTUSR
865 # create file for $TSTUSR
866 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
867 $LFS setstripe $TESTFILE -c 1 -i 0
868 chown $TSTUSR.$TSTUSR $TESTFILE
870 # create file for $TSTUSR2
871 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
872 $LFS setstripe $TESTFILE2 -c 1 -i 0
873 chown $TSTUSR2.$TSTUSR2 $TESTFILE2
875 # cache per-ID lock for $TSTUSR on slave
876 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
877 error "set quota failed"
878 $RUNAS $DD of=$TESTFILE count=1 ||
879 error "write $TESTFILE failure, expect success"
880 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
881 error "write $TESTFILE2 failure, expect success"
883 sync_all_data || true
885 #define QUOTA_DQACQ 601
886 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
887 lustre_fail mds 0x513 601
889 # write to un-enforced ID ($TSTUSR2) should succeed
890 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
891 error "write failure, expect success"
893 # write to enforced ID ($TSTUSR) in background, exceeding limit
894 # to make sure DQACQ is sent
895 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
898 # watchdog timer uses a factor of 2
899 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
900 sleep $((TIMEOUT * 2 + 1))
902 # write should be blocked and never finished
903 if ! ps -p $DDPID > /dev/null 2>&1; then
905 error "write finished incorrectly!"
910 # no watchdog is triggered
911 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
912 watchdog=$(awk '/sanity-quota test 6/ {start = 1;}
913 /Service thread pid/ && /was inactive/ {
917 }' $TMP/lustre-log-${TESTNAME}.log)
918 [ -z "$watchdog" ] || error "$watchdog"
920 rm -f $TMP/lustre-log-${TESTNAME}.log
922 # write should continue & succeed
925 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
926 if [ $count -ge 120 ]; then
927 quota_error u $TSTUSR "dd not finished in $count secs"
930 [ $((count % 10)) -eq 0 ] && echo "Waiting $count secs"
935 resetquota -u $TSTUSR
937 run_test 6 "Test dropping acquire request on master"
939 # quota reintegration (global index)
941 local TESTFILE=$DIR/$tdir/$tfile
944 [ "$SLOW" = "no" ] && LIMIT=5
947 trap cleanup_quota_test EXIT
949 # make sure the system is clean
950 local USED=$(getquota -u $TSTUSR global curspace)
951 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
953 # make sure no granted quota on ost1
954 set_ost_qtype "ug" || error "enable ost quota failed"
955 resetquota -u $TSTUSR
956 set_ost_qtype "none" || error "disable ost quota failed"
958 local OSTUUID=$(ostuuid_from_index 0)
959 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
960 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
964 $LFS setstripe $TESTFILE -c 1 -i 0
965 chown $TSTUSR.$TSTUSR $TESTFILE
970 echo "Enable quota & set quota limit for $TSTUSR"
971 set_ost_qtype "ug" || error "enable ost quota failed"
972 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
973 error "set quota failed"
976 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
979 wait_ost_reint "ug" || error "reintegration failed"
981 # hardlimit should have been fetched by slave during global
982 # reintegration, write will exceed quota
983 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
984 quota_error u $TSTUSR "write success, but expect EDQUOT"
987 wait_delete_completed
988 sync_all_data || true
994 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
995 error "clear quota failed"
998 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1001 wait_ost_reint "ug" || error "reintegration failed"
1003 # hardlimit should be cleared on slave during reintegration
1004 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1005 quota_error u $TSTUSR "write error, but expect success"
1008 resetquota -u $TSTUSR
1010 run_test 7a "Quota reintegration (global index)"
1012 # quota reintegration (slave index)
1015 local TESTFILE=$DIR/$tdir/$tfile
1018 trap cleanup_quota_test EXIT
1020 # make sure the system is clean
1021 local USED=$(getquota -u $TSTUSR global curspace)
1022 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1024 # make sure no granted quota on ost1
1025 set_ost_qtype "ug" || error "enable ost quota failed"
1026 resetquota -u $TSTUSR
1027 set_ost_qtype "none" || error "disable ost quota failed"
1029 local OSTUUID=$(ostuuid_from_index 0)
1030 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1031 [ $USED -ne 0 ] && error "limit($USED) on $OSTUUID for user" \
1035 $LFS setstripe $TESTFILE -c 1 -i 0
1036 chown $TSTUSR.$TSTUSR $TESTFILE
1038 # consume some space to make sure the granted space will not
1039 # be released during reconciliation
1040 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1041 error "consume space failure, expect success"
1043 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1044 lustre_fail mds 0xa02
1046 set_ost_qtype "ug" || error "enable ost quota failed"
1047 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1048 error "set quota failed"
1050 # ignore the write error
1051 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1053 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1057 echo "Restart ost to trigger reintegration..."
1059 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
1062 wait_ost_reint "ug" || error "reintegration failed"
1064 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1065 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1068 resetquota -u $TSTUSR
1071 run_test 7b "Quota reintegration (slave index)"
1073 # quota reintegration (restart mds during reintegration)
1075 local LIMIT=20 # 20M
1076 local TESTFILE=$DIR/$tdir/$tfile
1078 [ "$SLOW" = "no" ] && LIMIT=5
1081 trap cleanup_quota_test EXIT
1083 # make sure the system is clean
1084 local USED=$(getquota -u $TSTUSR global curspace)
1085 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1087 set_ost_qtype "none" || error "disable ost quota failed"
1088 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1089 error "set quota failed"
1091 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1092 lustre_fail ost 0xa03
1095 set_ost_qtype "ug" || error "enable ost quota failed"
1096 # trigger reintegration
1097 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1098 procf=${procf}quota_slave.force_reint
1099 $LCTL set_param $procf=1 || "force reintegration failed"
1107 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1110 # wait longer than usual to make sure the reintegration
1111 # is triggered by quota wb thread.
1112 wait_ost_reint "ug" 200 || error "reintegration failed"
1114 # hardlimit should have been fetched by slave during global
1115 # reintegration, write will exceed quota
1116 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1117 quota_error u $TSTUSR "write success, but expect EDQUOT"
1120 resetquota -u $TSTUSR
1122 run_test 7c "Quota reintegration (restart mds during reintegration)"
1124 # Quota reintegration (Transfer index in multiple bulks)
1126 local TESTFILE=$DIR/$tdir/$tfile
1127 local TESTFILE1="$DIR/$tdir/$tfile"-1
1131 trap cleanup_quota_test EXIT
1133 set_ost_qtype "none" || error "disable ost quota failed"
1134 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1135 error "set quota for $TSTUSR failed"
1136 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1137 error "set quota for $TSTUSR2 failed"
1139 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1140 lustre_fail mds 0x608 0
1142 # enable quota to tirgger reintegration
1143 set_ost_qtype "u" || error "enable ost quota failed"
1144 wait_ost_reint "u" || error "reintegration failed"
1148 # hardlimit should have been fetched by slave during global
1149 # reintegration, write will exceed quota
1150 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1151 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1153 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1154 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1157 resetquota -u $TSTUSR
1158 resetquota -u $TSTUSR2
1160 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1162 # quota reintegration (inode limits)
1164 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1166 local ilimit=$((1024 * 2)) # 2k inodes
1167 local TESTFILE=$DIR/${tdir}-1/$tfile
1170 trap cleanup_quota_test EXIT
1172 # make sure the system is clean
1173 local USED=$(getquota -u $TSTUSR global curinodes)
1174 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1176 # make sure no granted quota on mdt1
1177 set_mdt_qtype "ug" || error "enable mdt quota failed"
1178 resetquota -u $TSTUSR
1179 set_mdt_qtype "none" || error "disable mdt quota failed"
1181 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1182 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1183 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1186 echo "Stop mds${MDSCOUNT}..."
1189 echo "Enable quota & set quota limit for $TSTUSR"
1190 set_mdt_qtype "ug" || error "enable mdt quota failed"
1191 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1192 error "set quota failed"
1194 echo "Start mds${MDSCOUNT}..."
1195 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1198 wait_mdt_reint "ug" || error "reintegration failed"
1200 echo "create remote dir"
1201 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1202 error "create remote dir failed"
1203 chmod 0777 $DIR/${tdir}-1
1205 # hardlimit should have been fetched by slave during global
1206 # reintegration, create will exceed quota
1207 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1208 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1210 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1211 wait_delete_completed
1212 sync_all_data || true
1214 echo "Stop mds${MDSCOUNT}..."
1217 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1218 error "clear quota failed"
1220 echo "Start mds${MDSCOUNT}..."
1221 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1224 wait_mdt_reint "ug" || error "reintegration failed"
1226 # hardlimit should be cleared on slave during reintegration
1227 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1228 quota_error -u $TSTUSR "create failed, expect success"
1230 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1231 $LFS rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1234 resetquota -u $TSTUSR
1236 run_test 7e "Quota reintegration (inode limits)"
1238 # run dbench with quota enabled
1240 local BLK_LIMIT="100g" #100G
1241 local FILE_LIMIT=1000000
1244 trap cleanup_quota_test EXIT
1246 set_mdt_qtype "ug" || error "enable mdt quota failed"
1247 set_ost_qtype "ug" || error "enable ost quota failed"
1249 echo "Set enough high limit for user: $TSTUSR"
1250 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1251 error "set user quota failed"
1252 echo "Set enough high limit for group: $TSTUSR"
1253 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1254 error "set group quota failed"
1257 [ "$SLOW" = "no" ] && duration=" -t 120"
1258 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1259 quota_error a $TSTUSR "dbench failed!"
1262 resetquota -u $TSTUSR
1263 resetquota -g $TSTUSR
1265 run_test 8 "Run dbench with quota enabled"
1267 # this check is just for test_9
1268 OST0_MIN=4900000 #4.67G
1270 check_whether_skip () {
1271 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1272 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1273 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1274 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1281 # run for fixing bug10707, it needs a big room. test for 64bit
1283 local filesize=$((1024 * 9 / 2)) # 4.5G
1285 check_whether_skip && return 0
1288 trap cleanup_quota_test EXIT
1290 set_ost_qtype "ug" || error "enable ost quota failed"
1292 local TESTFILE="$DIR/$tdir/$tfile-0"
1293 local BLK_LIMIT=100G #100G
1294 local FILE_LIMIT=1000000
1296 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1298 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1300 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1301 error "set user quota failed"
1303 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1304 "for group: $TSTUSR"
1305 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1306 error "set group quota failed"
1308 quota_show_check a u $TSTUSR
1309 quota_show_check a g $TSTUSR
1311 echo "Create test file"
1312 $LFS setstripe $TESTFILE -c 1 -i 0
1313 chown $TSTUSR.$TSTUSR $TESTFILE
1315 log "Write the big file of 4.5G ..."
1316 $RUNAS $DD of=$TESTFILE count=$filesize ||
1317 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1323 resetquota -u $TSTUSR
1324 resetquota -g $TSTUSR
1329 run_test 9 "Block limit larger than 4GB (b10707)"
1332 local TESTFILE=$DIR/$tdir/$tfile
1335 trap cleanup_quota_test EXIT
1337 # set limit to root user should fail
1338 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1339 error "set limit for root user successfully, expect failure"
1340 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1341 error "set limit for root group successfully, expect failure"
1343 # root user can overrun quota
1344 set_ost_qtype "ug" || "enable ost quota failed"
1346 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1347 error "set quota failed"
1348 quota_show_check b u $TSTUSR
1350 $LFS setstripe $TESTFILE -c 1
1351 chown $TSTUSR.$TSTUSR $TESTFILE
1353 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1354 error "write failure, expect success"
1357 resetquota -u $TSTUSR
1359 run_test 10 "Test quota for root user"
1362 local TESTFILE=$DIR/$tdir/$tfile
1364 trap cleanup_quota_test EXIT
1366 set_mdt_qtype "ug" || "enable mdt quota failed"
1367 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1368 error "set quota failed"
1373 chown $TSTUSR.$TSTUSR "$TESTFILE"-0
1374 chown $TSTUSR.$TSTUSR "$TESTFILE"-1
1377 local USED=$(getquota -u $TSTUSR global curinodes)
1378 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1381 resetquota -u $TSTUSR
1383 run_test 11 "Chown/chgrp ignores quota"
1386 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1388 local blimit=22 # 22M
1389 local blk_cnt=$((blimit - 5))
1390 local TESTFILE0="$DIR/$tdir/$tfile"-0
1391 local TESTFILE1="$DIR/$tdir/$tfile"-1
1394 trap cleanup_quota_test EXIT
1396 set_ost_qtype "u" || "enable ost quota failed"
1397 quota_show_check b u $TSTUSR
1399 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1400 error "set quota failed"
1402 $LFS setstripe $TESTFILE0 -c 1 -i 0
1403 $LFS setstripe $TESTFILE1 -c 1 -i 1
1404 chown $TSTUSR.$TSTUSR $TESTFILE0
1405 chown $TSTUSR.$TSTUSR $TESTFILE1
1407 echo "Write to ost0..."
1408 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1409 quota_error a $TSTUSR "dd failed"
1411 echo "Write to ost1..."
1412 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1413 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1415 echo "Free space from ost0..."
1417 wait_delete_completed
1418 sync_all_data || true
1420 echo "Write to ost1 after space freed from ost0..."
1421 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1422 quota_error a $TSTUSR "rebalancing failed"
1425 resetquota -u $TSTUSR
1427 run_test 12a "Block quota rebalancing"
1430 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1432 local ilimit=$((1024 * 2)) # 2k inodes
1433 local TESTFILE0=$DIR/$tdir/$tfile
1434 local TESTFILE1=$DIR/${tdir}-1/$tfile
1437 trap cleanup_quota_test EXIT
1439 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1440 chmod 0777 $DIR/${tdir}-1
1442 set_mdt_qtype "u" || "enable mdt quota failed"
1443 quota_show_check f u $TSTUSR
1445 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1446 error "set quota failed"
1448 echo "Create $ilimit files on mdt0..."
1449 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1450 quota_error u $TSTUSR "create failed, but expect success"
1452 echo "Create files on mdt1..."
1453 $RUNAS createmany -m $TESTFILE1 1 &&
1454 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1456 echo "Free space from mdt0..."
1457 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1458 wait_delete_completed
1459 sync_all_data || true
1461 echo "Create files on mdt1 after space freed from mdt0..."
1462 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1463 quota_error a $TSTUSR "rebalancing failed"
1465 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1466 error "unlink mdt1 files failed"
1467 $LFS rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1470 resetquota -u $TSTUSR
1472 run_test 12b "Inode quota rebalancing"
1475 local TESTFILE=$DIR/$tdir/$tfile
1476 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1477 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1480 trap cleanup_quota_test EXIT
1482 set_ost_qtype "u" || "enable ost quota failed"
1483 quota_show_check b u $TSTUSR
1485 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1486 error "set quota failed"
1487 $LFS setstripe $TESTFILE -c 1 -i 0
1488 chown $TSTUSR.$TSTUSR $TESTFILE
1490 # clear the locks in cache first
1491 do_facet ost1 $LCTL set_param -n $procf=clear
1492 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1493 [ $nlock -eq 0 ] || error "$nlock cached locks"
1495 # write to acquire the per-ID lock
1496 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1497 quota_error a $TSTUSR "dd failed"
1499 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1500 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1502 # clear quota doesn't trigger per-ID lock cancellation
1503 resetquota -u $TSTUSR
1504 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1505 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1507 # clear the per-ID lock
1508 do_facet ost1 $LCTL set_param -n $procf=clear
1509 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1510 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1512 # spare quota should be released
1513 local OSTUUID=$(ostuuid_from_index 0)
1514 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1515 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1516 [ $limit -le $space ] ||
1517 error "spare quota isn't released, limit:$limit, space:$space"
1521 run_test 13 "Cancel per-ID lock in the LRU list"
1524 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1526 wait_delete_completed
1527 sync_all_data || true
1530 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1531 error "set user quota failed"
1532 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1533 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1534 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1535 resetquota -u $TSTUSR
1538 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1539 error "set group quota failed"
1540 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1541 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1542 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1543 resetquota -g $TSTUSR
1545 run_test 15 "Set over 4T block quota"
1549 local BLKS=1 # 1M less than limit
1550 local TESTFILE=$DIR/$tdir/$tfile
1553 trap cleanup_quota_test EXIT
1555 # make sure the system is clean
1556 local USED=$(getquota -u $TSTUSR global curspace)
1557 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1559 set_ost_qtype "ug" || error "enable ost quota failed"
1560 # make sure no granted quota on ost
1561 resetquota -u $TSTUSR
1562 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1563 error "set quota failed"
1565 quota_show_check b u $TSTUSR
1567 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1568 lustre_fail mds 0xa04 $err_code
1570 # write in background
1571 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1575 # write should be blocked and never finished
1576 if ! ps -p $DDPID > /dev/null 2>&1; then
1578 quota_error u $TSTUSR "write finished incorrectly!"
1586 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1588 if [ $count -gt $timeout ]; then
1589 quota_error u $TSTUSR "dd is not finished!"
1594 sync; sync_all_data || true
1596 USED=$(getquota -u $TSTUSR global curspace)
1597 [ $USED -ge $(($BLKS * 1024)) ] || quota_error u $TSTUSR \
1598 "Used space(${USED}K) is less than ${BLKS}M"
1601 resetquota -u $TSTUSR
1604 # DQACQ return recoverable error
1606 echo "DQACQ return -ENOLCK"
1608 test_17sub 37 || error "Handle -ENOLCK failed"
1610 echo "DQACQ return -EAGAIN"
1612 test_17sub 11 || error "Handle -EAGAIN failed"
1614 echo "DQACQ return -ETIMEDOUT"
1615 #define ETIMEDOUT 110
1616 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1618 echo "DQACQ return -ENOTCONN"
1619 #define ENOTCONN 107
1620 test_17sub 107 || error "Handle -ENOTCONN failed"
1623 run_test 17 "DQACQ return recoverable error"
1627 local blimit="200m" # 200M
1628 local TESTFILE="$DIR/$tdir/$tfile"
1631 trap cleanup_quota_test EXIT
1633 set_ost_qtype "u" || error "enable ost quota failed"
1634 log "User quota (limit: $blimit)"
1635 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1636 error "set quota failed"
1637 quota_show_check b u $TSTUSR
1639 $LFS setstripe $TESTFILE -i 0 -c 1
1640 chown $TSTUSR.$TSTUSR $TESTFILE
1642 local timeout=$(sysctl -n lustre.timeout)
1644 if [ $io_type = "directio" ]; then
1645 log "Write 100M (directio) ..."
1646 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1648 log "Write 100M (buffered) ..."
1649 $RUNAS $DD of=$TESTFILE count=100 &
1653 replay_barrier $SINGLEMDS
1654 log "Fail mds for $((2 * timeout)) seconds"
1655 fail $SINGLEMDS $((2 * timeout))
1658 if at_is_enabled; then
1659 timeout=$(at_max_get mds)
1661 timeout=$(lctl get_param -n timeout)
1665 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1666 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1667 log "it took $count second"
1672 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1674 cancel_lru_locks mdc
1675 cancel_lru_locks osc
1678 local testfile_size=$(stat -c %s $TESTFILE)
1679 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1680 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100)),"
1681 "got ${testfile_size}. Verifying file failed!"
1684 resetquota -u $TSTUSR
1687 # test when mds does failover, the ost still could work well
1688 # this test shouldn't trigger watchdog b=14840
1691 test_18_sub directio
1693 # check if watchdog is triggered
1694 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1695 local watchdog=$(awk '/sanity-quota test 18/ {start = 1;}
1696 /Service thread pid/ && /was inactive/ {
1700 }' $TMP/lustre-log-${TESTNAME}.log)
1701 [ -z "$watchdog" ] || error "$watchdog"
1702 rm -f $TMP/lustre-log-${TESTNAME}.log
1704 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1708 local TESTFILE=$DIR/$tdir/$tfile
1711 trap cleanup_quota_test EXIT
1713 set_ost_qtype "ug" || error "enable ost quota failed"
1715 # bind file to a single OST
1716 $LFS setstripe -c 1 $TESTFILE
1717 chown $TSTUSR.$TSTUSR $TESTFILE
1719 echo "Set user quota (limit: "$blimit"M)"
1720 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1721 error "set user quota failed"
1722 quota_show_check b u $TSTUSR
1723 echo "Update quota limits"
1724 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1725 error "set group quota failed"
1726 quota_show_check b u $TSTUSR
1728 # first wirte might be cached
1729 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1730 cancel_lru_locks osc
1732 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1733 quota_error u $TSTUSR "Write success, expect failure"
1737 resetquota -u $TSTUSR
1739 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1741 test_20() { # b15754
1742 local LSTR=(2g 1t 4k 3m) # limits strings
1744 local LVAL=($[2*1024*1024] $[1*1024*1024*1024] $[4*1024] $[3*1024*1024])
1746 resetquota -u $TSTUSR
1748 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1749 $MOUNT || error "could not set quota limits"
1750 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1751 --inode-softlimit ${LSTR[2]} \
1752 --inode-hardlimit ${LSTR[3]} \
1753 $MOUNT || error "could not set quota limits"
1755 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1756 error "bsoftlimit was not set properly"
1757 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1758 error "bhardlimit was not set properly"
1759 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1760 error "isoftlimit was not set properly"
1761 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1762 error "ihardlimit was not set properly"
1764 resetquota -u $TSTUSR
1766 run_test 20 "Test if setquota specifiers work properly (b15754)"
1773 local time=$(($(date +%s) + seconds))
1774 while [ $(date +%s) -lt $time ]; do
1775 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1779 # run for fixing bug16053, setquota shouldn't fail when writing and
1780 # deleting are happening
1782 local TESTFILE="$DIR/$tdir/$tfile"
1783 local BLIMIT=10 # 10G
1784 local ILIMIT=1000000
1787 trap cleanup_quota_test EXIT
1789 set_ost_qtype "ug" || error "Enable ost quota failed"
1791 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1792 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1793 error "set user quota failed"
1794 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1795 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1796 error "set group quota failed"
1798 # repeat writing on a 1M file
1799 test_21_sub ${TESTFILE}_1 1 30 &
1801 # repeat writing on a 128M file
1802 test_21_sub ${TESTFILE}_2 128 30 &
1805 local time=$(($(date +%s) + 30))
1807 while [ $(date +%s) -lt $time ]; do
1808 log "Set quota for $i times"
1809 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1810 -I $((ILIMIT + i)) $MOUNT ||
1811 error "Set user quota failed"
1812 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1813 -I $((ILIMIT + i)) $MOUNT ||
1814 error "Set group quota failed"
1821 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1823 if [ $count -gt 60 ]; then
1824 quota_error a $TSTUSR "dd should be finished!"
1828 echo "(dd_pid=$DDPID1, time=$count)successful"
1832 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1834 if [ $count -gt 60 ]; then
1835 quota_error a $TSTUSR "dd should be finished!"
1839 echo "(dd_pid=$DDPID2, time=$count)successful"
1842 resetquota -u $TSTUSR
1843 resetquota -g $TSTUSR
1845 run_test 21 "Setquota while writing & deleting (b16053)"
1847 # enable/disable quota enforcement permanently
1849 echo "Set both mdt & ost quota type as ug"
1850 set_mdt_qtype "ug" || error "enable mdt quota failed"
1851 set_ost_qtype "ug" || error "enable ost quota failed"
1858 echo "Verify if quota is enabled"
1859 local qtype=$(mdt_quota_type)
1860 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1861 qtype=$(ost_quota_type)
1862 [ $qtype != "ug" ] && error "ost quota setting is lost"
1864 echo "Set both mdt & ost quota type as none"
1865 set_mdt_qtype "none" || error "disable mdt quota failed"
1866 set_ost_qtype "none" || error "disable ost quota failed"
1874 echo "Verify if quota is disabled"
1875 qtype=$(mdt_quota_type)
1876 [ $qtype != "none" ] && error "mdt quota setting is lost"
1877 qtype=$(ost_quota_type)
1878 [ $qtype != "none" ] && error "ost quota setting is lost"
1882 run_test 22 "enable/disable quota by 'lctl conf_param'"
1885 local TESTFILE="$DIR/$tdir/$tfile"
1889 trap cleanup_quota_test EXIT
1891 set_ost_qtype "ug" || error "Enable ost quota failed"
1894 log "User quota (limit: $LIMIT MB)"
1895 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1896 error "set quota failed"
1897 quota_show_check b u $TSTUSR
1899 $LFS setstripe $TESTFILE -c 1 -i 0
1900 chown $TSTUSR.$TSTUSR $TESTFILE
1902 log "Step1: trigger EDQUOT with O_DIRECT"
1903 log "Write half of file"
1904 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1905 quota_error u $TSTUSR "(1) Write failure, expect success." \
1907 log "Write out of block quota ..."
1908 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1909 oflag=direct conv=notrunc &&
1910 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1914 log "Step2: rewrite should succeed"
1915 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1916 quota_error u $TSTUSR "(3) Write failure, expect success." \
1922 local OST0_UUID=$(ostuuid_from_index 0)
1923 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1924 [ $OST0_QUOTA_USED -ne 0 ] &&
1925 ($SHOW_QUOTA_USER; \
1926 quota_error u $TSTUSR "quota isn't released")
1928 resetquota -u $TSTUSR
1932 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1933 check_whether_skip && return 0
1934 log "run for 4MB test file"
1937 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1938 check_whether_skip && return 0
1939 log "run for 40MB test file"
1942 run_test 23 "Quota should be honored with directIO (b16125)"
1946 local TESTFILE="$DIR/$tdir/$tfile"
1949 trap cleanup_quota_test EXIT
1951 set_ost_qtype "ug" || error "enable ost quota failed"
1953 # bind file to a single OST
1954 $LFS setstripe -c 1 $TESTFILE
1955 chown $TSTUSR.$TSTUSR $TESTFILE
1957 echo "Set user quota (limit: "$blimit"M)"
1958 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1959 error "set quota failed"
1961 # overrun quota by root user
1962 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1963 error "write failure, expect success"
1964 cancel_lru_locks osc
1965 sync_all_data || true
1967 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1970 resetquota -u $TSTUSR
1972 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1974 test_27a() { # b19612
1975 $LFS quota $TSTUSR $DIR &&
1976 error "lfs succeeded with no type, but should have failed"
1977 $LFS setquota $TSTUSR $DIR &&
1978 error "lfs succeeded with no type, but should have failed"
1981 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
1983 test_27b() { # b20200
1984 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1985 error "lfs setquota failed with uid argument"
1986 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
1987 error "lfs stequota failed with gid argument"
1988 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
1989 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
1990 resetquota -u $TSTUSR
1991 resetquota -g $TSTUSR
1994 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
1999 local TESTFILE="$DIR/$tdir/$tfile"
2003 trap cleanup_quota_test EXIT
2005 set_ost_qtype "u" || error "enable ost quota failed"
2007 $LFS setstripe $TESTFILE -i 0 -c 1
2008 chown $TSTUSR.$TSTUSR $TESTFILE
2010 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2011 $MAX_IQ_TIME $DIR || error "set grace time failed"
2012 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2013 error "set quota failed"
2014 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2015 cancel_lru_locks osc
2017 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2018 # over-quota flag has not yet settled since we do not trigger async
2019 # events based on grace time period expiration
2021 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 || true
2022 cancel_lru_locks osc
2023 # now over-quota flag should be settled and further writes should fail
2025 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=1 &&
2026 error "grace times were reset"
2029 resetquota -u $TSTUSR
2030 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2031 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2033 run_test 30 "Hard limit updates should not reset grace times"
2035 # basic usage tracking for user & group
2037 local INODES=10 # 10 files
2038 local BLK_CNT=2 # of 2M each
2039 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2042 trap cleanup_quota_test EXIT
2044 # make sure the system is clean
2045 local USED=$(getquota -u $TSTID global curspace)
2047 error "Used space ($USED) for user $TSTID isn't 0."
2048 USED=$(getquota -g $TSTID global curspace)
2050 error "Used space ($USED) for group $TSTID isn't 0."
2052 echo "Write files..."
2053 for i in `seq 0 $INODES`; do
2054 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2055 error "write failed"
2056 echo "Iteration $i/$INODES completed"
2058 cancel_lru_locks osc
2059 sync; sync_all_data || true
2061 echo "Verify disk usage after write"
2062 USED=$(getquota -u $TSTID global curspace)
2063 [ $USED -lt $TOTAL_BLKS ] &&
2064 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2065 USED=$(getquota -g $TSTID global curspace)
2066 [ $USED -lt $TOTAL_BLKS ] &&
2067 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2069 echo "Verify inode usage after write"
2070 USED=$(getquota -u $TSTID global curinodes)
2071 [ $USED -lt $INODES ] &&
2072 error "Used inode for user $TSTID is $USED, expected $INODES"
2073 USED=$(getquota -g $TSTID global curinodes)
2074 [ $USED -lt $INODES ] &&
2075 error "Used inode for group $TSTID is $USED, expected $INODES"
2079 echo "Verify disk usage after delete"
2080 USED=$(getquota -u $TSTID global curspace)
2081 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2082 USED=$(getquota -u $TSTID global curinodes)
2083 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2084 USED=$(getquota -g $TSTID global curspace)
2085 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2086 USED=$(getquota -g $TSTID global curinodes)
2087 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2089 run_test 33 "Basic usage tracking for user & group"
2091 # usage transfer test for user & group
2093 local BLK_CNT=2 # 2MB
2096 trap cleanup_quota_test EXIT
2098 # make sure the system is clean
2099 local USED=$(getquota -u $TSTID global curspace)
2100 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2101 USED=$(getquota -g $TSTID global curspace)
2102 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2104 echo "Write file..."
2105 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2106 error "write failed"
2107 cancel_lru_locks osc
2108 sync; sync_all_data || true
2110 echo "chown the file to user $TSTID"
2111 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2113 echo "Wait for setattr on objects finished..."
2114 wait_delete_completed
2116 BLK_CNT=$((BLK_CNT * 1024))
2118 echo "Verify disk usage for user $TSTID"
2119 USED=$(getquota -u $TSTID global curspace)
2120 [ $USED -lt $BLK_CNT ] &&
2121 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2122 USED=$(getquota -u $TSTID global curinodes)
2124 error "Used inodes for user $TSTID is $USED, expected 1"
2126 echo "chgrp the file to group $TSTID"
2127 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2129 echo "Wait for setattr on objects finished..."
2130 wait_delete_completed
2132 echo "Verify disk usage for group $TSTID"
2133 USED=$(getquota -g $TSTID global curspace)
2134 [ $USED -ge $BLK_CNT ] ||
2135 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2136 USED=$(getquota -g $TSTID global curinodes)
2138 error "Used inodes for group $TSTID is $USED, expected 1"
2142 run_test 34 "Usage transfer for user & group"
2144 # usage is still accessible across restart
2146 local BLK_CNT=2 # 2 MB
2149 trap cleanup_quota_test EXIT
2151 echo "Write file..."
2152 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2153 error "write failed"
2154 cancel_lru_locks osc
2155 sync; sync_all_data || true
2157 echo "Save disk usage before restart"
2158 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2159 [ $ORIG_USR_SPACE -eq 0 ] &&
2160 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2161 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2162 [ $ORIG_USR_INODES -eq 0 ] &&
2163 error "Used inodes for user $TSTID is 0, expected 1"
2164 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2165 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2166 [ $ORIG_GRP_SPACE -eq 0 ] &&
2167 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2168 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2169 [ $ORIG_GRP_INODES -eq 0 ] &&
2170 error "Used inodes for group $TSTID is 0, expected 1"
2171 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2174 local ORIG_REFORMAT=$REFORMAT
2176 cleanup_and_setup_lustre
2177 REFORMAT=$ORIG_REFORMAT
2180 echo "Verify disk usage after restart"
2181 local USED=$(getquota -u $TSTID global curspace)
2182 [ $USED -eq $ORIG_USR_SPACE ] ||
2183 error "Used space for user $TSTID changed from " \
2184 "$ORIG_USR_SPACE to $USED"
2185 USED=$(getquota -u $TSTID global curinodes)
2186 [ $USED -eq $ORIG_USR_INODES ] ||
2187 error "Used inodes for user $TSTID changed from " \
2188 "$ORIG_USR_INODES to $USED"
2189 USED=$(getquota -g $TSTID global curspace)
2190 [ $USED -eq $ORIG_GRP_SPACE ] ||
2191 error "Used space for group $TSTID changed from " \
2192 "$ORIG_GRP_SPACE to $USED"
2193 USED=$(getquota -g $TSTID global curinodes)
2194 [ $USED -eq $ORIG_GRP_INODES ] ||
2195 error "Used inodes for group $TSTID changed from " \
2196 "$ORIG_GRP_INODES to $USED"
2198 # check if the vfs_dq_init() is called before writing
2199 echo "Append to the same file..."
2200 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2201 error "write failed"
2202 cancel_lru_locks osc
2203 sync; sync_all_data || true
2205 echo "Verify space usage is increased"
2206 USED=$(getquota -u $TSTID global curspace)
2207 [ $USED -gt $ORIG_USR_SPACE ] ||
2208 error "Used space for user $TSTID isn't increased" \
2209 "orig:$ORIG_USR_SPACE, now:$USED"
2210 USED=$(getquota -g $TSTID global curspace)
2211 [ $USED -gt $ORIG_GRP_SPACE ] ||
2212 error "Used space for group $TSTID isn't increased" \
2213 "orig:$ORIG_GRP_SPACE, now:$USED"
2217 run_test 35 "Usage is still accessible across reboot"
2219 # test migrating old amdin quota files (in Linux quota file format v2) into new
2220 # quota global index (in IAM format)
2222 [ $(facet_fstype $SINGLEMDS) != ldiskfs ] && \
2223 skip "skipping migration test" && return
2225 # get the mdt0 device name
2226 local mdt0_node=$(facet_active_host $SINGLEMDS)
2227 local mdt0_dev=$(mdsdevname ${SINGLEMDS//mds/})
2232 echo "Copy admin quota files into MDT0..."
2233 local mntpt=$(facet_mntpt $SINGLEMDS)
2234 local mdt0_fstype=$(facet_fstype $SINGLEMDS)
2236 if ! do_node $mdt0_node test -b $mdt0_fstype; then
2239 echo "$mdt0_node, $mdt0_dev, $mntpt, $opt"
2240 do_node $mdt0_node mount -t $mdt0_fstype $opt $mdt0_dev $mntpt
2241 do_node $mdt0_node mkdir $mntpt/OBJECTS
2242 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.usr $mntpt/OBJECTS
2243 do_node $mdt0_node cp $LUSTRE/tests/admin_quotafile_v2.grp $mntpt/OBJECTS
2244 do_node $mdt0_node umount -f $mntpt
2249 echo "Verify global limits..."
2253 local proc="qmt.*.md-0x0.glb-usr"
2254 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2255 [ $id_cnt -eq 403 ] || error "Migrate inode user limit failed: $id_cnt"
2256 limit=$(getquota -u 1 global isoftlimit)
2257 [ $limit -eq 1024 ] || error "User inode softlimit: $limit"
2258 limit=$(getquota -u 1 global ihardlimit)
2259 [ $limit -eq 2048 ] || error "User inode hardlimit: $limit"
2261 proc="qmt.*.md-0x0.glb-grp"
2262 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2263 [ $id_cnt -eq 403 ] || error "Migrate inode group limit failed: $id_cnt"
2264 limit=$(getquota -g 1 global isoftlimit)
2265 [ $limit -eq 1024 ] || error "Group inode softlimit: $limit"
2266 limit=$(getquota -g 1 global ihardlimit)
2267 [ $limit -eq 2048 ] || error "Group inode hardlimit: $limit"
2269 proc=" qmt.*.dt-0x0.glb-usr"
2270 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2271 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2272 limit=$(getquota -u 60001 global bsoftlimit)
2273 [ $limit -eq 10485760 ] || error "User block softlimit: $limit"
2274 limit=$(getquota -u 60001 global bhardlimit)
2275 [ $limit -eq 20971520 ] || error "User block hardlimit: $limit"
2277 proc="qmt.*.dt-0x0.glb-grp"
2278 id_cnt=$(do_node $mdt0_node $LCTL get_param -n $proc | wc -l)
2279 [ $id_cnt -eq 403 ] || error "Migrate block user limit failed: $id_cnt"
2280 limit=$(getquota -g 60001 global bsoftlimit)
2281 [ $limit -eq 10485760 ] || error "Group block softlimit: $limit"
2282 limit=$(getquota -g 60001 global bhardlimit)
2283 [ $limit -eq 20971520 ] || error "Group block hardlimit: $limit"
2289 run_test 36 "Migrate old admin files into new global indexes"
2293 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2299 check_and_cleanup_lustre
2300 export QUOTA_AUTO=$QUOTA_AUTO_OLD