generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 534
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 No. 534
6 #
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.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         _cleanup_flakey
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/dmflakey
28
29 # real QA test starts here
30 _supported_fs generic
31 _require_scratch
32 _require_dm_target flakey
33
34 rm -f $seqres.full
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _require_metadata_journaling $SCRATCH_DEV
38 _init_flakey
39 _mount_flakey
40
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" \
44              -c "fsync" \
45              -c "truncate 3000" \
46              $SCRATCH_MNT/foo | _filter_xfs_io
47
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
51
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
55
56 [ -f $SCRATCH_MNT/bar ] || echo "file name 'bar' is missing"
57 [ -f $SCRATCH_MNT/foo ] && echo "file name 'foo' still exists"
58
59 echo "File content after power failure:"
60 od -A d -t x1 $SCRATCH_MNT/bar
61
62 _unmount_flakey
63
64 status=0
65 exit