RDMA/nldev: Allow setting the device name while changing net namespace

Accept RDMA_NLDEV_ATTR_DEV_NAME together with RDMA_NLDEV_NET_NS_FD so a
netlink move can rename the device in the destination namespace. Keep the
name semantics aligned with the existing RDMA rename path.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Link: https://patch.msgid.link/20260716132316.1495242-6-jiri@resnulli.us
Signed-off-by: Leon Romanovsky <leon@kernel.org>
This commit is contained in:
Jiri Pirko
2026-07-16 15:23:06 +02:00
committed by Leon Romanovsky
parent e11553414e
commit 601f3fd97d
3 changed files with 28 additions and 10 deletions

View File

@@ -1901,6 +1901,9 @@ int ib_device_set_netns_put(struct sk_buff *skb,
if (ret == -EEXIST)
NL_SET_ERR_MSG(extack,
"Device name already exists in the target net namespace");
else if (ret == -EINVAL && name)
NL_SET_ERR_MSG(extack,
"Unable to use requested device name in the target net namespace");
goto ns_err;
}
@@ -1931,6 +1934,9 @@ int ib_device_set_netns_put(struct sk_buff *skb,
if (ret == -EEXIST)
NL_SET_ERR_MSG(extack,
"Device name already exists in the target net namespace");
else if (ret == -EINVAL && name)
NL_SET_ERR_MSG(extack,
"Unable to use requested device name in the target net namespace");
put_net(net);
return ret;

View File

@@ -1186,6 +1186,24 @@ static int nldev_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
if (!device)
return -EINVAL;
if (tb[RDMA_NLDEV_NET_NS_FD]) {
char name[IB_DEVICE_NAME_MAX] = {};
u32 ns_fd;
if (tb[RDMA_NLDEV_ATTR_DEV_NAME]) {
nla_strscpy(name, tb[RDMA_NLDEV_ATTR_DEV_NAME],
IB_DEVICE_NAME_MAX);
if (strlen(name) == 0) {
err = -EINVAL;
goto done;
}
}
ns_fd = nla_get_u32(tb[RDMA_NLDEV_NET_NS_FD]);
err = ib_device_set_netns_put(skb, device, ns_fd,
name[0] ? name : NULL, extack);
goto put_done;
}
if (tb[RDMA_NLDEV_ATTR_DEV_NAME]) {
char name[IB_DEVICE_NAME_MAX] = {};
@@ -1199,15 +1217,6 @@ static int nldev_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
goto done;
}
if (tb[RDMA_NLDEV_NET_NS_FD]) {
u32 ns_fd;
ns_fd = nla_get_u32(tb[RDMA_NLDEV_NET_NS_FD]);
err = ib_device_set_netns_put(skb, device, ns_fd, NULL,
extack);
goto put_done;
}
if (tb[RDMA_NLDEV_ATTR_DEV_DIM]) {
u8 use_dim;

View File

@@ -516,7 +516,10 @@ enum rdma_nldev_attr {
RDMA_NLDEV_ATTR_DEV_PROTOCOL, /* string */
/*
* File descriptor handle of the net namespace object
* File descriptor handle of the net namespace object. May be combined
* with RDMA_NLDEV_ATTR_DEV_NAME (a literal device name) to also rename
* the device in the destination namespace; the move fails with -EEXIST
* if that name is already taken there.
*/
RDMA_NLDEV_NET_NS_FD, /* u32 */
/*