[dpdk-dev] [RFC] hash/lpm: return NULL if the object exists
Bruce Richardson
bruce.richardson at intel.com
Fri Mar 25 11:45:37 CET 2016
On Fri, Mar 25, 2016 at 11:32:47AM +0100, Olivier Matz wrote:
> Hi Bruce,
>
> On 03/15/2016 01:25 PM, Olivier Matz wrote:
> > Seen by trying to fix the func_reentrancy autotest. The test
> > was doing the following on several cores in parallel:
> >
> > name = "common_name";
> > do several times {
> > obj = allocate_an_object(name) // obj = ring, mempool, hash, lpm, ...
> > if (obj == NULL && lookup(name) == NULL)
> > return TEST_FAIL;
> > }
> >
> > Issues:
> >
> > 1/ rings, mempools, hashs API are not coherent
> > rings and mempool return NULL if the object does not exist
> > hash and lpm return an object that was allocated allocated if
> > it already was allocated
> >
> > 2/ The hash/lpm API looks dangerous: when an object is returned,
> > the user does not know if it should be freed or not (no refcnt)
> >
> > 3/ There are some possible race conditions in cuckoo_hash as the
> > lock is not held in rte_hash_create(). We could find some cases
> > where NULL is returned when the object already exists (ex: when
> > rte_ring_create() fails).
> >
> > This patch tries to rationalize the APIs of lpm and hash.
> >
> > Signed-off-by: Olivier Matz <olivier.matz at 6wind.com>
>
> Sorry, I forgot to CC you in the first mail. Do you have any opinion
> about this rfc patch?
>
> Thanks,
> Olivier
Hi Olivier,
the idea looks good, since an object already existing is an error condition on
create. One small change to the libs I'd suggest is to set rte_errno to
EEXIST before exit, so that the error reason is known to the app.
Regards,
/Bruce
More information about the dev
mailing list