[RFC PATCH 1/2] nvme: derive zone-mgmt-act from struct request

Chaitanya Kulkarni kch at nvidia.com
Wed Mar 9 09:04:36 PST 2022


Instead of having 4 calls of nvme_setup_zone_mgmt_send() with
zone-mgmt-act as a separate parameter, have one call from nvme
setup_cmd() and derive zome-mgmt-act from struct request that we are
already passing to nvme_setup_zone_mgmt_send().

This reduces duplicate calls and break statements with removal of extra
function parameter.

Signed-off-by: Chaitanya Kulkarni <kch at nvidia.com>
---
 drivers/nvme/host/core.c |  8 +-------
 drivers/nvme/host/nvme.h |  6 ++----
 drivers/nvme/host/zns.c  | 13 +++++++++++--
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f8084ded69e5..b5d36e09e763 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1042,16 +1042,10 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
 		break;
 	case REQ_OP_ZONE_RESET_ALL:
 	case REQ_OP_ZONE_RESET:
-		ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_RESET);
-		break;
 	case REQ_OP_ZONE_OPEN:
-		ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_OPEN);
-		break;
 	case REQ_OP_ZONE_CLOSE:
-		ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_CLOSE);
-		break;
 	case REQ_OP_ZONE_FINISH:
-		ret = nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_FINISH);
+		ret = nvme_setup_zone_mgmt_send(ns, req, cmd);
 		break;
 	case REQ_OP_WRITE_ZEROES:
 		ret = nvme_setup_write_zeroes(ns, req, cmd);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 587d92df118b..a85dc4e29870 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -878,12 +878,10 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
 #ifdef CONFIG_BLK_DEV_ZONED
 int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf);
 blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
-				       struct nvme_command *cmnd,
-				       enum nvme_zone_mgmt_action action);
+				       struct nvme_command *cmnd);
 #else
 static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns,
-		struct request *req, struct nvme_command *cmnd,
-		enum nvme_zone_mgmt_action action)
+		struct request *req, struct nvme_command *cmnd)
 {
 	return BLK_STS_NOTSUPP;
 }
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 9f81beb4df4e..7bbbd24ba6b6 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -234,14 +234,23 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
 }
 
 blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request *req,
-		struct nvme_command *c, enum nvme_zone_mgmt_action action)
+		struct nvme_command *c)
 {
+	static enum nvme_zone_mgmt_action req_op_to_nvme_zmgmt_act[] = {
+		[REQ_OP_ZONE_OPEN] = NVME_ZONE_OPEN,
+		[REQ_OP_ZONE_CLOSE] = NVME_ZONE_CLOSE,
+		[REQ_OP_ZONE_FINISH] = NVME_ZONE_FINISH,
+		[REQ_OP_ZONE_RESET] = NVME_ZONE_RESET,
+		[REQ_OP_ZONE_RESET_ALL] = NVME_ZONE_RESET
+	};
+
 	memset(c, 0, sizeof(*c));
 
 	c->zms.opcode = nvme_cmd_zone_mgmt_send;
 	c->zms.nsid = cpu_to_le32(ns->head->ns_id);
 	c->zms.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
-	c->zms.zsa = action;
+	/* caller already validates REQ_OP_ZONE_XXX */
+	c->zms.zsa = req_op_to_nvme_zmgmt_act[req_op(req)];
 
 	if (req_op(req) == REQ_OP_ZONE_RESET_ALL)
 		c->zms.select_all = 1;
-- 
2.29.0




More information about the Linux-nvme mailing list