From patchwork Tue Oct 8 12:16:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 281463 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 5C19B2C00C7 for ; Tue, 8 Oct 2013 23:51:41 +1100 (EST) Received: from localhost ([::1]:36401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWFs-0007Tw-M8 for incoming@patchwork.ozlabs.org; Tue, 08 Oct 2013 08:19:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWDj-0004N0-Ma for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:17:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTWDd-0002n7-Ma for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:16:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWDd-0002ms-FK for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:16:53 -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 r98CGnYZ002797 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Oct 2013 08:16:49 -0400 Received: from dhcp-200-207.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r98CGOw0007904; Tue, 8 Oct 2013 08:16:48 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 8 Oct 2013 14:16:29 +0200 Message-Id: <1381234594-13968-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1381234594-13968-1-git-send-email-kwolf@redhat.com> References: <1381234594-13968-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, benoit.canet@irqsave.net, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, xiawenc@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 12/17] blockdev: Move virtio-blk device creation to drive_init 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: Max Reitz Reviewed-by: Eric Blake --- blockdev.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/blockdev.c b/blockdev.c index 1eaefb0..1c05c7a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -318,7 +318,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts, int ro = 0; int bdrv_flags = 0; int on_read_error, on_write_error; - const char *devaddr; DriveInfo *dinfo; ThrottleConfig cfg; int snapshot = 0; @@ -472,20 +471,12 @@ static DriveInfo *blockdev_init(QDict *bs_opts, } } - if ((devaddr = qemu_opt_get(opts, "addr")) != NULL) { - if (type != IF_VIRTIO) { - error_report("addr is not supported by this bus type"); - return NULL; - } - } - /* init */ dinfo = g_malloc0(sizeof(*dinfo)); dinfo->id = g_strdup(qemu_opts_id(opts)); dinfo->bdrv = bdrv_new(dinfo->id); dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0; dinfo->bdrv->read_only = ro; - dinfo->devaddr = devaddr; dinfo->type = type; dinfo->refcount = 1; if (serial != NULL) { @@ -512,22 +503,8 @@ static DriveInfo *blockdev_init(QDict *bs_opts, case IF_FLOPPY: case IF_PFLASH: case IF_MTD: - break; case IF_VIRTIO: - { - /* add virtio block device */ - QemuOpts *devopts; - devopts = qemu_opts_create_nofail(qemu_find_opts("device")); - if (arch_type == QEMU_ARCH_S390X) { - qemu_opt_set(devopts, "driver", "virtio-blk-s390"); - } else { - qemu_opt_set(devopts, "driver", "virtio-blk-pci"); - } - qemu_opt_set(devopts, "drive", dinfo->id); - if (devaddr) - qemu_opt_set(devopts, "addr", devaddr); break; - } default: abort(); } @@ -651,6 +628,10 @@ QemuOptsList qemu_legacy_drive_opts = { .name = "boot", .type = QEMU_OPT_BOOL, .help = "(deprecated, ignored)", + },{ + .name = "addr", + .type = QEMU_OPT_STRING, + .help = "pci address (virtio only)", }, { /* end of list */ } }, @@ -666,6 +647,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) BlockInterfaceType type; int cyls, heads, secs, translation; int max_devs, bus_id, unit_id, index; + const char *devaddr; Error *local_err = NULL; /* Change legacy command line options into QMP ones */ @@ -866,6 +848,27 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) g_free(new_id); } + /* Add virtio block device */ + devaddr = qemu_opt_get(legacy_opts, "addr"); + if (devaddr && type != IF_VIRTIO) { + error_report("addr is not supported by this bus type"); + goto fail; + } + + if (type == IF_VIRTIO) { + QemuOpts *devopts; + devopts = qemu_opts_create_nofail(qemu_find_opts("device")); + if (arch_type == QEMU_ARCH_S390X) { + qemu_opt_set(devopts, "driver", "virtio-blk-s390"); + } else { + qemu_opt_set(devopts, "driver", "virtio-blk-pci"); + } + qemu_opt_set(devopts, "drive", qdict_get_str(bs_opts, "id")); + if (devaddr) { + qemu_opt_set(devopts, "addr", devaddr); + } + } + /* Actual block device init: Functionality shared with blockdev-add */ dinfo = blockdev_init(bs_opts, type, media); if (dinfo == NULL) { @@ -883,6 +886,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) dinfo->bus = bus_id; dinfo->unit = unit_id; + dinfo->devaddr = devaddr; fail: qemu_opts_del(legacy_opts); @@ -2259,10 +2263,6 @@ QemuOptsList qemu_common_drive_opts = { .type = QEMU_OPT_STRING, .help = "write error action", },{ - .name = "addr", - .type = QEMU_OPT_STRING, - .help = "pci address (virtio only)", - },{ .name = "read-only", .type = QEMU_OPT_BOOL, .help = "open drive file as read-only",