From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: sthemmin@microsoft.com, dsahern@gmail.com, kuba@kernel.org,
moshe@nvidia.com, aeedm@nvidia.com
Subject: [patch iproute2-next 1/3] devlink: query ifname for devlink port instead of map lookup
Date: Fri, 4 Nov 2022 11:23:25 +0100 [thread overview]
Message-ID: <20221104102327.770260-2-jiri@resnulli.us> (raw)
In-Reply-To: <20221104102327.770260-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
ifname map is created once during init. However, ifnames can easily
change during the devlink process runtime (e. g. devlink mon).
Therefore, query ifname during each devlink port print.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
devlink/devlink.c | 46 +++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index 8aefa101b2f8..680936f891cf 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -864,21 +864,38 @@ static int ifname_map_lookup(struct dl *dl, const char *ifname,
return -ENOENT;
}
-static int ifname_map_rev_lookup(struct dl *dl, const char *bus_name,
- const char *dev_name, uint32_t port_index,
- char **p_ifname)
+static int port_ifname_get_cb(const struct nlmsghdr *nlh, void *data)
{
- struct ifname_map *ifname_map;
+ struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ char **p_ifname = data;
+ const char *ifname;
- list_for_each_entry(ifname_map, &dl->ifname_map_list, list) {
- if (strcmp(bus_name, ifname_map->bus_name) == 0 &&
- strcmp(dev_name, ifname_map->dev_name) == 0 &&
- port_index == ifname_map->port_index) {
- *p_ifname = ifname_map->ifname;
- return 0;
- }
- }
- return -ENOENT;
+ mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+ if (!tb[DEVLINK_ATTR_PORT_NETDEV_NAME])
+ return MNL_CB_ERROR;
+
+ ifname = mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_NETDEV_NAME]);
+ *p_ifname = strdup(ifname);
+ if (!*p_ifname)
+ return MNL_CB_ERROR;
+
+ return MNL_CB_OK;
+}
+
+static int port_ifname_get(struct dl *dl, const char *bus_name,
+ const char *dev_name, uint32_t port_index,
+ char **p_ifname)
+{
+ struct nlmsghdr *nlh;
+
+ nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
+ NLM_F_REQUEST | NLM_F_ACK);
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, bus_name);
+ mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, dev_name);
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port_index);
+ return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, port_ifname_get_cb,
+ p_ifname);
}
static int strtobool(const char *str, bool *p_val)
@@ -2577,8 +2594,7 @@ static void __pr_out_port_handle_start(struct dl *dl, const char *bus_name,
char *ifname = NULL;
if (dl->no_nice_names || !try_nice ||
- ifname_map_rev_lookup(dl, bus_name, dev_name,
- port_index, &ifname) != 0)
+ port_ifname_get(dl, bus_name, dev_name, port_index, &ifname) != 0)
sprintf(buf, "%s/%s/%d", bus_name, dev_name, port_index);
else
sprintf(buf, "%s", ifname);
--
2.37.3
next prev parent reply other threads:[~2022-11-04 10:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 10:23 [patch iproute2-next 0/3] devlink: make ifname-port relationship behaviour better Jiri Pirko
2022-11-04 10:23 ` Jiri Pirko [this message]
2022-11-07 15:16 ` [patch iproute2-next 1/3] devlink: query ifname for devlink port instead of map lookup David Ahern
2022-11-07 15:54 ` Jiri Pirko
2022-11-08 15:59 ` David Ahern
2022-11-09 11:57 ` Jiri Pirko
2022-11-04 10:23 ` [patch iproute2-next 2/3] devlink: add ifname_map_add/del() helpers Jiri Pirko
2022-11-04 10:23 ` [patch iproute2-next 3/3] devlink: get devlink port for ifname using RTNL get link command Jiri Pirko
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=20221104102327.770260-2-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=aeedm@nvidia.com \
--cc=dsahern@gmail.com \
--cc=kuba@kernel.org \
--cc=moshe@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=sthemmin@microsoft.com \
/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).