Skip to content

Commit e76c814

Browse files
author
root
committed
change ns list on ctrlr thread
1 parent 0f34c83 commit e76c814

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

lib/nvmf/subsystem.c

+39-9
Original file line numberDiff line numberDiff line change
@@ -1670,14 +1670,31 @@ struct subsystem_ns_change_ctx_v2 {
16701670
struct spdk_nvmf_ctrlr *ctrlr;
16711671
// spdk_nvmf_subsystem_state_change_done cb_fn;
16721672
// uint32_t nsid;
1673+
struct spdk_nvmf_subsystem *subsystem;
1674+
bool last_one;
1675+
struct spdk_thread *thread;
16731676
};
16741677

16751678

1679+
static void
1680+
nvmf_subsystem_ns_changed_v3(void *cb_arg)
1681+
{
1682+
struct spdk_nvmf_subsystem *subsystem = cb_arg;
1683+
SPDK_NOTICELOG("Running the subsystem.\n");
1684+
if (spdk_nvmf_subsystem_resume(subsystem, NULL, NULL) != 0) {
1685+
SPDK_ERRLOG("Failed to resume NVME-oF subsystem with id: %u\n", subsystem->id);
1686+
}
1687+
}
1688+
16761689
static void
16771690
nvmf_subsystem_ns_changed_v2(void *cb_arg)
16781691
{
16791692
struct subsystem_ns_change_ctx_v2 *ctx = cb_arg;
16801693
nvmf_ctrlr_ns_changed(ctx->ctrlr, ctx->nsid);
1694+
if (ctx->last_one) {
1695+
SPDK_NOTICELOG("changing the ns list namespace: %d done.\n", ctx->nsid);
1696+
spdk_thread_send_msg(ctx->thread, nvmf_subsystem_ns_changed_v3, ctx->subsystem);
1697+
}
16811698
free(ctx);
16821699
}
16831700

@@ -1686,14 +1703,31 @@ nvmf_subsystem_ns_changed(struct spdk_nvmf_subsystem *subsystem, uint32_t nsid)
16861703
{
16871704
struct spdk_nvmf_ctrlr *ctrlr;
16881705
struct subsystem_ns_change_ctx_v2 *ctx;
1689-
ctx = calloc(1, sizeof(struct subsystem_ns_change_ctx_v2));
1706+
int count = 0;
1707+
ctx = calloc(subsystem->max_cntlid, sizeof(struct subsystem_ns_change_ctx_v2));
1708+
if (!ctx) {
1709+
SPDK_ERRLOG("Cannot allocate memory for chnaging the ns list.\n");
1710+
if (spdk_nvmf_subsystem_resume(subsystem, NULL, NULL) != 0) {
1711+
SPDK_ERRLOG("Failed to resume NVME-oF subsystem with id: %u\n", subsystem->id);
1712+
}
1713+
return;
1714+
}
16901715
TAILQ_FOREACH(ctrlr, &subsystem->ctrlrs, link) {
16911716
if (nvmf_ctrlr_ns_is_visible(ctrlr, nsid)) {
1692-
ctx->nsid = nsid;
1693-
ctx->ctrlr = ctrlr;
1694-
spdk_thread_send_msg(ctrlr->thread, nvmf_subsystem_ns_changed_v2, ctx);
1717+
ctx[count].nsid = nsid;
1718+
ctx[count].ctrlr = ctrlr;
1719+
ctx[count].subsystem = subsystem;
1720+
ctx[count].thread = spdk_get_thread();
1721+
count++;
16951722
// nvmf_ctrlr_ns_changed(ctrlr, nsid);
1723+
}
1724+
}
1725+
1726+
for (int i = 0; i < count; i++) {
1727+
if ( i == count -1) {
1728+
ctx[i].last_one = true;
16961729
}
1730+
spdk_thread_send_msg(ctx[i].ctrlr->thread, nvmf_subsystem_ns_changed_v2, &ctx[i]);
16971731
}
16981732
}
16991733

@@ -1843,13 +1877,9 @@ static void
18431877
_nvmf_ns_resize(struct spdk_nvmf_subsystem *subsystem, void *cb_arg, int status)
18441878
{
18451879
struct subsystem_ns_change_ctx *ctx = cb_arg;
1846-
SPDK_NOTICELOG("starting to change the ns list.\n");
1880+
SPDK_NOTICELOG("starting to change the ns list namespace: %d.\n", ctx->nsid);
18471881
nvmf_subsystem_ns_changed(subsystem, ctx->nsid);
18481882
SPDK_NOTICELOG("ns list changed and resume the subsystem.\n");
1849-
if (spdk_nvmf_subsystem_resume(subsystem, NULL, NULL) != 0) {
1850-
SPDK_ERRLOG("Failed to resume NVME-oF subsystem with id: %u\n", subsystem->id);
1851-
}
1852-
18531883
free(ctx);
18541884
}
18551885

0 commit comments

Comments
 (0)