From patchwork Tue Oct 24 03:33:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sochin jiang X-Patchwork-Id: 10023467 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 93AB46035E for ; Tue, 24 Oct 2017 04:22:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 928DF288A6 for ; Tue, 24 Oct 2017 04:22:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85D472895A; Tue, 24 Oct 2017 04:22:28 +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 E49FE288A6 for ; Tue, 24 Oct 2017 04:22:27 +0000 (UTC) Received: from localhost ([::1]:41640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6qjT-0005MA-23 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 Oct 2017 00:22:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6qit-0005KZ-Ou for qemu-devel@nongnu.org; Tue, 24 Oct 2017 00:21:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e6qis-0001aK-Sb for qemu-devel@nongnu.org; Tue, 24 Oct 2017 00:21:51 -0400 Received: from [45.249.212.32] (port=33783 helo=huawei.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e6qin-0001VQ-Fd; Tue, 24 Oct 2017 00:21:45 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 96C07A4ED899A; Tue, 24 Oct 2017 11:33:58 +0800 (CST) Received: from localhost.localdomain (10.175.104.227) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.361.1; Tue, 24 Oct 2017 11:33:25 +0800 From: sochin jiang To: , , , , Date: Tue, 24 Oct 2017 11:33:51 +0800 Message-ID: <1508816031-82709-1-git-send-email-sochin.jiang@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.227] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.32 Subject: [Qemu-devel] [PATCH v2] throttle: fix a qemu crash problem when calling blk_delete 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: xieyingtai@huawei.com, lina.lulina@huawei.com, lizhengui@huawei.com, qemu-block@nongnu.org, subo7@huawei.com, eric.fangyi@huawei.com, zhangshuai13@huawei.com, qemu-devel@nongnu.org, sochin.jiang@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP commit 7ca7f0 moves the throttling related part of the BDS life cycle management to BlockBackend, adds call to throttle_timers_detach_aio_context in blk_remove_bs. commit 1606e remove a block device from its throttle group in blk_delete by calling blk_io_limits_disable, this fix an easily reproducible qemu crash. But delete a BB without a BDS inserted could easily cause a qemu crash too by calling bdrv_drained_begin in blk_io_limits_disable. Say, a simply drive_add and then a drive_del command. This patch removes draining BDS by calling throttle_group_unregister_tgm directly instead of blk_io_limits_disable, leaves draining operation to blk_remove_bs in case that there is no BDS inserted. Futhermore, make sure throttle timers are initialized or attached before throttle_timers_destroy is called in throttle_group_unregister_tgm. Signed-off-by: sochin jiang --- block/block-backend.c | 2 +- block/throttle-groups.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 45d9101..39c7cca 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -341,7 +341,7 @@ static void blk_delete(BlockBackend *blk) assert(!blk->name); assert(!blk->dev); if (blk->public.throttle_group_member.throttle_state) { - blk_io_limits_disable(blk); + throttle_group_unregister_tgm(&blk->public.throttle_group_member); } if (blk->root) { blk_remove_bs(blk); diff --git a/block/throttle-groups.c b/block/throttle-groups.c index b291a88..c5f9af3 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -576,7 +576,9 @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm) /* remove the current tgm from the list */ QLIST_REMOVE(tgm, round_robin); - throttle_timers_destroy(&tgm->throttle_timers); + if (throttle_timers_are_initialized(&tgm->throttle_timers)) { + throttle_timers_destroy(&tgm->throttle_timers); + } qemu_mutex_unlock(&tg->lock); throttle_group_unref(&tg->ts);