From 52bfa150c78aa1855a2cc5fccfc5beb84f57b16d Mon Sep 17 00:00:00 2001 From: jimharris Date: Fri, 19 Jul 2013 21:40:57 +0000 Subject: 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 --- sys/dev/nvd/nvd.c | 37 ++++++++++++++++++++++------- sys/dev/nvme/nvme.c | 1 - sys/dev/nvme/nvme.h | 6 +++-- sys/dev/nvme/nvme_util.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 sys/dev/nvme/nvme_util.c (limited to 'sys/dev') 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 +#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 +__FBSDID("$FreeBSD$"); + +#include +#include + +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'; +} + -- cgit v1.1