From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG5kX-0001Zc-43 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 10:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG5kV-0002HA-41 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 10:36:56 -0400 From: Kevin Wolf Date: Thu, 23 Jun 2016 16:36:27 +0200 Message-Id: <1466692592-9551-3-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> Subject: [Qemu-devel] [RFC PATCH 2/7] block: Add blk_by_dev() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eblake@redhat.com, armbru@redhat.com, stefanha@redhat.com, mreitz@redhat.com, famz@redhat.com, qemu-devel@nongnu.org This finds a BlockBackend given the device model that is attached to it. Signed-off-by: Kevin Wolf --- block/block-backend.c | 19 +++++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 20 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 34500e6..307cb17 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -544,6 +544,25 @@ void *blk_get_attached_dev(BlockBackend *blk) } /* + * Return the BlockBackend which has the device model @dev attached if it + * exists, else null. + * + * @dev must not be null. + */ +BlockBackend *blk_by_dev(void *dev) +{ + BlockBackend *blk = NULL; + + assert(dev != NULL); + while ((blk = blk_all_next(blk)) != NULL) { + if (blk->dev == dev) { + return blk; + } + } + return NULL; +} + +/* * Set @blk's device model callbacks to @ops. * @opaque is the opaque argument to pass to the callbacks. * This is for use by device models. diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index c04af8e..aec1471 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -110,6 +110,7 @@ int blk_attach_dev(BlockBackend *blk, void *dev); 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); 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); -- 1.8.3.1