From patchwork Sat Dec 15 11:35:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: block: Probe file for specified format Date: Sat, 15 Dec 2012 01:35:43 -0000 From: Stefan Weil X-Patchwork-Id: 206613 Message-Id: <1355571343-19878-1-git-send-email-sw@weilnetz.de> To: Stefan Hajnoczi , Kevin Wolf Cc: Stefan Weil , 1090600@bugs.launchpad.net, qemu-devel@nongnu.org Probe for the file format if the file format was specified explicitly and a probe function is available. example: -drive file=myfile,format=qcow2 Then myfile is probed and must be in qcow2 format. This fixes those bugs: https://bugzilla.redhat.com/show_bug.cgi?id=556482 https://bugs.launchpad.net/qemu/+bug/1090600 Signed-off-by: Stefan Weil --- This patch can also be used for the latest stable version of QEMU. blockdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockdev.c b/blockdev.c index 9a05e57..5a4cd56 100644 --- a/blockdev.c +++ b/blockdev.c @@ -411,6 +411,13 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType block_default_type) error_report("'%s' invalid format", buf); return NULL; } + if (file && drv->bdrv_probe) { + uint8_t data[2048]; + if (drv->bdrv_probe(data, sizeof(data), file) == 0) { + error_report("file '%s' not in '%s' format", file, buf); + return NULL; + } + } } /* disk I/O throttling */