From patchwork Mon May 23 16:55:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9132167 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 2474F607D5 for ; Mon, 23 May 2016 16:58:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 185BB2810E for ; Mon, 23 May 2016 16:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D4B828247; Mon, 23 May 2016 16:58:38 +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 9EA6C2810E for ; Mon, 23 May 2016 16:58:37 +0000 (UTC) Received: from localhost ([::1]:49384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4tBc-0006Ce-LV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 May 2016 12:58:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4t8k-0004Cq-4m for qemu-devel@nongnu.org; Mon, 23 May 2016 12:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4t8b-0007Ip-Pw for qemu-devel@nongnu.org; Mon, 23 May 2016 12:55:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4t8X-0007Hh-VR; Mon, 23 May 2016 12:55:26 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 78A81C05B1DB; Mon, 23 May 2016 16:55:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-74.ams2.redhat.com [10.36.116.74]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4NGtGhS018979; Mon, 23 May 2016 12:55:23 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 23 May 2016 18:55:14 +0200 Message-Id: <1464022515-11390-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1464022515-11390-1-git-send-email-kwolf@redhat.com> References: <1464022515-11390-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 23 May 2016 16:55:25 +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 3/4] block: Fix reconfiguring graph with drained nodes 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, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When changing the BlockDriverState that a BdrvChild points to while the node is currently drained, we must call the .drained_end() parent callback. Conversely, when this means attaching a new node that is already drained, we need to call .drained_begin(). bdrv_root_attach_child() takes now an opaque parameter, which is needed because the callbacks must also be called if we're attaching a new child to the BlockBackend when the root node is already drained, and they need a way to identify the BlockBackend. Previously, child->opaque was set too late and the callbacks would still see it as NULL. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 18 ++++++++++++++---- block/block-backend.c | 9 +++++---- include/block/block_int.h | 3 ++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/block.c b/block.c index 351344e..598624f 100644 --- a/block.c +++ b/block.c @@ -1155,24 +1155,33 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) BlockDriverState *old_bs = child->bs; if (old_bs) { + if (old_bs->quiesce_counter && child->role->drained_end) { + child->role->drained_end(child); + } QLIST_REMOVE(child, next_parent); } + + child->bs = new_bs; + if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); + if (new_bs->quiesce_counter && child->role->drained_begin) { + child->role->drained_begin(child); + } } - - child->bs = new_bs; } BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role) + const BdrvChildRole *child_role, + void *opaque) { BdrvChild *child = g_new(BdrvChild, 1); *child = (BdrvChild) { .bs = NULL, .name = g_strdup(child_name), .role = child_role, + .opaque = opaque, }; bdrv_replace_child(child, child_bs); @@ -1185,7 +1194,8 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, const char *child_name, const BdrvChildRole *child_role) { - BdrvChild *child = bdrv_root_attach_child(child_bs, child_name, child_role); + BdrvChild *child = bdrv_root_attach_child(child_bs, child_name, child_role, + NULL); QLIST_INSERT_HEAD(&parent_bs->children, child, next); return child; } diff --git a/block/block-backend.c b/block/block-backend.c index 4e8298b..14e528e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -161,8 +161,7 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, } blk_set_enable_write_cache(blk, true); - blk->root = bdrv_root_attach_child(bs, "root", &child_root); - blk->root->opaque = blk; + blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk); return blk; } @@ -481,8 +480,7 @@ void blk_remove_bs(BlockBackend *blk) void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { bdrv_ref(bs); - blk->root = bdrv_root_attach_child(bs, "root", &child_root); - blk->root->opaque = blk; + blk->root = bdrv_root_attach_child(bs, "root", &child_root, blk); notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { @@ -1676,6 +1674,9 @@ static void blk_root_drained_begin(BdrvChild *child) { BlockBackend *blk = child->opaque; + /* Note that blk->root may not be accessible here yet if we are just + * attaching to a BlockDriverState that is drained. Use child instead. */ + if (blk->public.io_limits_disabled++ == 0) { throttle_group_restart_blk(blk); } diff --git a/include/block/block_int.h b/include/block/block_int.h index b6f4755..30a9717 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -719,7 +719,8 @@ void hmp_drive_add_node(Monitor *mon, const char *optstr); BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name, - const BdrvChildRole *child_role); + const BdrvChildRole *child_role, + void *opaque); void bdrv_root_unref_child(BdrvChild *child); const char *bdrv_get_parent_name(const BlockDriverState *bs);