generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 422
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. generic/422
6 #
7 # Test that a filesystem's implementation of the stat(2) system call reports
8 # correct values for the number of blocks allocated for a file when there are
9 # delayed allocations.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
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         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32 _require_test
33 _require_scratch
34 _require_xfs_io_command "falloc" "-k"
35 _require_odirect
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >>$seqres.full 2>&1
40 _scratch_mount
41
42 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
43 $XFS_IO_PROG -f \
44      -c "pwrite -S 0xaa 0 64K" \
45      -c "truncate 128K" \
46      $SCRATCH_MNT/foo2 | _filter_xfs_io
47 $XFS_IO_PROG -f \
48      -c "falloc -k 0 128K" \
49      -c "pwrite -S 0xaa 0 64K" \
50      $SCRATCH_MNT/foo3 | _filter_xfs_io
51 touch $SCRATCH_MNT/foo4
52
53 # Make sure everything done so far is durably persisted.
54 sync
55
56 # Now overwrite the extent of the first file.
57 $XFS_IO_PROG -c "pwrite -S 0xff 0 64K" $SCRATCH_MNT/foo1 | _filter_xfs_io
58
59 # Write to a hole of the second file.
60 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
61 # Write again to the same location, just to test that the fs will not account
62 # the same write twice.
63 $XFS_IO_PROG -c "pwrite -S 0x20 64K 64K" $SCRATCH_MNT/foo2 | _filter_xfs_io
64
65 # Write beyond eof of the third file into the pre-allocated extent.
66 $XFS_IO_PROG -c "pwrite -S 0xff 64K 64K" $SCRATCH_MNT/foo3 | _filter_xfs_io
67
68 # Do a buffered write immediately followed by a direct IO write, without a
69 # fsync in between, just to test that page invalidation does not lead to an
70 # incorrect number of file blocks reported.
71 $XFS_IO_PROG -c "pwrite -S 0xab 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
72 $XFS_IO_PROG -d -c "pwrite -S 0xef 0 64K" $SCRATCH_MNT/foo4 | _filter_xfs_io
73
74 space_used() {
75     echo "Space used by file foo1:"
76     du -h $SCRATCH_MNT/foo1 | _filter_scratch
77
78     echo "Space used by file foo2:"
79     du -h $SCRATCH_MNT/foo2 | _filter_scratch
80
81     echo "Space used by file foo3:"
82     du -h $SCRATCH_MNT/foo3 | _filter_scratch
83
84     echo "Space used by file foo4:"
85     du -h $SCRATCH_MNT/foo4 | _filter_scratch
86 }
87
88 space_used > $SCRATCH_MNT/$seq.before
89 (
90     echo
91     echo "Before writeback"
92     echo
93
94     cat $SCRATCH_MNT/$seq.before
95 ) >> $seqres.full
96
97 sync
98
99 # We expect the same file sizes reported by 'du' after writeback finishes.
100
101 space_used > $SCRATCH_MNT/$seq.after
102 (
103     echo
104     echo "After writeback"
105     echo
106
107     cat $SCRATCH_MNT/$seq.after
108 ) >> $seqres.full
109
110 if diff -q $SCRATCH_MNT/$seq.before $SCRATCH_MNT/$seq.after; then
111         echo "Space used before and after writeback is equal"
112 fi
113
114 status=0
115 exit