|
|
32391d |
From e3610d3ea2c8d88c3dd61d845a682f74a1af1d1f Mon Sep 17 00:00:00 2001
|
|
|
32391d |
Message-Id: <e3610d3ea2c8d88c3dd61d845a682f74a1af1d1f.1643220552.git.aclaudi@redhat.com>
|
|
|
32391d |
In-Reply-To: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1643220552.git.aclaudi@redhat.com>
|
|
|
32391d |
References: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1643220552.git.aclaudi@redhat.com>
|
|
|
32391d |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
32391d |
Date: Wed, 26 Jan 2022 10:39:38 +0100
|
|
|
32391d |
Subject: [PATCH] vdpa: Enable user to query vdpa device config layout
|
|
|
32391d |
|
|
|
32391d |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2036880
|
|
|
32391d |
Upstream Status: iproute2.git commit a311f0c4
|
|
|
32391d |
|
|
|
32391d |
commit a311f0c43a67be939dfafda563453a3f9bf30e42
|
|
|
32391d |
Author: Parav Pandit <parav@nvidia.com>
|
|
|
32391d |
Date: Fri Dec 17 10:08:25 2021 +0200
|
|
|
32391d |
|
|
|
32391d |
vdpa: Enable user to query vdpa device config layout
|
|
|
32391d |
|
|
|
32391d |
Query the device configuration layout whenever kernel supports it.
|
|
|
32391d |
|
|
|
32391d |
An example of configuration layout of vdpa device of type network:
|
|
|
32391d |
|
|
|
32391d |
$ vdpa dev add name bar mgmtdev vdpasim_net
|
|
|
32391d |
|
|
|
32391d |
$ vdpa dev config show
|
|
|
32391d |
bar: mac 00:35:09:19:48:05 link up link_announce false mtu 1500
|
|
|
32391d |
|
|
|
32391d |
$ vdpa dev config show -jp
|
|
|
32391d |
{
|
|
|
32391d |
"config": {
|
|
|
32391d |
"bar": {
|
|
|
32391d |
"mac": "00:35:09:19:48:05",
|
|
|
32391d |
"link ": "up",
|
|
|
32391d |
"link_announce ": false,
|
|
|
32391d |
"mtu": 1500,
|
|
|
32391d |
}
|
|
|
32391d |
}
|
|
|
32391d |
}
|
|
|
32391d |
|
|
|
32391d |
Signed-off-by: Parav Pandit <parav@nvidia.com>
|
|
|
32391d |
Signed-off-by: David Ahern <dsahern@kernel.org>
|
|
|
32391d |
---
|
|
|
32391d |
man/man8/vdpa-dev.8 | 21 +++++++++
|
|
|
32391d |
vdpa/vdpa.c | 110 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
32391d |
2 files changed, 131 insertions(+)
|
|
|
32391d |
|
|
|
32391d |
diff --git a/man/man8/vdpa-dev.8 b/man/man8/vdpa-dev.8
|
|
|
32391d |
index 36433519..5d3a3f26 100644
|
|
|
32391d |
--- a/man/man8/vdpa-dev.8
|
|
|
32391d |
+++ b/man/man8/vdpa-dev.8
|
|
|
32391d |
@@ -36,6 +36,10 @@ vdpa-dev \- vdpa device configuration
|
|
|
32391d |
.B vdpa dev del
|
|
|
32391d |
.I DEV
|
|
|
32391d |
|
|
|
32391d |
+.ti -8
|
|
|
32391d |
+.B vdpa dev config show
|
|
|
32391d |
+.RI "[ " DEV " ]"
|
|
|
32391d |
+
|
|
|
32391d |
.SH "DESCRIPTION"
|
|
|
32391d |
.SS vdpa dev show - display vdpa device attributes
|
|
|
32391d |
|
|
|
32391d |
@@ -65,6 +69,18 @@ Name of the management device to use for device addition.
|
|
|
32391d |
.I "DEV"
|
|
|
32391d |
- specifies the vdpa device to delete.
|
|
|
32391d |
|
|
|
32391d |
+.SS vdpa dev config show - Show configuration of specific device or all devices.
|
|
|
32391d |
+
|
|
|
32391d |
+.PP
|
|
|
32391d |
+.I "DEV"
|
|
|
32391d |
+- specifies the vdpa device to show its configuration.
|
|
|
32391d |
+If this argument is omitted all devices configuration is listed.
|
|
|
32391d |
+
|
|
|
32391d |
+.in +4
|
|
|
32391d |
+Format is:
|
|
|
32391d |
+.in +2
|
|
|
32391d |
+VDPA_DEVICE_NAME
|
|
|
32391d |
+
|
|
|
32391d |
.SH "EXAMPLES"
|
|
|
32391d |
.PP
|
|
|
32391d |
vdpa dev show
|
|
|
32391d |
@@ -86,6 +102,11 @@ vdpa dev del foo
|
|
|
32391d |
.RS 4
|
|
|
32391d |
Delete the vdpa device named foo which was previously created.
|
|
|
32391d |
.RE
|
|
|
32391d |
+.PP
|
|
|
32391d |
+vdpa dev config show foo
|
|
|
32391d |
+.RS 4
|
|
|
32391d |
+Shows the vdpa device configuration of device named foo.
|
|
|
32391d |
+.RE
|
|
|
32391d |
|
|
|
32391d |
.SH SEE ALSO
|
|
|
32391d |
.BR vdpa (8),
|
|
|
32391d |
diff --git a/vdpa/vdpa.c b/vdpa/vdpa.c
|
|
|
32391d |
index 7fdb36b9..ba704254 100644
|
|
|
32391d |
--- a/vdpa/vdpa.c
|
|
|
32391d |
+++ b/vdpa/vdpa.c
|
|
|
32391d |
@@ -6,9 +6,11 @@
|
|
|
32391d |
#include <linux/genetlink.h>
|
|
|
32391d |
#include <linux/vdpa.h>
|
|
|
32391d |
#include <linux/virtio_ids.h>
|
|
|
32391d |
+#include <linux/virtio_net.h>
|
|
|
32391d |
#include <linux/netlink.h>
|
|
|
32391d |
#include <libmnl/libmnl.h>
|
|
|
32391d |
#include "mnl_utils.h"
|
|
|
32391d |
+#include <rt_names.h>
|
|
|
32391d |
|
|
|
32391d |
#include "version.h"
|
|
|
32391d |
#include "json_print.h"
|
|
|
32391d |
@@ -413,6 +415,7 @@ static void cmd_dev_help(void)
|
|
|
32391d |
fprintf(stderr, "Usage: vdpa dev show [ DEV ]\n");
|
|
|
32391d |
fprintf(stderr, " vdpa dev add name NAME mgmtdev MANAGEMENTDEV\n");
|
|
|
32391d |
fprintf(stderr, " vdpa dev del DEV\n");
|
|
|
32391d |
+ fprintf(stderr, "Usage: vdpa dev config COMMAND [ OPTIONS ]\n");
|
|
|
32391d |
}
|
|
|
32391d |
|
|
|
32391d |
static const char *device_type_name(uint32_t type)
|
|
|
32391d |
@@ -520,6 +523,111 @@ static int cmd_dev_del(struct vdpa *vdpa, int argc, char **argv)
|
|
|
32391d |
return mnlu_gen_socket_sndrcv(&vdpa->nlg, nlh, NULL, NULL);
|
|
|
32391d |
}
|
|
|
32391d |
|
|
|
32391d |
+static void pr_out_dev_net_config(struct nlattr **tb)
|
|
|
32391d |
+{
|
|
|
32391d |
+ SPRINT_BUF(macaddr);
|
|
|
32391d |
+ uint16_t val_u16;
|
|
|
32391d |
+
|
|
|
32391d |
+ if (tb[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
|
|
|
32391d |
+ const unsigned char *data;
|
|
|
32391d |
+ uint16_t len;
|
|
|
32391d |
+
|
|
|
32391d |
+ len = mnl_attr_get_payload_len(tb[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
|
|
|
32391d |
+ data = mnl_attr_get_payload(tb[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
|
|
|
32391d |
+
|
|
|
32391d |
+ print_string(PRINT_ANY, "mac", "mac %s ",
|
|
|
32391d |
+ ll_addr_n2a(data, len, 0, macaddr, sizeof(macaddr)));
|
|
|
32391d |
+ }
|
|
|
32391d |
+ if (tb[VDPA_ATTR_DEV_NET_STATUS]) {
|
|
|
32391d |
+ val_u16 = mnl_attr_get_u16(tb[VDPA_ATTR_DEV_NET_STATUS]);
|
|
|
32391d |
+ print_string(PRINT_ANY, "link ", "link %s ",
|
|
|
32391d |
+ (val_u16 & VIRTIO_NET_S_LINK_UP) ? "up" : "down");
|
|
|
32391d |
+ print_bool(PRINT_ANY, "link_announce ", "link_announce %s ",
|
|
|
32391d |
+ (val_u16 & VIRTIO_NET_S_ANNOUNCE) ? true : false);
|
|
|
32391d |
+ }
|
|
|
32391d |
+ if (tb[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]) {
|
|
|
32391d |
+ val_u16 = mnl_attr_get_u16(tb[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]);
|
|
|
32391d |
+ print_uint(PRINT_ANY, "max_vq_pairs", "max_vq_pairs %d ",
|
|
|
32391d |
+ val_u16);
|
|
|
32391d |
+ }
|
|
|
32391d |
+ if (tb[VDPA_ATTR_DEV_NET_CFG_MTU]) {
|
|
|
32391d |
+ val_u16 = mnl_attr_get_u16(tb[VDPA_ATTR_DEV_NET_CFG_MTU]);
|
|
|
32391d |
+ print_uint(PRINT_ANY, "mtu", "mtu %d ", val_u16);
|
|
|
32391d |
+ }
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
+static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)
|
|
|
32391d |
+{
|
|
|
32391d |
+ uint32_t device_id = mnl_attr_get_u32(tb[VDPA_ATTR_DEV_ID]);
|
|
|
32391d |
+
|
|
|
32391d |
+ pr_out_vdev_handle_start(vdpa, tb);
|
|
|
32391d |
+ switch (device_id) {
|
|
|
32391d |
+ case VIRTIO_ID_NET:
|
|
|
32391d |
+ pr_out_dev_net_config(tb);
|
|
|
32391d |
+ break;
|
|
|
32391d |
+ default:
|
|
|
32391d |
+ break;
|
|
|
32391d |
+ }
|
|
|
32391d |
+ pr_out_vdev_handle_end(vdpa);
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
+static int cmd_dev_config_show_cb(const struct nlmsghdr *nlh, void *data)
|
|
|
32391d |
+{
|
|
|
32391d |
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
|
|
|
32391d |
+ struct nlattr *tb[VDPA_ATTR_MAX + 1] = {};
|
|
|
32391d |
+ struct vdpa *vdpa = data;
|
|
|
32391d |
+
|
|
|
32391d |
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
|
|
|
32391d |
+ if (!tb[VDPA_ATTR_DEV_NAME] || !tb[VDPA_ATTR_DEV_ID])
|
|
|
32391d |
+ return MNL_CB_ERROR;
|
|
|
32391d |
+ pr_out_dev_config(vdpa, tb);
|
|
|
32391d |
+ return MNL_CB_OK;
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
+static int cmd_dev_config_show(struct vdpa *vdpa, int argc, char **argv)
|
|
|
32391d |
+{
|
|
|
32391d |
+ uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
|
|
|
32391d |
+ struct nlmsghdr *nlh;
|
|
|
32391d |
+ int err;
|
|
|
32391d |
+
|
|
|
32391d |
+ if (argc <= 0)
|
|
|
32391d |
+ flags |= NLM_F_DUMP;
|
|
|
32391d |
+
|
|
|
32391d |
+ nlh = mnlu_gen_socket_cmd_prepare(&vdpa->nlg, VDPA_CMD_DEV_CONFIG_GET,
|
|
|
32391d |
+ flags);
|
|
|
32391d |
+ if (argc > 0) {
|
|
|
32391d |
+ err = vdpa_argv_parse_put(nlh, vdpa, argc, argv,
|
|
|
32391d |
+ VDPA_OPT_VDEV_HANDLE);
|
|
|
32391d |
+ if (err)
|
|
|
32391d |
+ return err;
|
|
|
32391d |
+ }
|
|
|
32391d |
+
|
|
|
32391d |
+ pr_out_section_start(vdpa, "config");
|
|
|
32391d |
+ err = mnlu_gen_socket_sndrcv(&vdpa->nlg, nlh, cmd_dev_config_show_cb, vdpa);
|
|
|
32391d |
+ pr_out_section_end(vdpa);
|
|
|
32391d |
+ return err;
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
+static void cmd_dev_config_help(void)
|
|
|
32391d |
+{
|
|
|
32391d |
+ fprintf(stderr, "Usage: vdpa dev config show [ DEV ]\n");
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
+static int cmd_dev_config(struct vdpa *vdpa, int argc, char **argv)
|
|
|
32391d |
+{
|
|
|
32391d |
+ if (!argc)
|
|
|
32391d |
+ return cmd_dev_config_show(vdpa, argc - 1, argv + 1);
|
|
|
32391d |
+
|
|
|
32391d |
+ if (matches(*argv, "help") == 0) {
|
|
|
32391d |
+ cmd_dev_config_help();
|
|
|
32391d |
+ return 0;
|
|
|
32391d |
+ } else if (matches(*argv, "show") == 0) {
|
|
|
32391d |
+ return cmd_dev_config_show(vdpa, argc - 1, argv + 1);
|
|
|
32391d |
+ }
|
|
|
32391d |
+ fprintf(stderr, "Command \"%s\" not found\n", *argv);
|
|
|
32391d |
+ return -ENOENT;
|
|
|
32391d |
+}
|
|
|
32391d |
+
|
|
|
32391d |
static int cmd_dev(struct vdpa *vdpa, int argc, char **argv)
|
|
|
32391d |
{
|
|
|
32391d |
if (!argc)
|
|
|
32391d |
@@ -535,6 +643,8 @@ static int cmd_dev(struct vdpa *vdpa, int argc, char **argv)
|
|
|
32391d |
return cmd_dev_add(vdpa, argc - 1, argv + 1);
|
|
|
32391d |
} else if (matches(*argv, "del") == 0) {
|
|
|
32391d |
return cmd_dev_del(vdpa, argc - 1, argv + 1);
|
|
|
32391d |
+ } else if (matches(*argv, "config") == 0) {
|
|
|
32391d |
+ return cmd_dev_config(vdpa, argc - 1, argv + 1);
|
|
|
32391d |
}
|
|
|
32391d |
fprintf(stderr, "Command \"%s\" not found\n", *argv);
|
|
|
32391d |
return -ENOENT;
|
|
|
32391d |
--
|
|
|
32391d |
2.34.1
|
|
|
32391d |
|