svn commit: r351531 - stable/12/sys/dev/nvd
Alexander Motin
mav at FreeBSD.org
Tue Aug 27 04:01:10 UTC 2019
Author: mav
Date: Tue Aug 27 04:01:09 2019
New Revision: 351531
URL: https://svnweb.freebsd.org/changeset/base/351531
Log:
MFC r351004, r351006: Make nvd(4) report NGUID or EUI64 as GEOM::lunid.
With support for multiple namespaces and multiple ports in NVMe there is
now a need for reliable unique namespace identification alike to SCSI.
Sponsored by: iXsystems, Inc.
Modified:
stable/12/sys/dev/nvd/nvd.c
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/sys/dev/nvd/nvd.c
==============================================================================
--- stable/12/sys/dev/nvd/nvd.c Tue Aug 27 03:55:38 2019 (r351530)
+++ stable/12/sys/dev/nvd/nvd.c Tue Aug 27 04:01:09 2019 (r351531)
@@ -54,6 +54,7 @@ struct nvd_controller;
static disk_ioctl_t nvd_ioctl;
static disk_strategy_t nvd_strategy;
static dumper_t nvd_dump;
+static disk_getattr_t nvd_getattr;
static void nvd_done(void *arg, const struct nvme_completion *cpl);
static void nvd_gone(struct nvd_disk *ndisk);
@@ -294,6 +295,51 @@ nvd_dump(void *arg, void *virt, vm_offset_t phys, off_
return (nvme_ns_dump(ndisk->ns, virt, offset, len));
}
+static int
+nvd_getattr(struct bio *bp)
+{
+ struct nvd_disk *ndisk = (struct nvd_disk *)bp->bio_disk->d_drv1;
+ const struct nvme_namespace_data *nsdata;
+ u_int i;
+
+ if (!strcmp("GEOM::lunid", bp->bio_attribute)) {
+ nsdata = nvme_ns_get_data(ndisk->ns);
+
+ /* Try to return NGUID as lunid. */
+ for (i = 0; i < sizeof(nsdata->nguid); i++) {
+ if (nsdata->nguid[i] != 0)
+ break;
+ }
+ if (i < sizeof(nsdata->nguid)) {
+ if (bp->bio_length < sizeof(nsdata->nguid) * 2 + 1)
+ return (EFAULT);
+ for (i = 0; i < sizeof(nsdata->nguid); i++) {
+ sprintf(&bp->bio_data[i * 2], "%02x",
+ nsdata->nguid[i]);
+ }
+ bp->bio_completed = bp->bio_length;
+ return (0);
+ }
+
+ /* Try to return EUI64 as lunid. */
+ for (i = 0; i < sizeof(nsdata->eui64); i++) {
+ if (nsdata->eui64[i] != 0)
+ break;
+ }
+ if (i < sizeof(nsdata->eui64)) {
+ if (bp->bio_length < sizeof(nsdata->eui64) * 2 + 1)
+ return (EFAULT);
+ for (i = 0; i < sizeof(nsdata->eui64); i++) {
+ sprintf(&bp->bio_data[i * 2], "%02x",
+ nsdata->eui64[i]);
+ }
+ bp->bio_completed = bp->bio_length;
+ return (0);
+ }
+ }
+ return (-1);
+}
+
static void
nvd_done(void *arg, const struct nvme_completion *cpl)
{
@@ -403,6 +449,7 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_ar
disk->d_strategy = nvd_strategy;
disk->d_ioctl = nvd_ioctl;
disk->d_dump = nvd_dump;
+ disk->d_getattr = nvd_getattr;
disk->d_gone = nvd_gonecb;
disk->d_name = NVD_STR;
disk->d_unit = ndisk->unit;
More information about the svn-src-stable-12
mailing list