1*908eaf68SStefan 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 -- -- -- -- 55939e1640SKevin Wolf 56939e1640SKevin Wolfecho "Creating backing file" 57939e1640SKevin Wolfecho 58939e1640SKevin Wolf 59939e1640SKevin Wolf_make_test_img 1G 60939e1640SKevin Wolfio_pattern writev $((-2 * CLUSTER_SIZE)) $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 4 0x11 61939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_old 62939e1640SKevin Wolf 63939e1640SKevin Wolfecho "Creating new backing file" 64939e1640SKevin Wolfecho 65939e1640SKevin Wolf 66939e1640SKevin Wolf_make_test_img 1G 67939e1640SKevin Wolfio_pattern writev $((-4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 2 0x22 68939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_new 69939e1640SKevin Wolf 70939e1640SKevin Wolfecho "Creating COW image" 71939e1640SKevin Wolfecho 72939e1640SKevin Wolf 73939e1640SKevin Wolf_make_test_img -b $TEST_IMG.base_old 1G 74939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33 75939e1640SKevin Wolf 76939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly" 77939e1640SKevin Wolfecho 78939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 79939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 80939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 81939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 82939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 83939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 84939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 85939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 86939e1640SKevin Wolf 87939e1640SKevin Wolfecho 88939e1640SKevin Wolfecho Rebase and test again 89939e1640SKevin Wolfecho 90939e1640SKevin Wolf$QEMU_IMG rebase -b $TEST_IMG.base_new $TEST_IMG 91939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 92939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 93939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 94939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 95939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 96939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 97939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 98939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 99939e1640SKevin Wolf 100939e1640SKevin Wolf 101939e1640SKevin Wolf# success, all done 102939e1640SKevin Wolfecho "*** done" 103939e1640SKevin Wolfrm -f $seq.full 104939e1640SKevin Wolfstatus=0 105