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 sync_all_data || true
1140 #define QUOTA_DQACQ 601
1141 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1142 lustre_fail mds 0x513 601
1144 if at_is_enabled; then
1145 at_max_saved=$(at_max_get ost1)
1146 at_max_set $TIMEOUT ost1
1149 do_facet ost1 $LCTL set_param \
1150 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1152 # write to un-enforced ID ($TSTUSR2) should succeed
1153 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1154 error "write failure, expect success"
1156 # write to enforced ID ($TSTUSR) in background, exceeding limit
1157 # to make sure DQACQ is sent
1158 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1161 # watchdog timer uses a factor of 2
1162 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1163 sleep $((TIMEOUT * 2 + 1))
1165 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1167 # write should be blocked and never finished
1168 if ! ps -p $DDPID > /dev/null 2>&1; then
1170 error "write finished incorrectly!"
1175 # no watchdog is triggered
1176 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1177 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1178 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1179 [ -z "$watchdog" ] || error "$watchdog"
1181 rm -f $TMP/lustre-log-${TESTNAME}.log
1183 # write should continue then fail with EDQUOT
1187 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1188 if [ $count -ge 240 ]; then
1189 quota_error u $TSTUSR "dd not finished in $count secs"
1191 count=$((count + 1))
1192 if [ $((count % 30)) -eq 0 ]; then
1193 c_size=$(stat -c %s $TESTFILE)
1194 echo "Waiting $count secs. $c_size"
1202 run_test 6 "Test dropping acquire request on master"
1204 # quota reintegration (global index)
1206 local TESTFILE=$DIR/$tdir/$tfile
1207 local LIMIT=20 # 20M
1209 [ "$SLOW" = "no" ] && LIMIT=5
1211 setup_quota_test || error "setup quota failed with $?"
1212 trap cleanup_quota_test EXIT
1214 # make sure the system is clean
1215 local USED=$(getquota -u $TSTUSR global curspace)
1216 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1218 # make sure no granted quota on ost1
1219 set_ost_qtype $QTYPE || error "enable ost quota failed"
1220 resetquota -u $TSTUSR
1221 set_ost_qtype "none" || error "disable ost quota failed"
1223 local OSTUUID=$(ostuuid_from_index 0)
1224 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1226 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1229 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1230 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1235 echo "Enable quota & set quota limit for $TSTUSR"
1236 set_ost_qtype $QTYPE || error "enable ost quota failed"
1237 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1238 error "set quota failed"
1240 echo "Start ost1..."
1241 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1244 wait_ost_reint $QTYPE || error "reintegration failed"
1246 # hardlimit should have been fetched by slave during global
1247 # reintegration, write will exceed quota
1248 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1249 quota_error u $TSTUSR "write success, but expect EDQUOT"
1252 wait_delete_completed
1253 sync_all_data || true
1259 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1260 error "clear quota failed"
1262 echo "Start ost1..."
1263 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1266 wait_ost_reint $QTYPE || error "reintegration failed"
1268 # hardlimit should be cleared on slave during reintegration
1269 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1270 quota_error u $TSTUSR "write error, but expect success"
1274 run_test 7a "Quota reintegration (global index)"
1276 # quota reintegration (slave index)
1279 local TESTFILE=$DIR/$tdir/$tfile
1281 setup_quota_test || error "setup quota failed with $?"
1282 trap cleanup_quota_test EXIT
1284 # make sure the system is clean
1285 local USED=$(getquota -u $TSTUSR global curspace)
1286 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1288 # make sure no granted quota on ost1
1289 set_ost_qtype $QTYPE || error "enable ost quota failed"
1290 resetquota -u $TSTUSR
1291 set_ost_qtype "none" || error "disable ost quota failed"
1293 local OSTUUID=$(ostuuid_from_index 0)
1294 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1296 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1299 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1300 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1302 # consume some space to make sure the granted space will not
1303 # be released during reconciliation
1304 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1305 error "consume space failure, expect success"
1307 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1308 lustre_fail mds 0xa02
1310 set_ost_qtype $QTYPE || error "enable ost quota failed"
1311 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1312 error "set quota failed"
1314 # ignore the write error
1315 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1317 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1321 echo "Restart ost to trigger reintegration..."
1323 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1326 wait_ost_reint $QTYPE || error "reintegration failed"
1328 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1329 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1334 run_test 7b "Quota reintegration (slave index)"
1336 # quota reintegration (restart mds during reintegration)
1338 local LIMIT=20 # 20M
1339 local TESTFILE=$DIR/$tdir/$tfile
1341 [ "$SLOW" = "no" ] && LIMIT=5
1343 setup_quota_test || error "setup quota failed with $?"
1344 trap cleanup_quota_test EXIT
1346 # make sure the system is clean
1347 local USED=$(getquota -u $TSTUSR global curspace)
1348 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1350 set_ost_qtype "none" || error "disable ost quota failed"
1351 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1352 error "set quota failed"
1354 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1355 lustre_fail ost 0xa03
1358 set_ost_qtype $QTYPE || error "enable ost quota failed"
1359 # trigger reintegration
1360 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1361 procf=${procf}quota_slave.force_reint
1362 do_facet ost1 $LCTL set_param $procf=1 ||
1363 error "force reintegration failed"
1371 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1374 # wait longer than usual to make sure the reintegration
1375 # is triggered by quota wb thread.
1376 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1378 # hardlimit should have been fetched by slave during global
1379 # reintegration, write will exceed quota
1380 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1381 quota_error u $TSTUSR "write success, but expect EDQUOT"
1385 run_test 7c "Quota reintegration (restart mds during reintegration)"
1387 # Quota reintegration (Transfer index in multiple bulks)
1389 local TESTFILE=$DIR/$tdir/$tfile
1390 local TESTFILE1="$DIR/$tdir/$tfile"-1
1393 setup_quota_test || error "setup quota failed with $?"
1394 trap cleanup_quota_test EXIT
1396 set_ost_qtype "none" || error "disable ost quota failed"
1397 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1398 error "set quota for $TSTUSR failed"
1399 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1400 error "set quota for $TSTUSR2 failed"
1402 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1403 lustre_fail mds 0x608 0
1405 # enable quota to tirgger reintegration
1406 set_ost_qtype "u" || error "enable ost quota failed"
1407 wait_ost_reint "u" || error "reintegration failed"
1411 # hardlimit should have been fetched by slave during global
1412 # reintegration, write will exceed quota
1413 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1414 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1416 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1417 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1421 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1423 # quota reintegration (inode limits)
1425 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1427 # LU-2435: skip this quota test if underlying zfs version has not
1428 # supported native dnode accounting
1429 [ "$mds1_FSTYPE" == zfs ] && {
1430 local F="feature@userobj_accounting"
1431 local pool=$(zpool_name mds1)
1432 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1434 [[ "$feature" != *" active "* ]] &&
1435 skip "requires zpool with active userobj_accounting"
1438 local ilimit=$((1024 * 2)) # 2k inodes
1439 local TESTFILE=$DIR/${tdir}-1/$tfile
1441 setup_quota_test || error "setup quota failed with $?"
1442 trap cleanup_quota_test EXIT
1444 # make sure the system is clean
1445 local USED=$(getquota -u $TSTUSR global curinodes)
1446 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1448 # make sure no granted quota on mdt1
1449 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1450 resetquota -u $TSTUSR
1451 set_mdt_qtype "none" || error "disable mdt quota failed"
1453 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1454 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1455 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1458 echo "Stop mds${MDSCOUNT}..."
1461 echo "Enable quota & set quota limit for $TSTUSR"
1462 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1463 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1464 error "set quota failed"
1466 echo "Start mds${MDSCOUNT}..."
1467 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1470 wait_mdt_reint $QTYPE || error "reintegration failed"
1472 echo "create remote dir"
1473 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1474 error "create remote dir failed"
1475 chmod 0777 $DIR/${tdir}-1
1477 # hardlimit should have been fetched by slave during global
1478 # reintegration, create will exceed quota
1479 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1480 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1482 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1483 wait_delete_completed
1484 sync_all_data || true
1486 echo "Stop mds${MDSCOUNT}..."
1489 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1490 error "clear quota failed"
1492 echo "Start mds${MDSCOUNT}..."
1493 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1496 wait_mdt_reint $QTYPE || error "reintegration failed"
1498 # hardlimit should be cleared on slave during reintegration
1499 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1500 quota_error u $TSTUSR "create failed, expect success"
1502 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1503 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1507 run_test 7e "Quota reintegration (inode limits)"
1509 # run dbench with quota enabled
1511 local BLK_LIMIT="100g" #100G
1512 local FILE_LIMIT=1000000
1514 setup_quota_test || error "setup quota failed with $?"
1515 trap cleanup_quota_test EXIT
1517 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1518 set_ost_qtype $QTYPE || error "enable ost quota failed"
1520 echo "Set enough high limit for user: $TSTUSR"
1521 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1522 error "set user quota failed"
1523 echo "Set enough high limit for group: $TSTUSR"
1524 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1525 error "set group quota failed"
1526 if is_project_quota_supported; then
1527 change_project -sp $TSTPRJID $DIR/$tdir
1528 echo "Set enough high limit for project: $TSTPRJID"
1529 $LFS setquota -p $TSTPRJID -b 0 \
1530 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1531 error "set project quota failed"
1535 [ "$SLOW" = "no" ] && duration=" -t 120"
1536 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1537 quota_error a $TSTUSR "dbench failed!"
1539 is_project_quota_supported && change_project -C $DIR/$tdir
1542 run_test 8 "Run dbench with quota enabled"
1544 # this check is just for test_9
1545 OST0_MIN=4900000 #4.67G
1547 check_whether_skip () {
1548 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1549 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1550 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1551 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1558 # run for fixing bug10707, it needs a big room. test for 64bit
1560 local filesize=$((1024 * 9 / 2)) # 4.5G
1562 check_whether_skip && return 0
1564 setup_quota_test || error "setup quota failed with $?"
1565 trap cleanup_quota_test EXIT
1567 set_ost_qtype "ug" || error "enable ost quota failed"
1569 local TESTFILE="$DIR/$tdir/$tfile-0"
1570 local BLK_LIMIT=100G #100G
1571 local FILE_LIMIT=1000000
1573 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1575 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1577 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1578 error "set user quota failed"
1580 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1581 "for group: $TSTUSR"
1582 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1583 error "set group quota failed"
1585 quota_show_check a u $TSTUSR
1586 quota_show_check a g $TSTUSR
1588 echo "Create test file"
1589 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1590 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1592 log "Write the big file of 4.5G ..."
1593 $RUNAS $DD of=$TESTFILE count=$filesize ||
1594 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1604 run_test 9 "Block limit larger than 4GB (b10707)"
1607 local TESTFILE=$DIR/$tdir/$tfile
1609 setup_quota_test || error "setup quota failed with $?"
1610 trap cleanup_quota_test EXIT
1612 # set limit to root user should fail
1613 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1614 error "set limit for root user successfully, expect failure"
1615 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1616 error "set limit for root group successfully, expect failure"
1617 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1618 error "set limit for project 0 successfully, expect failure"
1620 # root user can overrun quota
1621 set_ost_qtype "ug" || error "enable ost quota failed"
1623 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1624 error "set quota failed"
1625 quota_show_check b u $TSTUSR
1627 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1628 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1630 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1631 error "write failure, expect success"
1635 run_test 10 "Test quota for root user"
1638 local TESTFILE=$DIR/$tdir/$tfile
1639 setup_quota_test || error "setup quota failed with $?"
1640 trap cleanup_quota_test EXIT
1642 set_mdt_qtype "ug" || error "enable mdt quota failed"
1643 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1644 error "set quota failed"
1646 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1647 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1649 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1650 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1653 local USED=$(getquota -u $TSTUSR global curinodes)
1654 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1658 run_test 11 "Chown/chgrp ignores quota"
1661 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1663 local blimit=22 # 22M
1664 local blk_cnt=$((blimit - 5))
1665 local TESTFILE0="$DIR/$tdir/$tfile"-0
1666 local TESTFILE1="$DIR/$tdir/$tfile"-1
1668 setup_quota_test || error "setup quota failed with $?"
1669 trap cleanup_quota_test EXIT
1671 set_ost_qtype "u" || error "enable ost quota failed"
1672 quota_show_check b u $TSTUSR
1674 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1675 error "set quota failed"
1677 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1678 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1679 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1680 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1682 echo "Write to ost0..."
1683 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1684 quota_error a $TSTUSR "dd failed"
1686 echo "Write to ost1..."
1687 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1688 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1690 echo "Free space from ost0..."
1692 wait_delete_completed
1693 sync_all_data || true
1695 echo "Write to ost1 after space freed from ost0..."
1696 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1697 quota_error a $TSTUSR "rebalancing failed"
1701 run_test 12a "Block quota rebalancing"
1704 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1706 local ilimit=$((1024 * 2)) # 2k inodes
1707 local TESTFILE0=$DIR/$tdir/$tfile
1708 local TESTFILE1=$DIR/${tdir}-1/$tfile
1710 setup_quota_test || error "setup quota failed with $?"
1711 trap cleanup_quota_test EXIT
1713 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1714 chmod 0777 $DIR/${tdir}-1
1716 set_mdt_qtype "u" || error "enable mdt quota failed"
1717 quota_show_check f u $TSTUSR
1719 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1720 error "set quota failed"
1722 echo "Create $ilimit files on mdt0..."
1723 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1724 quota_error u $TSTUSR "create failed, but expect success"
1726 echo "Create files on mdt1..."
1727 $RUNAS createmany -m $TESTFILE1 1 &&
1728 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1730 echo "Free space from mdt0..."
1731 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1732 wait_delete_completed
1733 sync_all_data || true
1735 echo "Create files on mdt1 after space freed from mdt0..."
1736 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1737 quota_error a $TSTUSR "rebalancing failed"
1739 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1740 error "unlink mdt1 files failed"
1741 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1745 run_test 12b "Inode quota rebalancing"
1748 local TESTFILE=$DIR/$tdir/$tfile
1749 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1750 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1752 setup_quota_test || error "setup quota failed with $?"
1753 trap cleanup_quota_test EXIT
1755 set_ost_qtype "u" || error "enable ost quota failed"
1756 quota_show_check b u $TSTUSR
1758 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1759 error "set quota failed"
1760 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1761 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1763 # clear the locks in cache first
1764 do_facet ost1 $LCTL set_param -n $procf=clear
1765 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1766 [ $nlock -eq 0 ] || error "$nlock cached locks"
1768 # write to acquire the per-ID lock
1769 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1770 quota_error a $TSTUSR "dd failed"
1772 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1773 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1775 # clear quota doesn't trigger per-ID lock cancellation
1776 resetquota -u $TSTUSR
1777 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1778 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1780 # clear the per-ID lock
1781 do_facet ost1 $LCTL set_param -n $procf=clear
1782 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1783 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1785 # spare quota should be released
1786 local OSTUUID=$(ostuuid_from_index 0)
1787 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1788 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1789 [ $limit -le $space ] ||
1790 error "spare quota isn't released, limit:$limit, space:$space"
1794 run_test 13 "Cancel per-ID lock in the LRU list"
1797 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1799 wait_delete_completed
1800 sync_all_data || true
1803 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1804 error "set user quota failed"
1805 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1806 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1807 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1808 resetquota -u $TSTUSR
1811 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1812 error "set group quota failed"
1813 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1814 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1815 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1816 resetquota -g $TSTUSR
1818 run_test 15 "Set over 4T block quota"
1822 local BLKS=1 # 1M less than limit
1823 local TESTFILE=$DIR/$tdir/$tfile
1825 setup_quota_test || error "setup quota failed with $?"
1826 trap cleanup_quota_test EXIT
1828 # make sure the system is clean
1829 local USED=$(getquota -u $TSTUSR global curspace)
1830 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1832 set_ost_qtype "ug" || error "enable ost quota failed"
1833 # make sure no granted quota on ost
1834 resetquota -u $TSTUSR
1835 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1836 error "set quota failed"
1838 quota_show_check b u $TSTUSR
1840 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1841 lustre_fail mds 0xa04 $err_code
1843 # write in background
1844 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1848 # write should be blocked and never finished
1849 if ! ps -p $DDPID > /dev/null 2>&1; then
1851 quota_error u $TSTUSR "write finished incorrectly!"
1859 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1861 if [ $count -gt $timeout ]; then
1862 quota_error u $TSTUSR "dd is not finished!"
1867 sync; sync_all_data || true
1869 USED=$(getquota -u $TSTUSR global curspace)
1870 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1871 "Used space(${USED}K) is less than ${BLKS}M"
1876 # DQACQ return recoverable error
1878 echo "DQACQ return -ENOLCK"
1880 test_17sub 37 || error "Handle -ENOLCK failed"
1882 echo "DQACQ return -EAGAIN"
1884 test_17sub 11 || error "Handle -EAGAIN failed"
1886 echo "DQACQ return -ETIMEDOUT"
1887 #define ETIMEDOUT 110
1888 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1890 echo "DQACQ return -ENOTCONN"
1891 #define ENOTCONN 107
1892 test_17sub 107 || error "Handle -ENOTCONN failed"
1895 run_test 17 "DQACQ return recoverable error"
1899 local blimit="200m" # 200M
1900 local TESTFILE="$DIR/$tdir/$tfile"
1902 setup_quota_test || error "setup quota failed with $?"
1903 trap cleanup_quota_test EXIT
1905 set_ost_qtype "u" || error "enable ost quota failed"
1906 log "User quota (limit: $blimit)"
1907 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1908 error "set quota failed"
1909 quota_show_check b u $TSTUSR
1911 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1912 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1914 local timeout=$(sysctl -n lustre.timeout)
1916 if [ $io_type = "directio" ]; then
1917 log "Write 100M (directio) ..."
1918 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1920 log "Write 100M (buffered) ..."
1921 $RUNAS $DD of=$TESTFILE count=100 &
1925 replay_barrier $SINGLEMDS
1926 log "Fail mds for $((2 * timeout)) seconds"
1927 fail $SINGLEMDS $((2 * timeout))
1930 if at_is_enabled; then
1931 timeout=$(at_max_get mds)
1933 timeout=$(lctl get_param -n timeout)
1937 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1938 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1939 log "it took $count second"
1944 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1946 cancel_lru_locks mdc
1947 cancel_lru_locks osc
1950 local testfile_size=$(stat -c %s $TESTFILE)
1951 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1952 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1953 "got ${testfile_size}. Verifying file failed!"
1958 # test when mds does failover, the ost still could work well
1959 # this test shouldn't trigger watchdog b=14840
1961 # Clear dmesg so watchdog is not triggered by previous
1963 do_facet ost1 dmesg -c > /dev/null
1966 test_18_sub directio
1968 # check if watchdog is triggered
1969 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1970 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1971 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1972 [ -z "$watchdog" ] || error "$watchdog"
1973 rm -f $TMP/lustre-log-${TESTNAME}.log
1975 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1979 local TESTFILE=$DIR/$tdir/$tfile
1981 setup_quota_test || error "setup quota failed with $?"
1982 trap cleanup_quota_test EXIT
1984 set_ost_qtype $QTYPE || error "enable ost quota failed"
1986 # bind file to a single OST
1987 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1988 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1990 echo "Set user quota (limit: ${blimit}M)"
1991 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1992 error "set user quota failed"
1993 quota_show_check b u $TSTUSR
1994 echo "Update quota limits"
1995 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1996 error "set group quota failed"
1997 quota_show_check b u $TSTUSR
1999 # first wirte might be cached
2000 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2001 cancel_lru_locks osc
2003 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2004 quota_error u $TSTUSR "Write success, expect failure"
2009 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2011 test_20() { # b15754
2012 local LSTR=(2g 1t 4k 3m) # limits strings
2014 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2017 resetquota -u $TSTUSR
2019 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2020 $MOUNT || error "could not set quota limits"
2021 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2022 --inode-softlimit ${LSTR[2]} \
2023 --inode-hardlimit ${LSTR[3]} \
2024 $MOUNT || error "could not set quota limits"
2026 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2027 error "bsoftlimit was not set properly"
2028 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2029 error "bhardlimit was not set properly"
2030 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2031 error "isoftlimit was not set properly"
2032 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2033 error "ihardlimit was not set properly"
2035 resetquota -u $TSTUSR
2037 run_test 20 "Test if setquota specifiers work properly (b15754)"
2044 local time=$(($(date +%s) + seconds))
2045 while [ $(date +%s) -lt $time ]; do
2046 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2050 # run for fixing bug16053, setquota shouldn't fail when writing and
2051 # deleting are happening
2053 local TESTFILE="$DIR/$tdir/$tfile"
2054 local BLIMIT=10 # 10G
2055 local ILIMIT=1000000
2057 setup_quota_test || error "setup quota failed with $?"
2058 trap cleanup_quota_test EXIT
2060 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2062 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2063 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2064 error "set user quota failed"
2065 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2066 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2067 error "set group quota failed"
2068 if is_project_quota_supported; then
2069 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2070 "project: $TSTPRJID"
2071 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2072 $MOUNT || error "set project quota failed"
2075 # repeat writing on a 1M file
2076 test_21_sub ${TESTFILE}_1 1 30 &
2078 # repeat writing on a 128M file
2079 test_21_sub ${TESTFILE}_2 128 30 &
2082 local time=$(($(date +%s) + 30))
2084 while [ $(date +%s) -lt $time ]; do
2085 log "Set quota for $i times"
2086 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2087 -I $((ILIMIT + i)) $MOUNT ||
2088 error "Set user quota failed"
2089 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2090 -I $((ILIMIT + i)) $MOUNT ||
2091 error "Set group quota failed"
2092 if is_project_quota_supported; then
2093 $LFS setquota -p $TSTPRJID -b 0 -B \
2094 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2095 error "Set project quota failed"
2103 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2105 if [ $count -gt 60 ]; then
2106 quota_error a $TSTUSR "dd should be finished!"
2110 echo "(dd_pid=$DDPID1, time=$count)successful"
2114 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2116 if [ $count -gt 60 ]; then
2117 quota_error a $TSTUSR "dd should be finished!"
2121 echo "(dd_pid=$DDPID2, time=$count)successful"
2125 run_test 21 "Setquota while writing & deleting (b16053)"
2127 # enable/disable quota enforcement permanently
2129 echo "Set both mdt & ost quota type as ug"
2131 is_project_quota_supported && qtype=$QTYPE
2132 set_mdt_qtype $qtype || error "enable mdt quota failed"
2133 set_ost_qtype $qtype || error "enable ost quota failed"
2136 stopall || error "failed to stopall (1)"
2140 echo "Verify if quota is enabled"
2141 local qtype1=$(mdt_quota_type)
2142 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2143 qtype=$(ost_quota_type)
2144 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2146 echo "Set both mdt & ost quota type as none"
2147 set_mdt_qtype "none" || error "disable mdt quota failed"
2148 set_ost_qtype "none" || error "disable ost quota failed"
2151 stopall || error "failed to stopall (2)"
2156 echo "Verify if quota is disabled"
2157 qtype=$(mdt_quota_type)
2158 [ $qtype != "none" ] && error "mdt quota setting is lost"
2159 qtype=$(ost_quota_type)
2160 [ $qtype != "none" ] && error "ost quota setting is lost"
2164 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2167 local TESTFILE="$DIR/$tdir/$tfile"
2170 setup_quota_test || error "setup quota failed with $?"
2171 trap cleanup_quota_test EXIT
2173 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2176 log "User quota (limit: $LIMIT MB)"
2177 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2178 error "set quota failed"
2179 quota_show_check b u $TSTUSR
2181 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2182 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2184 log "Step1: trigger EDQUOT with O_DIRECT"
2185 log "Write half of file"
2186 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2187 quota_error u $TSTUSR "(1) Write failure, expect success." \
2189 log "Write out of block quota ..."
2190 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2191 oflag=direct conv=notrunc &&
2192 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2196 log "Step2: rewrite should succeed"
2197 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2198 quota_error u $TSTUSR "(3) Write failure, expect success." \
2204 local OST0_UUID=$(ostuuid_from_index 0)
2205 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2206 [ $OST0_QUOTA_USED -ne 0 ] &&
2207 ($SHOW_QUOTA_USER; \
2208 quota_error u $TSTUSR "quota isn't released")
2213 [ "$ost1_FSTYPE" == zfs ] &&
2214 skip "Overwrite in place is not guaranteed to be " \
2215 "space neutral on ZFS"
2217 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2218 check_whether_skip && return 0
2219 log "run for 4MB test file"
2222 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2223 check_whether_skip && return 0
2224 log "run for 40MB test file"
2227 run_test 23 "Quota should be honored with directIO (b16125)"
2231 local TESTFILE="$DIR/$tdir/$tfile"
2233 setup_quota_test || error "setup quota failed with $?"
2234 trap cleanup_quota_test EXIT
2236 set_ost_qtype $QTYPE || error "enable ost quota failed"
2238 # bind file to a single OST
2239 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2240 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2242 echo "Set user quota (limit: ${blimit}M)"
2243 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2244 error "set quota failed"
2246 # overrun quota by root user
2247 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2248 error "write failure, expect success"
2249 cancel_lru_locks osc
2250 sync_all_data || true
2252 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2256 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2258 test_27a() { # b19612
2259 $LFS quota $TSTUSR $DIR &&
2260 error "lfs succeeded with no type, but should have failed"
2261 $LFS setquota $TSTUSR $DIR &&
2262 error "lfs succeeded with no type, but should have failed"
2265 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2267 test_27b() { # b20200
2268 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2269 error "lfs setquota failed with uid argument"
2270 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2271 error "lfs stequota failed with gid argument"
2272 if is_project_quota_supported; then
2273 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2274 1000 $DIR || error \
2275 "lfs stequota failed with projid argument"
2277 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2278 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2279 if is_project_quota_supported; then
2280 $SHOW_QUOTA_PROJID ||
2281 error "lfs quota failed with projid argument"
2283 resetquota -u $TSTUSR
2284 resetquota -g $TSTUSR
2285 resetquota -p $TSTPRJID
2288 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2293 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2294 error "lfs setquota failed"
2296 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2297 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2298 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2299 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2301 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2302 error "lfs setquota for $TSTID failed"
2304 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2305 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2306 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2307 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2309 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2310 error "total allocated inode/block limit not printed"
2312 resetquota -u $TSTUSR
2314 run_test 27c "lfs quota should support human-readable output"
2321 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2322 error "set fraction block limit failed"
2323 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2324 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2325 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2326 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2328 resetquota -u $TSTUSR
2330 run_test 27d "lfs setquota should support fraction block limit"
2334 local TESTFILE="$DIR/$tdir/$tfile"
2337 setup_quota_test || error "setup quota failed with $?"
2338 trap cleanup_quota_test EXIT
2340 set_ost_qtype "u" || error "enable ost quota failed"
2342 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2343 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2345 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2346 $MAX_IQ_TIME $DIR || error "set grace time failed"
2347 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2348 error "set quota failed"
2349 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2350 cancel_lru_locks osc
2352 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2353 # over-quota flag has not yet settled since we do not trigger async
2354 # events based on grace time period expiration
2356 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2357 cancel_lru_locks osc
2358 # now over-quota flag should be settled and further writes should fail
2360 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2361 error "grace times were reset"
2364 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2365 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2367 run_test 30 "Hard limit updates should not reset grace times"
2369 # basic usage tracking for user & group
2371 local INODES=10 # 10 files
2372 local BLK_CNT=2 # of 2M each
2373 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2375 setup_quota_test || error "setup quota failed with $?"
2376 trap cleanup_quota_test EXIT
2378 # make sure the system is clean
2379 local USED=$(getquota -u $TSTID global curspace)
2381 error "Used space ($USED) for user $TSTID isn't 0."
2382 USED=$(getquota -g $TSTID global curspace)
2384 error "Used space ($USED) for group $TSTID isn't 0."
2385 if is_project_quota_supported; then
2386 USED=$(getquota -p $TSTPRJID global curspace)
2387 [ $USED -ne 0 ] && error \
2388 "Used space ($USED) for project $TSTPRJID isn't 0."
2391 echo "Write files..."
2392 for i in $(seq 0 $INODES); do
2393 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2394 error "write failed"
2395 is_project_quota_supported &&
2396 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2397 echo "Iteration $i/$INODES completed"
2399 cancel_lru_locks osc
2401 echo "Wait for setattr on objects finished..."
2402 wait_delete_completed
2404 sync; sync_all_data || true
2406 echo "Verify disk usage after write"
2407 USED=$(getquota -u $TSTID global curspace)
2408 [ $USED -lt $TOTAL_BLKS ] &&
2409 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2410 USED=$(getquota -g $TSTID global curspace)
2411 [ $USED -lt $TOTAL_BLKS ] &&
2412 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2413 if is_project_quota_supported; then
2414 USED=$(getquota -p $TSTPRJID global curspace)
2415 [ $USED -lt $TOTAL_BLKS ] && error \
2416 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2419 echo "Verify inode usage after write"
2420 USED=$(getquota -u $TSTID global curinodes)
2421 [ $USED -lt $INODES ] &&
2422 error "Used inode for user $TSTID is $USED, expected $INODES"
2423 USED=$(getquota -g $TSTID global curinodes)
2424 [ $USED -lt $INODES ] &&
2425 error "Used inode for group $TSTID is $USED, expected $INODES"
2426 if is_project_quota_supported; then
2427 USED=$(getquota -p $TSTPRJID global curinodes)
2428 [ $USED -lt $INODES ] && error \
2429 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2434 echo "Verify disk usage after delete"
2435 USED=$(getquota -u $TSTID global curspace)
2436 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2437 USED=$(getquota -u $TSTID global curinodes)
2438 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2439 USED=$(getquota -g $TSTID global curspace)
2440 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2441 USED=$(getquota -g $TSTID global curinodes)
2442 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2443 if is_project_quota_supported; then
2444 USED=$(getquota -p $TSTPRJID global curspace)
2446 error "Used space for project $TSTPRJID isn't 0. $USED"
2447 USED=$(getquota -p $TSTPRJID global curinodes)
2449 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2452 run_test 33 "Basic usage tracking for user & group & project"
2454 # usage transfer test for user & group & project
2456 local BLK_CNT=2 # 2MB
2457 local project_supported="no"
2459 is_project_quota_supported && project_supported="yes"
2460 setup_quota_test || error "setup quota failed with $?"
2461 trap cleanup_quota_test EXIT
2463 # make sure the system is clean
2464 local USED=$(getquota -u $TSTID global curspace)
2465 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2466 USED=$(getquota -g $TSTID global curspace)
2467 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2469 local USED=$(getquota -u $TSTID2 global curspace)
2470 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2471 if [ $project_supported == "yes" ]; then
2472 USED=$(getquota -p $TSTPRJID global curspace)
2473 [ $USED -ne 0 ] && error \
2474 "Used space ($USED) for Project $TSTPRJID isn't 0."
2477 echo "Write file..."
2478 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2479 error "write failed"
2480 cancel_lru_locks osc
2481 sync; sync_all_data || true
2483 echo "chown the file to user $TSTID"
2484 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2486 echo "Wait for setattr on objects finished..."
2487 wait_delete_completed
2489 BLK_CNT=$((BLK_CNT * 1024))
2491 echo "Verify disk usage for user $TSTID"
2492 USED=$(getquota -u $TSTID global curspace)
2493 [ $USED -lt $BLK_CNT ] &&
2494 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2495 USED=$(getquota -u $TSTID global curinodes)
2497 error "Used inodes for user $TSTID is $USED, expected 1"
2499 echo "chgrp the file to group $TSTID"
2500 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2502 echo "Wait for setattr on objects finished..."
2503 wait_delete_completed
2505 echo "Verify disk usage for group $TSTID"
2506 USED=$(getquota -g $TSTID global curspace)
2507 [ $USED -ge $BLK_CNT ] ||
2508 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2509 USED=$(getquota -g $TSTID global curinodes)
2511 error "Used inodes for group $TSTID is $USED, expected 1"
2513 # chown won't change the ost object group. LU-4345 */
2514 echo "chown the file to user $TSTID2"
2515 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2517 echo "Wait for setattr on objects finished..."
2518 wait_delete_completed
2520 echo "change_project project id to $TSTPRJID"
2521 [ $project_supported == "yes" ] &&
2522 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2523 echo "Wait for setattr on objects finished..."
2524 wait_delete_completed
2526 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2527 USED=$(getquota -u $TSTID2 global curspace)
2528 [ $USED -lt $BLK_CNT ] &&
2529 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2530 USED=$(getquota -u $TSTID global curspace)
2532 error "Used space for user $TSTID is $USED, expected 0"
2533 USED=$(getquota -g $TSTID global curspace)
2534 [ $USED -lt $BLK_CNT ] &&
2535 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2536 if [ $project_supported == "yes" ]; then
2537 USED=$(getquota -p $TSTPRJID global curspace)
2538 [ $USED -lt $BLK_CNT ] && error \
2539 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2544 run_test 34 "Usage transfer for user & group & project"
2546 # usage is still accessible across restart
2548 local BLK_CNT=2 # 2 MB
2550 setup_quota_test || error "setup quota failed with $?"
2551 trap cleanup_quota_test EXIT
2553 echo "Write file..."
2554 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2555 error "write failed"
2556 is_project_quota_supported &&
2557 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2558 cancel_lru_locks osc
2560 echo "Wait for setattr on objects finished..."
2561 wait_delete_completed
2563 sync; sync_all_data || true
2565 echo "Save disk usage before restart"
2566 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2567 [ $ORIG_USR_SPACE -eq 0 ] &&
2568 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2569 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2570 [ $ORIG_USR_INODES -eq 0 ] &&
2571 error "Used inodes for user $TSTID is 0, expected 1"
2572 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2573 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2574 [ $ORIG_GRP_SPACE -eq 0 ] &&
2575 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2576 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2577 [ $ORIG_GRP_INODES -eq 0 ] &&
2578 error "Used inodes for group $TSTID is 0, expected 1"
2579 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2581 if is_project_quota_supported; then
2582 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2583 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2584 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2585 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2586 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2587 "Used inodes for project $TSTPRJID is 0, expected 1"
2588 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2596 echo "Verify disk usage after restart"
2597 local USED=$(getquota -u $TSTID global curspace)
2598 [ $USED -eq $ORIG_USR_SPACE ] ||
2599 error "Used space for user $TSTID changed from " \
2600 "$ORIG_USR_SPACE to $USED"
2601 USED=$(getquota -u $TSTID global curinodes)
2602 [ $USED -eq $ORIG_USR_INODES ] ||
2603 error "Used inodes for user $TSTID changed from " \
2604 "$ORIG_USR_INODES to $USED"
2605 USED=$(getquota -g $TSTID global curspace)
2606 [ $USED -eq $ORIG_GRP_SPACE ] ||
2607 error "Used space for group $TSTID changed from " \
2608 "$ORIG_GRP_SPACE to $USED"
2609 USED=$(getquota -g $TSTID global curinodes)
2610 [ $USED -eq $ORIG_GRP_INODES ] ||
2611 error "Used inodes for group $TSTID changed from " \
2612 "$ORIG_GRP_INODES to $USED"
2613 if [ $project_supported == "yes" ]; then
2614 USED=$(getquota -p $TSTPRJID global curinodes)
2615 [ $USED -eq $ORIG_PRJ_INODES ] ||
2616 error "Used inodes for project $TSTPRJID " \
2617 "changed from $ORIG_PRJ_INODES to $USED"
2618 USED=$(getquota -p $TSTPRJID global curspace)
2619 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2620 error "Used space for project $TSTPRJID "\
2621 "changed from $ORIG_PRJ_SPACE to $USED"
2624 # check if the vfs_dq_init() is called before writing
2625 echo "Append to the same file..."
2626 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2627 error "write failed"
2628 cancel_lru_locks osc
2629 sync; sync_all_data || true
2631 echo "Verify space usage is increased"
2632 USED=$(getquota -u $TSTID global curspace)
2633 [ $USED -gt $ORIG_USR_SPACE ] ||
2634 error "Used space for user $TSTID isn't increased" \
2635 "orig:$ORIG_USR_SPACE, now:$USED"
2636 USED=$(getquota -g $TSTID global curspace)
2637 [ $USED -gt $ORIG_GRP_SPACE ] ||
2638 error "Used space for group $TSTID isn't increased" \
2639 "orig:$ORIG_GRP_SPACE, now:$USED"
2640 if [ $project_supported == "yes" ]; then
2641 USED=$(getquota -p $TSTPRJID global curspace)
2642 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2643 error "Used space for project $TSTPRJID isn't " \
2644 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2649 run_test 35 "Usage is still accessible across reboot"
2651 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2654 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2655 skip "Old server doesn't have LU-5006 fix."
2657 setup_quota_test || error "setup quota failed with $?"
2658 trap cleanup_quota_test EXIT
2660 # make sure the system is clean
2661 local USED=$(getquota -u $TSTID global curspace)
2663 error "Used space ($USED) for user $TSTID isn't 0."
2665 # create file with MDS_OPEN_DELAY_CREATE flag
2666 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2667 error "Create file failed"
2669 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2670 oflag=sync || error "Write file failed"
2672 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2674 # wait for setattr on objects finished..."
2675 wait_delete_completed
2677 USED=$(getquota -u $TSTID global curspace)
2678 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2682 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2686 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2687 skip "Old server doesn't have LU-8801 fix."
2689 [ "$UID" != 0 ] && skip_env "must run as root" && return
2691 setup_quota_test || error "setup quota failed with $?"
2692 trap cleanup_quota_test EXIT
2694 # make sure the system is clean
2695 local USED=$(getquota -u $TSTID global curspace)
2697 error "Used space ($USED) for user $TSTID isn't 0."
2698 USED=$(getquota -u $TSTID2 global curspace)
2700 error "Used space ($USED) for user $TSTID2 isn't 0."
2702 local TESTFILE="$DIR/$tdir/$tfile"
2703 local file_cnt=10000
2705 # Generate id entries in accounting file
2706 echo "Create $file_cnt files..."
2707 for i in `seq $file_cnt`; do
2709 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2710 error "failed to chown $TESTFILE-$i"
2712 cancel_lru_locks osc
2713 sync; sync_all_data || true
2715 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2716 procf=${procf}.quota_slave.acct_user
2719 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2720 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2721 echo "Found $acct_cnt id entries"
2723 [ $file_cnt -eq $acct_cnt ] || {
2724 do_facet mds1 $LCTL get_param $procf
2725 error "skipped id entries"
2730 run_test 38 "Quota accounting iterator doesn't skip id entries"
2733 local TESTFILE="$DIR/$tdir/project"
2734 ! is_project_quota_supported &&
2735 skip "Project quota is not supported"
2737 setup_quota_test || error "setup quota failed with $?"
2740 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2741 [ $projectid -ne 0 ] &&
2742 error "Project id should be 0 not $projectid"
2743 change_project -p 1024 $TESTFILE
2744 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2745 [ $projectid -ne 1024 ] &&
2746 error "Project id should be 1024 not $projectid"
2748 stopall || error "failed to stopall (1)"
2751 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2752 [ $projectid -ne 1024 ] &&
2753 error "Project id should be 1024 not $projectid"
2757 run_test 39 "Project ID interface works correctly"
2760 ! is_project_quota_supported &&
2761 skip "Project quota is not supported"
2762 local dir1="$DIR/$tdir/dir1"
2763 local dir2="$DIR/$tdir/dir2"
2765 setup_quota_test || error "setup quota failed with $?"
2767 mkdir -p $dir1 $dir2
2768 change_project -sp 1 $dir1 && touch $dir1/1
2769 change_project -sp 2 $dir2
2771 ln $dir1/1 $dir2/1_link &&
2772 error "Hard link across different project quota should fail"
2777 run_test 40a "Hard link across different project ID"
2780 ! is_project_quota_supported &&
2781 skip "Project quota is not supported"
2782 local dir1="$DIR/$tdir/dir1"
2783 local dir2="$DIR/$tdir/dir2"
2785 setup_quota_test || error "setup quota failed with $?"
2786 mkdir -p $dir1 $dir2
2787 change_project -sp 1 $dir1 && touch $dir1/1
2788 change_project -sp 2 $dir2
2790 mv $dir1/1 $dir2/2 || error "mv failed $?"
2791 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2792 if [ "$projid" != "2" ]; then
2793 error "project id expected 2 not $projid"
2798 run_test 40b "Mv across different project ID"
2801 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2802 ! is_project_quota_supported &&
2803 skip "Project quota is not supported"
2805 setup_quota_test || error "setup quota failed with $?"
2806 local dir="$DIR/$tdir/dir"
2808 mkdir -p $dir && change_project -sp 1 $dir
2809 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2810 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2811 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2812 touch $dir/remote_dir/file
2813 #verify inherit works file for remote dir.
2814 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2815 [ "$projid" != "1" ] &&
2816 error "file under remote dir expected 1 not $projid"
2818 #Agent inode should be ignored for project quota
2819 USED=$(getquota -p 1 global curinodes)
2820 [ "$USED" != "3" ] &&
2821 error "file count expected 3 got $USED"
2827 run_test 40c "Remote child Dir inherit project quota properly"
2830 ! is_project_quota_supported &&
2831 skip "Project quota is not supported"
2833 setup_quota_test || error "setup quota failed with $?"
2834 local dir1="$DIR/$tdir/dir1"
2835 local dir2="$DIR/$tdir/dir2"
2837 mkdir -p $dir1 && change_project -sp 1 $dir1
2838 mkdir -p $dir2 && change_project -sp 2 $dir2
2839 for num in $(seq 1 10); do
2840 touch $dir1/file_$num $dir2/file_$num
2841 ln -s $dir1/file_$num $dir1/file_$num"_link"
2842 ln -s $dir2/file_$num $dir2/file_$num"_link"
2845 count=$($LFS find --projid 1 $DIR | wc -l)
2846 [ "$count" != 21 ] && error "expected 21 but got $count"
2848 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2849 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2850 [ "$count" != 22 ] && error "expected 22 but got $count"
2855 run_test 50 "Test if lfs find --projid works"
2858 ! is_project_quota_supported &&
2859 skip "Project quota is not supported"
2860 setup_quota_test || error "setup quota failed with $?"
2861 local dir="$DIR/$tdir/dir"
2863 mkdir $dir && change_project -sp 1 $dir
2864 local used=$(getquota -p 1 global curinodes)
2865 [ $used != "1" ] && error "expected 1 got $used"
2870 used=$(getquota -p 1 global curinodes)
2871 [ $used != "4" ] && error "expected 4 got $used"
2873 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2875 cp $DIR/$tdir/6 $dir/6
2876 used=$(getquota -p 1 global curinodes)
2877 [ $used != "5" ] && error "expected 5 got $used"
2880 mv $DIR/$tdir/6 $dir/7
2881 used=$(getquota -p 1 global curinodes)
2882 [ $used != "6" ] && error "expected 6 got $used"
2887 run_test 51 "Test project accounting with mv/cp"
2890 ! is_project_quota_supported &&
2891 skip "Project quota is not supported"
2892 setup_quota_test || error "setup quota failed with $?"
2893 local dir="$DIR/$tdir/dir"
2894 mkdir $dir && change_project -sp 1 $dir
2896 touch $DIR/$tdir/file
2897 #Try renaming a file into the project. This should fail.
2898 for num in $(seq 1 2000); do
2899 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2900 error "rename should fail"
2905 run_test 52 "Rename across different project ID"
2908 ! is_project_quota_supported &&
2909 skip "Project quota is not supported"
2910 setup_quota_test || error "setup quota failed with $?"
2911 local dir="$DIR/$tdir/dir"
2912 mkdir $dir && change_project -s $dir
2913 lfs project -d $dir | grep P || error "inherit attribute should be set"
2915 change_project -C $dir
2916 lfs project -d $dir | grep P &&
2917 error "inherit attribute should be cleared"
2922 run_test 53 "Project inherit attribute could be cleared"
2925 ! is_project_quota_supported &&
2926 skip "Project quota is not supported"
2927 setup_quota_test || error "setup quota failed with $?"
2928 trap cleanup_quota_test EXIT
2929 local testfile="$DIR/$tdir/$tfile-0"
2931 #set project ID/inherit attribute
2932 change_project -sp $TSTPRJID $DIR/$tdir
2933 $RUNAS createmany -m ${testfile} 100 ||
2934 error "create many files failed"
2936 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2937 # one more count for directory itself */
2941 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2942 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2944 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2945 [ $proj_count1 -eq $proj_count ] ||
2946 error "c2: expected $proj_count got $proj_count1"
2948 #clear project but with kept projid
2949 change_project -rCk $DIR/$tdir
2950 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2951 [ $proj_count1 -eq 1 ] ||
2952 error "c3: expected 1 got $proj_count1"
2954 #verify projid untouched.
2955 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2957 [ $proj_count1 -eq $proj_count ] ||
2958 error "c4: expected $proj_count got $proj_count1"
2961 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2962 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2963 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2965 #this time clear all
2966 change_project -rC $DIR/$tdir
2967 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2968 [ $proj_count1 -eq 0 ] ||
2969 error "c6: expected 0 got $proj_count1"
2971 unlinkmany ${testfile} 100 ||
2972 error "unlink many files failed"
2976 run_test 54 "basic lfs project interface test"
2979 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
2980 skip "Not supported before 2.10.58."
2981 setup_quota_test || error "setup quota failed with $?"
2983 set_ost_qtype $QTYPE || error "enable ost quota failed"
2986 #add second group to TSTUSR
2987 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
2990 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
2991 error "failed to dd"
2993 cancel_lru_locks osc
2994 sync; sync_all_data || true
2996 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
2997 error "failed to setquota on group $TSTUSR2"
2999 $LFS quota -v -g $TSTUSR2 $DIR
3001 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3002 error "chgrp should failed with -EDQUOT"
3004 USED=$(getquota -g $TSTUSR2 global curspace)
3007 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3008 error "failed to setquota on group $TSTUSR2"
3010 $LFS quota -v -g $TSTUSR2 $DIR
3012 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3013 error "chgrp should succeed"
3015 $LFS quota -v -g $TSTUSR2 $DIR
3019 run_test 55 "Chgrp should be affected by group quota"
3022 setup_quota_test || error "setup quota failed with $?"
3024 set_ost_qtype $QTYPE || error "enable ost quota failed"
3027 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3028 erro "failed to set grace time for usr quota"
3029 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3030 awk '{print $4 $8}')
3031 if [ "x$grace_time" != "x10s;10s" ]; then
3032 $LFS quota -t -u $DIR
3033 error "expected grace time: 10s;10s, got:$grace_time"
3038 run_test 56 "lfs quota -t should work well"
3041 setup_quota_test || error "setup quota failed with $?"
3043 local dir="$DIR/$tdir/dir"
3046 #try to change pipe file should not hang and return failure
3047 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3048 awk -F ':' '{ print \\\$2 }'" \
3049 " unable to get xattr for fifo '$dir/pipe'" || return 1
3050 #command can process further if it hit some errors
3051 touch $dir/aaa $dir/bbb
3052 mkdir $dir/subdir -p
3053 touch $dir/subdir/aaa $dir/subdir/bbb
3054 #create one invalid link file
3055 ln -s $dir/not_exist_file $dir/ccc
3056 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3057 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3061 run_test 57 "lfs project could tolerate errors"
3064 [ "$mds1_FSTYPE" != ldiskfs ] &&
3065 skip "ldiskfs only test"
3066 disable_project_quota
3067 setup_quota_test || error "setup quota failed with $?"
3070 local testfile="$DIR/$tdir/$tfile-0"
3071 #make sure it did not crash kernel
3072 touch $testfile && lfs project -sp 1 $testfile
3074 enable_project_quota
3077 run_test 59 "lfs project dosen't crash kernel with project disabled"
3080 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3081 skip "Needs MDS version 2.11.53 or later."
3082 setup_quota_test || error "setup quota failed with $?"
3083 trap cleanup_quota_test EXIT
3085 local testfile=$DIR/$tdir/$tfile
3088 set_mdt_qtype "ug" || error "enable mdt quota failed"
3090 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3091 error "set quota failed"
3092 quota_show_check a g $TSTUSR
3094 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3095 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3096 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3097 error "create many files failed"
3099 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3101 # root user can overrun quota
3102 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3103 error "root user should succeed"
3107 run_test 60 "Test quota for root with setgid"
3109 # test default quota
3110 test_default_quota() {
3111 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3112 skip "Not supported before 2.11.51."
3117 local qprjid=$TSTPRJID
3121 local LIMIT=20480 #20M disk space
3122 local TESTFILE="$DIR/$tdir/$tfile-0"
3124 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3125 echo "Project quota is not supported" && return 0
3127 [ $qtype == "-u" ] && qdtype="-U"
3128 [ $qtype == "-g" ] && qdtype="-G"
3129 [ $qtype == "-p" ] && {
3134 [ $qpool == "meta" ] && {
3135 LIMIT=10240 #10K inodes
3140 setup_quota_test || error "setup quota failed with $?"
3141 trap cleanup_quota_test EXIT
3145 # enable mdt/ost quota
3146 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3147 set_ost_qtype $QTYPE || error "enable ost quota failed"
3149 log "set to use default quota"
3150 $LFS setquota $qtype $qid -d $DIR ||
3151 error "set $qid to use default quota failed"
3153 log "set default quota"
3154 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3155 error "set $qid default quota failed"
3157 log "get default quota"
3158 $LFS quota $qdtype $DIR || error "get default quota failed"
3160 if [ $qpool == "data" ]; then
3161 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3163 [ $SLIMIT -eq $LIMIT ] ||
3164 error "the returned default quota is wrong"
3166 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3168 [ $SLIMIT -eq $LIMIT ] ||
3169 error "the returned default quota is wrong"
3172 # make sure the system is clean
3173 local USED=$(getquota $qtype $qid global curspace)
3174 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3176 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3177 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3179 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3181 log "Test not out of quota"
3182 if [ $qpool == "data" ]; then
3183 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3184 quota_error $qtype $qid "write failed, expect succeed"
3186 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3187 quota_error $qtype $qid "create failed, expect succeed"
3189 unlinkmany $TESTFILE $((LIMIT/2))
3192 log "Test out of quota"
3193 # flush cache, ensure noquota flag is set on client
3194 cancel_lru_locks osc
3195 cancel_lru_locks mdc
3196 sync; sync_all_data || true
3197 if [ $qpool == "data" ]; then
3198 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3199 quota_error $qtype $qid "write succeed, expect EDQUOT"
3201 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3202 quota_error $qtype $qid "create succeed, expect EDQUOT"
3204 unlinkmany $TESTFILE $((LIMIT*2))
3207 log "Increase default quota"
3208 # increase default quota
3209 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3210 error "set default quota failed"
3212 cancel_lru_locks osc
3213 cancel_lru_locks mdc
3214 sync; sync_all_data || true
3215 if [ $qpool == "data" ]; then
3216 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3217 quota_error $qtype $qid "write failed, expect succeed"
3219 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3220 quota_error $qtype $qid "create failed, expect succeed"
3222 unlinkmany $TESTFILE $((LIMIT*2))
3225 log "Set quota to override default quota"
3226 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3227 error "set $qid quota failed"
3229 cancel_lru_locks osc
3230 cancel_lru_locks mdc
3231 sync; sync_all_data || true
3232 if [ $qpool == "data" ]; then
3233 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3234 quota_error $qtype $qid "write succeed, expect EQUOT"
3236 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3237 quota_error $qtype $qid "create succeed, expect EQUOT"
3239 unlinkmany $TESTFILE $((LIMIT*2))
3242 log "Set to use default quota again"
3243 $LFS setquota $qtype $qid -d $DIR ||
3244 error "set $qid to use default quota failed"
3246 cancel_lru_locks osc
3247 cancel_lru_locks mdc
3248 sync; sync_all_data || true
3249 if [ $qpool == "data" ]; then
3250 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3251 quota_error $qtype $qid "write failed, expect succeed"
3253 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3254 quota_error $qtype $qid "create failed, expect succeed"
3256 unlinkmany $TESTFILE $((LIMIT*2))
3261 wait_delete_completed || error "wait_delete_completed failed"
3262 sync_all_data || true
3263 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3264 error "reset default quota failed"
3265 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3266 error "reset quota failed"
3272 test_default_quota "-u" "data"
3273 test_default_quota "-u" "meta"
3274 test_default_quota "-g" "data"
3275 test_default_quota "-g" "meta"
3276 test_default_quota "-p" "data"
3277 test_default_quota "-p" "meta"
3279 run_test 61 "default quota tests"
3282 ! is_project_quota_supported &&
3283 skip "Project quota is not supported"
3284 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3285 skip "chattr did not support project quota"
3286 setup_quota_test || error "setup quota failed with $?"
3287 local testdir=$DIR/$tdir/
3289 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3290 change_project -s $testdir
3291 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3292 error "inherit attribute should be set"
3293 # chattr used FS_IOC_SETFLAGS ioctl
3294 $RUNAS chattr -P $testdir &&
3295 error "regular user clear inherit should fail"
3296 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3297 error "inherit attribute should still be set"
3298 chattr -P $testdir || error "root failed to clear inherit"
3299 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3300 error "inherit attribute should be cleared"
3303 run_test 62 "Project inherit should be only changed by root"
3306 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3307 skip "Not supported before 2.11.55"
3311 local dd_failed=false
3312 local tdir_dom=${tdir}_dom
3313 local LIMIT=20480 #20M
3315 [ $qtype == "p" ] && ! is_project_quota_supported &&
3316 echo "Project quota is not supported" && return 0
3318 [ $qtype == "p" ] && qid=$TSTPRJID
3320 setup_quota_test || error "setup quota failed with $?"
3321 trap cleanup_quota_test EXIT
3325 # enable mdt/ost quota
3326 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3327 set_ost_qtype $QTYPE || error "enable ost quota failed"
3329 # make sure the system is clean
3330 local USED=$(getquota -$qtype $qid global curspace)
3331 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3333 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3335 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3336 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3337 error "setstripe $tdir_dom failed"
3338 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3340 [ $qtype == "p" ] && {
3341 change_project -sp $TSTPRJID $DIR/$tdir
3342 change_project -sp $TSTPRJID $DIR/$tdir_dom
3345 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3346 error "set $qid quota failed"
3348 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3349 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3353 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3355 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3356 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3360 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3362 rm -f $DIR/$tdir_dom/*
3364 # flush cache, ensure noquota flag is set on client
3365 cancel_lru_locks osc
3366 cancel_lru_locks mdc
3367 sync; sync_all_data || true
3371 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3372 quota_error $qtype $qid "write failed, expect succeed"
3374 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3375 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3379 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3382 rm -f $DIR/$tdir_dom/*
3384 # flush cache, ensure noquota flag is set on client
3385 cancel_lru_locks osc
3386 cancel_lru_locks mdc
3387 sync; sync_all_data || true
3391 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3392 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3396 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3398 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3399 quota_error $qtype $qid "write succeed, expect EDQUOT"
3402 rm -fr $DIR/$tdir_dom
3404 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3405 error "reset usr quota failed"
3415 run_test 63 "quota on DoM tests"
3418 ! is_project_quota_supported &&
3419 skip "Project quota is not supported"
3420 setup_quota_test || error "setup quota failed with $?"
3421 local dir1="$DIR/$tdir/"
3424 ln -s $dir1/file $dir1/file_link
3426 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3427 error "set symlink file's project should fail"
3429 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3430 error "get symlink file's project should fail"
3434 run_test 64 "lfs project on symlink files should fail"
3438 local TESTFILE="$DIR/$tdir/$tfile-0"
3440 setup_quota_test || error "setup quota failed with $?"
3441 set_ost_qtype $QTYPE || error "enable ost quota failed"
3445 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3446 error "failed to write"
3447 # flush cache, ensure noquota flag is set on client
3448 cancel_lru_locks osc
3449 sync; sync_all_data || true
3451 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3452 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3453 local quota_all=$($RUNAS $LFS quota $DIR)
3455 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3456 error "usr quota not match"
3457 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3458 error "grp quota not match"
3464 run_test 65 "Check lfs quota result"
3468 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3469 if $PQ_CLEANUP; then
3470 disable_project_quota
3473 reset_quota_settings
3478 check_and_cleanup_lustre
3479 export QUOTA_AUTO=$QUOTA_AUTO_OLD