2016-06-06 14:44:30 -07: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 11:18:25 -07:00
|
|
|
#include "spdk/stdinc.h"
|
2016-06-06 14:44:30 -07:00
|
|
|
|
|
|
|
#include "spdk/conf.h"
|
2016-09-19 10:01:52 -07:00
|
|
|
#include "spdk/nvmf.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
|
2016-11-07 15:10:28 -07:00
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
2016-07-06 10:50:44 -07:00
|
|
|
#include "subsystem.h"
|
2016-07-14 15:25:23 -07:00
|
|
|
#include "transport.h"
|
2016-06-06 14:44:30 -07:00
|
|
|
|
2016-06-07 15:51:23 -07:00
|
|
|
SPDK_LOG_REGISTER_TRACE_FLAG("nvmf", SPDK_TRACE_NVMF)
|
2016-06-06 14:44:30 -07:00
|
|
|
|
|
|
|
#define MAX_SUBSYSTEMS 4
|
|
|
|
|
2017-01-19 11:55:56 -07:00
|
|
|
struct spdk_nvmf_tgt g_nvmf_tgt;
|
2016-06-06 14:44:30 -07:00
|
|
|
|
|
|
|
int
|
2016-10-10 15:05:37 -07:00
|
|
|
spdk_nvmf_tgt_init(uint16_t max_queue_depth, uint16_t max_queues_per_sess,
|
|
|
|
uint32_t in_capsule_data_size, uint32_t max_io_size)
|
2016-06-06 14:44:30 -07:00
|
|
|
{
|
2016-10-19 10:03:45 -07:00
|
|
|
int rc;
|
|
|
|
|
2016-07-18 15:19:55 -07:00
|
|
|
g_nvmf_tgt.max_queues_per_session = max_queues_per_sess;
|
2016-07-21 15:10:09 -07:00
|
|
|
g_nvmf_tgt.max_queue_depth = max_queue_depth;
|
2016-07-25 14:22:58 -07:00
|
|
|
g_nvmf_tgt.in_capsule_data_size = in_capsule_data_size;
|
|
|
|
g_nvmf_tgt.max_io_size = max_io_size;
|
2017-02-17 09:32:09 +08:00
|
|
|
g_nvmf_tgt.discovery_genctr = 0;
|
2017-02-17 09:47:56 +08:00
|
|
|
g_nvmf_tgt.discovery_log_page = NULL;
|
2017-02-17 10:01:34 +08:00
|
|
|
g_nvmf_tgt.discovery_log_page_size = 0;
|
2017-03-03 12:24:16 +08:00
|
|
|
g_nvmf_tgt.current_subsystem_id = 0;
|
2017-02-17 10:01:34 +08:00
|
|
|
TAILQ_INIT(&g_nvmf_tgt.subsystems);
|
2017-02-20 12:49:39 +08:00
|
|
|
TAILQ_INIT(&g_nvmf_tgt.listen_addrs);
|
2016-07-25 14:22:58 -07:00
|
|
|
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max Queues Per Session: %d\n", max_queues_per_sess);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max Queue Depth: %d\n", max_queue_depth);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max In Capsule Data: %d bytes\n", in_capsule_data_size);
|
|
|
|
SPDK_TRACELOG(SPDK_TRACE_NVMF, "Max I/O Size: %d bytes\n", max_io_size);
|
2016-06-06 14:44:30 -07:00
|
|
|
|
2016-10-19 10:03:45 -07:00
|
|
|
rc = spdk_nvmf_transport_init();
|
2017-03-22 15:36:38 -07:00
|
|
|
if (rc < 0) {
|
2016-10-19 10:03:45 -07:00
|
|
|
SPDK_ERRLOG("Transport initialization failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:44:30 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-19 10:03:45 -07:00
|
|
|
int
|
2016-10-10 15:05:37 -07:00
|
|
|
spdk_nvmf_tgt_fini(void)
|
2016-10-19 10:03:45 -07:00
|
|
|
{
|
2017-02-20 12:49:39 +08:00
|
|
|
struct spdk_nvmf_listen_addr *listen_addr, *listen_addr_tmp;
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(listen_addr, &g_nvmf_tgt.listen_addrs, link, listen_addr_tmp) {
|
|
|
|
TAILQ_REMOVE(&g_nvmf_tgt.listen_addrs, listen_addr, link);
|
|
|
|
g_nvmf_tgt.discovery_genctr++;
|
|
|
|
|
|
|
|
spdk_nvmf_listen_addr_destroy(listen_addr);
|
|
|
|
}
|
|
|
|
|
2016-10-10 15:05:37 -07:00
|
|
|
spdk_nvmf_transport_fini();
|
|
|
|
|
|
|
|
return 0;
|
2016-10-19 10:03:45 -07:00
|
|
|
}
|
|
|
|
|
2017-01-19 11:17:16 -07:00
|
|
|
struct spdk_nvmf_listen_addr *
|
2017-02-02 09:44:26 -07:00
|
|
|
spdk_nvmf_listen_addr_create(const char *trname, const char *traddr, const char *trsvcid)
|
2017-01-19 11:17:16 -07:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_listen_addr *listen_addr;
|
|
|
|
const struct spdk_nvmf_transport *transport;
|
|
|
|
|
|
|
|
transport = spdk_nvmf_transport_get(trname);
|
|
|
|
if (!transport) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
listen_addr = calloc(1, sizeof(*listen_addr));
|
|
|
|
if (!listen_addr) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
listen_addr->traddr = strdup(traddr);
|
|
|
|
if (!listen_addr->traddr) {
|
|
|
|
free(listen_addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
listen_addr->trsvcid = strdup(trsvcid);
|
|
|
|
if (!listen_addr->trsvcid) {
|
|
|
|
free(listen_addr->traddr);
|
|
|
|
free(listen_addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
listen_addr->trname = strdup(trname);
|
|
|
|
if (!listen_addr->trname) {
|
|
|
|
free(listen_addr->traddr);
|
|
|
|
free(listen_addr->trsvcid);
|
|
|
|
free(listen_addr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return listen_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_listen_addr_destroy(struct spdk_nvmf_listen_addr *addr)
|
|
|
|
{
|
2017-01-25 19:51:35 +08:00
|
|
|
const struct spdk_nvmf_transport *transport;
|
|
|
|
|
|
|
|
transport = spdk_nvmf_transport_get(addr->trname);
|
|
|
|
assert(transport != NULL);
|
|
|
|
transport->listen_addr_remove(addr);
|
|
|
|
|
2017-02-20 12:52:59 +08:00
|
|
|
spdk_nvmf_listen_addr_cleanup(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_listen_addr_cleanup(struct spdk_nvmf_listen_addr *addr)
|
|
|
|
{
|
2017-01-19 11:17:16 -07:00
|
|
|
free(addr->trname);
|
|
|
|
free(addr->trsvcid);
|
|
|
|
free(addr->traddr);
|
|
|
|
free(addr);
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:44:30 -07:00
|
|
|
SPDK_TRACE_REGISTER_FN(nvmf_trace)
|
|
|
|
{
|
|
|
|
spdk_trace_register_object(OBJECT_NVMF_IO, 'r');
|
|
|
|
spdk_trace_register_description("NVMF_IO_START", "", TRACE_NVMF_IO_START,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 1, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_RDMA_READ_START", "", TRACE_RDMA_READ_START,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_RDMA_WRITE_START", "", TRACE_RDMA_WRITE_START,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_RDMA_READ_COMPLETE", "", TRACE_RDMA_READ_COMPLETE,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_RDMA_WRITE_COMPLETE", "", TRACE_RDMA_WRITE_COMPLETE,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_LIB_READ_START", "", TRACE_NVMF_LIB_READ_START,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_LIB_WRITE_START", "", TRACE_NVMF_LIB_WRITE_START,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_LIB_COMPLETE", "", TRACE_NVMF_LIB_COMPLETE,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
spdk_trace_register_description("NVMF_IO_COMPLETION_DONE", "", TRACE_NVMF_IO_COMPLETE,
|
|
|
|
OWNER_NONE, OBJECT_NVMF_IO, 0, 0, 0, "");
|
|
|
|
}
|