Merge remote-tracking branch 'remotes/ehabkost/tags/x86-next-for-5.1-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 252
blob6662f4c9dec76a3be23c6e9545f9930b55eb8a17
1 #!/usr/bin/env bash
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/>.
21 # creator
22 owner=mreitz@redhat.com
24 seq=$(basename $0)
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 _cleanup()
31 _cleanup_test_img
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
37 . ./common.rc
38 . ./common.filter
39 . ./common.pattern
41 # Currently only qcow2 and qed support rebasing, and only qcow2 v3 has
42 # zero cluster support
43 _supported_fmt qcow2
44 _unsupported_imgopts 'compat=0.10'
45 _supported_proto file
46 _supported_os Linux
48 CLUSTER_SIZE=65536
50 echo
51 echo "=== Test rebase without input base ==="
52 echo
54 # Cluster allocations to be tested:
56 # Backing (new) 11 -- 11 -- 11 --
57 # COW image 22 22 11 11 -- --
59 # Expected result:
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))
70 echo
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))" \
75 | _filter_qemu_io
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" \
81 | _filter_qemu_io
83 echo
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))" \
93 | _filter_qemu_io
95 echo
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
102 echo
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))" \
111 | _filter_qemu_io
113 echo
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
121 # success, all done
122 echo "*** done"
123 rm -f $seq.full
124 status=0