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 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
72 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
73 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
74 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
75 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
76 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
83 local fail_val=${3:-0}
87 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
88 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
89 ost) NODES="$(comma_list $(osts_nodes))";;
92 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
95 RUNAS="runas -u $TSTID -g $TSTID"
96 RUNAS2="runas -u $TSTID2 -g $TSTID2"
97 DD="dd if=/dev/zero bs=1M"
101 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
102 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
103 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
104 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
106 # clear quota limits for a user or a group
107 # usage: resetquota -u username
108 # resetquota -g groupname
111 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
112 [ "$1" != "-u" -a "$1" != "-g" ] &&
113 error "resetquota: wrong specifier $1 passed"
115 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
116 error "clear quota for [type:$1 name:$2] failed"
117 # give a chance to slave to release space
125 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
126 $LFS quota -v -u $LOCAL_ID $DIR
127 log "Files for user ($LOCAL_ID):"
128 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
129 xargs stat 2>/dev/null)
132 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
133 $LFS quota -v -g $LOCAL_ID $DIR
134 log "Files for group ($LOCAL_ID):"
135 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
136 xargs stat 2>/dev/null)
152 # get quota for a user or a group
153 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
154 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
159 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
160 [ "$1" != "-u" -a "$1" != "-g" ] &&
161 error "getquota: wrong u/g specifier $1 passed"
174 *) error "unknown quota parameter $4";;
177 [ "$uuid" = "global" ] && uuid=$DIR
179 $LFS quota -v "$1" "$2" $DIR |
180 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
181 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
186 # usage: set_mdt_qtype ug|u|g|none
190 local mdts=$(get_facets MDS)
192 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
193 # we have to make sure each MDT received config changes
194 for mdt in ${mdts//,/ }; do
196 cmd="$LCTL get_param -n "
197 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
198 cmd=${cmd}.quota_slave.enabled
200 if $(facet_up $mdt); then
201 wait_update_facet $mdt "$cmd" "$qtype" || return 1
208 # usage: set_ost_qtype ug|u|g|none
212 local osts=$(get_facets OST)
214 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
215 # we have to make sure each OST received config changes
216 for ost in ${osts//,/ }; do
218 cmd="$LCTL get_param -n "
219 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
220 cmd=${cmd}.quota_slave.enabled
222 if $(facet_up $ost); then
223 wait_update_facet $ost "$cmd" "$qtype" || return 1
229 wait_reintegration() {
233 local result="glb[1],slv[1],reint[0]"
238 if [ $ntype == "mdt" ]; then
239 tgts=$(get_facets MDS)
241 tgts=$(get_facets OST)
244 for tgt in ${tgts//,/ }; do
246 cmd="$LCTL get_param -n "
247 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
248 cmd=${cmd}.quota_slave.info
250 if $(facet_up $tgt); then
251 wait_update_facet $tgt "$cmd |
252 grep "$qtype" | awk '{ print \\\$3 }'" \
253 "$result" $max || return 1
263 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
264 wait_reintegration "mdt" "user" $max || return 1
267 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
268 wait_reintegration "mdt" "group" $max || return 1
277 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
278 wait_reintegration "ost" "user" $max || return 1
281 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
282 wait_reintegration "ost" "group" $max || return 1
288 wait_delete_completed
289 echo "Creating test directory"
290 mkdir $DIR/$tdir || return 1
291 chmod 0777 $DIR/$tdir || return 2
292 # always clear fail_loc in case of fail_loc isn't cleared
293 # properly when previous test failed
294 lustre_fail mds_ost 0
297 cleanup_quota_test() {
299 echo "Delete files..."
301 echo "Wait for unlink objects finished..."
302 wait_delete_completed
303 sync_all_data || true
312 $LFS quota -v -$ug $qid $DIR
314 if [ "$bf" == "a" -o "$bf" == "b" ]; then
315 usage=$(getquota -$ug $qid global curspace)
316 if [ -z $usage ]; then
317 quota_error $ug $qid \
318 "Query block quota failed ($ug:$qid)."
320 [ $usage -ne 0 ] && quota_log $ug $qid \
321 "Block quota isn't 0 ($ug:$qid:$usage)."
325 if [ "$bf" == "a" -o "$bf" == "f" ]; then
326 usage=$(getquota -$ug $qid global curinodes)
327 if [ -z $usage ]; then
328 quota_error $ug $qid \
329 "Query file quota failed ($ug:$qid)."
331 [ $usage -ne 0 ] && quota_log $ug $qid \
332 "File quota isn't 0 ($ug:$qid:$usage)."
339 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
343 resetquota -u $TSTUSR
344 resetquota -g $TSTUSR
345 resetquota -u $TSTUSR2
346 resetquota -g $TSTUSR2
348 test_quota_performance() {
349 local TESTFILE="$DIR/$tdir/$tfile-0"
350 local size=$1 # in MB
351 local stime=$(date +%s)
352 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
353 quota_error u $TSTUSR "write failure"
354 local etime=$(date +%s)
355 delta=$((etime - stime))
356 if [ $delta -gt 0 ]; then
357 rate=$((size * 1024 / delta))
358 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
359 # LU-2872 - see LU-2887 for fix
361 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
363 [ $rate -gt 1024 ] ||
364 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
370 # test basic quota performance b=21696
373 [ "$SLOW" = "no" ] && MB=10
375 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
376 [ $free_space -le $((MB * 1024)) ] &&
377 skip "not enough space ${free_space} KB, " \
378 "required $((MB * 1024)) KB" && return
379 setup_quota_test || error "setup quota failed with $?"
380 trap cleanup_quota_test EXIT
382 set_ost_qtype "none" || error "disable ost quota failed"
383 test_quota_performance $MB
385 set_ost_qtype "ug" || error "enable ost quota failed"
386 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
387 error "set quota failed"
388 test_quota_performance $MB
391 resetquota -u $TSTUSR
393 run_test 0 "Test basic quota performance"
395 # test block hardlimit
398 local TESTFILE="$DIR/$tdir/$tfile-0"
400 setup_quota_test || error "setup quota failed with $?"
401 trap cleanup_quota_test EXIT
404 set_ost_qtype "ug" || "enable ost quota failed"
407 log "User quota (block hardlimit:$LIMIT MB)"
408 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
409 error "set user quota failed"
411 # make sure the system is clean
412 local USED=$(getquota -u $TSTUSR global curspace)
413 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
415 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
416 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
419 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
420 quota_error u $TSTUSR "user write failure, but expect success"
421 log "Write out of block quota ..."
422 # this time maybe cache write, ignore it's failure
423 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
424 # flush cache, ensure noquota flag is set on client
426 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
427 quota_error u $TSTUSR "user write success, but expect EDQUOT"
430 wait_delete_completed || error "wait_delete_completed failed"
431 sync_all_data || true
432 USED=$(getquota -u $TSTUSR global curspace)
433 [ $USED -ne 0 ] && quota_error u $TSTUSR \
434 "user quota isn't released after deletion"
435 resetquota -u $TSTUSR
438 log "--------------------------------------"
439 log "Group quota (block hardlimit:$LIMIT MB)"
440 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
441 error "set group quota failed"
443 TESTFILE="$DIR/$tdir/$tfile-1"
444 # make sure the system is clean
445 USED=$(getquota -g $TSTUSR global curspace)
446 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
448 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
449 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
452 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
453 quota_error g $TSTUSR "group write failure, but expect success"
454 log "Write out of block quota ..."
455 # this time maybe cache write, ignore it's failure
456 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
458 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
459 quota_error g $TSTUSR "group write success, but expect EDQUOT"
464 USED=$(getquota -g $TSTUSR global curspace)
465 [ $USED -ne 0 ] && quota_error g $TSTUSR \
466 "group quota isn't released after deletion"
468 resetquota -g $TSTUSR
470 run_test 1 "Block hard limit (normal use and out of quota)"
472 # test inode hardlimit
474 local LIMIT=$((1024 * 1024)) # 1M inodes
475 local TESTFILE="$DIR/$tdir/$tfile-0"
477 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
479 local FREE_INODES=$(mdt_free_inodes 0)
480 echo "$FREE_INODES free inodes on master MDT"
481 [ $FREE_INODES -lt $LIMIT ] &&
482 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
485 setup_quota_test || error "setup quota failed with $?"
486 trap cleanup_quota_test EXIT
489 set_mdt_qtype "ug" || "enable mdt quota failed"
492 log "User quota (inode hardlimit:$LIMIT files)"
493 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
494 error "set user quota failed"
496 # make sure the system is clean
497 local USED=$(getquota -u $TSTUSR global curinodes)
498 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
500 log "Create $LIMIT files ..."
501 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
502 quota_error u $TSTUSR "user create failure, but expect success"
503 log "Create out of file quota ..."
504 $RUNAS touch ${TESTFILE}_xxx &&
505 quota_error u $TSTUSR "user create success, but expect EDQUOT"
508 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
509 rm -f ${TESTFILE}_xxx
510 wait_delete_completed
512 USED=$(getquota -u $TSTUSR global curinodes)
513 [ $USED -ne 0 ] && quota_error u $TSTUSR \
514 "user quota isn't released after deletion"
515 resetquota -u $TSTUSR
518 log "--------------------------------------"
519 log "Group quota (inode hardlimit:$LIMIT files)"
520 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
521 error "set group quota failed"
523 TESTFILE=$DIR/$tdir/$tfile-1
524 # make sure the system is clean
525 USED=$(getquota -g $TSTUSR global curinodes)
526 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
528 log "Create $LIMIT files ..."
529 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
530 quota_error g $TSTUSR "group create failure, but expect success"
531 log "Create out of file quota ..."
532 $RUNAS touch ${TESTFILE}_xxx &&
533 quota_error g $TSTUSR "group create success, but expect EDQUOT"
536 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
537 rm -f ${TESTFILE}_xxx
538 wait_delete_completed
540 USED=$(getquota -g $TSTUSR global curinodes)
541 [ $USED -ne 0 ] && quota_error g $TSTUSR \
542 "user quota isn't released after deletion"
545 resetquota -g $TSTUSR
547 run_test 2 "File hard limit (normal use and out of quota)"
551 local TIMER=$(($2 * 3 / 2))
556 trap cleanup_quota_test EXIT
558 $SETSTRIPE $TESTFILE -c 1 -i 0
559 chown $TSTUSR.$TSTUSR $TESTFILE
561 echo "Write up to soft limit"
562 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
563 quota_error a $TSTUSR "write failure, but expect success"
564 OFFSET=$((LIMIT * 1024))
567 echo "Write to exceed soft limit"
568 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
569 quota_error a $TSTUSR "write failure, but expect success"
570 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
575 $SHOW_QUOTA_INFO_USER
576 $SHOW_QUOTA_INFO_GROUP
578 echo "Write before timer goes off"
579 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
580 quota_error a $TSTUSR "write failure, but expect success"
581 OFFSET=$((OFFSET + 1024))
584 echo "Sleep $TIMER seconds ..."
589 $SHOW_QUOTA_INFO_USER
590 $SHOW_QUOTA_INFO_GROUP
592 echo "Write after timer goes off"
593 # maybe cache write, ignore.
594 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
595 OFFSET=$((OFFSET + 1024))
597 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
598 quota_error a $TSTUSR "write success, but expect EDQUOT"
602 $SHOW_QUOTA_INFO_USER
603 $SHOW_QUOTA_INFO_GROUP
605 echo "Unlink file to stop timer"
607 wait_delete_completed
608 sync_all_data || true
612 $SHOW_QUOTA_INFO_USER
613 $SHOW_QUOTA_INFO_GROUP
615 $SETSTRIPE $TESTFILE -c 1 -i 0
616 chown $TSTUSR.$TSTUSR $TESTFILE
619 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
620 quota_error a $TSTUSR "write failure, but expect success"
629 local TESTFILE=$DIR/$tdir/$tfile-0
631 set_ost_qtype "ug" || error "enable ost quota failed"
633 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
634 # make sure the system is clean
635 local USED=$(getquota -u $TSTUSR global curspace)
636 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
638 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
639 $MAX_IQ_TIME $DIR || error "set user grace time failed"
640 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
641 error "set user quota failed"
643 test_block_soft $TESTFILE $GRACE $LIMIT
644 resetquota -u $TSTUSR
646 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
647 TESTFILE=$DIR/$tdir/$tfile-1
648 # make sure the system is clean
649 USED=$(getquota -g $TSTUSR global curspace)
650 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
652 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
653 $MAX_IQ_TIME $DIR || error "set group grace time failed"
654 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
655 error "set group quota failed"
657 test_block_soft $TESTFILE $GRACE $LIMIT
658 resetquota -g $TSTUSR
661 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
662 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
663 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
664 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
666 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
672 local TIMER=$(($grace * 3 / 2))
675 trap cleanup_quota_test EXIT
677 echo "Create files to exceed soft limit"
678 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
679 quota_error a $TSTUSR "create failure, but expect success"
680 local trigger_time=$(date +%s)
682 sync_all_data || true
684 local cur_time=$(date +%s)
685 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
686 error "Passed grace time $grace, $trigger_time, $cur_time"
688 echo "Create file before timer goes off"
689 $RUNAS touch ${TESTFILE}_before ||
690 quota_error a $TSTUSR "failed create before timer expired," \
691 "but expect success. $trigger_time, $cur_time"
692 sync_all_data || true
694 echo "Sleep $TIMER seconds ..."
699 $SHOW_QUOTA_INFO_USER
700 $SHOW_QUOTA_INFO_GROUP
702 echo "Create file after timer goes off"
703 # There is a window that space is accounted in the quota usage but
704 # hasn't been decreased from the pending write, if we acquire quota
705 # in this window, we'll acquire more than we needed.
706 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
707 sync_all_data || true
708 $RUNAS touch ${TESTFILE}_after_3 &&
709 quota_error a $TSTUSR "create after timer expired," \
711 sync_all_data || true
715 $SHOW_QUOTA_INFO_USER
716 $SHOW_QUOTA_INFO_GROUP
718 echo "Unlink files to stop timer"
719 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
720 wait_delete_completed
723 $RUNAS touch ${TESTFILE}_xxx ||
724 quota_error a $TSTUSR "touch after timer stop failure," \
726 sync_all_data || true
734 local LIMIT=10 # inodes
735 local TESTFILE=$DIR/$tdir/$tfile-0
738 set_mdt_qtype "ug" || error "enable mdt quota failed"
740 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
741 # make sure the system is clean
742 local USED=$(getquota -u $TSTUSR global curinodes)
743 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
745 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
746 $GRACE $DIR || error "set user grace time failed"
747 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
748 error "set user quota failed"
750 test_file_soft $TESTFILE $LIMIT $GRACE
751 resetquota -u $TSTUSR
753 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
754 # make sure the system is clean
755 USED=$(getquota -g $TSTUSR global curinodes)
756 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
758 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
759 $GRACE $DIR || error "set group grace time failed"
760 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
761 error "set group quota failed"
762 TESTFILE=$DIR/$tdir/$tfile-1
764 test_file_soft $TESTFILE $LIMIT $GRACE
765 resetquota -g $TSTUSR
768 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
769 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
770 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
771 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
773 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
777 local GR_STR2="1000s"
779 local GR_STR4="1w2d3h4m5s"
781 local GR_STR6="18446744073709551615"
784 wait_delete_completed
786 # test of valid grace strings handling
787 echo "Valid grace strings test"
788 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
789 $GR_STR2 $DIR || error "set user grace time failed"
790 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
791 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
792 $GR_STR4 $DIR || error "set group grace time quota failed"
793 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
795 # test of invalid grace strings handling
796 echo " Invalid grace strings test"
797 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
798 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
799 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
803 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
804 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
805 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
806 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
808 run_test 4b "Grace time strings handling"
810 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
812 local BLIMIT=10 # 10M
813 local ILIMIT=10 # 10 inodes
815 setup_quota_test || error "setup quota failed with $?"
816 trap cleanup_quota_test EXIT
818 set_mdt_qtype "ug" || error "enable mdt quota failed"
819 set_ost_qtype "ug" || error "enable ost quota failed"
821 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
822 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
823 error "set user quota failed"
824 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
825 error "set group quota failed"
827 # make sure the system is clean
828 local USED=$(getquota -u $TSTUSR global curinodes)
829 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
830 USED=$(getquota -g $TSTUSR global curinodes)
831 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
832 USED=$(getquota -u $TSTUSR global curspace)
833 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
834 USED=$(getquota -g $TSTUSR global curspace)
835 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
837 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
838 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
839 error "create failure, expect success"
840 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
841 error "write failure, expect success"
843 echo "Chown files to $TSTUSR.$TSTUSR ..."
844 for i in $(seq 0 $ILIMIT); do
845 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
846 quota_error a $TSTUSR "chown failure, expect success"
850 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
851 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
854 resetquota -u $TSTUSR
855 resetquota -g $TSTUSR
857 run_test 5 "Chown & chgrp successfully even out of block/file quota"
859 # test dropping acquire request on master
863 # Clear dmesg so watchdog is not triggered by previous
865 do_facet ost1 dmesg -c > /dev/null
867 setup_quota_test || error "setup quota failed with $?"
868 trap cleanup_quota_test EXIT
870 # make sure the system is clean
871 local USED=$(getquota -u $TSTUSR global curspace)
872 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
874 # make sure no granted quota on ost
875 set_ost_qtype "ug" || error "enable ost quota failed"
876 resetquota -u $TSTUSR
878 # create file for $TSTUSR
879 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
880 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
881 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
883 # create file for $TSTUSR2
884 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
885 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
886 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
888 # cache per-ID lock for $TSTUSR on slave
889 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
890 error "set quota failed"
891 $RUNAS $DD of=$TESTFILE count=1 ||
892 error "write $TESTFILE failure, expect success"
893 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
894 error "write $TESTFILE2 failure, expect success"
896 sync_all_data || true
898 #define QUOTA_DQACQ 601
899 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
900 lustre_fail mds 0x513 601
902 # write to un-enforced ID ($TSTUSR2) should succeed
903 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
904 error "write failure, expect success"
906 # write to enforced ID ($TSTUSR) in background, exceeding limit
907 # to make sure DQACQ is sent
908 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
911 # watchdog timer uses a factor of 2
912 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
913 sleep $((TIMEOUT * 2 + 1))
915 # write should be blocked and never finished
916 if ! ps -p $DDPID > /dev/null 2>&1; then
918 error "write finished incorrectly!"
923 # no watchdog is triggered
924 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
925 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
926 { print; }' $TMP/lustre-log-${TESTNAME}.log)
927 [ -z "$watchdog" ] || error "$watchdog"
929 rm -f $TMP/lustre-log-${TESTNAME}.log
931 # write should continue then fail with EDQUOT
935 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
936 if [ $count -ge 240 ]; then
937 quota_error u $TSTUSR "dd not finished in $count secs"
940 if [ $((count % 30)) -eq 0 ]; then
941 c_size=$(stat -c %s $TESTFILE)
942 echo "Waiting $count secs. $c_size"
949 resetquota -u $TSTUSR
951 run_test 6 "Test dropping acquire request on master"
953 # quota reintegration (global index)
955 local TESTFILE=$DIR/$tdir/$tfile
958 [ "$SLOW" = "no" ] && LIMIT=5
960 setup_quota_test || error "setup quota failed with $?"
961 trap cleanup_quota_test EXIT
963 # make sure the system is clean
964 local USED=$(getquota -u $TSTUSR global curspace)
965 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
967 # make sure no granted quota on ost1
968 set_ost_qtype "ug" || error "enable ost quota failed"
969 resetquota -u $TSTUSR
970 set_ost_qtype "none" || error "disable ost quota failed"
972 local OSTUUID=$(ostuuid_from_index 0)
973 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
975 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
978 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
979 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
984 echo "Enable quota & set quota limit for $TSTUSR"
985 set_ost_qtype "ug" || error "enable ost quota failed"
986 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
987 error "set quota failed"
990 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
993 wait_ost_reint "ug" || error "reintegration failed"
995 # hardlimit should have been fetched by slave during global
996 # reintegration, write will exceed quota
997 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
998 quota_error u $TSTUSR "write success, but expect EDQUOT"
1001 wait_delete_completed
1002 sync_all_data || true
1008 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1009 error "clear quota failed"
1011 echo "Start ost1..."
1012 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1015 wait_ost_reint "ug" || error "reintegration failed"
1017 # hardlimit should be cleared on slave during reintegration
1018 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1019 quota_error u $TSTUSR "write error, but expect success"
1022 resetquota -u $TSTUSR
1024 run_test 7a "Quota reintegration (global index)"
1026 # quota reintegration (slave index)
1029 local TESTFILE=$DIR/$tdir/$tfile
1031 setup_quota_test || error "setup quota failed with $?"
1032 trap cleanup_quota_test EXIT
1034 # make sure the system is clean
1035 local USED=$(getquota -u $TSTUSR global curspace)
1036 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1038 # make sure no granted quota on ost1
1039 set_ost_qtype "ug" || error "enable ost quota failed"
1040 resetquota -u $TSTUSR
1041 set_ost_qtype "none" || error "disable ost quota failed"
1043 local OSTUUID=$(ostuuid_from_index 0)
1044 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1046 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1049 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1050 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1052 # consume some space to make sure the granted space will not
1053 # be released during reconciliation
1054 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1055 error "consume space failure, expect success"
1057 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1058 lustre_fail mds 0xa02
1060 set_ost_qtype "ug" || error "enable ost quota failed"
1061 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1062 error "set quota failed"
1064 # ignore the write error
1065 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1067 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1071 echo "Restart ost to trigger reintegration..."
1073 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1076 wait_ost_reint "ug" || error "reintegration failed"
1078 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1079 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1082 resetquota -u $TSTUSR
1085 run_test 7b "Quota reintegration (slave index)"
1087 # quota reintegration (restart mds during reintegration)
1089 local LIMIT=20 # 20M
1090 local TESTFILE=$DIR/$tdir/$tfile
1092 [ "$SLOW" = "no" ] && LIMIT=5
1094 setup_quota_test || error "setup quota failed with $?"
1095 trap cleanup_quota_test EXIT
1097 # make sure the system is clean
1098 local USED=$(getquota -u $TSTUSR global curspace)
1099 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1101 set_ost_qtype "none" || error "disable ost quota failed"
1102 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1103 error "set quota failed"
1105 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1106 lustre_fail ost 0xa03
1109 set_ost_qtype "ug" || error "enable ost quota failed"
1110 # trigger reintegration
1111 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1112 procf=${procf}quota_slave.force_reint
1113 do_facet ost1 $LCTL set_param $procf=1 ||
1114 error "force reintegration failed"
1122 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1125 # wait longer than usual to make sure the reintegration
1126 # is triggered by quota wb thread.
1127 wait_ost_reint "ug" 200 || error "reintegration failed"
1129 # hardlimit should have been fetched by slave during global
1130 # reintegration, write will exceed quota
1131 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1132 quota_error u $TSTUSR "write success, but expect EDQUOT"
1135 resetquota -u $TSTUSR
1137 run_test 7c "Quota reintegration (restart mds during reintegration)"
1139 # Quota reintegration (Transfer index in multiple bulks)
1141 local TESTFILE=$DIR/$tdir/$tfile
1142 local TESTFILE1="$DIR/$tdir/$tfile"-1
1145 setup_quota_test || error "setup quota failed with $?"
1146 trap cleanup_quota_test EXIT
1148 set_ost_qtype "none" || error "disable ost quota failed"
1149 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1150 error "set quota for $TSTUSR failed"
1151 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1152 error "set quota for $TSTUSR2 failed"
1154 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1155 lustre_fail mds 0x608 0
1157 # enable quota to tirgger reintegration
1158 set_ost_qtype "u" || error "enable ost quota failed"
1159 wait_ost_reint "u" || error "reintegration failed"
1163 # hardlimit should have been fetched by slave during global
1164 # reintegration, write will exceed quota
1165 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1166 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1168 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1169 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1172 resetquota -u $TSTUSR
1173 resetquota -u $TSTUSR2
1175 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1177 # quota reintegration (inode limits)
1179 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1181 local ilimit=$((1024 * 2)) # 2k inodes
1182 local TESTFILE=$DIR/${tdir}-1/$tfile
1184 setup_quota_test || error "setup quota failed with $?"
1185 trap cleanup_quota_test EXIT
1187 # make sure the system is clean
1188 local USED=$(getquota -u $TSTUSR global curinodes)
1189 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1191 # make sure no granted quota on mdt1
1192 set_mdt_qtype "ug" || error "enable mdt quota failed"
1193 resetquota -u $TSTUSR
1194 set_mdt_qtype "none" || error "disable mdt quota failed"
1196 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1197 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1198 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1201 echo "Stop mds${MDSCOUNT}..."
1204 echo "Enable quota & set quota limit for $TSTUSR"
1205 set_mdt_qtype "ug" || error "enable mdt quota failed"
1206 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1207 error "set quota failed"
1209 echo "Start mds${MDSCOUNT}..."
1210 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1213 wait_mdt_reint "ug" || error "reintegration failed"
1215 echo "create remote dir"
1216 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1217 error "create remote dir failed"
1218 chmod 0777 $DIR/${tdir}-1
1220 # hardlimit should have been fetched by slave during global
1221 # reintegration, create will exceed quota
1222 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1223 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1225 $RUNAS unlinkmany $TESTFILE $ilimit || "unlink files failed"
1226 wait_delete_completed
1227 sync_all_data || true
1229 echo "Stop mds${MDSCOUNT}..."
1232 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1233 error "clear quota failed"
1235 echo "Start mds${MDSCOUNT}..."
1236 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1239 wait_mdt_reint "ug" || error "reintegration failed"
1241 # hardlimit should be cleared on slave during reintegration
1242 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1243 quota_error -u $TSTUSR "create failed, expect success"
1245 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || "unlink failed"
1246 rmdir $DIR/${tdir}-1 || "unlink remote dir failed"
1249 resetquota -u $TSTUSR
1251 run_test 7e "Quota reintegration (inode limits)"
1253 # run dbench with quota enabled
1255 local BLK_LIMIT="100g" #100G
1256 local FILE_LIMIT=1000000
1258 setup_quota_test || error "setup quota failed with $?"
1259 trap cleanup_quota_test EXIT
1261 set_mdt_qtype "ug" || error "enable mdt quota failed"
1262 set_ost_qtype "ug" || error "enable ost quota failed"
1264 echo "Set enough high limit for user: $TSTUSR"
1265 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1266 error "set user quota failed"
1267 echo "Set enough high limit for group: $TSTUSR"
1268 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1269 error "set group quota failed"
1272 [ "$SLOW" = "no" ] && duration=" -t 120"
1273 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1274 quota_error a $TSTUSR "dbench failed!"
1277 resetquota -u $TSTUSR
1278 resetquota -g $TSTUSR
1280 run_test 8 "Run dbench with quota enabled"
1282 # this check is just for test_9
1283 OST0_MIN=4900000 #4.67G
1285 check_whether_skip () {
1286 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1287 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1288 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1289 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1296 # run for fixing bug10707, it needs a big room. test for 64bit
1298 local filesize=$((1024 * 9 / 2)) # 4.5G
1300 check_whether_skip && return 0
1302 setup_quota_test || error "setup quota failed with $?"
1303 trap cleanup_quota_test EXIT
1305 set_ost_qtype "ug" || error "enable ost quota failed"
1307 local TESTFILE="$DIR/$tdir/$tfile-0"
1308 local BLK_LIMIT=100G #100G
1309 local FILE_LIMIT=1000000
1311 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1313 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1315 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1316 error "set user quota failed"
1318 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1319 "for group: $TSTUSR"
1320 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1321 error "set group quota failed"
1323 quota_show_check a u $TSTUSR
1324 quota_show_check a g $TSTUSR
1326 echo "Create test file"
1327 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1328 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1330 log "Write the big file of 4.5G ..."
1331 $RUNAS $DD of=$TESTFILE count=$filesize ||
1332 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1338 resetquota -u $TSTUSR
1339 resetquota -g $TSTUSR
1344 run_test 9 "Block limit larger than 4GB (b10707)"
1347 local TESTFILE=$DIR/$tdir/$tfile
1349 setup_quota_test || error "setup quota failed with $?"
1350 trap cleanup_quota_test EXIT
1352 # set limit to root user should fail
1353 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1354 error "set limit for root user successfully, expect failure"
1355 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1356 error "set limit for root group successfully, expect failure"
1358 # root user can overrun quota
1359 set_ost_qtype "ug" || "enable ost quota failed"
1361 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1362 error "set quota failed"
1363 quota_show_check b u $TSTUSR
1365 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1366 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1368 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1369 error "write failure, expect success"
1372 resetquota -u $TSTUSR
1374 run_test 10 "Test quota for root user"
1377 local TESTFILE=$DIR/$tdir/$tfile
1378 setup_quota_test || error "setup quota failed with $?"
1379 trap cleanup_quota_test EXIT
1381 set_mdt_qtype "ug" || "enable mdt quota failed"
1382 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1383 error "set quota failed"
1385 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1386 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1388 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1389 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1392 local USED=$(getquota -u $TSTUSR global curinodes)
1393 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1396 resetquota -u $TSTUSR
1398 run_test 11 "Chown/chgrp ignores quota"
1401 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1403 local blimit=22 # 22M
1404 local blk_cnt=$((blimit - 5))
1405 local TESTFILE0="$DIR/$tdir/$tfile"-0
1406 local TESTFILE1="$DIR/$tdir/$tfile"-1
1408 setup_quota_test || error "setup quota failed with $?"
1409 trap cleanup_quota_test EXIT
1411 set_ost_qtype "u" || "enable ost quota failed"
1412 quota_show_check b u $TSTUSR
1414 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1415 error "set quota failed"
1417 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1418 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1419 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1420 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1422 echo "Write to ost0..."
1423 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1424 quota_error a $TSTUSR "dd failed"
1426 echo "Write to ost1..."
1427 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1428 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1430 echo "Free space from ost0..."
1432 wait_delete_completed
1433 sync_all_data || true
1435 echo "Write to ost1 after space freed from ost0..."
1436 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1437 quota_error a $TSTUSR "rebalancing failed"
1440 resetquota -u $TSTUSR
1442 run_test 12a "Block quota rebalancing"
1445 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1447 local ilimit=$((1024 * 2)) # 2k inodes
1448 local TESTFILE0=$DIR/$tdir/$tfile
1449 local TESTFILE1=$DIR/${tdir}-1/$tfile
1451 setup_quota_test || error "setup quota failed with $?"
1452 trap cleanup_quota_test EXIT
1454 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1455 chmod 0777 $DIR/${tdir}-1
1457 set_mdt_qtype "u" || "enable mdt quota failed"
1458 quota_show_check f u $TSTUSR
1460 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1461 error "set quota failed"
1463 echo "Create $ilimit files on mdt0..."
1464 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1465 quota_error u $TSTUSR "create failed, but expect success"
1467 echo "Create files on mdt1..."
1468 $RUNAS createmany -m $TESTFILE1 1 &&
1469 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1471 echo "Free space from mdt0..."
1472 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1473 wait_delete_completed
1474 sync_all_data || true
1476 echo "Create files on mdt1 after space freed from mdt0..."
1477 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1478 quota_error a $TSTUSR "rebalancing failed"
1480 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1481 error "unlink mdt1 files failed"
1482 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1485 resetquota -u $TSTUSR
1487 run_test 12b "Inode quota rebalancing"
1490 local TESTFILE=$DIR/$tdir/$tfile
1491 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1492 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1494 setup_quota_test || error "setup quota failed with $?"
1495 trap cleanup_quota_test EXIT
1497 set_ost_qtype "u" || "enable ost quota failed"
1498 quota_show_check b u $TSTUSR
1500 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1501 error "set quota failed"
1502 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1503 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1505 # clear the locks in cache first
1506 do_facet ost1 $LCTL set_param -n $procf=clear
1507 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1508 [ $nlock -eq 0 ] || error "$nlock cached locks"
1510 # write to acquire the per-ID lock
1511 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1512 quota_error a $TSTUSR "dd failed"
1514 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1515 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1517 # clear quota doesn't trigger per-ID lock cancellation
1518 resetquota -u $TSTUSR
1519 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1520 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1522 # clear the per-ID lock
1523 do_facet ost1 $LCTL set_param -n $procf=clear
1524 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1525 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1527 # spare quota should be released
1528 local OSTUUID=$(ostuuid_from_index 0)
1529 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1530 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1531 [ $limit -le $space ] ||
1532 error "spare quota isn't released, limit:$limit, space:$space"
1536 run_test 13 "Cancel per-ID lock in the LRU list"
1539 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1541 wait_delete_completed
1542 sync_all_data || true
1545 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1546 error "set user quota failed"
1547 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1548 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1549 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1550 resetquota -u $TSTUSR
1553 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1554 error "set group quota failed"
1555 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1556 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1557 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1558 resetquota -g $TSTUSR
1560 run_test 15 "Set over 4T block quota"
1564 local BLKS=1 # 1M less than limit
1565 local TESTFILE=$DIR/$tdir/$tfile
1567 setup_quota_test || error "setup quota failed with $?"
1568 trap cleanup_quota_test EXIT
1570 # make sure the system is clean
1571 local USED=$(getquota -u $TSTUSR global curspace)
1572 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1574 set_ost_qtype "ug" || error "enable ost quota failed"
1575 # make sure no granted quota on ost
1576 resetquota -u $TSTUSR
1577 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1578 error "set quota failed"
1580 quota_show_check b u $TSTUSR
1582 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1583 lustre_fail mds 0xa04 $err_code
1585 # write in background
1586 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1590 # write should be blocked and never finished
1591 if ! ps -p $DDPID > /dev/null 2>&1; then
1593 quota_error u $TSTUSR "write finished incorrectly!"
1601 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1603 if [ $count -gt $timeout ]; then
1604 quota_error u $TSTUSR "dd is not finished!"
1609 sync; sync_all_data || true
1611 USED=$(getquota -u $TSTUSR global curspace)
1612 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1613 "Used space(${USED}K) is less than ${BLKS}M"
1616 resetquota -u $TSTUSR
1619 # DQACQ return recoverable error
1621 echo "DQACQ return -ENOLCK"
1623 test_17sub 37 || error "Handle -ENOLCK failed"
1625 echo "DQACQ return -EAGAIN"
1627 test_17sub 11 || error "Handle -EAGAIN failed"
1629 echo "DQACQ return -ETIMEDOUT"
1630 #define ETIMEDOUT 110
1631 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1633 echo "DQACQ return -ENOTCONN"
1634 #define ENOTCONN 107
1635 test_17sub 107 || error "Handle -ENOTCONN failed"
1638 run_test 17 "DQACQ return recoverable error"
1642 local blimit="200m" # 200M
1643 local TESTFILE="$DIR/$tdir/$tfile"
1645 setup_quota_test || error "setup quota failed with $?"
1646 trap cleanup_quota_test EXIT
1648 set_ost_qtype "u" || error "enable ost quota failed"
1649 log "User quota (limit: $blimit)"
1650 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1651 error "set quota failed"
1652 quota_show_check b u $TSTUSR
1654 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1655 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1657 local timeout=$(sysctl -n lustre.timeout)
1659 if [ $io_type = "directio" ]; then
1660 log "Write 100M (directio) ..."
1661 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1663 log "Write 100M (buffered) ..."
1664 $RUNAS $DD of=$TESTFILE count=100 &
1668 replay_barrier $SINGLEMDS
1669 log "Fail mds for $((2 * timeout)) seconds"
1670 fail $SINGLEMDS $((2 * timeout))
1673 if at_is_enabled; then
1674 timeout=$(at_max_get mds)
1676 timeout=$(lctl get_param -n timeout)
1680 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1681 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1682 log "it took $count second"
1687 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1689 cancel_lru_locks mdc
1690 cancel_lru_locks osc
1693 local testfile_size=$(stat -c %s $TESTFILE)
1694 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1695 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1696 "got ${testfile_size}. Verifying file failed!"
1699 resetquota -u $TSTUSR
1702 # test when mds does failover, the ost still could work well
1703 # this test shouldn't trigger watchdog b=14840
1705 # Clear dmesg so watchdog is not triggered by previous
1707 do_facet ost1 dmesg -c > /dev/null
1710 test_18_sub directio
1712 # check if watchdog is triggered
1713 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1714 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1715 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1716 [ -z "$watchdog" ] || error "$watchdog"
1717 rm -f $TMP/lustre-log-${TESTNAME}.log
1719 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1723 local TESTFILE=$DIR/$tdir/$tfile
1725 setup_quota_test || error "setup quota failed with $?"
1726 trap cleanup_quota_test EXIT
1728 set_ost_qtype "ug" || error "enable ost quota failed"
1730 # bind file to a single OST
1731 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1732 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1734 echo "Set user quota (limit: ${blimit}M)"
1735 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1736 error "set user quota failed"
1737 quota_show_check b u $TSTUSR
1738 echo "Update quota limits"
1739 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1740 error "set group quota failed"
1741 quota_show_check b u $TSTUSR
1743 # first wirte might be cached
1744 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1745 cancel_lru_locks osc
1747 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1748 quota_error u $TSTUSR "Write success, expect failure"
1752 resetquota -u $TSTUSR
1754 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1756 test_20() { # b15754
1757 local LSTR=(2g 1t 4k 3m) # limits strings
1759 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1762 resetquota -u $TSTUSR
1764 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1765 $MOUNT || error "could not set quota limits"
1766 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1767 --inode-softlimit ${LSTR[2]} \
1768 --inode-hardlimit ${LSTR[3]} \
1769 $MOUNT || error "could not set quota limits"
1771 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1772 error "bsoftlimit was not set properly"
1773 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1774 error "bhardlimit was not set properly"
1775 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1776 error "isoftlimit was not set properly"
1777 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1778 error "ihardlimit was not set properly"
1780 resetquota -u $TSTUSR
1782 run_test 20 "Test if setquota specifiers work properly (b15754)"
1789 local time=$(($(date +%s) + seconds))
1790 while [ $(date +%s) -lt $time ]; do
1791 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1795 # run for fixing bug16053, setquota shouldn't fail when writing and
1796 # deleting are happening
1798 local TESTFILE="$DIR/$tdir/$tfile"
1799 local BLIMIT=10 # 10G
1800 local ILIMIT=1000000
1802 setup_quota_test || error "setup quota failed with $?"
1803 trap cleanup_quota_test EXIT
1805 set_ost_qtype "ug" || error "Enable ost quota failed"
1807 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1808 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1809 error "set user quota failed"
1810 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1811 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1812 error "set group quota failed"
1814 # repeat writing on a 1M file
1815 test_21_sub ${TESTFILE}_1 1 30 &
1817 # repeat writing on a 128M file
1818 test_21_sub ${TESTFILE}_2 128 30 &
1821 local time=$(($(date +%s) + 30))
1823 while [ $(date +%s) -lt $time ]; do
1824 log "Set quota for $i times"
1825 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1826 -I $((ILIMIT + i)) $MOUNT ||
1827 error "Set user quota failed"
1828 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1829 -I $((ILIMIT + i)) $MOUNT ||
1830 error "Set group quota failed"
1837 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1839 if [ $count -gt 60 ]; then
1840 quota_error a $TSTUSR "dd should be finished!"
1844 echo "(dd_pid=$DDPID1, time=$count)successful"
1848 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1850 if [ $count -gt 60 ]; then
1851 quota_error a $TSTUSR "dd should be finished!"
1855 echo "(dd_pid=$DDPID2, time=$count)successful"
1858 resetquota -u $TSTUSR
1859 resetquota -g $TSTUSR
1861 run_test 21 "Setquota while writing & deleting (b16053)"
1863 # enable/disable quota enforcement permanently
1865 echo "Set both mdt & ost quota type as ug"
1866 set_mdt_qtype "ug" || error "enable mdt quota failed"
1867 set_ost_qtype "ug" || error "enable ost quota failed"
1870 stopall || error "failed to stopall (1)"
1874 echo "Verify if quota is enabled"
1875 local qtype=$(mdt_quota_type)
1876 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1877 qtype=$(ost_quota_type)
1878 [ $qtype != "ug" ] && error "ost quota setting is lost"
1880 echo "Set both mdt & ost quota type as none"
1881 set_mdt_qtype "none" || error "disable mdt quota failed"
1882 set_ost_qtype "none" || error "disable ost quota failed"
1885 stopall || error "failed to stopall (2)"
1890 echo "Verify if quota is disabled"
1891 qtype=$(mdt_quota_type)
1892 [ $qtype != "none" ] && error "mdt quota setting is lost"
1893 qtype=$(ost_quota_type)
1894 [ $qtype != "none" ] && error "ost quota setting is lost"
1898 run_test 22 "enable/disable quota by 'lctl conf_param'"
1901 local TESTFILE="$DIR/$tdir/$tfile"
1904 setup_quota_test || error "setup quota failed with $?"
1905 trap cleanup_quota_test EXIT
1907 set_ost_qtype "ug" || error "Enable ost quota failed"
1910 log "User quota (limit: $LIMIT MB)"
1911 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1912 error "set quota failed"
1913 quota_show_check b u $TSTUSR
1915 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1916 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1918 log "Step1: trigger EDQUOT with O_DIRECT"
1919 log "Write half of file"
1920 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1921 quota_error u $TSTUSR "(1) Write failure, expect success." \
1923 log "Write out of block quota ..."
1924 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1925 oflag=direct conv=notrunc &&
1926 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1930 log "Step2: rewrite should succeed"
1931 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1932 quota_error u $TSTUSR "(3) Write failure, expect success." \
1938 local OST0_UUID=$(ostuuid_from_index 0)
1939 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1940 [ $OST0_QUOTA_USED -ne 0 ] &&
1941 ($SHOW_QUOTA_USER; \
1942 quota_error u $TSTUSR "quota isn't released")
1944 resetquota -u $TSTUSR
1948 [ $(facet_fstype ost1) == "zfs" ] &&
1949 skip "Overwrite in place is not guaranteed to be " \
1950 "space neutral on ZFS" && return
1952 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1953 check_whether_skip && return 0
1954 log "run for 4MB test file"
1957 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1958 check_whether_skip && return 0
1959 log "run for 40MB test file"
1962 run_test 23 "Quota should be honored with directIO (b16125)"
1966 local TESTFILE="$DIR/$tdir/$tfile"
1968 setup_quota_test || error "setup quota failed with $?"
1969 trap cleanup_quota_test EXIT
1971 set_ost_qtype "ug" || error "enable ost quota failed"
1973 # bind file to a single OST
1974 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1975 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1977 echo "Set user quota (limit: ${blimit}M)"
1978 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1979 error "set quota failed"
1981 # overrun quota by root user
1982 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1983 error "write failure, expect success"
1984 cancel_lru_locks osc
1985 sync_all_data || true
1987 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
1990 resetquota -u $TSTUSR
1992 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
1994 test_27a() { # b19612
1995 $LFS quota $TSTUSR $DIR &&
1996 error "lfs succeeded with no type, but should have failed"
1997 $LFS setquota $TSTUSR $DIR &&
1998 error "lfs succeeded with no type, but should have failed"
2001 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2003 test_27b() { # b20200
2004 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2005 error "lfs setquota failed with uid argument"
2006 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2007 error "lfs stequota failed with gid argument"
2008 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2009 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2010 resetquota -u $TSTUSR
2011 resetquota -g $TSTUSR
2014 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2019 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2020 error "lfs setquota failed"
2022 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2023 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2024 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2025 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2027 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2028 error "lfs setquota for $TSTID failed"
2030 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2031 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2032 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2033 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2035 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2036 error "total allocated inode/block limit not printed"
2038 resetquota -u $TSTUSR
2040 run_test 27c "lfs quota should support human-readable output"
2047 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2048 error "set fraction block limit failed"
2049 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2050 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2051 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2052 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2054 resetquota -u $TSTUSR
2056 run_test 27d "lfs setquota should support fraction block limit"
2060 local TESTFILE="$DIR/$tdir/$tfile"
2063 setup_quota_test || error "setup quota failed with $?"
2064 trap cleanup_quota_test EXIT
2066 set_ost_qtype "u" || error "enable ost quota failed"
2068 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2069 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2071 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2072 $MAX_IQ_TIME $DIR || error "set grace time failed"
2073 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2074 error "set quota failed"
2075 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2076 cancel_lru_locks osc
2078 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2079 # over-quota flag has not yet settled since we do not trigger async
2080 # events based on grace time period expiration
2082 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2083 cancel_lru_locks osc
2084 # now over-quota flag should be settled and further writes should fail
2086 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2087 error "grace times were reset"
2090 resetquota -u $TSTUSR
2091 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2092 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2094 run_test 30 "Hard limit updates should not reset grace times"
2096 # basic usage tracking for user & group
2098 local INODES=10 # 10 files
2099 local BLK_CNT=2 # of 2M each
2100 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2102 setup_quota_test || error "setup quota failed with $?"
2103 trap cleanup_quota_test EXIT
2105 # make sure the system is clean
2106 local USED=$(getquota -u $TSTID global curspace)
2108 error "Used space ($USED) for user $TSTID isn't 0."
2109 USED=$(getquota -g $TSTID global curspace)
2111 error "Used space ($USED) for group $TSTID isn't 0."
2113 echo "Write files..."
2114 for i in $(seq 0 $INODES); do
2115 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2116 error "write failed"
2117 echo "Iteration $i/$INODES completed"
2119 cancel_lru_locks osc
2120 sync; sync_all_data || true
2122 echo "Verify disk usage after write"
2123 USED=$(getquota -u $TSTID global curspace)
2124 [ $USED -lt $TOTAL_BLKS ] &&
2125 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2126 USED=$(getquota -g $TSTID global curspace)
2127 [ $USED -lt $TOTAL_BLKS ] &&
2128 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2130 echo "Verify inode usage after write"
2131 USED=$(getquota -u $TSTID global curinodes)
2132 [ $USED -lt $INODES ] &&
2133 error "Used inode for user $TSTID is $USED, expected $INODES"
2134 USED=$(getquota -g $TSTID global curinodes)
2135 [ $USED -lt $INODES ] &&
2136 error "Used inode for group $TSTID is $USED, expected $INODES"
2140 echo "Verify disk usage after delete"
2141 USED=$(getquota -u $TSTID global curspace)
2142 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2143 USED=$(getquota -u $TSTID global curinodes)
2144 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2145 USED=$(getquota -g $TSTID global curspace)
2146 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2147 USED=$(getquota -g $TSTID global curinodes)
2148 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2150 run_test 33 "Basic usage tracking for user & group"
2152 # usage transfer test for user & group
2154 local BLK_CNT=2 # 2MB
2156 setup_quota_test || error "setup quota failed with $?"
2157 trap cleanup_quota_test EXIT
2159 # make sure the system is clean
2160 local USED=$(getquota -u $TSTID global curspace)
2161 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2162 USED=$(getquota -g $TSTID global curspace)
2163 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2165 local USED=$(getquota -u $TSTID2 global curspace)
2166 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2168 echo "Write file..."
2169 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2170 error "write failed"
2171 cancel_lru_locks osc
2172 sync; sync_all_data || true
2174 echo "chown the file to user $TSTID"
2175 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2177 echo "Wait for setattr on objects finished..."
2178 wait_delete_completed
2180 BLK_CNT=$((BLK_CNT * 1024))
2182 echo "Verify disk usage for user $TSTID"
2183 USED=$(getquota -u $TSTID global curspace)
2184 [ $USED -lt $BLK_CNT ] &&
2185 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2186 USED=$(getquota -u $TSTID global curinodes)
2188 error "Used inodes for user $TSTID is $USED, expected 1"
2190 echo "chgrp the file to group $TSTID"
2191 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2193 echo "Wait for setattr on objects finished..."
2194 wait_delete_completed
2196 echo "Verify disk usage for group $TSTID"
2197 USED=$(getquota -g $TSTID global curspace)
2198 [ $USED -ge $BLK_CNT ] ||
2199 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2200 USED=$(getquota -g $TSTID global curinodes)
2202 error "Used inodes for group $TSTID is $USED, expected 1"
2204 # chown won't change the ost object group. LU-4345 */
2205 echo "chown the file to user $TSTID2"
2206 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2208 echo "Wait for setattr on objects finished..."
2209 wait_delete_completed
2211 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2212 USED=$(getquota -u $TSTID2 global curspace)
2213 [ $USED -lt $BLK_CNT ] &&
2214 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2215 USED=$(getquota -u $TSTID global curspace)
2217 error "Used space for user $TSTID is $USED, expected 0"
2218 USED=$(getquota -g $TSTID global curspace)
2219 [ $USED -lt $BLK_CNT ] &&
2220 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2224 run_test 34 "Usage transfer for user & group"
2226 # usage is still accessible across restart
2228 local BLK_CNT=2 # 2 MB
2230 setup_quota_test || error "setup quota failed with $?"
2231 trap cleanup_quota_test EXIT
2233 echo "Write file..."
2234 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2235 error "write failed"
2236 cancel_lru_locks osc
2237 sync; sync_all_data || true
2239 echo "Save disk usage before restart"
2240 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2241 [ $ORIG_USR_SPACE -eq 0 ] &&
2242 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2243 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2244 [ $ORIG_USR_INODES -eq 0 ] &&
2245 error "Used inodes for user $TSTID is 0, expected 1"
2246 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2247 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2248 [ $ORIG_GRP_SPACE -eq 0 ] &&
2249 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2250 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2251 [ $ORIG_GRP_INODES -eq 0 ] &&
2252 error "Used inodes for group $TSTID is 0, expected 1"
2253 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2256 local ORIG_REFORMAT=$REFORMAT
2258 cleanup_and_setup_lustre
2259 REFORMAT=$ORIG_REFORMAT
2262 echo "Verify disk usage after restart"
2263 local USED=$(getquota -u $TSTID global curspace)
2264 [ $USED -eq $ORIG_USR_SPACE ] ||
2265 error "Used space for user $TSTID changed from " \
2266 "$ORIG_USR_SPACE to $USED"
2267 USED=$(getquota -u $TSTID global curinodes)
2268 [ $USED -eq $ORIG_USR_INODES ] ||
2269 error "Used inodes for user $TSTID changed from " \
2270 "$ORIG_USR_INODES to $USED"
2271 USED=$(getquota -g $TSTID global curspace)
2272 [ $USED -eq $ORIG_GRP_SPACE ] ||
2273 error "Used space for group $TSTID changed from " \
2274 "$ORIG_GRP_SPACE to $USED"
2275 USED=$(getquota -g $TSTID global curinodes)
2276 [ $USED -eq $ORIG_GRP_INODES ] ||
2277 error "Used inodes for group $TSTID changed from " \
2278 "$ORIG_GRP_INODES to $USED"
2280 # check if the vfs_dq_init() is called before writing
2281 echo "Append to the same file..."
2282 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2283 error "write failed"
2284 cancel_lru_locks osc
2285 sync; sync_all_data || true
2287 echo "Verify space usage is increased"
2288 USED=$(getquota -u $TSTID global curspace)
2289 [ $USED -gt $ORIG_USR_SPACE ] ||
2290 error "Used space for user $TSTID isn't increased" \
2291 "orig:$ORIG_USR_SPACE, now:$USED"
2292 USED=$(getquota -g $TSTID global curspace)
2293 [ $USED -gt $ORIG_GRP_SPACE ] ||
2294 error "Used space for group $TSTID isn't increased" \
2295 "orig:$ORIG_GRP_SPACE, now:$USED"
2299 run_test 35 "Usage is still accessible across reboot"
2301 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2304 setup_quota_test || error "setup quota failed with $?"
2305 trap cleanup_quota_test EXIT
2307 # make sure the system is clean
2308 local USED=$(getquota -u $TSTID global curspace)
2310 error "Used space ($USED) for user $TSTID isn't 0."
2312 # create file with MDS_OPEN_DELAY_CREATE flag
2313 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2314 error "Create file failed"
2316 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2317 oflag=sync || error "Write file failed"
2319 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2321 # wait for setattr on objects finished..."
2322 wait_delete_completed
2324 USED=$(getquota -u $TSTID global curspace)
2325 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2329 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2333 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2339 check_and_cleanup_lustre
2340 export QUOTA_AUTO=$QUOTA_AUTO_OLD