git: d282baddb0b0 - main - Add interface NVME to devstat

From: Alexander Motin <mav_at_FreeBSD.org>
Date: Thu, 16 Nov 2023 04:14:07 UTC
The branch main has been updated by mav:

URL: https://cgit.FreeBSD.org/src/commit/?id=d282baddb0b029ca8466d23ac51e95c918442535

commit d282baddb0b029ca8466d23ac51e95c918442535
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2023-11-16 04:03:40 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2023-11-16 04:03:40 +0000

    Add interface NVME to devstat
    
    This allows to list only NVMe devices in systat, iostat, vmstat, etc.
    Previously those were counted as OTHER.
---
 cddl/lib/libdtrace/io.d  | 3 +++
 lib/libdevstat/devstat.3 | 2 ++
 lib/libdevstat/devstat.c | 1 +
 share/man/man9/devstat.9 | 1 +
 sys/cam/cam_ccb.h        | 1 +
 sys/dev/nvd/nvd.c        | 5 +++++
 sys/sys/devicestat.h     | 1 +
 usr.bin/vmstat/vmstat.8  | 2 ++
 usr.sbin/iostat/iostat.8 | 2 ++
 9 files changed, 18 insertions(+)

diff --git a/cddl/lib/libdtrace/io.d b/cddl/lib/libdtrace/io.d
index fbce09e2fcf7..043291244a50 100644
--- a/cddl/lib/libdtrace/io.d
+++ b/cddl/lib/libdtrace/io.d
@@ -194,6 +194,8 @@ inline int DEVSTAT_TYPE_IF_IDE =	0x020;
 #pragma D binding "1.13" DEVSTAT_TYPE_IF_IDE
 inline int DEVSTAT_TYPE_IF_OTHER =	0x030;
 #pragma D binding "1.13" DEVSTAT_TYPE_IF_OTHER
+inline int DEVSTAT_TYPE_IF_NVM =	0x040;
+#pragma D binding "1.13" DEVSTAT_TYPE_IF_NVME
 inline int DEVSTAT_TYPE_IF_MASK =	0x0f0;
 #pragma D binding "1.13" DEVSTAT_TYPE_IF_MASK
 inline int DEVSTAT_TYPE_PASS =		0x100;
@@ -228,6 +230,7 @@ inline string device_if_string[int type] =
 	type == DEVSTAT_TYPE_IF_SCSI ?	"SCSI" :
 	type == DEVSTAT_TYPE_IF_IDE ?	"IDE" :
 	type == DEVSTAT_TYPE_IF_OTHER ?	"OTHER" :
+	type == DEVSTAT_TYPE_IF_NVME ?	"NVME" :
 	strjoin("UNKNOWN(", strjoin(lltostr(type), ")"));
 
 #pragma D binding "1.13" device_if
diff --git a/lib/libdevstat/devstat.3 b/lib/libdevstat/devstat.3
index 20f5fdd5649c..d0eaff359e15 100644
--- a/lib/libdevstat/devstat.3
+++ b/lib/libdevstat/devstat.3
@@ -428,6 +428,8 @@ Floppy devices
 Integrated Drive Electronics devices
 .It Li SCSI
 Small Computer System Interface devices
+.It Li NVME
+NVM Express Interface devices
 .It Li other
 Any other device interface
 .El
