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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx>
---
 drivers/block/ublk_drv.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

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);
 
-- 
2.27.0




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux