3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 # Does e2fsprogs support quota feature?
47 if [ "$mds1_FSTYPE" == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip_env "e2fsprogs doesn't support quota"
53 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
55 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
60 QUOTA_AUTO_OLD=$QUOTA_AUTO
63 check_and_setup_lustre
65 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
67 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
68 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
69 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
70 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
71 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
72 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
73 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
74 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
79 local fail_val=${3:-0}
83 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
84 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
85 ost) NODES="$(comma_list $(osts_nodes))";;
88 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
94 lfs project $* || error "lfs project $* failed"
97 RUNAS="runas -u $TSTID -g $TSTID"
98 RUNAS2="runas -u $TSTID2 -g $TSTID2"
99 DD="dd if=/dev/zero bs=1M"
103 # clear quota limits for a user or a group
104 # usage: resetquota -u username
105 # resetquota -g groupname
106 # resetquota -p projid
109 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
110 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
111 error "resetquota: wrong specifier $1 passed"
113 if [ $1 == "-p" ]; then
114 is_project_quota_supported || return 0
117 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
118 error "clear quota for [type:$1 name:$2] failed"
119 # give a chance to slave to release space
127 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
128 $LFS quota -v -u $local_id $DIR
129 log "Files for user ($local_id):"
130 ($LFS find --user $local_id $DIR | head -n 4 |
131 xargs stat 2>/dev/null)
134 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
135 $LFS quota -v -g $local_id $DIR
136 log "Files for group ($local_id):"
137 ($LFS find --group $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
142 $LFS quota -v -p $TSTPRJID $DIR
143 log "Files for project ($TSTPRJID):"
144 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
145 xargs stat 2>/dev/null)
161 # get quota for a user or a group
162 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
163 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
168 sync_all_data > /dev/null 2>&1 || true
170 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
171 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
172 error "getquota: wrong u/g/p specifier $1 passed"
185 *) error "unknown quota parameter $4";;
188 [ "$uuid" = "global" ] && uuid=$DIR
190 $LFS quota -v "$1" "$2" $DIR |
191 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
192 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
197 # usage: set_mdt_qtype ugp|u|g|p|none
201 local mdts=$(get_facets MDS)
203 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
204 qtype=$(tr -d 'p' <<<$qtype)
206 if [[ $PERM_CMD == *"set_param -P"* ]]; then
207 do_facet mgs $PERM_CMD \
208 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
210 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
212 # we have to make sure each MDT received config changes
213 for mdt in ${mdts//,/ }; do
215 cmd="$LCTL get_param -n "
216 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
217 cmd=${cmd}.quota_slave.enabled
219 if $(facet_up $mdt); then
220 wait_update_facet $mdt "$cmd" "$qtype" || return 1
227 # usage: set_ost_qtype ugp|u|g|p|none
231 local osts=$(get_facets OST)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD == *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
242 # we have to make sure each OST received config changes
243 for ost in ${osts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $ost); then
250 wait_update_facet $ost "$cmd" "$qtype" || return 1
256 wait_reintegration() {
260 local result="glb[1],slv[1],reint[0]"
265 if [ $ntype == "mdt" ]; then
266 tgts=$(get_facets MDS)
268 tgts=$(get_facets OST)
271 for tgt in ${tgts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
275 cmd=${cmd}.quota_slave.info
277 if $(facet_up $tgt); then
278 wait_update_facet $tgt "$cmd |
279 grep "$qtype" | awk '{ print \\\$3 }'" \
280 "$result" $max || return 1
290 if [[ "$qtype" =~ "u" ]]; then
291 wait_reintegration "mdt" "user" $max || return 1
294 if [[ "$qtype" =~ "g" ]]; then
295 wait_reintegration "mdt" "group" $max || return 1
298 if [[ "$qtype" =~ "p" ]]; then
299 ! is_project_quota_supported && return 0
300 wait_reintegration "mdt" "project" $max || return 1
309 if [[ "$qtype" =~ "u" ]]; then
310 wait_reintegration "ost" "user" $max || return 1
313 if [[ "$qtype" =~ "g" ]]; then
314 wait_reintegration "ost" "group" $max || return 1
317 if [[ "$qtype" =~ "p" ]]; then
318 ! is_project_quota_supported && return 0
319 wait_reintegration "ost" "project" $max || return 1
327 local extrasleep=${3:-5}
333 *) error "get_grace_time: Invalid quota type: $qtype"
338 time=$(lfs quota -$qtype $qarg $DIR|
339 awk 'NR == 3{ print $5 }'| sed 's/s$//')
342 time=$(lfs quota -$qtype $qarg $DIR|
343 awk 'NR == 3{ print $9 }'| sed 's/s$//')
346 error "Unknown quota type: $flavour"
350 echo "Sleep through grace ..."
351 [ "$time" == "-" ] &&
352 error "Grace timeout was not set or quota not exceeded"
353 if [ "$time" == "none" ]; then
354 echo "...Grace timeout already expired"
356 let time+=$extrasleep
357 echo "...sleep $time seconds"
363 wait_delete_completed
364 echo "Creating test directory"
365 mkdir $DIR/$tdir || return 1
366 chmod 0777 $DIR/$tdir || return 2
367 # always clear fail_loc in case of fail_loc isn't cleared
368 # properly when previous test failed
369 lustre_fail mds_ost 0
372 cleanup_quota_test() {
374 echo "Delete files..."
376 echo "Wait for unlink objects finished..."
377 wait_delete_completed
378 sync_all_data || true
388 $LFS quota -v -$ugp $qid $DIR
390 if [ "$bf" == "a" -o "$bf" == "b" ]; then
391 usage=$(getquota -$ugp $qid global curspace)
392 if [ -z $usage ]; then
393 quota_error $ugp $qid \
394 "Query block quota failed ($ugp:$qid)."
396 [ $usage -ne 0 ] && quota_log $ugp $qid \
397 "Block quota isn't 0 ($ugp:$qid:$usage)."
401 if [ "$bf" == "a" -o "$bf" == "f" ]; then
402 usage=$(getquota -$ugp $qid global curinodes)
403 if [ -z $usage ]; then
404 quota_error $ugp $qid \
405 "Query file quota failed ($ugp:$qid)."
407 [ $usage -ne 0 ] && quota_log $ugp $qid \
408 "File quota isn't 0 ($ugp:$qid:$usage)."
413 project_quota_enabled () {
415 for num in $(seq $MDSCOUNT); do
416 do_facet mds$num $DEBUGFS -R features $(mdsdevname $num) |
417 grep -q project || rc=1
419 for num in $(seq $OSTCOUNT); do
420 do_facet ost$num $DEBUGFS -R features $(ostdevname $num) |
421 grep -q project || rc=1
423 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
427 project_quota_enabled || enable_project_quota
429 reset_quota_settings() {
430 resetquota -u $TSTUSR
431 resetquota -g $TSTUSR
432 resetquota -u $TSTUSR2
433 resetquota -g $TSTUSR2
434 resetquota -p $TSTPRJID
439 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
444 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
445 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
446 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
447 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
449 test_quota_performance() {
450 local TESTFILE="$DIR/$tdir/$tfile-0"
451 local size=$1 # in MB
452 local stime=$(date +%s)
453 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
454 quota_error u $TSTUSR "write failure"
455 local etime=$(date +%s)
456 delta=$((etime - stime))
457 if [ $delta -gt 0 ]; then
458 rate=$((size * 1024 / delta))
459 if [ "$mds1_FSTYPE" = zfs ]; then
460 # LU-2872 - see LU-2887 for fix
462 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
464 [ $rate -gt 1024 ] ||
465 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
471 # test basic quota performance b=21696
474 [ "$SLOW" = "no" ] && MB=10
476 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
477 [ $free_space -le $((MB * 1024)) ] &&
478 skip "not enough space ${free_space} KB, " \
479 "required $((MB * 1024)) KB"
480 setup_quota_test || error "setup quota failed with $?"
481 trap cleanup_quota_test EXIT
483 set_ost_qtype "none" || error "disable ost quota failed"
484 test_quota_performance $MB
486 set_ost_qtype $QTYPE || error "enable ost quota failed"
487 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
488 error "set quota failed"
489 test_quota_performance $MB
493 run_test 0 "Test basic quota performance"
495 # test block hardlimit
498 local TESTFILE="$DIR/$tdir/$tfile-0"
500 setup_quota_test || error "setup quota failed with $?"
501 trap cleanup_quota_test EXIT
504 set_ost_qtype $QTYPE || error "enable ost quota failed"
507 log "User quota (block hardlimit:$LIMIT MB)"
508 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
509 error "set user quota failed"
511 # make sure the system is clean
512 local USED=$(getquota -u $TSTUSR global curspace)
513 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
515 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
516 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
519 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
520 quota_error u $TSTUSR "user write failure, but expect success"
521 log "Write out of block quota ..."
522 # this time maybe cache write, ignore it's failure
523 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
524 # flush cache, ensure noquota flag is set on client
526 sync; sync_all_data || true
527 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
528 quota_error u $TSTUSR "user write success, but expect EDQUOT"
531 wait_delete_completed || error "wait_delete_completed failed"
532 sync_all_data || true
533 USED=$(getquota -u $TSTUSR global curspace)
534 [ $USED -ne 0 ] && quota_error u $TSTUSR \
535 "user quota isn't released after deletion"
536 resetquota -u $TSTUSR
539 log "--------------------------------------"
540 log "Group quota (block hardlimit:$LIMIT MB)"
541 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
542 error "set group quota failed"
544 TESTFILE="$DIR/$tdir/$tfile-1"
545 # make sure the system is clean
546 USED=$(getquota -g $TSTUSR global curspace)
547 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
549 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
550 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
553 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
554 quota_error g $TSTUSR "Group write failure, but expect success"
555 log "Write out of block quota ..."
556 # this time maybe cache write, ignore it's failure
557 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
559 sync; sync_all_data || true
560 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
561 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
563 wait_delete_completed || error "wait_delete_completed failed"
564 sync_all_data || true
565 USED=$(getquota -g $TSTUSR global curspace)
566 [ $USED -ne 0 ] && quota_error g $TSTUSR \
567 "Group quota isn't released after deletion"
568 resetquota -g $TSTUSR
570 if ! is_project_quota_supported; then
571 echo "Project quota is not supported"
576 TESTFILE="$DIR/$tdir/$tfile-2"
577 # make sure the system is clean
578 USED=$(getquota -p $TSTPRJID global curspace)
580 error "used space($USED) for project $TSTPRJID isn't 0"
583 log "--------------------------------------"
584 log "Project quota (block hardlimit:$LIMIT mb)"
585 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
586 error "set project quota failed"
588 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
589 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
590 change_project -p $TSTPRJID $TESTFILE
593 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
594 "project write failure, but expect success"
595 log "write out of block quota ..."
596 # this time maybe cache write, ignore it's failure
597 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
599 sync; sync_all_data || true
600 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
601 $TSTPRJID "project write success, but expect EDQUOT"
606 USED=$(getquota -p $TSTPRJID global curspace)
607 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
608 "project quota isn't released after deletion"
610 run_test 1 "Block hard limit (normal use and out of quota)"
612 # test inode hardlimit
614 local LIMIT=$((1024 * 1024)) # 1M inodes
615 local TESTFILE="$DIR/$tdir/$tfile-0"
617 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
619 local FREE_INODES=$(mdt_free_inodes 0)
620 echo "$FREE_INODES free inodes on master MDT"
621 [ $FREE_INODES -lt $LIMIT ] &&
622 skip "not enough free inodes $FREE_INODES required $LIMIT"
624 setup_quota_test || error "setup quota failed with $?"
625 trap cleanup_quota_test EXIT
628 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
631 log "User quota (inode hardlimit:$LIMIT files)"
632 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
633 error "set user quota failed"
635 # make sure the system is clean
636 local USED=$(getquota -u $TSTUSR global curinodes)
637 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
639 log "Create $LIMIT files ..."
640 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
641 quota_error u $TSTUSR "user create failure, but expect success"
642 log "Create out of file quota ..."
643 $RUNAS touch ${TESTFILE}_xxx &&
644 quota_error u $TSTUSR "user create success, but expect EDQUOT"
647 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
648 rm -f ${TESTFILE}_xxx
649 wait_delete_completed
651 USED=$(getquota -u $TSTUSR global curinodes)
652 [ $USED -ne 0 ] && quota_error u $TSTUSR \
653 "user quota isn't released after deletion"
654 resetquota -u $TSTUSR
657 log "--------------------------------------"
658 log "Group quota (inode hardlimit:$LIMIT files)"
659 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
660 error "set group quota failed"
662 TESTFILE=$DIR/$tdir/$tfile-1
663 # make sure the system is clean
664 USED=$(getquota -g $TSTUSR global curinodes)
665 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
667 log "Create $LIMIT files ..."
668 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
669 quota_error g $TSTUSR "group create failure, but expect success"
670 log "Create out of file quota ..."
671 $RUNAS touch ${TESTFILE}_xxx &&
672 quota_error g $TSTUSR "group create success, but expect EDQUOT"
675 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
676 rm -f ${TESTFILE}_xxx
677 wait_delete_completed
679 USED=$(getquota -g $TSTUSR global curinodes)
680 [ $USED -ne 0 ] && quota_error g $TSTUSR \
681 "user quota isn't released after deletion"
683 resetquota -g $TSTUSR
684 ! is_project_quota_supported && cleanup_quota_test &&
685 echo "Skip project quota is not supported" && return 0
688 log "--------------------------------------"
689 log "Project quota (inode hardlimit:$LIMIT files)"
690 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
691 error "set project quota failed"
693 TESTFILE=$DIR/$tdir/$tfile-1
694 # make sure the system is clean
695 USED=$(getquota -p $TSTPRJID global curinodes)
697 error "Used inodes($USED) for project $TSTPRJID isn't 0"
699 change_project -sp $TSTPRJID $DIR/$tdir
700 log "Create $LIMIT files ..."
701 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
702 $TSTPRJID "project create fail, but expect success"
703 log "Create out of file quota ..."
704 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
705 "project create success, but expect EDQUOT"
706 change_project -C $DIR/$tdir
709 USED=$(getquota -p $TSTPRJID global curinodes)
710 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
711 "project quota isn't released after deletion"
714 run_test 2 "File hard limit (normal use and out of quota)"
724 trap cleanup_quota_test EXIT
726 $LFS setstripe $TESTFILE -c 1 -i 0
727 chown $TSTUSR.$TSTUSR $TESTFILE
728 [ "$qtype" == "p" ] && is_project_quota_supported &&
729 change_project -p $TSTPRJID $TESTFILE
731 echo "Write up to soft limit"
732 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
733 quota_error a $TSTUSR "write failure, but expect success"
734 OFFSET=$((LIMIT * 1024))
737 echo "Write to exceed soft limit"
738 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
739 quota_error a $TSTUSR "write failure, but expect success"
740 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
746 $SHOW_QUOTA_INFO_USER
747 $SHOW_QUOTA_INFO_GROUP
748 $SHOW_QUOTA_INFO_PROJID
750 echo "Write before timer goes off"
751 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
752 quota_error a $TSTUSR "write failure, but expect success"
753 OFFSET=$((OFFSET + 1024))
756 wait_grace_time $qtype "block"
761 $SHOW_QUOTA_INFO_USER
762 $SHOW_QUOTA_INFO_GROUP
763 $SHOW_QUOTA_INFO_PROJID
765 echo "Write after timer goes off"
766 # maybe cache write, ignore.
767 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
768 OFFSET=$((OFFSET + 1024))
770 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
771 quota_error a $TSTUSR "write success, but expect EDQUOT"
776 $SHOW_QUOTA_INFO_USER
777 $SHOW_QUOTA_INFO_GROUP
778 $SHOW_QUOTA_INFO_PROJID
780 echo "Unlink file to stop timer"
782 wait_delete_completed
783 sync_all_data || true
788 $SHOW_QUOTA_INFO_USER
789 $SHOW_QUOTA_INFO_GROUP
790 $SHOW_QUOTA_INFO_PROJID
792 $LFS setstripe $TESTFILE -c 1 -i 0
793 chown $TSTUSR.$TSTUSR $TESTFILE
794 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
797 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
798 quota_error a $TSTUSR "write failure, but expect success"
806 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
809 local TESTFILE=$DIR/$tdir/$tfile-0
811 # get minimum soft qunit size
812 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
813 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
815 set_ost_qtype $QTYPE || error "enable ost quota failed"
817 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
818 # make sure the system is clean
819 local USED=$(getquota -u $TSTUSR global curspace)
820 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
822 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
823 $MAX_IQ_TIME $DIR || error "set user grace time failed"
824 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
825 error "set user quota failed"
827 test_block_soft $TESTFILE $GRACE $LIMIT "u"
829 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
830 TESTFILE=$DIR/$tdir/$tfile-1
831 # make sure the system is clean
832 USED=$(getquota -g $TSTUSR global curspace)
833 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
835 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
836 $MAX_IQ_TIME $DIR || error "set group grace time failed"
837 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
838 error "set group quota failed"
840 test_block_soft $TESTFILE $GRACE $LIMIT "g"
842 if is_project_quota_supported; then
843 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
844 TESTFILE=$DIR/$tdir/$tfile-2
845 # make sure the system is clean
846 USED=$(getquota -p $TSTPRJID global curspace)
847 [ $USED -ne 0 ] && error \
848 "Used space($USED) for project $TSTPRJID isn't 0."
850 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
852 error "set project grace time failed"
853 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
854 $DIR || error "set project quota failed"
856 test_block_soft $TESTFILE $GRACE $LIMIT "p"
857 resetquota -p $TSTPRJID
858 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
860 error "restore project grace time failed"
864 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
865 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
866 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
867 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
869 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
878 trap cleanup_quota_test EXIT
879 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
881 echo "Create files to exceed soft limit"
882 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
883 quota_error a $TSTUSR "create failure, but expect success"
884 local trigger_time=$(date +%s)
886 sync_all_data || true
888 local cur_time=$(date +%s)
889 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
890 error "Passed grace time $grace, $trigger_time, $cur_time"
892 echo "Create file before timer goes off"
893 $RUNAS touch ${TESTFILE}_before ||
894 quota_error a $TSTUSR "failed create before timer expired," \
895 "but expect success. $trigger_time, $cur_time"
896 sync_all_data || true
898 wait_grace_time $qtype "file"
903 $SHOW_QUOTA_INFO_USER
904 $SHOW_QUOTA_INFO_GROUP
905 $SHOW_QUOTA_INFO_PROJID
907 echo "Create file after timer goes off"
908 # There is a window that space is accounted in the quota usage but
909 # hasn't been decreased from the pending write, if we acquire quota
910 # in this window, we'll acquire more than we needed.
911 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
912 sync_all_data || true
913 $RUNAS touch ${TESTFILE}_after_3 &&
914 quota_error a $TSTUSR "create after timer expired," \
916 sync_all_data || true
921 $SHOW_QUOTA_INFO_USER
922 $SHOW_QUOTA_INFO_GROUP
923 $SHOW_QUOTA_INFO_PROJID
925 echo "Unlink files to stop timer"
926 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
927 wait_delete_completed
930 $RUNAS touch ${TESTFILE}_xxx ||
931 quota_error a $TSTUSR "touch after timer stop failure," \
933 sync_all_data || true
941 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
942 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
943 local TESTFILE=$DIR/$tdir/$tfile-0
946 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
948 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
949 # make sure the system is clean
950 local USED=$(getquota -u $TSTUSR global curinodes)
951 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
953 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
954 $GRACE $DIR || error "set user grace time failed"
955 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
956 error "set user quota failed"
958 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
960 test_file_soft $TESTFILE $LIMIT $GRACE "u"
962 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
963 # make sure the system is clean
964 USED=$(getquota -g $TSTUSR global curinodes)
965 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
967 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
968 $GRACE $DIR || error "set group grace time failed"
969 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
970 error "set group quota failed"
971 TESTFILE=$DIR/$tdir/$tfile-1
973 test_file_soft $TESTFILE $LIMIT $GRACE "g"
975 if is_project_quota_supported; then
976 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
977 # make sure the system is clean
978 USED=$(getquota -p $TSTPRJID global curinodes)
979 [ $USED -ne 0 ] && error \
980 "Used space($USED) for project $TSTPRJID isn't 0."
982 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
983 $GRACE $DIR || error "set project grace time failed"
984 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
985 error "set project quota failed"
987 TESTFILE=$DIR/$tdir/$tfile-1
988 # one less than limit, because of parent directory included.
989 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
990 resetquota -p $TSTPRJID
991 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
993 error "restore project grace time failed"
997 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
998 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
999 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1000 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1002 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1005 local GR_STR1="1w3d"
1006 local GR_STR2="1000s"
1008 local GR_STR4="1w2d3h4m5s"
1010 local GR_STR6="18446744073709551615"
1013 wait_delete_completed
1015 # test of valid grace strings handling
1016 echo "Valid grace strings test"
1017 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1018 $GR_STR2 $DIR || error "set user grace time failed"
1019 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1020 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1021 $GR_STR4 $DIR || error "set group grace time quota failed"
1022 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1024 # test of invalid grace strings handling
1025 echo " Invalid grace strings test"
1026 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1027 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1028 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1032 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1033 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1034 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1035 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1037 run_test 4b "Grace time strings handling"
1039 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1041 local BLIMIT=10 # 10M
1042 local ILIMIT=10 # 10 inodes
1044 setup_quota_test || error "setup quota failed with $?"
1045 trap cleanup_quota_test EXIT
1047 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1048 set_ost_qtype $QTYPE || error "enable ost quota failed"
1050 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1051 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1052 error "set user quota failed"
1053 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1054 if is_project_quota_supported; then
1055 error "set group quota failed"
1056 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1057 -I $ILIMIT $DIR || error "set project quota failed"
1060 # make sure the system is clean
1061 local USED=$(getquota -u $TSTUSR global curinodes)
1062 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1063 USED=$(getquota -g $TSTUSR global curinodes)
1064 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1065 USED=$(getquota -u $TSTUSR global curspace)
1066 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1067 USED=$(getquota -g $TSTUSR global curspace)
1068 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1069 if is_project_quota_supported; then
1070 USED=$(getquota -p $TSTPRJID global curinodes)
1072 error "Used inode($USED) for project $TSTPRJID isn't 0."
1073 USED=$(getquota -p $TSTPRJID global curspace)
1075 error "Used block($USED) for project $TSTPRJID isn't 0."
1078 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1079 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1080 error "create failure, expect success"
1081 if is_project_quota_supported; then
1082 touch $DIR/$tdir/$tfile-0_1
1083 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1085 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1086 error "write failure, expect success"
1088 echo "Chown files to $TSTUSR.$TSTUSR ..."
1089 for i in $(seq 0 $ILIMIT); do
1090 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1091 quota_error a $TSTUSR "chown failure, expect success"
1095 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1096 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1099 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1101 # test dropping acquire request on master
1105 # Clear dmesg so watchdog is not triggered by previous
1107 do_facet ost1 dmesg -c > /dev/null
1109 setup_quota_test || error "setup quota failed with $?"
1110 trap cleanup_quota_test EXIT
1112 # make sure the system is clean
1113 local USED=$(getquota -u $TSTUSR global curspace)
1114 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1116 # make sure no granted quota on ost
1117 set_ost_qtype $QTYPE || error "enable ost quota failed"
1118 resetquota -u $TSTUSR
1120 # create file for $TSTUSR
1121 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1122 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1123 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1125 # create file for $TSTUSR2
1126 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1127 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1128 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1130 # cache per-ID lock for $TSTUSR on slave
1131 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1132 error "set quota failed"
1133 $RUNAS $DD of=$TESTFILE count=1 ||
1134 error "write $TESTFILE failure, expect success"
1135 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1136 error "write $TESTFILE2 failure, expect success"
1138 if at_is_enabled; then
1139 at_max_saved=$(at_max_get ost1)
1140 at_max_set $TIMEOUT ost1
1142 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1143 # DQACQ is sent, which makes at_max to take effect
1144 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1147 wait_delete_completed
1151 sync_all_data || true
1153 #define QUOTA_DQACQ 601
1154 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1155 lustre_fail mds 0x513 601
1157 do_facet ost1 $LCTL set_param \
1158 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1160 # write to un-enforced ID ($TSTUSR2) should succeed
1161 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1162 error "write failure, expect success"
1164 # write to enforced ID ($TSTUSR) in background, exceeding limit
1165 # to make sure DQACQ is sent
1166 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1169 # watchdog timer uses a factor of 2
1170 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1171 sleep $((TIMEOUT * 2 + 1))
1173 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1175 # write should be blocked and never finished
1176 if ! ps -p $DDPID > /dev/null 2>&1; then
1178 error "write finished incorrectly!"
1183 # no watchdog is triggered
1184 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1185 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1186 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1187 [ -z "$watchdog" ] || error "$watchdog"
1189 rm -f $TMP/lustre-log-${TESTNAME}.log
1191 # write should continue then fail with EDQUOT
1195 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1196 if [ $count -ge 240 ]; then
1197 quota_error u $TSTUSR "dd not finished in $count secs"
1199 count=$((count + 1))
1200 if [ $((count % 30)) -eq 0 ]; then
1201 c_size=$(stat -c %s $TESTFILE)
1202 echo "Waiting $count secs. $c_size"
1210 run_test 6 "Test dropping acquire request on master"
1212 # quota reintegration (global index)
1214 local TESTFILE=$DIR/$tdir/$tfile
1215 local LIMIT=20 # 20M
1217 [ "$SLOW" = "no" ] && LIMIT=5
1219 setup_quota_test || error "setup quota failed with $?"
1220 trap cleanup_quota_test EXIT
1222 # make sure the system is clean
1223 local USED=$(getquota -u $TSTUSR global curspace)
1224 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1226 # make sure no granted quota on ost1
1227 set_ost_qtype $QTYPE || error "enable ost quota failed"
1228 resetquota -u $TSTUSR
1229 set_ost_qtype "none" || error "disable ost quota failed"
1231 local OSTUUID=$(ostuuid_from_index 0)
1232 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1234 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1237 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1238 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1243 echo "Enable quota & set quota limit for $TSTUSR"
1244 set_ost_qtype $QTYPE || error "enable ost quota failed"
1245 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1246 error "set quota failed"
1248 echo "Start ost1..."
1249 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1252 wait_ost_reint $QTYPE || error "reintegration failed"
1254 # hardlimit should have been fetched by slave during global
1255 # reintegration, write will exceed quota
1256 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1257 quota_error u $TSTUSR "write success, but expect EDQUOT"
1260 wait_delete_completed
1261 sync_all_data || true
1267 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1268 error "clear quota failed"
1270 echo "Start ost1..."
1271 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1274 wait_ost_reint $QTYPE || error "reintegration failed"
1276 # hardlimit should be cleared on slave during reintegration
1277 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1278 quota_error u $TSTUSR "write error, but expect success"
1282 run_test 7a "Quota reintegration (global index)"
1284 # quota reintegration (slave index)
1287 local TESTFILE=$DIR/$tdir/$tfile
1289 setup_quota_test || error "setup quota failed with $?"
1290 trap cleanup_quota_test EXIT
1292 # make sure the system is clean
1293 local USED=$(getquota -u $TSTUSR global curspace)
1294 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1296 # make sure no granted quota on ost1
1297 set_ost_qtype $QTYPE || error "enable ost quota failed"
1298 resetquota -u $TSTUSR
1299 set_ost_qtype "none" || error "disable ost quota failed"
1301 local OSTUUID=$(ostuuid_from_index 0)
1302 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1304 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1307 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1308 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1310 # consume some space to make sure the granted space will not
1311 # be released during reconciliation
1312 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1313 error "consume space failure, expect success"
1315 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1316 lustre_fail mds 0xa02
1318 set_ost_qtype $QTYPE || error "enable ost quota failed"
1319 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1320 error "set quota failed"
1322 # ignore the write error
1323 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1325 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1329 echo "Restart ost to trigger reintegration..."
1331 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1334 wait_ost_reint $QTYPE || error "reintegration failed"
1336 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1337 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1342 run_test 7b "Quota reintegration (slave index)"
1344 # quota reintegration (restart mds during reintegration)
1346 local LIMIT=20 # 20M
1347 local TESTFILE=$DIR/$tdir/$tfile
1349 [ "$SLOW" = "no" ] && LIMIT=5
1351 setup_quota_test || error "setup quota failed with $?"
1352 trap cleanup_quota_test EXIT
1354 # make sure the system is clean
1355 local USED=$(getquota -u $TSTUSR global curspace)
1356 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1358 set_ost_qtype "none" || error "disable ost quota failed"
1359 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1360 error "set quota failed"
1362 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1363 lustre_fail ost 0xa03
1366 set_ost_qtype $QTYPE || error "enable ost quota failed"
1367 # trigger reintegration
1368 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1369 procf=${procf}quota_slave.force_reint
1370 do_facet ost1 $LCTL set_param $procf=1 ||
1371 error "force reintegration failed"
1379 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1382 # wait longer than usual to make sure the reintegration
1383 # is triggered by quota wb thread.
1384 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1386 # hardlimit should have been fetched by slave during global
1387 # reintegration, write will exceed quota
1388 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1389 quota_error u $TSTUSR "write success, but expect EDQUOT"
1393 run_test 7c "Quota reintegration (restart mds during reintegration)"
1395 # Quota reintegration (Transfer index in multiple bulks)
1397 local TESTFILE=$DIR/$tdir/$tfile
1398 local TESTFILE1="$DIR/$tdir/$tfile"-1
1401 setup_quota_test || error "setup quota failed with $?"
1402 trap cleanup_quota_test EXIT
1404 set_ost_qtype "none" || error "disable ost quota failed"
1405 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1406 error "set quota for $TSTUSR failed"
1407 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1408 error "set quota for $TSTUSR2 failed"
1410 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1411 lustre_fail mds 0x608 0
1413 # enable quota to tirgger reintegration
1414 set_ost_qtype "u" || error "enable ost quota failed"
1415 wait_ost_reint "u" || error "reintegration failed"
1419 # hardlimit should have been fetched by slave during global
1420 # reintegration, write will exceed quota
1421 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1422 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1424 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1425 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1429 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1431 # quota reintegration (inode limits)
1433 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1435 # LU-2435: skip this quota test if underlying zfs version has not
1436 # supported native dnode accounting
1437 [ "$mds1_FSTYPE" == zfs ] && {
1438 local F="feature@userobj_accounting"
1439 local pool=$(zpool_name mds1)
1440 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1442 [[ "$feature" != *" active "* ]] &&
1443 skip "requires zpool with active userobj_accounting"
1446 local ilimit=$((1024 * 2)) # 2k inodes
1447 local TESTFILE=$DIR/${tdir}-1/$tfile
1449 setup_quota_test || error "setup quota failed with $?"
1450 trap cleanup_quota_test EXIT
1452 # make sure the system is clean
1453 local USED=$(getquota -u $TSTUSR global curinodes)
1454 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1456 # make sure no granted quota on mdt1
1457 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1458 resetquota -u $TSTUSR
1459 set_mdt_qtype "none" || error "disable mdt quota failed"
1461 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1462 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1463 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1466 echo "Stop mds${MDSCOUNT}..."
1469 echo "Enable quota & set quota limit for $TSTUSR"
1470 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1471 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1472 error "set quota failed"
1474 echo "Start mds${MDSCOUNT}..."
1475 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1478 wait_mdt_reint $QTYPE || error "reintegration failed"
1480 echo "create remote dir"
1481 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1482 error "create remote dir failed"
1483 chmod 0777 $DIR/${tdir}-1
1485 # hardlimit should have been fetched by slave during global
1486 # reintegration, create will exceed quota
1487 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1488 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1490 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1491 wait_delete_completed
1492 sync_all_data || true
1494 echo "Stop mds${MDSCOUNT}..."
1497 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1498 error "clear quota failed"
1500 echo "Start mds${MDSCOUNT}..."
1501 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1504 wait_mdt_reint $QTYPE || error "reintegration failed"
1506 # hardlimit should be cleared on slave during reintegration
1507 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1508 quota_error u $TSTUSR "create failed, expect success"
1510 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1511 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1515 run_test 7e "Quota reintegration (inode limits)"
1517 # run dbench with quota enabled
1519 local BLK_LIMIT="100g" #100G
1520 local FILE_LIMIT=1000000
1522 setup_quota_test || error "setup quota failed with $?"
1523 trap cleanup_quota_test EXIT
1525 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1526 set_ost_qtype $QTYPE || error "enable ost quota failed"
1528 echo "Set enough high limit for user: $TSTUSR"
1529 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1530 error "set user quota failed"
1531 echo "Set enough high limit for group: $TSTUSR"
1532 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1533 error "set group quota failed"
1534 if is_project_quota_supported; then
1535 change_project -sp $TSTPRJID $DIR/$tdir
1536 echo "Set enough high limit for project: $TSTPRJID"
1537 $LFS setquota -p $TSTPRJID -b 0 \
1538 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1539 error "set project quota failed"
1543 [ "$SLOW" = "no" ] && duration=" -t 120"
1544 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1545 quota_error a $TSTUSR "dbench failed!"
1547 is_project_quota_supported && change_project -C $DIR/$tdir
1550 run_test 8 "Run dbench with quota enabled"
1552 # this check is just for test_9
1553 OST0_MIN=4900000 #4.67G
1555 check_whether_skip () {
1556 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1557 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1558 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1559 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1566 # run for fixing bug10707, it needs a big room. test for 64bit
1568 local filesize=$((1024 * 9 / 2)) # 4.5G
1570 check_whether_skip && return 0
1572 setup_quota_test || error "setup quota failed with $?"
1573 trap cleanup_quota_test EXIT
1575 set_ost_qtype "ug" || error "enable ost quota failed"
1577 local TESTFILE="$DIR/$tdir/$tfile-0"
1578 local BLK_LIMIT=100G #100G
1579 local FILE_LIMIT=1000000
1581 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1583 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1585 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1586 error "set user quota failed"
1588 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1589 "for group: $TSTUSR"
1590 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1591 error "set group quota failed"
1593 quota_show_check a u $TSTUSR
1594 quota_show_check a g $TSTUSR
1596 echo "Create test file"
1597 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1598 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1600 log "Write the big file of 4.5G ..."
1601 $RUNAS $DD of=$TESTFILE count=$filesize ||
1602 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1612 run_test 9 "Block limit larger than 4GB (b10707)"
1615 local TESTFILE=$DIR/$tdir/$tfile
1617 setup_quota_test || error "setup quota failed with $?"
1618 trap cleanup_quota_test EXIT
1620 # set limit to root user should fail
1621 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1622 error "set limit for root user successfully, expect failure"
1623 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1624 error "set limit for root group successfully, expect failure"
1625 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1626 error "set limit for project 0 successfully, expect failure"
1628 # root user can overrun quota
1629 set_ost_qtype "ug" || error "enable ost quota failed"
1631 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1632 error "set quota failed"
1633 quota_show_check b u $TSTUSR
1635 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1636 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1638 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1639 error "write failure, expect success"
1643 run_test 10 "Test quota for root user"
1646 local TESTFILE=$DIR/$tdir/$tfile
1647 setup_quota_test || error "setup quota failed with $?"
1648 trap cleanup_quota_test EXIT
1650 set_mdt_qtype "ug" || error "enable mdt quota failed"
1651 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1652 error "set quota failed"
1654 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1655 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1657 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1658 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1661 local USED=$(getquota -u $TSTUSR global curinodes)
1662 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1666 run_test 11 "Chown/chgrp ignores quota"
1669 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1671 local blimit=22 # 22M
1672 local blk_cnt=$((blimit - 5))
1673 local TESTFILE0="$DIR/$tdir/$tfile"-0
1674 local TESTFILE1="$DIR/$tdir/$tfile"-1
1676 setup_quota_test || error "setup quota failed with $?"
1677 trap cleanup_quota_test EXIT
1679 set_ost_qtype "u" || error "enable ost quota failed"
1680 quota_show_check b u $TSTUSR
1682 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1683 error "set quota failed"
1685 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1686 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1687 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1688 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1690 echo "Write to ost0..."
1691 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1692 quota_error a $TSTUSR "dd failed"
1694 echo "Write to ost1..."
1695 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1696 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1698 echo "Free space from ost0..."
1700 wait_delete_completed
1701 sync_all_data || true
1703 echo "Write to ost1 after space freed from ost0..."
1704 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1705 quota_error a $TSTUSR "rebalancing failed"
1709 run_test 12a "Block quota rebalancing"
1712 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1714 local ilimit=$((1024 * 2)) # 2k inodes
1715 local TESTFILE0=$DIR/$tdir/$tfile
1716 local TESTFILE1=$DIR/${tdir}-1/$tfile
1718 setup_quota_test || error "setup quota failed with $?"
1719 trap cleanup_quota_test EXIT
1721 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1722 chmod 0777 $DIR/${tdir}-1
1724 set_mdt_qtype "u" || error "enable mdt quota failed"
1725 quota_show_check f u $TSTUSR
1727 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1728 error "set quota failed"
1730 echo "Create $ilimit files on mdt0..."
1731 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1732 quota_error u $TSTUSR "create failed, but expect success"
1734 echo "Create files on mdt1..."
1735 $RUNAS createmany -m $TESTFILE1 1 &&
1736 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1738 echo "Free space from mdt0..."
1739 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1740 wait_delete_completed
1741 sync_all_data || true
1743 echo "Create files on mdt1 after space freed from mdt0..."
1744 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1745 quota_error a $TSTUSR "rebalancing failed"
1747 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1748 error "unlink mdt1 files failed"
1749 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1753 run_test 12b "Inode quota rebalancing"
1756 local TESTFILE=$DIR/$tdir/$tfile
1757 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1758 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1760 setup_quota_test || error "setup quota failed with $?"
1761 trap cleanup_quota_test EXIT
1763 set_ost_qtype "u" || error "enable ost quota failed"
1764 quota_show_check b u $TSTUSR
1766 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1767 error "set quota failed"
1768 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1769 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1771 # clear the locks in cache first
1772 do_facet ost1 $LCTL set_param -n $procf=clear
1773 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1774 [ $nlock -eq 0 ] || error "$nlock cached locks"
1776 # write to acquire the per-ID lock
1777 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1778 quota_error a $TSTUSR "dd failed"
1780 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1781 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1783 # clear quota doesn't trigger per-ID lock cancellation
1784 resetquota -u $TSTUSR
1785 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1786 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1788 # clear the per-ID lock
1789 do_facet ost1 $LCTL set_param -n $procf=clear
1790 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1791 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1793 # spare quota should be released
1794 local OSTUUID=$(ostuuid_from_index 0)
1795 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1796 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1797 [ $limit -le $space ] ||
1798 error "spare quota isn't released, limit:$limit, space:$space"
1802 run_test 13 "Cancel per-ID lock in the LRU list"
1805 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1807 wait_delete_completed
1808 sync_all_data || true
1811 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1812 error "set user quota failed"
1813 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1814 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1815 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1816 resetquota -u $TSTUSR
1819 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1820 error "set group quota failed"
1821 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1822 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1823 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1824 resetquota -g $TSTUSR
1826 run_test 15 "Set over 4T block quota"
1830 local BLKS=1 # 1M less than limit
1831 local TESTFILE=$DIR/$tdir/$tfile
1833 setup_quota_test || error "setup quota failed with $?"
1834 trap cleanup_quota_test EXIT
1836 # make sure the system is clean
1837 local USED=$(getquota -u $TSTUSR global curspace)
1838 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1840 set_ost_qtype "ug" || error "enable ost quota failed"
1841 # make sure no granted quota on ost
1842 resetquota -u $TSTUSR
1843 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1844 error "set quota failed"
1846 quota_show_check b u $TSTUSR
1848 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1849 lustre_fail mds 0xa04 $err_code
1851 # write in background
1852 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1856 # write should be blocked and never finished
1857 if ! ps -p $DDPID > /dev/null 2>&1; then
1859 quota_error u $TSTUSR "write finished incorrectly!"
1867 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1869 if [ $count -gt $timeout ]; then
1870 quota_error u $TSTUSR "dd is not finished!"
1875 sync; sync_all_data || true
1877 USED=$(getquota -u $TSTUSR global curspace)
1878 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1879 "Used space(${USED}K) is less than ${BLKS}M"
1884 # DQACQ return recoverable error
1886 echo "DQACQ return -ENOLCK"
1888 test_17sub 37 || error "Handle -ENOLCK failed"
1890 echo "DQACQ return -EAGAIN"
1892 test_17sub 11 || error "Handle -EAGAIN failed"
1894 echo "DQACQ return -ETIMEDOUT"
1895 #define ETIMEDOUT 110
1896 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1898 echo "DQACQ return -ENOTCONN"
1899 #define ENOTCONN 107
1900 test_17sub 107 || error "Handle -ENOTCONN failed"
1903 run_test 17 "DQACQ return recoverable error"
1907 local blimit="200m" # 200M
1908 local TESTFILE="$DIR/$tdir/$tfile"
1910 setup_quota_test || error "setup quota failed with $?"
1911 trap cleanup_quota_test EXIT
1913 set_ost_qtype "u" || error "enable ost quota failed"
1914 log "User quota (limit: $blimit)"
1915 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1916 error "set quota failed"
1917 quota_show_check b u $TSTUSR
1919 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1920 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1922 local timeout=$(sysctl -n lustre.timeout)
1924 if [ $io_type = "directio" ]; then
1925 log "Write 100M (directio) ..."
1926 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1928 log "Write 100M (buffered) ..."
1929 $RUNAS $DD of=$TESTFILE count=100 &
1933 replay_barrier $SINGLEMDS
1934 log "Fail mds for $((2 * timeout)) seconds"
1935 fail $SINGLEMDS $((2 * timeout))
1938 if at_is_enabled; then
1939 timeout=$(at_max_get mds)
1941 timeout=$(lctl get_param -n timeout)
1945 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1946 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1947 log "it took $count second"
1952 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1954 cancel_lru_locks mdc
1955 cancel_lru_locks osc
1958 local testfile_size=$(stat -c %s $TESTFILE)
1959 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1960 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1961 "got ${testfile_size}. Verifying file failed!"
1966 # test when mds does failover, the ost still could work well
1967 # this test shouldn't trigger watchdog b=14840
1969 # Clear dmesg so watchdog is not triggered by previous
1971 do_facet ost1 dmesg -c > /dev/null
1974 test_18_sub directio
1976 # check if watchdog is triggered
1977 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1978 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1979 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1980 [ -z "$watchdog" ] || error "$watchdog"
1981 rm -f $TMP/lustre-log-${TESTNAME}.log
1983 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1987 local TESTFILE=$DIR/$tdir/$tfile
1989 setup_quota_test || error "setup quota failed with $?"
1990 trap cleanup_quota_test EXIT
1992 set_ost_qtype $QTYPE || error "enable ost quota failed"
1994 # bind file to a single OST
1995 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1996 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1998 echo "Set user quota (limit: ${blimit}M)"
1999 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2000 error "set user quota failed"
2001 quota_show_check b u $TSTUSR
2002 echo "Update quota limits"
2003 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2004 error "set group quota failed"
2005 quota_show_check b u $TSTUSR
2007 # first wirte might be cached
2008 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2009 cancel_lru_locks osc
2011 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2012 quota_error u $TSTUSR "Write success, expect failure"
2017 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2019 test_20() { # b15754
2020 local LSTR=(2g 1t 4k 3m) # limits strings
2022 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2025 resetquota -u $TSTUSR
2027 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2028 $MOUNT || error "could not set quota limits"
2029 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2030 --inode-softlimit ${LSTR[2]} \
2031 --inode-hardlimit ${LSTR[3]} \
2032 $MOUNT || error "could not set quota limits"
2034 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2035 error "bsoftlimit was not set properly"
2036 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2037 error "bhardlimit was not set properly"
2038 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2039 error "isoftlimit was not set properly"
2040 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2041 error "ihardlimit was not set properly"
2043 resetquota -u $TSTUSR
2045 run_test 20 "Test if setquota specifiers work properly (b15754)"
2052 local time=$(($(date +%s) + seconds))
2053 while [ $(date +%s) -lt $time ]; do
2054 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2058 # run for fixing bug16053, setquota shouldn't fail when writing and
2059 # deleting are happening
2061 local TESTFILE="$DIR/$tdir/$tfile"
2062 local BLIMIT=10 # 10G
2063 local ILIMIT=1000000
2065 setup_quota_test || error "setup quota failed with $?"
2066 trap cleanup_quota_test EXIT
2068 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2070 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2071 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2072 error "set user quota failed"
2073 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2074 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2075 error "set group quota failed"
2076 if is_project_quota_supported; then
2077 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2078 "project: $TSTPRJID"
2079 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2080 $MOUNT || error "set project quota failed"
2083 # repeat writing on a 1M file
2084 test_21_sub ${TESTFILE}_1 1 30 &
2086 # repeat writing on a 128M file
2087 test_21_sub ${TESTFILE}_2 128 30 &
2090 local time=$(($(date +%s) + 30))
2092 while [ $(date +%s) -lt $time ]; do
2093 log "Set quota for $i times"
2094 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2095 -I $((ILIMIT + i)) $MOUNT ||
2096 error "Set user quota failed"
2097 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2098 -I $((ILIMIT + i)) $MOUNT ||
2099 error "Set group quota failed"
2100 if is_project_quota_supported; then
2101 $LFS setquota -p $TSTPRJID -b 0 -B \
2102 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2103 error "Set project quota failed"
2111 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2113 if [ $count -gt 60 ]; then
2114 quota_error a $TSTUSR "dd should be finished!"
2118 echo "(dd_pid=$DDPID1, time=$count)successful"
2122 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2124 if [ $count -gt 60 ]; then
2125 quota_error a $TSTUSR "dd should be finished!"
2129 echo "(dd_pid=$DDPID2, time=$count)successful"
2133 run_test 21 "Setquota while writing & deleting (b16053)"
2135 # enable/disable quota enforcement permanently
2137 echo "Set both mdt & ost quota type as ug"
2139 is_project_quota_supported && qtype=$QTYPE
2140 set_mdt_qtype $qtype || error "enable mdt quota failed"
2141 set_ost_qtype $qtype || error "enable ost quota failed"
2144 stopall || error "failed to stopall (1)"
2148 echo "Verify if quota is enabled"
2149 local qtype1=$(mdt_quota_type)
2150 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2151 qtype=$(ost_quota_type)
2152 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2154 echo "Set both mdt & ost quota type as none"
2155 set_mdt_qtype "none" || error "disable mdt quota failed"
2156 set_ost_qtype "none" || error "disable ost quota failed"
2159 stopall || error "failed to stopall (2)"
2164 echo "Verify if quota is disabled"
2165 qtype=$(mdt_quota_type)
2166 [ $qtype != "none" ] && error "mdt quota setting is lost"
2167 qtype=$(ost_quota_type)
2168 [ $qtype != "none" ] && error "ost quota setting is lost"
2172 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2175 local TESTFILE="$DIR/$tdir/$tfile"
2178 setup_quota_test || error "setup quota failed with $?"
2179 trap cleanup_quota_test EXIT
2181 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2184 log "User quota (limit: $LIMIT MB)"
2185 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2186 error "set quota failed"
2187 quota_show_check b u $TSTUSR
2189 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2190 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2192 log "Step1: trigger EDQUOT with O_DIRECT"
2193 log "Write half of file"
2194 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2195 quota_error u $TSTUSR "(1) Write failure, expect success." \
2197 log "Write out of block quota ..."
2198 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2199 oflag=direct conv=notrunc &&
2200 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2204 log "Step2: rewrite should succeed"
2205 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2206 quota_error u $TSTUSR "(3) Write failure, expect success." \
2212 local OST0_UUID=$(ostuuid_from_index 0)
2213 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2214 [ $OST0_QUOTA_USED -ne 0 ] &&
2215 ($SHOW_QUOTA_USER; \
2216 quota_error u $TSTUSR "quota isn't released")
2221 [ "$ost1_FSTYPE" == zfs ] &&
2222 skip "Overwrite in place is not guaranteed to be " \
2223 "space neutral on ZFS"
2225 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2226 check_whether_skip && return 0
2227 log "run for 4MB test file"
2230 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2231 check_whether_skip && return 0
2232 log "run for 40MB test file"
2235 run_test 23 "Quota should be honored with directIO (b16125)"
2239 local TESTFILE="$DIR/$tdir/$tfile"
2241 setup_quota_test || error "setup quota failed with $?"
2242 trap cleanup_quota_test EXIT
2244 set_ost_qtype $QTYPE || error "enable ost quota failed"
2246 # bind file to a single OST
2247 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2248 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2250 echo "Set user quota (limit: ${blimit}M)"
2251 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2252 error "set quota failed"
2254 # overrun quota by root user
2255 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2256 error "write failure, expect success"
2257 cancel_lru_locks osc
2258 sync_all_data || true
2260 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2264 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2266 test_27a() { # b19612
2267 $LFS quota $TSTUSR $DIR &&
2268 error "lfs succeeded with no type, but should have failed"
2269 $LFS setquota $TSTUSR $DIR &&
2270 error "lfs succeeded with no type, but should have failed"
2273 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2275 test_27b() { # b20200
2276 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2277 error "lfs setquota failed with uid argument"
2278 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2279 error "lfs stequota failed with gid argument"
2280 if is_project_quota_supported; then
2281 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2282 1000 $DIR || error \
2283 "lfs stequota failed with projid argument"
2285 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2286 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2287 if is_project_quota_supported; then
2288 $SHOW_QUOTA_PROJID ||
2289 error "lfs quota failed with projid argument"
2291 resetquota -u $TSTUSR
2292 resetquota -g $TSTUSR
2293 resetquota -p $TSTPRJID
2296 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2301 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2302 error "lfs setquota failed"
2304 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2305 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2306 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2307 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2309 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2310 error "lfs setquota for $TSTID failed"
2312 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2313 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2314 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2315 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2317 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2318 error "total allocated inode/block limit not printed"
2320 resetquota -u $TSTUSR
2322 run_test 27c "lfs quota should support human-readable output"
2329 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2330 error "set fraction block limit failed"
2331 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2332 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2333 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2334 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2336 resetquota -u $TSTUSR
2338 run_test 27d "lfs setquota should support fraction block limit"
2342 local TESTFILE="$DIR/$tdir/$tfile"
2345 setup_quota_test || error "setup quota failed with $?"
2346 trap cleanup_quota_test EXIT
2348 set_ost_qtype "u" || error "enable ost quota failed"
2350 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2351 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2353 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2354 $MAX_IQ_TIME $DIR || error "set grace time failed"
2355 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2356 error "set quota failed"
2357 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2358 cancel_lru_locks osc
2360 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2361 # over-quota flag has not yet settled since we do not trigger async
2362 # events based on grace time period expiration
2364 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2365 cancel_lru_locks osc
2366 # now over-quota flag should be settled and further writes should fail
2368 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2369 error "grace times were reset"
2372 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2373 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2375 run_test 30 "Hard limit updates should not reset grace times"
2377 # basic usage tracking for user & group
2379 local INODES=10 # 10 files
2380 local BLK_CNT=2 # of 2M each
2381 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2383 setup_quota_test || error "setup quota failed with $?"
2384 trap cleanup_quota_test EXIT
2386 # make sure the system is clean
2387 local USED=$(getquota -u $TSTID global curspace)
2389 error "Used space ($USED) for user $TSTID isn't 0."
2390 USED=$(getquota -g $TSTID global curspace)
2392 error "Used space ($USED) for group $TSTID isn't 0."
2393 if is_project_quota_supported; then
2394 USED=$(getquota -p $TSTPRJID global curspace)
2395 [ $USED -ne 0 ] && error \
2396 "Used space ($USED) for project $TSTPRJID isn't 0."
2399 echo "Write files..."
2400 for i in $(seq 0 $INODES); do
2401 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2402 error "write failed"
2403 is_project_quota_supported &&
2404 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2405 echo "Iteration $i/$INODES completed"
2407 cancel_lru_locks osc
2409 echo "Wait for setattr on objects finished..."
2410 wait_delete_completed
2412 sync; sync_all_data || true
2414 echo "Verify disk usage after write"
2415 USED=$(getquota -u $TSTID global curspace)
2416 [ $USED -lt $TOTAL_BLKS ] &&
2417 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2418 USED=$(getquota -g $TSTID global curspace)
2419 [ $USED -lt $TOTAL_BLKS ] &&
2420 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2421 if is_project_quota_supported; then
2422 USED=$(getquota -p $TSTPRJID global curspace)
2423 [ $USED -lt $TOTAL_BLKS ] && error \
2424 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2427 echo "Verify inode usage after write"
2428 USED=$(getquota -u $TSTID global curinodes)
2429 [ $USED -lt $INODES ] &&
2430 error "Used inode for user $TSTID is $USED, expected $INODES"
2431 USED=$(getquota -g $TSTID global curinodes)
2432 [ $USED -lt $INODES ] &&
2433 error "Used inode for group $TSTID is $USED, expected $INODES"
2434 if is_project_quota_supported; then
2435 USED=$(getquota -p $TSTPRJID global curinodes)
2436 [ $USED -lt $INODES ] && error \
2437 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2442 echo "Verify disk usage after delete"
2443 USED=$(getquota -u $TSTID global curspace)
2444 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2445 USED=$(getquota -u $TSTID global curinodes)
2446 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2447 USED=$(getquota -g $TSTID global curspace)
2448 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2449 USED=$(getquota -g $TSTID global curinodes)
2450 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2451 if is_project_quota_supported; then
2452 USED=$(getquota -p $TSTPRJID global curspace)
2454 error "Used space for project $TSTPRJID isn't 0. $USED"
2455 USED=$(getquota -p $TSTPRJID global curinodes)
2457 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2460 run_test 33 "Basic usage tracking for user & group & project"
2462 # usage transfer test for user & group & project
2464 local BLK_CNT=2 # 2MB
2465 local project_supported="no"
2467 is_project_quota_supported && project_supported="yes"
2468 setup_quota_test || error "setup quota failed with $?"
2469 trap cleanup_quota_test EXIT
2471 # make sure the system is clean
2472 local USED=$(getquota -u $TSTID global curspace)
2473 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2474 USED=$(getquota -g $TSTID global curspace)
2475 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2477 local USED=$(getquota -u $TSTID2 global curspace)
2478 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2479 if [ $project_supported == "yes" ]; then
2480 USED=$(getquota -p $TSTPRJID global curspace)
2481 [ $USED -ne 0 ] && error \
2482 "Used space ($USED) for Project $TSTPRJID isn't 0."
2485 echo "Write file..."
2486 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2487 error "write failed"
2488 cancel_lru_locks osc
2489 sync; sync_all_data || true
2491 echo "chown the file to user $TSTID"
2492 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2494 echo "Wait for setattr on objects finished..."
2495 wait_delete_completed
2497 BLK_CNT=$((BLK_CNT * 1024))
2499 echo "Verify disk usage for user $TSTID"
2500 USED=$(getquota -u $TSTID global curspace)
2501 [ $USED -lt $BLK_CNT ] &&
2502 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2503 USED=$(getquota -u $TSTID global curinodes)
2505 error "Used inodes for user $TSTID is $USED, expected 1"
2507 echo "chgrp the file to group $TSTID"
2508 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2510 echo "Wait for setattr on objects finished..."
2511 wait_delete_completed
2513 echo "Verify disk usage for group $TSTID"
2514 USED=$(getquota -g $TSTID global curspace)
2515 [ $USED -ge $BLK_CNT ] ||
2516 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2517 USED=$(getquota -g $TSTID global curinodes)
2519 error "Used inodes for group $TSTID is $USED, expected 1"
2521 # chown won't change the ost object group. LU-4345 */
2522 echo "chown the file to user $TSTID2"
2523 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2525 echo "Wait for setattr on objects finished..."
2526 wait_delete_completed
2528 echo "change_project project id to $TSTPRJID"
2529 [ $project_supported == "yes" ] &&
2530 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2531 echo "Wait for setattr on objects finished..."
2532 wait_delete_completed
2534 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2535 USED=$(getquota -u $TSTID2 global curspace)
2536 [ $USED -lt $BLK_CNT ] &&
2537 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2538 USED=$(getquota -u $TSTID global curspace)
2540 error "Used space for user $TSTID is $USED, expected 0"
2541 USED=$(getquota -g $TSTID global curspace)
2542 [ $USED -lt $BLK_CNT ] &&
2543 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2544 if [ $project_supported == "yes" ]; then
2545 USED=$(getquota -p $TSTPRJID global curspace)
2546 [ $USED -lt $BLK_CNT ] && error \
2547 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2552 run_test 34 "Usage transfer for user & group & project"
2554 # usage is still accessible across restart
2556 local BLK_CNT=2 # 2 MB
2558 setup_quota_test || error "setup quota failed with $?"
2559 trap cleanup_quota_test EXIT
2561 echo "Write file..."
2562 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2563 error "write failed"
2564 is_project_quota_supported &&
2565 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2566 cancel_lru_locks osc
2568 echo "Wait for setattr on objects finished..."
2569 wait_delete_completed
2571 sync; sync_all_data || true
2573 echo "Save disk usage before restart"
2574 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2575 [ $ORIG_USR_SPACE -eq 0 ] &&
2576 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2577 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2578 [ $ORIG_USR_INODES -eq 0 ] &&
2579 error "Used inodes for user $TSTID is 0, expected 1"
2580 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2581 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2582 [ $ORIG_GRP_SPACE -eq 0 ] &&
2583 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2584 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2585 [ $ORIG_GRP_INODES -eq 0 ] &&
2586 error "Used inodes for group $TSTID is 0, expected 1"
2587 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2589 if is_project_quota_supported; then
2590 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2591 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2592 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2593 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2594 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2595 "Used inodes for project $TSTPRJID is 0, expected 1"
2596 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2604 echo "Verify disk usage after restart"
2605 local USED=$(getquota -u $TSTID global curspace)
2606 [ $USED -eq $ORIG_USR_SPACE ] ||
2607 error "Used space for user $TSTID changed from " \
2608 "$ORIG_USR_SPACE to $USED"
2609 USED=$(getquota -u $TSTID global curinodes)
2610 [ $USED -eq $ORIG_USR_INODES ] ||
2611 error "Used inodes for user $TSTID changed from " \
2612 "$ORIG_USR_INODES to $USED"
2613 USED=$(getquota -g $TSTID global curspace)
2614 [ $USED -eq $ORIG_GRP_SPACE ] ||
2615 error "Used space for group $TSTID changed from " \
2616 "$ORIG_GRP_SPACE to $USED"
2617 USED=$(getquota -g $TSTID global curinodes)
2618 [ $USED -eq $ORIG_GRP_INODES ] ||
2619 error "Used inodes for group $TSTID changed from " \
2620 "$ORIG_GRP_INODES to $USED"
2621 if [ $project_supported == "yes" ]; then
2622 USED=$(getquota -p $TSTPRJID global curinodes)
2623 [ $USED -eq $ORIG_PRJ_INODES ] ||
2624 error "Used inodes for project $TSTPRJID " \
2625 "changed from $ORIG_PRJ_INODES to $USED"
2626 USED=$(getquota -p $TSTPRJID global curspace)
2627 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2628 error "Used space for project $TSTPRJID "\
2629 "changed from $ORIG_PRJ_SPACE to $USED"
2632 # check if the vfs_dq_init() is called before writing
2633 echo "Append to the same file..."
2634 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2635 error "write failed"
2636 cancel_lru_locks osc
2637 sync; sync_all_data || true
2639 echo "Verify space usage is increased"
2640 USED=$(getquota -u $TSTID global curspace)
2641 [ $USED -gt $ORIG_USR_SPACE ] ||
2642 error "Used space for user $TSTID isn't increased" \
2643 "orig:$ORIG_USR_SPACE, now:$USED"
2644 USED=$(getquota -g $TSTID global curspace)
2645 [ $USED -gt $ORIG_GRP_SPACE ] ||
2646 error "Used space for group $TSTID isn't increased" \
2647 "orig:$ORIG_GRP_SPACE, now:$USED"
2648 if [ $project_supported == "yes" ]; then
2649 USED=$(getquota -p $TSTPRJID global curspace)
2650 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2651 error "Used space for project $TSTPRJID isn't " \
2652 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2657 run_test 35 "Usage is still accessible across reboot"
2659 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2662 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2663 skip "Old server doesn't have LU-5006 fix."
2665 setup_quota_test || error "setup quota failed with $?"
2666 trap cleanup_quota_test EXIT
2668 # make sure the system is clean
2669 local USED=$(getquota -u $TSTID global curspace)
2671 error "Used space ($USED) for user $TSTID isn't 0."
2673 # create file with MDS_OPEN_DELAY_CREATE flag
2674 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2675 error "Create file failed"
2677 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2678 oflag=sync || error "Write file failed"
2680 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2682 # wait for setattr on objects finished..."
2683 wait_delete_completed
2685 USED=$(getquota -u $TSTID global curspace)
2686 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2690 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2694 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2695 skip "Old server doesn't have LU-8801 fix."
2697 [ "$UID" != 0 ] && skip_env "must run as root" && return
2699 setup_quota_test || error "setup quota failed with $?"
2700 trap cleanup_quota_test EXIT
2702 # make sure the system is clean
2703 local USED=$(getquota -u $TSTID global curspace)
2705 error "Used space ($USED) for user $TSTID isn't 0."
2706 USED=$(getquota -u $TSTID2 global curspace)
2708 error "Used space ($USED) for user $TSTID2 isn't 0."
2710 local TESTFILE="$DIR/$tdir/$tfile"
2711 local file_cnt=10000
2713 # Generate id entries in accounting file
2714 echo "Create $file_cnt files..."
2715 for i in `seq $file_cnt`; do
2717 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2718 error "failed to chown $TESTFILE-$i"
2720 cancel_lru_locks osc
2721 sync; sync_all_data || true
2723 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2724 procf=${procf}.quota_slave.acct_user
2727 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2728 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2729 echo "Found $acct_cnt id entries"
2731 [ $file_cnt -eq $acct_cnt ] || {
2732 do_facet mds1 $LCTL get_param $procf
2733 error "skipped id entries"
2738 run_test 38 "Quota accounting iterator doesn't skip id entries"
2741 local TESTFILE="$DIR/$tdir/project"
2742 ! is_project_quota_supported &&
2743 skip "Project quota is not supported"
2745 setup_quota_test || error "setup quota failed with $?"
2748 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2749 [ $projectid -ne 0 ] &&
2750 error "Project id should be 0 not $projectid"
2751 change_project -p 1024 $TESTFILE
2752 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2753 [ $projectid -ne 1024 ] &&
2754 error "Project id should be 1024 not $projectid"
2756 stopall || error "failed to stopall (1)"
2759 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2760 [ $projectid -ne 1024 ] &&
2761 error "Project id should be 1024 not $projectid"
2765 run_test 39 "Project ID interface works correctly"
2768 ! is_project_quota_supported &&
2769 skip "Project quota is not supported"
2770 local dir1="$DIR/$tdir/dir1"
2771 local dir2="$DIR/$tdir/dir2"
2773 setup_quota_test || error "setup quota failed with $?"
2775 mkdir -p $dir1 $dir2
2776 change_project -sp 1 $dir1 && touch $dir1/1
2777 change_project -sp 2 $dir2
2779 ln $dir1/1 $dir2/1_link &&
2780 error "Hard link across different project quota should fail"
2785 run_test 40a "Hard link across different project ID"
2788 ! is_project_quota_supported &&
2789 skip "Project quota is not supported"
2790 local dir1="$DIR/$tdir/dir1"
2791 local dir2="$DIR/$tdir/dir2"
2793 setup_quota_test || error "setup quota failed with $?"
2794 mkdir -p $dir1 $dir2
2795 change_project -sp 1 $dir1 && touch $dir1/1
2796 change_project -sp 2 $dir2
2798 mv $dir1/1 $dir2/2 || error "mv failed $?"
2799 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2800 if [ "$projid" != "2" ]; then
2801 error "project id expected 2 not $projid"
2806 run_test 40b "Mv across different project ID"
2809 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2810 ! is_project_quota_supported &&
2811 skip "Project quota is not supported"
2813 setup_quota_test || error "setup quota failed with $?"
2814 local dir="$DIR/$tdir/dir"
2816 mkdir -p $dir && change_project -sp 1 $dir
2817 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2818 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2819 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2820 touch $dir/remote_dir/file
2821 #verify inherit works file for remote dir.
2822 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2823 [ "$projid" != "1" ] &&
2824 error "file under remote dir expected 1 not $projid"
2826 #Agent inode should be ignored for project quota
2827 USED=$(getquota -p 1 global curinodes)
2828 [ "$USED" != "3" ] &&
2829 error "file count expected 3 got $USED"
2835 run_test 40c "Remote child Dir inherit project quota properly"
2838 ! is_project_quota_supported &&
2839 skip "Project quota is not supported"
2841 setup_quota_test || error "setup quota failed with $?"
2842 local dir1="$DIR/$tdir/dir1"
2843 local dir2="$DIR/$tdir/dir2"
2845 mkdir -p $dir1 && change_project -sp 1 $dir1
2846 mkdir -p $dir2 && change_project -sp 2 $dir2
2847 for num in $(seq 1 10); do
2848 touch $dir1/file_$num $dir2/file_$num
2849 ln -s $dir1/file_$num $dir1/file_$num"_link"
2850 ln -s $dir2/file_$num $dir2/file_$num"_link"
2853 count=$($LFS find --projid 1 $DIR | wc -l)
2854 [ "$count" != 21 ] && error "expected 21 but got $count"
2856 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2857 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2858 [ "$count" != 22 ] && error "expected 22 but got $count"
2863 run_test 50 "Test if lfs find --projid works"
2866 ! is_project_quota_supported &&
2867 skip "Project quota is not supported"
2868 setup_quota_test || error "setup quota failed with $?"
2869 local dir="$DIR/$tdir/dir"
2871 mkdir $dir && change_project -sp 1 $dir
2872 local used=$(getquota -p 1 global curinodes)
2873 [ $used != "1" ] && error "expected 1 got $used"
2878 used=$(getquota -p 1 global curinodes)
2879 [ $used != "4" ] && error "expected 4 got $used"
2881 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2883 cp $DIR/$tdir/6 $dir/6
2884 used=$(getquota -p 1 global curinodes)
2885 [ $used != "5" ] && error "expected 5 got $used"
2888 mv $DIR/$tdir/6 $dir/7
2889 used=$(getquota -p 1 global curinodes)
2890 [ $used != "6" ] && error "expected 6 got $used"
2895 run_test 51 "Test project accounting with mv/cp"
2898 ! is_project_quota_supported &&
2899 skip "Project quota is not supported"
2900 setup_quota_test || error "setup quota failed with $?"
2901 local dir="$DIR/$tdir/dir"
2902 mkdir $dir && change_project -sp 1 $dir
2904 touch $DIR/$tdir/file
2905 #Try renaming a file into the project. This should fail.
2906 for num in $(seq 1 2000); do
2907 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2908 error "rename should fail"
2913 run_test 52 "Rename across different project ID"
2916 ! is_project_quota_supported &&
2917 skip "Project quota is not supported"
2918 setup_quota_test || error "setup quota failed with $?"
2919 local dir="$DIR/$tdir/dir"
2920 mkdir $dir && change_project -s $dir
2921 lfs project -d $dir | grep P || error "inherit attribute should be set"
2923 change_project -C $dir
2924 lfs project -d $dir | grep P &&
2925 error "inherit attribute should be cleared"
2930 run_test 53 "Project inherit attribute could be cleared"
2933 ! is_project_quota_supported &&
2934 skip "Project quota is not supported"
2935 setup_quota_test || error "setup quota failed with $?"
2936 trap cleanup_quota_test EXIT
2937 local testfile="$DIR/$tdir/$tfile-0"
2939 #set project ID/inherit attribute
2940 change_project -sp $TSTPRJID $DIR/$tdir
2941 $RUNAS createmany -m ${testfile} 100 ||
2942 error "create many files failed"
2944 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2945 # one more count for directory itself */
2949 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2950 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2952 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2953 [ $proj_count1 -eq $proj_count ] ||
2954 error "c2: expected $proj_count got $proj_count1"
2956 #clear project but with kept projid
2957 change_project -rCk $DIR/$tdir
2958 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2959 [ $proj_count1 -eq 1 ] ||
2960 error "c3: expected 1 got $proj_count1"
2962 #verify projid untouched.
2963 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2965 [ $proj_count1 -eq $proj_count ] ||
2966 error "c4: expected $proj_count got $proj_count1"
2969 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2970 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2971 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2973 #this time clear all
2974 change_project -rC $DIR/$tdir
2975 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2976 [ $proj_count1 -eq 0 ] ||
2977 error "c6: expected 0 got $proj_count1"
2979 unlinkmany ${testfile} 100 ||
2980 error "unlink many files failed"
2984 run_test 54 "basic lfs project interface test"
2987 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
2988 skip "Not supported before 2.10.58."
2989 setup_quota_test || error "setup quota failed with $?"
2991 set_ost_qtype $QTYPE || error "enable ost quota failed"
2994 #add second group to TSTUSR
2995 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
2998 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
2999 error "failed to dd"
3001 cancel_lru_locks osc
3002 sync; sync_all_data || true
3004 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3005 error "failed to setquota on group $TSTUSR2"
3007 $LFS quota -v -g $TSTUSR2 $DIR
3009 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3010 error "chgrp should failed with -EDQUOT"
3012 USED=$(getquota -g $TSTUSR2 global curspace)
3015 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3016 error "failed to setquota on group $TSTUSR2"
3018 $LFS quota -v -g $TSTUSR2 $DIR
3020 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3021 error "chgrp should succeed"
3023 $LFS quota -v -g $TSTUSR2 $DIR
3027 run_test 55 "Chgrp should be affected by group quota"
3030 setup_quota_test || error "setup quota failed with $?"
3032 set_ost_qtype $QTYPE || error "enable ost quota failed"
3035 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3036 erro "failed to set grace time for usr quota"
3037 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3038 awk '{print $4 $8}')
3039 if [ "x$grace_time" != "x10s;10s" ]; then
3040 $LFS quota -t -u $DIR
3041 error "expected grace time: 10s;10s, got:$grace_time"
3046 run_test 56 "lfs quota -t should work well"
3049 setup_quota_test || error "setup quota failed with $?"
3051 local dir="$DIR/$tdir/dir"
3054 #try to change pipe file should not hang and return failure
3055 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3056 awk -F ':' '{ print \\\$2 }'" \
3057 " unable to get xattr for fifo '$dir/pipe'" || return 1
3058 #command can process further if it hit some errors
3059 touch $dir/aaa $dir/bbb
3060 mkdir $dir/subdir -p
3061 touch $dir/subdir/aaa $dir/subdir/bbb
3062 #create one invalid link file
3063 ln -s $dir/not_exist_file $dir/ccc
3064 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3065 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3069 run_test 57 "lfs project could tolerate errors"
3072 [ "$mds1_FSTYPE" != ldiskfs ] &&
3073 skip "ldiskfs only test"
3074 disable_project_quota
3075 setup_quota_test || error "setup quota failed with $?"
3078 local testfile="$DIR/$tdir/$tfile-0"
3079 #make sure it did not crash kernel
3080 touch $testfile && lfs project -sp 1 $testfile
3082 enable_project_quota
3085 run_test 59 "lfs project dosen't crash kernel with project disabled"
3088 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3089 skip "Needs MDS version 2.11.53 or later."
3090 setup_quota_test || error "setup quota failed with $?"
3091 trap cleanup_quota_test EXIT
3093 local testfile=$DIR/$tdir/$tfile
3096 set_mdt_qtype "ug" || error "enable mdt quota failed"
3098 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3099 error "set quota failed"
3100 quota_show_check a g $TSTUSR
3102 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3103 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3104 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3105 error "create many files failed"
3107 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3109 # root user can overrun quota
3110 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3111 error "root user should succeed"
3115 run_test 60 "Test quota for root with setgid"
3117 # test default quota
3118 test_default_quota() {
3119 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3120 skip "Not supported before 2.11.51."
3125 local qprjid=$TSTPRJID
3129 local LIMIT=20480 #20M disk space
3130 local TESTFILE="$DIR/$tdir/$tfile-0"
3132 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3133 echo "Project quota is not supported" && return 0
3135 [ $qtype == "-u" ] && qdtype="-U"
3136 [ $qtype == "-g" ] && qdtype="-G"
3137 [ $qtype == "-p" ] && {
3142 [ $qpool == "meta" ] && {
3143 LIMIT=10240 #10K inodes
3148 setup_quota_test || error "setup quota failed with $?"
3149 trap cleanup_quota_test EXIT
3153 # enable mdt/ost quota
3154 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3155 set_ost_qtype $QTYPE || error "enable ost quota failed"
3157 log "set to use default quota"
3158 $LFS setquota $qtype $qid -d $DIR ||
3159 error "set $qid to use default quota failed"
3161 log "set default quota"
3162 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3163 error "set $qid default quota failed"
3165 log "get default quota"
3166 $LFS quota $qdtype $DIR || error "get default quota failed"
3168 if [ $qpool == "data" ]; then
3169 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3171 [ $SLIMIT -eq $LIMIT ] ||
3172 error "the returned default quota is wrong"
3174 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3176 [ $SLIMIT -eq $LIMIT ] ||
3177 error "the returned default quota is wrong"
3180 # make sure the system is clean
3181 local USED=$(getquota $qtype $qid global curspace)
3182 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3184 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3185 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3187 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3189 log "Test not out of quota"
3190 if [ $qpool == "data" ]; then
3191 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3192 quota_error $qtype $qid "write failed, expect succeed"
3194 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3195 quota_error $qtype $qid "create failed, expect succeed"
3197 unlinkmany $TESTFILE $((LIMIT/2))
3200 log "Test out of quota"
3201 # flush cache, ensure noquota flag is set on client
3202 cancel_lru_locks osc
3203 cancel_lru_locks mdc
3204 sync; sync_all_data || true
3205 if [ $qpool == "data" ]; then
3206 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3207 quota_error $qtype $qid "write succeed, expect EDQUOT"
3209 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3210 quota_error $qtype $qid "create succeed, expect EDQUOT"
3212 unlinkmany $TESTFILE $((LIMIT*2))
3215 log "Increase default quota"
3216 # increase default quota
3217 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3218 error "set default quota failed"
3220 cancel_lru_locks osc
3221 cancel_lru_locks mdc
3222 sync; sync_all_data || true
3223 if [ $qpool == "data" ]; then
3224 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3225 quota_error $qtype $qid "write failed, expect succeed"
3227 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3228 quota_error $qtype $qid "create failed, expect succeed"
3230 unlinkmany $TESTFILE $((LIMIT*2))
3233 log "Set quota to override default quota"
3234 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3235 error "set $qid quota failed"
3237 cancel_lru_locks osc
3238 cancel_lru_locks mdc
3239 sync; sync_all_data || true
3240 if [ $qpool == "data" ]; then
3241 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3242 quota_error $qtype $qid "write succeed, expect EQUOT"
3244 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3245 quota_error $qtype $qid "create succeed, expect EQUOT"
3247 unlinkmany $TESTFILE $((LIMIT*2))
3250 log "Set to use default quota again"
3251 $LFS setquota $qtype $qid -d $DIR ||
3252 error "set $qid to use default quota failed"
3254 cancel_lru_locks osc
3255 cancel_lru_locks mdc
3256 sync; sync_all_data || true
3257 if [ $qpool == "data" ]; then
3258 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3259 quota_error $qtype $qid "write failed, expect succeed"
3261 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3262 quota_error $qtype $qid "create failed, expect succeed"
3264 unlinkmany $TESTFILE $((LIMIT*2))
3269 wait_delete_completed || error "wait_delete_completed failed"
3270 sync_all_data || true
3271 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3272 error "reset default quota failed"
3273 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3274 error "reset quota failed"
3280 test_default_quota "-u" "data"
3281 test_default_quota "-u" "meta"
3282 test_default_quota "-g" "data"
3283 test_default_quota "-g" "meta"
3284 test_default_quota "-p" "data"
3285 test_default_quota "-p" "meta"
3287 run_test 61 "default quota tests"
3290 ! is_project_quota_supported &&
3291 skip "Project quota is not supported"
3292 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3293 skip "chattr did not support project quota"
3294 setup_quota_test || error "setup quota failed with $?"
3295 local testdir=$DIR/$tdir/
3297 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3298 change_project -s $testdir
3299 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3300 error "inherit attribute should be set"
3301 # chattr used FS_IOC_SETFLAGS ioctl
3302 $RUNAS chattr -P $testdir &&
3303 error "regular user clear inherit should fail"
3304 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3305 error "inherit attribute should still be set"
3306 chattr -P $testdir || error "root failed to clear inherit"
3307 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3308 error "inherit attribute should be cleared"
3311 run_test 62 "Project inherit should be only changed by root"
3314 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3315 skip "Not supported before 2.11.55"
3319 local dd_failed=false
3320 local tdir_dom=${tdir}_dom
3321 local LIMIT=20480 #20M
3323 [ $qtype == "p" ] && ! is_project_quota_supported &&
3324 echo "Project quota is not supported" && return 0
3326 [ $qtype == "p" ] && qid=$TSTPRJID
3328 setup_quota_test || error "setup quota failed with $?"
3329 trap cleanup_quota_test EXIT
3333 # enable mdt/ost quota
3334 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3335 set_ost_qtype $QTYPE || error "enable ost quota failed"
3337 # make sure the system is clean
3338 local USED=$(getquota -$qtype $qid global curspace)
3339 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3341 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3343 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3344 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3345 error "setstripe $tdir_dom failed"
3346 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3348 [ $qtype == "p" ] && {
3349 change_project -sp $TSTPRJID $DIR/$tdir
3350 change_project -sp $TSTPRJID $DIR/$tdir_dom
3353 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3354 error "set $qid quota failed"
3356 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3357 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3361 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3363 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3364 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3368 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3370 rm -f $DIR/$tdir_dom/*
3372 # flush cache, ensure noquota flag is set on client
3373 cancel_lru_locks osc
3374 cancel_lru_locks mdc
3375 sync; sync_all_data || true
3379 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3380 quota_error $qtype $qid "write failed, expect succeed"
3382 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3383 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3387 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3390 rm -f $DIR/$tdir_dom/*
3392 # flush cache, ensure noquota flag is set on client
3393 cancel_lru_locks osc
3394 cancel_lru_locks mdc
3395 sync; sync_all_data || true
3399 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3400 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3404 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3406 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3407 quota_error $qtype $qid "write succeed, expect EDQUOT"
3410 rm -fr $DIR/$tdir_dom
3412 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3413 error "reset usr quota failed"
3423 run_test 63 "quota on DoM tests"
3426 ! is_project_quota_supported &&
3427 skip "Project quota is not supported"
3428 setup_quota_test || error "setup quota failed with $?"
3429 local dir1="$DIR/$tdir/"
3432 ln -s $dir1/file $dir1/file_link
3434 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3435 error "set symlink file's project should fail"
3437 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3438 error "get symlink file's project should fail"
3442 run_test 64 "lfs project on symlink files should fail"
3446 local TESTFILE="$DIR/$tdir/$tfile-0"
3448 setup_quota_test || error "setup quota failed with $?"
3449 set_ost_qtype $QTYPE || error "enable ost quota failed"
3453 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3454 error "failed to write"
3455 # flush cache, ensure noquota flag is set on client
3456 cancel_lru_locks osc
3457 sync; sync_all_data || true
3459 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3460 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3461 local quota_all=$($RUNAS $LFS quota $DIR)
3463 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3464 error "usr quota not match"
3465 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3466 error "grp quota not match"
3472 run_test 65 "Check lfs quota result"
3476 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3477 if $PQ_CLEANUP; then
3478 disable_project_quota
3481 reset_quota_settings
3486 check_and_cleanup_lustre
3487 export QUOTA_AUTO=$QUOTA_AUTO_OLD