[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 5/9] block-backend: Add timeout support for retry
From: |
Jiahui Cen |
Subject: |
[PATCH v5 5/9] block-backend: Add timeout support for retry |
Date: |
Fri, 5 Feb 2021 18:13:11 +0800 |
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 <cenjiahui@huawei.com>
Signed-off-by: Ying Fang <fangying1@huawei.com>
---
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();
}
+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 = 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 = 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 *blk,
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);
--
2.29.2
- [PATCH v5 0/9] block: Add retry for werror=/rerror= mechanism, Jiahui Cen, 2021/02/05
- [PATCH v5 2/9] block-backend: Introduce retry timer, Jiahui Cen, 2021/02/05
- [PATCH v5 8/9] scsi-bus: Refactor the code that retries requests, Jiahui Cen, 2021/02/05
- [PATCH v5 1/9] qapi/block-core: Add retry option for error action, Jiahui Cen, 2021/02/05
- [PATCH v5 7/9] virtio_blk: Add support for retry on errors, Jiahui Cen, 2021/02/05
- [PATCH v5 5/9] block-backend: Add timeout support for retry,
Jiahui Cen <=
- [PATCH v5 9/9] scsi-disk: Add support for retry on errors, Jiahui Cen, 2021/02/05
- [PATCH v5 3/9] block-backend: Add device specific retry callback, Jiahui Cen, 2021/02/05
- [PATCH v5 6/9] block: Add error retry param setting, Jiahui Cen, 2021/02/05
- [PATCH v5 4/9] block-backend: Enable retry action on errors, Jiahui Cen, 2021/02/05
- Re: [PATCH v5 0/9] block: Add retry for werror=/rerror= mechanism, Jiahui Cen, 2021/02/09
- Re: [PATCH v5 0/9] block: Add retry for werror=/rerror= mechanism, Stefan Hajnoczi, 2021/02/22