Page MenuHomeFreeBSD

Use C errno as return value for cam_periph_acquire()
ClosedPublic

Authored by scottl on Jan 26 2018, 10:07 PM.

Details

Summary

There's no compelling reason to return a cam_status type for
cam_periph_acquire(), and doing so only creates confusion with normal C
coding practices. It's technically an API change, but the periph API
isn't widely used. No efffective change to operation.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

scottl created this revision.Jan 26 2018, 10:07 PM
imp accepted this revision.Jan 26 2018, 10:11 PM
This revision is now accepted and ready to land.Jan 26 2018, 10:11 PM
ken requested changes to this revision.Feb 1 2018, 11:39 PM

The change in general is fine. It just needs fixing in the ctlferegister() case.

sys/cam/ctl/scsi_ctl.c
546 ↗(On Diff #38498)

This isn't quite right. ctlferegister() is defined to return cam_status. The status variable is set above to CAM_REQ_CMP, and then reset to various things as we go through the loop.

Here, you're returning the status value that probably reflects success, but it should reflect a failure to acquire.

So, how about returning CAM_REQ_CMP_ERR here.

This revision now requires changes to proceed.Feb 1 2018, 11:39 PM
scottl added inline comments.Feb 5 2018, 9:56 PM
sys/cam/ctl/scsi_ctl.c
546 ↗(On Diff #38498)

Good catch, thanks.

mav added a comment.Feb 5 2018, 10:18 PM

I neither have major objections aside of one inline, nor too happy. From one side I agree that there is no any/much sense to return cam_status from functions like that, which do not work with command statuses. From the other side it is a) an API change, which may lead to difficult to find errors, but b) there are many other functions suffering the same problem (but which may be more invasive to fix though).

sys/cam/cam_periph.c
409 ↗(On Diff #38498)

Why still cam_status here? Should be an int probably.

scottl added inline comments.Feb 6 2018, 6:28 AM
sys/cam/cam_periph.c
409 ↗(On Diff #38498)

Good catch, I'll fix it.

scottl added a comment.Feb 6 2018, 6:30 AM
In D14063#298088, @mav wrote:

I neither have major objections aside of one inline, nor too happy. From one side I agree that there is no any/much sense to return cam_status from functions like that, which do not work with command statuses. From the other side it is a) an API change, which may lead to difficult to find errors, but b) there are many other functions suffering the same problem (but which may be more invasive to fix though).

This is just the first part of a larger project to clean up CAM. Some of the other functions that you refer to will be fixed after this.

This revision was not accepted when it landed; it landed in state Needs Revision.
This revision was automatically updated to reflect the committed changes.