[PATCH 6/6] nvme/fault-injection: Support for error injection with custom crd

Sagi Grimberg <[email protected]>
Newsgroups org.infradead.lists.linux-nvme
Message-ID <[email protected]>
This assumes that the controller exposed crdt[1,2,3] that are actually
meaningful in order to have make difference.

Signed-off-by: Sagi Grimberg <[email protected]>
---
 drivers/nvme/host/fault_inject.c | 8 ++++++--
 drivers/nvme/host/nvme.h         | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fault_inject.c b/drivers/nvme/host/fault_inject.c
index 105d6cb41c72..98363fc6dde7 100644
--- a/drivers/nvme/host/fault_inject.c
+++ b/drivers/nvme/host/fault_inject.c
@@ -42,11 +42,13 @@ void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
 	}
 	fault_inj->parent = parent;
 
-	/* create debugfs for status code and dont_retry */
+	/* create debugfs for status code, dont_retry and crd */
 	fault_inj->status = NVME_SC_INVALID_OPCODE;
 	fault_inj->dont_retry = true;
+	fault_inj->crd = 0;
 	debugfs_create_x16("status", 0600, dir,	&fault_inj->status);
 	debugfs_create_bool("dont_retry", 0600, dir, &fault_inj->dont_retry);
+	debugfs_create_u8("crd", 0600, dir, &fault_inj->crd);
 }
 
 void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject)
@@ -73,10 +75,12 @@ void nvme_should_fail(struct request *req)
 	}
 
 	if (fault_inject && should_fail(&fault_inject->attr, 1)) {
-		/* inject status code and DNR bit */
+		/* inject status code, optional DNR and CRD */
 		status = fault_inject->status;
 		if (fault_inject->dont_retry)
 			status |= NVME_STATUS_DNR;
+		if (fault_inject->crd && fault_inject->crd <= 3)
+			status |= (fault_inject->crd << 11) & NVME_STATUS_CRD;
 		nvme_req(req)->status =	status;
 	}
 }
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index e63f21b3110c..9aa0fc5e473a 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -318,6 +318,7 @@ struct nvme_fault_inject {
 	struct fault_attr attr;
 	struct dentry *parent;
 	bool dont_retry;	/* DNR, do not retry */
+	u8 crd;			/* Command Retry Delay (0-3) */
 	u16 status;		/* status code */
 #endif
 };
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.