Skip to content

Commit 69cea0d

Browse files
committed
dm mpath: changes from initial m->flags locking audit
Fix locking in slow-paths where m->lock should be taken. Signed-off-by: Mike Snitzer <[email protected]>
1 parent 11ba468 commit 69cea0d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/md/dm-mpath.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ static int pg_init_all_paths(struct multipath *m)
335335

336336
static void __switch_pg(struct multipath *m, struct priority_group *pg)
337337
{
338+
lockdep_assert_held(&m->lock);
339+
338340
m->current_pg = pg;
339341

340342
/* Must we initialise the PG first, and queue I/O till it's ready? */
@@ -382,7 +384,9 @@ static struct pgpath *choose_pgpath(struct multipath *m, size_t nr_bytes)
382384
unsigned bypassed = 1;
383385

384386
if (!atomic_read(&m->nr_valid_paths)) {
387+
spin_lock_irqsave(&m->lock, flags);
385388
clear_bit(MPATHF_QUEUE_IO, &m->flags);
389+
spin_unlock_irqrestore(&m->lock, flags);
386390
goto failed;
387391
}
388392

@@ -422,8 +426,11 @@ static struct pgpath *choose_pgpath(struct multipath *m, size_t nr_bytes)
422426
continue;
423427
pgpath = choose_path_in_pg(m, pg, nr_bytes);
424428
if (!IS_ERR_OR_NULL(pgpath)) {
425-
if (!bypassed)
429+
if (!bypassed) {
430+
spin_lock_irqsave(&m->lock, flags);
426431
set_bit(MPATHF_PG_INIT_DELAY_RETRY, &m->flags);
432+
spin_unlock_irqrestore(&m->lock, flags);
433+
}
427434
return pgpath;
428435
}
429436
}
@@ -1662,9 +1669,9 @@ static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone,
16621669

16631670
spin_lock_irqsave(&m->lock, flags);
16641671
bio_list_add(&m->queued_bios, clone);
1665-
spin_unlock_irqrestore(&m->lock, flags);
16661672
if (!test_bit(MPATHF_QUEUE_IO, &m->flags))
16671673
queue_work(kmultipathd, &m->process_queued_bios);
1674+
spin_unlock_irqrestore(&m->lock, flags);
16681675

16691676
r = DM_ENDIO_INCOMPLETE;
16701677
done:
@@ -1938,6 +1945,7 @@ static int multipath_prepare_ioctl(struct dm_target *ti,
19381945
{
19391946
struct multipath *m = ti->private;
19401947
struct pgpath *current_pgpath;
1948+
unsigned long flags;
19411949
int r;
19421950

19431951
current_pgpath = READ_ONCE(m->current_pgpath);
@@ -1965,8 +1973,10 @@ static int multipath_prepare_ioctl(struct dm_target *ti,
19651973
/* Path status changed, redo selection */
19661974
(void) choose_pgpath(m, 0);
19671975
}
1976+
spin_lock_irqsave(&m->lock, flags);
19681977
if (test_bit(MPATHF_PG_INIT_REQUIRED, &m->flags))
1969-
pg_init_all_paths(m);
1978+
(void) __pg_init_all_paths(m);
1979+
spin_unlock_irqrestore(&m->lock, flags);
19701980
dm_table_run_md_queue_async(m->ti->table);
19711981
process_queued_io_list(m);
19721982
}

0 commit comments

Comments
 (0)