From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7386C43381 for ; Thu, 21 Feb 2019 13:43:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1A5B207E0 for ; Thu, 21 Feb 2019 13:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728181AbfBUNnG (ORCPT ); Thu, 21 Feb 2019 08:43:06 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:43865 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728154AbfBUNnF (ORCPT ); Thu, 21 Feb 2019 08:43:05 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ayal@mellanox.com) with ESMTPS (AES256-SHA encrypted); 21 Feb 2019 15:42:59 +0200 Received: from dev-l-vrt-210.mtl.labs.mlnx (dev-l-vrt-210.mtl.labs.mlnx [10.134.210.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x1LDgxW1013981; Thu, 21 Feb 2019 15:42:59 +0200 Received: from dev-l-vrt-210.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Debian-8ubuntu1) with ESMTP id x1LDgx4S018296; Thu, 21 Feb 2019 15:42:59 +0200 Received: (from ayal@localhost) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id x1LDgxtL018295; Thu, 21 Feb 2019 15:42:59 +0200 From: Aya Levin To: David Ahern Cc: netdev@vger.kernel.org, Jiri Pirko , Moshe Shemesh , Eran Ben Elisha , Aya Levin Subject: [PATCH v2 iproute2-next 04/11] devlink: Add helper functions for name and value separately Date: Thu, 21 Feb 2019 15:42:40 +0200 Message-Id: <1550756567-18227-5-git-send-email-ayal@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1550756567-18227-1-git-send-email-ayal@mellanox.com> References: <1550756567-18227-1-git-send-email-ayal@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a new helper functions which outputs only values (without name label) for different types: boolean, uint, uint64, string and binary. In addition add a helper function which prints only the name label. Signed-off-by: Aya Levin Reviewed-by: Moshe Shemesh --- devlink/devlink.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index b073ae020d52..5d69c4f24f29 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -1588,7 +1588,6 @@ static void pr_out_port_handle_end(struct dl *dl) pr_out("\n"); } - static void pr_out_str(struct dl *dl, const char *name, const char *val) { if (dl->json_output) { @@ -1636,6 +1635,71 @@ static void pr_out_u64(struct dl *dl, const char *name, uint64_t val) } } +static void pr_out_bool_value(struct dl *dl, bool value) +{ + if (dl->json_output) + jsonw_bool(dl->jw, value); + else + pr_out(" %s", value ? "true" : "false"); +} + +static void pr_out_uint_value(struct dl *dl, unsigned int value) +{ + if (dl->json_output) + jsonw_uint(dl->jw, value); + else + pr_out(" %u", value); +} + +static void pr_out_uint64_value(struct dl *dl, uint64_t value) +{ + if (dl->json_output) + jsonw_u64(dl->jw, value); + else + pr_out(" %lu", value); +} + +static void pr_out_binary_value(struct dl *dl, uint8_t *data, uint32_t len) +{ + int i = 1; + + if (dl->json_output) + jsonw_start_array(dl->jw); + else + pr_out("\n"); + + while (i < len) { + if (dl->json_output) { + jsonw_printf(dl->jw, "%d", data[i]); + } else { + pr_out(" %02x", data[i]); + if (!(i % 16)) + pr_out("\n"); + } + i++; + } + if (dl->json_output) + jsonw_end_array(dl->jw); + else if ((i - 1) % 16) + pr_out("\n"); +} + +static void pr_out_str_value(struct dl *dl, const char *value) +{ + if (dl->json_output) + jsonw_string(dl->jw, value); + else + pr_out(" %s", value); +} + +static void pr_out_name(struct dl *dl, const char *name) +{ + if (dl->json_output) + jsonw_name(dl->jw, name); + else + pr_out(" %s:", name); +} + static void pr_out_region_chunk_start(struct dl *dl, uint64_t addr) { if (dl->json_output) { -- 2.14.1