diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d51c7bc3..f20082053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ 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. +### Block Device Abstraction Layer (bdev) + +The poller abstraction was removed from the bdev layer. There is now a general purpose +abstraction for pollers available in include/spdk/io_channel.h + ## v17.10: Logical Volumes ### New dependencies diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 6aced1dfa..4540b0cb7 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -60,7 +60,7 @@ struct spdk_fio_msg { /* A polling function */ struct spdk_fio_poller { - spdk_bdev_poller_fn cb_fn; + spdk_poller_fn cb_fn; void *cb_arg; uint64_t period_microseconds; @@ -93,7 +93,7 @@ struct spdk_fio_thread { unsigned int iocq_size; // number of iocq entries allocated }; -static __thread struct spdk_fio_thread *g_thread; +static struct spdk_fio_thread *g_init_thread = NULL; static bool g_spdk_env_initialized = false; static int spdk_fio_init(struct thread_data *td); @@ -131,15 +131,9 @@ spdk_fio_start_poller(void *thread_ctx, void *arg, uint64_t period_microseconds) { - struct spdk_fio_thread *fio_thread; + struct spdk_fio_thread *fio_thread = thread_ctx; struct spdk_fio_poller *fio_poller; - fio_thread = g_thread; - if (!fio_thread) { - SPDK_ERRLOG("Expected local thread to be initialized, but it was not.\n"); - return NULL; - } - fio_poller = calloc(1, sizeof(*fio_poller)); if (!fio_poller) { SPDK_ERRLOG("Unable to allocate poller\n"); @@ -155,40 +149,19 @@ spdk_fio_start_poller(void *thread_ctx, return (struct spdk_poller *)fio_poller; } -static void -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; + struct spdk_fio_thread *fio_thread = thread_ctx; fio_poller = (struct spdk_fio_poller *)poller; - fio_thread = g_thread; - if (!fio_thread) { - SPDK_ERRLOG("Expected local thread to be initialized, but it was not.\n"); - return; - } - TAILQ_REMOVE(&fio_thread->pollers, fio_poller, link); free(fio_poller); } -static void -spdk_fio_bdev_stop_poller(struct spdk_bdev_poller **ppoller) -{ - spdk_poller_unregister((struct spdk_poller **)ppoller); -} - static int spdk_fio_init_thread(struct thread_data *td) { @@ -230,9 +203,6 @@ spdk_fio_init_thread(struct thread_data *td) TAILQ_INIT(&fio_thread->targets); - /* Cache the thread in a thread-local variable for easy access */ - g_thread = fio_thread; - return 0; } @@ -291,15 +261,13 @@ spdk_fio_init_env(struct thread_data *td) return -1; } - fio_thread = td->io_ops_data; + g_init_thread = fio_thread = td->io_ops_data; /* Initialize the copy engine */ spdk_copy_engine_initialize(); /* Initialize the bdev layer */ - spdk_bdev_initialize(spdk_fio_bdev_init_done, &done, - spdk_fio_bdev_start_poller, - spdk_fio_bdev_stop_poller); + spdk_bdev_initialize(spdk_fio_bdev_init_done, &done); do { /* Handle init and all cleanup events */ @@ -421,8 +389,6 @@ spdk_fio_cleanup_thread(struct spdk_fio_thread *fio_thread) while (spdk_fio_poll_thread(fio_thread) > 0) {} - g_thread = NULL; - spdk_free_thread(); spdk_ring_free(fio_thread->ring); free(fio_thread->iocq); @@ -700,7 +666,7 @@ spdk_fio_finish_env(void) size_t count; /* the same thread that called spdk_fio_init_env */ - fio_thread = g_thread; + fio_thread = g_init_thread; spdk_bdev_finish(spdk_fio_module_finish_done, &done); diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index fe85513cb..8f1f86613 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -113,29 +113,16 @@ struct spdk_bdev_io_stat { uint64_t num_write_ops; }; -struct spdk_bdev_poller; - typedef void (*spdk_bdev_init_cb)(void *cb_arg, int rc); typedef void (*spdk_bdev_fini_cb)(void *cb_arg); -typedef void (*spdk_bdev_poller_fn)(void *arg); -typedef void (*spdk_bdev_poller_start_cb)(struct spdk_bdev_poller **ppoller, - spdk_bdev_poller_fn fn, - void *arg, - uint64_t period_microseconds); -typedef void (*spdk_bdev_poller_stop_cb)(struct spdk_bdev_poller **ppoller); - /** * Initialize block device modules. * * \param cb_fn Called when the initialization is complete. * \param cb_arg Argument passed to function cb_fn. - * \param start_poller_fn This function is called to request starting a poller. - * \param stop_poller_fn This function is called to request stopping a poller. */ -void spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg, - spdk_bdev_poller_start_cb start_poller_fn, - spdk_bdev_poller_stop_cb stop_poller_fn); +void spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg); /** * Perform cleanup work to remove the registered block device modules. diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 782320c73..908f84469 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -396,29 +396,6 @@ int spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *d struct spdk_bdev_module_if *module); void spdk_bdev_module_release_bdev(struct spdk_bdev *bdev); -/** - * Start a poller on the current thread to periodically call fn. - * - * \param[out] ppoller Will be filled with initialized poller pointer. - * \param fn Function to run periodically. - * \param arg Argument to be passed to fn. - * \param period_microseconds Delay between calls of the poller function, - * or 0 to call as frequently as possible. - * - * The user must call spdk_bdev_poller_stop() to clean up the resources allocated by this function. - */ -void spdk_bdev_poller_start(struct spdk_bdev_poller **ppoller, - spdk_bdev_poller_fn fn, - void *arg, - uint64_t period_microseconds); - -/** - * Stop a poller started by spdk_bdev_poller_start(). - * - * \param ppoller Poller to stop. - */ -void spdk_bdev_poller_stop(struct spdk_bdev_poller **ppoller); - /** * Allocate a buffer for given bdev_io. Allocation will happen * only if the bdev_io has no assigned SGL yet. The buffer will be diff --git a/lib/bdev/aio/bdev_aio.c b/lib/bdev/aio/bdev_aio.c index f7fb21d7a..35ee2a4df 100644 --- a/lib/bdev/aio/bdev_aio.c +++ b/lib/bdev/aio/bdev_aio.c @@ -312,7 +312,7 @@ bdev_aio_create_cb(void *io_device, void *ctx_buf) return -1; } - spdk_bdev_poller_start(&ch->poller, bdev_aio_poll, ch, 0); + ch->poller = spdk_poller_register(bdev_aio_poll, ch, 0); return 0; } @@ -322,7 +322,7 @@ bdev_aio_destroy_cb(void *io_device, void *ctx_buf) struct bdev_aio_io_channel *io_channel = ctx_buf; io_destroy(io_channel->io_ctx); - spdk_bdev_poller_stop(&io_channel->poller); + spdk_poller_unregister(&io_channel->poller); } static struct spdk_io_channel * diff --git a/lib/bdev/aio/bdev_aio.h b/lib/bdev/aio/bdev_aio.h index 0c93e0b3f..c3bca41f9 100644 --- a/lib/bdev/aio/bdev_aio.h +++ b/lib/bdev/aio/bdev_aio.h @@ -51,7 +51,7 @@ struct bdev_aio_task { struct bdev_aio_io_channel { io_context_t io_ctx; - struct spdk_bdev_poller *poller; + struct spdk_poller *poller; }; struct file_disk { diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index a4c62333d..675ea2892 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -75,9 +75,6 @@ struct spdk_bdev_mgr { TAILQ_HEAD(, spdk_bdev) bdevs; - spdk_bdev_poller_start_cb start_poller_fn; - spdk_bdev_poller_stop_cb stop_poller_fn; - bool init_complete; bool module_init_complete; @@ -89,8 +86,6 @@ struct spdk_bdev_mgr { static struct spdk_bdev_mgr g_bdev_mgr = { .bdev_modules = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdev_modules), .bdevs = TAILQ_HEAD_INITIALIZER(g_bdev_mgr.bdevs), - .start_poller_fn = NULL, - .stop_poller_fn = NULL, .init_complete = false, .module_init_complete = false, }; @@ -456,26 +451,8 @@ spdk_bdev_modules_init(void) g_bdev_mgr.module_init_complete = true; return rc; } - void -spdk_bdev_poller_start(struct spdk_bdev_poller **ppoller, - spdk_bdev_poller_fn fn, - void *arg, - uint64_t period_microseconds) -{ - g_bdev_mgr.start_poller_fn(ppoller, fn, arg, period_microseconds); -} - -void -spdk_bdev_poller_stop(struct spdk_bdev_poller **ppoller) -{ - g_bdev_mgr.stop_poller_fn(ppoller); -} - -void -spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg, - spdk_bdev_poller_start_cb start_poller_fn, - spdk_bdev_poller_stop_cb stop_poller_fn) +spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg) { int cache_size; int rc = 0; @@ -486,9 +463,6 @@ spdk_bdev_initialize(spdk_bdev_init_cb cb_fn, void *cb_arg, g_init_cb_fn = cb_fn; g_init_cb_arg = cb_arg; - g_bdev_mgr.start_poller_fn = start_poller_fn; - g_bdev_mgr.stop_poller_fn = stop_poller_fn; - snprintf(mempool_name, sizeof(mempool_name), "bdev_io_%d", getpid()); g_bdev_mgr.bdev_io_pool = spdk_mempool_create(mempool_name, diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index ce2ed71c6..27409d37d 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -62,7 +62,7 @@ struct nvme_ctrlr { char *name; int ref; - struct spdk_bdev_poller *adminq_timer_poller; + struct spdk_poller *adminq_timer_poller; /** linked list pointer for device list */ TAILQ_ENTRY(nvme_ctrlr) tailq; @@ -78,7 +78,7 @@ struct nvme_bdev { struct nvme_io_channel { struct spdk_nvme_qpair *qpair; - struct spdk_bdev_poller *poller; + struct spdk_poller *poller; bool collect_spin_stat; uint64_t spin_ticks; @@ -129,7 +129,7 @@ static int g_timeout = 0; static int g_nvme_adminq_poll_timeout_us = 0; static bool g_nvme_hotplug_enabled = false; static int g_nvme_hotplug_poll_timeout_us = 0; -static struct spdk_bdev_poller *g_hotplug_poller; +static struct spdk_poller *g_hotplug_poller; static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER; static TAILQ_HEAD(, nvme_ctrlr) g_nvme_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_ctrlrs); @@ -249,7 +249,7 @@ bdev_nvme_destruct(void *ctx) TAILQ_REMOVE(&g_nvme_ctrlrs, nvme_ctrlr, tailq); pthread_mutex_unlock(&g_bdev_nvme_mutex); spdk_io_device_unregister(nvme_ctrlr->ctrlr, bdev_nvme_unregister_cb); - spdk_bdev_poller_stop(&nvme_ctrlr->adminq_timer_poller); + spdk_poller_unregister(&nvme_ctrlr->adminq_timer_poller); free(nvme_ctrlr->name); free(nvme_ctrlr); return 0; @@ -532,7 +532,7 @@ bdev_nvme_create_cb(void *io_device, void *ctx_buf) return -1; } - spdk_bdev_poller_start(&ch->poller, bdev_nvme_poll, ch, 0); + ch->poller = spdk_poller_register(bdev_nvme_poll, ch, 0); return 0; } @@ -542,7 +542,7 @@ bdev_nvme_destroy_cb(void *io_device, void *ctx_buf) struct nvme_io_channel *ch = ctx_buf; spdk_nvme_ctrlr_free_io_qpair(ch->qpair); - spdk_bdev_poller_stop(&ch->poller); + spdk_poller_unregister(&ch->poller); } static struct spdk_io_channel * @@ -871,8 +871,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, return; } - spdk_bdev_poller_start(&nvme_ctrlr->adminq_timer_poller, bdev_nvme_poll_adminq, ctrlr, - g_nvme_adminq_poll_timeout_us); + nvme_ctrlr->adminq_timer_poller = spdk_poller_register(bdev_nvme_poll_adminq, ctrlr, + g_nvme_adminq_poll_timeout_us); TAILQ_INSERT_TAIL(&g_nvme_ctrlrs, nvme_ctrlr, tailq); @@ -1100,8 +1100,8 @@ bdev_nvme_library_init(void) } if (g_nvme_hotplug_enabled) { - spdk_bdev_poller_start(&g_hotplug_poller, bdev_nvme_hotplug, NULL, - g_nvme_hotplug_poll_timeout_us); + g_hotplug_poller = spdk_poller_register(bdev_nvme_hotplug, NULL, + g_nvme_hotplug_poll_timeout_us); } end: @@ -1115,7 +1115,7 @@ bdev_nvme_library_fini(void) struct nvme_bdev *nvme_bdev, *btmp; if (g_nvme_hotplug_enabled) { - spdk_bdev_poller_stop(&g_hotplug_poller); + spdk_poller_unregister(&g_hotplug_poller); } TAILQ_FOREACH_SAFE(nvme_bdev, &g_nvme_bdevs, link, btmp) { diff --git a/lib/bdev/rbd/bdev_rbd.c b/lib/bdev/rbd/bdev_rbd.c index 9f06be8e1..e9a0b4428 100644 --- a/lib/bdev/rbd/bdev_rbd.c +++ b/lib/bdev/rbd/bdev_rbd.c @@ -68,7 +68,7 @@ struct bdev_rbd_io_channel { struct pollfd pfd; rbd_image_t image; struct bdev_rbd *disk; - struct spdk_bdev_poller *poller; + struct spdk_poller *poller; }; static void @@ -417,7 +417,7 @@ bdev_rbd_create_cb(void *io_device, void *ctx_buf) goto err; } - spdk_bdev_poller_start(&ch->poller, bdev_rbd_io_poll, ch, 0); + ch->poller = spdk_poller_register(bdev_rbd_io_poll, ch, 0); return 0; @@ -433,7 +433,7 @@ bdev_rbd_destroy_cb(void *io_device, void *ctx_buf) bdev_rbd_free_channel(io_channel); - spdk_bdev_poller_stop(&io_channel->poller); + spdk_poller_unregister(&io_channel->poller); } static struct spdk_io_channel * diff --git a/lib/bdev/virtio/bdev_virtio.c b/lib/bdev/virtio/bdev_virtio.c index 18438c9ae..2cf2d7324 100644 --- a/lib/bdev/virtio/bdev_virtio.c +++ b/lib/bdev/virtio/bdev_virtio.c @@ -547,7 +547,7 @@ bdev_virtio_create_cb(void *io_device, void *ctx_buf) ch->vdev = vdev; ch->vq = vq; - spdk_bdev_poller_start(&vq->poller, bdev_virtio_poll, ch, 0); + vq->poller = spdk_poller_register(bdev_virtio_poll, ch, 0); return 0; } @@ -559,7 +559,7 @@ bdev_virtio_destroy_cb(void *io_device, void *ctx_buf) struct virtio_dev *vdev = io_channel->vdev; struct virtqueue *vq = io_channel->vq; - spdk_bdev_poller_stop(&vq->poller); + spdk_poller_unregister(&vq->poller); virtio_dev_release_queue(vdev, vq->vq_queue_index); } @@ -604,7 +604,7 @@ scan_target_finish(struct virtio_scsi_scan_base *base) return; } - spdk_bdev_poller_stop(&base->vq->poller); + spdk_poller_unregister(&base->vq->poller); base->vq->poller_ctx = NULL; virtio_dev_release_queue(base->vdev, base->vq->vq_queue_index); @@ -627,7 +627,7 @@ scan_target_finish(struct virtio_scsi_scan_base *base) ctrlq = base->vdev->vqs[VIRTIO_SCSI_CONTROLQ]; ctrlq->poller_ctx = ctrlq_ring; - spdk_bdev_poller_start(&ctrlq->poller, bdev_virtio_ctrlq_poll, base->vdev, CTRLQ_POLL_PERIOD_US); + ctrlq->poller = spdk_poller_register(bdev_virtio_ctrlq_poll, base->vdev, CTRLQ_POLL_PERIOD_US); spdk_io_device_register(base->vdev, bdev_virtio_create_cb, bdev_virtio_destroy_cb, sizeof(struct bdev_virtio_io_channel)); @@ -1094,7 +1094,7 @@ bdev_virtio_scsi_free(struct virtio_dev *vdev) if (virtio_dev_queue_is_acquired(vdev, VIRTIO_SCSI_REQUESTQ)) { vq = vdev->vqs[VIRTIO_SCSI_REQUESTQ]; - spdk_bdev_poller_stop(&vq->poller); + spdk_poller_unregister(&vq->poller); spdk_dma_free(vq->poller_ctx); vq->poller_ctx = NULL; virtio_dev_release_queue(vdev, VIRTIO_SCSI_REQUESTQ); @@ -1145,7 +1145,7 @@ bdev_virtio_scsi_scan(struct virtio_dev *vdev, virtio_create_device_cb cb_fn, vo vq = vdev->vqs[VIRTIO_SCSI_REQUESTQ]; base->vq = vq; vq->poller_ctx = base; - spdk_bdev_poller_start(&vq->poller, bdev_scan_poll, base, 0); + vq->poller = spdk_poller_register(bdev_scan_poll, base, 0); rc = scan_target(base); if (rc) { SPDK_ERRLOG("Failed to start target scan.\n"); @@ -1218,7 +1218,7 @@ virtio_scsi_dev_unregister_cb(void *io_device) if (virtio_dev_queue_is_acquired(vdev, VIRTIO_SCSI_CONTROLQ)) { vq = vdev->vqs[VIRTIO_SCSI_CONTROLQ]; - spdk_bdev_poller_stop(&vq->poller); + spdk_poller_unregister(&vq->poller); send_ring = vq->poller_ctx; /* bdevs built on top of this vdev mustn't be destroyed with outstanding I/O. */ assert(spdk_ring_count(send_ring) == 0); diff --git a/lib/bdev/virtio/rte_virtio/virtio.h b/lib/bdev/virtio/rte_virtio/virtio.h index ad7c5ea16..8f425bd11 100644 --- a/lib/bdev/virtio/rte_virtio/virtio.h +++ b/lib/bdev/virtio/rte_virtio/virtio.h @@ -188,7 +188,7 @@ struct virtqueue { struct spdk_thread *owner_thread; /** Response poller. */ - struct spdk_bdev_poller *poller; + struct spdk_poller *poller; /** Context for response poller. */ void *poller_ctx; diff --git a/lib/event/subsystems/bdev/bdev.c b/lib/event/subsystems/bdev/bdev.c index 8ce00abb6..18ede849b 100644 --- a/lib/event/subsystems/bdev/bdev.c +++ b/lib/event/subsystems/bdev/bdev.c @@ -46,27 +46,10 @@ spdk_bdev_initialize_complete(void *cb_arg, int rc) spdk_subsystem_init_next(rc); } -static void -spdk_bdev_subsystem_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_bdev_subsystem_stop_poller(struct spdk_bdev_poller **ppoller) -{ - spdk_poller_unregister((struct spdk_poller **)ppoller); -} - static void spdk_bdev_subsystem_initialize(void) { - spdk_bdev_initialize(spdk_bdev_initialize_complete, NULL, - spdk_bdev_subsystem_start_poller, - spdk_bdev_subsystem_stop_poller); + spdk_bdev_initialize(spdk_bdev_initialize_complete, NULL); } static void diff --git a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c index 2b8dd29d6..5211cd7f8 100644 --- a/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c +++ b/test/unit/lib/bdev/mt/bdev.c/bdev_ut.c @@ -202,7 +202,7 @@ setup_test(void) bool done = false; allocate_threads(BDEV_UT_NUM_THREADS); - spdk_bdev_initialize(bdev_init_cb, &done, NULL, NULL); + spdk_bdev_initialize(bdev_init_cb, &done); register_bdev(); spdk_bdev_open(&g_bdev.bdev, true, NULL, NULL, &g_desc); }