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
31 _require_xfs_io_command "falloc" "-k"
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
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"
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
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
57 echo "File digest after write:"
58 md5sum $SCRATCH_MNT/foobar | _filter_scratch
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 \
64 # Cleanly unmount the filesystem.
67 # Mount the filesystem again and verify the file has the same data it had before
68 # we unmounted the filesystem (same digest).
70 echo "File digest after mounting the filesystem again:"
71 md5sum $SCRATCH_MNT/foobar | _filter_scratch