blob: 073bc0b5403bf5c303d867347346c3eabe23277a [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;
Benoît Ganne77d42fc2020-04-20 09:52:39 +0200100 CLIB_MEM_UNPOISON (sh, sizeof (*sh));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101 sh->master_pid = ssvm->my_pid;
102 sh->ssvm_size = ssvm->ssvm_size;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400103 sh->ssvm_va = pointer_to_uword (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800104 sh->type = SSVM_SEGMENT_SHM;
Dave Barach6a5adc32018-07-04 10:56:23 -0400105 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
106 ssvm->ssvm_size - page_size,
107 1 /* locked */ );
108 mspace_disable_expand (sh->heap);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109
110 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800111 sh->name = format (0, "%s", ssvm->name, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112 ssvm_pop_heap (oldheap);
113
Florin Corasb384b542018-01-15 01:08:33 -0800114 ssvm->sh = sh;
115 ssvm->my_pid = getpid ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116 ssvm->i_am_master = 1;
117
118 /* The application has to set set sh->ready... */
119 return 0;
120}
121
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400122int
Florin Corasb384b542018-01-15 01:08:33 -0800123ssvm_slave_init_shm (ssvm_private_t * ssvm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124{
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400125 struct stat stat;
126 int ssvm_fd = -1;
127 ssvm_shared_header_t *sh;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Dave Wallaceb8856642017-07-31 13:33:11 -0400129 ASSERT (vec_c_string_is_terminated (ssvm->name));
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400130 ssvm->i_am_master = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Florin Corasb384b542018-01-15 01:08:33 -0800132 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400133 {
134 if (ssvm_fd < 0)
135 ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
136 if (ssvm_fd < 0)
137 {
138 sleep (1);
139 continue;
140 }
141 if (fstat (ssvm_fd, &stat) < 0)
142 {
143 sleep (1);
144 continue;
145 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400147 if (stat.st_size > 0)
148 goto map_it;
149 }
150 clib_warning ("slave timeout");
151 return SSVM_API_ERROR_SLAVE_TIMEOUT;
152
153map_it:
154 sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
155 ssvm_fd, 0);
156 if (sh == MAP_FAILED)
157 {
158 clib_unix_warning ("slave research mmap");
159 close (ssvm_fd);
160 return SSVM_API_ERROR_MMAP;
161 }
162
Florin Corasb384b542018-01-15 01:08:33 -0800163 while (ssvm->attach_timeout-- > 0)
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400164 {
165 if (sh->ready)
166 goto re_map_it;
167 }
168 close (ssvm_fd);
169 munmap (sh, MMAP_PAGESIZE);
170 clib_warning ("slave timeout 2");
171 return SSVM_API_ERROR_SLAVE_TIMEOUT;
172
173re_map_it:
David Johnsond9818dd2018-12-14 14:53:41 -0500174 ssvm->requested_va = sh->ssvm_va;
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400175 ssvm->ssvm_size = sh->ssvm_size;
176 munmap (sh, MMAP_PAGESIZE);
177
178 sh = ssvm->sh = (void *) mmap ((void *) ssvm->requested_va, ssvm->ssvm_size,
179 PROT_READ | PROT_WRITE,
180 MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
181
182 if (sh == MAP_FAILED)
183 {
184 clib_unix_warning ("slave final mmap");
185 close (ssvm_fd);
186 return SSVM_API_ERROR_MMAP;
187 }
188 sh->slave_pid = getpid ();
189 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700190}
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400191
Dave Barach68b0fb02017-02-28 15:15:56 -0500192void
Florin Corasb384b542018-01-15 01:08:33 -0800193ssvm_delete_shm (ssvm_private_t * ssvm)
Dave Barach68b0fb02017-02-28 15:15:56 -0500194{
195 u8 *fn;
196
197 fn = format (0, "/dev/shm/%s%c", ssvm->name, 0);
198
Dave Wallaced756b352017-07-03 13:11:38 -0400199 if (CLIB_DEBUG > 1)
200 clib_warning ("[%d] unlinking ssvm (%s) backing file '%s'", getpid (),
201 ssvm->name, fn);
202
Dave Barach68b0fb02017-02-28 15:15:56 -0500203 /* Throw away the backing file */
204 if (unlink ((char *) fn) < 0)
205 clib_unix_warning ("unlink segment '%s'", ssvm->name);
206
Dave Barach68b0fb02017-02-28 15:15:56 -0500207 vec_free (fn);
Dave Wallaced756b352017-07-03 13:11:38 -0400208 vec_free (ssvm->name);
209
Florin Coras6898e5c2019-07-01 08:57:42 -0700210 munmap ((void *) ssvm->sh, ssvm->ssvm_size);
Dave Barach68b0fb02017-02-28 15:15:56 -0500211}
212
Florin Corasb384b542018-01-15 01:08:33 -0800213/**
214 * Initialize memfd segment master
215 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800216int
Florin Corasb384b542018-01-15 01:08:33 -0800217ssvm_master_init_memfd (ssvm_private_t * memfd)
Florin Coras4d9b9d82018-01-14 12:25:50 -0800218{
Dave Barach6a5adc32018-07-04 10:56:23 -0400219 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800220 ssvm_shared_header_t *sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800221 void *oldheap;
Florin Corasd3e83a92018-01-16 02:40:18 -0800222 clib_mem_vm_alloc_t alloc = { 0 };
223 clib_error_t *err;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800224
225 if (memfd->ssvm_size == 0)
226 return SSVM_API_ERROR_NO_SIZE;
227
228 ASSERT (vec_c_string_is_terminated (memfd->name));
Florin Coras4d9b9d82018-01-14 12:25:50 -0800229
Florin Corasd3e83a92018-01-16 02:40:18 -0800230 alloc.name = (char *) memfd->name;
231 alloc.size = memfd->ssvm_size;
232 alloc.flags = CLIB_MEM_VM_F_SHARED;
Florin Corasb384b542018-01-15 01:08:33 -0800233 alloc.requested_va = memfd->requested_va;
Florin Coras6fe89982020-02-07 23:28:41 +0000234 if (memfd->numa)
235 {
236 alloc.numa_node = memfd->numa;
237 alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
238 }
Florin Corasd3e83a92018-01-16 02:40:18 -0800239 if ((err = clib_mem_vm_ext_alloc (&alloc)))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800240 {
Florin Corasd3e83a92018-01-16 02:40:18 -0800241 clib_error_report (err);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800242 return SSVM_API_ERROR_CREATE_FAILURE;
243 }
244
Florin Corasd3e83a92018-01-16 02:40:18 -0800245 memfd->fd = alloc.fd;
Florin Corasb384b542018-01-15 01:08:33 -0800246 memfd->sh = (ssvm_shared_header_t *) alloc.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800247 memfd->my_pid = getpid ();
Florin Corasd3e83a92018-01-16 02:40:18 -0800248 memfd->i_am_master = 1;
249
Haiyang Tana5ab5032018-10-15 06:17:55 -0700250 page_size = 1ull << alloc.log2_page_size;
Florin Corasb384b542018-01-15 01:08:33 -0800251 sh = memfd->sh;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800252 sh->master_pid = memfd->my_pid;
253 sh->ssvm_size = memfd->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800254 sh->ssvm_va = pointer_to_uword (sh);
255 sh->type = SSVM_SEGMENT_MEMFD;
Dave Barach6a5adc32018-07-04 10:56:23 -0400256
Dave Barach6a5adc32018-07-04 10:56:23 -0400257 sh->heap = create_mspace_with_base (((u8 *) sh) + page_size,
258 memfd->ssvm_size - page_size,
259 1 /* locked */ );
260 mspace_disable_expand (sh->heap);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800261 oldheap = ssvm_push_heap (sh);
Florin Corasb384b542018-01-15 01:08:33 -0800262 sh->name = format (0, "%s", memfd->name, 0);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800263 ssvm_pop_heap (oldheap);
264
Florin Coras4d9b9d82018-01-14 12:25:50 -0800265 /* The application has to set set sh->ready... */
266 return 0;
267}
268
Florin Corasb384b542018-01-15 01:08:33 -0800269/**
270 * Initialize memfd segment slave
271 *
272 * Subtly different than svm_slave_init. The caller needs to acquire
273 * a usable file descriptor for the memfd segment e.g. via
274 * vppinfra/socket.c:default_socket_recvmsg
Florin Coras4d9b9d82018-01-14 12:25:50 -0800275 */
Florin Coras4d9b9d82018-01-14 12:25:50 -0800276int
277ssvm_slave_init_memfd (ssvm_private_t * memfd)
278{
Florin Corasd3e83a92018-01-16 02:40:18 -0800279 clib_mem_vm_map_t mapa = { 0 };
Florin Coras4d9b9d82018-01-14 12:25:50 -0800280 ssvm_shared_header_t *sh;
Florin Corasd3e83a92018-01-16 02:40:18 -0800281 uword page_size;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800282
283 memfd->i_am_master = 0;
284
Damjan Marion567e61d2018-10-24 17:08:26 +0200285 page_size = clib_mem_get_fd_page_size (memfd->fd);
Florin Corasd3e83a92018-01-16 02:40:18 -0800286 if (!page_size)
287 {
288 clib_unix_warning ("page size unknown");
289 return SSVM_API_ERROR_MMAP;
290 }
291
292 /*
293 * Map the segment once, to look at the shared header
294 */
295 mapa.fd = memfd->fd;
296 mapa.size = page_size;
297
298 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800299 {
Florin Corasb384b542018-01-15 01:08:33 -0800300 clib_unix_warning ("slave research mmap (fd %d)", mapa.fd);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800301 close (memfd->fd);
302 return SSVM_API_ERROR_MMAP;
303 }
304
Florin Corasd3e83a92018-01-16 02:40:18 -0800305 sh = mapa.addr;
306 memfd->requested_va = sh->ssvm_va;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800307 memfd->ssvm_size = sh->ssvm_size;
Florin Corasb384b542018-01-15 01:08:33 -0800308 clib_mem_vm_free (sh, page_size);
Florin Coras4d9b9d82018-01-14 12:25:50 -0800309
Florin Corasd3e83a92018-01-16 02:40:18 -0800310 /*
311 * Remap the segment at the 'right' address
312 */
313 mapa.requested_va = memfd->requested_va;
314 mapa.size = memfd->ssvm_size;
315 if (clib_mem_vm_ext_map (&mapa))
Florin Coras4d9b9d82018-01-14 12:25:50 -0800316 {
317 clib_unix_warning ("slave final mmap");
318 close (memfd->fd);
319 return SSVM_API_ERROR_MMAP;
320 }
Florin Corasd3e83a92018-01-16 02:40:18 -0800321
322 sh = mapa.addr;
Florin Coras4d9b9d82018-01-14 12:25:50 -0800323 sh->slave_pid = getpid ();
324 memfd->sh = sh;
325 return 0;
326}
Dave Barach68b0fb02017-02-28 15:15:56 -0500327
Florin Corasd3e83a92018-01-16 02:40:18 -0800328void
329ssvm_delete_memfd (ssvm_private_t * memfd)
330{
331 vec_free (memfd->name);
332 clib_mem_vm_free (memfd->sh, memfd->ssvm_size);
333 close (memfd->fd);
334}
335
Florin Corasa332c462018-01-31 06:52:17 -0800336/**
337 * Initialize segment in a private heap
338 */
339int
340ssvm_master_init_private (ssvm_private_t * ssvm)
341{
Florin Corasef4f3e72019-12-11 14:27:53 -0800342 uword pagesize = clib_mem_get_page_size (), rnd_size = 0;
Florin Coras6fe89982020-02-07 23:28:41 +0000343 clib_mem_vm_alloc_t alloc = { 0 };
344 struct dlmallinfo dlminfo;
Florin Corasa332c462018-01-31 06:52:17 -0800345 ssvm_shared_header_t *sh;
Florin Coras6fe89982020-02-07 23:28:41 +0000346 clib_error_t *err;
Florin Corasa332c462018-01-31 06:52:17 -0800347 u8 *heap;
348
Florin Corasf9d4ab42019-05-11 16:55:53 -0700349 rnd_size = clib_max (ssvm->ssvm_size + (pagesize - 1), ssvm->ssvm_size);
350 rnd_size &= ~(pagesize - 1);
Dave Barach6a5adc32018-07-04 10:56:23 -0400351
Florin Coras6fe89982020-02-07 23:28:41 +0000352 alloc.name = (char *) ssvm->name;
353 alloc.size = rnd_size + pagesize;
354 if (ssvm->numa)
355 {
356 alloc.numa_node = ssvm->numa;
357 alloc.flags |= CLIB_MEM_VM_F_NUMA_PREFER;
358 }
Dave Barach6a5adc32018-07-04 10:56:23 -0400359
Florin Coras6fe89982020-02-07 23:28:41 +0000360 if ((err = clib_mem_vm_ext_alloc (&alloc)))
361 {
362 clib_error_report (err);
363 return SSVM_API_ERROR_CREATE_FAILURE;
364 }
365
366 heap = create_mspace_with_base ((u8 *) alloc.addr + pagesize, rnd_size,
367 1 /* locked */ );
Benoît Ganne0af49a82019-07-12 11:34:16 +0200368 if (heap == 0)
369 {
370 clib_unix_warning ("mheap alloc");
371 return -1;
372 }
373
Florin Corasf0b68a52019-06-10 16:22:48 -0700374 mspace_disable_expand (heap);
Florin Corasf8461bf2019-11-07 17:00:15 -0800375
376 /* Find actual size because mspace size is rounded up by dlmalloc */
Florin Corasf8461bf2019-11-07 17:00:15 -0800377 dlminfo = mspace_mallinfo (heap);
378 rnd_size = dlminfo.fordblks;
Florin Corasa332c462018-01-31 06:52:17 -0800379
380 ssvm->ssvm_size = rnd_size;
381 ssvm->i_am_master = 1;
382 ssvm->my_pid = getpid ();
383 ssvm->requested_va = ~0;
384
Florin Coras6fe89982020-02-07 23:28:41 +0000385 /* First page in allocated memory is set aside for the shared header */
386 sh = alloc.addr;
Florin Corasa332c462018-01-31 06:52:17 -0800387 ssvm->sh = sh;
388
Dave Barachb7b92992018-10-17 10:38:51 -0400389 clib_memset (sh, 0, sizeof (*sh));
Florin Corasa332c462018-01-31 06:52:17 -0800390 sh->heap = heap;
Florin Coras4453c092019-12-19 10:13:15 -0800391 sh->ssvm_size = rnd_size;
Florin Coras404b8a32019-05-09 12:08:06 -0700392 sh->ssvm_va = pointer_to_uword (heap);
Florin Corasa332c462018-01-31 06:52:17 -0800393 sh->type = SSVM_SEGMENT_PRIVATE;
Florin Coras5368bb02019-06-09 09:24:33 -0700394 sh->name = ssvm->name;
Florin Corasa332c462018-01-31 06:52:17 -0800395
396 return 0;
397}
398
399int
400ssvm_slave_init_private (ssvm_private_t * ssvm)
401{
402 clib_warning ("BUG: this should not be called!");
403 return -1;
404}
405
406void
407ssvm_delete_private (ssvm_private_t * ssvm)
408{
409 vec_free (ssvm->name);
Dave Barach6a5adc32018-07-04 10:56:23 -0400410 destroy_mspace (ssvm->sh->heap);
Florin Coras6fe89982020-02-07 23:28:41 +0000411 clib_mem_vm_free (ssvm->sh, ssvm->ssvm_size + clib_mem_get_page_size ());
Florin Corasa332c462018-01-31 06:52:17 -0800412}
413
Florin Corasb384b542018-01-15 01:08:33 -0800414int
415ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
416{
417 return (master_init_fns[type]) (ssvm);
418}
419
420int
421ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type)
422{
423 return (slave_init_fns[type]) (ssvm);
424}
425
426void
427ssvm_delete (ssvm_private_t * ssvm)
428{
429 delete_fns[ssvm->sh->type] (ssvm);
430}
431
432ssvm_segment_type_t
433ssvm_type (const ssvm_private_t * ssvm)
434{
435 return ssvm->sh->type;
436}
437
438u8 *
439ssvm_name (const ssvm_private_t * ssvm)
440{
441 return ssvm->sh->name;
442}
443
Dave Barach8a7fb0c2016-07-08 14:44:23 -0400444/*
445 * fd.io coding-style-patch-verification: ON
446 *
447 * Local Variables:
448 * eval: (c-set-style "gnu")
449 * End:
450 */