|
|
049c96 |
From 01194858b0ee630c56b7988b3e911ccf008b89ff 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: allow to parse both devlink and port handle in the
|
|
|
049c96 |
same time
|
|
|
049c96 |
|
|
|
049c96 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1342515
|
|
|
049c96 |
Upstream Status: iproute2.git commit 2f85a9c535874
|
|
|
049c96 |
|
|
|
049c96 |
commit 2f85a9c535874e721cfc8b8743325afc93a8b1fa
|
|
|
049c96 |
Author: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
Date: Fri Apr 15 09:51:50 2016 +0200
|
|
|
049c96 |
|
|
|
049c96 |
devlink: allow to parse both devlink and port handle in the same time
|
|
|
049c96 |
|
|
|
049c96 |
For filtering purposes, it makes sense for used to either specify
|
|
|
049c96 |
devlink handle of port handle.
|
|
|
049c96 |
|
|
|
049c96 |
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
|
|
|
049c96 |
---
|
|
|
049c96 |
devlink/devlink.c | 109 ++++++++++++++++++++++++++++++++++++++++++++----------
|
|
|
049c96 |
1 file changed, 90 insertions(+), 19 deletions(-)
|
|
|
049c96 |
|
|
|
049c96 |
diff --git a/devlink/devlink.c b/devlink/devlink.c
|
|
|
049c96 |
index d436bbf..e2e0413 100644
|
|
|
049c96 |
--- a/devlink/devlink.c
|
|
|
049c96 |
+++ b/devlink/devlink.c
|
|
|
049c96 |
@@ -363,6 +363,12 @@ static int strtouint32_t(const char *str, uint32_t *p_val)
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
+static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ strslashrsplit(str, p_bus_name, p_dev_name);
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
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 |
@@ -376,8 +382,40 @@ static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name)
|
|
|
049c96 |
pr_err("Expected \"bus_name/dev_name\".\n");
|
|
|
049c96 |
return -EINVAL;
|
|
|
049c96 |
}
|
|
|
049c96 |
+ return __dl_argv_handle(str, p_bus_name, p_dev_name);
|
|
|
049c96 |
+}
|
|
|
049c96 |
|
|
|
049c96 |
- strslashrsplit(str, p_bus_name, p_dev_name);
|
|
|
049c96 |
+static int __dl_argv_handle_port(char *str,
|
|
|
049c96 |
+ char **p_bus_name, char **p_dev_name,
|
|
|
049c96 |
+ uint32_t *p_port_index)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *handlestr = handlestr;
|
|
|
049c96 |
+ char *portstr = portstr;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ strslashrsplit(str, &handlestr, &portstr);
|
|
|
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, p_bus_name, p_dev_name);
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int __dl_argv_handle_port_ifname(struct dl *dl, char *str,
|
|
|
049c96 |
+ char **p_bus_name, char **p_dev_name,
|
|
|
049c96 |
+ uint32_t *p_port_index)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
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 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
|
|
|
049c96 |
@@ -386,7 +424,6 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
|
|
|
049c96 |
{
|
|
|
049c96 |
char *str = dl_argv_next(dl);
|
|
|
049c96 |
unsigned int slash_count;
|
|
|
049c96 |
- int err;
|
|
|
049c96 |
|
|
|
049c96 |
if (!str) {
|
|
|
049c96 |
pr_err("Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\") expected.\n");
|
|
|
049c96 |
@@ -398,26 +435,52 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
|
|
|
049c96 |
pr_err("Expected \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
|
|
|
049c96 |
return -EINVAL;
|
|
|
049c96 |
}
|
|
|
049c96 |
-
|
|
|
049c96 |
if (slash_count == 2) {
|
|
|
049c96 |
- char *handlestr = handlestr;
|
|
|
049c96 |
- char *portstr = portstr;
|
|
|
049c96 |
-
|
|
|
049c96 |
- err = strslashrsplit(str, &handlestr, &portstr);
|
|
|
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 __dl_argv_handle_port(str, p_bus_name,
|
|
|
049c96 |
+ p_dev_name, p_port_index);
|
|
|
049c96 |
+ } else if (slash_count == 0) {
|
|
|
049c96 |
+ return __dl_argv_handle_port_ifname(dl, str, p_bus_name,
|
|
|
049c96 |
+ p_dev_name, p_port_index);
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ return 0;
|
|
|
049c96 |
+}
|
|
|
049c96 |
+
|
|
|
049c96 |
+static int dl_argv_handle_both(struct dl *dl, char **p_bus_name,
|
|
|
049c96 |
+ char **p_dev_name, uint32_t *p_port_index,
|
|
|
049c96 |
+ uint32_t *p_handle_bit)
|
|
|
049c96 |
+{
|
|
|
049c96 |
+ char *str = dl_argv_next(dl);
|
|
|
049c96 |
+ unsigned int slash_count;
|
|
|
049c96 |
+ int err;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ if (!str) {
|
|
|
049c96 |
+ pr_err("One of following identifications expected:\n"
|
|
|
049c96 |
+ "Devlink identification (\"bus_name/dev_name\")\n"
|
|
|
049c96 |
+ "Port identification (\"bus_name/dev_name/port_index\" or \"netdev ifname\")\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
+ }
|
|
|
049c96 |
+ slash_count = strslashcount(str);
|
|
|
049c96 |
+ if (slash_count == 1) {
|
|
|
049c96 |
+ err = __dl_argv_handle(str, p_bus_name, p_dev_name);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
- }
|
|
|
049c96 |
- strslashrsplit(handlestr, p_bus_name, p_dev_name);
|
|
|
049c96 |
+ *p_handle_bit = DL_OPT_HANDLE;
|
|
|
049c96 |
+ } else if (slash_count == 2) {
|
|
|
049c96 |
+ err = __dl_argv_handle_port(str, p_bus_name,
|
|
|
049c96 |
+ p_dev_name, p_port_index);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ *p_handle_bit = DL_OPT_HANDLEP;
|
|
|
049c96 |
} else if (slash_count == 0) {
|
|
|
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 |
+ err = __dl_argv_handle_port_ifname(dl, str, p_bus_name,
|
|
|
049c96 |
+ p_dev_name, p_port_index);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
- }
|
|
|
049c96 |
+ *p_handle_bit = DL_OPT_HANDLEP;
|
|
|
049c96 |
+ } else {
|
|
|
049c96 |
+ pr_err("Wrong port identification string format.\n");
|
|
|
049c96 |
+ pr_err("Expected \"bus_name/dev_name\" or \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
|
|
|
049c96 |
+ return -EINVAL;
|
|
|
049c96 |
}
|
|
|
049c96 |
return 0;
|
|
|
049c96 |
}
|
|
|
049c96 |
@@ -475,7 +538,15 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
|
|
|
049c96 |
uint32_t o_found = 0;
|
|
|
049c96 |
int err;
|
|
|
049c96 |
|
|
|
049c96 |
- if (o_required & DL_OPT_HANDLE) {
|
|
|
049c96 |
+ if (o_required & DL_OPT_HANDLE && o_required & DL_OPT_HANDLEP) {
|
|
|
049c96 |
+ uint32_t handle_bit = handle_bit;
|
|
|
049c96 |
+
|
|
|
049c96 |
+ err = dl_argv_handle_both(dl, &opts->bus_name, &opts->dev_name,
|
|
|
049c96 |
+ &opts->port_index, &handle_bit);
|
|
|
049c96 |
+ if (err)
|
|
|
049c96 |
+ return err;
|
|
|
049c96 |
+ o_found |= handle_bit;
|
|
|
049c96 |
+ } else if (o_required & DL_OPT_HANDLE) {
|
|
|
049c96 |
err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name);
|
|
|
049c96 |
if (err)
|
|
|
049c96 |
return err;
|
|
|
049c96 |
--
|
|
|
049c96 |
1.8.3.1
|
|
|
049c96 |
|