Claude net/fs review
This commit is contained in:
@@ -24,6 +24,10 @@ enum CompletionKind {
|
||||
NotifySend = 3,
|
||||
Operation = 4,
|
||||
OperationCancel = 5,
|
||||
/// CQE produced by the IORING_OP_LINK_TIMEOUT SQE that accompanies a
|
||||
/// linked operation. We register it so the token range is claimed, but
|
||||
/// the completion itself carries no useful information and is discarded.
|
||||
LinkedTimeout = 6,
|
||||
}
|
||||
|
||||
type CompletionHandler = Box<dyn FnOnce(IoUringCqe) + Send + 'static>;
|
||||
@@ -224,6 +228,49 @@ impl Driver {
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
/// Submits a main operation linked to a timeout.
|
||||
///
|
||||
/// Internally two SQEs are enqueued atomically: the main op (with
|
||||
/// `IOSQE_IO_LINK`) and an `IORING_OP_LINK_TIMEOUT` SQE. If `timeout`
|
||||
/// elapses before the main op completes, the kernel cancels the main op and
|
||||
/// its CQE will carry `-ECANCELED`. The timeout's own CQE is silently
|
||||
/// discarded in `process_cqe`.
|
||||
///
|
||||
/// Returns the token for the main operation, which can be used with
|
||||
/// `cancel_operation` to cancel it early.
|
||||
pub(crate) fn submit_operation_with_linked_timeout(
|
||||
&self,
|
||||
fill: impl FnOnce(&mut IoUringSqe),
|
||||
timeout: Duration,
|
||||
on_complete: impl FnOnce(IoUringCqe) + Send + 'static,
|
||||
) -> io::Result<u64> {
|
||||
let main_token = self.next_token(CompletionKind::Operation);
|
||||
let timeout_token = self.next_token(CompletionKind::LinkedTimeout);
|
||||
#[cfg(debug_assertions)]
|
||||
tracing::trace!(
|
||||
target: trace_targets::ASYNC,
|
||||
event = "submit_operation_with_linked_timeout",
|
||||
main_token,
|
||||
timeout_token,
|
||||
timeout_ns = timeout.as_nanos() as u64,
|
||||
"submitting async driver operation with linked timeout"
|
||||
);
|
||||
self.completions
|
||||
.borrow_mut()
|
||||
.insert(main_token, Box::new(on_complete));
|
||||
|
||||
if let Err(error) =
|
||||
self.ring
|
||||
.submit_linked_with_timeout(main_token, fill, timeout_token, timeout)
|
||||
{
|
||||
let mut completions = self.completions.borrow_mut();
|
||||
let _ = completions.remove(&main_token);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
Ok(main_token)
|
||||
}
|
||||
|
||||
pub(crate) fn cancel_operation(&self, token: u64) -> io::Result<()> {
|
||||
#[cfg(debug_assertions)]
|
||||
tracing::trace!(
|
||||
@@ -302,6 +349,7 @@ impl Driver {
|
||||
Some(CompletionKind::TimerRemove)
|
||||
| Some(CompletionKind::NotifySend)
|
||||
| Some(CompletionKind::OperationCancel)
|
||||
| Some(CompletionKind::LinkedTimeout)
|
||||
| None => {}
|
||||
}
|
||||
}
|
||||
@@ -347,6 +395,7 @@ fn decode_token_kind(token: u64) -> Option<CompletionKind> {
|
||||
3 => Some(CompletionKind::NotifySend),
|
||||
4 => Some(CompletionKind::Operation),
|
||||
5 => Some(CompletionKind::OperationCancel),
|
||||
6 => Some(CompletionKind::LinkedTimeout),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user