common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / generic / 569
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-newer
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 569
6 #
7 # Check that we can't modify a file that's an active swap file.
8
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         swapoff $testfile
22         rm -rf $tmp.* $testfile
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_os Linux
31 _supported_fs generic
32 _require_xfs_io_command "falloc"
33 _require_test_program swapon
34 _require_scratch_swapfile
35
36 rm -f $seqres.full
37
38 _scratch_mkfs > $seqres.full 2>&1
39 _scratch_mount >> $seqres.full 2>&1
40
41 testfile=$SCRATCH_MNT/$seq.swap
42
43 _format_swapfile $testfile 20m
44
45 # Can you modify the swapfile via previously open file descriptors?
46 for verb in 1 2 3 4; do
47         echo "verb $verb"
48         "$here/src/swapon" -v $verb $testfile
49         swapoff $testfile
50 done
51
52 # Now try writing with a new file descriptor.
53 swapon $testfile 2>&1 | _filter_scratch
54
55 # Can we write to it?
56 $XFS_IO_PROG -c 'pwrite -S 0x59 64k 64k' $testfile 2>&1 | _filter_xfs_io_error
57 $XFS_IO_PROG -d -c 'pwrite -S 0x60 64k 64k' $testfile 2>&1 | _filter_xfs_io_error
58 $XFS_IO_PROG -c 'mmap -rw 64k 64k' -c 'mwrite -S 0x61 64k 64k' $testfile
59
60 # Can we change the file size?
61 $XFS_IO_PROG -c 'truncate 18m' $testfile
62
63 # Can you fallocate the file?
64 $XFS_IO_PROG -c 'falloc 0 32m' $testfile
65
66 # We test that you can't reflink, dedupe, or copy_file_range into a swapfile
67 # in other tests.
68
69 # success, all done
70 status=0
71 exit