generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 274
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011-2012 Fujitsu, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 274
6 #
7 # preallocation test:
8 # Preallocate space to a file, and fill the rest of the fs to 100%.
9 # Then test a write into that preallocated space, which should succeed.
10 #
11 #creator
12
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=0    # success is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26         _scratch_unmount
27 }
28
29 . ./common/rc
30 . ./common/filter
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch
36 _require_xfs_io_command "falloc" "-k"
37
38 echo "------------------------------"
39 echo "preallocation test"
40 echo "------------------------------"
41
42 rm -f $seqres.full
43
44 _scratch_unmount 2>/dev/null
45 _scratch_mkfs_sized $((2 * 1024 * 1024 * 1024)) >>$seqres.full 2>&1
46 _scratch_mount
47
48 # Create a 4k file and Allocate 4M past EOF on that file
49 $XFS_IO_PROG -f -c "pwrite 0 4k" -c "falloc -k 4k 4m" $SCRATCH_MNT/test \
50         >>$seqres.full 2>&1 || _fail "failed to create test file"
51
52 # Fill the rest of the fs completely
53 # Note, this will show ENOSPC errors in $seqres.full, that's ok.
54 echo "Fill fs with 1M IOs; ENOSPC expected" >> $seqres.full
55 dd if=/dev/zero of=$SCRATCH_MNT/tmp1 bs=1M >>$seqres.full 2>&1
56 echo "Fill fs with 4K IOs; ENOSPC expected" >> $seqres.full
57 dd if=/dev/zero of=$SCRATCH_MNT/tmp2 bs=4K >>$seqres.full 2>&1
58 sync
59 # Last effort, use O_SYNC
60 echo "Fill fs with 4K DIOs; ENOSPC expected" >> $seqres.full
61 dd if=/dev/zero of=$SCRATCH_MNT/tmp3 bs=4K oflag=sync >>$seqres.full 2>&1
62 # Save space usage info
63 echo "Post-fill space:" >> $seqres.full
64 df $SCRATCH_MNT >>$seqres.full 2>&1
65
66 # Now attempt a write into all of the preallocated space -
67 # in a very nasty way, badly fragmenting it and then filling it in.
68 echo "Fill in prealloc space; fragment at offsets:" >> $seqres.full
69 for i in `seq 1 2 1023`; do
70         echo -n "$i " >> $seqres.full
71         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
72                 >>$seqres.full 2>/dev/null || _fail "failed to write to test file"
73 done
74 sync
75 echo >> $seqres.full
76 echo "Fill in prealloc space; fill holes at offsets:" >> $seqres.full
77 for i in `seq 2 2 1023`; do
78         echo -n "$i " >> $seqres.full
79         dd if=/dev/zero of=$SCRATCH_MNT/test seek=$i bs=4K count=1 conv=notrunc \
80                 >>$seqres.full 2>/dev/null || _fail "failed to fill test file"
81 done
82 sync
83 echo >> $seqres.full
84
85 echo "done"
86 exit