generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 517
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 517
6 #
7 # Test that deduplication of an entire file that has a size that is not aligned
8 # to the filesystem's block size into the middle of a different file does not
9 # corrupt the destination's file data by reflinking the last (eof) block.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick dedupe clone
13
14 # Import common functions.
15 . ./common/filter
16 . ./common/reflink
17
18 # real QA test starts here
19 _supported_fs generic
20 _require_scratch_dedupe
21
22 _scratch_mkfs >>$seqres.full 2>&1
23 _scratch_mount
24
25 # The first byte with a value of 0xae starts at an offset (512Kb + 100) which is
26 # not a multiple of the block size.
27 $XFS_IO_PROG -f \
28         -c "pwrite -S 0x6b 0 524388" \
29         -c "pwrite -S 0xae 524388 256K" \
30         $SCRATCH_MNT/foo | _filter_xfs_io
31
32 # Create a second file with a length not aligned to the block size (128K + 100),
33 # whose bytes all have the value 0x6b, so that its extent(s) can be deduplicated
34 # with the first file.
35 $XFS_IO_PROG -f -c "pwrite -S 0x6b 0 131172" $SCRATCH_MNT/bar | _filter_xfs_io
36
37 # The file is filled with bytes having the value 0x6b from offset 0 to offset
38 # 524388 (512K + 100) and with the value 0xae from offset 524388 to offset
39 # 786532 (512K + 100 + 256K).
40 echo "File content before first deduplication:"
41 od -A d -t x1 $SCRATCH_MNT/foo
42
43 # Now deduplicate the entire second file into a range of the first file that
44 # also has all bytes with the value 0x6b. The destination range's end offset
45 # must not be aligned to the block size and must be less then the offset of
46 # the first byte with the value 0xae (byte at offset 524388).
47 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/bar 0 64K 131172" $SCRATCH_MNT/foo \
48         | _filter_xfs_io
49
50 # We should have exactly the same data we had before we asked for deduplication.
51 echo "File content after first deduplication and before unmounting:"
52 od -A d -t x1 $SCRATCH_MNT/foo
53
54 # Unmount the filesystem and mount it again. This guarantees any file data in
55 # the page cache is dropped.
56 _scratch_cycle_mount
57
58 # We should have exactly the same data we had before we asked for deduplication.
59 echo "File content after first unmount:"
60 od -A d -t x1 $SCRATCH_MNT/foo
61
62 # Now do a similar test when trying to dedup just the last (eof) block of a file
63 # into the middle of another file. This triggered a different bug on btrfs.
64 $XFS_IO_PROG -f -c "pwrite -S 0xae 0 100" $SCRATCH_MNT/baz | _filter_xfs_io
65
66 # Unmount the filesystem and mount it again before attempting to dedupe baz's
67 # last block into foo. This is necessary to trigger that btrfs bug mentioned
68 # before.
69 _scratch_cycle_mount
70
71 # Now attempt to dedupe the single block of baz into foo. The destination range,
72 # in file foo, has all bytes with the same value (0xae) as file baz.
73 $XFS_IO_PROG -c "dedupe $SCRATCH_MNT/baz 0 640K 100" $SCRATCH_MNT/foo \
74     | _filter_xfs_io
75
76 # Now attempt to unmount the filesystem before reading from the file. This is
77 # meant to trigger the btrfs bug which caused an infinite loop during inode
78 # eviction.
79 _scratch_cycle_mount
80
81 # We should have exactly the same data we had before we asked for deduplication.
82 echo "File content after second deduplication:"
83 od -A d -t x1 $SCRATCH_MNT/foo
84
85 status=0
86 exit