Message ID | 1456251287-65413-1-git-send-email-christophe.milard@linaro.org |
---|---|
State | Accepted |
Commit | 90d706251b2d000ae9682857f2e551a32e924778 |
Headers | show |
How look up for 2 process with the same shm name should work if we add prefix to shm files? In my understanding we need pids only for pools. Maxim. On 02/23/16 21:14, Christophe Milard wrote: > The name of the shared memory (created with linux shm_open() > when the ODP_SHM_PROC flag is given) is now prefixed with > "/odp-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem. > > Signed-off-by: Christophe Milard <christophe.milard@linaro.org> > Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> > --- > > since v1: fixed typo in commit message (Nikolay Nikolaev) > > platform/linux-generic/include/odp_internal.h | 2 ++ > platform/linux-generic/odp_init.c | 3 +++ > platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- > 3 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h > index e75154a..98a5699 100644 > --- a/platform/linux-generic/include/odp_internal.h > +++ b/platform/linux-generic/include/odp_internal.h > @@ -21,6 +21,7 @@ extern "C" { > #include <odp/init.h> > #include <odp/thread.h> > #include <stdio.h> > +#include <sys/types.h> > > extern __thread int __odp_errno; > > @@ -37,6 +38,7 @@ typedef struct { > } odp_system_info_t; > > struct odp_global_data_s { > + pid_t main_pid; > odp_log_func_t log_fn; > odp_abort_func_t abort_fn; > odp_system_info_t system_info; > diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c > index 3a990d2..4a5e687 100644 > --- a/platform/linux-generic/odp_init.c > +++ b/platform/linux-generic/odp_init.c > @@ -8,12 +8,15 @@ > #include <odp_internal.h> > #include <odp/debug.h> > #include <odp_debug_internal.h> > +#include <unistd.h> > > struct odp_global_data_s odp_global_data; > > int odp_init_global(const odp_init_t *params, > const odp_platform_init_t *platform_params ODP_UNUSED) > { > + odp_global_data.main_pid = getpid(); > + > enum init_stage stage = NO_INIT; > odp_global_data.log_fn = odp_override_log; > odp_global_data.abort_fn = odp_override_abort; > diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c > index 7847cc9..81000cb 100644 > --- a/platform/linux-generic/odp_shared_memory.c > +++ b/platform/linux-generic/odp_shared_memory.c > @@ -26,6 +26,9 @@ > #include <string.h> > #include <errno.h> > > +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) > +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */ > + > _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, > "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); > > @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm) > uint32_t i; > int ret; > odp_shm_block_t *block; > + char shm_devname[SHM_DEVNAME_MAXLEN]; > > if (shm == ODP_SHM_INVALID) { > ODP_DBG("odp_shm_free: Invalid handle\n"); > @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm) > } > > if (block->flags & ODP_SHM_PROC) { > - ret = shm_unlink(block->name); > + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, > + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, > + block->name); > + ret = shm_unlink(shm_devname); > if (0 != ret) { > ODP_DBG("odp_shm_free: shm_unlink failed\n"); > odp_spinlock_unlock(&odp_shm_tbl->lock); > @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, > uint32_t flags) > { > uint32_t i; > + char shm_devname[SHM_DEVNAME_MAXLEN]; > odp_shm_block_t *block; > void *addr; > int fd = -1; > @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, > #endif > > if (flags & ODP_SHM_PROC) { > - /* Creates a file to /dev/shm */ > - fd = shm_open(name, oflag, > + /* Creates a file to /dev/shm/odp */ > + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, > + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, name); > + fd = shm_open(shm_devname, oflag, > S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); > if (fd == -1) { > - ODP_DBG("%s: shm_open failed.\n", name); > + ODP_DBG("%s: shm_open failed.\n", shm_devname); > return ODP_SHM_INVALID; > } > } else {
I merged that patch to next, will be in rc1. Maxim. On 02/23/16 21:14, Christophe Milard wrote: > The name of the shared memory (created with linux shm_open() > when the ODP_SHM_PROC flag is given) is now prefixed with > "/odp-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem. > > Signed-off-by: Christophe Milard <christophe.milard@linaro.org> > Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> > --- > > since v1: fixed typo in commit message (Nikolay Nikolaev) > > platform/linux-generic/include/odp_internal.h | 2 ++ > platform/linux-generic/odp_init.c | 3 +++ > platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- > 3 files changed, 19 insertions(+), 4 deletions(-) > > diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h > index e75154a..98a5699 100644 > --- a/platform/linux-generic/include/odp_internal.h > +++ b/platform/linux-generic/include/odp_internal.h > @@ -21,6 +21,7 @@ extern "C" { > #include <odp/init.h> > #include <odp/thread.h> > #include <stdio.h> > +#include <sys/types.h> > > extern __thread int __odp_errno; > > @@ -37,6 +38,7 @@ typedef struct { > } odp_system_info_t; > > struct odp_global_data_s { > + pid_t main_pid; > odp_log_func_t log_fn; > odp_abort_func_t abort_fn; > odp_system_info_t system_info; > diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c > index 3a990d2..4a5e687 100644 > --- a/platform/linux-generic/odp_init.c > +++ b/platform/linux-generic/odp_init.c > @@ -8,12 +8,15 @@ > #include <odp_internal.h> > #include <odp/debug.h> > #include <odp_debug_internal.h> > +#include <unistd.h> > > struct odp_global_data_s odp_global_data; > > int odp_init_global(const odp_init_t *params, > const odp_platform_init_t *platform_params ODP_UNUSED) > { > + odp_global_data.main_pid = getpid(); > + > enum init_stage stage = NO_INIT; > odp_global_data.log_fn = odp_override_log; > odp_global_data.abort_fn = odp_override_abort; > diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c > index 7847cc9..81000cb 100644 > --- a/platform/linux-generic/odp_shared_memory.c > +++ b/platform/linux-generic/odp_shared_memory.c > @@ -26,6 +26,9 @@ > #include <string.h> > #include <errno.h> > > +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) > +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */ > + > _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, > "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); > > @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm) > uint32_t i; > int ret; > odp_shm_block_t *block; > + char shm_devname[SHM_DEVNAME_MAXLEN]; > > if (shm == ODP_SHM_INVALID) { > ODP_DBG("odp_shm_free: Invalid handle\n"); > @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm) > } > > if (block->flags & ODP_SHM_PROC) { > - ret = shm_unlink(block->name); > + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, > + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, > + block->name); > + ret = shm_unlink(shm_devname); > if (0 != ret) { > ODP_DBG("odp_shm_free: shm_unlink failed\n"); > odp_spinlock_unlock(&odp_shm_tbl->lock); > @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, > uint32_t flags) > { > uint32_t i; > + char shm_devname[SHM_DEVNAME_MAXLEN]; > odp_shm_block_t *block; > void *addr; > int fd = -1; > @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, > #endif > > if (flags & ODP_SHM_PROC) { > - /* Creates a file to /dev/shm */ > - fd = shm_open(name, oflag, > + /* Creates a file to /dev/shm/odp */ > + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, > + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, name); > + fd = shm_open(shm_devname, oflag, > S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); > if (fd == -1) { > - ODP_DBG("%s: shm_open failed.\n", name); > + ODP_DBG("%s: shm_open failed.\n", shm_devname); > return ODP_SHM_INVALID; > } > } else {
On 3 March 2016 at 14:55, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: > I merged that patch to next, will be in rc1. Nothing ever goes into next, see our release-guide [1]. Cheers, Anders [1] http://docs.opendataplane.org/master/linux-generic/output/release-guide.html > > Maxim. > > On 02/23/16 21:14, Christophe Milard wrote: >> >> The name of the shared memory (created with linux shm_open() >> when the ODP_SHM_PROC flag is given) is now prefixed with >> "/odp-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem. >> >> Signed-off-by: Christophe Milard <christophe.milard@linaro.org> >> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> >> --- >> >> since v1: fixed typo in commit message (Nikolay Nikolaev) >> >> platform/linux-generic/include/odp_internal.h | 2 ++ >> platform/linux-generic/odp_init.c | 3 +++ >> platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- >> 3 files changed, 19 insertions(+), 4 deletions(-) >> >> diff --git a/platform/linux-generic/include/odp_internal.h >> b/platform/linux-generic/include/odp_internal.h >> index e75154a..98a5699 100644 >> --- a/platform/linux-generic/include/odp_internal.h >> +++ b/platform/linux-generic/include/odp_internal.h >> @@ -21,6 +21,7 @@ extern "C" { >> #include <odp/init.h> >> #include <odp/thread.h> >> #include <stdio.h> >> +#include <sys/types.h> >> extern __thread int __odp_errno; >> @@ -37,6 +38,7 @@ typedef struct { >> } odp_system_info_t; >> struct odp_global_data_s { >> + pid_t main_pid; >> odp_log_func_t log_fn; >> odp_abort_func_t abort_fn; >> odp_system_info_t system_info; >> diff --git a/platform/linux-generic/odp_init.c >> b/platform/linux-generic/odp_init.c >> index 3a990d2..4a5e687 100644 >> --- a/platform/linux-generic/odp_init.c >> +++ b/platform/linux-generic/odp_init.c >> @@ -8,12 +8,15 @@ >> #include <odp_internal.h> >> #include <odp/debug.h> >> #include <odp_debug_internal.h> >> +#include <unistd.h> >> struct odp_global_data_s odp_global_data; >> int odp_init_global(const odp_init_t *params, >> const odp_platform_init_t *platform_params ODP_UNUSED) >> { >> + odp_global_data.main_pid = getpid(); >> + >> enum init_stage stage = NO_INIT; >> odp_global_data.log_fn = odp_override_log; >> odp_global_data.abort_fn = odp_override_abort; >> diff --git a/platform/linux-generic/odp_shared_memory.c >> b/platform/linux-generic/odp_shared_memory.c >> index 7847cc9..81000cb 100644 >> --- a/platform/linux-generic/odp_shared_memory.c >> +++ b/platform/linux-generic/odp_shared_memory.c >> @@ -26,6 +26,9 @@ >> #include <string.h> >> #include <errno.h> >> +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) >> +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */ >> + >> _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, >> "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); >> @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm) >> uint32_t i; >> int ret; >> odp_shm_block_t *block; >> + char shm_devname[SHM_DEVNAME_MAXLEN]; >> if (shm == ODP_SHM_INVALID) { >> ODP_DBG("odp_shm_free: Invalid handle\n"); >> @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm) >> } >> if (block->flags & ODP_SHM_PROC) { >> - ret = shm_unlink(block->name); >> + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, >> + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, >> + block->name); >> + ret = shm_unlink(shm_devname); >> if (0 != ret) { >> ODP_DBG("odp_shm_free: shm_unlink failed\n"); >> odp_spinlock_unlock(&odp_shm_tbl->lock); >> @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t >> size, uint64_t align, >> uint32_t flags) >> { >> uint32_t i; >> + char shm_devname[SHM_DEVNAME_MAXLEN]; >> odp_shm_block_t *block; >> void *addr; >> int fd = -1; >> @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t >> size, uint64_t align, >> #endif >> if (flags & ODP_SHM_PROC) { >> - /* Creates a file to /dev/shm */ >> - fd = shm_open(name, oflag, >> + /* Creates a file to /dev/shm/odp */ >> + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, >> + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, >> name); >> + fd = shm_open(shm_devname, oflag, >> S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); >> if (fd == -1) { >> - ODP_DBG("%s: shm_open failed.\n", name); >> + ODP_DBG("%s: shm_open failed.\n", shm_devname); >> return ODP_SHM_INVALID; >> } >> } else { > > > _______________________________________________ > lng-odp mailing list > lng-odp@lists.linaro.org > https://lists.linaro.org/mailman/listinfo/lng-odp
On 03/03/16 17:26, Anders Roxell wrote: > On 3 March 2016 at 14:55, Maxim Uvarov <maxim.uvarov@linaro.org> wrote: >> I merged that patch to next, will be in rc1. > Nothing ever goes into next, see our release-guide [1]. > > Cheers, > Anders > [1] http://docs.opendataplane.org/master/linux-generic/output/release-guide.html Right, I planned to rebase next so it will be the same as it will go to master. But according to rules I removed it from next and merged to master. Maxim. >> Maxim. >> >> On 02/23/16 21:14, Christophe Milard wrote: >>> The name of the shared memory (created with linux shm_open() >>> when the ODP_SHM_PROC flag is given) is now prefixed with >>> "/odp-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem. >>> >>> Signed-off-by: Christophe Milard <christophe.milard@linaro.org> >>> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> >>> --- >>> >>> since v1: fixed typo in commit message (Nikolay Nikolaev) >>> >>> platform/linux-generic/include/odp_internal.h | 2 ++ >>> platform/linux-generic/odp_init.c | 3 +++ >>> platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- >>> 3 files changed, 19 insertions(+), 4 deletions(-) >>> >>> diff --git a/platform/linux-generic/include/odp_internal.h >>> b/platform/linux-generic/include/odp_internal.h >>> index e75154a..98a5699 100644 >>> --- a/platform/linux-generic/include/odp_internal.h >>> +++ b/platform/linux-generic/include/odp_internal.h >>> @@ -21,6 +21,7 @@ extern "C" { >>> #include <odp/init.h> >>> #include <odp/thread.h> >>> #include <stdio.h> >>> +#include <sys/types.h> >>> extern __thread int __odp_errno; >>> @@ -37,6 +38,7 @@ typedef struct { >>> } odp_system_info_t; >>> struct odp_global_data_s { >>> + pid_t main_pid; >>> odp_log_func_t log_fn; >>> odp_abort_func_t abort_fn; >>> odp_system_info_t system_info; >>> diff --git a/platform/linux-generic/odp_init.c >>> b/platform/linux-generic/odp_init.c >>> index 3a990d2..4a5e687 100644 >>> --- a/platform/linux-generic/odp_init.c >>> +++ b/platform/linux-generic/odp_init.c >>> @@ -8,12 +8,15 @@ >>> #include <odp_internal.h> >>> #include <odp/debug.h> >>> #include <odp_debug_internal.h> >>> +#include <unistd.h> >>> struct odp_global_data_s odp_global_data; >>> int odp_init_global(const odp_init_t *params, >>> const odp_platform_init_t *platform_params ODP_UNUSED) >>> { >>> + odp_global_data.main_pid = getpid(); >>> + >>> enum init_stage stage = NO_INIT; >>> odp_global_data.log_fn = odp_override_log; >>> odp_global_data.abort_fn = odp_override_abort; >>> diff --git a/platform/linux-generic/odp_shared_memory.c >>> b/platform/linux-generic/odp_shared_memory.c >>> index 7847cc9..81000cb 100644 >>> --- a/platform/linux-generic/odp_shared_memory.c >>> +++ b/platform/linux-generic/odp_shared_memory.c >>> @@ -26,6 +26,9 @@ >>> #include <string.h> >>> #include <errno.h> >>> +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) >>> +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */ >>> + >>> _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, >>> "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); >>> @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm) >>> uint32_t i; >>> int ret; >>> odp_shm_block_t *block; >>> + char shm_devname[SHM_DEVNAME_MAXLEN]; >>> if (shm == ODP_SHM_INVALID) { >>> ODP_DBG("odp_shm_free: Invalid handle\n"); >>> @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm) >>> } >>> if (block->flags & ODP_SHM_PROC) { >>> - ret = shm_unlink(block->name); >>> + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, >>> + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, >>> + block->name); >>> + ret = shm_unlink(shm_devname); >>> if (0 != ret) { >>> ODP_DBG("odp_shm_free: shm_unlink failed\n"); >>> odp_spinlock_unlock(&odp_shm_tbl->lock); >>> @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t >>> size, uint64_t align, >>> uint32_t flags) >>> { >>> uint32_t i; >>> + char shm_devname[SHM_DEVNAME_MAXLEN]; >>> odp_shm_block_t *block; >>> void *addr; >>> int fd = -1; >>> @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t >>> size, uint64_t align, >>> #endif >>> if (flags & ODP_SHM_PROC) { >>> - /* Creates a file to /dev/shm */ >>> - fd = shm_open(name, oflag, >>> + /* Creates a file to /dev/shm/odp */ >>> + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, >>> + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, >>> name); >>> + fd = shm_open(shm_devname, oflag, >>> S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); >>> if (fd == -1) { >>> - ODP_DBG("%s: shm_open failed.\n", name); >>> + ODP_DBG("%s: shm_open failed.\n", shm_devname); >>> return ODP_SHM_INVALID; >>> } >>> } else { >> >> _______________________________________________ >> lng-odp mailing list >> lng-odp@lists.linaro.org >> https://lists.linaro.org/mailman/listinfo/lng-odp
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index e75154a..98a5699 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -21,6 +21,7 @@ extern "C" { #include <odp/init.h> #include <odp/thread.h> #include <stdio.h> +#include <sys/types.h> extern __thread int __odp_errno; @@ -37,6 +38,7 @@ typedef struct { } odp_system_info_t; struct odp_global_data_s { + pid_t main_pid; odp_log_func_t log_fn; odp_abort_func_t abort_fn; odp_system_info_t system_info; diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index 3a990d2..4a5e687 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -8,12 +8,15 @@ #include <odp_internal.h> #include <odp/debug.h> #include <odp_debug_internal.h> +#include <unistd.h> struct odp_global_data_s odp_global_data; int odp_init_global(const odp_init_t *params, const odp_platform_init_t *platform_params ODP_UNUSED) { + odp_global_data.main_pid = getpid(); + enum init_stage stage = NO_INIT; odp_global_data.log_fn = odp_override_log; odp_global_data.abort_fn = odp_override_abort; diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 7847cc9..81000cb 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -26,6 +26,9 @@ #include <string.h> #include <errno.h> +#define SHM_DEVNAME_MAXLEN (ODP_SHM_NAME_LEN + 16) +#define SHM_DEVNAME_FORMAT "/odp-%d-%s" /* /dev/shm/odp-<pid>-<name> */ + _ODP_STATIC_ASSERT(ODP_CONFIG_SHM_BLOCKS >= ODP_CONFIG_POOLS, "ODP_CONFIG_SHM_BLOCKS < ODP_CONFIG_POOLS"); @@ -135,6 +138,7 @@ int odp_shm_free(odp_shm_t shm) uint32_t i; int ret; odp_shm_block_t *block; + char shm_devname[SHM_DEVNAME_MAXLEN]; if (shm == ODP_SHM_INVALID) { ODP_DBG("odp_shm_free: Invalid handle\n"); @@ -167,7 +171,10 @@ int odp_shm_free(odp_shm_t shm) } if (block->flags & ODP_SHM_PROC) { - ret = shm_unlink(block->name); + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, + block->name); + ret = shm_unlink(shm_devname); if (0 != ret) { ODP_DBG("odp_shm_free: shm_unlink failed\n"); odp_spinlock_unlock(&odp_shm_tbl->lock); @@ -183,6 +190,7 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags) { uint32_t i; + char shm_devname[SHM_DEVNAME_MAXLEN]; odp_shm_block_t *block; void *addr; int fd = -1; @@ -207,11 +215,13 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, #endif if (flags & ODP_SHM_PROC) { - /* Creates a file to /dev/shm */ - fd = shm_open(name, oflag, + /* Creates a file to /dev/shm/odp */ + snprintf(shm_devname, SHM_DEVNAME_MAXLEN, + SHM_DEVNAME_FORMAT, odp_global_data.main_pid, name); + fd = shm_open(shm_devname, oflag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd == -1) { - ODP_DBG("%s: shm_open failed.\n", name); + ODP_DBG("%s: shm_open failed.\n", shm_devname); return ODP_SHM_INVALID; } } else {
The name of the shared memory (created with linux shm_open() when the ODP_SHM_PROC flag is given) is now prefixed with "/odp-<odp_pid>-" so as to name scope ODP shared mem in /dev/shmem. Signed-off-by: Christophe Milard <christophe.milard@linaro.org> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> --- since v1: fixed typo in commit message (Nikolay Nikolaev) platform/linux-generic/include/odp_internal.h | 2 ++ platform/linux-generic/odp_init.c | 3 +++ platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-)