111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3c5f6e493SKevin Wolf# 4c5f6e493SKevin Wolf# Test invalid backing file format in qcow2 images 5c5f6e493SKevin Wolf# 6c5f6e493SKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 7c5f6e493SKevin Wolf# 8c5f6e493SKevin Wolf# This program is free software; you can redistribute it and/or modify 9c5f6e493SKevin Wolf# it under the terms of the GNU General Public License as published by 10c5f6e493SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11c5f6e493SKevin Wolf# (at your option) any later version. 12c5f6e493SKevin Wolf# 13c5f6e493SKevin Wolf# This program is distributed in the hope that it will be useful, 14c5f6e493SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c5f6e493SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c5f6e493SKevin Wolf# GNU General Public License for more details. 17c5f6e493SKevin Wolf# 18c5f6e493SKevin Wolf# You should have received a copy of the GNU General Public License 19c5f6e493SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c5f6e493SKevin Wolf# 21c5f6e493SKevin Wolf 22c5f6e493SKevin Wolf# creator 23c5f6e493SKevin Wolfowner=kwolf@redhat.com 24c5f6e493SKevin Wolf 25c5f6e493SKevin Wolfseq="$(basename $0)" 26c5f6e493SKevin Wolfecho "QA output created by $seq" 27c5f6e493SKevin Wolf 28c5f6e493SKevin Wolfstatus=1 # failure is the default! 29c5f6e493SKevin Wolf 30c5f6e493SKevin Wolf_cleanup() 31c5f6e493SKevin Wolf{ 32c5f6e493SKevin Wolf _cleanup_test_img 33c5f6e493SKevin Wolf} 34c5f6e493SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 35c5f6e493SKevin Wolf 36c5f6e493SKevin Wolf# get standard environment, filters and checks 37c5f6e493SKevin Wolf. ./common.rc 38c5f6e493SKevin Wolf. ./common.filter 39c5f6e493SKevin Wolf 40c5f6e493SKevin Wolf_supported_fmt qcow2 41c5f6e493SKevin Wolf_supported_proto generic 42d9f059aaSEric Blake# At least OpenBSD doesn't seem to have truncate 43d9f059aaSEric 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*497a30dbSEric Blake# Older qemu-img could set up backing file without backing format; modern 48*497a30dbSEric Blake# qemu can't but we can use qcow2.py to simulate older files. 49d9f059aaSEric Blaketruncate -s $((64 * 1024 * 1024)) "$TEST_IMG.orig" 50*497a30dbSEric Blake_make_test_img -b "$TEST_IMG.orig" -F raw 64M 51*497a30dbSEric Blake$PYTHON qcow2.py "$TEST_IMG" del-header-ext 0xE2792ACA 52c5f6e493SKevin Wolf 53c5f6e493SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img 64M 54d9f059aaSEric Blake$QEMU_IMG convert -O qcow2 -B "$TEST_IMG.orig" "$TEST_IMG.orig" "$TEST_IMG" 55*497a30dbSEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 64M 56*497a30dbSEric Blake_make_test_img -u -b "$TEST_IMG.base" -F $IMGFMT 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*497a30dbSEric Blake# Rebase the image, to show that backing format is required. 68*497a30dbSEric Blake($QEMU_IMG rebase -u -b "$TEST_IMG.base" "$TEST_IMG" 2>&1 && echo "unexpected pass") | _filter_testdir 69*497a30dbSEric Blake$QEMU_IMG rebase -u -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG" 70d9f059aaSEric Blake$QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filter_testdir 71d9f059aaSEric Blake 72c5f6e493SKevin Wolf# success, all done 73c5f6e493SKevin Wolfecho '*** done' 74c5f6e493SKevin Wolfrm -f $seq.full 75c5f6e493SKevin Wolfstatus=0 76