From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jt@labs.hpe.com>
Received: from g2t2352.austin.hpe.com (g2t2352.austin.hpe.com [15.233.44.25])
 by dpdk.org (Postfix) with ESMTP id 4152E2A1A
 for <dev@dpdk.org>; Wed,  5 Oct 2016 19:47:36 +0200 (CEST)
Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net
 [16.196.225.135])
 by g2t2352.austin.hpe.com (Postfix) with ESMTP id 7995543;
 Wed,  5 Oct 2016 17:47:35 +0000 (UTC)
Received: from masterns.labs.hpecorp.net (mailhub-pa.labs.hpecorp.net
 [16.111.40.8])
 by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id 2819437;
 Wed,  5 Oct 2016 17:47:35 +0000 (UTC)
Received: from bougret.labs.hpecorp.net (bougret.labs.hpecorp.net
 [16.111.8.16])
 by masterns.labs.hpecorp.net (8.14.4/8.14.4/HPL-PA Hub) with ESMTP id
 u95HlYNH001105
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT);
 Wed, 5 Oct 2016 10:47:34 -0700
Received: from jt by bougret.labs.hpecorp.net with local (Exim 4.84_2)
 (envelope-from <jt@labs.hpe.com>)
 id 1brqI2-0003LY-Bp; Wed, 05 Oct 2016 10:47:34 -0700
Date: Wed, 5 Oct 2016 10:47:34 -0700
From: Jean Tourrilhes <jt@labs.hpe.com>
To: Thomas Monjalon <thomas.monjalon@6wind.com>
Cc: dev@dpdk.org, David Marchand <david.marchand@6wind.com>,
 Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>,
 olivier.matz@6wind.com, David Hunt <david.hunt@intel.com>
Message-ID: <20161005174734.GC12182@labs.hpe.com>
References: <20160922204637.GA3166@labs.hpe.com>
 <CALwxeUtkPsQop3zr4RnS7Y8bwKzar6DaRxCPWCX_trgc4kMm_w@mail.gmail.com>
 <20161005164906.GB11912@labs.hpe.com> <7491622.GqnA43pcBO@xps13>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <7491622.GqnA43pcBO@xps13>
Organisation: HP Labs Palo Alto
Address: HP Labs, MS1184, 1501 Page Mill road, Palo Alto, CA 94304, USA.
E-mail: jean.tourrilhes@hpe.com
User-Agent: Mutt/1.5.23 (2014-03-12)
Subject: [dpdk-dev] [PATCH v2] eal: don't fail secondary if primary is
	missing tailqs
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
Reply-To: jean.tourrilhes@hpe.com
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 05 Oct 2016 17:47:36 -0000

If the primary and secondary process were build using different build
systems, the list of constructors included by the linker in each
binary might be different. Tailqs are registered via constructors, so
the linker magic will directly impact which tailqs are registered with
the primary and the secondary.

DPDK currently assumes that the secondary has a subset of the tailqs
registered at the primary. In some build scenario, the secondary might
register a tailq that the primary did not register. In this case,
instead of exiting with a panic, just unregister the offending tailq
and allow the secondary to run.

Signed-off-by: Jean Tourrilhes <jt@labs.hpe.com>
---
 lib/librte_eal/common/eal_common_tailqs.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_tailqs.c b/lib/librte_eal/common/eal_common_tailqs.c
index bb08ec8..cf5a771 100644
--- a/lib/librte_eal/common/eal_common_tailqs.c
+++ b/lib/librte_eal/common/eal_common_tailqs.c
@@ -143,6 +143,8 @@ rte_eal_tailq_update(struct rte_tailq_elem *t)
 		t->head = rte_eal_tailq_create(t->name);
 	} else {
 		t->head = rte_eal_tailq_lookup(t->name);
+		if (t->head != NULL)
+			rte_tailqs_count++;
 	}
 }
 
@@ -178,19 +180,27 @@ int
 rte_eal_tailqs_init(void)
 {
 	struct rte_tailq_elem *t;
+	void *tmp_te;
 
 	rte_tailqs_count = 0;
 
-	TAILQ_FOREACH(t, &rte_tailq_elem_head, next) {
+	TAILQ_FOREACH_SAFE(t, &rte_tailq_elem_head, next, tmp_te) {
 		/* second part of register job for "early" tailqs, see
 		 * rte_eal_tailq_register and EAL_REGISTER_TAILQ */
 		rte_eal_tailq_update(t);
 		if (t->head == NULL) {
 			RTE_LOG(ERR, EAL,
 				"Cannot initialize tailq: %s\n", t->name);
-			/* no need to TAILQ_REMOVE, we are going to panic in
-			 * rte_eal_init() */
-			goto fail;
+			if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+				/* no need to TAILQ_REMOVE, we are going
+				 * to panic in rte_eal_init() */
+				goto fail;
+			} else {
+				/* This means our list of constructor is
+				 * no the same as primary. Just remove
+				 * that missing tailq and continue */
+				TAILQ_REMOVE(&rte_tailq_elem_head, t, next);
+			}
 		}
 	}