generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 335
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 335
6 #
7 # Test that if we move one file between directories, fsync the parent directory
8 # of the old directory, power fail and remount the filesystem, the file is not
9 # lost and it's located at the destination directory.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         _cleanup_flakey
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/dmflakey
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33 _require_scratch
34 _require_dm_target flakey
35
36 rm -f $seqres.full
37
38 _scratch_mkfs >>$seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
40 _init_flakey
41 _mount_flakey
42
43 # Create our test directories and the file we will later check if it has
44 # disappeared.
45 mkdir -p $SCRATCH_MNT/a/b
46 mkdir $SCRATCH_MNT/c
47 touch $SCRATCH_MNT/a/b/foo
48
49 # Make sure everything is durably persisted.
50 sync
51
52 # Now move our test file into a new parent directory.
53 mv $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/c/
54
55 # Create a new file inside the parent directory of the directory where our test
56 # file foo was previously at. This is just to ensure the fsync we do next
57 # against that parent directory actually does something and it's not a noop.
58 touch $SCRATCH_MNT/a/bar
59 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a
60
61 echo "Filesystem content before power failure:"
62 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
63
64 # Simulate a power failure / crash and remount the filesystem, so that the
65 # journal/log is replayed.
66 _flakey_drop_and_remount
67
68 # We expect our file foo to exist, have an entry in the new parent
69 # directory (c/) and not have anymore an entry in the old parent directory
70 # (a/b/).
71 # The new file named bar should also exist.
72 echo "Filesystem content after power failure:"
73 # Must match what we had before the power failure.
74 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
75
76 _unmount_flakey
77
78 status=0
79 exit