From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by dpdk.org (Postfix) with ESMTP id 7DB7E1B39B; Tue, 16 Apr 2019 04:01:47 +0200 (CEST) Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x3G21jkO021649; Tue, 16 Apr 2019 11:01:45 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 9FC2D63848B; Tue, 16 Apr 2019 11:01:45 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 9087D638480; Tue, 16 Apr 2019 11:01:45 +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 10:59:12 +0900 Message-Id: <1555379952-23517-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 X-TM-AS-MML: disable Subject: [dpdk-dev] [PATCH] 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: , X-List-Received-Date: Tue, 16 Apr 2019 02:01:48 -0000 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 as expected if secondary is run as app container becuase 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 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 A2B51A00E6 for ; Tue, 16 Apr 2019 04:01:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EE7E71B43C; Tue, 16 Apr 2019 04:01:49 +0200 (CEST) Received: from tama50.ecl.ntt.co.jp (tama50.ecl.ntt.co.jp [129.60.39.147]) by dpdk.org (Postfix) with ESMTP id 7DB7E1B39B; Tue, 16 Apr 2019 04:01:47 +0200 (CEST) Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x3G21jkO021649; Tue, 16 Apr 2019 11:01:45 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 9FC2D63848B; Tue, 16 Apr 2019 11:01:45 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 9087D638480; Tue, 16 Apr 2019 11:01:45 +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 10:59:12 +0900 Message-Id: <1555379952-23517-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 X-TM-AS-MML: disable Subject: [dpdk-dev] [PATCH] 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: <20190416015912.48E9p_jXqZ7uRPyYC5vVE6xY9ZEIg3-eXt9lNKWTX9g@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 as expected if secondary is run as app container becuase 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