From patchwork Fri Apr 12 20:47:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 236199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A5AF22C00AC for ; Sat, 13 Apr 2013 06:50:46 +1000 (EST) Received: from localhost ([::1]:35669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQkvk-0005Ex-SE for incoming@patchwork.ozlabs.org; Fri, 12 Apr 2013 16:50:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktY-00028r-Ks for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQktT-0004im-FR for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktT-0004i7-6M for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:23 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3CKmMvS016342 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 16:48:22 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3CKmCIu009994; Fri, 12 Apr 2013 16:48:21 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 12 Apr 2013 22:47:58 +0200 Message-Id: <1365799688-19918-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1365799688-19918-1-git-send-email-kwolf@redhat.com> References: <1365799688-19918-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 05/15] raw-win32: Use bdrv_open options instead of filename 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 Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/raw-win32.c | 57 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/block/raw-win32.c b/block/raw-win32.c index ece2f1a..49d9234 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -221,21 +221,50 @@ static void raw_parse_flags(int flags, int *access_flags, DWORD *overlapped) } } -static int raw_open(BlockDriverState *bs, const char *filename, +static QemuOptsList raw_runtime_opts = { + .name = "raw", + .head = QTAILQ_HEAD_INITIALIZER(raw_runtime_opts.head), + .desc = { + { + .name = "filename", + .type = QEMU_OPT_STRING, + .help = "File name of the image", + }, + { /* end of list */ } + }, +}; + +static int raw_open(BlockDriverState *bs, const char *unused, QDict *options, int flags) { BDRVRawState *s = bs->opaque; int access_flags; DWORD overlapped; + QemuOpts *opts; + Error *local_err = NULL; + const char* filename; + int ret; s->type = FTYPE_FILE; + 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 fail; + } + + filename = qemu_opt_get(opts, "filename"); + raw_parse_flags(flags, &access_flags, &overlapped); - + if ((flags & BDRV_O_NATIVE_AIO) && aio == NULL) { aio = win32_aio_init(); if (aio == NULL) { - return -EINVAL; + ret = -EINVAL; + goto fail; } } @@ -245,20 +274,27 @@ static int raw_open(BlockDriverState *bs, const char *filename, if (s->hfile == INVALID_HANDLE_VALUE) { int err = GetLastError(); - if (err == ERROR_ACCESS_DENIED) - return -EACCES; - return -EINVAL; + if (err == ERROR_ACCESS_DENIED) { + ret = -EACCES; + } else { + ret = -EINVAL; + } + goto fail; } if (flags & BDRV_O_NATIVE_AIO) { - int ret = win32_aio_attach(aio, s->hfile); + ret = win32_aio_attach(aio, s->hfile); if (ret < 0) { CloseHandle(s->hfile); - return ret; + goto fail; } s->aio = aio; } - return 0; + + ret = 0; +fail: + qemu_opts_del(opts); + return ret; } static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs, @@ -495,13 +531,14 @@ static int hdev_probe_device(const char *filename) return 0; } -static int hdev_open(BlockDriverState *bs, const char *filename, +static int hdev_open(BlockDriverState *bs, const char *dummy, QDict *options, int flags) { BDRVRawState *s = bs->opaque; int access_flags, create_flags; DWORD overlapped; char device_name[64]; + const char *filename = qdict_get_str(options, "filename"); if (strstart(filename, "/dev/cdrom", NULL)) { if (find_cdrom(device_name, sizeof(device_name)) < 0)