generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 353
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test 353
6 #
7 # Check if fiemap ioctl returns correct SHARED flag on reflinked file
8 # before and after sync the fs
9 #
10 # Btrfs has a bug in checking shared extent, which can only handle metadata
11 # already committed to disk, but not delayed extent tree modification.
12 # This caused SHARED flag only occurs after sync.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/reflink
33 . ./common/punch
34
35 # remove previous $seqres.full before test
36 rm -f $seqres.full
37
38 # real QA test starts here
39
40 # Modify as appropriate.
41 _supported_fs generic
42 _require_scratch_reflink
43 _require_xfs_io_command "fiemap"
44
45 _scratch_mkfs > /dev/null 2>&1
46 _scratch_mount
47
48 blocksize=64k
49 file1="$SCRATCH_MNT/file1"
50 file2="$SCRATCH_MNT/file2"
51
52 # write the initial file
53 _pwrite_byte 0xcdcdcdcd 0 $blocksize $file1 | _filter_xfs_io
54
55 # reflink initial file
56 _reflink_range $file1 0 $file2 0 $blocksize | _filter_xfs_io
57
58 # check their fiemap to make sure it's correct
59 echo "before sync:"
60 echo "$file1" | _filter_scratch
61 $XFS_IO_PROG -c "fiemap -v" $file1 | _filter_fiemap_flags
62 echo "$file2" | _filter_scratch
63 $XFS_IO_PROG -c "fiemap -v" $file2 | _filter_fiemap_flags
64
65 # sync and recheck, to make sure the fiemap doesn't change just
66 # due to sync
67 sync
68 echo "after sync:"
69 echo "$file1" | _filter_scratch
70 $XFS_IO_PROG -c "fiemap -v" $file1 | _filter_fiemap_flags
71 echo "$file2" | _filter_scratch
72 $XFS_IO_PROG -c "fiemap -v" $file2 | _filter_fiemap_flags
73
74 # success, all done
75 status=0
76 exit