From 9c35e39c546166c1f714f3634160660143d1b0f9 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 14 Nov 2017 13:42:17 -0700 Subject: [PATCH] event: Move spdk_poller_register to io_channel Make this generic and not directly dependent on the event framework. That way our libraries can register pollers without adding a dependency. Change-Id: I7ad7a7ddc131596ca1791a7b0f43dabfda050f5f Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/387690 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Dariusz Stojaczyk Reviewed-by: Daniel Verkamp --- CHANGELOG.md | 7 + app/nvmf_tgt/nvmf_tgt.c | 9 +- examples/bdev/fio_plugin/fio_plugin.c | 42 +++-- include/spdk/event.h | 15 -- include/spdk/io_channel.h | 32 +++- lib/copy/ioat/copy_engine_ioat.c | 2 +- lib/event/reactor.c | 178 ++++++++---------- lib/event/rpc.c | 4 +- lib/event/subsystems/bdev/bdev.c | 6 +- lib/iscsi/acceptor.c | 4 +- lib/iscsi/conn.c | 19 +- lib/rocksdb/env_spdk.cc | 3 +- lib/scsi/lun.c | 2 +- lib/util/io_channel.c | 58 +++++- lib/vhost/vhost_blk.c | 10 +- lib/vhost/vhost_scsi.c | 9 +- test/lib/bdev/bdevperf/bdevperf.c | 15 +- test/lib/bdev/nbd/nbd.c | 3 +- .../blobfs/blobfs_async_ut/blobfs_async_ut.c | 14 +- .../blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 12 +- test/lib/event/reactor/reactor.c | 35 ++-- test/lib/event/reactor_perf/reactor_perf.c | 5 +- test/lib/ut_multithread.c | 2 +- test/unit/lib/blob/blob.c/blob_ut.c | 2 +- test/unit/lib/lvol/lvol.c/lvol_ut.c | 32 ++-- test/unit/lib/scsi/lun.c/lun_ut.c | 6 +- .../lib/util/io_channel.c/io_channel_ut.c | 6 +- test/unit/lib/vhost/test_vhost.c | 3 - test/unit/lib/vhost/vhost.c/vhost_ut.c | 5 +- 29 files changed, 303 insertions(+), 237 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2243fffb5f..9d51c7bc3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,13 @@ A -r option command line option has been added to enable an alternative UNIX dom or a TCP port in the format ip_addr:tcp_port (i.e. 127.0.0.1:5260). The Rpc configuration file section is now deprecated and will be removed in the v18.04 release. +### I/O Channels + +spdk_poller_register() and spdk_poller_unregister() were moved from the event +framework (include/spdk/event.h) to the I/O channel library +(include/spdk/io_channel.h). This allows code that doesn't depend on the event +framework to request registration and unregistration of pollers. + ## v17.10: Logical Volumes ### New dependencies diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index 3fe8b52e53..5d277c2d6a 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -37,6 +37,7 @@ #include "spdk/bdev.h" #include "spdk/event.h" +#include "spdk/io_channel.h" #include "spdk/log.h" #include "spdk/nvme.h" #include "spdk/util.h" @@ -126,7 +127,7 @@ _nvmf_tgt_start_subsystem(void *arg1, void *arg2) spdk_nvmf_subsystem_start(subsystem); - spdk_poller_register(&app_subsys->poller, subsystem_poll, app_subsys, 0); + app_subsys->poller = spdk_poller_register(subsystem_poll, app_subsys, 0); } void @@ -275,7 +276,7 @@ nvmf_tgt_create_poll_group(void *arg1, void *arg2) SPDK_ERRLOG("Failed to create poll group for core %u\n", g_tgt.core); } - spdk_poller_register(&pg->poller, nvmf_tgt_poll_group_poll, pg, 0); + pg->poller = spdk_poller_register(nvmf_tgt_poll_group_poll, pg, 0); g_active_poll_groups++; spdk_event_call(event); @@ -342,8 +343,8 @@ nvmf_tgt_advance_state(void *arg1, void *arg2) break; } case NVMF_TGT_INIT_START_ACCEPTOR: - spdk_poller_register(&g_acceptor_poller, acceptor_poll, g_tgt.tgt, - g_spdk_nvmf_tgt_conf.acceptor_poll_rate); + g_acceptor_poller = spdk_poller_register(acceptor_poll, g_tgt.tgt, + g_spdk_nvmf_tgt_conf.acceptor_poll_rate); SPDK_NOTICELOG("Acceptor running\n"); g_tgt.state = NVMF_TGT_RUNNING; break; diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 10f4914fd0..6aced1dfae 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -125,9 +125,9 @@ spdk_fio_bdev_init_done(void *cb_arg, int rc) *(bool *)cb_arg = true; } -static void -spdk_fio_start_poller(struct spdk_bdev_poller **ppoller, - spdk_bdev_poller_fn fn, +static struct spdk_poller * +spdk_fio_start_poller(void *thread_ctx, + spdk_thread_fn fn, void *arg, uint64_t period_microseconds) { @@ -137,13 +137,13 @@ spdk_fio_start_poller(struct spdk_bdev_poller **ppoller, fio_thread = g_thread; if (!fio_thread) { SPDK_ERRLOG("Expected local thread to be initialized, but it was not.\n"); - return; + return NULL; } fio_poller = calloc(1, sizeof(*fio_poller)); if (!fio_poller) { SPDK_ERRLOG("Unable to allocate poller\n"); - return; + return NULL; } fio_poller->cb_fn = fn; @@ -152,16 +152,25 @@ spdk_fio_start_poller(struct spdk_bdev_poller **ppoller, TAILQ_INSERT_TAIL(&fio_thread->pollers, fio_poller, link); - *ppoller = (struct spdk_bdev_poller *)fio_poller; + return (struct spdk_poller *)fio_poller; } static void -spdk_fio_stop_poller(struct spdk_bdev_poller **ppoller) +spdk_fio_bdev_start_poller(struct spdk_bdev_poller **ppoller, + spdk_bdev_poller_fn fn, + void *arg, + uint64_t period_microseconds) +{ + *ppoller = (struct spdk_bdev_poller *)spdk_poller_register(fn, arg, period_microseconds); +} + +static void +spdk_fio_stop_poller(struct spdk_poller *poller, void *thread_ctx) { struct spdk_fio_poller *fio_poller; struct spdk_fio_thread *fio_thread; - fio_poller = *(struct spdk_fio_poller **)ppoller; + fio_poller = (struct spdk_fio_poller *)poller; fio_thread = g_thread; if (!fio_thread) { @@ -172,7 +181,12 @@ spdk_fio_stop_poller(struct spdk_bdev_poller **ppoller) TAILQ_REMOVE(&fio_thread->pollers, fio_poller, link); free(fio_poller); - *ppoller = NULL; +} + +static void +spdk_fio_bdev_stop_poller(struct spdk_bdev_poller **ppoller) +{ + spdk_poller_unregister((struct spdk_poller **)ppoller); } static int @@ -196,7 +210,11 @@ spdk_fio_init_thread(struct thread_data *td) return -1; } - fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg, fio_thread, "fio_thread"); + fio_thread->thread = spdk_allocate_thread(spdk_fio_send_msg, + spdk_fio_start_poller, + spdk_fio_stop_poller, + fio_thread, + "fio_thread"); if (!fio_thread->thread) { spdk_ring_free(fio_thread->ring); free(fio_thread); @@ -280,8 +298,8 @@ spdk_fio_init_env(struct thread_data *td) /* Initialize the bdev layer */ spdk_bdev_initialize(spdk_fio_bdev_init_done, &done, - spdk_fio_start_poller, - spdk_fio_stop_poller); + spdk_fio_bdev_start_poller, + spdk_fio_bdev_stop_poller); do { /* Handle init and all cleanup events */ diff --git a/include/spdk/event.h b/include/spdk/event.h index fd832a1434..15debebfe7 100644 --- a/include/spdk/event.h +++ b/include/spdk/event.h @@ -53,8 +53,6 @@ typedef void (*spdk_event_fn)(void *arg1, void *arg2); */ struct spdk_event; -typedef void (*spdk_poller_fn)(void *arg); - /** * \brief A poller is a function that is repeatedly called on an lcore. */ @@ -185,19 +183,6 @@ struct spdk_event *spdk_event_allocate(uint32_t lcore, spdk_event_fn fn, */ void spdk_event_call(struct spdk_event *event); -/** - * \brief Register a poller on the current lcore. - */ -void spdk_poller_register(struct spdk_poller **ppoller, - spdk_poller_fn fn, - void *arg, - uint64_t period_microseconds); - -/** - * \brief Unregister a poller on the given lcore. - */ -void spdk_poller_unregister(struct spdk_poller **ppoller); - /** * \brief Enable or disable monitoring of context switches. */ diff --git a/include/spdk/io_channel.h b/include/spdk/io_channel.h index 2166677d64..fa6ef300ff 100644 --- a/include/spdk/io_channel.h +++ b/include/spdk/io_channel.h @@ -44,11 +44,19 @@ struct spdk_thread; struct spdk_io_channel; +struct spdk_poller; typedef void (*spdk_thread_fn)(void *ctx); typedef void (*spdk_thread_pass_msg)(spdk_thread_fn fn, void *ctx, void *thread_ctx); +typedef void (*spdk_poller_fn)(void *ctx); +typedef struct spdk_poller *(*spdk_start_poller)(void *thread_ctx, + spdk_poller_fn fn, + void *arg, + uint64_t period_microseconds); +typedef void (*spdk_stop_poller)(struct spdk_poller *poller, void *thread_ctx); + typedef int (*spdk_io_channel_create_cb)(void *io_device, void *ctx_buf); typedef void (*spdk_io_channel_destroy_cb)(void *io_device, void *ctx_buf); @@ -70,7 +78,10 @@ typedef void (*spdk_channel_for_each_cpl)(void *io_device, void *ctx, int status * The string is copied, so the pointed-to data only needs to be valid during the * spdk_allocate_thread() call. May be NULL to specify no name. */ -struct spdk_thread *spdk_allocate_thread(spdk_thread_pass_msg fn, void *thread_ctx, +struct spdk_thread *spdk_allocate_thread(spdk_thread_pass_msg msg_fn, + spdk_start_poller start_poller_fn, + spdk_stop_poller stop_poller_fn, + void *thread_ctx, const char *name); /** @@ -105,6 +116,25 @@ const char *spdk_thread_get_name(const struct spdk_thread *thread); */ void spdk_thread_send_msg(const struct spdk_thread *thread, spdk_thread_fn fn, void *ctx); +/** + * \brief Register a poller on the current thread. The poller can be + * unregistered by calling spdk_poller_unregister(). + * + * @param fn This function will be called every `period_microseconds` + * @param arg Passed to fn + * @param period_microseconds How often to call `fn`. If 0, call `fn` as often as possible. + */ +struct spdk_poller *spdk_poller_register(spdk_thread_fn fn, + void *arg, + uint64_t period_microseconds); + +/** + * \brief Unregister a poller on the current thread. + * + * @param ppoller The poller to unregister. + */ +void spdk_poller_unregister(struct spdk_poller **ppoller); + /** * \brief Register the opaque io_device context as an I/O device. * diff --git a/lib/copy/ioat/copy_engine_ioat.c b/lib/copy/ioat/copy_engine_ioat.c index 3a7e5f79c2..a5ae3dee90 100644 --- a/lib/copy/ioat/copy_engine_ioat.c +++ b/lib/copy/ioat/copy_engine_ioat.c @@ -203,7 +203,7 @@ ioat_create_cb(void *io_device, void *ctx_buf) ch->ioat_dev = ioat_dev; ch->ioat_ch = ioat_dev->ioat; - spdk_poller_register(&ch->poller, ioat_poll, ch->ioat_ch, 0); + ch->poller = spdk_poller_register(ioat_poll, ch->ioat_ch, 0); return 0; } diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 7d8f702580..11c37b1c19 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -69,8 +69,6 @@ struct spdk_poller { uint64_t next_run_tick; spdk_poller_fn fn; void *arg; - - struct spdk_event *unregister_complete_event; }; enum spdk_reactor_state { @@ -202,7 +200,28 @@ _spdk_event_queue_run_batch(struct spdk_reactor *reactor) } static void -spdk_poller_insert_timer(struct spdk_reactor *reactor, struct spdk_poller *poller, uint64_t now) +_spdk_reactor_msg_passed(void *arg1, void *arg2) +{ + spdk_thread_fn fn = arg1; + + fn(arg2); +} + +static void +_spdk_reactor_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) +{ + struct spdk_event *event; + struct spdk_reactor *reactor; + + reactor = thread_ctx; + + event = spdk_event_allocate(reactor->lcore, _spdk_reactor_msg_passed, fn, ctx); + + spdk_event_call(event); +} + +static void +_spdk_poller_insert_timer(struct spdk_reactor *reactor, struct spdk_poller *poller, uint64_t now) { struct spdk_poller *iter; uint64_t next_run_tick; @@ -225,25 +244,68 @@ spdk_poller_insert_timer(struct spdk_reactor *reactor, struct spdk_poller *polle TAILQ_INSERT_HEAD(&reactor->timer_pollers, poller, tailq); } -static void -_spdk_reactor_msg_passed(void *arg1, void *arg2) +static struct spdk_poller * +_spdk_reactor_start_poller(void *thread_ctx, + spdk_thread_fn fn, + void *arg, + uint64_t period_microseconds) { - spdk_thread_fn fn = arg1; + struct spdk_poller *poller; + struct spdk_reactor *reactor; - fn(arg2); + reactor = thread_ctx; + + poller = calloc(1, sizeof(*poller)); + if (poller == NULL) { + SPDK_ERRLOG("Poller memory allocation failed\n"); + return NULL; + } + + poller->lcore = reactor->lcore; + poller->state = SPDK_POLLER_STATE_WAITING; + poller->fn = fn; + poller->arg = arg; + + if (period_microseconds) { + poller->period_ticks = (spdk_get_ticks_hz() * period_microseconds) / 1000000ULL; + } else { + poller->period_ticks = 0; + } + + if (poller->period_ticks) { + _spdk_poller_insert_timer(reactor, poller, spdk_get_ticks()); + } else { + TAILQ_INSERT_TAIL(&reactor->active_pollers, poller, tailq); + } + + return poller; } static void -_spdk_reactor_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) +_spdk_reactor_stop_poller(struct spdk_poller *poller, void *thread_ctx) { - uint32_t core; - struct spdk_event *event; + struct spdk_reactor *reactor; - core = *(uint32_t *)thread_ctx; + reactor = thread_ctx; - event = spdk_event_allocate(core, _spdk_reactor_msg_passed, fn, ctx); + assert(poller->lcore == spdk_env_get_current_core()); - spdk_event_call(event); + if (poller->state == SPDK_POLLER_STATE_RUNNING) { + /* + * We are being called from the poller_fn, so set the state to unregistered + * and let the reactor loop free the poller. + */ + poller->state = SPDK_POLLER_STATE_UNREGISTERED; + } else { + /* Poller is not running currently, so just free it. */ + if (poller->period_ticks) { + TAILQ_REMOVE(&reactor->timer_pollers, poller, tailq); + } else { + TAILQ_REMOVE(&reactor->active_pollers, poller, tailq); + } + + free(poller); + } } static void @@ -272,7 +334,7 @@ _spdk_reactor_context_switch_monitor_start(void *arg1, void *arg2) if (reactor->rusage_poller == NULL) { getrusage(RUSAGE_THREAD, &reactor->rusage); - spdk_poller_register(&reactor->rusage_poller, get_rusage, reactor, 1000000); + reactor->rusage_poller = spdk_poller_register(get_rusage, reactor, 1000000); } } @@ -347,7 +409,10 @@ _spdk_reactor_run(void *arg) char thread_name[32]; snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore); - if (spdk_allocate_thread(_spdk_reactor_send_msg, &reactor->lcore, thread_name) == NULL) { + if (spdk_allocate_thread(_spdk_reactor_send_msg, + _spdk_reactor_start_poller, + _spdk_reactor_stop_poller, + reactor, thread_name) == NULL) { return -1; } SPDK_NOTICELOG("Reactor started on core %u on socket %u\n", reactor->lcore, @@ -395,7 +460,7 @@ _spdk_reactor_run(void *arg) free(poller); } else { poller->state = SPDK_POLLER_STATE_WAITING; - spdk_poller_insert_timer(reactor, poller, now); + _spdk_poller_insert_timer(reactor, poller, now); } took_action = true; } @@ -674,85 +739,4 @@ spdk_reactors_fini(void) } } -void -spdk_poller_register(struct spdk_poller **ppoller, spdk_poller_fn fn, void *arg, - uint64_t period_microseconds) -{ - struct spdk_poller *poller; - struct spdk_reactor *reactor; - - poller = calloc(1, sizeof(*poller)); - if (poller == NULL) { - SPDK_ERRLOG("Poller memory allocation failed\n"); - abort(); - } - - poller->lcore = spdk_env_get_current_core(); - poller->state = SPDK_POLLER_STATE_WAITING; - poller->fn = fn; - poller->arg = arg; - - if (period_microseconds) { - poller->period_ticks = (spdk_get_ticks_hz() * period_microseconds) / 1000000ULL; - } else { - poller->period_ticks = 0; - } - - if (*ppoller != NULL) { - SPDK_ERRLOG("Attempted reuse of poller pointer\n"); - abort(); - } - - if (poller->lcore >= SPDK_MAX_REACTORS) { - SPDK_ERRLOG("Attempted to use lcore %u which is larger than max lcore %u\n", - poller->lcore, SPDK_MAX_REACTORS - 1); - abort(); - } - - *ppoller = poller; - reactor = spdk_reactor_get(poller->lcore); - - if (poller->period_ticks) { - spdk_poller_insert_timer(reactor, poller, spdk_get_ticks()); - } else { - TAILQ_INSERT_TAIL(&reactor->active_pollers, poller, tailq); - } -} - -void -spdk_poller_unregister(struct spdk_poller **ppoller) -{ - struct spdk_poller *poller; - struct spdk_reactor *reactor; - - poller = *ppoller; - - *ppoller = NULL; - - if (poller == NULL) { - return; - } - - assert(poller->lcore == spdk_env_get_current_core()); - - reactor = spdk_reactor_get(poller->lcore); - - if (poller->state == SPDK_POLLER_STATE_RUNNING) { - /* - * We are being called from the poller_fn, so set the state to unregistered - * and let the reactor loop free the poller. - */ - poller->state = SPDK_POLLER_STATE_UNREGISTERED; - } else { - /* Poller is not running currently, so just free it. */ - if (poller->period_ticks) { - TAILQ_REMOVE(&reactor->timer_pollers, poller, tailq); - } else { - TAILQ_REMOVE(&reactor->active_pollers, poller, tailq); - } - - free(poller); - } -} - SPDK_LOG_REGISTER_TRACE_FLAG("reactor", SPDK_TRACE_REACTOR) diff --git a/lib/event/rpc.c b/lib/event/rpc.c index 529bdecf03..ce0f5979cf 100644 --- a/lib/event/rpc.c +++ b/lib/event/rpc.c @@ -35,6 +35,7 @@ #include "spdk/conf.h" #include "spdk/env.h" +#include "spdk/io_channel.h" #include "spdk/log.h" #include "spdk/rpc.h" @@ -84,8 +85,7 @@ spdk_rpc_initialize(const char *listen_addr) } /* Register a poller to periodically check for RPCs */ - spdk_poller_register(&g_rpc_poller, spdk_rpc_subsystem_poll, NULL, - RPC_SELECT_INTERVAL); + g_rpc_poller = spdk_poller_register(spdk_rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL); } void diff --git a/lib/event/subsystems/bdev/bdev.c b/lib/event/subsystems/bdev/bdev.c index e0101c7a48..8ce00abb60 100644 --- a/lib/event/subsystems/bdev/bdev.c +++ b/lib/event/subsystems/bdev/bdev.c @@ -35,6 +35,7 @@ #include "spdk/bdev.h" #include "spdk/env.h" +#include "spdk/io_channel.h" #include "spdk_internal/event.h" #include "spdk/env.h" @@ -51,10 +52,7 @@ spdk_bdev_subsystem_start_poller(struct spdk_bdev_poller **ppoller, void *arg, uint64_t period_microseconds) { - spdk_poller_register((struct spdk_poller **)ppoller, - fn, - arg, - period_microseconds); + *ppoller = (struct spdk_bdev_poller *)spdk_poller_register(fn, arg, period_microseconds); } static void diff --git a/lib/iscsi/acceptor.c b/lib/iscsi/acceptor.c index 4cc0702364..b40175f48e 100644 --- a/lib/iscsi/acceptor.c +++ b/lib/iscsi/acceptor.c @@ -36,6 +36,7 @@ #include "spdk/env.h" #include "spdk/event.h" +#include "spdk/io_channel.h" #include "spdk/log.h" #include "spdk/net.h" #include "spdk/string.h" @@ -79,8 +80,7 @@ spdk_iscsi_portal_accept(void *arg) void spdk_iscsi_acceptor_start(struct spdk_iscsi_portal *p) { - spdk_poller_register(&p->acceptor_poller, spdk_iscsi_portal_accept, p, - ACCEPT_TIMEOUT_US); + p->acceptor_poller = spdk_poller_register(spdk_iscsi_portal_accept, p, ACCEPT_TIMEOUT_US); } void diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index b5d73dfee0..08d092319e 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -46,6 +46,7 @@ #include "spdk/endian.h" #include "spdk/env.h" #include "spdk/event.h" +#include "spdk/io_channel.h" #include "spdk/queue.h" #include "spdk/trace.h" #include "spdk/net.h" @@ -391,7 +392,7 @@ int spdk_initialize_iscsi_conns(void) return -1; } - spdk_poller_register(&g_idle_conn_poller, spdk_iscsi_conn_idle_do_work, NULL, 0); + g_idle_conn_poller = spdk_poller_register(spdk_iscsi_conn_idle_do_work, NULL, 0); return 0; } @@ -514,7 +515,7 @@ error_return: conn->lcore = spdk_env_get_current_core(); spdk_net_framework_clear_socket_association(conn->sock); __sync_fetch_and_add(&g_num_connections[conn->lcore], 1); - spdk_poller_register(&conn->poller, spdk_iscsi_conn_login_do_work, conn, 0); + conn->poller = spdk_poller_register(spdk_iscsi_conn_login_do_work, conn, 0); return 0; } @@ -715,8 +716,7 @@ void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn) rc = spdk_iscsi_conn_free_tasks(conn); if (rc < 0) { /* The connection cannot be freed yet. Check back later. */ - spdk_poller_register(&conn->shutdown_timer, _spdk_iscsi_conn_check_shutdown, conn, - 1000); + conn->shutdown_timer = spdk_poller_register(_spdk_iscsi_conn_check_shutdown, conn, 1000); } else { spdk_iscsi_conn_stop_poller(conn, _spdk_iscsi_conn_free, spdk_env_get_current_core()); } @@ -859,8 +859,8 @@ void spdk_shutdown_iscsi_conns(void) } pthread_mutex_unlock(&g_conns_mutex); - spdk_poller_register(&g_shutdown_timer, spdk_iscsi_conn_check_shutdown, NULL, - 1000); + g_shutdown_timer = spdk_poller_register(spdk_iscsi_conn_check_shutdown, NULL, + 1000); } int @@ -1423,8 +1423,8 @@ spdk_iscsi_conn_full_feature_migrate(void *arg1, void *arg2) /* The poller has been unregistered, so now we can re-register it on the new core. */ conn->lcore = spdk_env_get_current_core(); - spdk_poller_register(&conn->poller, spdk_iscsi_conn_full_feature_do_work, conn, - 0); + conn->poller = spdk_poller_register(spdk_iscsi_conn_full_feature_do_work, conn, + 0); } void @@ -1641,8 +1641,7 @@ void spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn) { conn->state = ISCSI_CONN_STATE_LOGGED_OUT; - spdk_poller_register(&conn->logout_timer, logout_timeout, conn, - ISCSI_LOGOUT_TIMEOUT * 1000000); + conn->logout_timer = spdk_poller_register(logout_timeout, conn, ISCSI_LOGOUT_TIMEOUT * 1000000); } SPDK_TRACE_REGISTER_FN(iscsi_conn_trace) diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index 06b16be436..392786f417 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -500,7 +500,8 @@ _spdk_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) void SpdkInitializeThread(void) { if (g_fs != NULL) { - spdk_allocate_thread(_spdk_send_msg, NULL, "spdk_rocksdb"); + /* TODO: Add an event lib call to dynamically register a thread */ + spdk_allocate_thread(_spdk_send_msg, NULL, NULL, NULL, "spdk_rocksdb"); g_sync_args.channel = spdk_fs_alloc_io_channel_sync(g_fs); } } diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index 3bbd17aa89..105d2bfb06 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -246,7 +246,7 @@ _spdk_scsi_lun_hot_remove(void *arg1, void *arg2) lun->hotremove_cb(lun, lun->hotremove_ctx); } - spdk_poller_register(&lun->hotplug_poller, spdk_scsi_lun_hotplug, lun, 0); + lun->hotplug_poller = spdk_poller_register(spdk_scsi_lun_hotplug, lun, 0); } static void diff --git a/lib/util/io_channel.c b/lib/util/io_channel.c index 0bab243f00..9c0037f1a9 100644 --- a/lib/util/io_channel.c +++ b/lib/util/io_channel.c @@ -77,7 +77,9 @@ struct spdk_io_channel { struct spdk_thread { pthread_t thread_id; - spdk_thread_pass_msg fn; + spdk_thread_pass_msg msg_fn; + spdk_start_poller start_poller_fn; + spdk_stop_poller stop_poller_fn; void *thread_ctx; TAILQ_HEAD(, spdk_io_channel) io_channels; TAILQ_ENTRY(spdk_thread) tailq; @@ -117,7 +119,10 @@ _set_thread_name(const char *thread_name) } struct spdk_thread * -spdk_allocate_thread(spdk_thread_pass_msg fn, void *thread_ctx, const char *name) +spdk_allocate_thread(spdk_thread_pass_msg msg_fn, + spdk_start_poller start_poller_fn, + spdk_stop_poller stop_poller_fn, + void *thread_ctx, const char *name) { struct spdk_thread *thread; @@ -138,7 +143,9 @@ spdk_allocate_thread(spdk_thread_pass_msg fn, void *thread_ctx, const char *name } thread->thread_id = pthread_self(); - thread->fn = fn; + thread->msg_fn = msg_fn; + thread->start_poller_fn = start_poller_fn; + thread->stop_poller_fn = stop_poller_fn; thread->thread_ctx = thread_ctx; TAILQ_INIT(&thread->io_channels); TAILQ_INSERT_TAIL(&g_threads, thread, tailq); @@ -199,7 +206,50 @@ spdk_thread_get_name(const struct spdk_thread *thread) void spdk_thread_send_msg(const struct spdk_thread *thread, spdk_thread_fn fn, void *ctx) { - thread->fn(fn, ctx, thread->thread_ctx); + thread->msg_fn(fn, ctx, thread->thread_ctx); +} + + +struct spdk_poller * +spdk_poller_register(spdk_poller_fn fn, + void *arg, + uint64_t period_microseconds) +{ + struct spdk_thread *thread; + struct spdk_poller *poller; + + thread = spdk_get_thread(); + if (!thread) { + abort(); + } + + poller = thread->start_poller_fn(thread->thread_ctx, fn, arg, period_microseconds); + if (!poller) { + SPDK_ERRLOG("Unable to start requested poller\n"); + abort(); + } + + return poller; +} + +void +spdk_poller_unregister(struct spdk_poller **ppoller) +{ + struct spdk_thread *thread; + struct spdk_poller *poller; + + poller = *ppoller; + if (poller == NULL) { + return; + } + + *ppoller = NULL; + + thread = spdk_get_thread(); + + if (thread) { + thread->stop_poller_fn(poller, thread->thread_ctx); + } } void diff --git a/lib/vhost/vhost_blk.c b/lib/vhost/vhost_blk.c index 5c273745c5..7d226ebfb1 100644 --- a/lib/vhost/vhost_blk.c +++ b/lib/vhost/vhost_blk.c @@ -397,7 +397,7 @@ _bdev_remove_cb(struct spdk_vhost_dev *vdev, void *arg) bvdev->vdev.name); if (bvdev->requestq_poller) { spdk_poller_unregister(&bvdev->requestq_poller); - spdk_poller_register(&bvdev->requestq_poller, no_bdev_vdev_worker, bvdev, 0); + bvdev->requestq_poller = spdk_poller_register(no_bdev_vdev_worker, bvdev, 0); } bvdev->bdev = NULL; @@ -503,8 +503,8 @@ spdk_vhost_blk_start(struct spdk_vhost_dev *vdev, void *event_ctx) } } - spdk_poller_register(&bvdev->requestq_poller, bvdev->bdev ? vdev_worker : no_bdev_vdev_worker, - bvdev, 0); + bvdev->requestq_poller = spdk_poller_register(bvdev->bdev ? vdev_worker : no_bdev_vdev_worker, + bvdev, 0); SPDK_NOTICELOG("Started poller for vhost controller %s on lcore %d\n", vdev->name, vdev->lcore); out: spdk_vhost_dev_backend_event_done(event_ctx, rc); @@ -569,8 +569,8 @@ spdk_vhost_blk_stop(struct spdk_vhost_dev *vdev, void *event_ctx) destroy_ctx->event_ctx = event_ctx; spdk_poller_unregister(&bvdev->requestq_poller); - spdk_poller_register(&destroy_ctx->poller, destroy_device_poller_cb, destroy_ctx, - 1000); + destroy_ctx->poller = spdk_poller_register(destroy_device_poller_cb, + destroy_ctx, 1000); return 0; err: diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index df4e0aa143..a5b6c9e5fe 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -36,6 +36,7 @@ #include #include "spdk/env.h" +#include "spdk/io_channel.h" #include "spdk/scsi.h" #include "spdk/scsi_spec.h" #include "spdk/conf.h" @@ -1046,8 +1047,8 @@ spdk_vhost_scsi_start(struct spdk_vhost_dev *vdev, void *event_ctx) spdk_vhost_dev_mem_register(vdev); - spdk_poller_register(&svdev->requestq_poller, vdev_worker, svdev, 0); - spdk_poller_register(&svdev->mgmt_poller, vdev_mgmt_worker, svdev, + svdev->requestq_poller = spdk_poller_register(vdev_worker, svdev, 0); + svdev->mgmt_poller = spdk_poller_register(vdev_mgmt_worker, svdev, MGMT_POLL_PERIOD_US); out: spdk_vhost_dev_backend_event_done(event_ctx, rc); @@ -1115,8 +1116,8 @@ spdk_vhost_scsi_stop(struct spdk_vhost_dev *vdev, void *event_ctx) spdk_poller_unregister(&svdev->requestq_poller); spdk_poller_unregister(&svdev->mgmt_poller); - spdk_poller_register(&destroy_ctx->poller, destroy_device_poller_cb, destroy_ctx, - 1000); + destroy_ctx->poller = spdk_poller_register(destroy_device_poller_cb, destroy_ctx, + 1000); return 0; diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index 08e3f53970..b8e460fd99 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -456,8 +456,8 @@ reset_cb(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg) TAILQ_INSERT_TAIL(&target->task_list, task, link); spdk_bdev_free_io(bdev_io); - spdk_poller_register(&target->reset_timer, reset_target, target, - 10 * 1000000); + target->reset_timer = spdk_poller_register(reset_target, target, + 10 * 1000000); } static void @@ -497,11 +497,11 @@ bdevperf_submit_on_core(void *arg1, void *arg2) target->ch = spdk_bdev_get_io_channel(target->bdev_desc); /* Start a timer to stop this I/O chain when the run is over */ - spdk_poller_register(&target->run_timer, end_target, target, - g_time_in_sec * 1000000); + target->run_timer = spdk_poller_register(end_target, target, + g_time_in_sec * 1000000); if (g_reset) { - spdk_poller_register(&target->reset_timer, reset_target, target, - 10 * 1000000); + target->reset_timer = spdk_poller_register(reset_target, target, + 10 * 1000000); } bdevperf_submit_io(target, g_queue_depth); target = target->next; @@ -642,8 +642,7 @@ bdevperf_run(void *arg1, void *arg2) /* Start a timer to dump performance numbers */ if (g_show_performance_real_time) { - spdk_poller_register(&g_perf_timer, performance_statistics_thread, NULL, - 1000000); + g_perf_timer = spdk_poller_register(performance_statistics_thread, NULL, 1000000); } g_master_core = spdk_env_get_current_core(); diff --git a/test/lib/bdev/nbd/nbd.c b/test/lib/bdev/nbd/nbd.c index 269a28727e..4ef459d096 100644 --- a/test/lib/bdev/nbd/nbd.c +++ b/test/lib/bdev/nbd/nbd.c @@ -39,6 +39,7 @@ #include "spdk/bdev.h" #include "spdk/env.h" #include "spdk/event.h" +#include "spdk/io_channel.h" #include "spdk/log.h" #include "spdk/util.h" @@ -88,7 +89,7 @@ nbd_start(void *arg1, void *arg2) return; } - spdk_poller_register(&g_nbd_poller, nbd_poll, NULL, 0); + g_nbd_poller = spdk_poller_register(nbd_poll, NULL, 0); } static void usage(char *program_name) diff --git a/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c b/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c index f81d91beb4..a4dad0c2a3 100644 --- a/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c +++ b/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c @@ -87,7 +87,7 @@ fs_init(void) struct spdk_bs_dev *dev; dev = init_dev(); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); CU_ASSERT(g_fs != NULL); @@ -131,7 +131,7 @@ fs_open(void) dev = init_dev(); memset(name, 'a', sizeof(name) - 1); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); CU_ASSERT(g_fs != NULL); @@ -190,7 +190,7 @@ fs_create(void) dev = init_dev(); memset(name, 'a', sizeof(name) - 1); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL); @@ -229,7 +229,7 @@ fs_truncate(void) struct spdk_bs_dev *dev; dev = init_dev(); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL); @@ -282,7 +282,7 @@ fs_rename(void) struct spdk_bs_dev *dev; dev = init_dev(); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL); @@ -435,7 +435,7 @@ channel_ops(void) struct spdk_io_channel *channel; dev = init_dev(); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL); @@ -463,7 +463,7 @@ channel_ops_sync(void) struct spdk_io_channel *channel; dev = init_dev(); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); spdk_fs_init(dev, NULL, fs_op_with_handle_complete, NULL); SPDK_CU_ASSERT_FATAL(g_fs != NULL); diff --git a/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index 08ec2b4475..d3ab743e3f 100644 --- a/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -172,7 +172,7 @@ cache_write(void) ut_send_request(_fs_init, NULL); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); channel = spdk_fs_alloc_io_channel_sync(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); @@ -210,7 +210,7 @@ cache_write_null_buffer(void) ut_send_request(_fs_init, NULL); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); channel = spdk_fs_alloc_io_channel_sync(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); @@ -241,7 +241,7 @@ fs_create_sync(void) ut_send_request(_fs_init, NULL); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); channel = spdk_fs_alloc_io_channel_sync(g_fs); CU_ASSERT(channel != NULL); @@ -270,7 +270,7 @@ cache_append_no_cache(void) ut_send_request(_fs_init, NULL); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); channel = spdk_fs_alloc_io_channel_sync(g_fs); rc = spdk_fs_open_file(g_fs, channel, "testfile", SPDK_BLOBFS_OPEN_CREATE, &g_file); @@ -308,7 +308,7 @@ fs_delete_file_without_close(void) struct spdk_file *file; ut_send_request(_fs_init, NULL); - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); channel = spdk_fs_alloc_io_channel_sync(g_fs); CU_ASSERT(channel != NULL); @@ -347,7 +347,7 @@ spdk_thread(void *arg) { struct ut_request *req; - spdk_allocate_thread(_fs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); while (1) { pthread_mutex_lock(&g_mutex); diff --git a/test/lib/event/reactor/reactor.c b/test/lib/event/reactor/reactor.c index 746a999c3c..312d55d383 100644 --- a/test/lib/event/reactor/reactor.c +++ b/test/lib/event/reactor/reactor.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "spdk/event.h" +#include "spdk/io_channel.h" static int g_time_in_sec; static struct spdk_poller *test_end_poller; @@ -47,6 +48,12 @@ static void test_end(void *arg) { printf("test_end\n"); + + spdk_poller_unregister(&test_end_poller); + spdk_poller_unregister(&poller_100ms); + spdk_poller_unregister(&poller_250ms); + spdk_poller_unregister(&poller_500ms); + spdk_app_stop(0); } @@ -76,29 +83,17 @@ test_start(void *arg1, void *arg2) printf("test_start\n"); /* Register a poller that will stop the test after the time has elapsed. */ - spdk_poller_register(&test_end_poller, test_end, NULL, g_time_in_sec * 1000000ULL); + test_end_poller = spdk_poller_register(test_end, NULL, g_time_in_sec * 1000000ULL); - spdk_poller_register(&poller_100ms, tick, (void *)100, 100000); - spdk_poller_register(&poller_250ms, tick, (void *)250, 250000); - spdk_poller_register(&poller_500ms, tick, (void *)500, 500000); - spdk_poller_register(&poller_oneshot, oneshot, NULL, 0); + poller_100ms = spdk_poller_register(tick, (void *)100, 100000); + poller_250ms = spdk_poller_register(tick, (void *)250, 250000); + poller_500ms = spdk_poller_register(tick, (void *)500, 500000); + poller_oneshot = spdk_poller_register(oneshot, NULL, 0); - spdk_poller_register(&poller_unregister, nop, NULL, 0); + poller_unregister = spdk_poller_register(nop, NULL, 0); spdk_poller_unregister(&poller_unregister); } -static void -test_cleanup(void) -{ - printf("test_cleanup\n"); - - spdk_poller_unregister(&test_end_poller); - spdk_poller_unregister(&poller_100ms); - spdk_poller_unregister(&poller_250ms); - spdk_poller_unregister(&poller_500ms); - /* poller_oneshot unregisters itself */ -} - static void usage(const char *program_name) { @@ -134,12 +129,8 @@ main(int argc, char **argv) exit(1); } - opts.shutdown_cb = test_cleanup; - spdk_app_start(&opts, test_start, NULL, NULL); - test_cleanup(); - spdk_app_fini(); return 0; diff --git a/test/lib/event/reactor_perf/reactor_perf.c b/test/lib/event/reactor_perf/reactor_perf.c index 2d1d9bdbbe..56331ff790 100644 --- a/test/lib/event/reactor_perf/reactor_perf.c +++ b/test/lib/event/reactor_perf/reactor_perf.c @@ -35,6 +35,7 @@ #include "spdk/env.h" #include "spdk/event.h" +#include "spdk/io_channel.h" static int g_time_in_sec; static int g_queue_depth; @@ -68,8 +69,8 @@ test_start(void *arg1, void *arg2) printf("test_start\n"); /* Register a poller that will stop the test after the time has elapsed. */ - spdk_poller_register(&test_end_poller, __test_end, NULL, - g_time_in_sec * 1000000ULL); + test_end_poller = spdk_poller_register(__test_end, NULL, + g_time_in_sec * 1000000ULL); for (i = 0; i < g_queue_depth; i++) { __submit_next(NULL, NULL); diff --git a/test/lib/ut_multithread.c b/test/lib/ut_multithread.c index 0a97144c60..ba40d9fbf3 100644 --- a/test/lib/ut_multithread.c +++ b/test/lib/ut_multithread.c @@ -92,7 +92,7 @@ allocate_threads(int num_threads) for (i = 0; i < g_ut_num_threads; i++) { set_thread(i); - spdk_allocate_thread(__send_msg, &g_ut_threads[i], NULL); + spdk_allocate_thread(__send_msg, NULL, NULL, &g_ut_threads[i], NULL); thread = spdk_get_thread(); SPDK_CU_ASSERT_FATAL(thread != NULL); g_ut_threads[i].thread = thread; diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 4af8b13685..884ad825fc 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -1936,7 +1936,7 @@ int main(int argc, char **argv) } g_dev_buffer = calloc(1, DEV_BUFFER_SIZE); - spdk_allocate_thread(_bs_send_msg, NULL, "thread0"); + spdk_allocate_thread(_bs_send_msg, NULL, NULL, NULL, "thread0"); CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); num_failures = CU_get_number_of_failures(); diff --git a/test/unit/lib/lvol/lvol.c/lvol_ut.c b/test/unit/lib/lvol/lvol.c/lvol_ut.c index 14fd169bf3..668975b2db 100644 --- a/test/unit/lib/lvol/lvol.c/lvol_ut.c +++ b/test/unit/lib/lvol/lvol.c/lvol_ut.c @@ -415,7 +415,7 @@ lvs_init_unload_success(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -465,7 +465,7 @@ lvs_init_destroy_success(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -510,7 +510,7 @@ lvs_init_opts_success(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); g_lvserrno = -1; @@ -539,7 +539,7 @@ lvs_unload_lvs_is_null_fail(void) { int rc = 0; - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); g_lvserrno = -1; rc = spdk_lvs_unload(NULL, lvol_store_op_complete, NULL); @@ -561,7 +561,7 @@ lvs_names(void) init_dev(&dev_y); init_dev(&dev_x2); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts_none); spdk_lvs_opts_init(&opts_x); @@ -667,7 +667,7 @@ lvol_create_destroy_success(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -707,7 +707,7 @@ lvol_create_fail(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -752,7 +752,7 @@ lvol_destroy_fail(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -791,7 +791,7 @@ lvol_close_fail(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -828,7 +828,7 @@ lvol_close_success(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -866,7 +866,7 @@ lvol_resize(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -954,7 +954,7 @@ lvs_load(void) strncpy(bs_opts.bstype.bstype, "LVOLSTORE", SPDK_BLOBSTORE_TYPE_LENGTH); spdk_bs_init(&dev.bs_dev, &bs_opts, null_cb, NULL); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); /* Fail on bs load */ dev.load_status = -1; @@ -1079,7 +1079,7 @@ lvols_load(void) spdk_blob_md_set_xattr(blob3, "name", "lvol3", strnlen("lvol3", SPDK_LVOL_NAME_MAX) + 1); blob3->uuid[UUID_STRING_LEN - 2] = '3'; - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); /* Load lvs with 0 blobs */ g_lvserrno = 0; @@ -1190,7 +1190,7 @@ lvol_open(void) spdk_blob_md_set_xattr(blob3, "name", "lvol3", strnlen("lvol3", SPDK_LVOL_NAME_MAX) + 1); blob3->uuid[UUID_STRING_LEN - 2] = '3'; - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); TAILQ_INSERT_TAIL(&dev.bs->blobs, blob1, link); TAILQ_INSERT_TAIL(&dev.bs->blobs, blob2, link); @@ -1253,7 +1253,7 @@ lvol_names(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); @@ -1326,7 +1326,7 @@ static void lvol_refcnt(void) init_dev(&dev); - spdk_allocate_thread(_lvol_send_msg, NULL, NULL); + spdk_allocate_thread(_lvol_send_msg, NULL, NULL, NULL, NULL); spdk_lvs_opts_init(&opts); strncpy(opts.name, "lvs", sizeof(opts.name)); diff --git a/test/unit/lib/scsi/lun.c/lun_ut.c b/test/unit/lib/scsi/lun.c/lun_ut.c index ff590fda16..eeea742500 100644 --- a/test/unit/lib/scsi/lun.c/lun_ut.c +++ b/test/unit/lib/scsi/lun.c/lun_ut.c @@ -54,10 +54,12 @@ static bool g_lun_execute_fail = false; static int g_lun_execute_status = SPDK_SCSI_TASK_PENDING; static uint32_t g_task_count = 0; -void -spdk_poller_register(struct spdk_poller **ppoller, spdk_poller_fn fn, void *arg, +struct spdk_poller * +spdk_poller_register(spdk_poller_fn fn, + void *arg, uint64_t period_microseconds) { + return NULL; } void diff --git a/test/unit/lib/util/io_channel.c/io_channel_ut.c b/test/unit/lib/util/io_channel.c/io_channel_ut.c index 2d2db1f375..d032bc843d 100644 --- a/test/unit/lib/util/io_channel.c/io_channel_ut.c +++ b/test/unit/lib/util/io_channel.c/io_channel_ut.c @@ -253,7 +253,7 @@ thread_name(void) const char *name; /* Create thread with no name */ - spdk_allocate_thread(_send_msg, NULL, NULL); + spdk_allocate_thread(_send_msg, NULL, NULL, NULL, NULL); thread = spdk_get_thread(); SPDK_CU_ASSERT_FATAL(thread != NULL); name = spdk_thread_get_name(thread); @@ -261,7 +261,7 @@ thread_name(void) spdk_free_thread(); /* Create thread named "test_thread" */ - spdk_allocate_thread(_send_msg, NULL, "test_thread"); + spdk_allocate_thread(_send_msg, NULL, NULL, NULL, "test_thread"); thread = spdk_get_thread(); SPDK_CU_ASSERT_FATAL(thread != NULL); name = spdk_thread_get_name(thread); @@ -326,7 +326,7 @@ channel(void) struct spdk_io_channel *ch1, *ch2; void *ctx; - spdk_allocate_thread(_send_msg, NULL, "thread0"); + spdk_allocate_thread(_send_msg, NULL, NULL, NULL, "thread0"); spdk_io_device_register(&device1, create_cb_1, destroy_cb_1, sizeof(ctx1)); spdk_io_device_register(&device2, create_cb_2, destroy_cb_2, sizeof(ctx2)); spdk_io_device_register(&device3, create_cb_null, NULL, 0); diff --git a/test/unit/lib/vhost/test_vhost.c b/test/unit/lib/vhost/test_vhost.c index 81f8e18b21..37a9a08c42 100644 --- a/test/unit/lib/vhost/test_vhost.c +++ b/test/unit/lib/vhost/test_vhost.c @@ -72,8 +72,6 @@ DEFINE_STUB(spdk_vhost_vq_used_signal, int, (struct spdk_vhost_dev *vdev, DEFINE_STUB_V(spdk_vhost_dev_used_signal, (struct spdk_vhost_dev *vdev)); DEFINE_STUB_V(spdk_vhost_dev_mem_register, (struct spdk_vhost_dev *vdev)); DEFINE_STUB_P(spdk_vhost_dev_find, struct spdk_vhost_dev, (const char *ctrlr_name), {0}); -DEFINE_STUB_V(spdk_poller_register, (struct spdk_poller **ppoller, spdk_poller_fn fn, void *arg, - uint64_t period_microseconds)); DEFINE_STUB_V(spdk_ring_free, (struct spdk_ring *ring)); DEFINE_STUB_P(spdk_conf_first_section, struct spdk_conf_section, (struct spdk_conf *cp), {0}); DEFINE_STUB(spdk_conf_section_match_prefix, bool, (const struct spdk_conf_section *sp, @@ -87,7 +85,6 @@ DEFINE_STUB_P(spdk_conf_section_get_nmval, char, (struct spdk_conf_section *sp, DEFINE_STUB_V(spdk_vhost_dev_mem_unregister, (struct spdk_vhost_dev *vdev)); DEFINE_STUB(spdk_vhost_event_send, int, (struct spdk_vhost_dev *vdev, spdk_vhost_event_fn cb_fn, void *arg, unsigned timeout_sec, const char *errmsg), 0); -DEFINE_STUB_V(spdk_poller_unregister, (struct spdk_poller **ppoller)); DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), 0); DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response)); DEFINE_STUB_V(spdk_vhost_lock, (void)); diff --git a/test/unit/lib/vhost/vhost.c/vhost_ut.c b/test/unit/lib/vhost/vhost.c/vhost_ut.c index 523bfbbdd3..627b59d46c 100644 --- a/test/unit/lib/vhost/vhost.c/vhost_ut.c +++ b/test/unit/lib/vhost/vhost.c/vhost_ut.c @@ -35,6 +35,7 @@ #include "CUnit/Basic.h" #include "spdk_cunit.h" +#include "spdk/io_channel.h" #include "spdk_internal/mock.h" #include "lib/test_env.c" @@ -48,8 +49,8 @@ DEFINE_STUB(spdk_mem_unregister, int, (void *vaddr, size_t len), 0); DEFINE_STUB(spdk_app_get_core_mask, uint64_t, (void), 0); DEFINE_STUB_V(spdk_app_stop, (int rc)); DEFINE_STUB_V(spdk_event_call, (struct spdk_event *event)); -DEFINE_STUB_V(spdk_poller_register, (struct spdk_poller **ppoller, spdk_poller_fn fn, void *arg, - uint64_t period_microseconds)); +DEFINE_STUB(spdk_poller_register, struct spdk_poller *, (spdk_poller_fn fn, void *arg, + uint64_t period_microseconds), NULL); DEFINE_STUB_V(spdk_poller_unregister, (struct spdk_poller **ppoller)); DEFINE_STUB(spdk_iommu_mem_unregister, int, (uint64_t addr, uint64_t len), 0); DEFINE_STUB(rte_vhost_get_mem_table, int, (int vid, struct rte_vhost_memory **mem), 0);