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:
14
lib/init.c
14
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user