2019-02-18 18:36:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-06-22 00:04:20 +08:00
|
|
|
/*
|
|
|
|
* Discovery service for the NVMe over Fabrics target.
|
|
|
|
* Copyright (C) 2016 Intel Corporation. All rights reserved.
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <generated/utsrelease.h>
|
|
|
|
#include "nvmet.h"
|
|
|
|
|
|
|
|
struct nvmet_subsys *nvmet_disc_subsys;
|
|
|
|
|
2018-11-14 23:46:23 +08:00
|
|
|
static u64 nvmet_genctr;
|
2016-06-22 00:04:20 +08:00
|
|
|
|
2018-11-13 05:56:40 +08:00
|
|
|
static void __nvmet_disc_changed(struct nvmet_port *port,
|
|
|
|
struct nvmet_ctrl *ctrl)
|
|
|
|
{
|
|
|
|
if (ctrl->port != port)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nvmet_aen_bit_disabled(ctrl, NVME_AEN_BIT_DISC_CHANGE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nvmet_add_async_event(ctrl, NVME_AER_TYPE_NOTICE,
|
|
|
|
NVME_AER_NOTICE_DISC_CHANGED, NVME_LOG_DISC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nvmet_port_disc_changed(struct nvmet_port *port,
|
|
|
|
struct nvmet_subsys *subsys)
|
|
|
|
{
|
|
|
|
struct nvmet_ctrl *ctrl;
|
|
|
|
|
2019-04-30 07:28:19 +08:00
|
|
|
lockdep_assert_held(&nvmet_config_sem);
|
2018-11-13 05:56:40 +08:00
|
|
|
nvmet_genctr++;
|
|
|
|
|
2019-04-30 07:28:19 +08:00
|
|
|
mutex_lock(&nvmet_disc_subsys->lock);
|
2018-11-13 05:56:40 +08:00
|
|
|
list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
|
|
|
|
if (subsys && !nvmet_host_allowed(subsys, ctrl->hostnqn))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
__nvmet_disc_changed(port, ctrl);
|
|
|
|
}
|
2019-04-30 07:28:19 +08:00
|
|
|
mutex_unlock(&nvmet_disc_subsys->lock);
|
2019-05-15 05:58:02 +08:00
|
|
|
|
|
|
|
/* If transport can signal change, notify transport */
|
|
|
|
if (port->tr_ops && port->tr_ops->discovery_chg)
|
|
|
|
port->tr_ops->discovery_chg(port);
|
2018-11-13 05:56:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
|
|
|
|
struct nvmet_subsys *subsys,
|
|
|
|
struct nvmet_host *host)
|
|
|
|
{
|
|
|
|
struct nvmet_ctrl *ctrl;
|
|
|
|
|
2019-04-30 07:28:19 +08:00
|
|
|
mutex_lock(&nvmet_disc_subsys->lock);
|
2018-11-13 05:56:40 +08:00
|
|
|
list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
|
|
|
|
if (host && strcmp(nvmet_host_name(host), ctrl->hostnqn))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
__nvmet_disc_changed(port, ctrl);
|
|
|
|
}
|
2019-04-30 07:28:19 +08:00
|
|
|
mutex_unlock(&nvmet_disc_subsys->lock);
|
2018-11-13 05:56:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,
|
|
|
|
struct nvmet_host *host)
|
|
|
|
{
|
|
|
|
struct nvmet_port *port;
|
|
|
|
struct nvmet_subsys_link *s;
|
|
|
|
|
|
|
|
nvmet_genctr++;
|
|
|
|
|
|
|
|
list_for_each_entry(port, nvmet_ports, global_entry)
|
|
|
|
list_for_each_entry(s, &port->subsystems, entry) {
|
|
|
|
if (s->subsys != subsys)
|
|
|
|
continue;
|
|
|
|
__nvmet_subsys_disc_changed(port, subsys, host);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
void nvmet_referral_enable(struct nvmet_port *parent, struct nvmet_port *port)
|
|
|
|
{
|
|
|
|
down_write(&nvmet_config_sem);
|
|
|
|
if (list_empty(&port->entry)) {
|
|
|
|
list_add_tail(&port->entry, &parent->referrals);
|
|
|
|
port->enabled = true;
|
2018-11-13 05:56:40 +08:00
|
|
|
nvmet_port_disc_changed(parent, NULL);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
up_write(&nvmet_config_sem);
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:56:40 +08:00
|
|
|
void nvmet_referral_disable(struct nvmet_port *parent, struct nvmet_port *port)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
down_write(&nvmet_config_sem);
|
|
|
|
if (!list_empty(&port->entry)) {
|
|
|
|
port->enabled = false;
|
|
|
|
list_del_init(&port->entry);
|
2018-11-13 05:56:40 +08:00
|
|
|
nvmet_port_disc_changed(parent, NULL);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
up_write(&nvmet_config_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nvmet_format_discovery_entry(struct nvmf_disc_rsp_page_hdr *hdr,
|
2018-01-25 02:27:10 +08:00
|
|
|
struct nvmet_port *port, char *subsys_nqn, char *traddr,
|
|
|
|
u8 type, u32 numrec)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
struct nvmf_disc_rsp_page_entry *e = &hdr->entries[numrec];
|
|
|
|
|
|
|
|
e->trtype = port->disc_addr.trtype;
|
|
|
|
e->adrfam = port->disc_addr.adrfam;
|
|
|
|
e->treq = port->disc_addr.treq;
|
|
|
|
e->portid = port->disc_addr.portid;
|
|
|
|
/* we support only dynamic controllers */
|
|
|
|
e->cntlid = cpu_to_le16(NVME_CNTLID_DYNAMIC);
|
2017-06-18 21:15:59 +08:00
|
|
|
e->asqsz = cpu_to_le16(NVME_AQ_DEPTH);
|
2016-09-30 19:51:06 +08:00
|
|
|
e->subtype = type;
|
2016-06-22 00:04:20 +08:00
|
|
|
memcpy(e->trsvcid, port->disc_addr.trsvcid, NVMF_TRSVCID_SIZE);
|
2018-01-25 02:27:10 +08:00
|
|
|
memcpy(e->traddr, traddr, NVMF_TRADDR_SIZE);
|
2016-06-22 00:04:20 +08:00
|
|
|
memcpy(e->tsas.common, port->disc_addr.tsas.common, NVMF_TSAS_SIZE);
|
nvme: target: fix buffer overflow
nvmet_execute_get_disc_log_page() passes a fixed-length string into
nvmet_format_discovery_entry(), which then does a longer memcpy() on
it, as pointed out by gcc-8:
In function 'nvmet_format_discovery_entry',
inlined from 'nvmet_execute_get_disc_log_page' at drivers/nvme/target/discovery.c:126:4:
drivers/nvme/target/discovery.c:62:2: error: 'memcpy' forming offset [38, 223] is out of the bounds [0, 37] [-Werror=array-bounds]
memcpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
Using strncpy() will make this well-defined, filling the rest of the
buffer with zeroes, under the assumption that the input is either
a NUL-terminated string, or a byte sequence containing no zeroes.
If the input is a string that is longer than NVMF_NQN_SIZE, we
continue to have no NUL-termination in the output.
Fixes: a07b4970f464 ("nvmet: add a generic NVMe target")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <keith.busch@intel.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-04-12 23:16:07 +08:00
|
|
|
strncpy(e->subnqn, subsys_nqn, NVMF_NQN_SIZE);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
2018-01-25 02:27:10 +08:00
|
|
|
/*
|
|
|
|
* nvmet_set_disc_traddr - set a correct discovery log entry traddr
|
|
|
|
*
|
|
|
|
* IP based transports (e.g RDMA) can listen on "any" ipv4/ipv6 addresses
|
|
|
|
* (INADDR_ANY or IN6ADDR_ANY_INIT). The discovery log page traddr reply
|
|
|
|
* must not contain that "any" IP address. If the transport implements
|
|
|
|
* .disc_traddr, use it. this callback will set the discovery traddr
|
|
|
|
* from the req->port address in case the port in question listens
|
|
|
|
* "any" IP address.
|
|
|
|
*/
|
|
|
|
static void nvmet_set_disc_traddr(struct nvmet_req *req, struct nvmet_port *port,
|
|
|
|
char *traddr)
|
|
|
|
{
|
|
|
|
if (req->ops->disc_traddr)
|
|
|
|
req->ops->disc_traddr(req, port, traddr);
|
|
|
|
else
|
|
|
|
memcpy(traddr, port->disc_addr.traddr, NVMF_TRADDR_SIZE);
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:03:59 +08:00
|
|
|
static size_t discovery_log_entries(struct nvmet_req *req)
|
|
|
|
{
|
|
|
|
struct nvmet_ctrl *ctrl = req->sq->ctrl;
|
|
|
|
struct nvmet_subsys_link *p;
|
|
|
|
struct nvmet_port *r;
|
|
|
|
size_t entries = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(p, &req->port->subsystems, entry) {
|
|
|
|
if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
|
|
|
|
continue;
|
|
|
|
entries++;
|
|
|
|
}
|
|
|
|
list_for_each_entry(r, &req->port->referrals, entry)
|
|
|
|
entries++;
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
2019-10-24 00:35:42 +08:00
|
|
|
static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
const int entry_size = sizeof(struct nvmf_disc_rsp_page_entry);
|
|
|
|
struct nvmet_ctrl *ctrl = req->sq->ctrl;
|
|
|
|
struct nvmf_disc_rsp_page_hdr *hdr;
|
2019-04-10 00:03:59 +08:00
|
|
|
u64 offset = nvmet_get_log_page_offset(req->cmd);
|
2016-06-22 00:04:20 +08:00
|
|
|
size_t data_len = nvmet_get_log_page_len(req->cmd);
|
2019-04-10 00:03:59 +08:00
|
|
|
size_t alloc_len;
|
2016-06-22 00:04:20 +08:00
|
|
|
struct nvmet_subsys_link *p;
|
|
|
|
struct nvmet_port *r;
|
|
|
|
u32 numrec = 0;
|
|
|
|
u16 status = 0;
|
2019-04-10 00:03:59 +08:00
|
|
|
void *buffer;
|
|
|
|
|
2019-10-24 00:35:44 +08:00
|
|
|
if (!nvmet_check_data_len(req, data_len))
|
|
|
|
return;
|
|
|
|
|
2019-10-24 00:35:42 +08:00
|
|
|
if (req->cmd->get_log_page.lid != NVME_LOG_DISC) {
|
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvme_get_log_page_command, lid);
|
|
|
|
status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:03:59 +08:00
|
|
|
/* Spec requires dword aligned offsets */
|
|
|
|
if (offset & 0x3) {
|
|
|
|
status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
|
|
|
|
goto out;
|
|
|
|
}
|
2016-06-22 00:04:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we're passing at least a buffer of response header size.
|
|
|
|
* If host provided data len is less than the header size, only the
|
|
|
|
* number of bytes requested by host will be sent to host.
|
|
|
|
*/
|
2019-04-10 00:03:59 +08:00
|
|
|
down_read(&nvmet_config_sem);
|
|
|
|
alloc_len = sizeof(*hdr) + entry_size * discovery_log_entries(req);
|
|
|
|
buffer = kzalloc(alloc_len, GFP_KERNEL);
|
|
|
|
if (!buffer) {
|
|
|
|
up_read(&nvmet_config_sem);
|
2016-06-22 00:04:20 +08:00
|
|
|
status = NVME_SC_INTERNAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:03:59 +08:00
|
|
|
hdr = buffer;
|
2016-06-22 00:04:20 +08:00
|
|
|
list_for_each_entry(p, &req->port->subsystems, entry) {
|
2019-04-10 00:03:59 +08:00
|
|
|
char traddr[NVMF_TRADDR_SIZE];
|
|
|
|
|
2018-11-13 05:56:39 +08:00
|
|
|
if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
|
2016-06-22 00:04:20 +08:00
|
|
|
continue;
|
2019-04-10 00:03:59 +08:00
|
|
|
|
|
|
|
nvmet_set_disc_traddr(req, req->port, traddr);
|
|
|
|
nvmet_format_discovery_entry(hdr, req->port,
|
|
|
|
p->subsys->subsysnqn, traddr,
|
|
|
|
NVME_NQN_NVME, numrec);
|
2016-06-22 00:04:20 +08:00
|
|
|
numrec++;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(r, &req->port->referrals, entry) {
|
2019-04-10 00:03:59 +08:00
|
|
|
nvmet_format_discovery_entry(hdr, r,
|
|
|
|
NVME_DISC_SUBSYS_NAME,
|
|
|
|
r->disc_addr.traddr,
|
|
|
|
NVME_NQN_DISC, numrec);
|
2016-06-22 00:04:20 +08:00
|
|
|
numrec++;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr->genctr = cpu_to_le64(nvmet_genctr);
|
|
|
|
hdr->numrec = cpu_to_le64(numrec);
|
|
|
|
hdr->recfmt = cpu_to_le16(0);
|
|
|
|
|
2018-11-13 05:56:40 +08:00
|
|
|
nvmet_clear_aen_bit(req, NVME_AEN_BIT_DISC_CHANGE);
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
up_read(&nvmet_config_sem);
|
|
|
|
|
2019-04-10 00:03:59 +08:00
|
|
|
status = nvmet_copy_to_sgl(req, 0, buffer + offset, data_len);
|
|
|
|
kfree(buffer);
|
2016-06-22 00:04:20 +08:00
|
|
|
out:
|
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
}
|
|
|
|
|
2019-10-24 00:35:42 +08:00
|
|
|
static void nvmet_execute_disc_identify(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
struct nvmet_ctrl *ctrl = req->sq->ctrl;
|
|
|
|
struct nvme_id_ctrl *id;
|
2019-10-25 00:55:58 +08:00
|
|
|
const char model[] = "Linux";
|
2016-06-22 00:04:20 +08:00
|
|
|
u16 status = 0;
|
|
|
|
|
2019-10-24 00:35:44 +08:00
|
|
|
if (!nvmet_check_data_len(req, NVME_IDENTIFY_DATA_SIZE))
|
|
|
|
return;
|
|
|
|
|
2019-10-24 00:35:42 +08:00
|
|
|
if (req->cmd->identify.cns != NVME_ID_CNS_CTRL) {
|
|
|
|
req->error_loc = offsetof(struct nvme_identify, cns);
|
|
|
|
status = NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-06-22 00:04:20 +08:00
|
|
|
id = kzalloc(sizeof(*id), GFP_KERNEL);
|
|
|
|
if (!id) {
|
|
|
|
status = NVME_SC_INTERNAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-10-25 00:55:58 +08:00
|
|
|
memset(id->sn, ' ', sizeof(id->sn));
|
|
|
|
bin2hex(id->sn, &ctrl->subsys->serial,
|
|
|
|
min(sizeof(ctrl->subsys->serial), sizeof(id->sn) / 2));
|
2016-06-22 00:04:20 +08:00
|
|
|
memset(id->fr, ' ', sizeof(id->fr));
|
2019-10-25 00:55:58 +08:00
|
|
|
memcpy_and_pad(id->mn, sizeof(id->mn), model, sizeof(model) - 1, ' ');
|
|
|
|
memcpy_and_pad(id->fr, sizeof(id->fr),
|
|
|
|
UTS_RELEASE, strlen(UTS_RELEASE), ' ');
|
2016-06-22 00:04:20 +08:00
|
|
|
|
|
|
|
/* no limit on data transfer sizes for now */
|
|
|
|
id->mdts = 0;
|
|
|
|
id->cntlid = cpu_to_le16(ctrl->cntlid);
|
|
|
|
id->ver = cpu_to_le32(ctrl->subsys->ver);
|
|
|
|
id->lpa = (1 << 2);
|
|
|
|
|
|
|
|
/* no enforcement soft-limit for maxcmd - pick arbitrary high value */
|
|
|
|
id->maxcmd = cpu_to_le16(NVMET_MAX_CMD);
|
|
|
|
|
|
|
|
id->sgls = cpu_to_le32(1 << 0); /* we always support SGLs */
|
|
|
|
if (ctrl->ops->has_keyed_sgls)
|
|
|
|
id->sgls |= cpu_to_le32(1 << 2);
|
nvmet-rdma: support max(16KB, PAGE_SIZE) inline data
The patch enables inline data sizes using up to 4 recv sges, and capping
the size at 16KB or at least 1 page size. So on a 4K page system, up to
16KB is supported, and for a 64K page system 1 page of 64KB is supported.
We avoid > 0 order page allocations for the inline buffers by using
multiple recv sges, one for each page. If the device cannot support
the configured inline data size due to lack of enough recv sges, then
log a warning and reduce the inline size.
Add a new configfs port attribute, called param_inline_data_size,
to allow configuring the size of inline data for a given nvmf port.
The maximum size allowed is still enforced by nvmet-rdma with
NVMET_RDMA_MAX_INLINE_DATA_SIZE, which is now max(16KB, PAGE_SIZE).
And the default size, if not specified via configfs, is still PAGE_SIZE.
This preserves the existing behavior, but allows larger inline sizes
for small page systems. If the configured inline data size exceeds
NVMET_RDMA_MAX_INLINE_DATA_SIZE, a warning is logged and the size is
reduced. If param_inline_data_size is set to 0, then inline data is
disabled for that nvmf port.
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
2018-06-20 22:15:10 +08:00
|
|
|
if (req->port->inline_data_size)
|
2016-06-22 00:04:20 +08:00
|
|
|
id->sgls |= cpu_to_le32(1 << 20);
|
|
|
|
|
2018-11-13 05:56:40 +08:00
|
|
|
id->oaes = cpu_to_le32(NVMET_DISC_AEN_CFG_OPTIONAL);
|
|
|
|
|
2018-10-09 05:28:51 +08:00
|
|
|
strlcpy(id->subnqn, ctrl->subsys->subsysnqn, sizeof(id->subnqn));
|
2016-06-22 00:04:20 +08:00
|
|
|
|
|
|
|
status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
|
|
|
|
|
|
|
|
kfree(id);
|
|
|
|
out:
|
|
|
|
nvmet_req_complete(req, status);
|
|
|
|
}
|
|
|
|
|
2018-11-13 05:56:38 +08:00
|
|
|
static void nvmet_execute_disc_set_features(struct nvmet_req *req)
|
|
|
|
{
|
2018-12-13 07:11:37 +08:00
|
|
|
u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
|
2018-11-13 05:56:38 +08:00
|
|
|
u16 stat;
|
|
|
|
|
2019-10-24 00:35:44 +08:00
|
|
|
if (!nvmet_check_data_len(req, 0))
|
|
|
|
return;
|
|
|
|
|
2018-11-13 05:56:38 +08:00
|
|
|
switch (cdw10 & 0xff) {
|
|
|
|
case NVME_FEAT_KATO:
|
|
|
|
stat = nvmet_set_feat_kato(req);
|
|
|
|
break;
|
|
|
|
case NVME_FEAT_ASYNC_EVENT:
|
|
|
|
stat = nvmet_set_feat_async_event(req,
|
|
|
|
NVMET_DISC_AEN_CFG_OPTIONAL);
|
|
|
|
break;
|
|
|
|
default:
|
2018-12-13 07:11:44 +08:00
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvme_common_command, cdw10);
|
2018-11-13 05:56:38 +08:00
|
|
|
stat = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvmet_req_complete(req, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nvmet_execute_disc_get_features(struct nvmet_req *req)
|
|
|
|
{
|
2018-12-13 07:11:37 +08:00
|
|
|
u32 cdw10 = le32_to_cpu(req->cmd->common.cdw10);
|
2018-11-13 05:56:38 +08:00
|
|
|
u16 stat = 0;
|
|
|
|
|
2019-10-24 00:35:44 +08:00
|
|
|
if (!nvmet_check_data_len(req, 0))
|
|
|
|
return;
|
|
|
|
|
2018-11-13 05:56:38 +08:00
|
|
|
switch (cdw10 & 0xff) {
|
|
|
|
case NVME_FEAT_KATO:
|
|
|
|
nvmet_get_feat_kato(req);
|
|
|
|
break;
|
|
|
|
case NVME_FEAT_ASYNC_EVENT:
|
|
|
|
nvmet_get_feat_async_event(req);
|
|
|
|
break;
|
|
|
|
default:
|
2018-12-13 07:11:44 +08:00
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvme_common_command, cdw10);
|
2018-11-13 05:56:38 +08:00
|
|
|
stat = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvmet_req_complete(req, stat);
|
|
|
|
}
|
|
|
|
|
2017-02-28 13:21:33 +08:00
|
|
|
u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
|
2016-06-22 00:04:20 +08:00
|
|
|
{
|
|
|
|
struct nvme_command *cmd = req->cmd;
|
|
|
|
|
|
|
|
if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
|
2017-02-28 13:21:02 +08:00
|
|
|
pr_err("got cmd %d while not ready\n",
|
|
|
|
cmd->common.opcode);
|
2018-12-13 07:11:44 +08:00
|
|
|
req->error_loc =
|
|
|
|
offsetof(struct nvme_common_command, opcode);
|
2016-06-22 00:04:20 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd->common.opcode) {
|
2018-11-13 05:56:38 +08:00
|
|
|
case nvme_admin_set_features:
|
|
|
|
req->execute = nvmet_execute_disc_set_features;
|
|
|
|
return 0;
|
|
|
|
case nvme_admin_get_features:
|
|
|
|
req->execute = nvmet_execute_disc_get_features;
|
|
|
|
return 0;
|
|
|
|
case nvme_admin_async_event:
|
|
|
|
req->execute = nvmet_execute_async_event;
|
|
|
|
return 0;
|
2018-11-13 05:56:35 +08:00
|
|
|
case nvme_admin_keep_alive:
|
|
|
|
req->execute = nvmet_execute_keep_alive;
|
|
|
|
return 0;
|
2016-06-22 00:04:20 +08:00
|
|
|
case nvme_admin_get_log_page:
|
2019-10-24 00:35:42 +08:00
|
|
|
req->execute = nvmet_execute_disc_get_log_page;
|
|
|
|
return 0;
|
2016-06-22 00:04:20 +08:00
|
|
|
case nvme_admin_identify:
|
2019-10-24 00:35:42 +08:00
|
|
|
req->execute = nvmet_execute_disc_identify;
|
|
|
|
return 0;
|
2016-06-22 00:04:20 +08:00
|
|
|
default:
|
2018-08-23 10:58:45 +08:00
|
|
|
pr_err("unhandled cmd %d\n", cmd->common.opcode);
|
2018-12-13 07:11:44 +08:00
|
|
|
req->error_loc = offsetof(struct nvme_common_command, opcode);
|
2016-06-22 00:04:20 +08:00
|
|
|
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int __init nvmet_init_discovery(void)
|
|
|
|
{
|
|
|
|
nvmet_disc_subsys =
|
|
|
|
nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_DISC);
|
2019-09-07 01:50:19 +08:00
|
|
|
return PTR_ERR_OR_ZERO(nvmet_disc_subsys);
|
2016-06-22 00:04:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nvmet_exit_discovery(void)
|
|
|
|
{
|
|
|
|
nvmet_subsys_put(nvmet_disc_subsys);
|
|
|
|
}
|