Transport: allocate a global array of transports
Currently the new transport is dynamically allocated and looks like not freed when the application exits. Trying to use the __attribute__((destructor)) function to free the allocated memory, it will not work in the case of user created thread as this function is called right after the "main" function while other operations may be still ongoing. In this case, add a global array of transports. Change-Id: I610b1e8114ba2e68abbd09ea5e02a9abce055e70 Signed-off-by: GangCao <gang.cao@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2415 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Xiaodong Liu <xiaodong.liu@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
4664d683cc
commit
2234bb665d
@ -38,6 +38,8 @@
|
||||
#include "nvme_internal.h"
|
||||
#include "spdk/queue.h"
|
||||
|
||||
#define SPDK_MAX_NUM_OF_TRANSPORTS 16
|
||||
|
||||
struct spdk_nvme_transport {
|
||||
struct spdk_nvme_transport_ops ops;
|
||||
TAILQ_ENTRY(spdk_nvme_transport) link;
|
||||
@ -46,6 +48,9 @@ struct spdk_nvme_transport {
|
||||
TAILQ_HEAD(nvme_transport_list, spdk_nvme_transport) g_spdk_nvme_transports =
|
||||
TAILQ_HEAD_INITIALIZER(g_spdk_nvme_transports);
|
||||
|
||||
struct spdk_nvme_transport g_spdk_transports[SPDK_MAX_NUM_OF_TRANSPORTS] = {};
|
||||
int g_current_transport_index = 0;
|
||||
|
||||
const struct spdk_nvme_transport *
|
||||
nvme_get_first_transport(void)
|
||||
{
|
||||
@ -101,12 +106,12 @@ void spdk_nvme_transport_register(const struct spdk_nvme_transport_ops *ops)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
new_transport = calloc(1, sizeof(*new_transport));
|
||||
if (new_transport == NULL) {
|
||||
SPDK_ERRLOG("Unable to allocate memory to register new NVMe transport.\n");
|
||||
if (g_current_transport_index == SPDK_MAX_NUM_OF_TRANSPORTS) {
|
||||
SPDK_ERRLOG("Unable to register new NVMe transport.\n");
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
new_transport = &g_spdk_transports[g_current_transport_index++];
|
||||
|
||||
new_transport->ops = *ops;
|
||||
TAILQ_INSERT_TAIL(&g_spdk_nvme_transports, new_transport, link);
|
||||
|
Loading…
Reference in New Issue
Block a user