generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 359
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 359
6 #
7 # Make sure that the reference counting mechanism can handle the case
8 # where we share the first 1/4 of an extent with a file, share the
9 # last 1/4 of the extent with a second file, share the first half of
10 # the extent with N files, and share the second half of the extent
11 # with a different set of N files.  The key point here is to test that
12 # we handle the case where a refcount extent record doesn't coincide
13 # exactly with the block mapping records.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 7 15
23
24 _cleanup()
25 {
26         cd /
27         rm -rf $tmp.*
28         wait
29 }
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/reflink
35
36 # real QA test starts here
37 _supported_os Linux
38 _require_scratch_reflink
39
40 echo "Format and mount"
41 _scratch_mkfs > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 blocks=64
48 blksz=65536
49 nr=4
50 halfway=$((blocks / 2 * blksz))
51 quarter=$((blocks / 4 * blksz))
52
53 echo "Initialize file"
54 _pwrite_byte 0x61 0 $((blocks * blksz)) $testdir/file >> $seqres.full
55
56 echo "Share the first half of the extent"
57 seq 1 $nr | while read nr; do
58         _reflink_range $testdir/file 0 $testdir/file$nr.0 0 $halfway >> $seqres.full
59 done
60
61 echo "Share the last half of the extent"
62 seq 1 $nr | while read nr; do
63         _reflink_range $testdir/file $halfway $testdir/file$nr.1 0 $halfway >> $seqres.full
64 done
65
66 echo "Share the first quarter of the extent"
67 _reflink_range $testdir/file 0 $testdir/file.2 0 $quarter >> $seqres.full
68
69 echo "Share the last quarter of the extent"
70 _reflink_range $testdir/file $((quarter * 3)) $testdir/file.3 0 $quarter >> $seqres.full
71
72 _scratch_cycle_mount
73
74 echo "Check output"
75 md5sum $testdir/file $testdir/file* | _filter_scratch
76
77 # success, all done
78 status=0
79 exit