generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 489
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 489
6 #
7 # Test that xattrs are not lost after calling fsync multiple times with a
8 # filesystem commit in between the fsync calls.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick attr log
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         _cleanup_flakey
17         cd /
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/dmflakey
24 . ./common/attr
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_scratch
29 _require_dm_target flakey
30 _require_attrs
31
32 _scratch_mkfs >>$seqres.full 2>&1
33 _require_metadata_journaling $SCRATCH_DEV
34 _init_flakey
35 _mount_flakey
36
37 touch $SCRATCH_MNT/foobar
38 $SETFATTR_PROG -n user.xa1 -v qwerty $SCRATCH_MNT/foobar
39 $SETFATTR_PROG -n user.xa2 -v 'hello world' $SCRATCH_MNT/foobar
40 $SETFATTR_PROG -n user.xa3 -v test $SCRATCH_MNT/foobar
41 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
42
43 # Call sync to commit all fileystem metadata.
44 sync
45
46 $XFS_IO_PROG -c "pwrite -S 0xea 0 64K" \
47              -c "fsync" \
48              $SCRATCH_MNT/foobar >>$seqres.full
49
50 # Simulate a power failure and mount the filesystem to check that the xattrs
51 # were not lost and neither was the data we wrote.
52 _flakey_drop_and_remount
53 echo "File xattrs after power failure:"
54 _getfattr --absolute-names --dump $SCRATCH_MNT/foobar | _filter_scratch
55 echo "File data after power failure:"
56 od -t x1 $SCRATCH_MNT/foobar
57
58 _unmount_flakey
59 _cleanup_flakey
60
61 status=0
62 exit