From: Parav Pandit Date: Tue, 23 Jun 2020 10:44:23 +0000 (+0000) Subject: devlink: Move devlink port code at start to reuse X-Git-Tag: v5.9.0~39^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2de449df19be72efb581b9b42246955e1529a75c;p=thirdparty%2Fiproute2.git devlink: Move devlink port code at start to reuse To reuse print routines for port function in subsequent patch, move print routine specific to devlink device at start of the file. Signed-off-by: Parav Pandit Reviewed-by: Jiri Pirko Signed-off-by: David Ahern --- diff --git a/devlink/devlink.c b/devlink/devlink.c index 507972c36..b7699f301 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -429,6 +429,127 @@ static void __pr_out_indent_newline(struct dl *dl) pr_out(" "); } +static bool is_binary_eol(int i) +{ + return !(i%16); +} + +static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len) +{ + int i = 0; + + while (i < len) { + if (dl->json_output) + print_int(PRINT_JSON, NULL, NULL, data[i]); + else + pr_out("%02x ", data[i]); + i++; + if (!dl->json_output && is_binary_eol(i)) + __pr_out_newline(); + } + if (!dl->json_output && !is_binary_eol(i)) + __pr_out_newline(); +} + +static void pr_out_name(struct dl *dl, const char *name) +{ + __pr_out_indent_newline(dl); + if (dl->json_output) + print_string(PRINT_JSON, name, NULL, NULL); + else + pr_out("%s:", name); +} + +static void pr_out_u64(struct dl *dl, const char *name, uint64_t val) +{ + __pr_out_indent_newline(dl); + if (val == (uint64_t) -1) + return print_string_name_value(name, "unlimited"); + + if (dl->json_output) + print_u64(PRINT_JSON, name, NULL, val); + else + pr_out("%s %"PRIu64, name, val); +} + +static void pr_out_section_start(struct dl *dl, const char *name) +{ + if (dl->json_output) { + open_json_object(NULL); + open_json_object(name); + } +} + +static void pr_out_section_end(struct dl *dl) +{ + if (dl->json_output) { + if (dl->arr_last.present) + close_json_array(PRINT_JSON, NULL); + close_json_object(); + close_json_object(); + } +} + +static void pr_out_array_start(struct dl *dl, const char *name) +{ + if (dl->json_output) { + open_json_array(PRINT_JSON, name); + } else { + __pr_out_indent_inc(); + __pr_out_newline(); + pr_out("%s:", name); + __pr_out_indent_inc(); + __pr_out_newline(); + } +} + +static void pr_out_array_end(struct dl *dl) +{ + if (dl->json_output) { + close_json_array(PRINT_JSON, NULL); + } else { + __pr_out_indent_dec(); + __pr_out_indent_dec(); + } +} + +static void pr_out_object_start(struct dl *dl, const char *name) +{ + if (dl->json_output) { + open_json_object(name); + } else { + __pr_out_indent_inc(); + __pr_out_newline(); + pr_out("%s:", name); + __pr_out_indent_inc(); + __pr_out_newline(); + } +} + +static void pr_out_object_end(struct dl *dl) +{ + if (dl->json_output) { + close_json_object(); + } else { + __pr_out_indent_dec(); + __pr_out_indent_dec(); + } +} + +static void pr_out_entry_start(struct dl *dl) +{ + if (dl->json_output) + open_json_object(NULL); +} + +static void pr_out_entry_end(struct dl *dl) +{ + if (dl->json_output) + close_json_object(); + else + __pr_out_newline(); +} + static void check_indent_newline(struct dl *dl) { __pr_out_indent_newline(dl); @@ -1950,49 +2071,6 @@ static void pr_out_port_handle_end(struct dl *dl) pr_out("\n"); } -static void pr_out_u64(struct dl *dl, const char *name, uint64_t val) -{ - __pr_out_indent_newline(dl); - if (val == (uint64_t) -1) - return print_string_name_value(name, "unlimited"); - - if (dl->json_output) - print_u64(PRINT_JSON, name, NULL, val); - else - pr_out("%s %"PRIu64, name, val); -} - -static bool is_binary_eol(int i) -{ - return !(i%16); -} - -static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len) -{ - int i = 0; - - while (i < len) { - if (dl->json_output) - print_int(PRINT_JSON, NULL, NULL, data[i]); - else - pr_out("%02x ", data[i]); - i++; - if (!dl->json_output && is_binary_eol(i)) - __pr_out_newline(); - } - if (!dl->json_output && !is_binary_eol(i)) - __pr_out_newline(); -} - -static void pr_out_name(struct dl *dl, const char *name) -{ - __pr_out_indent_newline(dl); - if (dl->json_output) - print_string(PRINT_JSON, name, NULL, NULL); - else - pr_out("%s:", name); -} - static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr) { if (dl->json_output) { @@ -2034,84 +2112,6 @@ static void pr_out_region_chunk(struct dl *dl, uint8_t *data, uint32_t len, pr_out_region_chunk_end(dl); } -static void pr_out_section_start(struct dl *dl, const char *name) -{ - if (dl->json_output) { - open_json_object(NULL); - open_json_object(name); - } -} - -static void pr_out_section_end(struct dl *dl) -{ - if (dl->json_output) { - if (dl->arr_last.present) - close_json_array(PRINT_JSON, NULL); - close_json_object(); - close_json_object(); - } -} - -static void pr_out_array_start(struct dl *dl, const char *name) -{ - if (dl->json_output) { - open_json_array(PRINT_JSON, name); - } else { - __pr_out_indent_inc(); - __pr_out_newline(); - pr_out("%s:", name); - __pr_out_indent_inc(); - __pr_out_newline(); - } -} - -static void pr_out_array_end(struct dl *dl) -{ - if (dl->json_output) { - close_json_array(PRINT_JSON, NULL); - } else { - __pr_out_indent_dec(); - __pr_out_indent_dec(); - } -} - -static void pr_out_object_start(struct dl *dl, const char *name) -{ - if (dl->json_output) { - open_json_object(name); - } else { - __pr_out_indent_inc(); - __pr_out_newline(); - pr_out("%s:", name); - __pr_out_indent_inc(); - __pr_out_newline(); - } -} - -static void pr_out_object_end(struct dl *dl) -{ - if (dl->json_output) { - close_json_object(); - } else { - __pr_out_indent_dec(); - __pr_out_indent_dec(); - } -} - -static void pr_out_entry_start(struct dl *dl) -{ - if (dl->json_output) - open_json_object(NULL); -} - -static void pr_out_entry_end(struct dl *dl) -{ - if (dl->json_output) - close_json_object(); - else - __pr_out_newline(); -} - static void pr_out_stats(struct dl *dl, struct nlattr *nla_stats) { struct nlattr *tb[DEVLINK_ATTR_STATS_MAX + 1] = {};