nvmf: Getting or setting the allow_any_host parameter no longer requires

a pause

This now also takes a lock instead of requiring a pause of the whole
subsystem.

Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Change-Id: I7de174f3f56d2b3767e723387c4f2257107d8b19
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4581
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Ben Walker 2020-10-08 10:28:43 -07:00 committed by Tomasz Zawadzki
parent d67119d8bd
commit eda91a7b07
3 changed files with 19 additions and 10 deletions

View File

@ -487,8 +487,6 @@ int spdk_nvmf_subsystem_remove_host(struct spdk_nvmf_subsystem *subsystem, const
/**
* Set whether a subsystem should allow any host or only hosts in the allowed list.
*
* May only be performed on subsystems in the PAUSED or INACTIVE states.
*
* \param subsystem Subsystem to modify.
* \param allow_any_host true to allow any host to connect to this subsystem,
* or false to enforce the whitelist configured with spdk_nvmf_subsystem_add_host().

View File

@ -275,7 +275,7 @@ struct spdk_nvmf_subsystem {
TAILQ_HEAD(, spdk_nvmf_ctrlr) ctrlrs;
/* A mutex used to protect the hosts list. Unlike the namespace
/* A mutex used to protect the hosts list and allow_any_host flag. Unlike the namespace
* array, this list is not used on the I/O path (it's needed for handling things like
* the CONNECT command), so use a mutex to protect it instead of requiring the subsystem
* state to be paused. This removes the requirement to pause the subsystem when hosts

View File

@ -763,12 +763,9 @@ spdk_nvmf_subsystem_remove_host(struct spdk_nvmf_subsystem *subsystem, const cha
int
spdk_nvmf_subsystem_set_allow_any_host(struct spdk_nvmf_subsystem *subsystem, bool allow_any_host)
{
if (!(subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE ||
subsystem->state == SPDK_NVMF_SUBSYSTEM_PAUSED)) {
return -EAGAIN;
}
pthread_mutex_lock(&subsystem->mutex);
subsystem->flags.allow_any_host = allow_any_host;
pthread_mutex_unlock(&subsystem->mutex);
return 0;
}
@ -776,7 +773,19 @@ spdk_nvmf_subsystem_set_allow_any_host(struct spdk_nvmf_subsystem *subsystem, bo
bool
spdk_nvmf_subsystem_get_allow_any_host(const struct spdk_nvmf_subsystem *subsystem)
{
return subsystem->flags.allow_any_host;
bool allow_any_host;
struct spdk_nvmf_subsystem *sub;
/* Technically, taking the mutex modifies data in the subsystem. But the const
* is still important to convey that this doesn't mutate any other data. Cast
* it away to work around this. */
sub = (struct spdk_nvmf_subsystem *)subsystem;
pthread_mutex_lock(&sub->mutex);
allow_any_host = sub->flags.allow_any_host;
pthread_mutex_unlock(&sub->mutex);
return allow_any_host;
}
bool
@ -788,11 +797,13 @@ spdk_nvmf_subsystem_host_allowed(struct spdk_nvmf_subsystem *subsystem, const ch
return false;
}
pthread_mutex_lock(&subsystem->mutex);
if (subsystem->flags.allow_any_host) {
pthread_mutex_unlock(&subsystem->mutex);
return true;
}
pthread_mutex_lock(&subsystem->mutex);
allowed = nvmf_subsystem_find_host(subsystem, hostnqn) != NULL;
pthread_mutex_unlock(&subsystem->mutex);