From 32228a450941c7ecb44ecdf9e5d38997a93f3675 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 2 Jan 2011 12:50:00 +1100 Subject: [PATCH] Negotiate InitialR2T during login. Default to offer No, but update and accept what Target responds. Store the result of the negotiated setting in the iscsi context so we can use it later to determine how to send solicited/unsolicited data. --- include/iscsi-private.h | 7 +++++++ lib/init.c | 6 ++++-- lib/login.c | 13 ++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index ddcffd3..9783d4b 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -40,6 +40,11 @@ struct iscsi_in_pdu { void iscsi_free_iscsi_in_pdu(struct iscsi_in_pdu *in); void iscsi_free_iscsi_inqueue(struct iscsi_in_pdu *inqueue); +enum iscsi_initial_r2t { + ISCSI_INITIAL_R2T_NO = 0, + ISCSI_INITIAL_R2T_YES = 1 +}; + struct iscsi_context { const char *initiator_name; const char *target_name; @@ -86,6 +91,8 @@ struct iscsi_context { uint32_t max_burst_length; uint32_t first_burst_length; uint32_t max_recv_data_segment_length; + enum iscsi_initial_r2t want_initial_r2t; + enum iscsi_initial_r2t use_initial_r2t; }; #define ISCSI_PDU_IMMEDIATE 0x40 diff --git a/lib/init.c b/lib/init.c index 5039f78..74255a8 100644 --- a/lib/init.c +++ b/lib/init.c @@ -60,9 +60,11 @@ iscsi_create_context(const char *initiator_name) iscsi->next_phase = ISCSI_PDU_LOGIN_NSG_OPNEG; iscsi->secneg_phase = ISCSI_LOGIN_SECNEG_PHASE_OFFER_CHAP; - iscsi->max_burst_length = 262144; - iscsi->first_burst_length = 262144; + iscsi->max_burst_length = 262144; + iscsi->first_burst_length = 262144; iscsi->max_recv_data_segment_length = 262144; + iscsi->want_initial_r2t = ISCSI_INITIAL_R2T_NO; + iscsi->use_initial_r2t = ISCSI_INITIAL_R2T_NO; return iscsi; } diff --git a/lib/login.c b/lib/login.c index 34b19fe..8346c7f 100644 --- a/lib/login.c +++ b/lib/login.c @@ -195,12 +195,15 @@ iscsi_login_add_initialr2t(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) return 0; } - str = (char *)"InitialR2T=Yes"; + asprintf(&str, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ? + "No" : "Yes"); if (iscsi_pdu_add_data(iscsi, pdu, (unsigned char *)str, strlen(str)+1) != 0) { iscsi_set_error(iscsi, "Out-of-memory: pdu add data failed."); + free(str); return -1; } + free(str); return 0; } @@ -931,6 +934,14 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, iscsi->first_burst_length = strtol((char *)ptr + 17, NULL, 10); } + if (!strncmp((char *)ptr, "InitialR2T=", 11)) { + if (!strcmp((char *)ptr + 11, "No")) { + iscsi->use_initial_r2t = ISCSI_INITIAL_R2T_NO; + } else { + iscsi->use_initial_r2t = ISCSI_INITIAL_R2T_YES; + } + } + if (!strncmp((char *)ptr, "MaxBurstLength=", 15)) { iscsi->max_burst_length = strtol((char *)ptr + 15, NULL, 10); }