From patchwork Fri Aug 19 16:50:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9290635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 034566077B for ; Fri, 19 Aug 2016 16:55:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9134294DB for ; Fri, 19 Aug 2016 16:55:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDA6F294EB; Fri, 19 Aug 2016 16:55:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73CE4294DB for ; Fri, 19 Aug 2016 16:55:50 +0000 (UTC) Received: from localhost ([::1]:58176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban5B-0006GC-Ix for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Aug 2016 12:55:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45752) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban0T-0001ug-57 for qemu-devel@nongnu.org; Fri, 19 Aug 2016 12:50:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ban0N-00068C-0h for qemu-devel@nongnu.org; Fri, 19 Aug 2016 12:50:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban0I-00066a-Uu; Fri, 19 Aug 2016 12:50:47 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C39080F7D; Fri, 19 Aug 2016 16:50:46 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7JGobJe001957; Fri, 19 Aug 2016 12:50:45 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 19 Aug 2016 18:50:30 +0200 Message-Id: <1471625435-6190-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1471625435-6190-1-git-send-email-kwolf@redhat.com> References: <1471625435-6190-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 19 Aug 2016 16:50:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/10] block: Accept device model name for x-blockdev-insert-medium X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to remove the necessity to use BlockBackend names in the external API, we want to allow qdev device names in all device related commands. This converts x-blockdev-insert-medium to accept a qdev device name. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- blockdev.c | 33 +++++++++++++++++---------------- qapi/block-core.json | 7 +++++-- qmp-commands.hx | 6 ++++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/blockdev.c b/blockdev.c index ee3a153..645c639 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2465,34 +2465,26 @@ out: aio_context_release(aio_context); } -static void qmp_blockdev_insert_anon_medium(const char *device, +static void qmp_blockdev_insert_anon_medium(BlockBackend *blk, BlockDriverState *bs, Error **errp) { - BlockBackend *blk; bool has_device; - blk = blk_by_name(device); - if (!blk) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", device); - return; - } - /* For BBs without a device, we can exchange the BDS tree at will */ has_device = blk_get_attached_dev(blk); if (has_device && !blk_dev_has_removable_media(blk)) { - error_setg(errp, "Device '%s' is not removable", device); + error_setg(errp, "Device is not removable"); return; } if (has_device && blk_dev_has_tray(blk) && !blk_dev_is_tray_open(blk)) { - error_setg(errp, "Tray of device '%s' is not open", device); + error_setg(errp, "Tray of the device is not open"); return; } if (blk_bs(blk)) { - error_setg(errp, "There already is a medium in device '%s'", device); + error_setg(errp, "There already is a medium in the device"); return; } @@ -2508,11 +2500,20 @@ static void qmp_blockdev_insert_anon_medium(const char *device, } } -void qmp_x_blockdev_insert_medium(const char *device, const char *node_name, - Error **errp) +void qmp_x_blockdev_insert_medium(bool has_device, const char *device, + bool has_id, const char *id, + const char *node_name, Error **errp) { + BlockBackend *blk; BlockDriverState *bs; + blk = qmp_get_blk(has_device ? device : NULL, + has_id ? id : NULL, + errp); + if (!blk) { + return; + } + bs = bdrv_find_node(node_name); if (!bs) { error_setg(errp, "Node '%s' not found", node_name); @@ -2525,7 +2526,7 @@ void qmp_x_blockdev_insert_medium(const char *device, const char *node_name, return; } - qmp_blockdev_insert_anon_medium(device, bs, errp); + qmp_blockdev_insert_anon_medium(blk, bs, errp); } void qmp_blockdev_change_medium(const char *device, const char *filename, @@ -2606,7 +2607,7 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, goto fail; } - qmp_blockdev_insert_anon_medium(device, medium_bs, &err); + qmp_blockdev_insert_anon_medium(blk, medium_bs, &err); if (err) { error_propagate(errp, err); goto fail; diff --git a/qapi/block-core.json b/qapi/block-core.json index 069c699..2625bf8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2380,14 +2380,17 @@ # This command is still a work in progress and is considered experimental. # Stay away from it unless you want to help with its development. # -# @device: block device name +# @device: block device name (deprecated, use @id instead) +# +# @id: the name or QOM path of the guest device (since: 2.8) # # @node-name: name of a node in the block driver state graph # # Since: 2.5 ## { 'command': 'x-blockdev-insert-medium', - 'data': { 'device': 'str', + 'data': { '*device': 'str', + '*id': 'str', 'node-name': 'str'} } diff --git a/qmp-commands.hx b/qmp-commands.hx index 0fd679c..b3aed7f 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -4412,7 +4412,7 @@ EQMP { .name = "x-blockdev-insert-medium", - .args_type = "device:s,node-name:s", + .args_type = "device:s?,id:s?,node-name:s", .mhandler.cmd_new = qmp_marshal_x_blockdev_insert_medium, }, @@ -4429,7 +4429,9 @@ Stay away from it unless you want to help with its development. Arguments: -- "device": block device name (json-string) +- "device": block device name (deprecated, use @id instead) + (json-string, optional) +- "id": the name or QOM path of the guest device (json-string, optional) - "node-name": root node of the BDS tree to insert into the block device Example: