public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Petr Machata <me@pmachata•org>
To: Leon Romanovsky <leon@kernel•org>
Cc: David Ahern <dsahern@gmail•com>,
	netdev@vger•kernel.org, stephen@networkplumber•org,
	john.fastabend@gmail•com, jiri@nvidia•com, idosch@nvidia•com,
	Jakub Kicinski <kuba@kernel•org>, Roman Mashak <mrv@mojatatu•com>
Subject: Re: [PATCH iproute2-next v2 03/11] lib: utils: Add print_on_off_bool()
Date: Tue, 03 Nov 2020 00:05:20 +0100	[thread overview]
Message-ID: <87h7q7iclr.fsf@nvidia.com> (raw)
In-Reply-To: <20201102063752.GE5429@unreal>


Leon Romanovsky <leon@kernel•org> writes:

> On Sun, Nov 01, 2020 at 04:55:42PM -0700, David Ahern wrote:
>> On 10/31/20 3:23 PM, Petr Machata wrote:
>> >
>> > David Ahern <dsahern@gmail•com> writes:
>> >
>> >> On 10/30/20 6:29 AM, Petr Machata wrote:
>> >>> diff --git a/lib/utils.c b/lib/utils.c
>> >>> index 930877ae0f0d..8deec86ecbcd 100644
>> >>> --- a/lib/utils.c
>> >>> +++ b/lib/utils.c
>> >>> @@ -1763,3 +1763,11 @@ int parse_on_off(const char *msg, const char *realval, int *p_err)
>> >>>
>> >>>  	return parse_one_of(msg, realval, values_on_off, ARRAY_SIZE(values_on_off), p_err);
>> >>>  }
>> >>> +
>> >>> +void print_on_off_bool(FILE *fp, const char *flag, bool val)
>> >>> +{
>> >>> +	if (is_json_context())
>> >>> +		print_bool(PRINT_JSON, flag, NULL, val);
>> >>> +	else
>> >>> +		fprintf(fp, "%s %s ", flag, val ? "on" : "off");
>> >>> +}
>> >>>
>> >>
>> >> I think print_on_off should be fine and aligns with parse_on_off once it
>> >> returns a bool.
>> >
>> > print_on_off() is already used in the RDMA tool, and actually outputs
>> > "on" and "off", unlike this. So I chose this instead.
>> >
>> > I could rename the RDMA one though -- it's used in two places, whereas
>> > this is used in about two dozen instances across the codebase.
>> >
>>
>> yes, the rdma utils are using generic function names. The rdma version
>> should be renamed; perhaps rd_print_on_off. That seems to be once common
>> prefix. Added Leon.
>
> I made fast experiment and the output for the code proposed here and existed
> in the RDMAtool - result the same. So the good thing will be to delete the
> function from the RDMA after print_on_off_bool() will be improved.

The RDMAtool uses literal "on" and "off" as values in JSON, not
booleans. Moving over to print_on_off_bool() would be a breaking change,
which is problematic especially in JSON output.

> However I don't understand why print_on_off_bool() is implemented in
> utils.c and not in lib/json_print.c that properly handles JSON context,

There's a whole lot of print_X functions for printing non-fundamental
data types in utils.c. Seemed obvious to put it there. I can move it to
json_print.c, no problem.

I think the current function does handle JSON context, what else do
you have in mind?

> provide colorized output and doesn't require to supply FILE *fp.

Stephen Hemminger already pointed out the FILE *fp bit, I'll be removing
it.

  parent reply	other threads:[~2020-11-02 23:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 12:29 [PATCH iproute2-next v2 00/11] Add a tool for configuration of DCB Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 01/11] Unify batch processing across tools Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 02/11] lib: Add parse_one_of(), parse_on_off() Petr Machata
2020-10-31 15:37   ` David Ahern
2020-10-31 21:25     ` Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 03/11] lib: utils: Add print_on_off_bool() Petr Machata
2020-10-30 16:05   ` Stephen Hemminger
2020-10-31 21:24     ` Petr Machata
2020-10-31 15:38   ` David Ahern
2020-10-31 21:23     ` Petr Machata
2020-11-01 23:55       ` David Ahern
2020-11-02  6:37         ` Leon Romanovsky
2020-11-02 15:10           ` David Ahern
2020-11-02 23:05           ` Petr Machata [this message]
2020-11-03  6:24             ` Leon Romanovsky
2020-11-03 21:01               ` Petr Machata
2020-11-04  8:15                 ` Leon Romanovsky
2020-11-05 20:59                   ` Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 04/11] lib: Extract from devlink/mnlg a helper, mnlu_socket_open() Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 05/11] lib: Extract from devlink/mnlg a helper, mnlu_msg_prepare() Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 06/11] lib: Extract from devlink/mnlg a helper, mnlu_socket_recv_run() Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 07/11] lib: Extract from iplink_vlan a helper to parse key:value arrays Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 08/11] lib: parse_mapping: Update argc, argv on error Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 09/11] lib: parse_mapping: Recognize a keyword "all" Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 10/11] Add skeleton of a new tool, dcb Petr Machata
2020-10-30 12:29 ` [PATCH iproute2-next v2 11/11] dcb: Add a subtool for the DCB ETS object Petr Machata
2020-10-31 15:51 ` [PATCH iproute2-next v2 00/11] Add a tool for configuration of DCB David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7q7iclr.fsf@nvidia.com \
    --to=me@pmachata$(echo .)org \
    --cc=dsahern@gmail$(echo .)com \
    --cc=idosch@nvidia$(echo .)com \
    --cc=jiri@nvidia$(echo .)com \
    --cc=john.fastabend@gmail$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=leon@kernel$(echo .)org \
    --cc=mrv@mojatatu$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=stephen@networkplumber$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox