f703c0dcf92faaefe74e1e210d8d992d453574ea
[xfstests-dev.git] / tests / xfs / 207
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 207
6 #
7 # Test setting the extsz and cowextsz hints:
8 # - Ensure that we can set both on a zero-byte file.
9 # - Ensure that we can set only cowextsz on a many-byte file.
10 # - Ensure that whatever we set we get back later.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -rf $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_scratch_reflink
35 _require_cp_reflink
36 _require_xfs_io_command "fiemap"
37 _require_xfs_io_command "cowextsize"
38
39 # Takes the fsxattr.xflags line,
40 # i.e. fsxattr.xflags = 0x0 [--------------C-]
41 # and tests whether a flag character is set
42 test_xflag()
43 {
44     local flg=$1
45     grep -q "\[.*${flg}.*\]" && echo "$flg flag set" || echo "$flg flag unset"
46 }
47
48 rm -f $seqres.full
49
50 echo "Format and mount"
51 _scratch_mkfs > $seqres.full 2>&1
52 _scratch_mount >> $seqres.full 2>&1
53
54 testdir=$SCRATCH_MNT/test-$seq
55 mkdir $testdir
56
57 echo "Create the original files"
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 0" $testdir/file1 >> $seqres.full
59 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 1048576" $testdir/file2 >> $seqres.full
60 $XFS_IO_PROG -f -c "pwrite -S 0x61 0 0" $testdir/file3 >> $seqres.full
61 _scratch_cycle_mount
62
63 echo "Set extsz and cowextsz on zero byte file"
64 $XFS_IO_PROG -c "extsize 1048576" $testdir/file1 | _filter_scratch
65 $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file1 | _filter_scratch
66
67 echo "Set extsz and cowextsz on 1Mbyte file"
68 $XFS_IO_PROG -c "extsize 1048576" $testdir/file2 | _filter_scratch
69 $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file2 | _filter_scratch
70 _scratch_cycle_mount
71
72 echo "Check extsz and cowextsz settings on zero byte file"
73 $XFS_IO_PROG -c "extsize" $testdir/file1 | _filter_scratch
74 $XFS_IO_PROG -c "cowextsize" $testdir/file1 | _filter_scratch
75
76 echo "Check extsz and cowextsz settings on 1Mbyte file"
77 $XFS_IO_PROG -c "extsize" $testdir/file2 | _filter_scratch
78 $XFS_IO_PROG -c "cowextsize" $testdir/file2 | _filter_scratch
79
80 echo "Set cowextsize and check flag"
81 $XFS_IO_PROG -c "cowextsize 1048576" $testdir/file3 | _filter_scratch
82 _scratch_cycle_mount
83
84 $XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
85 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
86
87 echo "Unset cowextsize and check flag"
88 $XFS_IO_PROG -c "cowextsize 0" $testdir/file3 | _filter_scratch
89 _scratch_cycle_mount
90
91 $XFS_IO_PROG -c "stat" $testdir/file3 | grep 'fsxattr.xflags' | test_xflag "C"
92 $XFS_IO_PROG -c "cowextsize" $testdir/file3 | _filter_scratch
93
94 status=0
95 exit