common/rc: add _scratch_{u}mount_idmapped() helpers
[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 _require_scratch
33 _require_dm_target flakey
34
35 rm -f $seqres.full
36
37 _scratch_mkfs >>$seqres.full 2>&1
38 _require_metadata_journaling $SCRATCH_DEV
39 _init_flakey
40 _mount_flakey
41
42 # Create our test directories and the file we will later check if it has
43 # disappeared.
44 mkdir -p $SCRATCH_MNT/a/b
45 mkdir $SCRATCH_MNT/c
46 touch $SCRATCH_MNT/a/b/foo
47
48 # Make sure everything is durably persisted.
49 sync
50
51 # Now move our test file into a new parent directory.
52 mv $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/c/
53
54 # Create a new file inside the parent directory of the directory where our test
55 # file foo was previously at. This is just to ensure the fsync we do next
56 # against that parent directory actually does something and it's not a noop.
57 touch $SCRATCH_MNT/a/bar
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a
59
60 echo "Filesystem content before power failure:"
61 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
62
63 # Simulate a power failure / crash and remount the filesystem, so that the
64 # journal/log is replayed.
65 _flakey_drop_and_remount
66
67 # We expect our file foo to exist, have an entry in the new parent
68 # directory (c/) and not have anymore an entry in the old parent directory
69 # (a/b/).
70 # The new file named bar should also exist.
71 echo "Filesystem content after power failure:"
72 # Must match what we had before the power failure.
73 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/c | _filter_scratch
74
75 _unmount_flakey
76
77 status=0
78 exit