xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 170
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. 170
6 #
7 # Test that if we write into an unwritten extent of a file when there is no
8 # more space left to allocate in the filesystem and then snapshot the file's
9 # subvolume, after a clean shutdown the data was not lost.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
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 btrfs
30 _require_scratch
31 _require_xfs_io_command "falloc" "-k"
32
33 rm -f $seqres.full
34
35 # Use a fixed size filesystem so that we can precisely fill the data block group
36 # mkfs.btrfs creates and allocate all unused space for a new data block group.
37 # It's important to not use the mixed block groups feature as well because we
38 # later want to not have more space available for allocating data extents but
39 # still have enough metadata space free for creating the snapshot.
40 fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
41 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
42
43 # Mount without space cache so that we can precisely fill all data space and
44 # unallocated space later (space cache v1 uses data block groups).
45 _scratch_mount "-o nospace_cache"
46
47 # Create our test file and allocate 1826.25Mb of space for it.
48 # This will exhaust the existing data block group and all unallocated space on
49 # this small fileystem (2Gb).
50 $XFS_IO_PROG -f -c "falloc -k 0 1914961920" $SCRATCH_MNT/foobar
51
52 # Write some data to the file and check its digest. This write will result in a
53 # NOCOW write because there's no more space available to allocate and the file
54 # has preallocated (unwritten) extents.
55 $XFS_IO_PROG -c "pwrite -S 0xea -b 128K 0 128K" $SCRATCH_MNT/foobar | _filter_xfs_io
56
57 echo "File digest after write:"
58 md5sum $SCRATCH_MNT/foobar | _filter_scratch
59
60 # Create a snapshot of the subvolume where our file is.
61 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap 2>&1 \
62         | _filter_scratch
63
64 # Cleanly unmount the filesystem.
65 _scratch_unmount
66
67 # Mount the filesystem again and verify the file has the same data it had before
68 # we unmounted the filesystem (same digest).
69 _scratch_mount
70 echo "File digest after mounting the filesystem again:"
71 md5sum $SCRATCH_MNT/foobar | _filter_scratch
72
73 status=0
74 exit