Re: [PATCH 4/6] rhashtable: allow a walk of the hash table without missing objects.

From: Herbert Xu
Date: Wed Mar 28 2018 - 02:07:49 EST


On Wed, Mar 28, 2018 at 08:54:41AM +1100, NeilBrown wrote:
>
> Possibly.
> I particularly want the interface to require that you pass the
> previously returned object to _continue. That makes it easy to see that
> the object is still being used. If someone changes to code to delete
> the object before the _continue, there should be a strong hint that it
> won't work.
>
> Maybe it would be better to make it a WARN_ON()
>
> if (!obj || WARN_ON(iter->p != obj))
> iter->p = NULL;

This doesn't really protect against the case where obj is removed.
All it proves is that the user saved a copy of obj which we already
did anyway.

To detect an actual removal you'd need to traverse the list.

I have another idea: we could save insert the walkers into the
hash table chain at the end, essentially as a hidden list. We
can mark it with a flag like rht_marker so that normal traversal
doesn't see it.

That way the removal code can simply traverse that list and inform
them that the iterator is invalid.

Cheers,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt