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
32 _require_dm_target flakey
36 _scratch_mkfs >>$seqres.full 2>&1
37 _require_metadata_journaling $SCRATCH_DEV
41 # Create our test file with an initial size of 8000 bytes, then fsync it,
42 # followed by a truncate that reduces its size down to 3000 bytes.
43 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 8000" \
46 $SCRATCH_MNT/foo | _filter_xfs_io
48 # Now rename the file and fsync it again.
49 mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
50 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
52 # Simulate a power failure and mount the filesystem to check that the file was
53 # persisted with the new name and has a size of 3000 bytes.
54 _flakey_drop_and_remount
56 [ -f $SCRATCH_MNT/bar ] || echo "file name 'bar' is missing"
57 [ -f $SCRATCH_MNT/foo ] && echo "file name 'foo' still exists"
59 echo "File content after power failure:"
60 od -A d -t x1 $SCRATCH_MNT/bar