From patchwork Mon Jan 28 14:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Kuchin X-Patchwork-Id: 10783827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36596922 for ; Mon, 28 Jan 2019 14:38:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25A522AFFC for ; Mon, 28 Jan 2019 14:38:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19C682B009; Mon, 28 Jan 2019 14:38:35 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 976C92AFFC for ; Mon, 28 Jan 2019 14:38:34 +0000 (UTC) Received: from localhost ([127.0.0.1]:33005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1go83V-0008Kx-Uy for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Jan 2019 09:38:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1go7ta-0000TQ-1Z for qemu-devel@nongnu.org; Mon, 28 Jan 2019 09:28:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1go7tZ-0006JT-BN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 09:28:18 -0500 Received: from forwardcorp1o.cmail.yandex.net ([2a02:6b8:0:1a72::290]:52033) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1go7tX-00067G-6A; Mon, 28 Jan 2019 09:28:15 -0500 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.cmail.yandex.net (Yandex) with ESMTP id 7F86420F85; Mon, 28 Jan 2019 17:28:11 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id laWI6kegN7-SBxeTRlo; Mon, 28 Jan 2019 17:28:11 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1548685691; bh=+7QKyyejJSBp3X/M6cbZ+dDjuClzorOH1o1kuQAaKwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=gCLW+kHdH+qXI0mbaSO80UyznoQwnzjkzu7nhQp0QgKy2uoyonYioB9wHtFZAvnAw eGetqPZS/+O1wUeFB+Uvv3L84emMVYSeuWKcblV3PvBxc4nnOXdWBGrzw7+Mkkg8o/ 9ho2EkGbU+TRFEiYJacSTxcE0LQQclvAo58uvQVw= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:408:250:b6ff:fe97:2682]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id S7ZFtr57gZ-SB5OLSYR; Mon, 28 Jan 2019 17:28:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Anton Kuchin To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 17:27:47 +0300 Message-Id: <20190128142748.29140-2-antonkuchin@yandex-team.ru> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128142748.29140-1-antonkuchin@yandex-team.ru> References: <20190128142748.29140-1-antonkuchin@yandex-team.ru> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1a72::290 Subject: [Qemu-devel] [PATCH 1/2] block: add functions to search BlockBackend by root BDS name 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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Anton Kuchin , Max Reitz , Evgeny Yakovlev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP BlockBackend name is empty if it is added with '-blockdev' and '-device' options or hotplugged with QMP but callers still expect backend to be accesible by name for operations like commit or statistics access. Intoduce blk_lookup function to search both by name and BDS-root node_name. Signed-off-by: Anton Kuchin --- block/block-backend.c | 29 +++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 60d37a0c3d..86a492853c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -684,6 +684,35 @@ static BlockBackend *bdrv_first_blk(BlockDriverState *bs) return NULL; } +/* + * Return the BlockBackend that has attached BDS-tree root with + * node_name @node_name if it exists, else null. + * @node_name must not be null. + */ +static BlockBackend *blk_by_root_name(const char *node_name) +{ + BlockBackend *blk = NULL; + + assert(node_name); + while ((blk = blk_all_next(blk)) != NULL) { + BlockDriverState *bs = blk_bs(blk); + if (bs && !strcmp(node_name, bs->node_name)) { + return blk; + } + } + return NULL; +} + +BlockBackend *blk_lookup(const char *name) +{ + assert(name); + BlockBackend *blk = blk_by_name(name); + if (!blk) { + blk = blk_by_root_name(name); + } + return blk; +} + /* * Returns true if @bs has an associated BlockBackend. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index c96bcdee14..290b8f8fc9 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -85,6 +85,13 @@ void blk_unref(BlockBackend *blk); void blk_remove_all_bs(void); const char *blk_name(const BlockBackend *blk); BlockBackend *blk_by_name(const char *name); + +/* + * Search BlockBackend by name or root BlockDriverSate node_name. + * Hotplug BlockBackends have no name so need to also check BDS-tree roots + * @name must not be null. + */ +BlockBackend *blk_lookup(const char *name); BlockBackend *blk_next(BlockBackend *blk); BlockBackend *blk_all_next(BlockBackend *blk); bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp); From patchwork Mon Jan 28 14:27:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Kuchin X-Patchwork-Id: 10783821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C465391E for ; Mon, 28 Jan 2019 14:36:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B43FF2946B for ; Mon, 28 Jan 2019 14:36:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7DFB2AFDA; Mon, 28 Jan 2019 14:36:09 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD7782B010 for ; Mon, 28 Jan 2019 14:36:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:32987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1go819-0006V5-0f for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Jan 2019 09:36:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1go7ta-0000TN-01 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 09:28:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1go7tZ-0006JF-7u for qemu-devel@nongnu.org; Mon, 28 Jan 2019 09:28:17 -0500 Received: from forwardcorp1j.cmail.yandex.net ([5.255.227.105]:53458) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1go7tW-00068O-Pt; Mon, 28 Jan 2019 09:28:14 -0500 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id F414F20F0A; Mon, 28 Jan 2019 17:28:11 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id VwKS1wqCxx-SBWKPPUr; Mon, 28 Jan 2019 17:28:11 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1548685691; bh=HTAmDCXFI3Bs8Mquxq1KebuSFkJQsyNulZD7qA0B5Z4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=P7FuZMw/vgdRtWYBD4pSFn3PXBTBPCqCdIcKvzFEEH5pUwfJuYZ7Y8AvSBrYhoF4G JWrAzzn0YGFXsQxRBEErj0+21D7M3p8S/RympPP6D8TVLOMEmiW0RiaNiFoz+Afz2t R3EhJcg+4KoyTuzB1Au+Asn8INAS5ftZiLKGx1mI= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:408:250:b6ff:fe97:2682]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id S7ZFtr57gZ-SB5CA0uh; Mon, 28 Jan 2019 17:28:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Anton Kuchin To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 17:27:48 +0300 Message-Id: <20190128142748.29140-3-antonkuchin@yandex-team.ru> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128142748.29140-1-antonkuchin@yandex-team.ru> References: <20190128142748.29140-1-antonkuchin@yandex-team.ru> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.255.227.105 Subject: [Qemu-devel] [PATCH 2/2] block: migrate callers from blk_by_name to blk_lookup 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: Kevin Wolf , qemu-block@nongnu.org, Markus Armbruster , "Dr. David Alan Gilbert" , Anton Kuchin , Max Reitz , Evgeny Yakovlev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Anton Kuchin --- blockdev-nbd.c | 2 +- blockdev.c | 6 +++--- hmp.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d73ac1b026..f2ea7318cf 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -162,7 +162,7 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name, return; } - on_eject_blk = blk_by_name(device); + on_eject_blk = blk_lookup(device); bs = bdrv_lookup_bs(device, device, errp); if (!bs) { diff --git a/blockdev.c b/blockdev.c index a8fa8748a9..bb01c41038 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1082,7 +1082,7 @@ void hmp_commit(Monitor *mon, const QDict *qdict) BlockDriverState *bs; AioContext *aio_context; - blk = blk_by_name(device); + blk = blk_lookup(device); if (!blk) { monitor_printf(mon, "Device '%s' not found\n", device); return; @@ -3066,7 +3066,7 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) return; } - blk = blk_by_name(id); + blk = blk_lookup(id); if (!blk) { error_report("Device '%s' not found", id); return; @@ -4431,7 +4431,7 @@ void qmp_x_block_latency_histogram_set( bool has_boundaries_flush, uint64List *boundaries_flush, Error **errp) { - BlockBackend *blk = blk_by_name(device); + BlockBackend *blk = blk_lookup(device); BlockAcctStats *stats; int ret; diff --git a/hmp.c b/hmp.c index b2a2b1f84e..7b03d5c1d7 100644 --- a/hmp.c +++ b/hmp.c @@ -2460,7 +2460,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) Error *err = NULL; int ret; - blk = blk_by_name(device); + blk = blk_lookup(device); if (!blk) { BlockDriverState *bs = bdrv_lookup_bs(NULL, device, &err); if (bs) {