Commit c1fef73f authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Christoph Hellwig

nvmet: add passthru code to process commands

Add passthru command handling capability for the NVMeOF target and
export passthru APIs which are used to integrate passthru
code with nvmet-core.

The new file passthru.c handles passthru cmd parsing and execution.
In the passthru mode, we create a block layer request from the nvmet
request and map the data on to the block layer request.

Admin commands and features are on an allow list as there are a number
of each that don't make too much sense with passthrough. We use an
allow list such that new commands can be considered before being blindly
passed through. In both cases, vendor specific commands are always
allowed.

We also reject reservation IO commands as the underlying device cannot
differentiate between multiple hosts behind a fabric.
Based-on-a-patch-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 24493b8b
...@@ -11,6 +11,7 @@ obj-$(CONFIG_NVME_TARGET_TCP) += nvmet-tcp.o ...@@ -11,6 +11,7 @@ obj-$(CONFIG_NVME_TARGET_TCP) += nvmet-tcp.o
nvmet-y += core.o configfs.o admin-cmd.o fabrics-cmd.o \ nvmet-y += core.o configfs.o admin-cmd.o fabrics-cmd.o \
discovery.o io-cmd-file.o io-cmd-bdev.o discovery.o io-cmd-file.o io-cmd-bdev.o
nvmet-$(CONFIG_NVME_TARGET_PASSTHRU) += passthru.o
nvme-loop-y += loop.o nvme-loop-y += loop.o
nvmet-rdma-y += rdma.o nvmet-rdma-y += rdma.o
nvmet-fc-y += fc.o nvmet-fc-y += fc.o
......
...@@ -749,7 +749,7 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask) ...@@ -749,7 +749,7 @@ u16 nvmet_set_feat_async_event(struct nvmet_req *req, u32 mask)
return 0; return 0;
} }
static void nvmet_execute_set_features(struct nvmet_req *req) void nvmet_execute_set_features(struct nvmet_req *req)
{ {
struct nvmet_subsys *subsys = req->sq->ctrl->subsys; struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10); u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
...@@ -824,7 +824,7 @@ void nvmet_get_feat_async_event(struct nvmet_req *req) ...@@ -824,7 +824,7 @@ void nvmet_get_feat_async_event(struct nvmet_req *req)
nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled)); nvmet_set_result(req, READ_ONCE(req->sq->ctrl->aen_enabled));
} }
static void nvmet_execute_get_features(struct nvmet_req *req) void nvmet_execute_get_features(struct nvmet_req *req)
{ {
struct nvmet_subsys *subsys = req->sq->ctrl->subsys; struct nvmet_subsys *subsys = req->sq->ctrl->subsys;
u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10); u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
...@@ -940,6 +940,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req) ...@@ -940,6 +940,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
if (nvmet_req_passthru_ctrl(req))
return nvmet_parse_passthru_admin_cmd(req);
switch (cmd->common.opcode) { switch (cmd->common.opcode) {
case nvme_admin_get_log_page: case nvme_admin_get_log_page:
req->execute = nvmet_execute_get_log_page; req->execute = nvmet_execute_get_log_page;
......
...@@ -849,6 +849,9 @@ static u16 nvmet_parse_io_cmd(struct nvmet_req *req) ...@@ -849,6 +849,9 @@ static u16 nvmet_parse_io_cmd(struct nvmet_req *req)
if (unlikely(ret)) if (unlikely(ret))
return ret; return ret;
if (nvmet_req_passthru_ctrl(req))
return nvmet_parse_passthru_io_cmd(req);
req->ns = nvmet_find_namespace(req->sq->ctrl, cmd->rw.nsid); req->ns = nvmet_find_namespace(req->sq->ctrl, cmd->rw.nsid);
if (unlikely(!req->ns)) { if (unlikely(!req->ns)) {
req->error_loc = offsetof(struct nvme_common_command, nsid); req->error_loc = offsetof(struct nvme_common_command, nsid);
......
...@@ -242,6 +242,10 @@ struct nvmet_subsys { ...@@ -242,6 +242,10 @@ struct nvmet_subsys {
struct config_group allowed_hosts_group; struct config_group allowed_hosts_group;
struct nvmet_subsys_model __rcu *model; struct nvmet_subsys_model __rcu *model;
#ifdef CONFIG_NVME_TARGET_PASSTHRU
struct nvme_ctrl *passthru_ctrl;
#endif /* CONFIG_NVME_TARGET_PASSTHRU */
}; };
static inline struct nvmet_subsys *to_subsys(struct config_item *item) static inline struct nvmet_subsys *to_subsys(struct config_item *item)
...@@ -321,6 +325,11 @@ struct nvmet_req { ...@@ -321,6 +325,11 @@ struct nvmet_req {
struct bio_vec *bvec; struct bio_vec *bvec;
struct work_struct work; struct work_struct work;
} f; } f;
struct {
struct request *rq;
struct work_struct work;
bool use_workqueue;
} p;
}; };
int sg_cnt; int sg_cnt;
int metadata_sg_cnt; int metadata_sg_cnt;
...@@ -400,6 +409,8 @@ void nvmet_req_complete(struct nvmet_req *req, u16 status); ...@@ -400,6 +409,8 @@ void nvmet_req_complete(struct nvmet_req *req, u16 status);
int nvmet_req_alloc_sgls(struct nvmet_req *req); int nvmet_req_alloc_sgls(struct nvmet_req *req);
void nvmet_req_free_sgls(struct nvmet_req *req); void nvmet_req_free_sgls(struct nvmet_req *req);
void nvmet_execute_set_features(struct nvmet_req *req);
void nvmet_execute_get_features(struct nvmet_req *req);
void nvmet_execute_keep_alive(struct nvmet_req *req); void nvmet_execute_keep_alive(struct nvmet_req *req);
void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, u16 qid, void nvmet_cq_setup(struct nvmet_ctrl *ctrl, struct nvmet_cq *cq, u16 qid,
...@@ -532,6 +543,34 @@ static inline u32 nvmet_dsm_len(struct nvmet_req *req) ...@@ -532,6 +543,34 @@ static inline u32 nvmet_dsm_len(struct nvmet_req *req)
sizeof(struct nvme_dsm_range); sizeof(struct nvme_dsm_range);
} }
#ifdef CONFIG_NVME_TARGET_PASSTHRU
u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req);
u16 nvmet_parse_passthru_io_cmd(struct nvmet_req *req);
static inline struct nvme_ctrl *nvmet_passthru_ctrl(struct nvmet_subsys *subsys)
{
return subsys->passthru_ctrl;
}
#else /* CONFIG_NVME_TARGET_PASSTHRU */
static inline u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req)
{
return 0;
}
static inline u16 nvmet_parse_passthru_io_cmd(struct nvmet_req *req)
{
return 0;
}
static inline struct nvme_ctrl *nvmet_passthru_ctrl(struct nvmet_subsys *subsys)
{
return NULL;
}
#endif /* CONFIG_NVME_TARGET_PASSTHRU */
static inline struct nvme_ctrl *
nvmet_req_passthru_ctrl(struct nvmet_req *req)
{
return nvmet_passthru_ctrl(req->sq->ctrl->subsys);
}
u16 errno_to_nvme_status(struct nvmet_req *req, int errno); u16 errno_to_nvme_status(struct nvmet_req *req, int errno);
/* Convert a 32-bit number to a 16-bit 0's based number */ /* Convert a 32-bit number to a 16-bit 0's based number */
......
This diff is collapsed.
...@@ -312,6 +312,7 @@ enum { ...@@ -312,6 +312,7 @@ enum {
NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1, NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
NVME_CTRL_ONCS_DSM = 1 << 2, NVME_CTRL_ONCS_DSM = 1 << 2,
NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3, NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3,
NVME_CTRL_ONCS_RESERVATIONS = 1 << 5,
NVME_CTRL_ONCS_TIMESTAMP = 1 << 6, NVME_CTRL_ONCS_TIMESTAMP = 1 << 6,
NVME_CTRL_VWC_PRESENT = 1 << 0, NVME_CTRL_VWC_PRESENT = 1 << 0,
NVME_CTRL_OACS_SEC_SUPP = 1 << 0, NVME_CTRL_OACS_SEC_SUPP = 1 << 0,
...@@ -982,6 +983,7 @@ enum nvme_admin_opcode { ...@@ -982,6 +983,7 @@ enum nvme_admin_opcode {
nvme_admin_security_recv = 0x82, nvme_admin_security_recv = 0x82,
nvme_admin_sanitize_nvm = 0x84, nvme_admin_sanitize_nvm = 0x84,
nvme_admin_get_lba_status = 0x86, nvme_admin_get_lba_status = 0x86,
nvme_admin_vendor_start = 0xC0,
}; };
#define nvme_admin_opcode_name(opcode) { opcode, #opcode } #define nvme_admin_opcode_name(opcode) { opcode, #opcode }
...@@ -1045,6 +1047,8 @@ enum { ...@@ -1045,6 +1047,8 @@ enum {
NVME_FEAT_RESV_MASK = 0x82, NVME_FEAT_RESV_MASK = 0x82,
NVME_FEAT_RESV_PERSIST = 0x83, NVME_FEAT_RESV_PERSIST = 0x83,
NVME_FEAT_WRITE_PROTECT = 0x84, NVME_FEAT_WRITE_PROTECT = 0x84,
NVME_FEAT_VENDOR_START = 0xC0,
NVME_FEAT_VENDOR_END = 0xFF,
NVME_LOG_ERROR = 0x01, NVME_LOG_ERROR = 0x01,
NVME_LOG_SMART = 0x02, NVME_LOG_SMART = 0x02,
NVME_LOG_FW_SLOT = 0x03, NVME_LOG_FW_SLOT = 0x03,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment