Skip to content

Commit

Permalink
[vioscsi] SendSRB minor refactor
Browse files Browse the repository at this point in the history
The virtqueue_add_buf() routine will return 0 on SUCCESS or otherwise
a negative number, usually -28 (ENOSPC), i.e no space for buffer. An
inline comment is added for edification.

Here we refactor virtqueue_add_buf() handling to only process the SRB
if virtqueue_add_buf() returns SUCCESS. Presently, other positive
return codes would be processed.

Here we define VQ_ADD_BUFFER_SUCCESS in vioscsi\helper.h

To ensure valid data is reported we also move the trace event on
failure to above the call to CompleteRequest() and wrap the line for
improved readability.

Signed-off-by: benyamin-codez <[email protected]>
  • Loading branch information
benyamin-codez committed Sep 19, 2024
1 parent 48aeb26 commit 281bb7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vioscsi/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ENTER_FN_SRB();
srbExt->out, srbExt->in,
&srbExt->cmd, va, pa);

if (res >= 0) {
if (res == VQ_ADD_BUFFER_SUCCESS) {
element = &adaptExt->processing_srbs[index];
InsertTailList(&element->srb_list, &srbExt->list_entry);
element->srb_cnt++;
Expand All @@ -120,13 +120,16 @@ ENTER_FN_SRB();
virtqueue_notify(adaptExt->vq[QueueNumber]);
}
} else {
// virtqueue_add_buf() returned -28 (ENOSPC), i.e. no space for buffer, or some other error
virtqueue_notify(adaptExt->vq[QueueNumber]);
ScsiStatus = SCSISTAT_QUEUE_FULL;
SRB_SET_SRB_STATUS(Srb, SRB_STATUS_BUSY);
SRB_SET_SCSI_STATUS(Srb, ScsiStatus);
StorPortBusy(DeviceExtension, 10);
RhelDbgPrint(TRACE_LEVEL_WARNING,
" Could not put an SRB into a VQ, so complete it with SRB_STATUS_BUSY. QueueNumber = %lu, SRB = 0x%p, Lun = %d, TimeOut = %d.\n",
QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue);
CompleteRequest(DeviceExtension, Srb);
RhelDbgPrint(TRACE_LEVEL_FATAL, " Could not put an SRB into a VQ, so complete it with SRB_STATUS_BUSY. QueueNumber = %d, SRB = 0x%p, Lun = %d, TimeOut = %d.\n", QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue);
}

EXIT_FN_SRB();
Expand Down
2 changes: 2 additions & 0 deletions vioscsi/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#define CACHE_LINE_SIZE 64
#define ROUND_TO_CACHE_LINES(Size) (((ULONG_PTR)(Size) + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1))

#define VQ_ADD_BUFFER_SUCCESS 0

#include <srbhelper.h>

// Note: SrbGetCdbLength is defined in srbhelper.h
Expand Down

0 comments on commit 281bb7b

Please sign in to comment.