fbarray: get fbarrays from containerized secondary

Message ID 1555379952-23517-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp (mailing list archive)
State Superseded, archived
Headers
Series fbarray: get fbarrays from containerized secondary |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS

Commit Message

Yasufumi Ogawa April 16, 2019, 1:59 a.m. UTC
  From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

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 <ogawa.yasufumi@lab.ntt.co.jp>
---
 lib/librte_eal/linux/eal/eal_memalloc.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger June 13, 2023, 4:51 p.m. UTC | #1
On Tue, 16 Apr 2019 10:59:12 +0900
ogawa.yasufumi@lab.ntt.co.jp wrote:

> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> 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 <ogawa.yasufumi@lab.ntt.co.jp>
> ---

Since this is an ABI break. I propose that a more invasive solution
would be better. Either change to using something more unique GUID
or change the fbarray structure to be a variable length array.
The internals of fbarray should also be hidden (ie not in rte_fbarray.h)
and the init() function changed into something that allocates the array.

The current patch has not gotten any followup or acceptance in 4 years.
So marking it as changes requested.
  

Patch

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,