diff --git a/lib/libdevstat/devstat.c b/lib/libdevstat/devstat.c
index 7465613da4f1..7aca8c5733d0 100644
--- a/lib/libdevstat/devstat.c
+++ b/lib/libdevstat/devstat.c
@@ -75,6 +75,7 @@ struct devstat_match_table match_table[] = {
 	{"scsi",	DEVSTAT_TYPE_IF_SCSI,	DEVSTAT_MATCH_IF},
 	{"ide",		DEVSTAT_TYPE_IF_IDE,	DEVSTAT_MATCH_IF},
 	{"other",	DEVSTAT_TYPE_IF_OTHER,	DEVSTAT_MATCH_IF},
+	{"nvme",	DEVSTAT_TYPE_IF_NVME,	DEVSTAT_MATCH_IF},
 	{"worm",	DEVSTAT_TYPE_WORM,	DEVSTAT_MATCH_TYPE},
 	{"sa",		DEVSTAT_TYPE_SEQUENTIAL,DEVSTAT_MATCH_TYPE},
 	{"pass",	DEVSTAT_TYPE_PASS,	DEVSTAT_MATCH_PASS},
diff --git a/share/man/man9/devstat.9 b/share/man/man9/devstat.9
index e474e3119418..3682ad024eae 100644
--- a/share/man/man9/devstat.9
+++ b/share/man/man9/devstat.9
@@ -414,6 +414,7 @@ typedef enum {
 	DEVSTAT_TYPE_IF_SCSI	= 0x010,
 	DEVSTAT_TYPE_IF_IDE	= 0x020,
 	DEVSTAT_TYPE_IF_OTHER	= 0x030,
+	DEVSTAT_TYPE_IF_NVME	= 0x040,
 	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
 	DEVSTAT_TYPE_PASS	= 0x100
 } devstat_type_flags;
diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h
index 9d52213e3952..66b374008aa5 100644
--- a/sys/cam/cam_ccb.h
+++ b/sys/cam/cam_ccb.h
@@ -306,6 +306,7 @@ typedef enum {
 				 !XPORT_IS_ATA(t) && !XPORT_IS_NVME(t))
 #define XPORT_DEVSTAT_TYPE(t)	(XPORT_IS_ATA(t) ? DEVSTAT_TYPE_IF_IDE : \
 				 XPORT_IS_SCSI(t) ? DEVSTAT_TYPE_IF_SCSI : \
+				 XPORT_IS_NVME(t) ? DEVSTAT_TYPE_IF_NVME : \
 				 DEVSTAT_TYPE_IF_OTHER)
 
 #define PROTO_VERSION_UNKNOWN (UINT_MAX - 1)
diff --git a/sys/dev/nvd/nvd.c b/sys/dev/nvd/nvd.c
index 6b83757aa938..26bc4ee36d50 100644
--- a/sys/dev/nvd/nvd.c
+++ b/sys/dev/nvd/nvd.c
@@ -30,6 +30,7 @@
 #include <sys/cdefs.h>
 #include <sys/param.h>
 #include <sys/bio.h>
+#include <sys/devicestat.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
@@ -471,6 +472,10 @@ nvd_new_disk(struct nvme_namespace *ns, void *ctrlr_arg)
 		disk->d_flags |= DISKFLAG_CANDELETE;
 	if (nvme_ns_get_flags(ns) & NVME_NS_FLUSH_SUPPORTED)
 		disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
+	disk->d_devstat = devstat_new_entry(disk->d_name, disk->d_unit,
+	    disk->d_sectorsize, DEVSTAT_ALL_SUPPORTED,
+	    DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_NVME,
+	    DEVSTAT_PRIORITY_DISK);
 
 	/*
 	 * d_ident and d_descr are both far bigger than the length of either
diff --git a/sys/sys/devicestat.h b/sys/sys/devicestat.h
index 1b8db6f100c9..2583697f7515 100644
--- a/sys/sys/devicestat.h
+++ b/sys/sys/devicestat.h
@@ -125,6 +125,7 @@ typedef enum {
 	DEVSTAT_TYPE_IF_SCSI	= 0x010,
 	DEVSTAT_TYPE_IF_IDE	= 0x020,
 	DEVSTAT_TYPE_IF_OTHER	= 0x030,
+	DEVSTAT_TYPE_IF_NVME	= 0x040,
 	DEVSTAT_TYPE_IF_MASK	= 0x0f0,
 	DEVSTAT_TYPE_PASS	= 0x100
 } devstat_type_flags;
diff --git a/usr.bin/vmstat/vmstat.8 b/usr.bin/vmstat/vmstat.8
index d1f0d4d60bcc..eead7a7ef9c3 100644
--- a/usr.bin/vmstat/vmstat.8
+++ b/usr.bin/vmstat/vmstat.8
@@ -173,6 +173,8 @@ Floppy devices
 Integrated Drive Electronics devices
 .It SCSI
 Small Computer System Interface devices
+.It NVME
+NVM Express Interface devices
 .It other
 Any other device interface
 .El
diff --git a/usr.sbin/iostat/iostat.8 b/usr.sbin/iostat/iostat.8
index 863f8ab8466c..a08a62dc694d 100644
--- a/usr.sbin/iostat/iostat.8
+++ b/usr.sbin/iostat/iostat.8
@@ -206,6 +206,8 @@ Floppy devices
 Integrated Drive Electronics devices
 .It SCSI
 Small Computer System Interface devices
+.It NVME
+NVM Express Interface devices
 .It other
 Any other device interface
 .El