generic/223: make sure all files get created on the data device
[xfstests-dev.git] / tests / generic / 466
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 466
6 #
7 # Check that high-offset reads and writes work.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_fs generic
30 _require_scratch_nocheck
31 _require_block_device $SCRATCH_DEV
32
33 rm -f $seqres.full
34
35 echo "Silence is golden"
36
37 # clear MKFS_OPTIONS which may contain user specified block size value, and
38 # _scratch_mkfs_sized will always use that value to create filesystem.
39 unset MKFS_OPTIONS
40
41 echo "Starting test" > $seqres.full
42 devsize=$(blockdev --getsize64 $SCRATCH_DEV)
43 for blocksize in 512 1024 2048 4096 8192 16384 32768 65536; do
44         echo "+ Format blocksize $blocksize and mount" >> $seqres.full
45         _scratch_unmount > /dev/null 2>&1
46         # Try to format and mount with the given blocksize.  If they don't
47         # succeed, move on to the next block size.
48         if ! _scratch_mkfs_sized $devsize $blocksize >> $seqres.full 2>&1 ||
49            ! _try_scratch_mount >> $seqres.full 2>&1 ||
50            test "$(stat -f -c '%S' $SCRATCH_MNT)" -ne "$blocksize"; then
51                 echo "+++ Format and mount failed" >> $seqres.full
52                 continue
53         fi
54
55         testdir=$SCRATCH_MNT/test-$seq
56         mkdir $testdir
57
58         echo "++ Create the original files" >> $seqres.full
59         bigoff=$(echo "2^63 - 2" | $BC_PROG)
60         len=$(echo "2^63 - 1" | $BC_PROG)
61         $XFS_IO_PROG -f -c "truncate $len" $testdir/file0 >> $seqres.full 2>&1
62         if [ ! -s $testdir/file0 ]; then
63                 # If we can't set a large file size then don't bother
64                 # with this blocksize because the fs doesn't support it.
65                 echo "+++ High offset ftruncate failed" >> $seqres.full
66                 continue
67         fi
68         _pwrite_byte 0x61 $bigoff 1 $testdir/file1 >> $seqres.full
69
70         echo "++ Check file creation" >> $seqres.full
71         _scratch_cycle_mount
72
73         expected="7ffffffffffffffe:  61  a"
74         actual="$($XFS_IO_PROG -c "pread -v -q $bigoff 1" $testdir/file1)"
75         if [ "$expected" = "$actual" ]; then
76                 echo "+++ Success!" >> $seqres.full
77         else
78                 echo "+++ Discrepancy @ blocksize $blocksize" >> $seqres.full
79                 echo "Discrepancy @ blocksize $blocksize"
80         fi
81
82         echo "++ Check scratchfs" >> $seqres.full
83         _check_scratch_fs
84 done
85
86 # success, all done
87 status=0
88 exit