From eaaddf3d48535b5d5e9185b94172e05ee7a08527 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 17 Nov 2017 11:31:29 -0700 Subject: [PATCH] nvmf: Poll groups now automatically register pollers This simplifies the public API and requirements for user applications. Change-Id: Ibb0d25a7838a0fa683f39e79cb4fef78adf6aee8 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/388040 Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System --- app/nvmf_tgt/nvmf_tgt.c | 22 ----------- include/spdk/nvmf.h | 8 ---- lib/nvmf/ctrlr.c | 6 --- lib/nvmf/nvmf.c | 38 +++++++++---------- lib/nvmf/nvmf_internal.h | 4 +- lib/nvmf/subsystem.c | 11 ------ test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c | 6 --- .../ctrlr_discovery.c/ctrlr_discovery_ut.c | 6 --- test/unit/lib/nvmf/subsystem.c/subsystem_ut.c | 6 --- 9 files changed, 21 insertions(+), 86 deletions(-) diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index 5d277c2d6a..fefd160a79 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -44,7 +44,6 @@ struct nvmf_tgt_poll_group { struct spdk_nvmf_poll_group *group; - struct spdk_poller *poller; }; struct nvmf_tgt g_tgt = {}; @@ -111,14 +110,6 @@ spdk_nvmf_shutdown_cb(void) nvmf_tgt_advance_state(NULL, NULL); } -static void -subsystem_poll(void *arg) -{ - struct nvmf_tgt_subsystem *app_subsys = arg; - - spdk_nvmf_subsystem_poll(app_subsys->subsystem); -} - static void _nvmf_tgt_start_subsystem(void *arg1, void *arg2) { @@ -126,8 +117,6 @@ _nvmf_tgt_start_subsystem(void *arg1, void *arg2) struct spdk_nvmf_subsystem *subsystem = app_subsys->subsystem; spdk_nvmf_subsystem_start(subsystem); - - app_subsys->poller = spdk_poller_register(subsystem_poll, app_subsys, 0); } void @@ -210,14 +199,6 @@ acceptor_poll(void *arg) spdk_nvmf_tgt_accept(tgt); } -static void -nvmf_tgt_poll_group_poll(void *arg) -{ - struct nvmf_tgt_poll_group *app_poll_group = arg; - - spdk_nvmf_poll_group_poll(app_poll_group->group); -} - static void nvmf_tgt_destroy_poll_group_done(void *arg1, void *arg2) { @@ -236,8 +217,6 @@ nvmf_tgt_destroy_poll_group(void *arg1, void *arg2) pg = &g_poll_groups[g_tgt.core]; assert(pg != NULL); - spdk_poller_unregister(&pg->poller); - spdk_nvmf_poll_group_destroy(pg->group); pg->group = NULL; @@ -276,7 +255,6 @@ nvmf_tgt_create_poll_group(void *arg1, void *arg2) SPDK_ERRLOG("Failed to create poll group for core %u\n", g_tgt.core); } - pg->poller = spdk_poller_register(nvmf_tgt_poll_group_poll, pg, 0); g_active_poll_groups++; spdk_event_call(event); diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index 95e8b25d01..5532c1d9b7 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -111,11 +111,6 @@ struct spdk_nvmf_poll_group *spdk_nvmf_poll_group_create(struct spdk_nvmf_tgt *t */ void spdk_nvmf_poll_group_destroy(struct spdk_nvmf_poll_group *group); -/** - * Check a poll group for work completions. - */ -int spdk_nvmf_poll_group_poll(struct spdk_nvmf_poll_group *group); - /* * The NVMf subsystem, as indicated in the specification, is a collection * of controllers. Any individual controller has @@ -254,9 +249,6 @@ struct spdk_nvmf_listener *spdk_nvmf_subsystem_get_next_listener( const struct spdk_nvme_transport_id *spdk_nvmf_listener_get_trid( struct spdk_nvmf_listener *listener); - -void spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem); - /** * Add a namespace to a subsytem. * diff --git a/lib/nvmf/ctrlr.c b/lib/nvmf/ctrlr.c index 11d7c904c5..18675e75c8 100644 --- a/lib/nvmf/ctrlr.c +++ b/lib/nvmf/ctrlr.c @@ -589,12 +589,6 @@ spdk_nvmf_property_set(struct spdk_nvmf_request *req) return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE; } -int -spdk_nvmf_ctrlr_poll(struct spdk_nvmf_ctrlr *ctrlr) -{ - return spdk_nvmf_poll_group_poll(ctrlr->group); -} - static int spdk_nvmf_ctrlr_set_features_host_identifier(struct spdk_nvmf_request *req) { diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index aa5b6fc20d..3473f73c92 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -199,6 +199,21 @@ spdk_nvmf_tgt_accept(struct spdk_nvmf_tgt *tgt) } } +static void +spdk_nvmf_poll_group_poll(void *ctx) +{ + struct spdk_nvmf_poll_group *group = ctx; + int rc; + struct spdk_nvmf_transport_poll_group *tgroup; + + TAILQ_FOREACH(tgroup, &group->tgroups, link) { + rc = spdk_nvmf_transport_poll_group_poll(tgroup); + if (rc < 0) { + return; + } + } +} + struct spdk_nvmf_poll_group * spdk_nvmf_poll_group_create(struct spdk_nvmf_tgt *tgt) { @@ -223,6 +238,8 @@ spdk_nvmf_poll_group_create(struct spdk_nvmf_tgt *tgt) TAILQ_INSERT_TAIL(&group->tgroups, tgroup, link); } + group->poller = spdk_poller_register(spdk_nvmf_poll_group_poll, group, 0); + return group; } @@ -231,6 +248,8 @@ spdk_nvmf_poll_group_destroy(struct spdk_nvmf_poll_group *group) { struct spdk_nvmf_transport_poll_group *tgroup, *tmp; + spdk_poller_unregister(&group->poller); + TAILQ_FOREACH_SAFE(tgroup, &group->tgroups, link, tmp) { TAILQ_REMOVE(&group->tgroups, tgroup, link); spdk_nvmf_transport_poll_group_destroy(tgroup); @@ -273,25 +292,6 @@ spdk_nvmf_poll_group_remove(struct spdk_nvmf_poll_group *group, return rc; } -int -spdk_nvmf_poll_group_poll(struct spdk_nvmf_poll_group *group) -{ - int rc; - int count = 0; - struct spdk_nvmf_transport_poll_group *tgroup; - - TAILQ_FOREACH(tgroup, &group->tgroups, link) { - rc = spdk_nvmf_transport_poll_group_poll(tgroup); - if (rc < 0) { - return rc; - } - count += rc; - break; - } - - return count; -} - SPDK_TRACE_REGISTER_FN(nvmf_trace) { spdk_trace_register_object(OBJECT_NVMF_IO, 'r'); diff --git a/lib/nvmf/nvmf_internal.h b/lib/nvmf/nvmf_internal.h index b9afd6391f..c034dfa1b0 100644 --- a/lib/nvmf/nvmf_internal.h +++ b/lib/nvmf/nvmf_internal.h @@ -78,7 +78,8 @@ struct spdk_nvmf_transport_poll_group { }; struct spdk_nvmf_poll_group { - TAILQ_HEAD(, spdk_nvmf_transport_poll_group) tgroups; + struct spdk_poller *poller; + TAILQ_HEAD(, spdk_nvmf_transport_poll_group) tgroups; }; typedef enum _spdk_nvmf_request_exec_status { @@ -214,7 +215,6 @@ void spdk_nvmf_get_discovery_log_page(struct spdk_nvmf_tgt *tgt, uint32_t length); struct spdk_nvmf_qpair *spdk_nvmf_ctrlr_get_qpair(struct spdk_nvmf_ctrlr *ctrlr, uint16_t qid); -int spdk_nvmf_ctrlr_poll(struct spdk_nvmf_ctrlr *ctrlr); void spdk_nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr); int spdk_nvmf_ctrlr_process_fabrics_cmd(struct spdk_nvmf_request *req); int spdk_nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req); diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 14a2bb0c5b..96aac1142e 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -50,17 +50,6 @@ spdk_nvmf_subsystem_start(struct spdk_nvmf_subsystem *subsystem) return spdk_nvmf_subsystem_bdev_attach(subsystem); } -void -spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem) -{ - struct spdk_nvmf_ctrlr *ctrlr; - - TAILQ_FOREACH(ctrlr, &subsystem->ctrlrs, link) { - /* For each connection in the ctrlr, check for completions */ - spdk_nvmf_ctrlr_poll(ctrlr); - } -} - static bool spdk_nvmf_valid_nqn(const char *nqn) { diff --git a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c index f6af9cbb65..af7cb9b993 100644 --- a/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c +++ b/test/unit/lib/nvmf/ctrlr.c/ctrlr_ut.c @@ -81,12 +81,6 @@ spdk_nvmf_poll_group_remove(struct spdk_nvmf_poll_group *group, return 0; } -int -spdk_nvmf_poll_group_poll(struct spdk_nvmf_poll_group *group) -{ - return 0; -} - const char * spdk_nvmf_subsystem_get_sn(const struct spdk_nvmf_subsystem *subsystem) { diff --git a/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c b/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c index d277d5a77a..e2da02c350 100644 --- a/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c +++ b/test/unit/lib/nvmf/ctrlr_discovery.c/ctrlr_discovery_ut.c @@ -122,12 +122,6 @@ spdk_nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr) { } -int -spdk_nvmf_ctrlr_poll(struct spdk_nvmf_ctrlr *ctrlr) -{ - return -1; -} - int spdk_nvmf_subsystem_bdev_attach(struct spdk_nvmf_subsystem *subsystem) { diff --git a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c index 2d8dc5dfb8..321ff15a31 100644 --- a/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c +++ b/test/unit/lib/nvmf/subsystem.c/subsystem_ut.c @@ -142,12 +142,6 @@ spdk_nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr) { } -int -spdk_nvmf_ctrlr_poll(struct spdk_nvmf_ctrlr *ctrlr) -{ - return -1; -} - int spdk_bdev_open(struct spdk_bdev *bdev, bool write, spdk_bdev_remove_cb_t remove_cb, void *remove_ctx, struct spdk_bdev_desc **desc)