Skip to content

Commit 8506774

Browse files
Ming Leisnitm
authored andcommitted
dm: do not use waitqueue for request-based DM
Given request-based DM now uses blk-mq's blk_mq_queue_inflight() to determine if outstanding IO has completed (and DM has no control over the blk-mq state machine used to track outstanding IO) it is unsafe to wakeup waiter (dm_wait_for_completion) before blk-mq has cleared a request's state bits (e.g. MQ_RQ_IN_FLIGHT or MQ_RQ_COMPLETE). As such dm_wait_for_completion() could be left to wait indefinitely if no other requests complete. Fix this by eliminating request-based DM's use of waitqueue to wait for blk-mq requests to complete in dm_wait_for_completion. Signed-off-by: Ming Lei <[email protected]> Depends-on: 3c94d83 ("blk-mq: change blk_mq_queue_busy() to blk_mq_queue_inflight()") Cc: [email protected] Signed-off-by: Mike Snitzer <[email protected]>
1 parent dcb7fd8 commit 8506774

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

drivers/md/dm-rq.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ static void rq_end_stats(struct mapped_device *md, struct request *orig)
146146
*/
147147
static void rq_completed(struct mapped_device *md)
148148
{
149-
/* nudge anyone waiting on suspend queue */
150-
if (unlikely(wq_has_sleeper(&md->wait)))
151-
wake_up(&md->wait);
152-
153149
/*
154150
* dm_put() must be at the end of this function. See the comment above
155151
*/

drivers/md/dm.c

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -654,28 +654,6 @@ static void free_tio(struct dm_target_io *tio)
654654
bio_put(&tio->clone);
655655
}
656656

657-
static bool md_in_flight_bios(struct mapped_device *md)
658-
{
659-
int cpu;
660-
struct hd_struct *part = &dm_disk(md)->part0;
661-
long sum = 0;
662-
663-
for_each_possible_cpu(cpu) {
664-
sum += part_stat_local_read_cpu(part, in_flight[0], cpu);
665-
sum += part_stat_local_read_cpu(part, in_flight[1], cpu);
666-
}
667-
668-
return sum != 0;
669-
}
670-
671-
static bool md_in_flight(struct mapped_device *md)
672-
{
673-
if (queue_is_mq(md->queue))
674-
return blk_mq_queue_inflight(md->queue);
675-
else
676-
return md_in_flight_bios(md);
677-
}
678-
679657
u64 dm_start_time_ns_from_clone(struct bio *bio)
680658
{
681659
struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
@@ -2470,15 +2448,29 @@ void dm_put(struct mapped_device *md)
24702448
}
24712449
EXPORT_SYMBOL_GPL(dm_put);
24722450

2473-
static int dm_wait_for_completion(struct mapped_device *md, long task_state)
2451+
static bool md_in_flight_bios(struct mapped_device *md)
2452+
{
2453+
int cpu;
2454+
struct hd_struct *part = &dm_disk(md)->part0;
2455+
long sum = 0;
2456+
2457+
for_each_possible_cpu(cpu) {
2458+
sum += part_stat_local_read_cpu(part, in_flight[0], cpu);
2459+
sum += part_stat_local_read_cpu(part, in_flight[1], cpu);
2460+
}
2461+
2462+
return sum != 0;
2463+
}
2464+
2465+
static int dm_wait_for_bios_completion(struct mapped_device *md, long task_state)
24742466
{
24752467
int r = 0;
24762468
DEFINE_WAIT(wait);
24772469

2478-
while (1) {
2470+
while (true) {
24792471
prepare_to_wait(&md->wait, &wait, task_state);
24802472

2481-
if (!md_in_flight(md))
2473+
if (!md_in_flight_bios(md))
24822474
break;
24832475

24842476
if (signal_pending_state(task_state, current)) {
@@ -2493,6 +2485,28 @@ static int dm_wait_for_completion(struct mapped_device *md, long task_state)
24932485
return r;
24942486
}
24952487

2488+
static int dm_wait_for_completion(struct mapped_device *md, long task_state)
2489+
{
2490+
int r = 0;
2491+
2492+
if (!queue_is_mq(md->queue))
2493+
return dm_wait_for_bios_completion(md, task_state);
2494+
2495+
while (true) {
2496+
if (!blk_mq_queue_inflight(md->queue))
2497+
break;
2498+
2499+
if (signal_pending_state(task_state, current)) {
2500+
r = -EINTR;
2501+
break;
2502+
}
2503+
2504+
msleep(5);
2505+
}
2506+
2507+
return r;
2508+
}
2509+
24962510
/*
24972511
* Process the deferred bios
24982512
*/

0 commit comments

Comments
 (0)