From nobody Mon Feb 9 18:19:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1603372253; cv=none; d=zohomail.com; s=zohoarc; b=i1bRnpcfAdIhExhtfNDqiOPWo+xIwEE6SqfYKQT3WwdTwTEJa0xnyaxP9+vDARQ42kdmoN1FHuCm3RljT6p5uw/yW5AI2IpCDXaQhqPm3vTvNUDMBWD8BEcj+qUqE86fdAzWDmy730WJOrlSs/rLSQftKr5pbMSu6zIgFNuG3YM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603372253; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Gsy7tB+DtN8AWblFMoSP2/5OuM5GN3ELOb0Hh65EY7Q=; b=XuT1cHkB6jbHBgSHbXXhL7Giq+FW1U0sgFbVLlYYmvZOx8dgpmTJXSzadg8MgBzFNGanEfArAj3I31J66LgWXm8hcUKrgu0HubRoOoMwM0Nd3xOuRfl4EN43d9VSz2s6ov5B+vZSVdUgNArmUL4yXFLszdyEx5l+4Zi4VV30/IY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1603372253056441.1108791671237; Thu, 22 Oct 2020 06:10:53 -0700 (PDT) Received: from localhost ([::1]:39918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVaMm-0005FS-Cw for importer@patchew.org; Thu, 22 Oct 2020 09:10:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVaG3-0004wB-HP; Thu, 22 Oct 2020 09:03:55 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:57162 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVaFx-0000gF-MT; Thu, 22 Oct 2020 09:03:55 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E437CE30195E75003329; Thu, 22 Oct 2020 21:03:38 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Thu, 22 Oct 2020 21:03:32 +0800 From: Jiahui Cen To: , , , Subject: [PATCH v3 5/9] block-backend: enable I/O hang when timeout is set Date: Thu, 22 Oct 2020 21:02:59 +0800 Message-ID: <20201022130303.1092-6-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201022130303.1092-1-cenjiahui@huawei.com> References: <20201022130303.1092-1-cenjiahui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.184.155] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.35; envelope-from=cenjiahui@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/22 09:03:40 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cenjiahui@huawei.com, zhang.zhanghailiang@huawei.com, qemu-block@nongnu.org, stefanha@redhat.com, fangying1@huawei.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Setting a non-zero timeout of I/O hang indicates I/O hang is enabled for the block backend. And when the block backend is going to be deleted, we should disable I/O hang. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 40 ++++++++++++++++++++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 41 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index c16d95a2c9..c812b3a9c7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -34,6 +34,7 @@ #define NOT_DONE 0x7fffffff /* used while emulated sync operation in progr= ess */ =20 static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb); +static void blk_rehandle_disable(BlockBackend *blk); =20 /* block backend rehandle timer interval 5s */ #define BLOCK_BACKEND_REHANDLE_TIMER_INTERVAL 5000 @@ -476,6 +477,8 @@ static void blk_delete(BlockBackend *blk) assert(!blk->refcnt); assert(!blk->name); assert(!blk->dev); + assert(qatomic_read(&blk->reinfo.in_flight) =3D=3D 0); + blk_rehandle_disable(blk); if (blk->public.throttle_group_member.throttle_state) { blk_io_limits_disable(blk); } @@ -2629,6 +2632,42 @@ static void blk_rehandle_aio_complete(BlkAioEmAIOCB = *acb) } } =20 +static void blk_rehandle_enable(BlockBackend *blk) +{ + BlockBackendRehandleInfo *reinfo =3D &blk->reinfo; + + aio_context_acquire(blk_get_aio_context(blk)); + if (reinfo->enable) { + aio_context_release(blk_get_aio_context(blk)); + return; + } + + reinfo->ts =3D aio_timer_new(blk_get_aio_context(blk), QEMU_CLOCK_REAL= TIME, + SCALE_MS, blk_rehandle_timer_cb, blk); + reinfo->timer_interval_ms =3D BLOCK_BACKEND_REHANDLE_TIMER_INTERVAL; + reinfo->status =3D BLOCK_BACKEND_REHANDLE_NORMAL; + reinfo->enable =3D true; + aio_context_release(blk_get_aio_context(blk)); +} + +static void blk_rehandle_disable(BlockBackend *blk) +{ + if (!blk->reinfo.enable) { + return; + } + + blk_rehandle_pause(blk); + timer_del(blk->reinfo.ts); + timer_free(blk->reinfo.ts); + blk->reinfo.ts =3D NULL; + blk->reinfo.enable =3D false; +} + +bool blk_iohang_is_enabled(BlockBackend *blk) +{ + return blk->iohang_timeout !=3D 0; +} + void blk_iohang_init(BlockBackend *blk, int64_t iohang_timeout) { if (!blk) { @@ -2641,6 +2680,7 @@ void blk_iohang_init(BlockBackend *blk, int64_t iohan= g_timeout) blk->iohang_status =3D BLOCK_IO_HANG_STATUS_NORMAL; if (iohang_timeout > 0) { blk->iohang_timeout =3D iohang_timeout; + blk_rehandle_enable(blk); } } =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 391a047444..851b90b99b 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -270,6 +270,7 @@ int blk_make_empty(BlockBackend *blk, Error **errp); =20 void blk_rehandle_pause(BlockBackend *blk); void blk_rehandle_unpause(BlockBackend *blk); +bool blk_iohang_is_enabled(BlockBackend *blk); void blk_iohang_init(BlockBackend *blk, int64_t iohang_timeout); =20 #endif --=20 2.19.1