Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / qemu-iotests / 252
blob522333cf1dc8b0274702f22ace22fcdb2df1a14d
1 #!/usr/bin/env bash
2 # group: rw auto backing quick
4 # Tests for rebasing COW images that require zero cluster support
6 # Copyright (C) 2019 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=hreitz@redhat.com
25 seq=$(basename $0)
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
33 _rm_test_img "$TEST_IMG.base_new"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40 . ./common.pattern
42 # Currently only qcow2 and qed support rebasing, and only qcow2 v3 has
43 # zero cluster support
44 _supported_fmt qcow2
45 _unsupported_imgopts 'compat=0.10'
46 _supported_proto file fuse
47 _supported_os Linux
49 CLUSTER_SIZE=65536
51 echo
52 echo "=== Test rebase without input base ==="
53 echo
55 # Cluster allocations to be tested:
57 # Backing (new) 11 -- 11 -- 11 --
58 # COW image 22 22 11 11 -- --
60 # Expected result:
62 # COW image 22 22 11 11 00 --
64 # (Cluster 2 might be "--" after the rebase, too, but rebase just
65 # compares the new backing file to the old one and disregards the
66 # overlay. Therefore, it will never discard overlay clusters.)
68 _make_test_img $((6 * CLUSTER_SIZE))
69 TEST_IMG="$TEST_IMG.base_new" _make_test_img $((6 * CLUSTER_SIZE))
71 echo
73 $QEMU_IO "$TEST_IMG" \
74 -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
75 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
76 | _filter_qemu_io
78 $QEMU_IO "$TEST_IMG.base_new" \
79 -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
80 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
81 -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
82 | _filter_qemu_io
84 echo
86 # This should be a no-op
87 $QEMU_IMG rebase -b "" "$TEST_IMG"
89 # Verify the data is correct
90 $QEMU_IO "$TEST_IMG" \
91 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
92 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
93 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
94 | _filter_qemu_io
96 echo
98 # Verify the allocation status (first four cluster should be allocated
99 # in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero
100 # clusters here because there is no backing file))
101 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
103 echo
105 $QEMU_IMG rebase -b "$TEST_IMG.base_new" -F $IMGFMT "$TEST_IMG"
107 # Verify the data is correct
108 $QEMU_IO "$TEST_IMG" \
109 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
110 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
111 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
112 | _filter_qemu_io
114 echo
116 # Verify the allocation status (first four cluster should be allocated
117 # in TEST_IMG, cluster 4 should be zero, and cluster 5 should be
118 # unallocated (signified by '"depth": 1'))
119 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
122 # success, all done
123 echo "*** done"
124 rm -f $seq.full
125 status=0