Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vioscsi] SendSRB minor refactor #1153

Conversation

benyamin-codez
Copy link
Contributor

@benyamin-codez benyamin-codez commented Sep 19, 2024

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.

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]>
vioscsi/helper.c Outdated Show resolved Hide resolved
vioscsi/helper.c Outdated Show resolved Hide resolved
vioscsi/helper.c Show resolved Hide resolved
vioscsi/helper.c Show resolved Hide resolved
vioscsi/helper.c Show resolved Hide resolved
@benyamin-codez
Copy link
Contributor Author

I'll drop another commit here in coming hours but thought it worth mentioning that I'm expecting the following gets clobbered by PR #1150, so won't do anything with that...

}
VioScsiVQUnlock(DeviceExtension, MessageID, &LockHandle, FALSE);
if ( res >= 0){
if (virtqueue_kick_prepare(adaptExt->vq[QueueNumber])) {
virtqueue_notify(adaptExt->vq[QueueNumber]);
}

From @JonKohler review feedback:
1. Use VQ_ADD_BUFFER_SUCCESS definition in virtqueue_add_buf() status variable init
2. Add virtqueue_add_buf() status variable to trace output on error

Also:
1. Cleaned up init table
2. Replaced mentions of index variable with vq_req_idx

Signed-off-by: benyamin-codez <[email protected]>
@benyamin-codez
Copy link
Contributor Author

Have pushed the additional commit...
Switching this from draft to review...

@benyamin-codez benyamin-codez marked this pull request as ready for review September 20, 2024 02:26
@benyamin-codez
Copy link
Contributor Author

Check will fail per:

I'll drop another commit here in coming hours but thought it worth mentioning that I'm expecting the following gets clobbered by PR #1150, so won't do anything with that...

}
VioScsiVQUnlock(DeviceExtension, MessageID, &LockHandle, FALSE);
if ( res >= 0){
if (virtqueue_kick_prepare(adaptExt->vq[QueueNumber])) {
virtqueue_notify(adaptExt->vq[QueueNumber]);
}

...for undeclared identifier res (as expected).

Let me know if that's ok or you need something else from me.

Copy link
Contributor

@JonKohler JonKohler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM at first glance, thanks for the cleanup

@kostyanf14
Copy link
Member

Hi @benyamin-codez, please fix build errors.

@benyamin-codez
Copy link
Contributor Author

@kostyanf14

Thanks I will revert the offending changes and put them in a new PR to review after other merges...

Revert variable add_buffer_req_status to res to complete build scripts
Will raise new PR for these changes

Signed-off-by: benyamin-codez <[email protected]>
@benyamin-codez
Copy link
Contributor Author

@JonKohler

Jon, I thought I'd better check the modded trace works properly...

I found we do actually set -ENOSPC in virtqueue_add_buf_split() and virtqueue_add_buf_packed() per, e.g. :

However, it returns -1 per:

I'm still of the view that ENOSPC is appropriate here.

@YanVugenfirer

Per the above, do you know if there was any reason we define ENOSPC as 1 in osdep.h rather than 28...?
I see it was implemented in 2014 per 264f1b6.

In Windows, 0x1 is ERROR_INVALID_FUNCTION and 0x1C (28) is ERROR_OUT_OF_PAPER...
Given why and how we are using it, alternatives might include one of the following:

ERROR_ACCESS_DENIED     0x5
ERROR_NOT_ENOUGH_MEMORY 0x8
ERROR_NOT_READY         0x15 (21)
ERROR_BUSY              0xAA (170)

...but these would require single line changes to VirtIO ( both VirtIORing.c and VirtIORing-Packed.c).

AFAICT, these are the only files in the tree which reference ENOSPC, but deleting the definition from osdep.h will result in undeclared identifier compilation errors. Perhaps I should include a commit to change it to 28 in this PR (or maybe a separate PR would be best)?

An alternative might be for me to use:

RhelDbgPrint(TRACE_LEVEL_WARNING, 
             " Could not put an SRB into a VQ due to error %s. To be completed with SRB_STATUS_BUSY. QueueNumber = %lu, SRB = 0x%p, Lun = %d, TimeOut = %d.\n", 
             (res == -1) ? "ENOSPC" : "UNKNOWN", QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue);

Any advice on how to proceed would be appreciated.

cc: @vrozenfe

@YanVugenfirer
Copy link
Collaborator

@benyamin-codez I will take a look. But I am travelling for the KVM Forum now and it might take me some time.

@JonKohler
Copy link
Contributor

@benyamin-codez I will take a look. But I am travelling for the KVM Forum now and it might take me some time.

Glad you could make it. Travel logistics to Brno are brutal from where I live, I wanted to go this year but yikes, it's tough!

@benyamin-codez benyamin-codez marked this pull request as draft October 4, 2024 12:02
@benyamin-codez
Copy link
Contributor Author

@vrozenfe
@YanVugenfirer

Yan & Vadim,

I've set this back to draft with a view to replacing it with a single commit PR.

I will rebase against master and add the changes I had reverted back in.

On the ENOSPC / SCSISTAT_QUEUE_FULL trace, I think it best to use:

        RhelDbgPrint(TRACE_LEVEL_WARNING, 
                     " Could not put an SRB into a VQ due to error %s (%i). To be completed with SRB_STATUS_BUSY. QueueNumber = %lu, SRB = 0x%p, Lun = %d, TimeOut = %d.\n", 
                     (res == -ENOSPC) ? "ENOSPC" : "UNKNOWN", res, QueueNumber, srbExt->Srb, SRB_LUN(Srb), Srb->TimeOutValue);

Let me know if you want a PR to change the definition of ENOSPC in \VirtIO\osdep.h from 1 to 28 (or xyz) ...

cc: @JonKohler

@vrozenfe
Copy link
Collaborator

vrozenfe commented Oct 4, 2024

Let me know if you want a PR to change the definition of ENOSPC in \VirtIO\osdep.h from 1 to 28 (or xyz) ...

As for me, I think it would be nice to keep the same definitions as in Linux.

Best,
Vadim.

@YanVugenfirer
Copy link
Collaborator

Let me know if you want a PR to change the definition of ENOSPC in \VirtIO\osdep.h from 1 to 28 (or xyz) ...

As for me, I think it would be nice to keep the same definitions as in Linux.

Best, Vadim.

@benyamin-codez I agree with Vadim. Better be consistence with Linux.

@benyamin-codez
Copy link
Contributor Author

Single commit PR is #1162.

PR for ENOSPC change is #1163.

Closing this one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants