generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 546
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 546
6 #
7 # Test when a fs is full we can still:
8 # - Do buffered write into a unpopulated preallocated extent
9 # - Clone the untouched part of that preallocated extent
10 # - Fsync
11 # - No data loss even power loss happens after fsync
12 # All operations above should not fail.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         _cleanup_flakey
26         cd /
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/reflink
34 . ./common/dmflakey
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40
41 # Modify as appropriate.
42 _supported_fs generic
43 _supported_os Linux
44 _require_xfs_io_command "falloc"
45 _require_scratch_reflink
46 _require_dm_target flakey
47
48 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1
49 _require_metadata_journaling $SCRATCH_DEV
50 _init_flakey
51 _mount_flakey
52
53 # Create preallocated extent where we can write into
54 $XFS_IO_PROG -f -c 'falloc 8k 64m' "$SCRATCH_MNT/foobar" >> $seqres.full
55
56 # Use up all data space, to test later write-into-preallocate behavior
57 _pwrite_byte 0x00 0 512m "$SCRATCH_MNT/padding" >> $seqres.full 2>&1
58
59 # Sync to ensure that padding file reach disk so that at log recovery we
60 # still have no data space
61 sync
62
63 # This should not fail
64 _pwrite_byte 0xcd 1m 16m "$SCRATCH_MNT/foobar" >> $seqres.full
65
66 # Do reflink here, we shouldn't use extra data space, thus it should not fail
67 $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foobar 8k 0 4k" "$SCRATCH_MNT/foobar" \
68         >> $seqres.full
69
70 # Checksum before power loss
71 echo md5 before $(_md5_checksum "$SCRATCH_MNT/foobar")
72
73 # Fsync to check if writeback is ok
74 $XFS_IO_PROG -c 'fsync'  "$SCRATCH_MNT/foobar"
75
76 # Now emulate power loss
77 _flakey_drop_and_remount
78
79 # Checksum after power loss
80 echo md5 after $(_md5_checksum "$SCRATCH_MNT/foobar")
81
82 # success, all done
83 status=0
84 exit