diff options
author | Kenneth D. Merry <ken@FreeBSD.org> | 2022-01-24 21:19:25 +0000 |
---|---|---|
committer | Kenneth D. Merry <ken@FreeBSD.org> | 2022-02-09 22:09:25 +0000 |
commit | 3090d5045a1e5663f151ef3f50f3c7db8f9a9e3c (patch) | |
tree | 1a44653371b30fadac8633edddd9abbbfeaec890 /sys/cam/nvme/nvme_da.c | |
parent | af7d105379a649b7af4bffd15fbeab692bb52b69 (diff) | |
download | src-3090d5045a1e5663f151ef3f50f3c7db8f9a9e3c.tar.gz src-3090d5045a1e5663f151ef3f50f3c7db8f9a9e3c.zip |
Fix non-printable characters in NVMe model and serial numbers.
The NVMe 1.4 spec simply says that Model and Serial numbers are
ASCII strings. Unlike SCSI, it doesn't prohibit non-printable
characters or say that the strings should be padded with spaces.
Since 2014, we have had cam_strvis_sbuf(), which gives additional
options for handling non-ASCII characters. That behavior hasn't
been available for non-sbuf consumers, so users of cam_strvis()
were left with having octal ASCII codes inserted.
So, to avoid having garbage or octal chracters in the strings, use
cam_strvis_sbuf() to create a new function, cam_strvis_flag(), and
re-implement cam_strvis() using cam_strvis_flag().
Now, for the NVMe drives, we can use cam_strvis_flag with the
CAM_STRVIS_FLAG_NONASCII_SPC flag. This transforms non-printable
characters into spaces.
sys/cam/cam.c:
Add a new function, cam_strvis_flag(), that creates an sbuf
on the stack with the user's destination buffer, and calls
cam_strvis_sbuf() with the given flag argument.
Re-implement cam_strvis() to call cam_strvis_flag with the
CAM_STRVIS_FLAG_NONASCII_ESC argument. This should be the
equivalent of the old cam_strvis() function, except for the
overhead of creating the sbuf and calling sbuf_putc/printf.
sys/cam/cam.h:
Declaration for cam_strvis_flag.
sys/cam/nvme/nvme_all.c:
In nvme_print_ident, use the NONASCII_SPC flag with
cam_strvis_flag().
sys/cam/nvme/nvme_da.c:
In ndaregister(), use cam_strvis_flag() with the
NONASCII_SPC flag for the disk description and serial
number we report to GEOM.
sys/cam/nvme/nvme_xpt.c:
In nvme_probe_done(), use cam_strvis_flag with the
NONASCII_SPC flag when storing the drive serial number
in the CAM EDT.
MFC after: 1 week
Sponsored by: Spectra Logic
Differential Revision: https://reviews.freebsd.org/D33973
Diffstat (limited to 'sys/cam/nvme/nvme_da.c')
-rw-r--r-- | sys/cam/nvme/nvme_da.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c index 7a489afdb993..a3d72e1017c9 100644 --- a/sys/cam/nvme/nvme_da.c +++ b/sys/cam/nvme/nvme_da.c @@ -930,10 +930,12 @@ ndaregister(struct cam_periph *periph, void *arg) * d_ident and d_descr are both far bigger than the length of either * the serial or model number strings. */ - cam_strvis(disk->d_descr, cd->mn, - NVME_MODEL_NUMBER_LENGTH, sizeof(disk->d_descr)); - cam_strvis(disk->d_ident, cd->sn, - NVME_SERIAL_NUMBER_LENGTH, sizeof(disk->d_ident)); + cam_strvis_flag(disk->d_descr, cd->mn, NVME_MODEL_NUMBER_LENGTH, + sizeof(disk->d_descr), CAM_STRVIS_FLAG_NONASCII_SPC); + + cam_strvis_flag(disk->d_ident, cd->sn, NVME_SERIAL_NUMBER_LENGTH, + sizeof(disk->d_ident), CAM_STRVIS_FLAG_NONASCII_SPC); + disk->d_hba_vendor = cpi.hba_vendor; disk->d_hba_device = cpi.hba_device; disk->d_hba_subvendor = cpi.hba_subvendor; |