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 # Bug number for skipped test:
14 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT"
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
18 echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
24 TSTID2=${TSTID2:-60001}
25 TSTUSR=${TSTUSR:-"quota_usr"}
26 TSTUSR2=${TSTUSR2:-"quota_2usr"}
31 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
32 . $LUSTRE/tests/test-framework.sh
34 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
38 require_dsh_mds || exit 0
39 require_dsh_ost || exit 0
41 # XXX Once we drop the interoperability with old server (< 2.3.50), the
42 # sanity-quota-old.sh should be removed.
43 if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
44 exec $LUSTRE/tests/sanity-quota-old.sh
47 # Does e2fsprogs support quota feature?
48 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
49 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
50 grep -q 'quota'"; then
51 skip "e2fsprogs doesn't support quota" && exit 0
54 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
55 # bug number for skipped test: LU-2836 LU-6836 LU-2836 LU-2059
56 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6 7d"
57 # bug number for skipped test: LU-5638
58 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
63 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
65 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
67 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
72 QUOTA_AUTO_OLD=$QUOTA_AUTO
75 check_and_setup_lustre
77 LOVNAME=$(lctl get_param -n llite.*.lov.common_name | tail -n 1)
78 OSTCOUNT=$(lctl get_param -n lov.$LOVNAME.numobd)
80 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
81 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
82 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
83 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
84 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
85 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
92 local fail_val=${3:-0}
96 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
97 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
98 ost) NODES="$(comma_list $(osts_nodes))";;
101 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
104 RUNAS="runas -u $TSTID -g $TSTID"
105 RUNAS2="runas -u $TSTID2 -g $TSTID2"
106 DD="dd if=/dev/zero bs=1M"
110 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
111 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
112 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
113 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
115 # clear quota limits for a user or a group
116 # usage: resetquota -u username
117 # resetquota -g groupname
120 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
121 [ "$1" != "-u" -a "$1" != "-g" ] &&
122 error "resetquota: wrong specifier $1 passed"
124 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
125 error "clear quota for [type:$1 name:$2] failed"
126 # give a chance to slave to release space
134 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
135 $LFS quota -v -u $LOCAL_ID $DIR
136 log "Files for user ($LOCAL_ID):"
137 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
142 $LFS quota -v -g $LOCAL_ID $DIR
143 log "Files for group ($LOCAL_ID):"
144 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
145 xargs stat 2>/dev/null)
161 # get quota for a user or a group
162 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
163 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
168 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
169 [ "$1" != "-u" -a "$1" != "-g" ] &&
170 error "getquota: wrong u/g specifier $1 passed"
183 *) error "unknown quota parameter $4";;
186 [ "$uuid" = "global" ] && uuid=$DIR
188 $LFS quota -v "$1" "$2" $DIR |
189 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
190 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
195 # usage: set_mdt_qtype ug|u|g|none
199 local mdts=$(get_facets MDS)
201 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
202 # we have to make sure each MDT received config changes
203 for mdt in ${mdts//,/ }; do
205 cmd="$LCTL get_param -n "
206 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
207 cmd=${cmd}.quota_slave.enabled
209 if $(facet_up $mdt); then
210 wait_update_facet $mdt "$cmd" "$qtype" || return 1
217 # usage: set_ost_qtype ug|u|g|none
221 local osts=$(get_facets OST)
223 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
224 # we have to make sure each OST received config changes
225 for ost in ${osts//,/ }; do
227 cmd="$LCTL get_param -n "
228 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
229 cmd=${cmd}.quota_slave.enabled
231 if $(facet_up $ost); then
232 wait_update_facet $ost "$cmd" "$qtype" || return 1
238 wait_reintegration() {
242 local result="glb[1],slv[1],reint[0]"
247 if [ $ntype == "mdt" ]; then
248 tgts=$(get_facets MDS)
250 tgts=$(get_facets OST)
253 for tgt in ${tgts//,/ }; do
255 cmd="$LCTL get_param -n "
256 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
257 cmd=${cmd}.quota_slave.info
259 if $(facet_up $tgt); then
260 wait_update_facet $tgt "$cmd |
261 grep "$qtype" | awk '{ print \\\$3 }'" \
262 "$result" $max || return 1
272 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
273 wait_reintegration "mdt" "user" $max || return 1
276 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
277 wait_reintegration "mdt" "group" $max || return 1
286 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
287 wait_reintegration "ost" "user" $max || return 1
290 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
291 wait_reintegration "ost" "group" $max || return 1
297 wait_delete_completed
298 echo "Creating test directory"
299 mkdir $DIR/$tdir || return 1
300 chmod 0777 $DIR/$tdir || return 2
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 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
368 # LU-2872 - see LU-2887 for fix
370 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
372 [ $rate -gt 1024 ] ||
373 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
379 # test basic quota performance b=21696
382 [ "$SLOW" = "no" ] && MB=10
384 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
385 [ $free_space -le $((MB * 1024)) ] &&
386 skip "not enough space ${free_space} KB, " \
387 "required $((MB * 1024)) KB" && return
388 setup_quota_test || error "setup quota failed with $?"
389 trap cleanup_quota_test EXIT
391 set_ost_qtype "none" || error "disable ost quota failed"
392 test_quota_performance $MB
394 set_ost_qtype "ug" || error "enable ost quota failed"
395 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
396 error "set quota failed"
397 test_quota_performance $MB
400 resetquota -u $TSTUSR
402 run_test 0 "Test basic quota performance"
404 # test block hardlimit
407 local TESTFILE="$DIR/$tdir/$tfile-0"
409 setup_quota_test || error "setup quota failed with $?"
410 trap cleanup_quota_test EXIT
413 set_ost_qtype "ug" || "enable ost quota failed"
416 log "User quota (block hardlimit:$LIMIT MB)"
417 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
418 error "set user quota failed"
420 # make sure the system is clean
421 local USED=$(getquota -u $TSTUSR global curspace)
422 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
424 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
425 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
428 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
429 quota_error u $TSTUSR "user write failure, but expect success"
430 log "Write out of block quota ..."
431 # this time maybe cache write, ignore it's failure
432 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
433 # flush cache, ensure noquota flag is set on client
435 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
436 quota_error u $TSTUSR "user write success, but expect EDQUOT"
439 wait_delete_completed || error "wait_delete_completed failed"
440 sync_all_data || true
441 USED=$(getquota -u $TSTUSR global curspace)
442 [ $USED -ne 0 ] && quota_error u $TSTUSR \
443 "user quota isn't released after deletion"
444 resetquota -u $TSTUSR
447 log "--------------------------------------"
448 log "Group quota (block hardlimit:$LIMIT MB)"
449 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
450 error "set group quota failed"
452 TESTFILE="$DIR/$tdir/$tfile-1"
453 # make sure the system is clean
454 USED=$(getquota -g $TSTUSR global curspace)
455 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
457 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
458 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
461 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
462 quota_error g $TSTUSR "group write failure, but expect success"
463 log "Write out of block quota ..."
464 # this time maybe cache write, ignore it's failure
465 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
467 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
468 quota_error g $TSTUSR "group write success, but expect EDQUOT"
473 USED=$(getquota -g $TSTUSR global curspace)
474 [ $USED -ne 0 ] && quota_error g $TSTUSR \
475 "group quota isn't released after deletion"
477 resetquota -g $TSTUSR
479 run_test 1 "Block hard limit (normal use and out of quota)"
481 # test inode hardlimit
483 local LIMIT=$((1024 * 1024)) # 1M inodes
484 local TESTFILE="$DIR/$tdir/$tfile-0"
486 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
488 local FREE_INODES=$(mdt_free_inodes 0)
489 echo "$FREE_INODES free inodes on master MDT"
490 [ $FREE_INODES -lt $LIMIT ] &&
491 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
494 setup_quota_test || error "setup quota failed with $?"
495 trap cleanup_quota_test EXIT
498 set_mdt_qtype "ug" || "enable mdt quota failed"
501 log "User quota (inode hardlimit:$LIMIT files)"
502 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
503 error "set user quota failed"
505 # make sure the system is clean
506 local USED=$(getquota -u $TSTUSR global curinodes)
507 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
509 log "Create $LIMIT files ..."
510 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
511 quota_error u $TSTUSR "user create failure, but expect success"
512 log "Create out of file quota ..."
513 $RUNAS touch ${TESTFILE}_xxx &&
514 quota_error u $TSTUSR "user create success, but expect EDQUOT"
517 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
518 rm -f ${TESTFILE}_xxx
519 wait_delete_completed
521 USED=$(getquota -u $TSTUSR global curinodes)
522 [ $USED -ne 0 ] && quota_error u $TSTUSR \
523 "user quota isn't released after deletion"
524 resetquota -u $TSTUSR
527 log "--------------------------------------"
528 log "Group quota (inode hardlimit:$LIMIT files)"
529 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
530 error "set group quota failed"
532 TESTFILE=$DIR/$tdir/$tfile-1
533 # make sure the system is clean
534 USED=$(getquota -g $TSTUSR global curinodes)
535 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
537 log "Create $LIMIT files ..."
538 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
539 quota_error g $TSTUSR "group create failure, but expect success"
540 log "Create out of file quota ..."
541 $RUNAS touch ${TESTFILE}_xxx &&
542 quota_error g $TSTUSR "group create success, but expect EDQUOT"
545 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
546 rm -f ${TESTFILE}_xxx
547 wait_delete_completed
549 USED=$(getquota -g $TSTUSR global curinodes)
550 [ $USED -ne 0 ] && quota_error g $TSTUSR \
551 "user quota isn't released after deletion"
554 resetquota -g $TSTUSR
556 run_test 2 "File hard limit (normal use and out of quota)"
560 local TIMER=$(($2 * 3 / 2))
565 trap cleanup_quota_test EXIT
567 $SETSTRIPE $TESTFILE -c 1 -i 0
568 chown $TSTUSR.$TSTUSR $TESTFILE
570 echo "Write up to soft limit"
571 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
572 quota_error a $TSTUSR "write failure, but expect success"
573 OFFSET=$((LIMIT * 1024))
576 echo "Write to exceed soft limit"
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)) # make sure we don't write to same block
584 $SHOW_QUOTA_INFO_USER
585 $SHOW_QUOTA_INFO_GROUP
587 echo "Write before timer goes off"
588 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
589 quota_error a $TSTUSR "write failure, but expect success"
590 OFFSET=$((OFFSET + 1024))
593 echo "Sleep $TIMER seconds ..."
598 $SHOW_QUOTA_INFO_USER
599 $SHOW_QUOTA_INFO_GROUP
601 echo "Write after timer goes off"
602 # maybe cache write, ignore.
603 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
604 OFFSET=$((OFFSET + 1024))
606 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
607 quota_error a $TSTUSR "write success, but expect EDQUOT"
611 $SHOW_QUOTA_INFO_USER
612 $SHOW_QUOTA_INFO_GROUP
614 echo "Unlink file to stop timer"
616 wait_delete_completed
617 sync_all_data || true
621 $SHOW_QUOTA_INFO_USER
622 $SHOW_QUOTA_INFO_GROUP
624 $SETSTRIPE $TESTFILE -c 1 -i 0
625 chown $TSTUSR.$TSTUSR $TESTFILE
628 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
629 quota_error a $TSTUSR "write failure, but expect success"
638 local TESTFILE=$DIR/$tdir/$tfile-0
640 set_ost_qtype "ug" || error "enable ost quota failed"
642 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
643 # make sure the system is clean
644 local USED=$(getquota -u $TSTUSR global curspace)
645 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
647 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
648 $MAX_IQ_TIME $DIR || error "set user grace time failed"
649 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
650 error "set user quota failed"
652 test_block_soft $TESTFILE $GRACE $LIMIT
653 resetquota -u $TSTUSR
655 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
656 TESTFILE=$DIR/$tdir/$tfile-1
657 # make sure the system is clean
658 USED=$(getquota -g $TSTUSR global curspace)
659 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
661 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
662 $MAX_IQ_TIME $DIR || error "set group grace time failed"
663 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
664 error "set group quota failed"
666 test_block_soft $TESTFILE $GRACE $LIMIT
667 resetquota -g $TSTUSR
670 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
671 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
672 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
673 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
675 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
681 local TIMER=$(($grace * 3 / 2))
684 trap cleanup_quota_test EXIT
686 echo "Create files to exceed soft limit"
687 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
688 quota_error a $TSTUSR "create failure, but expect success"
689 local trigger_time=$(date +%s)
691 sync_all_data || true
693 local cur_time=$(date +%s)
694 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
695 error "Passed grace time $grace, $trigger_time, $cur_time"
697 echo "Create file before timer goes off"
698 $RUNAS touch ${TESTFILE}_before ||
699 quota_error a $TSTUSR "failed create before timer expired," \
700 "but expect success. $trigger_time, $cur_time"
701 sync_all_data || true
703 echo "Sleep $TIMER seconds ..."
708 $SHOW_QUOTA_INFO_USER
709 $SHOW_QUOTA_INFO_GROUP
711 echo "Create file after timer goes off"
712 # There is a window that space is accounted in the quota usage but
713 # hasn't been decreased from the pending write, if we acquire quota
714 # in this window, we'll acquire more than we needed.
715 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
716 sync_all_data || true
717 $RUNAS touch ${TESTFILE}_after_3 &&
718 quota_error a $TSTUSR "create after timer expired," \
720 sync_all_data || true
724 $SHOW_QUOTA_INFO_USER
725 $SHOW_QUOTA_INFO_GROUP
727 echo "Unlink files to stop timer"
728 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
729 wait_delete_completed
732 $RUNAS touch ${TESTFILE}_xxx ||
733 quota_error a $TSTUSR "touch after timer stop failure," \
735 sync_all_data || true
743 local LIMIT=10 # inodes
744 local TESTFILE=$DIR/$tdir/$tfile-0
747 set_mdt_qtype "ug" || error "enable mdt quota failed"
749 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
750 # make sure the system is clean
751 local USED=$(getquota -u $TSTUSR global curinodes)
752 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
754 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
755 $GRACE $DIR || error "set user grace time failed"
756 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
757 error "set user quota failed"
759 test_file_soft $TESTFILE $LIMIT $GRACE
760 resetquota -u $TSTUSR
762 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
763 # make sure the system is clean
764 USED=$(getquota -g $TSTUSR global curinodes)
765 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
767 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
768 $GRACE $DIR || error "set group grace time failed"
769 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
770 error "set group quota failed"
771 TESTFILE=$DIR/$tdir/$tfile-1
773 test_file_soft $TESTFILE $LIMIT $GRACE
774 resetquota -g $TSTUSR
777 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
778 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
779 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
780 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
782 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
786 local GR_STR2="1000s"
788 local GR_STR4="1w2d3h4m5s"
790 local GR_STR6="18446744073709551615"
793 wait_delete_completed
795 # test of valid grace strings handling
796 echo "Valid grace strings test"
797 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
798 $GR_STR2 $DIR || error "set user grace time failed"
799 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
800 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
801 $GR_STR4 $DIR || error "set group grace time quota failed"
802 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
804 # test of invalid grace strings handling
805 echo " Invalid grace strings test"
806 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
807 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
808 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
812 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
813 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
814 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
815 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
817 run_test 4b "Grace time strings handling"
819 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
821 local BLIMIT=10 # 10M
822 local ILIMIT=10 # 10 inodes
824 setup_quota_test || error "setup quota failed with $?"
825 trap cleanup_quota_test EXIT
827 set_mdt_qtype "ug" || error "enable mdt quota failed"
828 set_ost_qtype "ug" || error "enable ost quota failed"
830 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
831 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
832 error "set user quota failed"
833 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
834 error "set group quota failed"
836 # make sure the system is clean
837 local USED=$(getquota -u $TSTUSR global curinodes)
838 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
839 USED=$(getquota -g $TSTUSR global curinodes)
840 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
841 USED=$(getquota -u $TSTUSR global curspace)
842 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
843 USED=$(getquota -g $TSTUSR global curspace)
844 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
846 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
847 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
848 error "create failure, expect success"
849 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
850 error "write failure, expect success"
852 echo "Chown files to $TSTUSR.$TSTUSR ..."
853 for i in $(seq 0 $ILIMIT); do
854 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
855 quota_error a $TSTUSR "chown failure, expect success"
859 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
860 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
863 resetquota -u $TSTUSR
864 resetquota -g $TSTUSR
866 run_test 5 "Chown & chgrp successfully even out of block/file quota"
868 # test dropping acquire request on master
872 # Clear dmesg so watchdog is not triggered by previous
874 do_facet ost1 dmesg -c > /dev/null
876 setup_quota_test || error "setup quota failed with $?"
877 trap cleanup_quota_test EXIT
879 # make sure the system is clean
880 local USED=$(getquota -u $TSTUSR global curspace)
881 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
883 # make sure no granted quota on ost
884 set_ost_qtype "ug" || error "enable ost quota failed"
885 resetquota -u $TSTUSR
887 # create file for $TSTUSR
888 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
889 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
890 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
892 # create file for $TSTUSR2
893 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
894 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
895 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
897 # cache per-ID lock for $TSTUSR on slave
898 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
899 error "set quota failed"
900 $RUNAS $DD of=$TESTFILE count=1 ||
901 error "write $TESTFILE failure, expect success"
902 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
903 error "write $TESTFILE2 failure, expect success"
905 sync_all_data || true
907 #define QUOTA_DQACQ 601
908 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
909 lustre_fail mds 0x513 601
911 # write to un-enforced ID ($TSTUSR2) should succeed
912 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
913 error "write failure, expect success"
915 # write to enforced ID ($TSTUSR) in background, exceeding limit
916 # to make sure DQACQ is sent
917 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
920 # watchdog timer uses a factor of 2
921 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
922 sleep $((TIMEOUT * 2 + 1))
924 # write should be blocked and never finished
925 if ! ps -p $DDPID > /dev/null 2>&1; then
927 error "write finished incorrectly!"
932 # no watchdog is triggered
933 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
934 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
935 { print; }' $TMP/lustre-log-${TESTNAME}.log)
936 [ -z "$watchdog" ] || error "$watchdog"
938 rm -f $TMP/lustre-log-${TESTNAME}.log
940 # write should continue then fail with EDQUOT
944 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
945 if [ $count -ge 240 ]; then
946 quota_error u $TSTUSR "dd not finished in $count secs"
949 if [ $((count % 30)) -eq 0 ]; then
950 c_size=$(stat -c %s $TESTFILE)
951 echo "Waiting $count secs. $c_size"
958 resetquota -u $TSTUSR
960 run_test 6 "Test dropping acquire request on master"
962 # quota reintegration (global index)
964 local TESTFILE=$DIR/$tdir/$tfile
967 [ "$SLOW" = "no" ] && LIMIT=5
969 setup_quota_test || error "setup quota failed with $?"
970 trap cleanup_quota_test EXIT
972 # make sure the system is clean
973 local USED=$(getquota -u $TSTUSR global curspace)
974 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
976 # make sure no granted quota on ost1
977 set_ost_qtype "ug" || error "enable ost quota failed"
978 resetquota -u $TSTUSR
979 set_ost_qtype "none" || error "disable ost quota failed"
981 local OSTUUID=$(ostuuid_from_index 0)
982 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
984 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
987 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
988 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
993 echo "Enable quota & set quota limit for $TSTUSR"
994 set_ost_qtype "ug" || error "enable ost quota failed"
995 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
996 error "set quota failed"
999 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1002 wait_ost_reint "ug" || error "reintegration failed"
1004 # hardlimit should have been fetched by slave during global
1005 # reintegration, write will exceed quota
1006 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1007 quota_error u $TSTUSR "write success, but expect EDQUOT"
1010 wait_delete_completed
1011 sync_all_data || true
1017 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1018 error "clear quota failed"
1020 echo "Start ost1..."
1021 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1024 wait_ost_reint "ug" || error "reintegration failed"
1026 # hardlimit should be cleared on slave during reintegration
1027 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1028 quota_error u $TSTUSR "write error, but expect success"
1031 resetquota -u $TSTUSR
1033 run_test 7a "Quota reintegration (global index)"
1035 # quota reintegration (slave index)
1038 local TESTFILE=$DIR/$tdir/$tfile
1040 setup_quota_test || error "setup quota failed with $?"
1041 trap cleanup_quota_test EXIT
1043 # make sure the system is clean
1044 local USED=$(getquota -u $TSTUSR global curspace)
1045 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1047 # make sure no granted quota on ost1
1048 set_ost_qtype "ug" || error "enable ost quota failed"
1049 resetquota -u $TSTUSR
1050 set_ost_qtype "none" || error "disable ost quota failed"
1052 local OSTUUID=$(ostuuid_from_index 0)
1053 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1055 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1058 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1059 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1061 # consume some space to make sure the granted space will not
1062 # be released during reconciliation
1063 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1064 error "consume space failure, expect success"
1066 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1067 lustre_fail mds 0xa02
1069 set_ost_qtype "ug" || error "enable ost quota failed"
1070 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1071 error "set quota failed"
1073 # ignore the write error
1074 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1076 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1080 echo "Restart ost to trigger reintegration..."
1082 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1085 wait_ost_reint "ug" || error "reintegration failed"
1087 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1088 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1091 resetquota -u $TSTUSR
1094 run_test 7b "Quota reintegration (slave index)"
1096 # quota reintegration (restart mds during reintegration)
1098 local LIMIT=20 # 20M
1099 local TESTFILE=$DIR/$tdir/$tfile
1101 [ "$SLOW" = "no" ] && LIMIT=5
1103 setup_quota_test || error "setup quota failed with $?"
1104 trap cleanup_quota_test EXIT
1106 # make sure the system is clean
1107 local USED=$(getquota -u $TSTUSR global curspace)
1108 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1110 set_ost_qtype "none" || error "disable ost quota failed"
1111 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1112 error "set quota failed"
1114 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1115 lustre_fail ost 0xa03
1118 set_ost_qtype "ug" || error "enable ost quota failed"
1119 # trigger reintegration
1120 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1121 procf=${procf}quota_slave.force_reint
1122 do_facet ost1 $LCTL set_param $procf=1 ||
1123 error "force reintegration failed"
1131 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1134 # wait longer than usual to make sure the reintegration
1135 # is triggered by quota wb thread.
1136 wait_ost_reint "ug" 200 || error "reintegration failed"
1138 # hardlimit should have been fetched by slave during global
1139 # reintegration, write will exceed quota
1140 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1141 quota_error u $TSTUSR "write success, but expect EDQUOT"
1144 resetquota -u $TSTUSR
1146 run_test 7c "Quota reintegration (restart mds during reintegration)"
1148 # Quota reintegration (Transfer index in multiple bulks)
1150 local TESTFILE=$DIR/$tdir/$tfile
1151 local TESTFILE1="$DIR/$tdir/$tfile"-1
1154 setup_quota_test || error "setup quota failed with $?"
1155 trap cleanup_quota_test EXIT
1157 set_ost_qtype "none" || error "disable ost quota failed"
1158 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1159 error "set quota for $TSTUSR failed"
1160 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1161 error "set quota for $TSTUSR2 failed"
1163 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1164 lustre_fail mds 0x608 0
1166 # enable quota to tirgger reintegration
1167 set_ost_qtype "u" || error "enable ost quota failed"
1168 wait_ost_reint "u" || error "reintegration failed"
1172 # hardlimit should have been fetched by slave during global
1173 # reintegration, write will exceed quota
1174 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1175 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1177 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1178 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1181 resetquota -u $TSTUSR
1182 resetquota -u $TSTUSR2
1184 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1186 # quota reintegration (inode limits)
1188 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1190 local ilimit=$((1024 * 2)) # 2k inodes
1191 local TESTFILE=$DIR/${tdir}-1/$tfile
1193 setup_quota_test || error "setup quota failed with $?"
1194 trap cleanup_quota_test EXIT
1196 # make sure the system is clean
1197 local USED=$(getquota -u $TSTUSR global curinodes)
1198 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1200 # make sure no granted quota on mdt1
1201 set_mdt_qtype "ug" || error "enable mdt quota failed"
1202 resetquota -u $TSTUSR
1203 set_mdt_qtype "none" || error "disable mdt quota failed"
1205 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1206 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1207 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1210 echo "Stop mds${MDSCOUNT}..."
1213 echo "Enable quota & set quota limit for $TSTUSR"
1214 set_mdt_qtype "ug" || error "enable mdt quota failed"
1215 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1216 error "set quota failed"
1218 echo "Start mds${MDSCOUNT}..."
1219 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1222 wait_mdt_reint "ug" || error "reintegration failed"
1224 echo "create remote dir"
1225 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1226 error "create remote dir failed"
1227 chmod 0777 $DIR/${tdir}-1
1229 # hardlimit should have been fetched by slave during global
1230 # reintegration, create will exceed quota
1231 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1232 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1234 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1235 wait_delete_completed
1236 sync_all_data || true
1238 echo "Stop mds${MDSCOUNT}..."
1241 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1242 error "clear quota failed"
1244 echo "Start mds${MDSCOUNT}..."
1245 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1248 wait_mdt_reint "ug" || error "reintegration failed"
1250 # hardlimit should be cleared on slave during reintegration
1251 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1252 quota_error -u $TSTUSR "create failed, expect success"
1254 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1255 rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1258 resetquota -u $TSTUSR
1260 run_test 7e "Quota reintegration (inode limits)"
1262 # run dbench with quota enabled
1264 local BLK_LIMIT="100g" #100G
1265 local FILE_LIMIT=1000000
1267 setup_quota_test || error "setup quota failed with $?"
1268 trap cleanup_quota_test EXIT
1270 set_mdt_qtype "ug" || error "enable mdt quota failed"
1271 set_ost_qtype "ug" || error "enable ost quota failed"
1273 echo "Set enough high limit for user: $TSTUSR"
1274 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1275 error "set user quota failed"
1276 echo "Set enough high limit for group: $TSTUSR"
1277 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1278 error "set group quota failed"
1281 [ "$SLOW" = "no" ] && duration=" -t 120"
1282 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1283 quota_error a $TSTUSR "dbench failed!"
1286 resetquota -u $TSTUSR
1287 resetquota -g $TSTUSR
1289 run_test 8 "Run dbench with quota enabled"
1291 # this check is just for test_9
1292 OST0_MIN=4900000 #4.67G
1294 check_whether_skip () {
1295 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1296 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1297 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1298 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1305 # run for fixing bug10707, it needs a big room. test for 64bit
1307 local filesize=$((1024 * 9 / 2)) # 4.5G
1309 check_whether_skip && return 0
1311 setup_quota_test || error "setup quota failed with $?"
1312 trap cleanup_quota_test EXIT
1314 set_ost_qtype "ug" || error "enable ost quota failed"
1316 local TESTFILE="$DIR/$tdir/$tfile-0"
1317 local BLK_LIMIT=100G #100G
1318 local FILE_LIMIT=1000000
1320 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1322 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1324 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1325 error "set user quota failed"
1327 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1328 "for group: $TSTUSR"
1329 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1330 error "set group quota failed"
1332 quota_show_check a u $TSTUSR
1333 quota_show_check a g $TSTUSR
1335 echo "Create test file"
1336 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1337 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1339 log "Write the big file of 4.5G ..."
1340 $RUNAS $DD of=$TESTFILE count=$filesize ||
1341 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1347 resetquota -u $TSTUSR
1348 resetquota -g $TSTUSR
1353 run_test 9 "Block limit larger than 4GB (b10707)"
1356 local TESTFILE=$DIR/$tdir/$tfile
1358 setup_quota_test || error "setup quota failed with $?"
1359 trap cleanup_quota_test EXIT
1361 # set limit to root user should fail
1362 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1363 error "set limit for root user successfully, expect failure"
1364 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1365 error "set limit for root group successfully, expect failure"
1367 # root user can overrun quota
1368 set_ost_qtype "ug" || "enable ost quota failed"
1370 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1371 error "set quota failed"
1372 quota_show_check b u $TSTUSR
1374 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1375 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1377 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1378 error "write failure, expect success"
1381 resetquota -u $TSTUSR
1383 run_test 10 "Test quota for root user"
1386 local TESTFILE=$DIR/$tdir/$tfile
1387 setup_quota_test || error "setup quota failed with $?"
1388 trap cleanup_quota_test EXIT
1390 set_mdt_qtype "ug" || "enable mdt quota failed"
1391 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1392 error "set quota failed"
1394 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1395 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1397 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1398 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1401 local USED=$(getquota -u $TSTUSR global curinodes)
1402 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1405 resetquota -u $TSTUSR
1407 run_test 11 "Chown/chgrp ignores quota"
1410 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1412 local blimit=22 # 22M
1413 local blk_cnt=$((blimit - 5))
1414 local TESTFILE0="$DIR/$tdir/$tfile"-0
1415 local TESTFILE1="$DIR/$tdir/$tfile"-1
1417 setup_quota_test || error "setup quota failed with $?"
1418 trap cleanup_quota_test EXIT
1420 set_ost_qtype "u" || "enable ost quota failed"
1421 quota_show_check b u $TSTUSR
1423 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1424 error "set quota failed"
1426 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1427 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1428 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1429 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1431 echo "Write to ost0..."
1432 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1433 quota_error a $TSTUSR "dd failed"
1435 echo "Write to ost1..."
1436 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1437 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1439 echo "Free space from ost0..."
1441 wait_delete_completed
1442 sync_all_data || true
1444 echo "Write to ost1 after space freed from ost0..."
1445 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1446 quota_error a $TSTUSR "rebalancing failed"
1449 resetquota -u $TSTUSR
1451 run_test 12a "Block quota rebalancing"
1454 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1456 local ilimit=$((1024 * 2)) # 2k inodes
1457 local TESTFILE0=$DIR/$tdir/$tfile
1458 local TESTFILE1=$DIR/${tdir}-1/$tfile
1460 setup_quota_test || error "setup quota failed with $?"
1461 trap cleanup_quota_test EXIT
1463 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1464 chmod 0777 $DIR/${tdir}-1
1466 set_mdt_qtype "u" || "enable mdt quota failed"
1467 quota_show_check f u $TSTUSR
1469 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1470 error "set quota failed"
1472 echo "Create $ilimit files on mdt0..."
1473 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1474 quota_error u $TSTUSR "create failed, but expect success"
1476 echo "Create files on mdt1..."
1477 $RUNAS createmany -m $TESTFILE1 1 &&
1478 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1480 echo "Free space from mdt0..."
1481 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1482 wait_delete_completed
1483 sync_all_data || true
1485 echo "Create files on mdt1 after space freed from mdt0..."
1486 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1487 quota_error a $TSTUSR "rebalancing failed"
1489 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1490 error "unlink mdt1 files failed"
1491 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1494 resetquota -u $TSTUSR
1496 run_test 12b "Inode quota rebalancing"
1499 local TESTFILE=$DIR/$tdir/$tfile
1500 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1501 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1503 setup_quota_test || error "setup quota failed with $?"
1504 trap cleanup_quota_test EXIT
1506 set_ost_qtype "u" || "enable ost quota failed"
1507 quota_show_check b u $TSTUSR
1509 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1510 error "set quota failed"
1511 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1512 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1514 # clear the locks in cache first
1515 do_facet ost1 $LCTL set_param -n $procf=clear
1516 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1517 [ $nlock -eq 0 ] || error "$nlock cached locks"
1519 # write to acquire the per-ID lock
1520 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1521 quota_error a $TSTUSR "dd failed"
1523 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1524 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1526 # clear quota doesn't trigger per-ID lock cancellation
1527 resetquota -u $TSTUSR
1528 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1529 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1531 # clear the per-ID lock
1532 do_facet ost1 $LCTL set_param -n $procf=clear
1533 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1534 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1536 # spare quota should be released
1537 local OSTUUID=$(ostuuid_from_index 0)
1538 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1539 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1540 [ $limit -le $space ] ||
1541 error "spare quota isn't released, limit:$limit, space:$space"
1545 run_test 13 "Cancel per-ID lock in the LRU list"
1548 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1550 wait_delete_completed
1551 sync_all_data || true
1554 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1555 error "set user quota failed"
1556 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1557 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1558 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1559 resetquota -u $TSTUSR
1562 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1563 error "set group quota failed"
1564 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1565 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1566 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1567 resetquota -g $TSTUSR
1569 run_test 15 "Set over 4T block quota"
1573 local BLKS=1 # 1M less than limit
1574 local TESTFILE=$DIR/$tdir/$tfile
1576 setup_quota_test || error "setup quota failed with $?"
1577 trap cleanup_quota_test EXIT
1579 # make sure the system is clean
1580 local USED=$(getquota -u $TSTUSR global curspace)
1581 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1583 set_ost_qtype "ug" || error "enable ost quota failed"
1584 # make sure no granted quota on ost
1585 resetquota -u $TSTUSR
1586 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1587 error "set quota failed"
1589 quota_show_check b u $TSTUSR
1591 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1592 lustre_fail mds 0xa04 $err_code
1594 # write in background
1595 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1599 # write should be blocked and never finished
1600 if ! ps -p $DDPID > /dev/null 2>&1; then
1602 quota_error u $TSTUSR "write finished incorrectly!"
1610 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1612 if [ $count -gt $timeout ]; then
1613 quota_error u $TSTUSR "dd is not finished!"
1618 sync; sync_all_data || true
1620 USED=$(getquota -u $TSTUSR global curspace)
1621 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1622 "Used space(${USED}K) is less than ${BLKS}M"
1625 resetquota -u $TSTUSR
1628 # DQACQ return recoverable error
1630 echo "DQACQ return -ENOLCK"
1632 test_17sub 37 || error "Handle -ENOLCK failed"
1634 echo "DQACQ return -EAGAIN"
1636 test_17sub 11 || error "Handle -EAGAIN failed"
1638 echo "DQACQ return -ETIMEDOUT"
1639 #define ETIMEDOUT 110
1640 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1642 echo "DQACQ return -ENOTCONN"
1643 #define ENOTCONN 107
1644 test_17sub 107 || error "Handle -ENOTCONN failed"
1647 run_test 17 "DQACQ return recoverable error"
1651 local blimit="200m" # 200M
1652 local TESTFILE="$DIR/$tdir/$tfile"
1654 setup_quota_test || error "setup quota failed with $?"
1655 trap cleanup_quota_test EXIT
1657 set_ost_qtype "u" || error "enable ost quota failed"
1658 log "User quota (limit: $blimit)"
1659 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1660 error "set quota failed"
1661 quota_show_check b u $TSTUSR
1663 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1664 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1666 local timeout=$(sysctl -n lustre.timeout)
1668 if [ $io_type = "directio" ]; then
1669 log "Write 100M (directio) ..."
1670 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1672 log "Write 100M (buffered) ..."
1673 $RUNAS $DD of=$TESTFILE count=100 &
1677 replay_barrier $SINGLEMDS
1678 log "Fail mds for $((2 * timeout)) seconds"
1679 fail $SINGLEMDS $((2 * timeout))
1682 if at_is_enabled; then
1683 timeout=$(at_max_get mds)
1685 timeout=$(lctl get_param -n timeout)
1689 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1690 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1691 log "it took $count second"
1696 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1698 cancel_lru_locks mdc
1699 cancel_lru_locks osc
1702 local testfile_size=$(stat -c %s $TESTFILE)
1703 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1704 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1705 "got ${testfile_size}. Verifying file failed!"
1708 resetquota -u $TSTUSR
1711 # test when mds does failover, the ost still could work well
1712 # this test shouldn't trigger watchdog b=14840
1714 # Clear dmesg so watchdog is not triggered by previous
1716 do_facet ost1 dmesg -c > /dev/null
1719 test_18_sub directio
1721 # check if watchdog is triggered
1722 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1723 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1724 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1725 [ -z "$watchdog" ] || error "$watchdog"
1726 rm -f $TMP/lustre-log-${TESTNAME}.log
1728 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1732 local TESTFILE=$DIR/$tdir/$tfile
1734 setup_quota_test || error "setup quota failed with $?"
1735 trap cleanup_quota_test EXIT
1737 set_ost_qtype "ug" || error "enable ost quota failed"
1739 # bind file to a single OST
1740 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1741 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1743 echo "Set user quota (limit: ${blimit}M)"
1744 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1745 error "set user quota failed"
1746 quota_show_check b u $TSTUSR
1747 echo "Update quota limits"
1748 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1749 error "set group quota failed"
1750 quota_show_check b u $TSTUSR
1752 # first wirte might be cached
1753 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1754 cancel_lru_locks osc
1756 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1757 quota_error u $TSTUSR "Write success, expect failure"
1761 resetquota -u $TSTUSR
1763 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1765 test_20() { # b15754
1766 local LSTR=(2g 1t 4k 3m) # limits strings
1768 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1771 resetquota -u $TSTUSR
1773 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1774 $MOUNT || error "could not set quota limits"
1775 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1776 --inode-softlimit ${LSTR[2]} \
1777 --inode-hardlimit ${LSTR[3]} \
1778 $MOUNT || error "could not set quota limits"
1780 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1781 error "bsoftlimit was not set properly"
1782 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1783 error "bhardlimit was not set properly"
1784 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1785 error "isoftlimit was not set properly"
1786 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1787 error "ihardlimit was not set properly"
1789 resetquota -u $TSTUSR
1791 run_test 20 "Test if setquota specifiers work properly (b15754)"
1798 local time=$(($(date +%s) + seconds))
1799 while [ $(date +%s) -lt $time ]; do
1800 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1804 # run for fixing bug16053, setquota shouldn't fail when writing and
1805 # deleting are happening
1807 local TESTFILE="$DIR/$tdir/$tfile"
1808 local BLIMIT=10 # 10G
1809 local ILIMIT=1000000
1811 setup_quota_test || error "setup quota failed with $?"
1812 trap cleanup_quota_test EXIT
1814 set_ost_qtype "ug" || error "Enable ost quota failed"
1816 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1817 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1818 error "set user quota failed"
1819 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1820 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1821 error "set group quota failed"
1823 # repeat writing on a 1M file
1824 test_21_sub ${TESTFILE}_1 1 30 &
1826 # repeat writing on a 128M file
1827 test_21_sub ${TESTFILE}_2 128 30 &
1830 local time=$(($(date +%s) + 30))
1832 while [ $(date +%s) -lt $time ]; do
1833 log "Set quota for $i times"
1834 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1835 -I $((ILIMIT + i)) $MOUNT ||
1836 error "Set user quota failed"
1837 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1838 -I $((ILIMIT + i)) $MOUNT ||
1839 error "Set group quota failed"
1846 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1848 if [ $count -gt 60 ]; then
1849 quota_error a $TSTUSR "dd should be finished!"
1853 echo "(dd_pid=$DDPID1, time=$count)successful"
1857 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1859 if [ $count -gt 60 ]; then
1860 quota_error a $TSTUSR "dd should be finished!"
1864 echo "(dd_pid=$DDPID2, time=$count)successful"
1867 resetquota -u $TSTUSR
1868 resetquota -g $TSTUSR
1870 run_test 21 "Setquota while writing & deleting (b16053)"
1872 # enable/disable quota enforcement permanently
1874 echo "Set both mdt & ost quota type as ug"
1875 set_mdt_qtype "ug" || error "enable mdt quota failed"
1876 set_ost_qtype "ug" || error "enable ost quota failed"
1879 stopall || error "failed to stopall (1)"
1883 echo "Verify if quota is enabled"
1884 local qtype=$(mdt_quota_type)
1885 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1886 qtype=$(ost_quota_type)
1887 [ $qtype != "ug" ] && error "ost quota setting is lost"
1889 echo "Set both mdt & ost quota type as none"
1890 set_mdt_qtype "none" || error "disable mdt quota failed"
1891 set_ost_qtype "none" || error "disable ost quota failed"
1894 stopall || error "failed to stopall (2)"
1899 echo "Verify if quota is disabled"
1900 qtype=$(mdt_quota_type)
1901 [ $qtype != "none" ] && error "mdt quota setting is lost"
1902 qtype=$(ost_quota_type)
1903 [ $qtype != "none" ] && error "ost quota setting is lost"
1907 run_test 22 "enable/disable quota by 'lctl conf_param'"
1910 local TESTFILE="$DIR/$tdir/$tfile"
1913 setup_quota_test || error "setup quota failed with $?"
1914 trap cleanup_quota_test EXIT
1916 set_ost_qtype "ug" || error "Enable ost quota failed"
1919 log "User quota (limit: $LIMIT MB)"
1920 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1921 error "set quota failed"
1922 quota_show_check b u $TSTUSR
1924 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1925 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1927 log "Step1: trigger EDQUOT with O_DIRECT"
1928 log "Write half of file"
1929 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1930 quota_error u $TSTUSR "(1) Write failure, expect success." \
1932 log "Write out of block quota ..."
1933 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1934 oflag=direct conv=notrunc &&
1935 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1939 log "Step2: rewrite should succeed"
1940 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1941 quota_error u $TSTUSR "(3) Write failure, expect success." \
1947 local OST0_UUID=$(ostuuid_from_index 0)
1948 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1949 [ $OST0_QUOTA_USED -ne 0 ] &&
1950 ($SHOW_QUOTA_USER; \
1951 quota_error u $TSTUSR "quota isn't released")
1953 resetquota -u $TSTUSR
1957 [ $(facet_fstype ost1) == "zfs" ] &&
1958 skip "Overwrite in place is not guaranteed to be " \
1959 "space neutral on ZFS" && return
1961 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1962 check_whether_skip && return 0
1963 log "run for 4MB test file"
1966 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1967 check_whether_skip && return 0
1968 log "run for 40MB test file"
1971 run_test 23 "Quota should be honored with directIO (b16125)"
1975 local TESTFILE="$DIR/$tdir/$tfile"
1977 setup_quota_test || error "setup quota failed with $?"
1978 trap cleanup_quota_test EXIT
1980 set_ost_qtype "ug" || error "enable ost quota failed"
1982 # bind file to a single OST
1983 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1984 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1986 echo "Set user quota (limit: ${blimit}M)"
1987 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1988 error "set quota failed"
1990 # overrun quota by root user
1991 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1992 error "write failure, expect success"
1993 cancel_lru_locks osc
1994 sync_all_data || true
1996 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1999 resetquota -u $TSTUSR
2001 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2003 test_27a() { # b19612
2004 $LFS quota $TSTUSR $DIR &&
2005 error "lfs succeeded with no type, but should have failed"
2006 $LFS setquota $TSTUSR $DIR &&
2007 error "lfs succeeded with no type, but should have failed"
2010 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2012 test_27b() { # b20200
2013 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2014 error "lfs setquota failed with uid argument"
2015 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2016 error "lfs stequota failed with gid argument"
2017 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2018 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2019 resetquota -u $TSTUSR
2020 resetquota -g $TSTUSR
2023 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2028 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2029 error "lfs setquota failed"
2031 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2032 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2033 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2034 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2036 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2037 error "lfs setquota for $TSTID failed"
2039 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2040 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2041 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2042 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2044 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2045 error "total allocated inode/block limit not printed"
2047 resetquota -u $TSTUSR
2049 run_test 27c "lfs quota should support human-readable output"
2053 local TESTFILE="$DIR/$tdir/$tfile"
2056 setup_quota_test || error "setup quota failed with $?"
2057 trap cleanup_quota_test EXIT
2059 set_ost_qtype "u" || error "enable ost quota failed"
2061 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2062 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2064 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2065 $MAX_IQ_TIME $DIR || error "set grace time failed"
2066 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2067 error "set quota failed"
2068 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2069 cancel_lru_locks osc
2071 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2072 # over-quota flag has not yet settled since we do not trigger async
2073 # events based on grace time period expiration
2075 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2076 cancel_lru_locks osc
2077 # now over-quota flag should be settled and further writes should fail
2079 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2080 error "grace times were reset"
2083 resetquota -u $TSTUSR
2084 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2085 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2087 run_test 30 "Hard limit updates should not reset grace times"
2089 # basic usage tracking for user & group
2091 local INODES=10 # 10 files
2092 local BLK_CNT=2 # of 2M each
2093 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2095 setup_quota_test || error "setup quota failed with $?"
2096 trap cleanup_quota_test EXIT
2098 # make sure the system is clean
2099 local USED=$(getquota -u $TSTID global curspace)
2101 error "Used space ($USED) for user $TSTID isn't 0."
2102 USED=$(getquota -g $TSTID global curspace)
2104 error "Used space ($USED) for group $TSTID isn't 0."
2106 echo "Write files..."
2107 for i in $(seq 0 $INODES); do
2108 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2109 error "write failed"
2110 echo "Iteration $i/$INODES completed"
2112 cancel_lru_locks osc
2113 sync; sync_all_data || true
2115 echo "Verify disk usage after write"
2116 USED=$(getquota -u $TSTID global curspace)
2117 [ $USED -lt $TOTAL_BLKS ] &&
2118 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2119 USED=$(getquota -g $TSTID global curspace)
2120 [ $USED -lt $TOTAL_BLKS ] &&
2121 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2123 echo "Verify inode usage after write"
2124 USED=$(getquota -u $TSTID global curinodes)
2125 [ $USED -lt $INODES ] &&
2126 error "Used inode for user $TSTID is $USED, expected $INODES"
2127 USED=$(getquota -g $TSTID global curinodes)
2128 [ $USED -lt $INODES ] &&
2129 error "Used inode for group $TSTID is $USED, expected $INODES"
2133 echo "Verify disk usage after delete"
2134 USED=$(getquota -u $TSTID global curspace)
2135 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2136 USED=$(getquota -u $TSTID global curinodes)
2137 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2138 USED=$(getquota -g $TSTID global curspace)
2139 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2140 USED=$(getquota -g $TSTID global curinodes)
2141 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2143 run_test 33 "Basic usage tracking for user & group"
2145 # usage transfer test for user & group
2147 local BLK_CNT=2 # 2MB
2149 setup_quota_test || error "setup quota failed with $?"
2150 trap cleanup_quota_test EXIT
2152 # make sure the system is clean
2153 local USED=$(getquota -u $TSTID global curspace)
2154 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2155 USED=$(getquota -g $TSTID global curspace)
2156 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2158 local USED=$(getquota -u $TSTID2 global curspace)
2159 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2161 echo "Write file..."
2162 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2163 error "write failed"
2164 cancel_lru_locks osc
2165 sync; sync_all_data || true
2167 echo "chown the file to user $TSTID"
2168 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2170 echo "Wait for setattr on objects finished..."
2171 wait_delete_completed
2173 BLK_CNT=$((BLK_CNT * 1024))
2175 echo "Verify disk usage for user $TSTID"
2176 USED=$(getquota -u $TSTID global curspace)
2177 [ $USED -lt $BLK_CNT ] &&
2178 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2179 USED=$(getquota -u $TSTID global curinodes)
2181 error "Used inodes for user $TSTID is $USED, expected 1"
2183 echo "chgrp the file to group $TSTID"
2184 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2186 echo "Wait for setattr on objects finished..."
2187 wait_delete_completed
2189 echo "Verify disk usage for group $TSTID"
2190 USED=$(getquota -g $TSTID global curspace)
2191 [ $USED -ge $BLK_CNT ] ||
2192 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2193 USED=$(getquota -g $TSTID global curinodes)
2195 error "Used inodes for group $TSTID is $USED, expected 1"
2197 # chown won't change the ost object group. LU-4345 */
2198 echo "chown the file to user $TSTID2"
2199 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2201 echo "Wait for setattr on objects finished..."
2202 wait_delete_completed
2204 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2205 USED=$(getquota -u $TSTID2 global curspace)
2206 [ $USED -lt $BLK_CNT ] &&
2207 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2208 USED=$(getquota -u $TSTID global curspace)
2210 error "Used space for user $TSTID is $USED, expected 0"
2211 USED=$(getquota -g $TSTID global curspace)
2212 [ $USED -lt $BLK_CNT ] &&
2213 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2217 run_test 34 "Usage transfer for user & group"
2219 # usage is still accessible across restart
2221 local BLK_CNT=2 # 2 MB
2223 setup_quota_test || error "setup quota failed with $?"
2224 trap cleanup_quota_test EXIT
2226 echo "Write file..."
2227 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2228 error "write failed"
2229 cancel_lru_locks osc
2230 sync; sync_all_data || true
2232 echo "Save disk usage before restart"
2233 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2234 [ $ORIG_USR_SPACE -eq 0 ] &&
2235 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2236 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2237 [ $ORIG_USR_INODES -eq 0 ] &&
2238 error "Used inodes for user $TSTID is 0, expected 1"
2239 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2240 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2241 [ $ORIG_GRP_SPACE -eq 0 ] &&
2242 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2243 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2244 [ $ORIG_GRP_INODES -eq 0 ] &&
2245 error "Used inodes for group $TSTID is 0, expected 1"
2246 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2249 local ORIG_REFORMAT=$REFORMAT
2251 cleanup_and_setup_lustre
2252 REFORMAT=$ORIG_REFORMAT
2255 echo "Verify disk usage after restart"
2256 local USED=$(getquota -u $TSTID global curspace)
2257 [ $USED -eq $ORIG_USR_SPACE ] ||
2258 error "Used space for user $TSTID changed from " \
2259 "$ORIG_USR_SPACE to $USED"
2260 USED=$(getquota -u $TSTID global curinodes)
2261 [ $USED -eq $ORIG_USR_INODES ] ||
2262 error "Used inodes for user $TSTID changed from " \
2263 "$ORIG_USR_INODES to $USED"
2264 USED=$(getquota -g $TSTID global curspace)
2265 [ $USED -eq $ORIG_GRP_SPACE ] ||
2266 error "Used space for group $TSTID changed from " \
2267 "$ORIG_GRP_SPACE to $USED"
2268 USED=$(getquota -g $TSTID global curinodes)
2269 [ $USED -eq $ORIG_GRP_INODES ] ||
2270 error "Used inodes for group $TSTID changed from " \
2271 "$ORIG_GRP_INODES to $USED"
2273 # check if the vfs_dq_init() is called before writing
2274 echo "Append to the same file..."
2275 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2276 error "write failed"
2277 cancel_lru_locks osc
2278 sync; sync_all_data || true
2280 echo "Verify space usage is increased"
2281 USED=$(getquota -u $TSTID global curspace)
2282 [ $USED -gt $ORIG_USR_SPACE ] ||
2283 error "Used space for user $TSTID isn't increased" \
2284 "orig:$ORIG_USR_SPACE, now:$USED"
2285 USED=$(getquota -g $TSTID global curspace)
2286 [ $USED -gt $ORIG_GRP_SPACE ] ||
2287 error "Used space for group $TSTID isn't increased" \
2288 "orig:$ORIG_GRP_SPACE, now:$USED"
2292 run_test 35 "Usage is still accessible across reboot"
2294 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2297 setup_quota_test || error "setup quota failed with $?"
2298 trap cleanup_quota_test EXIT
2300 # make sure the system is clean
2301 local USED=$(getquota -u $TSTID global curspace)
2303 error "Used space ($USED) for user $TSTID isn't 0."
2305 # create file with MDS_OPEN_DELAY_CREATE flag
2306 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2307 error "Create file failed"
2309 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2310 oflag=sync || error "Write file failed"
2312 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2314 # wait for setattr on objects finished..."
2315 wait_delete_completed
2317 USED=$(getquota -u $TSTID global curspace)
2318 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2322 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2326 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2332 check_and_cleanup_lustre
2333 export QUOTA_AUTO=$QUOTA_AUTO_OLD