nvme: Change namespace device name

Changes the device name for NVMe and NVMe-oF namespaces from using "ns"
to "n" to be more compatible with other operating systems. For example,
a device which was previously /dev/nvme0ns1 is now /dev/nvme0n1.

Preserves the existing functionality by creating alias from nvmeXnY to
nvmeXnsY.

Reviewed by:	imp
MFC after:	1 month
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D45414
This commit is contained in:
Chuck Tuffli 2024-06-01 04:08:24 -07:00
parent 3dc2a88489
commit ce75bfcac9
3 changed files with 14 additions and 6 deletions

View file

@ -1478,8 +1478,8 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev)
md_args.mda_mode = 0600;
md_args.mda_unit = device_get_unit(dev);
md_args.mda_si_drv1 = (void *)ctrlr;
status = make_dev_s(&md_args, &ctrlr->cdev, "nvme%d",
device_get_unit(dev));
status = make_dev_s(&md_args, &ctrlr->cdev, "%s",
device_get_nameunit(dev));
if (status != 0)
return (ENXIO);

View file

@ -604,10 +604,12 @@ nvme_ns_construct(struct nvme_namespace *ns, uint32_t id,
md_args.mda_unit = unit;
md_args.mda_mode = 0600;
md_args.mda_si_drv1 = ns;
res = make_dev_s(&md_args, &ns->cdev, "nvme%dns%d",
device_get_unit(ctrlr->dev), ns->id);
res = make_dev_s(&md_args, &ns->cdev, "%sn%d",
device_get_nameunit(ctrlr->dev), ns->id);
if (res != 0)
return (ENXIO);
ns->cdev->si_drv2 = make_dev_alias(ns->cdev, "%sns%d",
device_get_nameunit(ctrlr->dev), ns->id);
ns->cdev->si_flags |= SI_UNMAPPED;
@ -618,6 +620,8 @@ void
nvme_ns_destruct(struct nvme_namespace *ns)
{
if (ns->cdev->si_drv2 != NULL)
destroy_dev(ns->cdev->si_drv2);
if (ns->cdev != NULL)
destroy_dev(ns->cdev);
}

View file

@ -49,7 +49,7 @@ ns_printf(struct nvmf_namespace *ns, const char *fmt, ...)
sbuf_new(&sb, buf, sizeof(buf), SBUF_FIXEDLEN);
sbuf_set_drain(&sb, sbuf_printf_drain, NULL);
sbuf_printf(&sb, "%sns%u: ", device_get_nameunit(ns->sc->dev),
sbuf_printf(&sb, "%sn%u: ", device_get_nameunit(ns->sc->dev),
ns->id);
va_start(ap, fmt);
@ -371,10 +371,12 @@ nvmf_init_ns(struct nvmf_softc *sc, uint32_t id,
mda.mda_gid = GID_WHEEL;
mda.mda_mode = 0600;
mda.mda_si_drv1 = ns;
error = make_dev_s(&mda, &ns->cdev, "%sns%u",
error = make_dev_s(&mda, &ns->cdev, "%sn%u",
device_get_nameunit(sc->dev), id);
if (error != 0)
goto fail;
ns->cdev->si_drv2 = make_dev_alias(ns->cdev, "%sns%u",
device_get_nameunit(sc->dev), id);
ns->cdev->si_flags |= SI_UNMAPPED;
@ -418,6 +420,8 @@ nvmf_destroy_ns(struct nvmf_namespace *ns)
TAILQ_HEAD(, bio) bios;
struct bio *bio;
if (ns->cdev->si_drv2 != NULL)
destroy_dev(ns->cdev->si_drv2);
destroy_dev(ns->cdev);
/*