]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
loop: cleanup partitions when detaching loop device
authorPhillip Susi <psusi@ubuntu.com>
Wed, 20 Mar 2013 04:07:00 +0000 (15:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 21 Mar 2013 05:28:20 +0000 (16:28 +1100)
Any partitions added by user space to the loop device were being left in
place after detaching the loop device.  This was because the detach path
issued a BLKRRPART to clean up partitions if LO_FLAGS_PARTSCAN was set,
meaning that the partitions were auto scanned on attach.  Replace this
BLKRRPART with code that unconditionally cleans up partitions on detach
instead.

The user-visible effect of this bug is that the partition devnodes still
show up after detaching the backing file, and I think the partitions
remained in place after attaching a new file even though it had different
or no partitions at all.

Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/loop.c

index 747bb2af69dcc55fec530466a9f55d06914ba8f7..738cb0c6f9c3d2bef2b6953b5333ee62100e3d75 100644 (file)
@@ -1044,12 +1044,24 @@ static int loop_clr_fd(struct loop_device *lo)
        lo->lo_state = Lo_unbound;
        /* This is safe: open() is still holding a reference. */
        module_put(THIS_MODULE);
-       if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
-               ioctl_by_bdev(bdev, BLKRRPART, 0);
        lo->lo_flags = 0;
        if (!part_shift)
                lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;
        mutex_unlock(&lo->lo_ctl_mutex);
+       if (bdev)
+       {
+               struct disk_part_iter piter;
+               struct hd_struct *part;
+
+               mutex_lock_nested(&bdev->bd_mutex, 1);
+               invalidate_partition(bdev->bd_disk, 0);
+               disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
+               while ((part = disk_part_iter_next(&piter)))
+                       delete_partition(bdev->bd_disk, part->partno);
+               disk_part_iter_exit(&piter);
+               mutex_unlock(&bdev->bd_mutex);
+       }
+
        /*
         * Need not hold lo_ctl_mutex to fput backing file.
         * Calling fput holding lo_ctl_mutex triggers a circular