diff mbox series

[iproute2] devlink: Fix dumps where interface map is used

Message ID 20230427052521.464295-1-idosch@nvidia.com (mailing list archive)
State Accepted
Commit b6f4a62ba7a07c546d71c14a94be1c4481a65b1a
Delegated to: Stephen Hemminger
Headers show
Series [iproute2] devlink: Fix dumps where interface map is used | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Ido Schimmel April 27, 2023, 5:25 a.m. UTC
The devlink utility stores an interface map that can be used to map an
interface name to a devlink port and vice versa. The map is populated by
issuing a devlink port dump via 'DEVLINK_CMD_PORT_GET' command.

Cited commits started to populate the map only when it is actually
needed. One such case is when a dump (e.g., shared buffer dump) only
returns devlink port handles. When pretty printing is required, the
utility will consult the map to translate the devlink port handles to
the corresponding interface names.

The above is problematic as it means that the port dump response(s) will
be queued to the same receive buffer as the response(s) of the dump that
triggered the port dump, resulting in a failed dump [1].

Fix by using a different netlink socket for the population of the
interface map.

[1]
$ devlink sb tc bind show
kernel answers: Device or resource busy
Failed to create index map
//0:
  sb 0 tc 4 type egress pool 4 threshold 9
kernel answers: Device or resource busy
[...]
$ echo $?
1

Fixes: 5cddbb274eab ("devlink: load port-ifname map on demand")
Fixes: 63d84b1fc98d ("devlink: load ifname map on demand from ifname_map_rev_lookup() as well")
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 devlink/devlink.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org April 27, 2023, 4 p.m. UTC | #1
Hello:

This patch was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Thu, 27 Apr 2023 08:25:21 +0300 you wrote:
> The devlink utility stores an interface map that can be used to map an
> interface name to a devlink port and vice versa. The map is populated by
> issuing a devlink port dump via 'DEVLINK_CMD_PORT_GET' command.
> 
> Cited commits started to populate the map only when it is actually
> needed. One such case is when a dump (e.g., shared buffer dump) only
> returns devlink port handles. When pretty printing is required, the
> utility will consult the map to translate the devlink port handles to
> the corresponding interface names.
> 
> [...]

Here is the summary with links:
  - [iproute2] devlink: Fix dumps where interface map is used
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=b6f4a62ba7a0

You are awesome, thank you!
diff mbox series

Patch

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 795f8318c0c4..019ffc23e766 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -931,6 +931,7 @@  static void ifname_map_init(struct dl *dl)
 
 static int ifname_map_load(struct dl *dl, const char *ifname)
 {
+	struct mnlu_gen_socket nlg_map;
 	struct nlmsghdr *nlh;
 	int err;
 
@@ -943,15 +944,20 @@  static int ifname_map_load(struct dl *dl, const char *ifname)
 		 */
 	}
 
-	nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_PORT_GET,
+	err = mnlu_gen_socket_open(&nlg_map, DEVLINK_GENL_NAME,
+				   DEVLINK_GENL_VERSION);
+	if (err)
+		return err;
+
+	nlh = mnlu_gen_socket_cmd_prepare(&nlg_map, DEVLINK_CMD_PORT_GET,
 			       NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
 
-	err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, ifname_map_cb, dl);
-	if (err) {
+	err = mnlu_gen_socket_sndrcv(&nlg_map, nlh, ifname_map_cb, dl);
+	if (err)
 		ifname_map_fini(dl);
-		return err;
-	}
-	return 0;
+
+	mnlu_gen_socket_close(&nlg_map);
+	return err;
 }
 
 static int ifname_map_check_load(struct dl *dl, const char *ifname)