Commit 87cad790 authored by Seth Forshee's avatar Seth Forshee

loop: Refuse to tear down loop device if partitions are open

loop_clr_fd defers teardown if the loop device itself is
referenced but proceeds when a partition of the loop device is
open. When this happens partition scanning will fail, leaving
behind the block devices for the loop device's partitions.
Prevent this by returning -EBUSY when attempting to tear down
the loop device while any partition block device is open.
Signed-off-by: default avatarSeth Forshee <seth.forshee@canonical.com>
parent 23d19cbb
......@@ -843,6 +843,10 @@ static int loop_clr_fd(struct loop_device *lo)
if (lo->lo_state != Lo_bound)
return -ENXIO;
/* Fail if any partitions open */
if (bdev && bdev->bd_part_count > 0)
return -EBUSY;
/*
* If we've explicitly asked to tear down the loop device,
* and it has an elevated reference count, set it for auto-teardown when
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment