datapath: Update sysfs links when network devices are renamed.
authorBen Pfaff <blp@nicira.com>
Wed, 5 Aug 2009 21:36:21 +0000 (14:36 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 6 Aug 2009 23:57:06 +0000 (16:57 -0700)
We create symlinks from /sys/class/net/<bridgename>/brif/<devname> to
/sys/class/net/<devname>/brport, but until now we have never updated the
links when network devices are renamed.  This commit fixes this problem.

(Only the <devname> in /sys/class/net/<bridgename>/brif/<devname> needs to
be updated.  Symlinks within sysfs have stable targets; that is, no matter
how the object that a sysfs symlink points to moves around, the link is
still maintained correctly.)

datapath/datapath.c
datapath/datapath.h
datapath/dp_notify.c
datapath/dp_sysfs_if.c

index f4284edce58c567d3799e9ebe08698138d0d5561..bf8043b6054fffa428fb827321325f16cdfa6f87 100644 (file)
@@ -450,7 +450,7 @@ int dp_del_port(struct net_bridge_port *p)
 
 #ifdef SUPPORT_SYSFS
        if (p->port_no != ODPP_LOCAL)
-               sysfs_remove_link(&p->dp->ifobj, p->dev->name);
+               dp_sysfs_del_if(p);
 #endif
        dp_ifinfo_notify(RTM_DELLINK, p);
 
@@ -474,8 +474,6 @@ int dp_del_port(struct net_bridge_port *p)
 
        if (is_dp_dev(p->dev))
                dp_dev_destroy(p->dev);
-       if (p->port_no != ODPP_LOCAL)
-               dp_sysfs_del_if(p);
        dev_put(p->dev);
        kobject_put(&p->kobj);
 
index 63d92cbb5f723070a67cf27c9f85ea72e7384150..62c79d43b88d8e29eadb3116f8c5eb2f542f077f 100644 (file)
@@ -93,6 +93,7 @@ struct net_bridge_port {
        struct datapath *dp;
        struct net_device *dev;
        struct kobject kobj;
+       char linkname[IFNAMSIZ];
        struct list_head node;   /* Element in datapath.ports. */
 };
 
index 5b8cf17126ade11a00438e731bed8f193fef8394..f22d8b342f1b1b3d88d19132a2ad88d83feaec56 100644 (file)
@@ -17,12 +17,29 @@ static int dp_device_event(struct notifier_block *unused, unsigned long event,
                void *ptr) 
 {
        struct net_device *dev = ptr;
-       struct net_bridge_port *p = dev->br_port;
-       if (event == NETDEV_UNREGISTER && p) {
-               struct datapath *dp = p->dp;
+       struct net_bridge_port *p;
+       struct datapath *dp;
+
+       p = dev->br_port;
+       if (!p)
+               return NOTIFY_DONE;
+       dp = p->dp;
+
+       switch (event) {
+       case NETDEV_UNREGISTER:
                mutex_lock(&dp->mutex);
                dp_del_port(p);
                mutex_unlock(&dp->mutex);
+               break;
+
+       case NETDEV_CHANGENAME:
+               if (p->port_no != ODPP_LOCAL) {
+                       mutex_lock(&dp->mutex);
+                       dp_sysfs_del_if(p);
+                       dp_sysfs_add_if(p);
+                       mutex_unlock(&dp->mutex);
+               }
+               break;
        }
        return NOTIFY_DONE;
 }
index 178afbd733dea14af34f4502ee7cbebd57b05129..ab928f6c6534b7bbfa35cb6c019f0fdb47e4d22e 100644 (file)
@@ -302,6 +302,7 @@ int dp_sysfs_add_if(struct net_bridge_port *p)
        err = sysfs_create_link(&dp->ifobj, &p->kobj, p->dev->name);
        if (err)
                goto err_del;
+       strcpy(p->linkname, p->dev->name);
 
        kobject_uevent(&p->kobj, KOBJ_ADD);
 
@@ -319,6 +320,10 @@ err_put:
 
 int dp_sysfs_del_if(struct net_bridge_port *p)
 {
+       if (p->linkname[0]) {
+               sysfs_remove_link(&p->dp->ifobj, p->linkname);
+               p->linkname[0] = '\0';
+       }
        if (p->kobj.dentry) {
                kobject_uevent(&p->kobj, KOBJ_REMOVE);
                kobject_del(&p->kobj);