+# LU-8801
+test_38() {
+ [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.60) ] &&
+ skip "Old server doesn't have LU-8801 fix." && return
+
+ [ "$UID" != 0 ] && skip_env "must run as root" && return
+
+ setup_quota_test || error "setup quota failed with $?"
+ trap cleanup_quota_test EXIT
+
+ # 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
+ done
+ cancel_lru_locks osc
+ sync; sync_all_data || true
+
+ local procf="osd-$(facet_fstype $SINGLEMDS).$FSNAME-MDT0000"
+ procf=${procf}.quota_slave.acct_user
+ local accnt_cnt
+
+ acct_cnt=$(do_facet mds1 $LCTL get_param $procf | grep "id:" | wc -l)
+ echo "Found $acct_cnt id entries"
+
+ [ $file_cnt -eq $acct_cnt ] || error "skipped id entries"
+
+ cleanup_quota_test
+}
+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" && return 0
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ touch $TESTFILE
+ projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+ [ $projectid -ne 0 ] &&
+ error "Project id should be 0 not $projectid"
+ change_project -p 1024 $TESTFILE
+ projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+ [ $projectid -ne 1024 ] &&
+ error "Project id should be 1024 not $projectid"
+
+ stopall || error "failed to stopall (1)"
+ mount
+ setupall
+ projectid=$(lsattr -p $TESTFILE | awk '{print $1}')
+ [ $projectid -ne 1024 ] &&
+ error "Project id should be 1024 not $projectid"
+
+ cleanup_quota_test
+}
+run_test 39 "Project ID interface works correctly"
+
+test_40a() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+
+ setup_quota_test || error "setup quota failed with $?"
+
+ mkdir -p $dir1 $dir2
+ change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
+ change_project +P $dir2 && change_project -p 2 -d $dir2
+
+ ln $dir1/1 $dir2/1_link &&
+ error "Hard link across different project quota should fail"
+ rm -rf $dir1 $dir2
+
+ cleanup_quota_test
+}
+run_test 40a "Hard link across different project ID"
+
+test_40b() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+ local dir1="$DIR/$tdir/dir1"
+ local dir2="$DIR/$tdir/dir2"
+
+ setup_quota_test || error "setup quota failed with $?"
+ mkdir -p $dir1 $dir2
+ change_project +P $dir1 && change_project -p 1 -d $dir1 && touch $dir1/1
+ change_project +P $dir2 && change_project -p 2 -d $dir2
+
+ mv $dir1/1 $dir2/2 || error "mv failed $?"
+ local projid=$(lsattr -p $dir2/2 | awk '{print $1}')
+ if [ "$projid" != "2" ]; then
+ error "project id expected 2 not $projid"
+ fi
+ rm -rf $dir1 $dir2
+ cleanup_quota_test
+}
+run_test 40b "Mv across different project ID"
+
+test_40c() {
+ [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs" && return
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir -p $dir && change_project +P $dir && change_project -dp 1 $dir
+ $LFS mkdir -i 1 $dir/remote_dir || error "create remote dir failed"
+ local projid=$(lsattr -dp $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=$(lsattr -dp $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
+ USED=$(getquota -p 1 global curinodes)
+ [ "$USED" != "3" ] &&
+ error "file count expected 3 got $USED"
+
+ rm -rf $dir
+ cleanup_quota_test
+ return 0
+}
+run_test 40c "Remote child Dir inherit project quota properly"
+
+test_50() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir $dir && change_project -dp 1 $dir
+ count=$($LFS find --projid 1 $DIR | wc -l)
+ [ "$count" != 1 ] && error "expected 1 but got $count"
+
+ rm -rf $dir
+ cleanup_quota_test
+}
+run_test 50 "Test if lfs find --projid works"
+
+test_51() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+
+ mkdir $dir && change_project -dp 1 $dir && change_project +P $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 != "6" ] && error "expected 6 got $used"
+
+ rm -rf $dir
+ cleanup_quota_test
+}
+run_test 51 "Test project accounting with mv/cp"
+
+test_52() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+ mkdir $dir && change_project -dp 1 $dir && change_project +P $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
+ rm -rf $dir
+ cleanup_quota_test
+}
+run_test 52 "Rename across different project ID"
+
+test_53() {
+ ! is_project_quota_supported &&
+ skip "Project quota is not supported" && return 0
+ setup_quota_test || error "setup quota failed with $?"
+ local dir="$DIR/$tdir/dir"
+ mkdir $dir && change_project +P $dir
+ lsattr -pd $dir | grep P || error "inherit attribute should be set"
+
+ change_project -Pd $dir
+ lsattr -pd $dir | grep P && error "inherit attribute should be cleared"
+
+ rm -rf $dir
+ cleanup_quota_test
+}
+run_test 53 "Project inherit attribute could be cleared"
+