From patchwork Thu Mar 17 15:56:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8612601 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 CF1C3C0553 for ; Thu, 17 Mar 2016 16:01:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49B9F20361 for ; Thu, 17 Mar 2016 16:01:27 +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 85C5520364 for ; Thu, 17 Mar 2016 16:01:26 +0000 (UTC) Received: from localhost ([::1]:36154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaMX-0002X3-UU for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 12:01:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaIN-00023B-4a for qemu-devel@nongnu.org; Thu, 17 Mar 2016 11:57:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agaIJ-0001hq-48 for qemu-devel@nongnu.org; Thu, 17 Mar 2016 11:57:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaIG-0001gS-7K; Thu, 17 Mar 2016 11:57:00 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id C2DD71E44; Thu, 17 Mar 2016 15:56:59 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-71.ams2.redhat.com [10.36.116.71]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HFuj1G010106; Thu, 17 Mar 2016 11:56:58 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 17 Mar 2016 16:56:23 +0100 Message-Id: <1458230202-29136-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1458230202-29136-1-git-send-email-kwolf@redhat.com> References: <1458230202-29136-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 10/29] blockdev: Add list of all BlockBackends 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 From: Max Reitz While monitor_block_backends contains nearly all BBs, we sometimes really need all BBs. To this end, this patch adds the block_backend list. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block/block-backend.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 3bb2a6a..35206be 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -29,6 +29,7 @@ struct BlockBackend { int refcnt; BlockDriverState *bs; 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 */ void *dev; /* attached device model, if any */ @@ -69,6 +70,10 @@ static const AIOCBInfo block_backend_aiocb_info = { static void drive_info_del(DriveInfo *dinfo); +/* All BlockBackends */ +static QTAILQ_HEAD(, BlockBackend) block_backends = + QTAILQ_HEAD_INITIALIZER(block_backends); + /* All BlockBackends referenced by the monitor and which are iterated through by * blk_next() */ static QTAILQ_HEAD(, BlockBackend) monitor_block_backends = @@ -106,7 +111,10 @@ BlockBackend *blk_new(const char *name, Error **errp) blk->refcnt = 1; notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); + + QTAILQ_INSERT_TAIL(&block_backends, blk, link); QTAILQ_INSERT_TAIL(&monitor_block_backends, blk, monitor_link); + return blk; } @@ -177,11 +185,15 @@ static void blk_delete(BlockBackend *blk) g_free(blk->root_state.throttle_group); throttle_group_unref(blk->root_state.throttle_state); } + /* Avoid double-remove after blk_hide_on_behalf_of_hmp_drive_del() */ if (blk->name[0]) { QTAILQ_REMOVE(&monitor_block_backends, blk, monitor_link); } g_free(blk->name); + + QTAILQ_REMOVE(&block_backends, blk, link); + drive_info_del(blk->legacy_dinfo); block_acct_cleanup(&blk->stats); g_free(blk); @@ -226,11 +238,21 @@ void blk_unref(BlockBackend *blk) } } +/* + * Behaves similarly to blk_next() but iterates over all BlockBackends, even the + * ones which are hidden (i.e. are not referenced by the monitor). + */ +static BlockBackend *blk_all_next(BlockBackend *blk) +{ + return blk ? QTAILQ_NEXT(blk, link) + : QTAILQ_FIRST(&block_backends); +} + void blk_remove_all_bs(void) { BlockBackend *blk = NULL; - while ((blk = blk_next(blk)) != NULL) { + while ((blk = blk_all_next(blk)) != NULL) { AioContext *ctx = blk_get_aio_context(blk); aio_context_acquire(ctx);