From owner-svn-src-head@freebsd.org Tue Aug 13 21:49:08 2019 Return-Path: Delivered-To: svn-src-head@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 7B9C1BE3E1; Tue, 13 Aug 2019 21:49:08 +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 467RF02XVZz4ShB; Tue, 13 Aug 2019 21:49:08 +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 340FB1DEE5; Tue, 13 Aug 2019 21:49:08 +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 x7DLn8Ij039949; Tue, 13 Aug 2019 21:49:08 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x7DLn8vh039948; Tue, 13 Aug 2019 21:49:08 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201908132149.x7DLn8vh039948@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 13 Aug 2019 21:49:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351004 - head/sys/dev/nvd X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: head/sys/dev/nvd X-SVN-Commit-Revision: 351004 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Aug 2019 21:49:08 -0000 Author: mav Date: Tue Aug 13 21:49:07 2019 New Revision: 351004 URL: https://svnweb.freebsd.org/changeset/base/351004 Log: 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. MFC after: 1 weeks Sponsored by: iXsystems, Inc. Modified: head/sys/dev/nvd/nvd.c Modified: head/sys/dev/nvd/nvd.c ============================================================================== --- head/sys/dev/nvd/nvd.c Tue Aug 13 21:15:59 2019 (r351003) +++ head/sys/dev/nvd/nvd.c Tue Aug 13 21:49:07 2019 (r351004) @@ -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,47 @@ 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) + 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) + 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 +445,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;