From 4979b7346f55a57ba8f034a68b22cc006255f6dc Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 27 Mar 2011 19:27:10 +1100 Subject: [PATCH] From Richard Sharpe Add a mechanism where residual overflow/underflow can be reportad back to the application We probably need somethinf for bidir residuals at some stage too --- include/scsi-lowlevel.h | 8 ++++++++ lib/scsi-command.c | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 7b3dce7..2d9214f 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -107,6 +107,12 @@ struct scsi_allocated_memory { void *ptr; }; +enum scsi_residual { + SCSI_RESIDUAL_NO_RESIDUAL = 0, + SCSI_RESIDUAL_UNDERFLOW, + SCSI_RESIDUAL_OVERFLOW +}; + struct scsi_task { int status; @@ -123,6 +129,8 @@ struct scsi_task { struct scsi_modesense6_params modesense6; } params; + enum scsi_residual residual_status; + int residual; struct scsi_sense sense; struct scsi_data datain; struct scsi_allocated_memory *mem; diff --git a/lib/scsi-command.c b/lib/scsi-command.c index f042ecb..8ceadaa 100644 --- a/lib/scsi-command.c +++ b/lib/scsi-command.c @@ -354,6 +354,21 @@ iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, task->datain.data = pdu->indata.data; task->datain.size = pdu->indata.size; + task->residual_status = SCSI_RESIDUAL_NO_RESIDUAL; + task->residual = 0; + + /* + * These flags should only be set if the S flag is also set + */ + if (flags & (ISCSI_PDU_DATA_RESIDUAL_OVERFLOW|ISCSI_PDU_DATA_RESIDUAL_UNDERFLOW)) { + task->residual = ntohl(&in->hdr[44]); + if (flags & ISCSI_PDU_DATA_RESIDUAL_UNDERFLOW) { + task->residual_status = SCSI_RESIDUAL_UNDERFLOW; + } else { + task->residual_status = SCSI_RESIDUAL_OVERFLOW; + } + } + pdu->indata.data = NULL; pdu->indata.size = 0;