Commit dca0da83 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

nvmf: disallow adding the same host to a subsystem many times



We used to allow adding the same host to the same subsystem many times.
However, this can cause issues, as we didn't check transport-specific
host options (e.g. TLS PSK), so adding the same host with different
transport options would succeed, which is obviously incorrect.

We could fix it by comparing host's options and ensuring they're the
same, but it's easier to simply disallow it altogether.  It's also
consistent with the behavior of other RPCs.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I1a60329100f5a3256c5ccc09db0586e7a023b6e5
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22896


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJacek Kalwas <jacek.kalwas@intel.com>
Community-CI: Mellanox Build Bot
parent f09c7da5
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -8520,7 +8520,8 @@ Example response:

### nvmf_subsystem_add_host method {#rpc_nvmf_subsystem_add_host}

Add a host NQN to the list of allowed hosts.
Add a host NQN to the list of allowed hosts.  Adding an already allowed host will result in an
error.

#### Parameters

+2 −1
Original line number Diff line number Diff line
@@ -602,7 +602,8 @@ int spdk_nvmf_ns_remove_host(struct spdk_nvmf_subsystem *subsystem,
			     uint32_t flags);

/**
 * Allow the given host NQN to connect to the given subsystem.
 * Allow the given host NQN to connect to the given subsystem.  Adding a host that's already allowed
 * results in an error.
 *
 * \param subsystem Subsystem to add host to.
 * \param hostnqn The NQN for the host.
+1 −1
Original line number Diff line number Diff line
@@ -993,7 +993,7 @@ spdk_nvmf_subsystem_add_host_ext(struct spdk_nvmf_subsystem *subsystem,
	if (nvmf_subsystem_find_host(subsystem, hostnqn)) {
		/* This subsystem already allows the specified host. */
		pthread_mutex_unlock(&subsystem->mutex);
		return 0;
		return -EINVAL;
	}

	host = calloc(1, sizeof(*host));
+2 −2
Original line number Diff line number Diff line
@@ -1784,9 +1784,9 @@ test_spdk_nvmf_subsystem_add_host(void)
	CU_ASSERT(rc == 0);
	CU_ASSERT(!TAILQ_EMPTY(&subsystem->hosts));

	/* Add existing nqn, this function is allowed to be called if the nqn was previously added. */
	/* Add existing nqn, this function isn't allowed to be called if the nqn was previously added. */
	rc = spdk_nvmf_subsystem_add_host(subsystem, hostnqn, NULL);
	CU_ASSERT(rc == 0);
	CU_ASSERT(rc == -EINVAL);

	rc = spdk_nvmf_subsystem_remove_host(subsystem, hostnqn);
	CU_ASSERT(rc == 0);