All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] nvmet: small cleanup
@ 2021-06-14  1:58 Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 1/6] nvmet: use req->cmd directly in bdev-ns fast path Chaitanya Kulkarni
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

Hi,

This has cleanup for removing local variables which are only used once
or not used to do anything meaningful along with type mismatch for
subsys->max_nsid.

-ck

Chaitanya Kulkarni (6):
  nvmet: use req->cmd directly in bdev-ns fast path
  nvmet: use req->cmd directly in file-ns fast path
  nvmet: use u32 for nvmet_subsys max_nsid
  nvmet: use u32 type for the local variable nsid
  nvmet: use nvme status value directly
  nvmet: remove local variable

 drivers/nvme/target/core.c        | 30 ++++++++++--------------------
 drivers/nvme/target/io-cmd-bdev.c |  4 +---
 drivers/nvme/target/io-cmd-file.c |  4 +---
 drivers/nvme/target/nvmet.h       |  2 +-
 4 files changed, 13 insertions(+), 27 deletions(-)

-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] nvmet: use req->cmd directly in bdev-ns fast path
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 2/6] nvmet: use req->cmd directly in file-ns " Chaitanya Kulkarni
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

The function nvmet_bdev_parse_io_cmd() is called from the fast path.
The local variable to that function cmd is only used once.

Remove the local variable and use req->cmd directly.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/io-cmd-bdev.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index f673679d258a..5d998e5873d3 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -429,9 +429,7 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req)
 
 u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)
 {
-	struct nvme_command *cmd = req->cmd;
-
-	switch (cmd->common.opcode) {
+	switch (req->cmd->common.opcode) {
 	case nvme_cmd_read:
 	case nvme_cmd_write:
 		req->execute = nvmet_bdev_execute_rw;
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] nvmet: use req->cmd directly in file-ns fast path
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 1/6] nvmet: use req->cmd directly in bdev-ns fast path Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 3/6] nvmet: use u32 for nvmet_subsys max_nsid Chaitanya Kulkarni
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

The function nvmet_file_parse_io_cmd() is called from the fast path. The
local variable to that function cmd is only used once.

Remove the local variable and use req->cmd directly.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/io-cmd-file.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 7fdbdc496597..1dd1a0fe2e81 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -385,9 +385,7 @@ static void nvmet_file_execute_write_zeroes(struct nvmet_req *req)
 
 u16 nvmet_file_parse_io_cmd(struct nvmet_req *req)
 {
-	struct nvme_command *cmd = req->cmd;
-
-	switch (cmd->common.opcode) {
+	switch (req->cmd->common.opcode) {
 	case nvme_cmd_read:
 	case nvme_cmd_write:
 		req->execute = nvmet_file_execute_rw;
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] nvmet: use u32 for nvmet_subsys max_nsid
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 1/6] nvmet: use req->cmd directly in bdev-ns fast path Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 2/6] nvmet: use req->cmd directly in file-ns " Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 4/6] nvmet: use u32 type for the local variable nsid Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

Use u32 type for the nsid_max member of the nvmet_subsys structure.
This avoids the type confusion when updating the subsys->nax_nsid from
ns->nsid. This also matches the nvmet_ns->nsid member.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/nvmet.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index bd0a0b91d843..3468f25cb4b7 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -218,7 +218,7 @@ struct nvmet_subsys {
 
 	struct xarray		namespaces;
 	unsigned int		nr_namespaces;
-	unsigned int		max_nsid;
+	u32			max_nsid;
 	u16			cntlid_min;
 	u16			cntlid_max;
 
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] nvmet: use u32 type for the local variable nsid
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2021-06-14  1:58 ` [PATCH 3/6] nvmet: use u32 for nvmet_subsys max_nsid Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 5/6] nvmet: use nvme status value directly Chaitanya Kulkarni
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

In function nvmet_max_nsid() we calculate the max nsid by iterating
over the XArray and store it in the variable nsid that has type of
unsigned long.

Since the value of this function is stored into the subsys->max_nsid
which is of type u32, change the local variable nsid type and the return
type of the same function to u32.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 146909486b8f..8494a132da35 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -122,11 +122,11 @@ u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len)
 	return 0;
 }
 
-static unsigned int nvmet_max_nsid(struct nvmet_subsys *subsys)
+static u32 nvmet_max_nsid(struct nvmet_subsys *subsys)
 {
-	unsigned long nsid = 0;
 	struct nvmet_ns *cur;
 	unsigned long idx;
+	u32 nsid = 0;
 
 	xa_for_each(&subsys->namespaces, idx, cur)
 		nsid = cur->nsid;
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] nvmet: use nvme status value directly
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2021-06-14  1:58 ` [PATCH 4/6] nvmet: use u32 type for the local variable nsid Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-14  1:58 ` [PATCH 6/6] nvmet: remove local variable Chaitanya Kulkarni
  2021-06-15 16:18 ` [PATCH 0/6] nvmet: small cleanup Christoph Hellwig
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

