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 [ $(facet_fstype $SINGLEMDS) = "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 [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip_env "e2fsprogs doesn't support quota" && exit 0
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 [ $(facet_fstype $SINGLEMDS) = "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 [ $(facet_fstype $SINGLEMDS) = "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 do_facet ost1 $LCTL set_param \
1145 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1147 # write to un-enforced ID ($TSTUSR2) should succeed
1148 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1149 error "write failure, expect success"
1151 # write to enforced ID ($TSTUSR) in background, exceeding limit
1152 # to make sure DQACQ is sent
1153 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1156 # watchdog timer uses a factor of 2
1157 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1158 sleep $((TIMEOUT * 2 + 1))
1160 # write should be blocked and never finished
1161 if ! ps -p $DDPID > /dev/null 2>&1; then
1163 error "write finished incorrectly!"
1168 # no watchdog is triggered
1169 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1170 watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1171 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1172 [ -z "$watchdog" ] || error "$watchdog"
1174 rm -f $TMP/lustre-log-${TESTNAME}.log
1176 # write should continue then fail with EDQUOT
1180 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1181 if [ $count -ge 240 ]; then
1182 quota_error u $TSTUSR "dd not finished in $count secs"
1184 count=$((count + 1))
1185 if [ $((count % 30)) -eq 0 ]; then
1186 c_size=$(stat -c %s $TESTFILE)
1187 echo "Waiting $count secs. $c_size"
1195 run_test 6 "Test dropping acquire request on master"
1197 # quota reintegration (global index)
1199 local TESTFILE=$DIR/$tdir/$tfile
1200 local LIMIT=20 # 20M
1202 [ "$SLOW" = "no" ] && LIMIT=5
1204 setup_quota_test || error "setup quota failed with $?"
1205 trap cleanup_quota_test EXIT
1207 # make sure the system is clean
1208 local USED=$(getquota -u $TSTUSR global curspace)
1209 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1211 # make sure no granted quota on ost1
1212 set_ost_qtype $QTYPE || error "enable ost quota failed"
1213 resetquota -u $TSTUSR
1214 set_ost_qtype "none" || error "disable ost quota failed"
1216 local OSTUUID=$(ostuuid_from_index 0)
1217 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1219 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1222 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1223 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1228 echo "Enable quota & set quota limit for $TSTUSR"
1229 set_ost_qtype $QTYPE || error "enable ost quota failed"
1230 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1231 error "set quota failed"
1233 echo "Start ost1..."
1234 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1237 wait_ost_reint $QTYPE || error "reintegration failed"
1239 # hardlimit should have been fetched by slave during global
1240 # reintegration, write will exceed quota
1241 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1242 quota_error u $TSTUSR "write success, but expect EDQUOT"
1245 wait_delete_completed
1246 sync_all_data || true
1252 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1253 error "clear quota failed"
1255 echo "Start ost1..."
1256 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1259 wait_ost_reint $QTYPE || error "reintegration failed"
1261 # hardlimit should be cleared on slave during reintegration
1262 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1263 quota_error u $TSTUSR "write error, but expect success"
1267 run_test 7a "Quota reintegration (global index)"
1269 # quota reintegration (slave index)
1272 local TESTFILE=$DIR/$tdir/$tfile
1274 setup_quota_test || error "setup quota failed with $?"
1275 trap cleanup_quota_test EXIT
1277 # make sure the system is clean
1278 local USED=$(getquota -u $TSTUSR global curspace)
1279 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1281 # make sure no granted quota on ost1
1282 set_ost_qtype $QTYPE || error "enable ost quota failed"
1283 resetquota -u $TSTUSR
1284 set_ost_qtype "none" || error "disable ost quota failed"
1286 local OSTUUID=$(ostuuid_from_index 0)
1287 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1289 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1292 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1293 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1295 # consume some space to make sure the granted space will not
1296 # be released during reconciliation
1297 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1298 error "consume space failure, expect success"
1300 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1301 lustre_fail mds 0xa02
1303 set_ost_qtype $QTYPE || error "enable ost quota failed"
1304 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1305 error "set quota failed"
1307 # ignore the write error
1308 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1310 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1314 echo "Restart ost to trigger reintegration..."
1316 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1319 wait_ost_reint $QTYPE || error "reintegration failed"
1321 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1322 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1327 run_test 7b "Quota reintegration (slave index)"
1329 # quota reintegration (restart mds during reintegration)
1331 local LIMIT=20 # 20M
1332 local TESTFILE=$DIR/$tdir/$tfile
1334 [ "$SLOW" = "no" ] && LIMIT=5
1336 setup_quota_test || error "setup quota failed with $?"
1337 trap cleanup_quota_test EXIT
1339 # make sure the system is clean
1340 local USED=$(getquota -u $TSTUSR global curspace)
1341 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1343 set_ost_qtype "none" || error "disable ost quota failed"
1344 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1345 error "set quota failed"
1347 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1348 lustre_fail ost 0xa03
1351 set_ost_qtype $QTYPE || error "enable ost quota failed"
1352 # trigger reintegration
1353 local procf="osd-$(facet_fstype ost1).$FSNAME-OST*."
1354 procf=${procf}quota_slave.force_reint
1355 do_facet ost1 $LCTL set_param $procf=1 ||
1356 error "force reintegration failed"
1364 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1367 # wait longer than usual to make sure the reintegration
1368 # is triggered by quota wb thread.
1369 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1371 # hardlimit should have been fetched by slave during global
1372 # reintegration, write will exceed quota
1373 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1374 quota_error u $TSTUSR "write success, but expect EDQUOT"
1378 run_test 7c "Quota reintegration (restart mds during reintegration)"
1380 # Quota reintegration (Transfer index in multiple bulks)
1382 local TESTFILE=$DIR/$tdir/$tfile
1383 local TESTFILE1="$DIR/$tdir/$tfile"-1
1386 setup_quota_test || error "setup quota failed with $?"
1387 trap cleanup_quota_test EXIT
1389 set_ost_qtype "none" || error "disable ost quota failed"
1390 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1391 error "set quota for $TSTUSR failed"
1392 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1393 error "set quota for $TSTUSR2 failed"
1395 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1396 lustre_fail mds 0x608 0
1398 # enable quota to tirgger reintegration
1399 set_ost_qtype "u" || error "enable ost quota failed"
1400 wait_ost_reint "u" || error "reintegration failed"
1404 # hardlimit should have been fetched by slave during global
1405 # reintegration, write will exceed quota
1406 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1407 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1409 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1410 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1414 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1416 # quota reintegration (inode limits)
1418 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1420 # LU-2435: skip this quota test if underlying zfs version has not
1421 # supported native dnode accounting
1422 [ "$(facet_fstype mds1)" == "zfs" ] && {
1423 local F="feature@userobj_accounting"
1424 local pool=$(zpool_name mds1)
1425 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1427 [[ "$feature" != *" active "* ]] &&
1428 skip "requires zpool with active userobj_accounting"
1431 local ilimit=$((1024 * 2)) # 2k inodes
1432 local TESTFILE=$DIR/${tdir}-1/$tfile
1434 setup_quota_test || error "setup quota failed with $?"
1435 trap cleanup_quota_test EXIT
1437 # make sure the system is clean
1438 local USED=$(getquota -u $TSTUSR global curinodes)
1439 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1441 # make sure no granted quota on mdt1
1442 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1443 resetquota -u $TSTUSR
1444 set_mdt_qtype "none" || error "disable mdt quota failed"
1446 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1447 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1448 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1451 echo "Stop mds${MDSCOUNT}..."
1454 echo "Enable quota & set quota limit for $TSTUSR"
1455 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1456 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1457 error "set quota failed"
1459 echo "Start mds${MDSCOUNT}..."
1460 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1463 wait_mdt_reint $QTYPE || error "reintegration failed"
1465 echo "create remote dir"
1466 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1467 error "create remote dir failed"
1468 chmod 0777 $DIR/${tdir}-1
1470 # hardlimit should have been fetched by slave during global
1471 # reintegration, create will exceed quota
1472 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1473 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1475 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1476 wait_delete_completed
1477 sync_all_data || true
1479 echo "Stop mds${MDSCOUNT}..."
1482 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1483 error "clear quota failed"
1485 echo "Start mds${MDSCOUNT}..."
1486 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1489 wait_mdt_reint $QTYPE || error "reintegration failed"
1491 # hardlimit should be cleared on slave during reintegration
1492 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1493 quota_error u $TSTUSR "create failed, expect success"
1495 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1496 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1500 run_test 7e "Quota reintegration (inode limits)"
1502 # run dbench with quota enabled
1504 local BLK_LIMIT="100g" #100G
1505 local FILE_LIMIT=1000000
1507 setup_quota_test || error "setup quota failed with $?"
1508 trap cleanup_quota_test EXIT
1510 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1511 set_ost_qtype $QTYPE || error "enable ost quota failed"
1513 echo "Set enough high limit for user: $TSTUSR"
1514 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1515 error "set user quota failed"
1516 echo "Set enough high limit for group: $TSTUSR"
1517 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1518 error "set group quota failed"
1519 if is_project_quota_supported; then
1520 change_project -sp $TSTPRJID $DIR/$tdir
1521 echo "Set enough high limit for project: $TSTPRJID"
1522 $LFS setquota -p $TSTPRJID -b 0 \
1523 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1524 error "set project quota failed"
1528 [ "$SLOW" = "no" ] && duration=" -t 120"
1529 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1530 quota_error a $TSTUSR "dbench failed!"
1532 is_project_quota_supported && change_project -C $DIR/$tdir
1535 run_test 8 "Run dbench with quota enabled"
1537 # this check is just for test_9
1538 OST0_MIN=4900000 #4.67G
1540 check_whether_skip () {
1541 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1542 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1543 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1544 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1551 # run for fixing bug10707, it needs a big room. test for 64bit
1553 local filesize=$((1024 * 9 / 2)) # 4.5G
1555 check_whether_skip && return 0
1557 setup_quota_test || error "setup quota failed with $?"
1558 trap cleanup_quota_test EXIT
1560 set_ost_qtype "ug" || error "enable ost quota failed"
1562 local TESTFILE="$DIR/$tdir/$tfile-0"
1563 local BLK_LIMIT=100G #100G
1564 local FILE_LIMIT=1000000
1566 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1568 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1570 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1571 error "set user quota failed"
1573 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1574 "for group: $TSTUSR"
1575 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1576 error "set group quota failed"
1578 quota_show_check a u $TSTUSR
1579 quota_show_check a g $TSTUSR
1581 echo "Create test file"
1582 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1583 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1585 log "Write the big file of 4.5G ..."
1586 $RUNAS $DD of=$TESTFILE count=$filesize ||
1587 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1597 run_test 9 "Block limit larger than 4GB (b10707)"
1600 local TESTFILE=$DIR/$tdir/$tfile
1602 setup_quota_test || error "setup quota failed with $?"
1603 trap cleanup_quota_test EXIT
1605 # set limit to root user should fail
1606 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1607 error "set limit for root user successfully, expect failure"
1608 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1609 error "set limit for root group successfully, expect failure"
1610 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1611 error "set limit for project 0 successfully, expect failure"
1613 # root user can overrun quota
1614 set_ost_qtype "ug" || error "enable ost quota failed"
1616 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1617 error "set quota failed"
1618 quota_show_check b u $TSTUSR
1620 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1621 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1623 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1624 error "write failure, expect success"
1628 run_test 10 "Test quota for root user"
1631 local TESTFILE=$DIR/$tdir/$tfile
1632 setup_quota_test || error "setup quota failed with $?"
1633 trap cleanup_quota_test EXIT
1635 set_mdt_qtype "ug" || error "enable mdt quota failed"
1636 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1637 error "set quota failed"
1639 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1640 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1642 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1643 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1646 local USED=$(getquota -u $TSTUSR global curinodes)
1647 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1651 run_test 11 "Chown/chgrp ignores quota"
1654 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1656 local blimit=22 # 22M
1657 local blk_cnt=$((blimit - 5))
1658 local TESTFILE0="$DIR/$tdir/$tfile"-0
1659 local TESTFILE1="$DIR/$tdir/$tfile"-1
1661 setup_quota_test || error "setup quota failed with $?"
1662 trap cleanup_quota_test EXIT
1664 set_ost_qtype "u" || error "enable ost quota failed"
1665 quota_show_check b u $TSTUSR
1667 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1668 error "set quota failed"
1670 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1671 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1672 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1673 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1675 echo "Write to ost0..."
1676 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1677 quota_error a $TSTUSR "dd failed"
1679 echo "Write to ost1..."
1680 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1681 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1683 echo "Free space from ost0..."
1685 wait_delete_completed
1686 sync_all_data || true
1688 echo "Write to ost1 after space freed from ost0..."
1689 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1690 quota_error a $TSTUSR "rebalancing failed"
1694 run_test 12a "Block quota rebalancing"
1697 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1699 local ilimit=$((1024 * 2)) # 2k inodes
1700 local TESTFILE0=$DIR/$tdir/$tfile
1701 local TESTFILE1=$DIR/${tdir}-1/$tfile
1703 setup_quota_test || error "setup quota failed with $?"
1704 trap cleanup_quota_test EXIT
1706 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1707 chmod 0777 $DIR/${tdir}-1
1709 set_mdt_qtype "u" || error "enable mdt quota failed"
1710 quota_show_check f u $TSTUSR
1712 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1713 error "set quota failed"
1715 echo "Create $ilimit files on mdt0..."
1716 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1717 quota_error u $TSTUSR "create failed, but expect success"
1719 echo "Create files on mdt1..."
1720 $RUNAS createmany -m $TESTFILE1 1 &&
1721 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1723 echo "Free space from mdt0..."
1724 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1725 wait_delete_completed
1726 sync_all_data || true
1728 echo "Create files on mdt1 after space freed from mdt0..."
1729 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1730 quota_error a $TSTUSR "rebalancing failed"
1732 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1733 error "unlink mdt1 files failed"
1734 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1738 run_test 12b "Inode quota rebalancing"
1741 local TESTFILE=$DIR/$tdir/$tfile
1742 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1743 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1745 setup_quota_test || error "setup quota failed with $?"
1746 trap cleanup_quota_test EXIT
1748 set_ost_qtype "u" || error "enable ost quota failed"
1749 quota_show_check b u $TSTUSR
1751 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1752 error "set quota failed"
1753 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1754 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1756 # clear the locks in cache first
1757 do_facet ost1 $LCTL set_param -n $procf=clear
1758 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1759 [ $nlock -eq 0 ] || error "$nlock cached locks"
1761 # write to acquire the per-ID lock
1762 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1763 quota_error a $TSTUSR "dd failed"
1765 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1766 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1768 # clear quota doesn't trigger per-ID lock cancellation
1769 resetquota -u $TSTUSR
1770 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1771 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1773 # clear the per-ID lock
1774 do_facet ost1 $LCTL set_param -n $procf=clear
1775 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1776 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1778 # spare quota should be released
1779 local OSTUUID=$(ostuuid_from_index 0)
1780 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1781 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1782 [ $limit -le $space ] ||
1783 error "spare quota isn't released, limit:$limit, space:$space"
1787 run_test 13 "Cancel per-ID lock in the LRU list"
1790 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1792 wait_delete_completed
1793 sync_all_data || true
1796 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1797 error "set user quota failed"
1798 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1799 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1800 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1801 resetquota -u $TSTUSR
1804 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1805 error "set group quota failed"
1806 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1807 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1808 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1809 resetquota -g $TSTUSR
1811 run_test 15 "Set over 4T block quota"
1815 local BLKS=1 # 1M less than limit
1816 local TESTFILE=$DIR/$tdir/$tfile
1818 setup_quota_test || error "setup quota failed with $?"
1819 trap cleanup_quota_test EXIT
1821 # make sure the system is clean
1822 local USED=$(getquota -u $TSTUSR global curspace)
1823 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1825 set_ost_qtype "ug" || error "enable ost quota failed"
1826 # make sure no granted quota on ost
1827 resetquota -u $TSTUSR
1828 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1829 error "set quota failed"
1831 quota_show_check b u $TSTUSR
1833 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1834 lustre_fail mds 0xa04 $err_code
1836 # write in background
1837 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1841 # write should be blocked and never finished
1842 if ! ps -p $DDPID > /dev/null 2>&1; then
1844 quota_error u $TSTUSR "write finished incorrectly!"
1852 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1854 if [ $count -gt $timeout ]; then
1855 quota_error u $TSTUSR "dd is not finished!"
1860 sync; sync_all_data || true
1862 USED=$(getquota -u $TSTUSR global curspace)
1863 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1864 "Used space(${USED}K) is less than ${BLKS}M"
1869 # DQACQ return recoverable error
1871 echo "DQACQ return -ENOLCK"
1873 test_17sub 37 || error "Handle -ENOLCK failed"
1875 echo "DQACQ return -EAGAIN"
1877 test_17sub 11 || error "Handle -EAGAIN failed"
1879 echo "DQACQ return -ETIMEDOUT"
1880 #define ETIMEDOUT 110
1881 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1883 echo "DQACQ return -ENOTCONN"
1884 #define ENOTCONN 107
1885 test_17sub 107 || error "Handle -ENOTCONN failed"
1888 run_test 17 "DQACQ return recoverable error"
1892 local blimit="200m" # 200M
1893 local TESTFILE="$DIR/$tdir/$tfile"
1895 setup_quota_test || error "setup quota failed with $?"
1896 trap cleanup_quota_test EXIT
1898 set_ost_qtype "u" || error "enable ost quota failed"
1899 log "User quota (limit: $blimit)"
1900 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1901 error "set quota failed"
1902 quota_show_check b u $TSTUSR
1904 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1905 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1907 local timeout=$(sysctl -n lustre.timeout)
1909 if [ $io_type = "directio" ]; then
1910 log "Write 100M (directio) ..."
1911 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1913 log "Write 100M (buffered) ..."
1914 $RUNAS $DD of=$TESTFILE count=100 &
1918 replay_barrier $SINGLEMDS
1919 log "Fail mds for $((2 * timeout)) seconds"
1920 fail $SINGLEMDS $((2 * timeout))
1923 if at_is_enabled; then
1924 timeout=$(at_max_get mds)
1926 timeout=$(lctl get_param -n timeout)
1930 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1931 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1932 log "it took $count second"
1937 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1939 cancel_lru_locks mdc
1940 cancel_lru_locks osc
1943 local testfile_size=$(stat -c %s $TESTFILE)
1944 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1945 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1946 "got ${testfile_size}. Verifying file failed!"
1951 # test when mds does failover, the ost still could work well
1952 # this test shouldn't trigger watchdog b=14840
1954 # Clear dmesg so watchdog is not triggered by previous
1956 do_facet ost1 dmesg -c > /dev/null
1959 test_18_sub directio
1961 # check if watchdog is triggered
1962 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1963 local watchdog=$(awk '/Service thread pid/ && /was inactive/ \
1964 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1965 [ -z "$watchdog" ] || error "$watchdog"
1966 rm -f $TMP/lustre-log-${TESTNAME}.log
1968 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
1972 local TESTFILE=$DIR/$tdir/$tfile
1974 setup_quota_test || error "setup quota failed with $?"
1975 trap cleanup_quota_test EXIT
1977 set_ost_qtype $QTYPE || error "enable ost quota failed"
1979 # bind file to a single OST
1980 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
1981 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1983 echo "Set user quota (limit: ${blimit}M)"
1984 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1985 error "set user quota failed"
1986 quota_show_check b u $TSTUSR
1987 echo "Update quota limits"
1988 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
1989 error "set group quota failed"
1990 quota_show_check b u $TSTUSR
1992 # first wirte might be cached
1993 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
1994 cancel_lru_locks osc
1996 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
1997 quota_error u $TSTUSR "Write success, expect failure"
2002 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2004 test_20() { # b15754
2005 local LSTR=(2g 1t 4k 3m) # limits strings
2007 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2010 resetquota -u $TSTUSR
2012 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2013 $MOUNT || error "could not set quota limits"
2014 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2015 --inode-softlimit ${LSTR[2]} \
2016 --inode-hardlimit ${LSTR[3]} \
2017 $MOUNT || error "could not set quota limits"
2019 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2020 error "bsoftlimit was not set properly"
2021 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2022 error "bhardlimit was not set properly"
2023 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2024 error "isoftlimit was not set properly"
2025 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2026 error "ihardlimit was not set properly"
2028 resetquota -u $TSTUSR
2030 run_test 20 "Test if setquota specifiers work properly (b15754)"
2037 local time=$(($(date +%s) + seconds))
2038 while [ $(date +%s) -lt $time ]; do
2039 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2043 # run for fixing bug16053, setquota shouldn't fail when writing and
2044 # deleting are happening
2046 local TESTFILE="$DIR/$tdir/$tfile"
2047 local BLIMIT=10 # 10G
2048 local ILIMIT=1000000
2050 setup_quota_test || error "setup quota failed with $?"
2051 trap cleanup_quota_test EXIT
2053 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2055 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2056 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2057 error "set user quota failed"
2058 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2059 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2060 error "set group quota failed"
2061 if is_project_quota_supported; then
2062 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2063 "project: $TSTPRJID"
2064 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2065 $MOUNT || error "set project quota failed"
2068 # repeat writing on a 1M file
2069 test_21_sub ${TESTFILE}_1 1 30 &
2071 # repeat writing on a 128M file
2072 test_21_sub ${TESTFILE}_2 128 30 &
2075 local time=$(($(date +%s) + 30))
2077 while [ $(date +%s) -lt $time ]; do
2078 log "Set quota for $i times"
2079 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2080 -I $((ILIMIT + i)) $MOUNT ||
2081 error "Set user quota failed"
2082 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2083 -I $((ILIMIT + i)) $MOUNT ||
2084 error "Set group quota failed"
2085 if is_project_quota_supported; then
2086 $LFS setquota -p $TSTPRJID -b 0 -B \
2087 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2088 error "Set project quota failed"
2096 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2098 if [ $count -gt 60 ]; then
2099 quota_error a $TSTUSR "dd should be finished!"
2103 echo "(dd_pid=$DDPID1, time=$count)successful"
2107 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2109 if [ $count -gt 60 ]; then
2110 quota_error a $TSTUSR "dd should be finished!"
2114 echo "(dd_pid=$DDPID2, time=$count)successful"
2118 run_test 21 "Setquota while writing & deleting (b16053)"
2120 # enable/disable quota enforcement permanently
2122 echo "Set both mdt & ost quota type as ug"
2124 is_project_quota_supported && qtype=$QTYPE
2125 set_mdt_qtype $qtype || error "enable mdt quota failed"
2126 set_ost_qtype $qtype || error "enable ost quota failed"
2129 stopall || error "failed to stopall (1)"
2133 echo "Verify if quota is enabled"
2134 local qtype1=$(mdt_quota_type)
2135 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2136 qtype=$(ost_quota_type)
2137 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2139 echo "Set both mdt & ost quota type as none"
2140 set_mdt_qtype "none" || error "disable mdt quota failed"
2141 set_ost_qtype "none" || error "disable ost quota failed"
2144 stopall || error "failed to stopall (2)"
2149 echo "Verify if quota is disabled"
2150 qtype=$(mdt_quota_type)
2151 [ $qtype != "none" ] && error "mdt quota setting is lost"
2152 qtype=$(ost_quota_type)
2153 [ $qtype != "none" ] && error "ost quota setting is lost"
2157 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2160 local TESTFILE="$DIR/$tdir/$tfile"
2163 setup_quota_test || error "setup quota failed with $?"
2164 trap cleanup_quota_test EXIT
2166 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2169 log "User quota (limit: $LIMIT MB)"
2170 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2171 error "set quota failed"
2172 quota_show_check b u $TSTUSR
2174 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2175 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2177 log "Step1: trigger EDQUOT with O_DIRECT"
2178 log "Write half of file"
2179 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2180 quota_error u $TSTUSR "(1) Write failure, expect success." \
2182 log "Write out of block quota ..."
2183 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2184 oflag=direct conv=notrunc &&
2185 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2189 log "Step2: rewrite should succeed"
2190 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2191 quota_error u $TSTUSR "(3) Write failure, expect success." \
2197 local OST0_UUID=$(ostuuid_from_index 0)
2198 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2199 [ $OST0_QUOTA_USED -ne 0 ] &&
2200 ($SHOW_QUOTA_USER; \
2201 quota_error u $TSTUSR "quota isn't released")
2206 [ $(facet_fstype ost1) == "zfs" ] &&
2207 skip "Overwrite in place is not guaranteed to be " \
2208 "space neutral on ZFS"
2210 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2211 check_whether_skip && return 0
2212 log "run for 4MB test file"
2215 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2216 check_whether_skip && return 0
2217 log "run for 40MB test file"
2220 run_test 23 "Quota should be honored with directIO (b16125)"
2224 local TESTFILE="$DIR/$tdir/$tfile"
2226 setup_quota_test || error "setup quota failed with $?"
2227 trap cleanup_quota_test EXIT
2229 set_ost_qtype $QTYPE || error "enable ost quota failed"
2231 # bind file to a single OST
2232 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2233 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2235 echo "Set user quota (limit: ${blimit}M)"
2236 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2237 error "set quota failed"
2239 # overrun quota by root user
2240 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2241 error "write failure, expect success"
2242 cancel_lru_locks osc
2243 sync_all_data || true
2245 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2249 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2251 test_27a() { # b19612
2252 $LFS quota $TSTUSR $DIR &&
2253 error "lfs succeeded with no type, but should have failed"
2254 $LFS setquota $TSTUSR $DIR &&
2255 error "lfs succeeded with no type, but should have failed"
2258 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2260 test_27b() { # b20200
2261 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2262 error "lfs setquota failed with uid argument"
2263 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2264 error "lfs stequota failed with gid argument"
2265 if is_project_quota_supported; then
2266 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2267 1000 $DIR || error \
2268 "lfs stequota failed with projid argument"
2270 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2271 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2272 if is_project_quota_supported; then
2273 $SHOW_QUOTA_PROJID ||
2274 error "lfs quota failed with projid argument"
2276 resetquota -u $TSTUSR
2277 resetquota -g $TSTUSR
2278 resetquota -p $TSTPRJID
2281 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2286 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2287 error "lfs setquota failed"
2289 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2290 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2291 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2292 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2294 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2295 error "lfs setquota for $TSTID failed"
2297 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2298 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2299 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2300 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2302 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2303 error "total allocated inode/block limit not printed"
2305 resetquota -u $TSTUSR
2307 run_test 27c "lfs quota should support human-readable output"
2314 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2315 error "set fraction block limit failed"
2316 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2317 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2318 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2319 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2321 resetquota -u $TSTUSR
2323 run_test 27d "lfs setquota should support fraction block limit"
2327 local TESTFILE="$DIR/$tdir/$tfile"
2330 setup_quota_test || error "setup quota failed with $?"
2331 trap cleanup_quota_test EXIT
2333 set_ost_qtype "u" || error "enable ost quota failed"
2335 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2336 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2338 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2339 $MAX_IQ_TIME $DIR || error "set grace time failed"
2340 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2341 error "set quota failed"
2342 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2343 cancel_lru_locks osc
2345 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2346 # over-quota flag has not yet settled since we do not trigger async
2347 # events based on grace time period expiration
2349 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2350 cancel_lru_locks osc
2351 # now over-quota flag should be settled and further writes should fail
2353 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2354 error "grace times were reset"
2357 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2358 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2360 run_test 30 "Hard limit updates should not reset grace times"
2362 # basic usage tracking for user & group
2364 local INODES=10 # 10 files
2365 local BLK_CNT=2 # of 2M each
2366 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2368 setup_quota_test || error "setup quota failed with $?"
2369 trap cleanup_quota_test EXIT
2371 # make sure the system is clean
2372 local USED=$(getquota -u $TSTID global curspace)
2374 error "Used space ($USED) for user $TSTID isn't 0."
2375 USED=$(getquota -g $TSTID global curspace)
2377 error "Used space ($USED) for group $TSTID isn't 0."
2378 if is_project_quota_supported; then
2379 USED=$(getquota -p $TSTPRJID global curspace)
2380 [ $USED -ne 0 ] && error \
2381 "Used space ($USED) for project $TSTPRJID isn't 0."
2384 echo "Write files..."
2385 for i in $(seq 0 $INODES); do
2386 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2387 error "write failed"
2388 is_project_quota_supported &&
2389 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2390 echo "Iteration $i/$INODES completed"
2392 cancel_lru_locks osc
2394 echo "Wait for setattr on objects finished..."
2395 wait_delete_completed
2397 sync; sync_all_data || true
2399 echo "Verify disk usage after write"
2400 USED=$(getquota -u $TSTID global curspace)
2401 [ $USED -lt $TOTAL_BLKS ] &&
2402 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2403 USED=$(getquota -g $TSTID global curspace)
2404 [ $USED -lt $TOTAL_BLKS ] &&
2405 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2406 if is_project_quota_supported; then
2407 USED=$(getquota -p $TSTPRJID global curspace)
2408 [ $USED -lt $TOTAL_BLKS ] && error \
2409 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2412 echo "Verify inode usage after write"
2413 USED=$(getquota -u $TSTID global curinodes)
2414 [ $USED -lt $INODES ] &&
2415 error "Used inode for user $TSTID is $USED, expected $INODES"
2416 USED=$(getquota -g $TSTID global curinodes)
2417 [ $USED -lt $INODES ] &&
2418 error "Used inode for group $TSTID is $USED, expected $INODES"
2419 if is_project_quota_supported; then
2420 USED=$(getquota -p $TSTPRJID global curinodes)
2421 [ $USED -lt $INODES ] && error \
2422 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2427 echo "Verify disk usage after delete"
2428 USED=$(getquota -u $TSTID global curspace)
2429 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2430 USED=$(getquota -u $TSTID global curinodes)
2431 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2432 USED=$(getquota -g $TSTID global curspace)
2433 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2434 USED=$(getquota -g $TSTID global curinodes)
2435 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2436 if is_project_quota_supported; then
2437 USED=$(getquota -p $TSTPRJID global curspace)
2439 error "Used space for project $TSTPRJID isn't 0. $USED"
2440 USED=$(getquota -p $TSTPRJID global curinodes)
2442 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2445 run_test 33 "Basic usage tracking for user & group & project"
2447 # usage transfer test for user & group & project
2449 local BLK_CNT=2 # 2MB
2450 local project_supported="no"
2452 is_project_quota_supported && project_supported="yes"
2453 setup_quota_test || error "setup quota failed with $?"
2454 trap cleanup_quota_test EXIT
2456 # make sure the system is clean
2457 local USED=$(getquota -u $TSTID global curspace)
2458 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2459 USED=$(getquota -g $TSTID global curspace)
2460 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2462 local USED=$(getquota -u $TSTID2 global curspace)
2463 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2464 if [ $project_supported == "yes" ]; then
2465 USED=$(getquota -p $TSTPRJID global curspace)
2466 [ $USED -ne 0 ] && error \
2467 "Used space ($USED) for Project $TSTPRJID isn't 0."
2470 echo "Write file..."
2471 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2472 error "write failed"
2473 cancel_lru_locks osc
2474 sync; sync_all_data || true
2476 echo "chown the file to user $TSTID"
2477 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2479 echo "Wait for setattr on objects finished..."
2480 wait_delete_completed
2482 BLK_CNT=$((BLK_CNT * 1024))
2484 echo "Verify disk usage for user $TSTID"
2485 USED=$(getquota -u $TSTID global curspace)
2486 [ $USED -lt $BLK_CNT ] &&
2487 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2488 USED=$(getquota -u $TSTID global curinodes)
2490 error "Used inodes for user $TSTID is $USED, expected 1"
2492 echo "chgrp the file to group $TSTID"
2493 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2495 echo "Wait for setattr on objects finished..."
2496 wait_delete_completed
2498 echo "Verify disk usage for group $TSTID"
2499 USED=$(getquota -g $TSTID global curspace)
2500 [ $USED -ge $BLK_CNT ] ||
2501 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2502 USED=$(getquota -g $TSTID global curinodes)
2504 error "Used inodes for group $TSTID is $USED, expected 1"
2506 # chown won't change the ost object group. LU-4345 */
2507 echo "chown the file to user $TSTID2"
2508 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2510 echo "Wait for setattr on objects finished..."
2511 wait_delete_completed
2513 echo "change_project project id to $TSTPRJID"
2514 [ $project_supported == "yes" ] &&
2515 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2516 echo "Wait for setattr on objects finished..."
2517 wait_delete_completed
2519 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2520 USED=$(getquota -u $TSTID2 global curspace)
2521 [ $USED -lt $BLK_CNT ] &&
2522 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2523 USED=$(getquota -u $TSTID global curspace)
2525 error "Used space for user $TSTID is $USED, expected 0"
2526 USED=$(getquota -g $TSTID global curspace)
2527 [ $USED -lt $BLK_CNT ] &&
2528 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2529 if [ $project_supported == "yes" ]; then
2530 USED=$(getquota -p $TSTPRJID global curspace)
2531 [ $USED -lt $BLK_CNT ] && error \
2532 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2537 run_test 34 "Usage transfer for user & group & project"
2539 # usage is still accessible across restart
2541 local BLK_CNT=2 # 2 MB
2543 setup_quota_test || error "setup quota failed with $?"
2544 trap cleanup_quota_test EXIT
2546 echo "Write file..."
2547 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2548 error "write failed"
2549 is_project_quota_supported &&
2550 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2551 cancel_lru_locks osc
2553 echo "Wait for setattr on objects finished..."
2554 wait_delete_completed
2556 sync; sync_all_data || true
2558 echo "Save disk usage before restart"
2559 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2560 [ $ORIG_USR_SPACE -eq 0 ] &&
2561 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2562 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2563 [ $ORIG_USR_INODES -eq 0 ] &&
2564 error "Used inodes for user $TSTID is 0, expected 1"
2565 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2566 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2567 [ $ORIG_GRP_SPACE -eq 0 ] &&
2568 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2569 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2570 [ $ORIG_GRP_INODES -eq 0 ] &&
2571 error "Used inodes for group $TSTID is 0, expected 1"
2572 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2574 if is_project_quota_supported; then
2575 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2576 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2577 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2578 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2579 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2580 "Used inodes for project $TSTPRJID is 0, expected 1"
2581 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2589 echo "Verify disk usage after restart"
2590 local USED=$(getquota -u $TSTID global curspace)
2591 [ $USED -eq $ORIG_USR_SPACE ] ||
2592 error "Used space for user $TSTID changed from " \
2593 "$ORIG_USR_SPACE to $USED"
2594 USED=$(getquota -u $TSTID global curinodes)
2595 [ $USED -eq $ORIG_USR_INODES ] ||
2596 error "Used inodes for user $TSTID changed from " \
2597 "$ORIG_USR_INODES to $USED"
2598 USED=$(getquota -g $TSTID global curspace)
2599 [ $USED -eq $ORIG_GRP_SPACE ] ||
2600 error "Used space for group $TSTID changed from " \
2601 "$ORIG_GRP_SPACE to $USED"
2602 USED=$(getquota -g $TSTID global curinodes)
2603 [ $USED -eq $ORIG_GRP_INODES ] ||
2604 error "Used inodes for group $TSTID changed from " \
2605 "$ORIG_GRP_INODES to $USED"
2606 if [ $project_supported == "yes" ]; then
2607 USED=$(getquota -p $TSTPRJID global curinodes)
2608 [ $USED -eq $ORIG_PRJ_INODES ] ||
2609 error "Used inodes for project $TSTPRJID " \
2610 "changed from $ORIG_PRJ_INODES to $USED"
2611 USED=$(getquota -p $TSTPRJID global curspace)
2612 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2613 error "Used space for project $TSTPRJID "\
2614 "changed from $ORIG_PRJ_SPACE to $USED"
2617 # check if the vfs_dq_init() is called before writing
2618 echo "Append to the same file..."
2619 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2620 error "write failed"
2621 cancel_lru_locks osc
2622 sync; sync_all_data || true
2624 echo "Verify space usage is increased"
2625 USED=$(getquota -u $TSTID global curspace)
2626 [ $USED -gt $ORIG_USR_SPACE ] ||
2627 error "Used space for user $TSTID isn't increased" \
2628 "orig:$ORIG_USR_SPACE, now:$USED"
2629 USED=$(getquota -g $TSTID global curspace)
2630 [ $USED -gt $ORIG_GRP_SPACE ] ||
2631 error "Used space for group $TSTID isn't increased" \
2632 "orig:$ORIG_GRP_SPACE, now:$USED"
2633 if [ $project_supported == "yes" ]; then
2634 USED=$(getquota -p $TSTPRJID global curspace)
2635 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2636 error "Used space for project $TSTPRJID isn't " \
2637 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2642 run_test 35 "Usage is still accessible across reboot"
2644 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2647 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.93) ] &&
2648 skip "Old server doesn't have LU-5006 fix."
2650 setup_quota_test || error "setup quota failed with $?"
2651 trap cleanup_quota_test EXIT
2653 # make sure the system is clean
2654 local USED=$(getquota -u $TSTID global curspace)
2656 error "Used space ($USED) for user $TSTID isn't 0."
2658 # create file with MDS_OPEN_DELAY_CREATE flag
2659 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2660 error "Create file failed"
2662 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2663 oflag=sync || error "Write file failed"
2665 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2667 # wait for setattr on objects finished..."
2668 wait_delete_completed
2670 USED=$(getquota -u $TSTID global curspace)
2671 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2675 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2679 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
2680 skip "Old server doesn't have LU-8801 fix."
2682 [ "$UID" != 0 ] && skip_env "must run as root" && return
2684 setup_quota_test || error "setup quota failed with $?"
2685 trap cleanup_quota_test EXIT
2687 # make sure the system is clean
2688 local USED=$(getquota -u $TSTID global curspace)
2690 error "Used space ($USED) for user $TSTID isn't 0."
2691 USED=$(getquota -u $TSTID2 global curspace)
2693 error "Used space ($USED) for user $TSTID2 isn't 0."
2695 local TESTFILE="$DIR/$tdir/$tfile"
2696 local file_cnt=10000
2698 # Generate id entries in accounting file
2699 echo "Create $file_cnt files..."
2700 for i in `seq $file_cnt`; do
2702 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2703 error "failed to chown $TESTFILE-$i"
2705 cancel_lru_locks osc
2706 sync; sync_all_data || true
2708 local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
2709 procf=${procf}.quota_slave.acct_user
2712 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2713 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2714 echo "Found $acct_cnt id entries"
2716 [ $file_cnt -eq $acct_cnt ] || {
2717 do_facet mds1 $LCTL get_param $procf
2718 error "skipped id entries"
2723 run_test 38 "Quota accounting iterator doesn't skip id entries"
2726 local TESTFILE="$DIR/$tdir/project"
2727 ! is_project_quota_supported &&
2728 skip "Project quota is not supported"
2730 setup_quota_test || error "setup quota failed with $?"
2733 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2734 [ $projectid -ne 0 ] &&
2735 error "Project id should be 0 not $projectid"
2736 change_project -p 1024 $TESTFILE
2737 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2738 [ $projectid -ne 1024 ] &&
2739 error "Project id should be 1024 not $projectid"
2741 stopall || error "failed to stopall (1)"
2744 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2745 [ $projectid -ne 1024 ] &&
2746 error "Project id should be 1024 not $projectid"
2750 run_test 39 "Project ID interface works correctly"
2753 ! is_project_quota_supported &&
2754 skip "Project quota is not supported"
2755 local dir1="$DIR/$tdir/dir1"
2756 local dir2="$DIR/$tdir/dir2"
2758 setup_quota_test || error "setup quota failed with $?"
2760 mkdir -p $dir1 $dir2
2761 change_project -sp 1 $dir1 && touch $dir1/1
2762 change_project -sp 2 $dir2
2764 ln $dir1/1 $dir2/1_link &&
2765 error "Hard link across different project quota should fail"
2770 run_test 40a "Hard link across different project ID"
2773 ! is_project_quota_supported &&
2774 skip "Project quota is not supported"
2775 local dir1="$DIR/$tdir/dir1"
2776 local dir2="$DIR/$tdir/dir2"
2778 setup_quota_test || error "setup quota failed with $?"
2779 mkdir -p $dir1 $dir2
2780 change_project -sp 1 $dir1 && touch $dir1/1
2781 change_project -sp 2 $dir2
2783 mv $dir1/1 $dir2/2 || error "mv failed $?"
2784 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2785 if [ "$projid" != "2" ]; then
2786 error "project id expected 2 not $projid"
2791 run_test 40b "Mv across different project ID"
2794 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2795 ! is_project_quota_supported &&
2796 skip "Project quota is not supported"
2798 setup_quota_test || error "setup quota failed with $?"
2799 local dir="$DIR/$tdir/dir"
2801 mkdir -p $dir && change_project -sp 1 $dir
2802 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2803 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2804 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2805 touch $dir/remote_dir/file
2806 #verify inherit works file for remote dir.
2807 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2808 [ "$projid" != "1" ] &&
2809 error "file under remote dir expected 1 not $projid"
2811 #Agent inode should be ignored for project quota
2812 USED=$(getquota -p 1 global curinodes)
2813 [ "$USED" != "3" ] &&
2814 error "file count expected 3 got $USED"
2820 run_test 40c "Remote child Dir inherit project quota properly"
2823 ! is_project_quota_supported &&
2824 skip "Project quota is not supported"
2826 setup_quota_test || error "setup quota failed with $?"
2827 local dir1="$DIR/$tdir/dir1"
2828 local dir2="$DIR/$tdir/dir2"
2830 mkdir -p $dir1 && change_project -sp 1 $dir1
2831 mkdir -p $dir2 && change_project -sp 2 $dir2
2832 for num in $(seq 1 10); do
2833 touch $dir1/file_$num $dir2/file_$num
2834 ln -s $dir1/file_$num $dir1/file_$num"_link"
2835 ln -s $dir2/file_$num $dir2/file_$num"_link"
2838 count=$($LFS find --projid 1 $DIR | wc -l)
2839 [ "$count" != 21 ] && error "expected 21 but got $count"
2841 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2842 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2843 [ "$count" != 22 ] && error "expected 22 but got $count"
2848 run_test 50 "Test if lfs find --projid works"
2851 ! is_project_quota_supported &&
2852 skip "Project quota is not supported"
2853 setup_quota_test || error "setup quota failed with $?"
2854 local dir="$DIR/$tdir/dir"
2856 mkdir $dir && change_project -sp 1 $dir
2857 local used=$(getquota -p 1 global curinodes)
2858 [ $used != "1" ] && error "expected 1 got $used"
2863 used=$(getquota -p 1 global curinodes)
2864 [ $used != "4" ] && error "expected 4 got $used"
2866 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2868 cp $DIR/$tdir/6 $dir/6
2869 used=$(getquota -p 1 global curinodes)
2870 [ $used != "5" ] && error "expected 5 got $used"
2873 mv $DIR/$tdir/6 $dir/7
2874 used=$(getquota -p 1 global curinodes)
2875 [ $used != "6" ] && error "expected 6 got $used"
2880 run_test 51 "Test project accounting with mv/cp"
2883 ! is_project_quota_supported &&
2884 skip "Project quota is not supported"
2885 setup_quota_test || error "setup quota failed with $?"
2886 local dir="$DIR/$tdir/dir"
2887 mkdir $dir && change_project -sp 1 $dir
2889 touch $DIR/$tdir/file
2890 #Try renaming a file into the project. This should fail.
2891 for num in $(seq 1 2000); do
2892 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2893 error "rename should fail"
2898 run_test 52 "Rename across different project ID"
2901 ! is_project_quota_supported &&
2902 skip "Project quota is not supported"
2903 setup_quota_test || error "setup quota failed with $?"
2904 local dir="$DIR/$tdir/dir"
2905 mkdir $dir && change_project -s $dir
2906 lfs project -d $dir | grep P || error "inherit attribute should be set"
2908 change_project -C $dir
2909 lfs project -d $dir | grep P &&
2910 error "inherit attribute should be cleared"
2915 run_test 53 "Project inherit attribute could be cleared"
2918 ! is_project_quota_supported &&
2919 skip "Project quota is not supported"
2920 setup_quota_test || error "setup quota failed with $?"
2921 trap cleanup_quota_test EXIT
2922 local testfile="$DIR/$tdir/$tfile-0"
2924 #set project ID/inherit attribute
2925 change_project -sp $TSTPRJID $DIR/$tdir
2926 $RUNAS createmany -m ${testfile} 100 ||
2927 error "create many files failed"
2929 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2930 # one more count for directory itself */
2934 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2935 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2937 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2938 [ $proj_count1 -eq $proj_count ] ||
2939 error "c2: expected $proj_count got $proj_count1"
2941 #clear project but with kept projid
2942 change_project -rCk $DIR/$tdir
2943 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2944 [ $proj_count1 -eq 1 ] ||
2945 error "c3: expected 1 got $proj_count1"
2947 #verify projid untouched.
2948 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2950 [ $proj_count1 -eq $proj_count ] ||
2951 error "c4: expected $proj_count got $proj_count1"
2954 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2955 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2956 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2958 #this time clear all
2959 change_project -rC $DIR/$tdir
2960 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2961 [ $proj_count1 -eq 0 ] ||
2962 error "c6: expected 0 got $proj_count1"
2964 unlinkmany ${testfile} 100 ||
2965 error "unlink many files failed"
2969 run_test 54 "basic lfs project interface test"
2972 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
2973 skip "Not supported before 2.10.58."
2974 setup_quota_test || error "setup quota failed with $?"
2976 set_ost_qtype $QTYPE || error "enable ost quota failed"
2979 #add second group to TSTUSR
2980 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
2983 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
2984 error "failed to dd"
2986 cancel_lru_locks osc
2987 sync; sync_all_data || true
2989 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
2990 error "failed to setquota on group $TSTUSR2"
2992 $LFS quota -v -g $TSTUSR2 $DIR
2994 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
2995 error "chgrp should failed with -EDQUOT"
2997 USED=$(getquota -g $TSTUSR2 global curspace)
3000 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3001 error "failed to setquota on group $TSTUSR2"
3003 $LFS quota -v -g $TSTUSR2 $DIR
3005 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3006 error "chgrp should succeed"
3008 $LFS quota -v -g $TSTUSR2 $DIR
3012 run_test 55 "Chgrp should be affected by group quota"
3015 setup_quota_test || error "setup quota failed with $?"
3017 set_ost_qtype $QTYPE || error "enable ost quota failed"
3020 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3021 erro "failed to set grace time for usr quota"
3022 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3023 awk '{print $4 $8}')
3024 if [ "x$grace_time" != "x10s;10s" ]; then
3025 $LFS quota -t -u $DIR
3026 error "expected grace time: 10s;10s, got:$grace_time"
3031 run_test 56 "lfs quota -t should work well"
3034 setup_quota_test || error "setup quota failed with $?"
3036 local dir="$DIR/$tdir/dir"
3039 #try to change pipe file should not hang and return failure
3040 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3041 awk -F ':' '{ print \\\$2 }'" \
3042 " unable to get xattr for fifo '$dir/pipe'" || return 1
3043 #command can process further if it hit some errors
3044 touch $dir/aaa $dir/bbb
3045 mkdir $dir/subdir -p
3046 touch $dir/subdir/aaa $dir/subdir/bbb
3047 #create one invalid link file
3048 ln -s $dir/not_exist_file $dir/ccc
3049 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3050 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3054 run_test 57 "lfs project could tolerate errors"
3057 [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3058 skip "ldiskfs only test"
3059 disable_project_quota
3060 setup_quota_test || error "setup quota failed with $?"
3063 local testfile="$DIR/$tdir/$tfile-0"
3064 #make sure it did not crash kernel
3065 touch $testfile && lfs project -sp 1 $testfile
3067 enable_project_quota
3070 run_test 59 "lfs project dosen't crash kernel with project disabled"
3073 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3074 skip "Needs MDS version 2.11.53 or later."
3075 setup_quota_test || error "setup quota failed with $?"
3076 trap cleanup_quota_test EXIT
3078 local testfile=$DIR/$tdir/$tfile
3081 set_mdt_qtype "ug" || error "enable mdt quota failed"
3083 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3084 error "set quota failed"
3085 quota_show_check a g $TSTUSR
3087 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3088 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3089 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3090 error "create many files failed"
3092 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3094 # root user can overrun quota
3095 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3096 error "root user should succeed"
3100 run_test 60 "Test quota for root with setgid"
3102 # test default quota
3103 test_default_quota() {
3104 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.51) ] &&
3105 skip "Not supported before 2.11.51."
3110 local qprjid=$TSTPRJID
3114 local LIMIT=20480 #20M disk space
3115 local TESTFILE="$DIR/$tdir/$tfile-0"
3117 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3118 echo "Project quota is not supported" && return 0
3120 [ $qtype == "-u" ] && qdtype="-U"
3121 [ $qtype == "-g" ] && qdtype="-G"
3122 [ $qtype == "-p" ] && {
3127 [ $qpool == "meta" ] && {
3128 LIMIT=10240 #10K inodes
3133 setup_quota_test || error "setup quota failed with $?"
3134 trap cleanup_quota_test EXIT
3138 # enable mdt/ost quota
3139 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3140 set_ost_qtype $QTYPE || error "enable ost quota failed"
3142 log "set to use default quota"
3143 $LFS setquota $qtype $qid -d $DIR ||
3144 error "set $qid to use default quota failed"
3146 log "set default quota"
3147 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3148 error "set $qid default quota failed"
3150 log "get default quota"
3151 $LFS quota $qdtype $DIR || error "get default quota failed"
3153 if [ $qpool == "data" ]; then
3154 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3156 [ $SLIMIT -eq $LIMIT ] ||
3157 error "the returned default quota is wrong"
3159 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3161 [ $SLIMIT -eq $LIMIT ] ||
3162 error "the returned default quota is wrong"
3165 # make sure the system is clean
3166 local USED=$(getquota $qtype $qid global curspace)
3167 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3169 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3170 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3172 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3174 log "Test not out of quota"
3175 if [ $qpool == "data" ]; then
3176 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3177 quota_error $qtype $qid "write failed, expect succeed"
3179 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3180 quota_error $qtype $qid "create failed, expect succeed"
3182 unlinkmany $TESTFILE $((LIMIT/2))
3185 log "Test out of quota"
3186 # flush cache, ensure noquota flag is set on client
3187 cancel_lru_locks osc
3188 cancel_lru_locks mdc
3189 sync; sync_all_data || true
3190 if [ $qpool == "data" ]; then
3191 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3192 quota_error $qtype $qid "write succeed, expect EDQUOT"
3194 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3195 quota_error $qtype $qid "create succeed, expect EDQUOT"
3197 unlinkmany $TESTFILE $((LIMIT*2))
3200 log "Increase default quota"
3201 # increase default quota
3202 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3203 error "set default quota failed"
3205 cancel_lru_locks osc
3206 cancel_lru_locks mdc
3207 sync; sync_all_data || true
3208 if [ $qpool == "data" ]; then
3209 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3210 quota_error $qtype $qid "write failed, expect succeed"
3212 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3213 quota_error $qtype $qid "create failed, expect succeed"
3215 unlinkmany $TESTFILE $((LIMIT*2))
3218 log "Set quota to override default quota"
3219 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3220 error "set $qid quota failed"
3222 cancel_lru_locks osc
3223 cancel_lru_locks mdc
3224 sync; sync_all_data || true
3225 if [ $qpool == "data" ]; then
3226 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3227 quota_error $qtype $qid "write succeed, expect EQUOT"
3229 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3230 quota_error $qtype $qid "create succeed, expect EQUOT"
3232 unlinkmany $TESTFILE $((LIMIT*2))
3235 log "Set to use default quota again"
3236 $LFS setquota $qtype $qid -d $DIR ||
3237 error "set $qid to use default quota failed"
3239 cancel_lru_locks osc
3240 cancel_lru_locks mdc
3241 sync; sync_all_data || true
3242 if [ $qpool == "data" ]; then
3243 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3244 quota_error $qtype $qid "write failed, expect succeed"
3246 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3247 quota_error $qtype $qid "create failed, expect succeed"
3249 unlinkmany $TESTFILE $((LIMIT*2))
3254 wait_delete_completed || error "wait_delete_completed failed"
3255 sync_all_data || true
3256 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3257 error "reset default quota failed"
3258 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3259 error "reset quota failed"
3265 test_default_quota "-u" "data"
3266 test_default_quota "-u" "meta"
3267 test_default_quota "-g" "data"
3268 test_default_quota "-g" "meta"
3269 test_default_quota "-p" "data"
3270 test_default_quota "-p" "meta"
3272 run_test 61 "default quota tests"
3275 ! is_project_quota_supported &&
3276 skip "Project quota is not supported"
3277 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3278 skip "chattr did not support project quota"
3279 setup_quota_test || error "setup quota failed with $?"
3280 local testdir=$DIR/$tdir/
3282 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3283 change_project -s $testdir
3284 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3285 error "inherit attribute should be set"
3286 # chattr used FS_IOC_SETFLAGS ioctl
3287 $RUNAS chattr -P $testdir &&
3288 error "regular user clear inherit should fail"
3289 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3290 error "inherit attribute should still be set"
3291 chattr -P $testdir || error "root failed to clear inherit"
3292 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3293 error "inherit attribute should be cleared"
3296 run_test 62 "Project inherit should be only changed by root"
3299 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.55) ] &&
3300 skip "Not supported before 2.11.55" && return
3304 local dd_failed=false
3305 local tdir_dom=${tdir}_dom
3306 local LIMIT=20480 #20M
3308 [ $qtype == "p" ] && ! is_project_quota_supported &&
3309 echo "Project quota is not supported" && return 0
3311 [ $qtype == "p" ] && qid=$TSTPRJID
3313 setup_quota_test || error "setup quota failed with $?"
3314 trap cleanup_quota_test EXIT
3318 # enable mdt/ost quota
3319 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3320 set_ost_qtype $QTYPE || error "enable ost quota failed"
3322 # make sure the system is clean
3323 local USED=$(getquota -$qtype $qid global curspace)
3324 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3326 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3328 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3329 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3330 error "setstripe $tdir_dom failed"
3331 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3333 [ $qtype == "p" ] && {
3334 change_project -sp $TSTPRJID $DIR/$tdir
3335 change_project -sp $TSTPRJID $DIR/$tdir_dom
3338 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3339 error "set $qid quota failed"
3341 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3342 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3346 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3348 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3349 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3353 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3355 rm -f $DIR/$tdir_dom/*
3357 # flush cache, ensure noquota flag is set on client
3358 cancel_lru_locks osc
3359 cancel_lru_locks mdc
3360 sync; sync_all_data || true
3364 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3365 quota_error $qtype $qid "write failed, expect succeed"
3367 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3368 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3372 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3375 rm -f $DIR/$tdir_dom/*
3377 # flush cache, ensure noquota flag is set on client
3378 cancel_lru_locks osc
3379 cancel_lru_locks mdc
3380 sync; sync_all_data || true
3384 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3385 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3389 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3391 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3392 quota_error $qtype $qid "write succeed, expect EDQUOT"
3395 rm -fr $DIR/$tdir_dom
3397 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3398 error "reset usr quota failed"
3408 run_test 63 "quota on DoM tests"
3411 ! is_project_quota_supported &&
3412 skip "Project quota is not supported"
3413 setup_quota_test || error "setup quota failed with $?"
3414 local dir1="$DIR/$tdir/"
3417 ln -s $dir1/file $dir1/file_link
3419 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3420 error "set symlink file's project should fail"
3422 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3423 error "get symlink file's project should fail"
3427 run_test 64 "lfs project on symlink files should fail"
3431 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3432 if $PQ_CLEANUP; then
3433 disable_project_quota
3436 reset_quota_settings
3441 check_and_cleanup_lustre
3442 export QUOTA_AUTO=$QUOTA_AUTO_OLD