1a8110c3dSMax Reitz#!/bin/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 Reitzhere=`pwd` 28a8110c3dSMax Reitztmp=/tmp/$$ 29a8110c3dSMax Reitzstatus=1 # failure is the default! 30a8110c3dSMax Reitz 31a8110c3dSMax Reitz_cleanup() 32a8110c3dSMax Reitz{ 33a8110c3dSMax Reitz _cleanup_test_img 34a8110c3dSMax Reitz} 35a8110c3dSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 36a8110c3dSMax Reitz 37a8110c3dSMax Reitz# get standard environment, filters and checks 38a8110c3dSMax Reitz. ./common.rc 39a8110c3dSMax Reitz. ./common.filter 40a8110c3dSMax Reitz 41a8110c3dSMax Reitz# This tests qocw2-specific low-level functionality 42a8110c3dSMax Reitz_supported_fmt qcow2 431f7bf7d0SPeter Lieven_supported_proto file 44a8110c3dSMax Reitz_supported_os Linux 45a8110c3dSMax Reitz 46a8110c3dSMax Reitzecho 47a8110c3dSMax Reitzecho "=== Testing version downgrade with zero expansion ===" 48a8110c3dSMax Reitzecho 49a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 50a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 51ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 52a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 53ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 54a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 55a8110c3dSMax Reitz_check_test_img 56a8110c3dSMax Reitz 57a8110c3dSMax Reitzecho 58a8110c3dSMax Reitzecho "=== Testing dirty version downgrade ===" 59a8110c3dSMax Reitzecho 60a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 61*efd0fbbcSAlberto Garcia$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 62*efd0fbbcSAlberto Garcia -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 63ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 64a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 65ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 66a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 67a8110c3dSMax Reitz_check_test_img 68a8110c3dSMax Reitz 69a8110c3dSMax Reitzecho 70a8110c3dSMax Reitzecho "=== Testing version downgrade with unknown compat/autoclear flags ===" 71a8110c3dSMax Reitzecho 72a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 73ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" set-feature-bit compatible 42 74ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" set-feature-bit autoclear 42 75ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 76a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 77ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 78a8110c3dSMax Reitz_check_test_img 79a8110c3dSMax Reitz 80a8110c3dSMax Reitzecho 81a8110c3dSMax Reitzecho "=== Testing version upgrade and resize ===" 82a8110c3dSMax Reitzecho 83a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 84a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 85ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 86a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG" 87ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 88a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 89a8110c3dSMax Reitz_check_test_img 90a8110c3dSMax Reitz 91a8110c3dSMax Reitzecho 92a8110c3dSMax Reitzecho "=== Testing dirty lazy_refcounts=off ===" 93a8110c3dSMax Reitzecho 94a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 95*efd0fbbcSAlberto Garcia$QEMU_IO -c "write -P 0x2a 0 128k" -c flush \ 96*efd0fbbcSAlberto Garcia -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 | _filter_qemu_io 97ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 98a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 99ea81ca9dSMax Reitz$PYTHON qcow2.py "$TEST_IMG" dump-header 100a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 101a8110c3dSMax Reitz_check_test_img 102a8110c3dSMax Reitz 103a8110c3dSMax Reitzecho 104a8110c3dSMax Reitzecho "=== Testing backing file ===" 105a8110c3dSMax Reitzecho 106a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 107a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 108a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 109a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 110a8110c3dSMax Reitz$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 111a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 112a8110c3dSMax Reitz_check_test_img 113a8110c3dSMax Reitz 114a8110c3dSMax Reitzecho 115a8110c3dSMax Reitzecho "=== Testing invalid configurations ===" 116a8110c3dSMax Reitzecho 117a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 118a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 119a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 120a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 121a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 122a8110c3dSMax Reitz$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 123a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 124a8110c3dSMax Reitz$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 125a8110c3dSMax Reitz$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 126a8110c3dSMax Reitz 127a8110c3dSMax Reitzecho 128a8110c3dSMax Reitzecho "=== Testing correct handling of unset value ===" 129a8110c3dSMax Reitzecho 130a8110c3dSMax ReitzIMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M 131a8110c3dSMax Reitzecho "Should work:" 132a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 133a8110c3dSMax Reitzecho "Should not work:" # Just to know which of these tests actually fails 134a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 135a8110c3dSMax Reitz 136a8110c3dSMax Reitzecho 137a8110c3dSMax Reitzecho "=== Testing zero expansion on inactive clusters ===" 138a8110c3dSMax Reitzecho 139a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 140a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 141a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 142a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 143a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 144a8110c3dSMax Reitz_check_test_img 145a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 146a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 147a8110c3dSMax Reitz_check_test_img 148a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 149a8110c3dSMax Reitz 150a8110c3dSMax Reitzecho 151d982919dSMax Reitzecho "=== Testing zero expansion on shared L2 table ===" 152d982919dSMax Reitzecho 153d982919dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 154d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 155d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 156d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 157d982919dSMax Reitz_check_test_img 158d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 159d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 160d982919dSMax Reitz_check_test_img 161d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 162d982919dSMax Reitz 163d982919dSMax Reitzecho 164a8110c3dSMax Reitzecho "=== Testing zero expansion on backed image ===" 165a8110c3dSMax Reitzecho 166a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 167a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 168db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 169a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 170a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 171a8110c3dSMax Reitz_check_test_img 172a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 173a8110c3dSMax Reitz 174a8110c3dSMax Reitzecho 175a8110c3dSMax Reitzecho "=== Testing zero expansion on backed inactive clusters ===" 176a8110c3dSMax Reitzecho 177a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 178a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 179db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 180a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 181a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 182a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 183a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 184a8110c3dSMax Reitz_check_test_img 185a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 186a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 187a8110c3dSMax Reitz_check_test_img 188a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 189a8110c3dSMax Reitz 190d982919dSMax Reitzecho 191d982919dSMax Reitzecho "=== Testing zero expansion on backed image with shared L2 table ===" 192d982919dSMax Reitzecho 193d982919dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 194d982919dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 195db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 196d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 197d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 198d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 199d982919dSMax Reitz_check_test_img 200d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 201d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 202d982919dSMax Reitz_check_test_img 203d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 204d982919dSMax Reitz 205fd9e03e6SMax Reitzecho 206fd9e03e6SMax Reitzecho "=== Testing preallocated zero expansion on full image ===" 207fd9e03e6SMax Reitzecho 208fd9e03e6SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M 209fd9e03e6SMax Reitz$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 210fd9e03e6SMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 211fd9e03e6SMax Reitz_check_test_img 212fd9e03e6SMax Reitz$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 213fd9e03e6SMax Reitz 21478fa6582SMax Reitzecho 21578fa6582SMax Reitzecho "=== Testing progress report without snapshot ===" 21678fa6582SMax Reitzecho 21778fa6582SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 21878fa6582SMax ReitzIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 21978fa6582SMax Reitz$QEMU_IO -c "write -z 0 64k" \ 22078fa6582SMax Reitz -c "write -z 1G 64k" \ 22178fa6582SMax Reitz -c "write -z 2G 64k" \ 22278fa6582SMax Reitz -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 22378fa6582SMax Reitz$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 22478fa6582SMax Reitz_check_test_img 22578fa6582SMax Reitz 22678fa6582SMax Reitzecho 22778fa6582SMax Reitzecho "=== Testing progress report with snapshot ===" 22878fa6582SMax Reitzecho 22978fa6582SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 4G 23078fa6582SMax ReitzIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 4G 23178fa6582SMax Reitz$QEMU_IO -c "write -z 0 64k" \ 23278fa6582SMax Reitz -c "write -z 1G 64k" \ 23378fa6582SMax Reitz -c "write -z 2G 64k" \ 23478fa6582SMax Reitz -c "write -z 3G 64k" "$TEST_IMG" | _filter_qemu_io 23578fa6582SMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 23678fa6582SMax Reitz$QEMU_IMG amend -p -o "compat=0.10" "$TEST_IMG" 23778fa6582SMax Reitz_check_test_img 23878fa6582SMax Reitz 239a8110c3dSMax Reitz# success, all done 240a8110c3dSMax Reitzecho "*** done" 241a8110c3dSMax Reitzrm -f $seq.full 242a8110c3dSMax Reitzstatus=0 243