generic: test for file loss after mix of rename, fsync and inode eviction
[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 . ./common/preamble
15 _begin_fstest auto quick clone enospc log
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20         _cleanup_flakey
21         cd /
22         rm -f $tmp.*
23 }
24
25 # Import common functions.
26 . ./common/filter
27 . ./common/reflink
28 . ./common/dmflakey
29
30 # real QA test starts here
31
32 # Modify as appropriate.
33 _supported_fs generic
34 _require_xfs_io_command "falloc"
35 _require_scratch_reflink
36 _require_dm_target flakey
37
38 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
40 _init_flakey
41 _mount_flakey
42
43 # Create preallocated extent where we can write into
44 $XFS_IO_PROG -f -c 'falloc 8k 64m' "$SCRATCH_MNT/foobar" >> $seqres.full
45
46 # Use up all data space, to test later write-into-preallocate behavior
47 _pwrite_byte 0x00 0 512m "$SCRATCH_MNT/padding" >> $seqres.full 2>&1
48
49 # Sync to ensure that padding file reach disk so that at log recovery we
50 # still have no data space
51 sync
52
53 # This should not fail
54 _pwrite_byte 0xcd 1m 16m "$SCRATCH_MNT/foobar" >> $seqres.full
55
56 # Do reflink here, we shouldn't use extra data space, thus it should not fail
57 $XFS_IO_PROG -c "reflink ${SCRATCH_MNT}/foobar 8k 0 4k" "$SCRATCH_MNT/foobar" \
58         >> $seqres.full
59
60 # Checksum before power loss
61 echo md5 before $(_md5_checksum "$SCRATCH_MNT/foobar")
62
63 # Fsync to check if writeback is ok
64 $XFS_IO_PROG -c 'fsync'  "$SCRATCH_MNT/foobar"
65
66 # Now emulate power loss
67 _flakey_drop_and_remount
68
69 # Checksum after power loss
70 echo md5 after $(_md5_checksum "$SCRATCH_MNT/foobar")
71
72 # success, all done
73 status=0
74 exit