Re: [PATCH v4 07/11] rust: xarray: add entry API

From: Tamir Duberstein

Date: Fri Jun 05 2026 - 11:23:16 EST


On Thu, 04 Jun 2026 21:58:13 +0200, Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> Add an Entry API for XArray that provides ergonomic access to array
> slots that may be vacant or occupied. The API follows the pattern of
> Rust's standard library HashMap entry API, allowing efficient
> conditional insertion and modification of entries.

There's a lot more API here than this lets on.
`find_next_entry{,_circular}`, `Entry::is_occupied`, `into_guard`,
`insert{,_entry}` (do we need both?), `index`, `OccupiedEntry::swap`,
`Deref{,Mut}`.

It's not clear that all this API is needed, and this message does not
attempt to justify it. It is also inconsistent with the split in patches
3 and 4.

>
>
> diff --git a/rust/helpers/xarray.c b/rust/helpers/xarray.c
> index 08979b304341..19fce6862c78 100644
> --- a/rust/helpers/xarray.c
> +++ b/rust/helpers/xarray.c
> @@ -26,3 +26,20 @@ __rust_helper void rust_helper_xa_unlock(struct xarray *xa)
> {
> return xa_unlock(xa);
> }
> +
> +void *rust_helper_xas_result(struct xa_state *xas, void *curr)
> +{
> + if (xa_err(xas->xa_node))
> + curr = xas->xa_node;
> + return curr;
> +}
> +
> +void *rust_helper_xa_zero_to_null(void *entry)
> +{
> + return xa_is_zero(entry) ? NULL : entry;
> +}

These functions already exist in C, but are `static inline` in xarray.c.
Can we move them to the header instead of duplicating them here please?
That is what I did in 79ada2ae ("xarray: extract helper from
__xa_{insert,cmpxchg}").

--
Tamir Duberstein <tamird@xxxxxxxxxx>