diff --git a/iscsi-pdu.cpp b/iscsi-pdu.cpp index a6a1bc5..9da50d0 100644 --- a/iscsi-pdu.cpp +++ b/iscsi-pdu.cpp @@ -516,13 +516,18 @@ std::optional iscsi_pdu_scsi_cmd::get_response(scsi *const s 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 = 0; - if (my_getrandom(&TTT) == false) { + uint32_t ITT = get_Itasktag(); + if (ITT != 0xffffffff) { + DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "has an ITT: %08x", ITT); + TTT = ITT; + } + else 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); + DOLOG(logging::ll_debug, "iscsi_pdu_scsi_cmd::get_response", ses->get_endpoint_name(), "ITT/TTT is %08x", TTT); if (temp->set(*this, TTT, scsi_reply.value().r2t.bytes_done, scsi_reply.value().r2t.bytes_left) == false) { ok = false; diff --git a/scsi.cpp b/scsi.cpp index 6f69dc8..ea66e63 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -470,8 +470,12 @@ std::optional scsi::send(const uint64_t lun, const uint8_t *const else { DOLOG(logging::ll_debug, "scsi::send", lun_identifier, "WRITE without data"); - if (transfer_length) - response.type = ir_r2t; // allow R2T packets to come in + if (transfer_length) { + response.type = ir_r2t; // allow R2T packets to come in + response.r2t.buffer_lba = lba; + response.r2t.bytes_left = transfer_length * backend_block_size; + DOLOG(logging::ll_debug, "scsi::send", lun_identifier, "starting R2T with %u bytes left (LBA: %" PRIu64 ")", response.r2t.bytes_left, response.r2t.buffer_lba); + } else { response.type = ir_empty_sense; DOLOG(logging::ll_debug, "scsi::send", lun_identifier, "WRITE with 0 transfer_length");