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 34939e1640SKevin Wolf rm -f $TEST_DIR/t.$IMGFMT.base_old 35939e1640SKevin Wolf 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 44939e1640SKevin Wolf# Currently only qcow2 supports rebasing 45939e1640SKevin Wolf_supported_fmt qcow2 46939e1640SKevin Wolf_supported_os Linux 47939e1640SKevin Wolf 48939e1640SKevin WolfCLUSTER_SIZE=65536 49939e1640SKevin Wolf 50939e1640SKevin Wolf# Cluster allocations to be tested: 51939e1640SKevin Wolf# 52939e1640SKevin Wolf# Backing (old) 11 -- 11 -- 11 -- 11 -- 53939e1640SKevin Wolf# Backing (new) 22 22 -- -- 22 22 -- -- 54939e1640SKevin Wolf# COW image 33 33 33 33 -- -- -- -- 55*d586bc63SKevin Wolf# 56*d586bc63SKevin Wolf# The pattern is written twice to have both an alloc -> non-alloc and a 57*d586bc63SKevin Wolf# non-alloc -> alloc transition in the COW image. 58939e1640SKevin Wolf 59939e1640SKevin Wolfecho "Creating backing file" 60939e1640SKevin Wolfecho 61939e1640SKevin Wolf 62939e1640SKevin Wolf_make_test_img 1G 63*d586bc63SKevin Wolfio_pattern writev $((-2 * CLUSTER_SIZE)) $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11 64939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_old 65939e1640SKevin Wolf 66939e1640SKevin Wolfecho "Creating new backing file" 67939e1640SKevin Wolfecho 68939e1640SKevin Wolf 69939e1640SKevin Wolf_make_test_img 1G 70*d586bc63SKevin Wolfio_pattern writev $((-4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22 71939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_new 72939e1640SKevin Wolf 73939e1640SKevin Wolfecho "Creating COW image" 74939e1640SKevin Wolfecho 75939e1640SKevin Wolf 76939e1640SKevin Wolf_make_test_img -b $TEST_IMG.base_old 1G 77939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33 78*d586bc63SKevin Wolfio_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33 79939e1640SKevin Wolf 80939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly" 81939e1640SKevin Wolfecho 82939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 83939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 84939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 85939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 86939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 87939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 88939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 89939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 90*d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 91*d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 92*d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 93*d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 94*d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 95*d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 96*d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 97*d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 98939e1640SKevin Wolf 99939e1640SKevin Wolfecho 100939e1640SKevin Wolfecho Rebase and test again 101939e1640SKevin Wolfecho 102939e1640SKevin Wolf$QEMU_IMG rebase -b $TEST_IMG.base_new $TEST_IMG 103939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 104939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 105939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 106939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 107939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 108939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 109939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 110939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 111*d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 112*d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 113*d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 114*d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 115*d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 116*d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 117*d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 118*d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 119939e1640SKevin Wolf 120939e1640SKevin Wolf 121939e1640SKevin Wolf# success, all done 122939e1640SKevin Wolfecho "*** done" 123939e1640SKevin Wolfrm -f $seq.full 124939e1640SKevin Wolfstatus=0 125