2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
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.
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # real QA test starts here
32 _require_xfs_io_command "falloc" "-k"
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
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"
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
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
58 echo "File digest after write:"
59 md5sum $SCRATCH_MNT/foobar | _filter_scratch
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 \
65 # Cleanly unmount the filesystem.
68 # Mount the filesystem again and verify the file has the same data it had before
69 # we unmounted the filesystem (same digest).
71 echo "File digest after mounting the filesystem again:"
72 md5sum $SCRATCH_MNT/foobar | _filter_scratch