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

Handle interrupts in __ublksrv_ctrl_cmd #79

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

mattysweeps
Copy link
Contributor

The syscall io_uring_enter may return EINTR if it is interrupted by a delivery of a signal. This was happening to me recently; I saw that the SIG_PROF signal fired periodically, which would fail the ublksrv_ctrl_start_dev() call (returns -EINTR). The signal is firing due to unrelated circumstances.

Since __ublksrv_ctrl_cmd already added an SQE, it's easier for ublksrv to handle the error instead of the caller.

Note that I only added support to __ublksrv_ctrl_cmd since control commands are likely to be done once on startup. io_urings for handling IO are already expected to loop for IO, so there's no need for ublksrv to explicitly handle the EINTR.

Currently the code loops indefinitely. I'm also considering it best practice to set some maximum retry number or timeout, but I wanted to get your opinion first.

Also I thought about using TEMP_FAILURE_RETRY but the semantics from io_uring_wait_cqe are a bit different. TEMP_FAILURE_RETRY expects the return code to be -1 and then checks errno, but io_uring_wait_cqe returns -EINTR directly, so the do while loop is necessary.

The syscall io_uring_enter may return EINTR if it is interrupted by a
delivery of a signal. Since __ublksrv_ctrl_cmd already added an SQE, it's
easier for ublksrv to handle the error instead of the caller.

For example, if ublksrv_ctrl_start_dev() returns -EINTR, then the caller
has to either manually wait for the CQE or might call
ublksrv_ctrl_start_dev() again, resulting in an erroneous second SQE.
(Which may have no effect, but handling the interrupt seems the most
correct)
@ming1 ming1 merged commit 8f2a561 into ublk-org:master Dec 18, 2024
1 check passed
@mattysweeps mattysweeps deleted the handle-interrupt branch December 18, 2024 04:21
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.

2 participants