netdev
[Top] [All Lists]

Re: [PATCH] network device renaming sysfs fix

To: Dan Aloni <da-x@xxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>
Subject: Re: [PATCH] network device renaming sysfs fix
From: Stephen Hemminger <shemminger@xxxxxxxx>
Date: Fri, 15 Aug 2003 09:37:24 -0700
Cc: Linux Net-Dev <netdev@xxxxxxxxxxx>, Mark Huth <mhuth@xxxxxxxxxx>
In-reply-to: <20030815111514.GA5228@xxxxxxxxxxxxxxx>
Organization: Open Source Development Lab
References: <20030815111514.GA5228@xxxxxxxxxxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
On Fri, 15 Aug 2003 14:15:14 +0300
Dan Aloni <da-x@xxxxxxx> wrote:

> (repost, now will hopefully reach the mailing list)
> 
> I believe this is a better approach for fixing the sysfs renaming
> discrepancy. Later I'll also look into fixing the same issue 
> with sysctl.
> 

Yes, this is a better fix because it won't break when unregister and free are 
split
into seperate steps (coming soon).

But, do we really need the debug message?  
Why return an error if you already committed the change? If you get an error,
then don't rename the network device.

The class_dev kobject name is 20 chars and IFNAMSIZ is 16, so the solution
needs to truncate if new_name is not null terminated (all 16 chars long).

This seems like the best approach:

diff -Nru a/net/core/dev.c b/net/core/dev.c
--- a/net/core/dev.c    Fri Aug 15 09:34:11 2003
+++ b/net/core/dev.c    Fri Aug 15 09:34:11 2003
@@ -2343,14 +2343,18 @@
                case SIOCSIFNAME:
                        if (dev->flags & IFF_UP)
                                return -EBUSY;
+                       ifr->ifr_newname[IFNAMSIZ-1] = '\0';
                        if (__dev_get_by_name(ifr->ifr_newname))
                                return -EEXIST;
-                       memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
-                       dev->name[IFNAMSIZ - 1] = 0;
-                       strlcpy(dev->class_dev.class_id, dev->name, 
BUS_ID_SIZE);
-                       notifier_call_chain(&netdev_chain,
-                                           NETDEV_CHANGENAME, dev);
-                       return 0;
+                       err = class_device_rename(&dev->class_dev, 
+                                                 ifr->ifr_newname);
+                       if (!err) {
+                               strlcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
+
+                               notifier_call_chain(&netdev_chain,
+                                                   NETDEV_CHANGENAME, dev);
+                       }
+                       return err;
 
                /*
                 *      Unknown or private ioctl


<Prev in Thread] Current Thread [Next in Thread>