Commit 779059a2 authored by Jim Harris's avatar Jim Harris Committed by Konrad Sztyber
Browse files

nvmf: use spdk_bit_array to track subsystem ids



Currently the subsystem id (sid) is just the index
of the subsystem pointer into the target's subsystems
pointer array.  But this array is going away in
upcoming patches, while we still need subsystem ids
for things like subsystem poll groups.

So transition to that end scenario by introducing
an spdk_bit_array to track the subsystem ids.  So
now we will look for a free bit to get a free
sid, and then put the subsystem pointer into that
index in the target's subsystems array.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I0f01dfdec6f22c4937df63e50e05650a17c82fe1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17965


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
parent a2653a72
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -312,8 +312,15 @@ spdk_nvmf_tgt_create(struct spdk_nvmf_target_opts *opts)
	TAILQ_INIT(&tgt->poll_groups);
	tgt->num_poll_groups = 0;

	tgt->subsystem_ids = spdk_bit_array_create(tgt->max_subsystems);
	if (tgt->subsystem_ids == NULL) {
		free(tgt);
		return NULL;
	}

	tgt->subsystems = calloc(tgt->max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	if (!tgt->subsystems) {
		spdk_bit_array_free(&tgt->subsystem_ids);
		free(tgt);
		return NULL;
	}
@@ -390,6 +397,7 @@ nvmf_tgt_destroy_cb(void *io_device)
		}
	}
	free(tgt->subsystems);
	spdk_bit_array_free(&tgt->subsystem_ids);
	_nvmf_tgt_destroy_next_transport(tgt);
}

+2 −0
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ struct spdk_nvmf_tgt {

	enum spdk_nvmf_tgt_state                state;

	struct spdk_bit_array			*subsystem_ids;

	/* Array of subsystem pointers of size max_subsystems indexed by sid */
	struct spdk_nvmf_subsystem		**subsystems;

+5 −7
Original line number Diff line number Diff line
@@ -243,15 +243,10 @@ spdk_nvmf_subsystem_create(struct spdk_nvmf_tgt *tgt,
	}

	/* Find a free subsystem id (sid) */
	for (sid = 0; sid < tgt->max_subsystems; sid++) {
		if (tgt->subsystems[sid] == NULL) {
			break;
		}
	}
	if (sid >= tgt->max_subsystems) {
	sid = spdk_bit_array_find_first_clear(tgt->subsystem_ids, 0);
	if (sid == UINT32_MAX) {
		return NULL;
	}

	subsystem = calloc(1, sizeof(struct spdk_nvmf_subsystem));
	if (subsystem == NULL) {
		return NULL;
@@ -304,6 +299,7 @@ spdk_nvmf_subsystem_create(struct spdk_nvmf_tgt *tgt,
	snprintf(subsystem->mn, sizeof(subsystem->mn), "%s",
		 MODEL_NUMBER_DEFAULT);

	spdk_bit_array_set(tgt->subsystem_ids, sid);
	tgt->subsystems[sid] = subsystem;

	SPDK_DTRACE_PROBE1(nvmf_subsystem_create, subsystem->subnqn);
@@ -387,6 +383,8 @@ _nvmf_subsystem_destroy(struct spdk_nvmf_subsystem *subsystem)
	free(subsystem->ana_group);

	subsystem->tgt->subsystems[subsystem->id] = NULL;
	assert(spdk_bit_array_get(subsystem->tgt->subsystem_ids, subsystem->id) == true);
	spdk_bit_array_clear(subsystem->tgt->subsystem_ids, subsystem->id);

	pthread_mutex_destroy(&subsystem->mutex);

+4 −0
Original line number Diff line number Diff line
@@ -284,6 +284,7 @@ test_discovery_log(void)
	iov.iov_len = 8192;

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -374,6 +375,7 @@ test_discovery_log(void)
	CU_ASSERT(disc_log->numrec == 0);

	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

static void
@@ -417,6 +419,7 @@ test_discovery_log_with_filters(void)
	iov.iov_len = 8192;

	tgt.max_subsystems = 4;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -639,6 +642,7 @@ test_discovery_log_with_filters(void)
	subsystem->state = SPDK_NVMF_SUBSYSTEM_INACTIVE;
	spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

int
+10 −0
Original line number Diff line number Diff line
@@ -335,6 +335,7 @@ nvmf_test_create_subsystem(void)
	int rc;

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -457,6 +458,7 @@ nvmf_test_create_subsystem(void)
	SPDK_CU_ASSERT_FATAL(subsystem == NULL);

	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

static void
@@ -1347,6 +1349,7 @@ test_spdk_nvmf_ns_event(void)
	SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -1403,6 +1406,7 @@ test_spdk_nvmf_ns_event(void)
	free(subsystem.ns);
	free(subsystem.ana_group);
	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

static void
@@ -1444,6 +1448,7 @@ test_nvmf_subsystem_add_ctrlr(void)
	struct spdk_nvmf_subsystem *subsystem = NULL;

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -1463,6 +1468,7 @@ test_nvmf_subsystem_add_ctrlr(void)
	rc = spdk_nvmf_subsystem_destroy(subsystem, test_nvmf_subsystem_destroy_cb, NULL);
	CU_ASSERT(rc == 0);
	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

static void
@@ -1475,6 +1481,7 @@ test_spdk_nvmf_subsystem_add_host(void)
	const char subsystemnqn[] = "nqn.2016-06.io.spdk:subsystem1";

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -1500,6 +1507,7 @@ test_spdk_nvmf_subsystem_add_host(void)

	spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

static void
@@ -1711,6 +1719,7 @@ test_nvmf_subsystem_state_change(void)
	int rc;

	tgt.max_subsystems = 1024;
	tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
	tgt.subsystems = calloc(tgt.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
	SPDK_CU_ASSERT_FATAL(tgt.subsystems != NULL);

@@ -1761,6 +1770,7 @@ test_nvmf_subsystem_state_change(void)
	poll_threads();

	free(tgt.subsystems);
	spdk_bit_array_free(&tgt.subsystem_ids);
}

int