xref: /openbmc/qemu/tests/qemu-iotests/024 (revision 1f7bf7d0)
1908eaf68SStefan Hajnoczi#!/bin/bash
2939e1640SKevin Wolf#
3939e1640SKevin Wolf# Rebasing COW images
4939e1640SKevin Wolf#
5939e1640SKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
6939e1640SKevin Wolf#
7939e1640SKevin Wolf# This program is free software; you can redistribute it and/or modify
8939e1640SKevin Wolf# it under the terms of the GNU General Public License as published by
9939e1640SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10939e1640SKevin Wolf# (at your option) any later version.
11939e1640SKevin Wolf#
12939e1640SKevin Wolf# This program is distributed in the hope that it will be useful,
13939e1640SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14939e1640SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15939e1640SKevin Wolf# GNU General Public License for more details.
16939e1640SKevin Wolf#
17939e1640SKevin Wolf# You should have received a copy of the GNU General Public License
18939e1640SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19939e1640SKevin Wolf#
20939e1640SKevin Wolf
21939e1640SKevin Wolf# creator
22939e1640SKevin Wolfowner=kwolf@redhat.com
23939e1640SKevin Wolf
24939e1640SKevin Wolfseq=`basename $0`
25939e1640SKevin Wolfecho "QA output created by $seq"
26939e1640SKevin Wolf
27939e1640SKevin Wolfhere=`pwd`
28939e1640SKevin Wolftmp=/tmp/$$
29939e1640SKevin Wolfstatus=1	# failure is the default!
30939e1640SKevin Wolf
31939e1640SKevin Wolf_cleanup()
32939e1640SKevin Wolf{
33939e1640SKevin Wolf	_cleanup_test_img
34fef9c191SJeff Cody	rm -f "$TEST_DIR/t.$IMGFMT.base_old"
35fef9c191SJeff Cody	rm -f "$TEST_DIR/t.$IMGFMT.base_new"
36939e1640SKevin Wolf}
37939e1640SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
38939e1640SKevin Wolf
39939e1640SKevin Wolf# get standard environment, filters and checks
40939e1640SKevin Wolf. ./common.rc
41939e1640SKevin Wolf. ./common.filter
42939e1640SKevin Wolf. ./common.pattern
43939e1640SKevin Wolf
44f5a4bbd9SStefan Hajnoczi# Currently only qcow2 and qed support rebasing
45f5a4bbd9SStefan Hajnoczi_supported_fmt qcow2 qed
46*1f7bf7d0SPeter Lieven_supported_proto file
47939e1640SKevin Wolf_supported_os Linux
48939e1640SKevin Wolf
49939e1640SKevin WolfCLUSTER_SIZE=65536
50939e1640SKevin Wolf
51939e1640SKevin Wolf# Cluster allocations to be tested:
52939e1640SKevin Wolf#
53939e1640SKevin Wolf# Backing (old) 11  --  11  --  11  --  11  --
54939e1640SKevin Wolf# Backing (new) 22  22  --  --  22  22  --  --
55939e1640SKevin Wolf# COW image     33  33  33  33  --  --  --  --
56d586bc63SKevin Wolf#
57d586bc63SKevin Wolf# The pattern is written twice to have both an alloc -> non-alloc and a
58d586bc63SKevin Wolf# non-alloc -> alloc transition in the COW image.
59939e1640SKevin Wolf
60939e1640SKevin Wolfecho "Creating backing file"
61939e1640SKevin Wolfecho
62939e1640SKevin Wolf
63939e1640SKevin Wolf_make_test_img 1G
64dd0c35d6SStefan Hajnocziio_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11
65fef9c191SJeff Codymv "$TEST_IMG" "$TEST_IMG.base_old"
66939e1640SKevin Wolf
67939e1640SKevin Wolfecho "Creating new backing file"
68939e1640SKevin Wolfecho
69939e1640SKevin Wolf
70939e1640SKevin Wolf_make_test_img 1G
71dd0c35d6SStefan Hajnocziio_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22
72fef9c191SJeff Codymv "$TEST_IMG" "$TEST_IMG.base_new"
73939e1640SKevin Wolf
74939e1640SKevin Wolfecho "Creating COW image"
75939e1640SKevin Wolfecho
76939e1640SKevin Wolf
77fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base_old" 1G
78939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33
79d586bc63SKevin Wolfio_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33
80939e1640SKevin Wolf
81939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly"
82939e1640SKevin Wolfecho
83939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
84939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
85939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
86939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
87939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
88939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
89939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
90939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
91d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
92d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
93d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
94d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
95d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
96d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
97d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
98d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
99939e1640SKevin Wolf
100939e1640SKevin Wolfecho
101939e1640SKevin Wolfecho Rebase and test again
102939e1640SKevin Wolfecho
103fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG"
104939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
105939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
106939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
107939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
108939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
109939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
110939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
111939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
112d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
113d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
114d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
115d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
116d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
117d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
118d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
119d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
120939e1640SKevin Wolf
121939e1640SKevin Wolf
122939e1640SKevin Wolf# success, all done
123939e1640SKevin Wolfecho "*** done"
124939e1640SKevin Wolfrm -f $seq.full
125939e1640SKevin Wolfstatus=0
126