generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 501
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. 501
6 #
7 # Test that if we do a buffered write to a file, fsync it, clone a range from
8 # another file into our file that overlaps the previously written range, fsync
9 # the file again and then power fail, after we mount again the filesystem, no
10 # file data was lost or corrupted.
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/reflink
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch_reflink
36 _require_dm_target flakey
37
38 rm -f $seqres.full
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
42 _init_flakey
43 _mount_flakey
44
45 $XFS_IO_PROG -f -c "pwrite -S 0x18 9000K 6908K" $SCRATCH_MNT/foo >>$seqres.full
46 $XFS_IO_PROG -f -c "pwrite -S 0x20 2572K 156K" $SCRATCH_MNT/bar >>$seqres.full
47
48 # We clone from file foo into a range of file bar that overlaps the existing
49 # extent at file bar. The destination offset of the reflink operation matches
50 # the eof position of file bar minus 4Kb.
51 $XFS_IO_PROG -c "fsync" \
52              -c "reflink ${SCRATCH_MNT}/foo 0 2724K 15908K" \
53              -c "fsync" \
54              $SCRATCH_MNT/bar >>$seqres.full
55
56 echo "File bar digest before power failure:"
57 md5sum $SCRATCH_MNT/bar | _filter_scratch
58
59 # Simulate a power failure and mount the filesystem to check that no file data
60 # was lost or corrupted.
61 _flakey_drop_and_remount
62
63 echo "File bar digest after power failure:"
64 md5sum $SCRATCH_MNT/bar | _filter_scratch
65
66 _unmount_flakey
67 _cleanup_flakey
68
69 status=0
70 exit