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 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
14 status=1 # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
29 # real QA test starts here
33 _require_dm_target flakey
37 _scratch_mkfs >>$seqres.full 2>&1
38 _require_metadata_journaling $SCRATCH_DEV
42 # Create our test file with an initial size of 8000 bytes, then fsync it,
43 # followed by a truncate that reduces its size down to 3000 bytes.
44 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 8000" \
47 $SCRATCH_MNT/foo | _filter_xfs_io
49 # Now rename the file and fsync it again.
50 mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
51 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
53 # Simulate a power failure and mount the filesystem to check that the file was
54 # persisted with the new name and has a size of 3000 bytes.
55 _flakey_drop_and_remount
57 [ -f $SCRATCH_MNT/bar ] || echo "file name 'bar' is missing"
58 [ -f $SCRATCH_MNT/foo ] && echo "file name 'foo' still exists"
60 echo "File content after power failure:"
61 od -A d -t x1 $SCRATCH_MNT/bar