Re: 8d2a50bb3805 - main - nvme: Abstract out function to obtain a disk ident string from cdata
Date: Tue, 18 Nov 2025 14:52:39 UTC
Hi John,
LINT-NOVIMAGE fails because of this change. Specifically:
> In file included from sys/cam/ctl/ctl_nvme_all.c:18:
> In file included from sys/cam/nvme/nvme_all.h:31:
> sys/dev/nvme/nvme.h:2009:2: error: call to undeclared function 'memmove'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
> 2009 | memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
> | ^
> In file included from sys/cam/ctl/ctl_nvme_all.c:20:
> In file included from sys/cam/ctl/ctl_io.h:49:
> In file included from sys/cam/scsi/scsi_all.h:20:
> In file included from sys/sys/malloc.h:40:
> sys/sys/systm.h:259:7: error: conflicting types for 'memmove'
> 259 | void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
> | ^
> sys/dev/nvme/nvme.h:2009:2: note: previous implicit declaration is here
> 2009 | memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
> | ^
> 2 errors generated.
>
> *** Error code 1
And
> In file included from sys/cam/ctl/ctl_nvme_cmd_table.c:7:
> sys/dev/nvme/nvme.h:2009:2: error: call to undeclared function 'memmove'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
> 2009 | memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
> | ^
> In file included from sys/cam/ctl/ctl_nvme_cmd_table.c:11:
> In file included from sys/cam/ctl/ctl_io.h:49:
> In file included from sys/cam/scsi/scsi_all.h:20:
> In file included from sys/sys/malloc.h:40:
> sys/sys/systm.h:259:7: error: conflicting types for 'memmove'
> 259 | void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
> | ^
> sys/dev/nvme/nvme.h:2009:2: note: previous implicit declaration is here
> 2009 | memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
> | ^
> 2 errors generated.
>
> *** Error code 1
Thanks,
Ravi (rpokala@)
-----Original Message-----
From: <owner-src-committers@freebsd.org <mailto:owner-src-committers@freebsd.org>> on behalf of John Baldwin <jhb@FreeBSD.org <mailto:jhb@FreeBSD.org>>
Date: Monday, November 17, 2025 at 13:28
To: <src-committers@FreeBSD.org <mailto:src-committers@FreeBSD.org>>, <dev-commits-src-all@FreeBSD.org <mailto:dev-commits-src-all@FreeBSD.org>>, <dev-commits-src-main@FreeBSD.org <mailto:dev-commits-src-main@FreeBSD.org>>
Subject: git: 8d2a50bb3805 - main - nvme: Abstract out function to obtain a disk ident string from cdata
The branch main has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=8d2a50bb38051fefeb1427fdbfd249f2829310d8 <https://cgit.FreeBSD.org/src/commit/?id=8d2a50bb38051fefeb1427fdbfd249f2829310d8>
commit 8d2a50bb38051fefeb1427fdbfd249f2829310d8
Author: John Baldwin <jhb@FreeBSD.org <mailto:jhb@FreeBSD.org>>
AuthorDate: 2025-11-17 18:21:39 +0000
Commit: John Baldwin <jhb@FreeBSD.org <mailto:jhb@FreeBSD.org>>
CommitDate: 2025-11-17 18:21:39 +0000
nvme: Abstract out function to obtain a disk ident string from cdata
This will permit sharing the code with nvmf(4).
Sponsored by: Chelsio Communications
Differential Revision: https://reviews.freebsd.org/D53338 <https://reviews.freebsd.org/D53338>
---
sys/dev/nvme/nvme.h | 19 +++++++++++++++++++
sys/dev/nvme/nvme_ctrlr.c | 21 +--------------------
sys/dev/nvme/nvme_ns.c | 2 +-
sys/dev/nvme/nvme_private.h | 1 -
4 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/sys/dev/nvme/nvme.h b/sys/dev/nvme/nvme.h
index f4ea08f129c0..22421f5600ec 100644
--- a/sys/dev/nvme/nvme.h
+++ b/sys/dev/nvme/nvme.h
@@ -1910,6 +1910,7 @@ void nvme_sc_sbuf(const struct nvme_completion *cpl, struct sbuf *sbuf);
void nvme_strvis(uint8_t *dst, const uint8_t *src, int dstlen, int srclen);
#ifdef _KERNEL
+#include <sys/disk.h>
struct bio;
struct thread;
@@ -1995,6 +1996,24 @@ nvme_ctrlr_has_dataset_mgmt(const struct nvme_controller_data *cd)
return (NVMEV(NVME_CTRLR_DATA_ONCS_DSM, cd->oncs) != 0);
}
+/*
+ * Copy the NVME device's serial number to the provided buffer, which must be
+ * at least DISK_IDENT_SIZE bytes large.
+ */
+static inline void
+nvme_cdata_get_disk_ident(const struct nvme_controller_data *cdata, uint8_t *sn)
+{
+ _Static_assert(NVME_SERIAL_NUMBER_LENGTH < DISK_IDENT_SIZE,
+ "NVME serial number too big for disk ident");
+
+ memmove(sn, cdata->sn, NVME_SERIAL_NUMBER_LENGTH);
+ sn[NVME_SERIAL_NUMBER_LENGTH] = '\0';
+ for (int i = 0; sn[i] != '\0'; i++) {
+ if (sn[i] < 0x20 || sn[i] >= 0x80)
+ sn[i] = ' ';
+ }
+}
+
/* Namespace helper functions */
uint32_t nvme_ns_get_max_io_xfer_size(struct nvme_namespace *ns);
uint32_t nvme_ns_get_sector_size(struct nvme_namespace *ns);
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index e607667decf5..ab06c1d553d7 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -33,7 +33,6 @@
#include <sys/buf.h>
#include <sys/bus.h>
#include <sys/conf.h>
-#include <sys/disk.h>
#include <sys/ioccom.h>
#include <sys/proc.h>
#include <sys/smp.h>
@@ -1254,24 +1253,6 @@ nvme_ctrlr_poll(struct nvme_controller *ctrlr)
nvme_qpair_process_completions(&ctrlr->ioq[i]);
}
-/*
- * Copy the NVME device's serial number to the provided buffer, which must be
- * at least DISK_IDENT_SIZE bytes large.
- */
-void
-nvme_ctrlr_get_ident(const struct nvme_controller *ctrlr, uint8_t *sn)
-{
- _Static_assert(NVME_SERIAL_NUMBER_LENGTH < DISK_IDENT_SIZE,
- "NVME serial number too big for disk ident");
-
- memmove(sn, ctrlr->cdata.sn, NVME_SERIAL_NUMBER_LENGTH);
- sn[NVME_SERIAL_NUMBER_LENGTH] = '\0';
- for (int i = 0; sn[i] != '\0'; i++) {
- if (sn[i] < 0x20 || sn[i] >= 0x80)
- sn[i] = ' ';
- }
-}
-
/*
* Poll the single-vector interrupt case: num_io_queues will be 1 and
* there's only a single vector. While we're polling, we mask further
@@ -1516,7 +1497,7 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
break;
case DIOCGIDENT: {
uint8_t *sn = arg;
- nvme_ctrlr_get_ident(ctrlr, sn);
+ nvme_cdata_get_disk_ident(&ctrlr->cdata, sn);
break;
}
/* Linux Compatible (see nvme_linux.h) */
diff --git a/sys/dev/nvme/nvme_ns.c b/sys/dev/nvme/nvme_ns.c
index 17684cc14ba2..f238fa552350 100644
--- a/sys/dev/nvme/nvme_ns.c
+++ b/sys/dev/nvme/nvme_ns.c
@@ -90,7 +90,7 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t arg, int flag,
}
case DIOCGIDENT: {
uint8_t *sn = arg;
- nvme_ctrlr_get_ident(ctrlr, sn);
+ nvme_cdata_get_disk_ident(&ctrlr->cdata, sn);
break;
}
case DIOCGMEDIASIZE:
diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
index dd45e1acd0aa..a425a6a5ad62 100644
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -565,7 +565,6 @@ void nvme_notify_new_controller(struct nvme_controller *ctrlr);
void nvme_notify_ns(struct nvme_controller *ctrlr, int nsid);
void nvme_ctrlr_shared_handler(void *arg);
-void nvme_ctrlr_get_ident(const struct nvme_controller *ctrlr, uint8_t *sn);
void nvme_ctrlr_poll(struct nvme_controller *ctrlr);
int nvme_ctrlr_suspend(struct nvme_controller *ctrlr);