2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/235
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.
12 _begin_fstest auto quick send
14 # Override the default cleanup function.
18 rm -fr $send_files_dir
22 # Import common functions.
25 # real QA test starts here
29 _require_command "$SETCAP_PROG" setcap
30 _require_command "$GETCAP_PROG" getcap
32 send_files_dir=$TEST_DIR/btrfs-test-$seq
34 rm -fr $send_files_dir
37 _scratch_mkfs >>$seqres.full 2>&1
40 touch $SCRATCH_MNT/foo
41 touch $SCRATCH_MNT/bar
42 touch $SCRATCH_MNT/baz
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
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
55 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
56 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
58 # Now do something similar as before, but this time to test incremental
59 # send/receive instead.
61 touch $SCRATCH_MNT/foo2
62 touch $SCRATCH_MNT/bar2
63 touch $SCRATCH_MNT/baz2
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
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
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
78 # Now recreate the filesystem by receiving both send streams.
80 _scratch_mkfs >>$seqres.full 2>&1
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
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
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