diff --git a/include/iscsi-private.h b/include/iscsi-private.h index f5efd84..00f215c 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -153,6 +153,7 @@ struct iscsi_context { void* smalloc_ptrs[SMALL_ALLOC_MAX_FREE]; int smalloc_free; size_t smalloc_size; + int cache_allocations; time_t next_reconnect; int scsi_timeout; diff --git a/include/iscsi.h b/include/iscsi.h index c8f41bb..7aa2a44 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -51,7 +51,7 @@ struct sockaddr; "[:]\"" -EXTERN void iscsi_set_cache_allocations(int ca); +EXTERN void iscsi_set_cache_allocations(struct iscsi_context *iscsi, int ca); /* * The following three functions are used to integrate libiscsi in an event diff --git a/lib/connect.c b/lib/connect.c index dec2a4b..2fecb6c 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -411,6 +411,7 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi) iscsi->tcp_keepcnt = old_iscsi->tcp_keepcnt; iscsi->tcp_keepintvl = old_iscsi->tcp_keepintvl; iscsi->tcp_syncnt = old_iscsi->tcp_syncnt; + iscsi->cache_allocations = old_iscsi->cache_allocations; iscsi->reconnect_max_retries = old_iscsi->reconnect_max_retries; diff --git a/lib/init.c b/lib/init.c index 54dd1b1..0f40468 100644 --- a/lib/init.c +++ b/lib/init.c @@ -33,15 +33,13 @@ #include "iscsi-private.h" #include "slist.h" -int cache_allocations = 1; - /** * Whether or not the internal memory allocator caches allocations. Disable * memory allocation caching to improve the accuracy of Valgrind reports. */ -void iscsi_set_cache_allocations(int ca) +void iscsi_set_cache_allocations(struct iscsi_context *iscsi, int ca) { - cache_allocations = ca; + iscsi->cache_allocations = ca; } void* iscsi_malloc(struct iscsi_context *iscsi, size_t size) { @@ -96,7 +94,7 @@ void iscsi_sfree(struct iscsi_context *iscsi, void* ptr) { if (ptr == NULL) { return; } - if (cache_allocations) { + if (iscsi->cache_allocations) { if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) { int i; /* SMALL_ALLOC_MAX_FREE should be adjusted that this */ @@ -122,6 +120,7 @@ iscsi_create_context(const char *initiator_name) { struct iscsi_context *iscsi; size_t required = ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE; + char *ca; if (!initiator_name[0]) { return NULL; @@ -204,6 +203,11 @@ iscsi_create_context(const char *initiator_name) } ISCSI_LOG(iscsi,5,"small allocation size is %d byte", iscsi->smalloc_size); + ca = getenv("LIBISCSI_CACHE_ALLOCATIONS"); + if (!ca || atoi(ca) != 0) { + iscsi->cache_allocations = 1; + } + return iscsi; } diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 7aa90f1..ae236b2 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -971,11 +971,6 @@ main(int argc, char *argv[]) }; int i, c; int opt_idx = 0; - char *ca; - - ca = getenv("LIBISCSI_CACHE_ALLOCATIONS"); - if (ca && atoi(ca) == 0) - iscsi_set_cache_allocations(0); sd = malloc(sizeof(struct scsi_device)); memset(sd, '\0', sizeof(struct scsi_device));