nvmf: Encapsulate spdk_nvmf_host
Hide the definition of spdk_nvmf_host. Add accessors for the necessary data. Change-Id: I28f5b8d243cb1b299724a1dd32fcf2f2bd95e1f9 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/374870 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
0b6b572f7d
commit
45f04c8907
@ -90,10 +90,11 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct nvmf_tgt_subsystem *tg
|
|||||||
spdk_json_write_name(w, "hosts");
|
spdk_json_write_name(w, "hosts");
|
||||||
spdk_json_write_array_begin(w);
|
spdk_json_write_array_begin(w);
|
||||||
|
|
||||||
TAILQ_FOREACH(host, &subsystem->hosts, link) {
|
for (host = spdk_nvmf_subsystem_get_first_host(subsystem); host != NULL;
|
||||||
|
host = spdk_nvmf_subsystem_get_next_host(subsystem, host)) {
|
||||||
spdk_json_write_object_begin(w);
|
spdk_json_write_object_begin(w);
|
||||||
spdk_json_write_name(w, "nqn");
|
spdk_json_write_name(w, "nqn");
|
||||||
spdk_json_write_string(w, host->nqn);
|
spdk_json_write_string(w, spdk_nvmf_host_get_nqn(host));
|
||||||
spdk_json_write_object_end(w);
|
spdk_json_write_object_end(w);
|
||||||
}
|
}
|
||||||
spdk_json_write_array_end(w);
|
spdk_json_write_array_end(w);
|
||||||
|
@ -61,6 +61,7 @@ struct spdk_nvmf_qpair;
|
|||||||
struct spdk_nvmf_request;
|
struct spdk_nvmf_request;
|
||||||
struct spdk_bdev;
|
struct spdk_bdev;
|
||||||
struct spdk_nvmf_request;
|
struct spdk_nvmf_request;
|
||||||
|
struct spdk_nvmf_host;
|
||||||
|
|
||||||
typedef void (*spdk_nvmf_subsystem_connect_fn)(void *cb_ctx, struct spdk_nvmf_request *req);
|
typedef void (*spdk_nvmf_subsystem_connect_fn)(void *cb_ctx, struct spdk_nvmf_request *req);
|
||||||
typedef void (*spdk_nvmf_subsystem_disconnect_fn)(void *cb_ctx, struct spdk_nvmf_qpair *qpair);
|
typedef void (*spdk_nvmf_subsystem_disconnect_fn)(void *cb_ctx, struct spdk_nvmf_qpair *qpair);
|
||||||
@ -70,11 +71,6 @@ struct spdk_nvmf_listen_addr {
|
|||||||
TAILQ_ENTRY(spdk_nvmf_listen_addr) link;
|
TAILQ_ENTRY(spdk_nvmf_listen_addr) link;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spdk_nvmf_host {
|
|
||||||
char *nqn;
|
|
||||||
TAILQ_ENTRY(spdk_nvmf_host) link;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct spdk_nvmf_subsystem_allowed_listener {
|
struct spdk_nvmf_subsystem_allowed_listener {
|
||||||
struct spdk_nvmf_listen_addr *listen_addr;
|
struct spdk_nvmf_listen_addr *listen_addr;
|
||||||
TAILQ_ENTRY(spdk_nvmf_subsystem_allowed_listener) link;
|
TAILQ_ENTRY(spdk_nvmf_subsystem_allowed_listener) link;
|
||||||
@ -134,8 +130,51 @@ void spdk_nvmf_delete_subsystem(struct spdk_nvmf_subsystem *subsystem);
|
|||||||
|
|
||||||
struct spdk_nvmf_subsystem *spdk_nvmf_find_subsystem(const char *subnqn);
|
struct spdk_nvmf_subsystem *spdk_nvmf_find_subsystem(const char *subnqn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow the given host NQN to connect to the given subsystem.
|
||||||
|
*
|
||||||
|
* \param subsystem Subsystem to add host to
|
||||||
|
* \param host_nqn The NQN for the host
|
||||||
|
* \return 0 on success. Negated errno value on failure.
|
||||||
|
*/
|
||||||
|
int spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem,
|
||||||
|
const char *hostnqn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given host is allowed to connect to the subsystem.
|
||||||
|
*
|
||||||
|
* \param subsystem The subsystem to query
|
||||||
|
* \param hostnqn The NQN of the host
|
||||||
|
* \return true if allowed, false if not.
|
||||||
|
*/
|
||||||
bool spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn);
|
bool spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the first allowed host in a subsystem.
|
||||||
|
*
|
||||||
|
* \param subsystem Subsystem to query.
|
||||||
|
* \return First allowed host in this subsystem, or NULL if none allowed.
|
||||||
|
*/
|
||||||
|
struct spdk_nvmf_host *spdk_nvmf_subsystem_get_first_host(struct spdk_nvmf_subsystem *subsystem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next allowed host in a subsystem.
|
||||||
|
*
|
||||||
|
* \param subsystem Subsystem to query.
|
||||||
|
* \param prev_host Previous host returned from this function.
|
||||||
|
* \return Next allowed host in this subsystem, or NULL if prev_host was the last host.
|
||||||
|
*/
|
||||||
|
struct spdk_nvmf_host *spdk_nvmf_subsystem_get_next_host(struct spdk_nvmf_subsystem *subsystem,
|
||||||
|
struct spdk_nvmf_host *prev_host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a host's NQN
|
||||||
|
*
|
||||||
|
* \param host Host to query.
|
||||||
|
* \return NQN of host.
|
||||||
|
*/
|
||||||
|
const char *spdk_nvmf_host_get_nqn(struct spdk_nvmf_host *host);
|
||||||
|
|
||||||
struct spdk_nvmf_listen_addr *spdk_nvmf_tgt_listen(struct spdk_nvme_transport_id *trid);
|
struct spdk_nvmf_listen_addr *spdk_nvmf_tgt_listen(struct spdk_nvme_transport_id *trid);
|
||||||
|
|
||||||
int spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem,
|
int spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem,
|
||||||
@ -144,8 +183,7 @@ int spdk_nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem,
|
|||||||
bool spdk_nvmf_subsystem_listener_allowed(struct spdk_nvmf_subsystem *subsystem,
|
bool spdk_nvmf_subsystem_listener_allowed(struct spdk_nvmf_subsystem *subsystem,
|
||||||
struct spdk_nvmf_listen_addr *listen_addr);
|
struct spdk_nvmf_listen_addr *listen_addr);
|
||||||
|
|
||||||
int spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem,
|
|
||||||
const char *host_nqn);
|
|
||||||
|
|
||||||
void spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem);
|
void spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem);
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ struct spdk_nvmf_tgt {
|
|||||||
TAILQ_HEAD(, spdk_nvmf_transport) transports;
|
TAILQ_HEAD(, spdk_nvmf_transport) transports;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct spdk_nvmf_host {
|
||||||
|
char *nqn;
|
||||||
|
TAILQ_ENTRY(spdk_nvmf_host) link;
|
||||||
|
};
|
||||||
|
|
||||||
struct spdk_nvmf_poll_group {
|
struct spdk_nvmf_poll_group {
|
||||||
struct spdk_nvmf_transport *transport;
|
struct spdk_nvmf_transport *transport;
|
||||||
TAILQ_ENTRY(spdk_nvmf_poll_group) link;
|
TAILQ_ENTRY(spdk_nvmf_poll_group) link;
|
||||||
|
@ -81,29 +81,6 @@ spdk_nvmf_find_subsystem_with_cntlid(uint16_t cntlid)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn)
|
|
||||||
{
|
|
||||||
struct spdk_nvmf_host *host;
|
|
||||||
|
|
||||||
if (!hostnqn) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TAILQ_EMPTY(&subsystem->hosts)) {
|
|
||||||
/* No hosts means any host can connect */
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAILQ_FOREACH(host, &subsystem->hosts, link) {
|
|
||||||
if (strcmp(hostnqn, host->nqn) == 0) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem)
|
spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem)
|
||||||
{
|
{
|
||||||
@ -244,6 +221,75 @@ spdk_nvmf_delete_subsystem(struct spdk_nvmf_subsystem *subsystem)
|
|||||||
free(subsystem);
|
free(subsystem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn)
|
||||||
|
{
|
||||||
|
struct spdk_nvmf_host *host;
|
||||||
|
|
||||||
|
if (!spdk_nvmf_valid_nqn(hostnqn)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
host = calloc(1, sizeof(*host));
|
||||||
|
if (!host) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
host->nqn = strdup(hostnqn);
|
||||||
|
if (!host->nqn) {
|
||||||
|
free(host);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAILQ_INSERT_HEAD(&subsystem->hosts, host, link);
|
||||||
|
g_nvmf_tgt.discovery_genctr++;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn)
|
||||||
|
{
|
||||||
|
struct spdk_nvmf_host *host;
|
||||||
|
|
||||||
|
if (!hostnqn) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TAILQ_EMPTY(&subsystem->hosts)) {
|
||||||
|
/* No hosts means any host can connect */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAILQ_FOREACH(host, &subsystem->hosts, link) {
|
||||||
|
if (strcmp(hostnqn, host->nqn) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct spdk_nvmf_host *
|
||||||
|
spdk_nvmf_subsystem_get_first_host(struct spdk_nvmf_subsystem *subsystem)
|
||||||
|
{
|
||||||
|
return TAILQ_FIRST(&subsystem->hosts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct spdk_nvmf_host *
|
||||||
|
spdk_nvmf_subsystem_get_next_host(struct spdk_nvmf_subsystem *subsystem,
|
||||||
|
struct spdk_nvmf_host *prev_host)
|
||||||
|
{
|
||||||
|
return TAILQ_NEXT(prev_host, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
spdk_nvmf_host_get_nqn(struct spdk_nvmf_host *host)
|
||||||
|
{
|
||||||
|
return host->nqn;
|
||||||
|
}
|
||||||
|
|
||||||
struct spdk_nvmf_listen_addr *
|
struct spdk_nvmf_listen_addr *
|
||||||
spdk_nvmf_tgt_listen(struct spdk_nvme_transport_id *trid)
|
spdk_nvmf_tgt_listen(struct spdk_nvme_transport_id *trid)
|
||||||
{
|
{
|
||||||
@ -326,31 +372,6 @@ spdk_nvmf_subsystem_listener_allowed(struct spdk_nvmf_subsystem *subsystem,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
spdk_nvmf_subsystem_add_host(struct spdk_nvmf_subsystem *subsystem, const char *host_nqn)
|
|
||||||
{
|
|
||||||
struct spdk_nvmf_host *host;
|
|
||||||
|
|
||||||
if (!spdk_nvmf_valid_nqn(host_nqn)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
host = calloc(1, sizeof(*host));
|
|
||||||
if (!host) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
host->nqn = strdup(host_nqn);
|
|
||||||
if (!host->nqn) {
|
|
||||||
free(host);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAILQ_INSERT_HEAD(&subsystem->hosts, host, link);
|
|
||||||
g_nvmf_tgt.discovery_genctr++;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void spdk_nvmf_ctrlr_hot_remove(void *remove_ctx)
|
static void spdk_nvmf_ctrlr_hot_remove(void *remove_ctx)
|
||||||
{
|
{
|
||||||
struct spdk_nvmf_subsystem *subsystem = (struct spdk_nvmf_subsystem *)remove_ctx;
|
struct spdk_nvmf_subsystem *subsystem = (struct spdk_nvmf_subsystem *)remove_ctx;
|
||||||
|
Loading…
Reference in New Issue
Block a user