From patchwork Thu Jun 23 14:36:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 639666 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rb3wt3VwXz9t1J for ; Fri, 24 Jun 2016 00:38:22 +1000 (AEST) Received: from localhost ([::1]:37032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG5ls-0003w0-CC for incoming@patchwork.ozlabs.org; Thu, 23 Jun 2016 10:38:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG5kV-0001Yh-3G for qemu-devel@nongnu.org; Thu, 23 Jun 2016 10:36:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG5kU-0002Gk-7A for qemu-devel@nongnu.org; Thu, 23 Jun 2016 10:36:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53717) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG5kL-0002DT-Jn; Thu, 23 Jun 2016 10:36:45 -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 20FC38F279; Thu, 23 Jun 2016 14:36:45 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5NEaY3J012371; Thu, 23 Jun 2016 10:36:43 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 23 Jun 2016 16:36:29 +0200 Message-Id: <1466692592-9551-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1466692592-9551-1-git-send-email-kwolf@redhat.com> References: <1466692592-9551-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]); Thu, 23 Jun 2016 14:36:45 +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] [RFC PATCH 4/7] qdev-monitor: Add blk_by_qdev_id() 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, famz@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This finds the BlockBackend attached to the device model identified by its qdev ID. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/sysemu/block-backend.h | 1 + qdev-monitor.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index aec1471..79226d3 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -111,6 +111,7 @@ void blk_attach_dev_nofail(BlockBackend *blk, void *dev); void blk_detach_dev(BlockBackend *blk, void *dev); void *blk_get_attached_dev(BlockBackend *blk); BlockBackend *blk_by_dev(void *dev); +BlockBackend *blk_by_qdev_id(const char *id, Error **errp); void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque); int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, int count); diff --git a/qdev-monitor.c b/qdev-monitor.c index bc0213f..4f78ecb 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -28,6 +28,7 @@ #include "qemu/config-file.h" #include "qemu/error-report.h" #include "qemu/help_option.h" +#include "sysemu/block-backend.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -838,6 +839,23 @@ void qmp_device_del(const char *id, Error **errp) } } +BlockBackend *blk_by_qdev_id(const char *id, Error **errp) +{ + DeviceState *dev; + BlockBackend *blk; + + dev = find_device_state(id, errp); + if (dev == NULL) { + return NULL; + } + + blk = blk_by_dev(dev); + if (!blk) { + error_setg(errp, "Device does not have a block device backend"); + } + return blk; +} + void qdev_machine_init(void) { qdev_get_peripheral_anon();