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 # Does e2fsprogs support quota feature?
42 if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
43 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
44 grep -q 'quota'"; then
45 skip_env "e2fsprogs doesn't support quota" && exit 0
48 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
49 # bug number for skipped test: LU-2836 LU-6836 LU-2836 LU-2059
50 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6 7d"
51 # bug number for skipped test: LU-5638
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
57 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW 9 18 21"
59 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
61 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
66 QUOTA_AUTO_OLD=$QUOTA_AUTO
69 check_and_setup_lustre
71 LOVNAME=$(lctl get_param -n llite.*.lov.common_name | tail -n 1)
72 OSTCOUNT=$(lctl get_param -n lov.$LOVNAME.numobd)
74 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
75 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
76 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
77 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
78 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
79 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
86 local fail_val=${3:-0}
90 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
91 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
92 ost) NODES="$(comma_list $(osts_nodes))";;
95 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
98 RUNAS="runas -u $TSTID -g $TSTID"
99 RUNAS2="runas -u $TSTID2 -g $TSTID2"
100 DD="dd if=/dev/zero bs=1M"
104 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
105 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
106 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
107 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
109 # clear quota limits for a user or a group
110 # usage: resetquota -u username
111 # resetquota -g groupname
114 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
115 [ "$1" != "-u" -a "$1" != "-g" ] &&
116 error "resetquota: wrong specifier $1 passed"
118 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
119 error "clear quota for [type:$1 name:$2] failed"
120 # give a chance to slave to release space
128 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
129 $LFS quota -v -u $LOCAL_ID $DIR
130 log "Files for user ($LOCAL_ID):"
131 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
132 xargs stat 2>/dev/null)
135 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
136 $LFS quota -v -g $LOCAL_ID $DIR
137 log "Files for group ($LOCAL_ID):"
138 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
139 xargs stat 2>/dev/null)
155 # get quota for a user or a group
156 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
157 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
162 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
163 [ "$1" != "-u" -a "$1" != "-g" ] &&
164 error "getquota: wrong u/g specifier $1 passed"
177 *) error "unknown quota parameter $4";;
180 [ "$uuid" = "global" ] && uuid=$DIR
182 $LFS quota -v "$1" "$2" $DIR |
183 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
184 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
189 # usage: set_mdt_qtype ug|u|g|none
193 local mdts=$(get_facets MDS)
195 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
196 # we have to make sure each MDT received config changes
197 for mdt in ${mdts//,/ }; do
199 cmd="$LCTL get_param -n "
200 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
201 cmd=${cmd}.quota_slave.enabled
203 if $(facet_up $mdt); then
204 wait_update_facet $mdt "$cmd" "$qtype" || return 1
211 # usage: set_ost_qtype ug|u|g|none
215 local osts=$(get_facets OST)
217 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
218 # we have to make sure each OST received config changes
219 for ost in ${osts//,/ }; do
221 cmd="$LCTL get_param -n "
222 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
223 cmd=${cmd}.quota_slave.enabled
225 if $(facet_up $ost); then
226 wait_update_facet $ost "$cmd" "$qtype" || return 1
232 wait_reintegration() {
236 local result="glb[1],slv[1],reint[0]"
241 if [ $ntype == "mdt" ]; then
242 tgts=$(get_facets MDS)
244 tgts=$(get_facets OST)
247 for tgt in ${tgts//,/ }; do
249 cmd="$LCTL get_param -n "
250 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
251 cmd=${cmd}.quota_slave.info
253 if $(facet_up $tgt); then
254 wait_update_facet $tgt "$cmd |
255 grep "$qtype" | awk '{ print \\\$3 }'" \
256 "$result" $max || return 1
266 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
267 wait_reintegration "mdt" "user" $max || return 1
270 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
271 wait_reintegration "mdt" "group" $max || return 1
280 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
281 wait_reintegration "ost" "user" $max || return 1
284 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
285 wait_reintegration "ost" "group" $max || return 1
291 wait_delete_completed
292 echo "Creating test directory"
293 mkdir $DIR/$tdir || return 1
294 chmod 0777 $DIR/$tdir || return 2
295 # always clear fail_loc in case of fail_loc isn't cleared
296 # properly when previous test failed
297 lustre_fail mds_ost 0
300 cleanup_quota_test() {
302 echo "Delete files..."
304 echo "Wait for unlink objects finished..."
305 wait_delete_completed
306 sync_all_data || true
315 $LFS quota -v -$ug $qid $DIR
317 if [ "$bf" == "a" -o "$bf" == "b" ]; then
318 usage=$(getquota -$ug $qid global curspace)
319 if [ -z $usage ]; then
320 quota_error $ug $qid \
321 "Query block quota failed ($ug:$qid)."
323 [ $usage -ne 0 ] && quota_log $ug $qid \
324 "Block quota isn't 0 ($ug:$qid:$usage)."
328 if [ "$bf" == "a" -o "$bf" == "f" ]; then
329 usage=$(getquota -$ug $qid global curinodes)
330 if [ -z $usage ]; then
331 quota_error $ug $qid \
332 "Query file quota failed ($ug:$qid)."
334 [ $usage -ne 0 ] && quota_log $ug $qid \
335 "File quota isn't 0 ($ug:$qid:$usage)."
342 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
346 resetquota -u $TSTUSR
347 resetquota -g $TSTUSR
348 resetquota -u $TSTUSR2
349 resetquota -g $TSTUSR2
351 test_quota_performance() {
352 local TESTFILE="$DIR/$tdir/$tfile-0"
353 local size=$1 # in MB
354 local stime=$(date +%s)
355 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
356 quota_error u $TSTUSR "write failure"
357 local etime=$(date +%s)
358 delta=$((etime - stime))
359 if [ $delta -gt 0 ]; then
360 rate=$((size * 1024 / delta))
361 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
362 # LU-2872 - see LU-2887 for fix
364 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
366 [ $rate -gt 1024 ] ||
367 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
382 setup_quota_test || error "setup quota failed with $?"
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"
403 setup_quota_test || error "setup quota failed with $?"
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 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
419 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
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 || error "wait_delete_completed failed"
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 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
452 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
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=$(mdt_free_inodes 0)
483 echo "$FREE_INODES free inodes on master MDT"
484 [ $FREE_INODES -lt $LIMIT ] &&
485 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
488 setup_quota_test || error "setup quota failed with $?"
489 trap cleanup_quota_test EXIT
492 set_mdt_qtype "ug" || "enable mdt quota failed"
495 log "User quota (inode hardlimit:$LIMIT files)"
496 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
497 error "set user quota failed"
499 # make sure the system is clean
500 local USED=$(getquota -u $TSTUSR global curinodes)
501 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
503 log "Create $LIMIT files ..."
504 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
505 quota_error u $TSTUSR "user create failure, but expect success"
506 log "Create out of file quota ..."
507 $RUNAS touch ${TESTFILE}_xxx &&
508 quota_error u $TSTUSR "user create success, but expect EDQUOT"
511 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
512 rm -f ${TESTFILE}_xxx
513 wait_delete_completed
515 USED=$(getquota -u $TSTUSR global curinodes)
516 [ $USED -ne 0 ] && quota_error u $TSTUSR \
517 "user quota isn't released after deletion"
518 resetquota -u $TSTUSR
521 log "--------------------------------------"
522 log "Group quota (inode hardlimit:$LIMIT files)"
523 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
524 error "set group quota failed"
526 TESTFILE=$DIR/$tdir/$tfile-1
527 # make sure the system is clean
528 USED=$(getquota -g $TSTUSR global curinodes)
529 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
531 log "Create $LIMIT files ..."
532 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
533 quota_error g $TSTUSR "group create failure, but expect success"
534 log "Create out of file quota ..."
535 $RUNAS touch ${TESTFILE}_xxx &&
536 quota_error g $TSTUSR "group create success, but expect EDQUOT"
539 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
540 rm -f ${TESTFILE}_xxx
541 wait_delete_completed
543 USED=$(getquota -g $TSTUSR global curinodes)
544 [ $USED -ne 0 ] && quota_error g $TSTUSR \
545 "user quota isn't released after deletion"
548 resetquota -g $TSTUSR
550 run_test 2 "File hard limit (normal use and out of quota)"
554 local TIMER=$(($2 * 3 / 2))
559 trap cleanup_quota_test EXIT
561 $SETSTRIPE $TESTFILE -c 1 -i 0
562 chown $TSTUSR.$TSTUSR $TESTFILE
564 echo "Write up to soft limit"
565 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
566 quota_error a $TSTUSR "write failure, but expect success"
567 OFFSET=$((LIMIT * 1024))
570 echo "Write to exceed soft limit"
571 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
572 quota_error a $TSTUSR "write failure, but expect success"
573 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
578 $SHOW_QUOTA_INFO_USER
579 $SHOW_QUOTA_INFO_GROUP
581 echo "Write before timer goes off"
582 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
583 quota_error a $TSTUSR "write failure, but expect success"
584 OFFSET=$((OFFSET + 1024))
587 echo "Sleep $TIMER seconds ..."
592 $SHOW_QUOTA_INFO_USER
593 $SHOW_QUOTA_INFO_GROUP
595 echo "Write after timer goes off"
596 # maybe cache write, ignore.
597 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
598 OFFSET=$((OFFSET + 1024))
600 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
601 quota_error a $TSTUSR "write success, but expect EDQUOT"
605 $SHOW_QUOTA_INFO_USER
606 $SHOW_QUOTA_INFO_GROUP
608 echo "Unlink file to stop timer"
610 wait_delete_completed
611 sync_all_data || true
615 $SHOW_QUOTA_INFO_USER
616 $SHOW_QUOTA_INFO_GROUP
618 $SETSTRIPE $TESTFILE -c 1 -i 0
619 chown $TSTUSR.$TSTUSR $TESTFILE
622 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
623 quota_error a $TSTUSR "write failure, but expect success"
632 local TESTFILE=$DIR/$tdir/$tfile-0
634 set_ost_qtype "ug" || error "enable ost quota failed"
636 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
637 # make sure the system is clean
638 local USED=$(getquota -u $TSTUSR global curspace)
639 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
641 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
642 $MAX_IQ_TIME $DIR || error "set user grace time failed"
643 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
644 error "set user quota failed"
646 test_block_soft $TESTFILE $GRACE $LIMIT
647 resetquota -u $TSTUSR
649 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
650 TESTFILE=$DIR/$tdir/$tfile-1
651 # make sure the system is clean
652 USED=$(getquota -g $TSTUSR global curspace)
653 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
655 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
656 $MAX_IQ_TIME $DIR || error "set group grace time failed"
657 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
658 error "set group quota failed"
660 test_block_soft $TESTFILE $GRACE $LIMIT
661 resetquota -g $TSTUSR
664 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
665 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
666 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
667 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
669 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
675 local TIMER=$(($grace * 3 / 2))
678 trap cleanup_quota_test EXIT
680 echo "Create files to exceed soft limit"
681 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
682 quota_error a $TSTUSR "create failure, but expect success"
683 local trigger_time=$(date +%s)
685 sync_all_data || true
687 local cur_time=$(date +%s)
688 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
689 error "Passed grace time $grace, $trigger_time, $cur_time"
691 echo "Create file before timer goes off"
692 $RUNAS touch ${TESTFILE}_before ||
693 quota_error a $TSTUSR "failed create before timer expired," \
694 "but expect success. $trigger_time, $cur_time"
695 sync_all_data || true
697 echo "Sleep $TIMER seconds ..."
702 $SHOW_QUOTA_INFO_USER
703 $SHOW_QUOTA_INFO_GROUP
705 echo "Create file after timer goes off"
706 # There is a window that space is accounted in the quota usage but
707 # hasn't been decreased from the pending write, if we acquire quota
708 # in this window, we'll acquire more than we needed.
709 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
710 sync_all_data || true
711 $RUNAS touch ${TESTFILE}_after_3 &&
712 quota_error a $TSTUSR "create after timer expired," \
714 sync_all_data || true
718 $SHOW_QUOTA_INFO_USER
719 $SHOW_QUOTA_INFO_GROUP
721 echo "Unlink files to stop timer"
722 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
723 wait_delete_completed
726 $RUNAS touch ${TESTFILE}_xxx ||
727 quota_error a $TSTUSR "touch after timer stop failure," \
729 sync_all_data || true
737 local LIMIT=10 # inodes
738 local TESTFILE=$DIR/$tdir/$tfile-0
741 set_mdt_qtype "ug" || error "enable mdt quota failed"
743 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
744 # make sure the system is clean
745 local USED=$(getquota -u $TSTUSR global curinodes)
746 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
748 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
749 $GRACE $DIR || error "set user grace time failed"
750 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
751 error "set user quota failed"
753 test_file_soft $TESTFILE $LIMIT $GRACE
754 resetquota -u $TSTUSR
756 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
757 # make sure the system is clean
758 USED=$(getquota -g $TSTUSR global curinodes)
759 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
761 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
762 $GRACE $DIR || error "set group grace time failed"
763 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
764 error "set group quota failed"
765 TESTFILE=$DIR/$tdir/$tfile-1
767 test_file_soft $TESTFILE $LIMIT $GRACE
768 resetquota -g $TSTUSR
771 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
772 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
773 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
774 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
776 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
780 local GR_STR2="1000s"
782 local GR_STR4="1w2d3h4m5s"
784 local GR_STR6="18446744073709551615"
787 wait_delete_completed
789 # test of valid grace strings handling
790 echo "Valid grace strings test"
791 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
792 $GR_STR2 $DIR || error "set user grace time failed"
793 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
794 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
795 $GR_STR4 $DIR || error "set group grace time quota failed"
796 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
798 # test of invalid grace strings handling
799 echo " Invalid grace strings test"
800 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
801 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
802 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
806 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
807 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
808 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
809 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
811 run_test 4b "Grace time strings handling"
813 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
815 local BLIMIT=10 # 10M
816 local ILIMIT=10 # 10 inodes
818 setup_quota_test || error "setup quota failed with $?"
819 trap cleanup_quota_test EXIT
821 set_mdt_qtype "ug" || error "enable mdt quota failed"
822 set_ost_qtype "ug" || error "enable ost quota failed"
824 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
825 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
826 error "set user quota failed"
827 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
828 error "set group quota failed"
830 # make sure the system is clean
831 local USED=$(getquota -u $TSTUSR global curinodes)
832 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
833 USED=$(getquota -g $TSTUSR global curinodes)
834 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
835 USED=$(getquota -u $TSTUSR global curspace)
836 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
837 USED=$(getquota -g $TSTUSR global curspace)
838 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
840 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
841 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
842 error "create failure, expect success"
843 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
844 error "write failure, expect success"
846 echo "Chown files to $TSTUSR.$TSTUSR ..."
847 for i in $(seq 0 $ILIMIT); do
848 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
849 quota_error a $TSTUSR "chown failure, expect success"
853 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
854 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
857 resetquota -u $TSTUSR
858 resetquota -g $TSTUSR
860 run_test 5 "Chown & chgrp successfully even out of block/file quota"
862 # test dropping acquire request on master
866 # Clear dmesg so watchdog is not triggered by previous
868 do_facet ost1 dmesg -c > /dev/null
870 setup_quota_test || error "setup quota failed with $?"
871 trap cleanup_quota_test EXIT
873 # make sure the system is clean
874 local USED=$(getquota -u $TSTUSR global curspace)
875 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
877 # make sure no granted quota on ost
878 set_ost_qtype "ug" || error "enable ost quota failed"
879 resetquota -u $TSTUSR
881 # create file for $TSTUSR
882 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
883 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
884 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
886 # create file for $TSTUSR2
887 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
888 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
889 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
891 # cache per-ID lock for $TSTUSR on slave
892 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
893 error "set quota failed"
894 $RUNAS $DD of=$TESTFILE count=1 ||
895 error "write $TESTFILE failure, expect success"
896 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
897 error "write $TESTFILE2 failure, expect success"
899 sync_all_data || true
901 #define QUOTA_DQACQ 601
902 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
903 lustre_fail mds 0x513 601
905 # write to un-enforced ID ($TSTUSR2) should succeed
906 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
907 error "write failure, expect success"
909 # write to enforced ID ($TSTUSR) in background, exceeding limit
910 # to make sure DQACQ is sent
911 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
914 # watchdog timer uses a factor of 2
915 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
916 sleep $((TIMEOUT * 2 + 1))
918 # write should be blocked and never finished
919 if ! ps -p $DDPID > /dev/null 2>&1; then
921 error "write finished incorrectly!"
926 # no watchdog is triggered
927 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
928 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
929 { print; }' $TMP/lustre-log-${TESTNAME}.log)
930 [ -z "$watchdog" ] || error "$watchdog"
932 rm -f $TMP/lustre-log-${TESTNAME}.log
934 # write should continue then fail with EDQUOT
938 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
939 if [ $count -ge 240 ]; then
940 quota_error u $TSTUSR "dd not finished in $count secs"
943 if [ $((count % 30)) -eq 0 ]; then
944 c_size=$(stat -c %s $TESTFILE)
945 echo "Waiting $count secs. $c_size"
952 resetquota -u $TSTUSR
954 run_test 6 "Test dropping acquire request on master"
956 # quota reintegration (global index)
958 local TESTFILE=$DIR/$tdir/$tfile
961 [ "$SLOW" = "no" ] && LIMIT=5
963 setup_quota_test || error "setup quota failed with $?"
964 trap cleanup_quota_test EXIT
966 # make sure the system is clean
967 local USED=$(getquota -u $TSTUSR global curspace)
968 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
970 # make sure no granted quota on ost1
971 set_ost_qtype "ug" || error "enable ost quota failed"
972 resetquota -u $TSTUSR
973 set_ost_qtype "none" || error "disable ost quota failed"
975 local OSTUUID=$(ostuuid_from_index 0)
976 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
978 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
981 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
982 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
987 echo "Enable quota & set quota limit for $TSTUSR"
988 set_ost_qtype "ug" || error "enable ost quota failed"
989 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
990 error "set quota failed"
993 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
996 wait_ost_reint "ug" || error "reintegration failed"
998 # hardlimit should have been fetched by slave during global
999 # reintegration, write will exceed quota
1000 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1001 quota_error u $TSTUSR "write success, but expect EDQUOT"
1004 wait_delete_completed
1005 sync_all_data || true
1011 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1012 error "clear quota failed"
1014 echo "Start ost1..."
1015 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1018 wait_ost_reint "ug" || error "reintegration failed"
1020 # hardlimit should be cleared on slave during reintegration
1021 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1022 quota_error u $TSTUSR "write error, but expect success"
1025 resetquota -u $TSTUSR
1027 run_test 7a "Quota reintegration (global index)"
1029 # quota reintegration (slave index)
1032 local TESTFILE=$DIR/$tdir/$tfile
1034 setup_quota_test || error "setup quota failed with $?"
1035 trap cleanup_quota_test EXIT
1037 # make sure the system is clean
1038 local USED=$(getquota -u $TSTUSR global curspace)
1039 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1041 # make sure no granted quota on ost1
1042 set_ost_qtype "ug" || error "enable ost quota failed"
1043 resetquota -u $TSTUSR
1044 set_ost_qtype "none" || error "disable ost quota failed"
1046 local OSTUUID=$(ostuuid_from_index 0)
1047 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1049 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1052 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1053 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1055 # consume some space to make sure the granted space will not
1056 # be released during reconciliation
1057 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1058 error "consume space failure, expect success"
1060 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1061 lustre_fail mds 0xa02
1063 set_ost_qtype "ug" || error "enable ost quota failed"
1064 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1065 error "set quota failed"
1067 # ignore the write error
1068 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1070 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1074 echo "Restart ost to trigger reintegration..."
1076 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1079 wait_ost_reint "ug" || error "reintegration failed"
1081 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1082 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1085 resetquota -u $TSTUSR
1088 run_test 7b "Quota reintegration (slave index)"
1090 # quota reintegration (restart mds during reintegration)
1092 local LIMIT=20 # 20M
1093 local TESTFILE=$DIR/$tdir/$tfile
1095 [ "$SLOW" = "no" ] && LIMIT=5
1097 setup_quota_test || error "setup quota failed with $?"
1098 trap cleanup_quota_test EXIT
1100 # make sure the system is clean
1101 local USED=$(getquota -u $TSTUSR global curspace)
1102 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1104 set_ost_qtype "none" || error "disable ost quota failed"
1105 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1106 error "set quota failed"
1108 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1109 lustre_fail ost 0xa03
1112 set_ost_qtype "ug" || error "enable ost quota failed"
1113 # trigger reintegration
1114 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1115 procf=${procf}quota_slave.force_reint
1116 do_facet ost1 $LCTL set_param $procf=1 ||
1117 error "force reintegration failed"
1125 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1128 # wait longer than usual to make sure the reintegration
1129 # is triggered by quota wb thread.
1130 wait_ost_reint "ug" 200 || error "reintegration failed"
1132 # hardlimit should have been fetched by slave during global
1133 # reintegration, write will exceed quota
1134 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1135 quota_error u $TSTUSR "write success, but expect EDQUOT"
1138 resetquota -u $TSTUSR
1140 run_test 7c "Quota reintegration (restart mds during reintegration)"
1142 # Quota reintegration (Transfer index in multiple bulks)
1144 local TESTFILE=$DIR/$tdir/$tfile
1145 local TESTFILE1="$DIR/$tdir/$tfile"-1
1148 setup_quota_test || error "setup quota failed with $?"
1149 trap cleanup_quota_test EXIT
1151 set_ost_qtype "none" || error "disable ost quota failed"
1152 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1153 error "set quota for $TSTUSR failed"
1154 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1155 error "set quota for $TSTUSR2 failed"
1157 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1158 lustre_fail mds 0x608 0
1160 # enable quota to tirgger reintegration
1161 set_ost_qtype "u" || error "enable ost quota failed"
1162 wait_ost_reint "u" || error "reintegration failed"
1166 # hardlimit should have been fetched by slave during global
1167 # reintegration, write will exceed quota
1168 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1169 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1171 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1172 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1175 resetquota -u $TSTUSR
1176 resetquota -u $TSTUSR2
1178 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1180 # quota reintegration (inode limits)
1182 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1184 local ilimit=$((1024 * 2)) # 2k inodes
1185 local TESTFILE=$DIR/${tdir}-1/$tfile
1187 setup_quota_test || error "setup quota failed with $?"
1188 trap cleanup_quota_test EXIT
1190 # make sure the system is clean
1191 local USED=$(getquota -u $TSTUSR global curinodes)
1192 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1194 # make sure no granted quota on mdt1
1195 set_mdt_qtype "ug" || error "enable mdt quota failed"
1196 resetquota -u $TSTUSR
1197 set_mdt_qtype "none" || error "disable mdt quota failed"
1199 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1200 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1201 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1204 echo "Stop mds${MDSCOUNT}..."
1207 echo "Enable quota & set quota limit for $TSTUSR"
1208 set_mdt_qtype "ug" || error "enable mdt quota failed"
1209 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1210 error "set quota failed"
1212 echo "Start mds${MDSCOUNT}..."
1213 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1216 wait_mdt_reint "ug" || error "reintegration failed"
1218 echo "create remote dir"
1219 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1220 error "create remote dir failed"
1221 chmod 0777 $DIR/${tdir}-1
1223 # hardlimit should have been fetched by slave during global
1224 # reintegration, create will exceed quota
1225 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1226 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1228 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1229 wait_delete_completed
1230 sync_all_data || true
1232 echo "Stop mds${MDSCOUNT}..."
1235 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1236 error "clear quota failed"
1238 echo "Start mds${MDSCOUNT}..."
1239 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1242 wait_mdt_reint "ug" || error "reintegration failed"
1244 # hardlimit should be cleared on slave during reintegration
1245 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1246 quota_error -u $TSTUSR "create failed, expect success"
1248 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1249 rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1252 resetquota -u $TSTUSR
1254 run_test 7e "Quota reintegration (inode limits)"
1256 # run dbench with quota enabled
1258 local BLK_LIMIT="100g" #100G
1259 local FILE_LIMIT=1000000
1261 setup_quota_test || error "setup quota failed with $?"
1262 trap cleanup_quota_test EXIT
1264 set_mdt_qtype "ug" || error "enable mdt quota failed"
1265 set_ost_qtype "ug" || error "enable ost quota failed"
1267 echo "Set enough high limit for user: $TSTUSR"
1268 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1269 error "set user quota failed"
1270 echo "Set enough high limit for group: $TSTUSR"
1271 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1272 error "set group quota failed"
1275 [ "$SLOW" = "no" ] && duration=" -t 120"
1276 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1277 quota_error a $TSTUSR "dbench failed!"
1280 resetquota -u $TSTUSR
1281 resetquota -g $TSTUSR
1283 run_test 8 "Run dbench with quota enabled"
1285 # this check is just for test_9
1286 OST0_MIN=4900000 #4.67G
1288 check_whether_skip () {
1289 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1290 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1291 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1292 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1299 # run for fixing bug10707, it needs a big room. test for 64bit
1301 local filesize=$((1024 * 9 / 2)) # 4.5G
1303 check_whether_skip && return 0
1305 setup_quota_test || error "setup quota failed with $?"
1306 trap cleanup_quota_test EXIT
1308 set_ost_qtype "ug" || error "enable ost quota failed"
1310 local TESTFILE="$DIR/$tdir/$tfile-0"
1311 local BLK_LIMIT=100G #100G
1312 local FILE_LIMIT=1000000
1314 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1316 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1318 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1319 error "set user quota failed"
1321 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1322 "for group: $TSTUSR"
1323 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1324 error "set group quota failed"
1326 quota_show_check a u $TSTUSR
1327 quota_show_check a g $TSTUSR
1329 echo "Create test file"
1330 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1331 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1333 log "Write the big file of 4.5G ..."
1334 $RUNAS $DD of=$TESTFILE count=$filesize ||
1335 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1341 resetquota -u $TSTUSR
1342 resetquota -g $TSTUSR
1347 run_test 9 "Block limit larger than 4GB (b10707)"
1350 local TESTFILE=$DIR/$tdir/$tfile
1352 setup_quota_test || error "setup quota failed with $?"
1353 trap cleanup_quota_test EXIT
1355 # set limit to root user should fail
1356 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1357 error "set limit for root user successfully, expect failure"
1358 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1359 error "set limit for root group successfully, expect failure"
1361 # root user can overrun quota
1362 set_ost_qtype "ug" || "enable ost quota failed"
1364 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1365 error "set quota failed"
1366 quota_show_check b u $TSTUSR
1368 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1369 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1371 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1372 error "write failure, expect success"
1375 resetquota -u $TSTUSR
1377 run_test 10 "Test quota for root user"
1380 local TESTFILE=$DIR/$tdir/$tfile
1381 setup_quota_test || error "setup quota failed with $?"
1382 trap cleanup_quota_test EXIT
1384 set_mdt_qtype "ug" || "enable mdt quota failed"
1385 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1386 error "set quota failed"
1388 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1389 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1391 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1392 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1395 local USED=$(getquota -u $TSTUSR global curinodes)
1396 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1399 resetquota -u $TSTUSR
1401 run_test 11 "Chown/chgrp ignores quota"
1404 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1406 local blimit=22 # 22M
1407 local blk_cnt=$((blimit - 5))
1408 local TESTFILE0="$DIR/$tdir/$tfile"-0
1409 local TESTFILE1="$DIR/$tdir/$tfile"-1
1411 setup_quota_test || error "setup quota failed with $?"
1412 trap cleanup_quota_test EXIT
1414 set_ost_qtype "u" || "enable ost quota failed"
1415 quota_show_check b u $TSTUSR
1417 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1418 error "set quota failed"
1420 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1421 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1422 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1423 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1425 echo "Write to ost0..."
1426 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1427 quota_error a $TSTUSR "dd failed"
1429 echo "Write to ost1..."
1430 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1431 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1433 echo "Free space from ost0..."
1435 wait_delete_completed
1436 sync_all_data || true
1438 echo "Write to ost1 after space freed from ost0..."
1439 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1440 quota_error a $TSTUSR "rebalancing failed"
1443 resetquota -u $TSTUSR
1445 run_test 12a "Block quota rebalancing"
1448 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1450 local ilimit=$((1024 * 2)) # 2k inodes
1451 local TESTFILE0=$DIR/$tdir/$tfile
1452 local TESTFILE1=$DIR/${tdir}-1/$tfile
1454 setup_quota_test || error "setup quota failed with $?"
1455 trap cleanup_quota_test EXIT
1457 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1458 chmod 0777 $DIR/${tdir}-1
1460 set_mdt_qtype "u" || "enable mdt quota failed"
1461 quota_show_check f u $TSTUSR
1463 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1464 error "set quota failed"
1466 echo "Create $ilimit files on mdt0..."
1467 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1468 quota_error u $TSTUSR "create failed, but expect success"
1470 echo "Create files on mdt1..."
1471 $RUNAS createmany -m $TESTFILE1 1 &&
1472 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1474 echo "Free space from mdt0..."
1475 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1476 wait_delete_completed
1477 sync_all_data || true
1479 echo "Create files on mdt1 after space freed from mdt0..."
1480 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1481 quota_error a $TSTUSR "rebalancing failed"
1483 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1484 error "unlink mdt1 files failed"
1485 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1488 resetquota -u $TSTUSR
1490 run_test 12b "Inode quota rebalancing"
1493 local TESTFILE=$DIR/$tdir/$tfile
1494 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1495 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1497 setup_quota_test || error "setup quota failed with $?"
1498 trap cleanup_quota_test EXIT
1500 set_ost_qtype "u" || "enable ost quota failed"
1501 quota_show_check b u $TSTUSR
1503 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1504 error "set quota failed"
1505 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1506 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1508 # clear the locks in cache first
1509 do_facet ost1 $LCTL set_param -n $procf=clear
1510 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1511 [ $nlock -eq 0 ] || error "$nlock cached locks"
1513 # write to acquire the per-ID lock
1514 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1515 quota_error a $TSTUSR "dd failed"
1517 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1518 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1520 # clear quota doesn't trigger per-ID lock cancellation
1521 resetquota -u $TSTUSR
1522 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1523 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1525 # clear the per-ID lock
1526 do_facet ost1 $LCTL set_param -n $procf=clear
1527 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1528 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1530 # spare quota should be released
1531 local OSTUUID=$(ostuuid_from_index 0)
1532 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1533 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1534 [ $limit -le $space ] ||
1535 error "spare quota isn't released, limit:$limit, space:$space"
1539 run_test 13 "Cancel per-ID lock in the LRU list"
1542 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1544 wait_delete_completed
1545 sync_all_data || true
1548 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1549 error "set user quota failed"
1550 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1551 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1552 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1553 resetquota -u $TSTUSR
1556 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1557 error "set group quota failed"
1558 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1559 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1560 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1561 resetquota -g $TSTUSR
1563 run_test 15 "Set over 4T block quota"
1567 local BLKS=1 # 1M less than limit
1568 local TESTFILE=$DIR/$tdir/$tfile
1570 setup_quota_test || error "setup quota failed with $?"
1571 trap cleanup_quota_test EXIT
1573 # make sure the system is clean
1574 local USED=$(getquota -u $TSTUSR global curspace)
1575 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1577 set_ost_qtype "ug" || error "enable ost quota failed"
1578 # make sure no granted quota on ost
1579 resetquota -u $TSTUSR
1580 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1581 error "set quota failed"
1583 quota_show_check b u $TSTUSR
1585 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1586 lustre_fail mds 0xa04 $err_code
1588 # write in background
1589 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1593 # write should be blocked and never finished
1594 if ! ps -p $DDPID > /dev/null 2>&1; then
1596 quota_error u $TSTUSR "write finished incorrectly!"
1604 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1606 if [ $count -gt $timeout ]; then
1607 quota_error u $TSTUSR "dd is not finished!"
1612 sync; sync_all_data || true
1614 USED=$(getquota -u $TSTUSR global curspace)
1615 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1616 "Used space(${USED}K) is less than ${BLKS}M"
1619 resetquota -u $TSTUSR
1622 # DQACQ return recoverable error
1624 echo "DQACQ return -ENOLCK"
1626 test_17sub 37 || error "Handle -ENOLCK failed"
1628 echo "DQACQ return -EAGAIN"
1630 test_17sub 11 || error "Handle -EAGAIN failed"
1632 echo "DQACQ return -ETIMEDOUT"
1633 #define ETIMEDOUT 110
1634 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1636 echo "DQACQ return -ENOTCONN"
1637 #define ENOTCONN 107
1638 test_17sub 107 || error "Handle -ENOTCONN failed"
1641 run_test 17 "DQACQ return recoverable error"
1645 local blimit="200m" # 200M
1646 local TESTFILE="$DIR/$tdir/$tfile"
1648 setup_quota_test || error "setup quota failed with $?"
1649 trap cleanup_quota_test EXIT
1651 set_ost_qtype "u" || error "enable ost quota failed"
1652 log "User quota (limit: $blimit)"
1653 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1654 error "set quota failed"
1655 quota_show_check b u $TSTUSR
1657 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1658 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1660 local timeout=$(sysctl -n lustre.timeout)
1662 if [ $io_type = "directio" ]; then
1663 log "Write 100M (directio) ..."
1664 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1666 log "Write 100M (buffered) ..."
1667 $RUNAS $DD of=$TESTFILE count=100 &
1671 replay_barrier $SINGLEMDS
1672 log "Fail mds for $((2 * timeout)) seconds"
1673 fail $SINGLEMDS $((2 * timeout))
1676 if at_is_enabled; then
1677 timeout=$(at_max_get mds)
1679 timeout=$(lctl get_param -n timeout)
1683 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1684 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1685 log "it took $count second"
1690 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1692 cancel_lru_locks mdc
1693 cancel_lru_locks osc
1696 local testfile_size=$(stat -c %s $TESTFILE)
1697 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1698 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1699 "got ${testfile_size}. Verifying file failed!"
1702 resetquota -u $TSTUSR
1705 # test when mds does failover, the ost still could work well
1706 # this test shouldn't trigger watchdog b=14840
1708 # Clear dmesg so watchdog is not triggered by previous
1710 do_facet ost1 dmesg -c > /dev/null
1713 test_18_sub directio
1715 # check if watchdog is triggered
1716 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1717 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1718 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1719 [ -z "$watchdog" ] || error "$watchdog"
1720 rm -f $TMP/lustre-log-${TESTNAME}.log
1722 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1726 local TESTFILE=$DIR/$tdir/$tfile
1728 setup_quota_test || error "setup quota failed with $?"
1729 trap cleanup_quota_test EXIT
1731 set_ost_qtype "ug" || error "enable ost quota failed"
1733 # bind file to a single OST
1734 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1735 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1737 echo "Set user quota (limit: ${blimit}M)"
1738 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1739 error "set user quota failed"
1740 quota_show_check b u $TSTUSR
1741 echo "Update quota limits"
1742 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1743 error "set group quota failed"
1744 quota_show_check b u $TSTUSR
1746 # first wirte might be cached
1747 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1748 cancel_lru_locks osc
1750 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1751 quota_error u $TSTUSR "Write success, expect failure"
1755 resetquota -u $TSTUSR
1757 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1759 test_20() { # b15754
1760 local LSTR=(2g 1t 4k 3m) # limits strings
1762 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1765 resetquota -u $TSTUSR
1767 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1768 $MOUNT || error "could not set quota limits"
1769 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1770 --inode-softlimit ${LSTR[2]} \
1771 --inode-hardlimit ${LSTR[3]} \
1772 $MOUNT || error "could not set quota limits"
1774 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1775 error "bsoftlimit was not set properly"
1776 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1777 error "bhardlimit was not set properly"
1778 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1779 error "isoftlimit was not set properly"
1780 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1781 error "ihardlimit was not set properly"
1783 resetquota -u $TSTUSR
1785 run_test 20 "Test if setquota specifiers work properly (b15754)"
1792 local time=$(($(date +%s) + seconds))
1793 while [ $(date +%s) -lt $time ]; do
1794 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1798 # run for fixing bug16053, setquota shouldn't fail when writing and
1799 # deleting are happening
1801 local TESTFILE="$DIR/$tdir/$tfile"
1802 local BLIMIT=10 # 10G
1803 local ILIMIT=1000000
1805 setup_quota_test || error "setup quota failed with $?"
1806 trap cleanup_quota_test EXIT
1808 set_ost_qtype "ug" || error "Enable ost quota failed"
1810 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1811 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1812 error "set user quota failed"
1813 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1814 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1815 error "set group quota failed"
1817 # repeat writing on a 1M file
1818 test_21_sub ${TESTFILE}_1 1 30 &
1820 # repeat writing on a 128M file
1821 test_21_sub ${TESTFILE}_2 128 30 &
1824 local time=$(($(date +%s) + 30))
1826 while [ $(date +%s) -lt $time ]; do
1827 log "Set quota for $i times"
1828 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1829 -I $((ILIMIT + i)) $MOUNT ||
1830 error "Set user quota failed"
1831 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1832 -I $((ILIMIT + i)) $MOUNT ||
1833 error "Set group quota failed"
1840 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1842 if [ $count -gt 60 ]; then
1843 quota_error a $TSTUSR "dd should be finished!"
1847 echo "(dd_pid=$DDPID1, time=$count)successful"
1851 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1853 if [ $count -gt 60 ]; then
1854 quota_error a $TSTUSR "dd should be finished!"
1858 echo "(dd_pid=$DDPID2, time=$count)successful"
1861 resetquota -u $TSTUSR
1862 resetquota -g $TSTUSR
1864 run_test 21 "Setquota while writing & deleting (b16053)"
1866 # enable/disable quota enforcement permanently
1868 echo "Set both mdt & ost quota type as ug"
1869 set_mdt_qtype "ug" || error "enable mdt quota failed"
1870 set_ost_qtype "ug" || error "enable ost quota failed"
1873 stopall || error "failed to stopall (1)"
1877 echo "Verify if quota is enabled"
1878 local qtype=$(mdt_quota_type)
1879 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1880 qtype=$(ost_quota_type)
1881 [ $qtype != "ug" ] && error "ost quota setting is lost"
1883 echo "Set both mdt & ost quota type as none"
1884 set_mdt_qtype "none" || error "disable mdt quota failed"
1885 set_ost_qtype "none" || error "disable ost quota failed"
1888 stopall || error "failed to stopall (2)"
1893 echo "Verify if quota is disabled"
1894 qtype=$(mdt_quota_type)
1895 [ $qtype != "none" ] && error "mdt quota setting is lost"
1896 qtype=$(ost_quota_type)
1897 [ $qtype != "none" ] && error "ost quota setting is lost"
1901 run_test 22 "enable/disable quota by 'lctl conf_param'"
1904 local TESTFILE="$DIR/$tdir/$tfile"
1907 setup_quota_test || error "setup quota failed with $?"
1908 trap cleanup_quota_test EXIT
1910 set_ost_qtype "ug" || error "Enable ost quota failed"
1913 log "User quota (limit: $LIMIT MB)"
1914 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1915 error "set quota failed"
1916 quota_show_check b u $TSTUSR
1918 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1919 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1921 log "Step1: trigger EDQUOT with O_DIRECT"
1922 log "Write half of file"
1923 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1924 quota_error u $TSTUSR "(1) Write failure, expect success." \
1926 log "Write out of block quota ..."
1927 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1928 oflag=direct conv=notrunc &&
1929 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1933 log "Step2: rewrite should succeed"
1934 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1935 quota_error u $TSTUSR "(3) Write failure, expect success." \
1941 local OST0_UUID=$(ostuuid_from_index 0)
1942 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1943 [ $OST0_QUOTA_USED -ne 0 ] &&
1944 ($SHOW_QUOTA_USER; \
1945 quota_error u $TSTUSR "quota isn't released")
1947 resetquota -u $TSTUSR
1951 [ $(facet_fstype ost1) == "zfs" ] &&
1952 skip "Overwrite in place is not guaranteed to be " \
1953 "space neutral on ZFS" && return
1955 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1956 check_whether_skip && return 0
1957 log "run for 4MB test file"
1960 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1961 check_whether_skip && return 0
1962 log "run for 40MB test file"
1965 run_test 23 "Quota should be honored with directIO (b16125)"
1969 local TESTFILE="$DIR/$tdir/$tfile"
1971 setup_quota_test || error "setup quota failed with $?"
1972 trap cleanup_quota_test EXIT
1974 set_ost_qtype "ug" || error "enable ost quota failed"
1976 # bind file to a single OST
1977 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1978 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1980 echo "Set user quota (limit: ${blimit}M)"
1981 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1982 error "set quota failed"
1984 # overrun quota by root user
1985 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1986 error "write failure, expect success"
1987 cancel_lru_locks osc
1988 sync_all_data || true
1990 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1993 resetquota -u $TSTUSR
1995 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1997 test_27a() { # b19612
1998 $LFS quota $TSTUSR $DIR &&
1999 error "lfs succeeded with no type, but should have failed"
2000 $LFS setquota $TSTUSR $DIR &&
2001 error "lfs succeeded with no type, but should have failed"
2004 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2006 test_27b() { # b20200
2007 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2008 error "lfs setquota failed with uid argument"
2009 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2010 error "lfs stequota failed with gid argument"
2011 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2012 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2013 resetquota -u $TSTUSR
2014 resetquota -g $TSTUSR
2017 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2022 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2023 error "lfs setquota failed"
2025 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2026 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2027 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2028 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2030 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2031 error "lfs setquota for $TSTID failed"
2033 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2034 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2035 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2036 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2038 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2039 error "total allocated inode/block limit not printed"
2041 resetquota -u $TSTUSR
2043 run_test 27c "lfs quota should support human-readable output"
2050 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2051 error "set fraction block limit failed"
2052 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2053 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2054 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2055 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2057 resetquota -u $TSTUSR
2059 run_test 27d "lfs setquota should support fraction block limit"
2063 local TESTFILE="$DIR/$tdir/$tfile"
2066 setup_quota_test || error "setup quota failed with $?"
2067 trap cleanup_quota_test EXIT
2069 set_ost_qtype "u" || error "enable ost quota failed"
2071 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2072 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2074 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2075 $MAX_IQ_TIME $DIR || error "set grace time failed"
2076 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2077 error "set quota failed"
2078 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2079 cancel_lru_locks osc
2081 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2082 # over-quota flag has not yet settled since we do not trigger async
2083 # events based on grace time period expiration
2085 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2086 cancel_lru_locks osc
2087 # now over-quota flag should be settled and further writes should fail
2089 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2090 error "grace times were reset"
2093 resetquota -u $TSTUSR
2094 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2095 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2097 run_test 30 "Hard limit updates should not reset grace times"
2099 # basic usage tracking for user & group
2101 local INODES=10 # 10 files
2102 local BLK_CNT=2 # of 2M each
2103 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2105 setup_quota_test || error "setup quota failed with $?"
2106 trap cleanup_quota_test EXIT
2108 # make sure the system is clean
2109 local USED=$(getquota -u $TSTID global curspace)
2111 error "Used space ($USED) for user $TSTID isn't 0."
2112 USED=$(getquota -g $TSTID global curspace)
2114 error "Used space ($USED) for group $TSTID isn't 0."
2116 echo "Write files..."
2117 for i in $(seq 0 $INODES); do
2118 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2119 error "write failed"
2120 echo "Iteration $i/$INODES completed"
2122 cancel_lru_locks osc
2123 sync; sync_all_data || true
2125 echo "Verify disk usage after write"
2126 USED=$(getquota -u $TSTID global curspace)
2127 [ $USED -lt $TOTAL_BLKS ] &&
2128 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2129 USED=$(getquota -g $TSTID global curspace)
2130 [ $USED -lt $TOTAL_BLKS ] &&
2131 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2133 echo "Verify inode usage after write"
2134 USED=$(getquota -u $TSTID global curinodes)
2135 [ $USED -lt $INODES ] &&
2136 error "Used inode for user $TSTID is $USED, expected $INODES"
2137 USED=$(getquota -g $TSTID global curinodes)
2138 [ $USED -lt $INODES ] &&
2139 error "Used inode for group $TSTID is $USED, expected $INODES"
2143 echo "Verify disk usage after delete"
2144 USED=$(getquota -u $TSTID global curspace)
2145 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2146 USED=$(getquota -u $TSTID global curinodes)
2147 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2148 USED=$(getquota -g $TSTID global curspace)
2149 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2150 USED=$(getquota -g $TSTID global curinodes)
2151 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2153 run_test 33 "Basic usage tracking for user & group"
2155 # usage transfer test for user & group
2157 local BLK_CNT=2 # 2MB
2159 setup_quota_test || error "setup quota failed with $?"
2160 trap cleanup_quota_test EXIT
2162 # make sure the system is clean
2163 local USED=$(getquota -u $TSTID global curspace)
2164 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2165 USED=$(getquota -g $TSTID global curspace)
2166 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2168 local USED=$(getquota -u $TSTID2 global curspace)
2169 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2171 echo "Write file..."
2172 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2173 error "write failed"
2174 cancel_lru_locks osc
2175 sync; sync_all_data || true
2177 echo "chown the file to user $TSTID"
2178 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2180 echo "Wait for setattr on objects finished..."
2181 wait_delete_completed
2183 BLK_CNT=$((BLK_CNT * 1024))
2185 echo "Verify disk usage for user $TSTID"
2186 USED=$(getquota -u $TSTID global curspace)
2187 [ $USED -lt $BLK_CNT ] &&
2188 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2189 USED=$(getquota -u $TSTID global curinodes)
2191 error "Used inodes for user $TSTID is $USED, expected 1"
2193 echo "chgrp the file to group $TSTID"
2194 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2196 echo "Wait for setattr on objects finished..."
2197 wait_delete_completed
2199 echo "Verify disk usage for group $TSTID"
2200 USED=$(getquota -g $TSTID global curspace)
2201 [ $USED -ge $BLK_CNT ] ||
2202 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2203 USED=$(getquota -g $TSTID global curinodes)
2205 error "Used inodes for group $TSTID is $USED, expected 1"
2207 # chown won't change the ost object group. LU-4345 */
2208 echo "chown the file to user $TSTID2"
2209 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2211 echo "Wait for setattr on objects finished..."
2212 wait_delete_completed
2214 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2215 USED=$(getquota -u $TSTID2 global curspace)
2216 [ $USED -lt $BLK_CNT ] &&
2217 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2218 USED=$(getquota -u $TSTID global curspace)
2220 error "Used space for user $TSTID is $USED, expected 0"
2221 USED=$(getquota -g $TSTID global curspace)
2222 [ $USED -lt $BLK_CNT ] &&
2223 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2227 run_test 34 "Usage transfer for user & group"
2229 # usage is still accessible across restart
2231 local BLK_CNT=2 # 2 MB
2233 setup_quota_test || error "setup quota failed with $?"
2234 trap cleanup_quota_test EXIT
2236 echo "Write file..."
2237 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2238 error "write failed"
2239 cancel_lru_locks osc
2240 sync; sync_all_data || true
2242 echo "Save disk usage before restart"
2243 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2244 [ $ORIG_USR_SPACE -eq 0 ] &&
2245 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2246 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2247 [ $ORIG_USR_INODES -eq 0 ] &&
2248 error "Used inodes for user $TSTID is 0, expected 1"
2249 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2250 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2251 [ $ORIG_GRP_SPACE -eq 0 ] &&
2252 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2253 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2254 [ $ORIG_GRP_INODES -eq 0 ] &&
2255 error "Used inodes for group $TSTID is 0, expected 1"
2256 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2259 local ORIG_REFORMAT=$REFORMAT
2261 cleanup_and_setup_lustre
2262 REFORMAT=$ORIG_REFORMAT
2265 echo "Verify disk usage after restart"
2266 local USED=$(getquota -u $TSTID global curspace)
2267 [ $USED -eq $ORIG_USR_SPACE ] ||
2268 error "Used space for user $TSTID changed from " \
2269 "$ORIG_USR_SPACE to $USED"
2270 USED=$(getquota -u $TSTID global curinodes)
2271 [ $USED -eq $ORIG_USR_INODES ] ||
2272 error "Used inodes for user $TSTID changed from " \
2273 "$ORIG_USR_INODES to $USED"
2274 USED=$(getquota -g $TSTID global curspace)
2275 [ $USED -eq $ORIG_GRP_SPACE ] ||
2276 error "Used space for group $TSTID changed from " \
2277 "$ORIG_GRP_SPACE to $USED"
2278 USED=$(getquota -g $TSTID global curinodes)
2279 [ $USED -eq $ORIG_GRP_INODES ] ||
2280 error "Used inodes for group $TSTID changed from " \
2281 "$ORIG_GRP_INODES to $USED"
2283 # check if the vfs_dq_init() is called before writing
2284 echo "Append to the same file..."
2285 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2286 error "write failed"
2287 cancel_lru_locks osc
2288 sync; sync_all_data || true
2290 echo "Verify space usage is increased"
2291 USED=$(getquota -u $TSTID global curspace)
2292 [ $USED -gt $ORIG_USR_SPACE ] ||
2293 error "Used space for user $TSTID isn't increased" \
2294 "orig:$ORIG_USR_SPACE, now:$USED"
2295 USED=$(getquota -g $TSTID global curspace)
2296 [ $USED -gt $ORIG_GRP_SPACE ] ||
2297 error "Used space for group $TSTID isn't increased" \
2298 "orig:$ORIG_GRP_SPACE, now:$USED"
2302 run_test 35 "Usage is still accessible across reboot"
2304 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2307 setup_quota_test || error "setup quota failed with $?"
2308 trap cleanup_quota_test EXIT
2310 # make sure the system is clean
2311 local USED=$(getquota -u $TSTID global curspace)
2313 error "Used space ($USED) for user $TSTID isn't 0."
2315 # create file with MDS_OPEN_DELAY_CREATE flag
2316 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2317 error "Create file failed"
2319 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2320 oflag=sync || error "Write file failed"
2322 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2324 # wait for setattr on objects finished..."
2325 wait_delete_completed
2327 USED=$(getquota -u $TSTID global curspace)
2328 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2332 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2336 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2342 check_and_cleanup_lustre
2343 export QUOTA_AUTO=$QUOTA_AUTO_OLD