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.rc 39. ./common.filter 40 41# This tests qocw2-specific low-level functionality 42_supported_fmt qcow2 43_supported_proto file 44_supported_os Linux 45 46echo 47echo "=== Testing version downgrade with zero expansion ===" 48echo 49IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 50$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 51$PYTHON qcow2.py "$TEST_IMG" dump-header 52$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 53$PYTHON qcow2.py "$TEST_IMG" dump-header 54$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 55_check_test_img 56 57echo 58echo "=== Testing dirty version downgrade ===" 59echo 60IMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 61$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" 2>&1 \ 62 | _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" 2>&1 \ 96 | _filter_qemu_io 97$PYTHON qcow2.py "$TEST_IMG" dump-header 98$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 99$PYTHON qcow2.py "$TEST_IMG" dump-header 100$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 101_check_test_img 102 103echo 104echo "=== Testing backing file ===" 105echo 106IMGOPTS="compat=1.1" _make_test_img 64M 107IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 108$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 109$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 110$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 111$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 112_check_test_img 113 114echo 115echo "=== Testing invalid configurations ===" 116echo 117IMGOPTS="compat=0.10" _make_test_img 64M 118$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 119$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 120$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 121$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 122$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 123$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 124$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 125$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 126 127echo 128echo "=== Testing correct handling of unset value ===" 129echo 130IMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M 131echo "Should work:" 132$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 133echo "Should not work:" # Just to know which of these tests actually fails 134$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 135 136echo 137echo "=== Testing zero expansion on inactive clusters ===" 138echo 139IMGOPTS="compat=1.1" _make_test_img 64M 140$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 141$QEMU_IMG snapshot -c foo "$TEST_IMG" 142$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 143$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 144_check_test_img 145$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 146$QEMU_IMG snapshot -a foo "$TEST_IMG" 147_check_test_img 148$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 149 150echo 151echo "=== Testing zero expansion on shared L2 table ===" 152echo 153IMGOPTS="compat=1.1" _make_test_img 64M 154$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 155$QEMU_IMG snapshot -c foo "$TEST_IMG" 156$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 157_check_test_img 158$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 159$QEMU_IMG snapshot -a foo "$TEST_IMG" 160_check_test_img 161$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 162 163echo 164echo "=== Testing zero expansion on backed image ===" 165echo 166IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 167$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 168IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 169$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 170$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 171_check_test_img 172$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 173 174echo 175echo "=== Testing zero expansion on backed inactive clusters ===" 176echo 177IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 178$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 179IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 180$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 181$QEMU_IMG snapshot -c foo "$TEST_IMG" 182$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 183$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 184_check_test_img 185$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 186$QEMU_IMG snapshot -a foo "$TEST_IMG" 187_check_test_img 188$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 189 190echo 191echo "=== Testing zero expansion on backed image with shared L2 table ===" 192echo 193IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 194$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 195IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 196$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 197$QEMU_IMG snapshot -c foo "$TEST_IMG" 198$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 199_check_test_img 200$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 201$QEMU_IMG snapshot -a foo "$TEST_IMG" 202_check_test_img 203$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 204 205echo 206echo "=== Testing preallocated zero expansion on full image ===" 207echo 208IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M 209$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 210$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 211_check_test_img 212$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 213 214echo 215echo "=== Testing progress report without snapshot ===" 216echo 217IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 218IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 219$QEMU_IO -c "write -z 0 64k" \ 220 -c "write -z 1G 64k" \ 221 -c "write -z 2G 64k" \ 222 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 223$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 224_check_test_img 225 226echo 227echo "=== Testing progress report with snapshot ===" 228echo 229IMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 230IMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 231$QEMU_IO -c "write -z 0 64k" \ 232 -c "write -z 1G 64k" \ 233 -c "write -z 2G 64k" \ 234 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 235$QEMU_IMG snapshot -c foo "$TEST_IMG" 236$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 237_check_test_img 238 239# success, all done 240echo "*** done" 241rm -f $seq.full 242status=0 243