btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 107
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 107
6 #
7 # Project quota.
8 # Use of "sync" mount option here is an attempt to get deterministic
9 # allocator behaviour.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
19
20 # get standard environment, filters and checks
21 . ./common/rc
22 . ./common/filter
23 . ./common/quota
24
25 filter_xfs_quota()
26 {
27         perl -ne "
28 s,$target,[TARGET],;
29 s,$tmp.projects,[PROJECTS_FILE],;
30 s,$SCRATCH_MNT,[SCR_MNT],;
31 s,$SCRATCH_DEV,[SCR_DEV],;
32 s/Inode: \#\d+ \(0 blocks, 0 extents\)/Inode: #[INO] (0 blocks, 0 extents)/;
33 s/Inode: \#\d+ \(\d+ blocks, \d+ extents\)/Inode: #[INO] (X blocks, Y extents)/;
34         print;"
35 }
36
37 _supported_fs xfs
38 _require_scratch
39 _require_xfs_quota
40
41 # real QA test starts here
42 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
43 cat $tmp.mkfs >$seqres.full
44 . $tmp.mkfs
45
46 # setup a default run
47 if [ -z "$MOUNT_OPTIONS" ]; then
48         export MOUNT_OPTIONS="-o pquota,sync"
49 else
50         export MOUNT_OPTIONS="$MOUNT_OPTIONS -o sync"
51 fi
52
53 _qmount
54 _require_prjquota $SCRATCH_DEV
55
56 echo "### create projects file"
57 rm -f $tmp.projects
58 target=$SCRATCH_MNT/project
59 echo "6:$target" | tee -a $seqres.full > $tmp.projects
60
61 echo "### populate filesystem"
62 mkdir $target           || exit
63 $FSSTRESS_PROG -z -s 65261 -m 8 -n 1000 -p 4 \
64 -f allocsp=1 \
65 -f chown=3 \
66 -f creat=4 \
67 -f dwrite=4 \
68 -f fallocate=1 \
69 -f fdatasync=1 \
70 -f fiemap=1 \
71 -f freesp=1 \
72 -f fsync=1 \
73 -f link=1 \
74 -f mkdir=2 \
75 -f punch=1 \
76 -f rename=2 \
77 -f resvsp=1 \
78 -f rmdir=1 \
79 -f setxattr=1 \
80 -f sync=1 \
81 -f truncate=2 \
82 -f unlink=1 \
83 -f unresvsp=1 \
84 -f write=4 \
85 -d $target
86
87 $FSSTRESS_PROG -z -s 47806 -m 8 -n 500 -p 4 \
88 -f chown=250 \
89 -f setxattr=250 \
90 -d $target
91
92 QARGS="-x -D $tmp.projects -P /dev/null $SCRATCH_MNT"
93
94 echo "### initial report"
95 xfs_quota -c 'quot -p' -c 'quota -ip 6' $QARGS | filter_xfs_quota
96
97 echo "### check the project, should give warnings"
98 xfs_quota -c 'project -c 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
99
100 echo "### recursively setup the project"
101 xfs_quota -c 'project -s 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
102 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
103
104 echo "### check the project, should give no warnings now"
105 xfs_quota -c 'project -c 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
106
107 echo "### deny a hard link - wrong project ID"
108 rm -f $SCRATCH_MNT/outer $target/inner
109 $XFS_IO_PROG -f -c 'chproj 789' $SCRATCH_MNT/outer
110 ln $SCRATCH_MNT/outer $target/inner 2>/dev/null
111 if [ $? -eq 0 ]; then
112         echo hard link succeeded
113         ls -ld $SCRATCH_MNT/outer $target/inner
114 else
115         echo hard link failed
116 fi
117 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
118
119 echo "### allow a hard link - right project ID"
120 $XFS_IO_PROG -c 'chproj 6' $SCRATCH_MNT/outer
121 ln $SCRATCH_MNT/outer $target/inner
122 if [ $? -eq 0 ]; then
123         echo hard link succeeded
124 else
125         echo hard link failed
126         ls -ld $SCRATCH_MNT/outer $target/inner
127 fi
128 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
129
130 echo "### recursively clear the project"
131 xfs_quota -c 'project -C 6' $QARGS | LC_COLLATE=POSIX sort | filter_xfs_quota
132 #no output...
133 xfs_quota -c 'quota -ip 6' $QARGS | filter_xfs_quota
134
135 status=0
136 exit