Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64a0ca88 authored by Parav Pandit's avatar Parav Pandit Committed by Jens Axboe
Browse files

nvmet: Introduced helper routine for controller status check.



This patch introduces helper function for checking controller
status during admin and io command processing which returns u16
status. As to bring consistency on returning status, other
friend functions also now return u16 status instead of int
to match the spec.

As part of the theseerror log prints in also prints qid on
which command error occured.

Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 4151dd9a
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -480,22 +480,16 @@ static void nvmet_execute_keep_alive(struct nvmet_req *req)
	nvmet_req_complete(req, 0);
}

int nvmet_parse_admin_cmd(struct nvmet_req *req)
u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
{
	struct nvme_command *cmd = req->cmd;
	u16 ret;

	req->ns = NULL;

	if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) {
		pr_err("got admin cmd %d while CC.EN == 0\n",
		       cmd->common.opcode);
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
	}
	if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
		pr_err("got admin cmd %d while CSTS.RDY == 0\n",
		       cmd->common.opcode);
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
	}
	ret = nvmet_check_ctrl_status(req, cmd);
	if (unlikely(ret))
		return ret;

	switch (cmd->common.opcode) {
	case nvme_admin_get_log_page:
@@ -545,6 +539,7 @@ int nvmet_parse_admin_cmd(struct nvmet_req *req)
		return 0;
	}

	pr_err("unhandled cmd %d\n", cmd->common.opcode);
	pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode,
	       req->sq->qid);
	return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
}
+17 −0
Original line number Diff line number Diff line
@@ -661,6 +661,23 @@ u16 nvmet_ctrl_find_get(const char *subsysnqn, const char *hostnqn, u16 cntlid,
	return status;
}

u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd)
{
	if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) {
		pr_err("got io cmd %d while CC.EN == 0 on qid = %d\n",
		       cmd->common.opcode, req->sq->qid);
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
	}

	if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
		pr_err("got io cmd %d while CSTS.RDY == 0 on qid = %d\n",
		       cmd->common.opcode, req->sq->qid);
		req->ns = NULL;
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
	}
	return 0;
}

static bool __nvmet_host_allowed(struct nvmet_subsys *subsys,
		const char *hostnqn)
{
+1 −1
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ static void nvmet_execute_identify_disc_ctrl(struct nvmet_req *req)
	nvmet_req_complete(req, status);
}

int nvmet_parse_discovery_cmd(struct nvmet_req *req)
u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
{
	struct nvme_command *cmd = req->cmd;

+2 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ static void nvmet_execute_prop_get(struct nvmet_req *req)
	nvmet_req_complete(req, status);
}

int nvmet_parse_fabrics_cmd(struct nvmet_req *req)
u16 nvmet_parse_fabrics_cmd(struct nvmet_req *req)
{
	struct nvme_command *cmd = req->cmd;

@@ -214,7 +214,7 @@ static void nvmet_execute_io_connect(struct nvmet_req *req)
	goto out;
}

int nvmet_parse_connect_cmd(struct nvmet_req *req)
u16 nvmet_parse_connect_cmd(struct nvmet_req *req)
{
	struct nvme_command *cmd = req->cmd;

+8 −14
Original line number Diff line number Diff line
@@ -196,26 +196,19 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req)
	}
}

int nvmet_parse_io_cmd(struct nvmet_req *req)
u16 nvmet_parse_io_cmd(struct nvmet_req *req)
{
	struct nvme_command *cmd = req->cmd;
	u16 ret;

	if (unlikely(!(req->sq->ctrl->cc & NVME_CC_ENABLE))) {
		pr_err("got io cmd %d while CC.EN == 0\n",
		       cmd->common.opcode);
	ret = nvmet_check_ctrl_status(req, cmd);
	if (unlikely(ret)) {
		req->ns = NULL;
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
	}

	if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
		pr_err("got io cmd %d while CSTS.RDY == 0\n",
		       cmd->common.opcode);
		req->ns = NULL;
		return NVME_SC_CMD_SEQ_ERROR | NVME_SC_DNR;
		return ret;
	}

	req->ns = nvmet_find_namespace(req->sq->ctrl, cmd->rw.nsid);
	if (!req->ns)
	if (unlikely(!req->ns))
		return NVME_SC_INVALID_NS | NVME_SC_DNR;

	switch (cmd->common.opcode) {
@@ -237,7 +230,8 @@ int nvmet_parse_io_cmd(struct nvmet_req *req)
		req->execute = nvmet_execute_write_zeroes;
		return 0;
	default:
		pr_err("unhandled cmd %d\n", cmd->common.opcode);
		pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode,
		       req->sq->qid);
		return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
	}
}
Loading