From patchwork Tue Jul 23 13:03:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 261075 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 A261E2C00C8 for ; Tue, 23 Jul 2013 23:06:26 +1000 (EST) Received: from localhost ([::1]:45341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cIK-0003Es-Ar for incoming@patchwork.ozlabs.org; Tue, 23 Jul 2013 09:06:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cFy-0000Os-AR for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:04:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1cFw-0007UW-MK for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:03:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1cFw-0007UO-9t for qemu-devel@nongnu.org; Tue, 23 Jul 2013 09:03:56 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6ND3toJ019592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 23 Jul 2013 09:03:55 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6ND3U6J008625; Tue, 23 Jul 2013 09:03:53 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 15:03:19 +0200 Message-Id: <1374584606-5615-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1374584606-5615-1-git-send-email-kwolf@redhat.com> References: <1374584606-5615-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, armbru@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 11/18] block: Allow "driver" option on the top level 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 This is traditionally -drive format=..., which is now translated into the new driver option. This gives us a more consistent way to select the driver of BlockDriverStates that can be used in QMP context, too. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 7 +++++++ blockdev.c | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 03fe754..d2cd9ed 100644 --- a/block.c +++ b/block.c @@ -983,6 +983,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, char tmp_filename[PATH_MAX + 1]; BlockDriverState *file = NULL; QDict *file_options = NULL; + const char *drvname; /* NULL means an empty set of options */ if (options == NULL) { @@ -1079,6 +1080,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } /* Find the right image format driver */ + drvname = qdict_get_try_str(options, "driver"); + if (drvname) { + drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR)); + qdict_del(options, "driver"); + } + if (!drv) { ret = find_image_format(file, filename, &drv); } diff --git a/blockdev.c b/blockdev.c index c5abd65..8ff8ed3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -322,7 +322,6 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) enum { MEDIA_DISK, MEDIA_CDROM } media; int bus_id, unit_id; int cyls, heads, secs, translation; - BlockDriver *drv = NULL; int max_devs; int index; int ro = 0; @@ -338,6 +337,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) QemuOpts *opts; QDict *bs_opts; const char *id; + bool has_driver_specific_opts; translation = BIOS_ATA_TRANSLATION_AUTO; media = MEDIA_DISK; @@ -365,6 +365,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) qdict_del(bs_opts, "id"); } + has_driver_specific_opts = !!qdict_size(bs_opts); + /* extract parameters */ bus_id = qemu_opt_get_number(opts, "bus", 0); unit_id = qemu_opt_get_number(opts, "unit", -1); @@ -477,11 +479,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) error_printf("\n"); return NULL; } - drv = bdrv_find_whitelisted_format(buf, ro); - if (!drv) { - error_report("'%s' invalid format", buf); - return NULL; - } + + qdict_put(bs_opts, "driver", qstring_from_str(buf)); } /* disk I/O throttling */ @@ -658,7 +657,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) abort(); } if (!file || !*file) { - if (qdict_size(bs_opts)) { + if (has_driver_specific_opts) { file = NULL; } else { return dinfo; @@ -695,13 +694,13 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) error_report("warning: disabling copy_on_read on readonly drive"); } - ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv); - bs_opts = NULL; + QINCREF(bs_opts); + ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, NULL); if (ret < 0) { if (ret == -EMEDIUMTYPE) { error_report("could not open disk image %s: not in %s format", - file ?: dinfo->id, drv->format_name); + file ?: dinfo->id, qdict_get_str(bs_opts, "driver")); } else { error_report("could not open disk image %s: %s", file ?: dinfo->id, strerror(-ret)); @@ -712,6 +711,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) if (bdrv_key_required(dinfo->bdrv)) autostart = 0; + QDECREF(bs_opts); qemu_opts_del(opts); return dinfo;