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=-7.0 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS 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 67A34C43381 for ; Thu, 21 Feb 2019 18:02:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30D4020836 for ; Thu, 21 Feb 2019 18:02:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20150623.gappssmtp.com header.i=@networkplumber-org.20150623.gappssmtp.com header.b="jivddJHT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726476AbfBUSCR (ORCPT ); Thu, 21 Feb 2019 13:02:17 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43536 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbfBUSCQ (ORCPT ); Thu, 21 Feb 2019 13:02:16 -0500 Received: by mail-pl1-f194.google.com with SMTP id m10so4871861plt.10 for ; Thu, 21 Feb 2019 10:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PeqFFH3h+tDxxmf6wO89vFB66nJlx2IbTP5RA/EyJrs=; b=jivddJHT7LNHcDi4zc24WX2LtfZPDKjtMVbYO/PibGINzbf1gkQ6dHiOlagw9WS8xh ptngtEulxtOv//jXwfyRw0O56eLroM4sLDw5rxUKi4z3dgHyKDiSPa1MoTM2dzg+d/+e AAA9PoywtGobJ1HC2Yfc0S29WPg2K1t7eTVXM2jxAn4YC888NRd+xL08i7HgZXLEdrrg nUchU55chBzW5K/Zs4c1cZ+pbT3Ru9Ob6YhHUAbwxOW1uakf9WStGpZcmfl1Qyyydraz IgoPYji/JOeoWnqQWttc007QtQehn77NZWP4xxDDoLALiDsrlgY3wtQ/BOKHzwvkJZ7f bmhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PeqFFH3h+tDxxmf6wO89vFB66nJlx2IbTP5RA/EyJrs=; b=Xfcr4hDkN6wXj7qul0jO8x4N1XHv9sEz6Jn7V50fo5cQ01B0IqEEd84Oe/10GtbSd3 XgnWnxal0P5qDmb52sWY3F9ssd4uXyNzwB43ubWRBvE2hJXVruY7rii+DJadm1BDdTJ1 G5rq30+EWH2hEJFc2PVzq726H0Vvgp4xhgG2CtJWvmrg5no4FPhfcjXzlW2qzwExLWBP aq8S1xo1k36l2NkabeyCggQtAhpEsb20GS8P/QOw87O/o2zLlMjHzycIVcgDnMiRlg1M t6ncEOWStzZ9BBRjizQ42zz8Gb3Z/av83s6OjvEbTHGLSUXU2JXaFki9/zjmkQS3TrYV nvQg== X-Gm-Message-State: AHQUAuYxZ55nvPwrEElfNneaI4PZnDfcSlV6QxliEEyP6+Hwu/HKTAQ6 odeFNxi1SmtYPRx2BBzrLMXpIA== X-Google-Smtp-Source: AHgI3IZPm5Um7cSy8Kwn+n4pyxNCv9LxdNr9W5xd+soJldA2vq/81EAXf2xPffRhnrgJ0guLvNbFcQ== X-Received: by 2002:a17:902:f83:: with SMTP id 3mr38605961plz.125.1550772136045; Thu, 21 Feb 2019 10:02:16 -0800 (PST) Received: from shemminger-XPS-13-9360 (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id k26sm37802802pfb.87.2019.02.21.10.02.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Feb 2019 10:02:15 -0800 (PST) Date: Thu, 21 Feb 2019 10:02:11 -0800 From: Stephen Hemminger To: Aya Levin Cc: David Ahern , netdev@vger.kernel.org, Jiri Pirko , Moshe Shemesh , Eran Ben Elisha Subject: Re: [PATCH v2 iproute2-next 04/11] devlink: Add helper functions for name and value separately Message-ID: <20190221100211.28cef41a@shemminger-XPS-13-9360> In-Reply-To: <1550756567-18227-5-git-send-email-ayal@mellanox.com> References: <1550756567-18227-1-git-send-email-ayal@mellanox.com> <1550756567-18227-5-git-send-email-ayal@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, 21 Feb 2019 15:42:40 +0200 Aya Levin wrote: > 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) { NAK Please convert devlink to use existing iproute2 json_print infrasructure rather than reinventing it.