svn commit: r253631 - in stable/9: sbin/nvmecontrol sys/conf sys/dev/nvd sys/dev/nvme sys/modules/nvme

Jim Harris jimharris at FreeBSD.org
Wed Jul 24 22:48:32 UTC 2013


Author: jimharris
Date: Wed Jul 24 22:48:29 2013
New Revision: 253631
URL: http://svnweb.freebsd.org/changeset/base/253631

Log:
  MFC r253476:
  
    Add message when nvd disks are attached and detached.
  
    As part of this commit, add an nvme_strvis() function which borrows
    heavily from cam_strvis().  This will allow stripping of
    leading/trailing whitespace and also handle unprintable characters
    in model/serial numbers.  This function goes into a new nvme_util.c
    file which is used by both the driver and nvmecontrol.
  
  Approved by:	re (kib)
  Sponsored by:	Intel

Added:
  stable/9/sys/dev/nvme/nvme_util.c
     - copied unchanged from r253476, head/sys/dev/nvme/nvme_util.c
Modified:
  stable/9/sbin/nvmecontrol/Makefile
  stable/9/sbin/nvmecontrol/devlist.c
  stable/9/sbin/nvmecontrol/identify.c
  stable/9/sys/conf/files.amd64
  stable/9/sys/conf/files.i386
  stable/9/sys/dev/nvd/nvd.c
  stable/9/sys/dev/nvme/nvme.c
  stable/9/sys/dev/nvme/nvme.h
  stable/9/sys/modules/nvme/Makefile
Directory Properties:
  stable/9/sbin/nvmecontrol/   (props changed)
  stable/9/sys/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/dev/   (props changed)
  stable/9/sys/modules/   (props changed)

Modified: stable/9/sbin/nvmecontrol/Makefile
==============================================================================
--- stable/9/sbin/nvmecontrol/Makefile	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sbin/nvmecontrol/Makefile	Wed Jul 24 22:48:29 2013	(r253631)
@@ -2,7 +2,9 @@
 
 PROG=	nvmecontrol
 SRCS=	nvmecontrol.c devlist.c firmware.c identify.c logpage.c	\
-	perftest.c reset.c
+	perftest.c reset.c nvme_util.c
 MAN=	nvmecontrol.8
 
+.PATH:	${.CURDIR}/../../sys/dev/nvme
+
 .include <bsd.prog.mk>

Modified: stable/9/sbin/nvmecontrol/devlist.c
==============================================================================
--- stable/9/sbin/nvmecontrol/devlist.c	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sbin/nvmecontrol/devlist.c	Wed Jul 24 22:48:29 2013	(r253631)
@@ -62,6 +62,7 @@ devlist(int argc, char *argv[])
 	struct nvme_controller_data	cdata;
 	struct nvme_namespace_data	nsdata;
 	char				name[64];
+	uint8_t				mn[64];
 	uint32_t			i;
 	int				ch, ctrlr, fd, found, ret;
 
@@ -91,7 +92,8 @@ devlist(int argc, char *argv[])
 
 		found++;
 		read_controller_data(fd, &cdata);
