From patchwork Wed Mar 16 18:54:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 8603371 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 6AFF9C0553 for ; Wed, 16 Mar 2016 18:59:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF8C92026C for ; Wed, 16 Mar 2016 18:59:17 +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 07CE92020F for ; Wed, 16 Mar 2016 18:59:17 +0000 (UTC) Received: from localhost ([::1]:58258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agGf6-00028s-FQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 14:59:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agGbB-0000ti-QB for qemu-devel@nongnu.org; Wed, 16 Mar 2016 14:55:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agGbA-0005Yb-RH for qemu-devel@nongnu.org; Wed, 16 Mar 2016 14:55:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agGb6-0005X4-Fk; Wed, 16 Mar 2016 14:55:08 -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 14A1385541; Wed, 16 Mar 2016 18:55:08 +0000 (UTC) Received: from localhost (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GIt6HR017680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 16 Mar 2016 14:55:07 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 16 Mar 2016 19:54:36 +0100 Message-Id: <1458154485-32536-9-git-send-email-mreitz@redhat.com> In-Reply-To: <1458154485-32536-1-git-send-email-mreitz@redhat.com> References: <1458154485-32536-1-git-send-email-mreitz@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: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v4 08/17] 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 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 --- 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);