Skip to content

Commit cddae80

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: pass a hd_struct to delete_partition
All callers have the hd_struct at hand, so pass it instead of performing another lookup. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fa9156a commit cddae80

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

‎block/blk.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
390390
#define ADDPART_FLAG_RAID 1
391391
#define ADDPART_FLAG_WHOLEDISK 2
392392
void __delete_partition(struct percpu_ref *ref);
393-
void delete_partition(struct gendisk *disk, int partno);
393+
void delete_partition(struct gendisk *disk, struct hd_struct *part);
394394
int bdev_add_partition(struct block_device *bdev, int partno,
395395
sector_t start, sector_t length);
396396
int bdev_del_partition(struct block_device *bdev, int partno);

‎block/genhd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ void del_gendisk(struct gendisk *disk)
897897
while ((part = disk_part_iter_next(&piter))) {
898898
invalidate_partition(disk, part->partno);
899899
bdev_unhash_inode(part_devt(part));
900-
delete_partition(disk, part->partno);
900+
delete_partition(disk, part);
901901
}
902902
disk_part_iter_exit(&piter);
903903

‎block/partitions/core.c‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,12 @@ void __delete_partition(struct percpu_ref *ref)
296296
* Must be called either with bd_mutex held, before a disk can be opened or
297297
* after all disk users are gone.
298298
*/
299-
void delete_partition(struct gendisk *disk, int partno)
299+
void delete_partition(struct gendisk *disk, struct hd_struct *part)
300300
{
301301
struct disk_part_tbl *ptbl =
302302
rcu_dereference_protected(disk->part_tbl, 1);
303-
struct hd_struct *part;
304-
305-
if (partno >= ptbl->len)
306-
return;
307303

308-
part = rcu_dereference_protected(ptbl->part[partno], 1);
309-
if (!part)
310-
return;
311-
312-
rcu_assign_pointer(ptbl->part[partno], NULL);
304+
rcu_assign_pointer(ptbl->part[part->partno], NULL);
313305
rcu_assign_pointer(ptbl->last_lookup, NULL);
314306
kobject_put(part->holder_dir);
315307
device_del(part_to_dev(part));
@@ -520,10 +512,10 @@ int bdev_del_partition(struct block_device *bdev, int partno)
520512
if (!part)
521513
return -ENXIO;
522514

515+
ret = -ENOMEM;
523516
bdevp = bdget(part_devt(part));
524-
disk_put_part(part);
525517
if (!bdevp)
526-
return -ENOMEM;
518+
goto out_put_part;
527519

528520
mutex_lock(&bdevp->bd_mutex);
529521

@@ -535,13 +527,15 @@ int bdev_del_partition(struct block_device *bdev, int partno)
535527
invalidate_bdev(bdevp);
536528

537529
mutex_lock_nested(&bdev->bd_mutex, 1);
538-
delete_partition(bdev->bd_disk, partno);
530+
delete_partition(bdev->bd_disk, part);
539531
mutex_unlock(&bdev->bd_mutex);
540532

541533
ret = 0;
542534
out_unlock:
543535
mutex_unlock(&bdevp->bd_mutex);
544536
bdput(bdevp);
537+
out_put_part:
538+
disk_put_part(part);
545539
return ret;
546540
}
547541

@@ -617,7 +611,7 @@ int blk_drop_partitions(struct gendisk *disk, struct block_device *bdev)
617611

618612
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
619613
while ((part = disk_part_iter_next(&piter)))
620-
delete_partition(disk, part->partno);
614+
delete_partition(disk, part);
621615
disk_part_iter_exit(&piter);
622616

623617
return 0;

0 commit comments

Comments
 (0)