Skip to content

Commit

Permalink
- InitialR2T=Yes
Browse files Browse the repository at this point in the history
- unique TTT - disconnecte from ITT
  • Loading branch information
folkertvanheusden committed Oct 11, 2024
1 parent 3403920 commit 992f900
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
9 changes: 8 additions & 1 deletion iscsi-pdu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ bool iscsi_pdu_login_reply::set(const iscsi_pdu_login_request & reply_to)
"DefaultTime2Wait=2",
"DefaultTime2Retain=20",
"ErrorRecoveryLevel=0",
"InitialR2T=Yes",
myformat("MaxRecvDataSegmentLength=%u", MAX_DATA_SEGMENT_SIZE),
};
for(const auto & kv : kvs)
Expand Down Expand Up @@ -527,7 +528,13 @@ std::optional<iscsi_response_set> iscsi_pdu_scsi_cmd::get_response(scsi *const s
auto *temp = new iscsi_pdu_scsi_r2t(ses) /* 0x31 */;
DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "sending R2T with %zu sense bytes", scsi_reply.value().sense_data.size());

uint32_t TTT = ses->init_r2t_session(scsi_reply.value().r2t, this);
uint32_t TTT = 0;
if (my_getrandom(&TTT) == false) {
DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "my_getrandom failed");
ok = false;
}

ses->init_r2t_session(scsi_reply.value().r2t, this, TTT);
DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "TTT is %08x", TTT);

if (temp->set(*this, TTT, scsi_reply.value().r2t.bytes_done, scsi_reply.value().r2t.bytes_left) == false) {
Expand Down
20 changes: 11 additions & 9 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,19 @@ bool server::push_response(com_client *const cc, session *const ses, iscsi_pdu_b
auto pdu_data_out = reinterpret_cast<iscsi_pdu_scsi_data_out *>(pdu);
uint32_t offset = pdu_data_out->get_BufferOffset();
auto data = pdu_data_out->get_data();
uint32_t TTT = pdu_data_out->get_TTT();
uint32_t transfer_tag = pdu_data_out->get_TTT();
bool F = pdu_data_out->get_F();
auto session = ses->get_r2t_sesion(TTT);
auto session = ses->get_r2t_sesion(transfer_tag);

if (TTT == 0xffffffff) { // unsollicited data
TTT = pdu_data_out->get_Itasktag();
session = ses->get_r2t_sesion(TTT);
if (transfer_tag == 0xffffffff) { // unsollicited data
transfer_tag = pdu_data_out->get_Itasktag();
session = ses->get_r2t_sesion(transfer_tag);
}

DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "TT: %08x, F: %d, session: %d, offset: %u, has data: %u", transfer_tag, F, session != nullptr, offset, data.has_value() ? data.value().second : 0);

if (session == nullptr) {
DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "DATA-OUT PDU references unknown TTT (%08x)", TTT);
DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "DATA-OUT PDU references unknown TTT (%08x)", transfer_tag);
return false;
}
else if (data.has_value() && data.value().second > 0) {
Expand Down Expand Up @@ -333,7 +335,7 @@ bool server::push_response(com_client *const cc, session *const ses, iscsi_pdu_b
if (session->bytes_left == 0) {
DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "end of task");

ses->remove_r2t_session(TTT);
ses->remove_r2t_session(transfer_tag);
}
else {
DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "ask for more (%u bytes left)", session->bytes_left);
Expand All @@ -342,7 +344,7 @@ bool server::push_response(com_client *const cc, session *const ses, iscsi_pdu_b
temp.set(session->PDU_initiator.data, session->PDU_initiator.n);

auto *response = new iscsi_pdu_scsi_r2t(ses) /* 0x31 */;
if (response->set(temp, TTT, session->bytes_done, session->bytes_left) == false) {
if (response->set(temp, transfer_tag, session->bytes_done, session->bytes_left) == false) {
DOLOG(logging::ll_error, "server::push_response", cc->get_endpoint_name(), "response->set failed");
delete response;
return false;
Expand Down Expand Up @@ -384,7 +386,7 @@ bool server::push_response(com_client *const cc, session *const ses, iscsi_pdu_b
delete pdu_out;
}

// e.g. for READ_xx (as buffering may be RAM-wise too costly (on microcontrollers))
// e.g. for READ_xx (as buffering may be RAM-wise too costly (on microcontrollers)) -> DATA-IN
if (response_set.value().to_stream.has_value()) {
auto & stream_parameters = response_set.value().to_stream.value();

Expand Down
16 changes: 6 additions & 10 deletions session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@ uint32_t session::get_inc_datasn(const uint32_t data_sn_itt)
return data_sn++;
}

uint32_t session::init_r2t_session(const r2t_session & rs, iscsi_pdu_scsi_cmd *const pdu)
void session::init_r2t_session(const r2t_session & rs, iscsi_pdu_scsi_cmd *const pdu, const uint32_t transfer_tag)
{
uint32_t ITT = pdu->get_Itasktag();

auto it = r2t_sessions.find(ITT);
auto it = r2t_sessions.find(transfer_tag);
if (it != r2t_sessions.end())
return ITT;
return;

r2t_session *copy = new r2t_session;
r2t_session *copy = new r2t_session;
*copy = rs;
copy->PDU_initiator = pdu->get_raw();

DOLOG(logging::ll_debug, "session::init_r2t_session", get_endpoint_name(), "register ITT %08x", ITT);
r2t_sessions.insert({ ITT, copy });

return ITT;
DOLOG(logging::ll_debug, "session::init_r2t_session", get_endpoint_name(), "register transfer tag %08x", transfer_tag);
r2t_sessions.insert({ transfer_tag, copy });
}

r2t_session *session::get_r2t_sesion(const uint32_t ttt)
Expand Down
4 changes: 2 additions & 2 deletions session.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class session
void set_ack_interval(const uint32_t bytes) { ack_interval = bytes; }
std::optional<uint32_t> get_ack_interval() { return ack_interval; }

uint32_t init_r2t_session(const r2t_session & rs, iscsi_pdu_scsi_cmd *const pdu);
void init_r2t_session(const r2t_session & rs, iscsi_pdu_scsi_cmd *const pdu, const uint32_t transfer_tag);
r2t_session *get_r2t_sesion(const uint32_t ttt);
void remove_r2t_session(const uint32_t ttt);
void remove_r2t_session(const uint32_t ttt);
};

0 comments on commit 992f900

Please sign in to comment.