From patchwork Tue Mar 22 15:33:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8643711 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 8CDA6C0553 for ; Tue, 22 Mar 2016 15:34:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE834201FA for ; Tue, 22 Mar 2016 15:34:01 +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 23723201ED for ; Tue, 22 Mar 2016 15:34:01 +0000 (UTC) Received: from localhost ([::1]:37794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOJk-0006eX-G2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 Mar 2016 11:34:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOJQ-0006Ya-Un for qemu-devel@nongnu.org; Tue, 22 Mar 2016 11:33:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiOJM-0003hP-JR for qemu-devel@nongnu.org; Tue, 22 Mar 2016 11:33:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiOJE-0003fO-7a; Tue, 22 Mar 2016 11:33:28 -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 DC6417F0A6; Tue, 22 Mar 2016 15:33:27 +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 u2MFXNXk020137; Tue, 22 Mar 2016 11:33:26 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 22 Mar 2016 16:33:02 +0100 Message-Id: <1458660792-3035-3-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 02/12] block: Make sure throttled BDSes always have a BB 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 It was already true in principle that a throttled BDS always has a BB attached, except that the order of operations while attaching or detaching a BDS to/from a BB wasn't careful enough. This commit breaks graph manipulations while I/O throttling is enabled. It would have been possible, but quite cumbersome, to keep things working with some temporary hacks, so it's not worth the hassle. We'll fix things again in a minute. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 14 ++++++++++++++ block/block-backend.c | 3 +++ blockdev.c | 4 ++-- tests/test-throttle.c | 11 ++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index c22cb3f..4f05586 100644 --- a/block.c +++ b/block.c @@ -2255,8 +2255,22 @@ static void swap_feature_fields(BlockDriverState *bs_top, assert(!bs_new->throttle_state); if (bs_top->throttle_state) { assert(bs_top->io_limits_enabled); + /* + * FIXME Need to break I/O throttling with graph manipulations + * temporarily because of conflicting invariants (3. will go away when + * throttling is fully converted to work on BlockBackends): + * + * 1. Every BlockBackend has a single root BDS + * 2. I/O throttling functions require an attached BlockBackend + * 3. We need to first enable throttling on the new BDS and then + * disable it on the old one (because of throttle group refcounts) + */ +#if 0 bdrv_io_limits_enable(bs_new, throttle_group_get_name(bs_top)); bdrv_io_limits_disable(bs_top); +#else + abort(); +#endif } } diff --git a/block/block-backend.c b/block/block-backend.c index a528674..df8f717 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -419,6 +419,9 @@ void blk_remove_bs(BlockBackend *blk) notifier_list_notify(&blk->remove_bs_notifiers, blk); blk_update_root_state(blk); + if (blk->root->bs->io_limits_enabled) { + bdrv_io_limits_disable(blk->root->bs); + } blk->root->bs->blk = NULL; bdrv_root_unref_child(blk->root); diff --git a/blockdev.c b/blockdev.c index 5a53f59..cac9afd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2568,8 +2568,6 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, goto fail; } - blk_apply_root_state(blk, medium_bs); - bdrv_add_key(medium_bs, NULL, &err); if (err) { error_propagate(errp, err); @@ -2594,6 +2592,8 @@ void qmp_blockdev_change_medium(const char *device, const char *filename, goto fail; } + blk_apply_root_state(blk, medium_bs); + qmp_blockdev_close_tray(device, errp); fail: diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 59675fa..d0b3c86 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -573,11 +573,16 @@ static void test_accounting(void) static void test_groups(void) { ThrottleConfig cfg1, cfg2; + BlockBackend *blk1, *blk2, *blk3; BlockDriverState *bdrv1, *bdrv2, *bdrv3; - bdrv1 = bdrv_new(); - bdrv2 = bdrv_new(); - bdrv3 = bdrv_new(); + blk1 = blk_new_with_bs(&error_abort); + blk2 = blk_new_with_bs(&error_abort); + blk3 = blk_new_with_bs(&error_abort); + + bdrv1 = blk_bs(blk1); + bdrv2 = blk_bs(blk2); + bdrv3 = blk_bs(blk3); g_assert(bdrv1->throttle_state == NULL); g_assert(bdrv2->throttle_state == NULL);