Skip to content

Commit

Permalink
larger reads would not increment lba correctly in iscsi_fail_reason s…
Browse files Browse the repository at this point in the history
…erver::push_response
  • Loading branch information
folkertvanheusden committed Oct 25, 2024
1 parent f23218a commit fadb93b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,10 @@ iscsi_fail_reason server::push_response(com_client *const cc, session *const ses
}

while(offset < offset_end) {
uint64_t bytes_left = offset_end - offset;
uint32_t current_n = std::min(uint64_t(ses->get_max_seg_len()), std::min(bytes_left, buffer_n));
bool last_block = offset + current_n == offset_end;
uint64_t bytes_left = offset_end - offset;
uint32_t current_n = std::min(uint64_t(ses->get_max_seg_len()), std::min(bytes_left, buffer_n));
uint32_t is_n_blocks = current_n / s->get_block_size();
bool last_block = offset + current_n == offset_end;

std::optional<std::pair<residual, uint32_t> > has_residual;
if (last_block) {
Expand All @@ -455,6 +456,7 @@ iscsi_fail_reason server::push_response(com_client *const cc, session *const ses
has_residual = { iSR_UNDERFLOW, iscsi_wants - scsi_has };
}

DOLOG(logging::ll_debug, "server::push_response", cc->get_endpoint_name(), "generating response for offset %u, n %u, lba: %" PRIu64, offset, current_n, current_lba);
auto [ out, data_pointer ] = iscsi_pdu_scsi_data_in::gen_data_in_pdu(ses, reply_to, has_residual, offset, current_n, last_block);

scsi::scsi_rw_result rc = scsi::rw_fail_general;
Expand All @@ -467,7 +469,7 @@ iscsi_fail_reason server::push_response(com_client *const cc, session *const ses
delete [] temp_buffer;
}
else {
rc = s->read(current_lba, current_n / s->get_block_size(), data_pointer);
rc = s->read(current_lba, is_n_blocks, data_pointer);
}

if (rc != scsi::rw_ok) {
Expand All @@ -492,7 +494,7 @@ iscsi_fail_reason server::push_response(com_client *const cc, session *const ses
}

offset += current_n;
current_lba += 1;
current_lba += is_n_blocks;
ses->add_bytes_tx(out.n);
is->iscsiSsnTxDataOctets += out.n;
}
Expand Down

0 comments on commit fadb93b

Please sign in to comment.