Permalink
Browse files

MFC r257534:

Create a unique unit number for each controller and namespace cdev.

Sponsored by:	Intel
Approved by:	re (glebius)
  • Loading branch information...
1 parent e056215 commit 76e64e88a61d81b3667d049cb17dda24961289b3 @jimharris jimharris committed Nov 5, 2013
Showing with 11 additions and 4 deletions.
  1. +2 −2 sys/dev/nvme/nvme_ctrlr.c
  2. +9 −2 sys/dev/nvme/nvme_ns.c
@@ -1150,8 +1150,8 @@ nvme_ctrlr_construct(struct nvme_controller *ctrlr, device_t dev)
if (status != 0)
return (status);
- ctrlr->cdev = make_dev(&nvme_ctrlr_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
- "nvme%d", device_get_unit(dev));
+ ctrlr->cdev = make_dev(&nvme_ctrlr_cdevsw, device_get_unit(dev),
+ UID_ROOT, GID_WHEEL, 0600, "nvme%d", device_get_unit(dev));
if (ctrlr->cdev == NULL)
return (ENXIO);
View
@@ -492,6 +492,7 @@ nvme_ns_construct(struct nvme_namespace *ns, uint16_t id,
struct nvme_controller *ctrlr)
{
struct nvme_completion_poll_status status;
+ int unit;
ns->ctrlr = ctrlr;
ns->id = id;
@@ -553,18 +554,24 @@ nvme_ns_construct(struct nvme_namespace *ns, uint16_t id,
if (ns->cdev != NULL)
return (0);
+ /*
+ * Namespace IDs start at 1, so we need to subtract 1 to create a
+ * correct unit number.
+ */
+ unit = device_get_unit(ctrlr->dev) * NVME_MAX_NAMESPACES + ns->id - 1;
+
/*
* MAKEDEV_ETERNAL was added in r210923, for cdevs that will never
* be destroyed. This avoids refcounting on the cdev object.
* That should be OK case here, as long as we're not supporting PCIe
* surprise removal nor namespace deletion.
*/
#ifdef MAKEDEV_ETERNAL_KLD
- ns->cdev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &nvme_ns_cdevsw, 0,
+ ns->cdev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &nvme_ns_cdevsw, unit,
NULL, UID_ROOT, GID_WHEEL, 0600, "nvme%dns%d",
device_get_unit(ctrlr->dev), ns->id);
#else
- ns->cdev = make_dev_credf(0, &nvme_ns_cdevsw, 0,
+ ns->cdev = make_dev_credf(0, &nvme_ns_cdevsw, unit,
NULL, UID_ROOT, GID_WHEEL, 0600, "nvme%dns%d",
device_get_unit(ctrlr->dev), ns->id);
#endif

0 comments on commit 76e64e8

Please sign in to comment.