From nobody Tue Feb 10 06:07:57 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=1612520389; cv=none; d=zohomail.com; s=zohoarc; b=nfZglbqV2HNJwYyNPCsmLW4i0xE/GvsL7g6Mvphj0K1RkJPE+5Lu6xySf8kGMxmFLWQo9sjCPh0cwqMl1vUpgoREIKUeKgo4DJdhvH7pgnSnZ96UkRmoTh4HxlzGQ1/4m8HVwOgAs0ocy7KgJkqLTkFhDdjUk9WZC3OzxdC4yN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520389; 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=K4sR2IYg1jLVn81BtJ/qpWyY73zERDMkKCYLtj/75KA=; b=dRcG1j6cSmjYRX+rFjGHvVNFtiHQ/lzIkNke/JfvIkqK2+VFRR77SUaDH4kxcN9FNygn8+piUhj3WJGVcH42ArbiD3MW4pWO98i9Sz1VT9+AbVGATpGqUXa2MxIld4me006P881coXvC9DwPuECr6TogUYvewjZ60mUTTE5YXRA= 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 1612520389556468.59138770347965; Fri, 5 Feb 2021 02:19:49 -0800 (PST) Received: from localhost ([::1]:54230 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yDM-0000Qe-FA for importer@patchew.org; Fri, 05 Feb 2021 05:19:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-0002tR-SD; Fri, 05 Feb 2021 05:13:46 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7U-00075S-FB; Fri, 05 Feb 2021 05:13:46 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DXB6L6n6xzlH0p; Fri, 5 Feb 2021 18:11:54 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:29 +0800 From: Jiahui Cen To: Subject: [PATCH v5 2/9] block-backend: Introduce retry timer Date: Fri, 5 Feb 2021 18:13:08 +0800 Message-ID: <20210205101315.13042-3-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210205101315.13042-1-cenjiahui@huawei.com> References: <20210205101315.13042-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.190; envelope-from=cenjiahui@huawei.com; helo=szxga04-in.huawei.com 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_NONE=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: Kevin Wolf , cenjiahui@huawei.com, zhang.zhanghailiang@huawei.com, qemu-block@nongnu.org, "Michael S. Tsirkin" , Markus Armbruster , Max Reitz , Stefan Hajnoczi , fangying1@huawei.com, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add a timer to regularly trigger retry on errors. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index e493f17515..3a9d55cbe3 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -35,6 +35,9 @@ =20 static AioContext *blk_aiocb_get_aio_context(BlockAIOCB *acb); =20 +/* block backend default retry interval */ +#define BLOCK_BACKEND_DEFAULT_RETRY_INTERVAL 1000 + typedef struct BlockBackendAioNotifier { void (*attached_aio_context)(AioContext *new_context, void *opaque); void (*detach_aio_context)(void *opaque); @@ -95,6 +98,15 @@ struct BlockBackend { * Accessed with atomic ops. */ unsigned int in_flight; + + /* Timer for retry on errors. */ + QEMUTimer *retry_timer; + /* Interval in ms to trigger next retry. */ + int64_t retry_interval; + /* Start time of the first error. Used to check timeout. */ + int64_t retry_start_time; + /* Retry timeout. 0 represents infinite retry. */ + int64_t retry_timeout; }; =20 typedef struct BlockBackendAIOCB { @@ -345,6 +357,11 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, = uint64_t shared_perm) blk->on_read_error =3D BLOCKDEV_ON_ERROR_REPORT; blk->on_write_error =3D BLOCKDEV_ON_ERROR_ENOSPC; =20 + blk->retry_timer =3D NULL; + blk->retry_interval =3D BLOCK_BACKEND_DEFAULT_RETRY_INTERVAL; + blk->retry_start_time =3D 0; + blk->retry_timeout =3D 0; + block_acct_init(&blk->stats); =20 qemu_co_queue_init(&blk->queued_requests); @@ -456,6 +473,10 @@ static void blk_delete(BlockBackend *blk) QTAILQ_REMOVE(&block_backends, blk, link); drive_info_del(blk->legacy_dinfo); block_acct_cleanup(&blk->stats); + if (blk->retry_timer) { + timer_del(blk->retry_timer); + timer_free(blk->retry_timer); + } g_free(blk); } =20 --=20 2.29.2