diff options
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r-- | drivers/block/loop.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 747bb2af69dc..fe5f6403417f 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -1044,12 +1044,29 @@ static int loop_clr_fd(struct loop_device *lo) | |||
1044 | lo->lo_state = Lo_unbound; | 1044 | lo->lo_state = Lo_unbound; |
1045 | /* This is safe: open() is still holding a reference. */ | 1045 | /* This is safe: open() is still holding a reference. */ |
1046 | module_put(THIS_MODULE); | 1046 | module_put(THIS_MODULE); |
1047 | if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev) | ||
1048 | ioctl_by_bdev(bdev, BLKRRPART, 0); | ||
1049 | lo->lo_flags = 0; | 1047 | lo->lo_flags = 0; |
1050 | if (!part_shift) | 1048 | if (!part_shift) |
1051 | lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; | 1049 | lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; |
1052 | mutex_unlock(&lo->lo_ctl_mutex); | 1050 | mutex_unlock(&lo->lo_ctl_mutex); |
1051 | |||
1052 | /* | ||
1053 | * Remove all partitions, since BLKRRPART won't remove user | ||
1054 | * added partitions when max_part=0 | ||
1055 | */ | ||
1056 | if (bdev) { | ||
1057 | struct disk_part_iter piter; | ||
1058 | struct hd_struct *part; | ||
1059 | |||
1060 | mutex_lock_nested(&bdev->bd_mutex, 1); | ||
1061 | invalidate_partition(bdev->bd_disk, 0); | ||
1062 | disk_part_iter_init(&piter, bdev->bd_disk, | ||
1063 | DISK_PITER_INCL_EMPTY); | ||
1064 | while ((part = disk_part_iter_next(&piter))) | ||
1065 | delete_partition(bdev->bd_disk, part->partno); | ||
1066 | disk_part_iter_exit(&piter); | ||
1067 | mutex_unlock(&bdev->bd_mutex); | ||
1068 | } | ||
1069 | |||
1053 | /* | 1070 | /* |
1054 | * Need not hold lo_ctl_mutex to fput backing file. | 1071 | * Need not hold lo_ctl_mutex to fput backing file. |
1055 | * Calling fput holding lo_ctl_mutex triggers a circular | 1072 | * Calling fput holding lo_ctl_mutex triggers a circular |
@@ -1623,6 +1640,7 @@ static int loop_add(struct loop_device **l, int i) | |||
1623 | goto out_free_dev; | 1640 | goto out_free_dev; |
1624 | i = err; | 1641 | i = err; |
1625 | 1642 | ||
1643 | err = -ENOMEM; | ||
1626 | lo->lo_queue = blk_alloc_queue(GFP_KERNEL); | 1644 | lo->lo_queue = blk_alloc_queue(GFP_KERNEL); |
1627 | if (!lo->lo_queue) | 1645 | if (!lo->lo_queue) |
1628 | goto out_free_dev; | 1646 | goto out_free_dev; |