@@ -134,16 +134,8 @@ static void blk_flush_restore_request(struct request *rq)
134134
135135static bool blk_flush_queue_rq (struct request * rq , bool add_front )
136136{
137- if (rq -> q -> mq_ops ) {
138- blk_mq_add_to_requeue_list (rq , add_front , true);
139- return false;
140- } else {
141- if (add_front )
142- list_add (& rq -> queuelist , & rq -> q -> queue_head );
143- else
144- list_add_tail (& rq -> queuelist , & rq -> q -> queue_head );
145- return true;
146- }
137+ blk_mq_add_to_requeue_list (rq , add_front , true);
138+ return false;
147139}
148140
149141/**
@@ -204,10 +196,7 @@ static bool blk_flush_complete_seq(struct request *rq,
204196 BUG_ON (!list_empty (& rq -> queuelist ));
205197 list_del_init (& rq -> flush .list );
206198 blk_flush_restore_request (rq );
207- if (q -> mq_ops )
208- blk_mq_end_request (rq , error );
209- else
210- __blk_end_request_all (rq , error );
199+ blk_mq_end_request (rq , error );
211200 break ;
212201
213202 default :
@@ -226,20 +215,17 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
226215 struct request * rq , * n ;
227216 unsigned long flags = 0 ;
228217 struct blk_flush_queue * fq = blk_get_flush_queue (q , flush_rq -> mq_ctx );
218+ struct blk_mq_hw_ctx * hctx ;
229219
230- if (q -> mq_ops ) {
231- struct blk_mq_hw_ctx * hctx ;
232-
233- /* release the tag's ownership to the req cloned from */
234- spin_lock_irqsave (& fq -> mq_flush_lock , flags );
235- hctx = blk_mq_map_queue (q , flush_rq -> mq_ctx -> cpu );
236- if (!q -> elevator ) {
237- blk_mq_tag_set_rq (hctx , flush_rq -> tag , fq -> orig_rq );
238- flush_rq -> tag = -1 ;
239- } else {
240- blk_mq_put_driver_tag_hctx (hctx , flush_rq );
241- flush_rq -> internal_tag = -1 ;
242- }
220+ /* release the tag's ownership to the req cloned from */
221+ spin_lock_irqsave (& fq -> mq_flush_lock , flags );
222+ hctx = blk_mq_map_queue (q , flush_rq -> mq_ctx -> cpu );
223+ if (!q -> elevator ) {
224+ blk_mq_tag_set_rq (hctx , flush_rq -> tag , fq -> orig_rq );
225+ flush_rq -> tag = -1 ;
226+ } else {
227+ blk_mq_put_driver_tag_hctx (hctx , flush_rq );
228+ flush_rq -> internal_tag = -1 ;
243229 }
244230
245231 running = & fq -> flush_queue [fq -> flush_running_idx ];
@@ -248,9 +234,6 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
248234 /* account completion of the flush request */
249235 fq -> flush_running_idx ^= 1 ;
250236
251- if (!q -> mq_ops )
252- elv_completed_request (q , flush_rq );
253-
254237 /* and push the waiting requests to the next stage */
255238 list_for_each_entry_safe (rq , n , running , flush .list ) {
256239 unsigned int seq = blk_flush_cur_seq (rq );
@@ -259,24 +242,8 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
259242 queued |= blk_flush_complete_seq (rq , fq , seq , error );
260243 }
261244
262- /*
263- * Kick the queue to avoid stall for two cases:
264- * 1. Moving a request silently to empty queue_head may stall the
265- * queue.
266- * 2. When flush request is running in non-queueable queue, the
267- * queue is hold. Restart the queue after flush request is finished
268- * to avoid stall.
269- * This function is called from request completion path and calling
270- * directly into request_fn may confuse the driver. Always use
271- * kblockd.
272- */
273- if (queued || fq -> flush_queue_delayed ) {
274- WARN_ON (q -> mq_ops );
275- blk_run_queue_async (q );
276- }
277245 fq -> flush_queue_delayed = 0 ;
278- if (q -> mq_ops )
279- spin_unlock_irqrestore (& fq -> mq_flush_lock , flags );
246+ spin_unlock_irqrestore (& fq -> mq_flush_lock , flags );
280247}
281248
282249/**
@@ -301,6 +268,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
301268 struct request * first_rq =
302269 list_first_entry (pending , struct request , flush .list );
303270 struct request * flush_rq = fq -> flush_rq ;
271+ struct blk_mq_hw_ctx * hctx ;
304272
305273 /* C1 described at the top of this file */
306274 if (fq -> flush_pending_idx != fq -> flush_running_idx || list_empty (pending ))
@@ -334,19 +302,15 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
334302 * In case of IO scheduler, flush rq need to borrow scheduler tag
335303 * just for cheating put/get driver tag.
336304 */
337- if (q -> mq_ops ) {
338- struct blk_mq_hw_ctx * hctx ;
339-
340- flush_rq -> mq_ctx = first_rq -> mq_ctx ;
341-
342- if (!q -> elevator ) {
343- fq -> orig_rq = first_rq ;
344- flush_rq -> tag = first_rq -> tag ;
345- hctx = blk_mq_map_queue (q , first_rq -> mq_ctx -> cpu );
346- blk_mq_tag_set_rq (hctx , first_rq -> tag , flush_rq );
347- } else {
348- flush_rq -> internal_tag = first_rq -> internal_tag ;
349- }
305+ flush_rq -> mq_ctx = first_rq -> mq_ctx ;
306+
307+ if (!q -> elevator ) {
308+ fq -> orig_rq = first_rq ;
309+ flush_rq -> tag = first_rq -> tag ;
310+ hctx = blk_mq_map_queue (q , first_rq -> mq_ctx -> cpu );
311+ blk_mq_tag_set_rq (hctx , first_rq -> tag , flush_rq );
312+ } else {
313+ flush_rq -> internal_tag = first_rq -> internal_tag ;
350314 }
351315
352316 flush_rq -> cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH ;
@@ -358,49 +322,6 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
358322 return blk_flush_queue_rq (flush_rq , false);
359323}
360324
361- static void flush_data_end_io (struct request * rq , blk_status_t error )
362- {
363- struct request_queue * q = rq -> q ;
364- struct blk_flush_queue * fq = blk_get_flush_queue (q , NULL );
365-
366- lockdep_assert_held (q -> queue_lock );
367-
368- /*
369- * Updating q->in_flight[] here for making this tag usable
370- * early. Because in blk_queue_start_tag(),
371- * q->in_flight[BLK_RW_ASYNC] is used to limit async I/O and
372- * reserve tags for sync I/O.
373- *
374- * More importantly this way can avoid the following I/O
375- * deadlock:
376- *
377- * - suppose there are 40 fua requests comming to flush queue
378- * and queue depth is 31
379- * - 30 rqs are scheduled then blk_queue_start_tag() can't alloc
380- * tag for async I/O any more
381- * - all the 30 rqs are completed before FLUSH_PENDING_TIMEOUT
382- * and flush_data_end_io() is called
383- * - the other rqs still can't go ahead if not updating
384- * q->in_flight[BLK_RW_ASYNC] here, meantime these rqs
385- * are held in flush data queue and make no progress of
386- * handling post flush rq
387- * - only after the post flush rq is handled, all these rqs
388- * can be completed
389- */
390-
391- elv_completed_request (q , rq );
392-
393- /* for avoiding double accounting */
394- rq -> rq_flags &= ~RQF_STARTED ;
395-
396- /*
397- * After populating an empty queue, kick it to avoid stall. Read
398- * the comment in flush_end_io().
399- */
400- if (blk_flush_complete_seq (rq , fq , REQ_FSEQ_DATA , error ))
401- blk_run_queue_async (q );
402- }
403-
404325static void mq_flush_data_end_io (struct request * rq , blk_status_t error )
405326{
406327 struct request_queue * q = rq -> q ;
@@ -443,9 +364,6 @@ void blk_insert_flush(struct request *rq)
443364 unsigned int policy = blk_flush_policy (fflags , rq );
444365 struct blk_flush_queue * fq = blk_get_flush_queue (q , rq -> mq_ctx );
445366
446- if (!q -> mq_ops )
447- lockdep_assert_held (q -> queue_lock );
448-
449367 /*
450368 * @policy now records what operations need to be done. Adjust
451369 * REQ_PREFLUSH and FUA for the driver.
@@ -468,10 +386,7 @@ void blk_insert_flush(struct request *rq)
468386 * complete the request.
469387 */
470388 if (!policy ) {
471- if (q -> mq_ops )
472- blk_mq_end_request (rq , 0 );
473- else
474- __blk_end_request (rq , 0 , 0 );
389+ blk_mq_end_request (rq , 0 );
475390 return ;
476391 }
477392
@@ -484,10 +399,7 @@ void blk_insert_flush(struct request *rq)
484399 */
485400 if ((policy & REQ_FSEQ_DATA ) &&
486401 !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH ))) {
487- if (q -> mq_ops )
488- blk_mq_request_bypass_insert (rq , false);
489- else
490- list_add_tail (& rq -> queuelist , & q -> queue_head );
402+ blk_mq_request_bypass_insert (rq , false);
491403 return ;
492404 }
493405
@@ -499,17 +411,12 @@ void blk_insert_flush(struct request *rq)
499411 INIT_LIST_HEAD (& rq -> flush .list );
500412 rq -> rq_flags |= RQF_FLUSH_SEQ ;
501413 rq -> flush .saved_end_io = rq -> end_io ; /* Usually NULL */
502- if (q -> mq_ops ) {
503- rq -> end_io = mq_flush_data_end_io ;
504414
505- spin_lock_irq (& fq -> mq_flush_lock );
506- blk_flush_complete_seq (rq , fq , REQ_FSEQ_ACTIONS & ~policy , 0 );
507- spin_unlock_irq (& fq -> mq_flush_lock );
508- return ;
509- }
510- rq -> end_io = flush_data_end_io ;
415+ rq -> end_io = mq_flush_data_end_io ;
511416
417+ spin_lock_irq (& fq -> mq_flush_lock );
512418 blk_flush_complete_seq (rq , fq , REQ_FSEQ_ACTIONS & ~policy , 0 );
419+ spin_unlock_irq (& fq -> mq_flush_lock );
513420}
514421
515422/**
@@ -575,8 +482,7 @@ struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
575482 if (!fq )
576483 goto fail ;
577484
578- if (q -> mq_ops )
579- spin_lock_init (& fq -> mq_flush_lock );
485+ spin_lock_init (& fq -> mq_flush_lock );
580486
581487 rq_sz = round_up (rq_sz + cmd_size , cache_line_size ());
582488 fq -> flush_rq = kzalloc_node (rq_sz , flags , node );
0 commit comments