populate: add _require_populate_commands to check for tools
[xfstests-dev.git] / tests / xfs / 296
1 #! /bin/bash
2 # FS QA Test No. 296
3 #
4 # Test that xfsdump/restore preserves file capabilities
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     cd /
36     rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/dump
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs xfs
48 _supported_os Linux
49 _require_scratch
50
51 rm -f $seqres.full
52
53 _wipe_fs
54
55 mkdir -p $dump_dir
56 echo test > $dump_dir/testfile
57 # Set a generic xattr
58 setfattr -n user.name -v value $dump_dir/testfile
59 # Now set the cap (which is also an xattr)
60 setcap cap_setgid,cap_setuid+ep $dump_dir/testfile
61 # And make sure they are there on the source
62 echo "Checking for xattr on source file"
63 getfattr --absolute-names -m user.name $dump_dir/testfile | _dir_filter
64 echo "Checking for capability on source file"
65 getcap $dump_dir/testfile | _dir_filter
66 getfattr --absolute-names -m security.capability $dump_dir/testfile | _dir_filter
67
68 _do_dump_file -f $tmp.df.0
69 _prepare_restore_dir
70 _do_restore_file
71 # Basic dump/restore checks first - the file is there, right?
72 _ls_compare_sub
73 _diff_compare
74
75 echo "Checking for xattr on restored file"
76 getfattr --absolute-names -m user.name $restore_dir/$dump_sdir/testfile | _dir_filter
77 echo "Checking for capability on restored file"
78 getcap $restore_dir/$dump_sdir/testfile | _dir_filter
79 getfattr --absolute-names -m security.capability $restore_dir/$dump_sdir/testfile | _dir_filter
80
81 status=0
82 exit