Skip to content

Commit c30b978

Browse files
committed
block: simplify bdev_del_partition()
BLKPG_DEL_PARTITION refuses to delete partitions that still have openers, i.e., that has an elevated @bdev->bd_openers count. If a device is claimed by setting @bdev->bd_holder and @bdev->bd_holder_ops @bdev->bd_openers and @bdev->bd_holders are incremented. @bdev->bd_openers is effectively guaranteed to be >= @bdev->bd_holders. So as long as @bdev->bd_openers isn't zero we know that this partition is still in active use and that there might still be @bdev->bd_holder and @bdev->bd_holder_ops set. The only current example is @fs_holder_ops for filesystems. But that means bdev_mark_dead() which calls into bdev->bd_holder_ops->mark_dead::fs_bdev_mark_dead() is a nop. As long as there's an elevated @bdev->bd_openers count we can't delete the partition and if there isn't an elevated @bdev->bd_openers count then there's no @bdev->bd_holder or @bdev->bd_holder_ops. So simply open-code what we need to do. This gets rid of one more instance where we acquire s_umount under @disk->open_mutex. Link: https://lore.kernel.org/r/20231016-fototermin-umriss-59f1ea6c1fe6@brauner Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20231017184823.1383356-2-hch@lst.de Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent fd14641 commit c30b978

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

block/partitions/core.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,18 @@ int bdev_del_partition(struct gendisk *disk, int partno)
485485
if (atomic_read(&part->bd_openers))
486486
goto out_unlock;
487487

488-
delete_partition(part);
488+
/*
489+
* We verified that @part->bd_openers is zero above and so
490+
* @part->bd_holder{_ops} can't be set. And since we hold
491+
* @disk->open_mutex the device can't be claimed by anyone.
492+
*
493+
* So no need to call @part->bd_holder_ops->mark_dead() here.
494+
* Just delete the partition and invalidate it.
495+
*/
496+
497+
remove_inode_hash(part->bd_inode);
498+
invalidate_bdev(part);
499+
drop_partition(part);
489500
ret = 0;
490501
out_unlock:
491502
mutex_unlock(&disk->open_mutex);

0 commit comments

Comments
 (0)