From patchwork Fri Sep 6 15:38:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 273280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CF8032C0117 for ; Sat, 7 Sep 2013 03:08:59 +1000 (EST) Received: from localhost ([::1]:38421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHyAL-000694-JK for incoming@patchwork.ozlabs.org; Fri, 06 Sep 2013 11:41:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy8S-0004cx-QO for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHy8M-00059j-Ns for qemu-devel@nongnu.org; Fri, 06 Sep 2013 11:39:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHy8M-00059a-ET; Fri, 06 Sep 2013 11:39:42 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r86FddaE000979 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 Sep 2013 11:39:40 -0400 Received: from localhost (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r86Fdbvd010473; Fri, 6 Sep 2013 11:39:38 -0400 From: Stefan Hajnoczi To: Date: Fri, 6 Sep 2013 17:38:39 +0200 Message-Id: <1378481953-23099-9-git-send-email-stefanha@redhat.com> In-Reply-To: <1378481953-23099-1-git-send-email-stefanha@redhat.com> References: <1378481953-23099-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Stefan Weil , Stefan Hajnoczi , qemu-stable@nongnu.org, Anthony Liguori Subject: [Qemu-devel] [PULL 08/42] w32: Fix access to host devices (regression) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Weil QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk) since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?). Those devices use hdev_open which did not use the latest API for options. This resulted in a fatal runtime error: Block protocol 'host_device' doesn't support the option 'filename' Duplicate code from raw_open to fix this. Cc: qemu-stable@nongnu.org Reported-by: David Brenner Signed-off-by: Stefan Weil Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block/raw-win32.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/block/raw-win32.c b/block/raw-win32.c index 9b5b2af..d2d2d9f 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -535,13 +535,29 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags) { BDRVRawState *s = bs->opaque; int access_flags, create_flags; + int ret = 0; DWORD overlapped; char device_name[64]; - const char *filename = qdict_get_str(options, "filename"); + + Error *local_err = NULL; + const char *filename; + + QemuOpts *opts = qemu_opts_create_nofail(&raw_runtime_opts); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + ret = -EINVAL; + goto done; + } + + filename = qemu_opt_get(opts, "filename"); if (strstart(filename, "/dev/cdrom", NULL)) { - if (find_cdrom(device_name, sizeof(device_name)) < 0) - return -ENOENT; + if (find_cdrom(device_name, sizeof(device_name)) < 0) { + ret = -ENOENT; + goto done; + } filename = device_name; } else { /* transform drive letters into device name */ @@ -564,11 +580,17 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags) if (s->hfile == INVALID_HANDLE_VALUE) { int err = GetLastError(); - if (err == ERROR_ACCESS_DENIED) - return -EACCES; - return -1; + if (err == ERROR_ACCESS_DENIED) { + ret = -EACCES; + } else { + ret = -1; + } + goto done; } - return 0; + +done: + qemu_opts_del(opts); + return ret; } static BlockDriver bdrv_host_device = {