[PATCH v2 2/2] nvme: enable generic interface (/dev/ngXnY) for unknown command sets

Christoph Hellwig hch at lst.de
Mon Jun 13 11:24:39 PDT 2022


On Tue, Jun 07, 2022 at 03:40:55PM +0200, Joel Granados wrote:

>  static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid,
>  		struct nvme_ns_ids *ids)
>  {
> +	int ret = 0;
>  	struct nvme_ns *ns;
>  	struct gendisk *disk;
>  	struct nvme_id_ns *id;
> +	struct nvme_id_ns_cs_indep *indep_id;
>  	int node = ctrl->numa_node;
> +	bool cs_indep = nvme_ns_indep(ids);
>  
> -	if (nvme_identify_ns(ctrl, nsid, ids, &id))
> +	if (cs_indep)
> +		ret = nvme_identify_ns_cs_indep(ctrl, nsid, &indep_id);
> +	else
> +		ret = nvme_identify_ns(ctrl, nsid, ids, &id);

nvme_validate_or_alloc_ns already does the nvme_identify_ns_cs_indep, so
we should be able to reuse it or move it here.

> -	if (nvme_init_ns_head(ns, nsid, ids, id->nmic & NVME_NS_NMIC_SHARED))
> +	if (nvme_init_ns_head(ns, nsid, ids,
> +			      (cs_indep ? indep_id->nmic : id->nmic) & NVME_NS_NMIC_SHARED))

This is pretty ugly.  I think if there is no command set idepdent
structure supported, we should probably just fake one up based on the
legacy Identify Namespace.

> +	if (cs_indep)
> +		ret = nvme_update_ns_info_cs_indep(ns, indep_id);
> +	else
> +		ret = nvme_update_ns_info(ns, id);

And here we should do a switch on ids->csi ala:

	 switch (ids.csi) {
	 case NVME_CSI_NVM:
	 case NVME_CSI_ZNS:
	 	ret = nvme_update_ns_info_block(ns, id);
		break
	default:
		nvme_update_ns_info_generic(ns, iid);
		break;
	}



More information about the Linux-nvme mailing list