Re: [PATCH 04/79] block: rust: fix generation of bindings to `BLK_STS_.*`

From: Andreas Hindborg

Date: Mon Jun 01 2026 - 07:17:14 EST


Alice Ryhl <aliceryhl@xxxxxxxxxx> writes:

> On Mon, Mar 16, 2026 at 10:27 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>>
>> On Mon, Feb 16, 2026 at 12:34:51AM +0100, Andreas Hindborg wrote:
>> > Bindgen generates constants for CPP integer literals as u32. The
>> > `blk_status_t` type is defined as `u8` but the variants of the type are
>> > defined as integer literals via CPP macros. Thus the defined variants of
>> > the type are not of the same type as the type itself.
>> >
>> > Prevent bindgen from emitting generated bindings for the `BLK_STS_.*`
>> > defines and instead define constants manually in `bindings_helper.h`
>> >
>> > Also remove casts that are no longer necessary.
>> >
>> > Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
>>
>> It'd be ideal to change the C header to use an enum, but that may not
>> work as I'm not sure you can specify the integer width you want for an
>> enum.
>>
>> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
>
> Honestly, it might be better just to declare a Rust module somewhere
> with each constant redeclared:
>
> const BLK_STS_FOO: blk_status_t = bindings::BLK_STS_FOO as blk_status_t;

As it turns out, `bindgen` only emits a binding for `BLK_STS_OK`. It
cannot parse the rest, because they are declared as `((__force
blk_status_t)<N>)`. So in order to avoid special casing the `BLK_STS_OK`
constant, I think we should just keep the patch as is. I don't think we
will gain much from re-declaring all these in a local module.

I will update the comment on the `blocklist-item`:

+# Bindgen cannot extract values from the `((__force blk_status_t)N)`
+# CPP-macro form used by most of these and emits the few it can extract
+# as `u32`. Block them entirely; the `RUST_CONST_HELPER_BLK_STS_*`
+# definitions in `bindings_helper.h` expose them as `blk_status_t`.


Best regards,
Andreas Hindborg