generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 115
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 115
6 #
7 # Moving and deleting cloned ("reflinked") files on btrfs:
8 #   - Create a file and a reflink
9 #   - Move both to a directory
10 #   - Delete the original (moved) file, check that the copy still exists.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -f $tmp.* $testdir
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _require_test_reflink
34 _supported_os Linux
35
36 _require_xfs_io_command "fiemap"
37 _require_cp_reflink
38 _require_test
39
40 rm -f $seqres.full
41
42 testdir1=$TEST_DIR/test-$seq
43 rm -rf $testdir1
44 mkdir $testdir1
45
46 echo "Create the original files and reflink dirs"
47 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $testdir1/original \
48     >> $seqres.full
49 cp --reflink $testdir1/original $testdir1/copy
50
51 _verify_reflink $testdir1/original $testdir1/copy
52
53 echo "Move orig & reflink copy to subdir and md5sum:"
54 mkdir $testdir1/subdir
55 mv $testdir1/original $testdir1/subdir/original_moved
56 mv $testdir1/copy $testdir1/subdir/copy_moved
57 _verify_reflink $testdir1/subdir/original_moved \
58     $testdir1/subdir/copy_moved
59
60 md5sum $testdir1/subdir/original_moved | _filter_test_dir
61 md5sum $testdir1/subdir/copy_moved | _filter_test_dir
62
63 echo "remove orig from subdir and md5sum reflink copy:"
64 rm $testdir1/subdir/original_moved
65 md5sum $testdir1/subdir/copy_moved | _filter_test_dir
66 rm -rf $testdir1/subdir
67
68 # success, all done
69 status=0
70 exit