22 #include <sys/types.h> 25 #include <netinet/in.h> 53 int verbose = va_arg (*args,
int);
65 pthread_mutex_lock (&root_rp->
mutex);
76 name = vec_dup (subp->subregion_name);
77 vec_add1(svm_names, name);
80 pthread_mutex_unlock (&root_rp->
mutex);
82 for (i = 0; i <
vec_len(svm_names); i++) {
84 a->
name = (
char *) svm_names[i];
87 pthread_mutex_lock (&rp->
mutex);
89 pthread_mutex_unlock (&rp->
mutex);
99 void show (
char *chroot_path,
int verbose)
107 fformat(stdout,
"My pid is %d\n", getpid());
128 svm_fd = shm_open((
char *)shm_name, O_RDWR, 0777);
131 perror(
"svm_region_map(mmap open)");
137 PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0);
148 while (rp->
version == 0 && deadman++ < 5) {
165 rp = (
void *) mmap ((
void *)a->
baseva, a->
size,
166 PROT_READ | PROT_WRITE,
167 MAP_SHARED | MAP_FIXED, svm_fd, 0);
177 if (pthread_mutex_trylock(&rp->
mutex)) {
178 clib_warning (
"rp->mutex LOCKED by pid %d, tag %d, cleared...",
184 pthread_mutex_unlock(&rp->
mutex);
187 return ((
void *) rp);
206 pthread_mutex_lock(&rp->
mutex);
219 pthread_mutex_unlock(&rp->
mutex);
253 static void trace (
char *chroot_path,
char *name,
int enable_disable)
301 pthread_mutex_lock (&root_rp->
mutex);
310 name = vec_dup (subp->subregion_name);
311 vec_add1(svm_names, name);
314 pthread_mutex_unlock (&root_rp->
mutex);
316 for (i = 0; i <
vec_len(svm_names); i++) {
317 memset (&a, 0,
sizeof (a));
319 a.
name = (
char *) svm_names[i];
320 fformat(stdout,
"Checking %s region...\n",
331 void repair (
char *chroot_path,
int crash_root_region)
339 fformat(stdout,
"our pid: %d\n", getpid());
351 svm_fd = shm_open ((
char *)shm_name, O_RDWR, 0777);
354 perror(
"svm_region_map(mmap open)");
361 PROT_READ | PROT_WRITE, MAP_SHARED, svm_fd, 0);
376 root_rp = (
void *) mmap ((
void *)a->
baseva, a->
size,
377 PROT_READ | PROT_WRITE,
378 MAP_SHARED | MAP_FIXED, svm_fd, 0);
391 if (pthread_mutex_trylock(&root_rp->
mutex)) {
392 clib_warning (
"root_rp->mutex LOCKED by pid %d, tag %d, cleared...",
394 memset(&root_rp->
mutex, 0, sizeof (root_rp->
mutex));
398 pthread_mutex_unlock(&root_rp->
mutex);
409 if (crash_root_region) {
410 clib_warning (
"Leaving root region locked on purpose...");
411 pthread_mutex_lock(&root_rp->
mutex);
418 int main (
int argc,
char **argv)
423 char *chroot_path = 0;
429 if (
unformat(&input,
"show-verbose")) {
430 show (chroot_path, 1);
432 }
else if (
unformat (&input,
"show")) {
433 show (chroot_path, 0);
435 }
else if (
unformat (&input,
"client-scan")) {
438 }
else if (
unformat (&input,
"repair")) {
441 }
else if (
unformat (&input,
"crash")) {
444 }
else if (
unformat (&input,
"trace-on %s", &name)) {
445 trace (chroot_path, name, 1);
447 }
else if (
unformat (&input,
"trace-off %s", &name)) {
448 trace (chroot_path, name, 0);
450 }
else if (
unformat (&input,
"chroot %s", &chroot_u8)) {
451 chroot_path = (
char *) chroot_u8;
460 fformat(stdout,
"%s: show | show-verbose | client-scan | trace-on <region-name>\n", argv[0]);
461 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)
sll srl srl sll sra u16x4 i
static void svm_pop_heap(void *oldheap)
void * svm_map_region(svm_map_region_args_t *a)
#define pool_foreach(VAR, POOL, BODY)
static void * svm_push_data_heap(svm_region_t *rp)
void * svm_region_find_or_create(svm_map_region_args_t *a)
#define clib_warning(format, args...)
#define SVM_GLOBAL_REGION_BASEVA
u8 * format_svm_region(u8 *s, va_list *args)
svm_subregion_t * subregions
static void * svm_push_pvt_heap(svm_region_t *rp)
#define vec_free(V)
Free vector's memory (no header).
#define clib_unix_warning(format, args...)
u8 * shm_name_from_svm_map_region_args(svm_map_region_args_t *a)
void mheap_trace(void *v, int enable)
void svm_region_init_chroot(char *root_path)
#define SVM_GLOBAL_REGION_SIZE
#define SVM_GLOBAL_REGION_NAME
#define SVM_PVT_MHEAP_SIZE
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void svm_region_unmap(void *rp_arg)
#define hash_get_mem(h, key)
void svm_client_scan(char *root_path)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
static svm_region_t * root_rp