diff --git a/include/spdk/env.h b/include/spdk/env.h index 68aff6d73e..ec7fb3be0b 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -978,6 +978,13 @@ typedef int (*spdk_mem_map_notify_cb)(void *cb_ctx, struct spdk_mem_map *map, enum spdk_mem_map_notify_action action, void *vaddr, size_t size); +/** + * A function table to be implemented by each memory map. + */ +struct spdk_mem_map_ops { + spdk_mem_map_notify_cb notify_cb; +}; + /** * Allocate a virtual memory address translation map. * diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index b2b3819645..73b30a21b3 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -82,7 +82,7 @@ struct spdk_mem_map { struct map_256tb map_256tb; pthread_mutex_t mutex; uint64_t default_translation; - spdk_mem_map_notify_cb notify_cb; + struct spdk_mem_map_ops ops; void *cb_ctx; TAILQ_ENTRY(spdk_mem_map) tailq; }; @@ -106,7 +106,7 @@ spdk_mem_map_notify_walk(struct spdk_mem_map *map, enum spdk_mem_map_notify_acti do { \ if (contig_start != 0) { \ /* End of of a virtually contiguous range */ \ - map->notify_cb(map->cb_ctx, map, action, \ + map->ops.notify_cb(map->cb_ctx, map, action, \ (void *)contig_start, \ contig_end - contig_start + 2 * 1024 * 1024); \ } \ @@ -166,7 +166,7 @@ spdk_mem_map_alloc(uint64_t default_translation, spdk_mem_map_notify_cb notify_c } map->default_translation = default_translation; - map->notify_cb = notify_cb; + map->ops.notify_cb = notify_cb; map->cb_ctx = cb_ctx; pthread_mutex_lock(&g_spdk_mem_map_mutex); @@ -245,7 +245,7 @@ spdk_mem_register(void *vaddr, size_t len) if (ref_count > 0) { if (seg_len > 0) { TAILQ_FOREACH(map, &g_spdk_mem_maps, tailq) { - rc = map->notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_REGISTER, seg_vaddr, seg_len); + rc = map->ops.notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_REGISTER, seg_vaddr, seg_len); if (rc != 0) { pthread_mutex_unlock(&g_spdk_mem_map_mutex); return rc; @@ -265,7 +265,7 @@ spdk_mem_register(void *vaddr, size_t len) if (seg_len > 0) { TAILQ_FOREACH(map, &g_spdk_mem_maps, tailq) { - rc = map->notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_REGISTER, seg_vaddr, seg_len); + rc = map->ops.notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_REGISTER, seg_vaddr, seg_len); if (rc != 0) { pthread_mutex_unlock(&g_spdk_mem_map_mutex); return rc; @@ -321,7 +321,7 @@ spdk_mem_unregister(void *vaddr, size_t len) if (ref_count > 1) { if (seg_len > 0) { TAILQ_FOREACH(map, &g_spdk_mem_maps, tailq) { - rc = map->notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_UNREGISTER, seg_vaddr, seg_len); + rc = map->ops.notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_UNREGISTER, seg_vaddr, seg_len); if (rc != 0) { pthread_mutex_unlock(&g_spdk_mem_map_mutex); return rc; @@ -341,7 +341,7 @@ spdk_mem_unregister(void *vaddr, size_t len) if (seg_len > 0) { TAILQ_FOREACH(map, &g_spdk_mem_maps, tailq) { - rc = map->notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_UNREGISTER, seg_vaddr, seg_len); + rc = map->ops.notify_cb(map->cb_ctx, map, SPDK_MEM_MAP_NOTIFY_UNREGISTER, seg_vaddr, seg_len); if (rc != 0) { pthread_mutex_unlock(&g_spdk_mem_map_mutex); return rc;