1#!/bin/bash 2# 3# Test case for image option amendment in qcow2. 4# 5# Copyright (C) 2013 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=mreitz@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28tmp=/tmp/$$ 29status=1 # failure is the default! 30 31_cleanup() 32{ 33 _cleanup_test_img 34} 35trap "_cleanup; exit \$status" 0 1 2 3 15 36 37# get standard environment, filters and checks 38. ./common.env 39. ./common.rc 40. ./common.filter 41 42# This tests qocw2-specific low-level functionality 43_supported_fmt qcow2 44_supported_proto file 45_supported_os Linux 46 47echo 48echo "=== Testing version downgrade with zero expansion ===" 49echo 50IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 51$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 52$PYTHON qcow2.py "$TEST_IMG" dump-header 53$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 54$PYTHON qcow2.py "$TEST_IMG" dump-header 55$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 56_check_test_img 57 58echo 59echo "=== Testing dirty version downgrade ===" 60echo 61IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 62$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io 63$PYTHON qcow2.py "$TEST_IMG" dump-header 64$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 65$PYTHON qcow2.py "$TEST_IMG" dump-header 66$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 67_check_test_img 68 69echo 70echo "=== Testing version downgrade with unknown compat/autoclear flags ===" 71echo 72IMGOPTS="compat=1.1" _make_test_img 64M 73$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42 74$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42 75$PYTHON qcow2.py "$TEST_IMG" dump-header 76$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 77$PYTHON qcow2.py "$TEST_IMG" dump-header 78_check_test_img 79 80echo 81echo "=== Testing version upgrade and resize ===" 82echo 83IMGOPTS="compat=0.10" _make_test_img 64M 84$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 85$PYTHON qcow2.py "$TEST_IMG" dump-header 86$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG" 87$PYTHON qcow2.py "$TEST_IMG" dump-header 88$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 89_check_test_img 90 91echo 92echo "=== Testing dirty lazy_refcounts=off ===" 93echo 94IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 95$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io 96$PYTHON qcow2.py "$TEST_IMG" dump-header 97$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 98$PYTHON qcow2.py "$TEST_IMG" dump-header 99$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 100_check_test_img 101 102echo 103echo "=== Testing backing file ===" 104echo 105IMGOPTS="compat=1.1" _make_test_img 64M 106IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 107$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 108$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 109$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 110$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 111_check_test_img 112 113echo 114echo "=== Testing invalid configurations ===" 115echo 116IMGOPTS="compat=0.10" _make_test_img 64M 117$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 118$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 119$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 120$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 121$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 122$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 123$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 124$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 125 126echo 127echo "=== Testing correct handling of unset value ===" 128echo 129IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M 130echo "Should work:" 131$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 132echo "Should not work:" # Just to know which of these tests actually fails 133$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 134 135echo 136echo "=== Testing zero expansion on inactive clusters ===" 137echo 138IMGOPTS="compat=1.1" _make_test_img 64M 139$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 140$QEMU_IMG snapshot -c foo "$TEST_IMG" 141$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 142$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 143_check_test_img 144$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 145$QEMU_IMG snapshot -a foo "$TEST_IMG" 146_check_test_img 147$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 148 149echo 150echo "=== Testing zero expansion on shared L2 table ===" 151echo 152IMGOPTS="compat=1.1" _make_test_img 64M 153$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 154$QEMU_IMG snapshot -c foo "$TEST_IMG" 155$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 156_check_test_img 157$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 158$QEMU_IMG snapshot -a foo "$TEST_IMG" 159_check_test_img 160$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 161 162echo 163echo "=== Testing zero expansion on backed image ===" 164echo 165IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 166$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 167IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 168$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 169$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 170_check_test_img 171$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 172 173echo 174echo "=== Testing zero expansion on backed inactive clusters ===" 175echo 176IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 177$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 178IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 179$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 180$QEMU_IMG snapshot -c foo "$TEST_IMG" 181$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 182$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 183_check_test_img 184$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 185$QEMU_IMG snapshot -a foo "$TEST_IMG" 186_check_test_img 187$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 188 189echo 190echo "=== Testing zero expansion on backed image with shared L2 table ===" 191echo 192IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 193$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 194IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 195$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 196$QEMU_IMG snapshot -c foo "$TEST_IMG" 197$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 198_check_test_img 199$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 200$QEMU_IMG snapshot -a foo "$TEST_IMG" 201_check_test_img 202$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 203 204echo 205echo "=== Testing preallocated zero expansion on full image ===" 206echo 207IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M 208$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 209$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 210_check_test_img 211$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 212 213# success, all done 214echo "*** done" 215rm -f $seq.full 216status=0 217