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
761 $SHOW_QUOTA_INFO_USER
762 $SHOW_QUOTA_INFO_GROUP
763 $SHOW_QUOTA_INFO_PROJID
765 echo "Write before timer goes off"
766 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
767 quota_error a $TSTUSR "write failure, but expect success"
768 OFFSET=$((OFFSET + 1024))
771 wait_grace_time $qtype "block"
776 $SHOW_QUOTA_INFO_USER
777 $SHOW_QUOTA_INFO_GROUP
778 $SHOW_QUOTA_INFO_PROJID
780 echo "Write after timer goes off"
781 # maybe cache write, ignore.
782 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
783 OFFSET=$((OFFSET + 1024))
785 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
786 quota_error a $TSTUSR "write success, but expect EDQUOT"
791 $SHOW_QUOTA_INFO_USER
792 $SHOW_QUOTA_INFO_GROUP
793 $SHOW_QUOTA_INFO_PROJID
795 echo "Unlink file to stop timer"
797 wait_delete_completed
798 sync_all_data || true
803 $SHOW_QUOTA_INFO_USER
804 $SHOW_QUOTA_INFO_GROUP
805 $SHOW_QUOTA_INFO_PROJID
807 $LFS setstripe $TESTFILE -c 1 -i 0
808 chown $TSTUSR.$TSTUSR $TESTFILE
809 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
812 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
813 quota_error a $TSTUSR "write failure, but expect success"
821 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
824 local TESTFILE=$DIR/$tdir/$tfile-0
826 # get minimum soft qunit size
827 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
828 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
830 set_ost_qtype $QTYPE || error "enable ost quota failed"
832 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
833 # make sure the system is clean
834 local USED=$(getquota -u $TSTUSR global curspace)
835 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
837 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
838 $MAX_IQ_TIME $DIR || error "set user grace time failed"
839 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
840 error "set user quota failed"
842 test_block_soft $TESTFILE $GRACE $LIMIT "u"
844 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
845 TESTFILE=$DIR/$tdir/$tfile-1
846 # make sure the system is clean
847 USED=$(getquota -g $TSTUSR global curspace)
848 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
850 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
851 $MAX_IQ_TIME $DIR || error "set group grace time failed"
852 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
853 error "set group quota failed"
855 test_block_soft $TESTFILE $GRACE $LIMIT "g"
857 if is_project_quota_supported; then
858 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
859 TESTFILE=$DIR/$tdir/$tfile-2
860 # make sure the system is clean
861 USED=$(getquota -p $TSTPRJID global curspace)
862 [ $USED -ne 0 ] && error \
863 "Used space($USED) for project $TSTPRJID isn't 0."
865 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
867 error "set project grace time failed"
868 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
869 $DIR || error "set project quota failed"
871 test_block_soft $TESTFILE $GRACE $LIMIT "p"
872 resetquota -p $TSTPRJID
873 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
875 error "restore project grace time failed"
879 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
880 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
881 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
882 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
884 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
893 trap cleanup_quota_test EXIT
894 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
896 echo "Create files to exceed soft limit"
897 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
898 quota_error a $TSTUSR "create failure, but expect success"
899 local trigger_time=$(date +%s)
901 sync_all_data || true
903 local cur_time=$(date +%s)
904 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
905 error "Passed grace time $grace, $trigger_time, $cur_time"
907 echo "Create file before timer goes off"
908 $RUNAS touch ${TESTFILE}_before ||
909 quota_error a $TSTUSR "failed create before timer expired," \
910 "but expect success. $trigger_time, $cur_time"
911 sync_all_data || true
913 wait_grace_time $qtype "file"
918 $SHOW_QUOTA_INFO_USER
919 $SHOW_QUOTA_INFO_GROUP
920 $SHOW_QUOTA_INFO_PROJID
922 echo "Create file after timer goes off"
923 # There is a window that space is accounted in the quota usage but
924 # hasn't been decreased from the pending write, if we acquire quota
925 # in this window, we'll acquire more than we needed.
926 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
927 sync_all_data || true
928 $RUNAS touch ${TESTFILE}_after_3 &&
929 quota_error a $TSTUSR "create after timer expired," \
931 sync_all_data || true
936 $SHOW_QUOTA_INFO_USER
937 $SHOW_QUOTA_INFO_GROUP
938 $SHOW_QUOTA_INFO_PROJID
940 echo "Unlink files to stop timer"
941 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
942 wait_delete_completed
945 $RUNAS touch ${TESTFILE}_xxx ||
946 quota_error a $TSTUSR "touch after timer stop failure," \
948 sync_all_data || true
956 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
957 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
958 local TESTFILE=$DIR/$tdir/$tfile-0
961 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
963 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
964 # make sure the system is clean
965 local USED=$(getquota -u $TSTUSR global curinodes)
966 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
968 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
969 $GRACE $DIR || error "set user grace time failed"
970 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
971 error "set user quota failed"
973 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
975 test_file_soft $TESTFILE $LIMIT $GRACE "u"
977 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
978 # make sure the system is clean
979 USED=$(getquota -g $TSTUSR global curinodes)
980 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
982 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
983 $GRACE $DIR || error "set group grace time failed"
984 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
985 error "set group quota failed"
986 TESTFILE=$DIR/$tdir/$tfile-1
988 test_file_soft $TESTFILE $LIMIT $GRACE "g"
990 if is_project_quota_supported; then
991 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
992 # make sure the system is clean
993 USED=$(getquota -p $TSTPRJID global curinodes)
994 [ $USED -ne 0 ] && error \
995 "Used space($USED) for project $TSTPRJID isn't 0."
997 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
998 $GRACE $DIR || error "set project grace time failed"
999 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
1000 error "set project quota failed"
1002 TESTFILE=$DIR/$tdir/$tfile-1
1003 # one less than limit, because of parent directory included.
1004 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1005 resetquota -p $TSTPRJID
1006 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1007 $MAX_IQ_TIME $DIR ||
1008 error "restore project grace time failed"
1012 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1013 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1014 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1015 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1017 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1020 local GR_STR1="1w3d"
1021 local GR_STR2="1000s"
1023 local GR_STR4="1w2d3h4m5s"
1025 local GR_STR6="18446744073709551615"
1028 wait_delete_completed
1030 # test of valid grace strings handling
1031 echo "Valid grace strings test"
1032 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1033 $GR_STR2 $DIR || error "set user grace time failed"
1034 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1035 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1036 $GR_STR4 $DIR || error "set group grace time quota failed"
1037 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1039 # test of invalid grace strings handling
1040 echo " Invalid grace strings test"
1041 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1042 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1043 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1047 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1048 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1049 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1050 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1052 run_test 4b "Grace time strings handling"
1054 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1056 local BLIMIT=10 # 10M
1057 local ILIMIT=10 # 10 inodes
1059 setup_quota_test || error "setup quota failed with $?"
1060 trap cleanup_quota_test EXIT
1062 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1063 set_ost_qtype $QTYPE || error "enable ost quota failed"
1065 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1066 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1067 error "set user quota failed"
1068 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1069 if is_project_quota_supported; then
1070 error "set group quota failed"
1071 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1072 -I $ILIMIT $DIR || error "set project quota failed"
1075 # make sure the system is clean
1076 local USED=$(getquota -u $TSTUSR global curinodes)
1077 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1078 USED=$(getquota -g $TSTUSR global curinodes)
1079 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1080 USED=$(getquota -u $TSTUSR global curspace)
1081 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1082 USED=$(getquota -g $TSTUSR global curspace)
1083 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1084 if is_project_quota_supported; then
1085 USED=$(getquota -p $TSTPRJID global curinodes)
1087 error "Used inode($USED) for project $TSTPRJID isn't 0."
1088 USED=$(getquota -p $TSTPRJID global curspace)
1090 error "Used block($USED) for project $TSTPRJID isn't 0."
1093 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1094 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1095 error "create failure, expect success"
1096 if is_project_quota_supported; then
1097 touch $DIR/$tdir/$tfile-0_1
1098 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1100 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1101 error "write failure, expect success"
1103 echo "Chown files to $TSTUSR.$TSTUSR ..."
1104 for i in $(seq 0 $ILIMIT); do
1105 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1106 quota_error a $TSTUSR "chown failure, expect success"
1110 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1111 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1114 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1116 # test dropping acquire request on master
1120 # Clear dmesg so watchdog is not triggered by previous
1122 do_facet ost1 dmesg -c > /dev/null
1124 setup_quota_test || error "setup quota failed with $?"
1125 trap cleanup_quota_test EXIT
1127 # make sure the system is clean
1128 local USED=$(getquota -u $TSTUSR global curspace)
1129 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1131 # make sure no granted quota on ost
1132 set_ost_qtype $QTYPE || error "enable ost quota failed"
1133 resetquota -u $TSTUSR
1135 # create file for $TSTUSR
1136 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1137 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1138 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1140 # create file for $TSTUSR2
1141 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1142 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1143 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1145 # cache per-ID lock for $TSTUSR on slave
1146 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1147 error "set quota failed"
1148 $RUNAS $DD of=$TESTFILE count=1 ||
1149 error "write $TESTFILE failure, expect success"
1150 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1151 error "write $TESTFILE2 failure, expect success"
1153 if at_is_enabled; then
1154 at_max_saved=$(at_max_get ost1)
1155 at_max_set $TIMEOUT ost1
1157 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1158 # DQACQ is sent, which makes at_max to take effect
1159 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1162 wait_delete_completed
1166 sync_all_data || true
1168 #define QUOTA_DQACQ 601
1169 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1170 lustre_fail mds 0x513 601
1172 do_facet ost1 $LCTL set_param \
1173 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1175 # write to un-enforced ID ($TSTUSR2) should succeed
1176 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1177 error "write failure, expect success"
1179 # write to enforced ID ($TSTUSR) in background, exceeding limit
1180 # to make sure DQACQ is sent
1181 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1184 # watchdog timer uses a factor of 2
1185 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1186 sleep $((TIMEOUT * 2 + 1))
1188 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1190 # write should be blocked and never finished
1191 if ! ps -p $DDPID > /dev/null 2>&1; then
1193 error "write finished incorrectly!"
1198 # no watchdog is triggered
1199 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1200 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1201 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1202 [ -z "$watchdog" ] || error "$watchdog"
1204 rm -f $TMP/lustre-log-${TESTNAME}.log
1206 # write should continue then fail with EDQUOT
1210 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1211 if [ $count -ge 240 ]; then
1212 quota_error u $TSTUSR "dd not finished in $count secs"
1214 count=$((count + 1))
1215 if [ $((count % 30)) -eq 0 ]; then
1216 c_size=$(stat -c %s $TESTFILE)
1217 echo "Waiting $count secs. $c_size"
1225 run_test 6 "Test dropping acquire request on master"
1227 # quota reintegration (global index)
1229 local TESTFILE=$DIR/$tdir/$tfile
1230 local LIMIT=20 # 20M
1232 [ "$SLOW" = "no" ] && LIMIT=5
1234 setup_quota_test || error "setup quota failed with $?"
1235 trap cleanup_quota_test EXIT
1237 # make sure the system is clean
1238 local USED=$(getquota -u $TSTUSR global curspace)
1239 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1241 # make sure no granted quota on ost1
1242 set_ost_qtype $QTYPE || error "enable ost quota failed"
1243 resetquota -u $TSTUSR
1244 set_ost_qtype "none" || error "disable ost quota failed"
1246 local OSTUUID=$(ostuuid_from_index 0)
1247 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1249 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1252 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1253 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1258 echo "Enable quota & set quota limit for $TSTUSR"
1259 set_ost_qtype $QTYPE || error "enable ost quota failed"
1260 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1261 error "set quota failed"
1263 echo "Start ost1..."
1264 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1267 wait_ost_reint $QTYPE || error "reintegration failed"
1269 # hardlimit should have been fetched by slave during global
1270 # reintegration, write will exceed quota
1271 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1272 quota_error u $TSTUSR "write success, but expect EDQUOT"
1275 wait_delete_completed
1276 sync_all_data || true
1282 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1283 error "clear quota failed"
1285 echo "Start ost1..."
1286 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1289 wait_ost_reint $QTYPE || error "reintegration failed"
1291 # hardlimit should be cleared on slave during reintegration
1292 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1293 quota_error u $TSTUSR "write error, but expect success"
1297 run_test 7a "Quota reintegration (global index)"
1299 # quota reintegration (slave index)
1302 local TESTFILE=$DIR/$tdir/$tfile
1304 setup_quota_test || error "setup quota failed with $?"
1305 trap cleanup_quota_test EXIT
1307 # make sure the system is clean
1308 local USED=$(getquota -u $TSTUSR global curspace)
1309 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1311 # make sure no granted quota on ost1
1312 set_ost_qtype $QTYPE || error "enable ost quota failed"
1313 resetquota -u $TSTUSR
1314 set_ost_qtype "none" || error "disable ost quota failed"
1316 local OSTUUID=$(ostuuid_from_index 0)
1317 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1319 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1322 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1323 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1325 # consume some space to make sure the granted space will not
1326 # be released during reconciliation
1327 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1328 error "consume space failure, expect success"
1330 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1331 lustre_fail mds 0xa02
1333 set_ost_qtype $QTYPE || error "enable ost quota failed"
1334 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1335 error "set quota failed"
1337 # ignore the write error
1338 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1340 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1344 echo "Restart ost to trigger reintegration..."
1346 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1349 wait_ost_reint $QTYPE || error "reintegration failed"
1351 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1352 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1357 run_test 7b "Quota reintegration (slave index)"
1359 # quota reintegration (restart mds during reintegration)
1361 local LIMIT=20 # 20M
1362 local TESTFILE=$DIR/$tdir/$tfile
1364 [ "$SLOW" = "no" ] && LIMIT=5
1366 setup_quota_test || error "setup quota failed with $?"
1367 trap cleanup_quota_test EXIT
1369 # make sure the system is clean
1370 local USED=$(getquota -u $TSTUSR global curspace)
1371 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1373 set_ost_qtype "none" || error "disable ost quota failed"
1374 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1375 error "set quota failed"
1377 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1378 lustre_fail ost 0xa03
1381 set_ost_qtype $QTYPE || error "enable ost quota failed"
1382 # trigger reintegration
1383 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1384 procf=${procf}quota_slave.force_reint
1385 do_facet ost1 $LCTL set_param $procf=1 ||
1386 error "force reintegration failed"
1394 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1397 # wait longer than usual to make sure the reintegration
1398 # is triggered by quota wb thread.
1399 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1401 # hardlimit should have been fetched by slave during global
1402 # reintegration, write will exceed quota
1403 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1404 quota_error u $TSTUSR "write success, but expect EDQUOT"
1408 run_test 7c "Quota reintegration (restart mds during reintegration)"
1410 # Quota reintegration (Transfer index in multiple bulks)
1412 local TESTFILE=$DIR/$tdir/$tfile
1413 local TESTFILE1="$DIR/$tdir/$tfile"-1
1416 setup_quota_test || error "setup quota failed with $?"
1417 trap cleanup_quota_test EXIT
1419 set_ost_qtype "none" || error "disable ost quota failed"
1420 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1421 error "set quota for $TSTUSR failed"
1422 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1423 error "set quota for $TSTUSR2 failed"
1425 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1426 lustre_fail mds 0x608 0
1428 # enable quota to tirgger reintegration
1429 set_ost_qtype "u" || error "enable ost quota failed"
1430 wait_ost_reint "u" || error "reintegration failed"
1434 # hardlimit should have been fetched by slave during global
1435 # reintegration, write will exceed quota
1436 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1437 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1439 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1440 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1444 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1446 # quota reintegration (inode limits)
1448 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1450 # LU-2435: skip this quota test if underlying zfs version has not
1451 # supported native dnode accounting
1452 [ "$mds1_FSTYPE" == zfs ] && {
1453 local F="feature@userobj_accounting"
1454 local pool=$(zpool_name mds1)
1455 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1457 [[ "$feature" != *" active "* ]] &&
1458 skip "requires zpool with active userobj_accounting"
1461 local ilimit=$((1024 * 2)) # 2k inodes
1462 local TESTFILE=$DIR/${tdir}-1/$tfile
1464 setup_quota_test || error "setup quota failed with $?"
1465 trap cleanup_quota_test EXIT
1467 # make sure the system is clean
1468 local USED=$(getquota -u $TSTUSR global curinodes)
1469 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1471 # make sure no granted quota on mdt1
1472 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1473 resetquota -u $TSTUSR
1474 set_mdt_qtype "none" || error "disable mdt quota failed"
1476 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1477 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1478 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1481 echo "Stop mds${MDSCOUNT}..."
1484 echo "Enable quota & set quota limit for $TSTUSR"
1485 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1486 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1487 error "set quota failed"
1489 echo "Start mds${MDSCOUNT}..."
1490 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1493 wait_mdt_reint $QTYPE || error "reintegration failed"
1495 echo "create remote dir"
1496 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1497 error "create remote dir failed"
1498 chmod 0777 $DIR/${tdir}-1
1500 # hardlimit should have been fetched by slave during global
1501 # reintegration, create will exceed quota
1502 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1503 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1505 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1506 wait_delete_completed
1507 sync_all_data || true
1509 echo "Stop mds${MDSCOUNT}..."
1512 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1513 error "clear quota failed"
1515 echo "Start mds${MDSCOUNT}..."
1516 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1519 wait_mdt_reint $QTYPE || error "reintegration failed"
1521 # hardlimit should be cleared on slave during reintegration
1522 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1523 quota_error u $TSTUSR "create failed, expect success"
1525 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1526 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1530 run_test 7e "Quota reintegration (inode limits)"
1532 # run dbench with quota enabled
1534 local BLK_LIMIT="100g" #100G
1535 local FILE_LIMIT=1000000
1537 setup_quota_test || error "setup quota failed with $?"
1538 trap cleanup_quota_test EXIT
1540 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1541 set_ost_qtype $QTYPE || error "enable ost quota failed"
1543 echo "Set enough high limit for user: $TSTUSR"
1544 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1545 error "set user quota failed"
1546 echo "Set enough high limit for group: $TSTUSR"
1547 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1548 error "set group quota failed"
1549 if is_project_quota_supported; then
1550 change_project -sp $TSTPRJID $DIR/$tdir
1551 echo "Set enough high limit for project: $TSTPRJID"
1552 $LFS setquota -p $TSTPRJID -b 0 \
1553 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1554 error "set project quota failed"
1558 [ "$SLOW" = "no" ] && duration=" -t 120"
1559 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1560 quota_error a $TSTUSR "dbench failed!"
1562 is_project_quota_supported && change_project -C $DIR/$tdir
1565 run_test 8 "Run dbench with quota enabled"
1567 # this check is just for test_9
1568 OST0_MIN=4900000 #4.67G
1570 check_whether_skip () {
1571 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1572 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1573 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1574 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1581 # run for fixing bug10707, it needs a big room. test for 64bit
1583 local filesize=$((1024 * 9 / 2)) # 4.5G
1585 check_whether_skip && return 0
1587 setup_quota_test || error "setup quota failed with $?"
1588 trap cleanup_quota_test EXIT
1590 set_ost_qtype "ug" || error "enable ost quota failed"
1592 local TESTFILE="$DIR/$tdir/$tfile-0"
1593 local BLK_LIMIT=100G #100G
1594 local FILE_LIMIT=1000000
1596 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1598 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1600 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1601 error "set user quota failed"
1603 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1604 "for group: $TSTUSR"
1605 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1606 error "set group quota failed"
1608 quota_show_check a u $TSTUSR
1609 quota_show_check a g $TSTUSR
1611 echo "Create test file"
1612 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1613 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1615 log "Write the big file of 4.5G ..."
1616 $RUNAS $DD of=$TESTFILE count=$filesize ||
1617 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1627 run_test 9 "Block limit larger than 4GB (b10707)"
1630 local TESTFILE=$DIR/$tdir/$tfile
1632 setup_quota_test || error "setup quota failed with $?"
1633 trap cleanup_quota_test EXIT
1635 # set limit to root user should fail
1636 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1637 error "set limit for root user successfully, expect failure"
1638 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1639 error "set limit for root group successfully, expect failure"
1640 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1641 error "set limit for project 0 successfully, expect failure"
1643 # root user can overrun quota
1644 set_ost_qtype "ug" || error "enable ost quota failed"
1646 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1647 error "set quota failed"
1648 quota_show_check b u $TSTUSR
1650 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1651 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1653 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1654 error "write failure, expect success"
1658 run_test 10 "Test quota for root user"
1661 local TESTFILE=$DIR/$tdir/$tfile
1662 setup_quota_test || error "setup quota failed with $?"
1663 trap cleanup_quota_test EXIT
1665 set_mdt_qtype "ug" || error "enable mdt quota failed"
1666 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1667 error "set quota failed"
1669 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1670 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1672 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1673 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1676 local USED=$(getquota -u $TSTUSR global curinodes)
1677 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1681 run_test 11 "Chown/chgrp ignores quota"
1684 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1686 local blimit=22 # 22M
1687 local blk_cnt=$((blimit - 5))
1688 local TESTFILE0="$DIR/$tdir/$tfile"-0
1689 local TESTFILE1="$DIR/$tdir/$tfile"-1
1691 setup_quota_test || error "setup quota failed with $?"
1692 trap cleanup_quota_test EXIT
1694 set_ost_qtype "u" || error "enable ost quota failed"
1695 quota_show_check b u $TSTUSR
1697 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1698 error "set quota failed"
1700 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1701 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1702 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1703 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1705 echo "Write to ost0..."
1706 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1707 quota_error a $TSTUSR "dd failed"
1709 echo "Write to ost1..."
1710 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1711 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1713 echo "Free space from ost0..."
1715 wait_delete_completed
1716 sync_all_data || true
1718 echo "Write to ost1 after space freed from ost0..."
1719 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1720 quota_error a $TSTUSR "rebalancing failed"
1724 run_test 12a "Block quota rebalancing"
1727 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1729 local ilimit=$((1024 * 2)) # 2k inodes
1730 local TESTFILE0=$DIR/$tdir/$tfile
1731 local TESTFILE1=$DIR/${tdir}-1/$tfile
1733 setup_quota_test || error "setup quota failed with $?"
1734 trap cleanup_quota_test EXIT
1736 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1737 chmod 0777 $DIR/${tdir}-1
1739 set_mdt_qtype "u" || error "enable mdt quota failed"
1740 quota_show_check f u $TSTUSR
1742 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1743 error "set quota failed"
1745 echo "Create $ilimit files on mdt0..."
1746 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1747 quota_error u $TSTUSR "create failed, but expect success"
1749 echo "Create files on mdt1..."
1750 $RUNAS createmany -m $TESTFILE1 1 &&
1751 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1753 echo "Free space from mdt0..."
1754 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1755 wait_delete_completed
1756 sync_all_data || true
1758 echo "Create files on mdt1 after space freed from mdt0..."
1759 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1760 quota_error a $TSTUSR "rebalancing failed"
1762 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1763 error "unlink mdt1 files failed"
1764 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1768 run_test 12b "Inode quota rebalancing"
1771 local TESTFILE=$DIR/$tdir/$tfile
1772 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1773 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1775 setup_quota_test || error "setup quota failed with $?"
1776 trap cleanup_quota_test EXIT
1778 set_ost_qtype "u" || error "enable ost quota failed"
1779 quota_show_check b u $TSTUSR
1781 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1782 error "set quota failed"
1783 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1784 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1786 # clear the locks in cache first
1787 do_facet ost1 $LCTL set_param -n $procf=clear
1788 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1789 [ $nlock -eq 0 ] || error "$nlock cached locks"
1791 # write to acquire the per-ID lock
1792 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1793 quota_error a $TSTUSR "dd failed"
1795 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1796 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1798 # clear quota doesn't trigger per-ID lock cancellation
1799 resetquota -u $TSTUSR
1800 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1801 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1803 # clear the per-ID lock
1804 do_facet ost1 $LCTL set_param -n $procf=clear
1805 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1806 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1808 # spare quota should be released
1809 local OSTUUID=$(ostuuid_from_index 0)
1810 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1811 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1812 [ $limit -le $space ] ||
1813 error "spare quota isn't released, limit:$limit, space:$space"
1817 run_test 13 "Cancel per-ID lock in the LRU list"
1820 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1822 wait_delete_completed
1823 sync_all_data || true
1826 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1827 error "set user quota failed"
1828 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1829 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1830 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1831 resetquota -u $TSTUSR
1834 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1835 error "set group quota failed"
1836 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1837 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1838 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1839 resetquota -g $TSTUSR
1841 run_test 15 "Set over 4T block quota"
1845 local BLKS=1 # 1M less than limit
1846 local TESTFILE=$DIR/$tdir/$tfile
1848 setup_quota_test || error "setup quota failed with $?"
1849 trap cleanup_quota_test EXIT
1851 # make sure the system is clean
1852 local USED=$(getquota -u $TSTUSR global curspace)
1853 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1855 set_ost_qtype "ug" || error "enable ost quota failed"
1856 # make sure no granted quota on ost
1857 resetquota -u $TSTUSR
1858 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1859 error "set quota failed"
1861 quota_show_check b u $TSTUSR
1863 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1864 lustre_fail mds 0xa04 $err_code
1866 # write in background
1867 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1871 # write should be blocked and never finished
1872 if ! ps -p $DDPID > /dev/null 2>&1; then
1874 quota_error u $TSTUSR "write finished incorrectly!"
1882 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1884 if [ $count -gt $timeout ]; then
1885 quota_error u $TSTUSR "dd is not finished!"
1890 sync; sync_all_data || true
1892 USED=$(getquota -u $TSTUSR global curspace)
1893 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1894 "Used space(${USED}K) is less than ${BLKS}M"
1899 # DQACQ return recoverable error
1901 echo "DQACQ return -ENOLCK"
1903 test_17sub 37 || error "Handle -ENOLCK failed"
1905 echo "DQACQ return -EAGAIN"
1907 test_17sub 11 || error "Handle -EAGAIN failed"
1909 echo "DQACQ return -ETIMEDOUT"
1910 #define ETIMEDOUT 110
1911 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1913 echo "DQACQ return -ENOTCONN"
1914 #define ENOTCONN 107
1915 test_17sub 107 || error "Handle -ENOTCONN failed"
1918 run_test 17 "DQACQ return recoverable error"
1922 local blimit="200m" # 200M
1923 local TESTFILE="$DIR/$tdir/$tfile"
1925 setup_quota_test || error "setup quota failed with $?"
1926 trap cleanup_quota_test EXIT
1928 set_ost_qtype "u" || error "enable ost quota failed"
1929 log "User quota (limit: $blimit)"
1930 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1931 error "set quota failed"
1932 quota_show_check b u $TSTUSR
1934 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1935 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1937 local timeout=$(sysctl -n lustre.timeout)
1939 if [ $io_type = "directio" ]; then
1940 log "Write 100M (directio) ..."
1941 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1943 log "Write 100M (buffered) ..."
1944 $RUNAS $DD of=$TESTFILE count=100 &
1948 replay_barrier $SINGLEMDS
1949 log "Fail mds for $((2 * timeout)) seconds"
1950 fail $SINGLEMDS $((2 * timeout))
1953 if at_is_enabled; then
1954 timeout=$(at_max_get mds)
1956 timeout=$(lctl get_param -n timeout)
1960 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1961 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1962 log "it took $count second"
1967 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1969 cancel_lru_locks mdc
1970 cancel_lru_locks osc
1973 local testfile_size=$(stat -c %s $TESTFILE)
1974 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1975 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1976 "got ${testfile_size}. Verifying file failed!"
1981 # test when mds does failover, the ost still could work well
1982 # this test shouldn't trigger watchdog b=14840
1984 # Clear dmesg so watchdog is not triggered by previous
1986 do_facet ost1 dmesg -c > /dev/null
1989 test_18_sub directio
1991 # check if watchdog is triggered
1992 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1993 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1994 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1995 [ -z "$watchdog" ] || error "$watchdog"
1996 rm -f $TMP/lustre-log-${TESTNAME}.log
1998 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2002 local TESTFILE=$DIR/$tdir/$tfile
2004 setup_quota_test || error "setup quota failed with $?"
2005 trap cleanup_quota_test EXIT
2007 set_ost_qtype $QTYPE || error "enable ost quota failed"
2009 # bind file to a single OST
2010 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2011 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2013 echo "Set user quota (limit: ${blimit}M)"
2014 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2015 error "set user quota failed"
2016 quota_show_check b u $TSTUSR
2017 echo "Update quota limits"
2018 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2019 error "set group quota failed"
2020 quota_show_check b u $TSTUSR
2022 # first wirte might be cached
2023 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2024 cancel_lru_locks osc
2026 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2027 quota_error u $TSTUSR "Write success, expect failure"
2032 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2034 test_20() { # b15754
2035 local LSTR=(2g 1t 4k 3m) # limits strings
2037 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2040 resetquota -u $TSTUSR
2042 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2043 $MOUNT || error "could not set quota limits"
2044 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2045 --inode-softlimit ${LSTR[2]} \
2046 --inode-hardlimit ${LSTR[3]} \
2047 $MOUNT || error "could not set quota limits"
2049 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2050 error "bsoftlimit was not set properly"
2051 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2052 error "bhardlimit was not set properly"
2053 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2054 error "isoftlimit was not set properly"
2055 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2056 error "ihardlimit was not set properly"
2058 resetquota -u $TSTUSR
2060 run_test 20 "Test if setquota specifiers work properly (b15754)"
2067 local time=$(($(date +%s) + seconds))
2068 while [ $(date +%s) -lt $time ]; do
2069 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2073 # run for fixing bug16053, setquota shouldn't fail when writing and
2074 # deleting are happening
2076 local TESTFILE="$DIR/$tdir/$tfile"
2077 local BLIMIT=10 # 10G
2078 local ILIMIT=1000000
2080 setup_quota_test || error "setup quota failed with $?"
2081 trap cleanup_quota_test EXIT
2083 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2085 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2086 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2087 error "set user quota failed"
2088 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2089 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2090 error "set group quota failed"
2091 if is_project_quota_supported; then
2092 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2093 "project: $TSTPRJID"
2094 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2095 $MOUNT || error "set project quota failed"
2098 # repeat writing on a 1M file
2099 test_21_sub ${TESTFILE}_1 1 30 &
2101 # repeat writing on a 128M file
2102 test_21_sub ${TESTFILE}_2 128 30 &
2105 local time=$(($(date +%s) + 30))
2107 while [ $(date +%s) -lt $time ]; do
2108 log "Set quota for $i times"
2109 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2110 -I $((ILIMIT + i)) $MOUNT ||
2111 error "Set user quota failed"
2112 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2113 -I $((ILIMIT + i)) $MOUNT ||
2114 error "Set group quota failed"
2115 if is_project_quota_supported; then
2116 $LFS setquota -p $TSTPRJID -b 0 -B \
2117 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2118 error "Set project quota failed"
2126 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2128 if [ $count -gt 60 ]; then
2129 quota_error a $TSTUSR "dd should be finished!"
2133 echo "(dd_pid=$DDPID1, time=$count)successful"
2137 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2139 if [ $count -gt 60 ]; then
2140 quota_error a $TSTUSR "dd should be finished!"
2144 echo "(dd_pid=$DDPID2, time=$count)successful"
2148 run_test 21 "Setquota while writing & deleting (b16053)"
2150 # enable/disable quota enforcement permanently
2152 echo "Set both mdt & ost quota type as ug"
2154 is_project_quota_supported && qtype=$QTYPE
2155 set_mdt_qtype $qtype || error "enable mdt quota failed"
2156 set_ost_qtype $qtype || error "enable ost quota failed"
2159 stopall || error "failed to stopall (1)"
2163 echo "Verify if quota is enabled"
2164 local qtype1=$(mdt_quota_type)
2165 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2166 qtype=$(ost_quota_type)
2167 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2169 echo "Set both mdt & ost quota type as none"
2170 set_mdt_qtype "none" || error "disable mdt quota failed"
2171 set_ost_qtype "none" || error "disable ost quota failed"
2174 stopall || error "failed to stopall (2)"
2179 echo "Verify if quota is disabled"
2180 qtype=$(mdt_quota_type)
2181 [ $qtype != "none" ] && error "mdt quota setting is lost"
2182 qtype=$(ost_quota_type)
2183 [ $qtype != "none" ] && error "ost quota setting is lost"
2187 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2190 local TESTFILE="$DIR/$tdir/$tfile"
2193 setup_quota_test || error "setup quota failed with $?"
2194 trap cleanup_quota_test EXIT
2196 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2199 log "User quota (limit: $LIMIT MB)"
2200 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2201 error "set quota failed"
2202 quota_show_check b u $TSTUSR
2204 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2205 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2207 log "Step1: trigger EDQUOT with O_DIRECT"
2208 log "Write half of file"
2209 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2210 quota_error u $TSTUSR "(1) Write failure, expect success." \
2212 log "Write out of block quota ..."
2213 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2214 oflag=direct conv=notrunc &&
2215 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2219 log "Step2: rewrite should succeed"
2220 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2221 quota_error u $TSTUSR "(3) Write failure, expect success." \
2227 local OST0_UUID=$(ostuuid_from_index 0)
2228 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2229 [ $OST0_QUOTA_USED -ne 0 ] &&
2230 ($SHOW_QUOTA_USER; \
2231 quota_error u $TSTUSR "quota isn't released")
2236 [ "$ost1_FSTYPE" == zfs ] &&
2237 skip "Overwrite in place is not guaranteed to be " \
2238 "space neutral on ZFS"
2240 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2241 check_whether_skip && return 0
2242 log "run for 4MB test file"
2245 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2246 check_whether_skip && return 0
2247 log "run for 40MB test file"
2250 run_test 23 "Quota should be honored with directIO (b16125)"
2254 local TESTFILE="$DIR/$tdir/$tfile"
2256 setup_quota_test || error "setup quota failed with $?"
2257 trap cleanup_quota_test EXIT
2259 set_ost_qtype $QTYPE || error "enable ost quota failed"
2261 # bind file to a single OST
2262 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2263 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2265 echo "Set user quota (limit: ${blimit}M)"
2266 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2267 error "set quota failed"
2269 # overrun quota by root user
2270 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2271 error "write failure, expect success"
2272 cancel_lru_locks osc
2273 sync_all_data || true
2275 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2279 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2281 test_27a() { # b19612
2282 $LFS quota $TSTUSR $DIR &&
2283 error "lfs succeeded with no type, but should have failed"
2284 $LFS setquota $TSTUSR $DIR &&
2285 error "lfs succeeded with no type, but should have failed"
2288 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2290 test_27b() { # b20200
2291 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2292 error "lfs setquota failed with uid argument"
2293 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2294 error "lfs stequota failed with gid argument"
2295 if is_project_quota_supported; then
2296 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2297 1000 $DIR || error \
2298 "lfs stequota failed with projid argument"
2300 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2301 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2302 if is_project_quota_supported; then
2303 $SHOW_QUOTA_PROJID ||
2304 error "lfs quota failed with projid argument"
2306 resetquota -u $TSTID
2307 resetquota -g $TSTID
2308 resetquota -p $TSTPRJID
2311 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2316 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2317 error "lfs setquota failed"
2319 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2320 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2321 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2322 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2324 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2325 error "lfs setquota for $TSTID failed"
2327 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2328 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2329 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2330 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2332 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2333 error "total allocated inode/block limit not printed"
2335 resetquota -u $TSTUSR
2337 run_test 27c "lfs quota should support human-readable output"
2344 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2345 error "set fraction block limit failed"
2346 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2347 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2348 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2349 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2351 resetquota -u $TSTUSR
2353 run_test 27d "lfs setquota should support fraction block limit"
2357 local TESTFILE="$DIR/$tdir/$tfile"
2360 setup_quota_test || error "setup quota failed with $?"
2361 trap cleanup_quota_test EXIT
2363 set_ost_qtype "u" || error "enable ost quota failed"
2365 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2366 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2368 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2369 $MAX_IQ_TIME $DIR || error "set grace time failed"
2370 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2371 error "set quota failed"
2372 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2373 cancel_lru_locks osc
2375 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2376 # over-quota flag has not yet settled since we do not trigger async
2377 # events based on grace time period expiration
2379 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2380 cancel_lru_locks osc
2381 # now over-quota flag should be settled and further writes should fail
2383 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2384 error "grace times were reset"
2387 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2388 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2390 run_test 30 "Hard limit updates should not reset grace times"
2392 # basic usage tracking for user & group
2394 local INODES=10 # 10 files
2395 local BLK_CNT=2 # of 2M each
2396 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2398 setup_quota_test || error "setup quota failed with $?"
2399 trap cleanup_quota_test EXIT
2401 # make sure the system is clean
2402 local USED=$(getquota -u $TSTID global curspace)
2404 error "Used space ($USED) for user $TSTID isn't 0."
2405 USED=$(getquota -g $TSTID global curspace)
2407 error "Used space ($USED) for group $TSTID isn't 0."
2408 if is_project_quota_supported; then
2409 USED=$(getquota -p $TSTPRJID global curspace)
2410 [ $USED -ne 0 ] && error \
2411 "Used space ($USED) for project $TSTPRJID isn't 0."
2414 echo "Write files..."
2415 for i in $(seq 0 $INODES); do
2416 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2417 error "write failed"
2418 is_project_quota_supported &&
2419 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2420 echo "Iteration $i/$INODES completed"
2422 cancel_lru_locks osc
2424 echo "Wait for setattr on objects finished..."
2425 wait_delete_completed
2427 sync; sync_all_data || true
2429 echo "Verify disk usage after write"
2430 USED=$(getquota -u $TSTID global curspace)
2431 [ $USED -lt $TOTAL_BLKS ] &&
2432 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2433 USED=$(getquota -g $TSTID global curspace)
2434 [ $USED -lt $TOTAL_BLKS ] &&
2435 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2436 if is_project_quota_supported; then
2437 USED=$(getquota -p $TSTPRJID global curspace)
2438 [ $USED -lt $TOTAL_BLKS ] && error \
2439 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2442 echo "Verify inode usage after write"
2443 USED=$(getquota -u $TSTID global curinodes)
2444 [ $USED -lt $INODES ] &&
2445 error "Used inode for user $TSTID is $USED, expected $INODES"
2446 USED=$(getquota -g $TSTID global curinodes)
2447 [ $USED -lt $INODES ] &&
2448 error "Used inode for group $TSTID is $USED, expected $INODES"
2449 if is_project_quota_supported; then
2450 USED=$(getquota -p $TSTPRJID global curinodes)
2451 [ $USED -lt $INODES ] && error \
2452 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2457 echo "Verify disk usage after delete"
2458 USED=$(getquota -u $TSTID global curspace)
2459 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2460 USED=$(getquota -u $TSTID global curinodes)
2461 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2462 USED=$(getquota -g $TSTID global curspace)
2463 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2464 USED=$(getquota -g $TSTID global curinodes)
2465 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2466 if is_project_quota_supported; then
2467 USED=$(getquota -p $TSTPRJID global curspace)
2469 error "Used space for project $TSTPRJID isn't 0. $USED"
2470 USED=$(getquota -p $TSTPRJID global curinodes)
2472 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2475 run_test 33 "Basic usage tracking for user & group & project"
2477 # usage transfer test for user & group & project
2479 local BLK_CNT=2 # 2MB
2480 local project_supported="no"
2482 is_project_quota_supported && project_supported="yes"
2483 setup_quota_test || error "setup quota failed with $?"
2484 trap cleanup_quota_test EXIT
2486 # make sure the system is clean
2487 local USED=$(getquota -u $TSTID global curspace)
2488 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2489 USED=$(getquota -g $TSTID global curspace)
2490 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2492 local USED=$(getquota -u $TSTID2 global curspace)
2493 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2494 if [ $project_supported == "yes" ]; then
2495 USED=$(getquota -p $TSTPRJID global curspace)
2496 [ $USED -ne 0 ] && error \
2497 "Used space ($USED) for Project $TSTPRJID isn't 0."
2500 echo "Write file..."
2501 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2502 error "write failed"
2503 cancel_lru_locks osc
2504 sync; sync_all_data || true
2506 echo "chown the file to user $TSTID"
2507 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2509 echo "Wait for setattr on objects finished..."
2510 wait_delete_completed
2512 BLK_CNT=$((BLK_CNT * 1024))
2514 echo "Verify disk usage for user $TSTID"
2515 USED=$(getquota -u $TSTID global curspace)
2516 [ $USED -lt $BLK_CNT ] &&
2517 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2518 USED=$(getquota -u $TSTID global curinodes)
2520 error "Used inodes for user $TSTID is $USED, expected 1"
2522 echo "chgrp the file to group $TSTID"
2523 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2525 echo "Wait for setattr on objects finished..."
2526 wait_delete_completed
2528 echo "Verify disk usage for group $TSTID"
2529 USED=$(getquota -g $TSTID global curspace)
2530 [ $USED -ge $BLK_CNT ] ||
2531 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2532 USED=$(getquota -g $TSTID global curinodes)
2534 error "Used inodes for group $TSTID is $USED, expected 1"
2536 # chown won't change the ost object group. LU-4345 */
2537 echo "chown the file to user $TSTID2"
2538 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2540 echo "Wait for setattr on objects finished..."
2541 wait_delete_completed
2543 echo "change_project project id to $TSTPRJID"
2544 [ $project_supported == "yes" ] &&
2545 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2546 echo "Wait for setattr on objects finished..."
2547 wait_delete_completed
2549 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2550 USED=$(getquota -u $TSTID2 global curspace)
2551 [ $USED -lt $BLK_CNT ] &&
2552 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2553 USED=$(getquota -u $TSTID global curspace)
2555 error "Used space for user $TSTID is $USED, expected 0"
2556 USED=$(getquota -g $TSTID global curspace)
2557 [ $USED -lt $BLK_CNT ] &&
2558 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2559 if [ $project_supported == "yes" ]; then
2560 USED=$(getquota -p $TSTPRJID global curspace)
2561 [ $USED -lt $BLK_CNT ] && error \
2562 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2567 run_test 34 "Usage transfer for user & group & project"
2569 # usage is still accessible across restart
2571 local BLK_CNT=2 # 2 MB
2573 setup_quota_test || error "setup quota failed with $?"
2574 trap cleanup_quota_test EXIT
2576 echo "Write file..."
2577 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2578 error "write failed"
2579 is_project_quota_supported &&
2580 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2581 cancel_lru_locks osc
2583 echo "Wait for setattr on objects finished..."
2584 wait_delete_completed
2586 sync; sync_all_data || true
2588 echo "Save disk usage before restart"
2589 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2590 [ $ORIG_USR_SPACE -eq 0 ] &&
2591 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2592 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2593 [ $ORIG_USR_INODES -eq 0 ] &&
2594 error "Used inodes for user $TSTID is 0, expected 1"
2595 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2596 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2597 [ $ORIG_GRP_SPACE -eq 0 ] &&
2598 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2599 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2600 [ $ORIG_GRP_INODES -eq 0 ] &&
2601 error "Used inodes for group $TSTID is 0, expected 1"
2602 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2604 if is_project_quota_supported; then
2605 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2606 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2607 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2608 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2609 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2610 "Used inodes for project $TSTPRJID is 0, expected 1"
2611 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2619 echo "Verify disk usage after restart"
2620 local USED=$(getquota -u $TSTID global curspace)
2621 [ $USED -eq $ORIG_USR_SPACE ] ||
2622 error "Used space for user $TSTID changed from " \
2623 "$ORIG_USR_SPACE to $USED"
2624 USED=$(getquota -u $TSTID global curinodes)
2625 [ $USED -eq $ORIG_USR_INODES ] ||
2626 error "Used inodes for user $TSTID changed from " \
2627 "$ORIG_USR_INODES to $USED"
2628 USED=$(getquota -g $TSTID global curspace)
2629 [ $USED -eq $ORIG_GRP_SPACE ] ||
2630 error "Used space for group $TSTID changed from " \
2631 "$ORIG_GRP_SPACE to $USED"
2632 USED=$(getquota -g $TSTID global curinodes)
2633 [ $USED -eq $ORIG_GRP_INODES ] ||
2634 error "Used inodes for group $TSTID changed from " \
2635 "$ORIG_GRP_INODES to $USED"
2636 if [ $project_supported == "yes" ]; then
2637 USED=$(getquota -p $TSTPRJID global curinodes)
2638 [ $USED -eq $ORIG_PRJ_INODES ] ||
2639 error "Used inodes for project $TSTPRJID " \
2640 "changed from $ORIG_PRJ_INODES to $USED"
2641 USED=$(getquota -p $TSTPRJID global curspace)
2642 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2643 error "Used space for project $TSTPRJID "\
2644 "changed from $ORIG_PRJ_SPACE to $USED"
2647 # check if the vfs_dq_init() is called before writing
2648 echo "Append to the same file..."
2649 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2650 error "write failed"
2651 cancel_lru_locks osc
2652 sync; sync_all_data || true
2654 echo "Verify space usage is increased"
2655 USED=$(getquota -u $TSTID global curspace)
2656 [ $USED -gt $ORIG_USR_SPACE ] ||
2657 error "Used space for user $TSTID isn't increased" \
2658 "orig:$ORIG_USR_SPACE, now:$USED"
2659 USED=$(getquota -g $TSTID global curspace)
2660 [ $USED -gt $ORIG_GRP_SPACE ] ||
2661 error "Used space for group $TSTID isn't increased" \
2662 "orig:$ORIG_GRP_SPACE, now:$USED"
2663 if [ $project_supported == "yes" ]; then
2664 USED=$(getquota -p $TSTPRJID global curspace)
2665 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2666 error "Used space for project $TSTPRJID isn't " \
2667 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2672 run_test 35 "Usage is still accessible across reboot"
2674 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2677 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2678 skip "Old server doesn't have LU-5006 fix."
2680 setup_quota_test || error "setup quota failed with $?"
2681 trap cleanup_quota_test EXIT
2683 # make sure the system is clean
2684 local USED=$(getquota -u $TSTID global curspace)
2686 error "Used space ($USED) for user $TSTID isn't 0."
2688 # create file with MDS_OPEN_DELAY_CREATE flag
2689 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2690 error "Create file failed"
2692 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2693 oflag=sync || error "Write file failed"
2695 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2697 # wait for setattr on objects finished..."
2698 wait_delete_completed
2700 USED=$(getquota -u $TSTID global curspace)
2701 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2705 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2709 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2710 skip "Old server doesn't have LU-8801 fix."
2712 [ "$UID" != 0 ] && skip_env "must run as root" && return
2714 setup_quota_test || error "setup quota failed with $?"
2715 trap cleanup_quota_test EXIT
2717 # make sure the system is clean
2718 local USED=$(getquota -u $TSTID global curspace)
2720 error "Used space ($USED) for user $TSTID isn't 0."
2721 USED=$(getquota -u $TSTID2 global curspace)
2723 error "Used space ($USED) for user $TSTID2 isn't 0."
2725 local TESTFILE="$DIR/$tdir/$tfile"
2726 local file_cnt=10000
2728 # Generate id entries in accounting file
2729 echo "Create $file_cnt files..."
2730 for i in `seq $file_cnt`; do
2732 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2733 error "failed to chown $TESTFILE-$i"
2735 cancel_lru_locks osc
2736 sync; sync_all_data || true
2738 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2739 procf=${procf}.quota_slave.acct_user
2742 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2743 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2744 echo "Found $acct_cnt id entries"
2746 [ $file_cnt -eq $acct_cnt ] || {
2747 do_facet mds1 $LCTL get_param $procf
2748 error "skipped id entries"
2753 run_test 38 "Quota accounting iterator doesn't skip id entries"
2756 local TESTFILE="$DIR/$tdir/project"
2757 ! is_project_quota_supported &&
2758 skip "Project quota is not supported"
2760 setup_quota_test || error "setup quota failed with $?"
2763 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2764 [ $projectid -ne 0 ] &&
2765 error "Project id should be 0 not $projectid"
2766 change_project -p 1024 $TESTFILE
2767 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2768 [ $projectid -ne 1024 ] &&
2769 error "Project id should be 1024 not $projectid"
2771 stopall || error "failed to stopall (1)"
2774 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2775 [ $projectid -ne 1024 ] &&
2776 error "Project id should be 1024 not $projectid"
2780 run_test 39 "Project ID interface works correctly"
2783 ! is_project_quota_supported &&
2784 skip "Project quota is not supported"
2785 local dir1="$DIR/$tdir/dir1"
2786 local dir2="$DIR/$tdir/dir2"
2788 setup_quota_test || error "setup quota failed with $?"
2790 mkdir -p $dir1 $dir2
2791 change_project -sp 1 $dir1 && touch $dir1/1
2792 change_project -sp 2 $dir2
2794 ln $dir1/1 $dir2/1_link &&
2795 error "Hard link across different project quota should fail"
2800 run_test 40a "Hard link across different project ID"
2803 ! is_project_quota_supported &&
2804 skip "Project quota is not supported"
2805 local dir1="$DIR/$tdir/dir1"
2806 local dir2="$DIR/$tdir/dir2"
2808 setup_quota_test || error "setup quota failed with $?"
2809 mkdir -p $dir1 $dir2
2810 change_project -sp 1 $dir1 && touch $dir1/1
2811 change_project -sp 2 $dir2
2813 mv $dir1/1 $dir2/2 || error "mv failed $?"
2814 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2815 if [ "$projid" != "2" ]; then
2816 error "project id expected 2 not $projid"
2821 run_test 40b "Mv across different project ID"
2824 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2825 ! is_project_quota_supported &&
2826 skip "Project quota is not supported"
2828 setup_quota_test || error "setup quota failed with $?"
2829 local dir="$DIR/$tdir/dir"
2831 mkdir -p $dir && change_project -sp 1 $dir
2832 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2833 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2834 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2835 touch $dir/remote_dir/file
2836 #verify inherit works file for remote dir.
2837 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2838 [ "$projid" != "1" ] &&
2839 error "file under remote dir expected 1 not $projid"
2841 #Agent inode should be ignored for project quota
2842 USED=$(getquota -p 1 global curinodes)
2843 [ "$USED" != "3" ] &&
2844 error "file count expected 3 got $USED"
2850 run_test 40c "Remote child Dir inherit project quota properly"
2853 ! is_project_quota_supported &&
2854 skip "Project quota is not supported"
2856 setup_quota_test || error "setup quota failed with $?"
2857 local dir1="$DIR/$tdir/dir1"
2858 local dir2="$DIR/$tdir/dir2"
2860 mkdir -p $dir1 && change_project -sp 1 $dir1
2861 mkdir -p $dir2 && change_project -sp 2 $dir2
2862 for num in $(seq 1 10); do
2863 touch $dir1/file_$num $dir2/file_$num
2864 ln -s $dir1/file_$num $dir1/file_$num"_link"
2865 ln -s $dir2/file_$num $dir2/file_$num"_link"
2868 count=$($LFS find --projid 1 $DIR | wc -l)
2869 [ "$count" != 21 ] && error "expected 21 but got $count"
2871 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2872 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2873 [ "$count" != 22 ] && error "expected 22 but got $count"
2878 run_test 50 "Test if lfs find --projid works"
2881 ! is_project_quota_supported &&
2882 skip "Project quota is not supported"
2883 setup_quota_test || error "setup quota failed with $?"
2884 local dir="$DIR/$tdir/dir"
2886 mkdir $dir && change_project -sp 1 $dir
2887 local used=$(getquota -p 1 global curinodes)
2888 [ $used != "1" ] && error "expected 1 got $used"
2893 used=$(getquota -p 1 global curinodes)
2894 [ $used != "4" ] && error "expected 4 got $used"
2896 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2898 cp $DIR/$tdir/6 $dir/6
2899 used=$(getquota -p 1 global curinodes)
2900 [ $used != "5" ] && error "expected 5 got $used"
2903 mv $DIR/$tdir/6 $dir/7
2904 used=$(getquota -p 1 global curinodes)
2905 [ $used != "6" ] && error "expected 6 got $used"
2910 run_test 51 "Test project accounting with mv/cp"
2913 ! is_project_quota_supported &&
2914 skip "Project quota is not supported"
2915 setup_quota_test || error "setup quota failed with $?"
2916 local dir="$DIR/$tdir/dir"
2917 mkdir $dir && change_project -sp 1 $dir
2919 touch $DIR/$tdir/file
2920 #Try renaming a file into the project. This should fail.
2921 for num in $(seq 1 2000); do
2922 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2923 error "rename should fail"
2928 run_test 52 "Rename across different project ID"
2931 ! is_project_quota_supported &&
2932 skip "Project quota is not supported"
2933 setup_quota_test || error "setup quota failed with $?"
2934 local dir="$DIR/$tdir/dir"
2935 mkdir $dir && change_project -s $dir
2936 lfs project -d $dir | grep P || error "inherit attribute should be set"
2938 change_project -C $dir
2939 lfs project -d $dir | grep P &&
2940 error "inherit attribute should be cleared"
2945 run_test 53 "Project inherit attribute could be cleared"
2948 ! is_project_quota_supported &&
2949 skip "Project quota is not supported"
2950 setup_quota_test || error "setup quota failed with $?"
2951 trap cleanup_quota_test EXIT
2952 local testfile="$DIR/$tdir/$tfile-0"
2954 #set project ID/inherit attribute
2955 change_project -sp $TSTPRJID $DIR/$tdir
2956 $RUNAS createmany -m ${testfile} 100 ||
2957 error "create many files failed"
2959 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2960 # one more count for directory itself */
2964 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2965 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2967 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2968 [ $proj_count1 -eq $proj_count ] ||
2969 error "c2: expected $proj_count got $proj_count1"
2971 #clear project but with kept projid
2972 change_project -rCk $DIR/$tdir
2973 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2974 [ $proj_count1 -eq 1 ] ||
2975 error "c3: expected 1 got $proj_count1"
2977 #verify projid untouched.
2978 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2980 [ $proj_count1 -eq $proj_count ] ||
2981 error "c4: expected $proj_count got $proj_count1"
2984 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2985 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2986 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2988 #this time clear all
2989 change_project -rC $DIR/$tdir
2990 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2991 [ $proj_count1 -eq 0 ] ||
2992 error "c6: expected 0 got $proj_count1"
2994 unlinkmany ${testfile} 100 ||
2995 error "unlink many files failed"
2999 run_test 54 "basic lfs project interface test"
3002 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3003 skip "Not supported before 2.10.58."
3004 setup_quota_test || error "setup quota failed with $?"
3006 set_ost_qtype $QTYPE || error "enable ost quota failed"
3009 #add second group to TSTUSR
3010 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3013 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3014 error "failed to dd"
3016 cancel_lru_locks osc
3017 sync; sync_all_data || true
3019 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3020 error "failed to setquota on group $TSTUSR2"
3022 $LFS quota -v -g $TSTUSR2 $DIR
3024 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3025 error "chgrp should failed with -EDQUOT"
3027 USED=$(getquota -g $TSTUSR2 global curspace)
3030 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3031 error "failed to setquota on group $TSTUSR2"
3033 $LFS quota -v -g $TSTUSR2 $DIR
3035 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3036 error "chgrp should succeed"
3038 $LFS quota -v -g $TSTUSR2 $DIR
3042 run_test 55 "Chgrp should be affected by group quota"
3045 setup_quota_test || error "setup quota failed with $?"
3047 set_ost_qtype $QTYPE || error "enable ost quota failed"
3050 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3051 erro "failed to set grace time for usr quota"
3052 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3053 awk '{print $4 $8}')
3054 if [ "x$grace_time" != "x10s;10s" ]; then
3055 $LFS quota -t -u $DIR
3056 error "expected grace time: 10s;10s, got:$grace_time"
3061 run_test 56 "lfs quota -t should work well"
3064 setup_quota_test || error "setup quota failed with $?"
3066 local dir="$DIR/$tdir/dir"
3069 #try to change pipe file should not hang and return failure
3070 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3071 awk -F ':' '{ print \\\$2 }'" \
3072 " unable to get xattr for fifo '$dir/pipe'" || return 1
3073 #command can process further if it hit some errors
3074 touch $dir/aaa $dir/bbb
3075 mkdir $dir/subdir -p
3076 touch $dir/subdir/aaa $dir/subdir/bbb
3077 #create one invalid link file
3078 ln -s $dir/not_exist_file $dir/ccc
3079 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3080 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3084 run_test 57 "lfs project could tolerate errors"
3087 [ "$mds1_FSTYPE" != ldiskfs ] &&
3088 skip "ldiskfs only test"
3089 disable_project_quota
3090 setup_quota_test || error "setup quota failed with $?"
3093 local testfile="$DIR/$tdir/$tfile-0"
3094 #make sure it did not crash kernel
3095 touch $testfile && lfs project -sp 1 $testfile
3097 enable_project_quota
3100 run_test 59 "lfs project dosen't crash kernel with project disabled"
3103 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3104 skip "Needs MDS version 2.11.53 or later."
3105 setup_quota_test || error "setup quota failed with $?"
3106 trap cleanup_quota_test EXIT
3108 local testfile=$DIR/$tdir/$tfile
3111 set_mdt_qtype "ug" || error "enable mdt quota failed"
3113 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3114 error "set quota failed"
3115 quota_show_check a g $TSTUSR
3117 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3118 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3119 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3120 error "create many files failed"
3122 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3124 # root user can overrun quota
3125 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3126 error "root user should succeed"
3130 run_test 60 "Test quota for root with setgid"
3132 # test default quota
3133 test_default_quota() {
3134 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3135 skip "Not supported before 2.11.51."
3140 local qprjid=$TSTPRJID
3144 local LIMIT=20480 #20M disk space
3145 local TESTFILE="$DIR/$tdir/$tfile-0"
3147 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3148 echo "Project quota is not supported" && return 0
3150 [ $qtype == "-u" ] && qdtype="-U"
3151 [ $qtype == "-g" ] && qdtype="-G"
3152 [ $qtype == "-p" ] && {
3157 [ $qpool == "meta" ] && {
3158 LIMIT=10240 #10K inodes
3163 setup_quota_test || error "setup quota failed with $?"
3164 trap cleanup_quota_test EXIT
3168 # enable mdt/ost quota
3169 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3170 set_ost_qtype $QTYPE || error "enable ost quota failed"
3172 log "set to use default quota"
3173 $LFS setquota $qtype $qid -d $DIR ||
3174 error "set $qid to use default quota failed"
3176 log "set default quota"
3177 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3178 error "set $qid default quota failed"
3180 log "get default quota"
3181 $LFS quota $qdtype $DIR || error "get default quota failed"
3183 if [ $qpool == "data" ]; then
3184 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3186 [ $SLIMIT -eq $LIMIT ] ||
3187 error "the returned default quota is wrong"
3189 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3191 [ $SLIMIT -eq $LIMIT ] ||
3192 error "the returned default quota is wrong"
3195 # make sure the system is clean
3196 local USED=$(getquota $qtype $qid global curspace)
3197 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3199 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3200 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3202 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3204 log "Test not out of quota"
3205 if [ $qpool == "data" ]; then
3206 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3207 quota_error $qtype $qid "write failed, expect succeed"
3209 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3210 quota_error $qtype $qid "create failed, expect succeed"
3212 unlinkmany $TESTFILE $((LIMIT/2))
3215 log "Test out of quota"
3216 # flush cache, ensure noquota flag is set on client
3217 cancel_lru_locks osc
3218 cancel_lru_locks mdc
3219 sync; sync_all_data || true
3220 if [ $qpool == "data" ]; then
3221 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3222 quota_error $qtype $qid "write succeed, expect EDQUOT"
3224 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3225 quota_error $qtype $qid "create succeed, expect EDQUOT"
3227 unlinkmany $TESTFILE $((LIMIT*2))
3230 log "Increase default quota"
3231 # increase default quota
3232 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3233 error "set default quota failed"
3235 cancel_lru_locks osc
3236 cancel_lru_locks mdc
3237 sync; sync_all_data || true
3238 if [ $qpool == "data" ]; then
3239 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3240 quota_error $qtype $qid "write failed, expect succeed"
3242 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3243 quota_error $qtype $qid "create failed, expect succeed"
3245 unlinkmany $TESTFILE $((LIMIT*2))
3248 log "Set quota to override default quota"
3249 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3250 error "set $qid quota failed"
3252 cancel_lru_locks osc
3253 cancel_lru_locks mdc
3254 sync; sync_all_data || true
3255 if [ $qpool == "data" ]; then
3256 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3257 quota_error $qtype $qid "write succeed, expect EQUOT"
3259 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3260 quota_error $qtype $qid "create succeed, expect EQUOT"
3262 unlinkmany $TESTFILE $((LIMIT*2))
3265 log "Set to use default quota again"
3266 $LFS setquota $qtype $qid -d $DIR ||
3267 error "set $qid to use default quota failed"
3269 cancel_lru_locks osc
3270 cancel_lru_locks mdc
3271 sync; sync_all_data || true
3272 if [ $qpool == "data" ]; then
3273 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3274 quota_error $qtype $qid "write failed, expect succeed"
3276 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3277 quota_error $qtype $qid "create failed, expect succeed"
3279 unlinkmany $TESTFILE $((LIMIT*2))
3284 wait_delete_completed || error "wait_delete_completed failed"
3285 sync_all_data || true
3286 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3287 error "reset default quota failed"
3288 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3289 error "reset quota failed"
3295 test_default_quota "-u" "data"
3296 test_default_quota "-u" "meta"
3297 test_default_quota "-g" "data"
3298 test_default_quota "-g" "meta"
3299 test_default_quota "-p" "data"
3300 test_default_quota "-p" "meta"
3302 run_test 61 "default quota tests"
3305 ! is_project_quota_supported &&
3306 skip "Project quota is not supported"
3307 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3308 skip "chattr did not support project quota"
3309 setup_quota_test || error "setup quota failed with $?"
3310 local testdir=$DIR/$tdir/
3312 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3313 change_project -s $testdir
3314 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3315 error "inherit attribute should be set"
3316 # chattr used FS_IOC_SETFLAGS ioctl
3317 $RUNAS chattr -P $testdir &&
3318 error "regular user clear inherit should fail"
3319 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3320 error "inherit attribute should still be set"
3321 chattr -P $testdir || error "root failed to clear inherit"
3322 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3323 error "inherit attribute should be cleared"
3326 run_test 62 "Project inherit should be only changed by root"
3329 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3330 skip "Not supported before 2.11.55"
3334 local dd_failed=false
3335 local tdir_dom=${tdir}_dom
3336 local LIMIT=20480 #20M
3338 [ $qtype == "p" ] && ! is_project_quota_supported &&
3339 echo "Project quota is not supported" && return 0
3341 [ $qtype == "p" ] && qid=$TSTPRJID
3343 setup_quota_test || error "setup quota failed with $?"
3344 trap cleanup_quota_test EXIT
3348 # enable mdt/ost quota
3349 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3350 set_ost_qtype $QTYPE || error "enable ost quota failed"
3352 # make sure the system is clean
3353 local USED=$(getquota -$qtype $qid global curspace)
3354 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3356 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3358 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3359 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3360 error "setstripe $tdir_dom failed"
3361 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3363 [ $qtype == "p" ] && {
3364 change_project -sp $TSTPRJID $DIR/$tdir
3365 change_project -sp $TSTPRJID $DIR/$tdir_dom
3368 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3369 error "set $qid quota failed"
3371 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3372 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3376 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3378 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3379 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3383 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3385 rm -f $DIR/$tdir_dom/*
3387 # flush cache, ensure noquota flag is set on client
3388 cancel_lru_locks osc
3389 cancel_lru_locks mdc
3390 sync; sync_all_data || true
3394 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3395 quota_error $qtype $qid "write failed, expect succeed"
3397 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3398 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3402 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3405 rm -f $DIR/$tdir_dom/*
3407 # flush cache, ensure noquota flag is set on client
3408 cancel_lru_locks osc
3409 cancel_lru_locks mdc
3410 sync; sync_all_data || true
3414 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3415 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3419 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3421 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3422 quota_error $qtype $qid "write succeed, expect EDQUOT"
3425 rm -fr $DIR/$tdir_dom
3427 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3428 error "reset usr quota failed"
3438 run_test 63 "quota on DoM tests"
3441 ! is_project_quota_supported &&
3442 skip "Project quota is not supported"
3443 setup_quota_test || error "setup quota failed with $?"
3444 local dir1="$DIR/$tdir/"
3447 ln -s $dir1/file $dir1/file_link
3449 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3450 error "set symlink file's project should fail"
3452 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3453 error "get symlink file's project should fail"
3457 run_test 64 "lfs project on symlink files should fail"
3461 local TESTFILE="$DIR/$tdir/$tfile-0"
3463 setup_quota_test || error "setup quota failed with $?"
3464 set_ost_qtype $QTYPE || error "enable ost quota failed"
3468 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3469 error "failed to write"
3470 # flush cache, ensure noquota flag is set on client
3471 cancel_lru_locks osc
3472 sync; sync_all_data || true
3474 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3475 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3476 local quota_all=$($RUNAS $LFS quota $DIR)
3478 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3479 error "usr quota not match"
3480 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3481 error "grp quota not match"
3487 run_test 65 "Check lfs quota result"
3490 ! is_project_quota_supported &&
3491 skip "Project quota is not supported"
3492 setup_quota_test || error "setup quota failed with $?"
3493 stack_trap cleanup_quota_test EXIT
3494 local old=$(do_facet mds1 $LCTL get_param -n \
3495 mdt.*.enable_chprojid_gid | head -1)
3496 local testdir=$DIR/$tdir/foo
3498 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3499 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3502 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3503 chown -R $TSTID:$TSTID $testdir
3504 change_project -sp $TSTPRJID $testdir
3505 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3507 $RUNAS lfs project -p 0 $testdir/foo &&
3508 error "nonroot user should fail to set projid"
3510 $RUNAS lfs project -C $testdir/foo &&
3511 error "nonroot user should fail to clear projid"
3513 change_project -C $testdir/foo || error "failed to clear project"
3515 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3516 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3517 "failed to set projid with normal user when enable_chprojid_gid=-1"
3519 $RUNAS lfs project -rC $testdir/ || error \
3520 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3522 touch $testdir/bar || error "failed touch $testdir/bar"
3523 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3524 "normal user should not be able to set projid on root owned file"
3526 change_project -p $TSTPRJID $testdir/bar || error \
3527 "root should be able to change its own file's projid"
3531 run_test 66 "nonroot user can not change project state in default"
3535 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3536 if $PQ_CLEANUP; then
3537 disable_project_quota
3540 reset_quota_settings
3545 check_and_cleanup_lustre
3546 export QUOTA_AUTO=$QUOTA_AUTO_OLD