fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 235
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/235
6 #
7 # Test that if we set a capability on a file but not on the next files we create,
8 # send/receive operations only apply the capability to the first file, the one
9 # for which we have set a capability.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick send
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         cd /
18         rm -fr $send_files_dir
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24
25 # real QA test starts here
26 _supported_fs btrfs
27 _require_test
28 _require_scratch
29 _require_command "$SETCAP_PROG" setcap
30 _require_command "$GETCAP_PROG" getcap
31
32 send_files_dir=$TEST_DIR/btrfs-test-$seq
33
34 rm -fr $send_files_dir
35 mkdir $send_files_dir
36
37 _scratch_mkfs >>$seqres.full 2>&1
38 _scratch_mount
39
40 touch $SCRATCH_MNT/foo
41 touch $SCRATCH_MNT/bar
42 touch $SCRATCH_MNT/baz
43
44 # Set a capability only on file foo. Note that file foo has a lower inode number
45 # then files bar and baz - we want to test that if a file with a lower inode
46 # number has a capability set, after a send/receive, the capability is not set
47 # on the next files that have higher inode numbers.
48 $SETCAP_PROG cap_net_raw=p $SCRATCH_MNT/foo
49
50 # Now create the base snapshot, which is going to be the parent snapshot for
51 # a later incremental send.
52 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
53         $SCRATCH_MNT/mysnap1 > /dev/null
54
55 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
56         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
57
58 # Now do something similar as before, but this time to test incremental
59 # send/receive instead.
60
61 touch $SCRATCH_MNT/foo2
62 touch $SCRATCH_MNT/bar2
63 touch $SCRATCH_MNT/baz2
64
65 # Add a capability to file bar now. We want to check later that the capability
66 # is not added to file baz or any of the new files foo2, bar2 and baz2.
67 $SETCAP_PROG cap_net_raw=p $SCRATCH_MNT/bar
68
69 # Add a capability to the new file foo2, we want to check later that it is not
70 # incorrectly propagated to the new files bar2 and baz2.
71 $SETCAP_PROG cap_sys_nice=ep $SCRATCH_MNT/foo2
72
73 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
74                  $SCRATCH_MNT/mysnap2 > /dev/null
75 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
76                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
77
78 # Now recreate the filesystem by receiving both send streams.
79 _scratch_unmount
80 _scratch_mkfs >>$seqres.full 2>&1
81 _scratch_mount
82
83 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
84 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
85
86 echo "File mysnap1/foo capabilities:"
87 _getcap $SCRATCH_MNT/mysnap1/foo | _filter_scratch
88 echo "File mysnap1/bar capabilities:"
89 _getcap $SCRATCH_MNT/mysnap1/bar | _filter_scratch
90 echo "File mysnap1/baz capabilities:"
91 _getcap $SCRATCH_MNT/mysnap1/baz | _filter_scratch
92
93 echo "File mysnap2/foo capabilities:"
94 _getcap $SCRATCH_MNT/mysnap2/foo | _filter_scratch
95 echo "File mysnap2/bar capabilities:"
96 _getcap $SCRATCH_MNT/mysnap2/bar | _filter_scratch
97 echo "File mysnap2/baz capabilities:"
98 _getcap $SCRATCH_MNT/mysnap2/baz | _filter_scratch
99 echo "File mysnap2/foo2 capabilities:"
100 _getcap $SCRATCH_MNT/mysnap2/foo2 | _filter_scratch
101 echo "File mysnap2/bar2 capabilities:"
102 _getcap $SCRATCH_MNT/mysnap2/bar2 | _filter_scratch
103 echo "File mysnap2/baz2 capabilities:"
104 _getcap $SCRATCH_MNT/mysnap2/baz2 | _filter_scratch
105
106 status=0
107 exit