summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjimharris <jimharris@FreeBSD.org>2013-07-19 21:40:57 +0000
committerjimharris <jimharris@FreeBSD.org>2013-07-19 21:40:57 +0000
commit52bfa150c78aa1855a2cc5fccfc5beb84f57b16d (patch)
treeaf2bfcd29c3c4b521e2556f71dfd744f3a8c6df2 /sys
parent0ccd4d5781fdb67fda3917d5ffccf80806d0d9fb (diff)
downloadFreeBSD-src-52bfa150c78aa1855a2cc5fccfc5beb84f57b16d.zip
FreeBSD-src-52bfa150c78aa1855a2cc5fccfc5beb84f57b16d.tar.gz
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. Sponsored by: Intel Reviewed by: carl MFC after: 3 days
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files.amd641
-rw-r--r--sys/conf/files.i3861
-rw-r--r--sys/dev/nvd/nvd.c37
-rw-r--r--sys/dev/nvme/nvme.c1
-rw-r--r--sys/dev/nvme/nvme.h6
-rw-r--r--sys/dev/nvme/nvme_util.c61
-rw-r--r--sys/modules/nvme/Makefile1
7 files changed, 97 insertions, 11 deletions
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index 191f680..c898ef8 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -234,6 +234,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
diff --git a/sys/conf/files.i386 b/sys/conf/files.i386
index f4d7928..9a27bde 100644
--- a/sys/conf/files.i386
+++ b/sys/conf/files.i386
@@ -243,6 +243,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
diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c
index 1bde1ca..b2e880b 100644
--- a/sys/dev/nvd/nvd.c
+++ b/sys/dev/nvd/nvd.c
@@ -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, int type, void *arg)
}
moduledata_t nvd_mod = {
- "nvd",
+ NVD_STR,
(modeventhand_t)nvd_modevent,
0
};
@@ -271,6 +273,7 @@ nvd_new_controller(struct nvme_controller *ctrlr)
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, void *ctrlr_arg)
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, void *ctrlr_arg)
* 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, void *ctrlr_arg)
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);
diff --git a/sys/dev/nvme/nvme.c b/sys/dev/nvme/nvme.c
index 65bb05e..eacd0cc 100644
--- a/sys/dev/nvme/nvme.c
+++ b/sys/dev/nvme/nvme.c
@@ -383,4 +383,3 @@ nvme_completion_poll_cb(void *arg, const struct nvme_completion *cpl)
wmb();
status->done = TRUE;
}
-
diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index f30505a..9df75da 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -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;
diff --git a/sys/dev/nvme/nvme_util.c b/sys/dev/nvme/nvme_util.c
new file mode 100644
index 0000000..6d70841
--- /dev/null
+++ b/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';
+}
+
diff --git a/sys/modules/nvme/Makefile b/sys/modules/nvme/Makefile
index 17004bc..ae727a7 100644
--- a/sys/modules/nvme/Makefile
+++ b/sys/modules/nvme/Makefile
@@ -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 \
OpenPOWER on IntegriCloud