xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / ceph / 004
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 004
6 #
7 # Tests a bug fix found in cephfs quotas handling.  Here's a simplified testcase
8 # that *should* fail:
9 #
10 #    mkdir files limit
11 #    truncate files/file -s 10G
12 #    setfattr limit -n ceph.quota.max_bytes -v 1000000
13 #    mv files limit/
14 #
15 # Because we're creating a new file and truncating it, we have Fx caps and thus
16 # the truncate operation will be cached.  This prevents the MDSs from updating
17 # the quota realms and thus the client will allow the above rename(2) to happen.
18 #
19 # The bug resulted in dropping support for cross quota-realms renames, reverting
20 # kernel commit dffdcd71458e ("ceph: allow rename operation under different
21 # quota realms").
22 #
23 # So, the above test will now fail with a -EXDEV or, in the future (when we have
24 # a proper fix), with -EDQUOT.
25 #
26 # This bug was tracker here:
27 #
28 #   https://tracker.ceph.com/issues/48203
29 #
30 seq=`basename $0`
31 seqres=$RESULT_DIR/$seq
32 echo "QA output created by $seq"
33
34 here=`pwd`
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48 . ./common/attr
49
50 # remove previous $seqres.full before test
51 rm -f $seqres.full
52
53 # real QA test starts here
54
55 _supported_fs ceph
56 _require_attrs
57 _require_test
58 _require_test_program "rename"
59 _require_ceph_vxattr_caps # we need to get file capabilities
60
61 workdir=$TEST_DIR/test-$seq
62
63 orig1=$workdir/orig1
64 orig2=$workdir/orig2
65 file1=$orig1/file
66 file2=$orig2/file
67 dest=$workdir/dest
68
69 rm -rf $workdir
70 mkdir $workdir
71 mkdir $orig1 $orig2 $dest
72
73 # get only the hexadecimal value of the ceph.caps vxattr, which has the
74 # following format:
75 #   ceph.caps="pAsLsXsFscr/0xd55"
76 get_ceph_caps()
77 {
78         $GETFATTR_PROG --only-values -n "ceph.caps" $1 2>/dev/null \
79             | cut -d / -f2
80 }
81
82 # check that a file has cephfs capabilities 'Fs'
83 check_Fs_caps()
84 {
85         caps=`get_ceph_caps $1`
86         # Fs cap is bit (1 << 8)
87         Fs=$((1 << 8))
88         res=$(($caps & $Fs))
89         if [ $res -ne $Fs ]; then
90                 _fail "File $1 doesn't have Fs caps ($caps)"
91         fi
92 }
93
94 # set quota to 1m
95 $SETFATTR_PROG -n ceph.quota.max_bytes -v 1000000 $dest
96 # set quota to 20g
97 $SETFATTR_PROG -n ceph.quota.max_bytes -v 20000000000 $orig2
98
99 #
100 # The following 2 testcases shall fail with either -EXDEV or -EDQUOT
101 #
102
103 # from 'root' realm to $dest realm
104 $XFS_IO_PROG -f -c "truncate 10G" $file1
105 check_Fs_caps $file1
106 $here/src/rename $orig1 $dest/new1 >> $seqres.full 2>&1
107 [ $? -ne 1 ] && _fail "cross quota realms rename succeeded"
108
109 # from $orig2 realm to $dest realm
110 $XFS_IO_PROG -f -c "truncate 10G" $file2
111 check_Fs_caps $file2
112 $here/src/rename $orig2 $dest/new2 >> $seqres.full 2>&1
113 [ $? -ne 1 ] && _fail "cross quota realms rename succeeded"
114
115 echo "Silence is golden"
116
117 # success, all done
118 status=0
119 exit