3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 # Does e2fsprogs support quota feature?
47 if [ "$mds1_FSTYPE" == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip_env "e2fsprogs doesn't support quota"
53 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
55 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
60 QUOTA_AUTO_OLD=$QUOTA_AUTO
63 check_and_setup_lustre
65 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
67 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
68 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
69 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
70 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
71 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
72 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
73 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
74 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
79 local fail_val=${3:-0}
83 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
84 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
85 ost) NODES="$(comma_list $(osts_nodes))";;
88 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
94 lfs project $* || error "lfs project $* failed"
97 RUNAS="runas -u $TSTID -g $TSTID"
98 RUNAS2="runas -u $TSTID2 -g $TSTID2"
99 DD="dd if=/dev/zero bs=1M"
103 # clear quota limits for a user or a group
104 # usage: resetquota -u username
105 # resetquota -g groupname
106 # resetquota -p projid
109 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
110 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
111 error "resetquota: wrong specifier $1 passed"
113 if [ $1 == "-p" ]; then
114 is_project_quota_supported || return 0
117 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
118 error "clear quota for [type:$1 name:$2] failed"
119 # give a chance to slave to release space
127 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
128 $LFS quota -v -u $local_id $DIR
129 log "Files for user ($local_id):"
130 ($LFS find --user $local_id $DIR | head -n 4 |
131 xargs stat 2>/dev/null)
134 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
135 $LFS quota -v -g $local_id $DIR
136 log "Files for group ($local_id):"
137 ($LFS find --group $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 is_project_quota_supported || return 0
142 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
143 $LFS quota -v -p $TSTPRJID $DIR
144 log "Files for project ($TSTPRJID):"
145 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
146 xargs stat 2>/dev/null)
162 # get quota for a user or a group
163 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
164 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
169 sync_all_data > /dev/null 2>&1 || true
171 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
172 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
173 error "getquota: wrong u/g/p specifier $1 passed"
186 *) error "unknown quota parameter $4";;
189 [ "$uuid" = "global" ] && uuid=$DIR
191 $LFS quota -v "$1" "$2" $DIR |
192 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
193 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
198 # usage: set_mdt_qtype ugp|u|g|p|none
202 local mdts=$(get_facets MDS)
204 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
205 qtype=$(tr -d 'p' <<<$qtype)
207 if [[ $PERM_CMD == *"set_param -P"* ]]; then
208 do_facet mgs $PERM_CMD \
209 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
211 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
213 # we have to make sure each MDT received config changes
214 for mdt in ${mdts//,/ }; do
216 cmd="$LCTL get_param -n "
217 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
218 cmd=${cmd}.quota_slave.enabled
220 if $(facet_up $mdt); then
221 wait_update_facet $mdt "$cmd" "$qtype" || return 1
228 # usage: set_ost_qtype ugp|u|g|p|none
232 local osts=$(get_facets OST)
234 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
235 qtype=$(tr -d 'p' <<<$qtype)
237 if [[ $PERM_CMD == *"set_param -P"* ]]; then
238 do_facet mgs $PERM_CMD \
239 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
241 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
243 # we have to make sure each OST received config changes
244 for ost in ${osts//,/ }; do
246 cmd="$LCTL get_param -n "
247 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
248 cmd=${cmd}.quota_slave.enabled
250 if $(facet_up $ost); then
251 wait_update_facet $ost "$cmd" "$qtype" || return 1
257 wait_reintegration() {
261 local result="glb[1],slv[1],reint[0]"
266 if [ $ntype == "mdt" ]; then
267 tgts=$(get_facets MDS)
269 tgts=$(get_facets OST)
272 for tgt in ${tgts//,/ }; do
274 cmd="$LCTL get_param -n "
275 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
276 cmd=${cmd}.quota_slave.info
278 if $(facet_up $tgt); then
279 wait_update_facet $tgt "$cmd |
280 grep "$qtype" | awk '{ print \\\$3 }'" \
281 "$result" $max || return 1
291 if [[ "$qtype" =~ "u" ]]; then
292 wait_reintegration "mdt" "user" $max || return 1
295 if [[ "$qtype" =~ "g" ]]; then
296 wait_reintegration "mdt" "group" $max || return 1
299 if [[ "$qtype" =~ "p" ]]; then
300 ! is_project_quota_supported && return 0
301 wait_reintegration "mdt" "project" $max || return 1
310 if [[ "$qtype" =~ "u" ]]; then
311 wait_reintegration "ost" "user" $max || return 1
314 if [[ "$qtype" =~ "g" ]]; then
315 wait_reintegration "ost" "group" $max || return 1
318 if [[ "$qtype" =~ "p" ]]; then
319 ! is_project_quota_supported && return 0
320 wait_reintegration "ost" "project" $max || return 1
328 local extrasleep=${3:-5}
334 *) error "get_grace_time: Invalid quota type: $qtype"
339 time=$(lfs quota -$qtype $qarg $DIR|
340 awk 'NR == 3{ print $5 }'| sed 's/s$//')
343 time=$(lfs quota -$qtype $qarg $DIR|
344 awk 'NR == 3{ print $9 }'| sed 's/s$//')
347 error "Unknown quota type: $flavour"
351 echo "Sleep through grace ..."
352 [ "$time" == "-" ] &&
353 error "Grace timeout was not set or quota not exceeded"
354 if [ "$time" == "none" ]; then
355 echo "...Grace timeout already expired"
357 let time+=$extrasleep
358 echo "...sleep $time seconds"
364 wait_delete_completed
365 echo "Creating test directory"
366 mkdir $DIR/$tdir || return 1
367 chmod 0777 $DIR/$tdir || return 2
368 # always clear fail_loc in case of fail_loc isn't cleared
369 # properly when previous test failed
370 lustre_fail mds_ost 0
373 cleanup_quota_test() {
375 echo "Delete files..."
377 echo "Wait for unlink objects finished..."
378 wait_delete_completed
379 sync_all_data || true
389 $LFS quota -v -$ugp $qid $DIR
391 if [ "$bf" == "a" -o "$bf" == "b" ]; then
392 usage=$(getquota -$ugp $qid global curspace)
393 if [ -z $usage ]; then
394 quota_error $ugp $qid \
395 "Query block quota failed ($ugp:$qid)."
397 [ $usage -ne 0 ] && quota_log $ugp $qid \
398 "Block quota isn't 0 ($ugp:$qid:$usage)."
402 if [ "$bf" == "a" -o "$bf" == "f" ]; then
403 usage=$(getquota -$ugp $qid global curinodes)
404 if [ -z $usage ]; then
405 quota_error $ugp $qid \
406 "Query file quota failed ($ugp:$qid)."
408 [ $usage -ne 0 ] && quota_log $ugp $qid \
409 "File quota isn't 0 ($ugp:$qid:$usage)."
414 project_quota_enabled () {
416 local zfeat="feature@project_quota"
418 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
419 local facet_fstype=${facet:0:3}1_FSTYPE
422 if [ "${!facet_fstype}" = "zfs" ]; then
423 devname=$(zpool_name ${facet})
424 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
425 grep -wq active || rc=1
427 [ ${facet:0:3} == "mds" ] &&
428 devname=$(mdsdevname ${facet:3}) ||
429 devname=$(ostdevname ${facet:3})
430 do_facet ${facet} $DEBUGFS -R features $devname |
431 grep -q project || rc=1
434 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
438 project_quota_enabled || enable_project_quota
440 reset_quota_settings() {
441 resetquota -u $TSTUSR
443 resetquota -g $TSTUSR
445 resetquota -u $TSTUSR2
446 resetquota -u $TSTID2
447 resetquota -g $TSTUSR2
448 resetquota -g $TSTID2
449 resetquota -p $TSTPRJID
454 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
459 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
460 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
461 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
462 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
464 test_quota_performance() {
465 local TESTFILE="$DIR/$tdir/$tfile-0"
466 local size=$1 # in MB
467 local stime=$(date +%s)
468 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
469 quota_error u $TSTUSR "write failure"
470 local etime=$(date +%s)
471 delta=$((etime - stime))
472 if [ $delta -gt 0 ]; then
473 rate=$((size * 1024 / delta))
474 if [ "$mds1_FSTYPE" = zfs ]; then
475 # LU-2872 - see LU-2887 for fix
477 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
479 [ $rate -gt 1024 ] ||
480 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
486 # test basic quota performance b=21696
489 [ "$SLOW" = "no" ] && MB=10
491 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
492 [ $free_space -le $((MB * 1024)) ] &&
493 skip "not enough space ${free_space} KB, " \
494 "required $((MB * 1024)) KB"
495 setup_quota_test || error "setup quota failed with $?"
496 trap cleanup_quota_test EXIT
498 set_ost_qtype "none" || error "disable ost quota failed"
499 test_quota_performance $MB
501 set_ost_qtype $QTYPE || error "enable ost quota failed"
502 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
503 error "set quota failed"
504 test_quota_performance $MB
508 run_test 0 "Test basic quota performance"
510 # test block hardlimit
513 local TESTFILE="$DIR/$tdir/$tfile-0"
515 setup_quota_test || error "setup quota failed with $?"
516 trap cleanup_quota_test EXIT
519 set_ost_qtype $QTYPE || error "enable ost quota failed"
522 log "User quota (block hardlimit:$LIMIT MB)"
523 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
524 error "set user quota failed"
526 # make sure the system is clean
527 local USED=$(getquota -u $TSTUSR global curspace)
528 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
530 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
531 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
534 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
535 quota_error u $TSTUSR "user write failure, but expect success"
536 log "Write out of block quota ..."
537 # this time maybe cache write, ignore it's failure
538 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
539 # flush cache, ensure noquota flag is set on client
541 sync; sync_all_data || true
542 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
543 quota_error u $TSTUSR "user write success, but expect EDQUOT"
546 wait_delete_completed || error "wait_delete_completed failed"
547 sync_all_data || true
548 USED=$(getquota -u $TSTUSR global curspace)
549 [ $USED -ne 0 ] && quota_error u $TSTUSR \
550 "user quota isn't released after deletion"
551 resetquota -u $TSTUSR
554 log "--------------------------------------"
555 log "Group quota (block hardlimit:$LIMIT MB)"
556 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
557 error "set group quota failed"
559 TESTFILE="$DIR/$tdir/$tfile-1"
560 # make sure the system is clean
561 USED=$(getquota -g $TSTUSR global curspace)
562 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
564 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
565 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
568 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
569 quota_error g $TSTUSR "Group write failure, but expect success"
570 log "Write out of block quota ..."
571 # this time maybe cache write, ignore it's failure
572 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
574 sync; sync_all_data || true
575 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
576 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
578 wait_delete_completed || error "wait_delete_completed failed"
579 sync_all_data || true
580 USED=$(getquota -g $TSTUSR global curspace)
581 [ $USED -ne 0 ] && quota_error g $TSTUSR \
582 "Group quota isn't released after deletion"
583 resetquota -g $TSTUSR
585 if ! is_project_quota_supported; then
586 echo "Project quota is not supported"
591 TESTFILE="$DIR/$tdir/$tfile-2"
592 # make sure the system is clean
593 USED=$(getquota -p $TSTPRJID global curspace)
595 error "used space($USED) for project $TSTPRJID isn't 0"
598 log "--------------------------------------"
599 log "Project quota (block hardlimit:$LIMIT mb)"
600 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
601 error "set project quota failed"
603 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
604 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
605 change_project -p $TSTPRJID $TESTFILE
608 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
609 "project write failure, but expect success"
610 log "write out of block quota ..."
611 # this time maybe cache write, ignore it's failure
612 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
614 sync; sync_all_data || true
615 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
616 $TSTPRJID "project write success, but expect EDQUOT"
621 USED=$(getquota -p $TSTPRJID global curspace)
622 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
623 "project quota isn't released after deletion"
625 run_test 1 "Block hard limit (normal use and out of quota)"
627 # test inode hardlimit
629 local LIMIT=$((1024 * 1024)) # 1M inodes
630 local TESTFILE="$DIR/$tdir/$tfile-0"
632 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
634 local FREE_INODES=$(mdt_free_inodes 0)
635 echo "$FREE_INODES free inodes on master MDT"
636 [ $FREE_INODES -lt $LIMIT ] &&
637 skip "not enough free inodes $FREE_INODES required $LIMIT"
639 setup_quota_test || error "setup quota failed with $?"
640 trap cleanup_quota_test EXIT
643 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
646 log "User quota (inode hardlimit:$LIMIT files)"
647 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
648 error "set user quota failed"
650 # make sure the system is clean
651 local USED=$(getquota -u $TSTUSR global curinodes)
652 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
654 log "Create $LIMIT files ..."
655 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
656 quota_error u $TSTUSR "user create failure, but expect success"
657 log "Create out of file quota ..."
658 $RUNAS touch ${TESTFILE}_xxx &&
659 quota_error u $TSTUSR "user create success, but expect EDQUOT"
662 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
663 rm -f ${TESTFILE}_xxx
664 wait_delete_completed
666 USED=$(getquota -u $TSTUSR global curinodes)
667 [ $USED -ne 0 ] && quota_error u $TSTUSR \
668 "user quota isn't released after deletion"
669 resetquota -u $TSTUSR
672 log "--------------------------------------"
673 log "Group quota (inode hardlimit:$LIMIT files)"
674 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
675 error "set group quota failed"
677 TESTFILE=$DIR/$tdir/$tfile-1
678 # make sure the system is clean
679 USED=$(getquota -g $TSTUSR global curinodes)
680 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
682 log "Create $LIMIT files ..."
683 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
684 quota_error g $TSTUSR "group create failure, but expect success"
685 log "Create out of file quota ..."
686 $RUNAS touch ${TESTFILE}_xxx &&
687 quota_error g $TSTUSR "group create success, but expect EDQUOT"
690 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
691 rm -f ${TESTFILE}_xxx
692 wait_delete_completed
694 USED=$(getquota -g $TSTUSR global curinodes)
695 [ $USED -ne 0 ] && quota_error g $TSTUSR \
696 "user quota isn't released after deletion"
698 resetquota -g $TSTUSR
699 ! is_project_quota_supported && cleanup_quota_test &&
700 echo "Skip project quota is not supported" && return 0
703 log "--------------------------------------"
704 log "Project quota (inode hardlimit:$LIMIT files)"
705 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
706 error "set project quota failed"
708 TESTFILE=$DIR/$tdir/$tfile-1
709 # make sure the system is clean
710 USED=$(getquota -p $TSTPRJID global curinodes)
712 error "Used inodes($USED) for project $TSTPRJID isn't 0"
714 change_project -sp $TSTPRJID $DIR/$tdir
715 log "Create $LIMIT files ..."
716 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
717 $TSTPRJID "project create fail, but expect success"
718 log "Create out of file quota ..."
719 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
720 "project create success, but expect EDQUOT"
721 change_project -C $DIR/$tdir
724 USED=$(getquota -p $TSTPRJID global curinodes)
725 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
726 "project quota isn't released after deletion"
729 run_test 2 "File hard limit (normal use and out of quota)"
739 trap cleanup_quota_test EXIT
741 $LFS setstripe $TESTFILE -c 1 -i 0
742 chown $TSTUSR.$TSTUSR $TESTFILE
743 [ "$qtype" == "p" ] && is_project_quota_supported &&
744 change_project -p $TSTPRJID $TESTFILE
746 echo "Write up to soft limit"
747 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
748 quota_error a $TSTUSR "write failure, but expect success"
749 OFFSET=$((LIMIT * 1024))
752 echo "Write to exceed soft limit"
753 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
754 quota_error a $TSTUSR "write failure, but expect success"
755 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
758 echo "mmap write when over soft limit"
759 $RUNAS $MULTIOP $TESTFILE.mmap OT40960SMW ||
760 quota_error a $TSTUSR "mmap write failure, but expect success"
766 $SHOW_QUOTA_INFO_USER
767 $SHOW_QUOTA_INFO_GROUP
768 $SHOW_QUOTA_INFO_PROJID
770 echo "Write before timer goes off"
771 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
772 quota_error a $TSTUSR "write failure, but expect success"
773 OFFSET=$((OFFSET + 1024))
776 wait_grace_time $qtype "block"
781 $SHOW_QUOTA_INFO_USER
782 $SHOW_QUOTA_INFO_GROUP
783 $SHOW_QUOTA_INFO_PROJID
785 echo "Write after timer goes off"
786 # maybe cache write, ignore.
787 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
788 OFFSET=$((OFFSET + 1024))
790 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
791 quota_error a $TSTUSR "write success, but expect EDQUOT"
796 $SHOW_QUOTA_INFO_USER
797 $SHOW_QUOTA_INFO_GROUP
798 $SHOW_QUOTA_INFO_PROJID
800 echo "Unlink file to stop timer"
802 wait_delete_completed
803 sync_all_data || true
808 $SHOW_QUOTA_INFO_USER
809 $SHOW_QUOTA_INFO_GROUP
810 $SHOW_QUOTA_INFO_PROJID
812 $LFS setstripe $TESTFILE -c 1 -i 0
813 chown $TSTUSR.$TSTUSR $TESTFILE
814 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
817 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
818 quota_error a $TSTUSR "write failure, but expect success"
826 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
829 local TESTFILE=$DIR/$tdir/$tfile-0
831 # get minimum soft qunit size
832 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
833 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
835 set_ost_qtype $QTYPE || error "enable ost quota failed"
837 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
838 # make sure the system is clean
839 local USED=$(getquota -u $TSTUSR global curspace)
840 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
842 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
843 $MAX_IQ_TIME $DIR || error "set user grace time failed"
844 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
845 error "set user quota failed"
847 test_block_soft $TESTFILE $GRACE $LIMIT "u"
849 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
850 TESTFILE=$DIR/$tdir/$tfile-1
851 # make sure the system is clean
852 USED=$(getquota -g $TSTUSR global curspace)
853 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
855 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
856 $MAX_IQ_TIME $DIR || error "set group grace time failed"
857 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
858 error "set group quota failed"
860 test_block_soft $TESTFILE $GRACE $LIMIT "g"
862 if is_project_quota_supported; then
863 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
864 TESTFILE=$DIR/$tdir/$tfile-2
865 # make sure the system is clean
866 USED=$(getquota -p $TSTPRJID global curspace)
867 [ $USED -ne 0 ] && error \
868 "Used space($USED) for project $TSTPRJID isn't 0."
870 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
872 error "set project grace time failed"
873 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
874 $DIR || error "set project quota failed"
876 test_block_soft $TESTFILE $GRACE $LIMIT "p"
877 resetquota -p $TSTPRJID
878 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
880 error "restore project grace time failed"
884 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
885 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
886 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
887 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
889 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
898 trap cleanup_quota_test EXIT
899 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
901 echo "Create files to exceed soft limit"
902 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
903 quota_error a $TSTUSR "create failure, but expect success"
904 local trigger_time=$(date +%s)
906 sync_all_data || true
908 local cur_time=$(date +%s)
909 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
910 error "Passed grace time $grace, $trigger_time, $cur_time"
912 echo "Create file before timer goes off"
913 $RUNAS touch ${TESTFILE}_before ||
914 quota_error a $TSTUSR "failed create before timer expired," \
915 "but expect success. $trigger_time, $cur_time"
916 sync_all_data || true
918 wait_grace_time $qtype "file"
923 $SHOW_QUOTA_INFO_USER
924 $SHOW_QUOTA_INFO_GROUP
925 $SHOW_QUOTA_INFO_PROJID
927 echo "Create file after timer goes off"
928 # There is a window that space is accounted in the quota usage but
929 # hasn't been decreased from the pending write, if we acquire quota
930 # in this window, we'll acquire more than we needed.
931 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
932 sync_all_data || true
933 $RUNAS touch ${TESTFILE}_after_3 &&
934 quota_error a $TSTUSR "create after timer expired," \
936 sync_all_data || true
941 $SHOW_QUOTA_INFO_USER
942 $SHOW_QUOTA_INFO_GROUP
943 $SHOW_QUOTA_INFO_PROJID
945 echo "Unlink files to stop timer"
946 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
947 wait_delete_completed
950 $RUNAS touch ${TESTFILE}_xxx ||
951 quota_error a $TSTUSR "touch after timer stop failure," \
953 sync_all_data || true
961 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
962 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
963 local TESTFILE=$DIR/$tdir/$tfile-0
966 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
968 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
969 # make sure the system is clean
970 local USED=$(getquota -u $TSTUSR global curinodes)
971 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
973 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
974 $GRACE $DIR || error "set user grace time failed"
975 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
976 error "set user quota failed"
978 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
980 test_file_soft $TESTFILE $LIMIT $GRACE "u"
982 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
983 # make sure the system is clean
984 USED=$(getquota -g $TSTUSR global curinodes)
985 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
987 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
988 $GRACE $DIR || error "set group grace time failed"
989 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
990 error "set group quota failed"
991 TESTFILE=$DIR/$tdir/$tfile-1
993 test_file_soft $TESTFILE $LIMIT $GRACE "g"
995 if is_project_quota_supported; then
996 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
997 # make sure the system is clean
998 USED=$(getquota -p $TSTPRJID global curinodes)
999 [ $USED -ne 0 ] && error \
1000 "Used space($USED) for project $TSTPRJID isn't 0."
1002 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1003 $GRACE $DIR || error "set project grace time failed"
1004 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1005 error "set project quota failed"
1007 TESTFILE=$DIR/$tdir/$tfile-1
1008 # one less than limit, because of parent directory included.
1009 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1010 resetquota -p $TSTPRJID
1011 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1012 $MAX_IQ_TIME $DIR ||
1013 error "restore project grace time failed"
1017 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1018 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1019 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1020 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1022 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1025 local GR_STR1="1w3d"
1026 local GR_STR2="1000s"
1028 local GR_STR4="1w2d3h4m5s"
1030 local GR_STR6="18446744073709551615"
1033 wait_delete_completed
1035 # test of valid grace strings handling
1036 echo "Valid grace strings test"
1037 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1038 $GR_STR2 $DIR || error "set user grace time failed"
1039 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1040 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1041 $GR_STR4 $DIR || error "set group grace time quota failed"
1042 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1044 # test of invalid grace strings handling
1045 echo " Invalid grace strings test"
1046 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1047 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1048 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1052 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1053 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1054 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1055 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1057 run_test 4b "Grace time strings handling"
1059 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1061 local BLIMIT=10 # 10M
1062 local ILIMIT=10 # 10 inodes
1064 setup_quota_test || error "setup quota failed with $?"
1065 trap cleanup_quota_test EXIT
1067 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1068 set_ost_qtype $QTYPE || error "enable ost quota failed"
1070 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1071 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1072 error "set user quota failed"
1073 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1074 if is_project_quota_supported; then
1075 error "set group quota failed"
1076 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1077 -I $ILIMIT $DIR || error "set project quota failed"
1080 # make sure the system is clean
1081 local USED=$(getquota -u $TSTUSR global curinodes)
1082 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1083 USED=$(getquota -g $TSTUSR global curinodes)
1084 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1085 USED=$(getquota -u $TSTUSR global curspace)
1086 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1087 USED=$(getquota -g $TSTUSR global curspace)
1088 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1089 if is_project_quota_supported; then
1090 USED=$(getquota -p $TSTPRJID global curinodes)
1092 error "Used inode($USED) for project $TSTPRJID isn't 0."
1093 USED=$(getquota -p $TSTPRJID global curspace)
1095 error "Used block($USED) for project $TSTPRJID isn't 0."
1098 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1099 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1100 error "create failure, expect success"
1101 if is_project_quota_supported; then
1102 touch $DIR/$tdir/$tfile-0_1
1103 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1105 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1106 error "write failure, expect success"
1108 echo "Chown files to $TSTUSR.$TSTUSR ..."
1109 for i in $(seq 0 $ILIMIT); do
1110 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1111 quota_error a $TSTUSR "chown failure, expect success"
1115 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1116 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1119 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1121 # test dropping acquire request on master
1125 # Clear dmesg so watchdog is not triggered by previous
1127 do_facet ost1 dmesg -c > /dev/null
1129 setup_quota_test || error "setup quota failed with $?"
1130 trap cleanup_quota_test EXIT
1132 # make sure the system is clean
1133 local USED=$(getquota -u $TSTUSR global curspace)
1134 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1136 # make sure no granted quota on ost
1137 set_ost_qtype $QTYPE || error "enable ost quota failed"
1138 resetquota -u $TSTUSR
1140 # create file for $TSTUSR
1141 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1142 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1143 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1145 # create file for $TSTUSR2
1146 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1147 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1148 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1150 # cache per-ID lock for $TSTUSR on slave
1151 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1152 error "set quota failed"
1153 $RUNAS $DD of=$TESTFILE count=1 ||
1154 error "write $TESTFILE failure, expect success"
1155 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1156 error "write $TESTFILE2 failure, expect success"
1158 if at_is_enabled; then
1159 at_max_saved=$(at_max_get ost1)
1160 at_max_set $TIMEOUT ost1
1162 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1163 # DQACQ is sent, which makes at_max to take effect
1164 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1167 wait_delete_completed
1171 sync_all_data || true
1173 #define QUOTA_DQACQ 601
1174 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1175 lustre_fail mds 0x513 601
1177 do_facet ost1 $LCTL set_param \
1178 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1180 # write to un-enforced ID ($TSTUSR2) should succeed
1181 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1182 error "write failure, expect success"
1184 # write to enforced ID ($TSTUSR) in background, exceeding limit
1185 # to make sure DQACQ is sent
1186 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1189 # watchdog timer uses a factor of 2
1190 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1191 sleep $((TIMEOUT * 2 + 1))
1193 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1195 # write should be blocked and never finished
1196 if ! ps -p $DDPID > /dev/null 2>&1; then
1198 error "write finished incorrectly!"
1203 # no watchdog is triggered
1204 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1205 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1206 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1207 [ -z "$watchdog" ] || error "$watchdog"
1209 rm -f $TMP/lustre-log-${TESTNAME}.log
1211 # write should continue then fail with EDQUOT
1215 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1216 if [ $count -ge 240 ]; then
1217 quota_error u $TSTUSR "dd not finished in $count secs"
1219 count=$((count + 1))
1220 if [ $((count % 30)) -eq 0 ]; then
1221 c_size=$(stat -c %s $TESTFILE)
1222 echo "Waiting $count secs. $c_size"
1230 run_test 6 "Test dropping acquire request on master"
1232 # quota reintegration (global index)
1234 local TESTFILE=$DIR/$tdir/$tfile
1235 local LIMIT=20 # 20M
1237 [ "$SLOW" = "no" ] && LIMIT=5
1239 setup_quota_test || error "setup quota failed with $?"
1240 trap cleanup_quota_test EXIT
1242 # make sure the system is clean
1243 local USED=$(getquota -u $TSTUSR global curspace)
1244 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1246 # make sure no granted quota on ost1
1247 set_ost_qtype $QTYPE || error "enable ost quota failed"
1248 resetquota -u $TSTUSR
1249 set_ost_qtype "none" || error "disable ost quota failed"
1251 local OSTUUID=$(ostuuid_from_index 0)
1252 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1254 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1257 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1258 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1263 echo "Enable quota & set quota limit for $TSTUSR"
1264 set_ost_qtype $QTYPE || error "enable ost quota failed"
1265 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1266 error "set quota failed"
1268 echo "Start ost1..."
1269 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1272 wait_ost_reint $QTYPE || error "reintegration failed"
1274 # hardlimit should have been fetched by slave during global
1275 # reintegration, write will exceed quota
1276 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1277 quota_error u $TSTUSR "write success, but expect EDQUOT"
1280 wait_delete_completed
1281 sync_all_data || true
1287 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1288 error "clear quota failed"
1290 echo "Start ost1..."
1291 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1294 wait_ost_reint $QTYPE || error "reintegration failed"
1296 # hardlimit should be cleared on slave during reintegration
1297 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1298 quota_error u $TSTUSR "write error, but expect success"
1302 run_test 7a "Quota reintegration (global index)"
1304 # quota reintegration (slave index)
1307 local TESTFILE=$DIR/$tdir/$tfile
1309 setup_quota_test || error "setup quota failed with $?"
1310 trap cleanup_quota_test EXIT
1312 # make sure the system is clean
1313 local USED=$(getquota -u $TSTUSR global curspace)
1314 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1316 # make sure no granted quota on ost1
1317 set_ost_qtype $QTYPE || error "enable ost quota failed"
1318 resetquota -u $TSTUSR
1319 set_ost_qtype "none" || error "disable ost quota failed"
1321 local OSTUUID=$(ostuuid_from_index 0)
1322 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1324 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1327 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1328 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1330 # consume some space to make sure the granted space will not
1331 # be released during reconciliation
1332 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1333 error "consume space failure, expect success"
1335 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1336 lustre_fail mds 0xa02
1338 set_ost_qtype $QTYPE || error "enable ost quota failed"
1339 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1340 error "set quota failed"
1342 # ignore the write error
1343 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1345 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1349 echo "Restart ost to trigger reintegration..."
1351 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1354 wait_ost_reint $QTYPE || error "reintegration failed"
1356 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1357 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1362 run_test 7b "Quota reintegration (slave index)"
1364 # quota reintegration (restart mds during reintegration)
1366 local LIMIT=20 # 20M
1367 local TESTFILE=$DIR/$tdir/$tfile
1369 [ "$SLOW" = "no" ] && LIMIT=5
1371 setup_quota_test || error "setup quota failed with $?"
1372 trap cleanup_quota_test EXIT
1374 # make sure the system is clean
1375 local USED=$(getquota -u $TSTUSR global curspace)
1376 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1378 set_ost_qtype "none" || error "disable ost quota failed"
1379 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1380 error "set quota failed"
1382 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1383 lustre_fail ost 0xa03
1386 set_ost_qtype $QTYPE || error "enable ost quota failed"
1387 # trigger reintegration
1388 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1389 procf=${procf}quota_slave.force_reint
1390 do_facet ost1 $LCTL set_param $procf=1 ||
1391 error "force reintegration failed"
1399 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1402 # wait longer than usual to make sure the reintegration
1403 # is triggered by quota wb thread.
1404 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1406 # hardlimit should have been fetched by slave during global
1407 # reintegration, write will exceed quota
1408 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1409 quota_error u $TSTUSR "write success, but expect EDQUOT"
1413 run_test 7c "Quota reintegration (restart mds during reintegration)"
1415 # Quota reintegration (Transfer index in multiple bulks)
1417 local TESTFILE=$DIR/$tdir/$tfile
1418 local TESTFILE1="$DIR/$tdir/$tfile"-1
1421 setup_quota_test || error "setup quota failed with $?"
1422 trap cleanup_quota_test EXIT
1424 set_ost_qtype "none" || error "disable ost quota failed"
1425 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1426 error "set quota for $TSTUSR failed"
1427 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1428 error "set quota for $TSTUSR2 failed"
1430 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1431 lustre_fail mds 0x608 0
1433 # enable quota to tirgger reintegration
1434 set_ost_qtype "u" || error "enable ost quota failed"
1435 wait_ost_reint "u" || error "reintegration failed"
1439 # hardlimit should have been fetched by slave during global
1440 # reintegration, write will exceed quota
1441 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1442 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1444 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1445 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1449 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1451 # quota reintegration (inode limits)
1453 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1455 # LU-2435: skip this quota test if underlying zfs version has not
1456 # supported native dnode accounting
1457 [ "$mds1_FSTYPE" == zfs ] && {
1458 local F="feature@userobj_accounting"
1459 local pool=$(zpool_name mds1)
1460 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1462 [[ "$feature" != *" active "* ]] &&
1463 skip "requires zpool with active userobj_accounting"
1466 local ilimit=$((1024 * 2)) # 2k inodes
1467 local TESTFILE=$DIR/${tdir}-1/$tfile
1469 setup_quota_test || error "setup quota failed with $?"
1470 trap cleanup_quota_test EXIT
1472 # make sure the system is clean
1473 local USED=$(getquota -u $TSTUSR global curinodes)
1474 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1476 # make sure no granted quota on mdt1
1477 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1478 resetquota -u $TSTUSR
1479 set_mdt_qtype "none" || error "disable mdt quota failed"
1481 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1482 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1483 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1486 echo "Stop mds${MDSCOUNT}..."
1489 echo "Enable quota & set quota limit for $TSTUSR"
1490 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1491 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1492 error "set quota failed"
1494 echo "Start mds${MDSCOUNT}..."
1495 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1498 wait_mdt_reint $QTYPE || error "reintegration failed"
1500 echo "create remote dir"
1501 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1502 error "create remote dir failed"
1503 chmod 0777 $DIR/${tdir}-1
1505 # hardlimit should have been fetched by slave during global
1506 # reintegration, create will exceed quota
1507 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1508 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1510 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1511 wait_delete_completed
1512 sync_all_data || true
1514 echo "Stop mds${MDSCOUNT}..."
1517 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1518 error "clear quota failed"
1520 echo "Start mds${MDSCOUNT}..."
1521 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1524 wait_mdt_reint $QTYPE || error "reintegration failed"
1526 # hardlimit should be cleared on slave during reintegration
1527 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1528 quota_error u $TSTUSR "create failed, expect success"
1530 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1531 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1535 run_test 7e "Quota reintegration (inode limits)"
1537 # run dbench with quota enabled
1539 local BLK_LIMIT="100g" #100G
1540 local FILE_LIMIT=1000000
1542 setup_quota_test || error "setup quota failed with $?"
1543 trap cleanup_quota_test EXIT
1545 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1546 set_ost_qtype $QTYPE || error "enable ost quota failed"
1548 echo "Set enough high limit for user: $TSTUSR"
1549 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1550 error "set user quota failed"
1551 echo "Set enough high limit for group: $TSTUSR"
1552 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1553 error "set group quota failed"
1554 if is_project_quota_supported; then
1555 change_project -sp $TSTPRJID $DIR/$tdir
1556 echo "Set enough high limit for project: $TSTPRJID"
1557 $LFS setquota -p $TSTPRJID -b 0 \
1558 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1559 error "set project quota failed"
1563 [ "$SLOW" = "no" ] && duration=" -t 120"
1564 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1565 quota_error a $TSTUSR "dbench failed!"
1567 is_project_quota_supported && change_project -C $DIR/$tdir
1570 run_test 8 "Run dbench with quota enabled"
1572 # this check is just for test_9
1573 OST0_MIN=4900000 #4.67G
1575 check_whether_skip () {
1576 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1577 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1578 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1579 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1586 # run for fixing bug10707, it needs a big room. test for 64bit
1588 local filesize=$((1024 * 9 / 2)) # 4.5G
1590 check_whether_skip && return 0
1592 setup_quota_test || error "setup quota failed with $?"
1593 trap cleanup_quota_test EXIT
1595 set_ost_qtype "ug" || error "enable ost quota failed"
1597 local TESTFILE="$DIR/$tdir/$tfile-0"
1598 local BLK_LIMIT=100G #100G
1599 local FILE_LIMIT=1000000
1601 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1603 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1605 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1606 error "set user quota failed"
1608 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1609 "for group: $TSTUSR"
1610 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1611 error "set group quota failed"
1613 quota_show_check a u $TSTUSR
1614 quota_show_check a g $TSTUSR
1616 echo "Create test file"
1617 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1618 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1620 log "Write the big file of 4.5G ..."
1621 $RUNAS $DD of=$TESTFILE count=$filesize ||
1622 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1632 run_test 9 "Block limit larger than 4GB (b10707)"
1635 local TESTFILE=$DIR/$tdir/$tfile
1637 setup_quota_test || error "setup quota failed with $?"
1638 trap cleanup_quota_test EXIT
1640 # set limit to root user should fail
1641 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1642 error "set limit for root user successfully, expect failure"
1643 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1644 error "set limit for root group successfully, expect failure"
1645 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1646 error "set limit for project 0 successfully, expect failure"
1648 # root user can overrun quota
1649 set_ost_qtype "ug" || error "enable ost quota failed"
1651 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1652 error "set quota failed"
1653 quota_show_check b u $TSTUSR
1655 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1656 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1658 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1659 error "write failure, expect success"
1663 run_test 10 "Test quota for root user"
1666 local TESTFILE=$DIR/$tdir/$tfile
1667 setup_quota_test || error "setup quota failed with $?"
1668 trap cleanup_quota_test EXIT
1670 set_mdt_qtype "ug" || error "enable mdt quota failed"
1671 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1672 error "set quota failed"
1674 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1675 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1677 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1678 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1681 local USED=$(getquota -u $TSTUSR global curinodes)
1682 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1686 run_test 11 "Chown/chgrp ignores quota"
1689 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1691 local blimit=22 # 22M
1692 local blk_cnt=$((blimit - 5))
1693 local TESTFILE0="$DIR/$tdir/$tfile"-0
1694 local TESTFILE1="$DIR/$tdir/$tfile"-1
1696 setup_quota_test || error "setup quota failed with $?"
1697 trap cleanup_quota_test EXIT
1699 set_ost_qtype "u" || error "enable ost quota failed"
1700 quota_show_check b u $TSTUSR
1702 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1703 error "set quota failed"
1705 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1706 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1707 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1708 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1710 echo "Write to ost0..."
1711 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1712 quota_error a $TSTUSR "dd failed"
1714 echo "Write to ost1..."
1715 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1716 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1718 echo "Free space from ost0..."
1720 wait_delete_completed
1721 sync_all_data || true
1723 echo "Write to ost1 after space freed from ost0..."
1724 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1725 quota_error a $TSTUSR "rebalancing failed"
1729 run_test 12a "Block quota rebalancing"
1732 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1734 local ilimit=$((1024 * 2)) # 2k inodes
1735 local TESTFILE0=$DIR/$tdir/$tfile
1736 local TESTFILE1=$DIR/${tdir}-1/$tfile
1738 setup_quota_test || error "setup quota failed with $?"
1739 trap cleanup_quota_test EXIT
1741 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1742 chmod 0777 $DIR/${tdir}-1
1744 set_mdt_qtype "u" || error "enable mdt quota failed"
1745 quota_show_check f u $TSTUSR
1747 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1748 error "set quota failed"
1750 echo "Create $ilimit files on mdt0..."
1751 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1752 quota_error u $TSTUSR "create failed, but expect success"
1754 echo "Create files on mdt1..."
1755 $RUNAS createmany -m $TESTFILE1 1 &&
1756 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1758 echo "Free space from mdt0..."
1759 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1760 wait_delete_completed
1761 sync_all_data || true
1763 echo "Create files on mdt1 after space freed from mdt0..."
1764 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1765 quota_error a $TSTUSR "rebalancing failed"
1767 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1768 error "unlink mdt1 files failed"
1769 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1773 run_test 12b "Inode quota rebalancing"
1776 local TESTFILE=$DIR/$tdir/$tfile
1777 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1778 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1780 setup_quota_test || error "setup quota failed with $?"
1781 trap cleanup_quota_test EXIT
1783 set_ost_qtype "u" || error "enable ost quota failed"
1784 quota_show_check b u $TSTUSR
1786 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1787 error "set quota failed"
1788 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1789 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1791 # clear the locks in cache first
1792 do_facet ost1 $LCTL set_param -n $procf=clear
1793 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1794 [ $nlock -eq 0 ] || error "$nlock cached locks"
1796 # write to acquire the per-ID lock
1797 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1798 quota_error a $TSTUSR "dd failed"
1800 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1801 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1803 # clear quota doesn't trigger per-ID lock cancellation
1804 resetquota -u $TSTUSR
1805 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1806 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1808 # clear the per-ID lock
1809 do_facet ost1 $LCTL set_param -n $procf=clear
1810 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1811 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1813 # spare quota should be released
1814 local OSTUUID=$(ostuuid_from_index 0)
1815 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1816 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1817 [ $limit -le $space ] ||
1818 error "spare quota isn't released, limit:$limit, space:$space"
1822 run_test 13 "Cancel per-ID lock in the LRU list"
1825 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1827 wait_delete_completed
1828 sync_all_data || true
1831 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1832 error "set user quota failed"
1833 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1834 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1835 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1836 resetquota -u $TSTUSR
1839 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1840 error "set group quota failed"
1841 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1842 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1843 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1844 resetquota -g $TSTUSR
1846 run_test 15 "Set over 4T block quota"
1850 local BLKS=1 # 1M less than limit
1851 local TESTFILE=$DIR/$tdir/$tfile
1853 setup_quota_test || error "setup quota failed with $?"
1854 trap cleanup_quota_test EXIT
1856 # make sure the system is clean
1857 local USED=$(getquota -u $TSTUSR global curspace)
1858 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1860 set_ost_qtype "ug" || error "enable ost quota failed"
1861 # make sure no granted quota on ost
1862 resetquota -u $TSTUSR
1863 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1864 error "set quota failed"
1866 quota_show_check b u $TSTUSR
1868 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1869 lustre_fail mds 0xa04 $err_code
1871 # write in background
1872 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1876 # write should be blocked and never finished
1877 if ! ps -p $DDPID > /dev/null 2>&1; then
1879 quota_error u $TSTUSR "write finished incorrectly!"
1887 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1889 if [ $count -gt $timeout ]; then
1890 quota_error u $TSTUSR "dd is not finished!"
1895 sync; sync_all_data || true
1897 USED=$(getquota -u $TSTUSR global curspace)
1898 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1899 "Used space(${USED}K) is less than ${BLKS}M"
1904 # DQACQ return recoverable error
1906 echo "DQACQ return -ENOLCK"
1908 test_17sub 37 || error "Handle -ENOLCK failed"
1910 echo "DQACQ return -EAGAIN"
1912 test_17sub 11 || error "Handle -EAGAIN failed"
1914 echo "DQACQ return -ETIMEDOUT"
1915 #define ETIMEDOUT 110
1916 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1918 echo "DQACQ return -ENOTCONN"
1919 #define ENOTCONN 107
1920 test_17sub 107 || error "Handle -ENOTCONN failed"
1923 run_test 17 "DQACQ return recoverable error"
1927 local blimit="200m" # 200M
1928 local TESTFILE="$DIR/$tdir/$tfile"
1930 setup_quota_test || error "setup quota failed with $?"
1931 trap cleanup_quota_test EXIT
1933 set_ost_qtype "u" || error "enable ost quota failed"
1934 log "User quota (limit: $blimit)"
1935 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1936 error "set quota failed"
1937 quota_show_check b u $TSTUSR
1939 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1940 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1942 local timeout=$(sysctl -n lustre.timeout)
1944 if [ $io_type = "directio" ]; then
1945 log "Write 100M (directio) ..."
1946 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1948 log "Write 100M (buffered) ..."
1949 $RUNAS $DD of=$TESTFILE count=100 &
1953 replay_barrier $SINGLEMDS
1954 log "Fail mds for $((2 * timeout)) seconds"
1955 fail $SINGLEMDS $((2 * timeout))
1958 if at_is_enabled; then
1959 timeout=$(at_max_get mds)
1961 timeout=$(lctl get_param -n timeout)
1965 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1966 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1967 log "it took $count second"
1972 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1974 cancel_lru_locks mdc
1975 cancel_lru_locks osc
1978 local testfile_size=$(stat -c %s $TESTFILE)
1979 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1980 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1981 "got ${testfile_size}. Verifying file failed!"
1986 # test when mds does failover, the ost still could work well
1987 # this test shouldn't trigger watchdog b=14840
1989 # Clear dmesg so watchdog is not triggered by previous
1991 do_facet ost1 dmesg -c > /dev/null
1994 test_18_sub directio
1996 # check if watchdog is triggered
1997 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1998 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1999 { print; }' $TMP/lustre-log-${TESTNAME}.log)
2000 [ -z "$watchdog" ] || error "$watchdog"
2001 rm -f $TMP/lustre-log-${TESTNAME}.log
2003 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2007 local TESTFILE=$DIR/$tdir/$tfile
2009 setup_quota_test || error "setup quota failed with $?"
2010 trap cleanup_quota_test EXIT
2012 set_ost_qtype $QTYPE || error "enable ost quota failed"
2014 # bind file to a single OST
2015 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2016 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2018 echo "Set user quota (limit: ${blimit}M)"
2019 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2020 error "set user quota failed"
2021 quota_show_check b u $TSTUSR
2022 echo "Update quota limits"
2023 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2024 error "set group quota failed"
2025 quota_show_check b u $TSTUSR
2027 # first wirte might be cached
2028 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2029 cancel_lru_locks osc
2031 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2032 quota_error u $TSTUSR "Write success, expect failure"
2037 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2039 test_20() { # b15754
2040 local LSTR=(2g 1t 4k 3m) # limits strings
2042 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2045 resetquota -u $TSTUSR
2047 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2048 $MOUNT || error "could not set quota limits"
2049 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2050 --inode-softlimit ${LSTR[2]} \
2051 --inode-hardlimit ${LSTR[3]} \
2052 $MOUNT || error "could not set quota limits"
2054 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2055 error "bsoftlimit was not set properly"
2056 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2057 error "bhardlimit was not set properly"
2058 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2059 error "isoftlimit was not set properly"
2060 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2061 error "ihardlimit was not set properly"
2063 resetquota -u $TSTUSR
2065 run_test 20 "Test if setquota specifiers work properly (b15754)"
2072 local time=$(($(date +%s) + seconds))
2073 while [ $(date +%s) -lt $time ]; do
2074 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2078 # run for fixing bug16053, setquota shouldn't fail when writing and
2079 # deleting are happening
2081 local TESTFILE="$DIR/$tdir/$tfile"
2082 local BLIMIT=10 # 10G
2083 local ILIMIT=1000000
2085 setup_quota_test || error "setup quota failed with $?"
2086 trap cleanup_quota_test EXIT
2088 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2090 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2091 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2092 error "set user quota failed"
2093 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2094 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2095 error "set group quota failed"
2096 if is_project_quota_supported; then
2097 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2098 "project: $TSTPRJID"
2099 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2100 $MOUNT || error "set project quota failed"
2103 # repeat writing on a 1M file
2104 test_21_sub ${TESTFILE}_1 1 30 &
2106 # repeat writing on a 128M file
2107 test_21_sub ${TESTFILE}_2 128 30 &
2110 local time=$(($(date +%s) + 30))
2112 while [ $(date +%s) -lt $time ]; do
2113 log "Set quota for $i times"
2114 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2115 -I $((ILIMIT + i)) $MOUNT ||
2116 error "Set user quota failed"
2117 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2118 -I $((ILIMIT + i)) $MOUNT ||
2119 error "Set group quota failed"
2120 if is_project_quota_supported; then
2121 $LFS setquota -p $TSTPRJID -b 0 -B \
2122 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2123 error "Set project quota failed"
2131 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2133 if [ $count -gt 60 ]; then
2134 quota_error a $TSTUSR "dd should be finished!"
2138 echo "(dd_pid=$DDPID1, time=$count)successful"
2142 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2144 if [ $count -gt 60 ]; then
2145 quota_error a $TSTUSR "dd should be finished!"
2149 echo "(dd_pid=$DDPID2, time=$count)successful"
2153 run_test 21 "Setquota while writing & deleting (b16053)"
2155 # enable/disable quota enforcement permanently
2157 echo "Set both mdt & ost quota type as ug"
2159 is_project_quota_supported && qtype=$QTYPE
2160 set_mdt_qtype $qtype || error "enable mdt quota failed"
2161 set_ost_qtype $qtype || error "enable ost quota failed"
2164 stopall || error "failed to stopall (1)"
2168 echo "Verify if quota is enabled"
2169 local qtype1=$(mdt_quota_type)
2170 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2171 qtype=$(ost_quota_type)
2172 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2174 echo "Set both mdt & ost quota type as none"
2175 set_mdt_qtype "none" || error "disable mdt quota failed"
2176 set_ost_qtype "none" || error "disable ost quota failed"
2179 stopall || error "failed to stopall (2)"
2184 echo "Verify if quota is disabled"
2185 qtype=$(mdt_quota_type)
2186 [ $qtype != "none" ] && error "mdt quota setting is lost"
2187 qtype=$(ost_quota_type)
2188 [ $qtype != "none" ] && error "ost quota setting is lost"
2192 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2195 local TESTFILE="$DIR/$tdir/$tfile"
2198 setup_quota_test || error "setup quota failed with $?"
2199 trap cleanup_quota_test EXIT
2201 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2204 log "User quota (limit: $LIMIT MB)"
2205 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2206 error "set quota failed"
2207 quota_show_check b u $TSTUSR
2209 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2210 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2212 log "Step1: trigger EDQUOT with O_DIRECT"
2213 log "Write half of file"
2214 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2215 quota_error u $TSTUSR "(1) Write failure, expect success." \
2217 log "Write out of block quota ..."
2218 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2219 oflag=direct conv=notrunc &&
2220 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2224 log "Step2: rewrite should succeed"
2225 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2226 quota_error u $TSTUSR "(3) Write failure, expect success." \
2232 local OST0_UUID=$(ostuuid_from_index 0)
2233 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2234 [ $OST0_QUOTA_USED -ne 0 ] &&
2235 ($SHOW_QUOTA_USER; \
2236 quota_error u $TSTUSR "quota isn't released")
2241 [ "$ost1_FSTYPE" == zfs ] &&
2242 skip "Overwrite in place is not guaranteed to be " \
2243 "space neutral on ZFS"
2245 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2246 check_whether_skip && return 0
2247 log "run for 4MB test file"
2250 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2251 check_whether_skip && return 0
2252 log "run for 40MB test file"
2255 run_test 23 "Quota should be honored with directIO (b16125)"
2259 local TESTFILE="$DIR/$tdir/$tfile"
2261 setup_quota_test || error "setup quota failed with $?"
2262 trap cleanup_quota_test EXIT
2264 set_ost_qtype $QTYPE || error "enable ost quota failed"
2266 # bind file to a single OST
2267 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2268 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2270 echo "Set user quota (limit: ${blimit}M)"
2271 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2272 error "set quota failed"
2274 # overrun quota by root user
2275 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2276 error "write failure, expect success"
2277 cancel_lru_locks osc
2278 sync_all_data || true
2280 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2284 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2286 test_27a() { # b19612
2287 $LFS quota $TSTUSR $DIR &&
2288 error "lfs succeeded with no type, but should have failed"
2289 $LFS setquota $TSTUSR $DIR &&
2290 error "lfs succeeded with no type, but should have failed"
2293 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2295 test_27b() { # b20200
2296 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2297 error "lfs setquota failed with uid argument"
2298 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2299 error "lfs stequota failed with gid argument"
2300 if is_project_quota_supported; then
2301 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2302 1000 $DIR || error \
2303 "lfs stequota failed with projid argument"
2305 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2306 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2307 if is_project_quota_supported; then
2308 $SHOW_QUOTA_PROJID ||
2309 error "lfs quota failed with projid argument"
2311 resetquota -u $TSTID
2312 resetquota -g $TSTID
2313 resetquota -p $TSTPRJID
2316 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2321 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2322 error "lfs setquota failed"
2324 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2325 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2326 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2327 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2329 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2330 error "lfs setquota for $TSTID failed"
2332 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2333 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2334 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2335 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2337 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2338 error "total allocated inode/block limit not printed"
2340 resetquota -u $TSTUSR
2342 run_test 27c "lfs quota should support human-readable output"
2349 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2350 error "set fraction block limit failed"
2351 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2352 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2353 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2354 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2356 resetquota -u $TSTUSR
2358 run_test 27d "lfs setquota should support fraction block limit"
2362 local TESTFILE="$DIR/$tdir/$tfile"
2365 setup_quota_test || error "setup quota failed with $?"
2366 trap cleanup_quota_test EXIT
2368 set_ost_qtype "u" || error "enable ost quota failed"
2370 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2371 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2373 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2374 $MAX_IQ_TIME $DIR || error "set grace time failed"
2375 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2376 error "set quota failed"
2377 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2378 cancel_lru_locks osc
2380 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2381 # over-quota flag has not yet settled since we do not trigger async
2382 # events based on grace time period expiration
2384 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2385 cancel_lru_locks osc
2386 # now over-quota flag should be settled and further writes should fail
2388 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2389 error "grace times were reset"
2392 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2393 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2395 run_test 30 "Hard limit updates should not reset grace times"
2397 # basic usage tracking for user & group
2399 local INODES=10 # 10 files
2400 local BLK_CNT=2 # of 2M each
2401 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2403 setup_quota_test || error "setup quota failed with $?"
2404 trap cleanup_quota_test EXIT
2406 # make sure the system is clean
2407 local USED=$(getquota -u $TSTID global curspace)
2409 error "Used space ($USED) for user $TSTID isn't 0."
2410 USED=$(getquota -g $TSTID global curspace)
2412 error "Used space ($USED) for group $TSTID isn't 0."
2413 if is_project_quota_supported; then
2414 USED=$(getquota -p $TSTPRJID global curspace)
2415 [ $USED -ne 0 ] && error \
2416 "Used space ($USED) for project $TSTPRJID isn't 0."
2419 echo "Write files..."
2420 for i in $(seq 0 $INODES); do
2421 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2422 error "write failed"
2423 is_project_quota_supported &&
2424 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2425 echo "Iteration $i/$INODES completed"
2427 cancel_lru_locks osc
2429 echo "Wait for setattr on objects finished..."
2430 wait_delete_completed
2432 sync; sync_all_data || true
2434 echo "Verify disk usage after write"
2435 USED=$(getquota -u $TSTID global curspace)
2436 [ $USED -lt $TOTAL_BLKS ] &&
2437 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2438 USED=$(getquota -g $TSTID global curspace)
2439 [ $USED -lt $TOTAL_BLKS ] &&
2440 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2441 if is_project_quota_supported; then
2442 USED=$(getquota -p $TSTPRJID global curspace)
2443 [ $USED -lt $TOTAL_BLKS ] && error \
2444 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2447 echo "Verify inode usage after write"
2448 USED=$(getquota -u $TSTID global curinodes)
2449 [ $USED -lt $INODES ] &&
2450 error "Used inode for user $TSTID is $USED, expected $INODES"
2451 USED=$(getquota -g $TSTID global curinodes)
2452 [ $USED -lt $INODES ] &&
2453 error "Used inode for group $TSTID is $USED, expected $INODES"
2454 if is_project_quota_supported; then
2455 USED=$(getquota -p $TSTPRJID global curinodes)
2456 [ $USED -lt $INODES ] && error \
2457 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2462 echo "Verify disk usage after delete"
2463 USED=$(getquota -u $TSTID global curspace)
2464 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2465 USED=$(getquota -u $TSTID global curinodes)
2466 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2467 USED=$(getquota -g $TSTID global curspace)
2468 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2469 USED=$(getquota -g $TSTID global curinodes)
2470 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2471 if is_project_quota_supported; then
2472 USED=$(getquota -p $TSTPRJID global curspace)
2474 error "Used space for project $TSTPRJID isn't 0. $USED"
2475 USED=$(getquota -p $TSTPRJID global curinodes)
2477 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2480 run_test 33 "Basic usage tracking for user & group & project"
2482 # usage transfer test for user & group & project
2484 local BLK_CNT=2 # 2MB
2485 local project_supported="no"
2487 is_project_quota_supported && project_supported="yes"
2488 setup_quota_test || error "setup quota failed with $?"
2489 trap cleanup_quota_test EXIT
2491 # make sure the system is clean
2492 local USED=$(getquota -u $TSTID global curspace)
2493 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2494 USED=$(getquota -g $TSTID global curspace)
2495 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2497 local USED=$(getquota -u $TSTID2 global curspace)
2498 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2499 if [ $project_supported == "yes" ]; then
2500 USED=$(getquota -p $TSTPRJID global curspace)
2501 [ $USED -ne 0 ] && error \
2502 "Used space ($USED) for Project $TSTPRJID isn't 0."
2505 echo "Write file..."
2506 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2507 error "write failed"
2508 cancel_lru_locks osc
2509 sync; sync_all_data || true
2511 echo "chown the file to user $TSTID"
2512 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2514 echo "Wait for setattr on objects finished..."
2515 wait_delete_completed
2517 BLK_CNT=$((BLK_CNT * 1024))
2519 echo "Verify disk usage for user $TSTID"
2520 USED=$(getquota -u $TSTID global curspace)
2521 [ $USED -lt $BLK_CNT ] &&
2522 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2523 USED=$(getquota -u $TSTID global curinodes)
2525 error "Used inodes for user $TSTID is $USED, expected 1"
2527 echo "chgrp the file to group $TSTID"
2528 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2530 echo "Wait for setattr on objects finished..."
2531 wait_delete_completed
2533 echo "Verify disk usage for group $TSTID"
2534 USED=$(getquota -g $TSTID global curspace)
2535 [ $USED -ge $BLK_CNT ] ||
2536 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2537 USED=$(getquota -g $TSTID global curinodes)
2539 error "Used inodes for group $TSTID is $USED, expected 1"
2541 # chown won't change the ost object group. LU-4345 */
2542 echo "chown the file to user $TSTID2"
2543 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2545 echo "Wait for setattr on objects finished..."
2546 wait_delete_completed
2548 echo "change_project project id to $TSTPRJID"
2549 [ $project_supported == "yes" ] &&
2550 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2551 echo "Wait for setattr on objects finished..."
2552 wait_delete_completed
2554 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2555 USED=$(getquota -u $TSTID2 global curspace)
2556 [ $USED -lt $BLK_CNT ] &&
2557 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2558 USED=$(getquota -u $TSTID global curspace)
2560 error "Used space for user $TSTID is $USED, expected 0"
2561 USED=$(getquota -g $TSTID global curspace)
2562 [ $USED -lt $BLK_CNT ] &&
2563 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2564 if [ $project_supported == "yes" ]; then
2565 USED=$(getquota -p $TSTPRJID global curspace)
2566 [ $USED -lt $BLK_CNT ] && error \
2567 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2572 run_test 34 "Usage transfer for user & group & project"
2574 # usage is still accessible across restart
2576 local BLK_CNT=2 # 2 MB
2578 setup_quota_test || error "setup quota failed with $?"
2579 trap cleanup_quota_test EXIT
2581 echo "Write file..."
2582 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2583 error "write failed"
2584 is_project_quota_supported &&
2585 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2586 cancel_lru_locks osc
2588 echo "Wait for setattr on objects finished..."
2589 wait_delete_completed
2591 sync; sync_all_data || true
2593 echo "Save disk usage before restart"
2594 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2595 [ $ORIG_USR_SPACE -eq 0 ] &&
2596 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2597 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2598 [ $ORIG_USR_INODES -eq 0 ] &&
2599 error "Used inodes for user $TSTID is 0, expected 1"
2600 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2601 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2602 [ $ORIG_GRP_SPACE -eq 0 ] &&
2603 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2604 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2605 [ $ORIG_GRP_INODES -eq 0 ] &&
2606 error "Used inodes for group $TSTID is 0, expected 1"
2607 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2609 if is_project_quota_supported; then
2610 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2611 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2612 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2613 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2614 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2615 "Used inodes for project $TSTPRJID is 0, expected 1"
2616 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2624 echo "Verify disk usage after restart"
2625 local USED=$(getquota -u $TSTID global curspace)
2626 [ $USED -eq $ORIG_USR_SPACE ] ||
2627 error "Used space for user $TSTID changed from " \
2628 "$ORIG_USR_SPACE to $USED"
2629 USED=$(getquota -u $TSTID global curinodes)
2630 [ $USED -eq $ORIG_USR_INODES ] ||
2631 error "Used inodes for user $TSTID changed from " \
2632 "$ORIG_USR_INODES to $USED"
2633 USED=$(getquota -g $TSTID global curspace)
2634 [ $USED -eq $ORIG_GRP_SPACE ] ||
2635 error "Used space for group $TSTID changed from " \
2636 "$ORIG_GRP_SPACE to $USED"
2637 USED=$(getquota -g $TSTID global curinodes)
2638 [ $USED -eq $ORIG_GRP_INODES ] ||
2639 error "Used inodes for group $TSTID changed from " \
2640 "$ORIG_GRP_INODES to $USED"
2641 if [ $project_supported == "yes" ]; then
2642 USED=$(getquota -p $TSTPRJID global curinodes)
2643 [ $USED -eq $ORIG_PRJ_INODES ] ||
2644 error "Used inodes for project $TSTPRJID " \
2645 "changed from $ORIG_PRJ_INODES to $USED"
2646 USED=$(getquota -p $TSTPRJID global curspace)
2647 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2648 error "Used space for project $TSTPRJID "\
2649 "changed from $ORIG_PRJ_SPACE to $USED"
2652 # check if the vfs_dq_init() is called before writing
2653 echo "Append to the same file..."
2654 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2655 error "write failed"
2656 cancel_lru_locks osc
2657 sync; sync_all_data || true
2659 echo "Verify space usage is increased"
2660 USED=$(getquota -u $TSTID global curspace)
2661 [ $USED -gt $ORIG_USR_SPACE ] ||
2662 error "Used space for user $TSTID isn't increased" \
2663 "orig:$ORIG_USR_SPACE, now:$USED"
2664 USED=$(getquota -g $TSTID global curspace)
2665 [ $USED -gt $ORIG_GRP_SPACE ] ||
2666 error "Used space for group $TSTID isn't increased" \
2667 "orig:$ORIG_GRP_SPACE, now:$USED"
2668 if [ $project_supported == "yes" ]; then
2669 USED=$(getquota -p $TSTPRJID global curspace)
2670 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2671 error "Used space for project $TSTPRJID isn't " \
2672 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2677 run_test 35 "Usage is still accessible across reboot"
2679 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2682 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2683 skip "Old server doesn't have LU-5006 fix."
2685 setup_quota_test || error "setup quota failed with $?"
2686 trap cleanup_quota_test EXIT
2688 # make sure the system is clean
2689 local USED=$(getquota -u $TSTID global curspace)
2691 error "Used space ($USED) for user $TSTID isn't 0."
2693 # create file with MDS_OPEN_DELAY_CREATE flag
2694 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2695 error "Create file failed"
2697 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2698 oflag=sync || error "Write file failed"
2700 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2702 # wait for setattr on objects finished..."
2703 wait_delete_completed
2705 USED=$(getquota -u $TSTID global curspace)
2706 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2710 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2714 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2715 skip "Old server doesn't have LU-8801 fix."
2717 [ "$UID" != 0 ] && skip_env "must run as root" && return
2719 setup_quota_test || error "setup quota failed with $?"
2720 trap cleanup_quota_test EXIT
2722 # make sure the system is clean
2723 local USED=$(getquota -u $TSTID global curspace)
2725 error "Used space ($USED) for user $TSTID isn't 0."
2726 USED=$(getquota -u $TSTID2 global curspace)
2728 error "Used space ($USED) for user $TSTID2 isn't 0."
2730 local TESTFILE="$DIR/$tdir/$tfile"
2731 local file_cnt=10000
2733 # Generate id entries in accounting file
2734 echo "Create $file_cnt files..."
2735 for i in `seq $file_cnt`; do
2737 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2738 error "failed to chown $TESTFILE-$i"
2740 cancel_lru_locks osc
2741 sync; sync_all_data || true
2743 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2744 procf=${procf}.quota_slave.acct_user
2747 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2748 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2749 echo "Found $acct_cnt id entries"
2751 [ $file_cnt -eq $acct_cnt ] || {
2752 do_facet mds1 $LCTL get_param $procf
2753 error "skipped id entries"
2758 run_test 38 "Quota accounting iterator doesn't skip id entries"
2761 local TESTFILE="$DIR/$tdir/project"
2762 ! is_project_quota_supported &&
2763 skip "Project quota is not supported"
2765 setup_quota_test || error "setup quota failed with $?"
2768 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2769 [ $projectid -ne 0 ] &&
2770 error "Project id should be 0 not $projectid"
2771 change_project -p 1024 $TESTFILE
2772 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2773 [ $projectid -ne 1024 ] &&
2774 error "Project id should be 1024 not $projectid"
2776 stopall || error "failed to stopall (1)"
2779 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2780 [ $projectid -ne 1024 ] &&
2781 error "Project id should be 1024 not $projectid"
2785 run_test 39 "Project ID interface works correctly"
2788 ! is_project_quota_supported &&
2789 skip "Project quota is not supported"
2790 local dir1="$DIR/$tdir/dir1"
2791 local dir2="$DIR/$tdir/dir2"
2793 setup_quota_test || error "setup quota failed with $?"
2795 mkdir -p $dir1 $dir2
2796 change_project -sp 1 $dir1 && touch $dir1/1
2797 change_project -sp 2 $dir2
2799 ln $dir1/1 $dir2/1_link &&
2800 error "Hard link across different project quota should fail"
2805 run_test 40a "Hard link across different project ID"
2808 ! is_project_quota_supported &&
2809 skip "Project quota is not supported"
2810 local dir1="$DIR/$tdir/dir1"
2811 local dir2="$DIR/$tdir/dir2"
2813 setup_quota_test || error "setup quota failed with $?"
2814 mkdir -p $dir1 $dir2
2815 change_project -sp 1 $dir1 && touch $dir1/1
2816 change_project -sp 2 $dir2
2818 mv $dir1/1 $dir2/2 || error "mv failed $?"
2819 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2820 if [ "$projid" != "2" ]; then
2821 error "project id expected 2 not $projid"
2826 run_test 40b "Mv across different project ID"
2829 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2830 ! is_project_quota_supported &&
2831 skip "Project quota is not supported"
2833 setup_quota_test || error "setup quota failed with $?"
2834 local dir="$DIR/$tdir/dir"
2836 mkdir -p $dir && change_project -sp 1 $dir
2837 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2838 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2839 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2840 touch $dir/remote_dir/file
2841 #verify inherit works file for remote dir.
2842 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2843 [ "$projid" != "1" ] &&
2844 error "file under remote dir expected 1 not $projid"
2846 #Agent inode should be ignored for project quota
2847 USED=$(getquota -p 1 global curinodes)
2848 [ "$USED" != "3" ] &&
2849 error "file count expected 3 got $USED"
2855 run_test 40c "Remote child Dir inherit project quota properly"
2858 ! is_project_quota_supported &&
2859 skip "Project quota is not supported"
2861 setup_quota_test || error "setup quota failed with $?"
2862 local dir1="$DIR/$tdir/dir1"
2863 local dir2="$DIR/$tdir/dir2"
2865 mkdir -p $dir1 && change_project -sp 1 $dir1
2866 mkdir -p $dir2 && change_project -sp 2 $dir2
2867 for num in $(seq 1 10); do
2868 touch $dir1/file_$num $dir2/file_$num
2869 ln -s $dir1/file_$num $dir1/file_$num"_link"
2870 ln -s $dir2/file_$num $dir2/file_$num"_link"
2873 count=$($LFS find --projid 1 $DIR | wc -l)
2874 [ "$count" != 21 ] && error "expected 21 but got $count"
2876 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2877 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2878 [ "$count" != 22 ] && error "expected 22 but got $count"
2883 run_test 50 "Test if lfs find --projid works"
2886 ! is_project_quota_supported &&
2887 skip "Project quota is not supported"
2888 setup_quota_test || error "setup quota failed with $?"
2889 local dir="$DIR/$tdir/dir"
2891 mkdir $dir && change_project -sp 1 $dir
2892 local used=$(getquota -p 1 global curinodes)
2893 [ $used != "1" ] && error "expected 1 got $used"
2898 used=$(getquota -p 1 global curinodes)
2899 [ $used != "4" ] && error "expected 4 got $used"
2901 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2903 cp $DIR/$tdir/6 $dir/6
2904 used=$(getquota -p 1 global curinodes)
2905 [ $used != "5" ] && error "expected 5 got $used"
2908 mv $DIR/$tdir/6 $dir/7
2909 used=$(getquota -p 1 global curinodes)
2910 [ $used != "6" ] && error "expected 6 got $used"
2915 run_test 51 "Test project accounting with mv/cp"
2918 ! is_project_quota_supported &&
2919 skip "Project quota is not supported"
2920 setup_quota_test || error "setup quota failed with $?"
2921 local dir="$DIR/$tdir/dir"
2922 mkdir $dir && change_project -sp 1 $dir
2924 touch $DIR/$tdir/file
2925 #Try renaming a file into the project. This should fail.
2926 for num in $(seq 1 2000); do
2927 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2928 error "rename should fail"
2933 run_test 52 "Rename across different project ID"
2936 ! is_project_quota_supported &&
2937 skip "Project quota is not supported"
2938 setup_quota_test || error "setup quota failed with $?"
2939 local dir="$DIR/$tdir/dir"
2940 mkdir $dir && change_project -s $dir
2941 lfs project -d $dir | grep P || error "inherit attribute should be set"
2943 change_project -C $dir
2944 lfs project -d $dir | grep P &&
2945 error "inherit attribute should be cleared"
2950 run_test 53 "Project inherit attribute could be cleared"
2953 ! is_project_quota_supported &&
2954 skip "Project quota is not supported"
2955 setup_quota_test || error "setup quota failed with $?"
2956 trap cleanup_quota_test EXIT
2957 local testfile="$DIR/$tdir/$tfile-0"
2959 #set project ID/inherit attribute
2960 change_project -sp $TSTPRJID $DIR/$tdir
2961 $RUNAS createmany -m ${testfile} 100 ||
2962 error "create many files failed"
2964 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2965 # one more count for directory itself */
2969 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2970 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2972 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2973 [ $proj_count1 -eq $proj_count ] ||
2974 error "c2: expected $proj_count got $proj_count1"
2976 #clear project but with kept projid
2977 change_project -rCk $DIR/$tdir
2978 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2979 [ $proj_count1 -eq 1 ] ||
2980 error "c3: expected 1 got $proj_count1"
2982 #verify projid untouched.
2983 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2985 [ $proj_count1 -eq $proj_count ] ||
2986 error "c4: expected $proj_count got $proj_count1"
2989 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2990 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2991 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2993 #this time clear all
2994 change_project -rC $DIR/$tdir
2995 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2996 [ $proj_count1 -eq 0 ] ||
2997 error "c6: expected 0 got $proj_count1"
2999 unlinkmany ${testfile} 100 ||
3000 error "unlink many files failed"
3004 run_test 54 "basic lfs project interface test"
3007 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3008 skip "Not supported before 2.10.58."
3009 setup_quota_test || error "setup quota failed with $?"
3011 set_ost_qtype $QTYPE || error "enable ost quota failed"
3014 #add second group to TSTUSR
3015 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3018 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3019 error "failed to dd"
3021 cancel_lru_locks osc
3022 sync; sync_all_data || true
3024 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3025 error "failed to setquota on group $TSTUSR2"
3027 $LFS quota -v -g $TSTUSR2 $DIR
3029 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3030 error "chgrp should failed with -EDQUOT"
3032 USED=$(getquota -g $TSTUSR2 global curspace)
3035 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3036 error "failed to setquota on group $TSTUSR2"
3038 $LFS quota -v -g $TSTUSR2 $DIR
3040 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3041 error "chgrp should succeed"
3043 $LFS quota -v -g $TSTUSR2 $DIR
3047 run_test 55 "Chgrp should be affected by group quota"
3050 setup_quota_test || error "setup quota failed with $?"
3052 set_ost_qtype $QTYPE || error "enable ost quota failed"
3055 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3056 erro "failed to set grace time for usr quota"
3057 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3058 awk '{print $4 $8}')
3059 if [ "x$grace_time" != "x10s;10s" ]; then
3060 $LFS quota -t -u $DIR
3061 error "expected grace time: 10s;10s, got:$grace_time"
3066 run_test 56 "lfs quota -t should work well"
3069 setup_quota_test || error "setup quota failed with $?"
3071 local dir="$DIR/$tdir/dir"
3074 #try to change pipe file should not hang and return failure
3075 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3076 awk -F ':' '{ print \\\$2 }'" \
3077 " unable to get xattr for fifo '$dir/pipe'" || return 1
3078 #command can process further if it hit some errors
3079 touch $dir/aaa $dir/bbb
3080 mkdir $dir/subdir -p
3081 touch $dir/subdir/aaa $dir/subdir/bbb
3082 #create one invalid link file
3083 ln -s $dir/not_exist_file $dir/ccc
3084 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3085 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3089 run_test 57 "lfs project could tolerate errors"
3092 [ "$mds1_FSTYPE" != ldiskfs ] &&
3093 skip "ldiskfs only test"
3094 disable_project_quota
3095 setup_quota_test || error "setup quota failed with $?"
3098 local testfile="$DIR/$tdir/$tfile-0"
3099 #make sure it did not crash kernel
3100 touch $testfile && lfs project -sp 1 $testfile
3102 enable_project_quota
3105 run_test 59 "lfs project dosen't crash kernel with project disabled"
3108 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3109 skip "Needs MDS version 2.11.53 or later."
3110 setup_quota_test || error "setup quota failed with $?"
3111 trap cleanup_quota_test EXIT
3113 local testfile=$DIR/$tdir/$tfile
3116 set_mdt_qtype "ug" || error "enable mdt quota failed"
3118 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3119 error "set quota failed"
3120 quota_show_check a g $TSTUSR
3122 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3123 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3124 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3125 error "create many files failed"
3127 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3129 # root user can overrun quota
3130 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3131 error "root user should succeed"
3135 run_test 60 "Test quota for root with setgid"
3137 # test default quota
3138 test_default_quota() {
3139 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3140 skip "Not supported before 2.11.51."
3145 local qprjid=$TSTPRJID
3149 local LIMIT=20480 #20M disk space
3150 local TESTFILE="$DIR/$tdir/$tfile-0"
3152 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3153 echo "Project quota is not supported" && return 0
3155 [ $qtype == "-u" ] && qdtype="-U"
3156 [ $qtype == "-g" ] && qdtype="-G"
3157 [ $qtype == "-p" ] && {
3162 [ $qpool == "meta" ] && {
3163 LIMIT=10240 #10K inodes
3168 setup_quota_test || error "setup quota failed with $?"
3169 trap cleanup_quota_test EXIT
3173 # enable mdt/ost quota
3174 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3175 set_ost_qtype $QTYPE || error "enable ost quota failed"
3177 log "set to use default quota"
3178 $LFS setquota $qtype $qid -d $DIR ||
3179 error "set $qid to use default quota failed"
3181 log "set default quota"
3182 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3183 error "set $qid default quota failed"
3185 log "get default quota"
3186 $LFS quota $qdtype $DIR || error "get default quota failed"
3188 if [ $qpool == "data" ]; then
3189 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3191 [ $SLIMIT -eq $LIMIT ] ||
3192 error "the returned default quota is wrong"
3194 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3196 [ $SLIMIT -eq $LIMIT ] ||
3197 error "the returned default quota is wrong"
3200 # make sure the system is clean
3201 local USED=$(getquota $qtype $qid global curspace)
3202 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3204 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3205 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3207 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3209 log "Test not out of quota"
3210 if [ $qpool == "data" ]; then
3211 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3212 quota_error $qtype $qid "write failed, expect succeed"
3214 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3215 quota_error $qtype $qid "create failed, expect succeed"
3217 unlinkmany $TESTFILE $((LIMIT/2))
3220 log "Test out of quota"
3221 # flush cache, ensure noquota flag is set on client
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 EDQUOT"
3229 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3230 quota_error $qtype $qid "create succeed, expect EDQUOT"
3232 unlinkmany $TESTFILE $((LIMIT*2))
3235 log "Increase default quota"
3236 # increase default quota
3237 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3238 error "set default quota failed"
3240 cancel_lru_locks osc
3241 cancel_lru_locks mdc
3242 sync; sync_all_data || true
3243 if [ $qpool == "data" ]; then
3244 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3245 quota_error $qtype $qid "write failed, expect succeed"
3247 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3248 quota_error $qtype $qid "create failed, expect succeed"
3250 unlinkmany $TESTFILE $((LIMIT*2))
3253 log "Set quota to override default quota"
3254 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3255 error "set $qid quota failed"
3257 cancel_lru_locks osc
3258 cancel_lru_locks mdc
3259 sync; sync_all_data || true
3260 if [ $qpool == "data" ]; then
3261 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3262 quota_error $qtype $qid "write succeed, expect EQUOT"
3264 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3265 quota_error $qtype $qid "create succeed, expect EQUOT"
3267 unlinkmany $TESTFILE $((LIMIT*2))
3270 log "Set to use default quota again"
3271 $LFS setquota $qtype $qid -d $DIR ||
3272 error "set $qid to use default quota failed"
3274 cancel_lru_locks osc
3275 cancel_lru_locks mdc
3276 sync; sync_all_data || true
3277 if [ $qpool == "data" ]; then
3278 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3279 quota_error $qtype $qid "write failed, expect succeed"
3281 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3282 quota_error $qtype $qid "create failed, expect succeed"
3284 unlinkmany $TESTFILE $((LIMIT*2))
3289 wait_delete_completed || error "wait_delete_completed failed"
3290 sync_all_data || true
3291 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3292 error "reset default quota failed"
3293 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3294 error "reset quota failed"
3300 test_default_quota "-u" "data"
3301 test_default_quota "-u" "meta"
3302 test_default_quota "-g" "data"
3303 test_default_quota "-g" "meta"
3304 test_default_quota "-p" "data"
3305 test_default_quota "-p" "meta"
3307 run_test 61 "default quota tests"
3310 ! is_project_quota_supported &&
3311 skip "Project quota is not supported"
3312 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3313 skip "chattr did not support project quota"
3314 setup_quota_test || error "setup quota failed with $?"
3315 local testdir=$DIR/$tdir/
3317 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3318 change_project -s $testdir
3319 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3320 error "inherit attribute should be set"
3321 # chattr used FS_IOC_SETFLAGS ioctl
3322 $RUNAS chattr -P $testdir &&
3323 error "regular user clear inherit should fail"
3324 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3325 error "inherit attribute should still be set"
3326 chattr -P $testdir || error "root failed to clear inherit"
3327 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3328 error "inherit attribute should be cleared"
3331 run_test 62 "Project inherit should be only changed by root"
3334 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3335 skip "Not supported before 2.11.55"
3339 local dd_failed=false
3340 local tdir_dom=${tdir}_dom
3341 local LIMIT=20480 #20M
3343 [ $qtype == "p" ] && ! is_project_quota_supported &&
3344 echo "Project quota is not supported" && return 0
3346 [ $qtype == "p" ] && qid=$TSTPRJID
3348 setup_quota_test || error "setup quota failed with $?"
3349 trap cleanup_quota_test EXIT
3353 # enable mdt/ost quota
3354 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3355 set_ost_qtype $QTYPE || error "enable ost quota failed"
3357 # make sure the system is clean
3358 local USED=$(getquota -$qtype $qid global curspace)
3359 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3361 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3363 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3364 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3365 error "setstripe $tdir_dom failed"
3366 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3368 [ $qtype == "p" ] && {
3369 change_project -sp $TSTPRJID $DIR/$tdir
3370 change_project -sp $TSTPRJID $DIR/$tdir_dom
3373 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3374 error "set $qid quota failed"
3376 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3377 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3381 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3383 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3384 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3388 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3390 rm -f $DIR/$tdir_dom/*
3392 # flush cache, ensure noquota flag is set on client
3393 cancel_lru_locks osc
3394 cancel_lru_locks mdc
3395 sync; sync_all_data || true
3399 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3400 quota_error $qtype $qid "write failed, expect succeed"
3402 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3403 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3407 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3410 rm -f $DIR/$tdir_dom/*
3412 # flush cache, ensure noquota flag is set on client
3413 cancel_lru_locks osc
3414 cancel_lru_locks mdc
3415 sync; sync_all_data || true
3419 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3420 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3424 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3426 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3427 quota_error $qtype $qid "write succeed, expect EDQUOT"
3430 rm -fr $DIR/$tdir_dom
3432 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3433 error "reset usr quota failed"
3443 run_test 63 "quota on DoM tests"
3446 ! is_project_quota_supported &&
3447 skip "Project quota is not supported"
3448 setup_quota_test || error "setup quota failed with $?"
3449 local dir1="$DIR/$tdir/"
3452 ln -s $dir1/file $dir1/file_link
3454 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3455 error "set symlink file's project should fail"
3457 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3458 error "get symlink file's project should fail"
3462 run_test 64 "lfs project on symlink files should fail"
3466 local TESTFILE="$DIR/$tdir/$tfile-0"
3468 setup_quota_test || error "setup quota failed with $?"
3469 set_ost_qtype $QTYPE || error "enable ost quota failed"
3473 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3474 error "failed to write"
3475 # flush cache, ensure noquota flag is set on client
3476 cancel_lru_locks osc
3477 sync; sync_all_data || true
3479 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3480 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3481 local quota_all=$($RUNAS $LFS quota $DIR)
3483 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3484 error "usr quota not match"
3485 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3486 error "grp quota not match"
3492 run_test 65 "Check lfs quota result"
3495 ! is_project_quota_supported &&
3496 skip "Project quota is not supported"
3497 [ "$MDS1_VERSION" -lt $(version_code 2.12.4) ] &&
3498 skip "Not supported before 2.12.4"
3499 setup_quota_test || error "setup quota failed with $?"
3500 stack_trap cleanup_quota_test EXIT
3501 local old=$(do_facet mds1 $LCTL get_param -n \
3502 mdt.*.enable_chprojid_gid | head -1)
3503 local testdir=$DIR/$tdir/foo
3505 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3506 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3509 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3510 chown -R $TSTID:$TSTID $testdir
3511 change_project -sp $TSTPRJID $testdir
3512 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3514 $RUNAS lfs project -p 0 $testdir/foo &&
3515 error "nonroot user should fail to set projid"
3517 $RUNAS lfs project -C $testdir/foo &&
3518 error "nonroot user should fail to clear projid"
3520 change_project -C $testdir/foo || error "failed to clear project"
3522 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3523 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3524 "failed to set projid with normal user when enable_chprojid_gid=-1"
3526 $RUNAS lfs project -rC $testdir/ || error \
3527 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3529 touch $testdir/bar || error "failed touch $testdir/bar"
3530 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3531 "normal user should not be able to set projid on root owned file"
3533 change_project -p $TSTPRJID $testdir/bar || error \
3534 "root should be able to change its own file's projid"
3538 run_test 66 "nonroot user can not change project state in default"
3542 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3543 if $PQ_CLEANUP; then
3544 disable_project_quota
3547 reset_quota_settings
3552 check_and_cleanup_lustre
3553 export QUOTA_AUTO=$QUOTA_AUTO_OLD