common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / generic / 510
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. 510
6 #
7 # Test that if we move a file from a directory B to a directory A, replace
8 # directory B with directory A, fsync the file and then power fail, after
9 # mounting the filesystem the file has a single parent, named B and there
10 # is no longer any directory with the name A.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
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 file.
44 mkdir $SCRATCH_MNT/testdir
45 mkdir $SCRATCH_MNT/testdir/A
46 mkdir $SCRATCH_MNT/testdir/B
47 touch $SCRATCH_MNT/testdir/B/bar
48
49 # Make sure everything done so far is durably persisted.
50 sync
51
52 # Now move our file bar from directory B to directory A and then replace
53 # directory B with directory A, also renaming directory A to B. Finally
54 # fsync file bar.
55 mv $SCRATCH_MNT/testdir/B/bar $SCRATCH_MNT/testdir/A/bar
56 mv -T $SCRATCH_MNT/testdir/A $SCRATCH_MNT/testdir/B
57 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/B/bar
58
59 # Simulate a power failure and mount the filesystem. We expect file bar
60 # to exist and have a single parent directory, named B, and that no
61 # directory named A exists.
62 _flakey_drop_and_remount
63
64 echo "Filesystem content after power failure:"
65 ls -R $SCRATCH_MNT/testdir | _filter_scratch
66
67 _unmount_flakey
68
69 status=0
70 exit