RDMA/nldev: Report net namespace move errors through extack

Thread extack through the existing net namespace move helper and report the
main failure reasons from the core path. Keep the existing move UAPI shape
unchanged.

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

View File

@ -356,7 +356,8 @@ void ib_port_unregister_client_groups(struct ib_device *ibdev, u32 port_num,
const struct attribute_group **groups);
int ib_device_set_netns_put(struct sk_buff *skb,
struct ib_device *dev, u32 ns_fd, const char *name);
struct ib_device *dev, u32 ns_fd, const char *name,
struct netlink_ext_ack *extack);
int rdma_nl_net_init(struct rdma_dev_net *rnet);
void rdma_nl_net_exit(struct rdma_dev_net *rnet);

View File

@ -1871,18 +1871,22 @@ static int rdma_dev_change_netns(struct ib_device *device, struct net *cur_net,
}
int ib_device_set_netns_put(struct sk_buff *skb,
struct ib_device *dev, u32 ns_fd, const char *name)
struct ib_device *dev, u32 ns_fd, const char *name,
struct netlink_ext_ack *extack)
{
struct net *net;
int ret;
net = get_net_ns_by_fd(ns_fd);
if (IS_ERR(net)) {
NL_SET_ERR_MSG(extack, "Invalid target net namespace fd");
ret = PTR_ERR(net);
goto net_err;
}
if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) {
NL_SET_ERR_MSG(extack,
"Missing CAP_NET_ADMIN in the target net namespace");
ret = -EPERM;
goto ns_err;
}
@ -1893,6 +1897,10 @@ int ib_device_set_netns_put(struct sk_buff *skb,
*/
if (net_eq(net, read_pnet(&dev->coredev.rdma_net))) {
ret = name ? ib_device_rename(dev, name) : 0;
if (ret == -EEXIST)
NL_SET_ERR_MSG(extack,
"Device name already exists in the target net namespace");
goto ns_err;
}
@ -1901,7 +1909,16 @@ int ib_device_set_netns_put(struct sk_buff *skb,
* changed and this cannot be blocked waiting for userspace to do
* something, so disassociation is mandatory.
*/
if (!dev->ops.disassociate_ucontext || ib_devices_shared_netns) {
if (ib_devices_shared_netns) {
NL_SET_ERR_MSG(extack,
"Cannot change net namespace of RDMA device in shared netns mode");
ret = -EOPNOTSUPP;
goto ns_err;
}
if (!dev->ops.disassociate_ucontext) {
NL_SET_ERR_MSG(extack,
"Device does not support namespace changes (no disassociate support)");
ret = -EOPNOTSUPP;
goto ns_err;
}
@ -1911,6 +1928,9 @@ int ib_device_set_netns_put(struct sk_buff *skb,
ret = rdma_dev_change_netns(dev, current->nsproxy->net_ns, net, name,
NULL);
put_device(&dev->dev);
if (ret == -EEXIST)
NL_SET_ERR_MSG(extack,
"Device name already exists in the target net namespace");
put_net(net);
return ret;

View File

@ -1203,10 +1203,8 @@ static int nldev_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
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);
if (err == -EEXIST)
NL_SET_ERR_MSG(extack,
"Device name already exists in the target net namespace");
err = ib_device_set_netns_put(skb, device, ns_fd, NULL,
extack);
goto put_done;
}