Merge branch 'zero_copy_write-3' into resolve-conflicts
Conflicts: lib/iscsi-command.c lib/pdu.c lib/socket.c
This commit is contained in:
56
lib/pdu.c
56
lib/pdu.c
@@ -61,8 +61,8 @@ iscsi_itt_post_increment(struct iscsi_context *iscsi) {
|
||||
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_with_itt_flags_size(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags, size_t payload_size)
|
||||
iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags)
|
||||
{
|
||||
struct iscsi_pdu *pdu;
|
||||
|
||||
@@ -73,14 +73,7 @@ iscsi_allocate_pdu_with_itt_flags_size(struct iscsi_context *iscsi, enum iscsi_o
|
||||
}
|
||||
|
||||
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
||||
pdu->outdata.alloc_size = 64;
|
||||
|
||||
/* payload_size is limited by negotiated max_recv_data_segment_length */
|
||||
if (payload_size > iscsi->target_max_recv_data_segment_length)
|
||||
payload_size = iscsi->target_max_recv_data_segment_length;
|
||||
|
||||
while (pdu->outdata.alloc_size < ISCSI_HEADER_SIZE+payload_size) pdu->outdata.alloc_size<<=1;
|
||||
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.alloc_size);
|
||||
pdu->outdata.data = iscsi_malloc(iscsi, pdu->outdata.size);
|
||||
memset(pdu->outdata.data, 0, ISCSI_HEADER_SIZE);
|
||||
|
||||
if (pdu->outdata.data == NULL) {
|
||||
@@ -108,13 +101,6 @@ iscsi_allocate_pdu_with_itt_flags_size(struct iscsi_context *iscsi, enum iscsi_o
|
||||
return pdu;
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_with_itt_flags(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, uint32_t itt, uint32_t flags)
|
||||
{
|
||||
return iscsi_allocate_pdu_with_itt_flags_size(iscsi, opcode, response_opcode, itt, flags, 0);
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode)
|
||||
@@ -122,15 +108,6 @@ iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
return iscsi_allocate_pdu_with_itt_flags(iscsi, opcode, response_opcode, iscsi_itt_post_increment(iscsi), 0);
|
||||
}
|
||||
|
||||
struct iscsi_pdu *
|
||||
iscsi_allocate_pdu_size(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
||||
enum iscsi_opcode response_opcode, size_t payload_size)
|
||||
{
|
||||
return iscsi_allocate_pdu_with_itt_flags_size(iscsi, opcode, response_opcode, iscsi_itt_post_increment(iscsi), 0, payload_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iscsi_free_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
{
|
||||
@@ -162,42 +139,31 @@ iscsi_add_data(struct iscsi_context *iscsi, struct iscsi_data *data,
|
||||
}
|
||||
|
||||
len = data->size + dsize;
|
||||
|
||||
aligned = len;
|
||||
if (pdualignment) {
|
||||
aligned = (aligned+3)&0xfffffffc;
|
||||
}
|
||||
|
||||
size_t new_alloc_size = data->alloc_size;
|
||||
if (new_alloc_size < 64) new_alloc_size=64;
|
||||
|
||||
while (aligned > new_alloc_size) new_alloc_size<<=1;
|
||||
|
||||
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);
|
||||
if (data->size == 0) {
|
||||
data->data = iscsi_malloc(iscsi, aligned);
|
||||
} else {
|
||||
data->data = iscsi_realloc(iscsi, data->data, aligned);
|
||||
}
|
||||
else
|
||||
if (data->alloc_size != new_alloc_size) {
|
||||
data->data = iscsi_realloc(iscsi, data->data, new_alloc_size);
|
||||
}
|
||||
|
||||
if (data->data == NULL) {
|
||||
iscsi_set_error(iscsi, "failed to allocate buffer for %d "
|
||||
"bytes", (int) len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
data->alloc_size = new_alloc_size;
|
||||
|
||||
memcpy(data->data + data->size, dptr, dsize);
|
||||
data->size += dsize;
|
||||
|
||||
if (len != aligned) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user