summaryrefslogtreecommitdiffstats
path: root/svm/ssvm.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2016-07-08 14:44:23 -0400
committerDave Barach <dave@barachs.net>2016-07-08 14:44:38 -0400
commit8a7fb0cf6844ed09173fd58224f7753a1b504cf4 (patch)
tree45e21bd6bac95034fd589daf0ea898c6ede80afa /svm/ssvm.c
parent49a6963b1387bf7535f589f02ffc99de5b59192f (diff)
fd-io-styleify for svm
Change-Id: I816de8b1f255dc3bc6d2904566ea0b0f68fac5d8 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'svm/ssvm.c')
-rw-r--r--svm/ssvm.c183
1 files changed, 97 insertions, 86 deletions
diff --git a/svm/ssvm.c b/svm/ssvm.c
index 92d86e6d1e4..5db14231368 100644
--- a/svm/ssvm.c
+++ b/svm/ssvm.c
@@ -14,16 +14,17 @@
*/
#include "ssvm.h"
-int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
+int
+ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
{
int ssvm_fd;
- u8 * ssvm_filename;
+ u8 *ssvm_filename;
u8 junk = 0;
int flags;
- ssvm_shared_header_t * sh;
- u64 ticks = clib_cpu_time_now();
+ ssvm_shared_header_t *sh;
+ u64 ticks = clib_cpu_time_now ();
u64 randomize_baseva;
- void * oldheap;
+ void *oldheap;
if (ssvm->ssvm_size == 0)
return SSVM_API_ERROR_NO_SIZE;
@@ -32,9 +33,9 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
unlink ((char *) ssvm_filename);
- vec_free(ssvm_filename);
+ vec_free (ssvm_filename);
- ssvm_fd = shm_open((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
+ ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
if (ssvm_fd < 0)
{
@@ -42,14 +43,14 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
return SSVM_API_ERROR_CREATE_FAILURE;
}
- lseek(ssvm_fd, ssvm->ssvm_size, SEEK_SET);
- if (write(ssvm_fd, &junk, 1) != 1)
+ lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET);
+ if (write (ssvm_fd, &junk, 1) != 1)
{
clib_unix_warning ("set ssvm size");
- close(ssvm_fd);
+ close (ssvm_fd);
return SSVM_API_ERROR_SET_SIZE;
}
-
+
flags = MAP_SHARED;
if (ssvm->requested_va)
flags |= MAP_FIXED;
@@ -58,27 +59,29 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
if (ssvm->requested_va)
ssvm->requested_va += randomize_baseva;
-
- sh = ssvm->sh = (ssvm_shared_header_t *) mmap((void *)ssvm->requested_va, ssvm->ssvm_size,
- PROT_READ | PROT_WRITE, flags, ssvm_fd, 0);
+
+ sh = ssvm->sh =
+ (ssvm_shared_header_t *) mmap ((void *) ssvm->requested_va,
+ ssvm->ssvm_size, PROT_READ | PROT_WRITE,
+ flags, ssvm_fd, 0);
if (ssvm->sh == MAP_FAILED)
{
clib_unix_warning ("mmap");
- close(ssvm_fd);
+ close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
- close(ssvm_fd);
+ close (ssvm_fd);
- ssvm->my_pid = getpid();
+ ssvm->my_pid = getpid ();
sh->master_pid = ssvm->my_pid;
sh->ssvm_size = ssvm->ssvm_size;
- sh->heap = mheap_alloc_with_flags
- (((u8 *)sh) + MMAP_PAGESIZE, ssvm->ssvm_size - MMAP_PAGESIZE,
+ sh->heap = mheap_alloc_with_flags
+ (((u8 *) sh) + MMAP_PAGESIZE, ssvm->ssvm_size - MMAP_PAGESIZE,
MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE);
- sh->ssvm_va = pointer_to_uword(sh);
+ sh->ssvm_va = pointer_to_uword (sh);
sh->master_index = master_index;
oldheap = ssvm_push_heap (sh);
@@ -91,71 +94,79 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
return 0;
}
-int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
+int
+ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
{
- struct stat stat;
- int ssvm_fd = -1;
- ssvm_shared_header_t * sh;
-
- ssvm->i_am_master = 0;
-
- while (timeout_in_seconds-- > 0)
- {
- if (ssvm_fd < 0)
- ssvm_fd = shm_open((char *)ssvm->name, O_RDWR, 0777);
- if (ssvm_fd < 0)
- {
- sleep (1);
- continue;
- }
- if (fstat(ssvm_fd, &stat) < 0)
- {
- sleep (1);
- continue;
- }
-
- if (stat.st_size > 0)
- goto map_it;
- }
- clib_warning ("slave timeout");
- return SSVM_API_ERROR_SLAVE_TIMEOUT;
-
- map_it:
- sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
- ssvm_fd, 0);
- if (sh == MAP_FAILED)
- {
- clib_unix_warning ("slave research mmap");
- close (ssvm_fd);
- return SSVM_API_ERROR_MMAP;
- }
-
- while (timeout_in_seconds-- > 0)
- {
- if (sh->ready)
- goto re_map_it;
- }
- close (ssvm_fd);
- munmap (sh, MMAP_PAGESIZE);
- clib_warning ("slave timeout 2");
- return SSVM_API_ERROR_SLAVE_TIMEOUT;
-
- re_map_it:
- ssvm->requested_va = (u64) sh->ssvm_va;
- ssvm->ssvm_size = sh->ssvm_size;
- munmap (sh, MMAP_PAGESIZE);
-
- sh = ssvm->sh = (void *) mmap((void *)ssvm->requested_va, ssvm->ssvm_size,
- PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_FIXED,
- ssvm_fd, 0);
-
- if (sh == MAP_FAILED)
- {
- clib_unix_warning ("slave final mmap");
- close (ssvm_fd);
- return SSVM_API_ERROR_MMAP;
- }
- sh->slave_pid = getpid();
- return 0;
+ struct stat stat;
+ int ssvm_fd = -1;
+ ssvm_shared_header_t *sh;
+
+ ssvm->i_am_master = 0;
+
+ while (timeout_in_seconds-- > 0)
+ {
+ if (ssvm_fd < 0)
+ ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
+ if (ssvm_fd < 0)
+ {
+ sleep (1);
+ continue;
+ }
+ if (fstat (ssvm_fd, &stat) < 0)
+ {
+ sleep (1);
+ continue;
+ }
+
+ if (stat.st_size > 0)
+ goto map_it;
+ }
+ clib_warning ("slave timeout");
+ return SSVM_API_ERROR_SLAVE_TIMEOUT;
+
+map_it:
+ sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
+ ssvm_fd, 0);
+ if (sh == MAP_FAILED)
+ {
+ clib_unix_warning ("slave research mmap");
+ close (ssvm_fd);
+ return SSVM_API_ERROR_MMAP;
+ }
+
+ while (timeout_in_seconds-- > 0)
+ {
+ if (sh->ready)
+ goto re_map_it;
+ }
+ close (ssvm_fd);
+ munmap (sh, MMAP_PAGESIZE);
+ clib_warning ("slave timeout 2");
+ return SSVM_API_ERROR_SLAVE_TIMEOUT;
+
+re_map_it:
+ ssvm->requested_va = (u64) sh->ssvm_va;
+ ssvm->ssvm_size = sh->ssvm_size;
+ munmap (sh, MMAP_PAGESIZE);
+
+ sh = ssvm->sh = (void *) mmap ((void *) ssvm->requested_va, ssvm->ssvm_size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
+
+ if (sh == MAP_FAILED)
+ {
+ clib_unix_warning ("slave final mmap");
+ close (ssvm_fd);
+ return SSVM_API_ERROR_MMAP;
+ }
+ sh->slave_pid = getpid ();
+ return 0;
}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */