From bc64420badb76d2b314ee4786868d73ed57d0bfa Mon Sep 17 00:00:00 2001 From: Roy Shterman Date: Fri, 27 May 2016 18:47:18 +0300 Subject: [PATCH] Libiscsi: Changing header iscsi_in_pdu socket: need to malloc hdr include/iscsi-private: changing iscsi_in_pdu hdr to char* instead of static array for more convinient iser pdu creation. To use iscsi_in_pdu in iSER without making a copy of it we need to change hdr to pointer from static array, Because of that, iscsi_tcp flow need to do szmalloc (small zero malloc) hdr when creating new iscsi_in_pdu. iscsi_in_pdu is being malloced once per each received pdu. This change is reducing iscsi_in_pdu struct size but adding extra allocation of the same size we reduced from the struct. Signed-off-by: Roy Shterman --- include/iscsi-private.h | 2 +- lib/socket.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 4892154..9e5f5ef 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -55,7 +55,7 @@ struct iscsi_in_pdu { struct iscsi_in_pdu *next; long long hdr_pos; - unsigned char hdr[ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE]; + unsigned char *hdr; long long data_pos; unsigned char *data; diff --git a/lib/socket.c b/lib/socket.c index efdf83d..71a715c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -549,6 +549,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi) if (iscsi->incoming == NULL) { iscsi->incoming = iscsi_szmalloc(iscsi, sizeof(struct iscsi_in_pdu)); + iscsi->incoming->hdr = iscsi_szmalloc(iscsi, ISCSI_RAW_HEADER_SIZE + ISCSI_DIGEST_SIZE); if (iscsi->incoming == NULL) { iscsi_set_error(iscsi, "Out-of-memory: failed to malloc iscsi_in_pdu"); return -1; @@ -951,6 +952,7 @@ static int iscsi_tcp_queue_pdu(struct iscsi_context *iscsi, void iscsi_free_iscsi_in_pdu(struct iscsi_context *iscsi, struct iscsi_in_pdu *in) { + iscsi_free(iscsi, in->hdr); iscsi_free(iscsi, in->data); in->data=NULL; iscsi_sfree(iscsi, in);