22 #include <sys/types.h> 25 #include <netinet/in.h> 54 int verbose = va_arg (*args,
int);
66 pthread_mutex_lock (&root_rp->
mutex);
78 name = vec_dup (subp->subregion_name);
79 vec_add1(svm_names, name);
83 pthread_mutex_unlock (&root_rp->
mutex);
85 for (i = 0; i <
vec_len (svm_names); i++)
88 a->
name = (
char *) svm_names[i];
92 pthread_mutex_lock (&rp->
mutex);
94 pthread_mutex_unlock (&rp->
mutex);
105 show (
char *chroot_path,
int verbose)
113 fformat (stdout,
"My pid is %d\n", getpid ());
135 svm_fd = shm_open ((
char *) shm_name, O_RDWR, 0777);
139 perror (
"svm_region_map(mmap open)");
144 rp = mmap (0,
MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0);
156 while (rp->
version == 0 && deadman++ < 5)
176 PROT_READ | PROT_WRITE,
177 MAP_SHARED | MAP_FIXED, svm_fd, 0);
189 if (pthread_mutex_trylock (&rp->
mutex))
191 clib_warning (
"rp->mutex LOCKED by pid %d, tag %d, cleared...",
199 pthread_mutex_unlock (&rp->
mutex);
202 return ((
void *) rp);
223 pthread_mutex_lock (&rp->
mutex);
237 pthread_mutex_unlock (&rp->
mutex);
274 trace (
char *chroot_path,
char *name,
int enable_disable)
323 pthread_mutex_lock (&root_rp->
mutex);
333 name = vec_dup (subp->subregion_name);
334 vec_add1(svm_names, name);
338 pthread_mutex_unlock (&root_rp->
mutex);
340 for (i = 0; i <
vec_len (svm_names); i++)
342 memset (&a, 0,
sizeof (a));
344 a.
name = (
char *) svm_names[i];
345 fformat (stdout,
"Checking %s region...\n", a.
name);
357 repair (
char *chroot_path,
int crash_root_region)
365 fformat (stdout,
"our pid: %d\n", getpid ());
377 svm_fd = shm_open ((
char *) shm_name, O_RDWR, 0777);
381 perror (
"svm_region_map(mmap open)");
388 PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0);
405 PROT_READ | PROT_WRITE,
406 MAP_SHARED | MAP_FIXED, svm_fd, 0);
421 if (pthread_mutex_trylock (&root_rp->
mutex))
423 clib_warning (
"root_rp->mutex LOCKED by pid %d, tag %d, cleared...",
425 memset (&root_rp->
mutex, 0, sizeof (root_rp->
mutex));
431 pthread_mutex_unlock (&root_rp->
mutex);
442 if (crash_root_region)
444 clib_warning (
"Leaving root region locked on purpose...");
445 pthread_mutex_lock (&root_rp->
mutex);
458 char *chroot_path = 0;
465 if (
unformat (&input,
"show-verbose"))
467 show (chroot_path, 1);
472 show (chroot_path, 0);
475 else if (
unformat (&input,
"client-scan"))
480 else if (
unformat (&input,
"repair"))
485 else if (
unformat (&input,
"crash"))
490 else if (
unformat (&input,
"trace-on %s", &name))
492 trace (chroot_path, name, 1);
495 else if (
unformat (&input,
"trace-off %s", &name))
497 trace (chroot_path, name, 0);
500 else if (
unformat (&input,
"chroot %s", &chroot_u8))
502 chroot_path = (
char *) chroot_u8;
515 "%s: show | show-verbose | client-scan | trace-on <region-name>\n",
517 fformat (stdout,
" trace-off <region-name>\n");
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
svm_region_t * svm_get_root_rp(void)
#define SVM_GLOBAL_REGION_NAME
sll srl srl sll sra u16x4 i
static void svm_pop_heap(void *oldheap)
void * svm_map_region(svm_map_region_args_t *a)
Fixed length block allocator.
void svm_client_scan(const char *root_path)
#define SVM_PVT_MHEAP_SIZE
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static void * svm_push_data_heap(svm_region_t *rp)
void * svm_region_find_or_create(svm_map_region_args_t *a)
#define SVM_GLOBAL_REGION_BASEVA
u8 * format_svm_region(u8 *s, va_list *args)
svm_subregion_t * subregions
#define SVM_GLOBAL_REGION_SIZE
#define uword_to_pointer(u, type)
static void * svm_push_pvt_heap(svm_region_t *rp)
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
u8 * shm_name_from_svm_map_region_args(svm_map_region_args_t *a)
void mheap_trace(void *v, int enable)
Bitmaps built as vectors of machine words.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_unix_warning(format, args...)
void svm_region_unmap(void *rp_arg)
#define hash_get_mem(h, key)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static svm_region_t * root_rp
int svm_region_init_chroot(const char *root_path)