[PATCH 5/7] nvmet: Added debugfs fatal opcode

Randy Jennings randyj at purestorage.com
Thu Apr 30 16:29:11 PDT 2026


From: Mohamed Khalfella <mkhalfella at purestorage.com>

---
 drivers/nvme/target/Kconfig   | 10 +++++++++
 drivers/nvme/target/debugfs.c | 38 +++++++++++++++++++++++++++++++++++
 drivers/nvme/target/nvmet.h   |  4 ++++
 3 files changed, 52 insertions(+)

diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig
index cfcc652c6f9f..8386ffedf645 100644
--- a/drivers/nvme/target/Kconfig
+++ b/drivers/nvme/target/Kconfig
@@ -136,3 +136,13 @@ config NVME_TARGET_DELAY_REQUESTS
 	 NVMe over Fabrics target, which allows for support of the cancel command.
 
 	 If unsure, say N.
+
+config NVME_TARGET_FATAL_OPCODE
+	bool "NVMe over Fabrics target fatal opcode"
+	depends on NVME_TARGET && NVME_TARGET_DEBUGFS
+	help
+	 This is a testing feature to allow specifying an nvme opcode as fatal
+	 opcode. When nvme controller receives fatal opcode it will execute
+	 the request with specified delay and drop the connections to initiator.
+
+	 If unsure, say N.
diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c
index ae45aca728ea..28ab22ab3da8 100644
--- a/drivers/nvme/target/debugfs.c
+++ b/drivers/nvme/target/debugfs.c
@@ -206,6 +206,39 @@ static ssize_t nvmet_ctrl_delay_write(struct file *file, const char __user *buf,
 NVMET_DEBUGFS_RW_ATTR(nvmet_ctrl_delay);
 #endif /* CONFIG_NVME_TARGET_DELAY_REQUESTS */
 
+#if IS_ENABLED(CONFIG_NVME_TARGET_FATAL_OPCODE)
+static int nvmet_ctrl_fatal_opcode_show(struct seq_file *m, void *p)
+{
+	struct nvmet_ctrl *ctrl = m->private;
+
+	seq_printf(m, "%02x %u\n", ctrl->fopcode, ctrl->fopcode_delay_ms);
+	return 0;
+}
+
+static ssize_t nvmet_ctrl_fatal_opcode_write(struct file *file, const char __user *buf,
+				      size_t count, loff_t *ppos)
+{
+	struct seq_file *m = file->private_data;
+	struct nvmet_ctrl *ctrl = m->private;
+	char fopcode_buf[22] = {};
+	int fopcode_delay_ms, n;
+	uint8_t fopcode;
+
+	if (count >= sizeof(fopcode_buf))
+		return -EINVAL;
+	if (copy_from_user(fopcode_buf, buf, count))
+		return -EFAULT;
+
+	n = sscanf(fopcode_buf, "%hhx %u", &fopcode, &fopcode_delay_ms);
+	if (n != 2)
+		return -EINVAL;
+	ctrl->fopcode = fopcode;
+	ctrl->fopcode_delay_ms = fopcode_delay_ms;
+	return count;
+}
+NVMET_DEBUGFS_RW_ATTR(nvmet_ctrl_fatal_opcode);
+#endif /* CONFIG_NVME_TARGET_FATAL_OPCODE */
+
 int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
 {
 	char name[32];
@@ -245,6 +278,11 @@ int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
 	debugfs_create_file("delay", S_IWUSR, ctrl->debugfs_dir, ctrl,
 			    &nvmet_ctrl_delay_fops);
 #endif
+
+#if IS_ENABLED(CONFIG_NVME_TARGET_FATAL_OPCODE)
+	debugfs_create_file("fopcode", S_IWUSR, ctrl->debugfs_dir, ctrl,
+			    &nvmet_ctrl_fatal_opcode_fops);
+#endif
 	return 0;
 }
 
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 845072cf4fae..183f71bf27a4 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -317,6 +317,10 @@ struct nvmet_ctrl {
 #ifdef CONFIG_NVME_TARGET_DELAY_REQUESTS
 	atomic_t		delay_count;
 	u32			delay_msec;
+#endif
+#ifdef CONFIG_NVME_TARGET_FATAL_OPCODE
+	uint8_t			fopcode;
+	u32			fopcode_delay_ms;
 #endif
 	struct nvmet_pr_log_mgr pr_log_mgr;
 };
-- 
2.54.0




More information about the Linux-nvme mailing list