diff options
Diffstat (limited to 'drivers/block/loop.c')
-rw-r--r-- | drivers/block/loop.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index fe5f6403417f..dfe758382eaf 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c | |||
@@ -922,6 +922,11 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, | |||
922 | lo->lo_flags |= LO_FLAGS_PARTSCAN; | 922 | lo->lo_flags |= LO_FLAGS_PARTSCAN; |
923 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | 923 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) |
924 | ioctl_by_bdev(bdev, BLKRRPART, 0); | 924 | ioctl_by_bdev(bdev, BLKRRPART, 0); |
925 | |||
926 | /* Grab the block_device to prevent its destruction after we | ||
927 | * put /dev/loopXX inode. Later in loop_clr_fd() we bdput(bdev). | ||
928 | */ | ||
929 | bdgrab(bdev); | ||
925 | return 0; | 930 | return 0; |
926 | 931 | ||
927 | out_clr: | 932 | out_clr: |
@@ -1031,8 +1036,10 @@ static int loop_clr_fd(struct loop_device *lo) | |||
1031 | memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); | 1036 | memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); |
1032 | memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); | 1037 | memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); |
1033 | memset(lo->lo_file_name, 0, LO_NAME_SIZE); | 1038 | memset(lo->lo_file_name, 0, LO_NAME_SIZE); |
1034 | if (bdev) | 1039 | if (bdev) { |
1040 | bdput(bdev); | ||
1035 | invalidate_bdev(bdev); | 1041 | invalidate_bdev(bdev); |
1042 | } | ||
1036 | set_capacity(lo->lo_disk, 0); | 1043 | set_capacity(lo->lo_disk, 0); |
1037 | loop_sysfs_exit(lo); | 1044 | loop_sysfs_exit(lo); |
1038 | if (bdev) { | 1045 | if (bdev) { |
@@ -1044,29 +1051,12 @@ static int loop_clr_fd(struct loop_device *lo) | |||
1044 | lo->lo_state = Lo_unbound; | 1051 | lo->lo_state = Lo_unbound; |
1045 | /* This is safe: open() is still holding a reference. */ | 1052 | /* This is safe: open() is still holding a reference. */ |
1046 | module_put(THIS_MODULE); | 1053 | module_put(THIS_MODULE); |
1054 | if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev) | ||
1055 | ioctl_by_bdev(bdev, BLKRRPART, 0); | ||
1047 | lo->lo_flags = 0; | 1056 | lo->lo_flags = 0; |
1048 | if (!part_shift) | 1057 | if (!part_shift) |
1049 | lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; | 1058 | lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; |
1050 | mutex_unlock(&lo->lo_ctl_mutex); | 1059 | 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 | |||
1070 | /* | 1060 | /* |
1071 | * Need not hold lo_ctl_mutex to fput backing file. | 1061 | * Need not hold lo_ctl_mutex to fput backing file. |
1072 | * Calling fput holding lo_ctl_mutex triggers a circular | 1062 | * Calling fput holding lo_ctl_mutex triggers a circular |