+test_76() {
+ ! is_project_quota_supported &&
+ skip "skip project quota unsupported"
+
+ setup_quota_test || error "setup quota failed with $?"
+ quota_init
+
+ local testfile="$DIR/$tdir/$tfile-0"
+
+ touch $testfile
+ $LFS project -p 4294967295 $testfile &&
+ error "set project ID should fail"
+ return 0
+}
+run_test 76 "project ID 4294967295 should be not allowed"
+
+test_77()
+{
+ mount_client $MOUNT2 "ro"
+ lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
+ error "lfs setquota should fail in read-only Lustre mount"
+ umount $MOUNT2
+}
+run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
+
+test_78()
+{
+ (( $OST1_VERSION >= $(version_code 2.14.55) )) ||
+ skip "need OST at least 2.14.55"
+ check_set_fallocate_or_skip
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ # enable ost quota
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ mkdir -p $DIR/$tdir || error "failed to create $tdir"
+ chown $TSTUSR $DIR/$tdir || error "failed to chown $tdir"
+
+ # setup quota limit
+ $LFS setquota -u $TSTUSR -b25M -B25M $DIR/$tdir ||
+ error "lfs setquota failed"
+
+ # call fallocate
+ runas -u $TSTUSR -g $TSTUSR fallocate -l 204800 $DIR/$tdir/$tfile
+
+ kbytes=$(lfs quota -u $TSTUSR $DIR |
+ awk -v pattern=$DIR 'match($0, pattern) {printf $2}')
+ echo "kbytes returned:$kbytes"
+
+ # For file size of 204800. We should be having roughly 200 kbytes
+ # returned. Anything alarmingly low (50 taken as arbitrary value)
+ # would bail out this TC. Also this also avoids $kbytes of 0
+ # to be used in calculation below.
+ (( $kbytes > 50 )) ||
+ error "fallocate did not use quota. kbytes returned:$kbytes"
+
+ local expect_lo=$(($kbytes * 95 / 100)) # 5% below
+ local expect_hi=$(($kbytes * 105 / 100)) # 5% above
+
+ # Verify kbytes is 200 (204800/1024). With a permited 5% drift
+ (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
+ error "fallocate did not use quota correctly"
+}
+run_test 78 "Check fallocate increase quota usage"
+
+test_78a()
+{
+ (( $CLIENT_VERSION >= $(version_code 2.15.0) )) ||
+ skip "need client at least 2.15.0"
+ (( $OST1_VERSION >= $(version_code 2.15.0) )) ||
+ skip "need OST at least 2.15.0"
+ check_set_fallocate_or_skip
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ # enable ost quota
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ mkdir -p $DIR/$tdir || error "failed to create $tdir"
+
+ local projectid=5200 # Random project id to test
+
+ change_project -sp $projectid $DIR/$tdir
+
+ # setup quota limit
+ $LFS setquota -p $projectid -b25M -B25M $DIR/$tdir ||
+ error "lfs setquota project failed"
+
+ # call fallocate
+ fallocate -l 204800 $DIR/$tdir/$tfile
+
+ # Get curspace (kbytes) for $projectid
+ local kbytes=$(getquota -p $projectid global curspace)
+
+ echo "kbytes returned:$kbytes"
+
+ # For file size of 204800. We should be having roughly 200 kbytes
+ # returned. Anything alarmingly low (50 taken as arbitrary value)
+ # would bail out this TC. Also this also avoids $kbytes of 0
+ # to be used in calculation below.
+ (( $kbytes > 50 )) ||
+ error "fallocate did not use projectid. kbytes returned:$kbytes"
+
+ local expect_lo=$(($kbytes * 95 / 100)) # 5% below
+ local expect_hi=$(($kbytes * 105 / 100)) # 5% above
+
+ # Verify kbytes is 200 (204800/1024). With a permited 5% drift
+ (( $kbytes >= $expect_lo && $kbytes <= $expect_hi )) ||
+ error "fallocate did not use quota projectid correctly"
+}
+run_test 78a "Check fallocate increase projectid usage"
+
+test_79()
+{
+ local qpool="qpool1"
+ local cmd="$LCTL get_param -n qmt.$FSNAME-QMT0000.dt-$qpool.info"
+ local stopf=$TMP/$tfile
+
+ do_facet mds1 "touch $stopf"
+ stack_trap "do_facet mds1 'rm -f $stopf'"
+ do_facet mds1 "while [ -e $stopf ]; do $cmd &>/dev/null; done"&
+ local pid=$!
+ pool_add $qpool || error "pool_add failed"
+ do_facet mds1 "rm $stopf"
+ wait $pid
+}
+run_test 79 "access to non-existed dt-pool/info doesn't cause a panic"
+
+test_80()
+{
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+ local TESTFILE0="$dir1/$tfile-0"
+ local TESTFILE1="$dir1/$tfile-1"
+ local TESTFILE2="$dir1/$tfile-2"
+ local TESTFILE3="$dir2/$tfile-0"
+ local global_limit=100 # 100M
+ local limit=10 # 10M
+ local qpool="qpool1"
+
+ [ "$OSTCOUNT" -lt "2" ] && skip "needs >= 2 OSTs"
+ mds_supports_qp
+ [ "$ost1_FSTYPE" == zfs ] &&
+ skip "ZFS grants some block space together with inode"
+ setup_quota_test || error "setup quota failed with $?"
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # make sure the system is clean
+ local used=$(getquota -u $TSTUSR global curspace)
+ [ $used -ne 0 ] && error "Used space($used) for user $TSTUSR is not 0."
+
+ pool_add $qpool || error "pool_add failed"
+ pool_add_targets $qpool 0 1 ||
+ error "pool_add_targets failed"
+
+ $LFS setquota -u $TSTUSR -b 0 -B ${global_limit}M -i 0 -I 0 $DIR ||
+ error "set user quota failed"
+
+ $LFS setquota -u $TSTUSR -B ${global_limit}M --pool $qpool $DIR ||
+ error "set user quota failed"
+ $LFS setquota -u $TSTUSR -B ${limit}M --pool $qpool $DIR ||
+ error "set user quota failed"
+
+ mkdir -p $dir1 || error "failed to mkdir"
+ chown $TSTUSR.$TSTUSR $dir1 || error "chown $dir1 failed"
+ mkdir -p $dir2 || error "failed to mkdir"
+ chown $TSTUSR.$TSTUSR $dir2 || error "chown $dir2 failed"
+
+ $LFS setstripe $dir1 -i 1 -c 1|| error "setstripe $testfile failed"
+ $LFS setstripe $dir2 -i 0 -c 1|| error "setstripe $testfile failed"
+ lfs getstripe $dir1
+ lfs getstripe $dir2
+ sleep 3
+
+ $LFS quota -uv $TSTUSR $DIR
+ #define OBD_FAIL_QUOTA_PREACQ 0xA06
+ do_facet mds1 $LCTL set_param fail_loc=0xa06
+ $RUNAS $DD of=$TESTFILE3 count=3 ||
+ quota_error u $TSTUSR "write failed"
+ $RUNAS $DD of=$TESTFILE2 count=7 ||
+ quota_error u $TSTUSR "write failed"
+ $RUNAS $DD of=$TESTFILE1 count=1 oflag=direct ||
+ quota_error u $TSTUSR "write failed"
+ sync
+ sleep 3
+ $LFS quota -uv --pool $qpool $TSTUSR $DIR
+
+ rm -f $TESTFILE2
+ stop ost2
+ do_facet mds1 $LCTL set_param fail_loc=0
+ start ost2 $(ostdevname 2) $OST_MOUNT_OPTS || error "start ost2 failed"
+ $LFS quota -uv $TSTUSR --pool $qpool $DIR
+ # OST0 needs some time to update quota usage after removing TESTFILE2
+ sleep 4
+ $LFS quota -uv $TSTUSR --pool $qpool $DIR
+ $RUNAS $DD of=$TESTFILE0 count=2 oflag=direct ||
+ quota_error u $TSTUSR "write failure, but expect success"
+}
+run_test 80 "check for EDQUOT after OST failover"
+
+test_81() {
+ local global_limit=20 # 100M
+ local testfile="$DIR/$tdir/$tfile-0"
+ local qpool="qpool1"
+
+ mds_supports_qp
+ setup_quota_test || error "setup quota failed with $?"
+
+ # enable ost quota
+ set_ost_qtype $QTYPE || error "enable ost quota failed"
+
+ # test for user
+ log "User quota (block hardlimit:$global_limit MB)"
+ $LFS setquota -u $TSTUSR -B 1G $DIR || error "set user quota failed"
+
+ pool_add $qpool || error "pool_add failed"
+ #define OBD_FAIL_QUOTA_RECALC 0xA07
+ do_facet mds1 $LCTL set_param fail_loc=0x80000A07 fail_val=30
+ # added OST casues to start pool recalculation
+ pool_add_targets $qpool 0 0 1
+ stop mds1 -f || error "MDS umount failed"
+
+ #start mds1 back to destroy created pool
+ start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
+ clients_up || true
+}
+run_test 81 "Race qmt_start_pool_recalc with qmt_pool_free"
+
+test_82()
+{
+ (( $MDS1_VERSION >= $(version_code 2.14.55) )) ||
+ skip "need MDS 2.14.55 or later"
+ is_project_quota_supported ||
+ skip "skip project quota unsupported"
+
+ setup_quota_test || error "setup quota failed with $?"
+ stack_trap cleanup_quota_test
+ quota_init
+
+ local parent_dir="$DIR/$tdir.parent"
+ local child_dir="$parent_dir/child"
+
+ mkdir -p $child_dir
+ stack_trap "chown -R 0:0 $parent_dir"
+
+ chown $TSTUSR:$TSTUSR $parent_dir ||
+ error "failed to chown on $parent_dir"
+ chown $TSTUSR2:$TSTUSRS2 $child_dir ||
+ error "failed to chown on $parent_dir"
+
+ $LFS project -p 1000 $parent_dir ||
+ error "failed to set project id on $parent_dir"
+ $LFS project -p 1001 $child_dir ||
+ error "failed to set project id on $child_dir"
+
+ rmdir $child_dir || error "cannot remove child dir, test failed"
+}
+run_test 82 "verify more than 8 qids for single operation"
+