blob: 0305278a6b6e439a65142e779601ee1a1b6687d8 [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;
Florin Corasb384b542018-01-15 01:08:33 -080032 clib_mem_vm_map_t mapa = { 0 };
33 u8 junk = 0, *ssvm_filename;
Dave Barach8a7fb0c2016-07-08 14:44:23 -040034 ssvm_shared_header_t *sh;
Florin Corasf8f516a2018-02-08 15:10:09 -080035 uword page_size, requested_va = 0;
Dave Barach8a7fb0c2016-07-08 14:44:23 -040036 void *oldheap;
Ed Warnickecb9cada2015-12-08 15:45:58 -070037
38 if (ssvm->ssvm_size == 0)
39 return SSVM_API_ERROR_NO_SIZE;
40
Dave Wallaced756b352017-07-03 13:11:38 -040041 if (CLIB_DEBUG > 1)
42 clib_warning ("[%d] creating segment '%s'", getpid (), ssvm->name);
43
Dave Wallaceb8856642017-07-31 13:33:11 -040044 ASSERT (vec_c_string_is_terminated (ssvm->name));
Ed Warnickecb9cada2015-12-08 15:45:58 -070045 ssvm_filename = format (0, "/dev/shm/%s%c", ssvm->name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -070046 unlink ((char *) ssvm_filename);
Dave Barach8a7fb0c2016-07-08 14:44:23 -040047 vec_free (ssvm_filename);
Ed Warnickecb9cada2015-12-08 15:45:58 -070048
Dave Barach8a7fb0c2016-07-08 14:44:23 -040049 ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
Ed Warnickecb9cada2015-12-08 15:45:58 -070050 if (ssvm_fd < 0)
51 {
52 clib_unix_warning ("create segment '%s'", ssvm->name);
53 return SSVM_API_ERROR_CREATE_FAILURE;
54 }
55
Dave Wallace19296112017-08-31 15:54:11 -040056 if (fchmod (ssvm_fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
57 clib_unix_warning ("ssvm segment chmod");
Florin Coras65784c12018-07-04 04:17:41 -070058 if (svm_get_root_rp ())
59 {
60 /* TODO: is this really needed? */
61 svm_main_region_t *smr = svm_get_root_rp ()->data_base;
62 if (fchown (ssvm_fd, smr->uid, smr->gid) < 0)
63 clib_unix_warning ("ssvm segment chown");
64 }
Dave Wallace19296112017-08-31 15:54:11 -040065
Dave Barach56faee82016-08-04 18:58:05 -040066 if (lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET) < 0)
67 {
68 clib_unix_warning ("lseek");
69 close (ssvm_fd);
70 return SSVM_API_ERROR_SET_SIZE;
71 }
Ed Warnicke853e7202016-08-12 11:42:26 -070072
Dave Barach8a7fb0c2016-07-08 14:44:23 -040073 if (write (ssvm_fd, &junk, 1) != 1)
Ed Warnickecb9cada2015-12-08 15:45:58 -070074 {
75 clib_unix_warning ("set ssvm size");
Dave Barach8a7fb0c2016-07-08 14:44:23 -040076 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 return SSVM_API_ERROR_SET_SIZE;
78 }
Dave Barach8a7fb0c2016-07-08 14:44:23 -040079
Damjan Marion567e61d2018-10-24 17:08:26 +020080 page_size = clib_mem_get_fd_page_size (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070081 if (ssvm->requested_va)
Florin Corasf8f516a2018-02-08 15:10:09 -080082 {
83 requested_va = ssvm->requested_va;
84 clib_mem_vm_randomize_va (&requested_va, min_log2 (page_size));
85 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070086
Florin Corasf8f516a2018-02-08 15:10:09 -080087 mapa.requested_va = requested_va;
Florin Corasb384b542018-01-15 01:08:33 -080088 mapa.size = ssvm->ssvm_size;
89 mapa.fd = ssvm_fd;
Florin Coras6fe89982020-02-07 23:28:41 +000090 mapa.numa_node = ssvm->numa;
Florin Corasb384b542018-01-15 01:08:33 -080091 if (clib_mem_vm_ext_map (&mapa))
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 {
93 clib_unix_warning ("mmap");
Dave Barach8a7fb0c2016-07-08 14:44:23 -040094 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070095 return SSVM_API_ERROR_MMAP;
96 }
Dave Barach8a7fb0c2016-07-08 14:44:23 -040097 close (ssvm_fd);
Ed Warnickecb9cada2015-12-08 15:45:58 -070098
Florin Corasb384b542018-01-15 01:08:33 -080099 sh = mapa.addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 sh->master_pid = ssvm->my_pid;
101 sh->ssvm_size = ssvm->ssvm_size;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400102 sh->ssvm_va = pointer_to_uword (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800103 sh->type = SSVM_SEGMENT_SHM;
Dave Barach6a5adc32018-07-04 10:56:23 -0400104 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
105 ssvm->ssvm_size - page_size,
106 1 /* locked */ );
107 mspace_disable_expand (sh->heap);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108
109 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800110 sh->name = format (0, "%s", ssvm->name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111 ssvm_pop_heap (oldheap);
112
Florin Corasb384b542018-01-15 01:08:33 -0800113 ssvm->sh = sh;
114 ssvm->my_pid = getpid ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115 ssvm->i_am_master = 1;
116
117 /* The application has to set set sh->ready... */
118 return 0;
119}
120
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400121int
Florin Corasb384b542018-01-15 01:08:33 -0800122ssvm_slave_init_shm (ssvm_private_t * ssvm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123{
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400124 struct stat stat;
125 int ssvm_fd = -1;
126 ssvm_shared_header_t *sh;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127
Dave Wallaceb8856642017-07-31 13:33:11 -0400128 ASSERT (vec_c_string_is_terminated (ssvm->name));
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400129 ssvm->i_am_master = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
Florin Corasb384b542018-01-15 01:08:33 -0800131 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400132 {
133 if (ssvm_fd < 0)
134 ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
135 if (ssvm_fd < 0)
136 {
137 sleep (1);
138 continue;
139 }
140 if (fstat (ssvm_fd, &stat) < 0)
141 {
142 sleep (1);
143 continue;
144 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400146 if (stat.st_size > 0)
147 goto map_it;
148 }
149 clib_warning ("slave timeout");
150 return SSVM_API_ERROR_SLAVE_TIMEOUT;
151
152map_it:
153 sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
154 ssvm_fd, 0);
155 if (sh == MAP_FAILED)
156 {
157 clib_unix_warning ("slave research mmap");
158 close (ssvm_fd);
159 return SSVM_API_ERROR_MMAP;
160 }
161
Florin Corasb384b542018-01-15 01:08:33 -0800162 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400163 {
164 if (sh->ready)
165 goto re_map_it;
166 }
167 close (ssvm_fd);
168 munmap (sh, MMAP_PAGESIZE);
169 clib_warning ("slave timeout 2");
170 return SSVM_API_ERROR_SLAVE_TIMEOUT;
171
172re_map_it:
David Johnsond9818dd2018-12-14 14:53:41 -0500173 ssvm->requested_va = sh->ssvm_va;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400174 ssvm->ssvm_size = sh->ssvm_size;
175 munmap (sh, MMAP_PAGESIZE);
176
177 sh = ssvm->sh = (void *) mmap ((void *) ssvm->requested_va, ssvm->ssvm_size,
178 PROT_READ | PROT_WRITE,
179 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
180
181 if (sh == MAP_FAILED)
182 {
183 clib_unix_warning ("slave final mmap");
184 close (ssvm_fd);
185 return SSVM_API_ERROR_MMAP;
186 }
187 sh->slave_pid = getpid ();
188 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189}
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400190
Dave Barach68b0fb02017-02-28 15:15:56 -0500191void
Florin Corasb384b542018-01-15 01:08:33 -0800192ssvm_delete_shm (ssvm_private_t * ssvm)
Dave Barach68b0fb02017-02-28 15:15:56 -0500193{
194 u8 *fn;
195
196 fn = format (0, "/dev/shm/%s%c", ssvm->name, 0);
197
Dave Wallaced756b352017-07-03 13:11:38 -0400198 if (CLIB_DEBUG > 1)
199 clib_warning ("[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
200 ssvm->name, fn);
201
Dave Barach68b0fb02017-02-28 15:15:56 -0500202 /* Throw away the backing file */
203 if (unlink ((char *) fn) < 0)
204 clib_unix_warning ("unlink segment '%s'", ssvm->name);
205
Dave Barach68b0fb02017-02-28 15:15:56 -0500206 vec_free (fn);
Dave Wallaced756b352017-07-03 13:11:38 -0400207 vec_free (ssvm->name);
208
Florin Coras6898e5c2019-07-01 08:57:42 -0700209 munmap ((void *) ssvm->sh, ssvm->ssvm_size);
Dave Barach68b0fb02017-02-28 15:15:56 -0500210}
211
Florin Corasb384b542018-01-15 01:08:33 -0800212/**
213 * Initialize memfd segment master
214 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800215int
Florin Corasb384b542018-01-15 01:08:33 -0800216ssvm_master_init_memfd (ssvm_private_t * memfd)
Florin Coras4d9b9d82018-01-14 12:25:50 -0800217{
Dave Barach6a5adc32018-07-04 10:56:23 -0400218 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800219 ssvm_shared_header_t *sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800220 void *oldheap;
Florin Corasd3e83a92018-01-16 02:40:18 -0800221 clib_mem_vm_alloc_t alloc = { 0 };
222 clib_error_t *err;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800223
224 if (memfd->ssvm_size == 0)
225 return SSVM_API_ERROR_NO_SIZE;
226
227 ASSERT (vec_c_string_is_terminated (memfd->name));
Florin Coras4d9b9d82018-01-14 12:25:50 -0800228
Florin Corasd3e83a92018-01-16 02:40:18 -0800229 alloc.name = (char *) memfd->name;
230 alloc.size = memfd->ssvm_size;
231 alloc.flags = CLIB_MEM_VM_F_SHARED;
Florin Corasb384b542018-01-15 01:08:33 -0800232 alloc.requested_va = memfd->requested_va;
Florin Coras6fe89982020-02-07 23:28:41 +0000233 if (memfd->numa)
234 {
235 alloc.numa_node = memfd->numa;
236 alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
237 }
Florin Corasd3e83a92018-01-16 02:40:18 -0800238 if ((err = clib_mem_vm_ext_alloc (&alloc)))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800239 {
Florin Corasd3e83a92018-01-16 02:40:18 -0800240 clib_error_report (err);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800241 return SSVM_API_ERROR_CREATE_FAILURE;
242 }
243
Florin Corasd3e83a92018-01-16 02:40:18 -0800244 memfd->fd = alloc.fd;
Florin Corasb384b542018-01-15 01:08:33 -0800245 memfd->sh = (ssvm_shared_header_t *) alloc.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800246 memfd->my_pid = getpid ();
Florin Corasd3e83a92018-01-16 02:40:18 -0800247 memfd->i_am_master = 1;
248
Haiyang Tana5ab5032018-10-15 06:17:55 -0700249 page_size = 1ull << alloc.log2_page_size;
Florin Corasb384b542018-01-15 01:08:33 -0800250 sh = memfd->sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800251 sh->master_pid = memfd->my_pid;
252 sh->ssvm_size = memfd->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800253 sh->ssvm_va = pointer_to_uword (sh);
254 sh->type = SSVM_SEGMENT_MEMFD;
Dave Barach6a5adc32018-07-04 10:56:23 -0400255
Dave Barach6a5adc32018-07-04 10:56:23 -0400256 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
257 memfd->ssvm_size - page_size,
258 1 /* locked */ );
259 mspace_disable_expand (sh->heap);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800260 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800261 sh->name = format (0, "%s", memfd->name, 0);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800262 ssvm_pop_heap (oldheap);
263
Florin Coras4d9b9d82018-01-14 12:25:50 -0800264 /* The application has to set set sh->ready... */
265 return 0;
266}
267
Florin Corasb384b542018-01-15 01:08:33 -0800268/**
269 * Initialize memfd segment slave
270 *
271 * Subtly different than svm_slave_init. The caller needs to acquire
272 * a usable file descriptor for the memfd segment e.g. via
273 * vppinfra/socket.c:default_socket_recvmsg
Florin Coras4d9b9d82018-01-14 12:25:50 -0800274 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800275int
276ssvm_slave_init_memfd (ssvm_private_t * memfd)
277{
Florin Corasd3e83a92018-01-16 02:40:18 -0800278 clib_mem_vm_map_t mapa = { 0 };
Florin Coras4d9b9d82018-01-14 12:25:50 -0800279 ssvm_shared_header_t *sh;
Florin Corasd3e83a92018-01-16 02:40:18 -0800280 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800281
282 memfd->i_am_master = 0;
283
Damjan Marion567e61d2018-10-24 17:08:26 +0200284 page_size = clib_mem_get_fd_page_size (memfd->fd);
Florin Corasd3e83a92018-01-16 02:40:18 -0800285 if (!page_size)
286 {
287 clib_unix_warning ("page size unknown");
288 return SSVM_API_ERROR_MMAP;
289 }
290
291 /*
292 * Map the segment once, to look at the shared header
293 */
294 mapa.fd = memfd->fd;
295 mapa.size = page_size;
296
297 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800298 {
Florin Corasb384b542018-01-15 01:08:33 -0800299 clib_unix_warning ("slave research mmap (fd %d)", mapa.fd);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800300 close (memfd->fd);
301 return SSVM_API_ERROR_MMAP;
302 }
303
Florin Corasd3e83a92018-01-16 02:40:18 -0800304 sh = mapa.addr;
305 memfd->requested_va = sh->ssvm_va;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800306 memfd->ssvm_size = sh->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800307 clib_mem_vm_free (sh, page_size);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800308
Florin Corasd3e83a92018-01-16 02:40:18 -0800309 /*
310 * Remap the segment at the 'right' address
311 */
312 mapa.requested_va = memfd->requested_va;
313 mapa.size = memfd->ssvm_size;
314 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800315 {
316 clib_unix_warning ("slave final mmap");
317 close (memfd->fd);
318 return SSVM_API_ERROR_MMAP;
319 }
Florin Corasd3e83a92018-01-16 02:40:18 -0800320
321 sh = mapa.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800322 sh->slave_pid = getpid ();
323 memfd->sh = sh;
324 return 0;
325}
Dave Barach68b0fb02017-02-28 15:15:56 -0500326
Florin Corasd3e83a92018-01-16 02:40:18 -0800327void
328ssvm_delete_memfd (ssvm_private_t * memfd)
329{
330 vec_free (memfd->name);
331 clib_mem_vm_free (memfd->sh, memfd->ssvm_size);
332 close (memfd->fd);
333}
334
Florin Corasa332c462018-01-31 06:52:17 -0800335/**
336 * Initialize segment in a private heap
337 */
338int
339ssvm_master_init_private (ssvm_private_t * ssvm)
340{
Florin Corasef4f3e72019-12-11 14:27:53 -0800341 uword pagesize = clib_mem_get_page_size (), rnd_size = 0;
Florin Coras6fe89982020-02-07 23:28:41 +0000342 clib_mem_vm_alloc_t alloc = { 0 };
343 struct dlmallinfo dlminfo;
Florin Corasa332c462018-01-31 06:52:17 -0800344 ssvm_shared_header_t *sh;
Florin Coras6fe89982020-02-07 23:28:41 +0000345 clib_error_t *err;
Florin Corasa332c462018-01-31 06:52:17 -0800346 u8 *heap;
347
Florin Corasf9d4ab42019-05-11 16:55:53 -0700348 rnd_size = clib_max (ssvm->ssvm_size + (pagesize - 1), ssvm->ssvm_size);
349 rnd_size &= ~(pagesize - 1);
Dave Barach6a5adc32018-07-04 10:56:23 -0400350
Florin Coras6fe89982020-02-07 23:28:41 +0000351 alloc.name = (char *) ssvm->name;
352 alloc.size = rnd_size + pagesize;
353 if (ssvm->numa)
354 {
355 alloc.numa_node = ssvm->numa;
356 alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
357 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400358
Florin Coras6fe89982020-02-07 23:28:41 +0000359 if ((err = clib_mem_vm_ext_alloc (&alloc)))
360 {
361 clib_error_report (err);
362 return SSVM_API_ERROR_CREATE_FAILURE;
363 }
364
365 heap = create_mspace_with_base ((u8 *) alloc.addr + pagesize, rnd_size,
366 1 /* locked */ );
BenoƮt Ganne0af49a82019-07-12 11:34:16 +0200367 if (heap == 0)
368 {
369 clib_unix_warning ("mheap alloc");
370 return -1;
371 }
372
Florin Corasf0b68a52019-06-10 16:22:48 -0700373 mspace_disable_expand (heap);
Florin Corasf8461bf2019-11-07 17:00:15 -0800374
375 /* Find actual size because mspace size is rounded up by dlmalloc */
Florin Corasf8461bf2019-11-07 17:00:15 -0800376 dlminfo = mspace_mallinfo (heap);
377 rnd_size = dlminfo.fordblks;
Florin Corasa332c462018-01-31 06:52:17 -0800378
379 ssvm->ssvm_size = rnd_size;
380 ssvm->i_am_master = 1;
381 ssvm->my_pid = getpid ();
382 ssvm->requested_va = ~0;
383
Florin Coras6fe89982020-02-07 23:28:41 +0000384 /* First page in allocated memory is set aside for the shared header */
385 sh = alloc.addr;
Florin Corasa332c462018-01-31 06:52:17 -0800386 ssvm->sh = sh;
387
Dave Barachb7b92992018-10-17 10:38:51 -0400388 clib_memset (sh, 0, sizeof (*sh));
Florin Corasa332c462018-01-31 06:52:17 -0800389 sh->heap = heap;
Florin Coras4453c092019-12-19 10:13:15 -0800390 sh->ssvm_size = rnd_size;
Florin Coras404b8a32019-05-09 12:08:06 -0700391 sh->ssvm_va = pointer_to_uword (heap);
Florin Corasa332c462018-01-31 06:52:17 -0800392 sh->type = SSVM_SEGMENT_PRIVATE;
Florin Coras5368bb02019-06-09 09:24:33 -0700393 sh->name = ssvm->name;
Florin Corasa332c462018-01-31 06:52:17 -0800394
395 return 0;
396}
397
398int
399ssvm_slave_init_private (ssvm_private_t * ssvm)
400{
401 clib_warning ("BUG: this should not be called!");
402 return -1;
403}
404
405void
406ssvm_delete_private (ssvm_private_t * ssvm)
407{
408 vec_free (ssvm->name);
Dave Barach6a5adc32018-07-04 10:56:23 -0400409 destroy_mspace (ssvm->sh->heap);
Florin Coras6fe89982020-02-07 23:28:41 +0000410 clib_mem_vm_free (ssvm->sh, ssvm->ssvm_size + clib_mem_get_page_size ());
Florin Corasa332c462018-01-31 06:52:17 -0800411}
412
Florin Corasb384b542018-01-15 01:08:33 -0800413int
414ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
415{
416 return (master_init_fns[type]) (ssvm);
417}
418
419int
420ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
421{
422 return (slave_init_fns[type]) (ssvm);
423}
424
425void
426ssvm_delete (ssvm_private_t * ssvm)
427{
428 delete_fns[ssvm->sh->type] (ssvm);
429}
430
431ssvm_segment_type_t
432ssvm_type (const ssvm_private_t * ssvm)
433{
434 return ssvm->sh->type;
435}
436
437u8 *
438ssvm_name (const ssvm_private_t * ssvm)
439{
440 return ssvm->sh->name;
441}
442
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400443/*
444 * fd.io coding-style-patch-verification: ON
445 *
446 * Local Variables:
447 * eval: (c-set-style "gnu")
448 * End:
449 */