generic/077: fall back to /usr if /lib/modules doesn't exist
[xfstests-dev.git] / tests / xfs / 300
1 #! /bin/bash
2 # FS QA Test No. 300
3 #
4 # Test xfs_fsr / swapext management of di_forkoff w/ selinux
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 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     cd /
35     rm -f $tmp.*
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41
42 _require_scratch
43
44 # real QA test starts here
45
46 _supported_fs xfs
47 _supported_os Linux
48
49 getenforce | grep -q "Enforcing\|Permissive" || _notrun "SELinux not enabled"
50 [ "$XFS_FSR_PROG" = "" ] && _notrun "xfs_fsr not found"
51
52 rm -f $seqres.full
53
54 _scratch_mkfs_xfs -i size=256 >> $seqres.full 2>&1 || _fail "mkfs failed"
55
56 # Manually mount to avoid fs-wide context set by default in xfstests
57 mount $SCRATCH_DEV $SCRATCH_MNT
58
59 touch $SCRATCH_MNT/$seq.test
60
61 # Create an extents-format attribute on a file
62 $XFS_IO_PROG -f -c "pwrite -S 0x63 0 4096" $SCRATCH_MNT/attrvals >> $seqres.full 2>&1
63 cat $SCRATCH_MNT/attrvals | attr -s name $SCRATCH_MNT/$seq.test >> $seqres.full 2>&1
64
65 # Fragment the file by writing backwards
66 for I in `seq 6 -1 0`; do
67         dd if=/dev/zero of=$SCRATCH_MNT/$seq.test seek=$I bs=4k \
68            oflag=direct count=1 conv=notrunc >> $seqres.full 2>&1
69 done
70
71 # See if xfs_fsr works.
72
73 # The target file now has a non-local attribute, but the
74 # fsr temp file gets assigned a local attribute on creation,
75 # due to selinux.
76     
77 # In this case, the large-ish selinux attr will create a forkoff
78 # in the temp file smaller than the forkoff in the target file,
79 # because the FMT_EXTENTS attr takes up less space.  If there is
80 # no mechanism to grow the temp forkoff to match, we can end up
81 # failing to swap these 2 inodes if the result is not enough
82 # data space in the temp inode as a result.
83
84 $XFS_FSR_PROG -v $SCRATCH_MNT/$seq.test | _filter_scratch
85
86 # success, all done
87 status=0
88 exit