etf: make printing of variable JSON friendly
Subsystems (2)
PATCH 1/1 etf: make printing of variable JSON friendly
In iproute2 txtime-assist series, it was pointed out that print_bool() should be used to print binary values. This is to make it JSON friendly.
So, make the corresponding changes in ETF.
--- tc/q_etf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tc/q_etf.c +6 -6
@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check %s" , - (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) ?"on" :"off" ); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);return 0 ; }
Signature · 1 line
2.7.3
Quoted 25 lines · On Fri, 19 Jul 2019 14:40:43 -0700 Vedang Patel <[email protected]> wrote:
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>--- tc/q_etf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +0
-5@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); - print_string(PRINT_ANY, "skip_sock_check", "skip_sock_check %s",
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 10 lines
tc/q_etf.c +6
-1- (qopt->flags & TC_ETF_SKIP_SOCK_CHECK) ? "on" : "off"); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);return 0 ; }
Thanks, but if you are only going to print json boolean if true, then a common way to indicate that something is enabled is to use print_null().
Could you do that instead?
Quoted 26 lines · Vedang Patel
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>--- tc/q_etf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +0
-5@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); - print_string(PRINT_ANY, "skip_sock_check", "skip_sock_check %s",
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 10 lines
tc/q_etf.c +6
-1- (qopt->flags & TC_ETF_SKIP_SOCK_CHECK) ? "on" : "off"); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);return 0 ; }
This changes existing output for TC_ETF_OFFLOAD_ON and TC_ETF_DEADLINE_MODE_ON which were added a year ago.
Quoted 38 lines · David Ahern
Quoted 33 lines · Vedang Patel
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>---
tc/q_etf.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +6
-6@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check %s" , - (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) ?"on" :"off" ); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);
Quoted 6 lines
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 3 lines
tc/q_etf.c +0
-0return 0 ; }This changes existing output for
TC_ETF_OFFLOAD_ONandTC_ETF_DEADLINE_MODE_ONwhich were added a year ago.
Yes, this is a good point. I missed that.
Another idea is to use is_json_context() and call print_bool() there. But, that will still change values corresponding to the json output for the above flags from “on”/“off” to “true”/“false”. I am not sure if this is a big issue.
My suggestion is to keep the code as is. what do you think?
Thanks,
Vedang
Quoted 44 lines · Vedang
Quoted 38 lines · David Ahern
Quoted 33 lines · Vedang Patel
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>---
tc/q_etf.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +6
-6@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check %s" , - (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) ?"on" :"off" ); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);Quoted 6 lines
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 3 lines
tc/q_etf.c +0
-0return 0 ; }This changes existing output for
TC_ETF_OFFLOAD_ONandTC_ETF_DEADLINE_MODE_ONwhich were added a year ago.
Quoted 6 lines
Yes, this is a good point. I missed that.
Another idea is to use
is_json_context()and callprint_bool()there. But, that will still change values corresponding to the json output for the above flags from “on”/“off” to “true”/“false”. I am not sure if this is a big issue.My suggestion is to keep the code as is. what do you think?
I think we need automated checkers for new code. ;-)
The first 2 should not change for backward compatibility - unless there is agreement that this feature is too new and long term it is better to print as above.
Then the new one should follow context of the other 2 - consistency IMHO takes precedence.
Quoted 56 lines · David Ahern
Quoted 44 lines · Vedang
Quoted 38 lines · David Ahern
Quoted 33 lines · Vedang Patel
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>---
tc/q_etf.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +6
-6@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check %s" , - (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) ?"on" :"off" ); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);Quoted 6 lines
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 3 lines
tc/q_etf.c +0
-0return 0 ; }This changes existing output for
TC_ETF_OFFLOAD_ONandTC_ETF_DEADLINE_MODE_ONwhich were added a year ago.Quoted 6 lines
Yes, this is a good point. I missed that.
Another idea is to use
is_json_context()and callprint_bool()there. But, that will still change values corresponding to the json output for the above flags from “on”/“off” to “true”/“false”. I am not sure if this is a big issue.My suggestion is to keep the code as is. what do you think?
Quoted 8 lines
I think we need automated checkers for new code. ;-)
The first 2 should not change for backward compatibility - unless there is agreement that this feature is too new and long term it is better to print as above.
Then the new one should follow context of the other 2 - consistency IMHO takes precedence.
Thanks for the inputs.
Let’s keep whatever is currently present upstream and you can ignore this patch.
Thanks,
Vedang
Quoted 60 lines · Vedang
Quoted 60 lines · David Ahern
Quoted 44 lines · Vedang
Quoted 38 lines · David Ahern
Quoted 33 lines · Vedang Patel
In iproute2 txtime-assist series, it was pointed out that
print_bool()should be used to print binary values. This is to make it JSON friendly.So, make the corresponding changes in ETF.
Fixes 8ccd49383cdc ("etf: Add skip_sock_check")Reported-by Stephen Hemminger <[email protected]>Signed-off-by Vedang Patel <[email protected]>---
tc/q_etf.c| 12 ++++++------1 file changed, 6 insertions(+), 6 deletions(-)tc/q_etf.c +6
-6@@ -176,12 +176,12 @@ static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) get_clock_name(qopt->clockid));print_uint (PRINT_ANY ,"delta" ,"delta %d " , qopt->delta); -print_string (PRINT_ANY ,"offload" ,"offload %s " , - (qopt->flags &TC_ETF_OFFLOAD_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"deadline_mode" ,"deadline_mode %s " , - (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) ?"on" :"off" ); -print_string (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check %s" , - (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) ?"on" :"off" ); +if (qopt->flags &TC_ETF_OFFLOAD_ON ) +print_bool (PRINT_ANY ,"offload" ,"offload " , true); +if (qopt->flags &TC_ETF_DEADLINE_MODE_ON ) +print_bool (PRINT_ANY ,"deadline_mode" ,"deadline_mode " , true); +if (qopt->flags &TC_ETF_SKIP_SOCK_CHECK ) +print_bool (PRINT_ANY ,"skip_sock_check" ,"skip_sock_check" , true);Quoted 6 lines
tc/q_etf.c static int etf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 187
Quoted 3 lines
tc/q_etf.c +0
-0return 0 ; }This changes existing output for
TC_ETF_OFFLOAD_ONandTC_ETF_DEADLINE_MODE_ONwhich were added a year ago.Quoted 6 lines
Yes, this is a good point. I missed that.
Another idea is to use
is_json_context()and callprint_bool()there. But, that will still change values corresponding to the json output for the above flags from “on”/“off” to “true”/“false”. I am not sure if this is a big issue.My suggestion is to keep the code as is. what do you think?
I think we need automated checkers for new code. ;-)
The first 2 should not change for backward compatibility - unless there is agreement that this feature is too new and long term it is better to print as above.
Quoted 8 lines
Quoted 2 lines
Then the new one should follow context of the other 2 - consistency IMHO takes precedence.
Thanks for the inputs.
Let’s keep whatever is currently present upstream and you can ignore this patch.
Thanks,
Vedang
Agreed. At this point consistency is better.
Maybe at some future point, all the JSON will be reviewed and fixed (yes it would be a breaking flag day). But for now inconsistent usage across ip, tc, and devlink is a fact of life.