public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <kch@nvidia.com>
To: <linux-nvme@lists.infradead.org>
Cc: <kbusch@kernel.org>, <hch@lst.de>, <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>
Subject: [RFC PATCH 1/2] nvme: derive zone-mgmt-act from struct request
Date: Wed, 9 Mar 2022 09:04:36 -0800	[thread overview]
Message-ID: <20220309170437.4448-2-kch@nvidia.com> (raw)
In-Reply-To: <20220309170437.4448-1-kch@nvidia.com>

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@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



  reply	other threads:[~2022-03-09 17:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 17:04 [RFC PATCH 0/2] nvme: nvme_setup_cmd() cleanup Chaitanya Kulkarni
2022-03-09 17:04 ` Chaitanya Kulkarni [this message]
2022-03-09 17:04 ` [RFC PATCH 2/2] nvme: derive nvme cmd opcode from struct request Chaitanya Kulkarni
2022-03-14  7:22 ` [RFC PATCH 0/2] nvme: nvme_setup_cmd() cleanup Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220309170437.4448-2-kch@nvidia.com \
    --to=kch@nvidia.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox