From: Maxim Georgiev <glipus@gmail.com>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, kuba@kernel.org, glipus@gmail.com
Subject: [PATCH ethtool-next] JSON output support for Netlink implementation of --show-ring option
Date: Tue, 27 Dec 2022 10:52:21 -0700 [thread overview]
Message-ID: <20221227175221.7762-1-glipus@gmail.com> (raw)
Add --json support for Netlink implementation of --show-ring option
No changes for non-JSON output for this featire.
Example output without --json:
[ethtool-git]$ /ethtool -g enp9s0u2u1u2
Ring parameters for enp9s0u2u1u2:
Pre-set maximums:
RX: 4096
RX Mini: n/a
RX Jumbo: n/a
TX: n/a
Current hardware settings:
RX: 100
RX Mini: n/a
RX Jumbo: n/a
TX: n/a
RX Buf Len: n/a
CQE Size: n/a
TX Push: off
TCP data split: n/a
Same output with --json:
[ethtool-git]$ ./ethtool --json -g enp9s0u2u1u2
[ {
"ifname": "enp9s0u2u1u2",
"rx-max": 4096,
"rx": 100,
"tx-push": false
} ]
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maxim Georgiev <glipus@gmail.com>
---
ethtool.c | 1 +
netlink/rings.c | 35 +++++++++++++++++++++++++----------
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index 60da8af..cf08a69 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5751,6 +5751,7 @@ static const struct option args[] = {
},
{
.opts = "-g|--show-ring",
+ .json = true,
.func = do_gring,
.nlfunc = nl_gring,
.help = "Query RX/TX ring parameters"
diff --git a/netlink/rings.c b/netlink/rings.c
index 5996d5a..d51ef78 100644
--- a/netlink/rings.c
+++ b/netlink/rings.c
@@ -21,6 +21,9 @@ int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data)
DECLARE_ATTR_TB_INFO(tb);
struct nl_context *nlctx = data;
unsigned char tcp_hds;
+ char *tcp_hds_fmt;
+ char *tcp_hds_key;
+ char tcp_hds_buf[256];
bool silent;
int err_ret;
int ret;
@@ -34,16 +37,19 @@ int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data)
if (!dev_ok(nlctx))
return err_ret;
+ open_json_object(NULL);
+
if (silent)
- putchar('\n');
- printf("Ring parameters for %s:\n", nlctx->devname);
- printf("Pre-set maximums:\n");
+ show_cr();
+ print_string(PRINT_ANY, "ifname", "Ring parameters for %s:\n",
+ nlctx->devname);
+ print_string(PRINT_FP, NULL, "Pre-set maximums:\n", NULL);
show_u32("rx-max", "RX:\t\t", tb[ETHTOOL_A_RINGS_RX_MAX]);
show_u32("rx-mini-max", "RX Mini:\t", tb[ETHTOOL_A_RINGS_RX_MINI_MAX]);
show_u32("rx-jumbo-max", "RX Jumbo:\t",
tb[ETHTOOL_A_RINGS_RX_JUMBO_MAX]);
show_u32("tx-max", "TX:\t\t", tb[ETHTOOL_A_RINGS_TX_MAX]);
- printf("Current hardware settings:\n");
+ print_string(PRINT_FP, NULL, "Current hardware settings:\n", NULL);
show_u32("rx", "RX:\t\t", tb[ETHTOOL_A_RINGS_RX]);
show_u32("rx-mini", "RX Mini:\t", tb[ETHTOOL_A_RINGS_RX_MINI]);
show_u32("rx-jumbo", "RX Jumbo:\t", tb[ETHTOOL_A_RINGS_RX_JUMBO]);
@@ -52,24 +58,29 @@ int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data)
show_u32("cqe-size", "CQE Size:\t", tb[ETHTOOL_A_RINGS_CQE_SIZE]);
show_bool("tx-push", "TX Push:\t%s\n", tb[ETHTOOL_A_RINGS_TX_PUSH]);
+ tcp_hds_fmt = "TCP data split:\t%s\n";
+ tcp_hds_key = "tcp-data-split";
tcp_hds = tb[ETHTOOL_A_RINGS_TCP_DATA_SPLIT] ?
mnl_attr_get_u8(tb[ETHTOOL_A_RINGS_TCP_DATA_SPLIT]) : 0;
- printf("TCP data split:\t");
switch (tcp_hds) {
case ETHTOOL_TCP_DATA_SPLIT_UNKNOWN:
- printf("n/a\n");
+ print_string(PRINT_FP, tcp_hds_key, tcp_hds_fmt, "n/a");
break;
case ETHTOOL_TCP_DATA_SPLIT_DISABLED:
- printf("off\n");
+ print_string(PRINT_ANY, tcp_hds_key, tcp_hds_fmt, "off");
break;
case ETHTOOL_TCP_DATA_SPLIT_ENABLED:
- printf("on\n");
+ print_string(PRINT_ANY, tcp_hds_key, tcp_hds_fmt, "on");
break;
default:
- printf("unknown(%d)\n", tcp_hds);
+ snprintf(tcp_hds_buf, sizeof(tcp_hds_buf),
+ "unknown(%d)\n", tcp_hds);
+ print_string(PRINT_ANY, tcp_hds_key, tcp_hds_fmt, tcp_hds_buf);
break;
}
+ close_json_object();
+
return MNL_CB_OK;
}
@@ -91,7 +102,11 @@ int nl_gring(struct cmd_context *ctx)
ETHTOOL_A_RINGS_HEADER, 0);
if (ret < 0)
return ret;
- return nlsock_send_get_request(nlsk, rings_reply_cb);
+
+ new_json_obj(ctx->json);
+ ret = nlsock_send_get_request(nlsk, rings_reply_cb);
+ delete_json_obj();
+ return ret;
}
/* RINGS_SET */
--
2.38.1
reply other threads:[~2022-12-27 17:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221227175221.7762-1-glipus@gmail.com \
--to=glipus@gmail.com \
--cc=kuba@kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).