Commit eda91a7b authored by Ben Walker's avatar Ben Walker Committed by Tomasz Zawadzki
Browse files

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: default avatarBen Walker <benjamin.walker@intel.com>
Change-Id: I7de174f3f56d2b3767e723387c4f2257107d8b19
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4581


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent d67119d8
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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().
+1 −1
Original line number Diff line number Diff line
@@ -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
+18 −7
Original line number Diff line number Diff line
@@ -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);