generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 496
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 496
6 #
7 # Test various swapfile activation oddities on filesystems that support
8 # fallocated swapfiles.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
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         swapoff $swapfile 2> /dev/null
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34 _supported_fs generic
35 _supported_os Linux
36 _require_scratch_swapfile
37 _require_test_program mkswap
38 _require_test_program swapon
39 _require_xfs_io_command "falloc"
40
41 rm -f $seqres.full
42 _scratch_mkfs >>$seqres.full 2>&1
43 _scratch_mount >>$seqres.full 2>&1
44
45 swapfile=$SCRATCH_MNT/swap
46 len=$((2 * 1048576))
47 page_size=$(get_page_size)
48
49 swapfile_cycle() {
50         local swapfile="$1"
51
52         "$here/src/mkswap" $swapfile >> $seqres.full
53         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
54         swapoff $swapfile 2>> $seqres.full
55         rm -f $swapfile
56 }
57
58 # Create a fallocated swap file
59 echo "fallocate swap" | tee -a $seqres.full
60 touch $swapfile
61 # Swap files must be nocow on Btrfs.
62 $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
63 $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
64 "$here/src/mkswap" $swapfile
65 "$here/src/swapon" $swapfile >> $seqres.full 2>&1 || \
66         _notrun "fallocated swap not supported here"
67 swapoff $swapfile
68
69 # Create a fallocated swap file and touch every other $PAGE_SIZE to create
70 # a mess of written/unwritten extent records
71 echo "mixed swap" | tee -a $seqres.full
72 $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full
73 seq $page_size $((page_size * 2)) $len | while read offset; do
74         _pwrite_byte 0x58 $offset 1 $swapfile >> $seqres.full
75 done
76 swapfile_cycle $swapfile
77
78 status=0
79 exit