Skip to content

Commit d2c7f56

Browse files
Christoph Hellwigaxboe
authored andcommitted
loop: implement ->free_disk
Ensure that the lo_device which is stored in the gendisk private data is valid until the gendisk is freed. Currently the loop driver uses a lot of effort to make sure a device is not freed when it is still in use, but to to fix a potential deadlock this will be relaxed a bit soon. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1fe0b1a commit d2c7f56

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/block/loop.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,14 @@ static void lo_release(struct gendisk *disk, fmode_t mode)
17611761
mutex_unlock(&lo->lo_mutex);
17621762
}
17631763

1764+
static void lo_free_disk(struct gendisk *disk)
1765+
{
1766+
struct loop_device *lo = disk->private_data;
1767+
1768+
mutex_destroy(&lo->lo_mutex);
1769+
kfree(lo);
1770+
}
1771+
17641772
static const struct block_device_operations lo_fops = {
17651773
.owner = THIS_MODULE,
17661774
.open = lo_open,
@@ -1769,6 +1777,7 @@ static const struct block_device_operations lo_fops = {
17691777
#ifdef CONFIG_COMPAT
17701778
.compat_ioctl = lo_compat_ioctl,
17711779
#endif
1780+
.free_disk = lo_free_disk,
17721781
};
17731782

17741783
/*
@@ -2060,15 +2069,14 @@ static void loop_remove(struct loop_device *lo)
20602069
{
20612070
/* Make this loop device unreachable from pathname. */
20622071
del_gendisk(lo->lo_disk);
2063-
blk_cleanup_disk(lo->lo_disk);
2072+
blk_cleanup_queue(lo->lo_disk->queue);
20642073
blk_mq_free_tag_set(&lo->tag_set);
20652074

20662075
mutex_lock(&loop_ctl_mutex);
20672076
idr_remove(&loop_index_idr, lo->lo_number);
20682077
mutex_unlock(&loop_ctl_mutex);
2069-
/* There is no route which can find this loop device. */
2070-
mutex_destroy(&lo->lo_mutex);
2071-
kfree(lo);
2078+
2079+
put_disk(lo->lo_disk);
20722080
}
20732081

20742082
static void loop_probe(dev_t dev)

0 commit comments

Comments
 (0)