Remove the iscsi data alloc_size field.
Avoiding to realloc data over and over should rather be handled with something similar to iovectors instead.
This commit is contained in:
@@ -537,7 +537,6 @@ iscsi_task_mgmt_target_cold_reset_async(struct iscsi_context *iscsi,
|
|||||||
|
|
||||||
struct iscsi_data {
|
struct iscsi_data {
|
||||||
int size;
|
int size;
|
||||||
size_t alloc_size;
|
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -438,7 +438,7 @@ iscsi_process_scsi_data_in(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
|
|||||||
/* Dont add to reassembly buffer if we already have a user buffer */
|
/* Dont add to reassembly buffer if we already have a user buffer */
|
||||||
if (scsi_task_get_data_in_buffer(task, 0, NULL) == NULL) {
|
if (scsi_task_get_data_in_buffer(task, 0, NULL) == NULL) {
|
||||||
if (task->expxferlen > dsl && pdu->indata.data == NULL) {
|
if (task->expxferlen > dsl && pdu->indata.data == NULL) {
|
||||||
pdu->indata.alloc_size = task->expxferlen;
|
pdu->indata.size = task->expxferlen;
|
||||||
pdu->indata.data = iscsi_malloc(iscsi, task->expxferlen);
|
pdu->indata.data = iscsi_malloc(iscsi, task->expxferlen);
|
||||||
if (pdu->indata.data == NULL) {
|
if (pdu->indata.data == NULL) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: failed to allocate pdu indata buffer");
|
iscsi_set_error(iscsi, "Out-of-memory: failed to allocate pdu indata buffer");
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode
|
|||||||
}
|
}
|
||||||
|
|
||||||
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
||||||
pdu->outdata.alloc_size = 64;
|
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.size);
|
||||||
|
|
||||||
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.alloc_size);
|
|
||||||
memset(pdu->outdata.data, 0, ISCSI_HEADER_SIZE);
|
memset(pdu->outdata.data, 0, ISCSI_HEADER_SIZE);
|
||||||
|
|
||||||
if (pdu->outdata.data == NULL) {
|
if (pdu->outdata.data == NULL) {
|
||||||
@@ -117,42 +115,31 @@ iscsi_add_data(struct iscsi_context *iscsi, struct iscsi_data *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = data->size + dsize;
|
len = data->size + dsize;
|
||||||
|
|
||||||
aligned = len;
|
aligned = len;
|
||||||
if (pdualignment) {
|
if (pdualignment) {
|
||||||
aligned = (aligned+3)&0xfffffffc;
|
aligned = (aligned+3)&0xfffffffc;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t new_alloc_size = data->alloc_size;
|
if (data->size == 0) {
|
||||||
if (new_alloc_size < 64) new_alloc_size=64;
|
data->data = iscsi_malloc(iscsi, aligned);
|
||||||
|
} else {
|
||||||
while (aligned > new_alloc_size) new_alloc_size<<=1;
|
data->data = iscsi_realloc(iscsi, data->data, aligned);
|
||||||
|
|
||||||
if (data->data != NULL && data->alloc_size == 0) data->alloc_size=data->size;
|
|
||||||
|
|
||||||
if (data->alloc_size == 0) {
|
|
||||||
data->data = iscsi_malloc(iscsi, new_alloc_size);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
if (data->alloc_size != new_alloc_size) {
|
|
||||||
data->data = iscsi_realloc(iscsi, data->data, new_alloc_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data->data == NULL) {
|
if (data->data == NULL) {
|
||||||
iscsi_set_error(iscsi, "failed to allocate buffer for %d "
|
iscsi_set_error(iscsi, "failed to allocate buffer for %d "
|
||||||
"bytes", (int) len);
|
"bytes", (int) len);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->alloc_size = new_alloc_size;
|
|
||||||
memcpy(data->data + data->size, dptr, dsize);
|
memcpy(data->data + data->size, dptr, dsize);
|
||||||
|
data->size += dsize;
|
||||||
|
|
||||||
if (len != aligned) {
|
if (len != aligned) {
|
||||||
/* zero out any padding at the end */
|
/* zero out any padding at the end */
|
||||||
memset(data->data+len, 0, aligned-len);
|
memset(data->data + len, 0, aligned - len);
|
||||||
}
|
}
|
||||||
|
|
||||||
data->size = len;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user