MEMORY add compatibility for qemu-kvm
qemu-kvm iscsi block driver calls iscsi_parse_full_url without a valid iscsi_context. The driver also creates its own scsi_task objects.
This commit is contained in:
@@ -140,7 +140,8 @@ iscsi_full_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
struct connect_task *ct;
|
struct connect_task *ct;
|
||||||
|
|
||||||
iscsi->lun = lun;
|
iscsi->lun = lun;
|
||||||
strncpy(iscsi->portal,portal,MAX_STRING_SIZE);
|
if (iscsi->portal != portal)
|
||||||
|
strncpy(iscsi->portal,portal,MAX_STRING_SIZE);
|
||||||
|
|
||||||
ct = iscsi_malloc(iscsi, sizeof(struct connect_task));
|
ct = iscsi_malloc(iscsi, sizeof(struct connect_task));
|
||||||
if (ct == NULL) {
|
if (ct == NULL) {
|
||||||
@@ -326,14 +327,13 @@ try_again:
|
|||||||
|
|
||||||
close(iscsi->fd);
|
close(iscsi->fd);
|
||||||
iscsi->fd = old_iscsi->fd;
|
iscsi->fd = old_iscsi->fd;
|
||||||
int _mallocs = old_iscsi->mallocs;
|
iscsi->mallocs+=old_iscsi->mallocs;
|
||||||
int _frees = old_iscsi->frees;
|
iscsi->frees+=old_iscsi->frees;
|
||||||
|
|
||||||
memcpy(old_iscsi, iscsi, sizeof(struct iscsi_context));
|
memcpy(old_iscsi, iscsi, sizeof(struct iscsi_context));
|
||||||
free(iscsi);
|
free(iscsi);
|
||||||
|
|
||||||
old_iscsi->is_reconnecting = 0;
|
old_iscsi->is_reconnecting = 0;
|
||||||
old_iscsi->mallocs+=_mallocs;
|
|
||||||
old_iscsi->frees+=_frees;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
11
lib/init.c
11
lib/init.c
@@ -424,11 +424,15 @@ iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full)
|
|||||||
if (tmp) *tmp=0;
|
if (tmp) *tmp=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
iscsi_url = iscsi_zmalloc(iscsi, sizeof(struct iscsi_url));
|
if (iscsi != NULL)
|
||||||
|
iscsi_url = iscsi_malloc(iscsi, sizeof(struct iscsi_url));
|
||||||
|
else
|
||||||
|
iscsi_url = malloc(sizeof(struct iscsi_url));
|
||||||
if (iscsi_url == NULL) {
|
if (iscsi_url == NULL) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to allocate iscsi_url structure");
|
iscsi_set_error(iscsi, "Out-of-memory: Failed to allocate iscsi_url structure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
memset(iscsi_url, 0, sizeof(struct iscsi_url));
|
||||||
iscsi_url->iscsi= iscsi;
|
iscsi_url->iscsi= iscsi;
|
||||||
|
|
||||||
strncpy(iscsi_url->portal,portal,MAX_STRING_SIZE);
|
strncpy(iscsi_url->portal,portal,MAX_STRING_SIZE);
|
||||||
@@ -461,7 +465,10 @@ iscsi_parse_portal_url(struct iscsi_context *iscsi, const char *url)
|
|||||||
void
|
void
|
||||||
iscsi_destroy_url(struct iscsi_url *iscsi_url)
|
iscsi_destroy_url(struct iscsi_url *iscsi_url)
|
||||||
{
|
{
|
||||||
iscsi_free(iscsi_url->iscsi, iscsi_url);
|
if (iscsi_url->iscsi != NULL)
|
||||||
|
iscsi_free(iscsi_url->iscsi, iscsi_url);
|
||||||
|
else
|
||||||
|
free(iscsi_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,21 @@ scsi_free_scsi_task(struct scsi_task *task)
|
|||||||
{
|
{
|
||||||
struct scsi_allocated_memory *mem;
|
struct scsi_allocated_memory *mem;
|
||||||
|
|
||||||
while ((mem = task->mem)) {
|
if (task->iscsi != NULL) {
|
||||||
SLIST_REMOVE(&task->mem, mem);
|
while ((mem = task->mem)) {
|
||||||
iscsi_free(task->iscsi, mem);
|
SLIST_REMOVE(&task->mem, mem);
|
||||||
|
iscsi_free(task->iscsi, mem);
|
||||||
|
}
|
||||||
|
iscsi_free(task->iscsi,task->datain.data);
|
||||||
|
iscsi_free(task->iscsi,task);
|
||||||
|
} else {
|
||||||
|
while ((mem = task->mem)) {
|
||||||
|
SLIST_REMOVE(&task->mem, mem);
|
||||||
|
free(mem);
|
||||||
|
}
|
||||||
|
free(task->datain.data);
|
||||||
|
free(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
iscsi_free(task->iscsi,task->datain.data);
|
|
||||||
iscsi_free(task->iscsi,task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct scsi_task *
|
struct scsi_task *
|
||||||
@@ -68,10 +76,14 @@ void *
|
|||||||
scsi_malloc(struct scsi_task *task, size_t size)
|
scsi_malloc(struct scsi_task *task, size_t size)
|
||||||
{
|
{
|
||||||
struct scsi_allocated_memory *mem;
|
struct scsi_allocated_memory *mem;
|
||||||
mem = iscsi_zmalloc(task->iscsi,sizeof(struct scsi_allocated_memory) + size);
|
if (task->iscsi != NULL)
|
||||||
|
mem = iscsi_malloc(task->iscsi,sizeof(struct scsi_allocated_memory) + size);
|
||||||
|
else
|
||||||
|
mem = malloc(sizeof(struct scsi_allocated_memory) + size);
|
||||||
if (mem == NULL) {
|
if (mem == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
memset(mem, 0, sizeof(struct scsi_allocated_memory) + size);
|
||||||
mem->ptr = (void *) ((uintptr_t)mem + sizeof(struct scsi_allocated_memory));
|
mem->ptr = (void *) ((uintptr_t)mem + sizeof(struct scsi_allocated_memory));
|
||||||
SLIST_ADD(&task->mem, mem);
|
SLIST_ADD(&task->mem, mem);
|
||||||
return mem->ptr;
|
return mem->ptr;
|
||||||
|
|||||||
@@ -568,7 +568,9 @@ void
|
|||||||
iscsi_free_iscsi_in_pdu(struct iscsi_context *iscsi, struct iscsi_in_pdu *in)
|
iscsi_free_iscsi_in_pdu(struct iscsi_context *iscsi, struct iscsi_in_pdu *in)
|
||||||
{
|
{
|
||||||
iscsi_free(iscsi, in->data);
|
iscsi_free(iscsi, in->data);
|
||||||
|
in->data=NULL;
|
||||||
iscsi_free(iscsi, in);
|
iscsi_free(iscsi, in);
|
||||||
|
in=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user