|
|
049c96 |
From 4b03d06db283f11e3301e22e75b714abb7c446df Mon Sep 17 00:00:00 2001
|
|
|
049c96 |
From: Phil Sutter <psutter@redhat.com>
|
|
|
049c96 |
Date: Sat, 9 Jul 2016 11:33:14 +0200
|
|
|
049c96 |
Subject: [PATCH] devlink: split dl_argv_parse_put to parse and put parts
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1342515
|
|
|
049c96 |
Upstream Status: iproute2.git commit 6563a6eb539ba
|
|
|
049c96 |
|
|
|
049c96 |
commit 6563a6eb539ba5c3f9fa262bc302190abb7e5f39
|
|
|
049c96 |
Author: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
Date: Fri Apr 15 09:51:48 2016 +0200
|
|
|
049c96 |
|
|
|
049c96 |
devlink: split dl_argv_parse_put to parse and put parts
|
|
|
049c96 |
|
|
|
049c96 |
It is handy to have parsed cmdline data stored so they can be used for
|
|
|
049c96 |
dumps filtering. So split original dl_argv_parse_put into parse and put
|
|
|
049c96 |
parts.
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
---
|
|
|
049c96 |
devlink/devlink.c | 105 +++++++++++++++++++++++++++++++++++-------------------
|
|
|
049c96 |
1 file changed, 69 insertions(+), 36 deletions(-)
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/devlink/devlink.c b/devlink/devlink.c
|
|
|
049c96 |
index 5e08666..0c2132f 100644
|
|
|
049c96 |
--- a/devlink/devlink.c
|
|
|
049c96 |
+++ b/devlink/devlink.c
|
|
|
049c96 |
@@ -109,12 +109,28 @@ static void ifname_map_free(struct ifname_map *ifname_map)
|
|
|
049c96 |
free(ifname_map);
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
+#define BIT(nr) (1UL << (nr))
|
|
|
049c96 |
+#define DL_OPT_HANDLE BIT(0)
|
|
|
049c96 |
+#define DL_OPT_HANDLEP BIT(1)
|
|
|
049c96 |
+#define DL_OPT_PORT_TYPE BIT(2)
|
|
|
049c96 |
+#define DL_OPT_PORT_COUNT BIT(3)
|
|
|
049c96 |
+
|
|
|
049c96 |
+struct dl_opts {
|
|
|
049c96 |
+ uint32_t present; /* flags of present items */
|
|
|
049c96 |
+ char *bus_name;
|
|
|
049c96 |
+ char *dev_name;
|
|
|
049c96 |
+ uint32_t port_index;
|
|
|
049c96 |
+ enum devlink_port_type port_type;
|
|
|
049c96 |
+ uint32_t port_count;
|
|
|
049c96 |
+};
|
|
|
049c96 |
+
|
|
|
049c96 |
struct dl {
|
|
|
049c96 |
struct mnlg_socket *nlg;
|
|
|
049c96 |
struct list_head ifname_map_list;
|
|
|
049c96 |
int argc;
|
|
|
049c96 |
char **argv;
|
|
|
049c96 |
bool no_nice_names;
|
|
|
049c96 |
+ struct dl_opts opts;
|
|
|
049c96 |
};
|
|
|
049c96 |
|
|
|
049c96 |
static int dl_argc(struct dl *dl)
|
|
|
049c96 |
@@ -347,11 +363,9 @@ static int strtouint32_t(const char *str, uint32_t *p_val)
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
-static int dl_argv_put_handle(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
+static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name)
|
|
|
049c96 |
{
|
|
|
049c96 |
char *str = dl_argv_next(dl);
|
|
|
049c96 |
- char *bus_name = bus_name;
|
|
|
049c96 |
- char *dev_name = dev_name;
|
|
|
049c96 |
|
|
|
049c96 |
if (!str) {
|
|
|
049c96 |
pr_err("Devlink identification (\"bus_name/dev_name\") expected\n");
|
|
|
049c96 |
@@ -363,19 +377,15 @@ static int dl_argv_put_handle(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
return -EINVAL;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
- strslashrsplit(str, &bus_name, &dev_name);
|
|
|
049c96 |
- mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
|
|
|
049c96 |
- mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
|
|
|
049c96 |
+ strslashrsplit(str, p_bus_name, p_dev_name);
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
-static int dl_argv_put_handle_port(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
+static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
|
|
|
049c96 |
+ char **p_dev_name, uint32_t *p_port_index)
|
|
|
049c96 |
{
|
|
|
049c96 |
char *str = dl_argv_next(dl);
|
|
|
049c96 |
unsigned int slash_count;
|
|
|
049c96 |
- char *bus_name = bus_name;
|
|
|
049c96 |
- char *dev_name = dev_name;
|
|
|
049c96 |
- uint32_t port_index = port_index;
|
|
|
049c96 |
int err;
|
|
|
049c96 |
|
|
|
049c96 |
if (!str) {
|
|
|
049c96 |
@@ -394,24 +404,21 @@ static int dl_argv_put_handle_port(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
char *portstr = portstr;
|
|
|
049c96 |
|
|
|
049c96 |
err = strslashrsplit(str, &handlestr, &portstr);
|
|
|
049c96 |
- err = strtouint32_t(portstr, &port_index);
|
|
|
049c96 |
+ err = strtouint32_t(portstr, p_port_index);
|
|
|
049c96 |
if (err) {
|
|
|
049c96 |
pr_err("Port index \"%s\" is not a number or not within range\n",
|
|
|
049c96 |
portstr);
|
|
|
049c96 |
return err;
|
|
|
049c96 |
}
|
|
|
049c96 |
- strslashrsplit(handlestr, &bus_name, &dev_name);
|
|
|
049c96 |
+ strslashrsplit(handlestr, p_bus_name, p_dev_name);
|
|
|
049c96 |
} else if (slash_count == 0) {
|
|
|
049c96 |
- err = ifname_map_lookup(dl, str, &bus_name, &dev_name,
|
|
|
049c96 |
- &port_index);
|
|
|
049c96 |
+ err = ifname_map_lookup(dl, str, p_bus_name, p_dev_name,
|
|
|
049c96 |
+ p_port_index);
|
|
|
049c96 |
if (err) {
|
|
|
049c96 |
pr_err("Netdevice \"%s\" not found\n", str);
|
|
|
049c96 |
return err;
|
|
|
049c96 |
}
|
|
|
049c96 |
}
|
|
|
049c96 |
- mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
|
|
|
049c96 |
- mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
|
|
|
049c96 |
- mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port_index);
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
@@ -460,55 +467,46 @@ static int port_type_get(const char *typestr, enum devlink_port_type *p_type)
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
-#define BIT(nr) (1UL << (nr))
|
|
|
049c96 |
-#define DL_OPT_HANDLE BIT(0)
|
|
|
049c96 |
-#define DL_OPT_HANDLEP BIT(1)
|
|
|
049c96 |
-#define DL_OPT_PORT_TYPE BIT(2)
|
|
|
049c96 |
-#define DL_OPT_PORT_COUNT BIT(3)
|
|
|
049c96 |
-
|
|
|
049c96 |
-static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
|
|
049c96 |
- uint32_t o_required, uint32_t o_optional)
|
|
|
049c96 |
+static int dl_argv_parse(struct dl *dl, uint32_t o_required,
|
|
|
049c96 |
+ uint32_t o_optional)
|
|
|
049c96 |
{
|
|
|
049c96 |
+ struct dl_opts *opts = &dl->opts;
|
|
|
049c96 |
uint32_t o_all = o_required | o_optional;
|
|
|
049c96 |
uint32_t o_found = 0;
|
|
|
049c96 |
int err;
|
|
|
049c96 |
|
|
|
049c96 |
if (o_required & DL_OPT_HANDLE) {
|
|
|
049c96 |
- err = dl_argv_put_handle(nlh, dl);
|
|
|
049c96 |
+ err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
+ o_found |= DL_OPT_HANDLE;
|
|
|
049c96 |
} else if (o_required & DL_OPT_HANDLEP) {
|
|
|
049c96 |
- err = dl_argv_put_handle_port(nlh, dl);
|
|
|
049c96 |
+ err = dl_argv_handle_port(dl, &opts->bus_name, &opts->dev_name,
|
|
|
049c96 |
+ &opts->port_index);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
+ o_found |= DL_OPT_HANDLEP;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
while (dl_argc(dl)) {
|
|
|
049c96 |
if (dl_argv_match(dl, "type") &&
|
|
|
049c96 |
(o_all & DL_OPT_PORT_TYPE)) {
|
|
|
049c96 |
- enum devlink_port_type port_type;
|
|
|
049c96 |
const char *typestr;
|
|
|
049c96 |
|
|
|
049c96 |
dl_arg_inc(dl);
|
|
|
049c96 |
err = dl_argv_str(dl, &typestr);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
- err = port_type_get(typestr, &port_type);
|
|
|
049c96 |
+ err = port_type_get(typestr, &opts->port_type);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
- mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE,
|
|
|
049c96 |
- port_type);
|
|
|
049c96 |
o_found |= DL_OPT_PORT_TYPE;
|
|
|
049c96 |
} else if (dl_argv_match(dl, "count") &&
|
|
|
049c96 |
(o_all & DL_OPT_PORT_COUNT)) {
|
|
|
049c96 |
- uint32_t count;
|
|
|
049c96 |
-
|
|
|
049c96 |
dl_arg_inc(dl);
|
|
|
049c96 |
- err = dl_argv_uint32_t(dl, &count);
|
|
|
049c96 |
+ err = dl_argv_uint32_t(dl, &opts->port_count);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
- mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_SPLIT_COUNT,
|
|
|
049c96 |
- count);
|
|
|
049c96 |
o_found |= DL_OPT_PORT_COUNT;
|
|
|
049c96 |
} else {
|
|
|
049c96 |
pr_err("Unknown option \"%s\"\n", dl_argv(dl));
|
|
|
049c96 |
@@ -516,6 +514,8 @@ static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
|
|
049c96 |
}
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
+ opts->present = o_found;
|
|
|
049c96 |
+
|
|
|
049c96 |
if ((o_required & DL_OPT_PORT_TYPE) && !(o_found & DL_OPT_PORT_TYPE)) {
|
|
|
049c96 |
pr_err("Port type option expected.\n");
|
|
|
049c96 |
return -EINVAL;
|
|
|
049c96 |
@@ -530,6 +530,39 @@ static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
+static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ struct dl_opts *opts = &dl->opts;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (opts->present & DL_OPT_HANDLE) {
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name);
|
|
|
049c96 |
+ } else if (opts->present & DL_OPT_HANDLEP) {
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name);
|
|
|
049c96 |
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name);
|
|
|
049c96 |
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX,
|
|
|
049c96 |
+ opts->port_index);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ if (opts->present & DL_OPT_PORT_TYPE)
|
|
|
049c96 |
+ mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE,
|
|
|
049c96 |
+ opts->port_type);
|
|
|
049c96 |
+ if (opts->present & DL_OPT_PORT_COUNT)
|
|
|
049c96 |
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_SPLIT_COUNT,
|
|
|
049c96 |
+ opts->port_count);
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
|
|
|
049c96 |
+ uint32_t o_required, uint32_t o_optional)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_argv_parse(dl, o_required, o_optional);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ dl_opts_put(nlh, dl);
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
static void cmd_dev_help(void)
|
|
|
049c96 |
{
|
|
|
049c96 |
pr_out("Usage: devlink dev show [ DEV ]\n");
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|