common/xfs: refactor commands to select a particular xfs backing device
[xfstests-dev.git] / tests / xfs / 129
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 129
6 #
7 # Ensure that we can create enough distinct reflink entries to force creation
8 # of a multi-level refcount btree, and that metadump will successfully copy
9 # said block.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1    # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     _scratch_unmount > /dev/null 2>&1
24     rm -rf $tmp.* $testdir $metadump_file $TEST_DIR/image
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 _supported_fs xfs
34 _require_loop
35 _require_scratch_reflink
36
37 rm -f $seqres.full
38
39 _scratch_mkfs >/dev/null 2>&1
40 _scratch_mount
41
42 testdir=$SCRATCH_MNT/test-$seq
43 mkdir $testdir
44 metadump_file=$TEST_DIR/${seq}_metadump
45
46 echo "Create the original file blocks"
47 blksz="$(_get_file_block_size $testdir)"
48 nr_blks=$((4 * blksz / 12))
49 _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/file1 >> $seqres.full
50
51 echo "Reflink every other block"
52 seq 1 2 $((nr_blks - 1)) | while read nr; do
53         _reflink_range  $testdir/file1 $((nr * blksz)) \
54                         $testdir/file2 $((nr * blksz)) $blksz >> $seqres.full
55 done
56
57 echo "Create metadump file"
58 _scratch_unmount
59 _scratch_xfs_metadump $metadump_file
60
61 # Now restore the obfuscated one back and take a look around
62 echo "Restore metadump"
63 xfs_mdrestore $metadump_file $TEST_DIR/image
64 SCRATCH_DEV=$TEST_DIR/image _scratch_mount
65 SCRATCH_DEV=$TEST_DIR/image _scratch_unmount
66
67 echo "Check restored fs"
68 _check_generic_filesystem $metadump_file
69
70 # success, all done
71 status=0
72 exit