nvmf: remove the data structure spdk_nvmf_subsystem_add_ns_ctx.

Add pointer of subsystem in namespace data structure, then we can remove
the spdk_nvmf_subsystem_add_ns_ctx.

Change-Id: I2d024f10d35fdac64fc34d0cb6523cfca74a8164
Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/391697
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Cunyin Chang 2017-12-14 10:19:57 +08:00 committed by Ben Walker
parent a6bf23e272
commit 0b99cd6f1e
2 changed files with 6 additions and 20 deletions

View File

@ -125,6 +125,7 @@ struct spdk_nvmf_request {
}; };
struct spdk_nvmf_ns { struct spdk_nvmf_ns {
struct spdk_nvmf_subsystem *subsystem;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;
struct spdk_bdev_desc *desc; struct spdk_bdev_desc *desc;
uint32_t id; uint32_t id;

View File

@ -426,29 +426,21 @@ spdk_nvmf_listener_get_trid(struct spdk_nvmf_listener *listener)
return &listener->trid; return &listener->trid;
} }
struct spdk_nvmf_subsystem_add_ns_ctx {
struct spdk_nvmf_subsystem *subsystem;
struct spdk_nvmf_ns *ns;
};
static void static void
spdk_nvmf_subsystem_add_ns_done(struct spdk_io_channel_iter *i, int status) spdk_nvmf_subsystem_add_ns_done(struct spdk_io_channel_iter *i, int status)
{ {
void *ctx = spdk_io_channel_iter_get_ctx(i); return;
free(ctx);
} }
static void static void
spdk_nvmf_subsystem_ns_update_poll_group(struct spdk_io_channel_iter *i) spdk_nvmf_subsystem_ns_update_poll_group(struct spdk_io_channel_iter *i)
{ {
struct spdk_nvmf_subsystem_add_ns_ctx *ctx = spdk_io_channel_iter_get_ctx(i); struct spdk_nvmf_ns *ns = spdk_io_channel_iter_get_ctx(i);
struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i); struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
struct spdk_nvmf_poll_group *group = spdk_io_channel_get_ctx(ch); struct spdk_nvmf_poll_group *group = spdk_io_channel_get_ctx(ch);
int rc; int rc;
rc = spdk_nvmf_poll_group_add_ns(group, ctx->subsystem, ctx->ns); rc = spdk_nvmf_poll_group_add_ns(group, ns->subsystem, ns);
spdk_for_each_channel_continue(i, rc); spdk_for_each_channel_continue(i, rc);
} }
@ -457,7 +449,6 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
uint32_t nsid) uint32_t nsid)
{ {
struct spdk_nvmf_ns *ns; struct spdk_nvmf_ns *ns;
struct spdk_nvmf_subsystem_add_ns_ctx *ctx;
uint32_t i; uint32_t i;
int rc; int rc;
@ -518,6 +509,7 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
memset(ns, 0, sizeof(*ns)); memset(ns, 0, sizeof(*ns));
ns->bdev = bdev; ns->bdev = bdev;
ns->id = nsid; ns->id = nsid;
ns->subsystem = subsystem;
rc = spdk_bdev_open(bdev, true, NULL, NULL, &ns->desc); rc = spdk_bdev_open(bdev, true, NULL, NULL, &ns->desc);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Subsystem %s: bdev %s cannot be opened, error=%d\n", SPDK_ERRLOG("Subsystem %s: bdev %s cannot be opened, error=%d\n",
@ -534,13 +526,6 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
subsystem->max_nsid = spdk_max(subsystem->max_nsid, nsid); subsystem->max_nsid = spdk_max(subsystem->max_nsid, nsid);
subsystem->num_allocated_nsid++; subsystem->num_allocated_nsid++;
ctx = calloc(1, sizeof(*ctx));
if (!ctx) {
return -ENOMEM;
}
ctx->subsystem = subsystem;
ctx->ns = ns;
/* Send a message to each poll group to notify it that a new namespace /* Send a message to each poll group to notify it that a new namespace
* is available. * is available.
* TODO: This call does not currently allow the user to wait for these * TODO: This call does not currently allow the user to wait for these
@ -549,7 +534,7 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
*/ */
spdk_for_each_channel(subsystem->tgt, spdk_for_each_channel(subsystem->tgt,
spdk_nvmf_subsystem_ns_update_poll_group, spdk_nvmf_subsystem_ns_update_poll_group,
ctx, ns,
spdk_nvmf_subsystem_add_ns_done); spdk_nvmf_subsystem_add_ns_done);
return nsid; return nsid;