generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / generic / 497
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 497
6 #
7 # Test various swapfile activation oddities, having used fcollapse to
8 # create discontiguous ranges in the file.
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 _require_scratch_swapfile
36 _require_test_program mkswap
37 _require_test_program swapon
38 _require_xfs_io_command "fcollapse"
39
40 rm -f $seqres.full
41 _scratch_mkfs >>$seqres.full 2>&1
42 _scratch_mount >>$seqres.full 2>&1
43
44 swapfile=$SCRATCH_MNT/swap
45 len=$((2 * 1048576))
46 page_size=$(get_page_size)
47
48 swapfile_cycle() {
49         local swapfile="$1"
50
51         # Swap files must be nocow on Btrfs.
52         $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
53         "$here/src/mkswap" $swapfile >> $seqres.full
54         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
55         swapoff $swapfile 2>> $seqres.full
56         rm -f $swapfile
57 }
58
59 # Create a swap file with a large discontiguous range(?)
60 echo "large discontig swap" | tee -a $seqres.full
61 _pwrite_byte 0x58 0 $((len * 2)) $swapfile >> $seqres.full
62 old_sz="$(_get_filesize $swapfile)"
63 $XFS_IO_PROG -c "fcollapse $((len / 2)) $len" $swapfile >> $seqres.full 2>&1
64 new_sz="$(_get_filesize $swapfile)"
65 if [ $old_sz -gt $new_sz ]; then
66         swapfile_cycle $swapfile
67 fi
68 rm -f $swapfile
69
70 # Create a swap file with a small discontiguous range(?)
71 echo "small discontig swap" | tee -a $seqres.full
72 _pwrite_byte 0x58 0 $((len + 1024)) $swapfile >> $seqres.full
73 old_sz="$(_get_filesize $swapfile)"
74 $XFS_IO_PROG -c "fcollapse 66560 1024" $swapfile >> $seqres.full 2>&1
75 new_sz="$(_get_filesize $swapfile)"
76 if [ $old_sz -gt $new_sz ]; then
77         swapfile_cycle $swapfile
78 fi
79 rm -f $swapfile
80
81 status=0
82 exit