111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2c5f6e493SKevin Wolf# 3c5f6e493SKevin Wolf# Test invalid backing file format in qcow2 images 4c5f6e493SKevin Wolf# 5c5f6e493SKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 6c5f6e493SKevin Wolf# 7c5f6e493SKevin Wolf# This program is free software; you can redistribute it and/or modify 8c5f6e493SKevin Wolf# it under the terms of the GNU General Public License as published by 9c5f6e493SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10c5f6e493SKevin Wolf# (at your option) any later version. 11c5f6e493SKevin Wolf# 12c5f6e493SKevin Wolf# This program is distributed in the hope that it will be useful, 13c5f6e493SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14c5f6e493SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c5f6e493SKevin Wolf# GNU General Public License for more details. 16c5f6e493SKevin Wolf# 17c5f6e493SKevin Wolf# You should have received a copy of the GNU General Public License 18c5f6e493SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19c5f6e493SKevin Wolf# 20c5f6e493SKevin Wolf 21c5f6e493SKevin Wolf# creator 22c5f6e493SKevin Wolfowner=kwolf@redhat.com 23c5f6e493SKevin Wolf 24c5f6e493SKevin Wolfseq="$(basename $0)" 25c5f6e493SKevin Wolfecho "QA output created by $seq" 26c5f6e493SKevin Wolf 27c5f6e493SKevin Wolfstatus=1 # failure is the default! 28c5f6e493SKevin Wolf 29c5f6e493SKevin Wolf_cleanup() 30c5f6e493SKevin Wolf{ 31c5f6e493SKevin Wolf _cleanup_test_img 32c5f6e493SKevin Wolf} 33c5f6e493SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 34c5f6e493SKevin Wolf 35c5f6e493SKevin Wolf# get standard environment, filters and checks 36c5f6e493SKevin Wolf. ./common.rc 37c5f6e493SKevin Wolf. ./common.filter 38c5f6e493SKevin Wolf 39c5f6e493SKevin Wolf_supported_fmt qcow2 40c5f6e493SKevin Wolf_supported_proto generic 41a98f49f4SJeff Cody_unsupported_proto vxhs 42*d9f059aaSEric Blake# At least OpenBSD doesn't seem to have truncate 43*d9f059aaSEric Blake_supported_os Linux 443be2024aSMax Reitz# qcow2.py does not work too well with external data files 453be2024aSMax Reitz_unsupported_imgopts data_file 46c5f6e493SKevin Wolf 47*d9f059aaSEric Blake# Intentionally specify backing file without backing format; demonstrate 48*d9f059aaSEric Blake# the difference in warning messages when backing file could be probed. 49*d9f059aaSEric Blake# Note that only a non-raw probe result will affect the resulting image. 50*d9f059aaSEric Blaketruncate -s $((64 * 1024 * 1024)) "$TEST_IMG.orig" 51*d9f059aaSEric Blake_make_test_img -b "$TEST_IMG.orig" 64M 52c5f6e493SKevin Wolf 53c5f6e493SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img 64M 54*d9f059aaSEric Blake$QEMU_IMG convert -O qcow2 -B "$TEST_IMG.orig" "$TEST_IMG.orig" "$TEST_IMG" 55c5f6e493SKevin Wolf_make_test_img -b "$TEST_IMG.base" 64M 56*d9f059aaSEric Blake_make_test_img -u -b "$TEST_IMG.base" 64M 57c5f6e493SKevin Wolf 58c5f6e493SKevin Wolf# Set an invalid backing file format 59c5f6e493SKevin Wolf$PYTHON qcow2.py "$TEST_IMG" add-header-ext 0xE2792ACA "foo" 60c5f6e493SKevin Wolf_img_info 61c5f6e493SKevin Wolf 62c5f6e493SKevin Wolf# Try opening the image. Should fail (and not probe) in the first case, but 63c5f6e493SKevin Wolf# overriding the backing file format should be possible. 64c5f6e493SKevin Wolf$QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filter_testdir 65c5f6e493SKevin Wolf$QEMU_IO -c "open -o backing.driver=$IMGFMT $TEST_IMG" -c "read 0 4k" | _filter_qemu_io 66c5f6e493SKevin Wolf 67*d9f059aaSEric Blake# Rebase the image, to show that omitting backing format triggers a warning, 68*d9f059aaSEric Blake# but probing now lets us use the backing file. 69*d9f059aaSEric Blake$QEMU_IMG rebase -u -b "$TEST_IMG.base" "$TEST_IMG" 70*d9f059aaSEric Blake$QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filter_testdir 71*d9f059aaSEric Blake 72c5f6e493SKevin Wolf# success, all done 73c5f6e493SKevin Wolfecho '*** done' 74c5f6e493SKevin Wolfrm -f $seq.full 75c5f6e493SKevin Wolfstatus=0 76