From owner-svn-src-stable@freebsd.org Tue Aug 27 04:01:10 2019 Return-Path: Delivered-To: svn-src-stable@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 72A21C8502; Tue, 27 Aug 2019 04:01:10 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46HZtG1ZcSz4K11; Tue, 27 Aug 2019 04:01:10 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F195D18E82; Tue, 27 Aug 2019 04:01:09 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x7R419ki096585; Tue, 27 Aug 2019 04:01:09 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7R419bs096584; Tue, 27 Aug 2019 04:01:09 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201908270401.x7R419bs096584@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 27 Aug 2019 04:01:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r351531 - stable/12/sys/dev/nvd X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/dev/nvd X-SVN-Commit-Revision: 351531 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Aug 2019 04:01:10 -0000 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;