3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
15 ALWAYS_EXCEPT="$SANITY_QUOTA_EXCEPT "
16 # Bug number for skipped test: LU-5152
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 # Test duration: 30 min
21 [ "$SLOW" = "no" ] && EXCEPT_SLOW="61"
23 if [ "$mds1_FSTYPE" = zfs ]; then
25 # Test duration: 21 9 min"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW+=" 12a 9"
31 DIRECTIO=${DIRECTIO:-$LUSTRE/tests/directio}
34 TSTID2=${TSTID2:-60001}
35 TSTUSR=${TSTUSR:-"quota_usr"}
36 TSTUSR2=${TSTUSR2:-"quota_2usr"}
37 TSTPRJID=${TSTPRJID:-1000}
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 # Does e2fsprogs support quota feature?
47 if [ "$mds1_FSTYPE" == ldiskfs ] &&
48 do_facet $SINGLEMDS "! $DEBUGFS -c -R supported_features |
49 grep -q 'quota'"; then
50 skip_env "e2fsprogs doesn't support quota"
53 QUOTALOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
55 [ "$QUOTALOG" ] && rm -f $QUOTALOG || true
60 QUOTA_AUTO_OLD=$QUOTA_AUTO
63 check_and_setup_lustre
65 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
67 SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
68 SHOW_QUOTA_USERID="$LFS quota -v -u $TSTID $DIR"
69 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
70 SHOW_QUOTA_GROUPID="$LFS quota -v -g $TSTID $DIR"
71 SHOW_QUOTA_PROJID="eval is_project_quota_supported && $LFS quota -v -p $TSTPRJID $DIR"
72 SHOW_QUOTA_INFO_USER="$LFS quota -t -u $DIR"
73 SHOW_QUOTA_INFO_GROUP="$LFS quota -t -g $DIR"
74 SHOW_QUOTA_INFO_PROJID="eval is_project_quota_supported && $LFS quota -t -p $DIR"
79 local fail_val=${3:-0}
83 mds_ost|mdt_ost) NODES="$(comma_list $(mdts_nodes) $(osts_nodes))";;
84 mds|mdt) NODES="$(comma_list $(mdts_nodes))";;
85 ost) NODES="$(comma_list $(osts_nodes))";;
88 do_nodes $NODES "lctl set_param fail_val=$fail_val fail_loc=$fail_loc"
94 lfs project $* || error "lfs project $* failed"
97 RUNAS="runas -u $TSTID -g $TSTID"
98 RUNAS2="runas -u $TSTID2 -g $TSTID2"
99 DD="dd if=/dev/zero bs=1M"
103 # clear quota limits for a user or a group
104 # usage: resetquota -u username
105 # resetquota -g groupname
106 # resetquota -p projid
109 [ "$#" != 2 ] && error "resetquota: wrong number of arguments: $#"
110 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
111 error "resetquota: wrong specifier $1 passed"
113 if [ $1 == "-p" ]; then
114 is_project_quota_supported || return 0
117 $LFS setquota "$1" "$2" -b 0 -B 0 -i 0 -I 0 $MOUNT ||
118 error "clear quota for [type:$1 name:$2] failed"
119 # give a chance to slave to release space
127 if [ "$local_ugp" == "a" -o "$local_ugp" == "u" ]; then
128 $LFS quota -v -u $local_id $DIR
129 log "Files for user ($local_id):"
130 ($LFS find --user $local_id $DIR | head -n 4 |
131 xargs stat 2>/dev/null)
134 if [ "$local_ugp" == "a" -o "$local_ugp" == "g" ]; then
135 $LFS quota -v -g $local_id $DIR
136 log "Files for group ($local_id):"
137 ($LFS find --group $local_id $DIR | head -n 4 |
138 xargs stat 2>/dev/null)
141 if [ "$local_ugp" == "a" -o "$local_ugp" == "p" ]; then
142 $LFS quota -v -p $TSTPRJID $DIR
143 log "Files for project ($TSTPRJID):"
144 ($LFS find --projid $TSTPRJID $DIR | head -n 4 |
145 xargs stat 2>/dev/null)
161 # get quota for a user or a group
162 # usage: getquota -u|-g|-p <username>|<groupname>|<projid> global|<obd_uuid> \
163 # bhardlimit|bsoftlimit|bgrace|ihardlimit|isoftlimit|igrace
168 sync_all_data > /dev/null 2>&1 || true
170 [ "$#" != 4 ] && error "getquota: wrong number of arguments: $#"
171 [ "$1" != "-u" -a "$1" != "-g" -a "$1" != "-p" ] &&
172 error "getquota: wrong u/g/p specifier $1 passed"
185 *) error "unknown quota parameter $4";;
188 [ "$uuid" = "global" ] && uuid=$DIR
190 $LFS quota -v "$1" "$2" $DIR |
191 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
192 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
197 # usage: set_mdt_qtype ugp|u|g|p|none
201 local mdts=$(get_facets MDS)
203 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
204 qtype=$(tr -d 'p' <<<$qtype)
206 if [[ $PERM_CMD == *"set_param -P"* ]]; then
207 do_facet mgs $PERM_CMD \
208 osd-*.$FSNAME-MDT*.quota_slave.enable=$qtype
210 do_facet mgs $PERM_CMD $FSNAME.quota.mdt=$qtype
212 # we have to make sure each MDT received config changes
213 for mdt in ${mdts//,/ }; do
215 cmd="$LCTL get_param -n "
216 cmd=${cmd}osd-$(facet_fstype $mdt).${!varsvc}
217 cmd=${cmd}.quota_slave.enabled
219 if $(facet_up $mdt); then
220 wait_update_facet $mdt "$cmd" "$qtype" || return 1
227 # usage: set_ost_qtype ugp|u|g|p|none
231 local osts=$(get_facets OST)
233 [[ "$qtype" =~ "p" ]] && ! is_project_quota_supported &&
234 qtype=$(tr -d 'p' <<<$qtype)
236 if [[ $PERM_CMD == *"set_param -P"* ]]; then
237 do_facet mgs $PERM_CMD \
238 osd-*.$FSNAME-OST*.quota_slave.enable=$qtype
240 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$qtype
242 # we have to make sure each OST received config changes
243 for ost in ${osts//,/ }; do
245 cmd="$LCTL get_param -n "
246 cmd=${cmd}osd-$(facet_fstype $ost).${!varsvc}
247 cmd=${cmd}.quota_slave.enabled
249 if $(facet_up $ost); then
250 wait_update_facet $ost "$cmd" "$qtype" || return 1
256 wait_reintegration() {
260 local result="glb[1],slv[1],reint[0]"
265 if [ $ntype == "mdt" ]; then
266 tgts=$(get_facets MDS)
268 tgts=$(get_facets OST)
271 for tgt in ${tgts//,/ }; do
273 cmd="$LCTL get_param -n "
274 cmd=${cmd}osd-$(facet_fstype $tgt).${!varsvc}
275 cmd=${cmd}.quota_slave.info
277 if $(facet_up $tgt); then
278 wait_update_facet $tgt "$cmd |
279 grep "$qtype" | awk '{ print \\\$3 }'" \
280 "$result" $max || return 1
290 if [[ "$qtype" =~ "u" ]]; then
291 wait_reintegration "mdt" "user" $max || return 1
294 if [[ "$qtype" =~ "g" ]]; then
295 wait_reintegration "mdt" "group" $max || return 1
298 if [[ "$qtype" =~ "p" ]]; then
299 ! is_project_quota_supported && return 0
300 wait_reintegration "mdt" "project" $max || return 1
309 if [[ "$qtype" =~ "u" ]]; then
310 wait_reintegration "ost" "user" $max || return 1
313 if [[ "$qtype" =~ "g" ]]; then
314 wait_reintegration "ost" "group" $max || return 1
317 if [[ "$qtype" =~ "p" ]]; then
318 ! is_project_quota_supported && return 0
319 wait_reintegration "ost" "project" $max || return 1
327 local extrasleep=${3:-5}
333 *) error "get_grace_time: Invalid quota type: $qtype"
338 time=$(lfs quota -$qtype $qarg $DIR|
339 awk 'NR == 3{ print $5 }'| sed 's/s$//')
342 time=$(lfs quota -$qtype $qarg $DIR|
343 awk 'NR == 3{ print $9 }'| sed 's/s$//')
346 error "Unknown quota type: $flavour"
350 echo "Sleep through grace ..."
351 [ "$time" == "-" ] &&
352 error "Grace timeout was not set or quota not exceeded"
353 if [ "$time" == "none" ]; then
354 echo "...Grace timeout already expired"
356 let time+=$extrasleep
357 echo "...sleep $time seconds"
363 wait_delete_completed
364 echo "Creating test directory"
365 mkdir $DIR/$tdir || return 1
366 chmod 0777 $DIR/$tdir || return 2
367 # always clear fail_loc in case of fail_loc isn't cleared
368 # properly when previous test failed
369 lustre_fail mds_ost 0
372 cleanup_quota_test() {
374 echo "Delete files..."
376 echo "Wait for unlink objects finished..."
377 wait_delete_completed
378 sync_all_data || true
388 $LFS quota -v -$ugp $qid $DIR
390 if [ "$bf" == "a" -o "$bf" == "b" ]; then
391 usage=$(getquota -$ugp $qid global curspace)
392 if [ -z $usage ]; then
393 quota_error $ugp $qid \
394 "Query block quota failed ($ugp:$qid)."
396 [ $usage -ne 0 ] && quota_log $ugp $qid \
397 "Block quota isn't 0 ($ugp:$qid:$usage)."
401 if [ "$bf" == "a" -o "$bf" == "f" ]; then
402 usage=$(getquota -$ugp $qid global curinodes)
403 if [ -z $usage ]; then
404 quota_error $ugp $qid \
405 "Query file quota failed ($ugp:$qid)."
407 [ $usage -ne 0 ] && quota_log $ugp $qid \
408 "File quota isn't 0 ($ugp:$qid:$usage)."
413 project_quota_enabled () {
415 local zfeat="feature@project_quota"
417 for facet in $(seq -f mds%g $MDSCOUNT) $(seq -f ost%g $OSTCOUNT); do
418 local facet_fstype=${facet:0:3}1_FSTYPE
421 if [ "${!facet_fstype}" = "zfs" ]; then
422 devname=$(zpool_name ${facet})
423 do_facet ${facet} $ZPOOL get -H "$zfeat" $devname |
424 grep -wq active || rc=1
426 [ ${facet:0:3} == "mds" ] &&
427 devname=$(mdsdevname ${facet:3}) ||
428 devname=$(ostdevname ${facet:3})
429 do_facet ${facet} $DEBUGFS -R features $devname |
430 grep -q project || rc=1
433 [ $rc -eq 0 ] && PQ_CLEANUP=false || PQ_CLEANUP=true
437 project_quota_enabled || enable_project_quota
439 reset_quota_settings() {
440 resetquota -u $TSTUSR
442 resetquota -g $TSTUSR
444 resetquota -u $TSTUSR2
445 resetquota -u $TSTID2
446 resetquota -g $TSTUSR2
447 resetquota -g $TSTID2
448 resetquota -p $TSTPRJID
453 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=+quota"
458 check_runas_id_ret $TSTUSR $TSTUSR $RUNAS ||
459 error "Please create user $TSTUSR($TSTID) and group $TSTUSR($TSTID)"
460 check_runas_id_ret $TSTUSR2 $TSTUSR2 $RUNAS2 ||
461 error "Please create user $TSTUSR2($TSTID2) and group $TSTUSR2($TSTID2)"
463 test_quota_performance() {
464 local TESTFILE="$DIR/$tdir/$tfile-0"
465 local size=$1 # in MB
466 local stime=$(date +%s)
467 $RUNAS $DD of=$TESTFILE count=$size conv=fsync ||
468 quota_error u $TSTUSR "write failure"
469 local etime=$(date +%s)
470 delta=$((etime - stime))
471 if [ $delta -gt 0 ]; then
472 rate=$((size * 1024 / delta))
473 if [ "$mds1_FSTYPE" = zfs ]; then
474 # LU-2872 - see LU-2887 for fix
476 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
478 [ $rate -gt 1024 ] ||
479 error "SLOW IO for $TSTUSR (user): $rate KB/sec"
485 # test basic quota performance b=21696
488 [ "$SLOW" = "no" ] && MB=10
490 local free_space=$(lfs_df | grep "summary" | awk '{print $4}')
491 [ $free_space -le $((MB * 1024)) ] &&
492 skip "not enough space ${free_space} KB, " \
493 "required $((MB * 1024)) KB"
494 setup_quota_test || error "setup quota failed with $?"
495 trap cleanup_quota_test EXIT
497 set_ost_qtype "none" || error "disable ost quota failed"
498 test_quota_performance $MB
500 set_ost_qtype $QTYPE || error "enable ost quota failed"
501 $LFS setquota -u $TSTUSR -b 0 -B 10G -i 0 -I 0 $DIR ||
502 error "set quota failed"
503 test_quota_performance $MB
507 run_test 0 "Test basic quota performance"
509 # test block hardlimit
512 local TESTFILE="$DIR/$tdir/$tfile-0"
514 setup_quota_test || error "setup quota failed with $?"
515 trap cleanup_quota_test EXIT
518 set_ost_qtype $QTYPE || error "enable ost quota failed"
521 log "User quota (block hardlimit:$LIMIT MB)"
522 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
523 error "set user quota failed"
525 # make sure the system is clean
526 local USED=$(getquota -u $TSTUSR global curspace)
527 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
529 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
530 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
533 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
534 quota_error u $TSTUSR "user write failure, but expect success"
535 log "Write out of block quota ..."
536 # this time maybe cache write, ignore it's failure
537 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
538 # flush cache, ensure noquota flag is set on client
540 sync; sync_all_data || true
541 $RUNAS $DD of=$TESTFILE count=1 seek=$LIMIT &&
542 quota_error u $TSTUSR "user write success, but expect EDQUOT"
545 wait_delete_completed || error "wait_delete_completed failed"
546 sync_all_data || true
547 USED=$(getquota -u $TSTUSR global curspace)
548 [ $USED -ne 0 ] && quota_error u $TSTUSR \
549 "user quota isn't released after deletion"
550 resetquota -u $TSTUSR
553 log "--------------------------------------"
554 log "Group quota (block hardlimit:$LIMIT MB)"
555 $LFS setquota -g $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
556 error "set group quota failed"
558 TESTFILE="$DIR/$tdir/$tfile-1"
559 # make sure the system is clean
560 USED=$(getquota -g $TSTUSR global curspace)
561 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTUSR isn't 0"
563 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
564 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
567 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) ||
568 quota_error g $TSTUSR "Group write failure, but expect success"
569 log "Write out of block quota ..."
570 # this time maybe cache write, ignore it's failure
571 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
573 sync; sync_all_data || true
574 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT &&
575 quota_error g $TSTUSR "Group write success, but expect EDQUOT"
577 wait_delete_completed || error "wait_delete_completed failed"
578 sync_all_data || true
579 USED=$(getquota -g $TSTUSR global curspace)
580 [ $USED -ne 0 ] && quota_error g $TSTUSR \
581 "Group quota isn't released after deletion"
582 resetquota -g $TSTUSR
584 if ! is_project_quota_supported; then
585 echo "Project quota is not supported"
590 TESTFILE="$DIR/$tdir/$tfile-2"
591 # make sure the system is clean
592 USED=$(getquota -p $TSTPRJID global curspace)
594 error "used space($USED) for project $TSTPRJID isn't 0"
597 log "--------------------------------------"
598 log "Project quota (block hardlimit:$LIMIT mb)"
599 $LFS setquota -p $TSTPRJID -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
600 error "set project quota failed"
602 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
603 chown $TSTUSR:$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
604 change_project -p $TSTPRJID $TESTFILE
607 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) || quota_error p $TSTPRJID \
608 "project write failure, but expect success"
609 log "write out of block quota ..."
610 # this time maybe cache write, ignore it's failure
611 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) seek=$((LIMIT/2)) || true
613 sync; sync_all_data || true
614 $RUNAS $DD of=$TESTFILE count=10 seek=$LIMIT && quota_error p \
615 $TSTPRJID "project write success, but expect EDQUOT"
620 USED=$(getquota -p $TSTPRJID global curspace)
621 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
622 "project quota isn't released after deletion"
624 run_test 1 "Block hard limit (normal use and out of quota)"
626 # test inode hardlimit
628 local LIMIT=$((1024 * 1024)) # 1M inodes
629 local TESTFILE="$DIR/$tdir/$tfile-0"
631 [ "$SLOW" = "no" ] && LIMIT=1024 # 1k inodes
633 local FREE_INODES=$(mdt_free_inodes 0)
634 echo "$FREE_INODES free inodes on master MDT"
635 [ $FREE_INODES -lt $LIMIT ] &&
636 skip "not enough free inodes $FREE_INODES required $LIMIT"
638 setup_quota_test || error "setup quota failed with $?"
639 trap cleanup_quota_test EXIT
642 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
645 log "User quota (inode hardlimit:$LIMIT files)"
646 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
647 error "set user quota failed"
649 # make sure the system is clean
650 local USED=$(getquota -u $TSTUSR global curinodes)
651 [ $USED -ne 0 ] && error "Used inodes($USED) for user $TSTUSR isn't 0."
653 log "Create $LIMIT files ..."
654 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
655 quota_error u $TSTUSR "user create failure, but expect success"
656 log "Create out of file quota ..."
657 $RUNAS touch ${TESTFILE}_xxx &&
658 quota_error u $TSTUSR "user create success, but expect EDQUOT"
661 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
662 rm -f ${TESTFILE}_xxx
663 wait_delete_completed
665 USED=$(getquota -u $TSTUSR global curinodes)
666 [ $USED -ne 0 ] && quota_error u $TSTUSR \
667 "user quota isn't released after deletion"
668 resetquota -u $TSTUSR
671 log "--------------------------------------"
672 log "Group quota (inode hardlimit:$LIMIT files)"
673 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
674 error "set group quota failed"
676 TESTFILE=$DIR/$tdir/$tfile-1
677 # make sure the system is clean
678 USED=$(getquota -g $TSTUSR global curinodes)
679 [ $USED -ne 0 ] && error "Used inodes($USED) for group $TSTUSR isn't 0."
681 log "Create $LIMIT files ..."
682 $RUNAS createmany -m ${TESTFILE} $LIMIT ||
683 quota_error g $TSTUSR "group create failure, but expect success"
684 log "Create out of file quota ..."
685 $RUNAS touch ${TESTFILE}_xxx &&
686 quota_error g $TSTUSR "group create success, but expect EDQUOT"
689 unlinkmany ${TESTFILE} $LIMIT || error "unlinkmany $TESTFILE failed"
690 rm -f ${TESTFILE}_xxx
691 wait_delete_completed
693 USED=$(getquota -g $TSTUSR global curinodes)
694 [ $USED -ne 0 ] && quota_error g $TSTUSR \
695 "user quota isn't released after deletion"
697 resetquota -g $TSTUSR
698 ! is_project_quota_supported && cleanup_quota_test &&
699 echo "Skip project quota is not supported" && return 0
702 log "--------------------------------------"
703 log "Project quota (inode hardlimit:$LIMIT files)"
704 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i 0 -I $LIMIT $DIR ||
705 error "set project quota failed"
707 TESTFILE=$DIR/$tdir/$tfile-1
708 # make sure the system is clean
709 USED=$(getquota -p $TSTPRJID global curinodes)
711 error "Used inodes($USED) for project $TSTPRJID isn't 0"
713 change_project -sp $TSTPRJID $DIR/$tdir
714 log "Create $LIMIT files ..."
715 $RUNAS createmany -m ${TESTFILE} $((LIMIT-1)) || quota_error p \
716 $TSTPRJID "project create fail, but expect success"
717 log "Create out of file quota ..."
718 $RUNAS touch ${TESTFILE}_xxx && quota_error p $TSTPRJID \
719 "project create success, but expect EDQUOT"
720 change_project -C $DIR/$tdir
723 USED=$(getquota -p $TSTPRJID global curinodes)
724 [ $USED -eq 0 ] || quota_error p $TSTPRJID \
725 "project quota isn't released after deletion"
728 run_test 2 "File hard limit (normal use and out of quota)"
738 trap cleanup_quota_test EXIT
740 $LFS setstripe $TESTFILE -c 1 -i 0
741 chown $TSTUSR.$TSTUSR $TESTFILE
742 [ "$qtype" == "p" ] && is_project_quota_supported &&
743 change_project -p $TSTPRJID $TESTFILE
745 echo "Write up to soft limit"
746 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
747 quota_error a $TSTUSR "write failure, but expect success"
748 OFFSET=$((LIMIT * 1024))
751 echo "Write to exceed soft limit"
752 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
753 quota_error a $TSTUSR "write failure, but expect success"
754 OFFSET=$((OFFSET + 1024)) # make sure we don't write to same block
760 $SHOW_QUOTA_INFO_USER
761 $SHOW_QUOTA_INFO_GROUP
762 $SHOW_QUOTA_INFO_PROJID
764 echo "Write before timer goes off"
765 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET ||
766 quota_error a $TSTUSR "write failure, but expect success"
767 OFFSET=$((OFFSET + 1024))
770 wait_grace_time $qtype "block"
775 $SHOW_QUOTA_INFO_USER
776 $SHOW_QUOTA_INFO_GROUP
777 $SHOW_QUOTA_INFO_PROJID
779 echo "Write after timer goes off"
780 # maybe cache write, ignore.
781 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET || true
782 OFFSET=$((OFFSET + 1024))
784 $RUNAS dd if=/dev/zero of=$TESTFILE bs=1K count=10 seek=$OFFSET &&
785 quota_error a $TSTUSR "write success, but expect EDQUOT"
790 $SHOW_QUOTA_INFO_USER
791 $SHOW_QUOTA_INFO_GROUP
792 $SHOW_QUOTA_INFO_PROJID
794 echo "Unlink file to stop timer"
796 wait_delete_completed
797 sync_all_data || true
802 $SHOW_QUOTA_INFO_USER
803 $SHOW_QUOTA_INFO_GROUP
804 $SHOW_QUOTA_INFO_PROJID
806 $LFS setstripe $TESTFILE -c 1 -i 0
807 chown $TSTUSR.$TSTUSR $TESTFILE
808 [ "$qtype" == "p" ] && change_project -p $TSTPRJID $TESTFILE
811 $RUNAS $DD of=$TESTFILE count=$LIMIT ||
812 quota_error a $TSTUSR "write failure, but expect success"
820 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
823 local TESTFILE=$DIR/$tdir/$tfile-0
825 # get minimum soft qunit size
826 local LIMIT=$(( $(do_facet $SINGLEMDS $LCTL get_param -n \
827 qmt.$FSNAME-QMT0000.dt-0x0.soft_least_qunit) / 1024 ))
829 set_ost_qtype $QTYPE || error "enable ost quota failed"
831 echo "User quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
832 # make sure the system is clean
833 local USED=$(getquota -u $TSTUSR global curspace)
834 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
836 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
837 $MAX_IQ_TIME $DIR || error "set user grace time failed"
838 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
839 error "set user quota failed"
841 test_block_soft $TESTFILE $GRACE $LIMIT "u"
843 echo "Group quota (soft limit:$LIMIT MB grace:$GRACE seconds)"
844 TESTFILE=$DIR/$tdir/$tfile-1
845 # make sure the system is clean
846 USED=$(getquota -g $TSTUSR global curspace)
847 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
849 $LFS setquota -t -g --block-grace $GRACE --inode-grace \
850 $MAX_IQ_TIME $DIR || error "set group grace time failed"
851 $LFS setquota -g $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
852 error "set group quota failed"
854 test_block_soft $TESTFILE $GRACE $LIMIT "g"
856 if is_project_quota_supported; then
857 echo "Project quota (soft limit:$LIMIT MB grace:$GRACE sec)"
858 TESTFILE=$DIR/$tdir/$tfile-2
859 # make sure the system is clean
860 USED=$(getquota -p $TSTPRJID global curspace)
861 [ $USED -ne 0 ] && error \
862 "Used space($USED) for project $TSTPRJID isn't 0."
864 $LFS setquota -t -p --block-grace $GRACE --inode-grace \
866 error "set project grace time failed"
867 $LFS setquota -p $TSTPRJID -b ${LIMIT}M -B 0 -i 0 -I 0 \
868 $DIR || error "set project quota failed"
870 test_block_soft $TESTFILE $GRACE $LIMIT "p"
871 resetquota -p $TSTPRJID
872 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
874 error "restore project grace time failed"
878 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
879 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
880 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
881 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
883 run_test 3 "Block soft limit (start timer, timer goes off, stop timer)"
892 trap cleanup_quota_test EXIT
893 is_project_quota_supported && change_project -sp $TSTPRJID $DIR/$tdir
895 echo "Create files to exceed soft limit"
896 $RUNAS createmany -m ${TESTFILE}_ $((LIMIT + 1)) ||
897 quota_error a $TSTUSR "create failure, but expect success"
898 local trigger_time=$(date +%s)
900 sync_all_data || true
902 local cur_time=$(date +%s)
903 [ $(($cur_time - $trigger_time)) -ge $grace ] &&
904 error "Passed grace time $grace, $trigger_time, $cur_time"
906 echo "Create file before timer goes off"
907 $RUNAS touch ${TESTFILE}_before ||
908 quota_error a $TSTUSR "failed create before timer expired," \
909 "but expect success. $trigger_time, $cur_time"
910 sync_all_data || true
912 wait_grace_time $qtype "file"
917 $SHOW_QUOTA_INFO_USER
918 $SHOW_QUOTA_INFO_GROUP
919 $SHOW_QUOTA_INFO_PROJID
921 echo "Create file after timer goes off"
922 # There is a window that space is accounted in the quota usage but
923 # hasn't been decreased from the pending write, if we acquire quota
924 # in this window, we'll acquire more than we needed.
925 $RUNAS touch ${TESTFILE}_after_1 ${TESTFILE}_after_2 || true
926 sync_all_data || true
927 $RUNAS touch ${TESTFILE}_after_3 &&
928 quota_error a $TSTUSR "create after timer expired," \
930 sync_all_data || true
935 $SHOW_QUOTA_INFO_USER
936 $SHOW_QUOTA_INFO_GROUP
937 $SHOW_QUOTA_INFO_PROJID
939 echo "Unlink files to stop timer"
940 find $(dirname $TESTFILE) -name "$(basename ${TESTFILE})*" | xargs rm -f
941 wait_delete_completed
944 $RUNAS touch ${TESTFILE}_xxx ||
945 quota_error a $TSTUSR "touch after timer stop failure," \
947 sync_all_data || true
955 local LIMIT=$(do_facet $SINGLEMDS $LCTL get_param -n \
956 qmt.$FSNAME-QMT0000.md-0x0.soft_least_qunit)
957 local TESTFILE=$DIR/$tdir/$tfile-0
960 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
962 echo "User quota (soft limit:$LIMIT files grace:$GRACE seconds)"
963 # make sure the system is clean
964 local USED=$(getquota -u $TSTUSR global curinodes)
965 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
967 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
968 $GRACE $DIR || error "set user grace time failed"
969 $LFS setquota -u $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
970 error "set user quota failed"
972 [ "$mds1_FSTYPE" = zfs ] && GRACE=20
974 test_file_soft $TESTFILE $LIMIT $GRACE "u"
976 echo "Group quota (soft limit:$LIMIT files grace:$GRACE seconds)"
977 # make sure the system is clean
978 USED=$(getquota -g $TSTUSR global curinodes)
979 [ $USED -ne 0 ] && error "Used space($USED) for group $TSTUSR isn't 0."
981 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
982 $GRACE $DIR || error "set group grace time failed"
983 $LFS setquota -g $TSTUSR -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
984 error "set group quota failed"
985 TESTFILE=$DIR/$tdir/$tfile-1
987 test_file_soft $TESTFILE $LIMIT $GRACE "g"
989 if is_project_quota_supported; then
990 echo "Project quota (soft limit:$LIMIT files grace:$GRACE sec)"
991 # make sure the system is clean
992 USED=$(getquota -p $TSTPRJID global curinodes)
993 [ $USED -ne 0 ] && error \
994 "Used space($USED) for project $TSTPRJID isn't 0."
996 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
997 $GRACE $DIR || error "set project grace time failed"
998 $LFS setquota -p $TSTPRJID -b 0 -B 0 -i $LIMIT -I 0 $DIR ||
999 error "set project quota failed"
1001 TESTFILE=$DIR/$tdir/$tfile-1
1002 # one less than limit, because of parent directory included.
1003 test_file_soft $TESTFILE $((LIMIT-1)) $GRACE "p"
1004 resetquota -p $TSTPRJID
1005 $LFS setquota -t -p --block-grace $MAX_DQ_TIME --inode-grace \
1006 $MAX_IQ_TIME $DIR ||
1007 error "restore project grace time failed"
1011 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1012 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1013 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1014 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1016 run_test 4a "File soft limit (start timer, timer goes off, stop timer)"
1019 local GR_STR1="1w3d"
1020 local GR_STR2="1000s"
1022 local GR_STR4="1w2d3h4m5s"
1024 local GR_STR6="18446744073709551615"
1027 wait_delete_completed
1029 # test of valid grace strings handling
1030 echo "Valid grace strings test"
1031 $LFS setquota -t -u --block-grace $GR_STR1 --inode-grace \
1032 $GR_STR2 $DIR || error "set user grace time failed"
1033 $LFS quota -u -t $DIR | grep "Block grace time: $GR_STR1"
1034 $LFS setquota -t -g --block-grace $GR_STR3 --inode-grace \
1035 $GR_STR4 $DIR || error "set group grace time quota failed"
1036 $LFS quota -g -t $DIR | grep "Inode grace time: $GR_STR4"
1038 # test of invalid grace strings handling
1039 echo " Invalid grace strings test"
1040 ! $LFS setquota -t -u --block-grace $GR_STR4 --inode-grace $GR_STR5 $DIR
1041 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace $GR_STR6 $DIR
1042 ! $LFS setquota -t -g --block-grace $GR_STR4 --inode-grace \
1046 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
1047 $MAX_IQ_TIME $DIR || error "restore user grace time failed"
1048 $LFS setquota -t -g --block-grace $MAX_DQ_TIME --inode-grace \
1049 $MAX_IQ_TIME $DIR || error "restore group grace time failed"
1051 run_test 4b "Grace time strings handling"
1053 # chown & chgrp (chown & chgrp successfully even out of block/file quota)
1055 local BLIMIT=10 # 10M
1056 local ILIMIT=10 # 10 inodes
1058 setup_quota_test || error "setup quota failed with $?"
1059 trap cleanup_quota_test EXIT
1061 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1062 set_ost_qtype $QTYPE || error "enable ost quota failed"
1064 echo "Set quota limit (0 ${BLIMIT}M 0 $ILIMIT) for $TSTUSR.$TSTUSR"
1065 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1066 error "set user quota failed"
1067 $LFS setquota -g $TSTUSR -b 0 -B ${BLIMIT}M -i 0 -I $ILIMIT $DIR ||
1068 if is_project_quota_supported; then
1069 error "set group quota failed"
1070 $LFS setquota -p $TSTPRJID -b 0 -B ${BLIMIT}M -i 0 \
1071 -I $ILIMIT $DIR || error "set project quota failed"
1074 # make sure the system is clean
1075 local USED=$(getquota -u $TSTUSR global curinodes)
1076 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1077 USED=$(getquota -g $TSTUSR global curinodes)
1078 [ $USED -ne 0 ] && error "Used inode($USED) for group $TSTUSR isn't 0."
1079 USED=$(getquota -u $TSTUSR global curspace)
1080 [ $USED -ne 0 ] && error "Used block($USED) for user $TSTUSR isn't 0."
1081 USED=$(getquota -g $TSTUSR global curspace)
1082 [ $USED -ne 0 ] && error "Used block($USED) for group $TSTUSR isn't 0."
1083 if is_project_quota_supported; then
1084 USED=$(getquota -p $TSTPRJID global curinodes)
1086 error "Used inode($USED) for project $TSTPRJID isn't 0."
1087 USED=$(getquota -p $TSTPRJID global curspace)
1089 error "Used block($USED) for project $TSTPRJID isn't 0."
1092 echo "Create more than $ILIMIT files and more than $BLIMIT MB ..."
1093 createmany -m $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1094 error "create failure, expect success"
1095 if is_project_quota_supported; then
1096 touch $DIR/$tdir/$tfile-0_1
1097 change_project -p $TSTPRJID $DIR/$tdir/$tfile-0_1
1099 $DD of=$DIR/$tdir/$tfile-0_1 count=$((BLIMIT+1)) ||
1100 error "write failure, expect success"
1102 echo "Chown files to $TSTUSR.$TSTUSR ..."
1103 for i in $(seq 0 $ILIMIT); do
1104 chown $TSTUSR.$TSTUSR $DIR/$tdir/$tfile-0_$i ||
1105 quota_error a $TSTUSR "chown failure, expect success"
1109 unlinkmany $DIR/$tdir/$tfile-0_ $((ILIMIT + 1)) ||
1110 error "unlinkmany $DIR/$tdir/$tfile-0_ failed"
1113 run_test 5 "Chown & chgrp successfully even out of block/file quota"
1115 # test dropping acquire request on master
1119 # Clear dmesg so watchdog is not triggered by previous
1121 do_facet ost1 dmesg -c > /dev/null
1123 setup_quota_test || error "setup quota failed with $?"
1124 trap cleanup_quota_test EXIT
1126 # make sure the system is clean
1127 local USED=$(getquota -u $TSTUSR global curspace)
1128 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1130 # make sure no granted quota on ost
1131 set_ost_qtype $QTYPE || error "enable ost quota failed"
1132 resetquota -u $TSTUSR
1134 # create file for $TSTUSR
1135 local TESTFILE=$DIR/$tdir/$tfile-$TSTUSR
1136 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1137 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1139 # create file for $TSTUSR2
1140 local TESTFILE2=$DIR/$tdir/$tfile-$TSTUSR2
1141 $LFS setstripe $TESTFILE2 -c 1 -i 0 || error "setstripe $TESTFILE2 failed"
1142 chown $TSTUSR2.$TSTUSR2 $TESTFILE2 || error "chown $TESTFILE2 failed"
1144 # cache per-ID lock for $TSTUSR on slave
1145 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1146 error "set quota failed"
1147 $RUNAS $DD of=$TESTFILE count=1 ||
1148 error "write $TESTFILE failure, expect success"
1149 $RUNAS2 $DD of=$TESTFILE2 count=1 ||
1150 error "write $TESTFILE2 failure, expect success"
1152 if at_is_enabled; then
1153 at_max_saved=$(at_max_get ost1)
1154 at_max_set $TIMEOUT ost1
1156 # write to enforced ID ($TSTUSR) to exceed limit to make sure
1157 # DQACQ is sent, which makes at_max to take effect
1158 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync \
1161 wait_delete_completed
1165 sync_all_data || true
1167 #define QUOTA_DQACQ 601
1168 #define OBD_FAIL_PTLRPC_DROP_REQ_OPC 0x513
1169 lustre_fail mds 0x513 601
1171 do_facet ost1 $LCTL set_param \
1172 osd-*.$FSNAME-OST*.quota_slave.timeout=$((TIMEOUT / 2))
1174 # write to un-enforced ID ($TSTUSR2) should succeed
1175 $RUNAS2 $DD of=$TESTFILE2 count=$LIMIT seek=1 oflag=sync conv=notrunc ||
1176 error "write failure, expect success"
1178 # write to enforced ID ($TSTUSR) in background, exceeding limit
1179 # to make sure DQACQ is sent
1180 $RUNAS $DD of=$TESTFILE count=$LIMIT seek=1 oflag=sync conv=notrunc &
1183 # watchdog timer uses a factor of 2
1184 echo "Sleep for $((TIMEOUT * 2 + 1)) seconds ..."
1185 sleep $((TIMEOUT * 2 + 1))
1187 [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
1189 # write should be blocked and never finished
1190 if ! ps -p $DDPID > /dev/null 2>&1; then
1192 error "write finished incorrectly!"
1197 # no watchdog is triggered
1198 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1199 watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1200 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1201 [ -z "$watchdog" ] || error "$watchdog"
1203 rm -f $TMP/lustre-log-${TESTNAME}.log
1205 # write should continue then fail with EDQUOT
1209 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1210 if [ $count -ge 240 ]; then
1211 quota_error u $TSTUSR "dd not finished in $count secs"
1213 count=$((count + 1))
1214 if [ $((count % 30)) -eq 0 ]; then
1215 c_size=$(stat -c %s $TESTFILE)
1216 echo "Waiting $count secs. $c_size"
1224 run_test 6 "Test dropping acquire request on master"
1226 # quota reintegration (global index)
1228 local TESTFILE=$DIR/$tdir/$tfile
1229 local LIMIT=20 # 20M
1231 [ "$SLOW" = "no" ] && LIMIT=5
1233 setup_quota_test || error "setup quota failed with $?"
1234 trap cleanup_quota_test EXIT
1236 # make sure the system is clean
1237 local USED=$(getquota -u $TSTUSR global curspace)
1238 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1240 # make sure no granted quota on ost1
1241 set_ost_qtype $QTYPE || error "enable ost quota failed"
1242 resetquota -u $TSTUSR
1243 set_ost_qtype "none" || error "disable ost quota failed"
1245 local OSTUUID=$(ostuuid_from_index 0)
1246 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1248 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1251 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1252 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1257 echo "Enable quota & set quota limit for $TSTUSR"
1258 set_ost_qtype $QTYPE || error "enable ost quota failed"
1259 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1260 error "set quota failed"
1262 echo "Start ost1..."
1263 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1266 wait_ost_reint $QTYPE || error "reintegration failed"
1268 # hardlimit should have been fetched by slave during global
1269 # reintegration, write will exceed quota
1270 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1271 quota_error u $TSTUSR "write success, but expect EDQUOT"
1274 wait_delete_completed
1275 sync_all_data || true
1281 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1282 error "clear quota failed"
1284 echo "Start ost1..."
1285 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1288 wait_ost_reint $QTYPE || error "reintegration failed"
1290 # hardlimit should be cleared on slave during reintegration
1291 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync ||
1292 quota_error u $TSTUSR "write error, but expect success"
1296 run_test 7a "Quota reintegration (global index)"
1298 # quota reintegration (slave index)
1301 local TESTFILE=$DIR/$tdir/$tfile
1303 setup_quota_test || error "setup quota failed with $?"
1304 trap cleanup_quota_test EXIT
1306 # make sure the system is clean
1307 local USED=$(getquota -u $TSTUSR global curspace)
1308 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1310 # make sure no granted quota on ost1
1311 set_ost_qtype $QTYPE || error "enable ost quota failed"
1312 resetquota -u $TSTUSR
1313 set_ost_qtype "none" || error "disable ost quota failed"
1315 local OSTUUID=$(ostuuid_from_index 0)
1316 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1318 error "limit($USED) on $OSTUUID for user $TSTUSR isn't 0"
1321 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1322 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1324 # consume some space to make sure the granted space will not
1325 # be released during reconciliation
1326 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1327 error "consume space failure, expect success"
1329 # define OBD_FAIL_QUOTA_EDQUOT 0xa02
1330 lustre_fail mds 0xa02
1332 set_ost_qtype $QTYPE || error "enable ost quota failed"
1333 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1334 error "set quota failed"
1336 # ignore the write error
1337 $RUNAS $DD of=$TESTFILE count=1 seek=1 oflag=sync conv=notrunc
1339 local old_used=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1343 echo "Restart ost to trigger reintegration..."
1345 start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
1348 wait_ost_reint $QTYPE || error "reintegration failed"
1350 USED=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1351 [ $USED -gt $old_used ] || error "limit on $OSTUUID $USED <= $old_used"
1356 run_test 7b "Quota reintegration (slave index)"
1358 # quota reintegration (restart mds during reintegration)
1360 local LIMIT=20 # 20M
1361 local TESTFILE=$DIR/$tdir/$tfile
1363 [ "$SLOW" = "no" ] && LIMIT=5
1365 setup_quota_test || error "setup quota failed with $?"
1366 trap cleanup_quota_test EXIT
1368 # make sure the system is clean
1369 local USED=$(getquota -u $TSTUSR global curspace)
1370 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1372 set_ost_qtype "none" || error "disable ost quota failed"
1373 $LFS setquota -u $TSTUSR -b 0 -B ${LIMIT}M -i 0 -I 0 $DIR ||
1374 error "set quota failed"
1376 # define OBD_FAIL_QUOTA_DELAY_REINT 0xa03
1377 lustre_fail ost 0xa03
1380 set_ost_qtype $QTYPE || error "enable ost quota failed"
1381 # trigger reintegration
1382 local procf="osd-$ost1_FSTYPE.$FSNAME-OST*."
1383 procf=${procf}quota_slave.force_reint
1384 do_facet ost1 $LCTL set_param $procf=1 ||
1385 error "force reintegration failed"
1393 start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
1396 # wait longer than usual to make sure the reintegration
1397 # is triggered by quota wb thread.
1398 wait_ost_reint $QTYPE 200 || error "reintegration failed"
1400 # hardlimit should have been fetched by slave during global
1401 # reintegration, write will exceed quota
1402 $RUNAS $DD of=$TESTFILE count=$((LIMIT + 1)) oflag=sync &&
1403 quota_error u $TSTUSR "write success, but expect EDQUOT"
1407 run_test 7c "Quota reintegration (restart mds during reintegration)"
1409 # Quota reintegration (Transfer index in multiple bulks)
1411 local TESTFILE=$DIR/$tdir/$tfile
1412 local TESTFILE1="$DIR/$tdir/$tfile"-1
1415 setup_quota_test || error "setup quota failed with $?"
1416 trap cleanup_quota_test EXIT
1418 set_ost_qtype "none" || error "disable ost quota failed"
1419 $LFS setquota -u $TSTUSR -B ${limit}M $DIR ||
1420 error "set quota for $TSTUSR failed"
1421 $LFS setquota -u $TSTUSR2 -B ${limit}M $DIR ||
1422 error "set quota for $TSTUSR2 failed"
1424 #define OBD_FAIL_OBD_IDX_READ_BREAK 0x608
1425 lustre_fail mds 0x608 0
1427 # enable quota to tirgger reintegration
1428 set_ost_qtype "u" || error "enable ost quota failed"
1429 wait_ost_reint "u" || error "reintegration failed"
1433 # hardlimit should have been fetched by slave during global
1434 # reintegration, write will exceed quota
1435 $RUNAS $DD of=$TESTFILE count=$((limit + 1)) oflag=sync &&
1436 quota_error u $TSTUSR "$TSTUSR write success, expect EDQUOT"
1438 $RUNAS2 $DD of=$TESTFILE1 count=$((limit + 1)) oflag=sync &&
1439 quota_error u $TSTUSR2 "$TSTUSR2 write success, expect EDQUOT"
1443 run_test 7d "Quota reintegration (Transfer index in multiple bulks)"
1445 # quota reintegration (inode limits)
1447 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1449 # LU-2435: skip this quota test if underlying zfs version has not
1450 # supported native dnode accounting
1451 [ "$mds1_FSTYPE" == zfs ] && {
1452 local F="feature@userobj_accounting"
1453 local pool=$(zpool_name mds1)
1454 local feature=$(do_facet mds1 $ZPOOL get -H $F $pool)
1456 [[ "$feature" != *" active "* ]] &&
1457 skip "requires zpool with active userobj_accounting"
1460 local ilimit=$((1024 * 2)) # 2k inodes
1461 local TESTFILE=$DIR/${tdir}-1/$tfile
1463 setup_quota_test || error "setup quota failed with $?"
1464 trap cleanup_quota_test EXIT
1466 # make sure the system is clean
1467 local USED=$(getquota -u $TSTUSR global curinodes)
1468 [ $USED -ne 0 ] && error "Used inode($USED) for user $TSTUSR isn't 0."
1470 # make sure no granted quota on mdt1
1471 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1472 resetquota -u $TSTUSR
1473 set_mdt_qtype "none" || error "disable mdt quota failed"
1475 local MDTUUID=$(mdtuuid_from_index $((MDSCOUNT - 1)))
1476 USED=$(getquota -u $TSTUSR $MDTUUID ihardlimit)
1477 [ $USED -ne 0 ] && error "limit($USED) on $MDTUUID for user" \
1480 echo "Stop mds${MDSCOUNT}..."
1483 echo "Enable quota & set quota limit for $TSTUSR"
1484 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1485 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1486 error "set quota failed"
1488 echo "Start mds${MDSCOUNT}..."
1489 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1492 wait_mdt_reint $QTYPE || error "reintegration failed"
1494 echo "create remote dir"
1495 $LFS mkdir -i $((MDSCOUNT - 1)) $DIR/${tdir}-1 ||
1496 error "create remote dir failed"
1497 chmod 0777 $DIR/${tdir}-1
1499 # hardlimit should have been fetched by slave during global
1500 # reintegration, create will exceed quota
1501 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) &&
1502 quota_error u $TSTUSR "create succeeded, expect EDQUOT"
1504 $RUNAS unlinkmany $TESTFILE $ilimit || error "unlink files failed"
1505 wait_delete_completed
1506 sync_all_data || true
1508 echo "Stop mds${MDSCOUNT}..."
1511 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
1512 error "clear quota failed"
1514 echo "Start mds${MDSCOUNT}..."
1515 start mds${MDSCOUNT} $(mdsdevname $MDSCOUNT) $MDS_MOUNT_OPTS
1518 wait_mdt_reint $QTYPE || error "reintegration failed"
1520 # hardlimit should be cleared on slave during reintegration
1521 $RUNAS createmany -m $TESTFILE $((ilimit + 1)) ||
1522 quota_error u $TSTUSR "create failed, expect success"
1524 $RUNAS unlinkmany $TESTFILE $((ilimit + 1)) || error "unlink failed"
1525 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1529 run_test 7e "Quota reintegration (inode limits)"
1531 # run dbench with quota enabled
1533 local BLK_LIMIT="100g" #100G
1534 local FILE_LIMIT=1000000
1536 setup_quota_test || error "setup quota failed with $?"
1537 trap cleanup_quota_test EXIT
1539 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
1540 set_ost_qtype $QTYPE || error "enable ost quota failed"
1542 echo "Set enough high limit for user: $TSTUSR"
1543 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1544 error "set user quota failed"
1545 echo "Set enough high limit for group: $TSTUSR"
1546 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1547 error "set group quota failed"
1548 if is_project_quota_supported; then
1549 change_project -sp $TSTPRJID $DIR/$tdir
1550 echo "Set enough high limit for project: $TSTPRJID"
1551 $LFS setquota -p $TSTPRJID -b 0 \
1552 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1553 error "set project quota failed"
1557 [ "$SLOW" = "no" ] && duration=" -t 120"
1558 $RUNAS bash rundbench -D $DIR/$tdir 3 $duration ||
1559 quota_error a $TSTUSR "dbench failed!"
1561 is_project_quota_supported && change_project -C $DIR/$tdir
1564 run_test 8 "Run dbench with quota enabled"
1566 # this check is just for test_9
1567 OST0_MIN=4900000 #4.67G
1569 check_whether_skip () {
1570 local OST0_SIZE=$($LFS df $DIR | awk '/\[OST:0\]/ {print $4}')
1571 log "OST0_SIZE: $OST0_SIZE required: $OST0_MIN"
1572 if [ $OST0_SIZE -lt $OST0_MIN ]; then
1573 echo "WARN: OST0 has less than $OST0_MIN free, skip this test."
1580 # run for fixing bug10707, it needs a big room. test for 64bit
1582 local filesize=$((1024 * 9 / 2)) # 4.5G
1584 check_whether_skip && return 0
1586 setup_quota_test || error "setup quota failed with $?"
1587 trap cleanup_quota_test EXIT
1589 set_ost_qtype "ug" || error "enable ost quota failed"
1591 local TESTFILE="$DIR/$tdir/$tfile-0"
1592 local BLK_LIMIT=100G #100G
1593 local FILE_LIMIT=1000000
1595 echo "Set block limit $BLK_LIMIT bytes to $TSTUSR.$TSTUSR"
1597 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1599 $LFS setquota -u $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1600 error "set user quota failed"
1602 log "Set enough high limit(block:$BLK_LIMIT; file: $FILE_LIMIT)" \
1603 "for group: $TSTUSR"
1604 $LFS setquota -g $TSTUSR -b 0 -B $BLK_LIMIT -i 0 -I $FILE_LIMIT $DIR ||
1605 error "set group quota failed"
1607 quota_show_check a u $TSTUSR
1608 quota_show_check a g $TSTUSR
1610 echo "Create test file"
1611 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1612 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1614 log "Write the big file of 4.5G ..."
1615 $RUNAS $DD of=$TESTFILE count=$filesize ||
1616 quota_error a $TSTUSR "write 4.5G file failure, expect success"
1626 run_test 9 "Block limit larger than 4GB (b10707)"
1629 local TESTFILE=$DIR/$tdir/$tfile
1631 setup_quota_test || error "setup quota failed with $?"
1632 trap cleanup_quota_test EXIT
1634 # set limit to root user should fail
1635 $LFS setquota -u root -b 100G -B 500G -i 1K -I 1M $DIR &&
1636 error "set limit for root user successfully, expect failure"
1637 $LFS setquota -g root -b 1T -B 10T -i 5K -I 100M $DIR &&
1638 error "set limit for root group successfully, expect failure"
1639 $LFS setquota -p 0 -b 1T -B 10T -i 5K -I 100M $DIR &&
1640 error "set limit for project 0 successfully, expect failure"
1642 # root user can overrun quota
1643 set_ost_qtype "ug" || error "enable ost quota failed"
1645 $LFS setquota -u $TSTUSR -b 0 -B 2M -i 0 -I 0 $DIR ||
1646 error "set quota failed"
1647 quota_show_check b u $TSTUSR
1649 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
1650 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1652 runas -u 0 -g 0 $DD of=$TESTFILE count=3 oflag=sync ||
1653 error "write failure, expect success"
1657 run_test 10 "Test quota for root user"
1660 local TESTFILE=$DIR/$tdir/$tfile
1661 setup_quota_test || error "setup quota failed with $?"
1662 trap cleanup_quota_test EXIT
1664 set_mdt_qtype "ug" || error "enable mdt quota failed"
1665 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 1 $DIR ||
1666 error "set quota failed"
1668 touch "$TESTFILE"-0 || error "touch $TESTFILE-0 failed"
1669 touch "$TESTFILE"-1 || error "touch $TESTFILE-0 failed"
1671 chown $TSTUSR.$TSTUSR "$TESTFILE"-0 || error "chown $TESTFILE-0 failed"
1672 chown $TSTUSR.$TSTUSR "$TESTFILE"-1 || error "chown $TESTFILE-1 failed"
1675 local USED=$(getquota -u $TSTUSR global curinodes)
1676 [ $USED -ge 2 ] || error "Used inodes($USED) is less than 2"
1680 run_test 11 "Chown/chgrp ignores quota"
1683 [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
1685 local blimit=22 # 22M
1686 local blk_cnt=$((blimit - 5))
1687 local TESTFILE0="$DIR/$tdir/$tfile"-0
1688 local TESTFILE1="$DIR/$tdir/$tfile"-1
1690 setup_quota_test || error "setup quota failed with $?"
1691 trap cleanup_quota_test EXIT
1693 set_ost_qtype "u" || error "enable ost quota failed"
1694 quota_show_check b u $TSTUSR
1696 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $DIR ||
1697 error "set quota failed"
1699 $LFS setstripe $TESTFILE0 -c 1 -i 0 || error "setstripe $TESTFILE0 failed"
1700 $LFS setstripe $TESTFILE1 -c 1 -i 1 || error "setstripe $TESTFILE1 failed"
1701 chown $TSTUSR.$TSTUSR $TESTFILE0 || error "chown $TESTFILE0 failed"
1702 chown $TSTUSR.$TSTUSR $TESTFILE1 || error "chown $TESTFILE1 failed"
1704 echo "Write to ost0..."
1705 $RUNAS $DD of=$TESTFILE0 count=$blk_cnt oflag=sync ||
1706 quota_error a $TSTUSR "dd failed"
1708 echo "Write to ost1..."
1709 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync &&
1710 quota_error a $TSTUSR "dd succeed, expect EDQUOT"
1712 echo "Free space from ost0..."
1714 wait_delete_completed
1715 sync_all_data || true
1717 echo "Write to ost1 after space freed from ost0..."
1718 $RUNAS $DD of=$TESTFILE1 count=$blk_cnt oflag=sync ||
1719 quota_error a $TSTUSR "rebalancing failed"
1723 run_test 12a "Block quota rebalancing"
1726 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
1728 local ilimit=$((1024 * 2)) # 2k inodes
1729 local TESTFILE0=$DIR/$tdir/$tfile
1730 local TESTFILE1=$DIR/${tdir}-1/$tfile
1732 setup_quota_test || error "setup quota failed with $?"
1733 trap cleanup_quota_test EXIT
1735 $LFS mkdir -i 1 $DIR/${tdir}-1 || error "create remote dir failed"
1736 chmod 0777 $DIR/${tdir}-1
1738 set_mdt_qtype "u" || error "enable mdt quota failed"
1739 quota_show_check f u $TSTUSR
1741 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I $ilimit $DIR ||
1742 error "set quota failed"
1744 echo "Create $ilimit files on mdt0..."
1745 $RUNAS createmany -m $TESTFILE0 $ilimit ||
1746 quota_error u $TSTUSR "create failed, but expect success"
1748 echo "Create files on mdt1..."
1749 $RUNAS createmany -m $TESTFILE1 1 &&
1750 quota_error a $TSTUSR "create succeeded, expect EDQUOT"
1752 echo "Free space from mdt0..."
1753 $RUNAS unlinkmany $TESTFILE0 $ilimit || error "unlink mdt0 files failed"
1754 wait_delete_completed
1755 sync_all_data || true
1757 echo "Create files on mdt1 after space freed from mdt0..."
1758 $RUNAS createmany -m $TESTFILE1 $((ilimit / 2)) ||
1759 quota_error a $TSTUSR "rebalancing failed"
1761 $RUNAS unlinkmany $TESTFILE1 $((ilimit / 2)) ||
1762 error "unlink mdt1 files failed"
1763 rmdir $DIR/${tdir}-1 || error "unlink remote dir failed"
1767 run_test 12b "Inode quota rebalancing"
1770 local TESTFILE=$DIR/$tdir/$tfile
1771 # the name of lwp on ost1 name is MDT0000-lwp-OST0000
1772 local procf="ldlm.namespaces.*MDT0000-lwp-OST0000.lru_size"
1774 setup_quota_test || error "setup quota failed with $?"
1775 trap cleanup_quota_test EXIT
1777 set_ost_qtype "u" || error "enable ost quota failed"
1778 quota_show_check b u $TSTUSR
1780 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1781 error "set quota failed"
1782 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
1783 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1785 # clear the locks in cache first
1786 do_facet ost1 $LCTL set_param -n $procf=clear
1787 local nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1788 [ $nlock -eq 0 ] || error "$nlock cached locks"
1790 # write to acquire the per-ID lock
1791 $RUNAS $DD of=$TESTFILE count=1 oflag=sync ||
1792 quota_error a $TSTUSR "dd failed"
1794 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1795 [ $nlock -eq 1 ] || error "lock count($nlock) isn't 1"
1797 # clear quota doesn't trigger per-ID lock cancellation
1798 resetquota -u $TSTUSR
1799 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1800 [ $nlock -eq 1 ] || error "per-ID lock is lost on quota clear"
1802 # clear the per-ID lock
1803 do_facet ost1 $LCTL set_param -n $procf=clear
1804 nlock=$(do_facet ost1 $LCTL get_param -n $procf)
1805 [ $nlock -eq 0 ] || error "per-ID lock isn't cleared"
1807 # spare quota should be released
1808 local OSTUUID=$(ostuuid_from_index 0)
1809 local limit=$(getquota -u $TSTUSR $OSTUUID bhardlimit)
1810 local space=$(getquota -u $TSTUSR $OSTUUID curspace)
1811 [ $limit -le $space ] ||
1812 error "spare quota isn't released, limit:$limit, space:$space"
1816 run_test 13 "Cancel per-ID lock in the LRU list"
1819 local LIMIT=$((24 * 1024 * 1024 * 1024 * 1024)) # 24 TB
1821 wait_delete_completed
1822 sync_all_data || true
1825 $LFS setquota -u $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1826 error "set user quota failed"
1827 local TOTAL_LIMIT=$(getquota -u $TSTUSR global bhardlimit)
1828 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1829 error "(user) limit:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1830 resetquota -u $TSTUSR
1833 $LFS setquota -g $TSTUSR -b 0 -B $LIMIT -i 0 -I 0 $DIR ||
1834 error "set group quota failed"
1835 TOTAL_LIMIT=$(getquota -g $TSTUSR global bhardlimit)
1836 [ $TOTAL_LIMIT -eq $LIMIT ] ||
1837 error "(group) limits:$TOTAL_LIMIT, expect:$LIMIT, failed!"
1838 resetquota -g $TSTUSR
1840 run_test 15 "Set over 4T block quota"
1844 local BLKS=1 # 1M less than limit
1845 local TESTFILE=$DIR/$tdir/$tfile
1847 setup_quota_test || error "setup quota failed with $?"
1848 trap cleanup_quota_test EXIT
1850 # make sure the system is clean
1851 local USED=$(getquota -u $TSTUSR global curspace)
1852 [ $USED -ne 0 ] && error "Used space($USED) for user $TSTUSR isn't 0."
1854 set_ost_qtype "ug" || error "enable ost quota failed"
1855 # make sure no granted quota on ost
1856 resetquota -u $TSTUSR
1857 $LFS setquota -u $TSTUSR -b 0 -B 10M -i 0 -I 0 $DIR ||
1858 error "set quota failed"
1860 quota_show_check b u $TSTUSR
1862 #define OBD_FAIL_QUOTA_RECOVERABLE_ERR 0xa04
1863 lustre_fail mds 0xa04 $err_code
1865 # write in background
1866 $RUNAS $DD of=$TESTFILE count=$BLKS oflag=direct &
1870 # write should be blocked and never finished
1871 if ! ps -p $DDPID > /dev/null 2>&1; then
1873 quota_error u $TSTUSR "write finished incorrectly!"
1881 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1883 if [ $count -gt $timeout ]; then
1884 quota_error u $TSTUSR "dd is not finished!"
1889 sync; sync_all_data || true
1891 USED=$(getquota -u $TSTUSR global curspace)
1892 [ $USED -ge $((BLKS * 1024)) ] || quota_error u $TSTUSR \
1893 "Used space(${USED}K) is less than ${BLKS}M"
1898 # DQACQ return recoverable error
1900 echo "DQACQ return -ENOLCK"
1902 test_17sub 37 || error "Handle -ENOLCK failed"
1904 echo "DQACQ return -EAGAIN"
1906 test_17sub 11 || error "Handle -EAGAIN failed"
1908 echo "DQACQ return -ETIMEDOUT"
1909 #define ETIMEDOUT 110
1910 test_17sub 110 || error "Handle -ETIMEDOUT failed"
1912 echo "DQACQ return -ENOTCONN"
1913 #define ENOTCONN 107
1914 test_17sub 107 || error "Handle -ENOTCONN failed"
1917 run_test 17 "DQACQ return recoverable error"
1921 local blimit="200m" # 200M
1922 local TESTFILE="$DIR/$tdir/$tfile"
1924 setup_quota_test || error "setup quota failed with $?"
1925 trap cleanup_quota_test EXIT
1927 set_ost_qtype "u" || error "enable ost quota failed"
1928 log "User quota (limit: $blimit)"
1929 $LFS setquota -u $TSTUSR -b 0 -B $blimit -i 0 -I 0 $MOUNT ||
1930 error "set quota failed"
1931 quota_show_check b u $TSTUSR
1933 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
1934 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
1936 local timeout=$(sysctl -n lustre.timeout)
1938 if [ $io_type = "directio" ]; then
1939 log "Write 100M (directio) ..."
1940 $RUNAS $DD of=$TESTFILE count=100 oflag=direct &
1942 log "Write 100M (buffered) ..."
1943 $RUNAS $DD of=$TESTFILE count=100 &
1947 replay_barrier $SINGLEMDS
1948 log "Fail mds for $((2 * timeout)) seconds"
1949 fail $SINGLEMDS $((2 * timeout))
1952 if at_is_enabled; then
1953 timeout=$(at_max_get mds)
1955 timeout=$(lctl get_param -n timeout)
1959 if ! ps -p ${DDPID} > /dev/null 2>&1; then break; fi
1960 if [ $((++count % (2 * timeout) )) -eq 0 ]; then
1961 log "it took $count second"
1966 log "(dd_pid=$DDPID, time=$count, timeout=$timeout)"
1968 cancel_lru_locks mdc
1969 cancel_lru_locks osc
1972 local testfile_size=$(stat -c %s $TESTFILE)
1973 if [ $testfile_size -ne $((BLK_SZ * 1024 * 100)) ] ; then
1974 quota_error u $TSTUSR "expect $((BLK_SZ * 1024 * 100))," \
1975 "got ${testfile_size}. Verifying file failed!"
1980 # test when mds does failover, the ost still could work well
1981 # this test shouldn't trigger watchdog b=14840
1983 # Clear dmesg so watchdog is not triggered by previous
1985 do_facet ost1 dmesg -c > /dev/null
1988 test_18_sub directio
1990 # check if watchdog is triggered
1991 do_facet ost1 dmesg > $TMP/lustre-log-${TESTNAME}.log
1992 local watchdog=$(awk '/[Ss]ervice thread pid/ && /was inactive/ \
1993 { print; }' $TMP/lustre-log-${TESTNAME}.log)
1994 [ -z "$watchdog" ] || error "$watchdog"
1995 rm -f $TMP/lustre-log-${TESTNAME}.log
1997 run_test 18 "MDS failover while writing, no watchdog triggered (b14840)"
2001 local TESTFILE=$DIR/$tdir/$tfile
2003 setup_quota_test || error "setup quota failed with $?"
2004 trap cleanup_quota_test EXIT
2006 set_ost_qtype $QTYPE || error "enable ost quota failed"
2008 # bind file to a single OST
2009 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2010 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2012 echo "Set user quota (limit: ${blimit}M)"
2013 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2014 error "set user quota failed"
2015 quota_show_check b u $TSTUSR
2016 echo "Update quota limits"
2017 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2018 error "set group quota failed"
2019 quota_show_check b u $TSTUSR
2021 # first wirte might be cached
2022 $RUNAS $DD of=$TESTFILE count=$((blimit + 1))
2023 cancel_lru_locks osc
2025 $RUNAS $DD of=$TESTFILE count=$((blimit + 1)) seek=$((blimit + 1)) &&
2026 quota_error u $TSTUSR "Write success, expect failure"
2031 run_test 19 "Updating admin limits doesn't zero operational limits(b14790)"
2033 test_20() { # b15754
2034 local LSTR=(2g 1t 4k 3m) # limits strings
2036 local LVAL=($((2*1024*1024)) $((1*1024*1024*1024)) $((4*1024)) \
2039 resetquota -u $TSTUSR
2041 $LFS setquota -u $TSTUSR --block-softlimit ${LSTR[0]} \
2042 $MOUNT || error "could not set quota limits"
2043 $LFS setquota -u $TSTUSR --block-hardlimit ${LSTR[1]} \
2044 --inode-softlimit ${LSTR[2]} \
2045 --inode-hardlimit ${LSTR[3]} \
2046 $MOUNT || error "could not set quota limits"
2048 [ "$(getquota -u $TSTUSR global bsoftlimit)" = "${LVAL[0]}" ] ||
2049 error "bsoftlimit was not set properly"
2050 [ "$(getquota -u $TSTUSR global bhardlimit)" = "${LVAL[1]}" ] ||
2051 error "bhardlimit was not set properly"
2052 [ "$(getquota -u $TSTUSR global isoftlimit)" = "${LVAL[2]}" ] ||
2053 error "isoftlimit was not set properly"
2054 [ "$(getquota -u $TSTUSR global ihardlimit)" = "${LVAL[3]}" ] ||
2055 error "ihardlimit was not set properly"
2057 resetquota -u $TSTUSR
2059 run_test 20 "Test if setquota specifiers work properly (b15754)"
2066 local time=$(($(date +%s) + seconds))
2067 while [ $(date +%s) -lt $time ]; do
2068 $RUNAS $DD of=$testfile count=$blk_number > /dev/null 2>&1
2072 # run for fixing bug16053, setquota shouldn't fail when writing and
2073 # deleting are happening
2075 local TESTFILE="$DIR/$tdir/$tfile"
2076 local BLIMIT=10 # 10G
2077 local ILIMIT=1000000
2079 setup_quota_test || error "setup quota failed with $?"
2080 trap cleanup_quota_test EXIT
2082 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2084 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
2085 $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
2086 error "set user quota failed"
2087 log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
2088 $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
2089 error "set group quota failed"
2090 if is_project_quota_supported; then
2091 log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
2092 "project: $TSTPRJID"
2093 $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
2094 $MOUNT || error "set project quota failed"
2097 # repeat writing on a 1M file
2098 test_21_sub ${TESTFILE}_1 1 30 &
2100 # repeat writing on a 128M file
2101 test_21_sub ${TESTFILE}_2 128 30 &
2104 local time=$(($(date +%s) + 30))
2106 while [ $(date +%s) -lt $time ]; do
2107 log "Set quota for $i times"
2108 $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2109 -I $((ILIMIT + i)) $MOUNT ||
2110 error "Set user quota failed"
2111 $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
2112 -I $((ILIMIT + i)) $MOUNT ||
2113 error "Set group quota failed"
2114 if is_project_quota_supported; then
2115 $LFS setquota -p $TSTPRJID -b 0 -B \
2116 "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
2117 error "Set project quota failed"
2125 if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
2127 if [ $count -gt 60 ]; then
2128 quota_error a $TSTUSR "dd should be finished!"
2132 echo "(dd_pid=$DDPID1, time=$count)successful"
2136 if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
2138 if [ $count -gt 60 ]; then
2139 quota_error a $TSTUSR "dd should be finished!"
2143 echo "(dd_pid=$DDPID2, time=$count)successful"
2147 run_test 21 "Setquota while writing & deleting (b16053)"
2149 # enable/disable quota enforcement permanently
2151 echo "Set both mdt & ost quota type as ug"
2153 is_project_quota_supported && qtype=$QTYPE
2154 set_mdt_qtype $qtype || error "enable mdt quota failed"
2155 set_ost_qtype $qtype || error "enable ost quota failed"
2158 stopall || error "failed to stopall (1)"
2162 echo "Verify if quota is enabled"
2163 local qtype1=$(mdt_quota_type)
2164 [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
2165 qtype=$(ost_quota_type)
2166 [ $qtype1 != $qtype ] && error "ost quota setting is lost"
2168 echo "Set both mdt & ost quota type as none"
2169 set_mdt_qtype "none" || error "disable mdt quota failed"
2170 set_ost_qtype "none" || error "disable ost quota failed"
2173 stopall || error "failed to stopall (2)"
2178 echo "Verify if quota is disabled"
2179 qtype=$(mdt_quota_type)
2180 [ $qtype != "none" ] && error "mdt quota setting is lost"
2181 qtype=$(ost_quota_type)
2182 [ $qtype != "none" ] && error "ost quota setting is lost"
2186 run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
2189 local TESTFILE="$DIR/$tdir/$tfile"
2192 setup_quota_test || error "setup quota failed with $?"
2193 trap cleanup_quota_test EXIT
2195 set_ost_qtype $QTYPE || error "Enable ost quota failed"
2198 log "User quota (limit: $LIMIT MB)"
2199 $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
2200 error "set quota failed"
2201 quota_show_check b u $TSTUSR
2203 $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
2204 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2206 log "Step1: trigger EDQUOT with O_DIRECT"
2207 log "Write half of file"
2208 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
2209 quota_error u $TSTUSR "(1) Write failure, expect success." \
2211 log "Write out of block quota ..."
2212 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
2213 oflag=direct conv=notrunc &&
2214 quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
2218 log "Step2: rewrite should succeed"
2219 $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
2220 quota_error u $TSTUSR "(3) Write failure, expect success." \
2226 local OST0_UUID=$(ostuuid_from_index 0)
2227 local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
2228 [ $OST0_QUOTA_USED -ne 0 ] &&
2229 ($SHOW_QUOTA_USER; \
2230 quota_error u $TSTUSR "quota isn't released")
2235 [ "$ost1_FSTYPE" == zfs ] &&
2236 skip "Overwrite in place is not guaranteed to be " \
2237 "space neutral on ZFS"
2239 local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
2240 check_whether_skip && return 0
2241 log "run for 4MB test file"
2244 OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
2245 check_whether_skip && return 0
2246 log "run for 40MB test file"
2249 run_test 23 "Quota should be honored with directIO (b16125)"
2253 local TESTFILE="$DIR/$tdir/$tfile"
2255 setup_quota_test || error "setup quota failed with $?"
2256 trap cleanup_quota_test EXIT
2258 set_ost_qtype $QTYPE || error "enable ost quota failed"
2260 # bind file to a single OST
2261 $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
2262 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2264 echo "Set user quota (limit: ${blimit}M)"
2265 $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
2266 error "set quota failed"
2268 # overrun quota by root user
2269 runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
2270 error "write failure, expect success"
2271 cancel_lru_locks osc
2272 sync_all_data || true
2274 $SHOW_QUOTA_USER | grep '*' || error "no matching *"
2278 run_test 24 "lfs draws an asterix when limit is reached (b16646)"
2280 test_27a() { # b19612
2281 $LFS quota $TSTUSR $DIR &&
2282 error "lfs succeeded with no type, but should have failed"
2283 $LFS setquota $TSTUSR $DIR &&
2284 error "lfs succeeded with no type, but should have failed"
2287 run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
2289 test_27b() { # b20200
2290 $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2291 error "lfs setquota failed with uid argument"
2292 $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
2293 error "lfs stequota failed with gid argument"
2294 if is_project_quota_supported; then
2295 $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
2296 1000 $DIR || error \
2297 "lfs stequota failed with projid argument"
2299 $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
2300 $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
2301 if is_project_quota_supported; then
2302 $SHOW_QUOTA_PROJID ||
2303 error "lfs quota failed with projid argument"
2305 resetquota -u $TSTID
2306 resetquota -g $TSTID
2307 resetquota -p $TSTPRJID
2310 run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
2315 $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
2316 error "lfs setquota failed"
2318 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2319 [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
2320 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2321 [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
2323 $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
2324 error "lfs setquota for $TSTID failed"
2326 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
2327 [ $limit != "1.465G" ] && error "wrong softlimit $limit"
2328 limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
2329 [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
2331 $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
2332 error "total allocated inode/block limit not printed"
2334 resetquota -u $TSTUSR
2336 run_test 27c "lfs quota should support human-readable output"
2343 $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
2344 error "set fraction block limit failed"
2345 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
2346 [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
2347 limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
2348 [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
2350 resetquota -u $TSTUSR
2352 run_test 27d "lfs setquota should support fraction block limit"
2356 local TESTFILE="$DIR/$tdir/$tfile"
2359 setup_quota_test || error "setup quota failed with $?"
2360 trap cleanup_quota_test EXIT
2362 set_ost_qtype "u" || error "enable ost quota failed"
2364 $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
2365 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
2367 $LFS setquota -t -u --block-grace $GRACE --inode-grace \
2368 $MAX_IQ_TIME $DIR || error "set grace time failed"
2369 $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
2370 error "set quota failed"
2371 $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
2372 cancel_lru_locks osc
2374 $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
2375 # over-quota flag has not yet settled since we do not trigger async
2376 # events based on grace time period expiration
2378 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
2379 cancel_lru_locks osc
2380 # now over-quota flag should be settled and further writes should fail
2382 $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
2383 error "grace times were reset"
2386 $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
2387 $MAX_IQ_TIME $DIR || error "restore grace time failed"
2389 run_test 30 "Hard limit updates should not reset grace times"
2391 # basic usage tracking for user & group
2393 local INODES=10 # 10 files
2394 local BLK_CNT=2 # of 2M each
2395 local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
2397 setup_quota_test || error "setup quota failed with $?"
2398 trap cleanup_quota_test EXIT
2400 # make sure the system is clean
2401 local USED=$(getquota -u $TSTID global curspace)
2403 error "Used space ($USED) for user $TSTID isn't 0."
2404 USED=$(getquota -g $TSTID global curspace)
2406 error "Used space ($USED) for group $TSTID isn't 0."
2407 if is_project_quota_supported; then
2408 USED=$(getquota -p $TSTPRJID global curspace)
2409 [ $USED -ne 0 ] && error \
2410 "Used space ($USED) for project $TSTPRJID isn't 0."
2413 echo "Write files..."
2414 for i in $(seq 0 $INODES); do
2415 $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
2416 error "write failed"
2417 is_project_quota_supported &&
2418 change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
2419 echo "Iteration $i/$INODES completed"
2421 cancel_lru_locks osc
2423 echo "Wait for setattr on objects finished..."
2424 wait_delete_completed
2426 sync; sync_all_data || true
2428 echo "Verify disk usage after write"
2429 USED=$(getquota -u $TSTID global curspace)
2430 [ $USED -lt $TOTAL_BLKS ] &&
2431 error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
2432 USED=$(getquota -g $TSTID global curspace)
2433 [ $USED -lt $TOTAL_BLKS ] &&
2434 error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
2435 if is_project_quota_supported; then
2436 USED=$(getquota -p $TSTPRJID global curspace)
2437 [ $USED -lt $TOTAL_BLKS ] && error \
2438 "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
2441 echo "Verify inode usage after write"
2442 USED=$(getquota -u $TSTID global curinodes)
2443 [ $USED -lt $INODES ] &&
2444 error "Used inode for user $TSTID is $USED, expected $INODES"
2445 USED=$(getquota -g $TSTID global curinodes)
2446 [ $USED -lt $INODES ] &&
2447 error "Used inode for group $TSTID is $USED, expected $INODES"
2448 if is_project_quota_supported; then
2449 USED=$(getquota -p $TSTPRJID global curinodes)
2450 [ $USED -lt $INODES ] && error \
2451 "Used inode for project $TSTPRJID is $USED, expected $INODES"
2456 echo "Verify disk usage after delete"
2457 USED=$(getquota -u $TSTID global curspace)
2458 [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
2459 USED=$(getquota -u $TSTID global curinodes)
2460 [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
2461 USED=$(getquota -g $TSTID global curspace)
2462 [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
2463 USED=$(getquota -g $TSTID global curinodes)
2464 [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
2465 if is_project_quota_supported; then
2466 USED=$(getquota -p $TSTPRJID global curspace)
2468 error "Used space for project $TSTPRJID isn't 0. $USED"
2469 USED=$(getquota -p $TSTPRJID global curinodes)
2471 error "Used inodes for project $TSTPRJID isn't 0. $USED"
2474 run_test 33 "Basic usage tracking for user & group & project"
2476 # usage transfer test for user & group & project
2478 local BLK_CNT=2 # 2MB
2479 local project_supported="no"
2481 is_project_quota_supported && project_supported="yes"
2482 setup_quota_test || error "setup quota failed with $?"
2483 trap cleanup_quota_test EXIT
2485 # make sure the system is clean
2486 local USED=$(getquota -u $TSTID global curspace)
2487 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID isn't 0."
2488 USED=$(getquota -g $TSTID global curspace)
2489 [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
2491 local USED=$(getquota -u $TSTID2 global curspace)
2492 [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
2493 if [ $project_supported == "yes" ]; then
2494 USED=$(getquota -p $TSTPRJID global curspace)
2495 [ $USED -ne 0 ] && error \
2496 "Used space ($USED) for Project $TSTPRJID isn't 0."
2499 echo "Write file..."
2500 $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2501 error "write failed"
2502 cancel_lru_locks osc
2503 sync; sync_all_data || true
2505 echo "chown the file to user $TSTID"
2506 chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
2508 echo "Wait for setattr on objects finished..."
2509 wait_delete_completed
2511 BLK_CNT=$((BLK_CNT * 1024))
2513 echo "Verify disk usage for user $TSTID"
2514 USED=$(getquota -u $TSTID global curspace)
2515 [ $USED -lt $BLK_CNT ] &&
2516 error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
2517 USED=$(getquota -u $TSTID global curinodes)
2519 error "Used inodes for user $TSTID is $USED, expected 1"
2521 echo "chgrp the file to group $TSTID"
2522 chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
2524 echo "Wait for setattr on objects finished..."
2525 wait_delete_completed
2527 echo "Verify disk usage for group $TSTID"
2528 USED=$(getquota -g $TSTID global curspace)
2529 [ $USED -ge $BLK_CNT ] ||
2530 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2531 USED=$(getquota -g $TSTID global curinodes)
2533 error "Used inodes for group $TSTID is $USED, expected 1"
2535 # chown won't change the ost object group. LU-4345 */
2536 echo "chown the file to user $TSTID2"
2537 chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
2539 echo "Wait for setattr on objects finished..."
2540 wait_delete_completed
2542 echo "change_project project id to $TSTPRJID"
2543 [ $project_supported == "yes" ] &&
2544 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2545 echo "Wait for setattr on objects finished..."
2546 wait_delete_completed
2548 echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
2549 USED=$(getquota -u $TSTID2 global curspace)
2550 [ $USED -lt $BLK_CNT ] &&
2551 error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
2552 USED=$(getquota -u $TSTID global curspace)
2554 error "Used space for user $TSTID is $USED, expected 0"
2555 USED=$(getquota -g $TSTID global curspace)
2556 [ $USED -lt $BLK_CNT ] &&
2557 error "Used space for group $TSTID is $USED, expected $BLK_CNT"
2558 if [ $project_supported == "yes" ]; then
2559 USED=$(getquota -p $TSTPRJID global curspace)
2560 [ $USED -lt $BLK_CNT ] && error \
2561 "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
2566 run_test 34 "Usage transfer for user & group & project"
2568 # usage is still accessible across restart
2570 local BLK_CNT=2 # 2 MB
2572 setup_quota_test || error "setup quota failed with $?"
2573 trap cleanup_quota_test EXIT
2575 echo "Write file..."
2576 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
2577 error "write failed"
2578 is_project_quota_supported &&
2579 change_project -p $TSTPRJID $DIR/$tdir/$tfile
2580 cancel_lru_locks osc
2582 echo "Wait for setattr on objects finished..."
2583 wait_delete_completed
2585 sync; sync_all_data || true
2587 echo "Save disk usage before restart"
2588 local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
2589 [ $ORIG_USR_SPACE -eq 0 ] &&
2590 error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
2591 local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
2592 [ $ORIG_USR_INODES -eq 0 ] &&
2593 error "Used inodes for user $TSTID is 0, expected 1"
2594 echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
2595 local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
2596 [ $ORIG_GRP_SPACE -eq 0 ] &&
2597 error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
2598 local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
2599 [ $ORIG_GRP_INODES -eq 0 ] &&
2600 error "Used inodes for group $TSTID is 0, expected 1"
2601 echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
2603 if is_project_quota_supported; then
2604 local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
2605 [ $ORIG_PRJ_SPACE -eq 0 ] && error \
2606 "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
2607 local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
2608 [ $ORIG_PRJ_INODES -eq 0 ] && error \
2609 "Used inodes for project $TSTPRJID is 0, expected 1"
2610 echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
2618 echo "Verify disk usage after restart"
2619 local USED=$(getquota -u $TSTID global curspace)
2620 [ $USED -eq $ORIG_USR_SPACE ] ||
2621 error "Used space for user $TSTID changed from " \
2622 "$ORIG_USR_SPACE to $USED"
2623 USED=$(getquota -u $TSTID global curinodes)
2624 [ $USED -eq $ORIG_USR_INODES ] ||
2625 error "Used inodes for user $TSTID changed from " \
2626 "$ORIG_USR_INODES to $USED"
2627 USED=$(getquota -g $TSTID global curspace)
2628 [ $USED -eq $ORIG_GRP_SPACE ] ||
2629 error "Used space for group $TSTID changed from " \
2630 "$ORIG_GRP_SPACE to $USED"
2631 USED=$(getquota -g $TSTID global curinodes)
2632 [ $USED -eq $ORIG_GRP_INODES ] ||
2633 error "Used inodes for group $TSTID changed from " \
2634 "$ORIG_GRP_INODES to $USED"
2635 if [ $project_supported == "yes" ]; then
2636 USED=$(getquota -p $TSTPRJID global curinodes)
2637 [ $USED -eq $ORIG_PRJ_INODES ] ||
2638 error "Used inodes for project $TSTPRJID " \
2639 "changed from $ORIG_PRJ_INODES to $USED"
2640 USED=$(getquota -p $TSTPRJID global curspace)
2641 [ $USED -eq $ORIG_PRJ_SPACE ] ||
2642 error "Used space for project $TSTPRJID "\
2643 "changed from $ORIG_PRJ_SPACE to $USED"
2646 # check if the vfs_dq_init() is called before writing
2647 echo "Append to the same file..."
2648 $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
2649 error "write failed"
2650 cancel_lru_locks osc
2651 sync; sync_all_data || true
2653 echo "Verify space usage is increased"
2654 USED=$(getquota -u $TSTID global curspace)
2655 [ $USED -gt $ORIG_USR_SPACE ] ||
2656 error "Used space for user $TSTID isn't increased" \
2657 "orig:$ORIG_USR_SPACE, now:$USED"
2658 USED=$(getquota -g $TSTID global curspace)
2659 [ $USED -gt $ORIG_GRP_SPACE ] ||
2660 error "Used space for group $TSTID isn't increased" \
2661 "orig:$ORIG_GRP_SPACE, now:$USED"
2662 if [ $project_supported == "yes" ]; then
2663 USED=$(getquota -p $TSTPRJID global curspace)
2664 [ $USED -gt $ORIG_PRJ_SPACE ] ||
2665 error "Used space for project $TSTPRJID isn't " \
2666 "increased orig:$ORIG_PRJ_SPACE, now:$USED"
2671 run_test 35 "Usage is still accessible across reboot"
2673 # chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
2676 [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
2677 skip "Old server doesn't have LU-5006 fix."
2679 setup_quota_test || error "setup quota failed with $?"
2680 trap cleanup_quota_test EXIT
2682 # make sure the system is clean
2683 local USED=$(getquota -u $TSTID global curspace)
2685 error "Used space ($USED) for user $TSTID isn't 0."
2687 # create file with MDS_OPEN_DELAY_CREATE flag
2688 $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
2689 error "Create file failed"
2691 dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
2692 oflag=sync || error "Write file failed"
2694 chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
2696 # wait for setattr on objects finished..."
2697 wait_delete_completed
2699 USED=$(getquota -u $TSTID global curspace)
2700 [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
2704 run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
2708 [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
2709 skip "Old server doesn't have LU-8801 fix."
2711 [ "$UID" != 0 ] && skip_env "must run as root" && return
2713 setup_quota_test || error "setup quota failed with $?"
2714 trap cleanup_quota_test EXIT
2716 # make sure the system is clean
2717 local USED=$(getquota -u $TSTID global curspace)
2719 error "Used space ($USED) for user $TSTID isn't 0."
2720 USED=$(getquota -u $TSTID2 global curspace)
2722 error "Used space ($USED) for user $TSTID2 isn't 0."
2724 local TESTFILE="$DIR/$tdir/$tfile"
2725 local file_cnt=10000
2727 # Generate id entries in accounting file
2728 echo "Create $file_cnt files..."
2729 for i in `seq $file_cnt`; do
2731 chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
2732 error "failed to chown $TESTFILE-$i"
2734 cancel_lru_locks osc
2735 sync; sync_all_data || true
2737 local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
2738 procf=${procf}.quota_slave.acct_user
2741 acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
2742 awk '{if ($3 < 10000) {print $3}}' | wc -l)
2743 echo "Found $acct_cnt id entries"
2745 [ $file_cnt -eq $acct_cnt ] || {
2746 do_facet mds1 $LCTL get_param $procf
2747 error "skipped id entries"
2752 run_test 38 "Quota accounting iterator doesn't skip id entries"
2755 local TESTFILE="$DIR/$tdir/project"
2756 ! is_project_quota_supported &&
2757 skip "Project quota is not supported"
2759 setup_quota_test || error "setup quota failed with $?"
2762 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2763 [ $projectid -ne 0 ] &&
2764 error "Project id should be 0 not $projectid"
2765 change_project -p 1024 $TESTFILE
2766 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2767 [ $projectid -ne 1024 ] &&
2768 error "Project id should be 1024 not $projectid"
2770 stopall || error "failed to stopall (1)"
2773 projectid=$(lfs project $TESTFILE | awk '{print $1}')
2774 [ $projectid -ne 1024 ] &&
2775 error "Project id should be 1024 not $projectid"
2779 run_test 39 "Project ID interface works correctly"
2782 ! is_project_quota_supported &&
2783 skip "Project quota is not supported"
2784 local dir1="$DIR/$tdir/dir1"
2785 local dir2="$DIR/$tdir/dir2"
2787 setup_quota_test || error "setup quota failed with $?"
2789 mkdir -p $dir1 $dir2
2790 change_project -sp 1 $dir1 && touch $dir1/1
2791 change_project -sp 2 $dir2
2793 ln $dir1/1 $dir2/1_link &&
2794 error "Hard link across different project quota should fail"
2799 run_test 40a "Hard link across different project ID"
2802 ! is_project_quota_supported &&
2803 skip "Project quota is not supported"
2804 local dir1="$DIR/$tdir/dir1"
2805 local dir2="$DIR/$tdir/dir2"
2807 setup_quota_test || error "setup quota failed with $?"
2808 mkdir -p $dir1 $dir2
2809 change_project -sp 1 $dir1 && touch $dir1/1
2810 change_project -sp 2 $dir2
2812 mv $dir1/1 $dir2/2 || error "mv failed $?"
2813 local projid=$(lfs project $dir2/2 | awk '{print $1}')
2814 if [ "$projid" != "2" ]; then
2815 error "project id expected 2 not $projid"
2820 run_test 40b "Mv across different project ID"
2823 [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
2824 ! is_project_quota_supported &&
2825 skip "Project quota is not supported"
2827 setup_quota_test || error "setup quota failed with $?"
2828 local dir="$DIR/$tdir/dir"
2830 mkdir -p $dir && change_project -sp 1 $dir
2831 $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
2832 local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
2833 [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
2834 touch $dir/remote_dir/file
2835 #verify inherit works file for remote dir.
2836 local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
2837 [ "$projid" != "1" ] &&
2838 error "file under remote dir expected 1 not $projid"
2840 #Agent inode should be ignored for project quota
2841 USED=$(getquota -p 1 global curinodes)
2842 [ "$USED" != "3" ] &&
2843 error "file count expected 3 got $USED"
2849 run_test 40c "Remote child Dir inherit project quota properly"
2852 ! is_project_quota_supported &&
2853 skip "Project quota is not supported"
2855 setup_quota_test || error "setup quota failed with $?"
2856 local dir1="$DIR/$tdir/dir1"
2857 local dir2="$DIR/$tdir/dir2"
2859 mkdir -p $dir1 && change_project -sp 1 $dir1
2860 mkdir -p $dir2 && change_project -sp 2 $dir2
2861 for num in $(seq 1 10); do
2862 touch $dir1/file_$num $dir2/file_$num
2863 ln -s $dir1/file_$num $dir1/file_$num"_link"
2864 ln -s $dir2/file_$num $dir2/file_$num"_link"
2867 count=$($LFS find --projid 1 $DIR | wc -l)
2868 [ "$count" != 21 ] && error "expected 21 but got $count"
2870 # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
2871 count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
2872 [ "$count" != 22 ] && error "expected 22 but got $count"
2877 run_test 50 "Test if lfs find --projid works"
2880 ! is_project_quota_supported &&
2881 skip "Project quota is not supported"
2882 setup_quota_test || error "setup quota failed with $?"
2883 local dir="$DIR/$tdir/dir"
2885 mkdir $dir && change_project -sp 1 $dir
2886 local used=$(getquota -p 1 global curinodes)
2887 [ $used != "1" ] && error "expected 1 got $used"
2892 used=$(getquota -p 1 global curinodes)
2893 [ $used != "4" ] && error "expected 4 got $used"
2895 $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
2897 cp $DIR/$tdir/6 $dir/6
2898 used=$(getquota -p 1 global curinodes)
2899 [ $used != "5" ] && error "expected 5 got $used"
2902 mv $DIR/$tdir/6 $dir/7
2903 used=$(getquota -p 1 global curinodes)
2904 [ $used != "6" ] && error "expected 6 got $used"
2909 run_test 51 "Test project accounting with mv/cp"
2912 ! is_project_quota_supported &&
2913 skip "Project quota is not supported"
2914 setup_quota_test || error "setup quota failed with $?"
2915 local dir="$DIR/$tdir/dir"
2916 mkdir $dir && change_project -sp 1 $dir
2918 touch $DIR/$tdir/file
2919 #Try renaming a file into the project. This should fail.
2920 for num in $(seq 1 2000); do
2921 mrename $DIR/$tdir/file $dir/file >&/dev/null &&
2922 error "rename should fail"
2927 run_test 52 "Rename across different project ID"
2930 ! is_project_quota_supported &&
2931 skip "Project quota is not supported"
2932 setup_quota_test || error "setup quota failed with $?"
2933 local dir="$DIR/$tdir/dir"
2934 mkdir $dir && change_project -s $dir
2935 lfs project -d $dir | grep P || error "inherit attribute should be set"
2937 change_project -C $dir
2938 lfs project -d $dir | grep P &&
2939 error "inherit attribute should be cleared"
2944 run_test 53 "Project inherit attribute could be cleared"
2947 ! is_project_quota_supported &&
2948 skip "Project quota is not supported"
2949 setup_quota_test || error "setup quota failed with $?"
2950 trap cleanup_quota_test EXIT
2951 local testfile="$DIR/$tdir/$tfile-0"
2953 #set project ID/inherit attribute
2954 change_project -sp $TSTPRJID $DIR/$tdir
2955 $RUNAS createmany -m ${testfile} 100 ||
2956 error "create many files failed"
2958 local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
2959 # one more count for directory itself */
2963 local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2964 [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
2966 proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
2967 [ $proj_count1 -eq $proj_count ] ||
2968 error "c2: expected $proj_count got $proj_count1"
2970 #clear project but with kept projid
2971 change_project -rCk $DIR/$tdir
2972 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2973 [ $proj_count1 -eq 1 ] ||
2974 error "c3: expected 1 got $proj_count1"
2976 #verify projid untouched.
2977 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2979 [ $proj_count1 -eq $proj_count ] ||
2980 error "c4: expected $proj_count got $proj_count1"
2983 lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
2984 proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
2985 [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
2987 #this time clear all
2988 change_project -rC $DIR/$tdir
2989 proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
2990 [ $proj_count1 -eq 0 ] ||
2991 error "c6: expected 0 got $proj_count1"
2993 unlinkmany ${testfile} 100 ||
2994 error "unlink many files failed"
2998 run_test 54 "basic lfs project interface test"
3001 [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
3002 skip "Not supported before 2.10.58."
3003 setup_quota_test || error "setup quota failed with $?"
3005 set_ost_qtype $QTYPE || error "enable ost quota failed"
3008 #add second group to TSTUSR
3009 usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
3012 $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
3013 error "failed to dd"
3015 cancel_lru_locks osc
3016 sync; sync_all_data || true
3018 $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
3019 error "failed to setquota on group $TSTUSR2"
3021 $LFS quota -v -g $TSTUSR2 $DIR
3023 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
3024 error "chgrp should failed with -EDQUOT"
3026 USED=$(getquota -g $TSTUSR2 global curspace)
3029 $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
3030 error "failed to setquota on group $TSTUSR2"
3032 $LFS quota -v -g $TSTUSR2 $DIR
3034 runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
3035 error "chgrp should succeed"
3037 $LFS quota -v -g $TSTUSR2 $DIR
3041 run_test 55 "Chgrp should be affected by group quota"
3044 setup_quota_test || error "setup quota failed with $?"
3046 set_ost_qtype $QTYPE || error "enable ost quota failed"
3049 $LFS setquota -t -u -b 10 -i 10 $DIR ||
3050 erro "failed to set grace time for usr quota"
3051 grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
3052 awk '{print $4 $8}')
3053 if [ "x$grace_time" != "x10s;10s" ]; then
3054 $LFS quota -t -u $DIR
3055 error "expected grace time: 10s;10s, got:$grace_time"
3060 run_test 56 "lfs quota -t should work well"
3063 setup_quota_test || error "setup quota failed with $?"
3065 local dir="$DIR/$tdir/dir"
3068 #try to change pipe file should not hang and return failure
3069 wait_update_facet client "$LFS project -sp 1 $dir/pipe 2>&1 |
3070 awk -F ':' '{ print \\\$2 }'" \
3071 " unable to get xattr for fifo '$dir/pipe'" || return 1
3072 #command can process further if it hit some errors
3073 touch $dir/aaa $dir/bbb
3074 mkdir $dir/subdir -p
3075 touch $dir/subdir/aaa $dir/subdir/bbb
3076 #create one invalid link file
3077 ln -s $dir/not_exist_file $dir/ccc
3078 local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
3079 [ $cnt -eq 5 ] || error "expected 5 got $cnt"
3083 run_test 57 "lfs project could tolerate errors"
3086 [ "$mds1_FSTYPE" != ldiskfs ] &&
3087 skip "ldiskfs only test"
3088 disable_project_quota
3089 setup_quota_test || error "setup quota failed with $?"
3092 local testfile="$DIR/$tdir/$tfile-0"
3093 #make sure it did not crash kernel
3094 touch $testfile && lfs project -sp 1 $testfile
3096 enable_project_quota
3099 run_test 59 "lfs project dosen't crash kernel with project disabled"
3102 [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
3103 skip "Needs MDS version 2.11.53 or later."
3104 setup_quota_test || error "setup quota failed with $?"
3105 trap cleanup_quota_test EXIT
3107 local testfile=$DIR/$tdir/$tfile
3110 set_mdt_qtype "ug" || error "enable mdt quota failed"
3112 $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
3113 error "set quota failed"
3114 quota_show_check a g $TSTUSR
3116 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
3117 chmod g+s $DIR/$tdir || error "chmod g+s failed"
3118 $RUNAS createmany -m ${testfile} $((limit-1)) ||
3119 error "create many files failed"
3121 $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
3123 # root user can overrun quota
3124 runas -u 0 -g 0 touch $DIR/$tdir/foo ||
3125 error "root user should succeed"
3129 run_test 60 "Test quota for root with setgid"
3131 # test default quota
3132 test_default_quota() {
3133 [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
3134 skip "Not supported before 2.11.51."
3139 local qprjid=$TSTPRJID
3143 local LIMIT=20480 #20M disk space
3144 local TESTFILE="$DIR/$tdir/$tfile-0"
3146 [ $qtype == "-p" ] && ! is_project_quota_supported &&
3147 echo "Project quota is not supported" && return 0
3149 [ $qtype == "-u" ] && qdtype="-U"
3150 [ $qtype == "-g" ] && qdtype="-G"
3151 [ $qtype == "-p" ] && {
3156 [ $qpool == "meta" ] && {
3157 LIMIT=10240 #10K inodes
3162 setup_quota_test || error "setup quota failed with $?"
3163 trap cleanup_quota_test EXIT
3167 # enable mdt/ost quota
3168 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3169 set_ost_qtype $QTYPE || error "enable ost quota failed"
3171 log "set to use default quota"
3172 $LFS setquota $qtype $qid -d $DIR ||
3173 error "set $qid to use default quota failed"
3175 log "set default quota"
3176 $LFS setquota $qdtype $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3177 error "set $qid default quota failed"
3179 log "get default quota"
3180 $LFS quota $qdtype $DIR || error "get default quota failed"
3182 if [ $qpool == "data" ]; then
3183 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3185 [ $SLIMIT -eq $LIMIT ] ||
3186 error "the returned default quota is wrong"
3188 local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
3190 [ $SLIMIT -eq $LIMIT ] ||
3191 error "the returned default quota is wrong"
3194 # make sure the system is clean
3195 local USED=$(getquota $qtype $qid global curspace)
3196 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3198 $LFS setstripe $TESTFILE -c 1 || error "setstripe $TESTFILE failed"
3199 chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
3201 [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
3203 log "Test not out of quota"
3204 if [ $qpool == "data" ]; then
3205 $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
3206 quota_error $qtype $qid "write failed, expect succeed"
3208 $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
3209 quota_error $qtype $qid "create failed, expect succeed"
3211 unlinkmany $TESTFILE $((LIMIT/2))
3214 log "Test out of quota"
3215 # flush cache, ensure noquota flag is set on client
3216 cancel_lru_locks osc
3217 cancel_lru_locks mdc
3218 sync; sync_all_data || true
3219 if [ $qpool == "data" ]; then
3220 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3221 quota_error $qtype $qid "write succeed, expect EDQUOT"
3223 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3224 quota_error $qtype $qid "create succeed, expect EDQUOT"
3226 unlinkmany $TESTFILE $((LIMIT*2))
3229 log "Increase default quota"
3230 # increase default quota
3231 $LFS setquota $qdtype $qs $((LIMIT*3)) $qh $((LIMIT*3)) $DIR ||
3232 error "set default quota failed"
3234 cancel_lru_locks osc
3235 cancel_lru_locks mdc
3236 sync; sync_all_data || true
3237 if [ $qpool == "data" ]; then
3238 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3239 quota_error $qtype $qid "write failed, expect succeed"
3241 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3242 quota_error $qtype $qid "create failed, expect succeed"
3244 unlinkmany $TESTFILE $((LIMIT*2))
3247 log "Set quota to override default quota"
3248 $LFS setquota $qtype $qid $qs ${LIMIT} $qh ${LIMIT} $DIR ||
3249 error "set $qid quota failed"
3251 cancel_lru_locks osc
3252 cancel_lru_locks mdc
3253 sync; sync_all_data || true
3254 if [ $qpool == "data" ]; then
3255 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
3256 quota_error $qtype $qid "write succeed, expect EQUOT"
3258 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
3259 quota_error $qtype $qid "create succeed, expect EQUOT"
3261 unlinkmany $TESTFILE $((LIMIT*2))
3264 log "Set to use default quota again"
3265 $LFS setquota $qtype $qid -d $DIR ||
3266 error "set $qid to use default quota failed"
3268 cancel_lru_locks osc
3269 cancel_lru_locks mdc
3270 sync; sync_all_data || true
3271 if [ $qpool == "data" ]; then
3272 $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
3273 quota_error $qtype $qid "write failed, expect succeed"
3275 $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
3276 quota_error $qtype $qid "create failed, expect succeed"
3278 unlinkmany $TESTFILE $((LIMIT*2))
3283 wait_delete_completed || error "wait_delete_completed failed"
3284 sync_all_data || true
3285 $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR ||
3286 error "reset default quota failed"
3287 $LFS setquota $qtype $qid -b 0 -B 0 -i 0 -I 0 $DIR ||
3288 error "reset quota failed"
3294 test_default_quota "-u" "data"
3295 test_default_quota "-u" "meta"
3296 test_default_quota "-g" "data"
3297 test_default_quota "-g" "meta"
3298 test_default_quota "-p" "data"
3299 test_default_quota "-p" "meta"
3301 run_test 61 "default quota tests"
3304 ! is_project_quota_supported &&
3305 skip "Project quota is not supported"
3306 [[ "$(chattr -h 2>&1)" =~ "project" ]] ||
3307 skip "chattr did not support project quota"
3308 setup_quota_test || error "setup quota failed with $?"
3309 local testdir=$DIR/$tdir/
3311 $RUNAS mkdir -p $testdir || error "failed to mkdir"
3312 change_project -s $testdir
3313 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3314 error "inherit attribute should be set"
3315 # chattr used FS_IOC_SETFLAGS ioctl
3316 $RUNAS chattr -P $testdir &&
3317 error "regular user clear inherit should fail"
3318 [[ $($LFS project -d $testdir) =~ "P" ]] ||
3319 error "inherit attribute should still be set"
3320 chattr -P $testdir || error "root failed to clear inherit"
3321 [[ $($LFS project -d $testdir) =~ "P" ]] &&
3322 error "inherit attribute should be cleared"
3325 run_test 62 "Project inherit should be only changed by root"
3328 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
3329 skip "Not supported before 2.11.55"
3333 local dd_failed=false
3334 local tdir_dom=${tdir}_dom
3335 local LIMIT=20480 #20M
3337 [ $qtype == "p" ] && ! is_project_quota_supported &&
3338 echo "Project quota is not supported" && return 0
3340 [ $qtype == "p" ] && qid=$TSTPRJID
3342 setup_quota_test || error "setup quota failed with $?"
3343 trap cleanup_quota_test EXIT
3347 # enable mdt/ost quota
3348 set_mdt_qtype $QTYPE || error "enable mdt quota failed"
3349 set_ost_qtype $QTYPE || error "enable ost quota failed"
3351 # make sure the system is clean
3352 local USED=$(getquota -$qtype $qid global curspace)
3353 [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
3355 chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
3357 mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
3358 $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
3359 error "setstripe $tdir_dom failed"
3360 chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
3362 [ $qtype == "p" ] && {
3363 change_project -sp $TSTPRJID $DIR/$tdir
3364 change_project -sp $TSTPRJID $DIR/$tdir_dom
3367 $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
3368 error "set $qid quota failed"
3370 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3371 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3375 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3377 for ((i = $((LIMIT/2048)); i < $((LIMIT/1024 + 10)); i++)); do
3378 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3382 $dd_failed || quota_error $qtype $qid "write succeed, expect EDQUOT"
3384 rm -f $DIR/$tdir_dom/*
3386 # flush cache, ensure noquota flag is set on client
3387 cancel_lru_locks osc
3388 cancel_lru_locks mdc
3389 sync; sync_all_data || true
3393 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048)) oflag=sync ||
3394 quota_error $qtype $qid "write failed, expect succeed"
3396 for ((i = 0; i < $((LIMIT/2048 + 10)); i++)); do
3397 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3401 $dd_failed || quota_error $qtype $TSTID "write succeed, expect EDQUOT"
3404 rm -f $DIR/$tdir_dom/*
3406 # flush cache, ensure noquota flag is set on client
3407 cancel_lru_locks osc
3408 cancel_lru_locks mdc
3409 sync; sync_all_data || true
3413 for ((i = 0; i < $((LIMIT/2048)); i++)); do
3414 $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
3418 $dd_failed && quota_error $qtype $qid "write failed, expect succeed"
3420 $RUNAS $DD of=$DIR/$tdir/file count=$((LIMIT/2048 + 10)) oflag=sync &&
3421 quota_error $qtype $qid "write succeed, expect EDQUOT"
3424 rm -fr $DIR/$tdir_dom
3426 $LFS setquota -u $TSTUSR -b 0 -B 0 -i 0 -I 0 $DIR ||
3427 error "reset usr quota failed"
3437 run_test 63 "quota on DoM tests"
3440 ! is_project_quota_supported &&
3441 skip "Project quota is not supported"
3442 setup_quota_test || error "setup quota failed with $?"
3443 local dir1="$DIR/$tdir/"
3446 ln -s $dir1/file $dir1/file_link
3448 $LFS project -sp $TSTPRJID $dir1/file_link >&/dev/null &&
3449 error "set symlink file's project should fail"
3451 $LFS project $TSTPRJID $dir1/file_link >&/dev/null &&
3452 error "get symlink file's project should fail"
3456 run_test 64 "lfs project on symlink files should fail"
3460 local TESTFILE="$DIR/$tdir/$tfile-0"
3462 setup_quota_test || error "setup quota failed with $?"
3463 set_ost_qtype $QTYPE || error "enable ost quota failed"
3467 $RUNAS $DD of=$TESTFILE count=$SIZE ||
3468 error "failed to write"
3469 # flush cache, ensure noquota flag is set on client
3470 cancel_lru_locks osc
3471 sync; sync_all_data || true
3473 local quota_u=$($LFS quota -u $TSTUSR $DIR)
3474 local quota_g=$($LFS quota -g $TSTUSR $DIR)
3475 local quota_all=$($RUNAS $LFS quota $DIR)
3477 [ "$(echo "$quota_all" | head -n3)" != "$quota_u" ] &&
3478 error "usr quota not match"
3479 [ "$(echo "$quota_all" | tail -n3)" != "$quota_g" ] &&
3480 error "grp quota not match"
3486 run_test 65 "Check lfs quota result"
3489 ! is_project_quota_supported &&
3490 skip "Project quota is not supported"
3491 setup_quota_test || error "setup quota failed with $?"
3492 stack_trap cleanup_quota_test EXIT
3493 local old=$(do_facet mds1 $LCTL get_param -n \
3494 mdt.*.enable_chprojid_gid | head -1)
3495 local testdir=$DIR/$tdir/foo
3497 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0
3498 stack_trap "do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=0" \
3501 test_mkdir -i 0 -c 1 $testdir || error "failed to mkdir"
3502 chown -R $TSTID:$TSTID $testdir
3503 change_project -sp $TSTPRJID $testdir
3504 $RUNAS mkdir $testdir/foo || error "failed to mkdir foo"
3506 $RUNAS lfs project -p 0 $testdir/foo &&
3507 error "nonroot user should fail to set projid"
3509 $RUNAS lfs project -C $testdir/foo &&
3510 error "nonroot user should fail to clear projid"
3512 change_project -C $testdir/foo || error "failed to clear project"
3514 do_facet mds1 $LCTL set_param mdt.*.enable_chprojid_gid=-1
3515 $RUNAS lfs project -p $TSTPRJID $testdir/foo || error \
3516 "failed to set projid with normal user when enable_chprojid_gid=-1"
3518 $RUNAS lfs project -rC $testdir/ || error \
3519 "failed to clear project state with normal user when enable_chprojid_gid=-1"
3521 touch $testdir/bar || error "failed touch $testdir/bar"
3522 $RUNAS lfs project -p $TSTPRJID $testdir/bar && error \
3523 "normal user should not be able to set projid on root owned file"
3525 change_project -p $TSTPRJID $testdir/bar || error \
3526 "root should be able to change its own file's projid"
3530 run_test 66 "nonroot user can not change project state in default"
3534 do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"
3535 if $PQ_CLEANUP; then
3536 disable_project_quota
3539 reset_quota_settings
3544 check_and_cleanup_lustre
3545 export QUOTA_AUTO=$QUOTA_AUTO_OLD