From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 9CB98A00E6 for ; Tue, 16 Apr 2019 05:45:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E29611B455; Tue, 16 Apr 2019 05:45:43 +0200 (CEST) Received: from tama500.ecl.ntt.co.jp (tama500.ecl.ntt.co.jp [129.60.39.148]) by dpdk.org (Postfix) with ESMTP id BCA911B454; Tue, 16 Apr 2019 05:45:41 +0200 (CEST) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x3G3jeMG004276; Tue, 16 Apr 2019 12:45:40 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id E7C6CEA79F3; Tue, 16 Apr 2019 12:45:39 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id DA140EA7894; Tue, 16 Apr 2019 12:45:39 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: anatoly.burakov@intel.com Cc: dev@dpdk.org, stable@dpdk.org, Yasufumi Ogawa Date: Tue, 16 Apr 2019 12:43:23 +0900 Message-Id: <1555386203-23776-2-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1555386203-23776-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1555379952-23517-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> <1555386203-23776-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [dpdk-dev] [PATCH v2 1/1] fbarray: get fbarrays from containerized secondary X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190416034323.OAkcHaTfH2w9VMIOIGJaafrq_I-nfV_YQ5PaoCJh6fc@z> From: Yasufumi Ogawa In secondary_msl_create_walk(), it creates a file for fbarrays with its PID for reserving unique name among secondary processes. However, it does not work if secondary is run as app container because each of containerized secondary has PID 1. To reserve unique name, use hostname instead of PID if the value is 1. Cc: stable@dpdk.org Signed-off-by: Yasufumi Ogawa --- lib/librte_eal/linux/eal/eal_memalloc.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c index 1e9ebb86d..beec03648 100644 --- a/lib/librte_eal/linux/eal/eal_memalloc.c +++ b/lib/librte_eal/linux/eal/eal_memalloc.c @@ -1362,6 +1362,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl, struct rte_memseg_list *primary_msl, *local_msl; char name[PATH_MAX]; int msl_idx, ret; + char proc_id[16]; if (msl->external) return 0; @@ -1371,8 +1372,28 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl, local_msl = &local_memsegs[msl_idx]; /* create distinct fbarrays for each secondary */ - snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i", - primary_msl->memseg_arr.name, getpid()); + /* if run secondary in a container, the name of fbarray file cannot + * be decided with pid because getpid() always returns 1, so use + * hostname as a unique identifier among containers instead. + */ + if (getpid() == 1) { + FILE *hn_fp; + hn_fp = fopen("/etc/hostname", "r"); + if (hn_fp == NULL) { + RTE_LOG(ERR, EAL, + "Cannot open '/etc/hostname' for secondary\n"); + return -1; + } + + /* with docker, /etc/hostname just has one entry of hostname */ + if (fscanf(hn_fp, "%s", proc_id) == EOF) + return -1; + fclose(hn_fp); + } else + sprintf(proc_id, "%d", (int)getpid()); + + snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s", + primary_msl->memseg_arr.name, proc_id); ret = rte_fbarray_init(&local_msl->memseg_arr, name, primary_msl->memseg_arr.len, -- 2.17.1