2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that if we truncate a file to reduce its size, rename it and then fsync
8 # it, after a power failure the file has a correct size and name.
11 _begin_fstest auto quick log
13 # Override the default cleanup function.
21 # Import common functions.
25 # real QA test starts here
28 _require_dm_target flakey
30 _scratch_mkfs >>$seqres.full 2>&1
31 _require_metadata_journaling $SCRATCH_DEV
35 # Create our test file with an initial size of 8000 bytes, then fsync it,
36 # followed by a truncate that reduces its size down to 3000 bytes.
37 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 8000" \
40 $SCRATCH_MNT/foo | _filter_xfs_io
42 # Now rename the file and fsync it again.
43 mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
44 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
46 # Simulate a power failure and mount the filesystem to check that the file was
47 # persisted with the new name and has a size of 3000 bytes.
48 _flakey_drop_and_remount
50 [ -f $SCRATCH_MNT/bar ] || echo "file name 'bar' is missing"
51 [ -f $SCRATCH_MNT/foo ] && echo "file name 'foo' still exists"
53 echo "File content after power failure:"
54 od -A d -t x1 $SCRATCH_MNT/bar