-		printf("%6s: %.*s\n", name, NVME_MODEL_NUMBER_LENGTH, cdata.mn);
+		nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH);
+		printf("%6s: %s\n", name, mn);
 
 		for (i = 0; i < cdata.nn; i++) {
 			sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,

Modified: stable/9/sbin/nvmecontrol/identify.c
==============================================================================
--- stable/9/sbin/nvmecontrol/identify.c	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sbin/nvmecontrol/identify.c	Wed Jul 24 22:48:29 2013	(r253631)
@@ -43,16 +43,18 @@ __FBSDID("$FreeBSD$");
 static void
 print_controller(struct nvme_controller_data *cdata)
 {
+	uint8_t str[128];
+
 	printf("Controller Capabilities/Features\n");
 	printf("================================\n");
 	printf("Vendor ID:                  %04x\n", cdata->vid);
 	printf("Subsystem Vendor ID:        %04x\n", cdata->ssvid);
-	printf("Serial Number:              %.*s\n",
-	    NVME_SERIAL_NUMBER_LENGTH, cdata->sn);
-	printf("Model Number:               %.*s\n",
-	    NVME_MODEL_NUMBER_LENGTH, cdata->mn);
-	printf("Firmware Version:           %.*s\n",
-	    NVME_FIRMWARE_REVISION_LENGTH, cdata->fr);
+	nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
+	printf("Serial Number:              %s\n", str);
+	nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
+	printf("Model Number:               %s\n", str);
+	nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
+	printf("Firmware Version:           %s\n", str);
 	printf("Recommended Arb Burst:      %d\n", cdata->rab);
 	printf("IEEE OUI Identifier:        %02x %02x %02x\n",
 		cdata->ieee[0], cdata->ieee[1], cdata->ieee[2]);

Modified: stable/9/sys/conf/files.amd64
==============================================================================
--- stable/9/sys/conf/files.amd64	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/conf/files.amd64	Wed Jul 24 22:48:29 2013	(r253631)
@@ -233,6 +233,7 @@ dev/nvme/nvme_ns_cmd.c		optional	nvme
 dev/nvme/nvme_qpair.c		optional	nvme
 dev/nvme/nvme_sysctl.c		optional	nvme
 dev/nvme/nvme_test.c		optional	nvme
+dev/nvme/nvme_util.c		optional	nvme
 dev/nvram/nvram.c		optional	nvram isa
 dev/random/ivy.c		optional	random rdrand_rng
 dev/random/nehemiah.c		optional	random padlock_rng

Modified: stable/9/sys/conf/files.i386
==============================================================================
--- stable/9/sys/conf/files.i386	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/conf/files.i386	Wed Jul 24 22:48:29 2013	(r253631)
@@ -241,6 +241,7 @@ dev/nvme/nvme_ns_cmd.c		optional nvme
 dev/nvme/nvme_qpair.c		optional nvme
 dev/nvme/nvme_sysctl.c		optional nvme
 dev/nvme/nvme_test.c		optional nvme
+dev/nvme/nvme_util.c		optional nvme
 dev/nvram/nvram.c		optional nvram isa
 dev/pcf/pcf_isa.c		optional pcf
 dev/random/ivy.c		optional random rdrand_rng

Modified: stable/9/sys/dev/nvd/nvd.c
==============================================================================
--- stable/9/sys/dev/nvd/nvd.c	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/dev/nvd/nvd.c	Wed Jul 24 22:48:29 2013	(r253631)
@@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
 
 #include <dev/nvme/nvme.h>
 
+#define NVD_STR		"nvd"
+
 struct nvd_disk;
 
 static disk_ioctl_t nvd_ioctl;
@@ -102,7 +104,7 @@ static int nvd_modevent(module_t mod, in
 }
 
 moduledata_t nvd_mod = {
-	"nvd",
+	NVD_STR,
 	(modeventhand_t)nvd_modevent,
 	0
 };
@@ -271,6 +273,7 @@ nvd_new_controller(struct nvme_controlle
 static void *
 nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
 {
+	uint8_t			descr[NVME_MODEL_NUMBER_LENGTH+1];
 	struct nvd_disk		*ndisk;
 	struct disk		*disk;
 	struct nvd_controller	*ctrlr = ctrlr_arg;
@@ -280,7 +283,7 @@ nvd_new_disk(struct nvme_namespace *ns, 
 	disk = disk_alloc();
 	disk->d_strategy = nvd_strategy;
 	disk->d_ioctl = nvd_ioctl;
-	disk->d_name = "nvd";
+	disk->d_name = NVD_STR;
 	disk->d_drv1 = ndisk;
 
 	disk->d_maxsize = nvme_ns_get_max_io_xfer_size(ns);
@@ -310,12 +313,14 @@ nvd_new_disk(struct nvme_namespace *ns, 
 	 * d_ident and d_descr are both far bigger than the length of either
 	 *  the serial or model number strings.
 	 */
-	strlcpy(disk->d_ident, nvme_ns_get_serial_number(ns),
-	    min(sizeof(disk->d_ident), NVME_SERIAL_NUMBER_LENGTH));
+	nvme_strvis(disk->d_ident, nvme_ns_get_serial_number(ns),
+	    sizeof(disk->d_ident), NVME_SERIAL_NUMBER_LENGTH);
+
+	nvme_strvis(descr, nvme_ns_get_model_number(ns), sizeof(descr),
+	    NVME_MODEL_NUMBER_LENGTH);
 
 #if __FreeBSD_version >= 900034
-	strlcpy(disk->d_descr, nvme_ns_get_model_number(ns),
-	    min(sizeof(disk->d_descr), NVME_MODEL_NUMBER_LENGTH));
+	strlcpy(disk->d_descr, descr, sizeof(descr));
 #endif
 
 	ndisk->ns = ns;
@@ -335,15 +340,27 @@ nvd_new_disk(struct nvme_namespace *ns, 
 
 	disk_create(disk, DISK_VERSION);
 
+	printf(NVD_STR"%u: <%s> NVMe namespace\n", disk->d_unit, descr);
+	printf(NVD_STR"%u: %juMB (%ju %u byte sectors)\n", disk->d_unit,
+		(uintmax_t)disk->d_mediasize / (1024*1024),
+		(uintmax_t)disk->d_mediasize / disk->d_sectorsize,
+		disk->d_sectorsize);
+
 	return (NULL);
 }
 
 static void
 destroy_geom_disk(struct nvd_disk *ndisk)
 {
-	struct bio *bp;
+	struct bio	*bp;
+	struct disk	*disk;
+	uint32_t	unit;
+	int		cnt = 0;
 
+	disk = ndisk->disk;
+	unit = disk->d_unit;
 	taskqueue_free(ndisk->tq);
+
 	disk_destroy(ndisk->disk);
 
 	mtx_lock(&ndisk->bioqlock);
@@ -354,9 +371,13 @@ destroy_geom_disk(struct nvd_disk *ndisk
 		bp->bio_error = EIO;
 		bp->bio_flags |= BIO_ERROR;
 		bp->bio_resid = bp->bio_bcount;
-
+		cnt++;
 		biodone(bp);
 	}
+
+	printf(NVD_STR"%u: lost device - %d outstanding\n", unit, cnt);
+	printf(NVD_STR"%u: removing device entry\n", unit);
+
 	mtx_unlock(&ndisk->bioqlock);
 
 	mtx_destroy(&ndisk->bioqlock);

Modified: stable/9/sys/dev/nvme/nvme.c
==============================================================================
--- stable/9/sys/dev/nvme/nvme.c	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/dev/nvme/nvme.c	Wed Jul 24 22:48:29 2013	(r253631)
@@ -383,4 +383,3 @@ nvme_completion_poll_cb(void *arg, const
 	wmb();
 	status->done = TRUE;
 }
-

Modified: stable/9/sys/dev/nvme/nvme.h
==============================================================================
--- stable/9/sys/dev/nvme/nvme.h	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/dev/nvme/nvme.h	Wed Jul 24 22:48:29 2013	(r253631)
@@ -404,10 +404,10 @@ struct nvme_controller_data {
 	uint16_t		ssvid;
 
 	/** serial number */
-	int8_t			sn[NVME_SERIAL_NUMBER_LENGTH];
+	uint8_t			sn[NVME_SERIAL_NUMBER_LENGTH];
 
 	/** model number */
-	int8_t			mn[NVME_MODEL_NUMBER_LENGTH];
+	uint8_t			mn[NVME_MODEL_NUMBER_LENGTH];
 
 	/** firmware revision */
 	uint8_t			fr[NVME_FIRMWARE_REVISION_LENGTH];
@@ -786,6 +786,8 @@ struct nvme_pt_command {
 #define nvme_completion_is_error(cpl)					\
 	((cpl)->status.sc != 0 || (cpl)->status.sct != 0)
 
+void	nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen);
+
 #ifdef _KERNEL
 
 struct bio;

Copied: stable/9/sys/dev/nvme/nvme_util.c (from r253476, head/sys/dev/nvme/nvme_util.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/sys/dev/nvme/nvme_util.c	Wed Jul 24 22:48:29 2013	(r253631, copy of r253476, head/sys/dev/nvme/nvme_util.c)
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (C) 2013 Intel Corporation
+ * Copyright (C) 1997 Justin T. Gibbs
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <dev/nvme/nvme.h>
+
+void
+nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen)
+{
+	uint8_t *cur_pos;
+
+	/* Trim leading/trailing spaces, nulls. */
+	while (srclen > 0 && src[0] == ' ')
+		src++, srclen--;
+	while (srclen > 0
+	    && (src[srclen - 1] == ' ' || src[srclen - 1] == '\0'))
+		srclen--;
+
+	while (srclen > 0 && dstlen > 1) {
+		cur_pos = dst;
+
+		/* Show '?' for non-printable characters. */
+		if (*src < 0x20 || *src >= 0x7F)
+			*cur_pos++ = '?';
+		else
+			*cur_pos++ = *src;
+		src++;
+		srclen--;
+		dstlen -= cur_pos - dst;
+		dst = cur_pos;
+	}
+	*dst = '\0';
+}
+

Modified: stable/9/sys/modules/nvme/Makefile
==============================================================================
--- stable/9/sys/modules/nvme/Makefile	Wed Jul 24 22:46:27 2013	(r253630)
+++ stable/9/sys/modules/nvme/Makefile	Wed Jul 24 22:48:29 2013	(r253631)
@@ -12,6 +12,7 @@ SRCS =	nvme.c			\
 	nvme_qpair.c		\
 	nvme_sysctl.c		\
 	nvme_test.c		\
+	nvme_util.c		\
 				\
 	bus_if.h		\
 	device_if.h		\


More information about the svn-src-all mailing list