From patchwork Tue Mar 22 15:33:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8643761 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 371B4C0553 for ; Tue, 22 Mar 2016 15:36:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E04B0203DA for ; Tue, 22 Mar 2016 15:36:15 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 973502039E for ; Tue, 22 Mar 2016 15:36:13 +0000 (UTC) Received: from localhost ([::1]:37834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOLs-0002AB-WF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Mar 2016 11:36:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOJW-0006l7-Q8 for qemu-devel@nongnu.org; Tue, 22 Mar 2016 11:33:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiOJS-0003kg-OL for qemu-devel@nongnu.org; Tue, 22 Mar 2016 11:33:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39243) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOJF-0003ft-ML; Tue, 22 Mar 2016 11:33:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 586BAC049D5D; Tue, 22 Mar 2016 15:33:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MFXNXl020137; Tue, 22 Mar 2016 11:33:28 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 22 Mar 2016 16:33:03 +0100 Message-Id: <1458660792-3035-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1458660792-3035-1-git-send-email-kwolf@redhat.com> References: <1458660792-3035-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 03/12] block: Introduce BlockBackendPublic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some features, like I/O throttling, are implemented outside block-backend.c, but still want to keep BlockBackends in a list. In order to avoid exposing the whole struct layout in the public header file, this patch introduces an embedded public struct where list entry structs can be added and a pair of functions to convert between BlockBackend and BlockBackendPublic. Signed-off-by: Kevin Wolf --- block/block-backend.c | 17 +++++++++++++++++ include/sysemu/block-backend.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index df8f717..4394950 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -33,6 +33,7 @@ struct BlockBackend { DriveInfo *legacy_dinfo; /* null unless created by drive_new() */ QTAILQ_ENTRY(BlockBackend) link; /* for block_backends */ QTAILQ_ENTRY(BlockBackend) monitor_link; /* for monitor_block_backends */ + BlockBackendPublic public; void *dev; /* attached device model, if any */ /* TODO change to DeviceState when all users are qdevified */ @@ -410,6 +411,22 @@ BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo) } /* + * Returns a pointer to the publicly accessible fields of @blk. + */ +BlockBackendPublic *blk_get_public(BlockBackend *blk) +{ + return &blk->public; +} + +/* + * Returns a BlockBackend given the associated @public fields. + */ +BlockBackend *blk_by_public(BlockBackendPublic *public) +{ + return container_of(public, BlockBackend, public); +} + +/* * Disassociates the currently associated BlockDriverState from @blk. */ void blk_remove_bs(BlockBackend *blk) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d839bff..bb4ff6f 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -59,6 +59,12 @@ typedef struct BlockDevOps { void (*resize_cb)(void *opaque); } BlockDevOps; +/* This struct is embedded in (the private) BlockBackend struct and contains + * fields that must be public. This is in particular for QLIST_ENTRY() and + * friends so that BlockBackends can be kept in lists outside block-backend.c */ +typedef struct BlockBackendPublic { +} BlockBackendPublic; + BlockBackend *blk_new(Error **errp); BlockBackend *blk_new_with_bs(Error **errp); BlockBackend *blk_new_open(const char *filename, const char *reference, @@ -74,6 +80,9 @@ BlockDriverState *blk_next_root_bs(BlockDriverState *bs); bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp); void monitor_remove_blk(BlockBackend *blk); +BlockBackendPublic *blk_get_public(BlockBackend *blk); +BlockBackend *blk_by_public(BlockBackendPublic *public); + BlockDriverState *blk_bs(BlockBackend *blk); void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);