diff mbox series

[1/2] blk-mq: fix error handling in __blk_mq_alloc_disk

Message ID 20220720130541.1323531-1-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/2] blk-mq: fix error handling in __blk_mq_alloc_disk | expand

Commit Message

Christoph Hellwig July 20, 2022, 1:05 p.m. UTC
To fully clean up the queue if the disk allocation fails we need to
call blk_mq_destroy_queue and not just blk_put_queue.

Fixes: 6f8191fdf41d ("block: simplify disk shutdown")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ming Lei July 20, 2022, 11:55 p.m. UTC | #1
On Wed, Jul 20, 2022 at 03:05:40PM +0200, Christoph Hellwig wrote:
> To fully clean up the queue if the disk allocation fails we need to
> call blk_mq_destroy_queue and not just blk_put_queue.
> 
> Fixes: 6f8191fdf41d ("block: simplify disk shutdown")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  block/blk-mq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index d716b7f3763f3..70177ee74295b 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
>  
>  	disk = __alloc_disk_node(q, set->numa_node, lkclass);
>  	if (!disk) {
> -		blk_put_queue(q);
> +		blk_mq_destroy_queue(q);
>  		return ERR_PTR(-ENOMEM);
 
The same change is needed in case of blk_mq_init_allocated_queue() failure too.

Thanks,
Ming
Christoph Hellwig July 21, 2022, 5:03 a.m. UTC | #2
On Thu, Jul 21, 2022 at 07:55:03AM +0800, Ming Lei wrote:
> > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > index d716b7f3763f3..70177ee74295b 100644
> > --- a/block/blk-mq.c
> > +++ b/block/blk-mq.c
> > @@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
> >  
> >  	disk = __alloc_disk_node(q, set->numa_node, lkclass);
> >  	if (!disk) {
> > -		blk_put_queue(q);
> > +		blk_mq_destroy_queue(q);
> >  		return ERR_PTR(-ENOMEM);
>  
> The same change is needed in case of blk_mq_init_allocated_queue() failure too.

I don't think so.  blk_mq_init_allocated_queue only calls
blk_mq_add_queue_tag_set at the very end, after any failure point,
and the last failure point is blk_mq_realloc_hw_ctxs not mapping
any queues.  So what would we clean up when
blk_mq_init_allocated_queue fails?
Ming Lei July 21, 2022, 7:12 a.m. UTC | #3
On Thu, Jul 21, 2022 at 07:03:32AM +0200, Christoph Hellwig wrote:
> On Thu, Jul 21, 2022 at 07:55:03AM +0800, Ming Lei wrote:
> > > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > > index d716b7f3763f3..70177ee74295b 100644
> > > --- a/block/blk-mq.c
> > > +++ b/block/blk-mq.c
> > > @@ -3960,7 +3960,7 @@ struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
> > >  
> > >  	disk = __alloc_disk_node(q, set->numa_node, lkclass);
> > >  	if (!disk) {
> > > -		blk_put_queue(q);
> > > +		blk_mq_destroy_queue(q);
> > >  		return ERR_PTR(-ENOMEM);
> >  
> > The same change is needed in case of blk_mq_init_allocated_queue() failure too.
> 
> I don't think so.  blk_mq_init_allocated_queue only calls
> blk_mq_add_queue_tag_set at the very end, after any failure point,
> and the last failure point is blk_mq_realloc_hw_ctxs not mapping
> any queues.  So what would we clean up when
> blk_mq_init_allocated_queue fails?
 
OK, miss that, so looks fine:

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming
Jens Axboe July 21, 2022, 4:59 p.m. UTC | #4
On Wed, 20 Jul 2022 15:05:40 +0200, Christoph Hellwig wrote:
> To fully clean up the queue if the disk allocation fails we need to
> call blk_mq_destroy_queue and not just blk_put_queue.
> 
> 

Applied, thanks!

[1/2] blk-mq: fix error handling in __blk_mq_alloc_disk
      commit: 0a3e5cc7bbfcd571a2e53779ef7d7aa3c57d5432
[2/2] block: call blk_mq_exit_queue from disk_release for never added disks
      commit: c5db2cfc6274692d821d33b59acb6ff615e350c1

Best regards,
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index d716b7f3763f3..70177ee74295b 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3960,7 +3960,7 @@  struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
 
 	disk = __alloc_disk_node(q, set->numa_node, lkclass);
 	if (!disk) {
-		blk_put_queue(q);
+		blk_mq_destroy_queue(q);
 		return ERR_PTR(-ENOMEM);
 	}
 	set_bit(GD_OWNS_QUEUE, &disk->state);