diff mbox series

[RFC,V2,4/6] ublk_drv: requeue rqs with recovery feature enabled

Message ID 20220831155136.23434-5-ZiyangZhang@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series ublk_drv: add USER_RECOVERY support | expand

Commit Message

Ziyang Zhang Aug. 31, 2022, 3:51 p.m. UTC
With recovery feature enabled, in ublk_queue_rq or task work
(in exit_task_work or fallback wq), we requeue rqs instead of
ending(aborting) them.

No matter recovery feature is enabled or disabled, schedule monitor work
immediately after detecting a crash so it can find out the crash and
do aborting/recovery mechanism.

Signed-off-by: ZiyangZhang <ZiyangZhang@linux.alibaba.com>
---
 drivers/block/ublk_drv.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 0c3d32e8d686..296b9d80f003 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -690,7 +690,16 @@  static inline void __ublk_rq_task_work(struct request *req)
 	 * (2) current->flags & PF_EXITING.
 	 */
 	if (unlikely(current != ubq->ubq_daemon || current->flags & PF_EXITING)) {
-		blk_mq_end_request(req, BLK_STS_IOERR);
+		pr_devel("%s: %s q_id %d tag %d io_flags %x.\n", __func__,
+				(ublk_can_use_recovery(ub)) ? "requeue" : "abort",
+				ubq->q_id, req->tag, io->flags);
+
+		if (ublk_can_use_recovery(ub)) {
+			/* We cannot process this req so just requeue it. */
+			blk_mq_requeue_request(req, false);
+		} else {
+			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
 		mod_delayed_work(system_wq, &ub->monitor_work, 0);
 		return;
 	}
@@ -770,6 +779,7 @@  static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
 {
 	struct ublk_queue *ubq = hctx->driver_data;
 	struct request *rq = bd->rq;
+	struct ublk_io *io = &ubq->ios[rq->tag];
 	blk_status_t res;
 
 	/* fill iod to slot in io cmd buffer */
@@ -781,8 +791,18 @@  static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
 
 	if (unlikely(ubq_daemon_is_dying(ubq))) {
  fail:
+		pr_devel("%s: %s q_id %d tag %d io_flags %x.\n", __func__,
+				(ublk_can_use_recovery(ubq->dev)) ? "requeue" : "abort",
+				ubq->q_id, rq->tag, io->flags);
+
 		mod_delayed_work(system_wq, &ubq->dev->monitor_work, 0);
-		return BLK_STS_IOERR;
+		if (ublk_can_use_recovery(ubq->dev)) {
+			/* We cannot process this rq so just requeue it. */
+			blk_mq_requeue_request(rq, false);
+			return BLK_STS_OK;
+		} else {
+			return BLK_STS_IOERR;
+		}
 	}
 
 	if (ublk_can_use_task_work(ubq)) {
@@ -793,7 +813,6 @@  static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
 		if (task_work_add(ubq->ubq_daemon, &data->work, notify_mode))
 			goto fail;
 	} else {
-		struct ublk_io *io = &ubq->ios[rq->tag];
 		struct io_uring_cmd *cmd = io->cmd;
 		struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);