generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 534
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 534
6 #
7 # Test that if we truncate a file to reduce its size, rename it and then fsync
8 # it, after a power failure the file has a correct size and name.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         _cleanup_flakey
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/dmflakey
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
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 file with an initial size of 8000 bytes, then fsync it,
43 # followed by a truncate that reduces its size down to 3000 bytes.
44 $XFS_IO_PROG -f -c "pwrite -S 0xab 0 8000" \
45              -c "fsync" \
46              -c "truncate 3000" \
47              $SCRATCH_MNT/foo | _filter_xfs_io
48
49 # Now rename the file and fsync it again.
50 mv $SCRATCH_MNT/foo $SCRATCH_MNT/bar
51 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
52
53 # Simulate a power failure and mount the filesystem to check that the file was
54 # persisted with the new name and has a size of 3000 bytes.
55 _flakey_drop_and_remount
56
57 [ -f $SCRATCH_MNT/bar ] || echo "file name 'bar' is missing"
58 [ -f $SCRATCH_MNT/foo ] && echo "file name 'foo' still exists"
59
60 echo "File content after power failure:"
61 od -A d -t x1 $SCRATCH_MNT/bar
62
63 _unmount_flakey
64
65 status=0
66 exit