dm thin: fix a race in thin_dtr
authorMikulas Patocka <mpatocka@redhat.com>
Wed, 5 Nov 2014 22:00:13 +0000 (17:00 -0500)
committerMike Snitzer <snitzer@redhat.com>
Thu, 13 Nov 2014 01:15:04 +0000 (20:15 -0500)
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>
drivers/md/dm-thin.c

index 8c5504c0e8943be13f06fec2b511c68d61d4a719..767417a28b6fcd37bef7e37e06ad8a7f7587e92e 100644 (file)
@@ -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);