generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 250
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 250
6 #
7 # Test that if we write to a range of a NOCOW file that has allocated extents
8 # and there is not enough available free space for allocating new data extents,
9 # the write succeeds. Test for direct IO and buffered IO writes.
10 # The patch that fixes the direct IO case has the following subject:
11 #
12 # "btrfs: fix ENOSPC failure when attempting direct IO write into NOCOW range"
13 #
14 . ./common/preamble
15 _begin_fstest auto quick enospc
16
17 _cleanup()
18 {
19         cd /
20         rm -r -f $tmp.*
21 }
22
23 # Import common functions.
24 . ./common/filter
25
26 # real QA test starts here
27
28 _supported_fs btrfs
29 _require_scratch
30 _require_chattr C
31 _require_odirect
32
33 # Use a small fixed size filesystem so that it's quick to fill it up.
34 # Make sure the fs size is > 256M, so that the mixed block groups feature is
35 # not enabled by _scatch_mkfs_sized(), because we later want to not have more
36 # space available for allocating data extents but still have enough metadata
37 # space free for the file writes.
38 fs_size=$((1024 * 1024 * 1024)) # 1G
39 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
40 _scratch_mount
41
42 # Create our test file with the NOCOW attribute set.
43 touch $SCRATCH_MNT/foobar
44 $CHATTR_PROG +C $SCRATCH_MNT/foobar
45
46 # Now fill in all unallocated space with data for our test file.
47 # This will allocate a data block group that will be full and leave no (or a
48 # very small amount of) unallocated space in the device, so that it will not be
49 # possible to allocate a new block group later.
50 echo "Creating test file with initial data..."
51 $XFS_IO_PROG -c "pwrite -S 0xab -b 1M 0 900M" $SCRATCH_MNT/foobar | _filter_xfs_io
52
53 # Now try a direct IO write against file range [0, 10M[.
54 # This should succeed since this is a NOCOW file and an extent for the range was
55 # previously allocated.
56 echo "Trying direct IO write over allocated space..."
57 $XFS_IO_PROG -d -c "pwrite -S 0xcd -b 10M 0 10M" $SCRATCH_MNT/foobar | _filter_xfs_io
58
59 # Now try a buffered IO write against file range [10M, 20M[.
60 # This should also succeed since this is a NOCOW file and an extent for the range
61 # was previously allocated.
62 echo "Trying buffered IO write over allocated space..."
63 $XFS_IO_PROG -c "pwrite -S 0xef -b 10M 10M 10M" $SCRATCH_MNT/foobar | _filter_xfs_io
64
65 # Unmount and mount again the filesystem to clear any data from our file from the
66 # page cache.
67 _scratch_cycle_mount
68
69 # Now read the file and verify that all the writes we did before were durably
70 # persisted.
71 echo "File data after mounting again the filesystem:"
72 od -A d -t x1 $SCRATCH_MNT/foobar
73
74 # success, all done
75 status=0
76 exit