Skip to content

Commit c0a41b8

Browse files
shemmingerdavem330
authored andcommitted
hv_netvsc: move VF to same namespace as netvsc device
When VF is added, the paravirtual device is already present and may have been moved to another network namespace. For example, sometimes the management interface is put in another net namespace in some environments. The VF should get moved to where the netvsc device is when the VF is discovered. The user can move it later (if desired). Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7bf7bb3 commit c0a41b8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/net/hyperv/netvsc_drv.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,7 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
19281928
struct net_device *ndev;
19291929
struct net_device_context *net_device_ctx;
19301930
struct netvsc_device *netvsc_dev;
1931+
int ret;
19311932

19321933
if (vf_netdev->addr_len != ETH_ALEN)
19331934
return NOTIFY_DONE;
@@ -1946,11 +1947,29 @@ static int netvsc_register_vf(struct net_device *vf_netdev)
19461947
if (!netvsc_dev || rtnl_dereference(net_device_ctx->vf_netdev))
19471948
return NOTIFY_DONE;
19481949

1949-
if (netvsc_vf_join(vf_netdev, ndev) != 0)
1950+
/* if syntihetic interface is a different namespace,
1951+
* then move the VF to that namespace; join will be
1952+
* done again in that context.
1953+
*/
1954+
if (!net_eq(dev_net(ndev), dev_net(vf_netdev))) {
1955+
ret = dev_change_net_namespace(vf_netdev,
1956+
dev_net(ndev), "eth%d");
1957+
if (ret)
1958+
netdev_err(vf_netdev,
1959+
"could not move to same namespace as %s: %d\n",
1960+
ndev->name, ret);
1961+
else
1962+
netdev_info(vf_netdev,
1963+
"VF moved to namespace with: %s\n",
1964+
ndev->name);
19501965
return NOTIFY_DONE;
1966+
}
19511967

19521968
netdev_info(ndev, "VF registering: %s\n", vf_netdev->name);
19531969

1970+
if (netvsc_vf_join(vf_netdev, ndev) != 0)
1971+
return NOTIFY_DONE;
1972+
19541973
dev_hold(vf_netdev);
19551974
rcu_assign_pointer(net_device_ctx->vf_netdev, vf_netdev);
19561975
return NOTIFY_OK;

0 commit comments

Comments
 (0)