btrfs: add test for send/receive with file capabilities set
[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 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -fr $send_files_dir
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_test
33 _require_scratch
34 _require_command "$SETCAP_PROG" setcap
35 _require_command "$GETCAP_PROG" getcap
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 touch $SCRATCH_MNT/foo
47 touch $SCRATCH_MNT/bar
48 touch $SCRATCH_MNT/baz
49
50 # Set a capability only on file foo. Note that file foo has a lower inode number
51 # then files bar and baz - we want to test that if a file with a lower inode
52 # number has a capability set, after a send/receive, the capability is not set
53 # on the next files that have higher inode numbers.
54 $SETCAP_PROG cap_net_raw=p $SCRATCH_MNT/foo
55
56 # Now create the base snapshot, which is going to be the parent snapshot for
57 # a later incremental send.
58 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
59         $SCRATCH_MNT/mysnap1 > /dev/null
60
61 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
62         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
63
64 # Now do something similar as before, but this time to test incremental
65 # send/receive instead.
66
67 touch $SCRATCH_MNT/foo2
68 touch $SCRATCH_MNT/bar2
69 touch $SCRATCH_MNT/baz2
70
71 # Add a capability to file bar now. We want to check later that the capability
72 # is not added to file baz or any of the new files foo2, bar2 and baz2.
73 $SETCAP_PROG cap_net_raw=p $SCRATCH_MNT/bar
74
75 # Add a capability to the new file foo2, we want to check later that it is not
76 # incorrectly propagated to the new files bar2 and baz2.
77 $SETCAP_PROG cap_sys_nice=ep $SCRATCH_MNT/foo2
78
79 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
80                  $SCRATCH_MNT/mysnap2 > /dev/null
81 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
82                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
83
84 # Now recreate the filesystem by receiving both send streams.
85 _scratch_unmount
86 _scratch_mkfs >>$seqres.full 2>&1
87 _scratch_mount
88
89 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
90 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
91
92 echo "File mysnap1/foo capabilities:"
93 _getcap $SCRATCH_MNT/mysnap1/foo | _filter_scratch
94 echo "File mysnap1/bar capabilities:"
95 _getcap $SCRATCH_MNT/mysnap1/bar | _filter_scratch
96 echo "File mysnap1/baz capabilities:"
97 _getcap $SCRATCH_MNT/mysnap1/baz | _filter_scratch
98
99 echo "File mysnap2/foo capabilities:"
100 _getcap $SCRATCH_MNT/mysnap2/foo | _filter_scratch
101 echo "File mysnap2/bar capabilities:"
102 _getcap $SCRATCH_MNT/mysnap2/bar | _filter_scratch
103 echo "File mysnap2/baz capabilities:"
104 _getcap $SCRATCH_MNT/mysnap2/baz | _filter_scratch
105 echo "File mysnap2/foo2 capabilities:"
106 _getcap $SCRATCH_MNT/mysnap2/foo2 | _filter_scratch
107 echo "File mysnap2/bar2 capabilities:"
108 _getcap $SCRATCH_MNT/mysnap2/bar2 | _filter_scratch
109 echo "File mysnap2/baz2 capabilities:"
110 _getcap $SCRATCH_MNT/mysnap2/baz2 | _filter_scratch
111
112 status=0
113 exit