generic: test adding filesystem-level fscrypt key via key_id
[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 _supported_os Linux
34 _require_scratch
35 _require_dm_target flakey
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >>$seqres.full 2>&1
40 _require_metadata_journaling $SCRATCH_DEV
41 _init_flakey
42 _mount_flakey
43
44 # Create our test directories and file.
45 mkdir $SCRATCH_MNT/testdir
46 mkdir $SCRATCH_MNT/testdir/A
47 mkdir $SCRATCH_MNT/testdir/B
48 touch $SCRATCH_MNT/testdir/B/bar
49
50 # Make sure everything done so far is durably persisted.
51 sync
52
53 # Now move our file bar from directory B to directory A and then replace
54 # directory B with directory A, also renaming directory A to B. Finally
55 # fsync file bar.
56 mv $SCRATCH_MNT/testdir/B/bar $SCRATCH_MNT/testdir/A/bar
57 mv -T $SCRATCH_MNT/testdir/A $SCRATCH_MNT/testdir/B
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/B/bar
59
60 # Simulate a power failure and mount the filesystem. We expect file bar
61 # to exist and have a single parent directory, named B, and that no
62 # directory named A exists.
63 _flakey_drop_and_remount
64
65 echo "Filesystem content after power failure:"
66 ls -R $SCRATCH_MNT/testdir | _filter_scratch
67
68 _unmount_flakey
69
70 status=0
71 exit