From nobody Tue Nov 18 07:42:41 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