From patchwork Thu Feb 28 12:12:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aya Levin X-Patchwork-Id: 1049415 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=mellanox.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 449BKZ13h0z9s47 for ; Thu, 28 Feb 2019 23:13:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731428AbfB1MNU (ORCPT ); Thu, 28 Feb 2019 07:13:20 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:45494 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731217AbfB1MNT (ORCPT ); Thu, 28 Feb 2019 07:13:19 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ayal@mellanox.com) with ESMTPS (AES256-SHA encrypted); 28 Feb 2019 14:13:15 +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 x1SCDFnS013776; Thu, 28 Feb 2019 14:13:15 +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 x1SCDF4Z015814; Thu, 28 Feb 2019 14:13:15 +0200 Received: (from ayal@localhost) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id x1SCDE7t015813; Thu, 28 Feb 2019 14:13:14 +0200 From: Aya Levin To: David Ahern Cc: netdev@vger.kernel.org, Jiri Pirko , Moshe Shemesh , Eran Ben Elisha , Aya Levin Subject: [PATCH v4 iproute2-next 04/11] devlink: Add helper functions for name and value separately Date: Thu, 28 Feb 2019 14:12:57 +0200 Message-Id: <1551355984-15752-5-git-send-email-ayal@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1551355984-15752-1-git-send-email-ayal@mellanox.com> References: <1551355984-15752-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 Acked-by: Jiri Pirko --- devlink/devlink.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/devlink/devlink.c b/devlink/devlink.c index 4b7e8ec2c88a..c3f874564309 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -1661,6 +1661,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) {