2017-03-14 21:11:05 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NVMe over Fabrics discovery service
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2017-03-14 21:11:05 +00:00
|
|
|
|
|
|
|
#include "nvmf_internal.h"
|
|
|
|
#include "transport.h"
|
|
|
|
|
|
|
|
#include "spdk/string.h"
|
|
|
|
#include "spdk/trace.h"
|
|
|
|
#include "spdk/nvmf_spec.h"
|
|
|
|
|
|
|
|
#include "spdk_internal/bdev.h"
|
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
|
|
|
static void
|
2017-08-21 20:58:04 +00:00
|
|
|
nvmf_update_discovery_log(struct spdk_nvmf_tgt *tgt)
|
2017-03-14 21:11:05 +00:00
|
|
|
{
|
|
|
|
uint64_t numrec = 0;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2017-08-18 21:43:15 +00:00
|
|
|
struct spdk_nvmf_listener *listener;
|
2017-03-14 21:11:05 +00:00
|
|
|
struct spdk_nvmf_discovery_log_page_entry *entry;
|
|
|
|
struct spdk_nvmf_discovery_log_page *disc_log;
|
|
|
|
size_t cur_size;
|
|
|
|
|
2017-08-25 20:37:02 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_TRACE_NVMF, "Generating log page for genctr %" PRIu64 "\n",
|
2017-08-21 20:58:04 +00:00
|
|
|
tgt->discovery_genctr);
|
2017-03-14 21:11:05 +00:00
|
|
|
|
|
|
|
cur_size = sizeof(struct spdk_nvmf_discovery_log_page);
|
|
|
|
disc_log = calloc(1, cur_size);
|
|
|
|
if (disc_log == NULL) {
|
|
|
|
SPDK_ERRLOG("Discovery log page memory allocation error\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-21 20:58:04 +00:00
|
|
|
TAILQ_FOREACH(subsystem, &tgt->subsystems, entries) {
|
2017-03-14 21:11:05 +00:00
|
|
|
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-18 21:43:15 +00:00
|
|
|
for (listener = spdk_nvmf_subsystem_get_first_listener(subsystem); listener != NULL;
|
|
|
|
listener = spdk_nvmf_subsystem_get_next_listener(subsystem, listener)) {
|
2017-03-14 21:11:05 +00:00
|
|
|
size_t new_size = cur_size + sizeof(*entry);
|
|
|
|
void *new_log_page = realloc(disc_log, new_size);
|
|
|
|
|
|
|
|
if (new_log_page == NULL) {
|
|
|
|
SPDK_ERRLOG("Discovery log page memory allocation error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
disc_log = new_log_page;
|
|
|
|
cur_size = new_size;
|
|
|
|
|
|
|
|
entry = &disc_log->entries[numrec];
|
|
|
|
memset(entry, 0, sizeof(*entry));
|
|
|
|
entry->portid = numrec;
|
|
|
|
entry->cntlid = 0xffff;
|
2017-08-21 20:58:04 +00:00
|
|
|
entry->asqsz = tgt->opts.max_queue_depth;
|
2017-03-14 21:11:05 +00:00
|
|
|
entry->subtype = subsystem->subtype;
|
|
|
|
snprintf(entry->subnqn, sizeof(entry->subnqn), "%s", subsystem->subnqn);
|
|
|
|
|
2017-09-11 20:35:39 +00:00
|
|
|
spdk_nvmf_transport_listener_discover(listener->transport, &listener->trid, entry);
|
2017-03-14 21:11:05 +00:00
|
|
|
|
|
|
|
numrec++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
disc_log->numrec = numrec;
|
2017-08-21 20:58:04 +00:00
|
|
|
disc_log->genctr = tgt->discovery_genctr;
|
2017-03-14 21:11:05 +00:00
|
|
|
|
2017-08-21 20:58:04 +00:00
|
|
|
free(tgt->discovery_log_page);
|
2017-03-14 21:11:05 +00:00
|
|
|
|
2017-08-21 20:58:04 +00:00
|
|
|
tgt->discovery_log_page = disc_log;
|
|
|
|
tgt->discovery_log_page_size = cur_size;
|
2017-03-14 21:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-21 20:58:04 +00:00
|
|
|
spdk_nvmf_get_discovery_log_page(struct spdk_nvmf_tgt *tgt, void *buffer,
|
|
|
|
uint64_t offset, uint32_t length)
|
2017-03-14 21:11:05 +00:00
|
|
|
{
|
|
|
|
size_t copy_len = 0;
|
|
|
|
size_t zero_len = length;
|
|
|
|
|
2017-08-21 20:58:04 +00:00
|
|
|
if (tgt->discovery_log_page == NULL ||
|
|
|
|
tgt->discovery_log_page->genctr != tgt->discovery_genctr) {
|
|
|
|
nvmf_update_discovery_log(tgt);
|
2017-03-14 21:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the valid part of the discovery log page, if any */
|
2017-08-21 20:58:04 +00:00
|
|
|
if (tgt->discovery_log_page && offset < tgt->discovery_log_page_size) {
|
|
|
|
copy_len = spdk_min(tgt->discovery_log_page_size - offset, length);
|
2017-03-14 21:11:05 +00:00
|
|
|
zero_len -= copy_len;
|
2017-08-21 20:58:04 +00:00
|
|
|
memcpy(buffer, (char *)tgt->discovery_log_page + offset, copy_len);
|
2017-03-14 21:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Zero out the rest of the buffer */
|
|
|
|
if (zero_len) {
|
|
|
|
memset((char *)buffer + copy_len, 0, zero_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should have copied or zeroed every byte of the output buffer. */
|
|
|
|
assert(copy_len + zero_len == length);
|
|
|
|
}
|