common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / ext4 / 046
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 IBM Corporation. All Rights Reserved.
4 #
5 # FS QA Test No. ext4/046
6 #
7 # Test writes to falloc file with filesize > 4GB and make sure to verify
8 # the file checksum both before and after mount.
9 # This test is to check whether unwritten extents gets properly converted
10 # to written extent on a filesystem with bs < ps with dioread_nolock.
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 -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 _require_check_dmesg
35 _supported_fs ext4
36 _require_scratch
37 _require_xfs_io_command "falloc"
38 _require_scratch_size $((6 * 1024 * 1024)) #kB
39
40 _scratch_mkfs >> $seqres.full 2>&1
41 if ! _try_scratch_mount "-o dioread_nolock" >> $seqres.full 2>&1; then
42         err_str="can't mount with dioread_nolock if block size != PAGE_SIZE"
43         _check_dmesg_for ${err_str}
44         if [ $? -eq 0 ]; then
45                 _notrun "mount failed, ext4 doesn't support bs < ps with dioread_nolock"
46         else
47                 _fail "mount failed with dioread_nolock"
48         fi
49 fi
50
51 # Get blksz
52 blksz=$(_get_file_block_size $SCRATCH_MNT)
53
54 testfile=$SCRATCH_MNT/testfile-$seq
55
56 # Fallocate testfile with size > 4G
57 fsize=$((5 * 1024 * 1024 * 1024))
58 $XFS_IO_PROG -f -c "falloc 0 $fsize" $testfile >> $seqres.full 2>&1
59
60 # First write at offset < 4G (at few alternative blks)
61 off=$((3 * 1024 * 1024 * 1024))
62 for i in 1 2 3 4; do
63         $XFS_IO_PROG -f \
64                 -c "pwrite $off $blksz" \
65                 $testfile >> $seqres.full 2>&1
66         off=$(($off + (2*$blksz)))
67 done
68
69 # Then write at offset > 4G (at few alternative blks) to check
70 # any 32bit overflow case in map.m_lblk
71 off=$((4 * 1024 * 1024 * 1024))
72 for i in 1 2 3 4; do
73         $XFS_IO_PROG -f \
74                 -c "pwrite $off $blksz" \
75                 $testfile >> $seqres.full 2>&1
76         off=$(($off + (2*$blksz)))
77 done
78
79 # ==== Pre-Remount ===
80 md5_pre=`md5sum $testfile | cut -d' ' -f1`
81 echo "Pre-Remount md5sum of $testfile = $md5_pre" >> $seqres.full
82
83 _scratch_cycle_mount
84
85 # ==== Post-Remount ===
86 md5_post=`md5sum $testfile | cut -d' ' -f1`
87 echo "Post-Remount md5sum of $testfile = $md5_post" >> $seqres.full
88 test $md5_pre != $md5_post && echo "md5sum mismatch"
89
90 # success, all done
91 echo "Silence is golden"
92 status=0
93 exit