generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 498
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 498
6 #
7 # Test that if we create a new hard link for a file which was previously
8 # fsync'ed, fsync a parent directory of the new hard link and power fail,
9 # the parent directory exists after mounting the filesystem again.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick log
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         _cleanup_flakey
18         cd /
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/dmflakey
25
26 # real QA test starts here
27 _supported_fs generic
28 _require_scratch
29 _require_hardlinks
30 _require_dm_target flakey
31
32 _scratch_mkfs >>$seqres.full 2>&1
33 _require_metadata_journaling $SCRATCH_DEV
34 _init_flakey
35 _mount_flakey
36
37 mkdir $SCRATCH_MNT/A
38 mkdir $SCRATCH_MNT/B
39 mkdir $SCRATCH_MNT/A/C
40 touch $SCRATCH_MNT/B/foo
41 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/B/foo
42 # It is important the new hard link is located in a hierarchy of new directories
43 # (not yet persisted).
44 ln $SCRATCH_MNT/B/foo $SCRATCH_MNT/A/C/foo
45 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/A
46
47 # Simulate a power failure and mount the filesystem to check that what we
48 # explicitly fsync'ed exists.
49 _flakey_drop_and_remount
50
51 [ -d $SCRATCH_MNT/A ] || echo "directory A missing"
52 [ -f $SCRATCH_MNT/B/foo ] || echo "file B/foo is missing"
53
54 _unmount_flakey
55
56 echo "Silence is golden"
57 status=0
58 exit