diff mbox series

[v2,03/34] block/genhd: port disk_scan_partitions() to file

Message ID 20240123-vfs-bdev-file-v2-3-adbd023e19cc@kernel.org (mailing list archive)
State New, archived
Headers show
Series Open block devices as files | expand

Commit Message

Christian Brauner Jan. 23, 2024, 1:26 p.m. UTC
This may run from a kernel thread via device_add_disk(). So this could
also use __fput_sync() if we were worried about EBUSY. But when it is
called from a kernel thread it's always BLK_OPEN_READ so EBUSY can't
really happen even if we do BLK_OPEN_RESTRICT_WRITES or BLK_OPEN_EXCL.

Otherwise it's called from an ioctl on the block device which is only
called from userspace and can rely on task work.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 block/genhd.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Christoph Hellwig Jan. 29, 2024, 4:14 p.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Jan Kara Jan. 31, 2024, 6:13 p.m. UTC | #2
On Tue 23-01-24 14:26:20, Christian Brauner wrote:
> This may run from a kernel thread via device_add_disk(). So this could
> also use __fput_sync() if we were worried about EBUSY. But when it is
> called from a kernel thread it's always BLK_OPEN_READ so EBUSY can't
> really happen even if we do BLK_OPEN_RESTRICT_WRITES or BLK_OPEN_EXCL.
> 
> Otherwise it's called from an ioctl on the block device which is only
> called from userspace and can rely on task work.
> 
> Signed-off-by: Christian Brauner <brauner@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  block/genhd.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index d74fb5b4ae68..a911d2969c07 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(disk_uevent);
>  
>  int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
>  {
> -	struct bdev_handle *handle;
> +	struct file *file;
>  	int ret = 0;
>  
>  	if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
> @@ -366,12 +366,12 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
>  	}
>  
>  	set_bit(GD_NEED_PART_SCAN, &disk->state);
> -	handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL,
> -				  NULL);
> -	if (IS_ERR(handle))
> -		ret = PTR_ERR(handle);
> +	file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL,
> +				     NULL, NULL);
> +	if (IS_ERR(file))
> +		ret = PTR_ERR(file);
>  	else
> -		bdev_release(handle);
> +		fput(file);
>  
>  	/*
>  	 * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set,
> 
> -- 
> 2.43.0
>
diff mbox series

Patch

diff --git a/block/genhd.c b/block/genhd.c
index d74fb5b4ae68..a911d2969c07 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -342,7 +342,7 @@  EXPORT_SYMBOL_GPL(disk_uevent);
 
 int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 {
-	struct bdev_handle *handle;
+	struct file *file;
 	int ret = 0;
 
 	if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN))
@@ -366,12 +366,12 @@  int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode)
 	}
 
 	set_bit(GD_NEED_PART_SCAN, &disk->state);
-	handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL,
-				  NULL);
-	if (IS_ERR(handle))
-		ret = PTR_ERR(handle);
+	file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL,
+				     NULL, NULL);
+	if (IS_ERR(file))
+		ret = PTR_ERR(file);
 	else
-		bdev_release(handle);
+		fput(file);
 
 	/*
 	 * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set,