From 70283b25ae50d37458ad296e1ff39df55384a686 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 28 Nov 2012 13:46:45 +0100 Subject: [PATCH] --- yaml --- r: 345670 b: refs/heads/master c: 24faf6f604efe18236bded4303009fc252913bf0 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/block/blk-core.c | 10 ++++++++++ trunk/include/linux/blkdev.h | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 9838ebcd9ad9..d81a74549d25 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 704605711ef048a7c6ad2ec599f15d2e0baf86b2 +refs/heads/master: 24faf6f604efe18236bded4303009fc252913bf0 diff --git a/trunk/block/blk-core.c b/trunk/block/blk-core.c index 9fb23537c7ad..473015ee28a2 100644 --- a/trunk/block/blk-core.c +++ b/trunk/block/blk-core.c @@ -309,7 +309,16 @@ inline void __blk_run_queue_uncond(struct request_queue *q) if (unlikely(blk_queue_dead(q))) return; + /* + * Some request_fn implementations, e.g. scsi_request_fn(), unlock + * the queue lock internally. As a result multiple threads may be + * running such a request function concurrently. Keep track of the + * number of active request_fn invocations such that blk_drain_queue() + * can wait until all these request_fn calls have finished. + */ + q->request_fn_active++; q->request_fn(q); + q->request_fn_active--; } /** @@ -408,6 +417,7 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all) __blk_run_queue(q); drain |= q->nr_rqs_elvpriv; + drain |= q->request_fn_active; /* * Unfortunately, requests are queued at and tracked from diff --git a/trunk/include/linux/blkdev.h b/trunk/include/linux/blkdev.h index 8bc46c250ca4..c9d233e727f2 100644 --- a/trunk/include/linux/blkdev.h +++ b/trunk/include/linux/blkdev.h @@ -378,6 +378,12 @@ struct request_queue { unsigned int nr_sorted; unsigned int in_flight[2]; + /* + * Number of active block driver functions for which blk_drain_queue() + * must wait. Must be incremented around functions that unlock the + * queue_lock internally, e.g. scsi_request_fn(). + */ + unsigned int request_fn_active; unsigned int rq_timeout; struct timer_list timeout;