diff mbox series

[iproute2,2/3] tc: jsonify tbf qdisc parameters

Message ID 20190506161840.30919-3-nir.weiner@oracle.com
State Changes Requested
Delegated to: David Ahern
Headers show
Series Adding json support for showing htb&tbf classes | expand

Commit Message

Nir Weiner May 6, 2019, 4:18 p.m. UTC
Add json output to tbf qdisc parameters.

Acked-by: John Haxby <john.haxby@oracle.com>
Signed-off-by: Nir Weiner <nir.weiner@oracle.com>
Suggested-by: Liran Alon <liran.alon@oracle.com>
---
 tc/q_tbf.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

David Ahern May 17, 2019, 5:35 p.m. UTC | #1
On 5/6/19 10:18 AM, Nir Weiner wrote:

>  	if (prate64) {
> -		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
> +		print_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
>  		if (qopt->mtu || qopt->peakrate.mpu) {
>  			mtu = tc_calc_xmitsize(prate64, qopt->mtu);
>  			if (show_details) {
>  				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
>  					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));


The fprintf under show_details should be converted as well. This applies
to patch 1 as well.

And, please add example output to each patch.
Stephen Hemminger May 17, 2019, 5:57 p.m. UTC | #2
On Fri, 17 May 2019 11:35:16 -0600
David Ahern <dsahern@gmail.com> wrote:

> On 5/6/19 10:18 AM, Nir Weiner wrote:
> 
> >  	if (prate64) {
> > -		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
> > +		print_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
> >  		if (qopt->mtu || qopt->peakrate.mpu) {
> >  			mtu = tc_calc_xmitsize(prate64, qopt->mtu);
> >  			if (show_details) {
> >  				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
> >  					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));  
> 
> 
> The fprintf under show_details should be converted as well. This applies
> to patch 1 as well.
> 
> And, please add example output to each patch.

One trick I used was scanning for all calls to fprintf(f and replacing them
diff mbox series

Patch

diff --git a/tc/q_tbf.c b/tc/q_tbf.c
index b9465b20d2be..fd824e67e4f2 100644
--- a/tc/q_tbf.c
+++ b/tc/q_tbf.c
@@ -285,32 +285,32 @@  static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 	if (tb[TCA_TBF_RATE64] &&
 	    RTA_PAYLOAD(tb[TCA_TBF_RATE64]) >= sizeof(rate64))
 		rate64 = rta_getattr_u64(tb[TCA_TBF_RATE64]);
-	fprintf(f, "rate %s ", sprint_rate(rate64, b1));
+	print_string(PRINT_ANY, "rate", "rate %s ", sprint_rate(rate64, b1));
 	buffer = tc_calc_xmitsize(rate64, qopt->buffer);
 	if (show_details) {
 		fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
 			1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2));
 	} else {
-		fprintf(f, "burst %s ", sprint_size(buffer, b1));
+		print_string(PRINT_ANY, "burst", "burst %s ", sprint_size(buffer, b1));
 	}
 	if (show_raw)
-		fprintf(f, "[%08x] ", qopt->buffer);
+		print_0xhex(PRINT_ANY, "buffer", "[%08x] ", qopt->buffer);
 	prate64 = qopt->peakrate.rate;
 	if (tb[TCA_TBF_PRATE64] &&
 	    RTA_PAYLOAD(tb[TCA_TBF_PRATE64]) >= sizeof(prate64))
 		prate64 = rta_getattr_u64(tb[TCA_TBF_PRATE64]);
 	if (prate64) {
-		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
+		print_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
 		if (qopt->mtu || qopt->peakrate.mpu) {
 			mtu = tc_calc_xmitsize(prate64, qopt->mtu);
 			if (show_details) {
 				fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
 					1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));
 			} else {
-				fprintf(f, "minburst %s ", sprint_size(mtu, b1));
+				print_string(PRINT_ANY, "minburst", "minburst %s ", sprint_size(mtu, b1));
 			}
 			if (show_raw)
-				fprintf(f, "[%08x] ", qopt->mtu);
+				print_0xhex(PRINT_ANY, "mtu", "[%08x] ", qopt->mtu);
 		}
 	}
 
@@ -322,16 +322,16 @@  static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 			latency = lat2;
 	}
 	if (latency >= 0.0)
-		fprintf(f, "lat %s ", sprint_time(latency, b1));
+		print_string(PRINT_ANY, "lat", "lat %s ", sprint_time(latency, b1));
 	if (show_raw || latency < 0.0)
-		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));
+		print_string(PRINT_ANY, "limit", "limit %s ", sprint_size(qopt->limit, b1));
 
 	if (qopt->rate.overhead) {
-		fprintf(f, "overhead %d", qopt->rate.overhead);
+		print_int(PRINT_ANY, "overhead", "overhead %d", qopt->rate.overhead);
 	}
 	linklayer = (qopt->rate.linklayer & TC_LINKLAYER_MASK);
 	if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
-		fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b3));
+		print_string(PRINT_ANY, "linklayer", "linklayer %s ", sprint_linklayer(linklayer, b3));
 
 	return 0;
 }