[PATCH 19/20] nvme: refactor nvme_validate_ns

Christoph Hellwig hch at lst.de
Tue Sep 29 14:40:47 EDT 2020


On Mon, Sep 28, 2020 at 03:15:57PM +0000, Damien Le Moal wrote:
> On 2020/09/28 21:35, Christoph Hellwig wrote:
> > Move the logic to revalidate the block_device size or remove the
> > namespace from the caller into nvme_validate_ns.  This removes
> > the return value and thus the status code translation.  Additionally
> > it also catches non-permanent errors from nvme_update_ns_info using
> > the existing logic.
> > 
> > Signed-off-by: Christoph Hellwig <hch at lst.de>
> > ---
> >  drivers/nvme/host/core.c | 37 +++++++++++++++++--------------------
> >  1 file changed, 17 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 07309f6c14faab..0b88a377a47f6e 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -3899,6 +3899,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)
> >  	if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
> >  		return;
> >  
> > +	set_capacity(ns->disk, 0);
> >  	nvme_fault_inject_fini(&ns->fault_inject);
> >  
> >  	mutex_lock(&ns->ctrl->subsys->lock);
> > @@ -3936,58 +3937,54 @@ static void nvme_ns_remove_by_nsid(struct nvme_ctrl *ctrl, u32 nsid)
> >  	}
> >  }
> >  
> > -static int nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)
> > +static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_ids *ids)
> >  {
> >  	struct nvme_ctrl *ctrl = ns->ctrl;
> >  	struct nvme_id_ns *id;
> > -	int ret = 0;
> > +	int ret = -ENODEV;
> 
> No assignment needed. nvme_identify_ns() will overwrite it.
> 
> >  
> > -	if (test_bit(NVME_NS_DEAD, &ns->flags)) {
> > -		set_capacity(ns->disk, 0);
> > -		return -ENODEV;
> > -	}
> > +	if (test_bit(NVME_NS_DEAD, &ns->flags))
> > +		goto out;

.. but we can already jump to out here, so we do actually need it.



More information about the Linux-nvme mailing list