15382eb31638d6c0b6105a390b55ad4036d79928
[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 . ./common/preamble
12 _begin_fstest auto quick snapshot
13
14 # Import common functions.
15 . ./common/filter
16
17 # real QA test starts here
18 _supported_fs btrfs
19 _require_scratch
20 _require_xfs_io_command "falloc" "-k"
21
22 # Use a fixed size filesystem so that we can precisely fill the data block group
23 # mkfs.btrfs creates and allocate all unused space for a new data block group.
24 # It's important to not use the mixed block groups feature as well because we
25 # later want to not have more space available for allocating data extents but
26 # still have enough metadata space free for creating the snapshot.
27 fs_size=$((2 * 1024 * 1024 * 1024)) # 2Gb
28 _scratch_mkfs_sized $fs_size >>$seqres.full 2>&1
29
30 # Mount without space cache so that we can precisely fill all data space and
31 # unallocated space later (space cache v1 uses data block groups).
32 _scratch_mount "-o nospace_cache"
33
34 # Create our test file and allocate 1826.25Mb of space for it.
35 # This will exhaust the existing data block group and all unallocated space on
36 # this small fileystem (2Gb).
37 $XFS_IO_PROG -f -c "falloc -k 0 1914961920" $SCRATCH_MNT/foobar
38
39 # Write some data to the file and check its digest. This write will result in a
40 # NOCOW write because there's no more space available to allocate and the file
41 # has preallocated (unwritten) extents.
42 $XFS_IO_PROG -c "pwrite -S 0xea -b 128K 0 128K" $SCRATCH_MNT/foobar | _filter_xfs_io
43
44 echo "File digest after write:"
45 md5sum $SCRATCH_MNT/foobar | _filter_scratch
46
47 # Create a snapshot of the subvolume where our file is.
48 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/snap 2>&1 \
49         | _filter_scratch
50
51 # Cleanly unmount the filesystem.
52 _scratch_unmount
53
54 # Mount the filesystem again and verify the file has the same data it had before
55 # we unmounted the filesystem (same digest).
56 _scratch_mount
57 echo "File digest after mounting the filesystem again:"
58 md5sum $SCRATCH_MNT/foobar | _filter_scratch
59
60 status=0
61 exit