So we can clean up map_request() a bit, no functional change.

Cc: Mike Snitzer <[email protected]>
Cc: Laurence Oberman <[email protected]>
Cc: Bart Van Assche <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
---
 drivers/md/dm-rq.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index e0bb56723b9b..1408e6664c16 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -12,6 +12,9 @@
 
 #define DM_MSG_PREFIX "core-rq"
 
+#define  dispatch_busy(r)  \
+       (((r) == BLK_STS_RESOURCE) || ((r) == BLK_STS_DEV_RESOURCE))
+
 #define DM_MQ_NR_HW_QUEUES 1
 #define DM_MQ_QUEUE_DEPTH 2048
 static unsigned dm_mq_nr_hw_queues = DM_MQ_NR_HW_QUEUES;
@@ -399,7 +402,8 @@ static void end_clone_request(struct request *clone, 
blk_status_t error)
        dm_complete_request(tio->orig, error);
 }
 
-static blk_status_t dm_dispatch_clone_request(struct request *clone, struct 
request *rq)
+static blk_status_t dm_dispatch_clone_request(struct dm_rq_target_io *tio,
+               struct request *clone, struct request *rq)
 {
        blk_status_t r;
 
@@ -408,9 +412,17 @@ static blk_status_t dm_dispatch_clone_request(struct 
request *clone, struct requ
 
        clone->start_time = jiffies;
        r = blk_insert_cloned_request(clone->q, clone);
-       if (r != BLK_STS_OK && r != BLK_STS_RESOURCE)
+       if (dispatch_busy(r)) {
+               blk_rq_unprep_clone(clone);
+               tio->ti->type->release_clone_rq(clone);
+               tio->clone = NULL;
+       } else if (r != BLK_STS_OK) {
                /* must complete clone in terms of original request */
                dm_complete_request(rq, r);
+
+               /* we handled the failure, so return OK */
+               r = BLK_STS_OK;
+       }
        return r;
 }
 
@@ -499,11 +511,8 @@ static int map_request(struct dm_rq_target_io *tio)
                /* The target has remapped the I/O so dispatch it */
                trace_block_rq_remap(clone->q, clone, disk_devt(dm_disk(md)),
                                     blk_rq_pos(rq));
-               ret = dm_dispatch_clone_request(clone, rq);
-               if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE) {
-                       blk_rq_unprep_clone(clone);
-                       tio->ti->type->release_clone_rq(clone);
-                       tio->clone = NULL;
+               ret = dm_dispatch_clone_request(tio, clone, rq);
+               if (dispatch_busy(ret)) {
                        if (!rq->q->mq_ops)
                                r = DM_MAPIO_DELAY_REQUEUE;
                        else
-- 
2.9.5

Reply via email to