X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fcli.c;h=c43371e0d9f144d53e4adedc8bafff0af1c04903;hb=99e3b8b84e665616d5daa21d3f08c9c8358b8da4;hp=ec27c48137429dd7381ff35b683ac4f20798b0bc;hpb=a1f5a956e5b2cfeb591dcdfb34d23ebed84d0bca;p=vpp.git diff --git a/src/vlib/cli.c b/src/vlib/cli.c index ec27c481374..c43371e0d9f 100644 --- a/src/vlib/cli.c +++ b/src/vlib/cli.c @@ -38,7 +38,9 @@ */ #include +#include #include +#include #include #include #include @@ -157,6 +159,64 @@ done: return match; } +uword +unformat_vlib_cli_line (unformat_input_t *i, va_list *va) +{ + unformat_input_t *result = va_arg (*va, unformat_input_t *); + u8 *line = 0; + uword c; + int skip; + +next_line: + skip = 0; + + /* skip leading whitespace if any */ + unformat_skip_white_space (i); + + if (unformat_is_eof (i)) + return 0; + + while ((c = unformat_get_input (i)) != UNFORMAT_END_OF_INPUT) + { + if (c == '\\') + { + c = unformat_get_input (i); + + if (c == '\n') + { + if (!skip) + vec_add1 (line, '\n'); + skip = 0; + continue; + } + + if (!skip) + vec_add1 (line, '\\'); + + if (c == UNFORMAT_END_OF_INPUT) + break; + + if (!skip) + vec_add1 (line, c); + continue; + } + + if (c == '#') + skip = 1; + else if (c == '\n') + break; + + if (!skip) + vec_add1 (line, c); + } + + if (line == 0) + goto next_line; + + unformat_init_vector (result, line); + return 1; +} + /* Looks for string based sub-input formatted { SUB-INPUT }. */ uword unformat_vlib_cli_sub_input (unformat_input_t * i, va_list * args) @@ -204,35 +264,13 @@ get_sub_command (vlib_cli_main_t * cm, vlib_cli_command_t * parent, u32 si) static uword unformat_vlib_cli_sub_command (unformat_input_t * i, va_list * args) { - vlib_main_t *vm = va_arg (*args, vlib_main_t *); + vlib_main_t __clib_unused *vm = va_arg (*args, vlib_main_t *); + vlib_global_main_t *vgm = vlib_get_global_main (); vlib_cli_command_t *c = va_arg (*args, vlib_cli_command_t *); vlib_cli_command_t **result = va_arg (*args, vlib_cli_command_t **); - vlib_cli_main_t *cm = &vm->cli_main; + vlib_cli_main_t *cm = &vgm->cli_main; uword *match_bitmap, is_unique, index; - { - vlib_cli_sub_rule_t *sr; - vlib_cli_parse_rule_t *r; - vec_foreach (sr, c->sub_rules) - { - void **d; - r = vec_elt_at_index (cm->parse_rules, sr->rule_index); - vec_add2 (cm->parse_rule_data, d, 1); - vec_reset_length (d[0]); - if (r->data_size) - d[0] = _vec_resize (d[0], - /* length increment */ 1, - r->data_size, - /* header_bytes */ 0, - /* data align */ sizeof (uword)); - if (unformat_user (i, r->unformat_function, vm, d[0])) - { - *result = vec_elt_at_index (cm->commands, sr->command_index); - return 1; - } - } - } - match_bitmap = vlib_cli_sub_command_match (c, i); is_unique = clib_bitmap_count_set_bits (match_bitmap) == 1; index = ~0; @@ -260,8 +298,8 @@ vlib_cli_get_possible_completions (u8 * str) { vlib_cli_command_t *c; vlib_cli_sub_command_t *sc; - vlib_main_t *vm = vlib_get_main (); - vlib_cli_main_t *vcm = &vm->cli_main; + vlib_global_main_t *vgm = vlib_get_global_main (); + vlib_cli_main_t *vcm = &vgm->cli_main; uword *match_bitmap = 0; uword index, is_unique, help_next_level; u8 **result = 0; @@ -326,7 +364,7 @@ vlib_cli_get_possible_completions (u8 * str) * autocomplete the next level of subcommands */ help_next_level = (vec_len (str) == 0) || isspace (str[vec_len (str) - 1]); /* *INDENT-OFF* */ - clib_bitmap_foreach(index, match_bitmap, { + clib_bitmap_foreach (index, match_bitmap) { if (help_next_level && is_unique) { c = get_sub_command (vcm, c, index); vec_foreach (sc, c->sub_commands) { @@ -336,7 +374,7 @@ vlib_cli_get_possible_completions (u8 * str) } sc = &c->sub_commands[index]; vec_add1(result, (u8*) sc->name); - }); + } /* *INDENT-ON* */ done: @@ -362,50 +400,12 @@ format_vlib_cli_command_help (u8 * s, va_list * args) return s; } -static u8 * -format_vlib_cli_parse_rule_name (u8 * s, va_list * args) -{ - vlib_cli_parse_rule_t *r = va_arg (*args, vlib_cli_parse_rule_t *); - return format (s, "<%U>", format_c_identifier, r->name); -} - static u8 * format_vlib_cli_path (u8 * s, va_list * args) { u8 *path = va_arg (*args, u8 *); - int i, in_rule; - in_rule = 0; - for (i = 0; i < vec_len (path); i++) - { - switch (path[i]) - { - case '%': - in_rule = 1; - vec_add1 (s, '<'); /* start of */ - break; - - case '_': - /* _ -> space in rules. */ - vec_add1 (s, in_rule ? ' ' : '_'); - break; - - case ' ': - if (in_rule) - { - vec_add1 (s, '>'); /* end of */ - in_rule = 0; - } - vec_add1 (s, ' '); - break; - - default: - vec_add1 (s, path[i]); - break; - } - } - if (in_rule) - vec_add1 (s, '>'); /* terminate */ + s = format (s, "%v", path); return s; } @@ -415,13 +415,10 @@ all_subs (vlib_cli_main_t * cm, vlib_cli_command_t * subs, u32 command_index) { vlib_cli_command_t *c = vec_elt_at_index (cm->commands, command_index); vlib_cli_sub_command_t *sc; - vlib_cli_sub_rule_t *sr; if (c->function) vec_add1 (subs, c[0]); - vec_foreach (sr, c->sub_rules) - subs = all_subs (cm, subs, sr->command_index); vec_foreach (sc, c->sub_commands) subs = all_subs (cm, subs, sc->index); return subs; @@ -451,11 +448,12 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, unformat_input_t * input, uword parent_command_index) { + vlib_global_main_t *vgm = vlib_get_global_main (); vlib_cli_command_t *parent, *c; clib_error_t *error = 0; unformat_input_t sub_input; u8 *string; - uword is_main_dispatch = cm == &vm->cli_main; + uword is_main_dispatch = cm == &vgm->cli_main; parent = vec_elt_at_index (cm->commands, parent_command_index); if (is_main_dispatch && unformat (input, "help")) @@ -484,17 +482,14 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, vlib_cli_output (vm, "%U", format_vlib_cli_command_help, c, /* is_long */ 1); - else if (vec_len (c->sub_commands) + vec_len (c->sub_rules) == 0) + else if (vec_len (c->sub_commands) == 0) vlib_cli_output (vm, "%v: no sub-commands", c->path); else { + vlib_cli_sub_rule_t *sr, *subs = 0; vlib_cli_sub_command_t *sc; - vlib_cli_sub_rule_t *sr, *subs; - - subs = vec_dup (c->sub_rules); - /* Add in rules if any. */ vec_foreach (sc, c->sub_commands) { vec_add2 (subs, sr, 1); @@ -508,25 +503,11 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, for (i = 0; i < vec_len (subs); i++) { vlib_cli_command_t *d; - vlib_cli_parse_rule_t *r; d = vec_elt_at_index (cm->commands, subs[i].command_index); - r = - subs[i].rule_index != ~0 ? vec_elt_at_index (cm->parse_rules, - subs - [i].rule_index) : - 0; - - if (r) - vlib_cli_output - (vm, " %-30U %U", - format_vlib_cli_parse_rule_name, r, - format_vlib_cli_command_help, d, /* is_long */ 0); - else - vlib_cli_output - (vm, " %-30v %U", - subs[i].name, - format_vlib_cli_command_help, d, /* is_long */ 0); + vlib_cli_output + (vm, " %-30v %U", subs[i].name, + format_vlib_cli_command_help, d, /* is_long */ 0); } vec_free (subs); @@ -552,6 +533,23 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, vec_free (string); } + else if (unformat (input, "vpplog %v", &string)) + { + int i; + /* + * Delete leading whitespace, so "vpplog { this and that }" + * and "vpplog this" line up nicely. + */ + for (i = 0; i < vec_len (string); i++) + if (string[i] != ' ') + break; + if (i > 0) + vec_delete (string, i, 0); + + vlib_log_notice (cm->log, "CLI: %v", string); + vec_free (string); + } + else if (unformat (input, "uncomment %U", unformat_vlib_cli_sub_input, &sub_input)) { @@ -587,7 +585,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, } (void) clib_mem_trace_enable_disable (0); - leak_report = format (0, "%U", format_mheap, clib_mem_get_heap (), + leak_report = format (0, "%U", format_clib_mem_heap, 0, 1 /* verbose, i.e. print leaks */ ); clib_mem_trace (0); vlib_cli_output (vm, "%v", leak_report); @@ -638,16 +636,22 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, { u32 c; } *ed; - ed = ELOG_DATA (&vm->elog_main, e); - ed->c = elog_string (&vm->elog_main, c->path); + ed = ELOG_DATA (vlib_get_elog_main (), e); + ed->c = elog_string (vlib_get_elog_main (), "%v", c->path); } if (!c->is_mp_safe) vlib_worker_thread_barrier_sync (vm); + if (PREDICT_FALSE (vec_len (cm->perf_counter_cbs) != 0)) + clib_call_callbacks (cm->perf_counter_cbs, cm, + c - cm->commands, 0 /* before */ ); c->hit_counter++; c_error = c->function (vm, si, c); + if (PREDICT_FALSE (vec_len (cm->perf_counter_cbs) != 0)) + clib_call_callbacks (cm->perf_counter_cbs, cm, + c - cm->commands, 1 /* after */ ); if (!c->is_mp_safe) vlib_worker_thread_barrier_release (vm); @@ -664,17 +668,17 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm, { u32 c, err; } *ed; - ed = ELOG_DATA (&vm->elog_main, e); - ed->c = elog_string (&vm->elog_main, c->path); + ed = ELOG_DATA (vlib_get_elog_main (), e); + ed->c = elog_string (vlib_get_elog_main (), "%v", c->path); if (c_error) { vec_add1 (c_error->what, 0); - ed->err = elog_string (&vm->elog_main, + ed->err = elog_string (vlib_get_elog_main (), (char *) c_error->what); - _vec_len (c_error->what) -= 1; + vec_dec_len (c_error->what, 1); } else - ed->err = elog_string (&vm->elog_main, "OK"); + ed->err = elog_string (vlib_get_elog_main (), "OK"); } if (c_error) @@ -731,8 +735,8 @@ vlib_cli_input (vlib_main_t * vm, unformat_input_t * input, vlib_cli_output_function_t * function, uword function_arg) { + vlib_global_main_t *vgm = vlib_get_global_main (); vlib_process_t *cp = vlib_get_current_process (vm); - vlib_cli_main_t *cm = &vm->cli_main; clib_error_t *error; vlib_cli_output_function_t *save_function; uword save_function_arg; @@ -746,9 +750,8 @@ vlib_cli_input (vlib_main_t * vm, do { - vec_reset_length (cm->parse_rule_data); - error = vlib_cli_dispatch_sub_commands (vm, &vm->cli_main, input, /* parent */ - 0); + error = vlib_cli_dispatch_sub_commands (vm, &vgm->cli_main, input, + /* parent */ 0); } while (!error && !unformat (input, "%U", unformat_eof)); @@ -779,6 +782,11 @@ vlib_cli_output (vlib_main_t * vm, char *fmt, ...) s = va_format (0, fmt, &va); va_end (va); + /* some format functions might return 0 + * e.g. show int addr */ + if (NULL == s) + return; + /* Terminate with \n if not present. */ if (vec_len (s) > 0 && s[vec_len (s) - 1] != '\n') vec_add1 (s, '\n'); @@ -804,21 +812,17 @@ vl_msg_pop_heap (void *oldheap) { } -void *vlib_stats_push_heap (void *) __attribute__ ((weak)); -void * -vlib_stats_push_heap (void *notused) -{ - return 0; -} - static clib_error_t * show_memory_usage (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + clib_mem_main_t *mm = &clib_mem_main; int verbose __attribute__ ((unused)) = 0; - int api_segment = 0, stats_segment = 0, main_heap = 0; + int api_segment = 0, stats_segment = 0, main_heap = 0, numa_heaps = 0; + int map = 0; clib_error_t *error; u32 index = 0; + int i; uword clib_mem_trace_enable_disable (uword enable); uword was_enabled; @@ -833,6 +837,10 @@ show_memory_usage (vlib_main_t * vm, stats_segment = 1; else if (unformat (input, "main-heap")) main_heap = 1; + else if (unformat (input, "numa-heaps")) + numa_heaps = 1; + else if (unformat (input, "map")) + map = 1; else { error = clib_error_return (0, "unknown input `%U'", @@ -841,16 +849,16 @@ show_memory_usage (vlib_main_t * vm, } } - if ((api_segment + stats_segment + main_heap) == 0) + if ((api_segment + stats_segment + main_heap + numa_heaps + map) == 0) return clib_error_return - (0, "Please supply one of api-segment, stats-segment or main-heap"); + (0, "Need one of api-segment, stats-segment, main-heap, numa-heaps " + "or map"); if (api_segment) { void *oldheap = vl_msg_push_heap (); was_enabled = clib_mem_trace_enable_disable (0); - u8 *s_in_svm = - format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1); + u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1); vl_msg_pop_heap (oldheap); u8 *s = vec_dup (s_in_svm); @@ -864,15 +872,14 @@ show_memory_usage (vlib_main_t * vm, } if (stats_segment) { - void *oldheap = vlib_stats_push_heap (0); + void *oldheap = vlib_stats_set_heap (0); was_enabled = clib_mem_trace_enable_disable (0); - u8 *s_in_svm = - format (0, "%U\n", format_mheap, clib_mem_get_heap (), 1); + u8 *s_in_svm = format (0, "%U\n", format_clib_mem_heap, 0, 1); if (oldheap) clib_mem_set_heap (oldheap); u8 *s = vec_dup (s_in_svm); - oldheap = vlib_stats_push_heap (0); + oldheap = vlib_stats_set_heap (0); vec_free (s_in_svm); if (oldheap) { @@ -884,22 +891,7 @@ show_memory_usage (vlib_main_t * vm, vec_free (s); } -#if USE_DLMALLOC == 0 - /* *INDENT-OFF* */ - foreach_vlib_main ( - ({ - mheap_t *h = mheap_header (clib_per_cpu_mheaps[index]); - vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index, - vlib_worker_threads[index].name); - vlib_cli_output (vm, " %U\n", format_page_map, pointer_to_uword (h) - - h->vm_alloc_offset_from_header, - h->vm_alloc_size); - vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index], - verbose); - index++; - })); - /* *INDENT-ON* */ -#else + { if (main_heap) { @@ -909,38 +901,87 @@ show_memory_usage (vlib_main_t * vm, */ was_enabled = clib_mem_trace_enable_disable (0); - /* *INDENT-OFF* */ - foreach_vlib_main ( - ({ - struct dlmallinfo mi; - void *mspace; - mspace = clib_per_cpu_mheaps[index]; - - mi = mspace_mallinfo (mspace); - vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index, - vlib_worker_threads[index].name); - vlib_cli_output (vm, " %U\n", format_page_map, - pointer_to_uword (mspace_least_addr(mspace)), - mi.arena); - vlib_cli_output (vm, " %U\n", format_mheap, - clib_per_cpu_mheaps[index], - verbose); - index++; - })); - /* *INDENT-ON* */ + foreach_vlib_main () + { + vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n" : "", index, + vlib_worker_threads[index].name); + vlib_cli_output (vm, " %U\n", format_clib_mem_heap, + mm->per_cpu_mheaps[index], verbose); + index++; + } /* Restore the trace flag */ clib_mem_trace_enable_disable (was_enabled); } + if (numa_heaps) + { + for (i = 0; i < ARRAY_LEN (mm->per_numa_mheaps); i++) + { + if (mm->per_numa_mheaps[i] == 0) + continue; + if (mm->per_numa_mheaps[i] == mm->per_cpu_mheaps[i]) + { + vlib_cli_output (vm, "Numa %d uses the main heap...", i); + continue; + } + was_enabled = clib_mem_trace_enable_disable (0); + + vlib_cli_output (vm, "Numa %d:", i); + vlib_cli_output (vm, " %U\n", format_clib_mem_heap, + mm->per_numa_mheaps[index], verbose); + } + } + if (map) + { + clib_mem_page_stats_t stats = { }; + clib_mem_vm_map_hdr_t *hdr = 0; + u8 *s = 0; + int numa = -1; + + s = format (s, "\n%-16s%7s%5s%7s%7s", + "StartAddr", "size", "FD", "PageSz", "Pages"); + while ((numa = vlib_mem_get_next_numa_node (numa)) != -1) + s = format (s, " Numa%u", numa); + s = format (s, " NotMap"); + s = format (s, " Name"); + vlib_cli_output (vm, "%v", s); + vec_reset_length (s); + + while ((hdr = clib_mem_vm_get_next_map_hdr (hdr))) + { + clib_mem_get_page_stats ((void *) hdr->base_addr, + hdr->log2_page_sz, hdr->num_pages, + &stats); + s = format (s, "%016lx%7U", + hdr->base_addr, format_memory_size, + hdr->num_pages << hdr->log2_page_sz); + + if (hdr->fd != -1) + s = format (s, "%5d", hdr->fd); + else + s = format (s, "%5s", " "); + + s = format (s, "%7U%7lu", + format_log2_page_size, hdr->log2_page_sz, + hdr->num_pages); + while ((numa = vlib_mem_get_next_numa_node (numa)) != -1) + s = format (s, "%6lu", stats.per_numa[numa]); + s = format (s, "%7lu", stats.not_mapped); + s = format (s, " %s", hdr->name); + vlib_cli_output (vm, "%v", s); + vec_reset_length (s); + } + vec_free (s); + } } -#endif /* USE_DLMALLOC */ return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_memory_usage_command, static) = { .path = "show memory", - .short_help = "show memory [api-segment][stats-segment][verbose]", + .short_help = "show memory [api-segment][stats-segment][verbose]\n" + " [numa-heaps][map]", .function = show_memory_usage, }; /* *INDENT-ON* */ @@ -983,11 +1024,13 @@ enable_disable_memory_trace (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + clib_mem_main_t *mm = &clib_mem_main; unformat_input_t _line_input, *line_input = &_line_input; int enable = 1; int api_segment = 0; int stats_segment = 0; int main_heap = 0; + u32 numa_id = ~0; void *oldheap; if (!unformat_user (input, unformat_line_input, line_input)) @@ -1003,6 +1046,8 @@ enable_disable_memory_trace (vlib_main_t * vm, stats_segment = 1; else if (unformat (line_input, "main-heap")) main_heap = 1; + else if (unformat (line_input, "numa-heap %d", &numa_id)) + ; else { unformat_free (line_input); @@ -1011,10 +1056,12 @@ enable_disable_memory_trace (vlib_main_t * vm, } unformat_free (line_input); - if ((api_segment + stats_segment + main_heap + (enable == 0)) == 0) + if ((api_segment + stats_segment + main_heap + (enable == 0) + + (numa_id != ~0)) == 0) { return clib_error_return - (0, "Need one of main-heap, stats-segment or api-segment"); + (0, "Need one of main-heap, stats-segment, api-segment,\n" + "numa-heap or disable"); } /* Turn off current trace, if any */ @@ -1043,7 +1090,7 @@ enable_disable_memory_trace (vlib_main_t * vm, /* Stats segment */ if (stats_segment) { - oldheap = vlib_stats_push_heap (0); + oldheap = vlib_stats_set_heap (); current_traced_heap = clib_mem_get_heap (); clib_mem_trace (stats_segment); /* We don't want to call vlib_stats_pop_heap... */ @@ -1058,80 +1105,32 @@ enable_disable_memory_trace (vlib_main_t * vm, clib_mem_trace (main_heap); } - return 0; -} - -/* *INDENT-OFF* */ -VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = { - .path = "memory-trace", - .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n", - .function = enable_disable_memory_trace, -}; -/* *INDENT-ON* */ - - -static clib_error_t * -test_heap_validate (vlib_main_t * vm, unformat_input_t * input, - vlib_cli_command_t * cmd) -{ -#if USE_DLMALLOC == 0 - clib_error_t *error = 0; - void *heap; - mheap_t *mheap; - - if (unformat (input, "on")) - { - /* *INDENT-OFF* */ - foreach_vlib_main({ - heap = clib_per_cpu_mheaps[this_vlib_main->thread_index]; - mheap = mheap_header(heap); - mheap->flags |= MHEAP_FLAG_VALIDATE; - // Turn off small object cache because it delays detection of errors - mheap->flags &= ~MHEAP_FLAG_SMALL_OBJECT_CACHE; - }); - /* *INDENT-ON* */ - - } - else if (unformat (input, "off")) + if (numa_id != ~0) { - /* *INDENT-OFF* */ - foreach_vlib_main({ - heap = clib_per_cpu_mheaps[this_vlib_main->thread_index]; - mheap = mheap_header(heap); - mheap->flags &= ~MHEAP_FLAG_VALIDATE; - mheap->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE; - }); - /* *INDENT-ON* */ + if (numa_id >= ARRAY_LEN (mm->per_numa_mheaps)) + return clib_error_return (0, "Numa %d out of range", numa_id); + if (mm->per_numa_mheaps[numa_id] == 0) + return clib_error_return (0, "Numa %d heap not active", numa_id); + + if (mm->per_numa_mheaps[numa_id] == clib_mem_get_heap ()) + return clib_error_return (0, "Numa %d uses the main heap...", + numa_id); + current_traced_heap = mm->per_numa_mheaps[numa_id]; + oldheap = clib_mem_set_heap (current_traced_heap); + clib_mem_trace (1); + clib_mem_set_heap (oldheap); } - else if (unformat (input, "now")) - { - /* *INDENT-OFF* */ - foreach_vlib_main({ - heap = clib_per_cpu_mheaps[this_vlib_main->thread_index]; - mheap = mheap_header(heap); - mheap_validate(heap); - }); - /* *INDENT-ON* */ - vlib_cli_output (vm, "heap validation complete"); - } - else - { - return clib_error_return (0, "unknown input `%U'", - format_unformat_error, input); - } - return error; -#else - return clib_error_return (0, "unimplemented..."); -#endif /* USE_DLMALLOC */ + return 0; } /* *INDENT-OFF* */ -VLIB_CLI_COMMAND (cmd_test_heap_validate,static) = { - .path = "test heap-validate", - .short_help = " validate heap on future allocs/frees or right now", - .function = test_heap_validate, +VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = { + .path = "memory-trace", + .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n" + " [numa-heap ]\n", + .function = enable_disable_memory_trace, }; /* *INDENT-ON* */ @@ -1139,6 +1138,7 @@ static clib_error_t * restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + vlib_global_main_t *vgm = vlib_get_global_main (); clib_file_main_t *fm = &file_main; clib_file_t *f; @@ -1147,15 +1147,15 @@ restart_cmd_fn (vlib_main_t * vm, unformat_input_t * input, /* Close all known open files */ /* *INDENT-OFF* */ - pool_foreach(f, fm->file_pool, - ({ + pool_foreach (f, fm->file_pool) + { if (f->file_descriptor > 2) close(f->file_descriptor); - })); + } /* *INDENT-ON* */ /* Exec ourself */ - execve (vm->name, (char **) vm->argv, environ); + execve (vgm->name, (char **) vgm->argv, environ); return 0; } @@ -1237,7 +1237,7 @@ vlib_cli_normalize_path (char *input, char **result) /* Remove any extra space at end. */ if (l > 0 && s[l - 1] == ' ') - _vec_len (s) -= 1; + vec_dec_len (s, 1); *result = s; return index_of_last_space; @@ -1276,6 +1276,9 @@ add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index) vec_add (sub_name, c->path + l + 1, vec_len (c->path) - (l + 1)); } + /* "Can't happen," check mainly to shut up coverity */ + ALWAYS_ASSERT (sub_name != 0); + if (sub_name[0] == '%') { uword *q; @@ -1296,19 +1299,11 @@ add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index) return; } - q = hash_get_mem (cm->parse_rule_index_by_name, sub_name); - if (!q) - { - clib_error ("reference to unknown rule `%%%v' in path `%v'", - sub_name, c->path); - return; - } - hash_set_mem (p->sub_rule_index_by_name, sub_name, vec_len (p->sub_rules)); vec_add2 (p->sub_rules, sr, 1); sr->name = sub_name; - sr->rule_index = q[0]; + sr->rule_index = sr - p->sub_rules; sr->command_index = child_index; return; } @@ -1413,7 +1408,8 @@ vlib_cli_command_is_empty (vlib_cli_command_t * c) clib_error_t * vlib_cli_register (vlib_main_t * vm, vlib_cli_command_t * c) { - vlib_cli_main_t *cm = &vm->cli_main; + vlib_global_main_t *vgm = vlib_get_global_main (); + vlib_cli_main_t *cm = &vgm->cli_main; clib_error_t *error = 0; uword ci, *p; char *normalized_path; @@ -1492,6 +1488,8 @@ vlib_cli_register (vlib_main_t * vm, vlib_cli_command_t * c) return 0; } +#if 0 +/* $$$ turn back on again someday, maybe */ clib_error_t * vlib_cli_register_parse_rule (vlib_main_t * vm, vlib_cli_parse_rule_t * r_reg) { @@ -1524,8 +1522,6 @@ vlib_cli_register_parse_rule (vlib_main_t * vm, vlib_cli_parse_rule_t * r_reg) return error; } -#if 0 -/* $$$ turn back on again someday, maybe */ static clib_error_t *vlib_cli_register_parse_rules (vlib_main_t * vm, vlib_cli_parse_rule_t * lo, @@ -1555,8 +1551,9 @@ done: #endif static clib_error_t * -elog_trace_command_fn (vlib_main_t * vm, - unformat_input_t * input, vlib_cli_command_t * cmd) +event_logger_trace_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; int enable = 1; @@ -1607,7 +1604,7 @@ elog_trace_command_fn (vlib_main_t * vm, */ if (dispatch || circuit) { - elog_main_t *em = &vm->elog_main; + elog_main_t *em = &vlib_global_main.elog_main; em->n_total_events_disable_limit = em->n_total_events + vec_len (em->event_ring); @@ -1645,21 +1642,20 @@ print_status: * * @cliexpar * @clistart - * elog trace api cli barrier - * elog trace api cli barrier disable - * elog trace dispatch - * elog trace circuit-node ethernet-input - * elog trace + * event-logger trace api cli barrier + * event-logger trace api cli barrier disable + * event-logger trace dispatch + * event-logger trace circuit-node ethernet-input * @cliend - * @cliexcmd{elog trace [api][cli][barrier][disable]} + * @cliexcmd{event-logger trace [api][cli][barrier][disable]} ?*/ /* *INDENT-OFF* */ -VLIB_CLI_COMMAND (elog_trace_command, static) = +VLIB_CLI_COMMAND (event_logger_trace_command, static) = { - .path = "elog trace", - .short_help = "elog trace [api][cli][barrier][dispatch]\n" + .path = "event-logger trace", + .short_help = "event-logger trace [api][cli][barrier][dispatch]\n" "[circuit-node e.g. ethernet-input][disable]", - .function = elog_trace_command_fn, + .function = event_logger_trace_command_fn, }; /* *INDENT-ON* */ @@ -1687,8 +1683,8 @@ sort_cmds_by_path (void *a1, void *a2) { u32 *index1 = a1; u32 *index2 = a2; - vlib_main_t *vm = vlib_get_main (); - vlib_cli_main_t *cm = &vm->cli_main; + vlib_global_main_t *vgm = vlib_get_global_main (); + vlib_cli_main_t *cm = &vgm->cli_main; vlib_cli_command_t *c1, *c2; int i, lmin; @@ -1798,6 +1794,7 @@ static clib_error_t * show_cli_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + vlib_global_main_t *vgm = vlib_get_global_main (); int show_mp_safe = 0; int show_not_mp_safe = 0; int show_hit = 0; @@ -1821,8 +1818,8 @@ show_cli_command_fn (vlib_main_t * vm, if (clear_hit == 0 && (show_mp_safe + show_not_mp_safe) == 0) show_mp_safe = show_not_mp_safe = 1; - vlib_cli_output (vm, "%U", format_mp_safe, &vm->cli_main, - show_mp_safe, show_not_mp_safe, show_hit, clear_hit); + vlib_cli_output (vm, "%U", format_mp_safe, &vgm->cli_main, show_mp_safe, + show_not_mp_safe, show_hit, clear_hit); if (clear_hit) vlib_cli_output (vm, "hit counters cleared..."); @@ -1882,7 +1879,8 @@ VLIB_CLI_COMMAND (show_cli_command, static) = static clib_error_t * vlib_cli_init (vlib_main_t * vm) { - vlib_cli_main_t *cm = &vm->cli_main; + vlib_global_main_t *vgm = vlib_get_global_main (); + vlib_cli_main_t *cm = &vgm->cli_main; clib_error_t *error = 0; vlib_cli_command_t *cmd; @@ -1895,6 +1893,9 @@ vlib_cli_init (vlib_main_t * vm) return error; cmd = cmd->next_cli_command; } + + cm->log = vlib_log_register_class_rate_limit ( + "cli", "log", 0x7FFFFFFF /* aka no rate limit */); return error; }