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 43*1f7bf7d0SPeter 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 51a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 52a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 53a8110c3dSMax Reitz./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 61a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io 62a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 63a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 64a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 65a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 66a8110c3dSMax Reitz_check_test_img 67a8110c3dSMax Reitz 68a8110c3dSMax Reitzecho 69a8110c3dSMax Reitzecho "=== Testing version downgrade with unknown compat/autoclear flags ===" 70a8110c3dSMax Reitzecho 71a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 72a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" set-feature-bit compatible 42 73a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" set-feature-bit autoclear 42 74a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 75a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 76a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 77a8110c3dSMax Reitz_check_test_img 78a8110c3dSMax Reitz 79a8110c3dSMax Reitzecho 80a8110c3dSMax Reitzecho "=== Testing version upgrade and resize ===" 81a8110c3dSMax Reitzecho 82a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 83a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 84a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 85a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1,lazy_refcounts=on,size=128M" "$TEST_IMG" 86a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 87a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 42M 64k" "$TEST_IMG" | _filter_qemu_io 88a8110c3dSMax Reitz_check_test_img 89a8110c3dSMax Reitz 90a8110c3dSMax Reitzecho 91a8110c3dSMax Reitzecho "=== Testing dirty lazy_refcounts=off ===" 92a8110c3dSMax Reitzecho 93a8110c3dSMax ReitzIMGOPTS="compat=1.1,lazy_refcounts=on" _make_test_img 64M 94a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" -c flush -c abort "$TEST_IMG" | _filter_qemu_io 95a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 96a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=off" "$TEST_IMG" 97a8110c3dSMax Reitz./qcow2.py "$TEST_IMG" dump-header 98a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 99a8110c3dSMax Reitz_check_test_img 100a8110c3dSMax Reitz 101a8110c3dSMax Reitzecho 102a8110c3dSMax Reitzecho "=== Testing backing file ===" 103a8110c3dSMax Reitzecho 104a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 105a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 106a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 107a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 108a8110c3dSMax Reitz$QEMU_IMG amend -o "backing_file=$TEST_IMG.base,backing_fmt=qcow2" "$TEST_IMG" 109a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 110a8110c3dSMax Reitz_check_test_img 111a8110c3dSMax Reitz 112a8110c3dSMax Reitzecho 113a8110c3dSMax Reitzecho "=== Testing invalid configurations ===" 114a8110c3dSMax Reitzecho 115a8110c3dSMax ReitzIMGOPTS="compat=0.10" _make_test_img 64M 116a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 117a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=1.1" "$TEST_IMG" # actually valid 118a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10,lazy_refcounts=on" "$TEST_IMG" 119a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.42" "$TEST_IMG" 120a8110c3dSMax Reitz$QEMU_IMG amend -o "foo=bar" "$TEST_IMG" 121a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=1k" "$TEST_IMG" 122a8110c3dSMax Reitz$QEMU_IMG amend -o "encryption=on" "$TEST_IMG" 123a8110c3dSMax Reitz$QEMU_IMG amend -o "preallocation=on" "$TEST_IMG" 124a8110c3dSMax Reitz 125a8110c3dSMax Reitzecho 126a8110c3dSMax Reitzecho "=== Testing correct handling of unset value ===" 127a8110c3dSMax Reitzecho 128a8110c3dSMax ReitzIMGOPTS="compat=1.1,cluster_size=1k" _make_test_img 64M 129a8110c3dSMax Reitzecho "Should work:" 130a8110c3dSMax Reitz$QEMU_IMG amend -o "lazy_refcounts=on" "$TEST_IMG" 131a8110c3dSMax Reitzecho "Should not work:" # Just to know which of these tests actually fails 132a8110c3dSMax Reitz$QEMU_IMG amend -o "cluster_size=64k" "$TEST_IMG" 133a8110c3dSMax Reitz 134a8110c3dSMax Reitzecho 135a8110c3dSMax Reitzecho "=== Testing zero expansion on inactive clusters ===" 136a8110c3dSMax Reitzecho 137a8110c3dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 138a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 139a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 140a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 141a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 142a8110c3dSMax Reitz_check_test_img 143a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" "$TEST_IMG" | _filter_qemu_io 144a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 145a8110c3dSMax Reitz_check_test_img 146a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 147a8110c3dSMax Reitz 148a8110c3dSMax Reitzecho 149d982919dSMax Reitzecho "=== Testing zero expansion on shared L2 table ===" 150d982919dSMax Reitzecho 151d982919dSMax ReitzIMGOPTS="compat=1.1" _make_test_img 64M 152d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 153d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 154d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 155d982919dSMax Reitz_check_test_img 156d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 157d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 158d982919dSMax Reitz_check_test_img 159d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 160d982919dSMax Reitz 161d982919dSMax Reitzecho 162a8110c3dSMax Reitzecho "=== Testing zero expansion on backed image ===" 163a8110c3dSMax Reitzecho 164a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 165a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 166db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 167a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x2a 0 128k" -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 168a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 169a8110c3dSMax Reitz_check_test_img 170a8110c3dSMax Reitz$QEMU_IO -c "read -P 0 0 64k" -c "read -P 0x2a 64k 64k" "$TEST_IMG" | _filter_qemu_io 171a8110c3dSMax Reitz 172a8110c3dSMax Reitzecho 173a8110c3dSMax Reitzecho "=== Testing zero expansion on backed inactive clusters ===" 174a8110c3dSMax Reitzecho 175a8110c3dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 176a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x2a 0 128k" "$TEST_IMG.base" | _filter_qemu_io 177db5dc557SJeff CodyIMGOPTS="compat=1.1" _make_test_img -b "$TEST_IMG.base" 64M 178a8110c3dSMax Reitz$QEMU_IO -c "write -z 0 64k" "$TEST_IMG" | _filter_qemu_io 179a8110c3dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 180a8110c3dSMax Reitz$QEMU_IO -c "write -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 181a8110c3dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 182a8110c3dSMax Reitz_check_test_img 183a8110c3dSMax Reitz$QEMU_IO -c "read -P 0x42 0 128k" "$TEST_IMG" | _filter_qemu_io 184a8110c3dSMax Reitz$QEMU_IMG snapshot -a foo "$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 188d982919dSMax Reitzecho 189d982919dSMax Reitzecho "=== Testing zero expansion on backed image with shared L2 table ===" 190d982919dSMax Reitzecho 191d982919dSMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG.base" _make_test_img 64M 192d982919dSMax 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 194d982919dSMax Reitz$QEMU_IO -c "write -z 0 128k" "$TEST_IMG" | _filter_qemu_io 195d982919dSMax Reitz$QEMU_IMG snapshot -c foo "$TEST_IMG" 196d982919dSMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 197d982919dSMax Reitz_check_test_img 198d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 199d982919dSMax Reitz$QEMU_IMG snapshot -a foo "$TEST_IMG" 200d982919dSMax Reitz_check_test_img 201d982919dSMax Reitz$QEMU_IO -c "read -P 0 0 128k" "$TEST_IMG" | _filter_qemu_io 202d982919dSMax Reitz 203fd9e03e6SMax Reitzecho 204fd9e03e6SMax Reitzecho "=== Testing preallocated zero expansion on full image ===" 205fd9e03e6SMax Reitzecho 206fd9e03e6SMax ReitzIMGOPTS="compat=1.1" TEST_IMG="$TEST_IMG" _make_test_img 64M 207fd9e03e6SMax Reitz$QEMU_IO -c "write -P 0x2a 0 64M" "$TEST_IMG" -c "write -z 0 64M" | _filter_qemu_io 208fd9e03e6SMax Reitz$QEMU_IMG amend -o "compat=0.10" "$TEST_IMG" 209fd9e03e6SMax Reitz_check_test_img 210fd9e03e6SMax Reitz$QEMU_IO -c "read -P 0 0 64M" "$TEST_IMG" | _filter_qemu_io 211fd9e03e6SMax Reitz 212a8110c3dSMax Reitz# success, all done 213a8110c3dSMax Reitzecho "*** done" 214a8110c3dSMax Reitzrm -f $seq.full 215a8110c3dSMax Reitzstatus=0 216