[PATCH 3/5] nvme: refactor namespace probing

Joel Granados j.granados at samsung.com
Wed Jul 20 01:11:54 PDT 2022


On Tue, Jul 19, 2022 at 04:37:03PM +0200, Christoph Hellwig wrote:
> On Tue, Jul 19, 2022 at 03:00:48PM +0200, Joel Granados wrote:
> > > +++ b/drivers/nvme/host/core.c
> > > @@ -2011,8 +2011,10 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
> > > 
> > >        if (blk_queue_is_zoned(ns->queue)) {
> > >                ret = nvme_revalidate_zones(ns);
> > > -               if (ret && !nvme_first_scan(ns->disk))
> > > +               if (ret && !nvme_first_scan(ns->disk)) {
> > > +                       kfree(id);
> > >                        return ret;
> > > +               }
> > >        }
> > > 	
> > 
> > Should we also take care to hide the device?
> > As I read it the call to nvme_revalidate_zones can return a -ENODEV
> > (through blk_revalidate_disk_zones) which is the original condition to
> > hide the block device.
> 
> Yes, I think we need something like the patch below folded in.  This
> unfreezes before setting the hidden flag and setting the ns ready,
> but I can't see why we'd need it frozen for that.
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index bbdf0f95331f3..e6025f80744f6 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2012,7 +2012,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
>  	if (blk_queue_is_zoned(ns->queue)) {
>  		ret = nvme_revalidate_zones(ns);
>  		if (ret && !nvme_first_scan(ns->disk))
> -			return ret;
> +			goto out_free_id;
>  	}
>  
>  	if (nvme_ns_head_multipath(ns->head)) {
> @@ -2029,6 +2029,8 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
>  	return 0;
>  
>  out_unfreeze:
> +	blk_mq_unfreeze_queue(ns->disk->queue);
> +out_free_id:
>  	/*
>  	 * If probing fails due an unsupported feature, hide the block device,
>  	 * but still allow other access.
> @@ -2038,7 +2040,6 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
>  		set_bit(NVME_NS_READY, &ns->flags);
>  		ret = 0;
>  	}
> -	blk_mq_unfreeze_queue(ns->disk->queue);
>  	kfree(id);
>  	return ret;
>  }

Yes. And with unfreeze in its own goto, we can return with the
out_free_id on success. In this way we do not duplicate the 'kfree' line
and future uses of 'ret' will just work.
Something like this:

diff --git i/drivers/nvme/host/core.c w/drivers/nvme/host/core.c
index bbdf0f95331f..8359efbb1d29 100644
--- i/drivers/nvme/host/core.c
+++ w/drivers/nvme/host/core.c
@@ -2012,7 +2012,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
        if (blk_queue_is_zoned(ns->queue)) {
                ret = nvme_revalidate_zones(ns);
                if (ret && !nvme_first_scan(ns->disk))
-                       return ret;
+                       goto out_free_id;
        }
 
        if (nvme_ns_head_multipath(ns->head)) {
@@ -2025,10 +2025,11 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
                disk_update_readahead(ns->head->disk);
                blk_mq_unfreeze_queue(ns->head->disk->queue);
        }
-       kfree(id);
-       return 0;
+       goto out_free_id;
 
 out_unfreeze:
+       blk_mq_unfreeze_queue(ns->disk->queue);
+out_free_id:
        /*
         * If probing fails due an unsupported feature, hide the block device,
         * but still allow other access.
@@ -2038,7 +2039,6 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
                set_bit(NVME_NS_READY, &ns->flags);
                ret = 0;
        }
-       blk_mq_unfreeze_queue(ns->disk->queue);
        kfree(id);
        return ret;
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20220720/ec4d6c31/attachment.sig>


More information about the Linux-nvme mailing list