Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nvme: enable to inject errors into admin commands

This enables to inject errors into the commands submitted to the admin
queue.

It is useful to test error handling in the controller initialization.

# echo 100 > /sys/kernel/debug/nvme0/fault_inject/probability
# echo 1 > /sys/kernel/debug/nvme0/fault_inject/times
# echo 10 > /sys/kernel/debug/nvme0/fault_inject/space
# nvme reset /dev/nvme0
# dmesg
...
nvme nvme0: Could not set queue count (16385)
nvme nvme0: IO queues not created

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Akinobu Mita and committed by
Christoph Hellwig
f79d5fda a3646451

+7 -3
+3
drivers/nvme/host/core.c
··· 3722 3722 3723 3723 void nvme_uninit_ctrl(struct nvme_ctrl *ctrl) 3724 3724 { 3725 + nvme_fault_inject_fini(&ctrl->fault_inject); 3725 3726 dev_pm_qos_hide_latency_tolerance(ctrl->device); 3726 3727 cdev_device_del(&ctrl->cdev, ctrl->device); 3727 3728 } ··· 3817 3816 ctrl->device->power.set_latency_tolerance = nvme_set_latency_tolerance; 3818 3817 dev_pm_qos_update_user_latency_tolerance(ctrl->device, 3819 3818 min(default_ps_max_latency_us, (unsigned long)S32_MAX)); 3819 + 3820 + nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device)); 3820 3821 3821 3822 return 0; 3822 3823 out_free_name:
+2 -3
drivers/nvme/host/fault_inject.c
··· 60 60 struct nvme_fault_inject *fault_inject = NULL; 61 61 u16 status; 62 62 63 - /* 64 - * make sure this request is coming from a valid namespace 65 - */ 66 63 if (disk) { 67 64 struct nvme_ns *ns = disk->private_data; 68 65 ··· 67 70 fault_inject = &ns->fault_inject; 68 71 else 69 72 WARN_ONCE(1, "No namespace found for request\n"); 73 + } else { 74 + fault_inject = &nvme_req(req)->ctrl->fault_inject; 70 75 } 71 76 72 77 if (fault_inject && should_fail(&fault_inject->attr, 1)) {
+2
drivers/nvme/host/nvme.h
··· 256 256 257 257 struct page *discard_page; 258 258 unsigned long discard_page_busy; 259 + 260 + struct nvme_fault_inject fault_inject; 259 261 }; 260 262 261 263 enum nvme_iopolicy {