aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm/svm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm/svm.c')
-rw-r--r--src/svm/svm.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/svm/svm.c b/src/svm/svm.c
index c96135cfd5b..600fa7448ac 100644
--- a/src/svm/svm.c
+++ b/src/svm/svm.c
@@ -458,14 +458,15 @@ svm_map_region (svm_map_region_args_t * a)
struct stat stat;
struct timespec ts, tsrem;
- if (CLIB_DEBUG > 1)
- clib_warning ("[%d] map region %s", getpid (), a->name);
-
ASSERT ((a->size & ~(MMAP_PAGESIZE - 1)) == a->size);
ASSERT (a->name);
shm_name = shm_name_from_svm_map_region_args (a);
+ if (CLIB_DEBUG > 1)
+ clib_warning ("[%d] map region %s: shm_open (%s)",
+ getpid (), a->name, shm_name);
+
svm_fd = shm_open ((char *) shm_name, O_RDWR | O_CREAT | O_EXCL, 0777);
if (svm_fd >= 0)
@@ -947,6 +948,29 @@ svm_region_find_or_create (svm_map_region_args_t * a)
return (rp);
}
+void
+svm_region_unlink (svm_region_t * rp)
+{
+ svm_map_region_args_t _a, *a = &_a;
+ svm_main_region_t *mp;
+ u8 *shm_name;
+
+ ASSERT (root_rp);
+ ASSERT (rp);
+ ASSERT (vec_c_string_is_terminated (rp->region_name));
+
+ mp = root_rp->data_base;
+ ASSERT (mp);
+
+ a->root_path = (char *) mp->root_path;
+ a->name = rp->region_name;
+ shm_name = shm_name_from_svm_map_region_args (a);
+ if (CLIB_DEBUG > 1)
+ clib_warning ("[%d] shm_unlink (%s)", getpid (), shm_name);
+ shm_unlink ((const char *) shm_name);
+ vec_free (shm_name);
+}
+
/*
* svm_region_unmap
*
@@ -1056,7 +1080,7 @@ found:
vec_free (name);
region_unlock (rp);
- shm_unlink (rp->region_name);
+ svm_region_unlink (rp);
munmap ((void *) virtual_base, virtual_size);
region_unlock (root_rp);
svm_pop_heap (oldheap);
@@ -1071,9 +1095,6 @@ found:
/*
* svm_region_exit
- * There is no clean way to unlink the
- * root region when all clients go away,
- * so remove the pid entry and call it a day.
*/
void
svm_region_exit ()
@@ -1116,6 +1137,9 @@ svm_region_exit ()
found:
+ if (vec_len (root_rp->client_pids) == 0)
+ svm_region_unlink (root_rp);
+
region_unlock (root_rp);
svm_pop_heap (oldheap);