generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 493
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 493
6 #
7 # Check that we can't dedupe a swapfile.
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         rm -f $tmp.*
22 }
23
24 . ./common/rc
25 . ./common/filter
26 . ./common/reflink
27
28 rm -f $seqres.full
29
30 _supported_fs generic
31 _supported_os Linux
32 _require_scratch_swapfile
33 _require_scratch_dedupe
34
35 echo "Format and mount"
36 _scratch_mkfs > $seqres.full 2>&1
37 _scratch_mount >> $seqres.full 2>&1
38
39 testdir="$SCRATCH_MNT/test-$seq"
40 mkdir "$testdir"
41
42 blocks=160
43 blksz=65536
44
45 echo "Initialize file"
46 _format_swapfile "$testdir/file1" $((blocks * blksz))
47 swapon "$testdir/file1"
48
49 touch "$testdir/file2"
50 $CHATTR_PROG +C "$testdir/file2" >/dev/null 2>&1
51
52 echo "Try to dedupe"
53 cp "$testdir/file1" "$testdir/file2"
54 _dedupe_range "$testdir/file1" 0 "$testdir/file2" 0 $((blocks * blksz))
55 _dedupe_range "$testdir/file2" 0 "$testdir/file1" 0 $((blocks * blksz))
56
57 echo "Tear it down"
58 swapoff "$testdir/file1"
59
60 status=0
61 exit