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

Andreas Hindborg <[email protected]>
Newsgroups org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <[email protected]>
Tamir Duberstein <[email protected]> writes:

> On Thu, 04 Jun 2026 21:58:13 +0200, Andreas Hindborg <[email protected]> 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}`.

I can amend the commit message to enumerate the added methods.

> 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.

What do you mean when you say that it is not clear that the API is
needed? Are you referring to callers of this code? This is initially for
the rust null block driver, as expressed in the cover letter.

I'm not sure why you think this is inconsistent with patch 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}").

This is a great idea. I will follow up with a cleanup once this stuff is
in. Getting changes in the xarray C code has a rather high latency. I
would rather not be blocked by that at the moment.


Best regards,
Andreas Hindborg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.