Skip to content

Commit 1b8f21b

Browse files
Ming Leiaxboe
Ming Lei
authored andcommitted
blk-mq: introduce blk_mq_complete_request_sync()
In NVMe's error handler, follows the typical steps of tearing down hardware for recovering controller: 1) stop blk_mq hw queues 2) stop the real hw queues 3) cancel in-flight requests via blk_mq_tagset_busy_iter(tags, cancel_request, ...) cancel_request(): mark the request as abort blk_mq_complete_request(req); 4) destroy real hw queues However, there may be race between rib#3 and rib#4, because blk_mq_complete_request() may run q->mq_ops->complete(rq) remotelly and asynchronously, and ->complete(rq) may be run after rib#4. This patch introduces blk_mq_complete_request_sync() for fixing the above race. Cc: Sagi Grimberg <[email protected]> Cc: Bart Van Assche <[email protected]> Cc: James Smart <[email protected]> Cc: [email protected] Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ming Lei <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 1978f30 commit 1b8f21b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

block/blk-mq.c

+7
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ bool blk_mq_complete_request(struct request *rq)
654654
}
655655
EXPORT_SYMBOL(blk_mq_complete_request);
656656

657+
void blk_mq_complete_request_sync(struct request *rq)
658+
{
659+
WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
660+
rq->q->mq_ops->complete(rq);
661+
}
662+
EXPORT_SYMBOL_GPL(blk_mq_complete_request_sync);
663+
657664
int blk_mq_request_started(struct request *rq)
658665
{
659666
return blk_mq_rq_state(rq) != MQ_RQ_IDLE;

include/linux/blk-mq.h

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list);
302302
void blk_mq_kick_requeue_list(struct request_queue *q);
303303
void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
304304
bool blk_mq_complete_request(struct request *rq);
305+
void blk_mq_complete_request_sync(struct request *rq);
305306
bool blk_mq_bio_list_merge(struct request_queue *q, struct list_head *list,
306307
struct bio *bio);
307308
bool blk_mq_queue_stopped(struct request_queue *q);

0 commit comments

Comments
 (0)