aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2012-11-28 07:46:45 -0500
committerJens Axboe <axboe@kernel.dk>2012-12-06 08:33:00 -0500
commit24faf6f604efe18236bded4303009fc252913bf0 (patch)
treebc4d35a38c44a37ffd718089729ae59b23d50d99
parent704605711ef048a7c6ad2ec599f15d2e0baf86b2 (diff)
block: Make blk_cleanup_queue() wait until request_fn finished
Some request_fn implementations, e.g. scsi_request_fn(), unlock the queue lock internally. This may result in multiple threads executing request_fn for the same queue simultaneously. Keep track of the number of active request_fn calls and make sure that blk_cleanup_queue() waits until all active request_fn invocations have finished. A block driver may start cleaning up resources needed by its request_fn as soon as blk_cleanup_queue() finished, so blk_cleanup_queue() must wait for all outstanding request_fn invocations to finish. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reported-by: Chanho Min <chanho.min@lge.com> Cc: James Bottomley <JBottomley@Parallels.com> Cc: Mike Christie <michaelc@cs.wisc.edu> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-core.c10
-rw-r--r--include/linux/blkdev.h6
2 files changed, 16 insertions, 0 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 9fb23537c7ad..473015ee28a2 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -309,7 +309,16 @@ inline void __blk_run_queue_uncond(struct request_queue *q)
309 if (unlikely(blk_queue_dead(q))) 309 if (unlikely(blk_queue_dead(q)))
310 return; 310 return;
311 311
312 /*
313 * Some request_fn implementations, e.g. scsi_request_fn(), unlock
314 * the queue lock internally. As a result multiple threads may be
315 * running such a request function concurrently. Keep track of the
316 * number of active request_fn invocations such that blk_drain_queue()
317 * can wait until all these request_fn calls have finished.
318 */
319 q->request_fn_active++;
312 q->request_fn(q); 320 q->request_fn(q);
321 q->request_fn_active--;
313} 322}
314 323
315/** 324/**
@@ -408,6 +417,7 @@ static void __blk_drain_queue(struct request_queue *q, bool drain_all)
408 __blk_run_queue(q); 417 __blk_run_queue(q);
409 418
410 drain |= q->nr_rqs_elvpriv; 419 drain |= q->nr_rqs_elvpriv;
420 drain |= q->request_fn_active;
411 421
412 /* 422 /*
413 * Unfortunately, requests are queued at and tracked from 423 * Unfortunately, requests are queued at and tracked from
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8bc46c250ca4..c9d233e727f2 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -378,6 +378,12 @@ struct request_queue {
378 378
379 unsigned int nr_sorted; 379 unsigned int nr_sorted;
380 unsigned int in_flight[2]; 380 unsigned int in_flight[2];
381 /*
382 * Number of active block driver functions for which blk_drain_queue()
383 * must wait. Must be incremented around functions that unlock the
384 * queue_lock internally, e.g. scsi_request_fn().
385 */
386 unsigned int request_fn_active;
381 387
382 unsigned int rq_timeout; 388 unsigned int rq_timeout;
383 struct timer_list timeout; 389 struct timer_list timeout;