Re: [RFC PATCH 1/8] rust: kernel: add basic abstractions for device-mapper

From: Qingsong Chen
Date: Sun Jul 16 2023 - 23:04:56 EST


On 7/14/23 11:48 PM, Benno Lossin wrote:
- Declare `vtable` for basic target operations.
- Wrap `target_type` to register/unregister target.
- Wrap `dm_target`/`dm_dev` to handle io request.
- Add a dummy `bio` wrapper.

Signed-off-by: Qingsong Chen <changxian.cqs@xxxxxxxxxxxx>

On my system this patch series (I did not test which patch exactly) does
not compile.

I have left some comments below, they show some patterns present in
the other patches as well.

Thanks for the comments. Maybe `CONFIG_BLK_DEV_ZONED=y` is needed to
compile this patchset. This is because I cannot define two functions
with the same name in a trait (using the `vtable` macro), just like
the C definition:
```c
#ifdef CONFIG_BLK_DEV_ZONED
typedef int (*dm_report_zones_fn) (struct dm_target *ti,
struct dm_report_zones_args *args,
unsigned int nr_zones);
#else
typedef int (*dm_report_zones_fn) (struct dm_target *dummy);
#endif
```
To fix the `vtable`, I send a little patch[1] the other day. Based on
that, the compile error of this patchset should be fixed too.

[1]:
https://lore.kernel.org/rust-for-linux/20230626074242.3945398-1-changxian.cqs@xxxxxxxxxxxx/

+/// The return values of target map function, i.e., [`TargetOperations::map`].
+#[repr(u32)]
+pub enum MapState {
+ /// The target will handle the io by resubmitting it later.
+ Submitted = bindings::DM_MAPIO_SUBMITTED,
+
+ /// Simple remap complete.
+ Remapped = bindings::DM_MAPIO_REMAPPED,
+
+ /// The target wants to requeue the io.
+ Requeue = bindings::DM_MAPIO_REQUEUE,
+
+ /// The target wants to requeue the io after a delay.
+ DelayRequeue = bindings::DM_MAPIO_DELAY_REQUEUE,
+
+ /// The target wants to complete the io.
+ Kill = bindings::DM_MAPIO_KILL,
+}

Is it really necessary to have these correspond to the exact values?
Could we also just have a conversion function and leave the repr to
the compiler?

Sure, we can have a conversion function to return its value to C side
(without `as _`).

Regards,
Qingsong