+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] || quota_error u $TSTUSR "Used space is 0"
+}
+run_test 37 "Quota accounted properly for file created by 'lfs setstripe'"
+
+# LU-8801
+test_38() {
+ [ "$MDS1_VERSION" -lt $(version_code 2.8.60) ] &&
+ skip "Old server doesn't have LU-8801 fix."
+
+ [ "$UID" != 0 ] && skip_env "must run as root" && return
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ # make sure the system is clean
+ local USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space ($USED) for user $TSTID isn't 0."
+ USED=$(getquota -u $TSTID2 global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space ($USED) for user $TSTID2 isn't 0."
+
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local file_cnt=10000
+
+ # Generate id entries in accounting file
+ echo "Create $file_cnt files..."
+ for i in `seq $file_cnt`; do
+ touch $TESTFILE-$i
+ chown $((file_cnt - i)):$((file_cnt - i)) $TESTFILE-$i ||
+ error "failed to chown $TESTFILE-$i"
+ done
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ local procf="osd-$mds1_FSTYPE.$FSNAME-MDT0000"
+ procf=${procf}.quota_slave.acct_user
+ local acct_cnt
+
+ acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | \
+ awk '{if ($3 < 10000) {print $3}}' | wc -l)
+ echo "Found $acct_cnt id entries"
+
+ [ $file_cnt -eq $acct_cnt ] || {
+ do_facet mds1 $LCTL get_param $procf
+ error "skipped id entries"
+ }
+}
+run_test 38 "Quota accounting iterator doesn't skip id entries"
+
+test_39() {
+ local TESTFILE="$DIR/$tdir/project"
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ touch $TESTFILE
+ projectid=$(lfs project $TESTFILE | awk '{print $1}')
+ [ $projectid -ne 0 ] &&
+ error "Project id should be 0 not $projectid"
+ change_project -p 1024 $TESTFILE
+ projectid=$(lfs project $TESTFILE | awk '{print $1}')
+ [ $projectid -ne 1024 ] &&
+ error "Project id should be 1024 not $projectid"
+
+ stopall || error "failed to stopall (1)"
+ mount
+ setupall
+ projectid=$(lfs project $TESTFILE | awk '{print $1}')
+ [ $projectid -eq 1024 ] ||
+ error "Project id should be 1024 not $projectid"
+}
+run_test 39 "Project ID interface works correctly"
+
+test_40a() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ mkdir -p $dir1 $dir2
+ change_project -sp 1 $dir1 && touch $dir1/1
+ change_project -sp 2 $dir2
+
+ ln $dir1/1 $dir2/1_link &&
+ error "Hard link across different project quota should fail"
+ return 0
+}
+run_test 40a "Hard link across different project ID"
+
+test_40b() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+
+ setup_quota_test || error "setup quota failed with $?"
+ mkdir -p $dir1 $dir2
+ change_project -sp 1 $dir1 && touch $dir1/1
+ change_project -sp 2 $dir2
+
+ mv $dir1/1 $dir2/2 || error "mv failed $?"
+ local projid=$(lfs project $dir2/2 | awk '{print $1}')
+ [ "$projid" -eq 2 ] || error "project id expected 2 not $projid"
+}
+run_test 40b "Mv across different project ID"
+
+test_40c() {
+ [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir -p $dir && change_project -sp 1 $dir
+ $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
+ local projid=$(lfs project -d $dir/remote_dir | awk '{print $1}')
+ [ "$projid" != "1" ] && error "projid id expected 1 not $projid"
+ touch $dir/remote_dir/file
+ #verify inherit works file for remote dir.
+ local projid=$(lfs project -d $dir/remote_dir/file | awk '{print $1}')
+ [ "$projid" != "1" ] &&
+ error "file under remote dir expected 1 not $projid"
+
+ #Agent inode should be ignored for project quota
+ local used=$(getquota -p 1 global curinodes)
+ [ $used -eq 3 ] ||
+ error "file count expected 3 got $used"
+}
+run_test 40c "Remote child Dir inherit project quota properly"
+
+test_40d() {
+ [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs"
+ is_project_quota_supported || skip "Project quota is not supported"
+
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir -p $dir
+ $LFS setdirstripe -D -c 2 -i -1 $dir || error "setdirstripe failed"
+ change_project -sp $TSTPRJID $dir ||
+ error "change project on $dir failed"
+ for i in $(seq 5); do
+ mkdir -p $dir/d$i/d$i ||
+ error "mkdir $dir/d$i/d$i failed"
+ local projid=$($LFS project -d $dir/d$i/d$i |
+ awk '{print $1}')
+ [ "$projid" == "$TSTPRJID" ] ||
+ error "projid id expected $TSTPRJID not $projid"
+ touch $dir/d$i/d$i/file
+ #verify inherit works file for stripe dir.
+ local projid=$($LFS project -d $dir/d$i/d$i/file | awk '{print $1}')
+ [ "$projid" == "$TSTPRJID" ] ||
+ error "file under remote dir expected 1 not $projid"
+ done
+
+ # account should be 1 + (2 + 1) *10 + 1 * 5
+ local used=$(getquota -p $TSTPRJID global curinodes)
+ [ $used -eq 36 ] ||
+ error "file count expected 36 got $used"
+}
+run_test 40d "Stripe Directory inherit project quota properly"
+
+test_41() {
+ is_project_quota_supported ||
+ skip "Project quota is not supported"
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+ local blimit=102400
+ local ilimit=4096
+ local projid=$((testnum * 1000))
+
+ quota_init
+
+ # enable mdt/ost quota
+ set_mdt_qtype ugp || error "enable mdt quota failed"
+ set_ost_qtype ugp || error "enable ost quota failed"
+
+ test_mkdir -p $dir && change_project -sp $projid $dir
+ $LFS setquota -p $projid -b 0 -B ${blimit}K -i 0 -I $ilimit $dir ||
+ error "set project quota failed"
+
+ sync; sync_all_data
+ sleep_maxage
+
+ # check if df output works as expected
+ echo "== global statfs: $MOUNT =="
+ df -kP $MOUNT; df -iP $MOUNT; $LFS quota -p $projid $dir
+ echo
+ echo "== project statfs (prjid=$projid): $dir =="
+ df -kP $dir; df -iP $dir
+ local bused=$(getquota -p $projid global curspace)
+ local iused=$(getquota -p $projid global curinodes)
+ # note trailing space to match double printf from awk
+ local expected="$blimit $bused $ilimit $iused "
+
+ wait_update $HOSTNAME \
+ "{ df -kP $dir; df -iP $dir; } |
+ awk '/$FSNAME/ { printf \\\"%d %d \\\", \\\$2,\\\$3 }'" \
+ "$expected" ||
+ error "failed to get correct statfs for project quota"
+}
+run_test 41 "df should return projid-specific values"
+
+test_delete_qid()
+{
+ local qslv_file=$1
+ local qtype_file=$2
+ local qtype=$3
+ local qid=$4
+ local osd="osd-ldiskfs"
+
+ [ "$ost1_FSTYPE" = zfs ] && osd="osd-zfs"
+
+ rm -f $DIR/$tdir/$tfile
+ $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
+ chmod a+rw $DIR/$tdir/$tfile
+
+ $LFS setquota $qtype $qid -B 300M $MOUNT
+ $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
+ error "failed to dd"
+
+ do_facet $SINGLEMDS \
+ "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+ grep -E 'id: *$qid'" || error "QMT: no qid $qid is found"
+ echo $osd
+ do_facet ost1 \
+ "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+ grep -E 'id: *$qid'" || error "QSD: no qid $qid is found"
+
+ $LFS setquota $qtype $qid --delete $MOUNT
+ do_facet $SINGLEMDS \
+ "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+ grep -E 'id: *$qid'" && error "QMT: qid $qid is not deleted"
+ sleep 5
+ do_facet ost1 \
+ "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+ grep -E 'id: *$qid'" && error "QSD: qid $qid is not deleted"
+
+ $LFS setquota $qtype $qid -B 500M $MOUNT
+ $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 ||
+ error "failed to dd"
+ do_facet $SINGLEMDS \
+ "cat /proc/fs/lustre/qmt/$FSNAME-QMT0000/dt-0x0/$qtype_file |
+ grep -E 'id: *$qid'" || error "QMT: qid $pid is not recreated"
+ cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file
+ do_facet ost1 \
+ "cat /proc/fs/lustre/$osd/$FSNAME-OST0000/$qslv_file |
+ grep -E 'id: *$qid'" || error "QSD: qid $qid is not recreated"
+}
+
+test_48()
+{
+ setup_quota_test || error "setup quota failed with $?"
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+ quota_init
+
+ test_delete_qid "quota_slave/limit_user" "glb-usr" "-u" $TSTID
+ test_delete_qid "quota_slave/limit_group" "glb-grp" "-g" $TSTID
+ is_project_quota_supported &&
+ test_delete_qid "quota_slave/limit_project" "glb-prj" "-p" "10000"
+
+ cleanup_quota_test
+}
+run_test 48 "lfs quota --delete should delete quota project ID"
+
+test_50() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+
+ setup_quota_test || error "setup quota failed with $?"
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+
+ mkdir -p $dir1 && change_project -sp 1 $dir1
+ mkdir -p $dir2 && change_project -sp 2 $dir2
+ for num in $(seq 1 10); do
+ touch $dir1/file_$num $dir2/file_$num
+ ln -s $dir1/file_$num $dir1/file_$num"_link"
+ ln -s $dir2/file_$num $dir2/file_$num"_link"
+ done
+
+ count=$($LFS find --projid 1 $DIR | wc -l)
+ [ "$count" != 21 ] && error "expected 21 but got $count"
+
+ # 1(projid 0 dir) + 1(projid 2 dir) + 20(projid 2 files)
+ count=$($LFS find ! --projid 1 $DIR/$tdir | wc -l)
+ [ $count -eq 22 ] || error "expected 22 but got $count"
+}
+run_test 50 "Test if lfs find --projid works"
+
+test_51() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir $dir && change_project -sp 1 $dir
+ local used=$(getquota -p 1 global curinodes)
+ [ $used != "1" ] && error "expected 1 got $used"
+
+ touch $dir/1
+ touch $dir/2
+ cp $dir/2 $dir/3
+ used=$(getquota -p 1 global curinodes)
+ [ $used != "4" ] && error "expected 4 got $used"
+
+ $DD if=/dev/zero of=$DIR/$tdir/6 bs=1M count=1
+ #try cp to dir
+ cp $DIR/$tdir/6 $dir/6
+ used=$(getquota -p 1 global curinodes)
+ [ $used != "5" ] && error "expected 5 got $used"
+
+ #try mv to dir
+ mv $DIR/$tdir/6 $dir/7
+ used=$(getquota -p 1 global curinodes)
+ [ $used -eq 6 ] || error "expected 6 got $used"
+}
+run_test 51 "Test project accounting with mv/cp"
+
+test_52() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+
+ (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
+ skip "Need MDS version at least 2.14.55"
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ local dir1=$DIR/$tdir/t52_dir1
+ local dir2=$DIR/$tdir/t52_dir2
+
+ mkdir $dir1 || error "failed to mkdir $dir1"
+ mkdir $dir2 || error "failed to mkdir $dir2"
+
+ $LFS project -sp 1000 $dir1 || error "fail to set project on $dir1"
+ $LFS project -sp 1001 $dir2 || error "fail to set project on $dir2"
+
+ $DD if=/dev/zero of=/$dir1/$tfile bs=1M count=100 ||
+ error "failed to create and write $tdir1/$tfile"
+
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ local attrs=($(lsattr -p $dir1/$tfile))
+ (( ${attrs[0]} == 1000 )) ||
+ error "project ID on $dir1/$tfile is not inherited"
+
+ $LFS quota -p 1000 $DIR
+ $LFS quota -p 1001 $DIR
+
+ local prev_used=$(getquota -p 1000 global curspace)
+ local prev_used2=$(getquota -p 1001 global curspace)
+
+ mrename $dir1 $dir2/tdir || log "rename directory return $?"
+
+ local inum_before=$(ls -i $dir1/$tfile | awk '{print $1}')
+ mrename $dir1/$tfile $dir2/$tfile || error "failed to rename file"
+ local inum_after=$(ls -i $dir2/$tfile | awk '{print $1}')
+
+ attrs=($(lsattr -p $dir2/$tfile))
+ (( ${attrs[0]} == 1001 )) ||
+ error "project ID is not updated after rename"
+
+ (( $inum_before == $inum_after )) ||
+ error "inode is changed after rename: $inum_before, $inum_after"
+
+ sync_all_data || true
+
+ $LFS quota -p 1000 $DIR
+ $LFS quota -p 1001 $DIR
+
+ local new_used=$(getquota -p 1000 global curspace)
+ local new_used2=$(getquota -p 1001 global curspace)
+
+ (( $prev_used >= $new_used + 102400 )) ||
+ error "quota is not deducted from old project ID"
+ (( $prev_used2 <= $new_used2 - 102400 )) ||
+ error "quota is not added for the new project ID"
+}
+run_test 52 "Rename normal file across project ID"
+
+test_53() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+ mkdir $dir && change_project -s $dir
+ [[ $($LFS project -d $dir) =~ " P " ]] ||
+ error "inherit attribute should be set"
+
+ change_project -C $dir
+ [[ $($LFS project -d $dir) =~ " - " ]] ||
+ error "inherit attribute should be cleared"
+}
+run_test 53 "Project inherit attribute could be cleared"
+
+test_54() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ setup_quota_test || error "setup quota failed with $?"
+ local testfile="$DIR/$tdir/$tfile-0"
+
+ #set project ID/inherit attribute
+ change_project -sp $TSTPRJID $DIR/$tdir
+ $RUNAS createmany -m ${testfile} 100 ||
+ error "create many files failed"
+
+ local proj_count=$(lfs project -r $DIR/$tdir | wc -l)
+ # one more count for directory itself */
+ ((proj_count++))
+
+ #check project
+ local proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+ [ $proj_count1 -eq 0 ] || error "c1: expected 0 got $proj_count1"
+
+ proj_count1=$(lfs project -rcp $((TSTPRJID+1)) $DIR/$tdir | wc -l)
+ [ $proj_count1 -eq $proj_count ] ||
+ error "c2: expected $proj_count got $proj_count1"
+
+ #clear project but with kept projid
+ change_project -rCk $DIR/$tdir
+ proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+ [ $proj_count1 -eq 1 ] ||
+ error "c3: expected 1 got $proj_count1"
+
+ #verify projid untouched.
+ proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
+ ((proj_count1++))
+ [ $proj_count1 -eq $proj_count ] ||
+ error "c4: expected $proj_count got $proj_count1"
+
+ # test -0 option
+ lfs project $DIR/$tdir -cr -0 | xargs -0 lfs project -s
+ proj_count1=$(lfs project -rcp $TSTPRJID $DIR/$tdir | wc -l)
+ [ $proj_count1 -eq 0 ] || error "c5: expected 0 got $proj_count1"
+
+ #this time clear all
+ change_project -rC $DIR/$tdir
+ proj_count1=$(lfs project -r $DIR/$tdir | grep -c $TSTPRJID)
+ [ $proj_count1 -eq 0 ] ||
+ error "c6: expected 0 got $proj_count1"
+ #cleanup
+ unlinkmany ${testfile} 100 ||
+ error "unlink many files failed"
+}
+run_test 54 "basic lfs project interface test"
+
+test_55() {
+ [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
+ skip "Not supported before 2.10.58."
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+ quota_init
+
+ #add second group to TSTUSR
+ usermod -G $TSTUSR,$TSTUSR2 $TSTUSR
+
+ #prepare test file
+ $RUNAS dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1024 count=100000 ||
+ error "failed to dd"
+
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ $LFS setquota -g $TSTUSR2 -b 0 -B 50M $DIR ||
+ error "failed to setquota on group $TSTUSR2"
+
+ $LFS quota -v -g $TSTUSR2 $DIR
+
+ runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile &&
+ error "chgrp should failed with -EDQUOT"
+
+ USED=$(getquota -g $TSTUSR2 global curspace)
+ echo "$USED"
+
+ $LFS setquota -g $TSTUSR2 -b 0 -B 300M $DIR ||
+ error "failed to setquota on group $TSTUSR2"
+
+ $LFS quota -v -g $TSTUSR2 $DIR
+
+ runas -u $TSTUSR -g $TSTUSR2 chgrp $TSTUSR2 $DIR/$tdir/$tfile ||
+ error "chgrp should succeed"
+
+ $LFS quota -v -g $TSTUSR2 $DIR
+}
+run_test 55 "Chgrp should be affected by group quota"
+
+test_56() {
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+ quota_init
+
+ $LFS setquota -t -u -b 10 -i 10 $DIR ||
+ erro "failed to set grace time for usr quota"
+ grace_time=$($LFS quota -t -u $DIR | grep "Block grace time:" |
+ awk '{print $4 $8}')
+ if [ "x$grace_time" != "x10s;10s" ]; then
+ $LFS quota -t -u $DIR
+ error "expected grace time: 10s;10s, got:$grace_time"
+ fi
+}
+run_test 56 "lfs quota -t should work well"
+
+test_57() {
+ setup_quota_test || error "setup quota failed with $?"
+
+ local dir="$DIR/$tdir/dir"
+ mkdir -p $dir
+ mkfifo $dir/pipe
+ #command can process further if it hit some errors
+ $LFS project -sp 1 $dir/pipe
+ touch $dir/aaa $dir/bbb
+ mkdir $dir/subdir -p
+ touch $dir/subdir/aaa $dir/subdir/bbb
+ #create one invalid link file
+ ln -s $dir/not_exist_file $dir/ccc
+ local cnt=$(lfs project -r $dir 2>/dev/null | wc -l)
+ [ $cnt -eq 7 ] || error "expected 7 got $cnt"
+}
+run_test 57 "lfs project could tolerate errors"
+
+test_59() {
+ [ "$mds1_FSTYPE" != ldiskfs ] &&
+ skip "ldiskfs only test"
+ disable_project_quota
+ setup_quota_test || error "setup quota failed with $?"
+ quota_init
+
+ local testfile="$DIR/$tdir/$tfile-0"
+ #make sure it did not crash kernel
+ touch $testfile && lfs project -sp 1 $testfile
+
+ enable_project_quota
+}
+run_test 59 "lfs project dosen't crash kernel with project disabled"
+
+test_60() {
+ [ $MDS1_VERSION -lt $(version_code 2.11.53) ] &&
+ skip "Needs MDS version 2.11.53 or later."
+ setup_quota_test || error "setup quota failed with $?"
+
+ local testfile=$DIR/$tdir/$tfile
+ local limit=100
+
+ set_mdt_qtype "ug" || error "enable mdt quota failed"
+
+ $LFS setquota -g $TSTUSR -b 0 -B 0 -i 0 -I $limit $DIR ||
+ error "set quota failed"
+ quota_show_check a g $TSTUSR
+
+ chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $DIR/$tdir failed"
+ chmod g+s $DIR/$tdir || error "chmod g+s failed"
+ $RUNAS createmany -m ${testfile} $((limit-1)) ||
+ error "create many files failed"
+
+ $RUNAS touch $DIR/$tdir/foo && error "regular user should fail"
+
+ # root user can overrun quota
+ runas -u 0 -g 0 touch $DIR/$tdir/foo ||
+ error "root user should succeed"
+}
+run_test 60 "Test quota for root with setgid"
+
+# test default quota
+test_default_quota() {
+ [ "$MDS1_VERSION" -lt $(version_code 2.11.51) ] &&
+ skip "Not supported before 2.11.51."
+
+ local qtype=$1
+ local qres_type=$2
+ local qid=$TSTUSR
+ local qprjid=$TSTPRJID
+ local qdtype="-U"
+ local qs="-b"
+ local qh="-B"
+ local LIMIT=20480 #20M disk space
+ local TESTFILE="$DIR/$tdir/$tfile-0"
+ local $qpool_cmd
+
+ [ $qtype == "-p" ] && ! is_project_quota_supported &&
+ echo "Project quota is not supported" && return 0
+
+ [ $qtype == "-u" ] && qdtype="-U"
+ [ $qtype == "-g" ] && qdtype="-G"
+ [ $qtype == "-p" ] && {
+ qdtype="-P"
+ qid=$qprjid
+ }
+
+ [ $qres_type == "meta" ] && {
+ LIMIT=10240 #10K inodes
+ qs="-i"
+ qh="-I"
+ }
+ [ ! -z "$3" ] && {
+ qpool_cmd="--pool $3"
+ # pool quotas don't work properly without global limit
+ $LFS setquota $qtype $qid -B1T -b1T $DIR ||
+ error "set global limit failed"
+ }
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ quota_init
+
+ # enable mdt/ost quota
+ set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ log "set to use default quota"
+ $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
+ error "set $qid to use default quota failed"
+
+ log "set default quota"
+ $LFS setquota $qdtype $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
+ error "set $qid default quota failed"
+
+ log "get default quota"
+ $LFS quota $qdtype $DIR || error "get default quota failed"
+
+ if [ $qres_type == "data" ]; then
+ local SLIMIT=$($LFS quota $qpool_cmd $qdtype $DIR | \
+ grep "$MOUNT" | awk '{print $2}')
+ [ $SLIMIT -eq $LIMIT ] ||
+ error "the returned default quota is wrong"
+ else
+ local SLIMIT=$($LFS quota $qdtype $DIR | grep "$MOUNT" | \
+ awk '{print $5}')
+ [ $SLIMIT -eq $LIMIT ] ||
+ error "the returned default quota is wrong"
+ fi
+
+ # make sure the system is clean
+ local USED=$(getquota $qtype $qid global curspace)
+ [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
+
+ $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
+ error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ [ $qtype == "-p" ] && change_project -sp $TSTPRJID $DIR/$tdir
+
+ log "Test not out of quota"
+ if [ $qres_type == "data" ]; then
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 >> 10)) oflag=sync ||
+ quota_error $qtype $qid "write failed, expect succeed"
+ else
+ $RUNAS createmany -m $TESTFILE $((LIMIT/2)) ||
+ quota_error $qtype $qid "create failed, expect succeed"
+
+ unlinkmany $TESTFILE $((LIMIT/2))
+ fi
+
+ log "Test out of quota"
+ # flush cache, ensure noquota flag is set on client
+ cancel_lru_locks osc
+ cancel_lru_locks mdc
+ sync; sync_all_data || true
+ if [ $qres_type == "data" ]; then
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
+ quota_error $qtype $qid "write succeed, expect EDQUOT"
+ else
+ $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
+ quota_error $qtype $qid "create succeed, expect EDQUOT"
+
+ unlinkmany $TESTFILE $((LIMIT*2))
+ fi
+
+ rm -f $TESTFILE
+ $LFS setstripe $TESTFILE -c 1 $qpool_cmd ||
+ error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ log "Increase default quota"
+
+ # LU-4505: sleep 5 seconds to enable quota acquire
+ sleep 5
+
+ # increase default quota
+ $LFS setquota $qdtype $qpool_cmd $qs $((LIMIT*3)) \
+ $qh $((LIMIT*3)) $DIR || error "set default quota failed"
+
+ cancel_lru_locks osc
+ cancel_lru_locks mdc
+ sync; sync_all_data || true
+ if [ $qres_type == "data" ]; then
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
+ quota_error $qtype $qid "write failed, expect succeed"
+ else
+ $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
+ quota_error $qtype $qid "create failed, expect succeed"
+
+ unlinkmany $TESTFILE $((LIMIT*2))
+ fi
+
+ log "Set quota to override default quota"
+ $LFS setquota $qtype $qid $qpool_cmd $qs ${LIMIT} $qh ${LIMIT} $DIR ||
+ error "set $qid quota failed"
+
+ cancel_lru_locks osc
+ cancel_lru_locks mdc
+ sync; sync_all_data || true
+ if [ $qres_type == "data" ]; then
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync &&
+ quota_error $qtype $qid "write succeed, expect EQUOT"
+ else
+ $RUNAS createmany -m $TESTFILE $((LIMIT*2)) &&
+ quota_error $qtype $qid "create succeed, expect EQUOT"
+
+ unlinkmany $TESTFILE $((LIMIT*2))
+ fi
+
+ log "Set to use default quota again"
+
+ # LU-4505: sleep 5 seconds to enable quota acquire
+ sleep 5
+
+ $LFS setquota $qtype $qid -d $qpool_cmd $DIR ||
+ error "set $qid to use default quota failed"
+
+ cancel_lru_locks osc
+ cancel_lru_locks mdc
+ sync; sync_all_data || true
+ if [ $qres_type == "data" ]; then
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT*2 >> 10)) oflag=sync ||
+ quota_error $qtype $qid "write failed, expect succeed"
+ else
+ $RUNAS createmany -m $TESTFILE $((LIMIT*2)) ||
+ quota_error $qtype $qid "create failed, expect succeed"
+
+ unlinkmany $TESTFILE $((LIMIT*2))
+ fi
+
+ log "Cleanup"
+ rm -f $TESTFILE
+ wait_delete_completed || error "wait_delete_completed failed"
+ sync_all_data || true
+
+ $LFS setquota $qdtype $qpool_cmd $qs 0 $qh 0 $DIR ||
+ error "reset default quota failed"
+ $LFS setquota $qtype $qid $qpool_cmd $qs 0 $qh 0 $DIR ||
+ error "reset quota failed"
+ cleanup_quota_test
+}
+
+test_61() {
+ test_default_quota "-u" "data"
+ test_default_quota "-u" "meta"
+ test_default_quota "-g" "data"
+ test_default_quota "-g" "meta"
+ test_default_quota "-p" "data"
+ test_default_quota "-p" "meta"
+}
+run_test 61 "default quota tests"
+
+test_62() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported"
+ [[ "$(chattr -h 2>&1)" =~ "project" ||
+ "$(chattr -h 2>&1)" =~ "pRVf" ]] ||
+ skip "chattr did not support project quota"
+ setup_quota_test || error "setup quota failed with $?"
+ local testdir=$DIR/$tdir/
+
+ $RUNAS mkdir -p $testdir || error "failed to mkdir"
+ change_project -s $testdir
+ [[ $($LFS project -d $testdir) =~ "P" ]] ||
+ error "inherit attribute should be set"
+ # chattr used FS_IOC_SETFLAGS ioctl
+ $RUNAS chattr -P $testdir &&
+ error "regular user clear inherit should fail"
+ [[ $($LFS project -d $testdir) =~ "P" ]] ||
+ error "inherit attribute should still be set"
+ chattr -P $testdir || error "root failed to clear inherit"
+ [[ $($LFS project -d $testdir) =~ "P" ]] &&
+ error "inherit attribute should be cleared"
+ return 0
+}
+run_test 62 "Project inherit should be only changed by root"
+
+test_dom() {
+ [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ] &&
+ skip "Not supported before 2.11.55"
+
+ local qtype=$1
+ local qid=$TSTUSR
+ local dd_failed=false
+ local tdir_dom=${tdir}_dom
+ local LIMIT=20480 #20M
+
+ [ $qtype == "p" ] && ! is_project_quota_supported &&
+ echo "Project quota is not supported" && return 0
+
+ [ $qtype == "p" ] && qid=$TSTPRJID
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ quota_init
+
+ # enable mdt/ost quota
+ set_mdt_qtype $QTYPE || error "enable mdt quota failed"
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # make sure the system is clean
+ local USED=$(getquota -$qtype $qid global curspace)
+ [ $USED -ne 0 ] && error "Used space for $qid isn't 0."
+
+ chown $TSTUSR.$TSTUSR $DIR/$tdir || error "chown $tdir failed"
+
+ mkdir $DIR/$tdir_dom || error "mkdir $tdir_dom failed"
+ $LFS setstripe -E 1M -L mdt $DIR/$tdir_dom ||
+ error "setstripe $tdir_dom failed"
+ chown $TSTUSR.$TSTUSR $DIR/$tdir_dom || error "chown $tdir_dom failed"
+
+ [ $qtype == "p" ] && {
+ change_project -sp $TSTPRJID $DIR/$tdir
+ change_project -sp $TSTPRJID $DIR/$tdir_dom
+ }
+
+ $LFS setquota -$qtype $qid -b $LIMIT -B $LIMIT $DIR ||
+ error "set $qid quota failed"
+
+ for ((i = 0; i < $((LIMIT/2048)); i++)); do
+ $RUNAS $DD of=$DIR/$tdir_dom/$tfile-$i count=1 oflag=sync ||
+ dd_failed=true
+ done
+
+ $dd_failed && quota_error $qtype $qid "write failed, expect succeed"