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 461f7bf7d0SPeter 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 63*f19f1189SFam ZhengTEST_IMG_SAVE="$TEST_IMG" 64*f19f1189SFam ZhengTEST_IMG="$TEST_IMG.base_old" 65*f19f1189SFam Zheng 66939e1640SKevin Wolf_make_test_img 1G 67dd0c35d6SStefan Hajnocziio_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11 68*f19f1189SFam Zheng 69*f19f1189SFam ZhengTEST_IMG="$TEST_IMG_SAVE.base_new" 70939e1640SKevin Wolf 71939e1640SKevin Wolfecho "Creating new backing file" 72939e1640SKevin Wolfecho 73939e1640SKevin Wolf 74939e1640SKevin Wolf_make_test_img 1G 75dd0c35d6SStefan Hajnocziio_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22 76*f19f1189SFam Zheng 77*f19f1189SFam Zheng 78*f19f1189SFam ZhengTEST_IMG="$TEST_IMG_SAVE" 79939e1640SKevin Wolf 80939e1640SKevin Wolfecho "Creating COW image" 81939e1640SKevin Wolfecho 82939e1640SKevin Wolf 83fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base_old" 1G 84939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33 85d586bc63SKevin Wolfio_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33 86939e1640SKevin Wolf 87939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly" 88939e1640SKevin Wolfecho 89939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 90939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 91939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 92939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 93939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 94939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 95939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 96939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 97d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 98d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 99d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 100d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 101d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 102d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 103d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 104d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 105939e1640SKevin Wolf 106939e1640SKevin Wolfecho 107939e1640SKevin Wolfecho Rebase and test again 108939e1640SKevin Wolfecho 109fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG" 110939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 111939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 112939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 113939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 114939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 115939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 116939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 117939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 118d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 119d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 120d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 121d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 122d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 123d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 124d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 125d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 126939e1640SKevin Wolf 127939e1640SKevin Wolf 128939e1640SKevin Wolf# success, all done 129939e1640SKevin Wolfecho "*** done" 130939e1640SKevin Wolfrm -f $seq.full 131939e1640SKevin Wolfstatus=0 132