From patchwork Fri Aug 19 16:50:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9290629 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 110E660574 for ; Fri, 19 Aug 2016 16:51:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0413E294DF for ; Fri, 19 Aug 2016 16:51:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED0D2294E3; Fri, 19 Aug 2016 16:51:39 +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 A285C294DF for ; Fri, 19 Aug 2016 16:51:39 +0000 (UTC) Received: from localhost ([::1]:58154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban18-000247-Hv for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 Aug 2016 12:51:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45662) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban0N-0001pS-JI for qemu-devel@nongnu.org; Fri, 19 Aug 2016 12:50:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ban0L-00067k-J1 for qemu-devel@nongnu.org; Fri, 19 Aug 2016 12:50:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ban0C-00065P-Ul; Fri, 19 Aug 2016 12:50:41 -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 7BBCD3B72D; Fri, 19 Aug 2016 16:50:40 +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 u7JGobJa001957; Fri, 19 Aug 2016 12:50:39 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 19 Aug 2016 18:50:26 +0200 Message-Id: <1471625435-6190-2-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.30]); Fri, 19 Aug 2016 16:50:40 +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 01/10] block: Add blk_by_dev() 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 This finds a BlockBackend given the device model that is attached to it. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- 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 d1349d9..0bd19ab 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -560,6 +560,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 4808a96..410eb68 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -111,6 +111,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);