3 # Tests for rebasing COW images that require zero cluster support
5 # Copyright (C) 2019 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 owner
=mreitz@redhat.com
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
32 _rm_test_img
"$TEST_IMG.base_new"
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
41 # Currently only qcow2 and qed support rebasing, and only qcow2 v3 has
42 # zero cluster support
44 _unsupported_imgopts
'compat=0.10'
51 echo "=== Test rebase without input base ==="
54 # Cluster allocations to be tested:
56 # Backing (new) 11 -- 11 -- 11 --
57 # COW image 22 22 11 11 -- --
61 # COW image 22 22 11 11 00 --
63 # (Cluster 2 might be "--" after the rebase, too, but rebase just
64 # compares the new backing file to the old one and disregards the
65 # overlay. Therefore, it will never discard overlay clusters.)
67 _make_test_img $
((6 * CLUSTER_SIZE
))
68 TEST_IMG
="$TEST_IMG.base_new" _make_test_img $
((6 * CLUSTER_SIZE
))
72 $QEMU_IO "$TEST_IMG" \
73 -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
74 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
77 $QEMU_IO "$TEST_IMG.base_new" \
78 -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
79 -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
80 -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
85 # This should be a no-op
86 $QEMU_IMG rebase
-b "" "$TEST_IMG"
88 # Verify the data is correct
89 $QEMU_IO "$TEST_IMG" \
90 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
91 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
92 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
97 # Verify the allocation status (first four cluster should be allocated
98 # in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero
99 # clusters here because there is no backing file))
100 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map
104 $QEMU_IMG rebase
-b "$TEST_IMG.base_new" -F $IMGFMT "$TEST_IMG"
106 # Verify the data is correct
107 $QEMU_IO "$TEST_IMG" \
108 -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
109 -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
110 -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
115 # Verify the allocation status (first four cluster should be allocated
116 # in TEST_IMG, cluster 4 should be zero, and cluster 5 should be
117 # unallocated (signified by '"depth": 1'))
118 $QEMU_IMG map
--output=json
"$TEST_IMG" | _filter_qemu_img_map