[PATCH] nvme: keep ctrl->namespaces ordered

Christoph Hellwig hch at lst.de
Wed Sep 15 06:47:18 PDT 2021


On Wed, Sep 15, 2021 at 05:37:35AM -0700, Keith Busch wrote:
> On Wed, Sep 15, 2021 at 07:36:04AM +0000, Damien Le Moal wrote:
> > > +static void nvme_ns_add_to_ctrl_list(struct nvme_ns *ns)
> > > +{
> > > +	struct nvme_ns *tmp;
> > > +
> > > +	list_for_each_entry_reverse(tmp, &ns->ctrl->namespaces, list) {
> > > +		if (tmp->head->ns_id < ns->head->ns_id) {
> > > +			list_add(&tmp->list, &ns->ctrl->namespaces);
> > > +			return;
> > > +		}
> > > +	}
> > > +
> > > +	list_add_tail(&ns->list, &ns->ctrl->namespaces);
> > 
> > I wonder if it is worth checking that ns->head->id is not equal to the ID of the
> > first NS in the list. That can only happen for a very buggy system or device,
> > but that is not unheard of...
> 
> We would never be able to hit the condition of two heads with matching
> NSID's. If the controller was broken and provided duplicate NSIDs in the
> namespace list, this driver will just recheck the first namespace rather
> than allocate a new one.

Indeed.  So back to v1 for review then.



More information about the Linux-nvme mailing list