+ local BLIMIT=10 # 10G
+ local ILIMIT=1000000
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype $QTYPE || error "Enable ost quota failed"
+
+ log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for user: $TSTUSR"
+ $LFS setquota -u $TSTUSR -b 0 -B ${BLIMIT}G -i 0 -I $ILIMIT $MOUNT ||
+ error "set user quota failed"
+ log "Set limit(block:${BLIMIT}G; file:$ILIMIT) for group: $TSTUSR"
+ $LFS setquota -g $TSTUSR -b 0 -B $BLIMIT -i 0 -I $ILIMIT $MOUNT ||
+ error "set group quota failed"
+ if is_project_quota_supported; then
+ log "Set limit(block:${BLIMIT}G; file:$LIMIT) for " \
+ "project: $TSTPRJID"
+ $LFS setquota -p $TSTPRJID -b 0 -B $BLIMIT -i 0 -I $ILIMIT \
+ $MOUNT || error "set project quota failed"
+ fi
+
+ # repeat writing on a 1M file
+ test_21_sub ${TESTFILE}_1 1 30 &
+ local DDPID1=$!
+ # repeat writing on a 128M file
+ test_21_sub ${TESTFILE}_2 128 30 &
+ local DDPID2=$!
+
+ local time=$(($(date +%s) + 30))
+ local i=1
+ while [ $(date +%s) -lt $time ]; do
+ log "Set quota for $i times"
+ $LFS setquota -u $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
+ -I $((ILIMIT + i)) $MOUNT ||
+ error "Set user quota failed"
+ $LFS setquota -g $TSTUSR -b 0 -B "$((BLIMIT + i))G" -i 0 \
+ -I $((ILIMIT + i)) $MOUNT ||
+ error "Set group quota failed"
+ if is_project_quota_supported; then
+ $LFS setquota -p $TSTPRJID -b 0 -B \
+ "$((BLIMIT + i))G" -i 0 -I $((ILIMIT + i)) $MOUNT ||
+ error "Set project quota failed"
+ fi
+ i=$((i+1))
+ sleep 1
+ done
+
+ local count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID1} > /dev/null 2>&1; then break; fi
+ count=$((count+1))
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID1, time=$count)successful"
+
+ count=0
+ while [ true ]; do
+ if ! ps -p ${DDPID2} > /dev/null 2>&1; then break; fi
+ count=$((count+1))
+ if [ $count -gt 60 ]; then
+ quota_error a $TSTUSR "dd should be finished!"
+ fi
+ sleep 1
+ done
+ echo "(dd_pid=$DDPID2, time=$count)successful"
+}
+run_test 21 "Setquota while writing & deleting (b16053)"
+
+# enable/disable quota enforcement permanently
+test_22() {
+ echo "Set both mdt & ost quota type as ug"
+ local qtype="ug"
+ is_project_quota_supported && qtype=$QTYPE
+ set_mdt_qtype $qtype || error "enable mdt quota failed"
+ set_ost_qtype $qtype || error "enable ost quota failed"
+
+ echo "Restart..."
+ stopall || error "failed to stopall (1)"
+ mount
+ setupall
+
+ echo "Verify if quota is enabled"
+ local qtype1=$(mdt_quota_type)
+ [ $qtype1 != $qtype ] && error "mdt quota setting is lost"
+ qtype=$(ost_quota_type)
+ [ $qtype1 != $qtype ] && error "ost quota setting is lost"
+
+ echo "Set both mdt & ost quota type as none"
+ set_mdt_qtype "none" || error "disable mdt quota failed"
+ set_ost_qtype "none" || error "disable ost quota failed"
+
+ echo "Restart..."
+ stopall || error "failed to stopall (2)"
+ mount
+ setupall
+ quota_init
+
+ echo "Verify if quota is disabled"
+ qtype=$(mdt_quota_type)
+ [ $qtype != "none" ] && error "mdt quota setting is lost"
+ qtype=$(ost_quota_type)
+ [ $qtype != "none" ] && error "ost quota setting is lost"
+
+ return 0
+}
+run_test 22 "enable/disable quota by 'lctl conf_param/set_param -P'"
+
+test_23_sub() {
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local LIMIT=$1
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype $QTYPE || error "Enable ost quota failed"
+
+ # test for user
+ log "User quota (limit: $LIMIT MB)"
+ $LFS setquota -u $TSTUSR -b 0 -B "$LIMIT"M -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ quota_show_check b u $TSTUSR
+
+ $LFS setstripe $TESTFILE -c 1 -i 0 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ log "Step1: trigger EDQUOT with O_DIRECT"
+ log "Write half of file"
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT/2)) oflag=direct ||
+ quota_error u $TSTUSR "(1) Write failure, expect success." \
+ "limit=$LIMIT"
+ log "Write out of block quota ..."
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT/2 + 1)) seek=$((LIMIT/2)) \
+ oflag=direct conv=notrunc &&
+ quota_error u $TSTUSR "(2) Write success, expect EDQUOT." \
+ "limit=$LIMIT"
+ log "Step1: done"
+
+ log "Step2: rewrite should succeed"
+ $RUNAS $DD of=$TESTFILE count=1 oflag=direct conv=notrunc||
+ quota_error u $TSTUSR "(3) Write failure, expect success." \
+ "limit=$LIMIT"
+ log "Step2: done"
+
+ cleanup_quota_test
+
+ local OST0_UUID=$(ostuuid_from_index 0)
+ local OST0_QUOTA_USED=$(getquota -u $TSTUSR $OST0_UUID curspace)
+ [ $OST0_QUOTA_USED -ne 0 ] &&
+ ($SHOW_QUOTA_USER; \
+ quota_error u $TSTUSR "quota isn't released")
+ $SHOW_QUOTA_USER
+}
+
+test_23() {
+ [ "$ost1_FSTYPE" == zfs ] &&
+ skip "Overwrite in place is not guaranteed to be " \
+ "space neutral on ZFS"
+
+ local OST0_MIN=$((6 * 1024)) # 6MB, extra space for meta blocks.
+ check_whether_skip && return 0
+ log "run for 4MB test file"
+ test_23_sub 4
+
+ OST0_MIN=$((60 * 1024)) # 60MB, extra space for meta blocks.
+ check_whether_skip && return 0
+ log "run for 40MB test file"
+ test_23_sub 40
+}
+run_test 23 "Quota should be honored with directIO (b16125)"
+
+test_24() {
+ local blimit=5 # MB
+ local TESTFILE="$DIR/$tdir/$tfile"
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # bind file to a single OST
+ $LFS setstripe -c 1 $TESTFILE || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ echo "Set user quota (limit: ${blimit}M)"
+ $LFS setquota -u $TSTUSR -b 0 -B "$blimit"M -i 0 -I 0 $MOUNT ||
+ error "set quota failed"
+
+ # overrun quota by root user
+ runas -u 0 -g 0 $DD of=$TESTFILE count=$((blimit + 1)) ||
+ error "write failure, expect success"
+ cancel_lru_locks osc
+ sync_all_data || true
+
+ $SHOW_QUOTA_USER | grep '*' || error "no matching *"
+}
+run_test 24 "lfs draws an asterix when limit is reached (b16646)"
+
+test_27a() { # b19612
+ $LFS quota $TSTUSR $DIR &&
+ error "lfs succeeded with no type, but should have failed"
+ $LFS setquota $TSTUSR $DIR &&
+ error "lfs succeeded with no type, but should have failed"
+ return 0
+}
+run_test 27a "lfs quota/setquota should handle wrong arguments (b19612)"
+
+test_27b() { # b20200
+ $LFS setquota -u $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
+ error "lfs setquota failed with uid argument"
+ $LFS setquota -g $TSTID -b 1000 -B 1000 -i 1000 -I 1000 $DIR ||
+ error "lfs stequota failed with gid argument"
+ if is_project_quota_supported; then
+ $LFS setquota -p $TSTPRJID -b 1000 -B 1000 -i 1000 -I \
+ 1000 $DIR || error \
+ "lfs stequota failed with projid argument"
+ fi
+ $SHOW_QUOTA_USERID || error "lfs quota failed with uid argument"
+ $SHOW_QUOTA_GROUPID || error "lfs quota failed with gid argument"
+ if is_project_quota_supported; then
+ $SHOW_QUOTA_PROJID ||
+ error "lfs quota failed with projid argument"
+ fi
+ resetquota -u $TSTID
+ resetquota -g $TSTID
+ resetquota -p $TSTPRJID
+ return 0
+}
+run_test 27b "lfs quota/setquota should handle user/group/project ID (b20200)"
+
+test_27c() {
+ local limit
+
+ $LFS setquota -u $TSTID -b 30M -B 3T $DIR ||
+ error "lfs setquota failed"
+
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit != "30M" ] && error "softlimit $limit isn't human-readable"
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit != "3T" ] && error "hardlimit $limit isn't human-readable"
+
+ $LFS setquota -u $TSTID -b 1500M -B 18500G $DIR ||
+ error "lfs setquota for $TSTID failed"
+
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit != "1.465G" ] && error "wrong softlimit $limit"
+ limit=$($LFS quota -u $TSTID -v -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit != "18.07T" ] && error "wrong hardlimit $limit"
+
+ $LFS quota -u $TSTID -v -h $DIR | grep -q "Total allocated" ||
+ error "total allocated inode/block limit not printed"
+
+ resetquota -u $TSTUSR
+}
+run_test 27c "lfs quota should support human-readable output"
+
+test_27d() {
+ local softlimit=1.5
+ local hardlimit=2.3
+ local limit
+
+ $LFS setquota -u $TSTID -b ${softlimit}p -B ${hardlimit}P $DIR ||
+ error "set fraction block limit failed"
+ limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $3}')
+ [ $limit == ${softlimit}P ] || error "get fraction softlimit failed"
+ limit=$($LFS quota -u $TSTID -h $DIR | grep $DIR | awk '{print $4}')
+ [ $limit == ${hardlimit}P ] || error "get fraction hardlimit failed"
+
+ resetquota -u $TSTUSR
+}
+run_test 27d "lfs setquota should support fraction block limit"
+
+test_30() {
+ local LIMIT=4 # MB
+ local TESTFILE="$DIR/$tdir/$tfile"
+ local GRACE=10
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ set_ost_qtype "u" || error "enable ost quota failed"
+
+ $LFS setstripe $TESTFILE -i 0 -c 1 || error "setstripe $TESTFILE failed"
+ chown $TSTUSR.$TSTUSR $TESTFILE || error "chown $TESTFILE failed"
+
+ $LFS setquota -t -u --block-grace $GRACE --inode-grace \
+ $MAX_IQ_TIME $DIR || error "set grace time failed"
+ $LFS setquota -u $TSTUSR -b ${LIMIT}M -B 0 -i 0 -I 0 $DIR ||
+ error "set quota failed"
+ $RUNAS $DD of=$TESTFILE count=$((LIMIT * 2)) || true
+ cancel_lru_locks osc
+ sleep $GRACE
+ $LFS setquota -u $TSTUSR -B 0 $DIR || error "clear quota failed"
+ # over-quota flag has not yet settled since we do not trigger async
+ # events based on grace time period expiration
+ $SHOW_QUOTA_USER
+ $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 || true
+ cancel_lru_locks osc
+ # now over-quota flag should be settled and further writes should fail
+ $SHOW_QUOTA_USER
+ $RUNAS $DD of=$TESTFILE conv=notrunc oflag=append count=4 &&
+ error "grace times were reset"
+ $LFS setquota -t -u --block-grace $MAX_DQ_TIME --inode-grace \
+ $MAX_IQ_TIME $DIR || error "restore grace time failed"
+}
+run_test 30 "Hard limit updates should not reset grace times"
+
+# basic usage tracking for user & group
+test_33() {
+ local INODES=10 # files
+ local BLK_CNT=2 # MB each
+ local TOTAL_BLKS=$((INODES * BLK_CNT * 1024))
+
+ 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 -g $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space ($USED) for group $TSTID isn't 0."
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -ne 0 ] && error \
+ "Used space ($USED) for project $TSTPRJID isn't 0."
+ fi
+
+ echo "Write files..."
+ for i in $(seq 0 $INODES); do
+ $RUNAS $DD of=$DIR/$tdir/$tfile-$i count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ is_project_quota_supported &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile-$i
+ echo "Iteration $i/$INODES completed"
+ done
+ cancel_lru_locks osc
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ sync; sync_all_data || true
+
+ echo "Verify disk usage after write"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] &&
+ error "Used space for user $TSTID:$USED, expected:$TOTAL_BLKS"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] &&
+ error "Used space for group $TSTID:$USED, expected:$TOTAL_BLKS"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -lt $TOTAL_BLKS ] && error \
+ "Used space for project $TSTPRJID:$USED, expected:$TOTAL_BLKS"
+ fi
+
+ echo "Verify inode usage after write"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -lt $INODES ] &&
+ error "Used inode for user $TSTID is $USED, expected $INODES"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -lt $INODES ] &&
+ error "Used inode for group $TSTID is $USED, expected $INODES"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -lt $INODES ] && error \
+ "Used inode for project $TSTPRJID is $USED, expected $INODES"
+ fi
+
+ cleanup_quota_test
+
+ echo "Verify disk usage after delete"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -eq 0 ] || error "Used space for user $TSTID isn't 0. $USED"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -eq 0 ] || error "Used inodes for user $TSTID isn't 0. $USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -eq 0 ] || error "Used space for group $TSTID isn't 0. $USED"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq 0 ] || error "Used inodes for group $TSTID isn't 0. $USED"
+ if is_project_quota_supported; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -eq 0 ] ||
+ error "Used space for project $TSTPRJID isn't 0. $USED"
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -eq 0 ] ||
+ error "Used inodes for project $TSTPRJID isn't 0. $USED"
+ fi
+}
+run_test 33 "Basic usage tracking for user & group & project"
+
+# usage transfer test for user & group & project
+test_34() {
+ local BLK_CNT=2 # MB
+ local project_supported="no"
+
+ is_project_quota_supported && project_supported="yes"
+ 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 -g $TSTID global curspace)
+ [ $USED -ne 0 ] && error "Used space ($USED) for group $TSTID isn't 0."
+
+ local USED=$(getquota -u $TSTID2 global curspace)
+ [ $USED -ne 0 ] && error "Used space ($USED) for user $TSTID2 isn't 0."
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -ne 0 ] && error \
+ "Used space ($USED) for Project $TSTPRJID isn't 0."
+ fi
+
+ echo "Write file..."
+ $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ echo "chown the file to user $TSTID"
+ chown $TSTID $DIR/$tdir/$tfile || error "chown failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ BLK_CNT=$((BLK_CNT * 1024))
+
+ echo "Verify disk usage for user $TSTID"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for user $TSTID is ${USED}, expected $BLK_CNT"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -ne 1 ] &&
+ error "Used inodes for user $TSTID is $USED, expected 1"
+
+ echo "chgrp the file to group $TSTID"
+ chgrp $TSTID $DIR/$tdir/$tfile || error "chgrp failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "Verify disk usage for group $TSTID"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -ge $BLK_CNT ] ||
+ error "Used space for group $TSTID is $USED, expected $BLK_CNT"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq 1 ] ||
+ error "Used inodes for group $TSTID is $USED, expected 1"
+
+ # chown won't change the ost object group. LU-4345 */
+ echo "chown the file to user $TSTID2"
+ chown $TSTID2 $DIR/$tdir/$tfile || error "chown to $TSTID2 failed"
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "change_project project id to $TSTPRJID"
+ [ $project_supported == "yes" ] &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ echo "Verify disk usage for user $TSTID2/$TSTID and group $TSTID"
+ USED=$(getquota -u $TSTID2 global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for user $TSTID2 is $USED, expected $BLK_CNT"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -ne 0 ] &&
+ error "Used space for user $TSTID is $USED, expected 0"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -lt $BLK_CNT ] &&
+ error "Used space for group $TSTID is $USED, expected $BLK_CNT"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -lt $BLK_CNT ] && error \
+ "Used space for group $TSTPRJID is $USED, expected $BLK_CNT"
+ fi
+ return 0
+}
+run_test 34 "Usage transfer for user & group & project"
+
+# usage is still accessible across restart
+test_35() {
+ local BLK_CNT=2 # MB
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ echo "Write file..."
+ $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT 2>/dev/null ||
+ error "write failed"
+ is_project_quota_supported &&
+ change_project -p $TSTPRJID $DIR/$tdir/$tfile
+ cancel_lru_locks osc
+
+ echo "Wait for setattr on objects finished..."
+ wait_delete_completed
+
+ sync; sync_all_data || true
+
+ echo "Save disk usage before restart"
+ local ORIG_USR_SPACE=$(getquota -u $TSTID global curspace)
+ [ $ORIG_USR_SPACE -eq 0 ] &&
+ error "Used space for user $TSTID is 0, expected ${BLK_CNT}M"
+ local ORIG_USR_INODES=$(getquota -u $TSTID global curinodes)
+ [ $ORIG_USR_INODES -eq 0 ] &&
+ error "Used inodes for user $TSTID is 0, expected 1"
+ echo "User $TSTID: ${ORIG_USR_SPACE}KB $ORIG_USR_INODES inodes"
+ local ORIG_GRP_SPACE=$(getquota -g $TSTID global curspace)
+ [ $ORIG_GRP_SPACE -eq 0 ] &&
+ error "Used space for group $TSTID is 0, expected ${BLK_CNT}M"
+ local ORIG_GRP_INODES=$(getquota -g $TSTID global curinodes)
+ [ $ORIG_GRP_INODES -eq 0 ] &&
+ error "Used inodes for group $TSTID is 0, expected 1"
+ echo "Group $TSTID: ${ORIG_GRP_SPACE}KB $ORIG_GRP_INODES inodes"
+
+ if is_project_quota_supported; then
+ local ORIG_PRJ_SPACE=$(getquota -p $TSTPRJID global curspace)
+ [ $ORIG_PRJ_SPACE -eq 0 ] && error \
+ "Used space for project $TSTPRJID is 0, expected ${BLK_CNT}M"
+ local ORIG_PRJ_INODES=$(getquota -p $TSTPRJID global curinodes)
+ [ $ORIG_PRJ_INODES -eq 0 ] && error \
+ "Used inodes for project $TSTPRJID is 0, expected 1"
+ echo "Project $TSTPRJID: ${ORIG_PRJ_SPACE}KB $ORIG_PRJ_INODES inodes"
+ fi
+
+ log "Restart..."
+ stopall
+ setupall
+ quota_init
+
+ echo "Verify disk usage after restart"
+ local USED=$(getquota -u $TSTID global curspace)
+ [ $USED -eq $ORIG_USR_SPACE ] ||
+ error "Used space for user $TSTID changed from " \
+ "$ORIG_USR_SPACE to $USED"
+ USED=$(getquota -u $TSTID global curinodes)
+ [ $USED -eq $ORIG_USR_INODES ] ||
+ error "Used inodes for user $TSTID changed from " \
+ "$ORIG_USR_INODES to $USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -eq $ORIG_GRP_SPACE ] ||
+ error "Used space for group $TSTID changed from " \
+ "$ORIG_GRP_SPACE to $USED"
+ USED=$(getquota -g $TSTID global curinodes)
+ [ $USED -eq $ORIG_GRP_INODES ] ||
+ error "Used inodes for group $TSTID changed from " \
+ "$ORIG_GRP_INODES to $USED"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curinodes)
+ [ $USED -eq $ORIG_PRJ_INODES ] ||
+ error "Used inodes for project $TSTPRJID " \
+ "changed from $ORIG_PRJ_INODES to $USED"
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -eq $ORIG_PRJ_SPACE ] ||
+ error "Used space for project $TSTPRJID "\
+ "changed from $ORIG_PRJ_SPACE to $USED"
+ fi
+
+ # check if the vfs_dq_init() is called before writing
+ echo "Append to the same file..."
+ $RUNAS $DD of=$DIR/$tdir/$tfile count=$BLK_CNT seek=1 2>/dev/null ||
+ error "write failed"
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ echo "Verify space usage is increased"
+ USED=$(getquota -u $TSTID global curspace)
+ [ $USED -gt $ORIG_USR_SPACE ] ||
+ error "Used space for user $TSTID isn't increased" \
+ "orig:$ORIG_USR_SPACE, now:$USED"
+ USED=$(getquota -g $TSTID global curspace)
+ [ $USED -gt $ORIG_GRP_SPACE ] ||
+ error "Used space for group $TSTID isn't increased" \
+ "orig:$ORIG_GRP_SPACE, now:$USED"
+ if [ $project_supported == "yes" ]; then
+ USED=$(getquota -p $TSTPRJID global curspace)
+ [ $USED -gt $ORIG_PRJ_SPACE ] ||
+ error "Used space for project $TSTPRJID isn't " \
+ "increased orig:$ORIG_PRJ_SPACE, now:$USED"
+ fi
+}
+run_test 35 "Usage is still accessible across reboot"
+
+# chown/chgrp to the file created with MDS_OPEN_DELAY_CREATE
+# LU-5006
+test_37() {
+ [ "$MDS1_VERSION" -lt $(version_code 2.6.93) ] &&
+ skip "Old server doesn't have LU-5006 fix."
+
+ 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."
+
+ # create file with MDS_OPEN_DELAY_CREATE flag
+ $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile ||
+ error "Create file failed"
+ # write to file
+ dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 conv=notrunc \
+ oflag=sync || error "Write file failed"
+ # chown to the file
+ chown $TSTID $DIR/$tdir/$tfile || error "Chown to file failed"
+
+ # wait for setattr on objects finished..."
+ wait_delete_completed
+
+ 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 accnt_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_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"
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+ mkdir $dir && change_project -sp 1 $dir
+
+ touch $DIR/$tdir/file
+ #Try renaming a file into the project. This should fail.
+ for num in $(seq 1 2000); do
+ mrename $DIR/$tdir/file $dir/file >&/dev/null &&
+ error "rename should fail"
+ done
+ return 0
+}
+run_test 52 "Rename across different 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"