On 01-Nov-19 9:04 AM, yasufu...@gmail.com wrote:
From: Yasufumi Ogawa <ogawa.yasuf...@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 if several secondaries run as app containers because each
of containerized secondary has PID 1, and failed to reserve unique name
other than first one. To reserve unique name in each of containers, use
hostname in addition to PID.
Cc: sta...@dpdk.org
Signed-off-by: Yasufumi Ogawa <yasufu...@gmail.com>
---
lib/librte_eal/common/include/rte_fbarray.h | 2 +-
lib/librte_eal/linux/eal/eal_memalloc.c | 11 ++++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/librte_eal/common/include/rte_fbarray.h
b/lib/librte_eal/common/include/rte_fbarray.h
index 6dccdbec9..5c2815093 100644
--- a/lib/librte_eal/common/include/rte_fbarray.h
+++ b/lib/librte_eal/common/include/rte_fbarray.h
@@ -39,7 +39,7 @@ extern "C" {
#include <rte_compat.h>
#include <rte_rwlock.h>
-#define RTE_FBARRAY_NAME_LEN 64
+#define RTE_FBARRAY_NAME_LEN NAME_MAX
struct rte_fbarray {
char name[RTE_FBARRAY_NAME_LEN]; /**< name associated with an array */
diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c
b/lib/librte_eal/linux/eal/eal_memalloc.c
index af6d0d023..24f0275c9 100644
--- a/lib/librte_eal/linux/eal/eal_memalloc.c
+++ b/lib/librte_eal/linux/eal/eal_memalloc.c
@@ -1365,6 +1365,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 hostname[HOST_NAME_MAX] = { 0 };
if (msl->external)
return 0;
@@ -1373,9 +1374,13 @@ secondary_msl_create_walk(const struct rte_memseg_list
*msl,
primary_msl = &mcfg->memsegs[msl_idx];
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());
+ /* Create distinct fbarrays for each secondary by using PID and
+ * hostname. The reason why using hostname is because PID could be
+ * duplicated among secondaries if it is launched in a container.
+ */
+ gethostname(hostname, HOST_NAME_MAX);
+ snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s_%d",
+ primary_msl->memseg_arr.name, hostname, (int)getpid());
ret = rte_fbarray_init(&local_msl->memseg_arr, name,
primary_msl->memseg_arr.len,
I think the order should be reversed. Both containers and non-containers
can have their hostname set, and RTE_FBARRAY_NAME_LEN is of fairly
limited length, so if the hostname is long enough, the PID never gets
into the name string, resulting in duplicates. It is better have pid first.
Once that's fixed,
Acked-by: Anatoly Burakov <anatoly.bura...@intel.com>
--
Thanks,
Anatoly