024 6.3 KB
Newer Older
1
#!/bin/bash
K
Kevin Wolf 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#
# Rebasing COW images
#
# Copyright (C) 2009 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# creator
owner=kwolf@redhat.com

seq=`basename $0`
echo "QA output created by $seq"

status=1	# failure is the default!

_cleanup()
{
31 32 33 34 35 36 37 38
    _cleanup_test_img
    rm -f "$TEST_DIR/t.$IMGFMT.base_old"
    rm -f "$TEST_DIR/t.$IMGFMT.base_new"

    rm -f "$TEST_DIR/subdir/t.$IMGFMT"
    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_old"
    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_new"
    rmdir "$TEST_DIR/subdir" 2> /dev/null
K
Kevin Wolf 已提交
39 40 41 42 43 44 45 46
}
trap "_cleanup; exit \$status" 0 1 2 3 15

# get standard environment, filters and checks
. ./common.rc
. ./common.filter
. ./common.pattern

47 48
# Currently only qcow2 and qed support rebasing
_supported_fmt qcow2 qed
49
_supported_proto file
K
Kevin Wolf 已提交
50 51 52 53 54 55 56 57 58
_supported_os Linux

CLUSTER_SIZE=65536

# Cluster allocations to be tested:
#
# Backing (old) 11  --  11  --  11  --  11  --
# Backing (new) 22  22  --  --  22  22  --  --
# COW image     33  33  33  33  --  --  --  --
K
Kevin Wolf 已提交
59 60 61
#
# The pattern is written twice to have both an alloc -> non-alloc and a
# non-alloc -> alloc transition in the COW image.
K
Kevin Wolf 已提交
62 63 64 65

echo "Creating backing file"
echo

66 67 68
TEST_IMG_SAVE="$TEST_IMG"
TEST_IMG="$TEST_IMG.base_old"

K
Kevin Wolf 已提交
69
_make_test_img 1G
70
io_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11
71 72

TEST_IMG="$TEST_IMG_SAVE.base_new"
K
Kevin Wolf 已提交
73 74 75 76 77

echo "Creating new backing file"
echo

_make_test_img 1G
78
io_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22
79 80 81


TEST_IMG="$TEST_IMG_SAVE"
K
Kevin Wolf 已提交
82 83 84 85

echo "Creating COW image"
echo

86
_make_test_img -b "$TEST_IMG.base_old" 1G
K
Kevin Wolf 已提交
87
io_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33
K
Kevin Wolf 已提交
88
io_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33
K
Kevin Wolf 已提交
89 90 91 92 93 94 95 96 97 98 99

echo "Read before the rebase to make sure everything is set up correctly"
echo
io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
K
Kevin Wolf 已提交
100 101 102 103 104 105 106 107
io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
K
Kevin Wolf 已提交
108 109 110 111

echo
echo Rebase and test again
echo
112
$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG"
K
Kevin Wolf 已提交
113 114 115 116 117 118 119 120
io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
K
Kevin Wolf 已提交
121 122 123 124 125 126 127 128
io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
K
Kevin Wolf 已提交
129

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
echo
echo "=== Test rebase in a subdirectory of the working directory ==="
echo

# Clean up the old images beforehand so they do not interfere with
# this test
_cleanup

mkdir "$TEST_DIR/subdir"

# Relative to the overlay
BASE_OLD_OREL="t.$IMGFMT.base_old"
BASE_NEW_OREL="t.$IMGFMT.base_new"

# Relative to $TEST_DIR (which is going to be our working directory)
OVERLAY_WREL="subdir/t.$IMGFMT"

BASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL"
BASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL"
OVERLAY="$TEST_DIR/$OVERLAY_WREL"

# Test done here:
#
# Backing (old): 11 11 -- 11
# Backing (new): -- 22 22 11
# Overlay:       -- -- -- --
#
# Rebasing works, we have verified that above.  Here, we just want to
# see that rebasing is done for the correct target backing file.

TEST_IMG=$BASE_OLD _make_test_img 1M
TEST_IMG=$BASE_NEW _make_test_img 1M
TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" 1M

echo

$QEMU_IO "$BASE_OLD" \
    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
    | _filter_qemu_io

$QEMU_IO "$BASE_NEW" \
    -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
    | _filter_qemu_io

echo

pushd "$TEST_DIR" >/dev/null
$QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" "$OVERLAY_WREL"
popd >/dev/null

# Verify the backing path is correct
TEST_IMG=$OVERLAY _img_info | grep '^backing file'

echo

# Verify the data is correct
$QEMU_IO "$OVERLAY" \
    -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
    -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
    -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
    -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
    | _filter_qemu_io

echo

# Verify that cluster #3 is not allocated (because it is the same in
# $BASE_OLD and $BASE_NEW)
$QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map

K
Kevin Wolf 已提交
201 202 203 204 205

# success, all done
echo "*** done"
rm -f $seq.full
status=0