init: make LIBISCSI_CACHE_ALLOCATIONS a public environment variable

this variable was introduced for iscsi-test-cu only. This patch
makes it a generic environment variable that can be set per context.

Signed-off-by: Peter Lieven <pl@kamp.de>
This commit is contained in:
Peter Lieven
2015-05-05 14:10:44 +02:00
parent 724f44c31b
commit b4098c535e
5 changed files with 12 additions and 11 deletions
+1
View File
@@ -153,6 +153,7 @@ struct iscsi_context {
void* smalloc_ptrs[SMALL_ALLOC_MAX_FREE]; void* smalloc_ptrs[SMALL_ALLOC_MAX_FREE];
int smalloc_free; int smalloc_free;
size_t smalloc_size; size_t smalloc_size;
int cache_allocations;
time_t next_reconnect; time_t next_reconnect;
int scsi_timeout; int scsi_timeout;
+1 -1
View File
@@ -51,7 +51,7 @@ struct sockaddr;
"<host>[:<port>]\"" "<host>[:<port>]\""
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 * The following three functions are used to integrate libiscsi in an event
+1
View File
@@ -411,6 +411,7 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi)
iscsi->tcp_keepcnt = old_iscsi->tcp_keepcnt; iscsi->tcp_keepcnt = old_iscsi->tcp_keepcnt;
iscsi->tcp_keepintvl = old_iscsi->tcp_keepintvl; iscsi->tcp_keepintvl = old_iscsi->tcp_keepintvl;
iscsi->tcp_syncnt = old_iscsi->tcp_syncnt; iscsi->tcp_syncnt = old_iscsi->tcp_syncnt;
iscsi->cache_allocations = old_iscsi->cache_allocations;
iscsi->reconnect_max_retries = old_iscsi->reconnect_max_retries; iscsi->reconnect_max_retries = old_iscsi->reconnect_max_retries;
+9 -5
View File
@@ -33,15 +33,13 @@
#include "iscsi-private.h" #include "iscsi-private.h"
#include "slist.h" #include "slist.h"
int cache_allocations = 1;
/** /**
* Whether or not the internal memory allocator caches allocations. Disable * Whether or not the internal memory allocator caches allocations. Disable
* memory allocation caching to improve the accuracy of Valgrind reports. * 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) { 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) { if (ptr == NULL) {
return; return;
} }
if (cache_allocations) { if (iscsi->cache_allocations) {
if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) { if (iscsi->smalloc_free == SMALL_ALLOC_MAX_FREE) {
int i; int i;
/* SMALL_ALLOC_MAX_FREE should be adjusted that this */ /* SMALL_ALLOC_MAX_FREE should be adjusted that this */
@@ -122,6 +120,7 @@ iscsi_create_context(const char *initiator_name)
{ {
struct iscsi_context *iscsi; struct iscsi_context *iscsi;
size_t required = ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE; size_t required = ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE;
char *ca;
if (!initiator_name[0]) { if (!initiator_name[0]) {
return NULL; 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); 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; return iscsi;
} }
-5
View File
@@ -971,11 +971,6 @@ main(int argc, char *argv[])
}; };
int i, c; int i, c;
int opt_idx = 0; 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)); sd = malloc(sizeof(struct scsi_device));
memset(sd, '\0', sizeof(struct scsi_device)); memset(sd, '\0', sizeof(struct scsi_device));