Merge pull request #279 from ddiss/fix-nopin-data
fix NOP-In data segment handling and cleanup ISCSI_HEADER_SIZE usage
This commit is contained in:
@@ -86,7 +86,8 @@ void nop_out_cb(struct iscsi_context *iscsi, int status, void *command_data, voi
|
|||||||
|
|
||||||
printf("NOP-IN status:%d\n", status);
|
printf("NOP-IN status:%d\n", status);
|
||||||
if (data->size > 0) {
|
if (data->size > 0) {
|
||||||
printf("NOP-IN data:%s\n", data->data);
|
printf("NOP-IN (%zu) data:%.*s\n",
|
||||||
|
data->size, (int)data->size, data->data);
|
||||||
}
|
}
|
||||||
printf("Send SYNCHRONIZECACHE10\n");
|
printf("Send SYNCHRONIZECACHE10\n");
|
||||||
task = iscsi_synchronizecache10_task(iscsi, 2, 0, 0, 0, 0, synccache10_cb, private_data);
|
task = iscsi_synchronizecache10_task(iscsi, 2, 0, 0, 0, 0, synccache10_cb, private_data);
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ extern "C" {
|
|||||||
#define ISCSI_RAW_HEADER_SIZE 48
|
#define ISCSI_RAW_HEADER_SIZE 48
|
||||||
#define ISCSI_DIGEST_SIZE 4
|
#define ISCSI_DIGEST_SIZE 4
|
||||||
|
|
||||||
#define ISCSI_HEADER_SIZE (ISCSI_RAW_HEADER_SIZE \
|
#define ISCSI_HEADER_SIZE(hdr_digest) (ISCSI_RAW_HEADER_SIZE \
|
||||||
+ (iscsi->header_digest == ISCSI_HEADER_DIGEST_NONE?0:ISCSI_DIGEST_SIZE))
|
+ (hdr_digest == ISCSI_HEADER_DIGEST_NONE?0:ISCSI_DIGEST_SIZE))
|
||||||
|
|
||||||
#define SMALL_ALLOC_MAX_FREE (128) /* must be power of 2 */
|
#define SMALL_ALLOC_MAX_FREE (128) /* must be power of 2 */
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
|
|||||||
data.data = NULL;
|
data.data = NULL;
|
||||||
data.size = 0;
|
data.size = 0;
|
||||||
|
|
||||||
if (in->data_pos > ISCSI_HEADER_SIZE) {
|
if (in->data_pos) {
|
||||||
data.data = in->data;
|
data.data = in->data;
|
||||||
data.size = in->data_pos;
|
data.size = in->data_pos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pdu->outdata.size = ISCSI_HEADER_SIZE;
|
pdu->outdata.size = ISCSI_HEADER_SIZE(iscsi->header_digest);
|
||||||
pdu->outdata.data = iscsi_szmalloc(iscsi, pdu->outdata.size);
|
pdu->outdata.data = iscsi_szmalloc(iscsi, pdu->outdata.size);
|
||||||
|
|
||||||
if (pdu->outdata.data == NULL) {
|
if (pdu->outdata.data == NULL) {
|
||||||
@@ -236,7 +236,7 @@ iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
|
|||||||
|
|
||||||
/* update data segment length */
|
/* update data segment length */
|
||||||
scsi_set_uint32(&pdu->outdata.data[4], pdu->outdata.size
|
scsi_set_uint32(&pdu->outdata.data[4], pdu->outdata.size
|
||||||
- ISCSI_HEADER_SIZE);
|
- ISCSI_HEADER_SIZE(iscsi->header_digest));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
15
lib/socket.c
15
lib/socket.c
@@ -596,25 +596,30 @@ static int
|
|||||||
iscsi_read_from_socket(struct iscsi_context *iscsi)
|
iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||||
{
|
{
|
||||||
struct iscsi_in_pdu *in;
|
struct iscsi_in_pdu *in;
|
||||||
ssize_t data_size, count, padding_size;
|
ssize_t hdr_size, data_size, count, padding_size;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
hdr_size = ISCSI_HEADER_SIZE(iscsi->header_digest);
|
||||||
if (iscsi->incoming == NULL) {
|
if (iscsi->incoming == NULL) {
|
||||||
iscsi->incoming = iscsi_szmalloc(iscsi, sizeof(struct iscsi_in_pdu));
|
iscsi->incoming = iscsi_szmalloc(iscsi, sizeof(struct iscsi_in_pdu));
|
||||||
iscsi->incoming->hdr = iscsi_smalloc(iscsi, ISCSI_HEADER_SIZE);
|
|
||||||
if (iscsi->incoming == NULL) {
|
if (iscsi->incoming == NULL) {
|
||||||
iscsi_set_error(iscsi, "Out-of-memory: failed to malloc iscsi_in_pdu");
|
iscsi_set_error(iscsi, "Out-of-memory: failed to malloc iscsi_in_pdu");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
iscsi->incoming->hdr = iscsi_smalloc(iscsi, hdr_size);
|
||||||
|
if (iscsi->incoming->hdr == NULL) {
|
||||||
|
iscsi_set_error(iscsi, "Out-of-memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
in = iscsi->incoming;
|
in = iscsi->incoming;
|
||||||
|
|
||||||
/* first we must read the header, including any digests */
|
/* first we must read the header, including any digests */
|
||||||
if (in->hdr_pos < ISCSI_HEADER_SIZE) {
|
if (in->hdr_pos < hdr_size) {
|
||||||
/* try to only read the header, the socket is nonblocking, so
|
/* try to only read the header, the socket is nonblocking, so
|
||||||
* no need to limit the read to what is available in the socket
|
* no need to limit the read to what is available in the socket
|
||||||
*/
|
*/
|
||||||
count = ISCSI_HEADER_SIZE - in->hdr_pos;
|
count = hdr_size - in->hdr_pos;
|
||||||
count = recv(iscsi->fd, &in->hdr[in->hdr_pos], count, 0);
|
count = recv(iscsi->fd, &in->hdr[in->hdr_pos], count, 0);
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
/* remote side has closed the socket. */
|
/* remote side has closed the socket. */
|
||||||
@@ -631,7 +636,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
|||||||
in->hdr_pos += count;
|
in->hdr_pos += count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in->hdr_pos < ISCSI_HEADER_SIZE) {
|
if (in->hdr_pos < hdr_size) {
|
||||||
/* we don't have the full header yet, so return */
|
/* we don't have the full header yet, so return */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user