There is no point in keeping the status variable that is used only once
in the function nvmet_async_events_failall().

Remove the variable and use the value directly.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 8494a132da35..45a5b273b525 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -141,14 +141,13 @@ static u32 nvmet_async_event_result(struct nvmet_async_event *aen)
 
 static void nvmet_async_events_failall(struct nvmet_ctrl *ctrl)
 {
-	u16 status = NVME_SC_INTERNAL | NVME_SC_DNR;
 	struct nvmet_req *req;
 
 	mutex_lock(&ctrl->lock);
 	while (ctrl->nr_async_event_cmds) {
 		req = ctrl->async_event_cmds[--ctrl->nr_async_event_cmds];
 		mutex_unlock(&ctrl->lock);
-		nvmet_req_complete(req, status);
+		nvmet_req_complete(req, NVME_SC_INTERNAL | NVME_SC_DNR);
 		mutex_lock(&ctrl->lock);
 	}
 	mutex_unlock(&ctrl->lock);
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] nvmet: remove local variable
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
                   ` (4 preceding siblings ...)
  2021-06-14  1:58 ` [PATCH 5/6] nvmet: use nvme status value directly Chaitanya Kulkarni
@ 2021-06-14  1:58 ` Chaitanya Kulkarni
  2021-06-15 16:18 ` [PATCH 0/6] nvmet: small cleanup Christoph Hellwig
  6 siblings, 0 replies; 8+ messages in thread
From: Chaitanya Kulkarni @ 2021-06-14  1:58 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, sagi, Chaitanya Kulkarni

In function errno_to_nvme_status() we store the value of the NVMe
status into the local variable and don't do anything useful with that
but just return.

Remove the local variable and return the value directly from switch.
This also removed extra break statements.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/core.c | 23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 45a5b273b525..c8708dcaeaa5 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -43,43 +43,34 @@ DECLARE_RWSEM(nvmet_ana_sem);
 
 inline u16 errno_to_nvme_status(struct nvmet_req *req, int errno)
 {
-	u16 status;
-
 	switch (errno) {
 	case 0:
-		status = NVME_SC_SUCCESS;
-		break;
+		return NVME_SC_SUCCESS;
 	case -ENOSPC:
 		req->error_loc = offsetof(struct nvme_rw_command, length);
-		status = NVME_SC_CAP_EXCEEDED | NVME_SC_DNR;
-		break;
+		return NVME_SC_CAP_EXCEEDED | NVME_SC_DNR;
 	case -EREMOTEIO:
 		req->error_loc = offsetof(struct nvme_rw_command, slba);
-		status = NVME_SC_LBA_RANGE | NVME_SC_DNR;
-		break;
+		return  NVME_SC_LBA_RANGE | NVME_SC_DNR;
 	case -EOPNOTSUPP:
 		req->error_loc = offsetof(struct nvme_common_command, opcode);
 		switch (req->cmd->common.opcode) {
 		case nvme_cmd_dsm:
 		case nvme_cmd_write_zeroes:
-			status = NVME_SC_ONCS_NOT_SUPPORTED | NVME_SC_DNR;
-			break;
+			return NVME_SC_ONCS_NOT_SUPPORTED | NVME_SC_DNR;
 		default:
-			status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
+			return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
 		}
 		break;
 	case -ENODATA:
 		req->error_loc = offsetof(struct nvme_rw_command, nsid);
-		status = NVME_SC_ACCESS_DENIED;
-		break;
+		return NVME_SC_ACCESS_DENIED;
 	case -EIO:
 		fallthrough;
 	default:
 		req->error_loc = offsetof(struct nvme_common_command, opcode);
-		status = NVME_SC_INTERNAL | NVME_SC_DNR;
+		return NVME_SC_INTERNAL | NVME_SC_DNR;
 	}
-
-	return status;
 }
 
 u16 nvmet_report_invalid_opcode(struct nvmet_req *req)
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/6] nvmet: small cleanup
  2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
                   ` (5 preceding siblings ...)
  2021-06-14  1:58 ` [PATCH 6/6] nvmet: remove local variable Chaitanya Kulkarni
@ 2021-06-15 16:18 ` Christoph Hellwig
  6 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2021-06-15 16:18 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: linux-nvme, hch, sagi

Thanks,

applied to nvme-5.14.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-06-15 20:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14  1:58 [PATCH 0/6] nvmet: small cleanup Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 1/6] nvmet: use req->cmd directly in bdev-ns fast path Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 2/6] nvmet: use req->cmd directly in file-ns " Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 3/6] nvmet: use u32 for nvmet_subsys max_nsid Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 4/6] nvmet: use u32 type for the local variable nsid Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 5/6] nvmet: use nvme status value directly Chaitanya Kulkarni
2021-06-14  1:58 ` [PATCH 6/6] nvmet: remove local variable Chaitanya Kulkarni
2021-06-15 16:18 ` [PATCH 0/6] nvmet: small cleanup Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.