All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
To: Christoph Hellwig <hch@lst.de>,
	Richard Weinberger <richard@nod.at>, Jens Axboe <axboe@kernel.dk>
Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org
Subject: Re: [PATCH 2/2] ubd: use blk_mq_alloc_disk and blk_cleanup_disk
Date: Mon, 14 Jun 2021 09:26:58 +0100	[thread overview]
Message-ID: <847f7608-1d11-1410-5394-b5aa5de9f45e@cambridgegreys.com> (raw)
In-Reply-To: <20210614060759.3965724-3-hch@lst.de>



On 14/06/2021 07:07, Christoph Hellwig wrote:
> Use blk_mq_alloc_disk and blk_cleanup_disk to simplify the gendisk and
> request_queue allocation.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   arch/um/drivers/ubd_kern.c | 44 ++++++++++++--------------------------
>   1 file changed, 14 insertions(+), 30 deletions(-)
> 
> diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
> index f508d45f7a69..0b86aa1b12f1 100644
> --- a/arch/um/drivers/ubd_kern.c
> +++ b/arch/um/drivers/ubd_kern.c
> @@ -825,7 +825,6 @@ static void ubd_device_release(struct device *dev)
>   {
>   	struct ubd *ubd_dev = dev_get_drvdata(dev);
>   
> -	blk_cleanup_queue(ubd_dev->queue);
>   	blk_mq_free_tag_set(&ubd_dev->tag_set);
>   	*ubd_dev = ((struct ubd) DEFAULT_UBD);
>   }
> @@ -865,17 +864,12 @@ static const struct attribute_group *ubd_attr_groups[] = {
>   	NULL,
>   };
>   
> -static int ubd_disk_register(int major, u64 size, int unit,
> -			     struct gendisk **disk_out)
> +static void ubd_disk_register(int major, u64 size, int unit,
> +			      struct gendisk *disk)
>   {
> -	struct gendisk *disk;
> -
> -	disk = alloc_disk(1 << UBD_SHIFT);
> -	if(disk == NULL)
> -		return -ENOMEM;
> -
>   	disk->major = major;
>   	disk->first_minor = unit << UBD_SHIFT;
> +	disk->minors = 1 << UBD_SHIFT;
>   	disk->fops = &ubd_blops;
>   	set_capacity(disk, size / 512);
>   	sprintf(disk->disk_name, "ubd%c", 'a' + unit);
> @@ -889,9 +883,6 @@ static int ubd_disk_register(int major, u64 size, int unit,
>   	disk->private_data = &ubd_devs[unit];
>   	disk->queue = ubd_devs[unit].queue;
>   	device_add_disk(&ubd_devs[unit].pdev.dev, disk, ubd_attr_groups);
> -
> -	*disk_out = disk;
> -	return 0;
>   }
>   
>   #define ROUND_BLOCK(n) ((n + (SECTOR_SIZE - 1)) & (-SECTOR_SIZE))
> @@ -903,6 +894,7 @@ static const struct blk_mq_ops ubd_mq_ops = {
>   static int ubd_add(int n, char **error_out)
>   {
>   	struct ubd *ubd_dev = &ubd_devs[n];
> +	struct gendisk *disk;
>   	int err = 0;
>   
>   	if(ubd_dev->file == NULL)
> @@ -927,32 +919,24 @@ static int ubd_add(int n, char **error_out)
>   	if (err)
>   		goto out;
>   
> -	ubd_dev->queue = blk_mq_init_queue(&ubd_dev->tag_set);
> -	if (IS_ERR(ubd_dev->queue)) {
> -		err = PTR_ERR(ubd_dev->queue);
> +	disk = blk_mq_alloc_disk(&ubd_dev->tag_set, ubd_dev);
> +	if (IS_ERR(disk)) {
> +		err = PTR_ERR(disk);
>   		goto out_cleanup_tags;
>   	}
> +	ubd_dev->queue = disk->queue;
>   
> -	ubd_dev->queue->queuedata = ubd_dev;
>   	blk_queue_write_cache(ubd_dev->queue, true, false);
> -
>   	blk_queue_max_segments(ubd_dev->queue, MAX_SG);
>   	blk_queue_segment_boundary(ubd_dev->queue, PAGE_SIZE - 1);
> -	err = ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, &ubd_gendisk[n]);
> -	if(err){
> -		*error_out = "Failed to register device";
> -		goto out_cleanup_tags;
> -	}
> -
> -	err = 0;
> -out:
> -	return err;
> +	ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, disk);
> +	ubd_gendisk[n] = disk;
> +	return 0;
>   
>   out_cleanup_tags:
>   	blk_mq_free_tag_set(&ubd_dev->tag_set);
> -	if (!(IS_ERR(ubd_dev->queue)))
> -		blk_cleanup_queue(ubd_dev->queue);
> -	goto out;
> +out:
> +	return err;
>   }
>   
>   static int ubd_config(char *str, char **error_out)
> @@ -1055,7 +1039,7 @@ static int ubd_remove(int n, char **error_out)
>   	ubd_gendisk[n] = NULL;
>   	if(disk != NULL){
>   		del_gendisk(disk);
> -		put_disk(disk);
> +		blk_cleanup_disk(disk);
>   	}
>   
>   	err = 0;
> 

This does not build for me when applied to master:


arch/um/drivers/ubd_kern.c: In function ‘ubd_add’:
arch/um/drivers/ubd_kern.c:922:9: error: implicit declaration of function ‘blk_mq_alloc_disk’; did you mean ‘blk_mq_alloc_request’? [-Werror=implicit-function-declaration]
   disk = blk_mq_alloc_disk(&ubd_dev->tag_set, ubd_dev);
          ^~~~~~~~~~~~~~~~~
          blk_mq_alloc_request
arch/um/drivers/ubd_kern.c:922:7: warning: assignment to ‘struct gendisk *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
   disk = blk_mq_alloc_disk(&ubd_dev->tag_set, ubd_dev);
        ^
arch/um/drivers/ubd_kern.c: In function ‘ubd_remove’:
arch/um/drivers/ubd_kern.c:1042:3: error: implicit declaration of function ‘blk_cleanup_disk’; did you mean ‘blk_cleanup_queue’? [-Werror=implicit-function-declaration]
    blk_cleanup_disk(disk);

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

  reply	other threads:[~2021-06-14  8:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14  6:07 cleanup ubd gendisk registration Christoph Hellwig
2021-06-14  6:07 ` Christoph Hellwig
2021-06-14  6:07 ` [PATCH 1/2] ubd: remove the code to register as the legacy IDE driver Christoph Hellwig
2021-06-14  6:07   ` Christoph Hellwig
2021-06-14  8:22   ` Anton Ivanov
2021-06-14  6:07 ` [PATCH 2/2] ubd: use blk_mq_alloc_disk and blk_cleanup_disk Christoph Hellwig
2021-06-14  6:07   ` Christoph Hellwig
2021-06-14  8:26   ` Anton Ivanov [this message]
2021-06-14  9:49     ` Christoph Hellwig
2021-06-14  9:49       ` Christoph Hellwig
2021-06-15 21:57 ` cleanup ubd gendisk registration Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=847f7608-1d11-1410-5394-b5aa5de9f45e@cambridgegreys.com \
    --to=anton.ivanov@cambridgegreys.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.