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

From: Daniel Gomez

Date: Tue Feb 10 2026 - 11:48:28 EST


On 2026-02-09 15:38, Andreas Hindborg 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.

It makes sense to me to merge patch 4 and 5 to avoid this.

>
> 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
...
> @@ -319,6 +322,42 @@ pub fn store(
...
> +impl<'a, 'b, T: ForeignOwnable> XArrayState<'a, 'b, T> {
> + #[expect(dead_code)]
> + fn new(access: &'b Guard<'a, T>, index: usize) -> Self {
> + let ptr = access.xa.xa.get();
> + // INVARIANT: We initialize `self.state` to a valid value below.
> + Self {
> + _access: PhantomData,
> + state: bindings::xa_state {
> + xa: ptr,
> + xa_index: index,
> + xa_shift: 0,
> + xa_sibs: 0,
> + xa_offset: 0,

To match C XArray __XA_STATE() we should also pass shift and sibs. Even if the
only use case we have currently is setting these to 0 (XA_STATE()).