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 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
22 rm -fr $send_files_dir
26 # get standard environment, filters and checks
30 # real QA test starts here
34 _require_command "$SETCAP_PROG" setcap
35 _require_command "$GETCAP_PROG" getcap
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
40 rm -fr $send_files_dir
43 _scratch_mkfs >>$seqres.full 2>&1
46 touch $SCRATCH_MNT/foo
47 touch $SCRATCH_MNT/bar
48 touch $SCRATCH_MNT/baz
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
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
61 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
62 $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
64 # Now do something similar as before, but this time to test incremental
65 # send/receive instead.
67 touch $SCRATCH_MNT/foo2
68 touch $SCRATCH_MNT/bar2
69 touch $SCRATCH_MNT/baz2
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
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
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
84 # Now recreate the filesystem by receiving both send streams.
86 _scratch_mkfs >>$seqres.full 2>&1
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
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
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