1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2a8110c3dSMax Reitz# 3a8110c3dSMax Reitz# Test case for image option amendment in qcow2. 4a8110c3dSMax Reitz# 5a8110c3dSMax Reitz# Copyright (C) 2013 Red Hat, Inc. 6a8110c3dSMax Reitz# 7a8110c3dSMax Reitz# This program is free software; you can redistribute it and/or modify 8a8110c3dSMax Reitz# it under the terms of the GNU General Public License as published by 9a8110c3dSMax Reitz# the Free Software Foundation; either version 2 of the License, or 10a8110c3dSMax Reitz# (at your option) any later version. 11a8110c3dSMax Reitz# 12a8110c3dSMax Reitz# This program is distributed in the hope that it will be useful, 13a8110c3dSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14a8110c3dSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a8110c3dSMax Reitz# GNU General Public License for more details. 16a8110c3dSMax Reitz# 17a8110c3dSMax Reitz# You should have received a copy of the GNU General Public License 18a8110c3dSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19a8110c3dSMax Reitz# 20a8110c3dSMax Reitz 21a8110c3dSMax Reitz# creator 22a8110c3dSMax Reitzowner=mreitz@redhat.com 23a8110c3dSMax Reitz 24a8110c3dSMax Reitzseq=`basename $0` 25a8110c3dSMax Reitzecho "QA output created by $seq" 26a8110c3dSMax Reitz 27a8110c3dSMax Reitzstatus=1 # failure is the default! 28a8110c3dSMax Reitz 29a8110c3dSMax Reitz_cleanup() 30a8110c3dSMax Reitz{ 31a8110c3dSMax Reitz _cleanup_test_img 32a8110c3dSMax Reitz} 33a8110c3dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 34a8110c3dSMax Reitz 35a8110c3dSMax Reitz# get standard environment, filters and checks 36a8110c3dSMax Reitz. ./common.rc 37a8110c3dSMax Reitz. ./common.filter 38a8110c3dSMax Reitz 39a8110c3dSMax Reitz# This tests qocw2-specific low-level functionality 40a8110c3dSMax Reitz_supported_fmt qcow2 411f7bf7d0SPeter Lieven_supported_proto file 42a8110c3dSMax Reitz_supported_os Linux 43a8110c3dSMax Reitz 44a8110c3dSMax Reitzecho 45a8110c3dSMax Reitzecho "=== Testing version downgrade with zero expansion ===" 46a8110c3dSMax Reitzecho 47a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 48a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 49ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 50a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 51ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 52a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 53a8110c3dSMax Reitz_check_test_img 54a8110c3dSMax Reitz 55a8110c3dSMax Reitzecho 562ecec911SAlberto Garciaecho "=== Testing version downgrade with zero expansion and 4K cache entries ===" 572ecec911SAlberto Garciaecho 582ecec911SAlberto GarciaIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 592ecec911SAlberto Garcia$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 602ecec911SAlberto Garcia$QEMU_IO -c "write -z 32M 128k" "$TEST_IMG" | _filter_qemu_io 612ecec911SAlberto Garcia$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io 622ecec911SAlberto Garcia$PYTHON qcow2.py "$TEST_IMG" dump-header 632ecec911SAlberto Garcia$QEMU_IMG amend -o "compat=0.10" --image-opts \ 642ecec911SAlberto Garcia driver=qcow2,file.filename=$TEST_IMG,l2-cache-entry-size=4096 652ecec911SAlberto Garcia$PYTHON qcow2.py "$TEST_IMG" dump-header 662ecec911SAlberto Garcia$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 672ecec911SAlberto Garcia$QEMU_IO -c "read -P 0 32M 128k" "$TEST_IMG" | _filter_qemu_io 682ecec911SAlberto Garcia$QEMU_IO -c map "$TEST_IMG" | _filter_qemu_io 692ecec911SAlberto Garcia_check_test_img 702ecec911SAlberto Garcia 712ecec911SAlberto Garciaecho 72a8110c3dSMax Reitzecho "=== Testing dirty version downgrade ===" 73a8110c3dSMax Reitzecho 74a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 75efd0fbbcSAlberto Garcia$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 76efd0fbbcSAlberto Garcia -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 77ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 78a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 79ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 80a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 81a8110c3dSMax Reitz_check_test_img 82a8110c3dSMax Reitz 83a8110c3dSMax Reitzecho 84a8110c3dSMax Reitzecho "=== Testing version downgrade with unknown compat/autoclear flags ===" 85a8110c3dSMax Reitzecho 86a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 87ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42 88ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42 89ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 90a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 91ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 92a8110c3dSMax Reitz_check_test_img 93a8110c3dSMax Reitz 94a8110c3dSMax Reitzecho 95a8110c3dSMax Reitzecho "=== Testing version upgrade and resize ===" 96a8110c3dSMax Reitzecho 97a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 98a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 99ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 100a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG" 101ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 102a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 103a8110c3dSMax Reitz_check_test_img 104a8110c3dSMax Reitz 105a8110c3dSMax Reitzecho 106a8110c3dSMax Reitzecho "=== Testing dirty lazy_refcounts=off ===" 107a8110c3dSMax Reitzecho 108a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 109efd0fbbcSAlberto Garcia$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 110efd0fbbcSAlberto Garcia -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 111ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 112a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 113ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 114a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 115a8110c3dSMax Reitz_check_test_img 116a8110c3dSMax Reitz 117a8110c3dSMax Reitzecho 118a8110c3dSMax Reitzecho "=== Testing backing file ===" 119a8110c3dSMax Reitzecho 120a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 121a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 122a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 123a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 124a8110c3dSMax Reitz$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 125a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 126a8110c3dSMax Reitz_check_test_img 127a8110c3dSMax Reitz 128a8110c3dSMax Reitzecho 129a8110c3dSMax Reitzecho "=== Testing invalid configurations ===" 130a8110c3dSMax Reitzecho 131a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 132a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 133a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 134a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 135a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 136a8110c3dSMax Reitz$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 137a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 138a8110c3dSMax Reitz$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 139a8110c3dSMax Reitz$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 140a8110c3dSMax Reitz 141a8110c3dSMax Reitzecho 142a8110c3dSMax Reitzecho "=== Testing correct handling of unset value ===" 143a8110c3dSMax Reitzecho 144a8110c3dSMax ReitzIMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M 145a8110c3dSMax Reitzecho "Should work:" 146a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 147a8110c3dSMax Reitzecho "Should not work:" # Just to know which of these tests actually fails 148a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 149a8110c3dSMax Reitz 150a8110c3dSMax Reitzecho 151a8110c3dSMax Reitzecho "=== Testing zero expansion on inactive clusters ===" 152a8110c3dSMax Reitzecho 153a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 154a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 155a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 156a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 157a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 158a8110c3dSMax Reitz_check_test_img 159a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 160a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 161a8110c3dSMax Reitz_check_test_img 162a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 163a8110c3dSMax Reitz 164a8110c3dSMax Reitzecho 165d982919dSMax Reitzecho "=== Testing zero expansion on shared L2 table ===" 166d982919dSMax Reitzecho 167d982919dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 168d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 169d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 170d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 171d982919dSMax Reitz_check_test_img 172d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 173d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 174d982919dSMax Reitz_check_test_img 175d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 176d982919dSMax Reitz 177d982919dSMax Reitzecho 178a8110c3dSMax Reitzecho "=== Testing zero expansion on backed image ===" 179a8110c3dSMax Reitzecho 180a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 181a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 182db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 183a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 184a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 185a8110c3dSMax Reitz_check_test_img 186a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 187a8110c3dSMax Reitz 188a8110c3dSMax Reitzecho 189a8110c3dSMax Reitzecho "=== Testing zero expansion on backed inactive clusters ===" 190a8110c3dSMax Reitzecho 191a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 192a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 193db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 194a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 195a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 196a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 197a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 198a8110c3dSMax Reitz_check_test_img 199a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 200a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 201a8110c3dSMax Reitz_check_test_img 202a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 203a8110c3dSMax Reitz 204d982919dSMax Reitzecho 205d982919dSMax Reitzecho "=== Testing zero expansion on backed image with shared L2 table ===" 206d982919dSMax Reitzecho 207d982919dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 208d982919dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 209db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 210d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 211d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 212d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 213d982919dSMax Reitz_check_test_img 214d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 215d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 216d982919dSMax Reitz_check_test_img 217d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 218d982919dSMax Reitz 219fd9e03e6SMax Reitzecho 220fd9e03e6SMax Reitzecho "=== Testing preallocated zero expansion on full image ===" 221fd9e03e6SMax Reitzecho 222fd9e03e6SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M 223fd9e03e6SMax Reitz$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 224fd9e03e6SMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 225fd9e03e6SMax Reitz_check_test_img 226fd9e03e6SMax Reitz$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 227fd9e03e6SMax Reitz 22878fa6582SMax Reitzecho 22978fa6582SMax Reitzecho "=== Testing progress report without snapshot ===" 23078fa6582SMax Reitzecho 23178fa6582SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 23278fa6582SMax ReitzIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 23378fa6582SMax Reitz$QEMU_IO -c "write -z 0 64k" \ 23478fa6582SMax Reitz -c "write -z 1G 64k" \ 23578fa6582SMax Reitz -c "write -z 2G 64k" \ 23678fa6582SMax Reitz -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 23778fa6582SMax Reitz$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 23878fa6582SMax Reitz_check_test_img 23978fa6582SMax Reitz 24078fa6582SMax Reitzecho 24178fa6582SMax Reitzecho "=== Testing progress report with snapshot ===" 24278fa6582SMax Reitzecho 24378fa6582SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 24478fa6582SMax ReitzIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 24578fa6582SMax Reitz$QEMU_IO -c "write -z 0 64k" \ 24678fa6582SMax Reitz -c "write -z 1G 64k" \ 24778fa6582SMax Reitz -c "write -z 2G 64k" \ 24878fa6582SMax Reitz -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 24978fa6582SMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 25078fa6582SMax Reitz$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 25178fa6582SMax Reitz_check_test_img 25278fa6582SMax Reitz 253a8110c3dSMax Reitz# success, all done 254a8110c3dSMax Reitzecho "*** done" 255a8110c3dSMax Reitzrm -f $seq.full 256a8110c3dSMax Reitzstatus=0 257