summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
authorDave Wallace <dwallacelf@gmail.com>2017-07-03 13:11:38 -0400
committerDave Wallace <dwallacelf@gmail.com>2017-07-17 21:00:52 -0400
commitd756b35032cdf7fdaaf0d6611388a54d32d72e92 (patch)
tree21c9626d87fde1c935755862811b339dc7338ad1 /src/svm
parent365a2b851024080c2f8f59bce2b61f243a85c254 (diff)
Fix unlinking of /dev/shm files.
- api-segment prefix not used when unlinking shm files - unlink root region on exit if no clients referenced - stale reference to freed segment name - don't add fake client to /db unless CLIB_DEBUG > 2 - turn off the gmond plugin - clean up unused vars in vpp/api Change-Id: I66451fcfd6ee64a12466c2d6c209050e3cdb74b7 Signed-off-by: Dave Wallace <dwallacelf@gmail.com> Signed-off-by: Dave Barach <dave@barachs.net>
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);