2016-08-15 01:16:49 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-08-15 01:16:49 +00:00
|
|
|
|
|
|
|
#include "subsystem.h"
|
2017-07-13 21:18:08 +00:00
|
|
|
#include "ctrlr.h"
|
2016-08-15 01:16:49 +00:00
|
|
|
#include "request.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
|
|
|
|
#include "spdk/bdev.h"
|
2016-08-25 22:49:00 +00:00
|
|
|
#include "spdk/endian.h"
|
2017-03-02 05:31:48 +00:00
|
|
|
#include "spdk/io_channel.h"
|
2016-08-15 01:16:49 +00:00
|
|
|
#include "spdk/nvme.h"
|
|
|
|
#include "spdk/nvmf_spec.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
#include "spdk/scsi_spec.h"
|
|
|
|
#include "spdk/string.h"
|
2017-03-03 20:44:04 +00:00
|
|
|
#include "spdk/util.h"
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2016-11-07 22:10:28 +00:00
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
#define MODEL_NUMBER "SPDK bdev Controller"
|
2016-08-15 01:16:49 +00:00
|
|
|
#define FW_VERSION "FFFFFFFF"
|
|
|
|
|
|
|
|
/* read command dword 12 */
|
|
|
|
struct __attribute__((packed)) nvme_read_cdw12 {
|
|
|
|
uint16_t nlb; /* number of logical blocks */
|
|
|
|
uint16_t rsvd : 10;
|
|
|
|
uint8_t prinfo : 4; /* protection information field */
|
|
|
|
uint8_t fua : 1; /* force unit access */
|
|
|
|
uint8_t lr : 1; /* limited retry */
|
|
|
|
};
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
static void nvmf_bdev_set_dsm(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2017-06-15 21:52:40 +00:00
|
|
|
uint32_t i;
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
for (i = 0; i < ctrlr->subsys->dev.max_nsid; i++) {
|
|
|
|
struct spdk_bdev *bdev = ctrlr->subsys->dev.ns_list[i];
|
2016-08-26 16:28:15 +00:00
|
|
|
|
2017-06-15 21:52:40 +00:00
|
|
|
if (bdev == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-26 16:28:15 +00:00
|
|
|
if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF,
|
2017-06-15 21:52:40 +00:00
|
|
|
"Subsystem%u Namespace %s does not support unmap - not enabling DSM\n",
|
2017-05-10 20:29:31 +00:00
|
|
|
i, spdk_bdev_get_name(bdev));
|
2016-08-26 16:28:15 +00:00
|
|
|
return;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "All devices in Subsystem %s support unmap - enabling DSM\n",
|
2017-07-13 21:18:08 +00:00
|
|
|
spdk_nvmf_subsystem_get_nqn(ctrlr->subsys));
|
|
|
|
ctrlr->vcdata.oncs.dsm = 1;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-07-13 21:18:08 +00:00
|
|
|
nvmf_bdev_ctrlr_get_data(struct spdk_nvmf_ctrlr *ctrlr)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsys = ctrlr->subsys;
|
|
|
|
|
|
|
|
memset(&ctrlr->vcdata, 0, sizeof(struct spdk_nvme_ctrlr_data));
|
|
|
|
spdk_strcpy_pad(ctrlr->vcdata.fr, FW_VERSION, sizeof(ctrlr->vcdata.fr), ' ');
|
|
|
|
spdk_strcpy_pad(ctrlr->vcdata.mn, MODEL_NUMBER, sizeof(ctrlr->vcdata.mn), ' ');
|
|
|
|
spdk_strcpy_pad(ctrlr->vcdata.sn, spdk_nvmf_subsystem_get_sn(subsys),
|
|
|
|
sizeof(ctrlr->vcdata.sn), ' ');
|
|
|
|
ctrlr->vcdata.rab = 6;
|
|
|
|
ctrlr->vcdata.ver.bits.mjr = 1;
|
|
|
|
ctrlr->vcdata.ver.bits.mnr = 2;
|
|
|
|
ctrlr->vcdata.ver.bits.ter = 1;
|
|
|
|
ctrlr->vcdata.ctratt.host_id_exhid_supported = 1;
|
|
|
|
ctrlr->vcdata.aerl = 0;
|
|
|
|
ctrlr->vcdata.frmw.slot1_ro = 1;
|
|
|
|
ctrlr->vcdata.frmw.num_slots = 1;
|
|
|
|
ctrlr->vcdata.lpa.edlp = 1;
|
|
|
|
ctrlr->vcdata.elpe = 127;
|
|
|
|
ctrlr->vcdata.sqes.min = 0x06;
|
|
|
|
ctrlr->vcdata.sqes.max = 0x06;
|
|
|
|
ctrlr->vcdata.cqes.min = 0x04;
|
|
|
|
ctrlr->vcdata.cqes.max = 0x04;
|
|
|
|
ctrlr->vcdata.maxcmd = 1024;
|
|
|
|
ctrlr->vcdata.nn = subsys->dev.max_nsid;
|
|
|
|
ctrlr->vcdata.vwc.present = 1;
|
|
|
|
ctrlr->vcdata.sgls.supported = 1;
|
|
|
|
strncpy(ctrlr->vcdata.subnqn, ctrlr->subsys->subnqn, sizeof(ctrlr->vcdata.subnqn));
|
|
|
|
nvmf_bdev_set_dsm(ctrlr);
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_poll_for_completions(struct spdk_nvmf_subsystem *subsystem)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_complete_cmd(struct spdk_bdev_io *bdev_io, bool success,
|
|
|
|
void *cb_arg)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2016-10-05 22:00:20 +00:00
|
|
|
struct spdk_nvmf_request *req = cb_arg;
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
2017-01-18 21:43:15 +00:00
|
|
|
int sc, sct;
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2017-01-18 21:43:15 +00:00
|
|
|
spdk_bdev_io_get_nvme_status(bdev_io, &sc, &sct);
|
|
|
|
response->status.sc = sc;
|
|
|
|
response->status.sct = sct;
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
spdk_nvmf_request_complete(req);
|
|
|
|
spdk_bdev_free_io(bdev_io);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_get_log_page(struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2016-08-26 17:51:12 +00:00
|
|
|
uint8_t lid;
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
2016-12-13 19:56:10 +00:00
|
|
|
uint64_t log_page_offset;
|
2016-08-15 01:16:49 +00:00
|
|
|
|
|
|
|
if (req->data == NULL) {
|
|
|
|
SPDK_ERRLOG("get log command with no buffer\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-11-22 21:36:44 +00:00
|
|
|
memset(req->data, 0, req->length);
|
|
|
|
|
2016-12-13 19:56:10 +00:00
|
|
|
log_page_offset = (uint64_t)cmd->cdw12 | ((uint64_t)cmd->cdw13 << 32);
|
|
|
|
if (log_page_offset & 3) {
|
|
|
|
SPDK_ERRLOG("Invalid log page offset 0x%" PRIx64 "\n", log_page_offset);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:51:12 +00:00
|
|
|
lid = cmd->cdw10 & 0xFF;
|
|
|
|
switch (lid) {
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_LOG_ERROR:
|
|
|
|
case SPDK_NVME_LOG_HEALTH_INFORMATION:
|
|
|
|
case SPDK_NVME_LOG_FIRMWARE_SLOT:
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
default:
|
2016-08-26 17:51:12 +00:00
|
|
|
SPDK_ERRLOG("Unsupported Get Log Page 0x%02X\n", lid);
|
2016-11-22 21:51:56 +00:00
|
|
|
response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_LOG_PAGE;
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-08-29 08:20:34 +00:00
|
|
|
identify_ns(struct spdk_nvmf_subsystem *subsystem,
|
2016-08-26 17:05:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd,
|
|
|
|
struct spdk_nvme_cpl *rsp,
|
|
|
|
struct spdk_nvme_ns_data *nsdata)
|
|
|
|
{
|
|
|
|
struct spdk_bdev *bdev;
|
2017-05-12 17:29:00 +00:00
|
|
|
uint64_t num_blocks;
|
2016-08-26 17:05:48 +00:00
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
if (cmd->nsid > subsystem->dev.max_nsid || cmd->nsid == 0) {
|
2016-08-26 17:05:48 +00:00
|
|
|
SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
bdev = subsystem->dev.ns_list[cmd->nsid - 1];
|
2016-08-26 17:05:48 +00:00
|
|
|
|
2017-06-15 21:52:40 +00:00
|
|
|
if (bdev == NULL) {
|
|
|
|
memset(nsdata, 0, sizeof(*nsdata));
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-05-12 17:29:00 +00:00
|
|
|
num_blocks = spdk_bdev_get_num_blocks(bdev);
|
|
|
|
|
|
|
|
nsdata->nsze = num_blocks;
|
|
|
|
nsdata->ncap = num_blocks;
|
|
|
|
nsdata->nuse = num_blocks;
|
2016-08-26 17:05:48 +00:00
|
|
|
nsdata->nlbaf = 0;
|
|
|
|
nsdata->flbas.format = 0;
|
2017-05-12 17:29:00 +00:00
|
|
|
nsdata->lbaf[0].lbads = spdk_u32log2(spdk_bdev_get_block_size(bdev));
|
2016-08-26 17:05:48 +00:00
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-07-13 21:18:08 +00:00
|
|
|
identify_ctrlr(struct spdk_nvmf_ctrlr *ctrlr, struct spdk_nvme_ctrlr_data *cdata)
|
2016-08-26 17:05:48 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
*cdata = ctrlr->vcdata;
|
2016-08-26 17:05:48 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-08-29 08:20:34 +00:00
|
|
|
identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem,
|
2016-08-26 17:05:48 +00:00
|
|
|
struct spdk_nvme_cmd *cmd,
|
|
|
|
struct spdk_nvme_cpl *rsp,
|
|
|
|
struct spdk_nvme_ns_list *ns_list)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2016-08-26 17:05:48 +00:00
|
|
|
uint32_t i, num_ns, count = 0;
|
|
|
|
|
|
|
|
if (cmd->nsid >= 0xfffffffeUL) {
|
|
|
|
SPDK_ERRLOG("Identify Active Namespace List with invalid NSID %u\n", cmd->nsid);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
num_ns = subsystem->dev.max_nsid;
|
2016-08-26 17:05:48 +00:00
|
|
|
|
|
|
|
for (i = 1; i <= num_ns; i++) {
|
|
|
|
if (i <= cmd->nsid) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-27 18:26:19 +00:00
|
|
|
if (subsystem->dev.ns_list[i - 1] == NULL) {
|
2017-06-15 21:52:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-26 17:05:48 +00:00
|
|
|
ns_list->ns_list[count++] = i;
|
2017-03-03 20:44:04 +00:00
|
|
|
if (count == SPDK_COUNTOF(ns_list->ns_list)) {
|
2016-08-26 17:05:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2016-08-26 17:05:48 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_identify(struct spdk_nvmf_request *req)
|
2016-08-26 17:05:48 +00:00
|
|
|
{
|
|
|
|
uint8_t cns;
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->conn->ctrlr;
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
2016-08-26 17:05:48 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
|
2016-08-15 01:16:49 +00:00
|
|
|
|
|
|
|
if (req->data == NULL || req->length < 4096) {
|
|
|
|
SPDK_ERRLOG("identify command with invalid buffer\n");
|
2016-08-26 17:05:48 +00:00
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-26 17:05:48 +00:00
|
|
|
memset(req->data, 0, req->length);
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2016-08-26 17:05:48 +00:00
|
|
|
cns = cmd->cdw10 & 0xFF;
|
|
|
|
switch (cns) {
|
|
|
|
case SPDK_NVME_IDENTIFY_NS:
|
2016-08-29 08:20:34 +00:00
|
|
|
return identify_ns(subsystem, cmd, rsp, req->data);
|
2016-08-26 17:05:48 +00:00
|
|
|
case SPDK_NVME_IDENTIFY_CTRLR:
|
2017-07-13 21:18:08 +00:00
|
|
|
return identify_ctrlr(ctrlr, req->data);
|
2016-08-26 17:05:48 +00:00
|
|
|
case SPDK_NVME_IDENTIFY_ACTIVE_NS_LIST:
|
2016-08-29 08:20:34 +00:00
|
|
|
return identify_active_ns_list(subsystem, cmd, rsp, req->data);
|
2016-08-26 17:05:48 +00:00
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Identify command with unsupported CNS 0x%02x\n", cns);
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 17:06:09 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_abort(struct spdk_nvmf_request *req)
|
2017-06-16 17:06:09 +00:00
|
|
|
{
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = req->conn->ctrlr;
|
2017-06-16 17:06:09 +00:00
|
|
|
struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
uint32_t cdw10 = cmd->cdw10;
|
|
|
|
uint16_t cid = cdw10 >> 16;
|
|
|
|
uint16_t sqid = cdw10 & 0xFFFFu;
|
|
|
|
struct spdk_nvmf_conn *conn;
|
|
|
|
struct spdk_nvmf_request *req_to_abort;
|
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "abort sqid=%u cid=%u\n", sqid, cid);
|
|
|
|
|
|
|
|
rsp->cdw0 = 1; /* Command not aborted */
|
|
|
|
|
2017-07-13 21:18:08 +00:00
|
|
|
conn = spdk_nvmf_ctrlr_get_conn(ctrlr, sqid);
|
2017-06-16 17:06:09 +00:00
|
|
|
if (conn == NULL) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "sqid %u not found\n", sqid);
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-07-13 21:18:08 +00:00
|
|
|
* NOTE: This relies on the assumption that all connections for a ctrlr will be handled
|
2017-06-16 17:06:09 +00:00
|
|
|
* on the same thread. If this assumption becomes untrue, this will need to pass a message
|
|
|
|
* to the thread handling conn, and the abort will need to be asynchronous.
|
|
|
|
*/
|
|
|
|
req_to_abort = spdk_nvmf_conn_get_request(conn, cid);
|
|
|
|
if (req_to_abort == NULL) {
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "cid %u not found\n", cid);
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_request_abort(req_to_abort) == 0) {
|
2017-07-13 21:18:08 +00:00
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "abort ctrlr=%p req=%p sqid=%u cid=%u successful\n",
|
|
|
|
ctrlr, req_to_abort, sqid, cid);
|
2017-06-16 17:06:09 +00:00
|
|
|
rsp->cdw0 = 0; /* Command successfully aborted */
|
|
|
|
}
|
|
|
|
rsp->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
rsp->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_get_features(struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint8_t feature;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
feature = cmd->cdw10 & 0xff; /* mask out the FID value */
|
|
|
|
switch (feature) {
|
|
|
|
case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_get_features_number_of_queues(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_FEAT_VOLATILE_WRITE_CACHE:
|
|
|
|
response->cdw0 = 1;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_get_features_keep_alive_timer(req);
|
2016-11-18 22:32:02 +00:00
|
|
|
case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_get_features_async_event_configuration(req);
|
2016-11-22 22:20:47 +00:00
|
|
|
case SPDK_NVME_FEAT_HOST_IDENTIFIER:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_get_features_host_identifier(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
default:
|
2016-11-22 21:49:49 +00:00
|
|
|
SPDK_ERRLOG("Get Features command with unsupported feature ID 0x%02x\n", feature);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_set_features(struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint8_t feature;
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
feature = cmd->cdw10 & 0xff; /* mask out the FID value */
|
|
|
|
switch (feature) {
|
|
|
|
case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_set_features_number_of_queues(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_set_features_keep_alive_timer(req);
|
2016-11-18 22:32:02 +00:00
|
|
|
case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_set_features_async_event_configuration(req);
|
2016-11-22 22:20:47 +00:00
|
|
|
case SPDK_NVME_FEAT_HOST_IDENTIFIER:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_set_features_host_identifier(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
default:
|
2016-11-22 21:49:49 +00:00
|
|
|
SPDK_ERRLOG("Set Features command with unsupported feature ID 0x%02x\n", feature);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
/* pre-set response details for this command */
|
|
|
|
response->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
|
|
|
|
switch (cmd->opc) {
|
|
|
|
case SPDK_NVME_OPC_GET_LOG_PAGE:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_get_log_page(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_IDENTIFY:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_identify(req);
|
2017-06-16 17:06:09 +00:00
|
|
|
case SPDK_NVME_OPC_ABORT:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_abort(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_GET_FEATURES:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_get_features(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_SET_FEATURES:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_set_features(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_ASYNC_EVENT_REQUEST:
|
2017-07-13 21:18:08 +00:00
|
|
|
return spdk_nvmf_ctrlr_async_event_request(req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_KEEP_ALIVE:
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Keep Alive\n");
|
|
|
|
/*
|
2017-04-24 18:14:41 +00:00
|
|
|
* To handle keep alive just clear or reset the
|
2017-07-13 21:18:08 +00:00
|
|
|
* ctrlr based keep alive duration counter.
|
2017-04-24 18:14:41 +00:00
|
|
|
* When added, a separate timer based process
|
|
|
|
* will monitor if the time since last recorded
|
|
|
|
* keep alive has exceeded the max duration and
|
|
|
|
* take appropriate action.
|
|
|
|
*/
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
|
|
|
|
case SPDK_NVME_OPC_CREATE_IO_SQ:
|
|
|
|
case SPDK_NVME_OPC_CREATE_IO_CQ:
|
|
|
|
case SPDK_NVME_OPC_DELETE_IO_SQ:
|
|
|
|
case SPDK_NVME_OPC_DELETE_IO_CQ:
|
|
|
|
SPDK_ERRLOG("Admin opc 0x%02X not allowed in NVMf\n", cmd->opc);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("Unsupported admin command\n");
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_rw_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
|
|
|
|
struct spdk_io_channel *ch, struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint64_t lba_address;
|
|
|
|
uint64_t blockcnt;
|
2016-08-26 20:05:29 +00:00
|
|
|
uint64_t io_bytes;
|
2016-09-29 20:26:56 +00:00
|
|
|
uint64_t offset;
|
2016-08-15 01:16:49 +00:00
|
|
|
uint64_t llen;
|
2017-05-12 17:29:00 +00:00
|
|
|
uint32_t block_size = spdk_bdev_get_block_size(bdev);
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
struct nvme_read_cdw12 *cdw12 = (struct nvme_read_cdw12 *)&cmd->cdw12;
|
|
|
|
|
2017-05-12 17:29:00 +00:00
|
|
|
blockcnt = spdk_bdev_get_num_blocks(bdev);
|
2016-08-15 01:16:49 +00:00
|
|
|
lba_address = cmd->cdw11;
|
|
|
|
lba_address = (lba_address << 32) + cmd->cdw10;
|
2017-05-12 17:29:00 +00:00
|
|
|
offset = lba_address * block_size;
|
2016-08-15 01:16:49 +00:00
|
|
|
llen = cdw12->nlb + 1;
|
|
|
|
|
|
|
|
if (lba_address >= blockcnt || llen > blockcnt || lba_address > (blockcnt - llen)) {
|
|
|
|
SPDK_ERRLOG("end of media\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_LBA_OUT_OF_RANGE;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-05-12 17:29:00 +00:00
|
|
|
io_bytes = llen * block_size;
|
2016-08-26 20:05:29 +00:00
|
|
|
if (io_bytes > req->length) {
|
|
|
|
SPDK_ERRLOG("Read/Write NLB > SGL length\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
if (cmd->opc == SPDK_NVME_OPC_READ) {
|
|
|
|
spdk_trace_record(TRACE_NVMF_LIB_READ_START, 0, 0, (uint64_t)req, 0);
|
2017-06-27 18:26:19 +00:00
|
|
|
if (spdk_bdev_read(desc, ch, req->data, offset, req->length, nvmf_bdev_ctrlr_complete_cmd,
|
2017-06-05 18:39:38 +00:00
|
|
|
req)) {
|
2016-08-15 01:16:49 +00:00
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
spdk_trace_record(TRACE_NVMF_LIB_WRITE_START, 0, 0, (uint64_t)req, 0);
|
2017-06-27 18:26:19 +00:00
|
|
|
if (spdk_bdev_write(desc, ch, req->data, offset, req->length, nvmf_bdev_ctrlr_complete_cmd,
|
2017-06-05 18:39:38 +00:00
|
|
|
req)) {
|
2016-08-15 01:16:49 +00:00
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_flush_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
|
|
|
|
struct spdk_io_channel *ch, struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint64_t nbytes;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
2017-05-12 17:29:00 +00:00
|
|
|
nbytes = spdk_bdev_get_num_blocks(bdev) * spdk_bdev_get_block_size(bdev);
|
2017-06-27 18:26:19 +00:00
|
|
|
if (spdk_bdev_flush(desc, ch, 0, nbytes, nvmf_bdev_ctrlr_complete_cmd, req)) {
|
2016-08-15 01:16:49 +00:00
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:32:04 +00:00
|
|
|
struct nvmf_virtual_ctrlr_unmap {
|
|
|
|
struct spdk_nvmf_request *req;
|
|
|
|
uint32_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_virtual_ctrlr_dsm_cpl(struct spdk_bdev_io *bdev_io, bool success,
|
|
|
|
void *cb_arg)
|
|
|
|
{
|
|
|
|
struct nvmf_virtual_ctrlr_unmap *unmap_ctx = cb_arg;
|
|
|
|
struct spdk_nvmf_request *req = unmap_ctx->req;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
int sc, sct;
|
|
|
|
|
|
|
|
unmap_ctx->count--;
|
|
|
|
|
|
|
|
if (response->status.sct == SPDK_NVME_SCT_GENERIC &&
|
|
|
|
response->status.sc == SPDK_NVME_SC_SUCCESS) {
|
|
|
|
spdk_bdev_io_get_nvme_status(bdev_io, &sc, &sct);
|
|
|
|
response->status.sc = sc;
|
|
|
|
response->status.sct = sct;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unmap_ctx->count == 0) {
|
|
|
|
spdk_nvmf_request_complete(req);
|
|
|
|
spdk_bdev_free_io(bdev_io);
|
|
|
|
free(unmap_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
|
|
|
|
struct spdk_io_channel *ch, struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint32_t attribute;
|
2017-07-19 21:32:04 +00:00
|
|
|
uint16_t nr, i;
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
nr = ((cmd->cdw10 & 0x000000ff) + 1);
|
2016-08-26 20:05:29 +00:00
|
|
|
if (nr * sizeof(struct spdk_nvme_dsm_range) > req->length) {
|
|
|
|
SPDK_ERRLOG("Dataset Management number of ranges > SGL length\n");
|
|
|
|
response->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
attribute = cmd->cdw11 & 0x00000007;
|
2016-08-26 19:43:24 +00:00
|
|
|
if (attribute & SPDK_NVME_DSM_ATTR_DEALLOCATE) {
|
2017-07-19 21:32:04 +00:00
|
|
|
struct nvmf_virtual_ctrlr_unmap *unmap_ctx;
|
|
|
|
struct spdk_nvme_dsm_range *dsm_range;
|
|
|
|
uint64_t lba;
|
|
|
|
uint32_t lba_count;
|
|
|
|
uint32_t block_size = spdk_bdev_get_block_size(bdev);
|
|
|
|
|
|
|
|
unmap_ctx = calloc(1, sizeof(*unmap_ctx));
|
|
|
|
if (!unmap_ctx) {
|
2016-08-15 01:16:49 +00:00
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-07-19 21:32:04 +00:00
|
|
|
unmap_ctx->req = req;
|
|
|
|
|
|
|
|
response->status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
response->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
|
|
|
|
dsm_range = (struct spdk_nvme_dsm_range *)req->data;
|
2016-08-15 01:16:49 +00:00
|
|
|
for (i = 0; i < nr; i++) {
|
2017-07-19 21:32:04 +00:00
|
|
|
lba = dsm_range[i].starting_lba;
|
|
|
|
lba_count = dsm_range[i].length;
|
|
|
|
|
|
|
|
unmap_ctx->count++;
|
|
|
|
|
|
|
|
if (spdk_bdev_unmap(desc, ch, lba * block_size, lba_count * block_size,
|
|
|
|
nvmf_virtual_ctrlr_dsm_cpl, unmap_ctx)) {
|
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
|
|
|
unmap_ctx->count--;
|
|
|
|
/* We can't return here - we may have to wait for any other
|
|
|
|
* unmaps already sent to complete */
|
|
|
|
break;
|
|
|
|
}
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
2017-07-19 21:32:04 +00:00
|
|
|
|
|
|
|
if (unmap_ctx->count == 0) {
|
|
|
|
free(unmap_ctx);
|
2016-08-15 01:16:49 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
2016-08-26 19:43:24 +00:00
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
|
|
|
|
}
|
2017-07-19 21:32:04 +00:00
|
|
|
|
|
|
|
response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
2016-08-26 19:43:24 +00:00
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-05 18:28:43 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
|
|
|
|
struct spdk_io_channel *ch, struct spdk_nvmf_request *req)
|
2017-06-05 18:28:43 +00:00
|
|
|
{
|
2017-07-06 19:39:19 +00:00
|
|
|
if (spdk_bdev_nvme_io_passthru(desc, ch, &req->cmd->nvme_cmd, req->data, req->length,
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_complete_cmd, req)) {
|
2017-06-05 18:28:43 +00:00
|
|
|
req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INVALID_OPCODE;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
|
|
|
uint32_t nsid;
|
|
|
|
struct spdk_bdev *bdev;
|
2017-07-06 19:39:19 +00:00
|
|
|
struct spdk_bdev_desc *desc;
|
2016-09-20 23:18:44 +00:00
|
|
|
struct spdk_io_channel *ch;
|
2017-07-13 21:18:08 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem = req->conn->ctrlr->subsys;
|
2016-08-15 01:16:49 +00:00
|
|
|
struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
|
|
|
|
struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
|
|
|
|
|
|
|
|
/* pre-set response details for this command */
|
|
|
|
response->status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
nsid = cmd->nsid;
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
if (nsid > subsystem->dev.max_nsid || nsid == 0) {
|
2016-08-15 01:16:49 +00:00
|
|
|
SPDK_ERRLOG("Unsuccessful query for nsid %u\n", cmd->nsid);
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
bdev = subsystem->dev.ns_list[nsid - 1];
|
2017-06-15 21:52:40 +00:00
|
|
|
if (bdev == NULL) {
|
|
|
|
response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
|
|
|
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
desc = subsystem->dev.desc[nsid - 1];
|
|
|
|
ch = subsystem->dev.ch[nsid - 1];
|
2016-08-15 01:16:49 +00:00
|
|
|
switch (cmd->opc) {
|
|
|
|
case SPDK_NVME_OPC_READ:
|
|
|
|
case SPDK_NVME_OPC_WRITE:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_rw_cmd(bdev, desc, ch, req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_FLUSH:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_flush_cmd(bdev, desc, ch, req);
|
2016-08-15 01:16:49 +00:00
|
|
|
case SPDK_NVME_OPC_DATASET_MANAGEMENT:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_dsm_cmd(bdev, desc, ch, req);
|
2016-08-15 01:16:49 +00:00
|
|
|
default:
|
2017-06-27 18:26:19 +00:00
|
|
|
return nvmf_bdev_ctrlr_nvme_passthru_io(bdev, desc, ch, req);
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:01:51 +00:00
|
|
|
static int
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_attach(struct spdk_nvmf_subsystem *subsystem)
|
2017-03-03 23:01:51 +00:00
|
|
|
{
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
struct spdk_io_channel *ch;
|
|
|
|
uint32_t i;
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
for (i = 0; i < subsystem->dev.max_nsid; i++) {
|
|
|
|
bdev = subsystem->dev.ns_list[i];
|
2017-06-15 21:52:40 +00:00
|
|
|
if (bdev == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
ch = spdk_bdev_get_io_channel(subsystem->dev.desc[i]);
|
2017-03-03 23:01:51 +00:00
|
|
|
if (ch == NULL) {
|
|
|
|
SPDK_ERRLOG("io_channel allocation failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-06-27 18:26:19 +00:00
|
|
|
subsystem->dev.ch[i] = ch;
|
2017-03-03 23:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-15 01:16:49 +00:00
|
|
|
static void
|
2017-06-27 18:26:19 +00:00
|
|
|
nvmf_bdev_ctrlr_detach(struct spdk_nvmf_subsystem *subsystem)
|
2016-08-15 01:16:49 +00:00
|
|
|
{
|
2017-01-10 16:54:23 +00:00
|
|
|
uint32_t i;
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
for (i = 0; i < subsystem->dev.max_nsid; i++) {
|
|
|
|
if (subsystem->dev.ns_list[i]) {
|
|
|
|
spdk_put_io_channel(subsystem->dev.ch[i]);
|
|
|
|
spdk_bdev_close(subsystem->dev.desc[i]);
|
|
|
|
subsystem->dev.ch[i] = NULL;
|
|
|
|
subsystem->dev.ns_list[i] = NULL;
|
2017-03-02 05:31:48 +00:00
|
|
|
}
|
2017-01-10 16:54:23 +00:00
|
|
|
}
|
2017-06-27 18:26:19 +00:00
|
|
|
subsystem->dev.max_nsid = 0;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
const struct spdk_nvmf_ctrlr_ops spdk_nvmf_bdev_ctrlr_ops = {
|
|
|
|
.attach = nvmf_bdev_ctrlr_attach,
|
|
|
|
.ctrlr_get_data = nvmf_bdev_ctrlr_get_data,
|
|
|
|
.process_admin_cmd = nvmf_bdev_ctrlr_process_admin_cmd,
|
|
|
|
.process_io_cmd = nvmf_bdev_ctrlr_process_io_cmd,
|
|
|
|
.poll_for_completions = nvmf_bdev_ctrlr_poll_for_completions,
|
|
|
|
.detach = nvmf_bdev_ctrlr_detach,
|
2016-08-15 01:16:49 +00:00
|
|
|
};
|