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
50 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3 4a 6"
51 # bug number for skipped test: LU-5638
52 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 11 33 34 35"
58 [ "$SLOW" = "no" ] && EXCEPT_SLOW="$ZFS_SLOW"
60 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
62 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
67 QUOTA_AUTO_OLD=$QUOTA_AUTO
70 check_and_setup_lustre
72 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
73 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
74 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
75 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
76 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
77 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
84 local fail_val=${3:-0}
88 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
89 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
90 ost) NODES="$(comma_list $(osts_nodes))";;
93 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
96 RUNAS="runas -u $TSTID -g $TSTID"
97 RUNAS2="runas -u $TSTID2 -g $TSTID2"
98 DD="dd if=/dev/zero bs=1M"
102 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
103 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
104 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
105 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
107 # clear quota limits for a user or a group
108 # usage: resetquota -u username
109 # resetquota -g groupname
112 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
113 [ "$1" != "-u" -a "$1" != "-g" ] &&
114 error "resetquota: wrong specifier $1 passed"
116 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
117 error "clear quota for [type:$1 name:$2] failed"
118 # give a chance to slave to release space
126 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "u" ]; then
127 $LFS quota -v -u $LOCAL_ID $DIR
128 log "Files for user ($LOCAL_ID):"
129 ($LFS find -user $LOCAL_ID $DIR | head -n 4 |
130 xargs stat 2>/dev/null)
133 if [ "$LOCAL_UG" == "a" -o "$LOCAL_UG" == "g" ]; then
134 $LFS quota -v -g $LOCAL_ID $DIR
135 log "Files for group ($LOCAL_ID):"
136 ($LFS find -group $LOCAL_ID $DIR | head -n 4 |
137 xargs stat 2>/dev/null)
153 # get quota for a user or a group
154 # usage: getquota -u|-g <username>|<groupname> global|<obd_uuid> \
155 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
160 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
161 [ "$1" != "-u" -a "$1" != "-g" ] &&
162 error "getquota: wrong u/g specifier $1 passed"
175 *) error "unknown quota parameter $4";;
178 [ "$uuid" = "global" ] && uuid=$DIR
180 $LFS quota -v "$1" "$2" $DIR |
181 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
182 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
187 # usage: set_mdt_qtype ug|u|g|none
191 local mdts=$(get_facets MDS)
193 do_facet mgs $LCTL conf_param $FSNAME.quota.mdt=$qtype
194 # we have to make sure each MDT received config changes
195 for mdt in ${mdts//,/ }; do
197 cmd="$LCTL get_param -n "
198 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
199 cmd=${cmd}.quota_slave.enabled
201 if $(facet_up $mdt); then
202 wait_update_facet $mdt "$cmd" "$qtype" || return 1
209 # usage: set_ost_qtype ug|u|g|none
213 local osts=$(get_facets OST)
215 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=$qtype
216 # we have to make sure each OST received config changes
217 for ost in ${osts//,/ }; do
219 cmd="$LCTL get_param -n "
220 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
221 cmd=${cmd}.quota_slave.enabled
223 if $(facet_up $ost); then
224 wait_update_facet $ost "$cmd" "$qtype" || return 1
230 wait_reintegration() {
234 local result="glb[1],slv[1],reint[0]"
239 if [ $ntype == "mdt" ]; then
240 tgts=$(get_facets MDS)
242 tgts=$(get_facets OST)
245 for tgt in ${tgts//,/ }; do
247 cmd="$LCTL get_param -n "
248 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
249 cmd=${cmd}.quota_slave.info
251 if $(facet_up $tgt); then
252 wait_update_facet $tgt "$cmd |
253 grep "$qtype" | awk '{ print \\\$3 }'" \
254 "$result" $max || return 1
264 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
265 wait_reintegration "mdt" "user" $max || return 1
268 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
269 wait_reintegration "mdt" "group" $max || return 1
278 if [ $qtype == "u" ] || [ $qtype == "ug" ]; then
279 wait_reintegration "ost" "user" $max || return 1
282 if [ $qtype == "g" ] || [ $qtype == "ug" ]; then
283 wait_reintegration "ost" "group" $max || return 1
289 wait_delete_completed
290 echo "Creating test directory"
291 mkdir $DIR/$tdir || return 1
292 chmod 0777 $DIR/$tdir || return 2
293 # always clear fail_loc in case of fail_loc isn't cleared
294 # properly when previous test failed
295 lustre_fail mds_ost 0
298 cleanup_quota_test() {
300 echo "Delete files..."
302 echo "Wait for unlink objects finished..."
303 wait_delete_completed
304 sync_all_data || true
313 $LFS quota -v -$ug $qid $DIR
315 if [ "$bf" == "a" -o "$bf" == "b" ]; then
316 usage=$(getquota -$ug $qid global curspace)
317 if [ -z $usage ]; then
318 quota_error $ug $qid \
319 "Query block quota failed ($ug:$qid)."
321 [ $usage -ne 0 ] && quota_log $ug $qid \
322 "Block quota isn't 0 ($ug:$qid:$usage)."
326 if [ "$bf" == "a" -o "$bf" == "f" ]; then
327 usage=$(getquota -$ug $qid global curinodes)
328 if [ -z $usage ]; then
329 quota_error $ug $qid \
330 "Query file quota failed ($ug:$qid)."
332 [ $usage -ne 0 ] && quota_log $ug $qid \
333 "File quota isn't 0 ($ug:$qid:$usage)."
340 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
344 resetquota -u $TSTUSR
345 resetquota -g $TSTUSR
346 resetquota -u $TSTUSR2
347 resetquota -g $TSTUSR2
349 test_quota_performance() {
350 local TESTFILE="$DIR/$tdir/$tfile-0"
351 local size=$1 # in MB
352 local stime=$(date +%s)
353 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
354 quota_error u $TSTUSR "write failure"
355 local etime=$(date +%s)
356 delta=$((etime - stime))
357 if [ $delta -gt 0 ]; then
358 rate=$((size * 1024 / delta))
359 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
360 # LU-2872 - see LU-2887 for fix
362 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
364 [ $rate -gt 1024 ] ||
365 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
371 # test basic quota performance b=21696
374 [ "$SLOW" = "no" ] && MB=10
376 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
377 [ $free_space -le $((MB * 1024)) ] &&
378 skip "not enough space ${free_space} KB, " \
379 "required $((MB * 1024)) KB" && return
380 setup_quota_test || error "setup quota failed with $?"
381 trap cleanup_quota_test EXIT
383 set_ost_qtype "none" || error "disable ost quota failed"
384 test_quota_performance $MB
386 set_ost_qtype "ug" || error "enable ost quota failed"
387 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
388 error "set quota failed"
389 test_quota_performance $MB
392 resetquota -u $TSTUSR
394 run_test 0 "Test basic quota performance"
396 # test block hardlimit
399 local TESTFILE="$DIR/$tdir/$tfile-0"
401 setup_quota_test || error "setup quota failed with $?"
402 trap cleanup_quota_test EXIT
405 set_ost_qtype "ug" || error "enable ost quota failed"
408 log "User quota (block hardlimit:$LIMIT MB)"
409 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
410 error "set user quota failed"
412 # make sure the system is clean
413 local USED=$(getquota -u $TSTUSR global curspace)
414 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
416 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
417 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
420 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
421 quota_error u $TSTUSR "user write failure, but expect success"
422 log "Write out of block quota ..."
423 # this time maybe cache write, ignore it's failure
424 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
425 # flush cache, ensure noquota flag is set on client
427 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
428 quota_error u $TSTUSR "user write success, but expect EDQUOT"
431 wait_delete_completed || error "wait_delete_completed failed"
432 sync_all_data || true
433 USED=$(getquota -u $TSTUSR global curspace)
434 [ $USED -ne 0 ] && quota_error u $TSTUSR \
435 "user quota isn't released after deletion"
436 resetquota -u $TSTUSR
439 log "--------------------------------------"
440 log "Group quota (block hardlimit:$LIMIT MB)"
441 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
442 error "set group quota failed"
444 TESTFILE="$DIR/$tdir/$tfile-1"
445 # make sure the system is clean
446 USED=$(getquota -g $TSTUSR global curspace)
447 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0"
449 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
450 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
453 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
454 quota_error g $TSTUSR "group write failure, but expect success"
455 log "Write out of block quota ..."
456 # this time maybe cache write, ignore it's failure
457 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
459 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
460 quota_error g $TSTUSR "group write success, but expect EDQUOT"
465 USED=$(getquota -g $TSTUSR global curspace)
466 [ $USED -ne 0 ] && quota_error g $TSTUSR \
467 "group quota isn't released after deletion"
469 resetquota -g $TSTUSR
471 run_test 1 "Block hard limit (normal use and out of quota)"
473 # test inode hardlimit
475 local LIMIT=$((1024 * 1024)) # 1M inodes
476 local TESTFILE="$DIR/$tdir/$tfile-0"
478 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
480 local FREE_INODES=$(mdt_free_inodes 0)
481 echo "$FREE_INODES free inodes on master MDT"
482 [ $FREE_INODES -lt $LIMIT ] &&
483 skip "not enough free inodes $FREE_INODES required $LIMIT" &&
486 setup_quota_test || error "setup quota failed with $?"
487 trap cleanup_quota_test EXIT
490 set_mdt_qtype "ug" || error "enable mdt quota failed"
493 log "User quota (inode hardlimit:$LIMIT files)"
494 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
495 error "set user quota failed"
497 # make sure the system is clean
498 local USED=$(getquota -u $TSTUSR global curinodes)
499 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
501 log "Create $LIMIT files ..."
502 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
503 quota_error u $TSTUSR "user create failure, but expect success"
504 log "Create out of file quota ..."
505 $RUNAS touch ${TESTFILE}_xxx &&
506 quota_error u $TSTUSR "user create success, but expect EDQUOT"
509 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
510 rm -f ${TESTFILE}_xxx
511 wait_delete_completed
513 USED=$(getquota -u $TSTUSR global curinodes)
514 [ $USED -ne 0 ] && quota_error u $TSTUSR \
515 "user quota isn't released after deletion"
516 resetquota -u $TSTUSR
519 log "--------------------------------------"
520 log "Group quota (inode hardlimit:$LIMIT files)"
521 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
522 error "set group quota failed"
524 TESTFILE=$DIR/$tdir/$tfile-1
525 # make sure the system is clean
526 USED=$(getquota -g $TSTUSR global curinodes)
527 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
529 log "Create $LIMIT files ..."
530 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
531 quota_error g $TSTUSR "group create failure, but expect success"
532 log "Create out of file quota ..."
533 $RUNAS touch ${TESTFILE}_xxx &&
534 quota_error g $TSTUSR "group create success, but expect EDQUOT"
537 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
538 rm -f ${TESTFILE}_xxx
539 wait_delete_completed
541 USED=$(getquota -g $TSTUSR global curinodes)
542 [ $USED -ne 0 ] && quota_error g $TSTUSR \
543 "user quota isn't released after deletion"
546 resetquota -g $TSTUSR
548 run_test 2 "File hard limit (normal use and out of quota)"
552 local TIMER=$(($2 * 3 / 2))
557 trap cleanup_quota_test EXIT
559 $SETSTRIPE $TESTFILE -c 1 -i 0
560 chown $TSTUSR.$TSTUSR $TESTFILE
562 echo "Write up to soft limit"
563 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
564 quota_error a $TSTUSR "write failure, but expect success"
565 OFFSET=$((LIMIT * 1024))
568 echo "Write to exceed soft limit"
569 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
570 quota_error a $TSTUSR "write failure, but expect success"
571 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
576 $SHOW_QUOTA_INFO_USER
577 $SHOW_QUOTA_INFO_GROUP
579 echo "Write before timer goes off"
580 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
581 quota_error a $TSTUSR "write failure, but expect success"
582 OFFSET=$((OFFSET + 1024))
585 echo "Sleep $TIMER seconds ..."
590 $SHOW_QUOTA_INFO_USER
591 $SHOW_QUOTA_INFO_GROUP
593 echo "Write after timer goes off"
594 # maybe cache write, ignore.
595 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
596 OFFSET=$((OFFSET + 1024))
598 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
599 quota_error a $TSTUSR "write success, but expect EDQUOT"
603 $SHOW_QUOTA_INFO_USER
604 $SHOW_QUOTA_INFO_GROUP
606 echo "Unlink file to stop timer"
608 wait_delete_completed
609 sync_all_data || true
613 $SHOW_QUOTA_INFO_USER
614 $SHOW_QUOTA_INFO_GROUP
616 $SETSTRIPE $TESTFILE -c 1 -i 0
617 chown $TSTUSR.$TSTUSR $TESTFILE
620 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
621 quota_error a $TSTUSR "write failure, but expect success"
630 local TESTFILE=$DIR/$tdir/$tfile-0
632 set_ost_qtype "ug" || error "enable ost quota failed"
634 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
635 # make sure the system is clean
636 local USED=$(getquota -u $TSTUSR global curspace)
637 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
639 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
640 $MAX_IQ_TIME $DIR || error "set user grace time failed"
641 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
642 error "set user quota failed"
644 test_block_soft $TESTFILE $GRACE $LIMIT
645 resetquota -u $TSTUSR
647 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
648 TESTFILE=$DIR/$tdir/$tfile-1
649 # make sure the system is clean
650 USED=$(getquota -g $TSTUSR global curspace)
651 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
653 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
654 $MAX_IQ_TIME $DIR || error "set group grace time failed"
655 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
656 error "set group quota failed"
658 test_block_soft $TESTFILE $GRACE $LIMIT
659 resetquota -g $TSTUSR
662 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
663 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
664 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
665 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
667 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
673 local TIMER=$(($grace * 3 / 2))
676 trap cleanup_quota_test EXIT
678 echo "Create files to exceed soft limit"
679 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
680 quota_error a $TSTUSR "create failure, but expect success"
681 local trigger_time=$(date +%s)
683 sync_all_data || true
685 local cur_time=$(date +%s)
686 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
687 error "Passed grace time $grace, $trigger_time, $cur_time"
689 echo "Create file before timer goes off"
690 $RUNAS touch ${TESTFILE}_before ||
691 quota_error a $TSTUSR "failed create before timer expired," \
692 "but expect success. $trigger_time, $cur_time"
693 sync_all_data || true
695 echo "Sleep $TIMER seconds ..."
700 $SHOW_QUOTA_INFO_USER
701 $SHOW_QUOTA_INFO_GROUP
703 echo "Create file after timer goes off"
704 # There is a window that space is accounted in the quota usage but
705 # hasn't been decreased from the pending write, if we acquire quota
706 # in this window, we'll acquire more than we needed.
707 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
708 sync_all_data || true
709 $RUNAS touch ${TESTFILE}_after_3 &&
710 quota_error a $TSTUSR "create after timer expired," \
712 sync_all_data || true
716 $SHOW_QUOTA_INFO_USER
717 $SHOW_QUOTA_INFO_GROUP
719 echo "Unlink files to stop timer"
720 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
721 wait_delete_completed
724 $RUNAS touch ${TESTFILE}_xxx ||
725 quota_error a $TSTUSR "touch after timer stop failure," \
727 sync_all_data || true
735 local LIMIT=10 # inodes
736 local TESTFILE=$DIR/$tdir/$tfile-0
739 set_mdt_qtype "ug" || error "enable mdt quota failed"
741 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
742 # make sure the system is clean
743 local USED=$(getquota -u $TSTUSR global curinodes)
744 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
746 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
747 $GRACE $DIR || error "set user grace time failed"
748 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
749 error "set user quota failed"
751 test_file_soft $TESTFILE $LIMIT $GRACE
752 resetquota -u $TSTUSR
754 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
755 # make sure the system is clean
756 USED=$(getquota -g $TSTUSR global curinodes)
757 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
759 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
760 $GRACE $DIR || error "set group grace time failed"
761 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
762 error "set group quota failed"
763 TESTFILE=$DIR/$tdir/$tfile-1
765 test_file_soft $TESTFILE $LIMIT $GRACE
766 resetquota -g $TSTUSR
769 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
770 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
771 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
772 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
774 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
778 local GR_STR2="1000s"
780 local GR_STR4="1w2d3h4m5s"
782 local GR_STR6="18446744073709551615"
785 wait_delete_completed
787 # test of valid grace strings handling
788 echo "Valid grace strings test"
789 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
790 $GR_STR2 $DIR || error "set user grace time failed"
791 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
792 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
793 $GR_STR4 $DIR || error "set group grace time quota failed"
794 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
796 # test of invalid grace strings handling
797 echo " Invalid grace strings test"
798 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
799 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
800 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
804 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
805 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
806 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
807 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
809 run_test 4b "Grace time strings handling"
811 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
813 local BLIMIT=10 # 10M
814 local ILIMIT=10 # 10 inodes
816 setup_quota_test || error "setup quota failed with $?"
817 trap cleanup_quota_test EXIT
819 set_mdt_qtype "ug" || error "enable mdt quota failed"
820 set_ost_qtype "ug" || error "enable ost quota failed"
822 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
823 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
824 error "set user quota failed"
825 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
826 error "set group quota failed"
828 # make sure the system is clean
829 local USED=$(getquota -u $TSTUSR global curinodes)
830 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
831 USED=$(getquota -g $TSTUSR global curinodes)
832 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
833 USED=$(getquota -u $TSTUSR global curspace)
834 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
835 USED=$(getquota -g $TSTUSR global curspace)
836 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
838 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
839 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
840 error "create failure, expect success"
841 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
842 error "write failure, expect success"
844 echo "Chown files to $TSTUSR.$TSTUSR ..."
845 for i in $(seq 0 $ILIMIT); do
846 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
847 quota_error a $TSTUSR "chown failure, expect success"
851 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
852 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
855 resetquota -u $TSTUSR
856 resetquota -g $TSTUSR
858 run_test 5 "Chown & chgrp successfully even out of block/file quota"
860 # test dropping acquire request on master
864 # Clear dmesg so watchdog is not triggered by previous
866 do_facet ost1 dmesg -c > /dev/null
868 setup_quota_test || error "setup quota failed with $?"
869 trap cleanup_quota_test EXIT
871 # make sure the system is clean
872 local USED=$(getquota -u $TSTUSR global curspace)
873 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
875 # make sure no granted quota on ost
876 set_ost_qtype "ug" || error "enable ost quota failed"
877 resetquota -u $TSTUSR
879 # create file for $TSTUSR
880 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
881 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
882 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
884 # create file for $TSTUSR2
885 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
886 $SETSTRIPE $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
887 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
889 # cache per-ID lock for $TSTUSR on slave
890 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
891 error "set quota failed"
892 $RUNAS $DD of=$TESTFILE count=1 ||
893 error "write $TESTFILE failure, expect success"
894 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
895 error "write $TESTFILE2 failure, expect success"
897 sync_all_data || true
899 #define QUOTA_DQACQ 601
900 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
901 lustre_fail mds 0x513 601
903 # write to un-enforced ID ($TSTUSR2) should succeed
904 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
905 error "write failure, expect success"
907 # write to enforced ID ($TSTUSR) in background, exceeding limit
908 # to make sure DQACQ is sent
909 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
912 # watchdog timer uses a factor of 2
913 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
914 sleep $((TIMEOUT * 2 + 1))
916 # write should be blocked and never finished
917 if ! ps -p $DDPID > /dev/null 2>&1; then
919 error "write finished incorrectly!"
924 # no watchdog is triggered
925 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
926 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
927 { print; }' $TMP/lustre-log-${TESTNAME}.log)
928 [ -z "$watchdog" ] || error "$watchdog"
930 rm -f $TMP/lustre-log-${TESTNAME}.log
932 # write should continue then fail with EDQUOT
936 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
937 if [ $count -ge 240 ]; then
938 quota_error u $TSTUSR "dd not finished in $count secs"
941 if [ $((count % 30)) -eq 0 ]; then
942 c_size=$(stat -c %s $TESTFILE)
943 echo "Waiting $count secs. $c_size"
950 resetquota -u $TSTUSR
952 run_test 6 "Test dropping acquire request on master"
954 # quota reintegration (global index)
956 local TESTFILE=$DIR/$tdir/$tfile
959 [ "$SLOW" = "no" ] && LIMIT=5
961 setup_quota_test || error "setup quota failed with $?"
962 trap cleanup_quota_test EXIT
964 # make sure the system is clean
965 local USED=$(getquota -u $TSTUSR global curspace)
966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
968 # make sure no granted quota on ost1
969 set_ost_qtype "ug" || error "enable ost quota failed"
970 resetquota -u $TSTUSR
971 set_ost_qtype "none" || error "disable ost quota failed"
973 local OSTUUID=$(ostuuid_from_index 0)
974 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
976 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
979 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
980 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
985 echo "Enable quota & set quota limit for $TSTUSR"
986 set_ost_qtype "ug" || error "enable ost quota failed"
987 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
988 error "set quota failed"
991 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
994 wait_ost_reint "ug" || error "reintegration failed"
996 # hardlimit should have been fetched by slave during global
997 # reintegration, write will exceed quota
998 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
999 quota_error u $TSTUSR "write success, but expect EDQUOT"
1002 wait_delete_completed
1003 sync_all_data || true
1009 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1010 error "clear quota failed"
1012 echo "Start ost1..."
1013 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1016 wait_ost_reint "ug" || error "reintegration failed"
1018 # hardlimit should be cleared on slave during reintegration
1019 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1020 quota_error u $TSTUSR "write error, but expect success"
1023 resetquota -u $TSTUSR
1025 run_test 7a "Quota reintegration (global index)"
1027 # quota reintegration (slave index)
1030 local TESTFILE=$DIR/$tdir/$tfile
1032 setup_quota_test || error "setup quota failed with $?"
1033 trap cleanup_quota_test EXIT
1035 # make sure the system is clean
1036 local USED=$(getquota -u $TSTUSR global curspace)
1037 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1039 # make sure no granted quota on ost1
1040 set_ost_qtype "ug" || error "enable ost quota failed"
1041 resetquota -u $TSTUSR
1042 set_ost_qtype "none" || error "disable ost quota failed"
1044 local OSTUUID=$(ostuuid_from_index 0)
1045 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1047 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1050 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1051 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1053 # consume some space to make sure the granted space will not
1054 # be released during reconciliation
1055 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1056 error "consume space failure, expect success"
1058 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1059 lustre_fail mds 0xa02
1061 set_ost_qtype "ug" || error "enable ost quota failed"
1062 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1063 error "set quota failed"
1065 # ignore the write error
1066 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1068 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1072 echo "Restart ost to trigger reintegration..."
1074 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1077 wait_ost_reint "ug" || error "reintegration failed"
1079 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1080 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1083 resetquota -u $TSTUSR
1086 run_test 7b "Quota reintegration (slave index)"
1088 # quota reintegration (restart mds during reintegration)
1090 local LIMIT=20 # 20M
1091 local TESTFILE=$DIR/$tdir/$tfile
1093 [ "$SLOW" = "no" ] && LIMIT=5
1095 setup_quota_test || error "setup quota failed with $?"
1096 trap cleanup_quota_test EXIT
1098 # make sure the system is clean
1099 local USED=$(getquota -u $TSTUSR global curspace)
1100 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1102 set_ost_qtype "none" || error "disable ost quota failed"
1103 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1104 error "set quota failed"
1106 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1107 lustre_fail ost 0xa03
1110 set_ost_qtype "ug" || error "enable ost quota failed"
1111 # trigger reintegration
1112 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1113 procf=${procf}quota_slave.force_reint
1114 do_facet ost1 $LCTL set_param $procf=1 ||
1115 error "force reintegration failed"
1123 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1126 # wait longer than usual to make sure the reintegration
1127 # is triggered by quota wb thread.
1128 wait_ost_reint "ug" 200 || error "reintegration failed"
1130 # hardlimit should have been fetched by slave during global
1131 # reintegration, write will exceed quota
1132 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1133 quota_error u $TSTUSR "write success, but expect EDQUOT"
1136 resetquota -u $TSTUSR
1138 run_test 7c "Quota reintegration (restart mds during reintegration)"
1140 # Quota reintegration (Transfer index in multiple bulks)
1142 local TESTFILE=$DIR/$tdir/$tfile
1143 local TESTFILE1="$DIR/$tdir/$tfile"-1
1146 setup_quota_test || error "setup quota failed with $?"
1147 trap cleanup_quota_test EXIT
1149 set_ost_qtype "none" || error "disable ost quota failed"
1150 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1151 error "set quota for $TSTUSR failed"
1152 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1153 error "set quota for $TSTUSR2 failed"
1155 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1156 lustre_fail mds 0x608 0
1158 # enable quota to tirgger reintegration
1159 set_ost_qtype "u" || error "enable ost quota failed"
1160 wait_ost_reint "u" || error "reintegration failed"
1164 # hardlimit should have been fetched by slave during global
1165 # reintegration, write will exceed quota
1166 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1167 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1169 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1170 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1173 resetquota -u $TSTUSR
1174 resetquota -u $TSTUSR2
1176 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1178 # quota reintegration (inode limits)
1180 [ "$MDSCOUNT" -lt "2" ] && skip "Required more MDTs" && return
1182 # LU-2435: skip this quota test if underlying zfs version has not
1183 # supported native dnode accounting
1184 [ "$(facet_fstype mds1)" == "zfs" ] && {
1185 local zfs_version=$(do_facet mds1 cat /sys/module/zfs/version)
1187 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] &&
1188 skip "requires zfs version at least 0.7.0" && return
1191 local ilimit=$((1024 * 2)) # 2k inodes
1192 local TESTFILE=$DIR/${tdir}-1/$tfile
1194 setup_quota_test || error "setup quota failed with $?"
1195 trap cleanup_quota_test EXIT
1197 # make sure the system is clean
1198 local USED=$(getquota -u $TSTUSR global curinodes)
1199 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1201 # make sure no granted quota on mdt1
1202 set_mdt_qtype "ug" || error "enable mdt quota failed"
1203 resetquota -u $TSTUSR
1204 set_mdt_qtype "none" || error "disable mdt quota failed"
1206 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1207 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1208 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1211 echo "Stop mds${MDSCOUNT}..."
1214 echo "Enable quota & set quota limit for $TSTUSR"
1215 set_mdt_qtype "ug" || error "enable mdt quota failed"
1216 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1217 error "set quota failed"
1219 echo "Start mds${MDSCOUNT}..."
1220 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1223 wait_mdt_reint "ug" || error "reintegration failed"
1225 echo "create remote dir"
1226 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1227 error "create remote dir failed"
1228 chmod 0777 $DIR/${tdir}-1
1230 # hardlimit should have been fetched by slave during global
1231 # reintegration, create will exceed quota
1232 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1233 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1235 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1236 wait_delete_completed
1237 sync_all_data || true
1239 echo "Stop mds${MDSCOUNT}..."
1242 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1243 error "clear quota failed"
1245 echo "Start mds${MDSCOUNT}..."
1246 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1249 wait_mdt_reint "ug" || error "reintegration failed"
1251 # hardlimit should be cleared on slave during reintegration
1252 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1253 quota_error -u $TSTUSR "create failed, expect success"
1255 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1256 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1259 resetquota -u $TSTUSR
1261 run_test 7e "Quota reintegration (inode limits)"
1263 # run dbench with quota enabled
1265 local BLK_LIMIT="100g" #100G
1266 local FILE_LIMIT=1000000
1268 setup_quota_test || error "setup quota failed with $?"
1269 trap cleanup_quota_test EXIT
1271 set_mdt_qtype "ug" || error "enable mdt quota failed"
1272 set_ost_qtype "ug" || error "enable ost quota failed"
1274 echo "Set enough high limit for user: $TSTUSR"
1275 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1276 error "set user quota failed"
1277 echo "Set enough high limit for group: $TSTUSR"
1278 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1279 error "set group quota failed"
1282 [ "$SLOW" = "no" ] && duration=" -t 120"
1283 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1284 quota_error a $TSTUSR "dbench failed!"
1287 resetquota -u $TSTUSR
1288 resetquota -g $TSTUSR
1290 run_test 8 "Run dbench with quota enabled"
1292 # this check is just for test_9
1293 OST0_MIN=4900000 #4.67G
1295 check_whether_skip () {
1296 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1297 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1298 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1299 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1306 # run for fixing bug10707, it needs a big room. test for 64bit
1308 local filesize=$((1024 * 9 / 2)) # 4.5G
1310 check_whether_skip && return 0
1312 setup_quota_test || error "setup quota failed with $?"
1313 trap cleanup_quota_test EXIT
1315 set_ost_qtype "ug" || error "enable ost quota failed"
1317 local TESTFILE="$DIR/$tdir/$tfile-0"
1318 local BLK_LIMIT=100G #100G
1319 local FILE_LIMIT=1000000
1321 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1323 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1325 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1326 error "set user quota failed"
1328 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1329 "for group: $TSTUSR"
1330 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1331 error "set group quota failed"
1333 quota_show_check a u $TSTUSR
1334 quota_show_check a g $TSTUSR
1336 echo "Create test file"
1337 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1338 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1340 log "Write the big file of 4.5G ..."
1341 $RUNAS $DD of=$TESTFILE count=$filesize ||
1342 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1348 resetquota -u $TSTUSR
1349 resetquota -g $TSTUSR
1354 run_test 9 "Block limit larger than 4GB (b10707)"
1357 local TESTFILE=$DIR/$tdir/$tfile
1359 setup_quota_test || error "setup quota failed with $?"
1360 trap cleanup_quota_test EXIT
1362 # set limit to root user should fail
1363 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1364 error "set limit for root user successfully, expect failure"
1365 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1366 error "set limit for root group successfully, expect failure"
1368 # root user can overrun quota
1369 set_ost_qtype "ug" || error "enable ost quota failed"
1371 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1372 error "set quota failed"
1373 quota_show_check b u $TSTUSR
1375 $SETSTRIPE $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1376 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1378 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1379 error "write failure, expect success"
1382 resetquota -u $TSTUSR
1384 run_test 10 "Test quota for root user"
1387 local TESTFILE=$DIR/$tdir/$tfile
1388 setup_quota_test || error "setup quota failed with $?"
1389 trap cleanup_quota_test EXIT
1391 set_mdt_qtype "ug" || error "enable mdt quota failed"
1392 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1393 error "set quota failed"
1395 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1396 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1398 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1399 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1402 local USED=$(getquota -u $TSTUSR global curinodes)
1403 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1406 resetquota -u $TSTUSR
1408 run_test 11 "Chown/chgrp ignores quota"
1411 [ "$OSTCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1413 local blimit=22 # 22M
1414 local blk_cnt=$((blimit - 5))
1415 local TESTFILE0="$DIR/$tdir/$tfile"-0
1416 local TESTFILE1="$DIR/$tdir/$tfile"-1
1418 setup_quota_test || error "setup quota failed with $?"
1419 trap cleanup_quota_test EXIT
1421 set_ost_qtype "u" || error "enable ost quota failed"
1422 quota_show_check b u $TSTUSR
1424 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1425 error "set quota failed"
1427 $SETSTRIPE $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1428 $SETSTRIPE $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1429 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1430 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1432 echo "Write to ost0..."
1433 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1434 quota_error a $TSTUSR "dd failed"
1436 echo "Write to ost1..."
1437 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1438 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1440 echo "Free space from ost0..."
1442 wait_delete_completed
1443 sync_all_data || true
1445 echo "Write to ost1 after space freed from ost0..."
1446 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1447 quota_error a $TSTUSR "rebalancing failed"
1450 resetquota -u $TSTUSR
1452 run_test 12a "Block quota rebalancing"
1455 [ "$MDSCOUNT" -lt "2" ] && skip "skipping rebalancing test" && return
1457 local ilimit=$((1024 * 2)) # 2k inodes
1458 local TESTFILE0=$DIR/$tdir/$tfile
1459 local TESTFILE1=$DIR/${tdir}-1/$tfile
1461 setup_quota_test || error "setup quota failed with $?"
1462 trap cleanup_quota_test EXIT
1464 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1465 chmod 0777 $DIR/${tdir}-1
1467 set_mdt_qtype "u" || error "enable mdt quota failed"
1468 quota_show_check f u $TSTUSR
1470 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1471 error "set quota failed"
1473 echo "Create $ilimit files on mdt0..."
1474 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1475 quota_error u $TSTUSR "create failed, but expect success"
1477 echo "Create files on mdt1..."
1478 $RUNAS createmany -m $TESTFILE1 1 &&
1479 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1481 echo "Free space from mdt0..."
1482 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1483 wait_delete_completed
1484 sync_all_data || true
1486 echo "Create files on mdt1 after space freed from mdt0..."
1487 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1488 quota_error a $TSTUSR "rebalancing failed"
1490 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1491 error "unlink mdt1 files failed"
1492 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1495 resetquota -u $TSTUSR
1497 run_test 12b "Inode quota rebalancing"
1500 local TESTFILE=$DIR/$tdir/$tfile
1501 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1502 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1504 setup_quota_test || error "setup quota failed with $?"
1505 trap cleanup_quota_test EXIT
1507 set_ost_qtype "u" || error "enable ost quota failed"
1508 quota_show_check b u $TSTUSR
1510 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1511 error "set quota failed"
1512 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1513 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1515 # clear the locks in cache first
1516 do_facet ost1 $LCTL set_param -n $procf=clear
1517 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1518 [ $nlock -eq 0 ] || error "$nlock cached locks"
1520 # write to acquire the per-ID lock
1521 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1522 quota_error a $TSTUSR "dd failed"
1524 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1525 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1527 # clear quota doesn't trigger per-ID lock cancellation
1528 resetquota -u $TSTUSR
1529 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1530 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1532 # clear the per-ID lock
1533 do_facet ost1 $LCTL set_param -n $procf=clear
1534 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1535 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1537 # spare quota should be released
1538 local OSTUUID=$(ostuuid_from_index 0)
1539 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1540 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1541 [ $limit -le $space ] ||
1542 error "spare quota isn't released, limit:$limit, space:$space"
1546 run_test 13 "Cancel per-ID lock in the LRU list"
1549 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1551 wait_delete_completed
1552 sync_all_data || true
1555 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1556 error "set user quota failed"
1557 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1558 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1559 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1560 resetquota -u $TSTUSR
1563 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1564 error "set group quota failed"
1565 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1566 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1567 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1568 resetquota -g $TSTUSR
1570 run_test 15 "Set over 4T block quota"
1574 local BLKS=1 # 1M less than limit
1575 local TESTFILE=$DIR/$tdir/$tfile
1577 setup_quota_test || error "setup quota failed with $?"
1578 trap cleanup_quota_test EXIT
1580 # make sure the system is clean
1581 local USED=$(getquota -u $TSTUSR global curspace)
1582 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1584 set_ost_qtype "ug" || error "enable ost quota failed"
1585 # make sure no granted quota on ost
1586 resetquota -u $TSTUSR
1587 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1588 error "set quota failed"
1590 quota_show_check b u $TSTUSR
1592 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1593 lustre_fail mds 0xa04 $err_code
1595 # write in background
1596 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1600 # write should be blocked and never finished
1601 if ! ps -p $DDPID > /dev/null 2>&1; then
1603 quota_error u $TSTUSR "write finished incorrectly!"
1611 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1613 if [ $count -gt $timeout ]; then
1614 quota_error u $TSTUSR "dd is not finished!"
1619 sync; sync_all_data || true
1621 USED=$(getquota -u $TSTUSR global curspace)
1622 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1623 "Used space(${USED}K) is less than ${BLKS}M"
1626 resetquota -u $TSTUSR
1629 # DQACQ return recoverable error
1631 echo "DQACQ return -ENOLCK"
1633 test_17sub 37 || error "Handle -ENOLCK failed"
1635 echo "DQACQ return -EAGAIN"
1637 test_17sub 11 || error "Handle -EAGAIN failed"
1639 echo "DQACQ return -ETIMEDOUT"
1640 #define ETIMEDOUT 110
1641 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1643 echo "DQACQ return -ENOTCONN"
1644 #define ENOTCONN 107
1645 test_17sub 107 || error "Handle -ENOTCONN failed"
1648 run_test 17 "DQACQ return recoverable error"
1652 local blimit="200m" # 200M
1653 local TESTFILE="$DIR/$tdir/$tfile"
1655 setup_quota_test || error "setup quota failed with $?"
1656 trap cleanup_quota_test EXIT
1658 set_ost_qtype "u" || error "enable ost quota failed"
1659 log "User quota (limit: $blimit)"
1660 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1661 error "set quota failed"
1662 quota_show_check b u $TSTUSR
1664 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1665 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1667 local timeout=$(sysctl -n lustre.timeout)
1669 if [ $io_type = "directio" ]; then
1670 log "Write 100M (directio) ..."
1671 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1673 log "Write 100M (buffered) ..."
1674 $RUNAS $DD of=$TESTFILE count=100 &
1678 replay_barrier $SINGLEMDS
1679 log "Fail mds for $((2 * timeout)) seconds"
1680 fail $SINGLEMDS $((2 * timeout))
1683 if at_is_enabled; then
1684 timeout=$(at_max_get mds)
1686 timeout=$(lctl get_param -n timeout)
1690 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1691 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1692 log "it took $count second"
1697 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1699 cancel_lru_locks mdc
1700 cancel_lru_locks osc
1703 local testfile_size=$(stat -c %s $TESTFILE)
1704 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1705 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1706 "got ${testfile_size}. Verifying file failed!"
1709 resetquota -u $TSTUSR
1712 # test when mds does failover, the ost still could work well
1713 # this test shouldn't trigger watchdog b=14840
1715 # Clear dmesg so watchdog is not triggered by previous
1717 do_facet ost1 dmesg -c > /dev/null
1720 test_18_sub directio
1722 # check if watchdog is triggered
1723 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1724 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1725 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1726 [ -z "$watchdog" ] || error "$watchdog"
1727 rm -f $TMP/lustre-log-${TESTNAME}.log
1729 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1733 local TESTFILE=$DIR/$tdir/$tfile
1735 setup_quota_test || error "setup quota failed with $?"
1736 trap cleanup_quota_test EXIT
1738 set_ost_qtype "ug" || error "enable ost quota failed"
1740 # bind file to a single OST
1741 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1742 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1744 echo "Set user quota (limit: ${blimit}M)"
1745 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1746 error "set user quota failed"
1747 quota_show_check b u $TSTUSR
1748 echo "Update quota limits"
1749 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1750 error "set group quota failed"
1751 quota_show_check b u $TSTUSR
1753 # first wirte might be cached
1754 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1755 cancel_lru_locks osc
1757 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1758 quota_error u $TSTUSR "Write success, expect failure"
1762 resetquota -u $TSTUSR
1764 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
1766 test_20() { # b15754
1767 local LSTR=(2g 1t 4k 3m) # limits strings
1769 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
1772 resetquota -u $TSTUSR
1774 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
1775 $MOUNT || error "could not set quota limits"
1776 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
1777 --inode-softlimit ${LSTR[2]} \
1778 --inode-hardlimit ${LSTR[3]} \
1779 $MOUNT || error "could not set quota limits"
1781 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
1782 error "bsoftlimit was not set properly"
1783 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
1784 error "bhardlimit was not set properly"
1785 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
1786 error "isoftlimit was not set properly"
1787 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
1788 error "ihardlimit was not set properly"
1790 resetquota -u $TSTUSR
1792 run_test 20 "Test if setquota specifiers work properly (b15754)"
1799 local time=$(($(date +%s) + seconds))
1800 while [ $(date +%s) -lt $time ]; do
1801 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
1805 # run for fixing bug16053, setquota shouldn't fail when writing and
1806 # deleting are happening
1808 local TESTFILE="$DIR/$tdir/$tfile"
1809 local BLIMIT=10 # 10G
1810 local ILIMIT=1000000
1812 setup_quota_test || error "setup quota failed with $?"
1813 trap cleanup_quota_test EXIT
1815 set_ost_qtype "ug" || error "Enable ost quota failed"
1817 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
1818 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
1819 error "set user quota failed"
1820 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
1821 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
1822 error "set group quota failed"
1824 # repeat writing on a 1M file
1825 test_21_sub ${TESTFILE}_1 1 30 &
1827 # repeat writing on a 128M file
1828 test_21_sub ${TESTFILE}_2 128 30 &
1831 local time=$(($(date +%s) + 30))
1833 while [ $(date +%s) -lt $time ]; do
1834 log "Set quota for $i times"
1835 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1836 -I $((ILIMIT + i)) $MOUNT ||
1837 error "Set user quota failed"
1838 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
1839 -I $((ILIMIT + i)) $MOUNT ||
1840 error "Set group quota failed"
1847 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
1849 if [ $count -gt 60 ]; then
1850 quota_error a $TSTUSR "dd should be finished!"
1854 echo "(dd_pid=$DDPID1, time=$count)successful"
1858 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
1860 if [ $count -gt 60 ]; then
1861 quota_error a $TSTUSR "dd should be finished!"
1865 echo "(dd_pid=$DDPID2, time=$count)successful"
1868 resetquota -u $TSTUSR
1869 resetquota -g $TSTUSR
1871 run_test 21 "Setquota while writing & deleting (b16053)"
1873 # enable/disable quota enforcement permanently
1875 echo "Set both mdt & ost quota type as ug"
1876 set_mdt_qtype "ug" || error "enable mdt quota failed"
1877 set_ost_qtype "ug" || error "enable ost quota failed"
1880 stopall || error "failed to stopall (1)"
1884 echo "Verify if quota is enabled"
1885 local qtype=$(mdt_quota_type)
1886 [ $qtype != "ug" ] && error "mdt quota setting is lost"
1887 qtype=$(ost_quota_type)
1888 [ $qtype != "ug" ] && error "ost quota setting is lost"
1890 echo "Set both mdt & ost quota type as none"
1891 set_mdt_qtype "none" || error "disable mdt quota failed"
1892 set_ost_qtype "none" || error "disable ost quota failed"
1895 stopall || error "failed to stopall (2)"
1900 echo "Verify if quota is disabled"
1901 qtype=$(mdt_quota_type)
1902 [ $qtype != "none" ] && error "mdt quota setting is lost"
1903 qtype=$(ost_quota_type)
1904 [ $qtype != "none" ] && error "ost quota setting is lost"
1908 run_test 22 "enable/disable quota by 'lctl conf_param'"
1911 local TESTFILE="$DIR/$tdir/$tfile"
1914 setup_quota_test || error "setup quota failed with $?"
1915 trap cleanup_quota_test EXIT
1917 set_ost_qtype "ug" || error "Enable ost quota failed"
1920 log "User quota (limit: $LIMIT MB)"
1921 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
1922 error "set quota failed"
1923 quota_show_check b u $TSTUSR
1925 $SETSTRIPE $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1926 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1928 log "Step1: trigger EDQUOT with O_DIRECT"
1929 log "Write half of file"
1930 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
1931 quota_error u $TSTUSR "(1) Write failure, expect success." \
1933 log "Write out of block quota ..."
1934 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
1935 oflag=direct conv=notrunc &&
1936 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
1940 log "Step2: rewrite should succeed"
1941 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
1942 quota_error u $TSTUSR "(3) Write failure, expect success." \
1948 local OST0_UUID=$(ostuuid_from_index 0)
1949 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
1950 [ $OST0_QUOTA_USED -ne 0 ] &&
1951 ($SHOW_QUOTA_USER; \
1952 quota_error u $TSTUSR "quota isn't released")
1954 resetquota -u $TSTUSR
1958 [ $(facet_fstype ost1) == "zfs" ] &&
1959 skip "Overwrite in place is not guaranteed to be " \
1960 "space neutral on ZFS" && return
1962 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
1963 check_whether_skip && return 0
1964 log "run for 4MB test file"
1967 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
1968 check_whether_skip && return 0
1969 log "run for 40MB test file"
1972 run_test 23 "Quota should be honored with directIO (b16125)"
1976 local TESTFILE="$DIR/$tdir/$tfile"
1978 setup_quota_test || error "setup quota failed with $?"
1979 trap cleanup_quota_test EXIT
1981 set_ost_qtype "ug" || error "enable ost quota failed"
1983 # bind file to a single OST
1984 $SETSTRIPE -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1985 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1987 echo "Set user quota (limit: ${blimit}M)"
1988 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1989 error "set quota failed"
1991 # overrun quota by root user
1992 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
1993 error "write failure, expect success"
1994 cancel_lru_locks osc
1995 sync_all_data || true
1997 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2000 resetquota -u $TSTUSR
2002 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2004 test_27a() { # b19612
2005 $LFS quota $TSTUSR $DIR &&
2006 error "lfs succeeded with no type, but should have failed"
2007 $LFS setquota $TSTUSR $DIR &&
2008 error "lfs succeeded with no type, but should have failed"
2011 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2013 test_27b() { # b20200
2014 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2015 error "lfs setquota failed with uid argument"
2016 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2017 error "lfs stequota failed with gid argument"
2018 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2019 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2020 resetquota -u $TSTUSR
2021 resetquota -g $TSTUSR
2024 run_test 27b "lfs quota/setquota should handle user/group ID (b20200)"
2029 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2030 error "lfs setquota failed"
2032 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2033 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2034 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2035 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2037 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2038 error "lfs setquota for $TSTID failed"
2040 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2041 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2042 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2043 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2045 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2046 error "total allocated inode/block limit not printed"
2048 resetquota -u $TSTUSR
2050 run_test 27c "lfs quota should support human-readable output"
2057 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2058 error "set fraction block limit failed"
2059 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2060 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2061 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2062 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2064 resetquota -u $TSTUSR
2066 run_test 27d "lfs setquota should support fraction block limit"
2070 local TESTFILE="$DIR/$tdir/$tfile"
2073 setup_quota_test || error "setup quota failed with $?"
2074 trap cleanup_quota_test EXIT
2076 set_ost_qtype "u" || error "enable ost quota failed"
2078 $SETSTRIPE $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2079 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2081 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2082 $MAX_IQ_TIME $DIR || error "set grace time failed"
2083 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2084 error "set quota failed"
2085 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2086 cancel_lru_locks osc
2088 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2089 # over-quota flag has not yet settled since we do not trigger async
2090 # events based on grace time period expiration
2092 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2093 cancel_lru_locks osc
2094 # now over-quota flag should be settled and further writes should fail
2096 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2097 error "grace times were reset"
2100 resetquota -u $TSTUSR
2101 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2102 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2104 run_test 30 "Hard limit updates should not reset grace times"
2106 # basic usage tracking for user & group
2108 local INODES=10 # 10 files
2109 local BLK_CNT=2 # of 2M each
2110 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2112 setup_quota_test || error "setup quota failed with $?"
2113 trap cleanup_quota_test EXIT
2115 # make sure the system is clean
2116 local USED=$(getquota -u $TSTID global curspace)
2118 error "Used space ($USED) for user $TSTID isn't 0."
2119 USED=$(getquota -g $TSTID global curspace)
2121 error "Used space ($USED) for group $TSTID isn't 0."
2123 echo "Write files..."
2124 for i in $(seq 0 $INODES); do
2125 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2126 error "write failed"
2127 echo "Iteration $i/$INODES completed"
2129 cancel_lru_locks osc
2130 sync; sync_all_data || true
2132 echo "Verify disk usage after write"
2133 USED=$(getquota -u $TSTID global curspace)
2134 [ $USED -lt $TOTAL_BLKS ] &&
2135 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2136 USED=$(getquota -g $TSTID global curspace)
2137 [ $USED -lt $TOTAL_BLKS ] &&
2138 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2140 echo "Verify inode usage after write"
2141 USED=$(getquota -u $TSTID global curinodes)
2142 [ $USED -lt $INODES ] &&
2143 error "Used inode for user $TSTID is $USED, expected $INODES"
2144 USED=$(getquota -g $TSTID global curinodes)
2145 [ $USED -lt $INODES ] &&
2146 error "Used inode for group $TSTID is $USED, expected $INODES"
2150 echo "Verify disk usage after delete"
2151 USED=$(getquota -u $TSTID global curspace)
2152 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2153 USED=$(getquota -u $TSTID global curinodes)
2154 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2155 USED=$(getquota -g $TSTID global curspace)
2156 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2157 USED=$(getquota -g $TSTID global curinodes)
2158 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2160 run_test 33 "Basic usage tracking for user & group"
2162 # usage transfer test for user & group
2164 local BLK_CNT=2 # 2MB
2166 setup_quota_test || error "setup quota failed with $?"
2167 trap cleanup_quota_test EXIT
2169 # make sure the system is clean
2170 local USED=$(getquota -u $TSTID global curspace)
2171 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2172 USED=$(getquota -g $TSTID global curspace)
2173 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2175 local USED=$(getquota -u $TSTID2 global curspace)
2176 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2178 echo "Write file..."
2179 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2180 error "write failed"
2181 cancel_lru_locks osc
2182 sync; sync_all_data || true
2184 echo "chown the file to user $TSTID"
2185 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2187 echo "Wait for setattr on objects finished..."
2188 wait_delete_completed
2190 BLK_CNT=$((BLK_CNT * 1024))
2192 echo "Verify disk usage for user $TSTID"
2193 USED=$(getquota -u $TSTID global curspace)
2194 [ $USED -lt $BLK_CNT ] &&
2195 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2196 USED=$(getquota -u $TSTID global curinodes)
2198 error "Used inodes for user $TSTID is $USED, expected 1"
2200 echo "chgrp the file to group $TSTID"
2201 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2203 echo "Wait for setattr on objects finished..."
2204 wait_delete_completed
2206 echo "Verify disk usage for group $TSTID"
2207 USED=$(getquota -g $TSTID global curspace)
2208 [ $USED -ge $BLK_CNT ] ||
2209 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2210 USED=$(getquota -g $TSTID global curinodes)
2212 error "Used inodes for group $TSTID is $USED, expected 1"
2214 # chown won't change the ost object group. LU-4345 */
2215 echo "chown the file to user $TSTID2"
2216 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2218 echo "Wait for setattr on objects finished..."
2219 wait_delete_completed
2221 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2222 USED=$(getquota -u $TSTID2 global curspace)
2223 [ $USED -lt $BLK_CNT ] &&
2224 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2225 USED=$(getquota -u $TSTID global curspace)
2227 error "Used space for user $TSTID is $USED, expected 0"
2228 USED=$(getquota -g $TSTID global curspace)
2229 [ $USED -lt $BLK_CNT ] &&
2230 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2234 run_test 34 "Usage transfer for user & group"
2236 # usage is still accessible across restart
2238 local BLK_CNT=2 # 2 MB
2240 setup_quota_test || error "setup quota failed with $?"
2241 trap cleanup_quota_test EXIT
2243 echo "Write file..."
2244 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2245 error "write failed"
2246 cancel_lru_locks osc
2247 sync; sync_all_data || true
2249 echo "Save disk usage before restart"
2250 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2251 [ $ORIG_USR_SPACE -eq 0 ] &&
2252 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2253 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2254 [ $ORIG_USR_INODES -eq 0 ] &&
2255 error "Used inodes for user $TSTID is 0, expected 1"
2256 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2257 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2258 [ $ORIG_GRP_SPACE -eq 0 ] &&
2259 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2260 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2261 [ $ORIG_GRP_INODES -eq 0 ] &&
2262 error "Used inodes for group $TSTID is 0, expected 1"
2263 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2266 local ORIG_REFORMAT=$REFORMAT
2268 cleanup_and_setup_lustre
2269 REFORMAT=$ORIG_REFORMAT
2272 echo "Verify disk usage after restart"
2273 local USED=$(getquota -u $TSTID global curspace)
2274 [ $USED -eq $ORIG_USR_SPACE ] ||
2275 error "Used space for user $TSTID changed from " \
2276 "$ORIG_USR_SPACE to $USED"
2277 USED=$(getquota -u $TSTID global curinodes)
2278 [ $USED -eq $ORIG_USR_INODES ] ||
2279 error "Used inodes for user $TSTID changed from " \
2280 "$ORIG_USR_INODES to $USED"
2281 USED=$(getquota -g $TSTID global curspace)
2282 [ $USED -eq $ORIG_GRP_SPACE ] ||
2283 error "Used space for group $TSTID changed from " \
2284 "$ORIG_GRP_SPACE to $USED"
2285 USED=$(getquota -g $TSTID global curinodes)
2286 [ $USED -eq $ORIG_GRP_INODES ] ||
2287 error "Used inodes for group $TSTID changed from " \
2288 "$ORIG_GRP_INODES to $USED"
2290 # check if the vfs_dq_init() is called before writing
2291 echo "Append to the same file..."
2292 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2293 error "write failed"
2294 cancel_lru_locks osc
2295 sync; sync_all_data || true
2297 echo "Verify space usage is increased"
2298 USED=$(getquota -u $TSTID global curspace)
2299 [ $USED -gt $ORIG_USR_SPACE ] ||
2300 error "Used space for user $TSTID isn't increased" \
2301 "orig:$ORIG_USR_SPACE, now:$USED"
2302 USED=$(getquota -g $TSTID global curspace)
2303 [ $USED -gt $ORIG_GRP_SPACE ] ||
2304 error "Used space for group $TSTID isn't increased" \
2305 "orig:$ORIG_GRP_SPACE, now:$USED"
2309 run_test 35 "Usage is still accessible across reboot"
2311 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2314 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2315 skip "Old server doesn't have LU-5006 fix." && return
2317 setup_quota_test || error "setup quota failed with $?"
2318 trap cleanup_quota_test EXIT
2320 # make sure the system is clean
2321 local USED=$(getquota -u $TSTID global curspace)
2323 error "Used space ($USED) for user $TSTID isn't 0."
2325 # create file with MDS_OPEN_DELAY_CREATE flag
2326 $SETSTRIPE -c 1 -i 0 $DIR/$tdir/$tfile ||
2327 error "Create file failed"
2329 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2330 oflag=sync || error "Write file failed"
2332 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2334 # wait for setattr on objects finished..."
2335 wait_delete_completed
2337 USED=$(getquota -u $TSTID global curspace)
2338 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2342 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2346 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2347 skip "Old server doesn't have LU-8801 fix." && return
2349 [ "$UID" != 0 ] && skip_env "must run as root" && return
2351 setup_quota_test || error "setup quota failed with $?"
2352 trap cleanup_quota_test EXIT
2354 # make sure the system is clean
2355 local USED=$(getquota -u $TSTID global curspace)
2357 error "Used space ($USED) for user $TSTID isn't 0."
2358 USED=$(getquota -u $TSTID2 global curspace)
2360 error "Used space ($USED) for user $TSTID2 isn't 0."
2362 local TESTFILE="$DIR/$tdir/$tfile"
2363 local file_cnt=10000
2365 # Generate id entries in accounting file
2366 echo "Create $file_cnt files..."
2367 for i in `seq $file_cnt`; do
2369 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i
2371 cancel_lru_locks osc
2372 sync; sync_all_data || true
2374 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2375 procf=${procf}.quota_slave.acct_user
2378 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
2379 echo "Found $acct_cnt id entries"
2381 [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
2385 run_test 38 "Quota accounting iterator doesn't skip id entries"
2389 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
2395 check_and_cleanup_lustre
2396 export QUOTA_AUTO=$QUOTA_AUTO_OLD