Commit 5bb025fa authored by Veaceslav Falico's avatar Veaceslav Falico Committed by David S. Miller

net: rename sysfs symlinks on device name change

Currently, we don't rename the upper/lower_ifc symlinks in
/sys/class/net/*/ , which might result stale/duplicate links/names.

Fix this by adding netdev_adjacent_rename_links(dev, oldname) which renames
all the upper/lower interface's links to dev from the upper/lower_oldname
to the new name.

We don't need a rollback because only we control these symlinks and if we
fail to rename them - sysfs will anyway complain.
Reported-by: default avatarDing Tianhong <dingtianhong@huawei.com>
CC: Ding Tianhong <dingtianhong@huawei.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Eric Dumazet <edumazet@google.com>
CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
CC: Cong Wang <amwang@redhat.com>
Signed-off-by: default avatarVeaceslav Falico <vfalico@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3ee32707
...@@ -2941,6 +2941,7 @@ int netdev_master_upper_dev_link_private(struct net_device *dev, ...@@ -2941,6 +2941,7 @@ int netdev_master_upper_dev_link_private(struct net_device *dev,
void *private); void *private);
void netdev_upper_dev_unlink(struct net_device *dev, void netdev_upper_dev_unlink(struct net_device *dev,
struct net_device *upper_dev); struct net_device *upper_dev);
void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
void *netdev_lower_dev_get_private(struct net_device *dev, void *netdev_lower_dev_get_private(struct net_device *dev,
struct net_device *lower_dev); struct net_device *lower_dev);
int skb_checksum_help(struct sk_buff *skb); int skb_checksum_help(struct sk_buff *skb);
......
...@@ -1119,6 +1119,8 @@ int dev_change_name(struct net_device *dev, const char *newname) ...@@ -1119,6 +1119,8 @@ int dev_change_name(struct net_device *dev, const char *newname)
write_seqcount_end(&devnet_rename_seq); write_seqcount_end(&devnet_rename_seq);
netdev_adjacent_rename_links(dev, oldname);
write_lock_bh(&dev_base_lock); write_lock_bh(&dev_base_lock);
hlist_del_rcu(&dev->name_hlist); hlist_del_rcu(&dev->name_hlist);
write_unlock_bh(&dev_base_lock); write_unlock_bh(&dev_base_lock);
...@@ -1138,6 +1140,7 @@ int dev_change_name(struct net_device *dev, const char *newname) ...@@ -1138,6 +1140,7 @@ int dev_change_name(struct net_device *dev, const char *newname)
err = ret; err = ret;
write_seqcount_begin(&devnet_rename_seq); write_seqcount_begin(&devnet_rename_seq);
memcpy(dev->name, oldname, IFNAMSIZ); memcpy(dev->name, oldname, IFNAMSIZ);
memcpy(oldname, newname, IFNAMSIZ);
goto rollback; goto rollback;
} else { } else {
pr_err("%s: name change rollback failed: %d\n", pr_err("%s: name change rollback failed: %d\n",
...@@ -4999,6 +5002,25 @@ void netdev_upper_dev_unlink(struct net_device *dev, ...@@ -4999,6 +5002,25 @@ void netdev_upper_dev_unlink(struct net_device *dev,
} }
EXPORT_SYMBOL(netdev_upper_dev_unlink); EXPORT_SYMBOL(netdev_upper_dev_unlink);
void netdev_adjacent_rename_links(struct net_device *dev, char *oldname)
{
struct netdev_adjacent *iter;
list_for_each_entry(iter, &dev->adj_list.upper, list) {
netdev_adjacent_sysfs_del(iter->dev, oldname,
&iter->dev->adj_list.lower);
netdev_adjacent_sysfs_add(iter->dev, dev,
&iter->dev->adj_list.lower);
}
list_for_each_entry(iter, &dev->adj_list.lower, list) {
netdev_adjacent_sysfs_del(iter->dev, oldname,
&iter->dev->adj_list.upper);
netdev_adjacent_sysfs_add(iter->dev, dev,
&iter->dev->adj_list.upper);
}
}
void *netdev_lower_dev_get_private(struct net_device *dev, void *netdev_lower_dev_get_private(struct net_device *dev,
struct net_device *lower_dev) struct net_device *lower_dev)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment