From nobody Mon Feb 9 10:39:24 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=1612520235; cv=none; d=zohomail.com; s=zohoarc; b=C0rc6eeJbIi4EklDdxJ0/cn9Wg3g2gJtcFGW0m8Y9cPah6Zv+M6FHPOHvDq8vMBWU8R0bNCA+FSfcjh2qmmLqd0j/+Q2/ygCOc3EYARDfHP3jk2/BshmEuqEkNo/GWCMJ9fUulEmVL2UGzDPBjVTib8qdmqdXosUso1REs2SAXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520235; 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=JQ4HJ1UeYLYqlrP1jorVddkpG6HXHnzCjr52euypeXY=; b=MAsk5gbbecODZ+/L4KW2wz8KH2f++ti8KEeixC76Wg+jP+hwagwKwuL+VvZ6sNkulEJC5mInXdLaGaPzb7NzKCDRC9q91TfUbTkYYHhTUcZfK3reD8vgyfSgZ1+AB5EwZkRz/NnBvaCS9tpjtlmNUrlazPmHvueTtpBZwIDd33E= 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 1612520235341312.43095309006264; Fri, 5 Feb 2021 02:17:15 -0800 (PST) Received: from localhost ([::1]:47636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yAs-00065B-8e for importer@patchew.org; Fri, 05 Feb 2021 05:17:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7Z-0002vz-4W; Fri, 05 Feb 2021 05:13:49 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2937) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-00075T-GS; Fri, 05 Feb 2021 05:13:48 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DXB6L61NtzMVqV; Fri, 5 Feb 2021 18:11:54 +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.498.0; Fri, 5 Feb 2021 18:13:29 +0800 From: Jiahui Cen To: Subject: [PATCH v5 1/9] qapi/block-core: Add retry option for error action Date: Fri, 5 Feb 2021 18:13:07 +0800 Message-ID: <20210205101315.13042-2-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.191; envelope-from=cenjiahui@huawei.com; helo=szxga05-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_H2=-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 new error action 'retry' to support retry on errors. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- blockdev.c | 2 ++ qapi/block-core.json | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index b250b9b959..ece1d8ae58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -342,6 +342,8 @@ static int parse_block_error_action(const char *buf, bo= ol is_read, Error **errp) return BLOCKDEV_ON_ERROR_STOP; } else if (!strcmp(buf, "report")) { return BLOCKDEV_ON_ERROR_REPORT; + } else if (!strcmp(buf, "retry")) { + return BLOCKDEV_ON_ERROR_RETRY; } else { error_setg(errp, "'%s' invalid %s error action", buf, is_read ? "read" : "write"); diff --git a/qapi/block-core.json b/qapi/block-core.json index 9f555d5c1d..30ea43cb77 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1143,10 +1143,13 @@ # # @auto: inherit the error handling policy of the backend (since: 2.7) # +# @retry: for guest operations, retry the failing request; (since: 6.0) +# for jobs, not supported +# # Since: 1.3 ## { 'enum': 'BlockdevOnError', - 'data': ['report', 'ignore', 'enospc', 'stop', 'auto'] } + 'data': ['report', 'ignore', 'enospc', 'stop', 'auto', 'retry'] } =20 ## # @MirrorSyncMode: @@ -4839,10 +4842,12 @@ # # @stop: error caused VM to be stopped # +# @retry: error has been retried (since: 6.0) +# # Since: 2.1 ## { 'enum': 'BlockErrorAction', - 'data': [ 'ignore', 'report', 'stop' ] } + 'data': [ 'ignore', 'report', 'stop', 'retry' ] } =20 =20 ## --=20 2.29.2 From nobody Mon Feb 9 10:39:24 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 From nobody Mon Feb 9 10:39:24 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=1612520689; cv=none; d=zohomail.com; s=zohoarc; b=JLx+18UqCdscWbfjAInhebSwFtjgNjEf/5o2NqX2Q42MfKSKxQkC2Ax8n+rYejoGP2ygiYt6N7ev1zXpbu8bCEkysZ3/EkHMjEnD6uyPBqrJljg8dr/8KZJufoMNQIDJIkPfd/uXkFVKF/vI8r6yPc7IiaYVsfDWfQ7HicbgMo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520689; 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=brBLad/DmjWUrkT+Ait4D/IWOhHDSEgTb2RLfaUvp1M=; b=SIaXJ1d6A7UhSdfWfCzhZWZsdwPt+VDfbzQvAZy43Q/Rcu0lZG/qbFcHdvy8KopcR58vQty8l9LCD9KoIeU1/9gPorYHmThb5BaWBUmfqJ8gddN2sJ+35H+nU1D6wpko47kGLXLqMzHYOn7SaSC7oCzJjC6ff2ULppEk/5dw1sM= 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 1612520689852330.1180907403875; Fri, 5 Feb 2021 02:24:49 -0800 (PST) Received: from localhost ([::1]:40644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yIC-0006di-LE for importer@patchew.org; Fri, 05 Feb 2021 05:24:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7b-000319-M2; Fri, 05 Feb 2021 05:13:51 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7Y-00077Y-Aq; Fri, 05 Feb 2021 05:13:51 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DXB6s1hqjz7h16; Fri, 5 Feb 2021 18:12:21 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:30 +0800 From: Jiahui Cen To: Subject: [PATCH v5 3/9] block-backend: Add device specific retry callback Date: Fri, 5 Feb 2021 18:13:09 +0800 Message-ID: <20210205101315.13042-4-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.35; envelope-from=cenjiahui@huawei.com; helo=szxga07-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 retry_request_cb in BlockDevOps to do device specific retry action. Backend's timer would be registered only when the backend is set 'retry' on errors and the device supports retry action. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 8 ++++++++ include/sysemu/block-backend.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 3a9d55cbe3..a8bfaf6e4a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -995,6 +995,14 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDev= Ops *ops, blk->dev_ops =3D ops; blk->dev_opaque =3D opaque; =20 + if ((blk->on_read_error =3D=3D BLOCKDEV_ON_ERROR_RETRY || + blk->on_write_error =3D=3D BLOCKDEV_ON_ERROR_RETRY) && + ops->retry_request_cb) { + blk->retry_timer =3D aio_timer_new(blk->ctx, QEMU_CLOCK_REALTIME, + SCALE_MS, ops->retry_request_cb, + opaque); + } + /* Are we currently quiesced? Should we enforce this right now? */ if (blk->quiesce_counter && ops->drained_begin) { ops->drained_begin(opaque); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 880e903293..d806852db5 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -66,6 +66,10 @@ typedef struct BlockDevOps { * Runs when the backend's last drain request ends. */ void (*drained_end)(void *opaque); + /* + * Runs when retrying failed requests. + */ + void (*retry_request_cb)(void *opaque); } BlockDevOps; =20 /* This struct is embedded in (the private) BlockBackend struct and contai= ns --=20 2.29.2 From nobody Mon Feb 9 10:39:24 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=1612520162; cv=none; d=zohomail.com; s=zohoarc; b=QB00Oe7vgVCF9CMEXoNSVmc9B3ARzNI2WXd/DHuWyZc2i+ygNwAVv5w61EuO0Eo4ACqw2WQO1jqICOfGavfuqExrjXhSGCGM9TWr3qzWrziSFuMROdknR7llIVKn4DqbNnNXscd62eE3LVXFVr6lqYE7jfnQbcLyPr++PXaFXS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520162; 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=Kuc0QvOo8nKmVsHrysnxnFPhbTDLvW3lEHZXhP4VQ6E=; b=ItORxeRjekP7SsItyWmCXkEOSxGjtYP+3cjfzccRggvUP6bRxqDgcFKIjfdSdprHHsKtC+ijqsUPRiytO3p2hSWiJ0YEmpXMFgAb86wTIEScoOItpwAqt9EHGtqbN+a3JBP8q8TwlAoxxzEMn2q+Bj9GSgmzGidXBTShvCglyC4= 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 1612520162243248.25518950159847; Fri, 5 Feb 2021 02:16:02 -0800 (PST) Received: from localhost ([::1]:45344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7y9g-00056r-2s for importer@patchew.org; Fri, 05 Feb 2021 05:16:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7b-00030R-D9; Fri, 05 Feb 2021 05:13:51 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:3043) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7Y-000769-BC; Fri, 05 Feb 2021 05:13:51 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DXB751bPqzjGSt; Fri, 5 Feb 2021 18:12:33 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:30 +0800 From: Jiahui Cen To: Subject: [PATCH v5 4/9] block-backend: Enable retry action on errors Date: Fri, 5 Feb 2021 18:13:10 +0800 Message-ID: <20210205101315.13042-5-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.32; envelope-from=cenjiahui@huawei.com; helo=szxga06-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" Enable retry action when backend's retry timer is available. It would trigger the timer to do device specific retry action. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index a8bfaf6e4a..ab75cb1971 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1803,6 +1803,9 @@ BlockErrorAction blk_get_error_action(BlockBackend *b= lk, bool is_read, return BLOCK_ERROR_ACTION_REPORT; case BLOCKDEV_ON_ERROR_IGNORE: return BLOCK_ERROR_ACTION_IGNORE; + case BLOCKDEV_ON_ERROR_RETRY: + return (blk->retry_timer) ? + BLOCK_ERROR_ACTION_RETRY : BLOCK_ERROR_ACTION_REPORT; case BLOCKDEV_ON_ERROR_AUTO: default: abort(); @@ -1850,6 +1853,12 @@ void blk_error_action(BlockBackend *blk, BlockErrorA= ction action, qemu_system_vmstop_request_prepare(); send_qmp_error_event(blk, action, is_read, error); qemu_system_vmstop_request(RUN_STATE_IO_ERROR); + } else if (action =3D=3D BLOCK_ERROR_ACTION_RETRY) { + if (!blk->quiesce_counter) { + timer_mod(blk->retry_timer, qemu_clock_get_ms(QEMU_CLOCK_REALT= IME) + + blk->retry_interval); + send_qmp_error_event(blk, action, is_read, error); + } } else { send_qmp_error_event(blk, action, is_read, error); } --=20 2.29.2 From nobody Mon Feb 9 10:39:25 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=1612520870; cv=none; d=zohomail.com; s=zohoarc; b=O5xkq8YHSYoCAShXh7/noNQX/ZlN0FJZqbSl0djvc3BkMUix/Az47D8BX2+KcvgxO+7dks2ENSKn0s0ViRZu6ZaDBr3wV7ZEtfX+/AO/Jv9AGEl4Vixgw9IWgFq30lRJFnk0z7Rcw306Z+EHnej8rU645oGpa8c7dpjiyPx2r44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520870; 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=WgqKmVQ4ZuqXYJ61lzNFEhGT1rMrEEYruuSX6UuR4pY=; b=OlnKVY3Eqc7B/qI1fUk99DzIVlwyiyZbwF5/nDCsQaDvhGt1XmQBchFa1Keljosfcr8dY3fdjDFVjhiprn0LZ+XeZyCxsJL009UxcLwvlR5ry58usp+52QpdMigWFEAqpRp1ea8fPgLj1db+BocO1bEKtGZZ+7OpOyi99G6JzFU= 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 1612520870173873.7318111474066; Fri, 5 Feb 2021 02:27:50 -0800 (PST) Received: from localhost ([::1]:47890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yL7-0001Lg-1S for importer@patchew.org; Fri, 05 Feb 2021 05:27:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7c-00032O-3J; Fri, 05 Feb 2021 05:13:52 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-00076r-LZ; Fri, 05 Feb 2021 05:13:51 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DXB6q64bXz7h5Y; Fri, 5 Feb 2021 18:12:19 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:31 +0800 From: Jiahui Cen To: Subject: [PATCH v5 5/9] block-backend: Add timeout support for retry Date: Fri, 5 Feb 2021 18:13:11 +0800 Message-ID: <20210205101315.13042-6-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.35; envelope-from=cenjiahui@huawei.com; helo=szxga07-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" Retry should only be triggered when timeout is not reached, so let's check timeout before retry. Device should also reset retry_start_time after successful retry. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 25 +++++++++++++++++++- include/sysemu/block-backend.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index ab75cb1971..8ad1e5105d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1776,6 +1776,29 @@ void blk_drain_all(void) bdrv_drain_all_end(); } =20 +static bool blk_error_retry_timeout(BlockBackend *blk) +{ + /* No timeout set, infinite retries. */ + if (!blk->retry_timeout) { + return false; + } + + /* The first time an error occurs. */ + if (!blk->retry_start_time) { + blk->retry_start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + return false; + } + + return qemu_clock_get_ms(QEMU_CLOCK_REALTIME) > (blk->retry_start_time= + + blk->retry_timeout); +} + +void blk_error_retry_reset_timeout(BlockBackend *blk) +{ + if (blk->retry_timer && blk->retry_start_time) + blk->retry_start_time =3D 0; +} + void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, BlockdevOnError on_write_error) { @@ -1804,7 +1827,7 @@ BlockErrorAction blk_get_error_action(BlockBackend *b= lk, bool is_read, case BLOCKDEV_ON_ERROR_IGNORE: return BLOCK_ERROR_ACTION_IGNORE; case BLOCKDEV_ON_ERROR_RETRY: - return (blk->retry_timer) ? + return (blk->retry_timer && !blk_error_retry_timeout(blk)) ? BLOCK_ERROR_ACTION_RETRY : BLOCK_ERROR_ACTION_REPORT; case BLOCKDEV_ON_ERROR_AUTO: default: diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d806852db5..286d2db918 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -188,6 +188,7 @@ void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); void blk_drain(BlockBackend *blk); void blk_drain_all(void); +void blk_error_retry_reset_timeout(BlockBackend *blk); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, BlockdevOnError on_write_error); BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read); --=20 2.29.2 From nobody Mon Feb 9 10:39:25 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=1612520352; cv=none; d=zohomail.com; s=zohoarc; b=HA+JDwwxOgoew/inZFRJuVG8Fu/Oa49d28gYUtIA9SLV8aTuPAUZPyUlT4zSKvk2GN6RjecgQhtGAr/bBwbfxbjRRgfQ3vthkgbjoK4cRVInOFzvfT9VNUKuzt7bB3o55gl4wSEV9Vn8VaqvUyrU8xZJqRu4X45Mq0hI8NkpER8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520352; 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=MP/jWVlZaa+gFMY3KvDMf4VBcWszGeFDWIrlFtnqwbU=; b=azAJXFKVMQtthhHjABE9D/tv3m2UyD/2jq5rlbr2eix7rqHjypBizd9zHRkPBeBy7nH6hUWd0cugl6ou9DiRK4/BfDHnzwUNE5Oh+P6m0ZcvuIdvjS7AizDNHYuL8WGa2qzyzeKr5FhiTJId4Vm3aSuUDqSolxK9B9XKv8X8DN0= 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 1612520352077971.9457268090637; Fri, 5 Feb 2021 02:19:12 -0800 (PST) Received: from localhost ([::1]:53210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yCk-0008Rx-LJ for importer@patchew.org; Fri, 05 Feb 2021 05:19:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7a-0002yE-CD; Fri, 05 Feb 2021 05:13:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-000768-EH; Fri, 05 Feb 2021 05:13:50 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DXB6n5szCzjKVY; Fri, 5 Feb 2021 18:12:17 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:32 +0800 From: Jiahui Cen To: Subject: [PATCH v5 6/9] block: Add error retry param setting Date: Fri, 5 Feb 2021 18:13:12 +0800 Message-ID: <20210205101315.13042-7-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.191; envelope-from=cenjiahui@huawei.com; helo=szxga05-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_H2=-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 "retry_interval" and "retry_timeout" parameter for drive and device option. These parameter are valid only when werror/rerror=3Dretry. eg. --drive file=3Dimage,rerror=3Dretry,retry_interval=3D1000,retry_timeout= =3D5000 Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- block/block-backend.c | 13 +++-- blockdev.c | 50 ++++++++++++++++++++ hw/block/block.c | 10 ++++ include/hw/block/block.h | 7 ++- include/sysemu/block-backend.h | 5 ++ 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 8ad1e5105d..b97aba7110 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -35,9 +35,6 @@ =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); @@ -1776,6 +1773,16 @@ void blk_drain_all(void) bdrv_drain_all_end(); } =20 +void blk_set_on_error_retry_interval(BlockBackend *blk, int64_t interval) +{ + blk->retry_interval =3D interval; +} + +void blk_set_on_error_retry_timeout(BlockBackend *blk, int64_t timeout) +{ + blk->retry_timeout =3D timeout; +} + static bool blk_error_retry_timeout(BlockBackend *blk) { /* No timeout set, infinite retries. */ diff --git a/blockdev.c b/blockdev.c index ece1d8ae58..9b2cfdef78 100644 --- a/blockdev.c +++ b/blockdev.c @@ -489,6 +489,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, const char *buf; int bdrv_flags =3D 0; int on_read_error, on_write_error; + int64_t retry_interval, retry_timeout; bool account_invalid, account_failed; bool writethrough, read_only; BlockBackend *blk; @@ -581,6 +582,10 @@ static BlockBackend *blockdev_init(const char *file, Q= Dict *bs_opts, } } =20 + retry_interval =3D qemu_opt_get_number(opts, "retry_interval", + BLOCK_BACKEND_DEFAULT_RETRY_INTER= VAL); + retry_timeout =3D qemu_opt_get_number(opts, "retry_timeout", 0); + if (snapshot) { bdrv_flags |=3D BDRV_O_SNAPSHOT; } @@ -645,6 +650,11 @@ static BlockBackend *blockdev_init(const char *file, Q= Dict *bs_opts, =20 blk_set_enable_write_cache(blk, !writethrough); blk_set_on_error(blk, on_read_error, on_write_error); + if (on_read_error =3D=3D BLOCKDEV_ON_ERROR_RETRY || + on_write_error =3D=3D BLOCKDEV_ON_ERROR_RETRY) { + blk_set_on_error_retry_interval(blk, retry_interval); + blk_set_on_error_retry_timeout(blk, retry_timeout); + } =20 if (!monitor_add_blk(blk, id, errp)) { blk_unref(blk); @@ -771,6 +781,14 @@ QemuOptsList qemu_legacy_drive_opts =3D { .name =3D "werror", .type =3D QEMU_OPT_STRING, .help =3D "write error action", + },{ + .name =3D "retry_interval", + .type =3D QEMU_OPT_NUMBER, + .help =3D "interval for retry action in millisecond", + },{ + .name =3D "retry_timeout", + .type =3D QEMU_OPT_NUMBER, + .help =3D "timeout for retry action in millisecond", },{ .name =3D "copy-on-read", .type =3D QEMU_OPT_BOOL, @@ -793,6 +811,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type, BlockInterfaceType type; int max_devs, bus_id, unit_id, index; const char *werror, *rerror; + int64_t retry_interval, retry_timeout; bool read_only =3D false; bool copy_on_read; const char *filename; @@ -1004,6 +1023,29 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterf= aceType block_default_type, qdict_put_str(bs_opts, "rerror", rerror); } =20 + if (qemu_opt_find(legacy_opts, "retry_interval")) { + if ((werror =3D=3D NULL || strcmp(werror, "retry")) && + (rerror =3D=3D NULL || strcmp(rerror, "retry"))) { + error_setg(errp, "retry_interval is only supported " + "by werror/rerror=3Dretry"); + goto fail; + } + retry_interval =3D qemu_opt_get_number(legacy_opts, "retry_interva= l", + BLOCK_BACKEND_DEFAULT_RETRY_INTERVAL); + qdict_put_int(bs_opts, "retry_interval", retry_interval); + } + + if (qemu_opt_find(legacy_opts, "retry_timeout")) { + if ((werror =3D=3D NULL || strcmp(werror, "retry")) && + (rerror =3D=3D NULL || strcmp(rerror, "retry"))) { + error_setg(errp, "retry_timeout is only supported " + "by werror/rerror=3Dretry"); + goto fail; + } + retry_timeout =3D qemu_opt_get_number(legacy_opts, "retry_timeout"= , 0); + qdict_put_int(bs_opts, "retry_timeout", retry_timeout); + } + /* Actual block device init: Functionality shared with blockdev-add */ blk =3D blockdev_init(filename, bs_opts, errp); bs_opts =3D NULL; @@ -3820,6 +3862,14 @@ QemuOptsList qemu_common_drive_opts =3D { .name =3D "werror", .type =3D QEMU_OPT_STRING, .help =3D "write error action", + },{ + .name =3D "retry_interval", + .type =3D QEMU_OPT_NUMBER, + .help =3D "interval for retry action in millisecond", + },{ + .name =3D "retry_timeout", + .type =3D QEMU_OPT_NUMBER, + .help =3D "timeout for retry action in millisecond", },{ .name =3D BDRV_OPT_READ_ONLY, .type =3D QEMU_OPT_BOOL, diff --git a/hw/block/block.c b/hw/block/block.c index 1e34573da7..d2f35dc465 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -172,6 +172,16 @@ bool blkconf_apply_backend_options(BlockConf *conf, bo= ol readonly, blk_set_enable_write_cache(blk, wce); blk_set_on_error(blk, rerror, werror); =20 + if (rerror =3D=3D BLOCKDEV_ON_ERROR_RETRY || + werror =3D=3D BLOCKDEV_ON_ERROR_RETRY) { + if (conf->retry_interval >=3D 0) { + blk_set_on_error_retry_interval(blk, conf->retry_interval); + } + if (conf->retry_timeout >=3D 0) { + blk_set_on_error_retry_timeout(blk, conf->retry_timeout); + } + } + return true; } =20 diff --git a/include/hw/block/block.h b/include/hw/block/block.h index c172cbe65f..a8e77fae68 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -32,6 +32,8 @@ typedef struct BlockConf { bool share_rw; BlockdevOnError rerror; BlockdevOnError werror; + int64_t retry_interval; + int64_t retry_timeout; } BlockConf; =20 static inline unsigned int get_physical_block_exp(BlockConf *conf) @@ -76,7 +78,10 @@ static inline unsigned int get_physical_block_exp(BlockC= onf *conf) DEFINE_PROP_BLOCKDEV_ON_ERROR("rerror", _state, _conf.rerror, \ BLOCKDEV_ON_ERROR_AUTO), \ DEFINE_PROP_BLOCKDEV_ON_ERROR("werror", _state, _conf.werror, \ - BLOCKDEV_ON_ERROR_AUTO) + BLOCKDEV_ON_ERROR_AUTO), \ + DEFINE_PROP_INT64("retry_interval", _state, _conf.retry_interval, \ + -1), \ + DEFINE_PROP_INT64("retry_timeout", _state, _conf.retry_timeout, -1) =20 /* Backend access helpers */ =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 286d2db918..aecfa25b33 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -25,6 +25,9 @@ */ #include "block/block.h" =20 +/* block backend default retry interval */ +#define BLOCK_BACKEND_DEFAULT_RETRY_INTERVAL 1000 + /* Callbacks for block device models */ typedef struct BlockDevOps { /* @@ -188,6 +191,8 @@ void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); void blk_drain(BlockBackend *blk); void blk_drain_all(void); +void blk_set_on_error_retry_interval(BlockBackend *blk, int64_t interval); +void blk_set_on_error_retry_timeout(BlockBackend *blk, int64_t timeout); void blk_error_retry_reset_timeout(BlockBackend *blk); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, BlockdevOnError on_write_error); --=20 2.29.2 From nobody Mon Feb 9 10:39:25 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=1612520114; cv=none; d=zohomail.com; s=zohoarc; b=nmZ5r/Us/ofeocXiwYogVzrkFweKcAzKfePY4JAB2ESyoeFnZcuiYIIMRZqWAjzaSxm/YRobSJG2eEcHZC+hJ2+swwiL54GYihUS08WnycAywoaspEJ1lIxmolyQKW6Ci1l1llDFBXLyWexKjl2czaGok7917omuVpHN3/pmRjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520114; 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=ExpflIW9oZoaqhwjFYpcAV0yXUGTrvYGkDT8OQ8ANS4=; b=C+8hu7d+VHqoC8FQ0pDMtmMz8tCEH9NoNPKDtRAcuAM+ydWZ9gW5dbExMgdk3DzjCPlb8kiNptNX8/l680eNOU4AZGbVFyzWVeLzF8RutBRw6U7cDmEbnX6TqAsE6GNzqoHUQ+N/NzV5leKHYBRU1jouMb59fE5iVgLPK7NOtZs= 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 16125201149341009.0878406649495; Fri, 5 Feb 2021 02:15:14 -0800 (PST) Received: from localhost ([::1]:44094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7y8v-0004aq-N5 for importer@patchew.org; Fri, 05 Feb 2021 05:15:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7Z-0002wa-HH; Fri, 05 Feb 2021 05:13:49 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-00078Q-7h; Fri, 05 Feb 2021 05:13:49 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DXB6T2R83zMW3L; Fri, 5 Feb 2021 18:12:01 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:32 +0800 From: Jiahui Cen To: Subject: [PATCH v5 7/9] virtio_blk: Add support for retry on errors Date: Fri, 5 Feb 2021 18:13:13 +0800 Message-ID: <20210205101315.13042-8-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.191; envelope-from=cenjiahui@huawei.com; helo=szxga05-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_H2=-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" Insert failed requests into device's list for later retry and handle queued requests to implement retry_request_cb. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- hw/block/virtio-blk.c | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index e8600b069d..58f098fb9c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -108,6 +108,10 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *= req, int error, block_acct_failed(blk_get_stats(s->blk), &req->acct); } virtio_blk_free_request(req); + } else if (action =3D=3D BLOCK_ERROR_ACTION_RETRY) { + req->mr_next =3D NULL; + req->next =3D s->rq; + s->rq =3D req; } =20 blk_error_action(s->blk, action, is_read, error); @@ -149,6 +153,7 @@ static void virtio_blk_rw_complete(void *opaque, int re= t) } } =20 + blk_error_retry_reset_timeout(s->blk); virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); block_acct_done(blk_get_stats(s->blk), &req->acct); virtio_blk_free_request(req); @@ -168,6 +173,7 @@ static void virtio_blk_flush_complete(void *opaque, int= ret) } } =20 + blk_error_retry_reset_timeout(s->blk); virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); block_acct_done(blk_get_stats(s->blk), &req->acct); virtio_blk_free_request(req); @@ -190,6 +196,7 @@ static void virtio_blk_discard_write_zeroes_complete(vo= id *opaque, int ret) } } =20 + blk_error_retry_reset_timeout(s->blk); virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); if (is_write_zeroes) { block_acct_done(blk_get_stats(s->blk), &req->acct); @@ -828,12 +835,12 @@ static void virtio_blk_handle_output(VirtIODevice *vd= ev, VirtQueue *vq) =20 void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh) { - VirtIOBlockReq *req =3D s->rq; + VirtIOBlockReq *req; MultiReqBuffer mrb =3D {}; =20 - s->rq =3D NULL; - aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); + req =3D s->rq; + s->rq =3D NULL; while (req) { VirtIOBlockReq *next =3D req->next; if (virtio_blk_handle_request(req, &mrb)) { @@ -1134,8 +1141,16 @@ static void virtio_blk_resize(void *opaque) aio_bh_schedule_oneshot(qemu_get_aio_context(), virtio_resize_cb, vdev= ); } =20 +static void virtio_blk_retry_request(void *opaque) +{ + VirtIOBlock *s =3D VIRTIO_BLK(opaque); + + virtio_blk_process_queued_requests(s, false); +} + static const BlockDevOps virtio_block_ops =3D { .resize_cb =3D virtio_blk_resize, + .retry_request_cb =3D virtio_blk_retry_request, }; =20 static void virtio_blk_device_realize(DeviceState *dev, Error **errp) --=20 2.29.2 From nobody Mon Feb 9 10:39:25 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=1612520592; cv=none; d=zohomail.com; s=zohoarc; b=e2Cn4HnejyWwGT7Ptsi2M43r7oZPEYwf6tX3rU3zZ40k89lvqeAziH2u1g9HYkELuycWr8KqiCKZi4i+U6uKvX5lBHRGD/vCYVVkMgL3MbONACnI7t8cZjt85evJDLPaRiDI2+lcyibh3OGEQg/UZxTK+8fxsykivkVej5OtDMo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520592; 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=Zd/V82bhc5XG+R+IYYF9wrDNzPxcn1ZF4GX9xSpxLyo=; b=TIoWvl+SNmLSwyAiu0nK8UYkLL8Sj5IxpSaP/4I1oWyHL11MIzCumthhGSjCoWORWJxOU1d54UDAtZ7Gk8Q+siHBUcOlYotV+M9q2J+V8yPejyhIBtPMuDUsW7DonL9+oky0m/gpPhOmqtWC7aDvDrm2yMWb/1di+l6cvwBpyYI= 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 1612520592561925.6319230799772; Fri, 5 Feb 2021 02:23:12 -0800 (PST) Received: from localhost ([::1]:33810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yGd-0003om-Dh for importer@patchew.org; Fri, 05 Feb 2021 05:23:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7X-0002uQ-TL; Fri, 05 Feb 2021 05:13:47 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7U-00077b-JS; Fri, 05 Feb 2021 05:13:47 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DXB6s0Yrzz164WY; Fri, 5 Feb 2021 18:12:21 +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:33 +0800 From: Jiahui Cen To: Subject: [PATCH v5 8/9] scsi-bus: Refactor the code that retries requests Date: Fri, 5 Feb 2021 18:13:14 +0800 Message-ID: <20210205101315.13042-9-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" Move the code that retries requests from scsi_dma_restart_bh() to its own, non-static, function. This will allow us to call it from the retry_request_cb() of scsi-disk in a future patch. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- hw/scsi/scsi-bus.c | 16 +++++++++++----- include/hw/scsi/scsi.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index c349fb7f2d..b2a174efe2 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -143,14 +143,10 @@ void scsi_bus_new(SCSIBus *bus, size_t bus_size, Devi= ceState *host, qbus_set_bus_hotplug_handler(BUS(bus)); } =20 -static void scsi_dma_restart_bh(void *opaque) +void scsi_retry_requests(SCSIDevice *s) { - SCSIDevice *s =3D opaque; SCSIRequest *req, *next; =20 - qemu_bh_delete(s->bh); - s->bh =3D NULL; - aio_context_acquire(blk_get_aio_context(s->conf.blk)); QTAILQ_FOREACH_SAFE(req, &s->requests, next, next) { scsi_req_ref(req); @@ -170,6 +166,16 @@ static void scsi_dma_restart_bh(void *opaque) scsi_req_unref(req); } aio_context_release(blk_get_aio_context(s->conf.blk)); +} + +static void scsi_dma_restart_bh(void *opaque) +{ + SCSIDevice *s =3D opaque; + + qemu_bh_delete(s->bh); + s->bh =3D NULL; + + scsi_retry_requests(s); /* Drop the reference that was acquired in scsi_dma_restart_cb */ object_unref(OBJECT(s)); } diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 09fa5c9d2a..28f330deaf 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -181,6 +181,7 @@ void scsi_req_cancel_complete(SCSIRequest *req); void scsi_req_cancel(SCSIRequest *req); void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier); void scsi_req_retry(SCSIRequest *req); +void scsi_retry_requests(SCSIDevice *s); void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense); void scsi_device_report_change(SCSIDevice *dev, SCSISense sense); --=20 2.29.2 From nobody Mon Feb 9 10:39:25 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=1612520696; cv=none; d=zohomail.com; s=zohoarc; b=YXu2nIFYFyTpZ98wiWr2sOmLjLNGjz5wM+4aZBpyVvib6HggBLxlpvO6q3CLqVu8TE4x8FuLKdJWhgXxk0laYFajwBJgKAU59egPRfQikhubiXa2pk37CPPF0WlH2xQ4o6fyzn73eu5+UovHXvFTAO+bGvGSA9zPJjLmlTz5MPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612520696; 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=XyQihX/ntmpQECxAyG2ufg5wXkkm10/wr2QPwbyue08=; b=Kzwy5N7ItUUr6OmkvnnS4gCZKCdHBQIV5sLuqSyQG53J3KI5IQCnrtIHT0XFotO59u9mEXOCnO/CGvU6MuZhCo0L4Ss0wqO2LN8sTnbpHY5bMa9Gn/W4VgAc4bbT49WzUuV/nK4dpUsJkUk2Aqz0QRtzWa+GO5ySGYq1+N4yGz4= 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 1612520696601876.634566644707; Fri, 5 Feb 2021 02:24:56 -0800 (PST) Received: from localhost ([::1]:41172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7yII-0006t1-Es for importer@patchew.org; Fri, 05 Feb 2021 05:24:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7Z-0002wU-G1; Fri, 05 Feb 2021 05:13:49 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7y7W-00078Y-EI; Fri, 05 Feb 2021 05:13:49 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DXB6v3Nzfz164xB; Fri, 5 Feb 2021 18:12:23 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Fri, 5 Feb 2021 18:13:33 +0800 From: Jiahui Cen To: Subject: [PATCH v5 9/9] scsi-disk: Add support for retry on errors Date: Fri, 5 Feb 2021 18:13:15 +0800 Message-ID: <20210205101315.13042-10-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" Mark failed requests as to be retried and implement retry_request_cb to handle these requests. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang --- hw/scsi/scsi-disk.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index ed52fcd49f..687ed19822 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -184,6 +184,8 @@ static void scsi_disk_load_request(QEMUFile *f, SCSIReq= uest *req) =20 static bool scsi_disk_req_check_error(SCSIDiskReq *r, int ret, bool acct_f= ailed) { + SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); + if (r->req.io_canceled) { scsi_req_cancel_complete(&r->req); return true; @@ -193,6 +195,7 @@ static bool scsi_disk_req_check_error(SCSIDiskReq *r, i= nt ret, bool acct_failed) return scsi_handle_rw_error(r, -ret, acct_failed); } =20 + blk_error_retry_reset_timeout(s->qdev.conf.blk); return false; } =20 @@ -499,6 +502,10 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int e= rror, bool acct_failed) } } =20 + if (action =3D=3D BLOCK_ERROR_ACTION_RETRY) { + scsi_req_retry(&r->req); + } + blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action =3D=3D BLOCK_ERROR_ACTION_IGNORE) { scsi_req_complete(&r->req, 0); @@ -2284,6 +2291,13 @@ static void scsi_disk_resize_cb(void *opaque) } } =20 +static void scsi_disk_retry_request(void *opaque) +{ + SCSIDiskState *s =3D opaque; + + scsi_retry_requests(&s->qdev); +} + static void scsi_cd_change_media_cb(void *opaque, bool load, Error **errp) { SCSIDiskState *s =3D opaque; @@ -2332,10 +2346,12 @@ static const BlockDevOps scsi_disk_removable_block_= ops =3D { .is_medium_locked =3D scsi_cd_is_medium_locked, =20 .resize_cb =3D scsi_disk_resize_cb, + .retry_request_cb =3D scsi_disk_retry_request, }; =20 static const BlockDevOps scsi_disk_block_ops =3D { .resize_cb =3D scsi_disk_resize_cb, + .retry_request_cb =3D scsi_disk_retry_request, }; =20 static void scsi_disk_unit_attention_reported(SCSIDevice *dev) --=20 2.29.2