Skip to content

Commit

Permalink
dm thin: fix a race in thin_dtr
Browse files Browse the repository at this point in the history
As long as struct thin_c is in the list, anyone can grab a reference of
it.  Consequently, we must wait for the reference count to drop to zero
*after* we remove the structure from the list, not before.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Mikulas Patocka authored and Mike Snitzer committed Nov 13, 2014
1 parent d1d9220 commit 17181fb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/md/dm-thin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3622,14 +3622,14 @@ static void thin_dtr(struct dm_target *ti)
struct thin_c *tc = ti->private;
unsigned long flags;

thin_put(tc);
wait_for_completion(&tc->can_destroy);

spin_lock_irqsave(&tc->pool->lock, flags);
list_del_rcu(&tc->list);
spin_unlock_irqrestore(&tc->pool->lock, flags);
synchronize_rcu();

thin_put(tc);
wait_for_completion(&tc->can_destroy);

mutex_lock(&dm_thin_pool_table.mutex);

__pool_dec(tc->pool);
Expand Down

0 comments on commit 17181fb

Please sign in to comment.