All of lore.kernel.org
 help / color / mirror / Atom feed
From: chaitanya.kulkarni@wdc.com (Chaitanya Kulkarni)
Subject: [RFC PATCH 7/8] nvmet: integrate passthru code with target core
Date: Fri, 30 Mar 2018 02:57:46 -0400	[thread overview]
Message-ID: <20180330065747.20962-8-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20180330065747.20962-1-chaitanya.kulkarni@wdc.com>

This patch integrates passthru code with target core, it
exports APIs to enable/disable passthru ctrl via configfs.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 drivers/nvme/target/core.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/nvme/target/nvmet.h |  2 ++
 2 files changed, 49 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 406fc4ca9768..2dad36666772 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -400,6 +400,29 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid)
 	return ns;
 }
 
+int nvmet_pt_ctrl_enable(struct nvmet_subsys *subsys)
+{
+	if (!subsys)
+		return -ENODEV;
+
+	if (nvme_get_ctrl_by_name(subsys->pt_ctrl_path, &subsys->pt_ctrl)) {
+		pr_err("unable to find passthru ctrl' %s'\n",
+				subsys->pt_ctrl_path);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+void nvmet_pt_ctrl_disable(struct nvmet_subsys *subsys)
+{
+	if (!subsys || !subsys->pt_ctrl)
+		return;
+
+	nvme_put_ctrl_by_name(subsys->pt_ctrl);
+	subsys->pt_ctrl = NULL;
+}
+
 static void __nvmet_req_complete(struct nvmet_req *req, u16 status)
 {
 	u32 old_sqhd, new_sqhd;
@@ -501,6 +524,14 @@ int nvmet_sq_init(struct nvmet_sq *sq)
 }
 EXPORT_SYMBOL_GPL(nvmet_sq_init);
 
+static bool nvmet_ctrl_pt_allow(struct nvmet_req *req)
+{
+	if (req->sq->ctrl && !req->sq->ctrl->subsys->pt_ctrl)
+		return false;
+
+	return nvmet_is_pt_cmd_supported(req);
+}
+
 bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
 		struct nvmet_sq *sq, struct nvmet_fabrics_ops *ops)
 {
@@ -535,6 +566,8 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
 	if (unlikely(!req->sq->ctrl))
 		/* will return an error for any Non-connect command: */
 		status = nvmet_parse_connect_cmd(req);
+	else if (nvmet_ctrl_pt_allow(req))
+		status = nvmet_parse_pt_cmd(req);
 	else if (likely(req->sq->qid != 0))
 		status = nvmet_parse_io_cmd(req);
 	else if (req->cmd->common.opcode == nvme_fabrics_command)
@@ -570,6 +603,19 @@ EXPORT_SYMBOL_GPL(nvmet_req_uninit);
 
 void nvmet_req_execute(struct nvmet_req *req)
 {
+	/*
+	 * Right now data_len is calculated before the transfer len
+	 * after we parse the command, With passthru interface
+	 * we allow VUC's. In order to make the code simple and compact,
+	 * instead of assinging the the dala len for each VUC in the command
+	 * parse function just use the transfer len as it is. This may
+	 * result is error if expected data_len != transfer_len.
+	 */
+	if (req->sq->ctrl && req->sq->ctrl->subsys->pt_ctrl) {
+		req->execute(req);
+		return;
+	}
+
 	if (unlikely(req->data_len != req->transfer_len))
 		nvmet_req_complete(req, NVME_SC_SGL_INVALID_DATA | NVME_SC_DNR);
 	else
@@ -1010,6 +1056,7 @@ static void nvmet_subsys_free(struct kref *ref)
 
 	WARN_ON_ONCE(!list_empty(&subsys->namespaces));
 
+	kfree(subsys->pt_ctrl_path);
 	kfree(subsys->subsysnqn);
 	kfree(subsys);
 }
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 1495e6df84a7..f2d694fffa1c 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -350,5 +350,7 @@ extern struct rw_semaphore nvmet_config_sem;
 bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys,
 		const char *hostnqn);
 
+int nvmet_pt_ctrl_enable(struct nvmet_subsys *subsys);
+void nvmet_pt_ctrl_disable(struct nvmet_subsys *subsys);
 bool nvmet_is_pt_cmd_supported(struct nvmet_req *req);
 #endif /* _NVMET_H */
-- 
2.14.1

  parent reply	other threads:[~2018-03-30  6:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  6:57 [RFC PATCH 0/8] nvmet: implement target passthru commands support Chaitanya Kulkarni
2018-03-30  6:57 ` [RFC PATCH 1/8] nvme-core: add new interfaces Chaitanya Kulkarni
2018-03-30 17:48   ` Logan Gunthorpe
2018-04-02 23:25     ` Chaitanya Kulkarni
2018-04-04 11:52   ` Sagi Grimberg
2018-04-13 17:27     ` Christoph Hellwig
2018-03-30  6:57 ` [RFC PATCH 2/8] nvme-core: export existing ctrl and ns interfaces Chaitanya Kulkarni
2018-04-04 11:59   ` Sagi Grimberg
2018-03-30  6:57 ` [RFC PATCH 3/8] nvmet: add passthru members in target subsys Chaitanya Kulkarni
2018-03-30  6:57 ` [RFC PATCH 4/8] nvmet: use const values for id-ctrl Chaitanya Kulkarni
2018-03-30 18:50   ` Logan Gunthorpe
2018-04-02 23:27     ` Chaitanya Kulkarni
2018-04-13 17:28     ` Christoph Hellwig
2018-03-30  6:57 ` [RFC PATCH 5/8] nvmet: export nvmet_add_async_event api Chaitanya Kulkarni
2018-03-30  6:57 ` [RFC PATCH 6/8] nvmet: add target passthru command support Chaitanya Kulkarni
2018-03-30  6:57 ` Chaitanya Kulkarni [this message]
2018-03-30  6:57 ` [RFC PATCH 8/8] nvmet: add configfs interface for target passthru Chaitanya Kulkarni
2018-03-30 18:13   ` Logan Gunthorpe
2018-04-03  0:13     ` Chaitanya Kulkarni
2018-04-03  3:21       ` Logan Gunthorpe
2018-04-13 17:30     ` Christoph Hellwig
2018-04-13 17:37       ` Logan Gunthorpe
2018-04-13 21:50         ` Stephen  Bates
2018-03-30 17:46 ` [RFC PATCH 0/8] nvmet: implement target passthru commands support Logan Gunthorpe
2018-04-02 23:23   ` Chaitanya Kulkarni
2018-04-04 11:44 ` Sagi Grimberg
2018-04-13 17:35   ` 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=20180330065747.20962-8-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    /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 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.