aboutsummaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/ssvm.c11
-rw-r--r--src/svm/svm.c38
-rw-r--r--src/svm/svm_fifo_segment.c2
-rw-r--r--src/svm/svmdb.c15
4 files changed, 52 insertions, 14 deletions
diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c
index 6cda1f279e8..23e3cf443c3 100644
--- a/src/svm/ssvm.c
+++ b/src/svm/ssvm.c
@@ -29,6 +29,9 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
if (ssvm->ssvm_size == 0)
return SSVM_API_ERROR_NO_SIZE;
+ if (CLIB_DEBUG > 1)
+ clib_warning ("[%d] creating segment '%s'", getpid (), ssvm->name);
+
ssvm_filename = format (0, "/dev/shm/%s%c", ssvm->name, 0);
unlink ((char *) ssvm_filename);
@@ -176,12 +179,18 @@ ssvm_delete (ssvm_private_t * ssvm)
fn = format (0, "/dev/shm/%s%c", ssvm->name, 0);
+ if (CLIB_DEBUG > 1)
+ clib_warning ("[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
+ ssvm->name, fn);
+
/* Throw away the backing file */
if (unlink ((char *) fn) < 0)
clib_unix_warning ("unlink segment '%s'", ssvm->name);
- munmap ((void *) ssvm->requested_va, ssvm->ssvm_size);
vec_free (fn);
+ vec_free (ssvm->name);
+
+ munmap ((void *) ssvm->requested_va, ssvm->ssvm_size);
}
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);
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index 69d4ecb9387..c80374a7ffe 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -105,7 +105,7 @@ svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
s->ssvm.ssvm_size = a->segment_size;
s->ssvm.i_am_master = 1;
s->ssvm.my_pid = getpid ();
- s->ssvm.name = (u8 *) a->segment_name;
+ s->ssvm.name = format (0, "%s", a->segment_name);
s->ssvm.requested_va = sm->next_baseva;
rv = ssvm_master_init (&s->ssvm, s - sm->segments);
diff --git a/src/svm/svmdb.c b/src/svm/svmdb.c
index 03dfe7c33d3..043b0924d84 100644
--- a/src/svm/svmdb.c
+++ b/src/svm/svmdb.c
@@ -106,11 +106,16 @@ svmdb_map (svmdb_map_args_t * dba)
}
/* Nope, it's our problem... */
- /* Add a bogus client (pid=0) so the svm won't be deallocated */
- oldheap = svm_push_pvt_heap (db_rp);
- vec_add1 (client->db_rp->client_pids, 0);
- svm_pop_heap (oldheap);
-
+ if (CLIB_DEBUG > 2)
+ {
+ /* Add a bogus client (pid=0) so the svm won't be deallocated */
+ clib_warning
+ ("[%d] adding fake client (pid=0) so '%s' won't be unlinked",
+ getpid (), db_rp->region_name);
+ oldheap = svm_push_pvt_heap (db_rp);
+ vec_add1 (client->db_rp->client_pids, 0);
+ svm_pop_heap (oldheap);
+ }
oldheap = svm_push_data_heap (db_rp);
vec_validate (hp, 0);