blob: 69463b1f192628ab5989ca54391a18eee25836b4 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Florin Corasc5df8c72019-04-08 07:42:30 -07002 * Copyright (c) 2015-2019 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
Florin Coras4d9b9d82018-01-14 12:25:50 -080015#include <svm/ssvm.h>
16#include <svm/svm_common.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070017
Florin Corasb384b542018-01-15 01:08:33 -080018typedef int (*init_fn) (ssvm_private_t *);
19typedef void (*delete_fn) (ssvm_private_t *);
20
21static init_fn master_init_fns[SSVM_N_SEGMENT_TYPES] =
Florin Corasa332c462018-01-31 06:52:17 -080022 { ssvm_master_init_shm, ssvm_master_init_memfd, ssvm_master_init_private };
Florin Corasb384b542018-01-15 01:08:33 -080023static init_fn slave_init_fns[SSVM_N_SEGMENT_TYPES] =
Florin Corasa332c462018-01-31 06:52:17 -080024 { ssvm_slave_init_shm, ssvm_slave_init_memfd, ssvm_slave_init_private };
Florin Corasb384b542018-01-15 01:08:33 -080025static delete_fn delete_fns[SSVM_N_SEGMENT_TYPES] =
Florin Corasa332c462018-01-31 06:52:17 -080026 { ssvm_delete_shm, ssvm_delete_memfd, ssvm_delete_private };
Florin Corasb384b542018-01-15 01:08:33 -080027
Dave Barach8a7fb0c2016-07-08 14:44:23 -040028int
Florin Corasb384b542018-01-15 01:08:33 -080029ssvm_master_init_shm (ssvm_private_t * ssvm)
Ed Warnickecb9cada2015-12-08 15:45:58 -070030{
Dave Barach6a5adc32018-07-04 10:56:23 -040031 int ssvm_fd;
32#if USE_DLMALLOC == 0
33 int mh_flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
34#endif
Florin Corasb384b542018-01-15 01:08:33 -080035 clib_mem_vm_map_t mapa = { 0 };
36 u8 junk = 0, *ssvm_filename;
Dave Barach8a7fb0c2016-07-08 14:44:23 -040037 ssvm_shared_header_t *sh;
Florin Corasf8f516a2018-02-08 15:10:09 -080038 uword page_size, requested_va = 0;
Dave Barach8a7fb0c2016-07-08 14:44:23 -040039 void *oldheap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070040
41 if (ssvm->ssvm_size == 0)
42 return SSVM_API_ERROR_NO_SIZE;
43
Dave Wallaced756b352017-07-03 13:11:38 -040044 if (CLIB_DEBUG > 1)
45 clib_warning ("[%d] creating segment '%s'", getpid (), ssvm->name);
46
Dave Wallaceb8856642017-07-31 13:33:11 -040047 ASSERT (vec_c_string_is_terminated (ssvm->name));
Ed Warnickecb9cada2015-12-08 15:45:58 -070048 ssvm_filename = format (0, "/dev/shm/%s%c", ssvm->name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070049 unlink ((char *) ssvm_filename);
Dave Barach8a7fb0c2016-07-08 14:44:23 -040050 vec_free (ssvm_filename);
Ed Warnickecb9cada2015-12-08 15:45:58 -070051
Dave Barach8a7fb0c2016-07-08 14:44:23 -040052 ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
Ed Warnickecb9cada2015-12-08 15:45:58 -070053 if (ssvm_fd < 0)
54 {
55 clib_unix_warning ("create segment '%s'", ssvm->name);
56 return SSVM_API_ERROR_CREATE_FAILURE;
57 }
58
Dave Wallace19296112017-08-31 15:54:11 -040059 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
60 clib_unix_warning ("ssvm segment chmod");
Florin Coras65784c12018-07-04 04:17:41 -070061 if (svm_get_root_rp ())
62 {
63 /* TODO: is this really needed? */
64 svm_main_region_t *smr = svm_get_root_rp ()->data_base;
65 if (fchown (ssvm_fd, smr->uid, smr->gid) < 0)
66 clib_unix_warning ("ssvm segment chown");
67 }
Dave Wallace19296112017-08-31 15:54:11 -040068
Dave Barach56faee82016-08-04 18:58:05 -040069 if (lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET) < 0)
70 {
71 clib_unix_warning ("lseek");
72 close (ssvm_fd);
73 return SSVM_API_ERROR_SET_SIZE;
74 }
Ed Warnicke853e7202016-08-12 11:42:26 -070075
Dave Barach8a7fb0c2016-07-08 14:44:23 -040076 if (write (ssvm_fd, &junk, 1) != 1)
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 {
78 clib_unix_warning ("set ssvm size");
Dave Barach8a7fb0c2016-07-08 14:44:23 -040079 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070080 return SSVM_API_ERROR_SET_SIZE;
81 }
Dave Barach8a7fb0c2016-07-08 14:44:23 -040082
Damjan Marion567e61d2018-10-24 17:08:26 +020083 page_size = clib_mem_get_fd_page_size (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 if (ssvm->requested_va)
Florin Corasf8f516a2018-02-08 15:10:09 -080085 {
86 requested_va = ssvm->requested_va;
87 clib_mem_vm_randomize_va (&requested_va, min_log2 (page_size));
88 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070089
Florin Corasf8f516a2018-02-08 15:10:09 -080090 mapa.requested_va = requested_va;
Florin Corasb384b542018-01-15 01:08:33 -080091 mapa.size = ssvm->ssvm_size;
92 mapa.fd = ssvm_fd;
93 if (clib_mem_vm_ext_map (&mapa))
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 {
95 clib_unix_warning ("mmap");
Dave Barach8a7fb0c2016-07-08 14:44:23 -040096 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 return SSVM_API_ERROR_MMAP;
98 }
Dave Barach8a7fb0c2016-07-08 14:44:23 -040099 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100
Florin Corasb384b542018-01-15 01:08:33 -0800101 sh = mapa.addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 sh->master_pid = ssvm->my_pid;
103 sh->ssvm_size = ssvm->ssvm_size;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400104 sh->ssvm_va = pointer_to_uword (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800105 sh->type = SSVM_SEGMENT_SHM;
Dave Barach6a5adc32018-07-04 10:56:23 -0400106#if USE_DLMALLOC == 0
Florin Corasb384b542018-01-15 01:08:33 -0800107 sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
108 ssvm->ssvm_size - page_size, mh_flags);
Dave Barach6a5adc32018-07-04 10:56:23 -0400109#else
110 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
111 ssvm->ssvm_size - page_size,
112 1 /* locked */ );
113 mspace_disable_expand (sh->heap);
114#endif
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
116 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800117 sh->name = format (0, "%s", ssvm->name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118 ssvm_pop_heap (oldheap);
119
Florin Corasb384b542018-01-15 01:08:33 -0800120 ssvm->sh = sh;
121 ssvm->my_pid = getpid ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 ssvm->i_am_master = 1;
123
124 /* The application has to set set sh->ready... */
125 return 0;
126}
127
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400128int
Florin Corasb384b542018-01-15 01:08:33 -0800129ssvm_slave_init_shm (ssvm_private_t * ssvm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130{
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400131 struct stat stat;
132 int ssvm_fd = -1;
133 ssvm_shared_header_t *sh;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Dave Wallaceb8856642017-07-31 13:33:11 -0400135 ASSERT (vec_c_string_is_terminated (ssvm->name));
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400136 ssvm->i_am_master = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137
Florin Corasb384b542018-01-15 01:08:33 -0800138 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400139 {
140 if (ssvm_fd < 0)
141 ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
142 if (ssvm_fd < 0)
143 {
144 sleep (1);
145 continue;
146 }
147 if (fstat (ssvm_fd, &stat) < 0)
148 {
149 sleep (1);
150 continue;
151 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400153 if (stat.st_size > 0)
154 goto map_it;
155 }
156 clib_warning ("slave timeout");
157 return SSVM_API_ERROR_SLAVE_TIMEOUT;
158
159map_it:
160 sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
161 ssvm_fd, 0);
162 if (sh == MAP_FAILED)
163 {
164 clib_unix_warning ("slave research mmap");
165 close (ssvm_fd);
166 return SSVM_API_ERROR_MMAP;
167 }
168
Florin Corasb384b542018-01-15 01:08:33 -0800169 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400170 {
171 if (sh->ready)
172 goto re_map_it;
173 }
174 close (ssvm_fd);
175 munmap (sh, MMAP_PAGESIZE);
176 clib_warning ("slave timeout 2");
177 return SSVM_API_ERROR_SLAVE_TIMEOUT;
178
179re_map_it:
David Johnsond9818dd2018-12-14 14:53:41 -0500180 ssvm->requested_va = sh->ssvm_va;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400181 ssvm->ssvm_size = sh->ssvm_size;
182 munmap (sh, MMAP_PAGESIZE);
183
184 sh = ssvm->sh = (void *) mmap ((void *) ssvm->requested_va, ssvm->ssvm_size,
185 PROT_READ | PROT_WRITE,
186 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
187
188 if (sh == MAP_FAILED)
189 {
190 clib_unix_warning ("slave final mmap");
191 close (ssvm_fd);
192 return SSVM_API_ERROR_MMAP;
193 }
194 sh->slave_pid = getpid ();
195 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196}
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400197
Dave Barach68b0fb02017-02-28 15:15:56 -0500198void
Florin Corasb384b542018-01-15 01:08:33 -0800199ssvm_delete_shm (ssvm_private_t * ssvm)
Dave Barach68b0fb02017-02-28 15:15:56 -0500200{
201 u8 *fn;
202
203 fn = format (0, "/dev/shm/%s%c", ssvm->name, 0);
204
Dave Wallaced756b352017-07-03 13:11:38 -0400205 if (CLIB_DEBUG > 1)
206 clib_warning ("[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
207 ssvm->name, fn);
208
Dave Barach68b0fb02017-02-28 15:15:56 -0500209 /* Throw away the backing file */
210 if (unlink ((char *) fn) < 0)
211 clib_unix_warning ("unlink segment '%s'", ssvm->name);
212
Dave Barach68b0fb02017-02-28 15:15:56 -0500213 vec_free (fn);
Dave Wallaced756b352017-07-03 13:11:38 -0400214 vec_free (ssvm->name);
215
Florin Coras6898e5c2019-07-01 08:57:42 -0700216 munmap ((void *) ssvm->sh, ssvm->ssvm_size);
Dave Barach68b0fb02017-02-28 15:15:56 -0500217}
218
Florin Corasb384b542018-01-15 01:08:33 -0800219/**
220 * Initialize memfd segment master
221 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800222int
Florin Corasb384b542018-01-15 01:08:33 -0800223ssvm_master_init_memfd (ssvm_private_t * memfd)
Florin Coras4d9b9d82018-01-14 12:25:50 -0800224{
Dave Barach6a5adc32018-07-04 10:56:23 -0400225 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800226 ssvm_shared_header_t *sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800227 void *oldheap;
Florin Corasd3e83a92018-01-16 02:40:18 -0800228 clib_mem_vm_alloc_t alloc = { 0 };
229 clib_error_t *err;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800230
231 if (memfd->ssvm_size == 0)
232 return SSVM_API_ERROR_NO_SIZE;
233
234 ASSERT (vec_c_string_is_terminated (memfd->name));
Florin Coras4d9b9d82018-01-14 12:25:50 -0800235
Florin Corasd3e83a92018-01-16 02:40:18 -0800236 alloc.name = (char *) memfd->name;
237 alloc.size = memfd->ssvm_size;
238 alloc.flags = CLIB_MEM_VM_F_SHARED;
Florin Corasb384b542018-01-15 01:08:33 -0800239 alloc.requested_va = memfd->requested_va;
Florin Corasd3e83a92018-01-16 02:40:18 -0800240 if ((err = clib_mem_vm_ext_alloc (&alloc)))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800241 {
Florin Corasd3e83a92018-01-16 02:40:18 -0800242 clib_error_report (err);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800243 return SSVM_API_ERROR_CREATE_FAILURE;
244 }
245
Florin Corasd3e83a92018-01-16 02:40:18 -0800246 memfd->fd = alloc.fd;
Florin Corasb384b542018-01-15 01:08:33 -0800247 memfd->sh = (ssvm_shared_header_t *) alloc.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800248 memfd->my_pid = getpid ();
Florin Corasd3e83a92018-01-16 02:40:18 -0800249 memfd->i_am_master = 1;
250
Haiyang Tana5ab5032018-10-15 06:17:55 -0700251 page_size = 1ull << alloc.log2_page_size;
Florin Corasb384b542018-01-15 01:08:33 -0800252 sh = memfd->sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800253 sh->master_pid = memfd->my_pid;
254 sh->ssvm_size = memfd->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800255 sh->ssvm_va = pointer_to_uword (sh);
256 sh->type = SSVM_SEGMENT_MEMFD;
Dave Barach6a5adc32018-07-04 10:56:23 -0400257
258#if USE_DLMALLOC == 0
259 uword flags = MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE;
260
Florin Corasd3e83a92018-01-16 02:40:18 -0800261 sh->heap = mheap_alloc_with_flags (((u8 *) sh) + page_size,
262 memfd->ssvm_size - page_size, flags);
Dave Barach6a5adc32018-07-04 10:56:23 -0400263#else
264 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
265 memfd->ssvm_size - page_size,
266 1 /* locked */ );
267 mspace_disable_expand (sh->heap);
268#endif
Florin Coras4d9b9d82018-01-14 12:25:50 -0800269 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800270 sh->name = format (0, "%s", memfd->name, 0);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800271 ssvm_pop_heap (oldheap);
272
Florin Coras4d9b9d82018-01-14 12:25:50 -0800273 /* The application has to set set sh->ready... */
274 return 0;
275}
276
Florin Corasb384b542018-01-15 01:08:33 -0800277/**
278 * Initialize memfd segment slave
279 *
280 * Subtly different than svm_slave_init. The caller needs to acquire
281 * a usable file descriptor for the memfd segment e.g. via
282 * vppinfra/socket.c:default_socket_recvmsg
Florin Coras4d9b9d82018-01-14 12:25:50 -0800283 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800284int
285ssvm_slave_init_memfd (ssvm_private_t * memfd)
286{
Florin Corasd3e83a92018-01-16 02:40:18 -0800287 clib_mem_vm_map_t mapa = { 0 };
Florin Coras4d9b9d82018-01-14 12:25:50 -0800288 ssvm_shared_header_t *sh;
Florin Corasd3e83a92018-01-16 02:40:18 -0800289 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800290
291 memfd->i_am_master = 0;
292
Damjan Marion567e61d2018-10-24 17:08:26 +0200293 page_size = clib_mem_get_fd_page_size (memfd->fd);
Florin Corasd3e83a92018-01-16 02:40:18 -0800294 if (!page_size)
295 {
296 clib_unix_warning ("page size unknown");
297 return SSVM_API_ERROR_MMAP;
298 }
299
300 /*
301 * Map the segment once, to look at the shared header
302 */
303 mapa.fd = memfd->fd;
304 mapa.size = page_size;
305
306 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800307 {
Florin Corasb384b542018-01-15 01:08:33 -0800308 clib_unix_warning ("slave research mmap (fd %d)", mapa.fd);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800309 close (memfd->fd);
310 return SSVM_API_ERROR_MMAP;
311 }
312
Florin Corasd3e83a92018-01-16 02:40:18 -0800313 sh = mapa.addr;
314 memfd->requested_va = sh->ssvm_va;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800315 memfd->ssvm_size = sh->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800316 clib_mem_vm_free (sh, page_size);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800317
Florin Corasd3e83a92018-01-16 02:40:18 -0800318 /*
319 * Remap the segment at the 'right' address
320 */
321 mapa.requested_va = memfd->requested_va;
322 mapa.size = memfd->ssvm_size;
323 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800324 {
325 clib_unix_warning ("slave final mmap");
326 close (memfd->fd);
327 return SSVM_API_ERROR_MMAP;
328 }
Florin Corasd3e83a92018-01-16 02:40:18 -0800329
330 sh = mapa.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800331 sh->slave_pid = getpid ();
332 memfd->sh = sh;
333 return 0;
334}
Dave Barach68b0fb02017-02-28 15:15:56 -0500335
Florin Corasd3e83a92018-01-16 02:40:18 -0800336void
337ssvm_delete_memfd (ssvm_private_t * memfd)
338{
339 vec_free (memfd->name);
340 clib_mem_vm_free (memfd->sh, memfd->ssvm_size);
341 close (memfd->fd);
342}
343
Florin Corasa332c462018-01-31 06:52:17 -0800344/**
345 * Initialize segment in a private heap
346 */
347int
348ssvm_master_init_private (ssvm_private_t * ssvm)
349{
Florin Corasef4f3e72019-12-11 14:27:53 -0800350 uword pagesize = clib_mem_get_page_size (), rnd_size = 0;
Florin Corasa332c462018-01-31 06:52:17 -0800351 ssvm_shared_header_t *sh;
Florin Corasa332c462018-01-31 06:52:17 -0800352 u8 *heap;
353
Florin Corasf9d4ab42019-05-11 16:55:53 -0700354 rnd_size = clib_max (ssvm->ssvm_size + (pagesize - 1), ssvm->ssvm_size);
355 rnd_size &= ~(pagesize - 1);
Dave Barach6a5adc32018-07-04 10:56:23 -0400356
357#if USE_DLMALLOC == 0
358 {
359 mheap_t *heap_header;
360
361 heap = mheap_alloc (0, rnd_size);
362 if (heap == 0)
363 {
364 clib_unix_warning ("mheap alloc");
365 return -1;
366 }
367 heap_header = mheap_header (heap);
368 heap_header->flags |= MHEAP_FLAG_THREAD_SAFE;
369 }
370#else
371 heap = create_mspace (rnd_size, 1 /* locked */ );
BenoƮt Ganne0af49a82019-07-12 11:34:16 +0200372 if (heap == 0)
373 {
374 clib_unix_warning ("mheap alloc");
375 return -1;
376 }
377
Florin Corasf0b68a52019-06-10 16:22:48 -0700378 mspace_disable_expand (heap);
Florin Corasf8461bf2019-11-07 17:00:15 -0800379
380 /* Find actual size because mspace size is rounded up by dlmalloc */
381 struct dlmallinfo dlminfo;
382 dlminfo = mspace_mallinfo (heap);
383 rnd_size = dlminfo.fordblks;
Dave Barach6a5adc32018-07-04 10:56:23 -0400384#endif
Florin Corasa332c462018-01-31 06:52:17 -0800385
386 ssvm->ssvm_size = rnd_size;
387 ssvm->i_am_master = 1;
388 ssvm->my_pid = getpid ();
389 ssvm->requested_va = ~0;
390
391 /* Allocate a [sic] shared memory header, in process memory... */
392 sh = clib_mem_alloc_aligned (sizeof (*sh), CLIB_CACHE_LINE_BYTES);
393 ssvm->sh = sh;
394
Dave Barachb7b92992018-10-17 10:38:51 -0400395 clib_memset (sh, 0, sizeof (*sh));
Florin Corasa332c462018-01-31 06:52:17 -0800396 sh->heap = heap;
Florin Coras4453c092019-12-19 10:13:15 -0800397 sh->ssvm_size = rnd_size;
Florin Coras404b8a32019-05-09 12:08:06 -0700398 sh->ssvm_va = pointer_to_uword (heap);
Florin Corasa332c462018-01-31 06:52:17 -0800399 sh->type = SSVM_SEGMENT_PRIVATE;
Florin Coras5368bb02019-06-09 09:24:33 -0700400 sh->name = ssvm->name;
Florin Corasa332c462018-01-31 06:52:17 -0800401
402 return 0;
403}
404
405int
406ssvm_slave_init_private (ssvm_private_t * ssvm)
407{
408 clib_warning ("BUG: this should not be called!");
409 return -1;
410}
411
412void
413ssvm_delete_private (ssvm_private_t * ssvm)
414{
415 vec_free (ssvm->name);
Dave Barach6a5adc32018-07-04 10:56:23 -0400416#if USE_DLMALLOC == 0
Florin Corasa332c462018-01-31 06:52:17 -0800417 mheap_free (ssvm->sh->heap);
Dave Barach6a5adc32018-07-04 10:56:23 -0400418#else
419 destroy_mspace (ssvm->sh->heap);
420#endif
Florin Corasa332c462018-01-31 06:52:17 -0800421 clib_mem_free (ssvm->sh);
422}
423
Florin Corasb384b542018-01-15 01:08:33 -0800424int
425ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
426{
427 return (master_init_fns[type]) (ssvm);
428}
429
430int
431ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
432{
433 return (slave_init_fns[type]) (ssvm);
434}
435
436void
437ssvm_delete (ssvm_private_t * ssvm)
438{
439 delete_fns[ssvm->sh->type] (ssvm);
440}
441
442ssvm_segment_type_t
443ssvm_type (const ssvm_private_t * ssvm)
444{
445 return ssvm->sh->type;
446}
447
448u8 *
449ssvm_name (const ssvm_private_t * ssvm)
450{
451 return ssvm->sh->name;
452}
453
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400454/*
455 * fd.io coding-style-patch-verification: ON
456 *
457 * Local Variables:
458 * eval: (c-set-style "gnu")
459 * End:
460 */