X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fssvm.c;h=c04982de85a0c37c9766c90863b40caf288e657d;hb=2019748a0ef815852281aae0a603f0e970fa9d91;hp=6f409eb68b628f08c08683bdb7a1f69141957c22;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/svm/ssvm.c b/src/svm/ssvm.c index 6f409eb68b6..c04982de85a 100644 --- a/src/svm/ssvm.c +++ b/src/svm/ssvm.c @@ -13,10 +13,12 @@ * limitations under the License. */ #include "ssvm.h" +#include "svm_common.h" int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index) { + svm_main_region_t *smr = svm_get_root_rp ()->data_base; int ssvm_fd; u8 *ssvm_filename; u8 junk = 0; @@ -29,6 +31,10 @@ 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); + + ASSERT (vec_c_string_is_terminated (ssvm->name)); ssvm_filename = format (0, "/dev/shm/%s%c", ssvm->name, 0); unlink ((char *) ssvm_filename); @@ -43,6 +49,11 @@ ssvm_master_init (ssvm_private_t * ssvm, u32 master_index) return SSVM_API_ERROR_CREATE_FAILURE; } + if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) + clib_unix_warning ("ssvm segment chmod"); + if (fchown (ssvm_fd, smr->uid, smr->gid) < 0) + clib_unix_warning ("ssvm segment chown"); + if (lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET) < 0) { clib_unix_warning ("lseek"); @@ -107,6 +118,7 @@ ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds) int ssvm_fd = -1; ssvm_shared_header_t *sh; + ASSERT (vec_c_string_is_terminated (ssvm->name)); ssvm->i_am_master = 0; while (timeout_in_seconds-- > 0) @@ -169,6 +181,28 @@ re_map_it: return 0; } +void +ssvm_delete (ssvm_private_t * ssvm) +{ + u8 *fn; + + 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); + + vec_free (fn); + vec_free (ssvm->name); + + munmap ((void *) ssvm->requested_va, ssvm->ssvm_size); +} + + /* * fd.io coding-style-patch-verification: ON *