From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bruce Richardson Subject: Re: [RFC] hash/lpm: return NULL if the object exists Date: Fri, 25 Mar 2016 10:45:37 +0000 Message-ID: <20160325104537.GA18028@bricha3-MOBL3> References: <1458044745-32764-1-git-send-email-olivier.matz@6wind.com> <56F513CF.4090604@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org To: Olivier Matz Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 7E07D3990 for ; Fri, 25 Mar 2016 11:45:41 +0100 (CET) Content-Disposition: inline In-Reply-To: <56F513CF.4090604@6wind.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 > > 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