From nobody Tue Nov 18 06:06:13 2025 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=1608035591; cv=none; d=zohomail.com; s=zohoarc; b=WUstRGr9A1q4qYxLW5as3f/9HfLPArU4HEPy+Nwtq8/HD2NqDiKOGhIQ+H6skO/95yenC2HdW7H36KD0ymSMBALg/kLfCx/QamPmFU59vcYJwNJoKC+j4jhvgQYLh7GRHIwQcNdJLmAWMoR/qmoPDeu1yEG5J1RUZkiWHvjxO8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608035591; 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=Y+ymLtydSZHgwrvJi9uplc50zyCkzOcY26XaOX4PE9A=; b=ICXaQfofHMfh3t4AiaTmseC3IVleb2bOxzjFWl8E5pVdURDsNirE2saP8pLZoJgfWSxQlUEixbHgl6L/7JIjTlZdQe2ppDtwyVHWuFar1QYc840vnV39Q4FYECzG/8QYflx8maBWKoL5u7JiKVvu3PQ+WiUxHFT8udRBxxZ9Phk= 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 1608035591983565.0223148391547; Tue, 15 Dec 2020 04:33:11 -0800 (PST) Received: from localhost ([::1]:33740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9Vu-00015B-Lv for importer@patchew.org; Tue, 15 Dec 2020 07:33:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tc-0007kU-V2; Tue, 15 Dec 2020 07:30:48 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9TX-0006ru-UG; Tue, 15 Dec 2020 07:30:48 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CwHdj3SY1zhs6y; Tue, 15 Dec 2020 20:30:01 +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; Tue, 15 Dec 2020 20:30:24 +0800 From: Jiahui Cen To: Subject: [PATCH v4 1/7] qapi/block-core: Add retry option for error action Date: Tue, 15 Dec 2020 20:30:05 +0800 Message-ID: <20201215123011.4048-2-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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" 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 | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 412354b4b6..47c0e6db52 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 04c5196e59..ef5492bcdf 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1146,7 +1146,7 @@ # Since: 1.3 ## { 'enum': 'BlockdevOnError', - 'data': ['report', 'ignore', 'enospc', 'stop', 'auto'] } + 'data': ['report', 'ignore', 'enospc', 'stop', 'auto', 'retry'] } =20 ## # @MirrorSyncMode: @@ -4770,7 +4770,7 @@ # Since: 2.1 ## { 'enum': 'BlockErrorAction', - 'data': [ 'ignore', 'report', 'stop' ] } + 'data': [ 'ignore', 'report', 'stop', 'retry' ] } =20 =20 ## --=20 2.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608038933; cv=none; d=zohomail.com; s=zohoarc; b=OHA4TB28n9/eTHBcpBKEWK3mkMMPNIpdOjW2oPpjHWy3sz6eLs1nJP25/p48IJxq+57b76ZpWi8Q8sD+TZQAKK40QgFciEXffE6orEXJ2G9QC1Dq6CJCrnO8itPBPwNwodngQotF3SWUS+PdQIHhpvfaJSAwMWRhp7pBgpuWAqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608038933; 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=wRwHRNYvFhPzqYd8TX1qmZgDZb4dqVltafiORvSvRrw=; b=MuAGNibe02Y9ZuJZ5Bcc7zv21ABS24oIrTyb1elbDUM7vLrYIKfD4w9A9hMGPm4tORhEUYxoYD0WDMI6IhysAmFBJjf9Ie2S92Dqf94eTgGr/oWGdYIORq34iC9lmCQsB9TbVPrzxdUg1yF//7H9Cwv+4aSwB2cPqKVRbLDahv0= 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 1608038933493342.7628336973428; Tue, 15 Dec 2020 05:28:53 -0800 (PST) Received: from localhost ([::1]:52884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9cO-0000j6-9P for importer@patchew.org; Tue, 15 Dec 2020 07:39:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tl-0007uE-8T; Tue, 15 Dec 2020 07:30:57 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tc-0006ud-Pz; Tue, 15 Dec 2020 07:30:57 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CwHdN6Ql9zkqXY; Tue, 15 Dec 2020 20:29:44 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 20:30:25 +0800 From: Jiahui Cen To: Subject: [PATCH v4 2/7] block-backend: Introduce retry timer Date: Tue, 15 Dec 2020 20:30:06 +0800 Message-ID: <20201215123011.4048-3-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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 ce78d30794..fe775ea298 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.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608039201; cv=none; d=zohomail.com; s=zohoarc; b=G2DRmrt/roXLMCfw5Pokjm3TH/hQ8o0rnEBvCqqyBt0UB0gwv/rjQzT9yQJVT1CzUfCOBSRFHTVQRI2IcdTz0n32ekOpIn3S88unJkD+fVDwJxj0nT1X9RMH5o1Kwx/IrLsiWpzygIDhZ5jLHA9LXaLLEPYcTWRKry/oVNCD1/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608039201; 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=RMTr+QsC5/nflD8X6emyF8GBppB0LUGu1p21x7dLN0g=; b=aVyXqR/aal/9vOjHzP0C6GX9niVLonIC5lW9DqPOcg2YBMdFAyxntPRLOnikMrEGT3xv8j1jJRSQF0YwpRP8BzSPWARvEkWPE/CeXVsysVEkPMrYtG0BVtjwU8dvTsoL5aWJFdL9FaUVSt78bmw0OXYV22m4/BK4K98WcDCVPAA= 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 1608039200829968.9905601091834; Tue, 15 Dec 2020 05:33:20 -0800 (PST) Received: from localhost ([::1]:42838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9Yu-0004ys-2R for importer@patchew.org; Tue, 15 Dec 2020 07:36:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tg-0007o1-6z; Tue, 15 Dec 2020 07:30:52 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2998) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9TY-0006w7-Ew; Tue, 15 Dec 2020 07:30:51 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CwHdf4QHrzhsSt; Tue, 15 Dec 2020 20:29:58 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 20:30:26 +0800 From: Jiahui Cen To: Subject: [PATCH v4 3/7] block-backend: Add device specific retry callback Date: Tue, 15 Dec 2020 20:30:07 +0800 Message-ID: <20201215123011.4048-4-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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_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 fe775ea298..bca7c581ee 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 8203d7f6f9..b31144aca9 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.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608039218; cv=none; d=zohomail.com; s=zohoarc; b=J6musf96BJPGcsqb8+mkhtqZFq57OtEHtbIU35d0cghj92qIQ36RRa5cbEdVVfg0zJgRKXfxWgGP5Vrn2MQ0iGjyCcS/Yiv1JSnQksa+2Apd+iRmSvzXygxomyEzkI70BM6bXAQbOPjkieAruDmde/ykmGzDZCbPzNcRIn/4RAU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608039218; 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=dydO6O7wnweBJl585K+qfVQDuxBpqrP77FvJokZ7cHs=; b=l1ExdErLqtviVa6s7t6tW/PQvkll41Etn9DtMuQ5CKQTCewcvoFhv+UIASqhe6nuDdJdUbHXp0aaQwkp4yrf53BdZIB1AYdDtb9uOVml92bk+O8BMx2cHNkkYHNZkUC5HvfVYTzzsNMoVGqdDkK90LZN8FKoZt6Bh0Tj1SXRiYQ= 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 1608039218105172.83044407253772; Tue, 15 Dec 2020 05:33:38 -0800 (PST) Received: from localhost ([::1]:48130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9aS-0007Ag-W4 for importer@patchew.org; Tue, 15 Dec 2020 07:37:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tn-0007vp-BF; Tue, 15 Dec 2020 07:30:59 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Th-0006vJ-VE; Tue, 15 Dec 2020 07:30:59 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CwHdf6H6lz7FsH; Tue, 15 Dec 2020 20:29:58 +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; Tue, 15 Dec 2020 20:30:26 +0800 From: Jiahui Cen To: Subject: [PATCH v4 4/7] block-backend: Enable retry action on errors Date: Tue, 15 Dec 2020 20:30:08 +0800 Message-ID: <20201215123011.4048-5-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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" 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index bca7c581ee..9c6e50e568 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,10 @@ 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) { + timer_mod(blk->retry_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME)= + + blk->retry_interval); + send_qmp_error_event(blk, action, is_read, error); } else { send_qmp_error_event(blk, action, is_read, error); } --=20 2.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608035742; cv=none; d=zohomail.com; s=zohoarc; b=DRh/EgxJf7H9rJFIx1gjjOXgf4/F/k2xt/diF8nIj/CgGUJLDr2+p8ijSP6CgXUq4qWBlfJwHWwLOV0VEA3uXxb3rk0/gQ2zq2fU5IFy+wxvThtRnbun+tJF7v0PE8URSXwRbCxL8EaQEbbKGv87+cX3pSeyOB1vZCrEhr0t4bI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608035742; 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=t+nhlWForGNgQTkTpG7pma9u0uyQj0eRvUds606bgNE=; b=O/F3vbsIWTvZvz20IBd2FNXHF11YZ6YMpdhN/idqoE3RlJiP7q6qmmgwZglCZg2W4EczuDBntKoV9i11CTqwoKr3uiDD1UwOf1NvfaKXeKxU0GEc8Rla4gKwULmvt8hOkxGuKjjgdYj9Cd++cMXqyCfg5V200WMdlJLXKp6qMkE= 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 1608035742465638.3766370866076; Tue, 15 Dec 2020 04:35:42 -0800 (PST) Received: from localhost ([::1]:39652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9YK-0003aa-S5 for importer@patchew.org; Tue, 15 Dec 2020 07:35:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Th-0007oy-Vd; Tue, 15 Dec 2020 07:30:54 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tb-0006uV-9e; Tue, 15 Dec 2020 07:30:53 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CwHdm3zCvzhs8J; Tue, 15 Dec 2020 20:30:04 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 20:30:27 +0800 From: Jiahui Cen To: Subject: [PATCH v4 5/7] block-backend: Add timeout support for retry Date: Tue, 15 Dec 2020 20:30:09 +0800 Message-ID: <20201215123011.4048-6-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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" 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 9c6e50e568..f5386fabb9 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 b31144aca9..070eb7786c 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.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608036947; cv=none; d=zohomail.com; s=zohoarc; b=NDdOwi/hY0Q/9pErT9oOVM/9TsH+E5jdinaGTYGqW5nbYGxZv1eHhM6RyPGkRLLWHGpsrdjVwXHZKal7duladKuK5fiIIy/gaSemwqKEQA00246v/XZRyS9S0IhSxRIGXd4MiHq0LnxrqZOrGYQo8bEq5BoYXrZUjkoz5zxz9Q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608036947; 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=OWP+nfJwnPodf6MqORzBOXdX3AGE5ungongnboydfIA=; b=MNvU6dQ5lsysoOqYk0xuV18wa35newGoYpBVtqPoNrI1cMCU+b2WdtQlPE0eSN0SbbjeDid4k++cmKzXPbKjQ2nEPxv8MZnfZQrICdCbAbHu5oA1UG5JM//hGWvHACk8ujgNo/MXfSe+VG4EqgAqkHE3ij/PRGKtDNGN08kAqks= 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 160803694779879.78994191159484; Tue, 15 Dec 2020 04:55:47 -0800 (PST) Received: from localhost ([::1]:42126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9Yl-0004gT-PE for importer@patchew.org; Tue, 15 Dec 2020 07:36:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tl-0007u1-7b; Tue, 15 Dec 2020 07:30:57 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Tc-0006wQ-Qo; Tue, 15 Dec 2020 07:30:55 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CwHdh5p18z15drw; Tue, 15 Dec 2020 20:30:00 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 20:30:28 +0800 From: Jiahui Cen To: Subject: [PATCH v4 6/7] block: Add error retry param setting Date: Tue, 15 Dec 2020 20:30:10 +0800 Message-ID: <20201215123011.4048-7-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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 "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 f5386fabb9..230b1c65b5 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 47c0e6db52..39c0669981 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; @@ -3773,6 +3815,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 1e8b6253dd..a9f04db147 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -31,6 +31,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) @@ -75,7 +77,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 070eb7786c..a82b6da1da 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.28.0 From nobody Tue Nov 18 06:06:13 2025 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=1608036705; cv=none; d=zohomail.com; s=zohoarc; b=RMSiF4FM3VGm/SFVamH/rWZxkszWiWkKqnt0/CoaEY53S86THB6ZZydx3F1n1xQVouGXtx7On6nNfbdie+L4BjP9EsVM8uclegtytv2u7cSGcU2+g3fuelr3WVF/KXcHiHSVmVseBP59rAWLOGTKI952GeYvToTwaqdaP1mJ+SE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608036705; 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=JvG+G0ETf2kzcpDVfLOZoep1tCqyHGnu+Ap2Nuv5+ps=; b=Zw/k/XHFXFqdWSWQZmolnBqirvJeo2eKoTuOTj9EnM+S9Ckv3yuS0G9mds/ukDZKQLO0Qxg1YOrLgWuurAw0/KHrYtmpaeg9Fubel5LRGQFAXVpJZUahJEqq7WxoIKy/bvb7IcKUr+TOBoP+LLcNJeGJ8FDrOB3EKVF8zKFKYdM= 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 1608036705427298.09154217563014; Tue, 15 Dec 2020 04:51:45 -0800 (PST) Received: from localhost ([::1]:34626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kp9WM-0001Rr-UL for importer@patchew.org; Tue, 15 Dec 2020 07:33:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9Te-0007lc-EA; Tue, 15 Dec 2020 07:30:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2999) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kp9TZ-0006vK-F8; Tue, 15 Dec 2020 07:30:50 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CwHdf4lLxzhsTL; Tue, 15 Dec 2020 20:29:58 +0800 (CST) Received: from localhost (10.174.184.155) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 20:30:28 +0800 From: Jiahui Cen To: Subject: [PATCH v4 7/7] virtio_blk: Add support for retry on errors Date: Tue, 15 Dec 2020 20:30:11 +0800 Message-ID: <20201215123011.4048-8-cenjiahui@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201215123011.4048-1-cenjiahui@huawei.com> References: <20201215123011.4048-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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index bac2d6fa2b..cf8b350eaf 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); @@ -828,12 +833,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 +1139,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.28.0