Commit 238fa362 authored by Tom Gundersen's avatar Tom Gundersen Committed by David S. Miller

net: set name assign type for renamed devices

Based on a patch from David Herrmann.

This is the only place devices can be renamed.

v9: restore revers-christmas-tree order of local variables
Signed-off-by: default avatarTom Gundersen <teg@jklm.no>
Reviewed-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 685343fc
...@@ -1082,6 +1082,7 @@ static int dev_get_valid_name(struct net *net, ...@@ -1082,6 +1082,7 @@ static int dev_get_valid_name(struct net *net,
*/ */
int dev_change_name(struct net_device *dev, const char *newname) int dev_change_name(struct net_device *dev, const char *newname)
{ {
unsigned char old_assign_type;
char oldname[IFNAMSIZ]; char oldname[IFNAMSIZ];
int err = 0; int err = 0;
int ret; int ret;
...@@ -1109,10 +1110,14 @@ int dev_change_name(struct net_device *dev, const char *newname) ...@@ -1109,10 +1110,14 @@ int dev_change_name(struct net_device *dev, const char *newname)
return err; return err;
} }
old_assign_type = dev->name_assign_type;
dev->name_assign_type = NET_NAME_RENAMED;
rollback: rollback:
ret = device_rename(&dev->dev, dev->name); ret = device_rename(&dev->dev, dev->name);
if (ret) { if (ret) {
memcpy(dev->name, oldname, IFNAMSIZ); memcpy(dev->name, oldname, IFNAMSIZ);
dev->name_assign_type = old_assign_type;
write_seqcount_end(&devnet_rename_seq); write_seqcount_end(&devnet_rename_seq);
return ret; return ret;
} }
...@@ -1141,6 +1146,8 @@ int dev_change_name(struct net_device *dev, const char *newname) ...@@ -1141,6 +1146,8 @@ int dev_change_name(struct net_device *dev, const char *newname)
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); memcpy(oldname, newname, IFNAMSIZ);
dev->name_assign_type = old_assign_type;
old_assign_type = NET_NAME_RENAMED;
goto rollback; goto rollback;
} else { } else {
pr_err("%s: name change rollback failed: %d\n", pr_err("%s: name change rollback failed: %d\n",
......
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