From patchwork Fri Apr 12 20:47:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 236205 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 63B622C00AA for ; Sat, 13 Apr 2013 06:53:27 +1000 (EST) Received: from localhost ([::1]:44982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQkyL-0001w6-N9 for incoming@patchwork.ozlabs.org; Fri, 12 Apr 2013 16:53:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktY-00027k-0y for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQktR-0004hO-Oh for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktR-0004gb-Go for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:21 -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 r3CKmKp8020087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 16:48:21 -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 r3CKmCIt009994; Fri, 12 Apr 2013 16:48:19 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 12 Apr 2013 22:47:57 +0200 Message-Id: <1365799688-19918-5-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 04/15] raw-posix: 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-posix.c | 57 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 99ac869..9b7bc9c 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -262,15 +262,42 @@ error: } #endif -static int raw_open_common(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_common(BlockDriverState *bs, QDict *options, int bdrv_flags, int open_flags) { BDRVRawState *s = bs->opaque; + QemuOpts *opts; + Error *local_err = NULL; + const char* filename; int fd, ret; + 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"); + ret = raw_normalize_devicepath(&filename); if (ret != 0) { - return ret; + goto fail; } s->open_flags = open_flags; @@ -280,16 +307,18 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, fd = qemu_open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; - if (ret == -EROFS) + if (ret == -EROFS) { ret = -EACCES; - return ret; + } + goto fail; } s->fd = fd; #ifdef CONFIG_LINUX_AIO if (raw_set_aio(&s->aio_ctx, &s->use_aio, bdrv_flags)) { qemu_close(fd); - return -errno; + ret = -errno; + goto fail; } #endif @@ -300,7 +329,10 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, } #endif - return 0; + ret = 0; +fail: + qemu_opts_del(opts); + return ret; } static int raw_open(BlockDriverState *bs, const char *filename, @@ -309,7 +341,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, BDRVRawState *s = bs->opaque; s->type = FTYPE_FILE; - return raw_open_common(bs, filename, flags, 0); + return raw_open_common(bs, options, flags, 0); } static int raw_reopen_prepare(BDRVReopenState *state, @@ -1293,11 +1325,12 @@ static int check_hdev_writable(BDRVRawState *s) 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 ret; + const char *filename = qdict_get_str(options, "filename"); #if defined(__APPLE__) && defined(__MACH__) if (strstart(filename, "/dev/cdrom", NULL)) { @@ -1338,7 +1371,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, } #endif - ret = raw_open_common(bs, filename, flags, 0); + ret = raw_open_common(bs, options, flags, 0); if (ret < 0) { return ret; } @@ -1541,7 +1574,7 @@ static int floppy_open(BlockDriverState *bs, const char *filename, s->type = FTYPE_FD; /* open will not fail even if no floppy is inserted, so add O_NONBLOCK */ - ret = raw_open_common(bs, filename, flags, O_NONBLOCK); + ret = raw_open_common(bs, options, flags, O_NONBLOCK); if (ret) return ret; @@ -1663,7 +1696,7 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, s->type = FTYPE_CD; /* open will not fail even if no CD is inserted, so add O_NONBLOCK */ - return raw_open_common(bs, filename, flags, O_NONBLOCK); + return raw_open_common(bs, options, flags, O_NONBLOCK); } static int cdrom_probe_device(const char *filename) @@ -1772,7 +1805,7 @@ static int cdrom_open(BlockDriverState *bs, const char *filename, s->type = FTYPE_CD; - ret = raw_open_common(bs, filename, flags, 0); + ret = raw_open_common(bs, options, flags, 0); if (ret) return ret;