@@ -277,20 +277,26 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
277277{
278278 struct blk_mq_tags * tags = blk_mq_tags_from_data (data );
279279 struct request * rq = tags -> static_rqs [tag ];
280+ req_flags_t rq_flags = 0 ;
280281
281282 if (data -> q -> elevator ) {
282283 rq -> tag = BLK_MQ_NO_TAG ;
283284 rq -> internal_tag = tag ;
284285 } else {
286+ if (data -> hctx -> flags & BLK_MQ_F_TAG_SHARED ) {
287+ rq_flags = RQF_MQ_INFLIGHT ;
288+ atomic_inc (& data -> hctx -> nr_active );
289+ }
285290 rq -> tag = tag ;
286291 rq -> internal_tag = BLK_MQ_NO_TAG ;
292+ data -> hctx -> tags -> rqs [rq -> tag ] = rq ;
287293 }
288294
289295 /* csd/requeue_work/fifo_time is initialized before use */
290296 rq -> q = data -> q ;
291297 rq -> mq_ctx = data -> ctx ;
292298 rq -> mq_hctx = data -> hctx ;
293- rq -> rq_flags = 0 ;
299+ rq -> rq_flags = rq_flags ;
294300 rq -> cmd_flags = data -> cmd_flags ;
295301 if (data -> flags & BLK_MQ_REQ_PREEMPT )
296302 rq -> rq_flags |= RQF_PREEMPT ;
@@ -660,32 +666,10 @@ static inline bool blk_mq_complete_need_ipi(struct request *rq)
660666 return cpu_online (rq -> mq_ctx -> cpu );
661667}
662668
663- static void __blk_mq_put_driver_tag (struct blk_mq_hw_ctx * hctx ,
664- struct request * rq )
665- {
666- blk_mq_put_tag (hctx -> tags , rq -> mq_ctx , rq -> tag );
667- rq -> tag = BLK_MQ_NO_TAG ;
668-
669- if (rq -> rq_flags & RQF_MQ_INFLIGHT ) {
670- rq -> rq_flags &= ~RQF_MQ_INFLIGHT ;
671- atomic_dec (& hctx -> nr_active );
672- }
673- }
674-
675- static inline void blk_mq_put_driver_tag (struct request * rq )
676- {
677- if (rq -> tag == BLK_MQ_NO_TAG || rq -> internal_tag == BLK_MQ_NO_TAG )
678- return ;
679-
680- __blk_mq_put_driver_tag (rq -> mq_hctx , rq );
681- }
682-
683669bool blk_mq_complete_request_remote (struct request * rq )
684670{
685671 WRITE_ONCE (rq -> state , MQ_RQ_COMPLETE );
686672
687- blk_mq_put_driver_tag (rq );
688-
689673 /*
690674 * For a polled request, always complete locallly, it's pointless
691675 * to redirect the completion.
@@ -1121,10 +1105,9 @@ static bool __blk_mq_get_driver_tag(struct request *rq)
11211105{
11221106 struct sbitmap_queue * bt = & rq -> mq_hctx -> tags -> bitmap_tags ;
11231107 unsigned int tag_offset = rq -> mq_hctx -> tags -> nr_reserved_tags ;
1108+ bool shared = blk_mq_tag_busy (rq -> mq_hctx );
11241109 int tag ;
11251110
1126- blk_mq_tag_busy (rq -> mq_hctx );
1127-
11281111 if (blk_mq_tag_is_reserved (rq -> mq_hctx -> sched_tags , rq -> internal_tag )) {
11291112 bt = & rq -> mq_hctx -> tags -> breserved_tags ;
11301113 tag_offset = 0 ;
@@ -1137,22 +1120,19 @@ static bool __blk_mq_get_driver_tag(struct request *rq)
11371120 return false;
11381121
11391122 rq -> tag = tag + tag_offset ;
1123+ if (shared ) {
1124+ rq -> rq_flags |= RQF_MQ_INFLIGHT ;
1125+ atomic_inc (& rq -> mq_hctx -> nr_active );
1126+ }
1127+ rq -> mq_hctx -> tags -> rqs [rq -> tag ] = rq ;
11401128 return true;
11411129}
11421130
11431131static bool blk_mq_get_driver_tag (struct request * rq )
11441132{
1145- struct blk_mq_hw_ctx * hctx = rq -> mq_hctx ;
1146-
1147- if (rq -> tag == BLK_MQ_NO_TAG && !__blk_mq_get_driver_tag (rq ))
1148- return false;
1149-
1150- if (hctx -> flags & BLK_MQ_F_TAG_SHARED ) {
1151- rq -> rq_flags |= RQF_MQ_INFLIGHT ;
1152- atomic_inc (& hctx -> nr_active );
1153- }
1154- hctx -> tags -> rqs [rq -> tag ] = rq ;
1155- return true;
1133+ if (rq -> tag != BLK_MQ_NO_TAG )
1134+ return true;
1135+ return __blk_mq_get_driver_tag (rq );
11561136}
11571137
11581138static int blk_mq_dispatch_wake (wait_queue_entry_t * wait , unsigned mode ,
0 commit comments