diff mbox series

[1/7] ubd: remove the ubd_gendisk array

Message ID 20240222072417.3773131-2-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/7] ubd: remove the ubd_gendisk array | expand

Commit Message

Christoph Hellwig Feb. 22, 2024, 7:24 a.m. UTC
And add a disk pointer to the ubd structure instead to keep all
the per-device information together.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/um/drivers/ubd_kern.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

Comments

Richard Weinberger Feb. 27, 2024, 8:52 p.m. UTC | #1
----- Ursprüngliche Mail -----
> Von: "hch" <hch@lst.de>
> An: "richard" <richard@nod.at>, "anton ivanov" <anton.ivanov@cambridgegreys.com>, "Johannes Berg"
> <johannes@sipsolutions.net>, "Jens Axboe" <axboe@kernel.dk>
> CC: "linux-um" <linux-um@lists.infradead.org>, "linux-block" <linux-block@vger.kernel.org>
> Gesendet: Donnerstag, 22. Februar 2024 08:24:11
> Betreff: [PATCH 1/7] ubd: remove the ubd_gendisk array

> And add a disk pointer to the ubd structure instead to keep all
> the per-device information together.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> arch/um/drivers/ubd_kern.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
> index 48e11f073551b4..b203ebb1785125 100644
> --- a/arch/um/drivers/ubd_kern.c
> +++ b/arch/um/drivers/ubd_kern.c
> @@ -125,9 +125,6 @@ static const struct block_device_operations ubd_blops = {
> 	.getgeo		= ubd_getgeo,
> };
> 
> -/* Protected by ubd_lock */
> -static struct gendisk *ubd_gendisk[MAX_DEV];
> -
> #ifdef CONFIG_BLK_DEV_UBD_SYNC
> #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
> 					 .cl = 1 })
> @@ -165,6 +162,7 @@ struct ubd {
> 	unsigned no_trim:1;
> 	struct cow cow;
> 	struct platform_device pdev;
> +	struct gendisk *disk;
> 	struct request_queue *queue;
> 	struct blk_mq_tag_set tag_set;
> 	spinlock_t lock;
> @@ -922,7 +920,6 @@ static int ubd_add(int n, char **error_out)
> 	if (err)
> 		goto out_cleanup_disk;
> 
> -	ubd_gendisk[n] = disk;
> 	return 0;
> 
> out_cleanup_disk:
> @@ -1014,7 +1011,6 @@ static int ubd_id(char **str, int *start_out, int
> *end_out)
> 
> static int ubd_remove(int n, char **error_out)
> {
> -	struct gendisk *disk = ubd_gendisk[n];
> 	struct ubd *ubd_dev;
> 	int err = -ENODEV;
> 
> @@ -1030,10 +1026,9 @@ static int ubd_remove(int n, char **error_out)
> 	if(ubd_dev->count > 0)
> 		goto out;
> 
> -	ubd_gendisk[n] = NULL;
> -	if(disk != NULL){
> -		del_gendisk(disk);
> -		put_disk(disk);
> +	if (ubd_dev->disk) {
> +		del_gendisk(ubd_dev->disk);
> +		put_disk(ubd_dev->disk);
> 	}

Reviewed-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard
diff mbox series

Patch

diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 48e11f073551b4..b203ebb1785125 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -125,9 +125,6 @@  static const struct block_device_operations ubd_blops = {
 	.getgeo		= ubd_getgeo,
 };
 
-/* Protected by ubd_lock */
-static struct gendisk *ubd_gendisk[MAX_DEV];
-
 #ifdef CONFIG_BLK_DEV_UBD_SYNC
 #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
 					 .cl = 1 })
@@ -165,6 +162,7 @@  struct ubd {
 	unsigned no_trim:1;
 	struct cow cow;
 	struct platform_device pdev;
+	struct gendisk *disk;
 	struct request_queue *queue;
 	struct blk_mq_tag_set tag_set;
 	spinlock_t lock;
@@ -922,7 +920,6 @@  static int ubd_add(int n, char **error_out)
 	if (err)
 		goto out_cleanup_disk;
 
-	ubd_gendisk[n] = disk;
 	return 0;
 
 out_cleanup_disk:
@@ -1014,7 +1011,6 @@  static int ubd_id(char **str, int *start_out, int *end_out)
 
 static int ubd_remove(int n, char **error_out)
 {
-	struct gendisk *disk = ubd_gendisk[n];
 	struct ubd *ubd_dev;
 	int err = -ENODEV;
 
@@ -1030,10 +1026,9 @@  static int ubd_remove(int n, char **error_out)
 	if(ubd_dev->count > 0)
 		goto out;
 
-	ubd_gendisk[n] = NULL;
-	if(disk != NULL){
-		del_gendisk(disk);
-		put_disk(disk);
+	if (ubd_dev->disk) {
+		del_gendisk(ubd_dev->disk);
+		put_disk(ubd_dev->disk);
 	}
 
 	err = 0;