xref: /openbmc/qemu/tests/qemu-iotests/252 (revision 11f6fc50e7501b5f5d04100ea1c21fa8f1cf7b53)
1*11f6fc50SMax Reitz#!/usr/bin/env bash
2*11f6fc50SMax Reitz#
3*11f6fc50SMax Reitz# Tests for rebasing COW images that require zero cluster support
4*11f6fc50SMax Reitz#
5*11f6fc50SMax Reitz# Copyright (C) 2019 Red Hat, Inc.
6*11f6fc50SMax Reitz#
7*11f6fc50SMax Reitz# This program is free software; you can redistribute it and/or modify
8*11f6fc50SMax Reitz# it under the terms of the GNU General Public License as published by
9*11f6fc50SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*11f6fc50SMax Reitz# (at your option) any later version.
11*11f6fc50SMax Reitz#
12*11f6fc50SMax Reitz# This program is distributed in the hope that it will be useful,
13*11f6fc50SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*11f6fc50SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*11f6fc50SMax Reitz# GNU General Public License for more details.
16*11f6fc50SMax Reitz#
17*11f6fc50SMax Reitz# You should have received a copy of the GNU General Public License
18*11f6fc50SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*11f6fc50SMax Reitz#
20*11f6fc50SMax Reitz
21*11f6fc50SMax Reitz# creator
22*11f6fc50SMax Reitzowner=mreitz@redhat.com
23*11f6fc50SMax Reitz
24*11f6fc50SMax Reitzseq=$(basename $0)
25*11f6fc50SMax Reitzecho "QA output created by $seq"
26*11f6fc50SMax Reitz
27*11f6fc50SMax Reitzstatus=1	# failure is the default!
28*11f6fc50SMax Reitz
29*11f6fc50SMax Reitz_cleanup()
30*11f6fc50SMax Reitz{
31*11f6fc50SMax Reitz    _cleanup_test_img
32*11f6fc50SMax Reitz    rm -f "$TEST_IMG.base_new"
33*11f6fc50SMax Reitz}
34*11f6fc50SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35*11f6fc50SMax Reitz
36*11f6fc50SMax Reitz# get standard environment, filters and checks
37*11f6fc50SMax Reitz. ./common.rc
38*11f6fc50SMax Reitz. ./common.filter
39*11f6fc50SMax Reitz. ./common.pattern
40*11f6fc50SMax Reitz
41*11f6fc50SMax Reitz# Currently only qcow2 and qed support rebasing, and only qcow2 v3 has
42*11f6fc50SMax Reitz# zero cluster support
43*11f6fc50SMax Reitz_supported_fmt qcow2
44*11f6fc50SMax Reitz_unsupported_imgopts 'compat=0.10'
45*11f6fc50SMax Reitz_supported_proto file
46*11f6fc50SMax Reitz_supported_os Linux
47*11f6fc50SMax Reitz
48*11f6fc50SMax ReitzCLUSTER_SIZE=65536
49*11f6fc50SMax Reitz
50*11f6fc50SMax Reitzecho
51*11f6fc50SMax Reitzecho "=== Test rebase without input base ==="
52*11f6fc50SMax Reitzecho
53*11f6fc50SMax Reitz
54*11f6fc50SMax Reitz# Cluster allocations to be tested:
55*11f6fc50SMax Reitz#
56*11f6fc50SMax Reitz# Backing (new) 11 -- 11 -- 11 --
57*11f6fc50SMax Reitz# COW image     22 22 11 11 -- --
58*11f6fc50SMax Reitz#
59*11f6fc50SMax Reitz# Expected result:
60*11f6fc50SMax Reitz#
61*11f6fc50SMax Reitz# COW image     22 22 11 11 00 --
62*11f6fc50SMax Reitz#
63*11f6fc50SMax Reitz# (Cluster 2 might be "--" after the rebase, too, but rebase just
64*11f6fc50SMax Reitz#  compares the new backing file to the old one and disregards the
65*11f6fc50SMax Reitz#  overlay.  Therefore, it will never discard overlay clusters.)
66*11f6fc50SMax Reitz
67*11f6fc50SMax Reitz_make_test_img $((6 * CLUSTER_SIZE))
68*11f6fc50SMax ReitzTEST_IMG="$TEST_IMG.base_new" _make_test_img $((6 * CLUSTER_SIZE))
69*11f6fc50SMax Reitz
70*11f6fc50SMax Reitzecho
71*11f6fc50SMax Reitz
72*11f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
73*11f6fc50SMax Reitz    -c "write -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
74*11f6fc50SMax Reitz    -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
75*11f6fc50SMax Reitz    | _filter_qemu_io
76*11f6fc50SMax Reitz
77*11f6fc50SMax Reitz$QEMU_IO "$TEST_IMG.base_new" \
78*11f6fc50SMax Reitz    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
79*11f6fc50SMax Reitz    -c "write -P 0x11 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
80*11f6fc50SMax Reitz    -c "write -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
81*11f6fc50SMax Reitz    | _filter_qemu_io
82*11f6fc50SMax Reitz
83*11f6fc50SMax Reitzecho
84*11f6fc50SMax Reitz
85*11f6fc50SMax Reitz# This should be a no-op
86*11f6fc50SMax Reitz$QEMU_IMG rebase -b "" "$TEST_IMG"
87*11f6fc50SMax Reitz
88*11f6fc50SMax Reitz# Verify the data is correct
89*11f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
90*11f6fc50SMax Reitz    -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
91*11f6fc50SMax Reitz    -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
92*11f6fc50SMax Reitz    -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
93*11f6fc50SMax Reitz    | _filter_qemu_io
94*11f6fc50SMax Reitz
95*11f6fc50SMax Reitzecho
96*11f6fc50SMax Reitz
97*11f6fc50SMax Reitz# Verify the allocation status (first four cluster should be allocated
98*11f6fc50SMax Reitz# in TEST_IMG, clusters 4 and 5 should be unallocated (marked as zero
99*11f6fc50SMax Reitz# clusters here because there is no backing file))
100*11f6fc50SMax Reitz$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
101*11f6fc50SMax Reitz
102*11f6fc50SMax Reitzecho
103*11f6fc50SMax Reitz
104*11f6fc50SMax Reitz$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG"
105*11f6fc50SMax Reitz
106*11f6fc50SMax Reitz# Verify the data is correct
107*11f6fc50SMax Reitz$QEMU_IO "$TEST_IMG" \
108*11f6fc50SMax Reitz    -c "read -P 0x22 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
109*11f6fc50SMax Reitz    -c "read -P 0x11 $((2 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
110*11f6fc50SMax Reitz    -c "read -P 0x00 $((4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
111*11f6fc50SMax Reitz    | _filter_qemu_io
112*11f6fc50SMax Reitz
113*11f6fc50SMax Reitzecho
114*11f6fc50SMax Reitz
115*11f6fc50SMax Reitz# Verify the allocation status (first four cluster should be allocated
116*11f6fc50SMax Reitz# in TEST_IMG, cluster 4 should be zero, and cluster 5 should be
117*11f6fc50SMax Reitz# unallocated (signified by '"depth": 1'))
118*11f6fc50SMax Reitz$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
119*11f6fc50SMax Reitz
120*11f6fc50SMax Reitz
121*11f6fc50SMax Reitz# success, all done
122*11f6fc50SMax Reitzecho "*** done"
123*11f6fc50SMax Reitzrm -f $seq.full
124*11f6fc50SMax Reitzstatus=0
125