1*939e1640SKevin Wolf#!/bin/sh 2*939e1640SKevin Wolf# 3*939e1640SKevin Wolf# Rebasing COW images 4*939e1640SKevin Wolf# 5*939e1640SKevin Wolf# Copyright (C) 2009 Red Hat, Inc. 6*939e1640SKevin Wolf# 7*939e1640SKevin Wolf# This program is free software; you can redistribute it and/or modify 8*939e1640SKevin Wolf# it under the terms of the GNU General Public License as published by 9*939e1640SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*939e1640SKevin Wolf# (at your option) any later version. 11*939e1640SKevin Wolf# 12*939e1640SKevin Wolf# This program is distributed in the hope that it will be useful, 13*939e1640SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*939e1640SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*939e1640SKevin Wolf# GNU General Public License for more details. 16*939e1640SKevin Wolf# 17*939e1640SKevin Wolf# You should have received a copy of the GNU General Public License 18*939e1640SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*939e1640SKevin Wolf# 20*939e1640SKevin Wolf 21*939e1640SKevin Wolf# creator 22*939e1640SKevin Wolfowner=kwolf@redhat.com 23*939e1640SKevin Wolf 24*939e1640SKevin Wolfseq=`basename $0` 25*939e1640SKevin Wolfecho "QA output created by $seq" 26*939e1640SKevin Wolf 27*939e1640SKevin Wolfhere=`pwd` 28*939e1640SKevin Wolftmp=/tmp/$$ 29*939e1640SKevin Wolfstatus=1 # failure is the default! 30*939e1640SKevin Wolf 31*939e1640SKevin Wolf_cleanup() 32*939e1640SKevin Wolf{ 33*939e1640SKevin Wolf _cleanup_test_img 34*939e1640SKevin Wolf rm -f $TEST_DIR/t.$IMGFMT.base_old 35*939e1640SKevin Wolf rm -f $TEST_DIR/t.$IMGFMT.base_new 36*939e1640SKevin Wolf} 37*939e1640SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 38*939e1640SKevin Wolf 39*939e1640SKevin Wolf# get standard environment, filters and checks 40*939e1640SKevin Wolf. ./common.rc 41*939e1640SKevin Wolf. ./common.filter 42*939e1640SKevin Wolf. ./common.pattern 43*939e1640SKevin Wolf 44*939e1640SKevin Wolf# Currently only qcow2 supports rebasing 45*939e1640SKevin Wolf_supported_fmt qcow2 46*939e1640SKevin Wolf_supported_os Linux 47*939e1640SKevin Wolf 48*939e1640SKevin WolfCLUSTER_SIZE=65536 49*939e1640SKevin Wolf 50*939e1640SKevin Wolf# Cluster allocations to be tested: 51*939e1640SKevin Wolf# 52*939e1640SKevin Wolf# Backing (old) 11 -- 11 -- 11 -- 11 -- 53*939e1640SKevin Wolf# Backing (new) 22 22 -- -- 22 22 -- -- 54*939e1640SKevin Wolf# COW image 33 33 33 33 -- -- -- -- 55*939e1640SKevin Wolf 56*939e1640SKevin Wolfecho "Creating backing file" 57*939e1640SKevin Wolfecho 58*939e1640SKevin Wolf 59*939e1640SKevin Wolf_make_test_img 1G 60*939e1640SKevin Wolfio_pattern writev $((-2 * CLUSTER_SIZE)) $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 4 0x11 61*939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_old 62*939e1640SKevin Wolf 63*939e1640SKevin Wolfecho "Creating new backing file" 64*939e1640SKevin Wolfecho 65*939e1640SKevin Wolf 66*939e1640SKevin Wolf_make_test_img 1G 67*939e1640SKevin Wolfio_pattern writev $((-4 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 2 0x22 68*939e1640SKevin Wolfmv $TEST_IMG $TEST_IMG.base_new 69*939e1640SKevin Wolf 70*939e1640SKevin Wolfecho "Creating COW image" 71*939e1640SKevin Wolfecho 72*939e1640SKevin Wolf 73*939e1640SKevin Wolf_make_test_img -b $TEST_IMG.base_old 1G 74*939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33 75*939e1640SKevin Wolf 76*939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly" 77*939e1640SKevin Wolfecho 78*939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 79*939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 80*939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 81*939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 82*939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 83*939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 84*939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 85*939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 86*939e1640SKevin Wolf 87*939e1640SKevin Wolfecho 88*939e1640SKevin Wolfecho Rebase and test again 89*939e1640SKevin Wolfecho 90*939e1640SKevin Wolf$QEMU_IMG rebase -b $TEST_IMG.base_new $TEST_IMG 91*939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 92*939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 93*939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 94*939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 95*939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 96*939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 97*939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 98*939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 99*939e1640SKevin Wolf 100*939e1640SKevin Wolf 101*939e1640SKevin Wolf# success, all done 102*939e1640SKevin Wolfecho "*** done" 103*939e1640SKevin Wolfrm -f $seq.full 104*939e1640SKevin Wolfstatus=0 105