Re: [PATCH v3 04/12] rust: xarray: add `XArrayState`

From: Tamir Duberstein

Date: Tue Feb 24 2026 - 10:54:27 EST


On Tue, Feb 24, 2026 at 10:43 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> "Tamir Duberstein" <tamird@xxxxxxxxx> writes:
>
> > On Tue, Feb 24, 2026 at 9:27 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> >>
> >> Tamir Duberstein <tamird@xxxxxxxxx> writes:
> >>
> >> > On Mon, Feb 9, 2026 at 6:39 AM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> >> >>
> >> >> Add `XArrayState` as internal state for XArray iteration and entry
> >> >> operations. This struct wraps the C `xa_state` structure and holds a
> >> >> reference to a `Guard` to ensure exclusive access to the XArray for the
> >> >> lifetime of the state object.
> >> >>
> >> >> The `XAS_RESTART` constant is also exposed through the bindings helper
> >> >> to properly initialize the `xa_node` field.
> >> >>
> >> >> The struct and its constructor are marked with `#[expect(dead_code)]` as
> >> >> there are no users yet. We will remove this annotation in a later patch.
> >> >>
> >> >> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> >> >> ---
> >> >> rust/bindings/bindings_helper.h | 1 +
> >> >> rust/kernel/xarray.rs | 41 ++++++++++++++++++++++++++++++++++++++++-
> >> >> 2 files changed, 41 insertions(+), 1 deletion(-)
> >> >>
> >> >> diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
> >> >> index a067038b4b422..58605c32e8102 100644
> >> >> --- a/rust/bindings/bindings_helper.h
> >> >> +++ b/rust/bindings/bindings_helper.h
> >> >> @@ -117,6 +117,7 @@ const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT;
> >> >>
> >> >> const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC = XA_FLAGS_ALLOC;
> >> >> const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC1 = XA_FLAGS_ALLOC1;
> >> >> +const size_t RUST_CONST_HELPER_XAS_RESTART = (size_t)XAS_RESTART;
> >> >
> >> > Please add a comment to explain the cast.
> >>
> >> How is this:
> >>
> >> // `XAS_RESTART` is defined with type `struct xa_node *`. `bindgen`
> >> // cannot generate pointer typed constants, so we cast to `size_t`.
> >
> > Can we include a citation or explain why bindgen can't generate
> > pointer typed constants?
>
> If you have one, I can add it. I don't know why this is the case. My
> guess is that it's just not implemented yet.

If that's the state of your understanding, that's what the comment
should say. But IMO the burden of finding out the reason, filing
appropriate issues upstream, and documenting these things is on you as
part of this change.

>
> Best regards,
> Andreas Hindborg
>