From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmJOB-0003KC-5o for qemu-devel@nongnu.org; Tue, 20 Sep 2016 07:39:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmJO9-0001NW-7G for qemu-devel@nongnu.org; Tue, 20 Sep 2016 07:39:02 -0400 From: Kevin Wolf Date: Tue, 20 Sep 2016 13:38:42 +0200 Message-Id: <1474371529-24466-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1474371529-24466-1-git-send-email-kwolf@redhat.com> References: <1474371529-24466-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v3 03/10] qdev-monitor: Add blk_by_qdev_id() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eblake@redhat.com, mreitz@redhat.com, jsnow@redhat.com, qemu-devel@nongnu.org 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 410eb68..3b29317 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -112,6 +112,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(); -- 1.8.3.1