generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 502
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. 502
6 #
7 # Test that if we have a file with 2 (or more) hard links in the same parent
8 # directory, rename of the hard links, rename one of the other hard links to
9 # the old name of the hard link we renamed before, create a new file in the
10 # same parent directory with the old name of second hard link we renamed, fsync
11 # fsync this new file and power fail, we will be able to mount again the
12 # filesystem and the new file and all hard links exist.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         _cleanup_flakey
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/dmflakey
32
33 # real QA test starts here
34 _supported_fs generic
35 _supported_os Linux
36 _require_scratch
37 _require_dm_target flakey
38
39 rm -f $seqres.full
40
41 _scratch_mkfs >>$seqres.full 2>&1
42 _require_metadata_journaling $SCRATCH_DEV
43 _init_flakey
44 _mount_flakey
45
46 # Create our test file with 2 hard links in the same parent directory.
47 mkdir $SCRATCH_MNT/testdir
48 touch $SCRATCH_MNT/testdir/foo
49 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
50
51 # Make sure everything done so far is durably persisted.
52 sync
53
54 # Now rename the first hard link (foo) to a new name and rename the second hard
55 # link (bar) to the old name of the first hard link (foo).
56 mv $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/qwerty
57 mv $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/foo
58
59 # Create a new file, in the same parent directory, with the old name of the
60 # second hard link (bar) and fsync this new file.
61 touch $SCRATCH_MNT/testdir/bar
62 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
63
64 echo "Contents of test directory before the power failure:"
65 ls -R $SCRATCH_MNT/testdir | _filter_scratch
66
67 # Simulate a power failure and mount the filesystem to check that we are able to
68 # mount it and we have the same files, with the same hard links, that we had
69 # before the power failure and in the same order.
70 _flakey_drop_and_remount
71
72 echo "Contents of test directory after the power failure:"
73 ls -R $SCRATCH_MNT/testdir | _filter_scratch
74
75 _unmount_flakey
76 _cleanup_flakey
77
78 status=0
79 exit