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