diff --git a/CHANGELOG.md b/CHANGELOG.md index 042e0bbf48..50f2702f3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ The size parameter of spdk_mem_map_translate is now a pointer. This allows the function to report back the actual size of the translation relative to the original request made by the user. +A new structure spdk_mem_map_ops has been introduced to hold memory map related +callbacks. This structure is now passed as the second argument of spdk_mem_map_alloc +in lieu of the notify callback. + ### iscsi Parameter names of `set_iscsi_options` and `get_iscsi_global_params` RPC diff --git a/include/spdk/env.h b/include/spdk/env.h index ae06511ffb..8df04e6d3d 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -990,13 +990,13 @@ struct spdk_mem_map_ops { * Allocate a virtual memory address translation map. * * \param default_translation Default translation for the map. - * \param notify_cb Callback function to notify the mapping. + * \param ops Table of callback functions for map operations. * \param cb_ctx Argument passed to the callback function. * * \return a pointer to the allocated virtual memory address translation map. */ struct spdk_mem_map *spdk_mem_map_alloc(uint64_t default_translation, - spdk_mem_map_notify_cb notify_cb, void *cb_ctx); + const struct spdk_mem_map_ops *ops, void *cb_ctx); /** * Free a memory map previously allocated by spdk_mem_map_alloc(). diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 44ef4ce73e..a7618732df 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -151,7 +151,7 @@ spdk_mem_map_notify_walk(struct spdk_mem_map *map, enum spdk_mem_map_notify_acti } struct spdk_mem_map * -spdk_mem_map_alloc(uint64_t default_translation, spdk_mem_map_notify_cb notify_cb, void *cb_ctx) +spdk_mem_map_alloc(uint64_t default_translation, const struct spdk_mem_map_ops *ops, void *cb_ctx) { struct spdk_mem_map *map; @@ -166,12 +166,14 @@ spdk_mem_map_alloc(uint64_t default_translation, spdk_mem_map_notify_cb notify_c } map->default_translation = default_translation; - map->ops.notify_cb = notify_cb; map->cb_ctx = cb_ctx; + if (ops) { + map->ops = *ops; + } pthread_mutex_lock(&g_spdk_mem_map_mutex); - if (notify_cb) { + if (ops && ops->notify_cb) { spdk_mem_map_notify_walk(map, SPDK_MEM_MAP_NOTIFY_REGISTER); TAILQ_INSERT_TAIL(&g_spdk_mem_maps, map, tailq); } diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index a936130d16..3b330931fd 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -604,11 +604,15 @@ spdk_vtophys_pci_device_removed(struct rte_pci_device *pci_device) int spdk_vtophys_init(void) { + const struct spdk_mem_map_ops vtophys_map_ops = { + .notify_cb = spdk_vtophys_notify + }; + #if SPDK_VFIO_ENABLED spdk_vtophys_iommu_init(); #endif - g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, spdk_vtophys_notify, NULL); + g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, &vtophys_map_ops, NULL); if (g_vtophys_map == NULL) { DEBUG_PRINT("vtophys map allocation failed\n"); return -1; diff --git a/lib/nvme/nvme_rdma.c b/lib/nvme/nvme_rdma.c index 2aff646d52..3496387446 100644 --- a/lib/nvme/nvme_rdma.c +++ b/lib/nvme/nvme_rdma.c @@ -631,12 +631,14 @@ nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map, return rc; } - static int nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair) { struct ibv_pd *pd = rqpair->cm_id->qp->pd; struct spdk_nvme_rdma_mr_map *mr_map; + const struct spdk_mem_map_ops nvme_rdma_map_ops = { + .notify_cb = nvme_rdma_mr_map_notify + }; pthread_mutex_lock(&g_rdma_mr_maps_mutex); @@ -659,7 +661,7 @@ nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair) mr_map->ref = 1; mr_map->pd = pd; - mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, nvme_rdma_mr_map_notify, pd); + mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, &nvme_rdma_map_ops, pd); if (mr_map->map == NULL) { SPDK_ERRLOG("spdk_mem_map_alloc() failed\n"); free(mr_map); diff --git a/lib/nvmf/rdma.c b/lib/nvmf/rdma.c index 9992cf1c68..c33b4af92f 100644 --- a/lib/nvmf/rdma.c +++ b/lib/nvmf/rdma.c @@ -1634,6 +1634,10 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_transport_opts *opts) int flag; uint32_t sge_count; + const struct spdk_mem_map_ops nvmf_rdma_map_ops = { + .notify_cb = spdk_nvmf_rdma_mem_notify + }; + rtransport = calloc(1, sizeof(*rtransport)); if (!rtransport) { return NULL; @@ -1766,7 +1770,7 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_transport_opts *opts) break; } - device->map = spdk_mem_map_alloc(0, spdk_nvmf_rdma_mem_notify, device); + device->map = spdk_mem_map_alloc(0, &nvmf_rdma_map_ops, device); if (!device->map) { SPDK_ERRLOG("Unable to allocate memory map for new poll group\n"); ibv_dealloc_pd(device->pd); diff --git a/test/env/memory/memory_ut.c b/test/env/memory/memory_ut.c index 23e64a3e87..39a80c1213 100644 --- a/test/env/memory/memory_ut.c +++ b/test/env/memory/memory_ut.c @@ -96,13 +96,17 @@ test_mem_map_notify(void *cb_ctx, struct spdk_mem_map *map, return 0; } +const struct spdk_mem_map_ops test_mem_map_ops = { + .notify_cb = test_mem_map_notify +}; + static void test_mem_map_alloc_free(void) { struct spdk_mem_map *map; uint64_t default_translation = 0xDEADBEEF0BADF00D; - map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL); + map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL); SPDK_CU_ASSERT_FATAL(map != NULL); spdk_mem_map_free(&map); @@ -117,7 +121,7 @@ test_mem_map_translation(void) uint64_t addr; int rc; - map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL); + map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL); SPDK_CU_ASSERT_FATAL(map != NULL); /* Try to get translation for address with no translation */ @@ -204,7 +208,7 @@ test_mem_map_registration(void) struct spdk_mem_map *map; uint64_t default_translation = 0xDEADBEEF0BADF00D; - map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL); + map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL); SPDK_CU_ASSERT_FATAL(map != NULL); /* Unregister memory region that wasn't previously registered */ diff --git a/test/env/vtophys/vtophys.c b/test/env/vtophys/vtophys.c index 435c26d0e0..0387e36c20 100644 --- a/test/env/vtophys/vtophys.c +++ b/test/env/vtophys/vtophys.c @@ -135,8 +135,12 @@ mem_map_test(void) { struct spdk_mem_map *map; uint64_t default_translation = 0xDEADBEEF0BADF00D; + const struct spdk_mem_map_ops test_map_ops = { + .notify_cb = test_map_notify + }; - map = spdk_mem_map_alloc(default_translation, test_map_notify, NULL); + + map = spdk_mem_map_alloc(default_translation, &test_map_ops, NULL); if (map == NULL) { return 1; }