generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 472
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 472
6 #
7 # Test various swapfile activation oddities.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick swap
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         swapoff $swapfile 2> /dev/null
17         rm -f $tmp.*
18 }
19
20 # Import common functions.
21 . ./common/filter
22
23 # real QA test starts here
24 _supported_fs generic
25 _require_scratch_swapfile
26 _require_test_program mkswap
27 _require_test_program swapon
28
29 _scratch_mkfs >>$seqres.full 2>&1
30 _scratch_mount >>$seqres.full 2>&1
31
32 swapfile=$SCRATCH_MNT/swap
33 len=$((2 * 1048576))
34
35 swapfile_cycle() {
36         local swapfile="$1"
37         local len="$2"
38
39         touch $swapfile
40         # Swap files must be nocow on Btrfs.
41         $CHATTR_PROG +C $swapfile >> $seqres.full 2>&1
42         _pwrite_byte 0x58 0 $len $swapfile >> $seqres.full
43         "$here/src/mkswap" $swapfile >> $seqres.full
44         "$here/src/swapon" $swapfile 2>&1 | _filter_scratch
45         swapoff $swapfile 2>> $seqres.full
46         rm -f $swapfile
47 }
48
49 # Create a regular swap file
50 echo "regular swap" | tee -a $seqres.full
51 swapfile_cycle $swapfile $len
52
53 # Create a swap file with a little too much junk on the end
54 echo "too long swap" | tee -a $seqres.full
55 swapfile_cycle $swapfile $((len + 3))
56
57 # Create a ridiculously small swap file.  Each swap file must have at least
58 # two pages after the header page.
59 echo "tiny swap" | tee -a $seqres.full
60 swapfile_cycle $swapfile $(($(get_page_size) * 3))
61
62 status=0
63 exit