Re: [RFC PATCH 2/8] rust: kernel: add `request` related TargetOperations

From: Qingsong Chen
Date: Sun Jul 16 2023 - 23:43:19 EST


On 7/14/23 11:49 PM, Benno Lossin wrote:
@@ -31,6 +31,39 @@ pub trait TargetOperations: Sized {
/// Map block IOs. Return [`MapState`] to indicate how to handle the `bio`
/// later (end or resubmit).
fn map(t: &mut Target<Self>, bio: Pin<&mut Bio>) -> MapState;
+
+ /// Map `request`. Return [`MapState`] and the optional cloned `request`.
+ #[allow(unused)]
+ fn clone_and_map_rq<'a>(
+ t: &mut Target<Self>,
+ rq: Pin<&mut Request>,
+ map_ctx: &mut MapInfo,
+ ) -> (MapState, Option<Pin<&'a mut Request>>) {
+ unimplemented!()

Note that these should be implemented when you submit this as an actual
patch. (Not sure what you would do in this case, but throwing a panic is
not a good idea.) This also applies to all subsequent patches.
I think you might have done this, because you want the C side to choose
the default implementation. But it should also be possible to call these
from the Rust side.

In fact, we don't want users to call these callbacks manually. The normal call-chain would be like this: `map_request`(c) ->
`dm_clone_and_map_rq_fn`(unsafe rust) -> `clone_and_map_rq`(rust).
If users don't implement `clone_and_map_rq`, we would check the
corresponding field of `TargetType`, using the `check_target_operations`
macro. So it won't call the default implementation generally.

Regards,
Qingsong