1#!/usr/bin/env 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 27status=1 # failure is the default! 28 29_cleanup() 30{ 31 _cleanup_test_img 32 rm -f $TEST_IMG.data 33} 34trap "_cleanup; exit \$status" 0 1 2 3 15 35 36# get standard environment, filters and checks 37. ./common.rc 38. ./common.filter 39 40# This tests qcow2-specific low-level functionality 41_supported_fmt qcow2 42_supported_proto file 43_supported_os Linux 44# Conversion between different compat versions can only really work 45# with refcount_bits=16 46_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' 47 48echo 49echo "=== Testing version downgrade with zero expansion ===" 50echo 51_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M 52$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 53$PYTHON qcow2.py "$TEST_IMG" dump-header 54$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 55$PYTHON qcow2.py "$TEST_IMG" dump-header 56$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 57_check_test_img 58 59echo 60echo "=== Testing version downgrade with zero expansion and 4K cache entries ===" 61echo 62_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M 63$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 64$QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io 65$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io 66$PYTHON qcow2.py "$TEST_IMG" dump-header 67$QEMU_IMG amend -o "compat=0.10" --image-opts \ 68 driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096 69$PYTHON qcow2.py "$TEST_IMG" dump-header 70$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 71$QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io 72$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io 73_check_test_img 74 75echo 76echo "=== Testing dirty version downgrade ===" 77echo 78_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M 79_NO_VALGRIND \ 80$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 81 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 82$PYTHON qcow2.py "$TEST_IMG" dump-header 83$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 84$PYTHON qcow2.py "$TEST_IMG" dump-header 85$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 86_check_test_img 87 88echo 89echo "=== Testing version downgrade with unknown compat/autoclear flags ===" 90echo 91_make_test_img -o "compat=1.1" 64M 92$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42 93$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42 94$PYTHON qcow2.py "$TEST_IMG" dump-header 95$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 96$PYTHON qcow2.py "$TEST_IMG" dump-header 97_check_test_img 98 99echo 100echo "=== Testing version upgrade and resize ===" 101echo 102_make_test_img -o "compat=0.10" 64M 103$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 104$PYTHON qcow2.py "$TEST_IMG" dump-header 105$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG" 106$PYTHON qcow2.py "$TEST_IMG" dump-header 107$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 108_check_test_img 109 110echo 111echo "=== Testing dirty lazy_refcounts=off ===" 112echo 113_make_test_img -o "compat=1.1,lazy_refcounts=on" 64M 114_NO_VALGRIND \ 115$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 116 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 117$PYTHON qcow2.py "$TEST_IMG" dump-header 118$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 119$PYTHON qcow2.py "$TEST_IMG" dump-header 120$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 121_check_test_img 122 123echo 124echo "=== Testing backing file ===" 125echo 126_make_test_img -o "compat=1.1" 64M 127TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M 128$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 129$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 130$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 131$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 132_check_test_img 133 134echo 135echo "=== Testing invalid configurations ===" 136echo 137_make_test_img -o "compat=0.10" 64M 138$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 139$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 140$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 141$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 142$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 143$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 144$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 145$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 146 147echo 148echo "=== Testing correct handling of unset value ===" 149echo 150_make_test_img -o "compat=1.1,cluster_size=1k" 64M 151echo "Should work:" 152$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 153echo "Should not work:" # Just to know which of these tests actually fails 154$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 155 156echo 157echo "=== Testing zero expansion on inactive clusters ===" 158echo 159_make_test_img -o "compat=1.1" 64M 160$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 161$QEMU_IMG snapshot -c foo "$TEST_IMG" 162$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 163$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 164_check_test_img 165$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 166$QEMU_IMG snapshot -a foo "$TEST_IMG" 167_check_test_img 168$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 169 170echo 171echo "=== Testing zero expansion on shared L2 table ===" 172echo 173_make_test_img -o "compat=1.1" 64M 174$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 175$QEMU_IMG snapshot -c foo "$TEST_IMG" 176$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 177_check_test_img 178$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 179$QEMU_IMG snapshot -a foo "$TEST_IMG" 180_check_test_img 181$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 182 183echo 184echo "=== Testing zero expansion on backed image ===" 185echo 186TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M 187$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 188_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M 189$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 190$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 191_check_test_img 192$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 193 194echo 195echo "=== Testing zero expansion on backed inactive clusters ===" 196echo 197TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M 198$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 199_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M 200$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 201$QEMU_IMG snapshot -c foo "$TEST_IMG" 202$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 203$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 204_check_test_img 205$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 206$QEMU_IMG snapshot -a foo "$TEST_IMG" 207_check_test_img 208$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 209 210echo 211echo "=== Testing zero expansion on backed image with shared L2 table ===" 212echo 213TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 64M 214$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 215_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 64M 216$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 217$QEMU_IMG snapshot -c foo "$TEST_IMG" 218$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 219_check_test_img 220$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 221$QEMU_IMG snapshot -a foo "$TEST_IMG" 222_check_test_img 223$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 224 225echo 226echo "=== Testing preallocated zero expansion on full image ===" 227echo 228TEST_IMG="$TEST_IMG" _make_test_img -o "compat=1.1" 64M 229$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 230$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 231_check_test_img 232$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 233 234echo 235echo "=== Testing progress report without snapshot ===" 236echo 237TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G 238_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G 239$QEMU_IO -c "write -z 0 64k" \ 240 -c "write -z 1G 64k" \ 241 -c "write -z 2G 64k" \ 242 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 243$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 244_check_test_img 245 246echo 247echo "=== Testing progress report with snapshot ===" 248echo 249TEST_IMG="$TEST_IMG.base" _make_test_img -o "compat=1.1" 4G 250_make_test_img -o "compat=1.1" -b "$TEST_IMG.base" 4G 251$QEMU_IO -c "write -z 0 64k" \ 252 -c "write -z 1G 64k" \ 253 -c "write -z 2G 64k" \ 254 -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 255$QEMU_IMG snapshot -c foo "$TEST_IMG" 256$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 257_check_test_img 258 259echo 260echo "=== Testing version downgrade with external data file ===" 261echo 262_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M 263$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 264_img_info --format-specific 265_check_test_img 266 267echo 268echo "=== Try changing the external data file ===" 269echo 270_make_test_img -o "compat=1.1" 64M 271$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG" 272 273echo 274_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data" 64M 275$QEMU_IMG amend -o "data_file=foo" "$TEST_IMG" 276_img_info --format-specific 277TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts 278 279echo 280$QEMU_IMG amend -o "data_file=" --image-opts "data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" 281_img_info --format-specific 282TEST_IMG="data-file.filename=$TEST_IMG.data,file.filename=$TEST_IMG" _img_info --format-specific --image-opts 283 284echo 285echo "=== Clearing and setting data-file-raw ===" 286echo 287_make_test_img -o "compat=1.1,data_file=$TEST_IMG.data,data_file_raw=on" 64M 288$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG" 289_img_info --format-specific 290_check_test_img 291 292$QEMU_IMG amend -o "data_file_raw=off" "$TEST_IMG" 293_img_info --format-specific 294_check_test_img 295 296$QEMU_IMG amend -o "data_file_raw=on" "$TEST_IMG" 297_img_info --format-specific 298_check_test_img 299 300 301# success, all done 302echo "*** done" 303rm -f $seq.full 304status=0 305